@ivan-pasco/clean-node-server 0.1.49 → 0.1.50

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.
@@ -1,35 +1,92 @@
1
+ import { WasmState } from '../types';
2
+ export type JobStatus = 'pending' | 'running' | 'succeeded' | 'failed' | 'cancelled';
3
+ export type BackoffStrategy = 'fixed' | 'exponential';
4
+ interface JobConfig {
5
+ name: string;
6
+ handler: string;
7
+ maxAttempts: number;
8
+ backoff: BackoffStrategy;
9
+ delayMs: number;
10
+ timeoutMs: number;
11
+ queue: string;
12
+ }
13
+ interface JobRecord {
14
+ id: string;
15
+ name: string;
16
+ args: string;
17
+ status: JobStatus;
18
+ attempt: number;
19
+ maxAttempts: number;
20
+ backoff: BackoffStrategy;
21
+ delayMs: number;
22
+ timeoutMs: number;
23
+ queue: string;
24
+ handler: string;
25
+ scheduledAt: number;
26
+ createdAt: number;
27
+ updatedAt: number;
28
+ finishedAt: number | null;
29
+ result: string | null;
30
+ error: string | null;
31
+ }
1
32
  /**
2
- * frame.jobs (background job queue) bridge node-server stubs.
3
- *
4
- * The frame.jobs runtime is implemented in clean-server (Rust) at
5
- * clean-server/src/jobs.rs — FIFO queue with SQLite persistence,
6
- * retry/backoff state machine, worker pool, and request-scoped current-job
7
- * accessors.
8
- *
9
- * Porting to TypeScript is tracked in
10
- * foundation/management/cross-component-prompts/
11
- * all-host-bridge-parity-enforcement.md (Step 4 — node-server jobs).
12
- *
13
- * These stubs satisfy the WASM linker contract so apps using `jobs:` blocks
14
- * can instantiate on node-server, but any actual queue call fails loudly
15
- * instead of crashing in WASM linking or silently dropping work.
16
- *
17
- * Signature reference: foundation/platform-architecture/function-registry.toml
18
- * (entries with category = "jobs").
33
+ * Start the jobs worker against the provided WASM instance. Idempotent.
34
+ * Opens the SQLite store, ensures schema, recovers pending records, and
35
+ * begins polling every `WORKER_POLL_MS` ms.
19
36
  */
20
- import { WasmState } from '../types';
21
- export declare function createJobsBridge(_getState: () => WasmState): {
22
- _job_register(_namePtr: number, _maxAttempts: number, _backoffPtr: number, _baseMs: number, _maxMs: number, _retriesPtr: number, _timeoutPtr: number): void;
23
- _job_enqueue(_namePtr: number, _argsPtr: number): number;
24
- _job_enqueue_at(_namePtr: number, _argsPtr: number, _epochMs: number): number;
25
- _job_cancel(_idPtr: number): number;
26
- _job_status(_idPtr: number): number;
27
- _job_result(_idPtr: number): number;
37
+ export declare function startJobWorker(state: WasmState): void;
38
+ /** Stop the worker, clear in-memory state and the DB handle. */
39
+ export declare function stopJobWorker(): void;
40
+ /** Test-only synchronous tick — runs one poll/dispatch cycle. */
41
+ export declare function _runJobWorkerTickForTest(): void;
42
+ /** Test-only registry snapshot. */
43
+ export declare function _getJobsSnapshotForTest(): {
44
+ configs: JobConfig[];
45
+ records: Omit<JobRecord, 'updatedAt' | 'createdAt'>[];
46
+ };
47
+ export declare function createJobsBridge(getState: () => WasmState): {
48
+ /**
49
+ * Register a job handler.
50
+ * Registry: params=["string","string","i32","string","i32","i32","string"], returns="void"
51
+ * WASM args: (name_ptr,name_len, handler_ptr,handler_len, max_attempts:i32,
52
+ * backoff_ptr,backoff_len, delay:i32, timeout:i32,
53
+ * queue_ptr,queue_len)
54
+ */
55
+ _job_register(namePtr: number, nameLen: number, handlerPtr: number, handlerLen: number, maxAttempts: number, backoffPtr: number, backoffLen: number, delayMs: number, timeoutMs: number, queuePtr: number, queueLen: number): void;
56
+ /**
57
+ * Enqueue a job for immediate execution.
58
+ * Registry: params=["string","string"], returns="ptr" (LP string job ID).
59
+ */
60
+ _job_enqueue(namePtr: number, nameLen: number, argsPtr: number, argsLen: number): number;
61
+ /**
62
+ * Schedule a job at a specific Unix epoch ms (f64).
63
+ * Registry: params=["string","string","number"], returns="ptr".
64
+ * NaN / negative timestamps are clamped to 0 (run immediately).
65
+ */
66
+ _job_enqueue_at(namePtr: number, nameLen: number, argsPtr: number, argsLen: number, runAtMs: number): number;
67
+ /**
68
+ * Cancel a pending job.
69
+ * Registry: params=["string"], returns="boolean" — clean-server's wrapper
70
+ * returns 0 = cancelled, -1 = not found / not pending. Both are i32 at
71
+ * the WASM-shape layer; node-server matches the runtime values exactly.
72
+ */
73
+ _job_cancel(idPtr: number, idLen: number): number;
74
+ /** Return current status string (LP). */
75
+ _job_status(idPtr: number, idLen: number): number;
76
+ /** Return result/error string (LP). */
77
+ _job_result(idPtr: number, idLen: number): number;
78
+ /** Current job id inside a handler — empty string outside. */
28
79
  _job_current_id(): number;
80
+ /** Current job args inside a handler — empty string outside. */
29
81
  _job_current_args(): number;
82
+ /** Current attempt number (1-based) — 0 outside. */
30
83
  _job_current_attempt(): number;
31
- _job_retry_after(_delayMs: number): void;
32
- _job_fail(_msgPtr: number): void;
33
- _job_succeed(_resultPtr: number): void;
84
+ /** Override the backoff delay for this attempt's retry. */
85
+ _job_retry_after(delayMs: number): void;
86
+ /** Mark the current attempt as a permanent failure. */
87
+ _job_fail(reasonPtr: number, reasonLen: number): void;
88
+ /** Mark the current attempt as succeeded with the given JSON result. */
89
+ _job_succeed(resultPtr: number, resultLen: number): void;
34
90
  };
91
+ export {};
35
92
  //# sourceMappingURL=jobs.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"jobs.d.ts","sourceRoot":"","sources":["../../src/bridge/jobs.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AACH,OAAO,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AAWrC,wBAAgB,gBAAgB,CAAC,SAAS,EAAE,MAAM,SAAS;4BAG3C,MAAM,gBAAgB,MAAM,eAAe,MAAM,WAClD,MAAM,UAAU,MAAM,eAAe,MAAM,eAAe,MAAM,GACxE,IAAI;2BAIgB,MAAM,YAAY,MAAM,GAAG,MAAM;8BAI9B,MAAM,YAAY,MAAM,YAAY,MAAM,GAAG,MAAM;wBAIzD,MAAM,GAAG,MAAM;wBAIf,MAAM,GAAG,MAAM;wBAIf,MAAM,GAAG,MAAM;uBAIhB,MAAM;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