Skip to content

Commit

Permalink
refactor(grpc-sdk): switch to full named exports for cjs compatibility (
Browse files Browse the repository at this point in the history
  • Loading branch information
kkopanidis authored Jul 3, 2024
1 parent 46a95dc commit 6176ef5
Show file tree
Hide file tree
Showing 163 changed files with 290 additions and 165 deletions.
3 changes: 3 additions & 0 deletions libraries/grpc-sdk/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
"fast-jwt": "^3.3.2",
"fs-extra": "^11.2.0",
"ioredis": "^5.3.2",
"lodash": "^4.17.21",
"lodash-es": "^4.17.21",
"nice-grpc": "^2.1.7",
"nice-grpc-client-middleware-retry": "^3",
Expand All @@ -61,11 +62,13 @@
"devDependencies": {
"@rollup/plugin-commonjs": "^26.0.1",
"@rollup/plugin-json": "^6.1.0",
"@rollup/plugin-replace": "^5.0.7",
"@rollup/plugin-typescript": "^11.1.6",
"@types/convict": "^6.1.6",
"@types/express": "^4.17.21",
"@types/fs-extra": "^11.0.4",
"@types/google-protobuf": "^3.15.12",
"@types/lodash": "^4.17.6",
"@types/lodash-es": "^4.17.12",
"@types/node": "20.11.24",
"copyfiles": "^2.4.1",
Expand Down
12 changes: 11 additions & 1 deletion libraries/grpc-sdk/rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,27 @@ import pkg from './package.json' assert { type: 'json' };
import typescript from '@rollup/plugin-typescript';
import commonjs from '@rollup/plugin-commonjs';
import json from '@rollup/plugin-json';
import replace from '@rollup/plugin-replace';

export default [
{
input: 'src/index.ts',
plugins: [json(), commonjs(), typescript()],
output: [
{ file: pkg.main, format: 'cjs', sourcemap: true },
{
file: pkg.main,
format: 'cjs',
sourcemap: true,
},
{
file: pkg.module,
format: 'es',
sourcemap: true,
plugins: [
replace({
lodash: 'lodash-es',
}),
],
},
],
},
Expand Down
2 changes: 1 addition & 1 deletion libraries/grpc-sdk/src/classes/ConduitModule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
HealthDefinition,
} from '../protoUtils/index.js';
import { EventEmitter } from 'events';
import ConduitGrpcSdk from '../index.js';
import { ConduitGrpcSdk } from '../index.js';

export class ConduitModule<T extends CompatServiceDefinition> {
protected channel?: Channel;
Expand Down
2 changes: 1 addition & 1 deletion libraries/grpc-sdk/src/classes/HealthCheck.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {
} from '../interceptors/index.js';
import { createChannel, createClientFactory } from 'nice-grpc';
import { HealthCheckResponse, HealthDefinition } from '../protoUtils/index.js';
import ConduitGrpcSdk from '../index.js';
import { ConduitGrpcSdk } from '../index.js';

export async function checkModuleHealth(
clientName: string,
Expand Down
3 changes: 2 additions & 1 deletion libraries/grpc-sdk/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ import {

type UrlRemap = { [url: string]: string };

export default class ConduitGrpcSdk {
class ConduitGrpcSdk {
private static middleware: any[] = [];
public readonly name: string;
public readonly instance: string;
Expand Down Expand Up @@ -571,6 +571,7 @@ export default class ConduitGrpcSdk {
}
}

export { ConduitGrpcSdk };
export * from './interfaces/index.js';
export * from './classes/index.js';
export * from './modules/index.js';
Expand Down
2 changes: 1 addition & 1 deletion libraries/grpc-sdk/src/modules/config/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
RegisterModuleRequest,
} from '../../protoUtils/index.js';
import { Indexable } from '../../interfaces/index.js';
import ConduitGrpcSdk from '../../index.js';
import { ConduitGrpcSdk } from '../../index.js';
import { ClusterOptions, RedisOptions } from 'ioredis';

export class Config extends ConduitModule<typeof ConfigDefinition> {
Expand Down
2 changes: 1 addition & 1 deletion libraries/grpc-sdk/src/utilities/EventBus.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { RedisManager } from './RedisManager.js';
import { Cluster, Redis } from 'ioredis';
import crypto from 'crypto';
import ConduitGrpcSdk from '../index.js';
import { ConduitGrpcSdk } from '../index.js';

export class EventBus {
private _clientSubscriber: Redis | Cluster;
Expand Down
3 changes: 2 additions & 1 deletion libraries/hermes/src/GraphQl/GraphQL.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ import { processParams } from './utils/SimpleTypeParamUtils.js';
import { importDbTypes } from '../utils/types.js';
import { ConduitRouter } from '../Router.js';
import { errorHandler } from './utils/Request.utils.js';
import ConduitGrpcSdk, {
import {
ConduitGrpcSdk,
ConduitModel,
ConduitReturn,
ConduitRouteActions,
Expand Down
2 changes: 1 addition & 1 deletion libraries/hermes/src/GraphQl/utils/Request.utils.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import ConduitGrpcSdk, { ConduitError } from '@conduitplatform/grpc-sdk';
import { ConduitGrpcSdk, ConduitError } from '@conduitplatform/grpc-sdk';
import { GraphQLError } from 'graphql';

export const errorHandler = (err: Error | ConduitError | any) => {
Expand Down
2 changes: 1 addition & 1 deletion libraries/hermes/src/Proxy/Proxy.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { IRouterMatcher, NextFunction, Request, Response, Router } from 'express';
import { ConduitRouter } from '../Router.js';
import ConduitGrpcSdk from '@conduitplatform/grpc-sdk';
import { ConduitGrpcSdk } from '@conduitplatform/grpc-sdk';
import { ProxyRoute, TypeRegistry } from '../classes/index.js';
import { ProxyRouteActions } from '../interfaces/index.js';

Expand Down
3 changes: 2 additions & 1 deletion libraries/hermes/src/Rest/Rest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ import { SwaggerGenerator } from './Swagger.js';
import { extractRequestData, validateParams } from './util.js';
import { createHashKey, extractCaching } from '../cache.utils.js';
import { ConduitRouter } from '../Router.js';
import ConduitGrpcSdk, {
import {
ConduitGrpcSdk,
ConduitError,
ConduitRouteActions,
TYPE,
Expand Down
3 changes: 2 additions & 1 deletion libraries/hermes/src/Router.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { NextFunction, Request, Response, Router } from 'express';
import ConduitGrpcSdk, {
import {
ConduitGrpcSdk,
ConduitRouteActions,
ConduitRouteParameters,
GrpcError,
Expand Down
2 changes: 1 addition & 1 deletion libraries/hermes/src/Socket/Socket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {
SocketPush,
} from '../interfaces/index.js';
import ObjectHash from 'object-hash';
import ConduitGrpcSdk, { ConduitError } from '@conduitplatform/grpc-sdk';
import { ConduitGrpcSdk, ConduitError } from '@conduitplatform/grpc-sdk';

export class SocketController extends ConduitRouter {
private readonly httpServer: httpServer;
Expand Down
3 changes: 2 additions & 1 deletion libraries/hermes/src/classes/TypeRegistry.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import ConduitGrpcSdk, {
import {
ConduitGrpcSdk,
ConduitModel,
ConduitModelField,
} from '@conduitplatform/grpc-sdk';
Expand Down
3 changes: 2 additions & 1 deletion libraries/hermes/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ import express, { Express, NextFunction, Request, Response, Router } from 'expre
import { RestController } from './Rest/index.js';
import { GraphQLController } from './GraphQl/GraphQL.js';
import { SocketController } from './Socket/Socket.js';
import ConduitGrpcSdk, {
import {
ConduitGrpcSdk,
ConduitError,
IConduitLogger,
UntypedArray,
Expand Down
3 changes: 2 additions & 1 deletion libraries/hermes/src/utils/types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import ConduitGrpcSdk, {
import {
ConduitGrpcSdk,
ConduitModel,
ConduitModelFieldRelation,
} from '@conduitplatform/grpc-sdk';
Expand Down
3 changes: 3 additions & 0 deletions libraries/module-tools/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
"convict": "^6.2.4",
"express": "^4.19.2",
"fast-jwt": "^3.3.2",
"lodash": "^4.17.21",
"lodash-es": "^4.17.21",
"prom-client": "^15.1.0",
"protobufjs": "^7.2.6",
Expand All @@ -55,11 +56,13 @@
"@conduitplatform/grpc-sdk": "*",
"@rollup/plugin-commonjs": "^26.0.1",
"@rollup/plugin-json": "^6.1.0",
"@rollup/plugin-replace": "^5.0.7",
"@rollup/plugin-typescript": "^11.1.6",
"@types/convict": "^6.1.6",
"@types/express": "^4.17.21",
"@types/fs-extra": "^11.0.4",
"@types/google-protobuf": "^3.15.12",
"@types/lodash": "^4.17.6",
"@types/lodash-es": "^4.17.12",
"@types/node": "20.11.24",
"copyfiles": "^2.4.1",
Expand Down
12 changes: 11 additions & 1 deletion libraries/module-tools/rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,27 @@ import pkg from './package.json' assert { type: 'json' };
import typescript from '@rollup/plugin-typescript';
import commonjs from '@rollup/plugin-commonjs';
import json from '@rollup/plugin-json';
import replace from '@rollup/plugin-replace';

export default [
{
input: 'src/index.ts',
plugins: [json(), commonjs(), typescript()],
output: [
{ file: pkg.main, format: 'cjs', sourcemap: true },
{
file: pkg.main,
format: 'cjs',
sourcemap: true,
},
{
file: pkg.module,
format: 'es',
sourcemap: true,
plugins: [
replace({
lodash: 'lodash-es',
}),
],
},
],
},
Expand Down
5 changes: 3 additions & 2 deletions libraries/module-tools/src/ManagedModule.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { ConduitServiceModule, ConfigController, GrpcServer } from './classes/index.js';
import { kebabCase } from 'lodash-es';
import { kebabCase } from 'lodash';
import { status } from '@grpc/grpc-js';
import convict from 'convict';
import { ConduitService, ModuleLifecycleStage } from './interfaces/index.js';
import ConduitGrpcSdk, {
import {
ConduitGrpcSdk,
GrpcRequest,
GrpcResponse,
SetConfigRequest,
Expand Down
5 changes: 3 additions & 2 deletions libraries/module-tools/src/classes/ConduitServiceModule.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import path from 'path';
import { EventEmitter } from 'events';
import { camelCase } from 'lodash-es';
import { camelCase } from 'lodash';
import { ServerWritableStream } from '@grpc/grpc-js';
import { GrpcServer } from './GrpcServer.js';
import ConduitGrpcSdk, {
import {
ConduitGrpcSdk,
GrpcCallback,
GrpcRequest,
GrpcResponse,
Expand Down
4 changes: 2 additions & 2 deletions libraries/module-tools/src/classes/GrpcServer.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { addServiceToServer, createServer, wrapGrpcFunctions } from '../helpers/index.js';
import { Server } from '@grpc/grpc-js';
import { isNil } from 'lodash-es';
import ConduitGrpcSdk from '@conduitplatform/grpc-sdk';
import { isNil } from 'lodash';
import { ConduitGrpcSdk } from '@conduitplatform/grpc-sdk';

export class GrpcServer {
private grpcServer?: Server;
Expand Down
2 changes: 1 addition & 1 deletion libraries/module-tools/src/helpers/wrapGrpcFunctions.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { createVerifier } from 'fast-jwt';
import { status } from '@grpc/grpc-js';
import ConduitGrpcSdk, { GrpcCallback } from '@conduitplatform/grpc-sdk';
import { ConduitGrpcSdk, GrpcCallback } from '@conduitplatform/grpc-sdk';

interface JWT {
moduleName: string;
Expand Down
5 changes: 3 additions & 2 deletions libraries/module-tools/src/logging/index.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import ConduitGrpcSdk, {
import {
ConduitGrpcSdk,
IConduitLogger,
Indexable,
UntypedArray,
} from '@conduitplatform/grpc-sdk';
import winston, { format, LogCallback, Logger } from 'winston';
import { isEmpty } from 'lodash-es';
import { isEmpty } from 'lodash';
import { get } from 'http';
import LokiTransport from 'winston-loki';
import { linearBackoffTimeoutAsync } from '../utilities/index.js';
Expand Down
4 changes: 2 additions & 2 deletions libraries/module-tools/src/metrics/MetricsServer.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import express, { Express } from 'express';
import { Registry } from 'prom-client';
import { isNaN } from 'lodash-es';
import ConduitGrpcSdk from '@conduitplatform/grpc-sdk';
import { isNaN } from 'lodash';
import { ConduitGrpcSdk } from '@conduitplatform/grpc-sdk';

export class MetricsServer {
private readonly moduleName: string;
Expand Down
3 changes: 2 additions & 1 deletion libraries/module-tools/src/routing/wrapRouterFunctions.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import ConduitGrpcSdk, {
import {
ConduitGrpcSdk,
Indexable,
ParsedRouterRequest,
ParsedSocketRequest,
Expand Down
3 changes: 2 additions & 1 deletion libraries/module-tools/src/utilities/initializeSdk.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import ConduitGrpcSdk, {
import {
ConduitGrpcSdk,
HealthCheckStatus,
IConduitLogger,
} from '@conduitplatform/grpc-sdk';
Expand Down
2 changes: 1 addition & 1 deletion libraries/module-tools/src/utilities/merge.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { mergeWith as _mergeWith } from 'lodash-es';
import { mergeWith as _mergeWith } from 'lodash';

export function merge<T extends object>(objA: T, objB: T) {
const customizer = (objValue: unknown, srcValue: unknown) => {
Expand Down
3 changes: 2 additions & 1 deletion modules/authentication/src/Authentication.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import ConduitGrpcSdk, {
import {
ConduitGrpcSdk,
DatabaseProvider,
GrpcCallback,
GrpcRequest,
Expand Down
3 changes: 2 additions & 1 deletion modules/authentication/src/admin/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import ConduitGrpcSdk, {
import {
ConduitGrpcSdk,
ConduitRouteActions,
ConduitRouteReturnDefinition,
TYPE,
Expand Down
3 changes: 2 additions & 1 deletion modules/authentication/src/admin/service.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import ConduitGrpcSdk, {
import {
ConduitGrpcSdk,
GrpcError,
ParsedRouterRequest,
UnparsedRouterResponse,
Expand Down
3 changes: 2 additions & 1 deletion modules/authentication/src/admin/team.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import ConduitGrpcSdk, {
import {
ConduitGrpcSdk,
ConduitRouteActions,
ConduitRouteReturnDefinition,
GrpcError,
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,4 +1,5 @@
import ConduitGrpcSdk, {
import {
ConduitGrpcSdk,
GrpcError,
Indexable,
ParsedRouterRequest,
Expand Down
3 changes: 2 additions & 1 deletion modules/authentication/src/handlers/biometric.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import ConduitGrpcSdk, {
import {
ConduitGrpcSdk,
ConduitRouteActions,
ConduitRouteReturnDefinition,
GrpcError,
Expand Down
3 changes: 2 additions & 1 deletion modules/authentication/src/handlers/common.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { isNil } from 'lodash-es';
import moment from 'moment';
import ConduitGrpcSdk, {
import {
ConduitGrpcSdk,
ConduitRouteActions,
ConduitRouteReturnDefinition,
GrpcError,
Expand Down
3 changes: 2 additions & 1 deletion modules/authentication/src/handlers/local.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ import { AuthUtils } from '../utils/index.js';
import { TokenType } from '../constants/index.js';
import { v4 as uuid } from 'uuid';
import { Config } from '../config/index.js';
import ConduitGrpcSdk, {
import {
ConduitGrpcSdk,
ConduitRouteActions,
ConduitRouteReturnDefinition,
Email,
Expand Down
3 changes: 2 additions & 1 deletion modules/authentication/src/handlers/magicLink.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { isEmpty, isNil } from 'lodash-es';
import { TokenType } from '../constants/index.js';
import { v4 as uuid } from 'uuid';
import ConduitGrpcSdk, {
import {
ConduitGrpcSdk,
ConduitRouteActions,
ConduitRouteReturnDefinition,
Email,
Expand Down
3 changes: 2 additions & 1 deletion modules/authentication/src/handlers/oauth2/OAuth2.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import ConduitGrpcSdk, {
import {
ConduitGrpcSdk,
ConduitRouteActions,
ConduitRouteReturnDefinition,
GrpcError,
Expand Down
Loading

0 comments on commit 6176ef5

Please sign in to comment.