@owlmeans/queue 0.1.18-rc.2 → 0.1.18-rc.21

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 (54) hide show
  1. package/README.md +237 -8
  2. package/agent-meta/manifest.json +2 -2
  3. package/agent-meta/skills/queue/SKILL.md +198 -12
  4. package/build/bridge.d.ts +30 -0
  5. package/build/bridge.d.ts.map +1 -0
  6. package/build/bridge.js +108 -0
  7. package/build/bridge.js.map +1 -0
  8. package/build/config.d.ts +22 -0
  9. package/build/config.d.ts.map +1 -0
  10. package/build/config.js +41 -0
  11. package/build/config.js.map +1 -0
  12. package/build/consts.d.ts +33 -0
  13. package/build/consts.d.ts.map +1 -0
  14. package/build/consts.js +35 -0
  15. package/build/consts.js.map +1 -0
  16. package/build/errors.d.ts +59 -0
  17. package/build/errors.d.ts.map +1 -0
  18. package/build/errors.js +90 -0
  19. package/build/errors.js.map +1 -0
  20. package/build/index.d.ts +8 -0
  21. package/build/index.d.ts.map +1 -1
  22. package/build/index.js +8 -1
  23. package/build/index.js.map +1 -1
  24. package/build/protocol.d.ts +11 -0
  25. package/build/protocol.d.ts.map +1 -0
  26. package/build/protocol.js +59 -0
  27. package/build/protocol.js.map +1 -0
  28. package/build/transport.d.ts +15 -0
  29. package/build/transport.d.ts.map +1 -0
  30. package/build/transport.js +62 -0
  31. package/build/transport.js.map +1 -0
  32. package/build/types.d.ts +248 -0
  33. package/build/types.d.ts.map +1 -0
  34. package/build/types.js +2 -0
  35. package/build/types.js.map +1 -0
  36. package/build/worker.d.ts +27 -0
  37. package/build/worker.d.ts.map +1 -0
  38. package/build/worker.js +58 -0
  39. package/build/worker.js.map +1 -0
  40. package/package.json +12 -2
  41. package/src/bridge.ts +126 -0
  42. package/src/config.ts +56 -0
  43. package/src/consts.ts +39 -0
  44. package/src/errors.ts +106 -0
  45. package/src/index.ts +8 -0
  46. package/src/protocol.ts +81 -0
  47. package/src/transport.ts +82 -0
  48. package/src/types.ts +260 -0
  49. package/src/worker.ts +72 -0
  50. package/tests/bridge.spec.ts +64 -0
  51. package/tests/config.spec.ts +66 -0
  52. package/tests/protocol.spec.ts +58 -0
  53. package/tsconfig.json +1 -0
  54. package/build/.gitkeep +0 -0
@@ -0,0 +1,22 @@
1
+ import type { Config, JobOptions, QueueDeclaration, QueueWorkerOptions } from './types.js';
2
+ /**
3
+ * Add a queue to the shared configuration. Every process in the monorepo loads the same
4
+ * declarations — a producer needs them to know a queue exists and what it accepts, a worker needs
5
+ * them to bind. Declaring twice replaces, so a helper that runs per app is safe to call.
6
+ */
7
+ export declare const declareQueue: <C extends Config>(cfg: C, name: string, jobs: string[], opts?: {
8
+ worker?: QueueWorkerOptions;
9
+ defaults?: JobOptions;
10
+ }) => C;
11
+ /**
12
+ * Name the queues this process consumes. It is what turns an otherwise identical binary into a
13
+ * worker, which is why it lives in the process's own config and never in a declaration.
14
+ */
15
+ export declare const listenQueues: <C extends Config>(cfg: C, ...names: string[]) => C;
16
+ /**
17
+ * @throws {UnknownQueue}
18
+ */
19
+ export declare const queueOf: <C extends Config>(cfg: C, name: string) => QueueDeclaration;
20
+ export declare const queueOfJob: <C extends Config>(cfg: C, job: string) => QueueDeclaration | undefined;
21
+ export declare const isListening: <C extends Config>(cfg: C, name: string) => boolean;
22
+ //# sourceMappingURL=config.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,UAAU,EAAE,gBAAgB,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAA;AAG1F;;;;GAIG;AACH,eAAO,MAAM,YAAY,GAAI,CAAC,SAAS,MAAM,OACtC,CAAC,QAAQ,MAAM,QAAQ,MAAM,EAAE,SAAS;IAAE,MAAM,CAAC,EAAE,kBAAkB,CAAC;IAAC,QAAQ,CAAC,EAAE,UAAU,CAAA;CAAE,KAClG,CAcF,CAAA;AAED;;;GAGG;AACH,eAAO,MAAM,YAAY,GAAI,CAAC,SAAS,MAAM,OAAO,CAAC,YAAY,MAAM,EAAE,KAAG,CAM3E,CAAA;AAED;;GAEG;AACH,eAAO,MAAM,OAAO,GAAI,CAAC,SAAS,MAAM,OAAO,CAAC,QAAQ,MAAM,KAAG,gBAQhE,CAAA;AAED,eAAO,MAAM,UAAU,GAAI,CAAC,SAAS,MAAM,OAAO,CAAC,OAAO,MAAM,KAAG,gBAAgB,GAAG,SACpB,CAAA;AAElE,eAAO,MAAM,WAAW,GAAI,CAAC,SAAS,MAAM,OAAO,CAAC,QAAQ,MAAM,KAAG,OACzB,CAAA"}
@@ -0,0 +1,41 @@
1
+ import { UnknownQueue } from './errors.js';
2
+ /**
3
+ * Add a queue to the shared configuration. Every process in the monorepo loads the same
4
+ * declarations — a producer needs them to know a queue exists and what it accepts, a worker needs
5
+ * them to bind. Declaring twice replaces, so a helper that runs per app is safe to call.
6
+ */
7
+ export const declareQueue = (cfg, name, jobs, opts) => {
8
+ const queue = { name, jobs, ...opts };
9
+ const queues = cfg.queue?.queues ?? [];
10
+ const existing = queues.findIndex(declared => declared.name === name);
11
+ if (existing < 0) {
12
+ queues.push(queue);
13
+ }
14
+ else {
15
+ queues[existing] = queue;
16
+ }
17
+ cfg.queue = { ...cfg.queue, queues };
18
+ return cfg;
19
+ };
20
+ /**
21
+ * Name the queues this process consumes. It is what turns an otherwise identical binary into a
22
+ * worker, which is why it lives in the process's own config and never in a declaration.
23
+ */
24
+ export const listenQueues = (cfg, ...names) => {
25
+ const listen = new Set([...(cfg.queue?.listen ?? []), ...names]);
26
+ cfg.queue = { ...cfg.queue, listen: [...listen] };
27
+ return cfg;
28
+ };
29
+ /**
30
+ * @throws {UnknownQueue}
31
+ */
32
+ export const queueOf = (cfg, name) => {
33
+ const queue = cfg.queue?.queues?.find(declared => declared.name === name);
34
+ if (queue == null) {
35
+ throw new UnknownQueue(name);
36
+ }
37
+ return queue;
38
+ };
39
+ export const queueOfJob = (cfg, job) => cfg.queue?.queues?.find(declared => declared.jobs.includes(job));
40
+ export const isListening = (cfg, name) => cfg.queue?.listen?.includes(name) === true;
41
+ //# sourceMappingURL=config.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"config.js","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAA;AAE1C;;;;GAIG;AACH,MAAM,CAAC,MAAM,YAAY,GAAG,CAC1B,GAAM,EAAE,IAAY,EAAE,IAAc,EAAE,IAA6D,EAChG,EAAE;IACL,MAAM,KAAK,GAAqB,EAAE,IAAI,EAAE,IAAI,EAAE,GAAG,IAAI,EAAE,CAAA;IACvD,MAAM,MAAM,GAAG,GAAG,CAAC,KAAK,EAAE,MAAM,IAAI,EAAE,CAAA;IACtC,MAAM,QAAQ,GAAG,MAAM,CAAC,SAAS,CAAC,QAAQ,CAAC,EAAE,CAAC,QAAQ,CAAC,IAAI,KAAK,IAAI,CAAC,CAAA;IAErE,IAAI,QAAQ,GAAG,CAAC,EAAE,CAAC;QACjB,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAA;IACpB,CAAC;SAAM,CAAC;QACN,MAAM,CAAC,QAAQ,CAAC,GAAG,KAAK,CAAA;IAC1B,CAAC;IAED,GAAG,CAAC,KAAK,GAAG,EAAE,GAAG,GAAG,CAAC,KAAK,EAAE,MAAM,EAAE,CAAA;IAEpC,OAAO,GAAG,CAAA;AACZ,CAAC,CAAA;AAED;;;GAGG;AACH,MAAM,CAAC,MAAM,YAAY,GAAG,CAAmB,GAAM,EAAE,GAAG,KAAe,EAAK,EAAE;IAC9E,MAAM,MAAM,GAAG,IAAI,GAAG,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,KAAK,EAAE,MAAM,IAAI,EAAE,CAAC,EAAE,GAAG,KAAK,CAAC,CAAC,CAAA;IAEhE,GAAG,CAAC,KAAK,GAAG,EAAE,GAAG,GAAG,CAAC,KAAK,EAAE,MAAM,EAAE,CAAC,GAAG,MAAM,CAAC,EAAE,CAAA;IAEjD,OAAO,GAAG,CAAA;AACZ,CAAC,CAAA;AAED;;GAEG;AACH,MAAM,CAAC,MAAM,OAAO,GAAG,CAAmB,GAAM,EAAE,IAAY,EAAoB,EAAE;IAClF,MAAM,KAAK,GAAG,GAAG,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,CAAC,QAAQ,CAAC,EAAE,CAAC,QAAQ,CAAC,IAAI,KAAK,IAAI,CAAC,CAAA;IAEzE,IAAI,KAAK,IAAI,IAAI,EAAE,CAAC;QAClB,MAAM,IAAI,YAAY,CAAC,IAAI,CAAC,CAAA;IAC9B,CAAC;IAED,OAAO,KAAK,CAAA;AACd,CAAC,CAAA;AAED,MAAM,CAAC,MAAM,UAAU,GAAG,CAAmB,GAAM,EAAE,GAAW,EAAgC,EAAE,CAChG,GAAG,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,CAAC,QAAQ,CAAC,EAAE,CAAC,QAAQ,CAAC,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAA;AAElE,MAAM,CAAC,MAAM,WAAW,GAAG,CAAmB,GAAM,EAAE,IAAY,EAAW,EAAE,CAC7E,GAAG,CAAC,KAAK,EAAE,MAAM,EAAE,QAAQ,CAAC,IAAI,CAAC,KAAK,IAAI,CAAA"}
@@ -0,0 +1,33 @@
1
+ export declare const DEFAULT_ALIAS = "queue";
2
+ /**
3
+ * The state a job is in, as the broker reports it. `Waiting` covers both a job queued normally
4
+ * and one held by an unfinished parent — the difference matters to the broker, never to a caller
5
+ * asking whether an answer has arrived.
6
+ */
7
+ export declare enum JobState {
8
+ Waiting = "waiting",
9
+ Delayed = "delayed",
10
+ Active = "active",
11
+ Completed = "completed",
12
+ Failed = "failed",
13
+ Unknown = "unknown"
14
+ }
15
+ /** A job has reached a state it will not leave on its own. */
16
+ export declare const isSettled: (state?: JobState) => boolean;
17
+ export declare enum JobEventType {
18
+ Completed = "completed",
19
+ Failed = "failed",
20
+ Progress = "progress"
21
+ }
22
+ /**
23
+ * How long a caller waits for a reply when neither the route nor the request says. Long enough
24
+ * for work that talks to a model, short enough that a lost job surfaces as an error rather than a
25
+ * hung request.
26
+ */
27
+ export declare const DEFAULT_JOB_TIMEOUT = 60000;
28
+ /**
29
+ * Retries default to one attempt: the jobs here are mostly LLM work, and a blind retry re-spends
30
+ * the tokens that just failed. A queue whose jobs are cheap and idempotent raises it per queue.
31
+ */
32
+ export declare const DEFAULT_ATTEMPTS = 1;
33
+ //# sourceMappingURL=consts.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"consts.d.ts","sourceRoot":"","sources":["../src/consts.ts"],"names":[],"mappings":"AACA,eAAO,MAAM,aAAa,UAAU,CAAA;AAEpC;;;;GAIG;AACH,oBAAY,QAAQ;IAClB,OAAO,YAAY;IACnB,OAAO,YAAY;IACnB,MAAM,WAAW;IACjB,SAAS,cAAc;IACvB,MAAM,WAAW;IACjB,OAAO,YAAY;CACpB;AAED,8DAA8D;AAC9D,eAAO,MAAM,SAAS,WAAY,QAAQ,KAAG,OACc,CAAA;AAE3D,oBAAY,YAAY;IACtB,SAAS,cAAc;IACvB,MAAM,WAAW;IACjB,QAAQ,aAAa;CACtB;AAED;;;;GAIG;AACH,eAAO,MAAM,mBAAmB,QAAS,CAAA;AAEzC;;;GAGG;AACH,eAAO,MAAM,gBAAgB,IAAI,CAAA"}
@@ -0,0 +1,35 @@
1
+ export const DEFAULT_ALIAS = 'queue';
2
+ /**
3
+ * The state a job is in, as the broker reports it. `Waiting` covers both a job queued normally
4
+ * and one held by an unfinished parent — the difference matters to the broker, never to a caller
5
+ * asking whether an answer has arrived.
6
+ */
7
+ export var JobState;
8
+ (function (JobState) {
9
+ JobState["Waiting"] = "waiting";
10
+ JobState["Delayed"] = "delayed";
11
+ JobState["Active"] = "active";
12
+ JobState["Completed"] = "completed";
13
+ JobState["Failed"] = "failed";
14
+ JobState["Unknown"] = "unknown";
15
+ })(JobState || (JobState = {}));
16
+ /** A job has reached a state it will not leave on its own. */
17
+ export const isSettled = (state) => state === JobState.Completed || state === JobState.Failed;
18
+ export var JobEventType;
19
+ (function (JobEventType) {
20
+ JobEventType["Completed"] = "completed";
21
+ JobEventType["Failed"] = "failed";
22
+ JobEventType["Progress"] = "progress";
23
+ })(JobEventType || (JobEventType = {}));
24
+ /**
25
+ * How long a caller waits for a reply when neither the route nor the request says. Long enough
26
+ * for work that talks to a model, short enough that a lost job surfaces as an error rather than a
27
+ * hung request.
28
+ */
29
+ export const DEFAULT_JOB_TIMEOUT = 60_000;
30
+ /**
31
+ * Retries default to one attempt: the jobs here are mostly LLM work, and a blind retry re-spends
32
+ * the tokens that just failed. A queue whose jobs are cheap and idempotent raises it per queue.
33
+ */
34
+ export const DEFAULT_ATTEMPTS = 1;
35
+ //# sourceMappingURL=consts.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"consts.js","sourceRoot":"","sources":["../src/consts.ts"],"names":[],"mappings":"AACA,MAAM,CAAC,MAAM,aAAa,GAAG,OAAO,CAAA;AAEpC;;;;GAIG;AACH,MAAM,CAAN,IAAY,QAOX;AAPD,WAAY,QAAQ;IAClB,+BAAmB,CAAA;IACnB,+BAAmB,CAAA;IACnB,6BAAiB,CAAA;IACjB,mCAAuB,CAAA;IACvB,6BAAiB,CAAA;IACjB,+BAAmB,CAAA;AACrB,CAAC,EAPW,QAAQ,KAAR,QAAQ,QAOnB;AAED,8DAA8D;AAC9D,MAAM,CAAC,MAAM,SAAS,GAAG,CAAC,KAAgB,EAAW,EAAE,CACrD,KAAK,KAAK,QAAQ,CAAC,SAAS,IAAI,KAAK,KAAK,QAAQ,CAAC,MAAM,CAAA;AAE3D,MAAM,CAAN,IAAY,YAIX;AAJD,WAAY,YAAY;IACtB,uCAAuB,CAAA;IACvB,iCAAiB,CAAA;IACjB,qCAAqB,CAAA;AACvB,CAAC,EAJW,YAAY,KAAZ,YAAY,QAIvB;AAED;;;;GAIG;AACH,MAAM,CAAC,MAAM,mBAAmB,GAAG,MAAM,CAAA;AAEzC;;;GAGG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAAC,CAAA"}
@@ -0,0 +1,59 @@
1
+ import { ResilientError } from '@owlmeans/error';
2
+ export declare class QueueError extends ResilientError {
3
+ static typeName: string;
4
+ constructor(message?: string);
5
+ }
6
+ /**
7
+ * The caller stopped waiting. The job is untouched — it may still be queued, running, or already
8
+ * finished; only the wait ended. Read the job back to learn which.
9
+ */
10
+ export declare class QueueTimeout extends QueueError {
11
+ static typeName: string;
12
+ constructor(msg: string);
13
+ }
14
+ /** No job with that id in this queue — it never existed, or it was removed after completing. */
15
+ export declare class UnknownJob extends QueueError {
16
+ static typeName: string;
17
+ constructor(msg: string);
18
+ }
19
+ /**
20
+ * A job name the queue does not declare. Declaring every job a queue accepts is what keeps an
21
+ * enqueue from succeeding into a queue where nothing can ever process it.
22
+ */
23
+ export declare class UnknownJobName extends QueueError {
24
+ static typeName: string;
25
+ constructor(msg: string);
26
+ }
27
+ /** A queue asked for that no declaration names. */
28
+ export declare class UnknownQueue extends QueueError {
29
+ static typeName: string;
30
+ constructor(msg: string);
31
+ }
32
+ /**
33
+ * This process was asked to consume a queue it does not listen to. Which queues a process
34
+ * consumes is configuration (`cfg.queue.listen`), so this is a deployment question, not a code
35
+ * one — the same binary is a producer or a worker depending on it.
36
+ */
37
+ export declare class QueueNotListening extends QueueError {
38
+ static typeName: string;
39
+ constructor(msg: string);
40
+ }
41
+ /**
42
+ * The job named an entrypoint this process does not serve. Unlike a missing queue this is not a
43
+ * declaration problem: the alias exists, but nothing here bound it, so the job was taken by a
44
+ * worker that cannot run it.
45
+ */
46
+ export declare class JobNotServed extends QueueError {
47
+ static typeName: string;
48
+ constructor(msg: string);
49
+ }
50
+ /**
51
+ * The signed envelope is older than the configured lifetime. Freshness is judged from when the
52
+ * producer enqueued the job, not from when a worker picked it up, so a long backlog does not
53
+ * invalidate work that was legitimate when it was submitted.
54
+ */
55
+ export declare class EnvelopeExpired extends QueueError {
56
+ static typeName: string;
57
+ constructor(msg: string);
58
+ }
59
+ //# sourceMappingURL=errors.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAA;AAEhD,qBAAa,UAAW,SAAQ,cAAc;IAC5C,OAAuB,QAAQ,SAAe;IAE9C,YAAY,OAAO,GAAE,MAAgB,EAEpC;CACF;AAED;;;GAGG;AACH,qBAAa,YAAa,SAAQ,UAAU;IAC1C,OAAuB,QAAQ,SAAkC;IAEjE,YAAY,GAAG,EAAE,MAAM,EAGtB;CACF;AAED,gGAAgG;AAChG,qBAAa,UAAW,SAAQ,UAAU;IACxC,OAAuB,QAAQ,SAAqC;IAEpE,YAAY,GAAG,EAAE,MAAM,EAGtB;CACF;AAED;;;GAGG;AACH,qBAAa,cAAe,SAAQ,UAAU;IAC5C,OAAuB,QAAQ,SAAyC;IAExE,YAAY,GAAG,EAAE,MAAM,EAGtB;CACF;AAED,mDAAmD;AACnD,qBAAa,YAAa,SAAQ,UAAU;IAC1C,OAAuB,QAAQ,SAAuC;IAEtE,YAAY,GAAG,EAAE,MAAM,EAGtB;CACF;AAED;;;;GAIG;AACH,qBAAa,iBAAkB,SAAQ,UAAU;IAC/C,OAAuB,QAAQ,SAAuC;IAEtE,YAAY,GAAG,EAAE,MAAM,EAGtB;CACF;AAED;;;;GAIG;AACH,qBAAa,YAAa,SAAQ,UAAU;IAC1C,OAAuB,QAAQ,SAAuC;IAEtE,YAAY,GAAG,EAAE,MAAM,EAGtB;CACF;AAED;;;;GAIG;AACH,qBAAa,eAAgB,SAAQ,UAAU;IAC7C,OAAuB,QAAQ,SAA0C;IAEzE,YAAY,GAAG,EAAE,MAAM,EAGtB;CACF"}
@@ -0,0 +1,90 @@
1
+ import { ResilientError } from '@owlmeans/error';
2
+ export class QueueError extends ResilientError {
3
+ static typeName = 'QueueError';
4
+ constructor(message = 'error') {
5
+ super(QueueError.typeName, `queue:${message}`);
6
+ }
7
+ }
8
+ /**
9
+ * The caller stopped waiting. The job is untouched — it may still be queued, running, or already
10
+ * finished; only the wait ended. Read the job back to learn which.
11
+ */
12
+ export class QueueTimeout extends QueueError {
13
+ static typeName = `${QueueError.typeName}Timeout`;
14
+ constructor(msg) {
15
+ super(`timeout:${msg}`);
16
+ this.type = QueueTimeout.typeName;
17
+ }
18
+ }
19
+ /** No job with that id in this queue — it never existed, or it was removed after completing. */
20
+ export class UnknownJob extends QueueError {
21
+ static typeName = `${QueueError.typeName}UnknownJob`;
22
+ constructor(msg) {
23
+ super(`unknown-job:${msg}`);
24
+ this.type = UnknownJob.typeName;
25
+ }
26
+ }
27
+ /**
28
+ * A job name the queue does not declare. Declaring every job a queue accepts is what keeps an
29
+ * enqueue from succeeding into a queue where nothing can ever process it.
30
+ */
31
+ export class UnknownJobName extends QueueError {
32
+ static typeName = `${QueueError.typeName}UnknownJobName`;
33
+ constructor(msg) {
34
+ super(`unknown-job-name:${msg}`);
35
+ this.type = UnknownJobName.typeName;
36
+ }
37
+ }
38
+ /** A queue asked for that no declaration names. */
39
+ export class UnknownQueue extends QueueError {
40
+ static typeName = `${QueueError.typeName}UnknownQueue`;
41
+ constructor(msg) {
42
+ super(`unknown-queue:${msg}`);
43
+ this.type = UnknownQueue.typeName;
44
+ }
45
+ }
46
+ /**
47
+ * This process was asked to consume a queue it does not listen to. Which queues a process
48
+ * consumes is configuration (`cfg.queue.listen`), so this is a deployment question, not a code
49
+ * one — the same binary is a producer or a worker depending on it.
50
+ */
51
+ export class QueueNotListening extends QueueError {
52
+ static typeName = `${QueueError.typeName}NotListening`;
53
+ constructor(msg) {
54
+ super(`not-listening:${msg}`);
55
+ this.type = QueueNotListening.typeName;
56
+ }
57
+ }
58
+ /**
59
+ * The job named an entrypoint this process does not serve. Unlike a missing queue this is not a
60
+ * declaration problem: the alias exists, but nothing here bound it, so the job was taken by a
61
+ * worker that cannot run it.
62
+ */
63
+ export class JobNotServed extends QueueError {
64
+ static typeName = `${QueueError.typeName}JobNotServed`;
65
+ constructor(msg) {
66
+ super(`job-not-served:${msg}`);
67
+ this.type = JobNotServed.typeName;
68
+ }
69
+ }
70
+ /**
71
+ * The signed envelope is older than the configured lifetime. Freshness is judged from when the
72
+ * producer enqueued the job, not from when a worker picked it up, so a long backlog does not
73
+ * invalidate work that was legitimate when it was submitted.
74
+ */
75
+ export class EnvelopeExpired extends QueueError {
76
+ static typeName = `${QueueError.typeName}EnvelopeExpired`;
77
+ constructor(msg) {
78
+ super(`envelope-expired:${msg}`);
79
+ this.type = EnvelopeExpired.typeName;
80
+ }
81
+ }
82
+ ResilientError.registerErrorClass(QueueError);
83
+ ResilientError.registerErrorClass(QueueTimeout);
84
+ ResilientError.registerErrorClass(UnknownJob);
85
+ ResilientError.registerErrorClass(UnknownJobName);
86
+ ResilientError.registerErrorClass(UnknownQueue);
87
+ ResilientError.registerErrorClass(QueueNotListening);
88
+ ResilientError.registerErrorClass(JobNotServed);
89
+ ResilientError.registerErrorClass(EnvelopeExpired);
90
+ //# sourceMappingURL=errors.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.js","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAA;AAEhD,MAAM,OAAO,UAAW,SAAQ,cAAc;IACrC,MAAM,CAAU,QAAQ,GAAG,YAAY,CAAA;IAE9C,YAAY,OAAO,GAAW,OAAO;QACnC,KAAK,CAAC,UAAU,CAAC,QAAQ,EAAE,SAAS,OAAO,EAAE,CAAC,CAAA;IAChD,CAAC;CACF;AAED;;;GAGG;AACH,MAAM,OAAO,YAAa,SAAQ,UAAU;IACnC,MAAM,CAAU,QAAQ,GAAG,GAAG,UAAU,CAAC,QAAQ,SAAS,CAAA;IAEjE,YAAY,GAAW;QACrB,KAAK,CAAC,WAAW,GA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UAAU,CAAC,QAAQ,cAAc,CAAA;IAEtE,YAAY,GAAW;QACrB,KAAK,CAAC,kBAAkB,GAAG,EAAE,CAAC,CAAA;QAC9B,IAAI,CAAC,IAAI,GAAG,YAAY,CAAC,QAAQ,CAAA;IACnC,CAAC;CACF;AAED;;;;GAIG;AACH,MAAM,OAAO,eAAgB,SAAQ,UAAU;IACtC,MAAM,CAAU,QAAQ,GAAG,GAAG,UAAU,CAAC,QAAQ,iBAAiB,CAAA;IAEzE,YAAY,GAAW;QACrB,KAAK,CAAC,oBAAoB,GAAG,EAAE,CAAC,CAAA;QAChC,IAAI,CAAC,IAAI,GAAG,eAAe,CAAC,QAAQ,CAAA;IACtC,CAAC;CACF;AAED,cAAc,CAAC,kBAAkB,CAAC,UAAU,CAAC,CAAA;AAC7C,cAAc,CAAC,kBAAkB,CAAC,YAAY,CAAC,CAAA;AAC/C,cAAc,CAAC,kBAAkB,CAAC,UAAU,CAAC,CAAA;AAC7C,cAAc,CAAC,kBAAkB,CAAC,cAAc,CAAC,CAAA;AACjD,cAAc,CAAC,kBAAkB,CAAC,YAAY,CAAC,CAAA;AAC/C,cAAc,CAAC,kBAAkB,CAAC,iBAAiB,CAAC,CAAA;AACpD,cAAc,CAAC,kBAAkB,CAAC,YAAY,CAAC,CAAA;AAC/C,cAAc,CAAC,kBAAkB,CAAC,eAAe,CAAC,CAAA"}
package/build/index.d.ts CHANGED
@@ -1 +1,9 @@
1
+ export * from './types.js';
2
+ export * from './consts.js';
3
+ export * from './errors.js';
4
+ export * from './config.js';
5
+ export * from './transport.js';
6
+ export * from './bridge.js';
7
+ export * from './worker.js';
8
+ export * from './protocol.js';
1
9
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":""}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAA;AAC1B,cAAc,aAAa,CAAA;AAC3B,cAAc,aAAa,CAAA;AAC3B,cAAc,aAAa,CAAA;AAC3B,cAAc,gBAAgB,CAAA;AAC9B,cAAc,aAAa,CAAA;AAC3B,cAAc,aAAa,CAAA;AAC3B,cAAc,eAAe,CAAA"}
package/build/index.js CHANGED
@@ -1,2 +1,9 @@
1
- "use strict";
1
+ export * from './types.js';
2
+ export * from './consts.js';
3
+ export * from './errors.js';
4
+ export * from './config.js';
5
+ export * from './transport.js';
6
+ export * from './bridge.js';
7
+ export * from './worker.js';
8
+ export * from './protocol.js';
2
9
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":""}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAA;AAC1B,cAAc,aAAa,CAAA;AAC3B,cAAc,aAAa,CAAA;AAC3B,cAAc,aAAa,CAAA;AAC3B,cAAc,gBAAgB,CAAA;AAC9B,cAAc,aAAa,CAAA;AAC3B,cAAc,aAAa,CAAA;AAC3B,cAAc,eAAe,CAAA"}
@@ -0,0 +1,11 @@
1
+ import type { EntrypointProtocolDeclaration, RequestOf, ResponseOf } from '@owlmeans/entrypoint';
2
+ import type { Config, Context, JobEnvelope, JobOptions, JobRecord, JobReply, QueueAppend } from './types.js';
3
+ type QueueContext = Context<Config> & QueueAppend;
4
+ /** Enqueue an immutable QUEUE protocol while preserving its exact request and response types. */
5
+ export declare const enqueueProtocol: <Protocol extends EntrypointProtocolDeclaration>(context: QueueContext, declaration: Protocol, request: RequestOf<Protocol>, options?: JobOptions) => Promise<JobRecord<JobEnvelope, JobReply<ResponseOf<Protocol>>>>;
6
+ /** Wait for a protocol job and unwrap the typed entrypoint reply. */
7
+ export declare const waitForProtocol: <Protocol extends EntrypointProtocolDeclaration>(context: QueueContext, declaration: Protocol, job: string | JobRecord<JobEnvelope, JobReply<ResponseOf<Protocol>>>, options?: {
8
+ timeout?: number;
9
+ }) => Promise<ResponseOf<Protocol>>;
10
+ export {};
11
+ //# sourceMappingURL=protocol.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"protocol.d.ts","sourceRoot":"","sources":["../src/protocol.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,6BAA6B,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAA;AAMhG,OAAO,KAAK,EACV,MAAM,EAAE,OAAO,EAAE,WAAW,EAAE,UAAU,EAAE,SAAS,EAAE,QAAQ,EAAE,WAAW,EAC3E,MAAM,YAAY,CAAA;AAEnB,KAAK,YAAY,GAAG,OAAO,CAAC,MAAM,CAAC,GAAG,WAAW,CAAA;AAuBjD,iGAAiG;AACjG,eAAO,MAAM,eAAe,GAAU,QAAQ,SAAS,6BAA6B,WACzE,YAAY,eACR,QAAQ,WACZ,SAAS,CAAC,QAAQ,CAAC,YAClB,UAAU,KACnB,OAAO,CAAC,SAAS,CAAC,WAAW,EAAE,QAAQ,CAAC,UAAU,CAAC,QAAQ,CAAC,CAAC,CAAC,CAkBhE,CAAA;AAED,qEAAqE;AACrE,eAAO,MAAM,eAAe,GAAU,QAAQ,SAAS,6BAA6B,WACzE,YAAY,eACR,QAAQ,OAChB,MAAM,GAAG,SAAS,CAAC,WAAW,EAAE,QAAQ,CAAC,UAAU,CAAC,QAAQ,CAAC,CAAC,CAAC,YAC1D;IAAE,OAAO,CAAC,EAAE,MAAM,CAAA;CAAE,KAC7B,OAAO,CAAC,UAAU,CAAC,QAAQ,CAAC,CAe9B,CAAA"}
@@ -0,0 +1,59 @@
1
+ import { isEntrypointProtocol } from '@owlmeans/entrypoint';
2
+ import { ResilientError } from '@owlmeans/error';
3
+ import { RouteProtocols } from '@owlmeans/route';
4
+ import { queueOf } from './config.js';
5
+ import { UnknownQueue } from './errors.js';
6
+ const queueFor = (context, declaration) => {
7
+ if (declaration == null || typeof declaration !== 'object' || !isEntrypointProtocol(declaration)) {
8
+ throw new UnknownQueue('protocol declaration required');
9
+ }
10
+ if (declaration.route.route.protocol !== RouteProtocols.QUEUE) {
11
+ throw new UnknownQueue(`${declaration.alias}: not a QUEUE protocol`);
12
+ }
13
+ const queue = declaration.route.route.queue;
14
+ if (queue == null) {
15
+ throw new UnknownQueue(`${declaration.alias}: route declares no queue`);
16
+ }
17
+ const configured = queueOf(context.cfg, queue);
18
+ if (!configured.jobs.includes(declaration.alias)) {
19
+ throw new UnknownQueue(`${queue}:${declaration.alias}`);
20
+ }
21
+ return { protocol: declaration, queue };
22
+ };
23
+ /** Enqueue an immutable QUEUE protocol while preserving its exact request and response types. */
24
+ export const enqueueProtocol = async (context, declaration, request, options) => {
25
+ const { protocol, queue } = queueFor(context, declaration);
26
+ const shaped = (request ?? {});
27
+ const envelope = {
28
+ alias: protocol.alias,
29
+ params: shaped.params,
30
+ body: shaped.body,
31
+ query: shaped.query,
32
+ headers: shaped.headers,
33
+ enqueuedAt: new Date().toISOString(),
34
+ };
35
+ return await context.jobs(queue).create({
36
+ queue,
37
+ name: protocol.alias,
38
+ data: envelope,
39
+ opts: options,
40
+ });
41
+ };
42
+ /** Wait for a protocol job and unwrap the typed entrypoint reply. */
43
+ export const waitForProtocol = async (context, declaration, job, options) => {
44
+ const { protocol, queue } = queueFor(context, declaration);
45
+ if (typeof job !== 'string' && (job.queue !== queue || job.name !== protocol.alias)) {
46
+ throw new UnknownQueue(`${job.queue}:${job.name}`);
47
+ }
48
+ const id = typeof job === 'string' ? job : job.id;
49
+ if (id == null) {
50
+ throw new UnknownQueue(`${queue}:${protocol.alias}: missing job id`);
51
+ }
52
+ const reply = await context.jobs(queue)
53
+ .wait(id, options);
54
+ if (reply.error != null) {
55
+ throw ResilientError.ensure(reply.error);
56
+ }
57
+ return reply.value;
58
+ };
59
+ //# sourceMappingURL=protocol.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"protocol.js","sourceRoot":"","sources":["../src/protocol.ts"],"names":[],"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E,GAAG,OAAO,GAAG,KAAK,QAAQ,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC,EAAE,CAAA;IACjD,IAAI,EAAE,IAAI,IAAI,EAAE,CAAC;QACf,MAAM,IAAI,YAAY,CAAC,GAAG,KAAK,IAAI,QAAQ,CAAC,KAAK,kBAAkB,CAAC,CAAA;IACtE,CAAC;IACD,MAAM,KAAK,GAAG,MAAM,OAAO,CAAC,IAAI,CAA8C,KAAK,CAAC;SACjF,IAAI,CAAC,EAAE,EAAE,OAAO,CAAC,CAAA;IACpB,IAAI,KAAK,CAAC,KAAK,IAAI,IAAI,EAAE,CAAC;QACxB,MAAM,cAAc,CAAC,MAAM,CAAC,KAAK,CAAC,KAAuB,CAAC,CAAA;IAC5D,CAAC;IACD,OAAO,KAAK,CAAC,KAA6B,CAAA;AAC5C,CAAC,CAAA"}
@@ -0,0 +1,15 @@
1
+ import type { EntrypointTransport } from '@owlmeans/entrypoint';
2
+ import type { Config, Context } from './types.js';
3
+ /**
4
+ * The producing half of the bridge: it turns a call on a QUEUE entrypoint into a job, and the
5
+ * job's outcome back into a reply.
6
+ *
7
+ * Registering it is the whole opt-in. `apiHandler` looks up a transport by the route's protocol,
8
+ * so a consumer writes `ep.call(...)` against a declaration it shares with every other kind of
9
+ * entrypoint and never learns which one carried it. That is also why the envelope is built from
10
+ * the request rather than from the entrypoint: the far side rebuilds a request, and anything only
11
+ * HTTP understands would not survive the trip anyway.
12
+ */
13
+ export declare const makeQueueTransport: (alias?: string) => EntrypointTransport;
14
+ export declare const appendQueueTransport: <C extends Config, T extends Context<C> = Context<C>>(context: T, alias?: string) => T;
15
+ //# sourceMappingURL=transport.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"transport.d.ts","sourceRoot":"","sources":["../src/transport.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAqC,mBAAmB,EAAE,MAAM,sBAAsB,CAAA;AAKlG,OAAO,KAAK,EAAE,MAAM,EAAE,OAAO,EAAsC,MAAM,YAAY,CAAA;AAIrF;;;;;;;;;GASG;AACH,eAAO,MAAM,kBAAkB,WAAW,MAAM,wBAmD/C,CAAA;AAED,eAAO,MAAM,oBAAoB,GAAI,CAAC,SAAS,MAAM,EAAE,CAAC,SAAS,OAAO,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,WAC7E,CAAC,UAAU,MAAM,KACzB,CAMF,CAAA"}
@@ -0,0 +1,62 @@
1
+ import { assertContext, createService } from '@owlmeans/context';
2
+ import { EntrypointOutcome, transportAlias } from '@owlmeans/entrypoint';
3
+ import { RouteProtocols } from '@owlmeans/route';
4
+ import { ResilientError } from '@owlmeans/error';
5
+ import { DEFAULT_JOB_TIMEOUT } from './consts.js';
6
+ import { UnknownQueue } from './errors.js';
7
+ /**
8
+ * The producing half of the bridge: it turns a call on a QUEUE entrypoint into a job, and the
9
+ * job's outcome back into a reply.
10
+ *
11
+ * Registering it is the whole opt-in. `apiHandler` looks up a transport by the route's protocol,
12
+ * so a consumer writes `ep.call(...)` against a declaration it shares with every other kind of
13
+ * entrypoint and never learns which one carried it. That is also why the envelope is built from
14
+ * the request rather than from the entrypoint: the far side rebuilds a request, and anything only
15
+ * HTTP understands would not survive the trip anyway.
16
+ */
17
+ export const makeQueueTransport = (alias = transportAlias(RouteProtocols.QUEUE)) => {
18
+ const location = `queue-transport:${alias}`;
19
+ const service = createService(alias, {
20
+ protocol: RouteProtocols.QUEUE,
21
+ handle: (async (req, res) => {
22
+ const context = assertContext(service.ctx, location);
23
+ const entrypoint = context.entrypoint(req.alias);
24
+ const route = entrypoint.route.route;
25
+ if (route.queue == null) {
26
+ throw new UnknownQueue(`${req.alias}: route declares no queue`);
27
+ }
28
+ const jobs = context.jobs(route.queue);
29
+ const envelope = {
30
+ alias: req.alias,
31
+ params: req.params,
32
+ body: req.body,
33
+ query: req.query,
34
+ headers: req.headers,
35
+ enqueuedAt: new Date().toISOString(),
36
+ };
37
+ const job = await jobs.create({ queue: route.queue, name: req.alias, data: envelope });
38
+ // `reply: false` says the caller is not waiting for the work, only for the promise that it
39
+ // was taken. `Accepted` plus the job's identity is the whole answer — enough to watch it.
40
+ if (route.reply === false) {
41
+ res.resolve({ id: job.id, queue: route.queue }, EntrypointOutcome.Accepted);
42
+ return;
43
+ }
44
+ const reply = await jobs.wait(job.id, {
45
+ timeout: req.timeout ?? route.timeout ?? DEFAULT_JOB_TIMEOUT
46
+ });
47
+ // A processor reports a domain failure by returning it, so it crosses the hop as the class
48
+ // it was thrown as rather than as a string a caller would have to parse.
49
+ if (reply?.error != null) {
50
+ throw ResilientError.ensure(reply.error);
51
+ }
52
+ res.resolve(reply?.value, reply?.outcome ?? EntrypointOutcome.Ok);
53
+ })
54
+ });
55
+ return service;
56
+ };
57
+ export const appendQueueTransport = (context, alias) => {
58
+ const service = makeQueueTransport(alias);
59
+ context.registerService(service);
60
+ return context;
61
+ };
62
+ //# sourceMappingURL=transport.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"transport.js","sourceRoot":"","sources":["../src/transport.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAA;AAEhE,OAAO,EAAE,iBAAiB,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAA;AACxE,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAA;AAChD,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAA;AAGhD,OAAO,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAA;AACjD,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAA;AAE1C;;;;;;;;;GASG;AACH,MAAM,CAAC,MAAM,kBAAkB,GAAG,CAAC,KAAK,GAAW,cAAc,CAAC,cAAc,CAAC,KAAK,CAAC,EAAE,EAAE;IACzF,MAAM,QAAQ,GAAG,mBAAmB,KAAK,EAAE,CAAA;IAE3C,MAAM,OAAO,GAAG,aAAa,CAAsB,KAAK,EA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