@common-stack/server-stack 8.0.2-alpha.0 → 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 (147) hide show
  1. package/LICENSE +34 -21
  2. package/lib/MainStackServer.cjs +126 -146
  3. package/lib/MainStackServer.cjs.map +1 -1
  4. package/lib/MainStackServer.d.ts +12 -6
  5. package/lib/MainStackServer.mjs +126 -146
  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 +5 -0
  77. package/lib/middleware/index.d.ts +5 -0
  78. package/lib/middleware/redis-client.cjs +18 -0
  79. package/lib/middleware/redis-client.cjs.map +1 -0
  80. package/lib/middleware/redis-client.d.ts +16 -0
  81. package/lib/middleware/redis-client.mjs +18 -0
  82. package/lib/middleware/redis-client.mjs.map +1 -0
  83. package/lib/plugins/responseCachePlugin.cjs +2 -2
  84. package/lib/plugins/responseCachePlugin.cjs.map +1 -1
  85. package/lib/plugins/responseCachePlugin.mjs +2 -2
  86. package/lib/plugins/responseCachePlugin.mjs.map +1 -1
  87. package/lib/servers/ExpressApp.cjs +8 -3
  88. package/lib/servers/ExpressApp.cjs.map +1 -1
  89. package/lib/servers/ExpressApp.d.ts +1 -1
  90. package/lib/servers/ExpressApp.mjs +8 -3
  91. package/lib/servers/ExpressApp.mjs.map +1 -1
  92. package/lib/servers/GraphqlServer.cjs +7 -2
  93. package/lib/servers/GraphqlServer.cjs.map +1 -1
  94. package/lib/servers/GraphqlServer.d.ts +8 -6
  95. package/lib/servers/GraphqlServer.mjs +7 -2
  96. package/lib/servers/GraphqlServer.mjs.map +1 -1
  97. package/lib/servers/GraphqlWs.cjs +3 -44
  98. package/lib/servers/GraphqlWs.cjs.map +1 -1
  99. package/lib/servers/GraphqlWs.mjs +3 -44
  100. package/lib/servers/GraphqlWs.mjs.map +1 -1
  101. package/lib/servers/WebsocketMultipathUpdate.cjs +4 -2
  102. package/lib/servers/WebsocketMultipathUpdate.cjs.map +1 -1
  103. package/lib/servers/WebsocketMultipathUpdate.mjs +4 -2
  104. package/lib/servers/WebsocketMultipathUpdate.mjs.map +1 -1
  105. package/lib/servers/mongodb-migration-update.d.ts +1 -1
  106. package/lib/servers/websocket-context.cjs +70 -0
  107. package/lib/servers/websocket-context.cjs.map +1 -0
  108. package/lib/servers/websocket-context.d.ts +30 -0
  109. package/lib/servers/websocket-context.mjs +70 -0
  110. package/lib/servers/websocket-context.mjs.map +1 -0
  111. package/lib/utils/add-shareable-directive-to-schema.cjs +44 -0
  112. package/lib/utils/add-shareable-directive-to-schema.cjs.map +1 -0
  113. package/lib/utils/add-shareable-directive-to-schema.d.ts +1 -0
  114. package/lib/utils/add-shareable-directive-to-schema.mjs +44 -0
  115. package/lib/utils/add-shareable-directive-to-schema.mjs.map +1 -0
  116. package/lib/utils/index.d.ts +2 -0
  117. package/lib/utils/safe-model-factory.d.ts +18 -0
  118. package/package.json +15 -11
  119. package/lib/api/resolver.cjs +0 -12
  120. package/lib/api/resolver.cjs.map +0 -1
  121. package/lib/api/resolver.mjs +0 -12
  122. package/lib/api/resolver.mjs.map +0 -1
  123. package/lib/api/root-schema.graphqls.cjs +0 -2
  124. package/lib/api/root-schema.graphqls.cjs.map +0 -1
  125. package/lib/api/root-schema.graphqls.mjs +0 -2
  126. package/lib/api/root-schema.graphqls.mjs.map +0 -1
  127. package/lib/api/scalar.cjs +0 -16
  128. package/lib/api/scalar.cjs.map +0 -1
  129. package/lib/api/scalar.mjs +0 -16
  130. package/lib/api/scalar.mjs.map +0 -1
  131. package/lib/graphql/directives/index.cjs +0 -10
  132. package/lib/graphql/directives/index.cjs.map +0 -1
  133. package/lib/graphql/directives/index.d.ts +0 -7
  134. package/lib/graphql/directives/index.mjs +0 -10
  135. package/lib/graphql/directives/index.mjs.map +0 -1
  136. package/lib/graphql/index.d.ts +0 -2
  137. package/lib/graphql/schema/directives.graphql.cjs +0 -1
  138. package/lib/graphql/schema/directives.graphql.cjs.map +0 -1
  139. package/lib/graphql/schema/directives.graphql.mjs +0 -1
  140. package/lib/graphql/schema/directives.graphql.mjs.map +0 -1
  141. package/lib/graphql/schema/index.cjs +0 -1
  142. package/lib/graphql/schema/index.cjs.map +0 -1
  143. package/lib/graphql/schema/index.d.ts +0 -1
  144. package/lib/graphql/schema/index.mjs +0 -1
  145. package/lib/graphql/schema/index.mjs.map +0 -1
  146. package/lib/plugins/invalidateCachePlugin.test.d.ts +0 -1
  147. package/lib/plugins/response-cache-plugin.test.d.ts +0 -1
@@ -0,0 +1,47 @@
1
+ 'use strict';var inngest=require('inngest'),envConfig=require('../config/env-config.cjs'),autoResolveInvoke_middleware=require('../inngest/middleware/auto-resolve-invoke.middleware.cjs'),functionReferenceHelper=require('../inngest/middleware/function-reference-helper.cjs');const generateInngestClientId = (configParams, logger) => {
2
+ const { APP_NAME, NODE_ENV, INNGEST_CLIENT_ID } = configParams;
3
+ if (INNGEST_CLIENT_ID) {
4
+ return INNGEST_CLIENT_ID;
5
+ }
6
+ const inngestId = `${APP_NAME}-${NODE_ENV}-${Date.now()}`;
7
+ logger.info(`Generated Inngest client ID: ${inngestId}`);
8
+ return inngestId;
9
+ };
10
+ const createInngestClient = (logger) => {
11
+ // Generate unique Inngest client ID for multi-developer environments
12
+ const inngestId = generateInngestClientId({
13
+ APP_NAME: envConfig.config.APP_NAME,
14
+ NODE_ENV: envConfig.config.NODE_ENV,
15
+ INNGEST_CLIENT_ID: envConfig.config.INNGEST_CLIENT_ID,
16
+ }, logger);
17
+ // Create middleware instance (will be populated with functions later)
18
+ const autoResolveMiddleware = autoResolveInvoke_middleware.createCommonStackAutoResolveMiddleware({
19
+ debug: envConfig.config.NODE_ENV === 'development',
20
+ customMappings: {
21
+ // Add any special case mappings here if needed
22
+ // Example: 'short-name': 'full-function-id'
23
+ },
24
+ });
25
+ // Create combined function reference middleware
26
+ // This provides both manual referenceFunction() and auto-resolve capabilities
27
+ const combinedMiddleware = functionReferenceHelper.createCombinedFunctionMiddleware({
28
+ autoResolve: true, // Enable automatic function resolution
29
+ debug: envConfig.config.NODE_ENV === 'development',
30
+ });
31
+ // Create Inngest client
32
+ const client = new inngest.Inngest({
33
+ id: inngestId,
34
+ eventKey: envConfig.config.INNGEST_EVENT_KEY,
35
+ signingKey: envConfig.config.INNGEST_SIGNING_KEY,
36
+ isDev: envConfig.config.INNGEST_IS_DEV,
37
+ env: envConfig.config.INNGEST_ENVIRONMENT,
38
+ baseUrl: envConfig.config.INNGEST_BASE_URL,
39
+ // ✨ Combined middleware stack:
40
+ // 1. Combined middleware - provides referenceFunction() + auto-resolve
41
+ // 2. Legacy auto-resolve - for backward compatibility
42
+ middleware: [combinedMiddleware, autoResolveMiddleware],
43
+ });
44
+ // Store middleware reference for later function registration
45
+ client._autoResolveMiddleware = autoResolveMiddleware;
46
+ return client;
47
+ };exports.createInngestClient=createInngestClient;exports.generateInngestClientId=generateInngestClientId;//# sourceMappingURL=inngest-factory.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"inngest-factory.cjs","sources":["../../src/infrastructure/inngest-factory.ts"],"sourcesContent":[null],"names":["config","createCommonStackAutoResolveMiddleware","createCombinedFunctionMiddleware","Inngest"],"mappings":"wRAMa,uBAAuB,GAAG,CACnC,YAIC,EACD,MAAyB,KACjB;IACR,MAAM,EAAE,QAAQ,EAAE,QAAQ,EAAE,iBAAiB,EAAE,GAAG,YAAY,CAAC;IAE/D,IAAI,iBAAiB,EAAE;AACnB,QAAA,OAAO,iBAAiB,CAAC;KAC5B;AAED,IAAA,MAAM,SAAS,GAAG,CAAG,EAAA,QAAQ,CAAI,CAAA,EAAA,QAAQ,CAAI,CAAA,EAAA,IAAI,CAAC,GAAG,EAAE,CAAA,CAAE,CAAC;AAC1D,IAAA,MAAM,CAAC,IAAI,CAAC,gCAAgC,SAAS,CAAA,CAAE,CAAC,CAAC;AACzD,IAAA,OAAO,SAAS,CAAC;AACrB,EAAE;AAEW,MAAA,mBAAmB,GAAG,CAAC,MAAyB,KAAa;;IAEtE,MAAM,SAAS,GAAG,uBAAuB,CACrC;QACI,QAAQ,EAAEA,gBAAM,CAAC,QAAQ;QACzB,QAAQ,EAAEA,gBAAM,CAAC,QAAQ;QACzB,iBAAiB,EAAEA,gBAAM,CAAC,iBAAiB;KAC9C,EACD,MAAM,CACT,CAAC;;IAGF,MAAM,qBAAqB,GAAGC,mEAAsC,CAAC;AACjE,QAAA,KAAK,EAAED,gBAAM,CAAC,QAAQ,KAAK,aAAa;AACxC,QAAA,cAAc,EAAE;;;AAGf,SAAA;AACJ,KAAA,CAAC,CAAC;;;IAIH,MAAM,kBAAkB,GAAGE,wDAAgC,CAAC;QACxD,WAAW,EAAE,IAAI;AACjB,QAAA,KAAK,EAAEF,gBAAM,CAAC,QAAQ,KAAK,aAAa;AAC3C,KAAA,CAAC,CAAC;;AAGH,IAAA,MAAM,MAAM,GAAG,IAAIG,eAAO,CAAC;AACvB,QAAA,EAAE,EAAE,SAAS;QACb,QAAQ,EAAEH,gBAAM,CAAC,iBAAiB;QAClC,UAAU,EAAEA,gBAAM,CAAC,mBAAmB;QACtC,KAAK,EAAEA,gBAAM,CAAC,cAAc;QAC5B,GAAG,EAAEA,gBAAM,CAAC,mBAAmB;QAC/B,OAAO,EAAEA,gBAAM,CAAC,gBAAgB;;;;AAKhC,QAAA,UAAU,EAAE,CAAC,kBAAkB,EAAE,qBAAqB,CAAQ;AACjE,KAAA,CAAC,CAAC;;AAGF,IAAA,MAAc,CAAC,sBAAsB,GAAG,qBAAqB,CAAC;AAE/D,IAAA,OAAO,MAAM,CAAC;AAClB"}
@@ -0,0 +1,8 @@
1
+ import { Inngest } from 'inngest';
2
+ import { CdmLogger } from '@cdm-logger/core';
3
+ export declare const generateInngestClientId: (configParams: {
4
+ APP_NAME: string;
5
+ NODE_ENV: string;
6
+ INNGEST_CLIENT_ID?: string;
7
+ }, logger: CdmLogger.ILogger) => string;
8
+ export declare const createInngestClient: (logger: CdmLogger.ILogger) => Inngest;
@@ -0,0 +1,47 @@
1
+ import {Inngest}from'inngest';import {config}from'../config/env-config.mjs';import {createCommonStackAutoResolveMiddleware}from'../inngest/middleware/auto-resolve-invoke.middleware.mjs';import {createCombinedFunctionMiddleware}from'../inngest/middleware/function-reference-helper.mjs';const generateInngestClientId = (configParams, logger) => {
2
+ const { APP_NAME, NODE_ENV, INNGEST_CLIENT_ID } = configParams;
3
+ if (INNGEST_CLIENT_ID) {
4
+ return INNGEST_CLIENT_ID;
5
+ }
6
+ const inngestId = `${APP_NAME}-${NODE_ENV}-${Date.now()}`;
7
+ logger.info(`Generated Inngest client ID: ${inngestId}`);
8
+ return inngestId;
9
+ };
10
+ const createInngestClient = (logger) => {
11
+ // Generate unique Inngest client ID for multi-developer environments
12
+ const inngestId = generateInngestClientId({
13
+ APP_NAME: config.APP_NAME,
14
+ NODE_ENV: config.NODE_ENV,
15
+ INNGEST_CLIENT_ID: config.INNGEST_CLIENT_ID,
16
+ }, logger);
17
+ // Create middleware instance (will be populated with functions later)
18
+ const autoResolveMiddleware = createCommonStackAutoResolveMiddleware({
19
+ debug: config.NODE_ENV === 'development',
20
+ customMappings: {
21
+ // Add any special case mappings here if needed
22
+ // Example: 'short-name': 'full-function-id'
23
+ },
24
+ });
25
+ // Create combined function reference middleware
26
+ // This provides both manual referenceFunction() and auto-resolve capabilities
27
+ const combinedMiddleware = createCombinedFunctionMiddleware({
28
+ autoResolve: true, // Enable automatic function resolution
29
+ debug: config.NODE_ENV === 'development',
30
+ });
31
+ // Create Inngest client
32
+ const client = new Inngest({
33
+ id: inngestId,
34
+ eventKey: config.INNGEST_EVENT_KEY,
35
+ signingKey: config.INNGEST_SIGNING_KEY,
36
+ isDev: config.INNGEST_IS_DEV,
37
+ env: config.INNGEST_ENVIRONMENT,
38
+ baseUrl: config.INNGEST_BASE_URL,
39
+ // ✨ Combined middleware stack:
40
+ // 1. Combined middleware - provides referenceFunction() + auto-resolve
41
+ // 2. Legacy auto-resolve - for backward compatibility
42
+ middleware: [combinedMiddleware, autoResolveMiddleware],
43
+ });
44
+ // Store middleware reference for later function registration
45
+ client._autoResolveMiddleware = autoResolveMiddleware;
46
+ return client;
47
+ };export{createInngestClient,generateInngestClientId};//# sourceMappingURL=inngest-factory.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"inngest-factory.mjs","sources":["../../src/infrastructure/inngest-factory.ts"],"sourcesContent":[null],"names":[],"mappings":"mSAMa,uBAAuB,GAAG,CACnC,YAIC,EACD,MAAyB,KACjB;IACR,MAAM,EAAE,QAAQ,EAAE,QAAQ,EAAE,iBAAiB,EAAE,GAAG,YAAY,CAAC;IAE/D,IAAI,iBAAiB,EAAE;AACnB,QAAA,OAAO,iBAAiB,CAAC;KAC5B;AAED,IAAA,MAAM,SAAS,GAAG,CAAG,EAAA,QAAQ,CAAI,CAAA,EAAA,QAAQ,CAAI,CAAA,EAAA,IAAI,CAAC,GAAG,EAAE,CAAA,CAAE,CAAC;AAC1D,IAAA,MAAM,CAAC,IAAI,CAAC,gCAAgC,SAAS,CAAA,CAAE,CAAC,CAAC;AACzD,IAAA,OAAO,SAAS,CAAC;AACrB,EAAE;AAEW,MAAA,mBAAmB,GAAG,CAAC,MAAyB,KAAa;;IAEtE,MAAM,SAAS,GAAG,uBAAuB,CACrC;QACI,QAAQ,EAAE,MAAM,CAAC,QAAQ;QACzB,QAAQ,EAAE,MAAM,CAAC,QAAQ;QACzB,iBAAiB,EAAE,MAAM,CAAC,iBAAiB;KAC9C,EACD,MAAM,CACT,CAAC;;IAGF,MAAM,qBAAqB,GAAG,sCAAsC,CAAC;AACjE,QAAA,KAAK,EAAE,MAAM,CAAC,QAAQ,KAAK,aAAa;AACxC,QAAA,cAAc,EAAE;;;AAGf,SAAA;AACJ,KAAA,CAAC,CAAC;;;IAIH,MAAM,kBAAkB,GAAG,gCAAgC,CAAC;QACxD,WAAW,EAAE,IAAI;AACjB,QAAA,KAAK,EAAE,MAAM,CAAC,QAAQ,KAAK,aAAa;AAC3C,KAAA,CAAC,CAAC;;AAGH,IAAA,MAAM,MAAM,GAAG,IAAI,OAAO,CAAC;AACvB,QAAA,EAAE,EAAE,SAAS;QACb,QAAQ,EAAE,MAAM,CAAC,iBAAiB;QAClC,UAAU,EAAE,MAAM,CAAC,mBAAmB;QACtC,KAAK,EAAE,MAAM,CAAC,cAAc;QAC5B,GAAG,EAAE,MAAM,CAAC,mBAAmB;QAC/B,OAAO,EAAE,MAAM,CAAC,gBAAgB;;;;AAKhC,QAAA,UAAU,EAAE,CAAC,kBAAkB,EAAE,qBAAqB,CAAQ;AACjE,KAAA,CAAC,CAAC;;AAGF,IAAA,MAAc,CAAC,sBAAsB,GAAG,qBAAqB,CAAC;AAE/D,IAAA,OAAO,MAAM,CAAC;AAClB"}
@@ -0,0 +1,28 @@
1
+ import { ServiceBroker } from 'moleculer';
2
+ import { CdmLogger } from '@cdm-logger/core';
3
+ import { Inngest } from 'inngest';
4
+ export interface InfrastructureContext {
5
+ broker: ServiceBroker;
6
+ pubsub: any;
7
+ mongoClient: any;
8
+ logger: CdmLogger.ILogger;
9
+ redisClient: any;
10
+ inngestClient?: Inngest;
11
+ }
12
+ export interface WorkflowStep {
13
+ name: string;
14
+ order: number;
15
+ enabled: boolean;
16
+ execute: (context: InfrastructureContext) => Promise<void> | void;
17
+ }
18
+ export interface ConnectorConfig {
19
+ redis: boolean;
20
+ mongo: boolean;
21
+ pubsub: boolean;
22
+ inngest: boolean;
23
+ }
24
+ export interface InfrastructureConfig {
25
+ connectors: ConnectorConfig;
26
+ workflows: WorkflowStep[];
27
+ environment: string;
28
+ }
@@ -0,0 +1,9 @@
1
+ import { MainStackServer } from '../MainStackServer';
2
+ import { StackServer } from '../StackServer';
3
+ /**
4
+ * Example usage of the new modular infrastructure system
5
+ */
6
+ export declare function startMainServer(): Promise<MainStackServer>;
7
+ export declare function startMicroservice(): Promise<StackServer>;
8
+ export declare function startServerWithCustomWorkflows(): Promise<MainStackServer>;
9
+ export declare function getEnvironmentConfig(environment: string): import("./types").ConnectorConfig;
@@ -0,0 +1,59 @@
1
+ 'use strict';class WorkflowOrchestrator {
2
+ config;
3
+ steps;
4
+ constructor(config) {
5
+ this.config = config;
6
+ this.steps = [...config.workflows].sort((a, b) => a.order - b.order);
7
+ }
8
+ addStep(step) {
9
+ this.steps.push(step);
10
+ this.steps.sort((a, b) => a.order - b.order);
11
+ }
12
+ async executeWorkflow(context) {
13
+ for (const step of this.steps) {
14
+ if (step.enabled) {
15
+ try {
16
+ await step.execute(context);
17
+ context.logger?.debug(`Workflow step '${step.name}' completed successfully`);
18
+ }
19
+ catch (error) {
20
+ context.logger?.error(`Workflow step '${step.name}' failed:`, error);
21
+ throw error;
22
+ }
23
+ }
24
+ else {
25
+ context.logger?.debug(`Workflow step '${step.name}' skipped (disabled)`);
26
+ }
27
+ }
28
+ }
29
+ getEnabledSteps() {
30
+ return this.steps.filter((step) => step.enabled);
31
+ }
32
+ }
33
+ // Predefined connector configurations
34
+ const CONNECTOR_CONFIGS = {
35
+ FULL: {
36
+ redis: true,
37
+ mongo: true,
38
+ pubsub: true,
39
+ inngest: true,
40
+ },
41
+ BASIC: {
42
+ redis: false,
43
+ mongo: true,
44
+ pubsub: true,
45
+ inngest: false,
46
+ },
47
+ MICROSERVICE: {
48
+ redis: true,
49
+ mongo: true,
50
+ pubsub: true,
51
+ inngest: true,
52
+ },
53
+ DEVELOPMENT: {
54
+ redis: true,
55
+ mongo: true,
56
+ pubsub: true,
57
+ inngest: true,
58
+ },
59
+ };exports.CONNECTOR_CONFIGS=CONNECTOR_CONFIGS;exports.WorkflowOrchestrator=WorkflowOrchestrator;//# sourceMappingURL=workflow-orchestrator.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"workflow-orchestrator.cjs","sources":["../../src/infrastructure/workflow-orchestrator.ts"],"sourcesContent":[null],"names":[],"mappings":"mBAEa,oBAAoB,CAAA;AACrB,IAAA,MAAM,CAAuB;AAC7B,IAAA,KAAK,CAAiB;AAE9B,IAAA,WAAA,CAAY,MAA4B,EAAA;AACpC,Q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AO,CAAC,CAAC;KACpD;AACJ,CAAA;AAED;AACa,MAAA,iBAAiB,GAAoC;AAC9D,IAAA,IAAI,EAAE;AACF,QAAA,KAAK,EAAE,IAAI;AACX,QAAA,KAAK,EAAE,IAAI;AACX,QAAA,MAAM,EAAE,IAAI;AACZ,QAAA,OAAO,EAAE,IAAI;AAChB,KAAA;AACD,IAAA,KAAK,EAAE;AACH,QAAA,KAAK,EAAE,KAAK;AACZ,QAAA,KAAK,EAAE,IAAI;AACX,QAAA,MAAM,EAAE,IAAI;AACZ,QAAA,OAAO,EAAE,KAAK;AACjB,KAAA;AACD,IAAA,YAAY,EAAE;AACV,QAAA,KAAK,EAAE,IAAI;AACX,QAAA,KAAK,EAAE,IAAI;AACX,QAAA,MAAM,EAAE,IAAI;AACZ,QAAA,OAAO,EAAE,IAAI;AAChB,KAAA;AACD,IAAA,WAAW,EAAE;AACT,QAAA,KAAK,EAAE,IAAI;AACX,QAAA,KAAK,EAAE,IAAI;AACX,QAAA,MAAM,EAAE,IAAI;AACZ,QAAA,OAAO,EAAE,IAAI;AAChB,KAAA;"}
@@ -0,0 +1,10 @@
1
+ import { InfrastructureConfig, WorkflowStep, ConnectorConfig } from './types';
2
+ export declare class WorkflowOrchestrator {
3
+ private config;
4
+ private steps;
5
+ constructor(config: InfrastructureConfig);
6
+ addStep(step: WorkflowStep): void;
7
+ executeWorkflow(context: any): Promise<void>;
8
+ getEnabledSteps(): WorkflowStep[];
9
+ }
10
+ export declare const CONNECTOR_CONFIGS: Record<string, ConnectorConfig>;
@@ -0,0 +1,59 @@
1
+ class WorkflowOrchestrator {
2
+ config;
3
+ steps;
4
+ constructor(config) {
5
+ this.config = config;
6
+ this.steps = [...config.workflows].sort((a, b) => a.order - b.order);
7
+ }
8
+ addStep(step) {
9
+ this.steps.push(step);
10
+ this.steps.sort((a, b) => a.order - b.order);
11
+ }
12
+ async executeWorkflow(context) {
13
+ for (const step of this.steps) {
14
+ if (step.enabled) {
15
+ try {
16
+ await step.execute(context);
17
+ context.logger?.debug(`Workflow step '${step.name}' completed successfully`);
18
+ }
19
+ catch (error) {
20
+ context.logger?.error(`Workflow step '${step.name}' failed:`, error);
21
+ throw error;
22
+ }
23
+ }
24
+ else {
25
+ context.logger?.debug(`Workflow step '${step.name}' skipped (disabled)`);
26
+ }
27
+ }
28
+ }
29
+ getEnabledSteps() {
30
+ return this.steps.filter((step) => step.enabled);
31
+ }
32
+ }
33
+ // Predefined connector configurations
34
+ const CONNECTOR_CONFIGS = {
35
+ FULL: {
36
+ redis: true,
37
+ mongo: true,
38
+ pubsub: true,
39
+ inngest: true,
40
+ },
41
+ BASIC: {
42
+ redis: false,
43
+ mongo: true,
44
+ pubsub: true,
45
+ inngest: false,
46
+ },
47
+ MICROSERVICE: {
48
+ redis: true,
49
+ mongo: true,
50
+ pubsub: true,
51
+ inngest: true,
52
+ },
53
+ DEVELOPMENT: {
54
+ redis: true,
55
+ mongo: true,
56
+ pubsub: true,
57
+ inngest: true,
58
+ },
59
+ };export{CONNECTOR_CONFIGS,WorkflowOrchestrator};//# sourceMappingURL=workflow-orchestrator.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"workflow-orchestrator.mjs","sources":["../../src/infrastructure/workflow-orchestrator.ts"],"sourcesContent":[null],"names":[],"mappings":"MAEa,oBAAoB,CAAA;AACrB,IAAA,MAAM,CAAuB;AAC7B,IAAA,KAAK,CAAiB;AAE9B,IAAA,WAAA,CAAY,MAA4B,EAAA;AACpC,QAAA,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,KAAK,GAAG,CAAC,GAAG,MAAM,CAAC,SAAS,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,CAAC,KAAK,GAAG,CAAC,CAAC,KAAK,CAAC,CAAC;KACxE;AAEM,IAAA,OAAO,CAAC,IAAkB,EAAA;AAC7B,QAAA,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CA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,EAAE,IAAI;AACZ,QAAA,OAAO,EAAE,KAAK;AACjB,KAAA;AACD,IAAA,YAAY,EAAE;AACV,QAAA,KAAK,EAAE,IAAI;AACX,QAAA,KAAK,EAAE,IAAI;AACX,QAAA,MAAM,EAAE,IAAI;AACZ,QAAA,OAAO,EAAE,IAAI;AAChB,KAAA;AACD,IAAA,WAAW,EAAE;AACT,QAAA,KAAK,EAAE,IAAI;AACX,QAAA,KAAK,EAAE,IAAI;AACX,QAAA,MAAM,EAAE,IAAI;AACZ,QAAA,OAAO,EAAE,IAAI;AAChB,KAAA;"}
@@ -0,0 +1,29 @@
1
+ export interface InngestClientIdConfig {
2
+ APP_NAME: string;
3
+ NODE_ENV: string;
4
+ INNGEST_CLIENT_ID?: string;
5
+ }
6
+ /**
7
+ * Generates a unique Inngest client ID for multi-developer environments
8
+ * Combines app name, environment, username, and hostname for uniqueness
9
+ */
10
+ export declare function generateInngestClientId(config: InngestClientIdConfig, logger?: any): string;
11
+ /**
12
+ * Examples of generated IDs:
13
+ *
14
+ * Production:
15
+ * - APP_NAME=OrderAPI, NODE_ENV=production → "orderapi"
16
+ *
17
+ * Staging:
18
+ * - APP_NAME=OrderAPI, NODE_ENV=staging → "orderapi-staging"
19
+ *
20
+ * Development:
21
+ * - APP_NAME=OrderAPI, NODE_ENV=development, USER=john, HOSTNAME=macbook-pro
22
+ * → "orderapi-development-john-macbookp"
23
+ *
24
+ * - APP_NAME=OrderAPI, NODE_ENV=development, USER=mary, HOSTNAME=mary-laptop
25
+ * → "orderapi-development-mary-marylap"
26
+ *
27
+ * Explicit Override:
28
+ * - INNGEST_CLIENT_ID=custom-client-id → "custom-client-id"
29
+ */
@@ -0,0 +1,24 @@
1
+ import { Container } from 'inversify';
2
+ import { Feature } from '@common-stack/server-core';
3
+ export type InngestFunctionFactory = (params: {
4
+ container: Container;
5
+ inngest: any;
6
+ settings?: any;
7
+ }) => Record<string, any>;
8
+ /**
9
+ * Creates an Inngest handler that combines functions from multiple modules
10
+ * Similar to how Moleculer services are loaded
11
+ *
12
+ * The improved loadInngestFunctions method now:
13
+ * - Handles both array and object returns from factories
14
+ * - Automatically extracts function instances from objects
15
+ * - Flattens nested arrays
16
+ * - Validates function instances
17
+ */
18
+ export declare const createInngestHandler: (features: Feature[], container: Container, inngestClient: any, settings?: any) => Promise<any[]>;
19
+ /**
20
+ * Legacy factory for backward compatibility
21
+ * @param container - The inversify container
22
+ * @deprecated Use createInngestHandler with Feature system instead
23
+ */
24
+ export declare const inngestHandlerFactory: (container: Container, inngestClient?: any) => Promise<any[]>;
@@ -0,0 +1,275 @@
1
+ 'use strict';/**
2
+ * Auto-Resolve Invoke Middleware for Inngest
3
+ *
4
+ * Makes the `function` parameter optional in step.invoke() by automatically
5
+ * resolving functions from the registry based on step names.
6
+ *
7
+ * Usage:
8
+ * ```typescript
9
+ * const inngest = new Inngest({
10
+ * middleware: [
11
+ * createFunctionMapperMiddleware(), // Required first
12
+ * createAutoResolveInvokeMiddleware(), // Then this
13
+ * ]
14
+ * });
15
+ *
16
+ * // In your functions
17
+ * async ({ step }) => {
18
+ * // Function auto-resolved from step name!
19
+ * await step.invoke('user-create', {
20
+ * data: { email: 'test@example.com' }
21
+ * });
22
+ * }
23
+ * ```
24
+ */
25
+ /**
26
+ * Creates middleware that auto-resolves functions for step.invoke()
27
+ *
28
+ * IMPORTANT: This middleware requires functions to be provided explicitly.
29
+ * Use `createAutoResolveInvokeMiddlewareWithFunctions()` helper instead,
30
+ * or pass functions manually after calling serve().
31
+ *
32
+ * Resolution strategy (in order):
33
+ * 1. If function explicitly provided → use it
34
+ * 2. Try custom mappings
35
+ * 3. Try exact match with function ID
36
+ * 4. Try stripping configured prefixes
37
+ * 5. Throw error or return null (based on throwOnNotFound)
38
+ */
39
+ function createAutoResolveInvokeMiddleware(options = {}) {
40
+ const { mappings = {}, stripPrefixes = ['invoke-', 'call-'], caseSensitive = false, throwOnNotFound = true, debug = false, } = options;
41
+ // Function registry (populated manually or via helper)
42
+ const registry = new Map();
43
+ let registryPopulated = false;
44
+ const log = (...args) => {
45
+ if (debug) {
46
+ console.log('[AutoResolveInvoke]', ...args);
47
+ }
48
+ };
49
+ /**
50
+ * Auto-resolve function from step name
51
+ */
52
+ const autoResolveFunction = (stepId) => {
53
+ const searchId = caseSensitive ? stepId : stepId.toLowerCase();
54
+ log(`Attempting to resolve function for step: "${stepId}" (search: "${searchId}")`);
55
+ // Strategy 1: Try custom mapping first
56
+ if (mappings[stepId]) {
57
+ const mappedId = mappings[stepId];
58
+ const mappedKey = caseSensitive ? mappedId : mappedId.toLowerCase();
59
+ const resolvedFn = registry.get(mappedKey);
60
+ if (resolvedFn) {
61
+ log(`✓ Resolved "${stepId}" via mapping to "${mappedId}"`);
62
+ return resolvedFn;
63
+ }
64
+ }
65
+ // Strategy 2: Try exact match
66
+ let resolvedFn = registry.get(searchId);
67
+ if (resolvedFn) {
68
+ log(`✓ Resolved "${stepId}" via exact match`);
69
+ return resolvedFn;
70
+ }
71
+ // Strategy 3: Try stripping prefixes
72
+ for (const prefix of stripPrefixes) {
73
+ const prefixLower = caseSensitive ? prefix : prefix.toLowerCase();
74
+ if (searchId.startsWith(prefixLower)) {
75
+ const stripped = searchId.substring(prefix.length);
76
+ resolvedFn = registry.get(stripped);
77
+ if (resolvedFn) {
78
+ log(`✓ Resolved "${stepId}" by stripping prefix "${prefix}" → "${stripped}"`);
79
+ return resolvedFn;
80
+ }
81
+ }
82
+ }
83
+ // Strategy 4: Not found
84
+ if (throwOnNotFound) {
85
+ const available = Array.from(registry.keys());
86
+ const availableList = available.length > 10
87
+ ? available.slice(0, 10).join(', ') + `, ... (${available.length - 10} more)`
88
+ : available.join(', ');
89
+ throw new Error(`[AutoResolveInvoke] Cannot resolve function for step "${stepId}". ` +
90
+ `Available functions: ${availableList}. ` +
91
+ `Tip: Ensure the function ID matches the step name, or configure custom mappings.`);
92
+ }
93
+ log(`✗ Could not resolve function for step "${stepId}"`);
94
+ return null;
95
+ };
96
+ /**
97
+ * Transform Input Handler: Wrap step.invoke to auto-resolve functions
98
+ */
99
+ const transformInputHandler = (inputCtx) => {
100
+ log('transformInput called, context keys:', Object.keys(inputCtx));
101
+ // Extract step object from various possible locations
102
+ const step = inputCtx.step || inputCtx.steps || (inputCtx.ctx && inputCtx.ctx.step);
103
+ if (!step) {
104
+ log('⚠ No step object found, trying to find it in context');
105
+ return inputCtx;
106
+ }
107
+ // Check if registry has functions
108
+ if (registry.size === 0) {
109
+ console.warn('[AutoResolveInvoke] ⚠ Function registry is empty. Auto-resolve will not work.');
110
+ console.warn('[AutoResolveInvoke] Tip: Ensure functions are registered before middleware initialization.');
111
+ return inputCtx;
112
+ }
113
+ log(`✓ Found step object, registry has ${registry.size} functions`);
114
+ /**
115
+ * Wrap step.invoke with auto-resolution
116
+ */
117
+ const wrappedStep = new Proxy(step, {
118
+ get(target, prop) {
119
+ // Intercept invoke method
120
+ if (prop === 'invoke') {
121
+ return async (stepId, opts = {}) => {
122
+ log(`invoke() called with stepId: "${stepId}", has explicit function:`, !!opts.function);
123
+ // If function not provided, auto-resolve it
124
+ if (!opts.function) {
125
+ const resolvedFn = autoResolveFunction(stepId);
126
+ if (resolvedFn) {
127
+ opts = { ...opts, function: resolvedFn };
128
+ log(`Auto-resolved function for step "${stepId}"`);
129
+ }
130
+ else {
131
+ log(`No function resolved for step "${stepId}", will use original behavior`);
132
+ }
133
+ }
134
+ else {
135
+ log(`Using explicit function for step "${stepId}"`);
136
+ }
137
+ // Call original invoke method
138
+ return target.invoke(stepId, opts);
139
+ };
140
+ }
141
+ // Pass through all other step methods unchanged
142
+ const value = target[prop];
143
+ return typeof value === 'function' ? value.bind(target) : value;
144
+ },
145
+ });
146
+ // Return modified context with wrapped step
147
+ return {
148
+ ...inputCtx,
149
+ step: wrappedStep,
150
+ steps: wrappedStep,
151
+ ctx: inputCtx.ctx
152
+ ? {
153
+ ...inputCtx.ctx,
154
+ step: wrappedStep,
155
+ resolveFunction: autoResolveFunction,
156
+ }
157
+ : undefined,
158
+ };
159
+ };
160
+ // Expose method to populate registry
161
+ const middleware = {
162
+ name: 'auto-resolve-invoke-middleware',
163
+ // Method to populate registry (called by helper or manually)
164
+ _populateRegistry(functions) {
165
+ if (registryPopulated) {
166
+ log('Registry already populated, skipping');
167
+ return;
168
+ }
169
+ if (!Array.isArray(functions) || functions.length === 0) {
170
+ console.warn('[AutoResolveInvoke] No functions provided to populate registry');
171
+ return;
172
+ }
173
+ log('Populating registry with', functions.length, 'functions');
174
+ try {
175
+ functions.forEach((fn, index) => {
176
+ try {
177
+ if (!fn) {
178
+ console.warn(`[AutoResolveInvoke] Skipping null/undefined function at index ${index}`);
179
+ return;
180
+ }
181
+ // Get the ID - it might be a property or a method
182
+ let fnId;
183
+ if (typeof fn.id === 'function') {
184
+ fnId = fn.id(); // Call the id method
185
+ console.log(`[AutoResolveInvoke] Function at index ${index} has id() method, returned: ${fnId}`);
186
+ }
187
+ else if (typeof fn.id === 'string') {
188
+ fnId = fn.id;
189
+ }
190
+ else {
191
+ console.warn(`[AutoResolveInvoke] Skipping function at index ${index} - id is ${typeof fn.id}:`, fn.id);
192
+ return;
193
+ }
194
+ if (!fnId) {
195
+ console.warn(`[AutoResolveInvoke] Skipping function at index ${index} - empty ID`);
196
+ return;
197
+ }
198
+ const key = caseSensitive ? fnId : fnId.toLowerCase();
199
+ registry.set(key, fn);
200
+ log(`Registered: ${fnId} (key: ${key})`);
201
+ }
202
+ catch (fnError) {
203
+ console.error(`[AutoResolveInvoke] Error processing function at index ${index}:`, fnError);
204
+ throw fnError;
205
+ }
206
+ });
207
+ }
208
+ catch (loopError) {
209
+ console.error('[AutoResolveInvoke] Error during function registration loop:', loopError);
210
+ throw loopError;
211
+ }
212
+ registryPopulated = true;
213
+ console.log(`[AutoResolveInvoke] ✅ Registered ${registry.size} functions for auto-resolution`);
214
+ if (debug && registry.size > 0) {
215
+ console.log('[AutoResolveInvoke] Available function IDs:', Array.from(registry.keys()).join(', '));
216
+ }
217
+ },
218
+ /**
219
+ * Initialize: Build function registry from registered functions
220
+ *
221
+ * Note: In Inngest v3+, middleware init receives { client }, not { functions }.
222
+ * Functions are registered separately via serve({ client, functions }).
223
+ * We register functions lazily during transformInput instead.
224
+ */
225
+ init: (initCtx) => {
226
+ log('Init hook called with context:', Object.keys(initCtx));
227
+ // In modern Inngest, we can't access functions during init
228
+ // The registry will be populated during transformInput when we have access to function context
229
+ log('Middleware initialized - function registry will be populated on first use');
230
+ // Return lifecycle hooks (required by Inngest middleware API)
231
+ // transformInput must be inside onFunctionRun for Inngest v3
232
+ return {
233
+ onFunctionRun: (ctx) => {
234
+ log('onFunctionRun called, context keys:', Object.keys(ctx));
235
+ return {
236
+ transformInput: transformInputHandler,
237
+ };
238
+ },
239
+ onSendEvent: () => ({}),
240
+ };
241
+ },
242
+ };
243
+ return middleware;
244
+ }
245
+ /**
246
+ * Helper: Create middleware configured for common-stack WorkflowNamespace patterns
247
+ *
248
+ * Handles your naming convention where:
249
+ * - Function IDs: 'aicode-code-agent', 'project-mgmt-main-workflow'
250
+ * - Event Names: 'aicode/code-agent-trigger', 'project-mgmt-main-workflow/trigger'
251
+ *
252
+ * Example usage:
253
+ * ```typescript
254
+ * // In your workflow
255
+ * await step.invoke('aicode-code-agent', { data: {...} });
256
+ * // Resolves to function with ID 'aicode-code-agent'
257
+ *
258
+ * await step.invoke('project-mgmt-create-from-template', { data: {...} });
259
+ * // Resolves to function with ID 'project-mgmt-create-from-template'
260
+ * ```
261
+ */
262
+ function createCommonStackAutoResolveMiddleware(options) {
263
+ return createAutoResolveInvokeMiddleware({
264
+ // Strip common suffixes
265
+ stripPrefixes: ['-function', '-workflow'],
266
+ // Case-insensitive for flexibility
267
+ caseSensitive: false,
268
+ // Throw helpful errors
269
+ throwOnNotFound: true,
270
+ // Custom mappings if provided
271
+ mappings: options?.customMappings,
272
+ // Debug mode
273
+ debug: options?.debug || false,
274
+ });
275
+ }exports.createAutoResolveInvokeMiddleware=createAutoResolveInvokeMiddleware;exports.createCommonStackAutoResolveMiddleware=createCommonStackAutoResolveMiddleware;//# sourceMappingURL=auto-resolve-invoke.middleware.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"auto-resolve-invoke.middleware.cjs","sources":["../../../src/inngest/middleware/auto-resolve-invoke.middleware.ts"],"sourcesContent":[null],"names":[],"mappings":"aAAA;;;;;;;;;;;;;;;;;;;;;;;AAuBG;AAmCH;;;;;;;;;;;;;AAaG;AACa,SAAA,iCAAiC,CAAC,OAAA,GAAoC,EAAE,EAAA;IACpF,MAAM,EACF,QAAQ,GAAG,EAAE,EACb,aAAa,GAAG,CAAC,SAAS,EAAE,OAAO,CAAC,EACpC,aAAa,GAAG,KAAK,EACrB,eAAe,GAAG,IAAI,EACtB,KAAK,GAAG,KAAK,GAChB,GAAG,OAAO,CAAC;;AAGZ,IAAA,MAAM,QAAQ,GAAG,IAAI,GAAG,EAAe,CAAC;IACxC,IAAI,iBAAiB,GAAG,KAAK,CAAC;AAE9B,IAAA,MAAM,GAAG,GAAG,CAAC,GAAG,IAAW,KAAI;QAC3B,IAAI,KAAK,EAAE;YACP,OAAO,CAAC,GAAG,CAAC,qBAAqB,EAAE,GAAG,IAAI,CAAC,CAAC;SAC/C;AACL,KAAC,CAAC;AAEF;;AAEG;AACH,IAAA,MAAM,mBAAmB,GAAG,CAAC,MAAc,KAAS;AAChD,QAAA,MAAM,QAAQ,GAAG,aAAa,GAAG,MAAM,GAAG,MAAM,CAAC,WAAW,EAAE,CAAC;AAC/D,QAAA,GAAG,CAAC,CAA6C,0CAAA,EAAA,MAAM,eAAe,QAAQ,CAAA,EAAA,CAAI,CAAC,CAAC;;AAGpF,QAAA,IAAI,QAAQ,CAAC,MAAM,CAAC,EAAE;AAClB,YAAA,MAAM,QAAQ,GAAG,QAAQ,CAAC,MAAM,CAAC,CAAC;AAClC,YAAA,MAAM,SAAS,GAAG,aAAa,GAAG,QAAQ,GAAG,QAAQ,CAAC,WAAW,EAAE,CAAC;YACpE,MAAM,UAAU,GA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