@things-factory/shell 6.2.84 → 6.2.88

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (74) hide show
  1. package/dist-server/graphql-local-client.d.ts +19 -0
  2. package/dist-server/graphql-local-client.js +14 -0
  3. package/dist-server/graphql-local-client.js.map +1 -1
  4. package/dist-server/initializers/database.d.ts +26 -0
  5. package/dist-server/initializers/database.js +26 -0
  6. package/dist-server/initializers/database.js.map +1 -1
  7. package/dist-server/pubsub-log-transport.d.ts +27 -0
  8. package/dist-server/pubsub-log-transport.js +15 -0
  9. package/dist-server/pubsub-log-transport.js.map +1 -1
  10. package/dist-server/pubsub.d.ts +7 -0
  11. package/dist-server/pubsub.js +12 -0
  12. package/dist-server/pubsub.js.map +1 -1
  13. package/dist-server/schema.d.ts +4 -0
  14. package/dist-server/schema.js +4 -0
  15. package/dist-server/schema.js.map +1 -1
  16. package/dist-server/tsconfig.tsbuildinfo +1 -1
  17. package/dist-server/typeorm/encrypt-transform.d.ts +5 -0
  18. package/dist-server/typeorm/encrypt-transform.js +25 -0
  19. package/dist-server/typeorm/encrypt-transform.js.map +1 -1
  20. package/dist-server/utils/condition-builder.d.ts +11 -0
  21. package/dist-server/utils/condition-builder.js +11 -0
  22. package/dist-server/utils/condition-builder.js.map +1 -1
  23. package/dist-server/utils/get-domain.d.ts +46 -0
  24. package/dist-server/utils/get-domain.js +70 -0
  25. package/dist-server/utils/get-domain.js.map +1 -1
  26. package/dist-server/utils/get-query-builder-from-list-params.d.ts +12 -2
  27. package/dist-server/utils/get-query-builder-from-list-params.js +24 -8
  28. package/dist-server/utils/get-query-builder-from-list-params.js.map +1 -1
  29. package/dist-server/utils/get-times-for-period.d.ts +14 -0
  30. package/dist-server/utils/get-times-for-period.js +14 -0
  31. package/dist-server/utils/get-times-for-period.js.map +1 -1
  32. package/dist-server/utils/list-param-adjuster.d.ts +9 -0
  33. package/dist-server/utils/list-param-adjuster.js +9 -0
  34. package/dist-server/utils/list-param-adjuster.js.map +1 -1
  35. package/dist-server/utils/list-params-converter.d.ts +6 -0
  36. package/dist-server/utils/list-params-converter.js +27 -0
  37. package/dist-server/utils/list-params-converter.js.map +1 -1
  38. package/dist-server/utils/list-query-builder.d.ts +10 -1
  39. package/dist-server/utils/list-query-builder.js +10 -1
  40. package/dist-server/utils/list-query-builder.js.map +1 -1
  41. package/dist-server/utils/publish-progress.d.ts +9 -0
  42. package/dist-server/utils/publish-progress.js +9 -0
  43. package/dist-server/utils/publish-progress.js.map +1 -1
  44. package/package.json +2 -2
  45. package/server/graphql-local-client.ts +20 -0
  46. package/server/initializers/database.ts +26 -0
  47. package/server/pubsub-log-transport.ts +29 -0
  48. package/server/pubsub.ts +13 -0
  49. package/server/schema.ts +4 -0
  50. package/server/typeorm/encrypt-transform.ts +26 -0
  51. package/server/utils/condition-builder.ts +12 -8
  52. package/server/utils/get-domain.ts +70 -0
  53. package/server/utils/get-query-builder-from-list-params.ts +26 -16
  54. package/server/utils/get-times-for-period.ts +15 -4
  55. package/server/utils/list-param-adjuster.ts +9 -0
  56. package/server/utils/list-params-converter.ts +28 -4
  57. package/server/utils/list-query-builder.ts +13 -17
  58. package/server/utils/publish-progress.ts +9 -0
  59. package/dist-server/webpack/koa-webpack/client.d.ts +0 -1
  60. package/dist-server/webpack/koa-webpack/client.js +0 -24
  61. package/dist-server/webpack/koa-webpack/client.js.map +0 -1
  62. package/dist-server/webpack/koa-webpack/index.d.ts +0 -2
  63. package/dist-server/webpack/koa-webpack/index.js +0 -58
  64. package/dist-server/webpack/koa-webpack/index.js.map +0 -1
  65. package/dist-server/webpack/koa-webpack/middleware.d.ts +0 -0
  66. package/dist-server/webpack/koa-webpack/middleware.js +0 -42
  67. package/dist-server/webpack/koa-webpack/middleware.js.map +0 -1
  68. package/dist-server/webpack/koa-webpack/validate.d.ts +0 -1
  69. package/dist-server/webpack/koa-webpack/validate.js +0 -26
  70. package/dist-server/webpack/koa-webpack/validate.js.map +0 -1
  71. package/server/webpack/koa-webpack/client.ts +0 -26
  72. package/server/webpack/koa-webpack/index.ts +0 -71
  73. package/server/webpack/koa-webpack/middleware.ts +0 -47
  74. package/server/webpack/koa-webpack/validate.ts +0 -27
@@ -1,5 +1,24 @@
1
+ /**
2
+ * Apollo Client configuration for a local GraphQL schema.
3
+ * This class provides a static method `init` to initialize the client with a schema and an app context.
4
+ */
1
5
  import { ApolloClient, NormalizedCacheObject } from '@apollo/client';
6
+ /**
7
+ * GraphqlLocalClient is a utility class for initializing an Apollo Client for a local GraphQL schema.
8
+ * It provides a static `init` method for setting up the client with a schema and an app context.
9
+ */
2
10
  export declare class GraphqlLocalClient {
11
+ /**
12
+ * Apollo Client instance for local GraphQL schema.
13
+ * @static
14
+ * @type {ApolloClient<NormalizedCacheObject>}
15
+ */
3
16
  static client: ApolloClient<NormalizedCacheObject>;
17
+ /**
18
+ * Initializes the Apollo Client for a local GraphQL schema.
19
+ * @static
20
+ * @param {object} schema - The GraphQL schema to use.
21
+ * @param {object} app - The application context to be passed in as part of the execution context.
22
+ */
4
23
  static init(schema: any, app: any): void;
5
24
  }
@@ -1,6 +1,10 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.GraphqlLocalClient = void 0;
4
+ /**
5
+ * Apollo Client configuration for a local GraphQL schema.
6
+ * This class provides a static method `init` to initialize the client with a schema and an app context.
7
+ */
4
8
  const client_1 = require("@apollo/client");
5
9
  const schema_1 = require("@apollo/client/link/schema");
6
10
  const defaultOptions = {
@@ -19,7 +23,17 @@ const defaultOptions = {
19
23
  const cache = new client_1.InMemoryCache({
20
24
  addTypename: false
21
25
  });
26
+ /**
27
+ * GraphqlLocalClient is a utility class for initializing an Apollo Client for a local GraphQL schema.
28
+ * It provides a static `init` method for setting up the client with a schema and an app context.
29
+ */
22
30
  class GraphqlLocalClient {
31
+ /**
32
+ * Initializes the Apollo Client for a local GraphQL schema.
33
+ * @static
34
+ * @param {object} schema - The GraphQL schema to use.
35
+ * @param {object} app - The application context to be passed in as part of the execution context.
36
+ */
23
37
  static init(schema, app) {
24
38
  GraphqlLocalClient.client = new client_1.ApolloClient({
25
39
  defaultOptions,
@@ -1 +1 @@
1
- {"version":3,"file":"graphql-local-client.js","sourceRoot":"","sources":["../server/graphql-local-client.ts"],"names":[],"mappings":";;;AAAA,2CAAmF;AACnF,uDAAuD;AAEvD,MAAM,cAAc,GAAQ;IAC1B,UAAU,EAAE;QACV,WAAW,EAAE,UAAU;QACvB,WAAW,EAAE,QAAQ;KACtB;IACD,KAAK,EAAE;QACL,WAAW,EAAE,UAAU;QACvB,WAAW,EAAE,KAAK;KACnB;IACD,MAAM,EAAE;QACN,WAAW,EAAE,KAAK;KACnB;CACF,CAAA;AAED,MAAM,KAAK,GAAG,IAAI,sBAAa,CAAC;IAC9B,WAAW,EAAE,KAAK;CACnB,CAAC,CAAA;AACF,MAAa,kBAAkB;IAG7B,MAAM,CAAC,IAAI,CAAC,MAAM,EAAE,GAAG;QACrB,kBAAkB,CAAC,MAAM,GAAG,IAAI,qBAAY,CAAC;YAC3C,cAAc;YACd,KAAK;YACL,IAAI,EAAE,IAAI,mBAAU,CAAC;gBACnB,MAAM;gBACN,OAAO,EAAE,CAAC,GAAG,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,EAAE;oBACpC,uCACK,GAAG,CAAC,UAAU,EAAE,KACnB,GAAG,IACJ;gBACH,CAAC;aACF,CAAC;SACH,CAAC,CAAA;IACJ,CAAC;CACF;AAlBD,gDAkBC","sourcesContent":["import { ApolloClient, InMemoryCache, NormalizedCacheObject } from '@apollo/client'\nimport { SchemaLink } from '@apollo/client/link/schema'\n\nconst defaultOptions: any = {\n watchQuery: {\n fetchPolicy: 'no-cache',\n errorPolicy: 'ignore'\n },\n query: {\n fetchPolicy: 'no-cache',\n errorPolicy: 'all'\n },\n mutate: {\n errorPolicy: 'all'\n }\n}\n\nconst cache = new InMemoryCache({\n addTypename: false\n})\nexport class GraphqlLocalClient {\n static client: ApolloClient<NormalizedCacheObject>\n\n static init(schema, app) {\n GraphqlLocalClient.client = new ApolloClient({\n defaultOptions,\n cache,\n link: new SchemaLink({\n schema,\n context: (obj, args, context, info) => {\n return {\n ...obj.getContext(),\n app\n }\n }\n })\n })\n }\n}\n"]}
1
+ {"version":3,"file":"graphql-local-client.js","sourceRoot":"","sources":["../server/graphql-local-client.ts"],"names":[],"mappings":";;;AAAA;;;GAGG;AACH,2CAAmF;AACnF,uDAAuD;AAEvD,MAAM,cAAc,GAAQ;IAC1B,UAAU,EAAE;QACV,WAAW,EAAE,UAAU;QACvB,WAAW,EAAE,QAAQ;KACtB;IACD,KAAK,EAAE;QACL,WAAW,EAAE,UAAU;QACvB,WAAW,EAAE,KAAK;KACnB;IACD,MAAM,EAAE;QACN,WAAW,EAAE,KAAK;KACnB;CACF,CAAA;AAED,MAAM,KAAK,GAAG,IAAI,sBAAa,CAAC;IAC9B,WAAW,EAAE,KAAK;CACnB,CAAC,CAAA;AAEF;;;GAGG;AACH,MAAa,kBAAkB;IAQ7B;;;;;OAKG;IACH,MAAM,CAAC,IAAI,CAAC,MAAM,EAAE,GAAG;QACrB,kBAAkB,CAAC,MAAM,GAAG,IAAI,qBAAY,CAAC;YAC3C,cAAc;YACd,KAAK;YACL,IAAI,EAAE,IAAI,mBAAU,CAAC;gBACnB,MAAM;gBACN,OAAO,EAAE,CAAC,GAAG,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,EAAE;oBACpC,uCACK,GAAG,CAAC,UAAU,EAAE,KACnB,GAAG,IACJ;gBACH,CAAC;aACF,CAAC;SACH,CAAC,CAAA;IACJ,CAAC;CACF;AA7BD,gDA6BC","sourcesContent":["/**\n * Apollo Client configuration for a local GraphQL schema.\n * This class provides a static method `init` to initialize the client with a schema and an app context.\n */\nimport { ApolloClient, InMemoryCache, NormalizedCacheObject } from '@apollo/client'\nimport { SchemaLink } from '@apollo/client/link/schema'\n\nconst defaultOptions: any = {\n watchQuery: {\n fetchPolicy: 'no-cache',\n errorPolicy: 'ignore'\n },\n query: {\n fetchPolicy: 'no-cache',\n errorPolicy: 'all'\n },\n mutate: {\n errorPolicy: 'all'\n }\n}\n\nconst cache = new InMemoryCache({\n addTypename: false\n})\n\n/**\n * GraphqlLocalClient is a utility class for initializing an Apollo Client for a local GraphQL schema.\n * It provides a static `init` method for setting up the client with a schema and an app context.\n */\nexport class GraphqlLocalClient {\n /**\n * Apollo Client instance for local GraphQL schema.\n * @static\n * @type {ApolloClient<NormalizedCacheObject>}\n */\n static client: ApolloClient<NormalizedCacheObject>\n\n /**\n * Initializes the Apollo Client for a local GraphQL schema.\n * @static\n * @param {object} schema - The GraphQL schema to use.\n * @param {object} app - The application context to be passed in as part of the execution context.\n */\n static init(schema, app) {\n GraphqlLocalClient.client = new ApolloClient({\n defaultOptions,\n cache,\n link: new SchemaLink({\n schema,\n context: (obj, args, context, info) => {\n return {\n ...obj.getContext(),\n app\n }\n }\n })\n })\n }\n}\n"]}
@@ -1,7 +1,33 @@
1
1
  import { DataSource, EntityTarget, Repository } from 'typeorm';
2
+ /**
3
+ * Returns the specified DataSource by name.
4
+ * @param {string} name - The name of the DataSource.
5
+ * @returns {DataSource} - The DataSource with the specified name.
6
+ */
2
7
  export declare function getDataSource(name?: string): DataSource;
8
+ /**
9
+ * Adds a new DataSource with the specified name.
10
+ * @param {string} name - The name of the DataSource to add.
11
+ * @param {DataSource} dataSource - The DataSource to add.
12
+ */
3
13
  export declare function addDataSource(name: string, dataSource: DataSource): void;
14
+ /**
15
+ * Removes a DataSource with the specified name.
16
+ * @param {string} name - The name of the DataSource to remove.
17
+ */
4
18
  export declare function removeDataSource(name: string): void;
19
+ /**
20
+ * Returns an array of all registered DataSource names.
21
+ * @returns {string[]} - An array of DataSource names.
22
+ */
5
23
  export declare function getDataSourceNames(): string[];
24
+ /**
25
+ * Returns a repository for the specified entity.
26
+ * @param {EntityTarget<X>} target - The target entity for which to get the repository.
27
+ * @returns {Repository<X>} - The repository for the specified entity.
28
+ */
6
29
  export declare function getRepository<X>(target: EntityTarget<X>): Repository<X>;
30
+ /**
31
+ * Initializes the database connections and data sources.
32
+ */
7
33
  export declare const databaseInitializer: () => Promise<void>;
@@ -12,26 +12,52 @@ catch (e) {
12
12
  ormconfig = require('@things-factory/shell/ormconfig');
13
13
  }
14
14
  const dataSources = {};
15
+ /**
16
+ * Returns the specified DataSource by name.
17
+ * @param {string} name - The name of the DataSource.
18
+ * @returns {DataSource} - The DataSource with the specified name.
19
+ */
15
20
  function getDataSource(name) {
16
21
  return dataSources[name || 'default'];
17
22
  }
18
23
  exports.getDataSource = getDataSource;
24
+ /**
25
+ * Adds a new DataSource with the specified name.
26
+ * @param {string} name - The name of the DataSource to add.
27
+ * @param {DataSource} dataSource - The DataSource to add.
28
+ */
19
29
  function addDataSource(name, dataSource) {
20
30
  dataSources[name] = dataSource;
21
31
  }
22
32
  exports.addDataSource = addDataSource;
33
+ /**
34
+ * Removes a DataSource with the specified name.
35
+ * @param {string} name - The name of the DataSource to remove.
36
+ */
23
37
  function removeDataSource(name) {
24
38
  delete dataSources[name];
25
39
  }
26
40
  exports.removeDataSource = removeDataSource;
41
+ /**
42
+ * Returns an array of all registered DataSource names.
43
+ * @returns {string[]} - An array of DataSource names.
44
+ */
27
45
  function getDataSourceNames() {
28
46
  return Object.keys(dataSources);
29
47
  }
30
48
  exports.getDataSourceNames = getDataSourceNames;
49
+ /**
50
+ * Returns a repository for the specified entity.
51
+ * @param {EntityTarget<X>} target - The target entity for which to get the repository.
52
+ * @returns {Repository<X>} - The repository for the specified entity.
53
+ */
31
54
  function getRepository(target) {
32
55
  return getDataSource('default').getRepository(target);
33
56
  }
34
57
  exports.getRepository = getRepository;
58
+ /**
59
+ * Initializes the database connections and data sources.
60
+ */
35
61
  const databaseInitializer = async () => {
36
62
  try {
37
63
  const readConnectionConfig = env_1.config.get('ormconfig');
@@ -1 +1 @@
1
- {"version":3,"file":"database.js","sourceRoot":"","sources":["../../server/initializ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E7C,IAAI,oBAAoB,CAAC,IAAI,IAAI,QAAQ,IAAI,oBAAoB,CAAC,WAAW,IAAI,KAAK,EAAE;YACtF,MAAM,UAAU,CAAC,KAAK,CAAC,yBAAyB,CAAC,CAAA;YACjD,MAAM,UAAU,CAAC,WAAW,EAAE,CAAA;YAC9B,MAAM,UAAU,CAAC,KAAK,CAAC,wBAAwB,CAAC,CAAA;SACjD;QAED,IAAI,YAAM,CAAC,GAAG,CAAC,cAAc,CAAC,EAAE;YAC9B,MAAM,aAAa,GAAG,IAAI,oBAAU,iCAC/B,SAAS,GACT,YAAM,CAAC,GAAG,CAAC,cAAc,CAAC,EAC7B,CAAA;YACF,MAAM,aAAa,CAAC,UAAU,EAAE,CAAA;YAChC,aAAa,CAAC,IAAI,EAAE,aAAa,CAAC,CAAA;YAElC,YAAM,CAAC,IAAI,CAAC,oCAAoC,CAAC,CAAA;SAClD;aAAM;YACL,aAAa,CAAC,IAAI,EAAE,UAAU,CAAC,CAAA;SAChC;KACF;IAAC,OAAO,CAAC,EAAE;QACV,YAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAA;KAChB;AACH,CAAC,CAAA;AAlCY,QAAA,mBAAmB,uBAkC/B","sourcesContent":["import { createConnection, DataSource, EntityTarget, Repository } from 'typeorm'\n\nimport { appRootPath, config, logger } from '@things-factory/env'\n\nconst path = require('path')\n\nvar ormconfig\ntry {\n ormconfig = require(path.resolve(appRootPath, 'ormconfig'))\n} catch (e) {\n ormconfig = require('@things-factory/shell/ormconfig')\n}\n\nconst dataSources: { [name: string]: DataSource } = {}\n\nexport function getDataSource(name?: string): DataSource {\n return dataSources[name || 'default']\n}\n\nexport function addDataSource(name: string, dataSource: DataSource) {\n dataSources[name] = dataSource\n}\n\nexport function removeDataSource(name: string) {\n delete dataSources[name]\n}\n\nexport function getDataSourceNames() {\n return Object.keys(dataSources)\n}\n\nexport function getRepository<X>(target: EntityTarget<X>): Repository<X> {\n return getDataSource('default').getRepository<X>(target)\n}\n\nexport const databaseInitializer = async () => {\n try {\n const readConnectionConfig = config.get('ormconfig')\n\n const dataSource = await createConnection({\n ...ormconfig,\n ...readConnectionConfig\n })\n\n addDataSource('default', dataSource)\n\n logger.info('Default DataSource established')\n\n if (readConnectionConfig.type == 'sqlite' && readConnectionConfig.synchronize == false) {\n await dataSource.query('PRAGMA foreign_keys=OFF')\n await dataSource.synchronize()\n await dataSource.query('PRAGMA foreign_keys=ON')\n }\n\n if (config.get('ormconfig4Tx')) {\n const dataSource4Tx = new DataSource({\n ...ormconfig,\n ...config.get('ormconfig4Tx')\n })\n await dataSource4Tx.initialize()\n addDataSource('tx', dataSource4Tx)\n\n logger.info('Transaction DataSource established')\n } else {\n addDataSource('tx', dataSource)\n }\n } catch (e) {\n logger.error(e)\n }\n}\n"]}
1
+ {"version":3,"file":"database.js","sourceRoot":"","sources":["../../server/initializers/database.ts"],"names":[],"mappings":";;;AAAA,qCAAgF;AAEhF,6CAAiE;AAEjE,MAAM,IAAI,GAAG,OAAO,CAAC,MAAM,CAAC,CAAA;AAE5B,IAAI,SAAS,CAAA;AACb,IAAI;IACF,SAAS,GAAG,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,iBAAW,EAAE,WAAW,CAAC,CAAC,CAAA;CAC5D;AAAC,OAAO,CAAC,EAAE;IACV,SAAS,GAAG,OAAO,CAAC,iCAAiC,CAAC,CAAA;CACvD;AAED,MAAM,WAAW,GAAmC,EAAE,CAAA;AAEtD;;;;GAIG;AACH,SAAgB,aAAa,CAAC,IAAa;IACzC,OAAO,WAAW,CAAC,IAAI,IAAI,SAAS,CAAC,CAAA;AACvC,CAAC;AAFD,sCAEC;AAED;;;;GAIG;AACH,SAAgB,aAAa,CAAC,IAAY,EAAE,UAAsB;IAChE,WAAW,CAAC,IAAI,CAAC,GAAG,UAAU,CAAA;AAChC,CAAC;AAFD,sCAEC;AAED;;;GAGG;AACH,SAAgB,gBAAgB,CAAC,IAAY;IAC3C,OAAO,WAAW,CAAC,IAAI,CAAC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F;IAAC,OAAO,CAAC,EAAE;QACV,YAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAA;KAChB;AACH,CAAC,CAAA;AAlCY,QAAA,mBAAmB,uBAkC/B","sourcesContent":["import { createConnection, DataSource, EntityTarget, Repository } from 'typeorm'\n\nimport { appRootPath, config, logger } from '@things-factory/env'\n\nconst path = require('path')\n\nvar ormconfig\ntry {\n ormconfig = require(path.resolve(appRootPath, 'ormconfig'))\n} catch (e) {\n ormconfig = require('@things-factory/shell/ormconfig')\n}\n\nconst dataSources: { [name: string]: DataSource } = {}\n\n/**\n * Returns the specified DataSource by name.\n * @param {string} name - The name of the DataSource.\n * @returns {DataSource} - The DataSource with the specified name.\n */\nexport function getDataSource(name?: string): DataSource {\n return dataSources[name || 'default']\n}\n\n/**\n * Adds a new DataSource with the specified name.\n * @param {string} name - The name of the DataSource to add.\n * @param {DataSource} dataSource - The DataSource to add.\n */\nexport function addDataSource(name: string, dataSource: DataSource) {\n dataSources[name] = dataSource\n}\n\n/**\n * Removes a DataSource with the specified name.\n * @param {string} name - The name of the DataSource to remove.\n */\nexport function removeDataSource(name: string) {\n delete dataSources[name]\n}\n\n/**\n * Returns an array of all registered DataSource names.\n * @returns {string[]} - An array of DataSource names.\n */\nexport function getDataSourceNames() {\n return Object.keys(dataSources)\n}\n\n/**\n * Returns a repository for the specified entity.\n * @param {EntityTarget<X>} target - The target entity for which to get the repository.\n * @returns {Repository<X>} - The repository for the specified entity.\n */\nexport function getRepository<X>(target: EntityTarget<X>): Repository<X> {\n return getDataSource('default').getRepository<X>(target)\n}\n\n/**\n * Initializes the database connections and data sources.\n */\nexport const databaseInitializer = async () => {\n try {\n const readConnectionConfig = config.get('ormconfig')\n\n const dataSource = await createConnection({\n ...ormconfig,\n ...readConnectionConfig\n })\n\n addDataSource('default', dataSource)\n\n logger.info('Default DataSource established')\n\n if (readConnectionConfig.type == 'sqlite' && readConnectionConfig.synchronize == false) {\n await dataSource.query('PRAGMA foreign_keys=OFF')\n await dataSource.synchronize()\n await dataSource.query('PRAGMA foreign_keys=ON')\n }\n\n if (config.get('ormconfig4Tx')) {\n const dataSource4Tx = new DataSource({\n ...ormconfig,\n ...config.get('ormconfig4Tx')\n })\n await dataSource4Tx.initialize()\n addDataSource('tx', dataSource4Tx)\n\n logger.info('Transaction DataSource established')\n } else {\n addDataSource('tx', dataSource)\n }\n } catch (e) {\n logger.error(e)\n }\n}\n"]}
@@ -1,8 +1,35 @@
1
1
  import Transport from 'winston-transport';
2
+ /**
3
+ * PubSubLogTransport is a custom Winston transport that publishes log messages to a GraphQL Pub/Sub topic.
4
+ */
2
5
  export declare class PubSubLogTransport extends Transport {
6
+ /**
7
+ * The source object providing the log messages.
8
+ * @type {object}
9
+ */
3
10
  source: object;
11
+ /**
12
+ * The Pub/Sub topic to which log messages will be published.
13
+ * @type {string}
14
+ */
4
15
  topic: string;
16
+ /**
17
+ * The name of the field resolver for log messages.
18
+ * @type {string}
19
+ */
5
20
  resolver: string;
21
+ /**
22
+ * Creates an instance of PubSubLogTransport.
23
+ * @param {object} opts - Options for configuring the transport.
24
+ * @param {string} opts.topic - The Pub/Sub topic to which log messages will be published.
25
+ * @param {object} opts.source - The source object providing the log messages.
26
+ * @param {string} opts.resolver - The name of the field resolver for log messages (default: derived from the topic).
27
+ */
6
28
  constructor(opts: any);
29
+ /**
30
+ * Publishes a log message to the configured Pub/Sub topic.
31
+ * @param {object} info - The log message information.
32
+ * @param {Function} callback - The callback function to be called after publishing the message.
33
+ */
7
34
  log(info: any, callback: any): void;
8
35
  }
@@ -5,13 +5,28 @@ const tslib_1 = require("tslib");
5
5
  const camelCase_1 = tslib_1.__importDefault(require("lodash/camelCase"));
6
6
  const winston_transport_1 = tslib_1.__importDefault(require("winston-transport"));
7
7
  const pubsub_1 = require("./pubsub");
8
+ /**
9
+ * PubSubLogTransport is a custom Winston transport that publishes log messages to a GraphQL Pub/Sub topic.
10
+ */
8
11
  class PubSubLogTransport extends winston_transport_1.default {
12
+ /**
13
+ * Creates an instance of PubSubLogTransport.
14
+ * @param {object} opts - Options for configuring the transport.
15
+ * @param {string} opts.topic - The Pub/Sub topic to which log messages will be published.
16
+ * @param {object} opts.source - The source object providing the log messages.
17
+ * @param {string} opts.resolver - The name of the field resolver for log messages (default: derived from the topic).
18
+ */
9
19
  constructor(opts) {
10
20
  super(opts);
11
21
  this.topic = opts.topic;
12
22
  this.source = opts.source;
13
23
  this.resolver = opts.resolver || (0, camelCase_1.default)(this.topic);
14
24
  }
25
+ /**
26
+ * Publishes a log message to the configured Pub/Sub topic.
27
+ * @param {object} info - The log message information.
28
+ * @param {Function} callback - The callback function to be called after publishing the message.
29
+ */
15
30
  log(info, callback) {
16
31
  setImmediate(() => {
17
32
  pubsub_1.pubsub.publish(this.topic, {
@@ -1 +1 @@
1
- {"version":3,"file":"pubsub-log-transport.js","sourceRoot":"","sources":["../server/pubsub-log-transport.ts"],"names":[],"mappings":";;;;AAAA,yEAAwC;AACxC,kFAAyC;AACzC,qCAAiC;AAEjC,MAAa,kBAAmB,SAAQ,2BAAS;IAK/C,YAAY,IAAI;QACd,KAAK,CAAC,IAAI,CAAC,CAAA;QAEX,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC,KAAK,CAAA;QACvB,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,MAAM,CAAA;QACzB,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAC,QAAQ,IAAI,IAAA,mBAAS,EAAC,IAAI,CAAC,KAAK,CAAC,CAAA;IACxD,CAAC;IAED,GAAG,CAAC,IAAI,EAAE,QAAQ;QAChB,YAAY,CAAC,GAAG,EAAE;YAChB,eAAM,CAAC,OAAO,CAAC,IAAI,CAAC,KAAK,EAAE;gBACzB,CAAC,IAAI,CAAC,QAAQ,CAAC,kBACb,MAAM,EAAE,IAAI,CAAC,MAAM,IAChB,IAAI,CACR;aACF,CAAC,CAAA;QACJ,CAAC,CAAC,CAAA;QAEF,QAAQ,EAAE,CAAA;IACZ,CAAC;CACF;AAzBD,gDAyBC","sourcesContent":["import camelCase from 'lodash/camelCase'\nimport Transport from 'winston-transport'\nimport { pubsub } from './pubsub'\n\nexport class PubSubLogTransport extends Transport {\n source: object\n topic: string\n resolver: string /* field resolver name */\n\n constructor(opts) {\n super(opts)\n\n this.topic = opts.topic\n this.source = opts.source\n this.resolver = opts.resolver || camelCase(this.topic)\n }\n\n log(info, callback) {\n setImmediate(() => {\n pubsub.publish(this.topic, {\n [this.resolver]: {\n source: this.source,\n ...info\n }\n })\n })\n\n callback()\n }\n}\n"]}
1
+ {"version":3,"file":"pubsub-log-transport.js","sourceRoot":"","sources":["../server/pubsub-log-transport.ts"],"names":[],"mappings":";;;;AAAA,yEAAwC;AACxC,kFAAyC;AACzC,qCAAiC;AAEjC;;GAEG;AACH,MAAa,kBAAmB,SAAQ,2BAAS;IAmB/C;;;;;;OAMG;IACH,YAAY,IAAI;QACd,KAAK,CAAC,IAAI,CAAC,CAAA;QAEX,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC,KAAK,CAAA;QACvB,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,MAAM,CAAA;QACzB,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAC,QAAQ,IAAI,IAAA,mBAAS,EAAC,IAAI,CAAC,KAAK,CAAC,CAAA;IACxD,CAAC;IAED;;;;OAIG;IACH,GAAG,CAAC,IAAI,EAAE,QAAQ;QAChB,YAAY,CAAC,GAAG,EAAE;YAChB,eAAM,CAAC,OAAO,CAAC,IAAI,CAAC,KAAK,EAAE;gBACzB,CAAC,IAAI,CAAC,QAAQ,CAAC,kBACb,MAAM,EAAE,IAAI,CAAC,MAAM,IAChB,IAAI,CACR;aACF,CAAC,CAAA;QACJ,CAAC,CAAC,CAAA;QAEF,QAAQ,EAAE,CAAA;IACZ,CAAC;CACF;AAnDD,gDAmDC","sourcesContent":["import camelCase from 'lodash/camelCase'\nimport Transport from 'winston-transport'\nimport { pubsub } from './pubsub'\n\n/**\n * PubSubLogTransport is a custom Winston transport that publishes log messages to a GraphQL Pub/Sub topic.\n */\nexport class PubSubLogTransport extends Transport {\n /**\n * The source object providing the log messages.\n * @type {object}\n */\n source: object\n\n /**\n * The Pub/Sub topic to which log messages will be published.\n * @type {string}\n */\n topic: string\n\n /**\n * The name of the field resolver for log messages.\n * @type {string}\n */\n resolver: string /* field resolver name */\n\n /**\n * Creates an instance of PubSubLogTransport.\n * @param {object} opts - Options for configuring the transport.\n * @param {string} opts.topic - The Pub/Sub topic to which log messages will be published.\n * @param {object} opts.source - The source object providing the log messages.\n * @param {string} opts.resolver - The name of the field resolver for log messages (default: derived from the topic).\n */\n constructor(opts) {\n super(opts)\n\n this.topic = opts.topic\n this.source = opts.source\n this.resolver = opts.resolver || camelCase(this.topic)\n }\n\n /**\n * Publishes a log message to the configured Pub/Sub topic.\n * @param {object} info - The log message information.\n * @param {Function} callback - The callback function to be called after publishing the message.\n */\n log(info, callback) {\n setImmediate(() => {\n pubsub.publish(this.topic, {\n [this.resolver]: {\n source: this.source,\n ...info\n }\n })\n })\n\n callback()\n }\n}\n"]}
@@ -1,2 +1,9 @@
1
+ /**
2
+ * @module pubsub
3
+ * @description
4
+ * This module provides a Pub/Sub (Publish/Subscribe) mechanism for handling messages and events.
5
+ * Developers can use various middleware options such as MQTT, Redis, Redis Cluster, or Kafka
6
+ * to implement Pub/Sub functionality.
7
+ */
1
8
  declare let pubsub: any;
2
9
  export { pubsub };
@@ -1,4 +1,11 @@
1
1
  "use strict";
2
+ /**
3
+ * @module pubsub
4
+ * @description
5
+ * This module provides a Pub/Sub (Publish/Subscribe) mechanism for handling messages and events.
6
+ * Developers can use various middleware options such as MQTT, Redis, Redis Cluster, or Kafka
7
+ * to implement Pub/Sub functionality.
8
+ */
2
9
  Object.defineProperty(exports, "__esModule", { value: true });
3
10
  exports.pubsub = void 0;
4
11
  const tslib_1 = require("tslib");
@@ -13,6 +20,7 @@ let pubsub;
13
20
  exports.pubsub = pubsub;
14
21
  switch (middleware) {
15
22
  case 'mqtt':
23
+ //@ts-ignore
16
24
  exports.pubsub = pubsub = new graphql_mqtt_subscriptions_1.MQTTPubSub({
17
25
  client: (0, mqtt_1.connect)('mqtt://' + host, Object.assign({ reconnectPeriod: 1000 }, options))
18
26
  });
@@ -23,6 +31,7 @@ switch (middleware) {
23
31
  // reconnect after
24
32
  return Math.min(times * 50, 2000);
25
33
  } }, options);
34
+ //@ts-ignore
26
35
  exports.pubsub = pubsub = new graphql_redis_subscriptions_1.RedisPubSub({
27
36
  publisher: new ioredis_1.default(redisOption),
28
37
  subscriber: new ioredis_1.default(redisOption)
@@ -30,6 +39,7 @@ switch (middleware) {
30
39
  break;
31
40
  case 'redisCluster':
32
41
  const cluster = new ioredis_1.default.Cluster(nodes, options);
42
+ //@ts-ignore
33
43
  exports.pubsub = pubsub = new graphql_redis_subscriptions_1.RedisPubSub({
34
44
  publisher: cluster,
35
45
  subscriber: cluster
@@ -56,8 +66,10 @@ switch (middleware) {
56
66
  }
57
67
  // kafka pubsub keeps connection and app port with 'ctrl+c' termination.
58
68
  const exitHandler = async (evt) => {
69
+ //@ts-ignore
59
70
  if (pubsub.close) {
60
71
  try {
72
+ //@ts-ignore
61
73
  await pubsub.close();
62
74
  }
63
75
  catch (err) {
@@ -1 +1 @@
1
- {"version":3,"file":"pubsub.js","sourceRoot":"","sources":["../server/pubsub.ts"],"names":[],"mappings":";;;;AAAA,2EAAuD;AACvD,6EAAyD;AACzD,iEAA8C;AAC9C,8DAA2B;AAC3B,+BAA8B;AAE9B,6CAAoD;AAEpD,MAAM,EAAE,UAAU,EAAE,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,KAAK,EAAE,OAAO,EAAE,GAAG,YAAM,CAAC,GAAG,CAAC,QAAQ,EAAE,EAAE,CAAC,CAAA;AAElF,IAAI,MAAW,CAAA;AAmFN,wBAAM;AAjFf,QAAQ,UAAU,EAAE;IAClB,KAAK,MAAM;QACT,iBAAA,MAAM,GAAG,IAAI,uCAAU,CAAC;YACtB,MAAM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AChB,IAAI;YACF,MAAM,MAAM,CAAC,KAAK,EAAE,CAAA;SACrB;QAAC,OAAO,GAAG,EAAE;YACZ,YAAM,CAAC,KAAK,CAAC,GAAG,CAAC,CAAA;SAClB;KACF;AACH,CAAC,CAAA;AAED;;GAEG;AAEH,kCAAkC;AAClC,OAAO,CAAC,EAAE,CAAC,MAAM,EAAE,WAAW,CAAC,IAAI,CAAC,IAAI,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC,CAAC,CAAA;AAExE,sBAAsB;AACtB,OAAO,CAAC,EAAE,CAAC,QAAQ,EAAE,WAAW,CAAC,IAAI,CAAC,IAAI,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC,CAAC,CAAA;AAE5E,oDAAoD;AACpD,OAAO,CAAC,EAAE,CAAC,SAAS,EAAE,WAAW,CAAC,IAAI,CAAC,IAAI,EAAE,EAAE,IAAI,EAAE,SAAS,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC,CAAC,CAAA;AAC9E,OAAO,CAAC,EAAE,CAAC,SAAS,EAAE,WAAW,CAAC,IAAI,CAAC,IAAI,EAAE,EAAE,IAAI,EAAE,SAAS,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC,CAAC,CAAA","sourcesContent":["import { MQTTPubSub } from 'graphql-mqtt-subscriptions'\nimport { RedisPubSub } from 'graphql-redis-subscriptions'\nimport { PubSub } from 'graphql-subscriptions'\nimport Redis from 'ioredis'\nimport { connect } from 'mqtt'\n\nimport { config, logger } from '@things-factory/env'\n\nconst { middleware, host, port, nodes, topic, options } = config.get('pubsub', {})\n\nlet pubsub: any\n\nswitch (middleware) {\n case 'mqtt':\n pubsub = new MQTTPubSub({\n client: connect('mqtt://' + host, {\n reconnectPeriod: 1000,\n ...options\n }) as any\n })\n break\n case 'redis':\n const redisOption = {\n host,\n port,\n retryStrategy: times => {\n // reconnect after\n return Math.min(times * 50, 2000)\n },\n ...options\n }\n pubsub = new RedisPubSub({\n publisher: new Redis(redisOption),\n subscriber: new Redis(redisOption)\n })\n break\n case 'redisCluster':\n const cluster = new Redis.Cluster(nodes, options)\n pubsub = new RedisPubSub({\n publisher: cluster,\n subscriber: cluster\n })\n break\n case 'kafka':\n try {\n /*\n * https://github.com/hatiolab/things-factory/issues/1239\n */\n const { KafkaPubSub } = require('graphql-kafka-subscriptions')\n pubsub = new KafkaPubSub({\n topic,\n host,\n port,\n ...options\n })\n } catch (e) {\n logger.error('graphql-kafka-subscriptions module is not installed, so application can not go further.')\n throw e\n }\n break\n default:\n pubsub = new PubSub()\n break\n}\n\n// kafka pubsub keeps connection and app port with 'ctrl+c' termination.\nconst exitHandler = async evt => {\n if (pubsub.close) {\n try {\n await pubsub.close()\n } catch (err) {\n logger.error(err)\n }\n }\n}\n\n/*\n * exit events hint from https://stackoverflow.com/a/14032965/14539284\n */\n\n//do something when app is closing\nprocess.on('exit', exitHandler.bind(null, { name: 'exit', exit: true }))\n\n//catches ctrl+c event\nprocess.on('SIGINT', exitHandler.bind(null, { name: 'SIGINT', exit: true }))\n\n// catches \"kill pid\" (for example: nodemon restart)\nprocess.on('SIGUSR1', exitHandler.bind(null, { name: 'SIGUSR1', exit: true }))\nprocess.on('SIGUSR2', exitHandler.bind(null, { name: 'SIGUSR2', exit: true }))\n\n//catches uncaught exceptions\n// process.on('uncaughtException', exitHandler.bind(null, { name: 'uncaughtException', exit: true }))\n\nexport { pubsub }\n"]}
1
+ {"version":3,"file":"pubsub.js","sourceRoot":"","sources":["../server/pubsub.ts"],"names":[],"mappings":";AAAA;;;;;;GAMG;;;;AAEH,2EAAuD;AACvD,6EAAyD;AACzD,iEAA8C;AAC9C,8DAA2B;AAC3B,+BAA8B;AAE9B,6CAAoD;AAEpD,MAAM,EAAE,UAAU,EAAE,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,KAAK,EAAE,OAAO,EAAE,GAAG,YAAM,CAAC,GAAG,CAAC,QAAQ,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AAA;SACR;QACD,MAAK;IACP;QACE,iBAAA,MAAM,GAAG,IAAI,8BAAM,EAAE,CAAA;QACrB,MAAK;CACR;AAED,wEAAwE;AACxE,MAAM,WAAW,GAAG,KAAK,EAAC,GAAG,EAAC,EAAE;IAC9B,YAAY;IACZ,IAAI,MAAM,CAAC,KAAK,EAAE;QAChB,IAAI;YACF,YAAY;YACZ,MAAM,MAAM,CAAC,KAAK,EAAE,CAAA;SACrB;QAAC,OAAO,GAAG,EAAE;YACZ,YAAM,CAAC,KAAK,CAAC,GAAG,CAAC,CAAA;SAClB;KACF;AACH,CAAC,CAAA;AAED;;GAEG;AAEH,kCAAkC;AAClC,OAAO,CAAC,EAAE,CAAC,MAAM,EAAE,WAAW,CAAC,IAAI,CAAC,IAAI,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC,CAAC,CAAA;AAExE,sBAAsB;AACtB,OAAO,CAAC,EAAE,CAAC,QAAQ,EAAE,WAAW,CAAC,IAAI,CAAC,IAAI,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC,CAAC,CAAA;AAE5E,oDAAoD;AACpD,OAAO,CAAC,EAAE,CAAC,SAAS,EAAE,WAAW,CAAC,IAAI,CAAC,IAAI,EAAE,EAAE,IAAI,EAAE,SAAS,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC,CAAC,CAAA;AAC9E,OAAO,CAAC,EAAE,CAAC,SAAS,EAAE,WAAW,CAAC,IAAI,CAAC,IAAI,EAAE,EAAE,IAAI,EAAE,SAAS,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC,CAAC,CAAA","sourcesContent":["/**\n * @module pubsub\n * @description\n * This module provides a Pub/Sub (Publish/Subscribe) mechanism for handling messages and events.\n * Developers can use various middleware options such as MQTT, Redis, Redis Cluster, or Kafka\n * to implement Pub/Sub functionality.\n */\n\nimport { MQTTPubSub } from 'graphql-mqtt-subscriptions'\nimport { RedisPubSub } from 'graphql-redis-subscriptions'\nimport { PubSub } from 'graphql-subscriptions'\nimport Redis from 'ioredis'\nimport { connect } from 'mqtt'\n\nimport { config, logger } from '@things-factory/env'\n\nconst { middleware, host, port, nodes, topic, options } = config.get('pubsub', {})\n\nlet pubsub: any\n\nswitch (middleware) {\n case 'mqtt':\n //@ts-ignore\n pubsub = new MQTTPubSub({\n client: connect('mqtt://' + host, {\n reconnectPeriod: 1000,\n ...options\n }) as any\n })\n break\n case 'redis':\n const redisOption = {\n host,\n port,\n retryStrategy: times => {\n // reconnect after\n return Math.min(times * 50, 2000)\n },\n ...options\n }\n //@ts-ignore\n pubsub = new RedisPubSub({\n publisher: new Redis(redisOption),\n subscriber: new Redis(redisOption)\n })\n break\n case 'redisCluster':\n const cluster = new Redis.Cluster(nodes, options)\n //@ts-ignore\n pubsub = new RedisPubSub({\n publisher: cluster,\n subscriber: cluster\n })\n break\n case 'kafka':\n try {\n /*\n * https://github.com/hatiolab/things-factory/issues/1239\n */\n const { KafkaPubSub } = require('graphql-kafka-subscriptions')\n pubsub = new KafkaPubSub({\n topic,\n host,\n port,\n ...options\n })\n } catch (e) {\n logger.error('graphql-kafka-subscriptions module is not installed, so application can not go further.')\n throw e\n }\n break\n default:\n pubsub = new PubSub()\n break\n}\n\n// kafka pubsub keeps connection and app port with 'ctrl+c' termination.\nconst exitHandler = async evt => {\n //@ts-ignore\n if (pubsub.close) {\n try {\n //@ts-ignore\n await pubsub.close()\n } catch (err) {\n logger.error(err)\n }\n }\n}\n\n/*\n * exit events hint from https://stackoverflow.com/a/14032965/14539284\n */\n\n//do something when app is closing\nprocess.on('exit', exitHandler.bind(null, { name: 'exit', exit: true }))\n\n//catches ctrl+c event\nprocess.on('SIGINT', exitHandler.bind(null, { name: 'SIGINT', exit: true }))\n\n// catches \"kill pid\" (for example: nodemon restart)\nprocess.on('SIGUSR1', exitHandler.bind(null, { name: 'SIGUSR1', exit: true }))\nprocess.on('SIGUSR2', exitHandler.bind(null, { name: 'SIGUSR2', exit: true }))\n\n//catches uncaught exceptions\n// process.on('uncaughtException', exitHandler.bind(null, { name: 'uncaughtException', exit: true }))\n\nexport { pubsub }\n"]}
@@ -1,2 +1,6 @@
1
1
  import { GraphQLSchema } from 'graphql';
2
+ /**
3
+ * Generates and returns a GraphQL schema by merging schemas and resolvers from various modules.
4
+ * @returns {GraphQLSchema} The merged GraphQL schema.
5
+ */
2
6
  export declare function schema(): Promise<GraphQLSchema>;
@@ -8,6 +8,10 @@ const schema_1 = require("@graphql-tools/schema");
8
8
  const env_1 = require("@things-factory/env");
9
9
  const utils_1 = require("@things-factory/utils");
10
10
  const path = require('path');
11
+ /**
12
+ * Generates and returns a GraphQL schema by merging schemas and resolvers from various modules.
13
+ * @returns {GraphQLSchema} The merged GraphQL schema.
14
+ */
11
15
  async function schema() {
12
16
  const schemas = env_1.orderedModuleNames
13
17
  .map(dep => (0, env_1.loader)(dep).schema)
@@ -1 +1 @@
1
- {"version":3,"file":"schema.js","sourceRoot":"","sources":["../server/schema.ts"],"names":[],"mappings":";;;AACA,sEAA+D;AAC/D,+CAA0C;AAC1C,qDAA0F;AAE1F,kDAAoD;AACpD,6CAAgE;AAChE,iDAAiD;AAEjD,MAAM,IAAI,GAAG,OAAO,CAAC,MAAM,CAAC,CAAA;AAErB,KAAK,UAAU,MAAM;IAC1B,MAAM,OAAO,GAAG,wBAAkB;SAC/B,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC,IAAA,YAAM,EAAC,GAAG,CAAC,CAAC,MAAM,CAAC;SAC9B,MAAM,CAAC,MAAM,CAAC,EAAE,CAAC,MAAM,CAAC;SACxB,MAAM,CACL,CAAC,GAAG,EAAE,MAAM,EAAE,EAAE;QACd,MAAM,EAAE,QAAQ,EAAE,SAAS,EAAE,eAAe,EAAE,UAAU,EAAE,GAAG,GAAG,CAAA;QAChE,IAAI,EACF,QAAQ,EAAE,SAAS,GAAG,EAAE,EACxB,SAAS,EAAE,UAAU,GAAG,EAAE,EAC1B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tB,OAAO,SAAS,CAAC,QAAQ,CAAA;IACzB,OAAO,SAAS,CAAC,YAAY,CAAA;IAC7B,OAAO,SAAS,CAAC,SAAS,CAAA;IAE1B,SAAS,iCACP,MAAM,EAAE,gCAAoB,EAC5B,KAAK,EAAE,IAAA,iBAAS,EAAC,KAAK,EAAE,cAAc,CAAC,EACvC,QAAQ,EAAE,IAAA,iBAAS,EAAC,QAAQ,EAAE,iBAAiB,CAAC,EAChD,YAAY,EAAE,IAAA,iBAAS,EAAC,YAAY,EAAE,qBAAqB,CAAC,IACzD,2BAAe,GACf,SAAS,CACb,CAAA;IAED,IAAI,MAAM,GAAG,IAAA,qBAAY,EAAC;QACxB,OAAO,EAAE;YACP,MAAM,IAAA,0BAAW,EAAC;gBAChB,SAAS,EAAE,OAAO,CAAC,eAAe;gBAClC,gEAAgE;gBAChE,iCAAiC;gBACjC,kDAAkD;gBAClD,cAAc,EAAE,OAAO,CAAC,GAAG,CAAC,QAAQ,IAAI,aAAa;gBACrD,4EAA4E;aAC7E,CAAC;SACH;QACD,QAAQ;QACR,SAAS;KACV,CAAC,CAAA;IAEF,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC,GAAG,CAAC,CAAC,SAAwC,EAAE,EAAE;QACjF,MAAM,GAAG,SAAS,CAAC,MAAM,CAAQ,CAAA;IACnC,CAAC,CAAC,CAAA;IAEF,OAAO,MAAM,CAAA;AACf,CAAC;AA1JD,wBA0JC","sourcesContent":["import { GraphQLSchema } from 'graphql'\nimport { GraphQLUpload } from 'graphql-upload/GraphQLUpload.js'\nimport { buildSchema } from 'type-graphql'\nimport { typeDefs as scalarTypeDefs, resolvers as scalarResolvers } from 'graphql-scalars'\n\nimport { mergeSchemas } from '@graphql-tools/schema'\nimport { loader, orderedModuleNames } from '@things-factory/env'\nimport { deepMerge } from '@things-factory/utils'\n\nconst path = require('path')\n\nexport async function schema() {\n const schemas = orderedModuleNames\n .map(dep => loader(dep).schema)\n .filter(schema => schema)\n .reduce(\n (sum, schema) => {\n const { typeDefs, resolvers, resolverClasses, directives } = sum\n let {\n typeDefs: sTypeDefs = {},\n resolvers: sResolvers = {},\n resolverClasses: sResolverClasses = [],\n directives: sDirectives = {}\n } = schema\n\n return {\n typeDefs: deepMerge(typeDefs, sTypeDefs),\n resolvers: deepMerge(resolvers, sResolvers),\n resolverClasses: [...resolverClasses, ...(sResolverClasses || [])],\n directives: deepMerge(directives, sDirectives)\n }\n },\n {\n typeDefs: {},\n resolvers: {},\n resolverClasses: [],\n directives: {}\n }\n )\n\n /* for typeDefs */\n var typeDefs = schemas.typeDefs\n var { queries = [], mutations = [], subscriptions = [], directives = [], types = [] } = typeDefs\n\n queries = [...queries, ...(typeDefs.Query || [])]\n mutations = [...mutations, ...(typeDefs.Mutation || [])]\n subscriptions = [...subscriptions, ...(typeDefs.Subscription || [])]\n directives = [...directives, ...(typeDefs.Directive || [])]\n\n delete typeDefs.Query\n delete typeDefs.Mutation\n delete typeDefs.Subscription\n delete typeDefs.Directive\n\n delete typeDefs.queries\n delete typeDefs.mutations\n delete typeDefs.subscriptions\n delete typeDefs.directives\n delete typeDefs.types\n\n const defs = {\n query: queries.length > 0 ? ['type Query {', ...queries, '}'].join('\\n') : 'type Query { _ : Boolean }',\n mutation:\n mutations.length > 0 ? ['type Mutation {', ...mutations, '}'].join('\\n') : 'type Mutation { _ : Boolean }',\n subscription:\n subscriptions.length > 0\n ? ['type Subscription {', ...subscriptions, '}'].join('\\n')\n : 'type Subscription { _ : Boolean }'\n }\n\n typeDefs = [\n ...scalarTypeDefs,\n `\n scalar Upload\n `,\n defs.query,\n defs.mutation,\n defs.subscription,\n ...directives,\n ...types,\n ...Object.values(typeDefs)\n ].filter(type => !!type)\n\n /* for resolvers */\n var { resolvers } = schemas\n var { queries = [], mutations = [], subscriptions = [], directives = [] } = resolvers\n\n var queryResolvers =\n queries.length > 0 &&\n queries.reduce((sum, query) => {\n return {\n ...sum,\n ...query\n }\n }, {})\n\n var mutationResolvers =\n mutations.length > 0 &&\n mutations.reduce((sum, mutation) => {\n return {\n ...sum,\n ...mutation\n }\n }, {})\n\n var subscriptionResolvers =\n subscriptions.length > 0 &&\n subscriptions.reduce((sum, subscription) => {\n return {\n ...sum,\n ...subscription\n }\n }, {})\n\n var directiveResolvers = directives.reduce((sum, directive) => {\n return {\n ...sum,\n ...directive\n }\n }, {})\n\n delete resolvers.queries\n delete resolvers.mutations\n delete resolvers.subscriptions\n delete resolvers.directives\n\n var Query = resolvers.Query || {}\n var Mutation = resolvers.Mutation || {}\n var Subscription = resolvers.Subscription || {}\n var Directive = resolvers.Directive || {}\n\n delete resolvers.Query\n delete resolvers.Mutation\n delete resolvers.Subscription\n delete resolvers.Directive\n\n resolvers = {\n Upload: GraphQLUpload as any,\n Query: deepMerge(Query, queryResolvers),\n Mutation: deepMerge(Mutation, mutationResolvers),\n Subscription: deepMerge(Subscription, subscriptionResolvers),\n ...scalarResolvers,\n ...resolvers\n }\n\n var merged = mergeSchemas({\n schemas: [\n await buildSchema({\n resolvers: schemas.resolverClasses,\n // automatically create `schema.gql` file with schema definition\n // in project's working directory\n // or create the file with schema in selected path\n emitSchemaFile: process.env.NODE_ENV == 'development'\n // emitSchemaFile: path.resolve(__dirname, 'snapshots/schema', 'schema.gql')\n })\n ],\n typeDefs,\n resolvers\n })\n\n Object.values(schemas.directives).map((directive: (schema: GraphQLSchema) => {}) => {\n merged = directive(merged) as any\n })\n\n return merged\n}\n"]}
1
+ {"version":3,"file":"schema.js","sourceRoot":"","sources":["../server/schema.ts"],"names":[],"mappings":";;;AACA,sEAA+D;AAC/D,+CAA0C;AAC1C,qDAA0F;AAE1F,kDAAoD;AACpD,6CAAgE;AAChE,iDAAiD;AAEjD,MAAM,IAAI,GAAG,OAAO,CAAC,MAAM,CAAC,CAAA;AAE5B;;;GAGG;AACI,KAAK,UAAU,MAAM;IAC1B,MAAM,OAAO,GAAG,wBAAkB;SAC/B,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC,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A0JC","sourcesContent":["import { GraphQLSchema } from 'graphql'\nimport { GraphQLUpload } from 'graphql-upload/GraphQLUpload.js'\nimport { buildSchema } from 'type-graphql'\nimport { typeDefs as scalarTypeDefs, resolvers as scalarResolvers } from 'graphql-scalars'\n\nimport { mergeSchemas } from '@graphql-tools/schema'\nimport { loader, orderedModuleNames } from '@things-factory/env'\nimport { deepMerge } from '@things-factory/utils'\n\nconst path = require('path')\n\n/**\n * Generates and returns a GraphQL schema by merging schemas and resolvers from various modules.\n * @returns {GraphQLSchema} The merged GraphQL schema.\n */\nexport async function schema() {\n const schemas = orderedModuleNames\n .map(dep => loader(dep).schema)\n .filter(schema => schema)\n .reduce(\n (sum, schema) => {\n const { typeDefs, resolvers, resolverClasses, directives } = sum\n let {\n typeDefs: sTypeDefs = {},\n resolvers: sResolvers = {},\n resolverClasses: sResolverClasses = [],\n directives: sDirectives = {}\n } = schema\n\n return {\n typeDefs: deepMerge(typeDefs, sTypeDefs),\n resolvers: deepMerge(resolvers, sResolvers),\n resolverClasses: [...resolverClasses, ...(sResolverClasses || [])],\n directives: deepMerge(directives, sDirectives)\n }\n },\n {\n typeDefs: {},\n resolvers: {},\n resolverClasses: [],\n directives: {}\n }\n )\n\n /* for typeDefs */\n var typeDefs = schemas.typeDefs\n var { queries = [], mutations = [], subscriptions = [], directives = [], types = [] } = typeDefs\n\n queries = [...queries, ...(typeDefs.Query || [])]\n mutations = [...mutations, ...(typeDefs.Mutation || [])]\n subscriptions = [...subscriptions, ...(typeDefs.Subscription || [])]\n directives = [...directives, ...(typeDefs.Directive || [])]\n\n delete typeDefs.Query\n delete typeDefs.Mutation\n delete typeDefs.Subscription\n delete typeDefs.Directive\n\n delete typeDefs.queries\n delete typeDefs.mutations\n delete typeDefs.subscriptions\n delete typeDefs.directives\n delete typeDefs.types\n\n const defs = {\n query: queries.length > 0 ? ['type Query {', ...queries, '}'].join('\\n') : 'type Query { _ : Boolean }',\n mutation:\n mutations.length > 0 ? ['type Mutation {', ...mutations, '}'].join('\\n') : 'type Mutation { _ : Boolean }',\n subscription:\n subscriptions.length > 0\n ? ['type Subscription {', ...subscriptions, '}'].join('\\n')\n : 'type Subscription { _ : Boolean }'\n }\n\n typeDefs = [\n ...scalarTypeDefs,\n `\n scalar Upload\n `,\n defs.query,\n defs.mutation,\n defs.subscription,\n ...directives,\n ...types,\n ...Object.values(typeDefs)\n ].filter(type => !!type)\n\n /* for resolvers */\n var { resolvers } = schemas\n var { queries = [], mutations = [], subscriptions = [], directives = [] } = resolvers\n\n var queryResolvers =\n queries.length > 0 &&\n queries.reduce((sum, query) => {\n return {\n ...sum,\n ...query\n }\n }, {})\n\n var mutationResolvers =\n mutations.length > 0 &&\n mutations.reduce((sum, mutation) => {\n return {\n ...sum,\n ...mutation\n }\n }, {})\n\n var subscriptionResolvers =\n subscriptions.length > 0 &&\n subscriptions.reduce((sum, subscription) => {\n return {\n ...sum,\n ...subscription\n }\n }, {})\n\n var directiveResolvers = directives.reduce((sum, directive) => {\n return {\n ...sum,\n ...directive\n }\n }, {})\n\n delete resolvers.queries\n delete resolvers.mutations\n delete resolvers.subscriptions\n delete resolvers.directives\n\n var Query = resolvers.Query || {}\n var Mutation = resolvers.Mutation || {}\n var Subscription = resolvers.Subscription || {}\n var Directive = resolvers.Directive || {}\n\n delete resolvers.Query\n delete resolvers.Mutation\n delete resolvers.Subscription\n delete resolvers.Directive\n\n resolvers = {\n Upload: GraphQLUpload as any,\n Query: deepMerge(Query, queryResolvers),\n Mutation: deepMerge(Mutation, mutationResolvers),\n Subscription: deepMerge(Subscription, subscriptionResolvers),\n ...scalarResolvers,\n ...resolvers\n }\n\n var merged = mergeSchemas({\n schemas: [\n await buildSchema({\n resolvers: schemas.resolverClasses,\n // automatically create `schema.gql` file with schema definition\n // in project's working directory\n // or create the file with schema in selected path\n emitSchemaFile: process.env.NODE_ENV == 'development'\n // emitSchemaFile: path.resolve(__dirname, 'snapshots/schema', 'schema.gql')\n })\n ],\n typeDefs,\n resolvers\n })\n\n Object.values(schemas.directives).map((directive: (schema: GraphQLSchema) => {}) => {\n merged = directive(merged) as any\n })\n\n return merged\n}\n"]}