@common-stack/server-stack 8.0.1-alpha.2 → 8.2.1-alpha.0

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 (152) hide show
  1. package/LICENSE +34 -21
  2. package/lib/MainStackServer.cjs +126 -143
  3. package/lib/MainStackServer.cjs.map +1 -1
  4. package/lib/MainStackServer.d.ts +12 -6
  5. package/lib/MainStackServer.mjs +126 -143
  6. package/lib/MainStackServer.mjs.map +1 -1
  7. package/lib/StackServer.cjs +23 -66
  8. package/lib/StackServer.cjs.map +1 -1
  9. package/lib/StackServer.d.ts +4 -5
  10. package/lib/StackServer.mjs +23 -66
  11. package/lib/StackServer.mjs.map +1 -1
  12. package/lib/api/schema-builder.cjs +13 -12
  13. package/lib/api/schema-builder.cjs.map +1 -1
  14. package/lib/api/schema-builder.mjs +13 -12
  15. package/lib/api/schema-builder.mjs.map +1 -1
  16. package/lib/api/sub-graph-schema-builder.cjs +147 -0
  17. package/lib/api/sub-graph-schema-builder.cjs.map +1 -0
  18. package/lib/api/sub-graph-schema-builder.d.ts +24 -0
  19. package/lib/api/sub-graph-schema-builder.mjs +147 -0
  20. package/lib/api/sub-graph-schema-builder.mjs.map +1 -0
  21. package/lib/config/env-config.cjs +6 -0
  22. package/lib/config/env-config.cjs.map +1 -1
  23. package/lib/config/env-config.d.ts +6 -0
  24. package/lib/config/env-config.mjs +6 -0
  25. package/lib/config/env-config.mjs.map +1 -1
  26. package/lib/examples/tenant-feature-example.d.ts +13 -0
  27. package/lib/examples/tenant-feature-integration.d.ts +14 -0
  28. package/lib/features/multi-module-example.d.ts +17 -0
  29. package/lib/index.cjs +1 -1
  30. package/lib/index.d.ts +1 -0
  31. package/lib/index.mjs +1 -1
  32. package/lib/infrastructure/container-module.cjs +27 -0
  33. package/lib/infrastructure/container-module.cjs.map +1 -0
  34. package/lib/infrastructure/container-module.d.ts +3 -0
  35. package/lib/infrastructure/container-module.mjs +27 -0
  36. package/lib/infrastructure/container-module.mjs.map +1 -0
  37. package/lib/infrastructure/example-workflows.d.ts +16 -0
  38. package/lib/infrastructure/index.d.ts +5 -0
  39. package/lib/infrastructure/infrastructure-factory.cjs +172 -0
  40. package/lib/infrastructure/infrastructure-factory.cjs.map +1 -0
  41. package/lib/infrastructure/infrastructure-factory.d.ts +36 -0
  42. package/lib/infrastructure/infrastructure-factory.mjs +172 -0
  43. package/lib/infrastructure/infrastructure-factory.mjs.map +1 -0
  44. package/lib/infrastructure/inngest-factory.cjs +47 -0
  45. package/lib/infrastructure/inngest-factory.cjs.map +1 -0
  46. package/lib/infrastructure/inngest-factory.d.ts +8 -0
  47. package/lib/infrastructure/inngest-factory.mjs +47 -0
  48. package/lib/infrastructure/inngest-factory.mjs.map +1 -0
  49. package/lib/infrastructure/types.d.ts +28 -0
  50. package/lib/infrastructure/usage-examples.d.ts +9 -0
  51. package/lib/infrastructure/workflow-orchestrator.cjs +59 -0
  52. package/lib/infrastructure/workflow-orchestrator.cjs.map +1 -0
  53. package/lib/infrastructure/workflow-orchestrator.d.ts +10 -0
  54. package/lib/infrastructure/workflow-orchestrator.mjs +59 -0
  55. package/lib/infrastructure/workflow-orchestrator.mjs.map +1 -0
  56. package/lib/inngest/client-id-generator.d.ts +29 -0
  57. package/lib/inngest/handler-factory.d.ts +24 -0
  58. package/lib/inngest/middleware/auto-resolve-invoke.middleware.cjs +275 -0
  59. package/lib/inngest/middleware/auto-resolve-invoke.middleware.cjs.map +1 -0
  60. package/lib/inngest/middleware/auto-resolve-invoke.middleware.d.ts +111 -0
  61. package/lib/inngest/middleware/auto-resolve-invoke.middleware.mjs +275 -0
  62. package/lib/inngest/middleware/auto-resolve-invoke.middleware.mjs.map +1 -0
  63. package/lib/inngest/middleware/function-reference-helper.cjs +363 -0
  64. package/lib/inngest/middleware/function-reference-helper.cjs.map +1 -0
  65. package/lib/inngest/middleware/function-reference-helper.d.ts +211 -0
  66. package/lib/inngest/middleware/function-reference-helper.mjs +363 -0
  67. package/lib/inngest/middleware/function-reference-helper.mjs.map +1 -0
  68. package/lib/inngest/middleware/index.d.ts +31 -0
  69. package/lib/inngest/middleware/types.d.ts +162 -0
  70. package/lib/inngest/multi-module-functions.d.ts +133 -0
  71. package/lib/inngest/setup.cjs +55 -0
  72. package/lib/inngest/setup.cjs.map +1 -0
  73. package/lib/inngest/setup.d.ts +10 -0
  74. package/lib/inngest/setup.mjs +55 -0
  75. package/lib/inngest/setup.mjs.map +1 -0
  76. package/lib/interfaces/graphql-request-context.d.ts +20 -0
  77. package/lib/interfaces/index.d.ts +1 -0
  78. package/lib/middleware/index.d.ts +5 -0
  79. package/lib/middleware/redis-client.cjs +18 -0
  80. package/lib/middleware/redis-client.cjs.map +1 -0
  81. package/lib/middleware/redis-client.d.ts +16 -0
  82. package/lib/middleware/redis-client.mjs +18 -0
  83. package/lib/middleware/redis-client.mjs.map +1 -0
  84. package/lib/plugins/index.d.ts +1 -0
  85. package/lib/plugins/invalidateCachePlugin.cjs +33 -10
  86. package/lib/plugins/invalidateCachePlugin.cjs.map +1 -1
  87. package/lib/plugins/invalidateCachePlugin.mjs +33 -10
  88. package/lib/plugins/invalidateCachePlugin.mjs.map +1 -1
  89. package/lib/plugins/responseCachePlugin.cjs +63 -0
  90. package/lib/plugins/responseCachePlugin.cjs.map +1 -0
  91. package/lib/plugins/responseCachePlugin.d.ts +12 -0
  92. package/lib/plugins/responseCachePlugin.mjs +63 -0
  93. package/lib/plugins/responseCachePlugin.mjs.map +1 -0
  94. package/lib/servers/ExpressApp.cjs +8 -3
  95. package/lib/servers/ExpressApp.cjs.map +1 -1
  96. package/lib/servers/ExpressApp.d.ts +1 -1
  97. package/lib/servers/ExpressApp.mjs +8 -3
  98. package/lib/servers/ExpressApp.mjs.map +1 -1
  99. package/lib/servers/GraphqlServer.cjs +10 -36
  100. package/lib/servers/GraphqlServer.cjs.map +1 -1
  101. package/lib/servers/GraphqlServer.d.ts +8 -6
  102. package/lib/servers/GraphqlServer.mjs +10 -36
  103. package/lib/servers/GraphqlServer.mjs.map +1 -1
  104. package/lib/servers/GraphqlWs.cjs +3 -44
  105. package/lib/servers/GraphqlWs.cjs.map +1 -1
  106. package/lib/servers/GraphqlWs.mjs +3 -44
  107. package/lib/servers/GraphqlWs.mjs.map +1 -1
  108. package/lib/servers/WebsocketMultipathUpdate.cjs +4 -2
  109. package/lib/servers/WebsocketMultipathUpdate.cjs.map +1 -1
  110. package/lib/servers/WebsocketMultipathUpdate.mjs +4 -2
  111. package/lib/servers/WebsocketMultipathUpdate.mjs.map +1 -1
  112. package/lib/servers/mongodb-migration-update.d.ts +1 -1
  113. package/lib/servers/websocket-context.cjs +70 -0
  114. package/lib/servers/websocket-context.cjs.map +1 -0
  115. package/lib/servers/websocket-context.d.ts +30 -0
  116. package/lib/servers/websocket-context.mjs +70 -0
  117. package/lib/servers/websocket-context.mjs.map +1 -0
  118. package/lib/utils/add-shareable-directive-to-schema.cjs +44 -0
  119. package/lib/utils/add-shareable-directive-to-schema.cjs.map +1 -0
  120. package/lib/utils/add-shareable-directive-to-schema.d.ts +1 -0
  121. package/lib/utils/add-shareable-directive-to-schema.mjs +44 -0
  122. package/lib/utils/add-shareable-directive-to-schema.mjs.map +1 -0
  123. package/lib/utils/index.d.ts +3 -0
  124. package/lib/utils/safe-model-factory.d.ts +18 -0
  125. package/package.json +15 -11
  126. package/lib/api/resolver.cjs +0 -12
  127. package/lib/api/resolver.cjs.map +0 -1
  128. package/lib/api/resolver.mjs +0 -12
  129. package/lib/api/resolver.mjs.map +0 -1
  130. package/lib/api/root-schema.graphqls.cjs +0 -2
  131. package/lib/api/root-schema.graphqls.cjs.map +0 -1
  132. package/lib/api/root-schema.graphqls.mjs +0 -2
  133. package/lib/api/root-schema.graphqls.mjs.map +0 -1
  134. package/lib/api/scalar.cjs +0 -16
  135. package/lib/api/scalar.cjs.map +0 -1
  136. package/lib/api/scalar.mjs +0 -16
  137. package/lib/api/scalar.mjs.map +0 -1
  138. package/lib/graphql/directives/index.cjs +0 -10
  139. package/lib/graphql/directives/index.cjs.map +0 -1
  140. package/lib/graphql/directives/index.d.ts +0 -7
  141. package/lib/graphql/directives/index.mjs +0 -10
  142. package/lib/graphql/directives/index.mjs.map +0 -1
  143. package/lib/graphql/index.d.ts +0 -2
  144. package/lib/graphql/schema/directives.graphql.cjs +0 -1
  145. package/lib/graphql/schema/directives.graphql.cjs.map +0 -1
  146. package/lib/graphql/schema/directives.graphql.mjs +0 -1
  147. package/lib/graphql/schema/directives.graphql.mjs.map +0 -1
  148. package/lib/graphql/schema/index.cjs +0 -1
  149. package/lib/graphql/schema/index.cjs.map +0 -1
  150. package/lib/graphql/schema/index.d.ts +0 -1
  151. package/lib/graphql/schema/index.mjs +0 -1
  152. package/lib/graphql/schema/index.mjs.map +0 -1
@@ -1,4 +1,4 @@
1
- import*as url from'url';import {WebSocketServer}from'ws';import {useServer}from'graphql-ws/lib/use/ws';class WebsocketMultiPathServer {
1
+ import*as url from'url';import {WebSocketServer}from'ws';import {useServer}from'graphql-ws/lib/use/ws';import {createWebSocketContext}from'./websocket-context.mjs';class WebsocketMultiPathServer {
2
2
  moduleService;
3
3
  cache;
4
4
  webSockets = {};
@@ -9,10 +9,12 @@ import*as url from'url';import {WebSocketServer}from'ws';import {useServer}from'
9
9
  this.cache = cache;
10
10
  this._graphqlWs = new WebSocketServer({ noServer: true, path: __GRAPHQL_ENDPOINT__ });
11
11
  this.webSockets[__GRAPHQL_ENDPOINT__] = this._graphqlWs;
12
- this.webSockets[__GRAPHQL_ENDPOINT__].on('connection', (ws, request) => {
12
+ this.webSockets[__GRAPHQL_ENDPOINT__].on('connection', () => {
13
13
  console.log('--REQUESTED CONNECTION--', this._graphqlWs);
14
14
  useServer({
15
15
  schema: moduleService.schema,
16
+ // Using shared context creation function to maintain consistency with GraphqlWs
17
+ context: async (ctx) => createWebSocketContext(ctx, moduleService, cache),
16
18
  }, this._graphqlWs);
17
19
  });
18
20
  for (let key in multiplePathConfig) {
@@ -1 +1 @@
1
- {"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IAAI,CAAC,YAAY,EAAE,EAAE,EAAE,OAAO,CAAC,CAAC;AAC9D,aAAC,CAAC,CAAC;AACP,SAAC,CAAC,CAAC;;;;;AAOH,QAAA,OAAO,UAAU,CAAC;KACrB;AAED,IAAA,IAAW,SAAS,GAAA;QAChB,OAAO,IAAI,CAAC,UAAU,CAAC;KAC1B;IACM,KAAK,GAAA;AACR,QAAA,KAAK,MAAM,GAAG,IAAI,IAAI,CAAC,UAAU,EAAE;YAC/B,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,CAAC;SAChC;KACJ;AACJ"}
@@ -1,5 +1,5 @@
1
- import { IModuleService } from '../interfaces';
2
1
  import { Schema, Connection as DBConnection } from 'mongoose';
2
+ import { IModuleService } from '../interfaces';
3
3
  export declare const MigrationSchema: Schema<any, import("mongoose").Model<any, any, any, any, any>, {}, {}, {}, {}, import("mongoose").DefaultSchemaOptions, {
4
4
  name: string;
5
5
  migrated_at?: Date;
@@ -0,0 +1,70 @@
1
+ 'use strict';/**
2
+ * Helper function to construct data sources for WebSocket subscriptions
3
+ *
4
+ * @workaround DataSources are an Apollo Server feature that only work with HTTP requests.
5
+ * When using graphql-ws for WebSocket subscriptions, we must manually initialize data sources
6
+ * because graphql-ws has a separate context pipeline from Apollo Server's HTTP pipeline.
7
+ *
8
+ * This is necessary as of:
9
+ * - Apollo Server v4.10.4
10
+ * - graphql-ws v5.11.2
11
+ *
12
+ * References:
13
+ * - Original issue: https://github.com/apollographql/apollo-server/issues/1526
14
+ * - Community solution: https://github.com/apollographql/apollo-server/issues/1526#issuecomment-502884432
15
+ * - graphql-ws context: https://github.com/enisdenjo/graphql-ws#context
16
+ */
17
+ const constructDataSourcesForSubscriptions = (context, cache, dataSources) => {
18
+ const initializeDataSource = (instance) => {
19
+ instance.initialize({ context, cache });
20
+ };
21
+ // tslint:disable-next-line:forin
22
+ for (const prop in dataSources) {
23
+ if (dataSources[prop] && typeof dataSources[prop]?.initialize === 'function') {
24
+ initializeDataSource(dataSources[prop]);
25
+ }
26
+ }
27
+ return dataSources;
28
+ };
29
+ /**
30
+ * Creates the WebSocket subscription context
31
+ * This function is shared between GraphqlWs and WebsocketMultiPathServer
32
+ * to ensure consistent context creation across all subscription endpoints.
33
+ *
34
+ * @param ctx - The graphql-ws context containing connectionParams
35
+ * @param moduleService - The module service for creating context
36
+ * @param cache - Redis cache instance
37
+ * @returns Promise<object> - The complete subscription context
38
+ */
39
+ async function createWebSocketContext(ctx, moduleService, cache) {
40
+ try {
41
+ const connectionParams = ctx.connectionParams || {};
42
+ const pureContext = await moduleService.createContext(connectionParams, null);
43
+ const contextServices = await moduleService.serviceContext(connectionParams, null);
44
+ const context = {
45
+ ...contextServices,
46
+ ...pureContext,
47
+ preferences: moduleService.defaultPreferences,
48
+ ...ctx,
49
+ };
50
+ const addons = {
51
+ dataSources: constructDataSourcesForSubscriptions(context, cache, moduleService.dataSource),
52
+ };
53
+ return {
54
+ ...context,
55
+ ...addons,
56
+ ...ctx,
57
+ ...pureContext,
58
+ preferences: moduleService.defaultPreferences,
59
+ };
60
+ }
61
+ catch (err) {
62
+ moduleService.logger.error('Error creating WebSocket context:', err);
63
+ // Return a minimal context to prevent crashes
64
+ return {
65
+ userContext: {},
66
+ req: {},
67
+ connectionParams: ctx.connectionParams || {},
68
+ };
69
+ }
70
+ }exports.constructDataSourcesForSubscriptions=constructDataSourcesForSubscriptions;exports.createWebSocketContext=createWebSocketContext;//# sourceMappingURL=websocket-context.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"websocket-context.cjs","sources":["../../src/servers/websocket-context.ts"],"sourcesContent":[null],"names":[],"mappings":"aAGA;;;;;;;;;;;;;;;AAeG;AACU,MAAA,oCAAoC,GAAG,CAAC,OAAY,EAAE,KAAU,EAAE,WAAgB,KAAI;AAC/F,IAAA,MAAM,oBAAoB,GAAG,CAAC,QAAa,KAAI;QAC3C,QAAQ,CAAC,UAAU,CAAC,EAAE,OAAO,EAAE,KAAK,E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E;AACf,YAAA,GAAG,EAAE,EAAE;AACP,YAAA,gBAAgB,EAAE,GAAG,CAAC,gBAAgB,IAAI,EAAE;SAC/C,CAAC;KACL;AACL"}
@@ -0,0 +1,30 @@
1
+ import * as IORedis from 'ioredis';
2
+ import { IModuleService } from '../interfaces';
3
+ /**
4
+ * Helper function to construct data sources for WebSocket subscriptions
5
+ *
6
+ * @workaround DataSources are an Apollo Server feature that only work with HTTP requests.
7
+ * When using graphql-ws for WebSocket subscriptions, we must manually initialize data sources
8
+ * because graphql-ws has a separate context pipeline from Apollo Server's HTTP pipeline.
9
+ *
10
+ * This is necessary as of:
11
+ * - Apollo Server v4.10.4
12
+ * - graphql-ws v5.11.2
13
+ *
14
+ * References:
15
+ * - Original issue: https://github.com/apollographql/apollo-server/issues/1526
16
+ * - Community solution: https://github.com/apollographql/apollo-server/issues/1526#issuecomment-502884432
17
+ * - graphql-ws context: https://github.com/enisdenjo/graphql-ws#context
18
+ */
19
+ export declare const constructDataSourcesForSubscriptions: (context: any, cache: any, dataSources: any) => any;
20
+ /**
21
+ * Creates the WebSocket subscription context
22
+ * This function is shared between GraphqlWs and WebsocketMultiPathServer
23
+ * to ensure consistent context creation across all subscription endpoints.
24
+ *
25
+ * @param ctx - The graphql-ws context containing connectionParams
26
+ * @param moduleService - The module service for creating context
27
+ * @param cache - Redis cache instance
28
+ * @returns Promise<object> - The complete subscription context
29
+ */
30
+ export declare function createWebSocketContext(ctx: any, moduleService: IModuleService, cache: IORedis.Redis | IORedis.Cluster): Promise<any>;
@@ -0,0 +1,70 @@
1
+ /**
2
+ * Helper function to construct data sources for WebSocket subscriptions
3
+ *
4
+ * @workaround DataSources are an Apollo Server feature that only work with HTTP requests.
5
+ * When using graphql-ws for WebSocket subscriptions, we must manually initialize data sources
6
+ * because graphql-ws has a separate context pipeline from Apollo Server's HTTP pipeline.
7
+ *
8
+ * This is necessary as of:
9
+ * - Apollo Server v4.10.4
10
+ * - graphql-ws v5.11.2
11
+ *
12
+ * References:
13
+ * - Original issue: https://github.com/apollographql/apollo-server/issues/1526
14
+ * - Community solution: https://github.com/apollographql/apollo-server/issues/1526#issuecomment-502884432
15
+ * - graphql-ws context: https://github.com/enisdenjo/graphql-ws#context
16
+ */
17
+ const constructDataSourcesForSubscriptions = (context, cache, dataSources) => {
18
+ const initializeDataSource = (instance) => {
19
+ instance.initialize({ context, cache });
20
+ };
21
+ // tslint:disable-next-line:forin
22
+ for (const prop in dataSources) {
23
+ if (dataSources[prop] && typeof dataSources[prop]?.initialize === 'function') {
24
+ initializeDataSource(dataSources[prop]);
25
+ }
26
+ }
27
+ return dataSources;
28
+ };
29
+ /**
30
+ * Creates the WebSocket subscription context
31
+ * This function is shared between GraphqlWs and WebsocketMultiPathServer
32
+ * to ensure consistent context creation across all subscription endpoints.
33
+ *
34
+ * @param ctx - The graphql-ws context containing connectionParams
35
+ * @param moduleService - The module service for creating context
36
+ * @param cache - Redis cache instance
37
+ * @returns Promise<object> - The complete subscription context
38
+ */
39
+ async function createWebSocketContext(ctx, moduleService, cache) {
40
+ try {
41
+ const connectionParams = ctx.connectionParams || {};
42
+ const pureContext = await moduleService.createContext(connectionParams, null);
43
+ const contextServices = await moduleService.serviceContext(connectionParams, null);
44
+ const context = {
45
+ ...contextServices,
46
+ ...pureContext,
47
+ preferences: moduleService.defaultPreferences,
48
+ ...ctx,
49
+ };
50
+ const addons = {
51
+ dataSources: constructDataSourcesForSubscriptions(context, cache, moduleService.dataSource),
52
+ };
53
+ return {
54
+ ...context,
55
+ ...addons,
56
+ ...ctx,
57
+ ...pureContext,
58
+ preferences: moduleService.defaultPreferences,
59
+ };
60
+ }
61
+ catch (err) {
62
+ moduleService.logger.error('Error creating WebSocket context:', err);
63
+ // Return a minimal context to prevent crashes
64
+ return {
65
+ userContext: {},
66
+ req: {},
67
+ connectionParams: ctx.connectionParams || {},
68
+ };
69
+ }
70
+ }export{constructDataSourcesForSubscriptions,createWebSocketContext};//# sourceMappingURL=websocket-context.mjs.map
@@ -0,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C;QAEF,OAAO;AACH,YAAA,GAAG,OAAO;AACV,YAAA,GAAG,MAAM;AACT,YAAA,GAAG,GAAG;AACN,YAAA,GAAG,WAAW;YACd,WAAW,EAAE,aAAa,CAAC,kBAAkB;SAChD,CAAC;KACL;IAAC,OAAO,GAAG,EAAE;QACV,aAAa,CAAC,MAAM,CAAC,KAAK,CAAC,mCAAmC,EAAE,GAAG,CAAC,CAAC;;QAErE,OAAO;AACH,YAAA,WAAW,EAAE,EAAE;AACf,YAAA,GAAG,EAAE,EAAE;AACP,YAAA,gBAAgB,EAAE,GAAG,CAAC,gBAAgB,IAAI,EAAE;SAC/C,CAAC;KACL;AACL"}
@@ -0,0 +1,44 @@
1
+ 'use strict';var graphql=require('graphql');const addShareableDirectiveToSchema = (schemaString) => {
2
+ const ast = graphql.parse(schemaString);
3
+ const modifiedAst = graphql.visit(ast, {
4
+ ObjectTypeDefinition(node) {
5
+ // Add @shareable directive to each type
6
+ const shareableDirective = {
7
+ kind: graphql.Kind.DIRECTIVE,
8
+ name: { kind: graphql.Kind.NAME, value: 'shareable' },
9
+ };
10
+ return {
11
+ ...node,
12
+ directives: [...(node.directives || []), shareableDirective],
13
+ };
14
+ },
15
+ ObjectTypeExtension(node) {
16
+ // Add @shareable directive to each extended type
17
+ const shareableDirective = {
18
+ kind: graphql.Kind.DIRECTIVE,
19
+ name: { kind: graphql.Kind.NAME, value: 'shareable' },
20
+ };
21
+ return {
22
+ ...node,
23
+ directives: [...(node.directives || []), shareableDirective],
24
+ };
25
+ },
26
+ FieldDefinition(node, _key, _parent, _path, ancestors) {
27
+ // Get the parent type definition from ancestors
28
+ const parent = ancestors[2];
29
+ // @ts-expect-error - parent is an object, but we need to check if it has a kind property
30
+ if (parent?.kind === graphql.Kind.OBJECT_TYPE_DEFINITION && parent.name.value === 'Query') {
31
+ const shareableDirective = {
32
+ kind: graphql.Kind.DIRECTIVE,
33
+ name: { kind: graphql.Kind.NAME, value: 'shareable' },
34
+ };
35
+ return {
36
+ ...node,
37
+ directives: [...(node.directives || []), shareableDirective],
38
+ };
39
+ }
40
+ return node;
41
+ },
42
+ });
43
+ return graphql.print(modifiedAst);
44
+ };exports.addShareableDirectiveToSchema=addShareableDirectiveToSchema;//# sourceMappingURL=add-shareable-directive-to-schema.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"add-shareable-directive-to-schema.cjs","sources":["../../src/utils/add-shareable-directive-to-schema.ts"],"sourcesContent":[null],"names":["parse","visit","Kind","print"],"mappings":"4CAEa,MAAA,6BAA6B,GAAG,CAAC,YAAoB,KAAI;AAClE,IAAA,MAAM,GAAG,GAAGA,aAAK,CAAC,YAAY,CAAC,CAAC;AAEhC,IAAA,MAAM,WAAW,GAAGC,aAAK,CAAC,GAAG,EAAE;AAC3B,QAAA,oBAAoB,CAAC,IAAI,EAAA;;AAErB,YAAA,MAAM,kBAAkB,GAAG;gBACvB,IAAI,EAAEC,YAAI,CAAC,SAAS;gBACpB,IAAI,EAAE,EAAE,IAAI,EAAEA,YAAI,CAAC,IAAI,EAAE,KAAK,EAAE,WAAW,EAAE;aAChD,CAAC;YAEF,OAAO;AACH,gBAAA,GAAG,IAAI;AACP,gBAAA,UAAU,EAAE,CAAC,IAAI,IAAI,CAAC,UAAU,IAAI,EAAE,CAAC,EAAE,kBAAkB,CAAC;aAC/D,CAAC;SACL;AACD,QAAA,mBAAmB,CAAC,IAAI,EAAA;;AAEpB,YAAA,MAAM,kBAAkB,GAAG;gBACvB,IAAI,EAAEA,YAAI,CAAC,SAAS;gBACpB,IAAI,EAAE,EAAE,IAAI,EAAEA,YAAI,CAAC,IAAI,EAAE,KAAK,EAAE,WAAW,EAAE;aAChD,CAAC;YAEF,OAAO;AACH,gBAAA,GAAG,IAAI;AACP,gBAAA,UAAU,EAAE,CAAC,IAAI,IAAI,CAAC,UAAU,IAAI,EAAE,CAAC,EAAE,kBAAkB,CAAC;aAC/D,CAAC;SACL;QACD,eAAe,CAAC,IAAI,EAAE,IAAI,EAAE,OAAO,EAAE,KAAK,EAAE,SAAS,EAAA;;AAEjD,YAAA,MAAM,MAAM,GAAG,SAAS,CAAC,CAAC,CAAC,CAAC;;AAE5B,YAAA,IAAI,MAAM,EAAE,IAAI,KAAKA,YAAI,CAAC,sBAAsB,IAAI,MAAM,CAAC,IAAI,CAAC,KAAK,KAAK,OAAO,EAAE;AAC/E,gBAAA,MAAM,kBAAkB,GAAG;oBACvB,IAAI,EAAEA,YAAI,CAAC,SAAS;oBACpB,IAAI,EAAE,EAAE,IAAI,EAAEA,YAAI,CAAC,IAAI,EAAE,KAAK,EAAE,WAAW,EAAE;iBAChD,CAAC;gBAEF,OAAO;AACH,oBAAA,GAAG,IAAI;AACP,oBAAA,UAAU,EAAE,CAAC,IAAI,IAAI,CAAC,UAAU,IAAI,EAAE,CAAC,EAAE,kBAAkB,CAAC;iBAC/D,CAAC;aACL;AACD,YAAA,OAAO,IAAI,CAAC;SACf;AACJ,KAAA,CAAC,CAAC;AAEH,IAAA,OAAOC,aAAK,CAAC,WAAW,CAAC,CAAC;AAC9B"}
@@ -0,0 +1 @@
1
+ export declare const addShareableDirectiveToSchema: (schemaString: string) => string;
@@ -0,0 +1,44 @@
1
+ import {parse,visit,Kind,print}from'graphql';const addShareableDirectiveToSchema = (schemaString) => {
2
+ const ast = parse(schemaString);
3
+ const modifiedAst = visit(ast, {
4
+ ObjectTypeDefinition(node) {
5
+ // Add @shareable directive to each type
6
+ const shareableDirective = {
7
+ kind: Kind.DIRECTIVE,
8
+ name: { kind: Kind.NAME, value: 'shareable' },
9
+ };
10
+ return {
11
+ ...node,
12
+ directives: [...(node.directives || []), shareableDirective],
13
+ };
14
+ },
15
+ ObjectTypeExtension(node) {
16
+ // Add @shareable directive to each extended type
17
+ const shareableDirective = {
18
+ kind: Kind.DIRECTIVE,
19
+ name: { kind: Kind.NAME, value: 'shareable' },
20
+ };
21
+ return {
22
+ ...node,
23
+ directives: [...(node.directives || []), shareableDirective],
24
+ };
25
+ },
26
+ FieldDefinition(node, _key, _parent, _path, ancestors) {
27
+ // Get the parent type definition from ancestors
28
+ const parent = ancestors[2];
29
+ // @ts-expect-error - parent is an object, but we need to check if it has a kind property
30
+ if (parent?.kind === Kind.OBJECT_TYPE_DEFINITION && parent.name.value === 'Query') {
31
+ const shareableDirective = {
32
+ kind: Kind.DIRECTIVE,
33
+ name: { kind: Kind.NAME, value: 'shareable' },
34
+ };
35
+ return {
36
+ ...node,
37
+ directives: [...(node.directives || []), shareableDirective],
38
+ };
39
+ }
40
+ return node;
41
+ },
42
+ });
43
+ return print(modifiedAst);
44
+ };export{addShareableDirectiveToSchema};//# sourceMappingURL=add-shareable-directive-to-schema.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"add-shareable-directive-to-schema.mjs","sources":["../../src/utils/add-shareable-directive-to-schema.ts"],"sourcesContent":[null],"names":[],"mappings":"6CAEa,MAAA,6BAA6B,GAAG,CAAC,YAAoB,KAAI;AAClE,IAAA,MAAM,GAAG,GAAG,KAAK,CAAC,YAAY,CAAC,CAAC;AAEhC,IAAA,MAAM,WAAW,GAAG,KAAK,CAAC,GAAG,EAAE;AAC3B,QAAA,oBAAoB,CAAC,IAAI,EAAA;;AAErB,YAAA,MAAM,kBAAkB,GAAG;gBACvB,IAAI,EAAE,IAAI,CAAC,SAAS;gBACpB,IAAI,EAAE,EAAE,IAAI,EAAE,IAAI,CAAC,IAAI,EAAE,KAAK,EAAE,WAAW,EAAE;aAChD,CAAC;YAEF,OAAO;AACH,gBAAA,GAAG,IAAI;AACP,gBAAA,UAAU,EAAE,CAAC,IAAI,IAAI,CAAC,UAAU,IAAI,EAAE,CAAC,EAAE,kBAAkB,CAAC;aAC/D,CAAC;SACL;AACD,QAAA,mBAAmB,CAAC,IAAI,EAAA;;AAEpB,YAAA,MAAM,kBAAkB,GAAG;gBACvB,IAAI,EAAE,IAAI,CAAC,SAAS;gBACpB,IAAI,EAAE,EAAE,IAAI,EAAE,IAAI,CAAC,IAAI,EAAE,KAAK,EAAE,WAAW,EAAE;aAChD,CAAC;YAEF,OAAO;AACH,gBAAA,GAAG,IAAI;AACP,gBAAA,UAAU,EAAE,CAAC,IAAI,IAAI,CAAC,UAAU,IAAI,EAAE,CAAC,EAAE,kBAAkB,CAAC;aAC/D,CAAC;SACL;QACD,eAAe,CAAC,IAAI,EAAE,IAAI,EAAE,OAAO,EAAE,KAAK,EAAE,SAAS,EAAA;;AAEjD,YAAA,MAAM,MAAM,GAAG,SAAS,CAAC,CAAC,CAAC,CAAC;;AAE5B,YAAA,IAAI,MAAM,EAAE,IAAI,KAAK,IAAI,CAAC,sBAAsB,IAAI,MAAM,CAAC,IAAI,CAAC,KAAK,KAAK,OAAO,EAAE;AAC/E,gBAAA,MAAM,kBAAkB,GAAG;oBACvB,IAAI,EAAE,IAAI,CAAC,SAAS;oBACpB,IAAI,EAAE,EAAE,IAAI,EAAE,IAAI,CAAC,IAAI,EAAE,KAAK,EAAE,WAAW,EAAE;iBAChD,CAAC;gBAEF,OAAO;AACH,oBAAA,GAAG,IAAI;AACP,oBAAA,UAAU,EAAE,CAAC,IAAI,IAAI,CAAC,UAAU,IAAI,EAAE,CAAC,EAAE,kBAAkB,CAAC;iBAC/D,CAAC;aACL;AACD,YAAA,OAAO,IAAI,CAAC;SACf;AACJ,KAAA,CAAC,CAAC;AAEH,IAAA,OAAO,KAAK,CAAC,WAAW,CAAC,CAAC;AAC9B"}
@@ -0,0 +1,3 @@
1
+ export * from './migrations';
2
+ export * from './add-shareable-directive-to-schema';
3
+ export * from './safe-model-factory';
@@ -0,0 +1,18 @@
1
+ import { Connection, Model, Schema } from 'mongoose';
2
+ /**
3
+ * Safely creates or retrieves a Mongoose model, preventing "Cannot overwrite model once compiled" errors
4
+ *
5
+ * @param db - MongoDB connection
6
+ * @param modelName - Name of the model
7
+ * @param schema - Mongoose schema (only used if model doesn't exist)
8
+ * @returns The Mongoose model
9
+ */
10
+ export declare function safeModelFactory<T = any>(db: Connection, modelName: string, schema?: Schema<T>): Model<T>;
11
+ /**
12
+ * Creates a model factory function that uses safe model registration
13
+ *
14
+ * @param modelName - Name of the model
15
+ * @param schema - Mongoose schema
16
+ * @returns A factory function that safely creates/retrieves the model
17
+ */
18
+ export declare function createSafeModelFactory<T = any>(modelName: string, schema: Schema<T>): (db: Connection) => Model<T>;
package/package.json CHANGED
@@ -1,8 +1,8 @@
1
1
  {
2
2
  "name": "@common-stack/server-stack",
3
- "version": "8.0.1-alpha.2",
3
+ "version": "8.2.1-alpha.0",
4
4
  "description": "common core for higher packages to depend on",
5
- "license": "ISC",
5
+ "license": "UNLICENSED",
6
6
  "author": "CDMBase LLC",
7
7
  "main": "lib/index.mjs",
8
8
  "module": "lib/index.mjs",
@@ -26,16 +26,14 @@
26
26
  "@apollo/datasource-rest": "^6.3.0",
27
27
  "@apollo/server": "^4.10.4",
28
28
  "@apollo/server-plugin-response-cache": "^4.1.3",
29
+ "@apollo/subgraph": "^2.7.1",
29
30
  "@apollo/utils.keyvadapter": "^3.1.0",
30
31
  "@casl/ability": "^4.1.5",
31
- "@cdm-logger/client": "^9.0.3",
32
- "@cdm-logger/server": "^9.0.3",
32
+ "@cdm-logger/client": "^9.0.8",
33
+ "@cdm-logger/server": "^9.0.15",
33
34
  "@cdmbase/graphql-type-uri": "^4.0.0",
34
- "@common-stack/cache-api-server": "8.0.1-alpha.0",
35
- "@common-stack/client-core": "8.0.1-alpha.0",
36
- "@common-stack/core": "8.0.1-alpha.0",
37
- "@common-stack/server-core": "8.0.1-alpha.0",
38
- "@common-stack/store-mongo": "8.0.1-alpha.2",
35
+ "@common-stack/codegen-zod": "8.2.1-alpha.0",
36
+ "@common-stack/graphql-api": "8.2.1-alpha.0",
39
37
  "@graphql-tools/links": "~9.0.1",
40
38
  "@graphql-tools/schema": "~10.0.6",
41
39
  "@graphql-tools/stitch": "~9.2.10",
@@ -64,6 +62,7 @@
64
62
  "graphql-tools": "~9.0.0",
65
63
  "graphql-type-json": "^0.3.1",
66
64
  "graphql-ws": "^5.11.2",
65
+ "inngest": "^3.32.5",
67
66
  "inversify": "~6.0.2",
68
67
  "ioredis": "^5.4.1",
69
68
  "isomorphic-fetch": "^2.2.1",
@@ -78,7 +77,12 @@
78
77
  "rxjs": "^7.8.1",
79
78
  "subscriptions-transport-ws": "^0.11.0",
80
79
  "universal-cookie-express": "^4.0.1",
81
- "ws": "^8.11.0"
80
+ "ws": "^8.11.0",
81
+ "zod": "^4.0.0"
82
+ },
83
+ "devDependencies": {
84
+ "@common-stack/server-core": "8.2.1-alpha.0",
85
+ "common": "8.2.1-alpha.0"
82
86
  },
83
87
  "peerDependencies": {
84
88
  "@cdm-logger/core": ">=7.0.12",
@@ -91,5 +95,5 @@
91
95
  "typescript": {
92
96
  "definition": "lib/index.d.ts"
93
97
  },
94
- "gitHead": "740324071e77326fc0d9dd3ce4a1bc4a64a472f8"
98
+ "gitHead": "b46db06f987271c3a2e050f081e266d3a01b285b"
95
99
  }
@@ -1,12 +0,0 @@
1
- 'use strict';var GraphQLJSON=require('graphql-type-json'),graphqlScalars=require('graphql-scalars'),GraphQLURISource=require('@cdmbase/graphql-type-uri'),scalar=require('./scalar.cjs');/* eslint-disable import/no-extraneous-dependencies */
2
- const GraphQLURI = GraphQLURISource.default ?? GraphQLURISource;
3
- const resolvers = {
4
- AnyObject: scalar.GraphQLAnyObject,
5
- Date: graphqlScalars.GraphQLDate,
6
- Time: graphqlScalars.GraphQLTime,
7
- URI: GraphQLURI('URI'),
8
- URIInput: GraphQLURI('URIInput'),
9
- DateTime: graphqlScalars.GraphQLDateTime,
10
- JSON: GraphQLJSON,
11
- JSONObject: GraphQLJSON.GraphQLJSONObject,
12
- };exports.resolvers=resolvers;//# sourceMappingURL=resolver.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"resolver.cjs","sources":["../../src/api/resolver.ts"],"sourcesContent":[null],"names":["GraphQLAnyObject","GraphQLDate","GraphQLTime","GraphQLDateTime","GraphQLJSONObject"],"mappings":"yLAAA;AAMA,MAAM,UAAU,GAAI,gBAAwB,CAAC,OAAO,IAAI,gBAAgB,CAAC;AAC5D,MAAA,SAAS,GAAG;AACrB,IAAA,SAAS,EAAEA,uBAAgB;AAC3B,IAAA,IAAI,EAAEC,0BAAW;AACjB,IAAA,IAAI,EAAEC,0BAAW;AACjB,IAAA,GAAG,EAAE,UAAU,CAAC,KAAK,CAAC;AACtB,IAAA,QAAQ,EAAE,UAAU,CAAC,UAAU,CAAC;AAChC,IAAA,QAAQ,EAAEC,8BAAe;AACzB,IAAA,IAAI,EAAE,WAAW;AACjB,IAAA,UAAU,EAAEC,6BAAiB;"}
@@ -1,12 +0,0 @@
1
- import GraphQLJSON,{GraphQLJSONObject}from'graphql-type-json';import {GraphQLDate,GraphQLTime,GraphQLDateTime}from'graphql-scalars';import GraphQLURISource from'@cdmbase/graphql-type-uri';import {GraphQLAnyObject}from'./scalar.mjs';/* eslint-disable import/no-extraneous-dependencies */
2
- const GraphQLURI = GraphQLURISource.default ?? GraphQLURISource;
3
- const resolvers = {
4
- AnyObject: GraphQLAnyObject,
5
- Date: GraphQLDate,
6
- Time: GraphQLTime,
7
- URI: GraphQLURI('URI'),
8
- URIInput: GraphQLURI('URIInput'),
9
- DateTime: GraphQLDateTime,
10
- JSON: GraphQLJSON,
11
- JSONObject: GraphQLJSONObject,
12
- };export{resolvers};//# sourceMappingURL=resolver.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"resolver.mjs","sources":["../../src/api/resolver.ts"],"sourcesContent":[null],"names":[],"mappings":"wOAAA;AAMA,MAAM,UAAU,GAAI,gBAAwB,CAAC,OAAO,IAAI,gBAAgB,CAAC;AAC5D,MAAA,SAAS,GAAG;AACrB,IAAA,SAAS,EAAE,gBAAgB;AAC3B,IAAA,IAAI,EAAE,WAAW;AACjB,IAAA,IAAI,EAAE,WAAW;AACjB,IAAA,GAAG,EAAE,UAAU,CAAC,KAAK,CAAC;AACtB,IAAA,QAAQ,EAAE,UAAU,CAAC,UAAU,CAAC;AAChC,IAAA,QAAQ,EAAE,eAAe;AACzB,IAAA,IAAI,EAAE,WAAW;AACjB,IAAA,UAAU,EAAE,iBAAiB;"}
@@ -1,2 +0,0 @@
1
- 'use strict';Object.defineProperty(exports,'__esModule',{value:true});var rootSchemaDef = "scalar AnyObject\nscalar Date\nscalar Time\nscalar DateTime\nscalar Timestamp\nscalar URI\nscalar URIInput\nscalar Observable\nscalar JSON\nscalar JSONObject\n\n\"\"\"\n An object with an ID.\n\"\"\"\ninterface Node {\n \"\"\"\n The ID of the node.\n \"\"\"\n id: ID!\n}\n\n# Pagination information. See https://facebook.github.io/relay/graphql/connections.htm#sec-undefined.PageInfo.\ntype PageInfo {\n # Whether there is a next page of nodes in the connection.\n hasNextPage: Boolean!\n}\n\n\"\"\"\n Represents a null return value.\n\"\"\"\ntype EmptyResponse {\n # A dummy null value.\n alwaysNil: String\n}\n\ntype FieldError {\n field: String!\n message: String!\n}\n\ninput Sort{\n key: String!,\n value: SortEnum!,\n}\n\nenum SortEnum{\n ASC\n DESC\n}\n\ntype Query {\n \"\"\"\n Looks up a node by ID.\n \"\"\"\n node(id: ID!): Node\n\n}\n\ntype Mutation {\n dummy: Int\n}\n\ntype Subscription {\n dummy: Int\n}\n\n\ntype AdminIdeSettings {\n dummy: Int\n}\n\n\"\"\" All Moleculer Topic names are extended from this.\"\"\"\nenum MoleculerServiceName {\n dummy\n}\n\ninterface IResourceUtilizationSettings {\n subTopic: String\n adminApiNamespace: String\n}\n\n\"\"\"\nTo calculate geometry over an Eath-like sphere.\nList the `longitude` first and then `latitude`\n - Validate longitude values are between `-180` and `180`\n - Validate latitude values are between `-90` and `90`\n\"\"\"\ntype GeoLocation {\n coordinates: [Float]\n}\n\"\"\"\nInput geometry of the location.\nList the `longitude` first and then `latitude`\n - Validate longitude values are between `-180` and `180`\n - Validate latitude values are between `-90` and `90`\n\"\"\"\ninput GeoLocationInput {\n type: String = \"Point\"\n coordinates: [Float]\n}\n\n\"\"\"\nInput geometry of the location.\nList the `longitude` first and then `latitude`\n - Validate longitude values are between `-180` and `180`\n - Validate latitude values are between `-90` and `90`\n\"\"\"\ninput GeoLocationInput {\n type: String = \"Point\"\n coordinates: [Float]\n}\n\nenum MailTemplateId {\n dummy\n}\n\nenum MoleculerCronServiceName {\n dummy\n}\n\nschema {\n query: Query\n mutation: Mutation\n subscription: Subscription\n}\n\n";
2
- exports.default=rootSchemaDef;//# sourceMappingURL=root-schema.graphqls.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"root-schema.graphqls.cjs","sources":[],"sourcesContent":[],"names":[],"mappings":";"}
@@ -1,2 +0,0 @@
1
- var rootSchemaDef = "scalar AnyObject\nscalar Date\nscalar Time\nscalar DateTime\nscalar Timestamp\nscalar URI\nscalar URIInput\nscalar Observable\nscalar JSON\nscalar JSONObject\n\n\"\"\"\n An object with an ID.\n\"\"\"\ninterface Node {\n \"\"\"\n The ID of the node.\n \"\"\"\n id: ID!\n}\n\n# Pagination information. See https://facebook.github.io/relay/graphql/connections.htm#sec-undefined.PageInfo.\ntype PageInfo {\n # Whether there is a next page of nodes in the connection.\n hasNextPage: Boolean!\n}\n\n\"\"\"\n Represents a null return value.\n\"\"\"\ntype EmptyResponse {\n # A dummy null value.\n alwaysNil: String\n}\n\ntype FieldError {\n field: String!\n message: String!\n}\n\ninput Sort{\n key: String!,\n value: SortEnum!,\n}\n\nenum SortEnum{\n ASC\n DESC\n}\n\ntype Query {\n \"\"\"\n Looks up a node by ID.\n \"\"\"\n node(id: ID!): Node\n\n}\n\ntype Mutation {\n dummy: Int\n}\n\ntype Subscription {\n dummy: Int\n}\n\n\ntype AdminIdeSettings {\n dummy: Int\n}\n\n\"\"\" All Moleculer Topic names are extended from this.\"\"\"\nenum MoleculerServiceName {\n dummy\n}\n\ninterface IResourceUtilizationSettings {\n subTopic: String\n adminApiNamespace: String\n}\n\n\"\"\"\nTo calculate geometry over an Eath-like sphere.\nList the `longitude` first and then `latitude`\n - Validate longitude values are between `-180` and `180`\n - Validate latitude values are between `-90` and `90`\n\"\"\"\ntype GeoLocation {\n coordinates: [Float]\n}\n\"\"\"\nInput geometry of the location.\nList the `longitude` first and then `latitude`\n - Validate longitude values are between `-180` and `180`\n - Validate latitude values are between `-90` and `90`\n\"\"\"\ninput GeoLocationInput {\n type: String = \"Point\"\n coordinates: [Float]\n}\n\n\"\"\"\nInput geometry of the location.\nList the `longitude` first and then `latitude`\n - Validate longitude values are between `-180` and `180`\n - Validate latitude values are between `-90` and `90`\n\"\"\"\ninput GeoLocationInput {\n type: String = \"Point\"\n coordinates: [Float]\n}\n\nenum MailTemplateId {\n dummy\n}\n\nenum MoleculerCronServiceName {\n dummy\n}\n\nschema {\n query: Query\n mutation: Mutation\n subscription: Subscription\n}\n\n";
2
- export{rootSchemaDef as default};//# sourceMappingURL=root-schema.graphqls.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"root-schema.graphqls.mjs","sources":[],"sourcesContent":[],"names":[],"mappings":";"}
@@ -1,16 +0,0 @@
1
- 'use strict';var graphql=require('graphql');// add any scalar types
2
- // https://stackoverflow.com/questions/41557536/custom-map-keys-in-graphql-response
3
- const GraphQLAnyObject = new graphql.GraphQLScalarType({
4
- name: 'AnyObject',
5
- description: 'Any JSON object. This type bypasses type checking.',
6
- serialize: (value) => value,
7
- parseValue: (value) => value,
8
- parseLiteral: (ast) => {
9
- if (ast.kind !== graphql.Kind.OBJECT) {
10
- throw new graphql.GraphQLError(`Query error: Can only parse object but got a: ${ast.kind}`, {
11
- nodes: [ast],
12
- });
13
- }
14
- return ast.fields;
15
- },
16
- });exports.GraphQLAnyObject=GraphQLAnyObject;//# sourceMappingURL=scalar.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"scalar.cjs","sources":["../../src/api/scalar.ts"],"sourcesContent":[null],"names":["GraphQLScalarType","Kind","GraphQLError"],"mappings":"4CAAA;AAGA;AACa,MAAA,gBAAgB,GAAG,IAAIA,yBAAiB,CAAC;AAClD,IAAA,IAAI,EAAE,WAAW;AACjB,IAAA,WAAW,EAAE,oDAAoD;AACjE,IAAA,SAAS,EAAE,CAAC,KAAK,KAAK,KAAK;AAC3B,IAAA,UAAU,EAAE,CAAC,KAAK,KAAK,KAAK;AAC5B,IAAA,YAAY,EAAE,CAAC,GAAG,KAAI;QAClB,IAAI,GAAG,CAAC,IAAI,KAAKC,YAAI,CAAC,MAAM,EAAE;YAC1B,MAAM,IAAIC,oBAAY,CAAC,CAAA,8CAAA,EAAiD,GAAG,CAAC,IAAI,EAAE,EAAE;gBAChF,KAAK,EAAE,CAAC,GAAG,CAAC;AACf,aAAA,CAAC,CAAC;SACN;QACD,OAAO,GAAG,CAAC,MAAM,CAAC;KACrB;AACJ,CAAA"}
@@ -1,16 +0,0 @@
1
- import {GraphQLScalarType,Kind,GraphQLError}from'graphql';// add any scalar types
2
- // https://stackoverflow.com/questions/41557536/custom-map-keys-in-graphql-response
3
- const GraphQLAnyObject = new GraphQLScalarType({
4
- name: 'AnyObject',
5
- description: 'Any JSON object. This type bypasses type checking.',
6
- serialize: (value) => value,
7
- parseValue: (value) => value,
8
- parseLiteral: (ast) => {
9
- if (ast.kind !== Kind.OBJECT) {
10
- throw new GraphQLError(`Query error: Can only parse object but got a: ${ast.kind}`, {
11
- nodes: [ast],
12
- });
13
- }
14
- return ast.fields;
15
- },
16
- });export{GraphQLAnyObject};//# sourceMappingURL=scalar.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"scalar.mjs","sources":["../../src/api/scalar.ts"],"sourcesContent":[null],"names":[],"mappings":"0DAAA;AAGA;AACa,MAAA,gBAAgB,GAAG,IAAI,iBAAiB,CAAC;AAClD,IAAA,IAAI,EAAE,WAAW;AACjB,IAAA,WAAW,EAAE,oDAAoD;AACjE,IAAA,SAAS,EAAE,CAAC,KAAK,KAAK,KAAK;AAC3B,IAAA,UAAU,EAAE,CAAC,KAAK,KAAK,KAAK;AAC5B,IAAA,YAAY,EAAE,CAAC,GAAG,KAAI;QAClB,IAAI,GAAG,CAAC,IAAI,KAAK,IAAI,CAAC,MAAM,EAAE;YAC1B,MAAM,IAAI,YAAY,CAAC,CAAA,8CAAA,EAAiD,GAAG,CAAC,IAAI,EAAE,EAAE;gBAChF,KAAK,EAAE,CAAC,GAAG,CAAC;AACf,aAAA,CAAC,CAAC;SACN;QACD,OAAO,GAAG,CAAC,MAAM,CAAC;KACrB;AACJ,CAAA"}
@@ -1,10 +0,0 @@
1
- 'use strict';const serverDirectives = (_) => ({
2
- invalidateCache(next, source, { queries }, context) {
3
- context.queriesToInvalidate = queries;
4
- return next();
5
- },
6
- cacheControl(next, source, args, context) {
7
- context.overallCachePolicy = args;
8
- return next();
9
- },
10
- });exports.serverDirectives=serverDirectives;//# sourceMappingURL=index.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.cjs","sources":["../../../src/graphql/directives/index.ts"],"sourcesContent":[null],"names":[],"mappings":"mBAEa,gBAAgB,GAAG,CAAC,CAAoB,MAAM;IACvD,eAAe,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,OAAO,EAAE,EAAE,OAAO,EAAA;AAC9C,QAAA,OAAO,CAAC,mBAAmB,GAAG,OAAO,CAAC;QACtC,OAAO,IAAI,EAAE,CAAC;KACjB;AACD,IAAA,YAAY,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,OAAO,EAAA;AACpC,QAAA,OAAO,CAAC,kBAAkB,GAAG,IAAI,CAAC;QAClC,OAAO,IAAI,EAAE,CAAC;KACjB;AACJ,CAAA"}
@@ -1,7 +0,0 @@
1
- import { IDirectiveOptions } from '@common-stack/server-core';
2
- export declare const serverDirectives: (_: IDirectiveOptions) => {
3
- invalidateCache(next: any, source: any, { queries }: {
4
- queries: any;
5
- }, context: any): any;
6
- cacheControl(next: any, source: any, args: any, context: any): any;
7
- };
@@ -1,10 +0,0 @@
1
- const serverDirectives = (_) => ({
2
- invalidateCache(next, source, { queries }, context) {
3
- context.queriesToInvalidate = queries;
4
- return next();
5
- },
6
- cacheControl(next, source, args, context) {
7
- context.overallCachePolicy = args;
8
- return next();
9
- },
10
- });export{serverDirectives};//# sourceMappingURL=index.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.mjs","sources":["../../../src/graphql/directives/index.ts"],"sourcesContent":[null],"names":[],"mappings":"MAEa,gBAAgB,GAAG,CAAC,CAAoB,MAAM;IACvD,eAAe,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,OAAO,EAAE,EAAE,OAAO,EAAA;AAC9C,QAAA,OAAO,CAAC,mBAAmB,GAAG,OAAO,CAAC;QACtC,OAAO,IAAI,EAAE,CAAC;KACjB;AACD,IAAA,YAAY,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,OAAO,EAAA;AACpC,QAAA,OAAO,CAAC,kBAAkB,GAAG,IAAI,CAAC;QAClC,OAAO,IAAI,EAAE,CAAC;KACjB;AACJ,CAAA"}
@@ -1,2 +0,0 @@
1
- export * from './directives';
2
- export * from './schema';
@@ -1 +0,0 @@
1
- 'use strict';Object.defineProperty(exports,'__esModule',{value:true});var directive = "directive @invalidateCache(queries:[String!]!) on MUTATION | FIELD_DEFINITION\n\nenum CacheControlScope {\n PUBLIC\n PRIVATE\n}\n\ndirective @cacheControl(\n maxAge: Int\n scope: CacheControlScope\n inheritMaxAge: Boolean\n) on FIELD_DEFINITION | OBJECT | INTERFACE | UNION\n";exports.default=directive;//# sourceMappingURL=directives.graphql.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"directives.graphql.cjs","sources":[],"sourcesContent":[],"names":[],"mappings":""}
@@ -1 +0,0 @@
1
- var directive = "directive @invalidateCache(queries:[String!]!) on MUTATION | FIELD_DEFINITION\n\nenum CacheControlScope {\n PUBLIC\n PRIVATE\n}\n\ndirective @cacheControl(\n maxAge: Int\n scope: CacheControlScope\n inheritMaxAge: Boolean\n) on FIELD_DEFINITION | OBJECT | INTERFACE | UNION\n";export{directive as default};//# sourceMappingURL=directives.graphql.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"directives.graphql.mjs","sources":[],"sourcesContent":[],"names":[],"mappings":""}
@@ -1 +0,0 @@
1
- 'use strict';var directives=require('./directives.graphql.cjs');const schema = [directives.default].join('\n');exports.schema=schema;//# sourceMappingURL=index.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.cjs","sources":["../../../src/graphql/schema/index.ts"],"sourcesContent":[null],"names":["directive"],"mappings":"gEAEO,MAAM,MAAM,GAAG,CAACA,kBAAS,CAAC,CAAC,IAAI,CAAC,IAAI"}
@@ -1 +0,0 @@
1
- export declare const schema: string;
@@ -1 +0,0 @@
1
- import directive from'./directives.graphql.mjs';const schema = [directive].join('\n');export{schema};//# sourceMappingURL=index.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.mjs","sources":["../../../src/graphql/schema/index.ts"],"sourcesContent":[null],"names":[],"mappings":"gDAEO,MAAM,MAAM,GAAG,CAAC,SAAS,CAAC,CAAC,IAAI,CAAC,IAAI"}