@things-factory/shell 7.0.0-alpha.0 → 7.0.0-alpha.18

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 (97) hide show
  1. package/client/bootstrap.js +5 -0
  2. package/config/license.json +12 -12
  3. package/dist-server/graphql-local-client.d.ts +19 -0
  4. package/dist-server/graphql-local-client.js +17 -3
  5. package/dist-server/graphql-local-client.js.map +1 -1
  6. package/dist-server/index.d.ts +2 -0
  7. package/dist-server/index.js +2 -0
  8. package/dist-server/index.js.map +1 -1
  9. package/dist-server/initializers/database.d.ts +26 -0
  10. package/dist-server/initializers/database.js +26 -0
  11. package/dist-server/initializers/database.js.map +1 -1
  12. package/dist-server/pubsub-log-transport.d.ts +27 -0
  13. package/dist-server/pubsub-log-transport.js +15 -0
  14. package/dist-server/pubsub-log-transport.js.map +1 -1
  15. package/dist-server/pubsub.d.ts +9 -1
  16. package/dist-server/pubsub.js +14 -2
  17. package/dist-server/pubsub.js.map +1 -1
  18. package/dist-server/schema.d.ts +4 -0
  19. package/dist-server/schema.js +7 -3
  20. package/dist-server/schema.js.map +1 -1
  21. package/dist-server/server-dev.js +4 -1
  22. package/dist-server/server-dev.js.map +1 -1
  23. package/dist-server/server.js +4 -1
  24. package/dist-server/server.js.map +1 -1
  25. package/dist-server/service/subscription-data/data-resolver.js +6 -12
  26. package/dist-server/service/subscription-data/data-resolver.js.map +1 -1
  27. package/dist-server/tsconfig.tsbuildinfo +1 -1
  28. package/dist-server/typeorm/encrypt-transform.d.ts +5 -0
  29. package/dist-server/typeorm/encrypt-transform.js +25 -0
  30. package/dist-server/typeorm/encrypt-transform.js.map +1 -1
  31. package/dist-server/typeorm/json5-transform.d.ts +2 -0
  32. package/dist-server/typeorm/json5-transform.js +29 -0
  33. package/dist-server/typeorm/json5-transform.js.map +1 -0
  34. package/dist-server/typeorm/round-transform.d.ts +5 -0
  35. package/dist-server/typeorm/round-transform.js +21 -0
  36. package/dist-server/typeorm/round-transform.js.map +1 -0
  37. package/dist-server/utils/condition-builder.d.ts +11 -0
  38. package/dist-server/utils/condition-builder.js +11 -0
  39. package/dist-server/utils/condition-builder.js.map +1 -1
  40. package/dist-server/utils/get-domain.d.ts +46 -0
  41. package/dist-server/utils/get-domain.js +70 -0
  42. package/dist-server/utils/get-domain.js.map +1 -1
  43. package/dist-server/utils/get-query-builder-from-list-params.d.ts +12 -2
  44. package/dist-server/utils/get-query-builder-from-list-params.js +24 -8
  45. package/dist-server/utils/get-query-builder-from-list-params.js.map +1 -1
  46. package/dist-server/utils/get-times-for-period.d.ts +14 -0
  47. package/dist-server/utils/get-times-for-period.js +14 -0
  48. package/dist-server/utils/get-times-for-period.js.map +1 -1
  49. package/dist-server/utils/list-param-adjuster.d.ts +9 -0
  50. package/dist-server/utils/list-param-adjuster.js +9 -0
  51. package/dist-server/utils/list-param-adjuster.js.map +1 -1
  52. package/dist-server/utils/list-params-converter.d.ts +6 -0
  53. package/dist-server/utils/list-params-converter.js +27 -0
  54. package/dist-server/utils/list-params-converter.js.map +1 -1
  55. package/dist-server/utils/list-query-builder.d.ts +10 -1
  56. package/dist-server/utils/list-query-builder.js +10 -1
  57. package/dist-server/utils/list-query-builder.js.map +1 -1
  58. package/dist-server/utils/publish-progress.d.ts +9 -0
  59. package/dist-server/utils/publish-progress.js +9 -0
  60. package/dist-server/utils/publish-progress.js.map +1 -1
  61. package/package.json +7 -7
  62. package/server/graphql-local-client.ts +23 -3
  63. package/server/index.ts +3 -0
  64. package/server/initializers/database.ts +26 -0
  65. package/server/pubsub-log-transport.ts +29 -0
  66. package/server/pubsub.ts +17 -3
  67. package/server/schema.ts +9 -12
  68. package/server/server-dev.ts +7 -8
  69. package/server/server.ts +7 -8
  70. package/server/service/subscription-data/data-resolver.ts +9 -18
  71. package/server/typeorm/encrypt-transform.ts +26 -0
  72. package/server/typeorm/json5-transform.ts +26 -0
  73. package/server/typeorm/round-transform.ts +20 -0
  74. package/server/utils/condition-builder.ts +12 -8
  75. package/server/utils/get-domain.ts +70 -0
  76. package/server/utils/get-query-builder-from-list-params.ts +26 -16
  77. package/server/utils/get-times-for-period.ts +15 -4
  78. package/server/utils/list-param-adjuster.ts +9 -0
  79. package/server/utils/list-params-converter.ts +28 -4
  80. package/server/utils/list-query-builder.ts +13 -17
  81. package/server/utils/publish-progress.ts +9 -0
  82. package/dist-server/webpack/koa-webpack/client.d.ts +0 -1
  83. package/dist-server/webpack/koa-webpack/client.js +0 -24
  84. package/dist-server/webpack/koa-webpack/client.js.map +0 -1
  85. package/dist-server/webpack/koa-webpack/index.d.ts +0 -2
  86. package/dist-server/webpack/koa-webpack/index.js +0 -58
  87. package/dist-server/webpack/koa-webpack/index.js.map +0 -1
  88. package/dist-server/webpack/koa-webpack/middleware.d.ts +0 -0
  89. package/dist-server/webpack/koa-webpack/middleware.js +0 -42
  90. package/dist-server/webpack/koa-webpack/middleware.js.map +0 -1
  91. package/dist-server/webpack/koa-webpack/validate.d.ts +0 -1
  92. package/dist-server/webpack/koa-webpack/validate.js +0 -26
  93. package/dist-server/webpack/koa-webpack/validate.js.map +0 -1
  94. package/server/webpack/koa-webpack/client.ts +0 -26
  95. package/server/webpack/koa-webpack/index.ts +0 -71
  96. package/server/webpack/koa-webpack/middleware.ts +0 -47
  97. package/server/webpack/koa-webpack/validate.ts +0 -27
@@ -1,6 +1,11 @@
1
1
  import { installMediaQueryWatcher } from 'pwa-helpers/media-query.js'
2
2
  import { updateLayout } from '@operato/layout'
3
3
 
4
+ const ENV = process.env
5
+ const version = ENV['APP-VERSION']
6
+
7
+ window['appversion@things-factory'] = version
8
+
4
9
  export default function bootstrap() {
5
10
  installMediaQueryWatcher(`(min-width: 460px)`, matches => updateLayout(matches))
6
11
  }
@@ -1,13 +1,13 @@
1
1
  {
2
- "Customer": "hatiolab.com",
3
- "Product": "Things Factory Framework",
4
- "License Type": "Evaluation",
5
- "Purchase Date": "2023.11.29",
6
- "Expiration Date": "2024.02.29",
7
- "Host Address": "UNLIMITED",
8
- "Max Target Count": 0,
9
- "Max Domain Count": 0,
10
- "Permissions For Board Usage": "Viewer, Modeller",
11
- "Permissions For Tailor Tool": "Runner, Studio",
12
- "Key": "6eyJDdXN0b21lciI6ImhhdGlvbGFiLmNvbSIsIlByb2R1Y3QiOiJUaGluZ3MgRmFjdG9yeSBGcmFtZXdvcmsiLCJMaWNlbnNlIFR5cGUiOiJFdmFsdWF0aW9uIiwiUHVyY2hhc2UgRGF0ZSI6IjIwMjMuMTEuMjkiLCJFeHBpcmF0aW9uIERhdGUiOiIyMDI0LjAyLjI5IiwiSG9zdCBBZGRyZXNzIjoiVU5MSU1JVEVEIiwiTWF4IFRhcmdldCBDb3VudCI6MCwiTWF4IERvbWFpbiBDb3VudCI6MCwiUGVybWlzc2lvbnMgRm9yIEJvYXJkIFVzYWdlIjoiVmlld2VyLCBNb2RlbGxlciIsIlBlcm1pc3Npb25zIEZvciBUYWlsb3IgVG9vbCI6IlJ1bm5lciwgU3R1ZGlvIiwiS2V5IjoiQXhncUpRczRIakVBQkRjTEVRQW1GaU1NQmpvRUdnZ05EU2NtQ0JZL0doVVNGaVpUSXdzZ1N3WXZJamdXRXhzSUV6c2VEQk1pQTFVU0xoVTVGZ3d1QVFzbk14Z0RKU1lhRVFRcFZCSUpBa2dGREFFQUl5TWlGQUVwR2dzU0JTRk1JeHNRQndVYUh3QWdTU0liQWo4aUVoQVNLUkFMQ2lsSEh3Z0RBQm9vRmhnSkJBQUhFVGNhUnhvYUhBSU9EaXN6SmtvakZoVThHeFFuRlNwVkh3a0pPeHdlS2lNS0tDb1BBVDhpTVJNU05sVWpIQkE2QkJvZkFDQkpJeGdWRmg4eEtBRXVXU0FKR1FjZkNBTUFIQ2N6R1FJVkpoOGFJaDFaRWdrVVRCOEpCUUFaTlRjVUR5YzNGeDRrR1NVakNCVTdGQW91TlNZbUdnY0JQd1FMRUNZdEpBb3VERWNFSGlzeklpTUxDQTRwSWkwckpCMVdDZ29jUWdZSU1pVU5FeFlVQWhVZkt5Y21DRWtYR2d4TEJnb0lFUXdTQUJVQVFCc0dJZ1EyV1NNY0dFZ1BDU29DSmlZV0dRa3BCQXNyQVFCSkZnd0tQZ1F2SGhBakl5b1RBQVFXQ3hJaUNVd0pDQmxGSHdzeUF3eE5PdzhCQlJvUEVqYzZXaU1jQ0VnRkNESVVGamNBRWdBRkh3WWVJalpXQ2g0WkNCOExLamdOVFRjTEFUc1BCaDgySFJFU0dncElIdzFFTEE9PSJ9101865"
13
- }
2
+ "Customer": "hatiolab.com",
3
+ "Product": "Things Factory",
4
+ "License Type": "Evaluation",
5
+ "Purchase Date": "2024.02.29",
6
+ "Expiration Date": "2024.05.29",
7
+ "Host Address": "UNLIMITED",
8
+ "Max Target Count": 0,
9
+ "Max Domain Count": 0,
10
+ "Permissions For Board Usage": "Viewer, Modeller",
11
+ "Permissions For Tailor Tool": "Runner, Studio",
12
+ "Key": "5eyJDdXN0b21lciI6ImhhdGlvbGFiLmNvbSIsIlByb2R1Y3QiOiJUaGluZ3MgRmFjdG9yeSIsIkxpY2Vuc2UgVHlwZSI6IkV2YWx1YXRpb24iLCJQdXJjaGFzZSBEYXRlIjoiMjAyNC4wMi4yOSIsIkV4cGlyYXRpb24gRGF0ZSI6IjIwMjQuMDUuMjkiLCJIb3N0IEFkZHJlc3MiOiJVTkxJTUlURUQiLCJNYXggVGFyZ2V0IENvdW50IjowLCJNYXggRG9tYWluIENvdW50IjowLCJQZXJtaXNzaW9ucyBGb3IgQm9hcmQgVXNhZ2UiOiJWaWV3ZXIsIE1vZGVsbGVyIiwiUGVybWlzc2lvbnMgRm9yIFRhaWxvciBUb29sIjoiUnVubmVyLCBTdHVkaW8iLCJLZXkiOiJBeGdxSlFzNEhqRUFCRGNMRVFBbUZpTU1Cam9FR2dnTkRTY21DQlkvR2hVU0ZpWlRJd3NnU3dZdklqZ1dFeHNJRXpzZURCTWlBMVVTTGhVNUZnd3VBUXNuTXhnREpSOFNLd0lKVUJNdkRFY0ZMeDhDR1NnQUZnZ2xIeXNyQWhrU0V3b1dBdzhKSWdjTkVqZ0lGaFVlRUJBUkpVb0xHaHhNRGc0eUpCWTRHZ3NaUEFjSUp3RXVXUjRlTGtrYkNFQVFJRE1qRWhrOUVpMFJJZ05aRXdrUVFnWXZRQUlkSnlZeENDVWZLeXNCSmxjZkNSRkhHeDBmRENKS0FRZ1dGUjRZRWpZaEVDTWNIRDBPR1NvRERCTWZDQk03SGdzZ0Fna3FHQXdLSnhZTUl3QWpJeUlUQ1NvQkJoNGlLVmtTTHd3Q0h4d21EUXMzTnpFWlBBY1dLQ1lsTGhNSkJUa1dHanNMRmpjQUZCa1hHaFVRRWpvUUl3a05TUndlS2hnVk9DSVRBU29hR1JNU05sVUpHQ0FaQmk0ckFoNU5Nd2NCUHhjR0hoRWhTQkl2RFRzWkNDb1NEamNXTGdncUh4SXJKRDVXRWhvTVJRWWFIaEFtU1FzSURSa1NHQklTQTFvSkx3cElCZzBuQWgxTk14Z1pHQllIRXhJSlZna0lJQ2NHTHpzS0prb0RDQTFBRWhRU0JCbFpJQjRnSmdRWkhnSU9OelFJQkNNckpBPT0ifQ==99789"
13
+ }
@@ -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 = {
@@ -16,11 +20,21 @@ const defaultOptions = {
16
20
  errorPolicy: 'all'
17
21
  }
18
22
  };
19
- const cache = new client_1.InMemoryCache({
20
- addTypename: false
21
- });
23
+ /**
24
+ * GraphqlLocalClient is a utility class for initializing an Apollo Client for a local GraphQL schema.
25
+ * It provides a static `init` method for setting up the client with a schema and an app context.
26
+ */
22
27
  class GraphqlLocalClient {
28
+ /**
29
+ * Initializes the Apollo Client for a local GraphQL schema.
30
+ * @static
31
+ * @param {object} schema - The GraphQL schema to use.
32
+ * @param {object} app - The application context to be passed in as part of the execution context.
33
+ */
23
34
  static init(schema, app) {
35
+ const cache = new client_1.InMemoryCache({
36
+ addTypename: false
37
+ });
24
38
  GraphqlLocalClient.client = new client_1.ApolloClient({
25
39
  defaultOptions,
26
40
  cache,
@@ -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;;;GAGG;AACH,MAAa,kBAAkB;IAQ7B;;;;;OAKG;IACH,MAAM,CAAC,IAAI,CAAC,MAAM,EAAE,GAAG;QACrB,MAAM,KAAK,GAAG,IAAI,sBAAa,CAAC;YAC9B,WAAW,EAAE,KAAK;SACnB,CAAC,CAAA;QAEF,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;AAjCD,gDAiCC","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\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 const cache = new InMemoryCache({\n addTypename: false\n })\n\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"]}
@@ -8,3 +8,5 @@ export * from './middlewares';
8
8
  export * from './graphql-local-client';
9
9
  export * from './service';
10
10
  export * from './typeorm/encrypt-transform';
11
+ export * from './typeorm/json5-transform';
12
+ export * from './typeorm/round-transform';
@@ -11,4 +11,6 @@ tslib_1.__exportStar(require("./middlewares"), exports);
11
11
  tslib_1.__exportStar(require("./graphql-local-client"), exports);
12
12
  tslib_1.__exportStar(require("./service"), exports);
13
13
  tslib_1.__exportStar(require("./typeorm/encrypt-transform"), exports);
14
+ tslib_1.__exportStar(require("./typeorm/json5-transform"), exports);
15
+ tslib_1.__exportStar(require("./typeorm/round-transform"), exports);
14
16
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../server/index.ts"],"names":[],"mappings":";;;AAAA,uDAA4B;AAC5B,yEAA8C;AAC9C,kEAAuC;AACvC,kDAAuB;AACvB,mDAAwB;AACxB,iEAAsC;AACtC,wDAA6B;AAC7B,iEAAsC;AACtC,oDAAyB;AACzB,sEAA2C","sourcesContent":["export * from './migrations'\nexport * from './initializers/naming-strategy'\nexport * from './initializers/database'\nexport * from './utils'\nexport * from './pubsub'\nexport * from './pubsub-log-transport'\nexport * from './middlewares'\nexport * from './graphql-local-client'\nexport * from './service'\nexport * from './typeorm/encrypt-transform'\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../server/index.ts"],"names":[],"mappings":";;;AAAA,uDAA4B;AAC5B,yEAA8C;AAC9C,kEAAuC;AACvC,kDAAuB;AACvB,mDAAwB;AACxB,iEAAsC;AACtC,wDAA6B;AAC7B,iEAAsC;AACtC,oDAAyB;AAEzB,sEAA2C;AAC3C,oEAAyC;AACzC,oEAAyC","sourcesContent":["export * from './migrations'\nexport * from './initializers/naming-strategy'\nexport * from './initializers/database'\nexport * from './utils'\nexport * from './pubsub'\nexport * from './pubsub-log-transport'\nexport * from './middlewares'\nexport * from './graphql-local-client'\nexport * from './service'\n\nexport * from './typeorm/encrypt-transform'\nexport * from './typeorm/json5-transform'\nexport * from './typeorm/round-transform'\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/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,SAAgB,aAAa,CAAC,IAAa;IACzC,OAAO,WAAW,CAAC,IAAI,IAAI,SAAS,CAAC,CAAA;AACvC,CAAC;AAFD,sCAEC;AAED,SAAgB,aAAa,CAAC,IAAY,EAAE,UAAsB;IAChE,WAA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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":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AAC,SAAS,EAAE,UAAU,CAAC,CAAA;QAEpC,YAAM,CAAC,IAAI,CAAC,gCAAgC,CAAC,CAAA;QAE7C,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\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,10 @@
1
- declare let pubsub: any;
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
+ */
8
+ import { PubSub } from 'type-graphql';
9
+ declare let pubsub: PubSub;
2
10
  export { pubsub };
@@ -1,10 +1,17 @@
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");
5
12
  const graphql_mqtt_subscriptions_1 = require("graphql-mqtt-subscriptions");
6
13
  const graphql_redis_subscriptions_1 = require("graphql-redis-subscriptions");
7
- const graphql_subscriptions_1 = require("graphql-subscriptions");
14
+ const graphql_yoga_1 = require("graphql-yoga");
8
15
  const ioredis_1 = tslib_1.__importDefault(require("ioredis"));
9
16
  const mqtt_1 = require("mqtt");
10
17
  const env_1 = require("@things-factory/env");
@@ -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
@@ -51,13 +61,15 @@ switch (middleware) {
51
61
  }
52
62
  break;
53
63
  default:
54
- exports.pubsub = pubsub = new graphql_subscriptions_1.PubSub();
64
+ exports.pubsub = pubsub = (0, graphql_yoga_1.createPubSub)();
55
65
  break;
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,EAAE,IAAA,cAAO,EAAC,SAAS,GAAG,IAAI,kBAC9B,eAAe,EAAE,IAAI,IAClB,OAAO,EACH;SACV,CAA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AAC,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,+CAA2C;AAC3C,8DAA2B;AAC3B,+BAA8B;AAE9B,6CAAoD;AAGpD,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,MAAc,CAAA;AAwFT,wBAAM;AAtFf,QAAQ,UAAU,EAAE;IAClB,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,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 { createPubSub } from 'graphql-yoga'\nimport Redis from 'ioredis'\nimport { connect } from 'mqtt'\n\nimport { config, logger } from '@things-factory/env'\nimport { PubSub } from 'type-graphql'\n\nconst { middleware, host, port, nodes, topic, options } = config.get('pubsub', {})\n\nlet pubsub: PubSub\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 = createPubSub()\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>;
@@ -7,7 +7,12 @@ const graphql_scalars_1 = require("graphql-scalars");
7
7
  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
+ const pubsub_1 = require("./pubsub");
10
11
  const path = require('path');
12
+ /**
13
+ * Generates and returns a GraphQL schema by merging schemas and resolvers from various modules.
14
+ * @returns {GraphQLSchema} The merged GraphQL schema.
15
+ */
11
16
  async function schema() {
12
17
  const schemas = env_1.orderedModuleNames
13
18
  .map(dep => (0, env_1.loader)(dep).schema)
@@ -46,9 +51,7 @@ async function schema() {
46
51
  const defs = {
47
52
  query: queries.length > 0 ? ['type Query {', ...queries, '}'].join('\n') : 'type Query { _ : Boolean }',
48
53
  mutation: mutations.length > 0 ? ['type Mutation {', ...mutations, '}'].join('\n') : 'type Mutation { _ : Boolean }',
49
- subscription: subscriptions.length > 0
50
- ? ['type Subscription {', ...subscriptions, '}'].join('\n')
51
- : 'type Subscription { _ : Boolean }'
54
+ subscription: subscriptions.length > 0 ? ['type Subscription {', ...subscriptions, '}'].join('\n') : 'type Subscription { _ : Boolean }'
52
55
  };
53
56
  typeDefs = [
54
57
  ...graphql_scalars_1.typeDefs,
@@ -96,6 +99,7 @@ async function schema() {
96
99
  var merged = (0, schema_1.mergeSchemas)({
97
100
  schemas: [
98
101
  await (0, type_graphql_1.buildSchema)({
102
+ pubSub: pubsub_1.pubsub,
99
103
  resolvers: schemas.resolverClasses,
100
104
  // automatically create `schema.gql` file with schema definition
101
105
  // in project's working directory
@@ -1 +1 @@
1
- {"version":3,"file":"schema.js","sourceRoot":"","sources":["../server/schema.ts"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C;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;AACjD,qCAAiC;AAEjC,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,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,EAAE,QAAQ,EAAE,SAAS,GAAG,EAAE,EAAE,SAAS,EAAE,UAAU,GAAG,EAAE,EAAE,eAAe,EAAE,gBAAgB,GAAG,EAAE,EAAE,UAAU,EAAE,WAAW,GAAG,EAAE,EAAE,GAAG,MAAM,CAAA;QAE3I,OAAO;YACL,QAAQ,EAAE,IAAA,iBAAS,EAAC,QAAQ,EAAE,SAAS,CAAC;YACxC,SAAS,EAAE,IAAA,iBAAS,EAAC,SAAS,EAAE,UAAU,CAAC;YAC3C,eAAe,EAAE,CAAC,GAAG,eAAe,EAAE,GAAG,CAAC,gBAAgB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,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,MAAM,EAAE,eAAM;gBACd,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;AAlJD,wBAkJC","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'\nimport { pubsub } from './pubsub'\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 { typeDefs: sTypeDefs = {}, resolvers: sResolvers = {}, resolverClasses: sResolverClasses = [], directives: sDirectives = {} } = 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: mutations.length > 0 ? ['type Mutation {', ...mutations, '}'].join('\\n') : 'type Mutation { _ : Boolean }',\n subscription: subscriptions.length > 0 ? ['type Subscription {', ...subscriptions, '}'].join('\\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 pubSub: pubsub,\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"]}
@@ -2,7 +2,10 @@
2
2
  // ts-import-sorter: disable
3
3
  Object.defineProperty(exports, "__esModule", { value: true });
4
4
  const tslib_1 = require("tslib");
5
- /* following 2 lines should be located in top of the file */
5
+ /* following 7 lines should be located in top of the file */
6
+ const OS = require('os');
7
+ process.env.UV_THREADPOOL_SIZE = OS.cpus().length;
8
+ console.log('UV_THREADPOOL_SIZE', process.env.UV_THREADPOOL_SIZE);
6
9
  process.env.NODE_ENV = 'development';
7
10
  process.setMaxListeners(0);
8
11
  const server_1 = require("@apollo/server");
@@ -1 +1 @@
1
- {"version":3,"file":"server-dev.js","sourceRoot":"","sources":["../server/server-dev.ts"],"names":[],"mappings":";AAAA,4BAA4B;;;AAE5B,4DAA4D;AAC5D,OAAO,CAAC,GAAG,CAAC,QAAQ,GAAG,aAA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,EAAC,MAAM,EAAE;QACpB,OAAO,EAAE,KAAK,EAAE,EAAE,GAAG,EAAE,EAAE,EAAE,CAAC,GAAG;KAChC,CAAC,CACH,CAAA;IACD,GAAG,CAAC,GAAG,CAAC,uBAAa,CAAC,MAAM,EAAE,CAAC,CAAA;IAC/B,GAAG,CAAC,GAAG,CAAC,uBAAa,CAAC,cAAc,EAAE,CAAC,CAAA;IAEvC,oFAAoF;IACpF,GAAG,CAAC,GAAG,CAAC,IAAA,sDAAkB,EAAC,EAAE,SAAS,EAAE,EAAE,EAAE,CAAC,CAAC,CAAA;IAE9C,GAAG,CAAC,GAAG,CAAC,UAAU,CAAC,CAAA;IAEnB,GAAG,CAAC,GAAG,CACL,IAAA,oBAAS,EAAC,QAAQ,CAAC,UAAU,EAAE;QAC7B,KAAK,EAAE,KAAK;KACb,CAAC,CACH,CAAA;IAED,UAAU,CAAC,MAAM,CAAC,EAAE,IAAI,EAAE,IAAI,EAAE,EAAE,GAAG,EAAE;QACrC,YAAM,CAAC,IAAI,CAAC,qCAAqC,IAAI,UAAU,CAAC,CAAA;QAChE,YAAM,CAAC,IAAI,CAAC,0CAA0C,IAAI,UAAU,CAAC,CAAA;QAErE,OAAO,CAAC,IAAI,CAAC,wBAA+B,EAAE,EAAE,GAAG,EAAE,MAAM,EAAN,YAAM,EAAE,WAAW,EAAE,UAAU,EAAS,CAAC,CAAA;IAChG,CAAC,CAAC,CAAA;AACJ,CAAC,CAAA;AAED,SAAS,EAAE,CAAA","sourcesContent":["// ts-import-sorter: disable\n\n/* following 2 lines should be located in top of the file */\nprocess.env.NODE_ENV = 'development'\nprocess.setMaxListeners(0)\n\nimport { ApolloServer } from '@apollo/server'\nimport { ApolloServerPluginDrainHttpServer } from '@apollo/server/plugin/drainHttpServer'\nimport { ApolloServerPluginLandingPageLocalDefault } from '@apollo/server/plugin/landingPage/default'\n\nimport { koaMiddleware } from '@as-integrations/koa'\nimport bytesFormat from 'bytes'\nimport graphqlUploadKoa from 'graphql-upload/graphqlUploadKoa.js'\nimport { useServer } from 'graphql-ws/lib/use/ws'\nimport { createServer } from 'http'\nimport Koa from 'koa'\nimport koaBodyParser from 'koa-bodyparser'\nimport koaStatic from 'koa-static'\nimport compose from 'koa-compose'\nimport { historyApiFallback } from 'koa2-connect-history-api-fallback'\nimport { WebSocketServer } from 'ws'\nimport co from 'co'\nimport http from 'http'\n\nimport koaWebpack from '@hatiolab/koa-webpack'\nimport cors from '@koa/cors'\nimport { config, loader, logger, orderedModuleNames } from '@things-factory/env'\nimport { initLicense, checkValidity } from '@things-factory/operato-license-checker'\n\nimport { GraphqlLocalClient } from './graphql-local-client'\nimport { databaseInitializer } from './initializers/database'\nimport {\n domainPrivateRouter,\n domainPublicRouter,\n globalPrivateRouter,\n globalPublicRouter,\n graphqlRouter\n} from './routers'\nimport { schema } from './schema'\nimport { Domain } from './service'\nimport { EntityManager } from 'typeorm'\nimport { domainMiddleware } from './middlewares'\n\nprocess.on('uncaughtException', error => {\n logger.error('uncaughtException: ', error, error.stack)\n\n //process.exit(1)\n})\n\nconst args = require('args')\n\nargs.option('port', 'The port on which the app will be running', config.get('port', 3000))\nargs.option(\n 'inspect',\n `The address on which the inspection will be running. Used in development mode only.\n This option is just to prevent termination for reasons of not recognizing the 'inspect' option.`,\n config.get('inspect', ':9229')\n)\nargs.option('webpack', 'webpack configuration file', config.get('webpack'))\n\nconst flags = args.parse(process.argv)\n\nconst path = require('path')\nconst webpack = require('webpack')\nconst webpackConfig = require(flags.webpack || '@things-factory/builder/webpack.config.dev.js')\n\nconst compiler = webpack(webpackConfig)\n\nconst PORT = (process.env.PORT = flags.port)\n\nconst requestBody = config.get('requestBody') || {}\n\nconst bodyParserOption = {\n formLimit: requestBody.formLimit || '10mb',\n jsonLimit: requestBody.jsonLimit || '10mb',\n textLimit: requestBody.textLimit || '10mb'\n}\n\nconst fileUpload = config.get('fileUpload') || {}\nconst fileUploadOption = {\n maxFileSize: bytesFormat.parse(fileUpload.maxFileSize) || bytesFormat.parse('10mb'),\n maxFiles: fileUpload.maxFiles || 10\n}\n\ninterface ICustomAppState {\n domain: Domain\n user: any\n tx: EntityManager\n}\n\ninterface ICustomAppContext {\n t: any\n ssoMiddlewares: any[]\n}\n\ninitLicense(config.get('licenseKey'))\n\n/* bootstrap */\nconst bootstrap = async () => {\n await databaseInitializer()\n\n const app = new Koa<ICustomAppState, ICustomAppContext>() as any\n\n app.use(\n cors({\n origin: function (ctx) {\n return ctx.request.headers.origin || '*'\n },\n exposeHeaders: ['WWW-Authenticate', 'Server-Authorization'],\n maxAge: 5,\n credentials: true,\n /* allowMethods: ['GET', 'POST', 'DELETE'], -- use default */\n allowHeaders: ['Content-Type', 'Authorization', 'Accept']\n })\n )\n\n var subscriptionMiddleware = []\n process.emit('bootstrap-module-subscription' as any, app, subscriptionMiddleware)\n\n const builtSchema = await schema()\n\n const httpServer = createServer(app.callback())\n const websocketServer = new WebSocketServer({\n server: httpServer,\n path: '/graphql'\n })\n\n // Save the returned server's info so we can shut down this server later\n const serverCleanup = useServer(\n {\n schema: builtSchema,\n context: async (ctx, msg, args) => {\n return ctx['context']\n },\n onConnect: async ctx => {\n var { extra, connectionParams } = ctx\n var { request } = extra\n\n if (((connectionParams['headers'] as any) || connectionParams)?.referer) {\n var url = new URL(((connectionParams['headers'] as any) || connectionParams).referer)\n var accessToken = url.searchParams.get('access_token')\n if (accessToken) {\n connectionParams['headers']['authorization'] = accessToken\n }\n }\n\n request.headers = {\n ...request.headers,\n ...(connectionParams['headers'] || (connectionParams as any))\n }\n\n var koacontext = await app.createContext(request, new http.ServerResponse(request))\n koacontext['state'] = {}\n\n /* in case connect error(like a authentication error) just throw exception */\n var middlewares = [domainMiddleware, ...subscriptionMiddleware]\n const fn = co.wrap(compose(middlewares))\n\n await fn(koacontext)\n\n return (ctx['context'] = koacontext)\n },\n onDisconnect(ctx, code, reason) {\n console.log('Disconnected!')\n },\n onError(ctx, msg, errors) {\n console.error(msg, errors)\n }\n },\n websocketServer\n )\n\n const server = new ApolloServer({\n schema: builtSchema,\n formatError: error => {\n logger.error(error)\n return error\n },\n introspection: true,\n csrfPrevention: true,\n plugins: [\n // Proper shutdown for the HTTP server.\n ApolloServerPluginDrainHttpServer({ httpServer }),\n // Proper shutdown for the WebSocket server.\n {\n async serverWillStart() {\n return {\n async drainServer() {\n await serverCleanup.dispose()\n }\n }\n }\n },\n // TODO make this landing page work\n ApolloServerPluginLandingPageLocalDefault({\n footer: false,\n embed: true,\n includeCookies: true\n })\n ],\n cache: 'bounded'\n })\n\n await server.start()\n\n GraphqlLocalClient.init(builtSchema, app)\n\n orderedModuleNames.forEach(name => {\n const { initMiddlewares } = loader(name)\n initMiddlewares && initMiddlewares(app)\n })\n\n const render = require('@things-factory/ejs-remote')\n render(app, {\n root: '/views',\n host: `http://127.0.0.1:${PORT}`,\n layout: false,\n viewExt: 'html',\n cache: false,\n debug: false\n })\n\n const middleware = await koaWebpack({\n compiler,\n hotClient: {},\n devMiddleware: {\n publicPath: webpackConfig.output.publicPath,\n stats: { colors: true }\n }\n })\n\n // only for development mode. triggered after webpack compilation is done.\n compiler.hooks.done.tap({ name: 'server-dev' }, stats => {\n process.emit('client-rebuilt' as any, app, compiler.outputFileSystem)\n })\n\n app.use(koaBodyParser(bodyParserOption))\n\n /* routers */\n const ssoMiddlewares = []\n process.emit('bootstrap-collect-sso-middleware' as any, null, ssoMiddlewares)\n app.ssoMiddlewares = ssoMiddlewares\n\n process.emit('bootstrap-module-global-public-route' as any, app, globalPublicRouter)\n process.emit('bootstrap-module-global-private-route' as any, app, globalPrivateRouter)\n process.emit('bootstrap-module-domain-public-route' as any, app, domainPublicRouter)\n process.emit('bootstrap-module-domain-private-route' as any, app, domainPrivateRouter)\n\n app.use(checkValidity) /* Check the license after most of the context has been built */\n\n app\n .use(globalPublicRouter.routes())\n .use(globalPublicRouter.allowedMethods())\n .use(globalPrivateRouter.routes())\n .use(globalPrivateRouter.allowedMethods())\n .use(domainPublicRouter.routes())\n .use(domainPublicRouter.allowedMethods())\n .use(domainPrivateRouter.routes())\n .use(domainPrivateRouter.allowedMethods())\n\n /* Graphql Upload's multipart/form-data handling affects the restful file upload feature, so it should be placed after the routers configuration. */\n app.use(graphqlUploadKoa(fileUploadOption))\n\n graphqlRouter.post(\n '/graphql',\n koaMiddleware(server, {\n context: async ({ ctx }) => ctx\n })\n )\n app.use(graphqlRouter.routes())\n app.use(graphqlRouter.allowedMethods())\n\n /* should follow this order : history-fallback => webpack-middleware => koaStatic */\n app.use(historyApiFallback({ whiteList: [] }))\n\n app.use(middleware)\n\n app.use(\n koaStatic(compiler.outputPath, {\n index: false\n })\n )\n\n httpServer.listen({ port: PORT }, () => {\n logger.info(`🚀 Server ready at http://0.0.0.0:${PORT}/graphql`)\n logger.info(`🚀 Subscriptions ready at ws://0.0.0.0:${PORT}/graphql`)\n\n process.emit('bootstrap-module-start' as any, { app, config, builtSchema, httpServer } as any)\n })\n}\n\nbootstrap()\n"]}
1
+ {"version":3,"file":"server-dev.js","sourceRoot":"","sources":["../server/server-dev.ts"],"names":[],"mappings":";AAAA,4BAA4B;;;AAE5B,4DAA4D;AAC5D,MAAM,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAAA;AACxB,OAAO,CAAC,GAAG,CAAC,kBAAkB,GAAG,EAAE,CAAC,IAAI,EAAE,CAAC,MAAM,CAAA;AAEjD,OAAO,CAAC,GAAG,CAAC,oBAAoB,EAAE,OAAO,CAAC,GAAG,CAAC,kBAAkB,CAAC,CAAA;AAEjE,OAAO,CAAC,GAAG,CAAC,QAAQ,GAAG,aAAa,CAAA;AACpC,OAAO,CAAC,eAAe,CAAC,CAAC,CAAC,CAAA;AAE1B,2CAA6C;AAC7C,2EAAyF;AACzF,uEAAqG;AAErG,8CAAoD;AACpD,0DAA+B;AAC/B,qGAAiE;AACjE,8CAAiD;AACjD,+BAAmC;AACnC,sDAAqB;AACrB,4EAA0C;AAC1C,oEAAkC;AAClC,sEAAiC;AACjC,yFAAsE;AACtE,2BAAoC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oF;IACpF,GAAG,CAAC,GAAG,CAAC,IAAA,sDAAkB,EAAC,EAAE,SAAS,EAAE,EAAE,EAAE,CAAC,CAAC,CAAA;IAE9C,GAAG,CAAC,GAAG,CAAC,UAAU,CAAC,CAAA;IAEnB,GAAG,CAAC,GAAG,CACL,IAAA,oBAAS,EAAC,QAAQ,CAAC,UAAU,EAAE;QAC7B,KAAK,EAAE,KAAK;KACb,CAAC,CACH,CAAA;IAED,UAAU,CAAC,MAAM,CAAC,EAAE,IAAI,EAAE,IAAI,EAAE,EAAE,GAAG,EAAE;QACrC,YAAM,CAAC,IAAI,CAAC,qCAAqC,IAAI,UAAU,CAAC,CAAA;QAChE,YAAM,CAAC,IAAI,CAAC,0CAA0C,IAAI,UAAU,CAAC,CAAA;QAErE,OAAO,CAAC,IAAI,CAAC,wBAA+B,EAAE,EAAE,GAAG,EAAE,MAAM,EAAN,YAAM,EAAE,WAAW,EAAE,UAAU,EAAS,CAAC,CAAA;IAChG,CAAC,CAAC,CAAA;AACJ,CAAC,CAAA;AAED,SAAS,EAAE,CAAA","sourcesContent":["// ts-import-sorter: disable\n\n/* following 7 lines should be located in top of the file */\nconst OS = require('os')\nprocess.env.UV_THREADPOOL_SIZE = OS.cpus().length\n\nconsole.log('UV_THREADPOOL_SIZE', process.env.UV_THREADPOOL_SIZE)\n\nprocess.env.NODE_ENV = 'development'\nprocess.setMaxListeners(0)\n\nimport { ApolloServer } from '@apollo/server'\nimport { ApolloServerPluginDrainHttpServer } from '@apollo/server/plugin/drainHttpServer'\nimport { ApolloServerPluginLandingPageLocalDefault } from '@apollo/server/plugin/landingPage/default'\n\nimport { koaMiddleware } from '@as-integrations/koa'\nimport bytesFormat from 'bytes'\nimport graphqlUploadKoa from 'graphql-upload/graphqlUploadKoa.js'\nimport { useServer } from 'graphql-ws/lib/use/ws'\nimport { createServer } from 'http'\nimport Koa from 'koa'\nimport koaBodyParser from 'koa-bodyparser'\nimport koaStatic from 'koa-static'\nimport compose from 'koa-compose'\nimport { historyApiFallback } from 'koa2-connect-history-api-fallback'\nimport { WebSocketServer } from 'ws'\nimport co from 'co'\nimport http from 'http'\n\nimport koaWebpack from '@hatiolab/koa-webpack'\nimport cors from '@koa/cors'\nimport { config, loader, logger, orderedModuleNames } from '@things-factory/env'\nimport { initLicense, checkValidity } from '@things-factory/operato-license-checker'\n\nimport { GraphqlLocalClient } from './graphql-local-client'\nimport { databaseInitializer } from './initializers/database'\nimport { domainPrivateRouter, domainPublicRouter, globalPrivateRouter, globalPublicRouter, graphqlRouter } from './routers'\nimport { schema } from './schema'\nimport { Domain } from './service'\nimport { EntityManager } from 'typeorm'\nimport { domainMiddleware } from './middlewares'\n\nprocess.on('uncaughtException', error => {\n logger.error('uncaughtException: ', error, error.stack)\n\n //process.exit(1)\n})\n\nconst args = require('args')\n\nargs.option('port', 'The port on which the app will be running', config.get('port', 3000))\nargs.option(\n 'inspect',\n `The address on which the inspection will be running. Used in development mode only.\n This option is just to prevent termination for reasons of not recognizing the 'inspect' option.`,\n config.get('inspect', ':9229')\n)\nargs.option('webpack', 'webpack configuration file', config.get('webpack'))\n\nconst flags = args.parse(process.argv)\n\nconst path = require('path')\nconst webpack = require('webpack')\nconst webpackConfig = require(flags.webpack || '@things-factory/builder/webpack.config.dev.js')\n\nconst compiler = webpack(webpackConfig)\n\nconst PORT = (process.env.PORT = flags.port)\n\nconst requestBody = config.get('requestBody') || {}\n\nconst bodyParserOption = {\n formLimit: requestBody.formLimit || '10mb',\n jsonLimit: requestBody.jsonLimit || '10mb',\n textLimit: requestBody.textLimit || '10mb'\n}\n\nconst fileUpload = config.get('fileUpload') || {}\nconst fileUploadOption = {\n maxFileSize: bytesFormat.parse(fileUpload.maxFileSize) || bytesFormat.parse('10mb'),\n maxFiles: fileUpload.maxFiles || 10\n}\n\ninterface ICustomAppState {\n domain: Domain\n user: any\n tx: EntityManager\n}\n\ninterface ICustomAppContext {\n t: any\n ssoMiddlewares: any[]\n}\n\ninitLicense(config.get('licenseKey'))\n\n/* bootstrap */\nconst bootstrap = async () => {\n await databaseInitializer()\n\n const app = new Koa<ICustomAppState, ICustomAppContext>() as any\n\n app.use(\n cors({\n origin: function (ctx) {\n return ctx.request.headers.origin || '*'\n },\n exposeHeaders: ['WWW-Authenticate', 'Server-Authorization'],\n maxAge: 5,\n credentials: true,\n /* allowMethods: ['GET', 'POST', 'DELETE'], -- use default */\n allowHeaders: ['Content-Type', 'Authorization', 'Accept']\n })\n )\n\n var subscriptionMiddleware = []\n process.emit('bootstrap-module-subscription' as any, app, subscriptionMiddleware)\n\n const builtSchema = await schema()\n\n const httpServer = createServer(app.callback())\n const websocketServer = new WebSocketServer({\n server: httpServer,\n path: '/graphql'\n })\n\n // Save the returned server's info so we can shut down this server later\n const serverCleanup = useServer(\n {\n schema: builtSchema,\n context: async (ctx, msg, args) => {\n return ctx['context']\n },\n onConnect: async ctx => {\n var { extra, connectionParams } = ctx\n var { request } = extra\n\n if (((connectionParams['headers'] as any) || connectionParams)?.referer) {\n var url = new URL(((connectionParams['headers'] as any) || connectionParams).referer)\n var accessToken = url.searchParams.get('access_token')\n if (accessToken) {\n connectionParams['headers']['authorization'] = accessToken\n }\n }\n\n request.headers = {\n ...request.headers,\n ...(connectionParams['headers'] || (connectionParams as any))\n }\n\n var koacontext = await app.createContext(request, new http.ServerResponse(request))\n koacontext['state'] = {}\n\n /* in case connect error(like a authentication error) just throw exception */\n var middlewares = [domainMiddleware, ...subscriptionMiddleware]\n const fn = co.wrap(compose(middlewares))\n\n await fn(koacontext)\n\n return (ctx['context'] = koacontext)\n },\n onDisconnect(ctx, code, reason) {\n console.log('Disconnected!')\n },\n onError(ctx, msg, errors) {\n console.error(msg, errors)\n }\n },\n websocketServer\n )\n\n const server = new ApolloServer({\n schema: builtSchema,\n formatError: error => {\n logger.error(error)\n return error\n },\n introspection: true,\n csrfPrevention: true,\n plugins: [\n // Proper shutdown for the HTTP server.\n ApolloServerPluginDrainHttpServer({ httpServer }),\n // Proper shutdown for the WebSocket server.\n {\n async serverWillStart() {\n return {\n async drainServer() {\n await serverCleanup.dispose()\n }\n }\n }\n },\n // TODO make this landing page work\n ApolloServerPluginLandingPageLocalDefault({\n footer: false,\n embed: true,\n includeCookies: true\n })\n ],\n cache: 'bounded'\n })\n\n await server.start()\n\n GraphqlLocalClient.init(builtSchema, app)\n\n orderedModuleNames.forEach(name => {\n const { initMiddlewares } = loader(name)\n initMiddlewares && initMiddlewares(app)\n })\n\n const render = require('@things-factory/ejs-remote')\n render(app, {\n root: '/views',\n host: `http://127.0.0.1:${PORT}`,\n layout: false,\n viewExt: 'html',\n cache: false,\n debug: false\n })\n\n const middleware = await koaWebpack({\n compiler,\n hotClient: {},\n devMiddleware: {\n publicPath: webpackConfig.output.publicPath,\n stats: { colors: true }\n }\n })\n\n // only for development mode. triggered after webpack compilation is done.\n compiler.hooks.done.tap({ name: 'server-dev' }, stats => {\n process.emit('client-rebuilt' as any, app, compiler.outputFileSystem)\n })\n\n app.use(koaBodyParser(bodyParserOption))\n\n /* routers */\n const ssoMiddlewares = []\n process.emit('bootstrap-collect-sso-middleware' as any, null, ssoMiddlewares)\n app.ssoMiddlewares = ssoMiddlewares\n\n process.emit('bootstrap-module-global-public-route' as any, app, globalPublicRouter)\n process.emit('bootstrap-module-global-private-route' as any, app, globalPrivateRouter)\n process.emit('bootstrap-module-domain-public-route' as any, app, domainPublicRouter)\n process.emit('bootstrap-module-domain-private-route' as any, app, domainPrivateRouter)\n\n app.use(checkValidity) /* Check the license after most of the context has been built */\n\n app\n .use(globalPublicRouter.routes())\n .use(globalPublicRouter.allowedMethods())\n .use(globalPrivateRouter.routes())\n .use(globalPrivateRouter.allowedMethods())\n .use(domainPublicRouter.routes())\n .use(domainPublicRouter.allowedMethods())\n .use(domainPrivateRouter.routes())\n .use(domainPrivateRouter.allowedMethods())\n\n /* Graphql Upload's multipart/form-data handling affects the restful file upload feature, so it should be placed after the routers configuration. */\n app.use(graphqlUploadKoa(fileUploadOption))\n\n graphqlRouter.post(\n '/graphql',\n koaMiddleware(server, {\n context: async ({ ctx }) => ctx\n })\n )\n app.use(graphqlRouter.routes())\n app.use(graphqlRouter.allowedMethods())\n\n /* should follow this order : history-fallback => webpack-middleware => koaStatic */\n app.use(historyApiFallback({ whiteList: [] }))\n\n app.use(middleware)\n\n app.use(\n koaStatic(compiler.outputPath, {\n index: false\n })\n )\n\n httpServer.listen({ port: PORT }, () => {\n logger.info(`🚀 Server ready at http://0.0.0.0:${PORT}/graphql`)\n logger.info(`🚀 Subscriptions ready at ws://0.0.0.0:${PORT}/graphql`)\n\n process.emit('bootstrap-module-start' as any, { app, config, builtSchema, httpServer } as any)\n })\n}\n\nbootstrap()\n"]}