@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.
- package/LICENSE +34 -21
- package/lib/MainStackServer.cjs +126 -146
- package/lib/MainStackServer.cjs.map +1 -1
- package/lib/MainStackServer.d.ts +12 -6
- package/lib/MainStackServer.mjs +126 -146
- package/lib/MainStackServer.mjs.map +1 -1
- package/lib/StackServer.cjs +23 -66
- package/lib/StackServer.cjs.map +1 -1
- package/lib/StackServer.d.ts +4 -5
- package/lib/StackServer.mjs +23 -66
- package/lib/StackServer.mjs.map +1 -1
- package/lib/api/schema-builder.cjs +13 -12
- package/lib/api/schema-builder.cjs.map +1 -1
- package/lib/api/schema-builder.mjs +13 -12
- package/lib/api/schema-builder.mjs.map +1 -1
- package/lib/api/sub-graph-schema-builder.cjs +147 -0
- package/lib/api/sub-graph-schema-builder.cjs.map +1 -0
- package/lib/api/sub-graph-schema-builder.d.ts +24 -0
- package/lib/api/sub-graph-schema-builder.mjs +147 -0
- package/lib/api/sub-graph-schema-builder.mjs.map +1 -0
- package/lib/config/env-config.cjs +6 -0
- package/lib/config/env-config.cjs.map +1 -1
- package/lib/config/env-config.d.ts +6 -0
- package/lib/config/env-config.mjs +6 -0
- package/lib/config/env-config.mjs.map +1 -1
- package/lib/examples/tenant-feature-example.d.ts +13 -0
- package/lib/examples/tenant-feature-integration.d.ts +14 -0
- package/lib/features/multi-module-example.d.ts +17 -0
- package/lib/index.cjs +1 -1
- package/lib/index.d.ts +1 -0
- package/lib/index.mjs +1 -1
- package/lib/infrastructure/container-module.cjs +27 -0
- package/lib/infrastructure/container-module.cjs.map +1 -0
- package/lib/infrastructure/container-module.d.ts +3 -0
- package/lib/infrastructure/container-module.mjs +27 -0
- package/lib/infrastructure/container-module.mjs.map +1 -0
- package/lib/infrastructure/example-workflows.d.ts +16 -0
- package/lib/infrastructure/index.d.ts +5 -0
- package/lib/infrastructure/infrastructure-factory.cjs +172 -0
- package/lib/infrastructure/infrastructure-factory.cjs.map +1 -0
- package/lib/infrastructure/infrastructure-factory.d.ts +36 -0
- package/lib/infrastructure/infrastructure-factory.mjs +172 -0
- package/lib/infrastructure/infrastructure-factory.mjs.map +1 -0
- package/lib/infrastructure/inngest-factory.cjs +47 -0
- package/lib/infrastructure/inngest-factory.cjs.map +1 -0
- package/lib/infrastructure/inngest-factory.d.ts +8 -0
- package/lib/infrastructure/inngest-factory.mjs +47 -0
- package/lib/infrastructure/inngest-factory.mjs.map +1 -0
- package/lib/infrastructure/types.d.ts +28 -0
- package/lib/infrastructure/usage-examples.d.ts +9 -0
- package/lib/infrastructure/workflow-orchestrator.cjs +59 -0
- package/lib/infrastructure/workflow-orchestrator.cjs.map +1 -0
- package/lib/infrastructure/workflow-orchestrator.d.ts +10 -0
- package/lib/infrastructure/workflow-orchestrator.mjs +59 -0
- package/lib/infrastructure/workflow-orchestrator.mjs.map +1 -0
- package/lib/inngest/client-id-generator.d.ts +29 -0
- package/lib/inngest/handler-factory.d.ts +24 -0
- package/lib/inngest/middleware/auto-resolve-invoke.middleware.cjs +275 -0
- package/lib/inngest/middleware/auto-resolve-invoke.middleware.cjs.map +1 -0
- package/lib/inngest/middleware/auto-resolve-invoke.middleware.d.ts +111 -0
- package/lib/inngest/middleware/auto-resolve-invoke.middleware.mjs +275 -0
- package/lib/inngest/middleware/auto-resolve-invoke.middleware.mjs.map +1 -0
- package/lib/inngest/middleware/function-reference-helper.cjs +363 -0
- package/lib/inngest/middleware/function-reference-helper.cjs.map +1 -0
- package/lib/inngest/middleware/function-reference-helper.d.ts +211 -0
- package/lib/inngest/middleware/function-reference-helper.mjs +363 -0
- package/lib/inngest/middleware/function-reference-helper.mjs.map +1 -0
- package/lib/inngest/middleware/index.d.ts +31 -0
- package/lib/inngest/middleware/types.d.ts +162 -0
- package/lib/inngest/multi-module-functions.d.ts +133 -0
- package/lib/inngest/setup.cjs +55 -0
- package/lib/inngest/setup.cjs.map +1 -0
- package/lib/inngest/setup.d.ts +10 -0
- package/lib/inngest/setup.mjs +55 -0
- package/lib/inngest/setup.mjs.map +1 -0
- package/lib/interfaces/graphql-request-context.d.ts +5 -0
- package/lib/middleware/index.d.ts +5 -0
- package/lib/middleware/redis-client.cjs +18 -0
- package/lib/middleware/redis-client.cjs.map +1 -0
- package/lib/middleware/redis-client.d.ts +16 -0
- package/lib/middleware/redis-client.mjs +18 -0
- package/lib/middleware/redis-client.mjs.map +1 -0
- package/lib/plugins/responseCachePlugin.cjs +2 -2
- package/lib/plugins/responseCachePlugin.cjs.map +1 -1
- package/lib/plugins/responseCachePlugin.mjs +2 -2
- package/lib/plugins/responseCachePlugin.mjs.map +1 -1
- package/lib/servers/ExpressApp.cjs +8 -3
- package/lib/servers/ExpressApp.cjs.map +1 -1
- package/lib/servers/ExpressApp.d.ts +1 -1
- package/lib/servers/ExpressApp.mjs +8 -3
- package/lib/servers/ExpressApp.mjs.map +1 -1
- package/lib/servers/GraphqlServer.cjs +7 -2
- package/lib/servers/GraphqlServer.cjs.map +1 -1
- package/lib/servers/GraphqlServer.d.ts +8 -6
- package/lib/servers/GraphqlServer.mjs +7 -2
- package/lib/servers/GraphqlServer.mjs.map +1 -1
- package/lib/servers/GraphqlWs.cjs +3 -44
- package/lib/servers/GraphqlWs.cjs.map +1 -1
- package/lib/servers/GraphqlWs.mjs +3 -44
- package/lib/servers/GraphqlWs.mjs.map +1 -1
- package/lib/servers/WebsocketMultipathUpdate.cjs +4 -2
- package/lib/servers/WebsocketMultipathUpdate.cjs.map +1 -1
- package/lib/servers/WebsocketMultipathUpdate.mjs +4 -2
- package/lib/servers/WebsocketMultipathUpdate.mjs.map +1 -1
- package/lib/servers/mongodb-migration-update.d.ts +1 -1
- package/lib/servers/websocket-context.cjs +70 -0
- package/lib/servers/websocket-context.cjs.map +1 -0
- package/lib/servers/websocket-context.d.ts +30 -0
- package/lib/servers/websocket-context.mjs +70 -0
- package/lib/servers/websocket-context.mjs.map +1 -0
- package/lib/utils/add-shareable-directive-to-schema.cjs +44 -0
- package/lib/utils/add-shareable-directive-to-schema.cjs.map +1 -0
- package/lib/utils/add-shareable-directive-to-schema.d.ts +1 -0
- package/lib/utils/add-shareable-directive-to-schema.mjs +44 -0
- package/lib/utils/add-shareable-directive-to-schema.mjs.map +1 -0
- package/lib/utils/index.d.ts +2 -0
- package/lib/utils/safe-model-factory.d.ts +18 -0
- package/package.json +15 -11
- package/lib/api/resolver.cjs +0 -12
- package/lib/api/resolver.cjs.map +0 -1
- package/lib/api/resolver.mjs +0 -12
- package/lib/api/resolver.mjs.map +0 -1
- package/lib/api/root-schema.graphqls.cjs +0 -2
- package/lib/api/root-schema.graphqls.cjs.map +0 -1
- package/lib/api/root-schema.graphqls.mjs +0 -2
- package/lib/api/root-schema.graphqls.mjs.map +0 -1
- package/lib/api/scalar.cjs +0 -16
- package/lib/api/scalar.cjs.map +0 -1
- package/lib/api/scalar.mjs +0 -16
- package/lib/api/scalar.mjs.map +0 -1
- package/lib/graphql/directives/index.cjs +0 -10
- package/lib/graphql/directives/index.cjs.map +0 -1
- package/lib/graphql/directives/index.d.ts +0 -7
- package/lib/graphql/directives/index.mjs +0 -10
- package/lib/graphql/directives/index.mjs.map +0 -1
- package/lib/graphql/index.d.ts +0 -2
- package/lib/graphql/schema/directives.graphql.cjs +0 -1
- package/lib/graphql/schema/directives.graphql.cjs.map +0 -1
- package/lib/graphql/schema/directives.graphql.mjs +0 -1
- package/lib/graphql/schema/directives.graphql.mjs.map +0 -1
- package/lib/graphql/schema/index.cjs +0 -1
- package/lib/graphql/schema/index.cjs.map +0 -1
- package/lib/graphql/schema/index.d.ts +0 -1
- package/lib/graphql/schema/index.mjs +0 -1
- package/lib/graphql/schema/index.mjs.map +0 -1
- package/lib/plugins/invalidateCachePlugin.test.d.ts +0 -1
- package/lib/plugins/response-cache-plugin.test.d.ts +0 -1
|
@@ -0,0 +1,363 @@
|
|
|
1
|
+
'use strict';/**
|
|
2
|
+
* Function Reference Helper for Inngest
|
|
3
|
+
*
|
|
4
|
+
* Provides automatic function reference resolution for all registered functions.
|
|
5
|
+
* Instead of manually importing functions, you can reference them by ID.
|
|
6
|
+
*
|
|
7
|
+
* This combines:
|
|
8
|
+
* 1. Inngest's native `referenceFunction()` pattern
|
|
9
|
+
* 2. Automatic registry from all Feature-registered functions
|
|
10
|
+
* 3. Type-safe helpers for common patterns
|
|
11
|
+
*
|
|
12
|
+
* Usage:
|
|
13
|
+
* ```typescript
|
|
14
|
+
* // Instead of:
|
|
15
|
+
* import { someFunction } from '../other-module';
|
|
16
|
+
* await step.invoke('call-it', { function: someFunction, data: {...} });
|
|
17
|
+
*
|
|
18
|
+
* // You can do:
|
|
19
|
+
* await step.invoke('call-it', {
|
|
20
|
+
* function: ctx.resolveFunction('some-function-id'),
|
|
21
|
+
* data: {...}
|
|
22
|
+
* });
|
|
23
|
+
*
|
|
24
|
+
* // Or even simpler (if middleware auto-resolve enabled):
|
|
25
|
+
* await step.invoke('some-function-id', { data: {...} });
|
|
26
|
+
* ```
|
|
27
|
+
*/
|
|
28
|
+
/**
|
|
29
|
+
* Global function registry
|
|
30
|
+
* Populated by setup.ts after all functions are loaded
|
|
31
|
+
*/
|
|
32
|
+
class FunctionRegistry {
|
|
33
|
+
functions = new Map();
|
|
34
|
+
initialized = false;
|
|
35
|
+
/**
|
|
36
|
+
* Register all functions from Feature system
|
|
37
|
+
*/
|
|
38
|
+
register(functions) {
|
|
39
|
+
if (this.initialized) {
|
|
40
|
+
console.warn('[FunctionRegistry] Already initialized, skipping re-registration');
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
console.log(`[FunctionRegistry] Registering ${functions.length} functions...`);
|
|
44
|
+
functions.forEach((fn, index) => {
|
|
45
|
+
try {
|
|
46
|
+
if (!fn) {
|
|
47
|
+
console.warn(`[FunctionRegistry] Skipping null function at index ${index}`);
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
// Get function ID (might be method or property)
|
|
51
|
+
let fnId;
|
|
52
|
+
if (typeof fn.id === 'function') {
|
|
53
|
+
fnId = fn.id();
|
|
54
|
+
}
|
|
55
|
+
else {
|
|
56
|
+
fnId = String(fn.id);
|
|
57
|
+
}
|
|
58
|
+
if (!fnId) {
|
|
59
|
+
console.warn(`[FunctionRegistry] Skipping function at index ${index} - empty ID`);
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
62
|
+
this.functions.set(fnId, fn);
|
|
63
|
+
// Also register lowercase version for case-insensitive lookup
|
|
64
|
+
this.functions.set(fnId.toLowerCase(), fn);
|
|
65
|
+
}
|
|
66
|
+
catch (error) {
|
|
67
|
+
console.error(`[FunctionRegistry] Error registering function at index ${index}:`, error);
|
|
68
|
+
}
|
|
69
|
+
});
|
|
70
|
+
this.initialized = true;
|
|
71
|
+
const uniqueCount = Array.from(new Set(this.functions.values())).length;
|
|
72
|
+
console.log(`[FunctionRegistry] ✅ Registered ${uniqueCount} unique functions`);
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Get function by ID (case-insensitive)
|
|
76
|
+
*/
|
|
77
|
+
get(functionId) {
|
|
78
|
+
// Try exact match first
|
|
79
|
+
let fn = this.functions.get(functionId);
|
|
80
|
+
if (fn)
|
|
81
|
+
return fn;
|
|
82
|
+
// Try lowercase match
|
|
83
|
+
fn = this.functions.get(functionId.toLowerCase());
|
|
84
|
+
if (fn)
|
|
85
|
+
return fn;
|
|
86
|
+
return undefined;
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Check if function exists
|
|
90
|
+
*/
|
|
91
|
+
has(functionId) {
|
|
92
|
+
return this.functions.has(functionId) || this.functions.has(functionId.toLowerCase());
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Get all registered function IDs
|
|
96
|
+
*/
|
|
97
|
+
getAllIds() {
|
|
98
|
+
const uniqueFunctions = Array.from(new Set(this.functions.values()));
|
|
99
|
+
return uniqueFunctions
|
|
100
|
+
.map((fn) => {
|
|
101
|
+
if (typeof fn.id === 'function') {
|
|
102
|
+
return fn.id();
|
|
103
|
+
}
|
|
104
|
+
return String(fn.id);
|
|
105
|
+
})
|
|
106
|
+
.filter(Boolean);
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* Get count of registered functions
|
|
110
|
+
*/
|
|
111
|
+
get count() {
|
|
112
|
+
return Array.from(new Set(this.functions.values())).length;
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* Check if registry is initialized
|
|
116
|
+
*/
|
|
117
|
+
get isInitialized() {
|
|
118
|
+
return this.initialized;
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* Clear registry (for testing)
|
|
122
|
+
*/
|
|
123
|
+
clear() {
|
|
124
|
+
this.functions.clear();
|
|
125
|
+
this.initialized = false;
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
// Global singleton instance
|
|
129
|
+
const globalFunctionRegistry = new FunctionRegistry();
|
|
130
|
+
/**
|
|
131
|
+
* Reference a function by its ID
|
|
132
|
+
* Similar to Inngest's native referenceFunction, but automatically uses global registry
|
|
133
|
+
*
|
|
134
|
+
* @param functionIdOrOptions - The ID of the function or options object with functionId
|
|
135
|
+
* @returns The function reference to use in step.invoke()
|
|
136
|
+
*
|
|
137
|
+
* @example
|
|
138
|
+
* ```typescript
|
|
139
|
+
* // Simple usage
|
|
140
|
+
* const userCreateFn = referenceFunction('user-create');
|
|
141
|
+
*
|
|
142
|
+
* // Type-safe usage
|
|
143
|
+
* const computePi = referenceFunction({ functionId: 'compute-pi' });
|
|
144
|
+
*
|
|
145
|
+
* await step.invoke('create-user', {
|
|
146
|
+
* function: userCreateFn,
|
|
147
|
+
* data: { email: 'user@example.com' }
|
|
148
|
+
* });
|
|
149
|
+
* ```
|
|
150
|
+
*/
|
|
151
|
+
function referenceFunction(functionIdOrOptions) {
|
|
152
|
+
const functionId = typeof functionIdOrOptions === 'string' ? functionIdOrOptions : functionIdOrOptions.functionId;
|
|
153
|
+
if (!globalFunctionRegistry.isInitialized) {
|
|
154
|
+
throw new Error(`[referenceFunction] Function registry not initialized yet. ` +
|
|
155
|
+
`Ensure setupInngestFunctions() has completed before using referenceFunction().`);
|
|
156
|
+
}
|
|
157
|
+
const fn = globalFunctionRegistry.get(functionId);
|
|
158
|
+
if (!fn) {
|
|
159
|
+
const available = globalFunctionRegistry.getAllIds();
|
|
160
|
+
const suggestions = available.filter((id) => id.toLowerCase().includes(functionId.toLowerCase())).slice(0, 5);
|
|
161
|
+
let errorMsg = `[referenceFunction] Function "${functionId}" not found in registry.`;
|
|
162
|
+
if (suggestions.length > 0) {
|
|
163
|
+
errorMsg += `\n\nDid you mean one of these?\n - ${suggestions.join('\n - ')}`;
|
|
164
|
+
}
|
|
165
|
+
else {
|
|
166
|
+
errorMsg += `\n\nAvailable functions (${available.length} total):\n - ${available.slice(0, 10).join('\n - ')}`;
|
|
167
|
+
if (available.length > 10) {
|
|
168
|
+
errorMsg += `\n ... and ${available.length - 10} more`;
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
throw new Error(errorMsg);
|
|
172
|
+
}
|
|
173
|
+
return fn;
|
|
174
|
+
}
|
|
175
|
+
/**
|
|
176
|
+
* Batch reference multiple functions at once
|
|
177
|
+
* Useful for orchestrator workflows that call many functions
|
|
178
|
+
*
|
|
179
|
+
* @example
|
|
180
|
+
* ```typescript
|
|
181
|
+
* const { userCreate, emailSend, analyticsTrack } = referenceFunctions([
|
|
182
|
+
* 'user-create',
|
|
183
|
+
* 'email-send-welcome',
|
|
184
|
+
* 'analytics-track-event'
|
|
185
|
+
* ]);
|
|
186
|
+
*
|
|
187
|
+
* await step.invoke('create-user', { function: userCreate, data: {...} });
|
|
188
|
+
* await step.invoke('send-email', { function: emailSend, data: {...} });
|
|
189
|
+
* await step.invoke('track', { function: analyticsTrack, data: {...} });
|
|
190
|
+
* ```
|
|
191
|
+
*/
|
|
192
|
+
function referenceFunctions(functionIds) {
|
|
193
|
+
const result = {};
|
|
194
|
+
for (const functionId of functionIds) {
|
|
195
|
+
result[functionId] = referenceFunction(functionId);
|
|
196
|
+
}
|
|
197
|
+
return result;
|
|
198
|
+
}
|
|
199
|
+
/**
|
|
200
|
+
* Check if a function is registered
|
|
201
|
+
* Useful for conditional logic
|
|
202
|
+
*
|
|
203
|
+
* @example
|
|
204
|
+
* ```typescript
|
|
205
|
+
* if (hasFunctionReference('email-send-welcome')) {
|
|
206
|
+
* const emailFn = referenceFunction('email-send-welcome');
|
|
207
|
+
* await step.invoke('send-email', { function: emailFn, data: {...} });
|
|
208
|
+
* }
|
|
209
|
+
* ```
|
|
210
|
+
*/
|
|
211
|
+
function hasFunctionReference(functionId) {
|
|
212
|
+
return globalFunctionRegistry.has(functionId);
|
|
213
|
+
}
|
|
214
|
+
/**
|
|
215
|
+
* Get all available function IDs
|
|
216
|
+
* Useful for debugging and introspection
|
|
217
|
+
*
|
|
218
|
+
* @example
|
|
219
|
+
* ```typescript
|
|
220
|
+
* console.log('Available functions:', getAvailableFunctions());
|
|
221
|
+
* ```
|
|
222
|
+
*/
|
|
223
|
+
function getAvailableFunctions() {
|
|
224
|
+
return globalFunctionRegistry.getAllIds();
|
|
225
|
+
}
|
|
226
|
+
/**
|
|
227
|
+
* Resolve a workflow-style or ID-style function reference to an Inngest function reference.
|
|
228
|
+
*
|
|
229
|
+
* Supported inputs:
|
|
230
|
+
* - Exact function id: "user-create"
|
|
231
|
+
* - Workflow-style: "WORKFLOWNAME.Function/trigger" or "WORKFLOWNAME.Function.trigger"
|
|
232
|
+
*
|
|
233
|
+
* The resolver will first try the exact ID as provided. If not found it will
|
|
234
|
+
* normalize the string by replacing separators ("/", ".") with dashes and
|
|
235
|
+
* collapsing non-alphanumerics, then lower-case the result. Example:
|
|
236
|
+
*
|
|
237
|
+
* WORKFLOWNAME.Function/trigger -> workflowname-function-trigger
|
|
238
|
+
*
|
|
239
|
+
* If still not found, it will throw the same helpful error as `referenceFunction`.
|
|
240
|
+
*/
|
|
241
|
+
function resolveFunctionId(functionRef) {
|
|
242
|
+
const raw = typeof functionRef === 'string' ? functionRef : functionRef.functionId;
|
|
243
|
+
if (!raw || typeof raw !== 'string') {
|
|
244
|
+
throw new Error('[resolveFunctionId] Invalid function reference');
|
|
245
|
+
}
|
|
246
|
+
// Try direct lookup first
|
|
247
|
+
if (globalFunctionRegistry.has(raw)) {
|
|
248
|
+
return referenceFunction(raw);
|
|
249
|
+
}
|
|
250
|
+
// Normalize common workflow-style patterns into kebab-case id
|
|
251
|
+
let normalized = raw
|
|
252
|
+
// Replace separators with dashes
|
|
253
|
+
.replace(/[\/\.\s]+/g, '-')
|
|
254
|
+
// Insert dashes between camelCase / PascalCase boundaries (aB -> a-B)
|
|
255
|
+
.replace(/([a-z0-9])([A-Z])/g, '$1-$2')
|
|
256
|
+
// Remove non-alphanumeric/dash characters
|
|
257
|
+
.replace(/[^a-zA-Z0-9-]+/g, '-')
|
|
258
|
+
// Collapse multiple dashes
|
|
259
|
+
.replace(/-+/g, '-')
|
|
260
|
+
// Trim dashes
|
|
261
|
+
.replace(/(^-|-$)/g, '')
|
|
262
|
+
.toLowerCase();
|
|
263
|
+
if (globalFunctionRegistry.has(normalized)) {
|
|
264
|
+
return referenceFunction(normalized);
|
|
265
|
+
}
|
|
266
|
+
// As a last resort, try lowercasing the raw input
|
|
267
|
+
if (globalFunctionRegistry.has(raw.toLowerCase())) {
|
|
268
|
+
return referenceFunction(raw.toLowerCase());
|
|
269
|
+
}
|
|
270
|
+
// Not found - rethrow a helpful error from referenceFunction to show suggestions
|
|
271
|
+
return referenceFunction(normalized);
|
|
272
|
+
}
|
|
273
|
+
/**
|
|
274
|
+
* Combined middleware: Reference + Auto-Resolve
|
|
275
|
+
* Provides both manual and automatic function resolution
|
|
276
|
+
*
|
|
277
|
+
* @example
|
|
278
|
+
* ```typescript
|
|
279
|
+
* const inngest = new Inngest({
|
|
280
|
+
* middleware: [createCombinedFunctionMiddleware()],
|
|
281
|
+
* });
|
|
282
|
+
*
|
|
283
|
+
* // Method 1: Manual reference
|
|
284
|
+
* const userFn = ctx.resolveFunction('user-create');
|
|
285
|
+
* await step.invoke('create-user', { function: userFn, data: {...} });
|
|
286
|
+
*
|
|
287
|
+
* // Method 2: Automatic (if function ID matches)
|
|
288
|
+
* await step.invoke('user-create', { data: {...} }); // Auto-resolved!
|
|
289
|
+
* ```
|
|
290
|
+
*/
|
|
291
|
+
function createCombinedFunctionMiddleware(options) {
|
|
292
|
+
const { autoResolve = true, caseSensitive = false, debug = false } = options || {};
|
|
293
|
+
const log = (...args) => {
|
|
294
|
+
if (debug) {
|
|
295
|
+
console.log('[CombinedFunctionMiddleware]', ...args);
|
|
296
|
+
}
|
|
297
|
+
};
|
|
298
|
+
return {
|
|
299
|
+
name: 'combined-function-middleware',
|
|
300
|
+
init() {
|
|
301
|
+
return {
|
|
302
|
+
onFunctionRun({ ctx }) {
|
|
303
|
+
// Inject reference helpers
|
|
304
|
+
ctx.resolveFunction = referenceFunction;
|
|
305
|
+
ctx.resolveFunctions = referenceFunctions;
|
|
306
|
+
ctx.hasFunction = hasFunctionReference;
|
|
307
|
+
ctx.getAvailableFunctions = getAvailableFunctions;
|
|
308
|
+
ctx.resolveFunctionId = resolveFunctionId;
|
|
309
|
+
return {
|
|
310
|
+
transformInput(inputCtx) {
|
|
311
|
+
// Inject into context
|
|
312
|
+
if (inputCtx.ctx) {
|
|
313
|
+
inputCtx.ctx.resolveFunction = referenceFunction;
|
|
314
|
+
inputCtx.ctx.resolveFunctions = referenceFunctions;
|
|
315
|
+
inputCtx.ctx.hasFunction = hasFunctionReference;
|
|
316
|
+
inputCtx.ctx.getAvailableFunctions = getAvailableFunctions;
|
|
317
|
+
inputCtx.ctx.resolveFunctionId = resolveFunctionId;
|
|
318
|
+
}
|
|
319
|
+
// Inject helper functions into step object for inline editor support
|
|
320
|
+
// The actual step object that gets passed to workflow functions is inputCtx.ctx.step
|
|
321
|
+
// inputCtx.step is the step data array, inputCtx.ctx.step is the step object with methods
|
|
322
|
+
const stepObject = inputCtx.ctx && inputCtx.ctx.step;
|
|
323
|
+
log('Checking step object - inputCtx.step:', !!inputCtx.step, 'inputCtx.steps:', !!inputCtx.steps, 'inputCtx.ctx.step:', !!stepObject, 'found step object:', !!stepObject);
|
|
324
|
+
if (stepObject) {
|
|
325
|
+
// Make referenceFunction available as step.referenceFunction()
|
|
326
|
+
stepObject.referenceFunction = referenceFunction;
|
|
327
|
+
stepObject.hasFunction = hasFunctionReference;
|
|
328
|
+
stepObject.getAvailableFunctions = getAvailableFunctions;
|
|
329
|
+
stepObject.resolveFunctionId = resolveFunctionId;
|
|
330
|
+
log('✅ Injected referenceFunction into step object');
|
|
331
|
+
}
|
|
332
|
+
else {
|
|
333
|
+
log('❌ No step object found in inputCtx.ctx.step');
|
|
334
|
+
}
|
|
335
|
+
// Auto-resolve if enabled
|
|
336
|
+
if (autoResolve && stepObject) {
|
|
337
|
+
const originalInvoke = stepObject.invoke;
|
|
338
|
+
stepObject.invoke = async (stepId, opts = {}) => {
|
|
339
|
+
log(`invoke() called: "${stepId}", has function:`, !!opts.function);
|
|
340
|
+
// Auto-resolve if no function provided
|
|
341
|
+
if (!opts.function) {
|
|
342
|
+
try {
|
|
343
|
+
const fn = referenceFunction(stepId);
|
|
344
|
+
opts = { ...opts, function: fn };
|
|
345
|
+
log(`✅ Auto-resolved function for step "${stepId}"`);
|
|
346
|
+
}
|
|
347
|
+
catch (error) {
|
|
348
|
+
log(`⚠️ Could not auto-resolve "${stepId}":`, error.message);
|
|
349
|
+
// Continue with original behavior
|
|
350
|
+
}
|
|
351
|
+
}
|
|
352
|
+
return originalInvoke.call(stepObject, stepId, opts);
|
|
353
|
+
};
|
|
354
|
+
}
|
|
355
|
+
return inputCtx;
|
|
356
|
+
},
|
|
357
|
+
};
|
|
358
|
+
},
|
|
359
|
+
onSendEvent: () => ({}),
|
|
360
|
+
};
|
|
361
|
+
},
|
|
362
|
+
};
|
|
363
|
+
}exports.createCombinedFunctionMiddleware=createCombinedFunctionMiddleware;exports.getAvailableFunctions=getAvailableFunctions;exports.globalFunctionRegistry=globalFunctionRegistry;exports.hasFunctionReference=hasFunctionReference;exports.referenceFunction=referenceFunction;exports.referenceFunctions=referenceFunctions;exports.resolveFunctionId=resolveFunctionId;//# sourceMappingURL=function-reference-helper.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"function-reference-helper.cjs","sources":["../../../src/inngest/middleware/function-reference-helper.ts"],"sourcesContent":[null],"names":[],"mappings":"aAAA;;;;;;;;;;;;;;;;;;;;;;;;;;AA0BG;AAIH;;;AAGG;AACH,MAAM,gBAAgB,CAAA;AACV,IAAA,SAAS,GAAG,IAAI,GAAG,EAA+B,CAAC;IACnD,WAAW,GAAG,KAAK,CAAC;AAE5B;;AAEG;AACH,IAAA,QAAQ,CAAC,SAAgC,EAAA;AACrC,QAAA,IAAI,IAAI,CAAC,WAAW,EAAE;AAClB,YAAA,OAAO,CAAC,IAAI,CAAC,kEAAkE,CAAC,CAAC;YACjF,OAAO;SACV;QAED,OAAO,CAAC,GAAG,CAAC,CAAA,+BAAA,EAAkC,SAAS,CAAC,MAAM,CAAe,aAAA,CAAA,CAAC,CAAC;QAE/E,SAAS,CAAC,OAAO,CAAC,CAAC,EAAE,EAAE,KAAK,KAAI;AAC5B,YAAA,IAAI;gBACA,IAAI,CAAC,EAAE,EAAE;AACL,oBAAA,OAAO,CAAC,IAAI,CAAC,sDAAsD,KAAK,CAAA,CAAE,CAAC,CAAC;oBAC5E,OAAO;iBACV;;AAGD,gBAAA,IAAI,IAAY,CAAC;AACjB,gBAAA,IAAI,OAAO,EAAE,CAAC,EAAE,KAAK,UAAU,EAAE;AAC7B,oBAAA,IAAI,GAAG,EAAE,CAAC,EAAE,EAAE,CAAC;iBAClB;qBAAM;AACH,oBAAA,IAAI,GAAG,MAAM,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC;iBACxB;gBAED,IAAI,CAAC,IAAI,EAAE;AACP,oBAAA,OAAO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CAAC,CAAA,mCAAA,EAAsC,MAAM,CAAA,CAAA,CAAG,CAAC,CAAC;yCACxD;wCAAC,OAAO,KAAK,EAAE;4CACZ,GAAG,CAAC,+BAA+B,MAAM,CAAA,EAAA,CAAI,EAAG,KAAe,CAAC,OAAO,CAAC,CAAC;;yCAE5E;qCACJ;oCAED,OAAO,cAAc,CAAC,IAAI,CAAC,UAAU,EAAE,MAAM,EAAE,IAAI,CAAC,CAAC;AACzD,iCAAC,CAAC;6BACL;AAED,4BAAA,OAAO,QAAQ,CAAC;yBACnB;qBACJ,CAAC;iBACL;AACD,gBAAA,WAAW,EAAE,OAAO,EAAE,CAAC;aAC1B,CAAC;SACL;KACJ,CAAC;AACN"}
|
|
@@ -0,0 +1,211 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Function Reference Helper for Inngest
|
|
3
|
+
*
|
|
4
|
+
* Provides automatic function reference resolution for all registered functions.
|
|
5
|
+
* Instead of manually importing functions, you can reference them by ID.
|
|
6
|
+
*
|
|
7
|
+
* This combines:
|
|
8
|
+
* 1. Inngest's native `referenceFunction()` pattern
|
|
9
|
+
* 2. Automatic registry from all Feature-registered functions
|
|
10
|
+
* 3. Type-safe helpers for common patterns
|
|
11
|
+
*
|
|
12
|
+
* Usage:
|
|
13
|
+
* ```typescript
|
|
14
|
+
* // Instead of:
|
|
15
|
+
* import { someFunction } from '../other-module';
|
|
16
|
+
* await step.invoke('call-it', { function: someFunction, data: {...} });
|
|
17
|
+
*
|
|
18
|
+
* // You can do:
|
|
19
|
+
* await step.invoke('call-it', {
|
|
20
|
+
* function: ctx.resolveFunction('some-function-id'),
|
|
21
|
+
* data: {...}
|
|
22
|
+
* });
|
|
23
|
+
*
|
|
24
|
+
* // Or even simpler (if middleware auto-resolve enabled):
|
|
25
|
+
* await step.invoke('some-function-id', { data: {...} });
|
|
26
|
+
* ```
|
|
27
|
+
*/
|
|
28
|
+
import { InngestFunction } from 'inngest';
|
|
29
|
+
/**
|
|
30
|
+
* Global function registry
|
|
31
|
+
* Populated by setup.ts after all functions are loaded
|
|
32
|
+
*/
|
|
33
|
+
declare class FunctionRegistry {
|
|
34
|
+
private functions;
|
|
35
|
+
private initialized;
|
|
36
|
+
/**
|
|
37
|
+
* Register all functions from Feature system
|
|
38
|
+
*/
|
|
39
|
+
register(functions: InngestFunction.Any[]): void;
|
|
40
|
+
/**
|
|
41
|
+
* Get function by ID (case-insensitive)
|
|
42
|
+
*/
|
|
43
|
+
get(functionId: string): InngestFunction.Any | undefined;
|
|
44
|
+
/**
|
|
45
|
+
* Check if function exists
|
|
46
|
+
*/
|
|
47
|
+
has(functionId: string): boolean;
|
|
48
|
+
/**
|
|
49
|
+
* Get all registered function IDs
|
|
50
|
+
*/
|
|
51
|
+
getAllIds(): string[];
|
|
52
|
+
/**
|
|
53
|
+
* Get count of registered functions
|
|
54
|
+
*/
|
|
55
|
+
get count(): number;
|
|
56
|
+
/**
|
|
57
|
+
* Check if registry is initialized
|
|
58
|
+
*/
|
|
59
|
+
get isInitialized(): boolean;
|
|
60
|
+
/**
|
|
61
|
+
* Clear registry (for testing)
|
|
62
|
+
*/
|
|
63
|
+
clear(): void;
|
|
64
|
+
}
|
|
65
|
+
export declare const globalFunctionRegistry: FunctionRegistry;
|
|
66
|
+
/**
|
|
67
|
+
* Reference a function by its ID
|
|
68
|
+
* Similar to Inngest's native referenceFunction, but automatically uses global registry
|
|
69
|
+
*
|
|
70
|
+
* @param functionIdOrOptions - The ID of the function or options object with functionId
|
|
71
|
+
* @returns The function reference to use in step.invoke()
|
|
72
|
+
*
|
|
73
|
+
* @example
|
|
74
|
+
* ```typescript
|
|
75
|
+
* // Simple usage
|
|
76
|
+
* const userCreateFn = referenceFunction('user-create');
|
|
77
|
+
*
|
|
78
|
+
* // Type-safe usage
|
|
79
|
+
* const computePi = referenceFunction({ functionId: 'compute-pi' });
|
|
80
|
+
*
|
|
81
|
+
* await step.invoke('create-user', {
|
|
82
|
+
* function: userCreateFn,
|
|
83
|
+
* data: { email: 'user@example.com' }
|
|
84
|
+
* });
|
|
85
|
+
* ```
|
|
86
|
+
*/
|
|
87
|
+
export declare function referenceFunction<T extends InngestFunction.Any = InngestFunction.Any>(functionIdOrOptions: string | {
|
|
88
|
+
functionId: string;
|
|
89
|
+
}): T;
|
|
90
|
+
/**
|
|
91
|
+
* Batch reference multiple functions at once
|
|
92
|
+
* Useful for orchestrator workflows that call many functions
|
|
93
|
+
*
|
|
94
|
+
* @example
|
|
95
|
+
* ```typescript
|
|
96
|
+
* const { userCreate, emailSend, analyticsTrack } = referenceFunctions([
|
|
97
|
+
* 'user-create',
|
|
98
|
+
* 'email-send-welcome',
|
|
99
|
+
* 'analytics-track-event'
|
|
100
|
+
* ]);
|
|
101
|
+
*
|
|
102
|
+
* await step.invoke('create-user', { function: userCreate, data: {...} });
|
|
103
|
+
* await step.invoke('send-email', { function: emailSend, data: {...} });
|
|
104
|
+
* await step.invoke('track', { function: analyticsTrack, data: {...} });
|
|
105
|
+
* ```
|
|
106
|
+
*/
|
|
107
|
+
export declare function referenceFunctions<T extends readonly string[]>(functionIds: T): {
|
|
108
|
+
[K in T[number]]: InngestFunction.Any;
|
|
109
|
+
};
|
|
110
|
+
/**
|
|
111
|
+
* Check if a function is registered
|
|
112
|
+
* Useful for conditional logic
|
|
113
|
+
*
|
|
114
|
+
* @example
|
|
115
|
+
* ```typescript
|
|
116
|
+
* if (hasFunctionReference('email-send-welcome')) {
|
|
117
|
+
* const emailFn = referenceFunction('email-send-welcome');
|
|
118
|
+
* await step.invoke('send-email', { function: emailFn, data: {...} });
|
|
119
|
+
* }
|
|
120
|
+
* ```
|
|
121
|
+
*/
|
|
122
|
+
export declare function hasFunctionReference(functionId: string): boolean;
|
|
123
|
+
/**
|
|
124
|
+
* Get all available function IDs
|
|
125
|
+
* Useful for debugging and introspection
|
|
126
|
+
*
|
|
127
|
+
* @example
|
|
128
|
+
* ```typescript
|
|
129
|
+
* console.log('Available functions:', getAvailableFunctions());
|
|
130
|
+
* ```
|
|
131
|
+
*/
|
|
132
|
+
export declare function getAvailableFunctions(): string[];
|
|
133
|
+
/**
|
|
134
|
+
* Resolve a workflow-style or ID-style function reference to an Inngest function reference.
|
|
135
|
+
*
|
|
136
|
+
* Supported inputs:
|
|
137
|
+
* - Exact function id: "user-create"
|
|
138
|
+
* - Workflow-style: "WORKFLOWNAME.Function/trigger" or "WORKFLOWNAME.Function.trigger"
|
|
139
|
+
*
|
|
140
|
+
* The resolver will first try the exact ID as provided. If not found it will
|
|
141
|
+
* normalize the string by replacing separators ("/", ".") with dashes and
|
|
142
|
+
* collapsing non-alphanumerics, then lower-case the result. Example:
|
|
143
|
+
*
|
|
144
|
+
* WORKFLOWNAME.Function/trigger -> workflowname-function-trigger
|
|
145
|
+
*
|
|
146
|
+
* If still not found, it will throw the same helpful error as `referenceFunction`.
|
|
147
|
+
*/
|
|
148
|
+
export declare function resolveFunctionId(functionRef: string | {
|
|
149
|
+
functionId: string;
|
|
150
|
+
}): InngestFunction.Any;
|
|
151
|
+
/**
|
|
152
|
+
* Middleware that injects referenceFunction into context
|
|
153
|
+
* Makes it available in all function handlers
|
|
154
|
+
*
|
|
155
|
+
* @example
|
|
156
|
+
* ```typescript
|
|
157
|
+
* const inngest = new Inngest({
|
|
158
|
+
* middleware: [createFunctionReferenceMiddleware()],
|
|
159
|
+
* });
|
|
160
|
+
*
|
|
161
|
+
* const myFn = inngest.createFunction(..., async ({ step, ctx }) => {
|
|
162
|
+
* // Access via context!
|
|
163
|
+
* const userFn = ctx.resolveFunction('user-create');
|
|
164
|
+
* await step.invoke('create-user', { function: userFn, data: {...} });
|
|
165
|
+
* });
|
|
166
|
+
* ```
|
|
167
|
+
*/
|
|
168
|
+
export declare function createFunctionReferenceMiddleware(): {
|
|
169
|
+
name: string;
|
|
170
|
+
init(): {
|
|
171
|
+
onFunctionRun({ ctx }: any): {
|
|
172
|
+
transformInput(inputCtx: any): any;
|
|
173
|
+
};
|
|
174
|
+
onSendEvent: () => {};
|
|
175
|
+
};
|
|
176
|
+
};
|
|
177
|
+
/**
|
|
178
|
+
* Combined middleware: Reference + Auto-Resolve
|
|
179
|
+
* Provides both manual and automatic function resolution
|
|
180
|
+
*
|
|
181
|
+
* @example
|
|
182
|
+
* ```typescript
|
|
183
|
+
* const inngest = new Inngest({
|
|
184
|
+
* middleware: [createCombinedFunctionMiddleware()],
|
|
185
|
+
* });
|
|
186
|
+
*
|
|
187
|
+
* // Method 1: Manual reference
|
|
188
|
+
* const userFn = ctx.resolveFunction('user-create');
|
|
189
|
+
* await step.invoke('create-user', { function: userFn, data: {...} });
|
|
190
|
+
*
|
|
191
|
+
* // Method 2: Automatic (if function ID matches)
|
|
192
|
+
* await step.invoke('user-create', { data: {...} }); // Auto-resolved!
|
|
193
|
+
* ```
|
|
194
|
+
*/
|
|
195
|
+
export declare function createCombinedFunctionMiddleware(options?: {
|
|
196
|
+
/** Enable auto-resolve (default: true) */
|
|
197
|
+
autoResolve?: boolean;
|
|
198
|
+
/** Case-sensitive matching (default: false) */
|
|
199
|
+
caseSensitive?: boolean;
|
|
200
|
+
/** Enable debug logging (default: false) */
|
|
201
|
+
debug?: boolean;
|
|
202
|
+
}): {
|
|
203
|
+
name: string;
|
|
204
|
+
init(): {
|
|
205
|
+
onFunctionRun({ ctx }: any): {
|
|
206
|
+
transformInput(inputCtx: any): any;
|
|
207
|
+
};
|
|
208
|
+
onSendEvent: () => {};
|
|
209
|
+
};
|
|
210
|
+
};
|
|
211
|
+
export {};
|