@nwire/forge 0.9.1 → 0.10.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/README.md +133 -155
- package/dist/foundation.d.ts +0 -13
- package/dist/foundation.js +2 -13
- package/dist/framework-events.d.ts +51 -54
- package/dist/framework-events.js +18 -65
- package/dist/{cli-runner.d.ts → helpers/cli-runner.d.ts} +2 -3
- package/dist/{cli-runner.js → helpers/cli-runner.js} +11 -27
- package/dist/{public-marker.d.ts → helpers/public-marker.d.ts} +0 -1
- package/dist/{public-marker.js → helpers/public-marker.js} +0 -1
- package/dist/{response.d.ts → helpers/response.d.ts} +0 -1
- package/dist/{response.js → helpers/response.js} +0 -1
- package/dist/helpers/retry-helpers.d.ts +22 -0
- package/dist/helpers/retry-helpers.js +43 -0
- package/dist/{validate.d.ts → helpers/validate.d.ts} +0 -1
- package/dist/{validate.js → helpers/validate.js} +0 -1
- package/dist/index.d.ts +42 -48
- package/dist/index.js +47 -55
- package/dist/{event-message.d.ts → messages/event-message.d.ts} +0 -1
- package/dist/{event-message.js → messages/event-message.js} +0 -1
- package/dist/{dev-logger.d.ts → observability/dev-logger.d.ts} +2 -2
- package/dist/{dev-logger.js → observability/dev-logger.js} +0 -30
- package/dist/{define-action.d.ts → primitives/define-action.d.ts} +0 -1
- package/dist/{define-action.js → primitives/define-action.js} +0 -1
- package/dist/{define-actor.d.ts → primitives/define-actor.d.ts} +0 -1
- package/dist/{define-actor.js → primitives/define-actor.js} +0 -1
- package/dist/{define-cron.d.ts → primitives/define-cron.d.ts} +0 -1
- package/dist/{define-cron.js → primitives/define-cron.js} +0 -1
- package/dist/{define-error.d.ts → primitives/define-error.d.ts} +0 -1
- package/dist/{define-error.js → primitives/define-error.js} +0 -1
- package/dist/{define-external-call.d.ts → primitives/define-external-call.d.ts} +0 -1
- package/dist/{define-external-call.js → primitives/define-external-call.js} +0 -1
- package/dist/{define-handler.d.ts → primitives/define-handler.d.ts} +29 -2
- package/dist/{define-handler.js → primitives/define-handler.js} +13 -2
- package/dist/{define-inbound-webhook.d.ts → primitives/define-inbound-webhook.d.ts} +1 -2
- package/dist/{define-inbound-webhook.js → primitives/define-inbound-webhook.js} +1 -2
- package/dist/{define-inbox.d.ts → primitives/define-inbox.d.ts} +0 -1
- package/dist/{define-inbox.js → primitives/define-inbox.js} +0 -1
- package/dist/{define-outbox.d.ts → primitives/define-outbox.d.ts} +0 -1
- package/dist/{define-outbox.js → primitives/define-outbox.js} +0 -1
- package/dist/{define-projection.d.ts → primitives/define-projection.d.ts} +0 -1
- package/dist/{define-projection.js → primitives/define-projection.js} +0 -1
- package/dist/{define-query.d.ts → primitives/define-query.d.ts} +1 -2
- package/dist/{define-query.js → primitives/define-query.js} +1 -2
- package/dist/{define-schema.d.ts → primitives/define-schema.d.ts} +1 -2
- package/dist/{define-schema.js → primitives/define-schema.js} +1 -2
- package/dist/{define-upcaster.d.ts → primitives/define-upcaster.d.ts} +0 -1
- package/dist/{define-upcaster.js → primitives/define-upcaster.js} +0 -1
- package/dist/{define-workflow.d.ts → primitives/define-workflow.d.ts} +2 -3
- package/dist/{define-workflow.js → primitives/define-workflow.js} +2 -3
- package/dist/runtime/create-forge-app.d.ts +64 -0
- package/dist/runtime/create-forge-app.js +78 -0
- package/dist/runtime/forge-dispatcher.d.ts +148 -0
- package/dist/{runtime.js → runtime/forge-dispatcher.js} +242 -571
- package/dist/runtime/forge-plugin.d.ts +59 -0
- package/dist/runtime/forge-plugin.js +121 -0
- package/dist/runtime/forge-types.d.ts +204 -0
- package/dist/runtime/forge-types.js +5 -0
- package/dist/{actor-store.d.ts → stores/actor-store.d.ts} +1 -2
- package/dist/{actor-store.js → stores/actor-store.js} +0 -1
- package/dist/{idempotency-store.d.ts → stores/idempotency-store.d.ts} +0 -1
- package/dist/{idempotency-store.js → stores/idempotency-store.js} +0 -1
- package/dist/{projection-store.d.ts → stores/projection-store.d.ts} +0 -1
- package/dist/{projection-store.js → stores/projection-store.js} +0 -1
- package/dist/{workflow-timer-store.d.ts → stores/workflow-timer-store.d.ts} +0 -1
- package/dist/{workflow-timer-store.js → stores/workflow-timer-store.js} +0 -1
- package/package.json +11 -11
- package/dist/__tests__/action-hooks.test.d.ts +0 -8
- package/dist/__tests__/action-hooks.test.d.ts.map +0 -1
- package/dist/__tests__/action-hooks.test.js +0 -95
- package/dist/__tests__/action-hooks.test.js.map +0 -1
- package/dist/__tests__/actor-methods.test.d.ts +0 -9
- package/dist/__tests__/actor-methods.test.d.ts.map +0 -1
- package/dist/__tests__/actor-methods.test.js +0 -210
- package/dist/__tests__/actor-methods.test.js.map +0 -1
- package/dist/__tests__/actor-schema-bound.test.d.ts +0 -6
- package/dist/__tests__/actor-schema-bound.test.d.ts.map +0 -1
- package/dist/__tests__/actor-schema-bound.test.js +0 -112
- package/dist/__tests__/actor-schema-bound.test.js.map +0 -1
- package/dist/__tests__/actor-workflow-hooks.test.d.ts +0 -8
- package/dist/__tests__/actor-workflow-hooks.test.d.ts.map +0 -1
- package/dist/__tests__/actor-workflow-hooks.test.js +0 -106
- package/dist/__tests__/actor-workflow-hooks.test.js.map +0 -1
- package/dist/__tests__/app-capabilities.test.d.ts +0 -19
- package/dist/__tests__/app-capabilities.test.d.ts.map +0 -1
- package/dist/__tests__/app-capabilities.test.js +0 -57
- package/dist/__tests__/app-capabilities.test.js.map +0 -1
- package/dist/__tests__/cli-runner.test.d.ts +0 -6
- package/dist/__tests__/cli-runner.test.d.ts.map +0 -1
- package/dist/__tests__/cli-runner.test.js +0 -158
- package/dist/__tests__/cli-runner.test.js.map +0 -1
- package/dist/__tests__/create-app.test.d.ts +0 -18
- package/dist/__tests__/create-app.test.d.ts.map +0 -1
- package/dist/__tests__/create-app.test.js +0 -189
- package/dist/__tests__/create-app.test.js.map +0 -1
- package/dist/__tests__/cross-service-bus.test.d.ts +0 -8
- package/dist/__tests__/cross-service-bus.test.d.ts.map +0 -1
- package/dist/__tests__/cross-service-bus.test.js +0 -139
- package/dist/__tests__/cross-service-bus.test.js.map +0 -1
- package/dist/__tests__/define-schema.test.d.ts +0 -5
- package/dist/__tests__/define-schema.test.d.ts.map +0 -1
- package/dist/__tests__/define-schema.test.js +0 -83
- package/dist/__tests__/define-schema.test.js.map +0 -1
- package/dist/__tests__/dev-logger.test.d.ts +0 -9
- package/dist/__tests__/dev-logger.test.d.ts.map +0 -1
- package/dist/__tests__/dev-logger.test.js +0 -126
- package/dist/__tests__/dev-logger.test.js.map +0 -1
- package/dist/__tests__/external-call.test.d.ts +0 -14
- package/dist/__tests__/external-call.test.d.ts.map +0 -1
- package/dist/__tests__/external-call.test.js +0 -99
- package/dist/__tests__/external-call.test.js.map +0 -1
- package/dist/__tests__/framework-events.test.d.ts +0 -13
- package/dist/__tests__/framework-events.test.d.ts.map +0 -1
- package/dist/__tests__/framework-events.test.js +0 -204
- package/dist/__tests__/framework-events.test.js.map +0 -1
- package/dist/__tests__/inline-handler.test.d.ts +0 -8
- package/dist/__tests__/inline-handler.test.d.ts.map +0 -1
- package/dist/__tests__/inline-handler.test.js +0 -101
- package/dist/__tests__/inline-handler.test.js.map +0 -1
- package/dist/__tests__/lifecycle-logging.test.d.ts +0 -12
- package/dist/__tests__/lifecycle-logging.test.d.ts.map +0 -1
- package/dist/__tests__/lifecycle-logging.test.js +0 -114
- package/dist/__tests__/lifecycle-logging.test.js.map +0 -1
- package/dist/__tests__/middleware.test.d.ts +0 -7
- package/dist/__tests__/middleware.test.d.ts.map +0 -1
- package/dist/__tests__/middleware.test.js +0 -109
- package/dist/__tests__/middleware.test.js.map +0 -1
- package/dist/__tests__/module-needs.test.d.ts +0 -10
- package/dist/__tests__/module-needs.test.d.ts.map +0 -1
- package/dist/__tests__/module-needs.test.js +0 -77
- package/dist/__tests__/module-needs.test.js.map +0 -1
- package/dist/__tests__/module-topo-sort.test.d.ts +0 -15
- package/dist/__tests__/module-topo-sort.test.d.ts.map +0 -1
- package/dist/__tests__/module-topo-sort.test.js +0 -105
- package/dist/__tests__/module-topo-sort.test.js.map +0 -1
- package/dist/__tests__/multi-tenancy.test.d.ts +0 -10
- package/dist/__tests__/multi-tenancy.test.d.ts.map +0 -1
- package/dist/__tests__/multi-tenancy.test.js +0 -122
- package/dist/__tests__/multi-tenancy.test.js.map +0 -1
- package/dist/__tests__/needs-topology.test.d.ts +0 -11
- package/dist/__tests__/needs-topology.test.d.ts.map +0 -1
- package/dist/__tests__/needs-topology.test.js +0 -82
- package/dist/__tests__/needs-topology.test.js.map +0 -1
- package/dist/__tests__/plugin-app-narrow.test.d.ts +0 -12
- package/dist/__tests__/plugin-app-narrow.test.d.ts.map +0 -1
- package/dist/__tests__/plugin-app-narrow.test.js +0 -77
- package/dist/__tests__/plugin-app-narrow.test.js.map +0 -1
- package/dist/__tests__/plugin-closure.test.d.ts +0 -15
- package/dist/__tests__/plugin-closure.test.d.ts.map +0 -1
- package/dist/__tests__/plugin-closure.test.js +0 -140
- package/dist/__tests__/plugin-closure.test.js.map +0 -1
- package/dist/__tests__/plugin-stress.test.d.ts +0 -21
- package/dist/__tests__/plugin-stress.test.d.ts.map +0 -1
- package/dist/__tests__/plugin-stress.test.js +0 -203
- package/dist/__tests__/plugin-stress.test.js.map +0 -1
- package/dist/__tests__/plugin.test.d.ts +0 -10
- package/dist/__tests__/plugin.test.d.ts.map +0 -1
- package/dist/__tests__/plugin.test.js +0 -225
- package/dist/__tests__/plugin.test.js.map +0 -1
- package/dist/__tests__/primitives.test.d.ts +0 -9
- package/dist/__tests__/primitives.test.d.ts.map +0 -1
- package/dist/__tests__/primitives.test.js +0 -434
- package/dist/__tests__/primitives.test.js.map +0 -1
- package/dist/__tests__/production-readiness.test.d.ts +0 -22
- package/dist/__tests__/production-readiness.test.d.ts.map +0 -1
- package/dist/__tests__/production-readiness.test.js +0 -196
- package/dist/__tests__/production-readiness.test.js.map +0 -1
- package/dist/__tests__/provider.test.d.ts +0 -6
- package/dist/__tests__/provider.test.d.ts.map +0 -1
- package/dist/__tests__/provider.test.js +0 -122
- package/dist/__tests__/provider.test.js.map +0 -1
- package/dist/__tests__/public-marker.test.d.ts +0 -7
- package/dist/__tests__/public-marker.test.d.ts.map +0 -1
- package/dist/__tests__/public-marker.test.js +0 -58
- package/dist/__tests__/public-marker.test.js.map +0 -1
- package/dist/__tests__/retry-dlq.test.d.ts +0 -6
- package/dist/__tests__/retry-dlq.test.d.ts.map +0 -1
- package/dist/__tests__/retry-dlq.test.js +0 -68
- package/dist/__tests__/retry-dlq.test.js.map +0 -1
- package/dist/__tests__/validate.test.d.ts +0 -5
- package/dist/__tests__/validate.test.d.ts.map +0 -1
- package/dist/__tests__/validate.test.js +0 -53
- package/dist/__tests__/validate.test.js.map +0 -1
- package/dist/__tests__/workflow-saga.test.d.ts +0 -7
- package/dist/__tests__/workflow-saga.test.d.ts.map +0 -1
- package/dist/__tests__/workflow-saga.test.js +0 -265
- package/dist/__tests__/workflow-saga.test.js.map +0 -1
- package/dist/actor-store.d.ts.map +0 -1
- package/dist/actor-store.js.map +0 -1
- package/dist/cli-runner.d.ts.map +0 -1
- package/dist/cli-runner.js.map +0 -1
- package/dist/create-app.d.ts +0 -146
- package/dist/create-app.d.ts.map +0 -1
- package/dist/create-app.js +0 -703
- package/dist/create-app.js.map +0 -1
- package/dist/define-action.d.ts.map +0 -1
- package/dist/define-action.js.map +0 -1
- package/dist/define-actor.d.ts.map +0 -1
- package/dist/define-actor.js.map +0 -1
- package/dist/define-app.d.ts +0 -104
- package/dist/define-app.d.ts.map +0 -1
- package/dist/define-app.js +0 -49
- package/dist/define-app.js.map +0 -1
- package/dist/define-cron.d.ts.map +0 -1
- package/dist/define-cron.js.map +0 -1
- package/dist/define-error.d.ts.map +0 -1
- package/dist/define-error.js.map +0 -1
- package/dist/define-external-call.d.ts.map +0 -1
- package/dist/define-external-call.js.map +0 -1
- package/dist/define-handler.d.ts.map +0 -1
- package/dist/define-handler.js.map +0 -1
- package/dist/define-inbound-webhook.d.ts.map +0 -1
- package/dist/define-inbound-webhook.js.map +0 -1
- package/dist/define-inbox.d.ts.map +0 -1
- package/dist/define-inbox.js.map +0 -1
- package/dist/define-initializer.d.ts +0 -54
- package/dist/define-initializer.d.ts.map +0 -1
- package/dist/define-initializer.js +0 -38
- package/dist/define-initializer.js.map +0 -1
- package/dist/define-middleware.d.ts +0 -8
- package/dist/define-middleware.d.ts.map +0 -1
- package/dist/define-middleware.js +0 -8
- package/dist/define-middleware.js.map +0 -1
- package/dist/define-model.d.ts +0 -10
- package/dist/define-model.d.ts.map +0 -1
- package/dist/define-model.js +0 -13
- package/dist/define-model.js.map +0 -1
- package/dist/define-module.d.ts +0 -160
- package/dist/define-module.d.ts.map +0 -1
- package/dist/define-module.js +0 -63
- package/dist/define-module.js.map +0 -1
- package/dist/define-outbox.d.ts.map +0 -1
- package/dist/define-outbox.js.map +0 -1
- package/dist/define-plugin.d.ts +0 -195
- package/dist/define-plugin.d.ts.map +0 -1
- package/dist/define-plugin.js +0 -220
- package/dist/define-plugin.js.map +0 -1
- package/dist/define-projection.d.ts.map +0 -1
- package/dist/define-projection.js.map +0 -1
- package/dist/define-provider.d.ts +0 -49
- package/dist/define-provider.d.ts.map +0 -1
- package/dist/define-provider.js +0 -45
- package/dist/define-provider.js.map +0 -1
- package/dist/define-query.d.ts.map +0 -1
- package/dist/define-query.js.map +0 -1
- package/dist/define-resolver.d.ts +0 -111
- package/dist/define-resolver.d.ts.map +0 -1
- package/dist/define-resolver.js +0 -146
- package/dist/define-resolver.js.map +0 -1
- package/dist/define-schema.d.ts.map +0 -1
- package/dist/define-schema.js.map +0 -1
- package/dist/define-upcaster.d.ts.map +0 -1
- package/dist/define-upcaster.js.map +0 -1
- package/dist/define-workflow.d.ts.map +0 -1
- package/dist/define-workflow.js.map +0 -1
- package/dist/dev-logger.d.ts.map +0 -1
- package/dist/dev-logger.js.map +0 -1
- package/dist/event-message.d.ts.map +0 -1
- package/dist/event-message.js.map +0 -1
- package/dist/foundation.d.ts.map +0 -1
- package/dist/foundation.js.map +0 -1
- package/dist/framework-event-bus.d.ts +0 -13
- package/dist/framework-event-bus.d.ts.map +0 -1
- package/dist/framework-event-bus.js +0 -13
- package/dist/framework-event-bus.js.map +0 -1
- package/dist/framework-events.d.ts.map +0 -1
- package/dist/framework-events.js.map +0 -1
- package/dist/idempotency-store.d.ts.map +0 -1
- package/dist/idempotency-store.js.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/module-surface.d.ts +0 -47
- package/dist/module-surface.d.ts.map +0 -1
- package/dist/module-surface.js +0 -65
- package/dist/module-surface.js.map +0 -1
- package/dist/projection-store.d.ts.map +0 -1
- package/dist/projection-store.js.map +0 -1
- package/dist/public-marker.d.ts.map +0 -1
- package/dist/public-marker.js.map +0 -1
- package/dist/response.d.ts.map +0 -1
- package/dist/response.js.map +0 -1
- package/dist/runtime.d.ts +0 -621
- package/dist/runtime.d.ts.map +0 -1
- package/dist/runtime.js.map +0 -1
- package/dist/validate.d.ts.map +0 -1
- package/dist/validate.js.map +0 -1
- package/dist/when.d.ts +0 -101
- package/dist/when.d.ts.map +0 -1
- package/dist/when.js +0 -57
- package/dist/when.js.map +0 -1
- package/dist/workflow-timer-store.d.ts.map +0 -1
- package/dist/workflow-timer-store.js.map +0 -1
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
*
|
|
13
13
|
* #!/usr/bin/env node
|
|
14
14
|
* import { runCli } from '@nwire/forge'
|
|
15
|
-
* import { boot } from './app/boot
|
|
15
|
+
* import { boot } from './app/boot'
|
|
16
16
|
*
|
|
17
17
|
* const app = await boot() // returns { learnflow: App }
|
|
18
18
|
* const exitCode = await runCli(app.learnflow, process.argv.slice(2))
|
|
@@ -43,14 +43,14 @@ export async function runCli(app, argv, options = {}) {
|
|
|
43
43
|
}
|
|
44
44
|
const targetName = argv[0];
|
|
45
45
|
const rest = argv.slice(1);
|
|
46
|
-
|
|
47
|
-
const action =
|
|
46
|
+
const dispatcher = app.dispatcher();
|
|
47
|
+
const action = dispatcher.findActionByName(targetName);
|
|
48
48
|
if (action) {
|
|
49
49
|
const { tenant, parsed } = parseFlags(rest);
|
|
50
50
|
try {
|
|
51
51
|
const validated = action.schema.parse(parsed);
|
|
52
52
|
const envelope = tenant ? seedEnvelope({ tenant }) : undefined;
|
|
53
|
-
await app.
|
|
53
|
+
await app.dispatch(action, validated, envelope);
|
|
54
54
|
stdout("OK");
|
|
55
55
|
return 0;
|
|
56
56
|
}
|
|
@@ -60,10 +60,10 @@ export async function runCli(app, argv, options = {}) {
|
|
|
60
60
|
}
|
|
61
61
|
}
|
|
62
62
|
// Fall back to query.
|
|
63
|
-
if (
|
|
63
|
+
if (dispatcher.listQueries().includes(targetName)) {
|
|
64
64
|
const { tenant, parsed } = parseFlags(rest);
|
|
65
65
|
try {
|
|
66
|
-
const result = await app.
|
|
66
|
+
const result = await app.query(targetName, parsed, tenant);
|
|
67
67
|
stdout(JSON.stringify(result, null, 2));
|
|
68
68
|
return 0;
|
|
69
69
|
}
|
|
@@ -75,32 +75,17 @@ export async function runCli(app, argv, options = {}) {
|
|
|
75
75
|
stderr(`unknown action or query: "${targetName}". Run with --help for the list.`);
|
|
76
76
|
return 1;
|
|
77
77
|
}
|
|
78
|
-
function findAction(app, name) {
|
|
79
|
-
return toActionMap(app)[name];
|
|
80
|
-
}
|
|
81
|
-
function toActionMap(app) {
|
|
82
|
-
const map = {};
|
|
83
|
-
for (const module of app.modules) {
|
|
84
|
-
for (const action of module.manifest.actions ?? []) {
|
|
85
|
-
map[action.name] = action;
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
return map;
|
|
89
|
-
}
|
|
90
78
|
function printHelp(app, stdout) {
|
|
79
|
+
const dispatcher = app.dispatcher();
|
|
91
80
|
stdout("nwire — action CLI runner\n");
|
|
92
81
|
stdout("Usage: amit <action-or-query-name> [--field value ...] [--tenant <id>]\n");
|
|
93
82
|
stdout("Actions:");
|
|
94
|
-
for (const
|
|
95
|
-
|
|
96
|
-
stdout(` ${action.name}${action.description ? " — " + action.description.slice(0, 60) : ""}`);
|
|
97
|
-
}
|
|
83
|
+
for (const name of dispatcher.listHandlers()) {
|
|
84
|
+
stdout(` ${name}`);
|
|
98
85
|
}
|
|
99
86
|
stdout("Queries:");
|
|
100
|
-
for (const
|
|
101
|
-
|
|
102
|
-
stdout(` ${query.name}${query.description ? " — " + query.description.slice(0, 60) : ""}`);
|
|
103
|
-
}
|
|
87
|
+
for (const name of dispatcher.listQueries()) {
|
|
88
|
+
stdout(` ${name}`);
|
|
104
89
|
}
|
|
105
90
|
}
|
|
106
91
|
function parseFlags(argv) {
|
|
@@ -161,4 +146,3 @@ function coerce(value) {
|
|
|
161
146
|
return Number(value);
|
|
162
147
|
return value;
|
|
163
148
|
}
|
|
164
|
-
//# sourceMappingURL=cli-runner.js.map
|
|
@@ -5,4 +5,3 @@
|
|
|
5
5
|
* the same export names so existing call sites compile unchanged.
|
|
6
6
|
*/
|
|
7
7
|
export { response, isResponseSpec, isResponseInstance, ok, created, accepted, noContent, notModified, gone, type ResponseSpec, type ListResponseSpec, type ResponseInstance, type ResponseSpecBase, type ResponseKind, } from "@nwire/handler";
|
|
8
|
-
//# sourceMappingURL=response.d.ts.map
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Retry-loop helpers shared between forge's dispatch path and the
|
|
3
|
+
* external-call execution path. Lives in its own file so both
|
|
4
|
+
* `runtime.ts` and `forge-dispatcher.ts` can import without circles.
|
|
5
|
+
*/
|
|
6
|
+
export declare function sleep(ms: number): Promise<void>;
|
|
7
|
+
/**
|
|
8
|
+
* Compute the delay before attempt `attemptIndex` (1-indexed) given a
|
|
9
|
+
* retry config. Returns 0 when no retry is configured. Exponential by
|
|
10
|
+
* default with `2^(attemptIndex-1) * baseDelayMs`, capped at `maxDelayMs`;
|
|
11
|
+
* `backoff: "fixed"` uses `baseDelayMs` flat.
|
|
12
|
+
*/
|
|
13
|
+
export declare function computeBackoff(retry: {
|
|
14
|
+
backoff?: "exponential" | "fixed";
|
|
15
|
+
baseDelayMs?: number;
|
|
16
|
+
maxDelayMs?: number;
|
|
17
|
+
} | undefined, attemptIndex: number): number;
|
|
18
|
+
/**
|
|
19
|
+
* Parse a delay string like '3d', '90s', '4h' into milliseconds.
|
|
20
|
+
* Supports: ms, s, m, h, d. Numbers without units treated as ms.
|
|
21
|
+
*/
|
|
22
|
+
export declare function parseDelay(value: string): number;
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Retry-loop helpers shared between forge's dispatch path and the
|
|
3
|
+
* external-call execution path. Lives in its own file so both
|
|
4
|
+
* `runtime.ts` and `forge-dispatcher.ts` can import without circles.
|
|
5
|
+
*/
|
|
6
|
+
export function sleep(ms) {
|
|
7
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Compute the delay before attempt `attemptIndex` (1-indexed) given a
|
|
11
|
+
* retry config. Returns 0 when no retry is configured. Exponential by
|
|
12
|
+
* default with `2^(attemptIndex-1) * baseDelayMs`, capped at `maxDelayMs`;
|
|
13
|
+
* `backoff: "fixed"` uses `baseDelayMs` flat.
|
|
14
|
+
*/
|
|
15
|
+
export function computeBackoff(retry, attemptIndex) {
|
|
16
|
+
if (!retry)
|
|
17
|
+
return 0;
|
|
18
|
+
const base = retry.baseDelayMs ?? 100;
|
|
19
|
+
const cap = retry.maxDelayMs ?? 30_000;
|
|
20
|
+
if (retry.backoff === "fixed")
|
|
21
|
+
return Math.min(base, cap);
|
|
22
|
+
return Math.min(Math.floor(Math.pow(2, attemptIndex - 1) * base), cap);
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Parse a delay string like '3d', '90s', '4h' into milliseconds.
|
|
26
|
+
* Supports: ms, s, m, h, d. Numbers without units treated as ms.
|
|
27
|
+
*/
|
|
28
|
+
export function parseDelay(value) {
|
|
29
|
+
const match = /^(\d+(?:\.\d+)?)(ms|s|m|h|d)?$/.exec(value);
|
|
30
|
+
if (!match) {
|
|
31
|
+
throw new Error(`Runtime: cannot parse delay "${value}". Expected '3d', '90s', '4h', '500ms'.`);
|
|
32
|
+
}
|
|
33
|
+
const n = Number(match[1]);
|
|
34
|
+
const unit = match[2] ?? "ms";
|
|
35
|
+
const multipliers = {
|
|
36
|
+
ms: 1,
|
|
37
|
+
s: 1000,
|
|
38
|
+
m: 60_000,
|
|
39
|
+
h: 3_600_000,
|
|
40
|
+
d: 86_400_000,
|
|
41
|
+
};
|
|
42
|
+
return n * (multipliers[unit] ?? 1);
|
|
43
|
+
}
|
|
@@ -30,4 +30,3 @@ export type Invariant<TInput, TState = unknown> = (input: TInput, state: TState)
|
|
|
30
30
|
export declare function validate<TInput, TState = unknown>(input: TInput, predicates: ReadonlyArray<Invariant<TInput, TState>>, state?: TState): void;
|
|
31
31
|
/** Type-narrowing predicate. */
|
|
32
32
|
export declare function isInvariantError(x: unknown): x is InvariantError;
|
|
33
|
-
//# sourceMappingURL=validate.d.ts.map
|
package/dist/index.d.ts
CHANGED
|
@@ -1,55 +1,49 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* `@nwire/forge` —
|
|
2
|
+
* `@nwire/forge` — CQRS engine delivered as an app plugin.
|
|
3
3
|
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
* — one primitive). Actors carry state when entities need identity over time.
|
|
7
|
-
* Projections + queries are the read side.
|
|
4
|
+
* import { createApp } from "@nwire/app";
|
|
5
|
+
* import { forgePlugin } from "@nwire/forge";
|
|
8
6
|
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
*
|
|
7
|
+
* const app = createApp({ appName: "orders", plugins: [forgePlugin, …] });
|
|
8
|
+
*
|
|
9
|
+
* Or via the convenience wrapper that auto-installs forgePlugin and adds
|
|
10
|
+
* the dispatch/publish/query/… verbs as methods on the app handle:
|
|
11
|
+
*
|
|
12
|
+
* import { createForgeApp } from "@nwire/forge";
|
|
13
|
+
*
|
|
14
|
+
* const app = createForgeApp({ name: "orders", handlers, actors, … });
|
|
17
15
|
*/
|
|
18
|
-
export {
|
|
19
|
-
export {
|
|
20
|
-
export {
|
|
21
|
-
export {
|
|
22
|
-
export {
|
|
23
|
-
export {
|
|
24
|
-
export {
|
|
25
|
-
export {
|
|
26
|
-
export {
|
|
27
|
-
export {
|
|
28
|
-
export {
|
|
29
|
-
export {
|
|
30
|
-
export {
|
|
31
|
-
export {
|
|
32
|
-
export {
|
|
33
|
-
export {
|
|
34
|
-
export {
|
|
35
|
-
export {
|
|
36
|
-
export {
|
|
37
|
-
export {
|
|
16
|
+
export { forgePlugin, createForgePlugin, FORGE_DISPATCHER_BINDING, } from "./runtime/forge-plugin.js";
|
|
17
|
+
export { ForgeDispatcher, type ForgeDispatcherOptions } from "./runtime/forge-dispatcher.js";
|
|
18
|
+
export type { ForgeTelemetry, DispatchOptions, ActionBeforeHookCtx, ActionAfterHookCtx, ActorTransitionHookCtx, WorkflowFireHookCtx, } from "./runtime/forge-types.js";
|
|
19
|
+
export { createForgeApp, type ForgeApp, type ForgeAppOptions, } from "./runtime/create-forge-app.js";
|
|
20
|
+
export { defineAction, isCommandMessage, resolveDispatch, type ActionDefinition, type CallableActionDefinition, type CommandMessage, type ActionMeta, type ActionInput, type ActionResult, type ActionPolicy, type NwireActionRegistry, type RetryPolicy, } from "./primitives/define-action.js";
|
|
21
|
+
export { defineActor, eventKey, type ActorDefinition, type ActorOptions, type ActorOptionsBound, type ActorReaction, type ActorStateConfig, type ActorTimerSpec, type ActorMethod, type ActorInstanceView, } from "./primitives/define-actor.js";
|
|
22
|
+
export { defineSchema, isSchemaDefinition, type SchemaDefinition, type SchemaOptions, type SchemaStateSpec, type SchemaStorageHints, } from "./primitives/define-schema.js";
|
|
23
|
+
export { validate, isInvariantError, InvariantError, type Invariant } from "./helpers/validate.js";
|
|
24
|
+
export { defineHandler, type HandlerContext, type HandlerDefinition, type HandlerReturn, } from "./primitives/define-handler.js";
|
|
25
|
+
export { eventFactory, isEventMessage, normalizeEventReturn, type EventMessage, type EventFactory, } from "./messages/event-message.js";
|
|
26
|
+
export { defineWorkflow, COMPLETE_EVENT_NAME, type WorkflowDefinition, type WorkflowContext, type StatelessWorkflowContext, type StatefulWorkflowContext, type WorkflowEffects, type WorkflowOptions, type StatelessWorkflowOptions, type StatefulWorkflowOptions, type WorkflowOnOptions, type WorkflowRetryPolicy, type WorkflowStateSpec, type WorkflowInstance, type WorkflowCorrelateMap, type FireContext, type CompleteEvent, type StateCallable, type TimerDefinition, } from "./primitives/define-workflow.js";
|
|
27
|
+
export { defineProjection, type ProjectionDefinition, type ProjectionOptions, type ProjectionReducer, } from "./primitives/define-projection.js";
|
|
28
|
+
export { defineQuery, type QueryDefinition, type QueryOptions } from "./primitives/define-query.js";
|
|
29
|
+
export { defineUpcaster, applyUpcasters, type UpcasterDefinition } from "./primitives/define-upcaster.js";
|
|
30
|
+
export { defineExternalCall, type ExternalCallDefinition, type ExternalCallMeta, type ExternalCallTarget, type ExternalCallSlo, type ExternalCallRetry, type ExternalCallExecutor, } from "./primitives/define-external-call.js";
|
|
31
|
+
export { defineInboundWebhook, type InboundWebhookDefinition, type InboundWebhookMeta, type WebhookSignatureVerifier, type WebhookDedupe, } from "./primitives/define-inbound-webhook.js";
|
|
32
|
+
export { defineOutbox, type OutboxDefinition, type OutboxMeta } from "./primitives/define-outbox.js";
|
|
33
|
+
export { defineInbox, type InboxDefinition, type InboxMeta } from "./primitives/define-inbox.js";
|
|
34
|
+
export { defineCron, type CronDefinition, type CronMeta } from "./primitives/define-cron.js";
|
|
35
|
+
export { defineError, isNwireError, NwireError, Unauthorized, Forbidden, NotFound, Gone, BadRequest, Conflict, type ErrorDefinition, type ErrorMeta, } from "./primitives/define-error.js";
|
|
36
|
+
export { InMemoryActorStore, createInitialInstance, ActorVersionConflictError, type ActorStore, type ActorInstance, type ActorSaveOptions, type ActorTimerHandle, } from "./stores/actor-store.js";
|
|
37
|
+
export { InMemoryProjectionStore, type ProjectionStore } from "./stores/projection-store.js";
|
|
38
|
+
export { InMemoryIdempotencyStore, type IdempotencyStore } from "./stores/idempotency-store.js";
|
|
39
|
+
export { InMemoryWorkflowTimerStore, timerEventName, type WorkflowTimer, type WorkflowTimerStore, } from "./stores/workflow-timer-store.js";
|
|
40
|
+
export { parseDelay } from "./helpers/retry-helpers.js";
|
|
41
|
+
export { isPublic, type PublicMarker } from "./helpers/public-marker.js";
|
|
42
|
+
export { attachDevLogger, formatTelemetry, type DevLoggerOptions } from "./observability/dev-logger.js";
|
|
43
|
+
export { runCli, type RunCliOptions } from "./helpers/cli-runner.js";
|
|
38
44
|
export { NoopLogger, ConsoleLogger, loggerForEnvelope, type Logger } from "@nwire/logger";
|
|
39
45
|
export { InMemoryDeadLetterSink, buildDeadLetterEntry, type DeadLetterSink, type DeadLetterEntry, } from "@nwire/dead-letter";
|
|
40
|
-
export type { RetryPolicy } from "./define-action.js";
|
|
41
|
-
export type { DispatchOptions } from "./runtime.js";
|
|
42
|
-
export { defineProjection, type ProjectionDefinition, type ProjectionOptions, type ProjectionReducer, } from "./define-projection.js";
|
|
43
|
-
export { InMemoryProjectionStore, type ProjectionStore } from "./projection-store.js";
|
|
44
|
-
export { InMemoryIdempotencyStore, type IdempotencyStore } from "./idempotency-store.js";
|
|
45
|
-
export { defineQuery, type QueryDefinition, type QueryOptions } from "./define-query.js";
|
|
46
|
-
export { defineUpcaster, applyUpcasters, type UpcasterDefinition } from "./define-upcaster.js";
|
|
47
|
-
export { defineModule, type ModuleDefinition, type ModuleManifest, type ModuleNeeds, } from "./define-module.js";
|
|
48
|
-
export { createApp, type App, type CreateAppOptions, type TimerSchedulerOptions, } from "./create-app.js";
|
|
49
|
-
export { attachDevLogger, formatTelemetry, type DevLoggerOptions } from "./dev-logger.js";
|
|
50
|
-
export { defineApp, type AppDefinition, type DefineAppOptions, type EndpointDefinition, type TenantModel, } from "./define-app.js";
|
|
51
|
-
export { definePlugin, type PluginDefinition, type PluginOptions, type PluginContext, type PluginSetup, type PluginActorHooks, type ActorTransitionHook, } from "./define-plugin.js";
|
|
52
46
|
export { defineResource, isResourceDefinition, type ResourceDefinition, type DefineResourceOptions, } from "@nwire/handler";
|
|
53
|
-
export {
|
|
54
|
-
|
|
55
|
-
|
|
47
|
+
export { response, isResponseSpec, isResponseInstance, ok, created, accepted, noContent, notModified, gone, type ResponseSpec, type ListResponseSpec, type ResponseInstance, type ResponseKind, } from "./helpers/response.js";
|
|
48
|
+
import "./framework-events";
|
|
49
|
+
export type { FrameworkHooks, PluginKind } from "@nwire/app";
|
package/dist/index.js
CHANGED
|
@@ -1,62 +1,54 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* `@nwire/forge` —
|
|
2
|
+
* `@nwire/forge` — CQRS engine delivered as an app plugin.
|
|
3
3
|
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
* — one primitive). Actors carry state when entities need identity over time.
|
|
7
|
-
* Projections + queries are the read side.
|
|
4
|
+
* import { createApp } from "@nwire/app";
|
|
5
|
+
* import { forgePlugin } from "@nwire/forge";
|
|
8
6
|
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
*
|
|
7
|
+
* const app = createApp({ appName: "orders", plugins: [forgePlugin, …] });
|
|
8
|
+
*
|
|
9
|
+
* Or via the convenience wrapper that auto-installs forgePlugin and adds
|
|
10
|
+
* the dispatch/publish/query/… verbs as methods on the app handle:
|
|
11
|
+
*
|
|
12
|
+
* import { createForgeApp } from "@nwire/forge";
|
|
13
|
+
*
|
|
14
|
+
* const app = createForgeApp({ name: "orders", handlers, actors, … });
|
|
17
15
|
*/
|
|
18
|
-
|
|
19
|
-
export {
|
|
20
|
-
export {
|
|
21
|
-
export {
|
|
22
|
-
|
|
23
|
-
export {
|
|
24
|
-
export {
|
|
25
|
-
export {
|
|
26
|
-
export {
|
|
27
|
-
export {
|
|
28
|
-
|
|
29
|
-
export {
|
|
30
|
-
export {
|
|
31
|
-
export {
|
|
32
|
-
export {
|
|
33
|
-
export {
|
|
34
|
-
export {
|
|
35
|
-
|
|
36
|
-
export {
|
|
37
|
-
export {
|
|
38
|
-
export {
|
|
39
|
-
//
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
//
|
|
45
|
-
export {
|
|
16
|
+
// ─── Plugin + composition ──────────────────────────────────────────
|
|
17
|
+
export { forgePlugin, createForgePlugin, FORGE_DISPATCHER_BINDING, } from "./runtime/forge-plugin.js";
|
|
18
|
+
export { ForgeDispatcher } from "./runtime/forge-dispatcher.js";
|
|
19
|
+
export { createForgeApp, } from "./runtime/create-forge-app.js";
|
|
20
|
+
// ─── Domain primitives ─────────────────────────────────────────────
|
|
21
|
+
export { defineAction, isCommandMessage, resolveDispatch, } from "./primitives/define-action.js";
|
|
22
|
+
export { defineActor, eventKey, } from "./primitives/define-actor.js";
|
|
23
|
+
export { defineSchema, isSchemaDefinition, } from "./primitives/define-schema.js";
|
|
24
|
+
export { validate, isInvariantError, InvariantError } from "./helpers/validate.js";
|
|
25
|
+
export { defineHandler, } from "./primitives/define-handler.js";
|
|
26
|
+
export { eventFactory, isEventMessage, normalizeEventReturn, } from "./messages/event-message.js";
|
|
27
|
+
export { defineWorkflow, COMPLETE_EVENT_NAME, } from "./primitives/define-workflow.js";
|
|
28
|
+
export { defineProjection, } from "./primitives/define-projection.js";
|
|
29
|
+
export { defineQuery } from "./primitives/define-query.js";
|
|
30
|
+
export { defineUpcaster, applyUpcasters } from "./primitives/define-upcaster.js";
|
|
31
|
+
export { defineExternalCall, } from "./primitives/define-external-call.js";
|
|
32
|
+
export { defineInboundWebhook, } from "./primitives/define-inbound-webhook.js";
|
|
33
|
+
export { defineOutbox } from "./primitives/define-outbox.js";
|
|
34
|
+
export { defineInbox } from "./primitives/define-inbox.js";
|
|
35
|
+
export { defineCron } from "./primitives/define-cron.js";
|
|
36
|
+
export { defineError, isNwireError, NwireError, Unauthorized, Forbidden, NotFound, Gone, BadRequest, Conflict, } from "./primitives/define-error.js";
|
|
37
|
+
// ─── Stores ────────────────────────────────────────────────────────
|
|
38
|
+
export { InMemoryActorStore, createInitialInstance, ActorVersionConflictError, } from "./stores/actor-store.js";
|
|
39
|
+
export { InMemoryProjectionStore } from "./stores/projection-store.js";
|
|
40
|
+
export { InMemoryIdempotencyStore } from "./stores/idempotency-store.js";
|
|
41
|
+
export { InMemoryWorkflowTimerStore, timerEventName, } from "./stores/workflow-timer-store.js";
|
|
42
|
+
// ─── Helpers ───────────────────────────────────────────────────────
|
|
43
|
+
export { parseDelay } from "./helpers/retry-helpers.js";
|
|
44
|
+
export { isPublic } from "./helpers/public-marker.js";
|
|
45
|
+
export { attachDevLogger, formatTelemetry } from "./observability/dev-logger.js";
|
|
46
|
+
export { runCli } from "./helpers/cli-runner.js";
|
|
47
|
+
// ─── Re-exports from neighbours ────────────────────────────────────
|
|
46
48
|
export { NoopLogger, ConsoleLogger, loggerForEnvelope } from "@nwire/logger";
|
|
47
49
|
export { InMemoryDeadLetterSink, buildDeadLetterEntry, } from "@nwire/dead-letter";
|
|
48
|
-
export { defineProjection, } from "./define-projection.js";
|
|
49
|
-
export { InMemoryProjectionStore } from "./projection-store.js";
|
|
50
|
-
export { InMemoryIdempotencyStore } from "./idempotency-store.js";
|
|
51
|
-
export { defineQuery } from "./define-query.js";
|
|
52
|
-
export { defineUpcaster, applyUpcasters } from "./define-upcaster.js";
|
|
53
|
-
export { defineModule, } from "./define-module.js";
|
|
54
|
-
export { createApp, } from "./create-app.js";
|
|
55
|
-
export { attachDevLogger, formatTelemetry } from "./dev-logger.js";
|
|
56
|
-
export { defineApp, } from "./define-app.js";
|
|
57
|
-
export { definePlugin, } from "./define-plugin.js";
|
|
58
|
-
// ─── Interface / app layer primitives ────────────────────────────
|
|
59
50
|
export { defineResource, isResourceDefinition, } from "@nwire/handler";
|
|
60
|
-
export {
|
|
61
|
-
|
|
62
|
-
|
|
51
|
+
export { response, isResponseSpec, isResponseInstance, ok, created, accepted, noContent, notModified, gone, } from "./helpers/response.js";
|
|
52
|
+
// Module augmentation side effect — adds Action* / Event* slots to
|
|
53
|
+
// FrameworkHooks on @nwire/app's runtime.
|
|
54
|
+
import "./framework-events";
|
|
@@ -41,4 +41,3 @@ export declare function isEventMessage(value: unknown): value is EventMessage;
|
|
|
41
41
|
* via `runtime.dispatch`'s return + the `ActionCompleted` event.
|
|
42
42
|
*/
|
|
43
43
|
export declare function normalizeEventReturn(value: void | EventMessage | EventMessage[] | Record<string, unknown> | null | undefined): EventMessage[];
|
|
44
|
-
//# sourceMappingURL=event-message.d.ts.map
|
|
@@ -15,7 +15,8 @@
|
|
|
15
15
|
* Orchestrator + queue/cron records are suppressed by default to keep
|
|
16
16
|
* the firehose readable.
|
|
17
17
|
*/
|
|
18
|
-
import type { Runtime
|
|
18
|
+
import type { Runtime } from "@nwire/app";
|
|
19
|
+
import type { ForgeTelemetry as Telemetry } from "../runtime/forge-types.js";
|
|
19
20
|
export interface DevLoggerOptions {
|
|
20
21
|
/**
|
|
21
22
|
* Filter — only records whose `kind` matches one of these is printed.
|
|
@@ -38,4 +39,3 @@ export declare function formatTelemetry(rec: Telemetry): string;
|
|
|
38
39
|
* stores the unsubscribe and calls it in stop().
|
|
39
40
|
*/
|
|
40
41
|
export declare function attachDevLogger(runtime: Runtime, options?: DevLoggerOptions): () => void;
|
|
41
|
-
//# sourceMappingURL=dev-logger.d.ts.map
|
|
@@ -24,7 +24,6 @@ const DEFAULT_KINDS = [
|
|
|
24
24
|
"reaction.failed",
|
|
25
25
|
"dlq.recorded",
|
|
26
26
|
"query.executed",
|
|
27
|
-
"lifecycle",
|
|
28
27
|
"hook.step",
|
|
29
28
|
];
|
|
30
29
|
/**
|
|
@@ -104,34 +103,6 @@ export function formatTelemetry(rec) {
|
|
|
104
103
|
const err = rec.error ? ` ${color(rec.error.message, RED)}` : "";
|
|
105
104
|
return `${dim(t)} ${phaseGlyph} ${tag}${padded} ${rec.hookName}:${stepLabel}${dur}${err}`;
|
|
106
105
|
}
|
|
107
|
-
case "lifecycle": {
|
|
108
|
-
// Namespaced lifecycle log: render `nwire:<ns>` colored by phase
|
|
109
|
-
// (app / plugin / wire / hook) so the eye groups events by axis.
|
|
110
|
-
// Pad the visible tag width to 14 chars so subsequent columns
|
|
111
|
-
// line up regardless of which namespace.
|
|
112
|
-
const visibleTag = `nwire:${rec.namespace}`;
|
|
113
|
-
const padded = visibleTag.padEnd(14, " ");
|
|
114
|
-
const tag = namespaceTag(rec.namespace) + padded.slice(visibleTag.length);
|
|
115
|
-
const marker = rec.phase === "prevented" ? color("✗", RED) : color("•", DIM);
|
|
116
|
-
// Strip the leading `nwire.` from the event name — every event has
|
|
117
|
-
// it; printing it once via the colored tag is enough.
|
|
118
|
-
const shortName = rec.event.replace(/^nwire\./, "");
|
|
119
|
-
// Pull the most useful 1-2 fields out of the payload for context.
|
|
120
|
-
const p = rec.payload;
|
|
121
|
-
const ctx = [];
|
|
122
|
-
if (p) {
|
|
123
|
-
if (typeof p["pluginName"] === "string")
|
|
124
|
-
ctx.push(p["pluginName"]);
|
|
125
|
-
if (typeof p["transport"] === "string")
|
|
126
|
-
ctx.push(p["transport"]);
|
|
127
|
-
if (typeof p["reason"] === "string")
|
|
128
|
-
ctx.push(p["reason"]);
|
|
129
|
-
if (typeof p["durationMs"] === "number")
|
|
130
|
-
ctx.push(`${p["durationMs"]}ms`);
|
|
131
|
-
}
|
|
132
|
-
const ctxLine = ctx.length > 0 ? ` ${dim(ctx.join(" · "))}` : "";
|
|
133
|
-
return `${dim(t)} ${marker} ${tag} ${shortName}${ctxLine}`;
|
|
134
|
-
}
|
|
135
106
|
default:
|
|
136
107
|
return `${dim(t)} ${rec.kind}`;
|
|
137
108
|
}
|
|
@@ -153,4 +124,3 @@ export function attachDevLogger(runtime, options) {
|
|
|
153
124
|
write(line);
|
|
154
125
|
});
|
|
155
126
|
}
|
|
156
|
-
//# sourceMappingURL=dev-logger.js.map
|
|
@@ -30,7 +30,7 @@ import type { z } from "zod";
|
|
|
30
30
|
import type { ZodTypeAny, SourceLocation } from "@nwire/messages";
|
|
31
31
|
import type { Container } from "@nwire/container";
|
|
32
32
|
import type { MessageEnvelope } from "@nwire/envelope";
|
|
33
|
-
import type { EventMessage } from "
|
|
33
|
+
import type { EventMessage } from "../messages/event-message.js";
|
|
34
34
|
import type { ActionDefinition, ActionInput, ActionResult } from "./define-action.js";
|
|
35
35
|
import type { ActorDefinition, ActorInstanceView } from "./define-actor.js";
|
|
36
36
|
import type { QueryDefinition } from "./define-query.js";
|
|
@@ -123,12 +123,39 @@ export interface HandlerContext {
|
|
|
123
123
|
* at runtime by the missing `eventName` + `payload` shape.
|
|
124
124
|
*/
|
|
125
125
|
export type HandlerReturn = void | EventMessage | EventMessage[] | Record<string, unknown> | null;
|
|
126
|
+
/**
|
|
127
|
+
* Outer-ctx shape `HandlerDefinition.run` consumes. Matches what
|
|
128
|
+
* `@nwire/app`'s `Runtime.execute` builds: `input`, `envelope`, and a
|
|
129
|
+
* `resolve` looking up bindings on the per-request scope. Forge's `.run`
|
|
130
|
+
* implementation pulls the forge dispatcher off the container and
|
|
131
|
+
* delegates so the full dispatcher pipeline (validation, action.before/
|
|
132
|
+
* after hooks, retry, telemetry, persistence, …) fires.
|
|
133
|
+
*/
|
|
134
|
+
export interface HandlerRunCtx<TSchema extends ZodTypeAny = ZodTypeAny> {
|
|
135
|
+
readonly input: z.output<TSchema>;
|
|
136
|
+
readonly envelope?: MessageEnvelope;
|
|
137
|
+
resolve<T = unknown>(name: string): T;
|
|
138
|
+
}
|
|
139
|
+
export interface HandlerRunOptions {
|
|
140
|
+
readonly signal?: AbortSignal;
|
|
141
|
+
}
|
|
126
142
|
export interface HandlerDefinition<TSchema extends ZodTypeAny = ZodTypeAny> {
|
|
127
143
|
readonly $kind: "handler";
|
|
128
144
|
readonly action: ActionDefinition<TSchema>;
|
|
129
145
|
readonly handler: (input: z.output<TSchema>, ctx: HandlerContext) => Promise<HandlerReturn> | HandlerReturn;
|
|
130
146
|
/** Where the handler was declared. Studio uses this for IDE-open links. */
|
|
131
147
|
readonly $source?: SourceLocation;
|
|
148
|
+
/**
|
|
149
|
+
* Forge handlers satisfy the `@nwire/handler.HandlerDefinition` shape
|
|
150
|
+
* structurally so `Runtime.execute(handler, input, envelope)` works
|
|
151
|
+
* directly without the adopter knowing about forge. The fields below
|
|
152
|
+
* expose the metadata `Runtime` reads + the canonical `run()` entry
|
|
153
|
+
* point that routes through the forge dispatcher.
|
|
154
|
+
*/
|
|
155
|
+
readonly name: string;
|
|
156
|
+
readonly input: TSchema;
|
|
157
|
+
run(ctx: HandlerRunCtx<TSchema>, opts?: HandlerRunOptions): Promise<{
|
|
158
|
+
result: ActionResult<ActionDefinition<TSchema>>;
|
|
159
|
+
}>;
|
|
132
160
|
}
|
|
133
161
|
export declare function defineHandler<TSchema extends ZodTypeAny>(action: ActionDefinition<TSchema>, handler: HandlerDefinition<TSchema>["handler"]): HandlerDefinition<TSchema>;
|
|
134
|
-
//# sourceMappingURL=define-handler.d.ts.map
|