@nanobpm/urban 0.28.0 → 0.29.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/dist/runtime/adapters/deno.js +5 -0
- package/dist/runtime/adapters/node.js +5 -0
- package/dist/runtime/core/execContext.d.ts +28 -0
- package/dist/runtime/core/execContext.js +39 -0
- package/dist/runtime/core/host.d.ts +41 -0
- package/dist/runtime/core/manifest.d.ts +1 -1
- package/dist/runtime/core/modules/connectors.js +3 -1
- package/dist/runtime/core/modules/datasource.d.ts +18 -1
- package/dist/runtime/core/modules/datasource.js +56 -2
- package/dist/runtime/core/modules/gateway.d.ts +10 -3
- package/dist/runtime/core/modules/gateway.js +23 -6
- package/dist/runtime/core/modules/instance-tracking.d.ts +14 -0
- package/dist/runtime/core/modules/instance-tracking.js +141 -0
- package/dist/runtime/core/modules/scheduler.d.ts +11 -0
- package/dist/runtime/core/modules/scheduler.js +21 -0
- package/dist/runtime/core/modules/triggers.d.ts +2 -8
- package/dist/runtime/core/modules/triggers.js +1 -16
- package/dist/runtime/core/modules/workers.js +3 -2
- package/dist/runtime/core/runtime.d.ts +3 -0
- package/dist/runtime/core/runtime.js +12 -0
- package/dist/runtime/core/validate.js +38 -0
- package/dist/runtime/engine/nanosdk.d.ts +14 -1
- package/dist/runtime/engine/nanosdk.js +49 -0
- package/package.json +2 -2
- package/src/runtime/adapters/deno.ts +6 -0
- package/src/runtime/adapters/node.ts +6 -0
- package/src/runtime/core/execContext.ts +56 -0
- package/src/runtime/core/host.ts +44 -0
- package/src/runtime/core/manifest.ts +1 -0
- package/src/runtime/core/modules/actions.test.ts +1 -0
- package/src/runtime/core/modules/connectors.test.ts +1 -0
- package/src/runtime/core/modules/connectors.ts +7 -1
- package/src/runtime/core/modules/datasource.migrations.test.ts +1 -0
- package/src/runtime/core/modules/datasource.ts +72 -2
- package/src/runtime/core/modules/gateway.ts +28 -6
- package/src/runtime/core/modules/instance-tracking.test.ts +345 -0
- package/src/runtime/core/modules/instance-tracking.ts +158 -0
- package/src/runtime/core/modules/pages.test.ts +1 -0
- package/src/runtime/core/modules/provenance.test.ts +181 -0
- package/src/runtime/core/modules/scheduler.ts +31 -0
- package/src/runtime/core/modules/surfaces.test.ts +2 -0
- package/src/runtime/core/modules/triggers.test.ts +1 -0
- package/src/runtime/core/modules/triggers.ts +3 -25
- package/src/runtime/core/modules/workers.test.ts +1 -0
- package/src/runtime/core/modules/workers.ts +11 -2
- package/src/runtime/core/runtime.test.ts +3 -0
- package/src/runtime/core/runtime.ts +16 -0
- package/src/runtime/core/validate.test.ts +96 -0
- package/src/runtime/core/validate.ts +39 -0
- package/src/runtime/engine/nanosdk.test.ts +73 -0
- package/src/runtime/engine/nanosdk.ts +63 -0
|
@@ -15,6 +15,8 @@ import type {
|
|
|
15
15
|
EngineClient,
|
|
16
16
|
EngineJob,
|
|
17
17
|
JobHandler,
|
|
18
|
+
ProcessInstanceSnapshot,
|
|
19
|
+
ProcessInstanceState,
|
|
18
20
|
WorkerSubscription,
|
|
19
21
|
} from "../core/host.ts";
|
|
20
22
|
import { isBpmnError } from "../core/host.ts";
|
|
@@ -30,6 +32,26 @@ export function requireProcessInstanceKey(key: string | number | null | undefine
|
|
|
30
32
|
return String(key);
|
|
31
33
|
}
|
|
32
34
|
|
|
35
|
+
/** Map the engine's process-instance `state` onto the transport-agnostic
|
|
36
|
+
* {@link ProcessInstanceState} union, or `undefined` for an unrecognized value
|
|
37
|
+
* (which the caller skips rather than mis-reconciling). Case-insensitive so a
|
|
38
|
+
* future casing tweak on the engine side doesn't silently drop instances. */
|
|
39
|
+
export function normalizeProcessInstanceState(
|
|
40
|
+
raw: unknown,
|
|
41
|
+
): ProcessInstanceState | undefined {
|
|
42
|
+
if (typeof raw !== "string") return undefined;
|
|
43
|
+
switch (raw.toUpperCase()) {
|
|
44
|
+
case "ACTIVE":
|
|
45
|
+
return "ACTIVE";
|
|
46
|
+
case "COMPLETED":
|
|
47
|
+
return "COMPLETED";
|
|
48
|
+
case "TERMINATED":
|
|
49
|
+
return "TERMINATED";
|
|
50
|
+
default:
|
|
51
|
+
return undefined;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
33
55
|
/** A job as delivered to a nano-sdk job handler: the frame fields plus the
|
|
34
56
|
* acknowledgement actions the handler must call. */
|
|
35
57
|
export interface NanoSdkActivatedJob {
|
|
@@ -103,6 +125,11 @@ export interface NanoSdkClient {
|
|
|
103
125
|
input: { userTaskKey: string; variables?: Record<string, unknown> },
|
|
104
126
|
options?: unknown,
|
|
105
127
|
): Promise<unknown>;
|
|
128
|
+
searchProcessInstances(
|
|
129
|
+
input: { filter?: Record<string, unknown>; page?: Record<string, unknown> },
|
|
130
|
+
consistency?: unknown,
|
|
131
|
+
options?: unknown,
|
|
132
|
+
): Promise<Record<string, unknown>>;
|
|
106
133
|
createJobWorker(cfg: NanoSdkJobWorkerConfig): NanoSdkJobWorker;
|
|
107
134
|
/** Stop every worker created on this client. Used on teardown to also drain a
|
|
108
135
|
* REST-fallback worker, whose handle the `createJobWorker` proxy starts internally
|
|
@@ -213,6 +240,42 @@ export class SdkEngineClient implements EngineClient {
|
|
|
213
240
|
await this.client.completeUserTask({ userTaskKey, variables: variables ?? {} });
|
|
214
241
|
}
|
|
215
242
|
|
|
243
|
+
async searchProcessInstances(filter?: {
|
|
244
|
+
processInstanceKeys?: string[];
|
|
245
|
+
state?: ProcessInstanceState;
|
|
246
|
+
}): Promise<ProcessInstanceSnapshot[]> {
|
|
247
|
+
const f: Record<string, unknown> = {};
|
|
248
|
+
if (filter?.state) f.state = filter.state;
|
|
249
|
+
const keys = filter?.processInstanceKeys?.filter((k) => k != null && k !== "");
|
|
250
|
+
if (keys && keys.length > 0) f.processInstanceKey = { $in: keys };
|
|
251
|
+
// A process-instance search is an eventually consistent read; ask for zero-wait
|
|
252
|
+
// consistency so it reflects what is currently visible without blocking. Cap the page
|
|
253
|
+
// to the number of keys asked for (each key matches at most one instance), so a bounded
|
|
254
|
+
// reconcile query never silently truncates on the API's default page size.
|
|
255
|
+
const page = keys && keys.length > 0 ? { limit: keys.length } : undefined;
|
|
256
|
+
const body = await this.client.searchProcessInstances(
|
|
257
|
+
{ filter: f, ...(page ? { page } : {}) },
|
|
258
|
+
{ consistency: { waitUpToMs: 0 } },
|
|
259
|
+
);
|
|
260
|
+
const items = Array.isArray(body.items) ? body.items.filter(isRecord) : [];
|
|
261
|
+
return items.flatMap((it) => {
|
|
262
|
+
const key = it.processInstanceKey;
|
|
263
|
+
if (key == null || key === "") {
|
|
264
|
+
this.log("warn", "skipping process instance with no key in engine response");
|
|
265
|
+
return [];
|
|
266
|
+
}
|
|
267
|
+
const state = normalizeProcessInstanceState(it.state);
|
|
268
|
+
if (!state) {
|
|
269
|
+
this.log("warn", "skipping process instance with unrecognized state", {
|
|
270
|
+
processInstanceKey: String(key),
|
|
271
|
+
state: String(it.state),
|
|
272
|
+
});
|
|
273
|
+
return [];
|
|
274
|
+
}
|
|
275
|
+
return [{ processInstanceKey: String(key), state }];
|
|
276
|
+
});
|
|
277
|
+
}
|
|
278
|
+
|
|
216
279
|
async registerWorker(
|
|
217
280
|
jobType: string,
|
|
218
281
|
handler: JobHandler,
|