Skip to content

Commit

Permalink
Fix types (#544)
Browse files Browse the repository at this point in the history
  • Loading branch information
SotiriaSte committed Feb 28, 2023
1 parent ae52a45 commit c9cf6a9
Show file tree
Hide file tree
Showing 26 changed files with 93 additions and 54 deletions.
11 changes: 11 additions & 0 deletions libraries/grpc-sdk/src/interfaces/Params.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { Indexable } from './Indexable';

export type UrlParams = {
[key: string]: string;
};

export type QueryParams = {
[key: string]: string | string[];
};

export type BodyParams = Indexable;
1 change: 1 addition & 0 deletions libraries/grpc-sdk/src/interfaces/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ export * from './GrpcCallback';
export * from './Indexable';
export * from './RawQuery';
export * from './UntypedArray';
export * from './Params';
4 changes: 2 additions & 2 deletions libraries/grpc-sdk/src/modules/database/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
DropCollectionResponse,
Schema,
} from '../../protoUtils/database';
import { ConduitSchemaExtension, RawQuery } from '../../interfaces';
import { ConduitSchemaExtension, RawQuery, UntypedArray } from '../../interfaces';
import { Query } from '../../types/db';

export class DatabaseProvider extends ConduitModule<typeof DatabaseProviderDefinition> {
Expand Down Expand Up @@ -170,7 +170,7 @@ export class DatabaseProvider extends ConduitModule<typeof DatabaseProviderDefin
);
}

createMany<T>(schemaName: string, query: Query<T>[]): Promise<T[] | any[]> {
createMany<T>(schemaName: string, query: Query<T>[]): Promise<T[] | UntypedArray> {
return this.client!.createMany({ schemaName, query: this.processQuery(query) }).then(
res => {
return JSON.parse(res.result);
Expand Down
4 changes: 2 additions & 2 deletions libraries/grpc-sdk/src/routing/wrapRouterFunctions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ function parseResponseData(
}
}
} else {
if (r.hasOwnProperty('data')) (r as any).data = JSON.stringify((r as any).data);
if (r.hasOwnProperty('data')) r.data = JSON.stringify(r.data);
callback(null, r);
}
generateLog(routerRequest, requestReceive, call, undefined);
Expand Down Expand Up @@ -137,7 +137,7 @@ export function wrapRouterGrpcFunction(
}

const responded = { did: false };
fun(call, (r: any) => {
fun(call, r => {
parseResponseData(r, routerRequest, requestReceive, call, callback, responded);
})
.then(r =>
Expand Down
4 changes: 2 additions & 2 deletions libraries/grpc-sdk/src/utilities/Logger.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import ConduitGrpcSdk from '../index';
import ConduitGrpcSdk, { UntypedArray } from '../index';
import { Indexable } from '../interfaces';
import { linearBackoffTimeoutAsync } from '../utilities';
import winston, { format, LogCallback, Logger } from 'winston';
Expand Down Expand Up @@ -116,7 +116,7 @@ export class ConduitLogger {

async function lokiReadyCheck(lokiUrl: string): Promise<void> {
return new Promise((resolve, reject) => {
const data: any[] = [];
const data: UntypedArray = [];
get(`${lokiUrl}/ready`, r => {
r.on('data', chunk => data.push(chunk));
r.on('end', () => {
Expand Down
9 changes: 7 additions & 2 deletions libraries/hermes/src/GraphQl/GraphQlParser.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
import { ConduitModel, ConduitRouteOption, Indexable } from '@conduitplatform/grpc-sdk';
import {
ConduitModel,
ConduitRouteOption,
Indexable,
UntypedArray,
} from '@conduitplatform/grpc-sdk';
import { ConduitParser, TypeRegistry } from '../classes';

export interface ResolverDefinition {
Expand Down Expand Up @@ -131,7 +136,7 @@ export class GraphQlParser extends ConduitParser<ParseResult, ProcessingObject>
processingObject: ProcessingObject,
resolverName: string,
name: string,
value: any[],
value: UntypedArray,
isRequired: boolean = false,
nestedType?: boolean,
description?: string,
Expand Down
12 changes: 9 additions & 3 deletions libraries/hermes/src/Rest/SwaggerParser.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
import { ConduitModel, ConduitRouteOption, TYPE } from '@conduitplatform/grpc-sdk';
import {
ConduitModel,
ConduitRouteOption,
Indexable,
TYPE,
UntypedArray,
} from '@conduitplatform/grpc-sdk';
import { ConduitParser } from '../classes';

export interface ParseResult {
Expand Down Expand Up @@ -30,7 +36,7 @@ export interface SwaggerObject extends SwaggerDefinition {
export interface ProcessingObject {
type: 'object' | 'string' | 'array' | 'boolean' | 'number' | undefined;
format?: string;
properties: { [key: string]: any };
properties: Indexable;
required?: (string | keyof ProcessingObject['properties'])[];
items?: SwaggerDefinition | SwaggerObject | SwaggerString;
}
Expand Down Expand Up @@ -153,7 +159,7 @@ export class SwaggerParser extends ConduitParser<ParseResult, ProcessingObject>
processingObject: ProcessingObject,
resolverName: string,
name: string,
value: any[],
value: UntypedArray,
isRequired: boolean = false,
nestedType?: boolean,
description?: string,
Expand Down
21 changes: 9 additions & 12 deletions libraries/hermes/src/Rest/util.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,16 @@
import { Request } from 'express';
import { ConduitError, Indexable, Params, TYPE } from '@conduitplatform/grpc-sdk';
import {
BodyParams,
ConduitError,
Indexable,
Params,
QueryParams,
TYPE,
UrlParams,
} from '@conduitplatform/grpc-sdk';
import { isArray, isNil, isObject } from 'lodash';

type ConduitRequest = Request & { conduit?: Indexable };
type UrlParams = {
[key: string]: string;
};

type QueryParams = {
[key: string]: string | string[];
};

type BodyParams = {
[key: string]: any;
};

export function extractRequestData(req: ConduitRequest) {
const context = req.conduit || {};
Expand Down
3 changes: 2 additions & 1 deletion libraries/hermes/src/classes/ConduitParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
ConduitModelField,
TYPE,
ConduitRouteOption,
UntypedArray,
} from '@conduitplatform/grpc-sdk';

const baseTypes = ['String', 'Number', 'Boolean', 'Date', 'ObjectId', 'JSON'];
Expand Down Expand Up @@ -62,7 +63,7 @@ export abstract class ConduitParser<ParseResult, ProcessingObject> {
processingObject: ProcessingObject,
resolverName: string,
name: string,
value: any[],
value: UntypedArray,
isRequired: boolean,
nestedType?: boolean,
description?: string,
Expand Down
3 changes: 2 additions & 1 deletion modules/authentication/src/admin/user.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import ConduitGrpcSdk, {
GrpcError,
Indexable,
ParsedRouterRequest,
UnparsedRouterResponse,
} from '@conduitplatform/grpc-sdk';
Expand All @@ -17,7 +18,7 @@ export class UserAdmin {
const { skip } = call.request.params ?? 0;
const { limit } = call.request.params ?? 25;

let query: any = {};
let query: Indexable = {};
if (!isNil(isActive)) {
query.active = isActive;
}
Expand Down
5 changes: 3 additions & 2 deletions modules/authentication/src/handlers/oauth2/apple/apple.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import ConduitGrpcSdk, {
ConduitString,
ConfigController,
GrpcError,
Indexable,
ParsedRouterRequest,
RoutingManager,
} from '@conduitplatform/grpc-sdk';
Expand Down Expand Up @@ -65,7 +66,7 @@ export class AppleHandlers extends OAuth2<AppleUser, AppleOAuth2Settings> {

const publicKeys = await axios.get('https://appleid.apple.com/auth/keys');
const publicKey = publicKeys.data.keys.find(
(key: any) => key.kid === decoded_id_token!.header.kid,
(key: Indexable) => key.kid === decoded_id_token!.header.kid,
);
const applePublicKey = await this.generateApplePublicKey(publicKey.kid);
this.verifyIdentityToken(applePublicKey, params.id_token);
Expand All @@ -85,7 +86,7 @@ export class AppleHandlers extends OAuth2<AppleUser, AppleOAuth2Settings> {
sub: this.settings.clientId,
};

const apple_client_secret = jwt.sign(jwtPayload, apple_private_key as any, {
const apple_client_secret = jwt.sign(jwtPayload, apple_private_key, {
algorithm: 'ES256',
header: jwtHeader,
});
Expand Down
6 changes: 3 additions & 3 deletions modules/authentication/src/handlers/tokenProvider.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import ConduitGrpcSdk, { Query } from '@conduitplatform/grpc-sdk';
import ConduitGrpcSdk, { Indexable, Query } from '@conduitplatform/grpc-sdk';
import { AccessToken, RefreshToken, User } from '../models';
import moment from 'moment/moment';
import { AuthUtils } from '../utils';
import * as jwt from 'jsonwebtoken';
import { SignOptions } from 'jsonwebtoken';
import { Config } from '../config';
import { Cookie } from '../interfaces/Cookie';
import { isNil } from 'lodash';
import { Cookie } from '../interfaces';

export interface TokenOptions {
user: User;
Expand Down Expand Up @@ -170,7 +170,7 @@ export class TokenProvider {
return cookies;
}

private signToken(data: { [key: string]: any }, secret: string, options: SignOptions) {
private signToken(data: Indexable, secret: string, options: SignOptions) {
return jwt.sign(data, secret, options);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
} from '../../interfaces';
import { MongooseAdapter } from './index';
import { parseQuery } from './parser';
import { ConduitSchema } from '@conduitplatform/grpc-sdk';
import { ConduitSchema, Indexable } from '@conduitplatform/grpc-sdk';
import { isNil } from 'lodash';

const EJSON = require('mongodb-extended-json');
Expand Down
5 changes: 3 additions & 2 deletions modules/database/src/adapters/mongoose-adapter/utils.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import {
ConduitModel,
Indexable,
MongoIndexOptions,
PostgresIndexOptions,
} from '@conduitplatform/grpc-sdk';
Expand All @@ -11,7 +12,7 @@ import { Doc, Fields } from '../../interfaces';
/**
* @throws {Error}
*/
async function _createOrUpdate(obj: any, model: MongooseSchema) {
async function _createOrUpdate(obj: Indexable, model: MongooseSchema) {
if (obj.hasOwnProperty('_id')) {
const _id = obj._id;
delete obj._id;
Expand Down Expand Up @@ -44,7 +45,7 @@ async function _createWithPopulations(

if (isArray(document[key])) {
for (let i = 0; i < document[key].length; i++) {
const val: any = document[key][i];
const val = document[key][i];
if (!isObject(val)) {
continue;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,11 @@ export abstract class SequelizeSchema implements SchemaAdapter<ModelStatic<any>>
return inclusionArray;
}

createWithPopulation(doc: Model, relationObjects: any, transaction?: Transaction) {
createWithPopulation(
doc: Model,
relationObjects: Indexable,
transaction?: Transaction,
) {
let hasOne = false;
for (const relation in this.extractedRelations) {
if (!this.extractedRelations.hasOwnProperty(relation)) continue;
Expand Down
5 changes: 3 additions & 2 deletions modules/database/src/adapters/sequelize-adapter/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import ConduitGrpcSdk, {
PostgresIndexType,
RawSQLQuery,
sleep,
UntypedArray,
} from '@conduitplatform/grpc-sdk';
import { status } from '@grpc/grpc-js';
import { SequelizeAuto } from 'sequelize-auto';
Expand Down Expand Up @@ -241,7 +242,7 @@ export abstract class SequelizeAdapter<
if (!this.models[schemaName])
throw new GrpcError(status.NOT_FOUND, 'Requested schema not found');
const queryInterface = this.sequelize.getQueryInterface();
const result = (await queryInterface.showIndex('cnd_' + schemaName)) as Array<any>;
const result = (await queryInterface.showIndex('cnd_' + schemaName)) as UntypedArray;
result.filter(index => {
const fieldNames = [];
for (const field of index.fields) {
Expand Down Expand Up @@ -285,7 +286,7 @@ export abstract class SequelizeAdapter<
return 'Indexes deleted';
}

async execRawQuery(schemaName: string, rawQuery: RawSQLQuery): Promise<any> {
async execRawQuery(schemaName: string, rawQuery: RawSQLQuery) {
return await this.sequelize
.query(rawQuery.query, rawQuery.options)
.catch((e: Error) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export class SQLSchema extends SequelizeSchema {
query: SingleDocQuery,
populate?: string[],
transaction?: Transaction,
): Promise<{ [key: string]: any }> {
): Promise<Indexable> {
const { t, parsedQuery, transactionProvided } = await getTransactionAndParsedQuery(
transaction,
query,
Expand Down Expand Up @@ -149,7 +149,7 @@ export class SQLSchema extends SequelizeSchema {
parsedQuery.updatedAt = new Date();
incrementDbQueries();
const assocs = extractAssociationsFromObject(parsedQuery, this.associations);
const associationObjects: { [key: string]: any } = {};
const associationObjects: Indexable = {};
for (const assoc in assocs) {
if (Array.isArray(assocs[assoc]) && !Array.isArray(parsedQuery[assoc])) {
throw new Error(`Cannot update association ${assoc} with non-array value`);
Expand Down Expand Up @@ -178,7 +178,7 @@ export class SQLSchema extends SequelizeSchema {
for (const assoc in associationObjects) {
if (!associationObjects.hasOwnProperty(assoc)) continue;
if (Array.isArray(associationObjects[assoc])) {
associationObjects[assoc].forEach((obj: any) => {
associationObjects[assoc].forEach((obj: Indexable) => {
if (obj.hasOwnProperty('_id')) {
promises.push(
(this.associations[assoc] as SQLSchema).findByIdAndUpdate(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { SQLSchema } from './SQLSchema';
import { schemaConverter } from './SchemaConverter';
import { ConduitSchema } from '@conduitplatform/grpc-sdk';
import { ConduitSchema, Indexable } from '@conduitplatform/grpc-sdk';
import { isNil } from 'lodash';
import { ConduitDatabaseSchema } from '../../../interfaces';
import { SequelizeAdapter } from '../index';
Expand All @@ -17,7 +17,7 @@ export class SQLAdapter extends SequelizeAdapter<SQLSchema> {

private async processExtractedSchemas(
schema: ConduitSchema,
extractedSchemas: { [key: string]: any },
extractedSchemas: Indexable,
associatedSchemas: { [key: string]: SQLSchema | SQLSchema[] },
) {
for (const extractedSchema in extractedSchemas) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { DataTypes, ModelStatic, Sequelize, Transaction } from 'sequelize';
import { ConduitSchema, Indexable, sleep } from '@conduitplatform/grpc-sdk';
import { ConduitSchema, Indexable, sleep, UntypedArray } from '@conduitplatform/grpc-sdk';
import { SequelizeSchema } from '../SequelizeSchema';
import { ConduitDatabaseSchema, ParsedQuery } from '../../../interfaces';
import { isNil } from 'lodash';
Expand Down Expand Up @@ -178,7 +178,7 @@ export function processPushOperations(
export function compileSchema(
schema: ConduitDatabaseSchema,
registeredSchemas: Map<string, ConduitSchema>,
sequelizeModels: { [key: string]: any },
sequelizeModels: Indexable,
): ConduitDatabaseSchema {
let compiledSchema = JSON.parse(JSON.stringify(schema));
validateFieldConstraints(compiledSchema);
Expand Down Expand Up @@ -209,15 +209,15 @@ type ExtractedRelations = {
export async function resolveRelatedSchemas(
schema: ConduitDatabaseSchema,
extractedRelations: ExtractedRelations,
models: { [name: string]: any },
models: Indexable,
) {
const relatedSchemas: { [key: string]: SequelizeSchema | SequelizeSchema[] } = {};

if (Object.keys(extractedRelations).length > 0) {
let pendingModels: string[] = [];
for (const relation in extractedRelations) {
const rel = Array.isArray(extractedRelations[relation])
? (extractedRelations[relation] as any[])[0]
? (extractedRelations[relation] as UntypedArray)[0]
: extractedRelations[relation];
if (!models[rel.model] || !models[rel.model].synced) {
if (!pendingModels.includes(rel.model)) {
Expand Down
3 changes: 2 additions & 1 deletion modules/database/src/admin/documents.admin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import ConduitGrpcSdk, {
GrpcError,
ParsedRouterRequest,
UnparsedRouterResponse,
UntypedArray,
} from '@conduitplatform/grpc-sdk';
import { status } from '@grpc/grpc-js';
import { isNil } from 'lodash';
Expand Down Expand Up @@ -127,7 +128,7 @@ export class DocumentsAdmin {
'Schema does not exist or disallows doc modifications',
);
}
const updatedDocuments: any[] = [];
const updatedDocuments: UntypedArray = [];
for (const doc of changedDocuments) {
const dbDocument: Doc = await this.database
.getSchemaModel(schemaName)
Expand Down
Loading

0 comments on commit c9cf6a9

Please sign in to comment.