@anatta.io/tva 0.0.0-stage → 0.1.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 +50 -2
- package/dist/actions/action-consumer.d.ts +45 -0
- package/dist/actions/action-consumer.js +90 -0
- package/dist/actions/action.d.ts +67 -0
- package/dist/actions/action.js +12 -0
- package/dist/actions/index.d.ts +3 -0
- package/dist/actions/index.js +4 -0
- package/dist/actions/run-action.d.ts +31 -0
- package/dist/actions/run-action.js +113 -0
- package/dist/adapters/cloudflare/bindings.d.ts +10 -0
- package/dist/adapters/cloudflare/bindings.js +1 -0
- package/dist/adapters/cloudflare/blob-store.d.ts +39 -0
- package/dist/adapters/cloudflare/blob-store.js +95 -0
- package/dist/adapters/cloudflare/cache.d.ts +14 -0
- package/dist/adapters/cloudflare/cache.js +48 -0
- package/dist/adapters/cloudflare/faults.d.ts +7 -0
- package/dist/adapters/cloudflare/faults.js +39 -0
- package/dist/adapters/cloudflare/index.d.ts +15 -0
- package/dist/adapters/cloudflare/index.js +16 -0
- package/dist/adapters/cloudflare/jobs.d.ts +97 -0
- package/dist/adapters/cloudflare/jobs.js +218 -0
- package/dist/adapters/cloudflare/journal.d.ts +107 -0
- package/dist/adapters/cloudflare/journal.js +305 -0
- package/dist/adapters/cloudflare/ledger.d.ts +14 -0
- package/dist/adapters/cloudflare/ledger.js +108 -0
- package/dist/adapters/cloudflare/logger.d.ts +22 -0
- package/dist/adapters/cloudflare/logger.js +49 -0
- package/dist/adapters/cloudflare/manifest.d.ts +81 -0
- package/dist/adapters/cloudflare/manifest.js +81 -0
- package/dist/adapters/cloudflare/queue.d.ts +80 -0
- package/dist/adapters/cloudflare/queue.js +177 -0
- package/dist/adapters/cloudflare/retention.d.ts +24 -0
- package/dist/adapters/cloudflare/retention.js +103 -0
- package/dist/adapters/cloudflare/session-storage.d.ts +27 -0
- package/dist/adapters/cloudflare/session-storage.js +78 -0
- package/dist/adapters/cloudflare/toolkit.d.ts +16 -0
- package/dist/adapters/cloudflare/toolkit.js +57 -0
- package/dist/adapters/cloudflare/workflow-jobs.d.ts +57 -0
- package/dist/adapters/cloudflare/workflow-jobs.js +319 -0
- package/dist/adapters/journal-records.d.ts +79 -0
- package/dist/adapters/journal-records.js +74 -0
- package/dist/adapters/memory/blob-store.d.ts +9 -0
- package/dist/adapters/memory/blob-store.js +19 -0
- package/dist/adapters/memory/cache.d.ts +13 -0
- package/dist/adapters/memory/cache.js +36 -0
- package/dist/adapters/memory/clock.d.ts +1 -0
- package/dist/adapters/memory/clock.js +4 -0
- package/dist/adapters/memory/index.d.ts +11 -0
- package/dist/adapters/memory/index.js +11 -0
- package/dist/adapters/memory/jobs.d.ts +62 -0
- package/dist/adapters/memory/jobs.js +219 -0
- package/dist/adapters/memory/journal.d.ts +34 -0
- package/dist/adapters/memory/journal.js +135 -0
- package/dist/adapters/memory/ledger.d.ts +9 -0
- package/dist/adapters/memory/ledger.js +33 -0
- package/dist/adapters/memory/logger.d.ts +16 -0
- package/dist/adapters/memory/logger.js +21 -0
- package/dist/adapters/memory/manifest.d.ts +59 -0
- package/dist/adapters/memory/manifest.js +59 -0
- package/dist/adapters/memory/queue.d.ts +20 -0
- package/dist/adapters/memory/queue.js +102 -0
- package/dist/adapters/memory/session-storage.d.ts +20 -0
- package/dist/adapters/memory/session-storage.js +33 -0
- package/dist/adapters/memory/toolkit.d.ts +8 -0
- package/dist/adapters/memory/toolkit.js +31 -0
- package/dist/adapters/postgres/cache.d.ts +17 -0
- package/dist/adapters/postgres/cache.js +69 -0
- package/dist/adapters/postgres/config.d.ts +27 -0
- package/dist/adapters/postgres/config.js +45 -0
- package/dist/adapters/postgres/faults.d.ts +14 -0
- package/dist/adapters/postgres/faults.js +47 -0
- package/dist/adapters/postgres/index.d.ts +12 -0
- package/dist/adapters/postgres/index.js +12 -0
- package/dist/adapters/postgres/journal.d.ts +83 -0
- package/dist/adapters/postgres/journal.js +314 -0
- package/dist/adapters/postgres/ledger.d.ts +16 -0
- package/dist/adapters/postgres/ledger.js +97 -0
- package/dist/adapters/postgres/logger.d.ts +19 -0
- package/dist/adapters/postgres/logger.js +37 -0
- package/dist/adapters/postgres/manifest.d.ts +52 -0
- package/dist/adapters/postgres/manifest.js +53 -0
- package/dist/adapters/postgres/migrate.d.ts +20 -0
- package/dist/adapters/postgres/migrate.js +96 -0
- package/dist/adapters/postgres/queue.d.ts +64 -0
- package/dist/adapters/postgres/queue.js +333 -0
- package/dist/adapters/postgres/retention.d.ts +18 -0
- package/dist/adapters/postgres/retention.js +104 -0
- package/dist/adapters/postgres/session-storage.d.ts +20 -0
- package/dist/adapters/postgres/session-storage.js +71 -0
- package/dist/adapters/postgres/toolkit.d.ts +25 -0
- package/dist/adapters/postgres/toolkit.js +58 -0
- package/dist/adapters/postgres/with-client.d.ts +11 -0
- package/dist/adapters/postgres/with-client.js +29 -0
- package/dist/adapters/reference-executor.d.ts +171 -0
- package/dist/adapters/reference-executor.js +564 -0
- package/dist/adapters/retention.d.ts +18 -0
- package/dist/adapters/retention.js +13 -0
- package/dist/adapters/s3/blob-store.d.ts +35 -0
- package/dist/adapters/s3/blob-store.js +92 -0
- package/dist/adapters/s3/faults.d.ts +8 -0
- package/dist/adapters/s3/faults.js +34 -0
- package/dist/adapters/s3/index.d.ts +2 -0
- package/dist/adapters/s3/index.js +2 -0
- package/dist/adapters/session-envelope.d.ts +21 -0
- package/dist/adapters/session-envelope.js +122 -0
- package/dist/adapters/system-clock.d.ts +8 -0
- package/dist/adapters/system-clock.js +8 -0
- package/dist/contracts/blob-store.d.ts +11 -0
- package/dist/contracts/blob-store.js +1 -0
- package/dist/contracts/cache.d.ts +27 -0
- package/dist/contracts/cache.js +1 -0
- package/dist/contracts/duration.d.ts +23 -0
- package/dist/contracts/duration.js +27 -0
- package/dist/contracts/faults.d.ts +28 -0
- package/dist/contracts/faults.js +29 -0
- package/dist/contracts/identity.d.ts +12 -0
- package/dist/contracts/identity.js +1 -0
- package/dist/contracts/index.d.ts +14 -0
- package/dist/contracts/index.js +15 -0
- package/dist/contracts/instant.d.ts +17 -0
- package/dist/contracts/instant.js +12 -0
- package/dist/contracts/jobs.d.ts +335 -0
- package/dist/contracts/jobs.js +1 -0
- package/dist/contracts/journal.d.ts +186 -0
- package/dist/contracts/journal.js +10 -0
- package/dist/contracts/ledger.d.ts +34 -0
- package/dist/contracts/ledger.js +1 -0
- package/dist/contracts/logger.d.ts +11 -0
- package/dist/contracts/logger.js +1 -0
- package/dist/contracts/manifest.d.ts +37 -0
- package/dist/contracts/manifest.js +30 -0
- package/dist/contracts/queue.d.ts +55 -0
- package/dist/contracts/queue.js +1 -0
- package/dist/contracts/session-storage.d.ts +18 -0
- package/dist/contracts/session-storage.js +1 -0
- package/dist/contracts/toolkit.d.ts +21 -0
- package/dist/contracts/toolkit.js +1 -0
- package/dist/schedule/schedule.d.ts +40 -0
- package/dist/schedule/schedule.js +135 -0
- package/dist/webhooks/create-webhook-handler.d.ts +63 -0
- package/dist/webhooks/create-webhook-handler.js +246 -0
- package/dist/webhooks/dead-letter-consumer.d.ts +14 -0
- package/dist/webhooks/dead-letter-consumer.js +42 -0
- package/dist/webhooks/define-registry.d.ts +42 -0
- package/dist/webhooks/define-registry.js +56 -0
- package/dist/webhooks/once.d.ts +15 -0
- package/dist/webhooks/once.js +29 -0
- package/dist/webhooks/redact-customer-bodies.d.ts +29 -0
- package/dist/webhooks/redact-customer-bodies.js +45 -0
- package/dist/webhooks/replay-webhooks.d.ts +39 -0
- package/dist/webhooks/replay-webhooks.js +79 -0
- package/dist/webhooks/sign-shopify-webhook.d.ts +14 -0
- package/dist/webhooks/sign-shopify-webhook.js +31 -0
- package/dist/webhooks/webhook-consumer.d.ts +51 -0
- package/dist/webhooks/webhook-consumer.js +127 -0
- package/migrations/0001_create_ledger_claims.sql +23 -0
- package/migrations/0002_create_journal.sql +76 -0
- package/migrations/0003_create_shopify_sessions.sql +30 -0
- package/migrations/0004_create_journal_steps.sql +34 -0
- package/migrations/0007_create_job_tables.sql +71 -0
- package/migrations/0008_add_ledger_completed_at.sql +7 -0
- package/migrations/0009_create_webhook_receipts.sql +34 -0
- package/migrations/0010_index_webhook_deliveries_received_at.sql +2 -0
- package/migrations/0011_add_webhook_task_reason_code.sql +4 -0
- package/migrations/postgres/0001_create_ledger_claims.sql +13 -0
- package/migrations/postgres/0002_create_journal.sql +48 -0
- package/migrations/postgres/0003_create_shopify_sessions.sql +12 -0
- package/migrations/postgres/0004_create_journal_steps.sql +19 -0
- package/migrations/postgres/0005_create_cache_entries.sql +14 -0
- package/migrations/postgres/0006_create_queue.sql +42 -0
- package/migrations/postgres/0007_create_job_tables.sql +40 -0
- package/migrations/postgres/0008_add_ledger_completed_at.sql +3 -0
- package/migrations/postgres/0009_create_webhook_receipts.sql +23 -0
- package/migrations/postgres/0010_index_webhook_deliveries_received_at.sql +2 -0
- package/migrations/postgres/0011_add_webhook_task_reason_code.sql +3 -0
- package/package.json +137 -4
|
@@ -0,0 +1,319 @@
|
|
|
1
|
+
import { WorkflowEntrypoint } from 'cloudflare:workers';
|
|
2
|
+
import { NonRetryableError } from 'cloudflare:workflows';
|
|
3
|
+
import { LimitExceeded, Misconfigured, Unavailable, } from '../../contracts/index.js';
|
|
4
|
+
import { toFault } from './faults.js';
|
|
5
|
+
import { CLOUDFLARE_MANIFEST } from './manifest.js';
|
|
6
|
+
const TOOL = 'jobs';
|
|
7
|
+
const NAME = /^[A-Za-z0-9_]{1,64}$/;
|
|
8
|
+
const KEY = /^[A-Za-z0-9_-]+$/;
|
|
9
|
+
const ID = /^[A-Za-z0-9_]+-[A-Za-z0-9_-]+$/;
|
|
10
|
+
const ID_MAX = 100;
|
|
11
|
+
/**
|
|
12
|
+
* Workflows' documented maximum event payload, 1 MiB (docs/platform-facts.md,
|
|
13
|
+
* "Maximum event payload"). The params are the input and the run id, and
|
|
14
|
+
* they are checked here, before `create()` (rule 7).
|
|
15
|
+
*/
|
|
16
|
+
const PARAMS_MAX_BYTES = 1_048_576;
|
|
17
|
+
/**
|
|
18
|
+
* THE EXHAUSTION HANDLER'S STEP. The contract says a throw from the handler
|
|
19
|
+
* is a fault and the executor runs it again, and that `failed` means it has
|
|
20
|
+
* finished, so it gets as many retries as Workflows allows: 10,000
|
|
21
|
+
* (docs/platform-facts.md, "Maximum retries per step"). A fixed minute
|
|
22
|
+
* between them keeps a handler that always throws from spinning. The
|
|
23
|
+
* reference executor waits a minute too. The contract gives the handler no
|
|
24
|
+
* timeout, so this sets none, and Workflows' default applies.
|
|
25
|
+
*
|
|
26
|
+
* A handler that throws 10,001 times fails its step, and the instance ends
|
|
27
|
+
* `errored`, which `status` reports as `failed` although the handler never
|
|
28
|
+
* finished. That is the one way this executor breaks "failed means the
|
|
29
|
+
* handler has finished", and it takes about a week of throws.
|
|
30
|
+
*/
|
|
31
|
+
const HANDLER_STEP = {
|
|
32
|
+
retries: { limit: 10_000, delay: 60_000, backoff: 'constant' },
|
|
33
|
+
};
|
|
34
|
+
/**
|
|
35
|
+
* Workflows step names. A user step is `step:<name>`, so no step name a Job
|
|
36
|
+
* chooses can be the handler's: the handler's step has no `:`-prefix of that
|
|
37
|
+
* form, and Workflows caches a step's result by its name.
|
|
38
|
+
*/
|
|
39
|
+
const stepName = (name) => `step:${name}`;
|
|
40
|
+
const HANDLER_STEP_NAME = 'onExhausted';
|
|
41
|
+
/**
|
|
42
|
+
* HOW A STEP BODY TELLS `run()` WHY IT STOPPED. A terminal outcome and a
|
|
43
|
+
* result that is too large are thrown from inside `step.do` as a
|
|
44
|
+
* `NonRetryableError`, so Workflows does not retry them. Locally, `run()`
|
|
45
|
+
* catches a plain `Error` whose message is `NonRetryableError: <message>`
|
|
46
|
+
* (docs/platform-facts.md, "Under the test pool"), so the class is lost and
|
|
47
|
+
* the message is all that arrives. The marker is therefore searched for
|
|
48
|
+
* anywhere in the message, and the reason code is URI-encoded so that it
|
|
49
|
+
* holds no space.
|
|
50
|
+
*
|
|
51
|
+
* NOT MEASURED DEPLOYED: what message `run()` catches there, and what a
|
|
52
|
+
* replay of a failed `step.do` throws. If the marker does not survive, a
|
|
53
|
+
* terminal step is reported to the handler as `retries-exhausted`. It is
|
|
54
|
+
* still not retried.
|
|
55
|
+
*/
|
|
56
|
+
const MARKER = 'anatta-jobs:';
|
|
57
|
+
const MARKED = /anatta-jobs:(terminal|result-too-large):(\S*)/;
|
|
58
|
+
const mark = (cause, reasonCode = '') => `${MARKER}${cause}:${encodeURIComponent(reasonCode)}`;
|
|
59
|
+
function exhaustionOf(step, error) {
|
|
60
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
61
|
+
const m = MARKED.exec(message);
|
|
62
|
+
if (m?.[1] === 'terminal') {
|
|
63
|
+
return {
|
|
64
|
+
step,
|
|
65
|
+
cause: 'terminal',
|
|
66
|
+
reasonCode: decodeURIComponent(m[2] ?? ''),
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
if (m?.[1] === 'result-too-large') {
|
|
70
|
+
return { step, cause: 'result-too-large' };
|
|
71
|
+
}
|
|
72
|
+
return { step, cause: 'retries-exhausted' };
|
|
73
|
+
}
|
|
74
|
+
const bytes = (json) => new TextEncoder().encode(json).byteLength;
|
|
75
|
+
/**
|
|
76
|
+
* `create()` with an id that Workflows still retains. Deployed, the message
|
|
77
|
+
* is `(instance.already_exists) Instance already exists` (PR #89,
|
|
78
|
+
* docs/platform-facts.md "Deployed"). The test pool's miniflare does not
|
|
79
|
+
* throw at all, so only the unit test in workflow-jobs.spec.ts shows this mapping.
|
|
80
|
+
*/
|
|
81
|
+
const alreadyExists = (e) => e instanceof Error && e.message.includes('instance.already_exists');
|
|
82
|
+
/**
|
|
83
|
+
* `get()` for an id that Workflows has no instance for. Locally the message
|
|
84
|
+
* is `instance.not_found`; deployed it is `(instance.not_found) Instance not
|
|
85
|
+
* found` (PR #89).
|
|
86
|
+
*
|
|
87
|
+
* THE RISK, ACCEPTED ON #71: locally, `get()` turns every failure to read an
|
|
88
|
+
* instance's status into this same error, so a fault reading an instance
|
|
89
|
+
* that exists reads as `unknown`. Deployed, no fault could be induced, so
|
|
90
|
+
* whether a read fault can also arrive as `instance.not_found` is not
|
|
91
|
+
* measured. If it can, `status` reports `unknown` for an instance that
|
|
92
|
+
* exists. Any other error is a fault, and throws (rule 8).
|
|
93
|
+
*/
|
|
94
|
+
const notFound = (e) => e instanceof Error && e.message.includes('instance.not_found');
|
|
95
|
+
/**
|
|
96
|
+
* Unpacks one registration. The generic callback is the only place the
|
|
97
|
+
* definition's own types are known, so each run closes over them there and
|
|
98
|
+
* builds the deps itself, inside the `step.do` that runs the step.
|
|
99
|
+
*/
|
|
100
|
+
function unpack(registration) {
|
|
101
|
+
return registration((definition, deps) => {
|
|
102
|
+
const typed = (base) => ({
|
|
103
|
+
...base,
|
|
104
|
+
input: base.input,
|
|
105
|
+
results: base.results,
|
|
106
|
+
deps: deps(),
|
|
107
|
+
});
|
|
108
|
+
const handler = definition.onExhausted;
|
|
109
|
+
return {
|
|
110
|
+
name: definition.name,
|
|
111
|
+
key: (input) => definition.key(input),
|
|
112
|
+
steps: definition.steps.map((s) => ({
|
|
113
|
+
name: s.name,
|
|
114
|
+
retries: s.retries,
|
|
115
|
+
timeoutSeconds: s.timeoutSeconds,
|
|
116
|
+
run: async (base) => s.run(typed(base)),
|
|
117
|
+
})),
|
|
118
|
+
onExhausted: handler === undefined
|
|
119
|
+
? undefined
|
|
120
|
+
: async (base, exhaustion) => handler({ ...typed(base), exhaustion }),
|
|
121
|
+
};
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* Every registration, by name. Throws for a name that breaks the rule or is
|
|
126
|
+
* registered twice, and for a Job with two steps of the same name: each is a
|
|
127
|
+
* defect in the definition, found when the executor is built (rule 7,
|
|
128
|
+
* `Job.name`, `Step`). A repeated step name would also give two `step.do`
|
|
129
|
+
* calls one name, and Workflows caches a step's result by its name.
|
|
130
|
+
*/
|
|
131
|
+
function registry(registrations) {
|
|
132
|
+
const jobs = new Map();
|
|
133
|
+
for (const registration of registrations) {
|
|
134
|
+
const job = unpack(registration);
|
|
135
|
+
if (!NAME.test(job.name)) {
|
|
136
|
+
throw new LimitExceeded(TOOL, `Job name ${JSON.stringify(job.name)} must be 1 to 64 characters of [A-Za-z0-9_]`);
|
|
137
|
+
}
|
|
138
|
+
const stepNames = new Set();
|
|
139
|
+
for (const step of job.steps) {
|
|
140
|
+
if (stepNames.has(step.name)) {
|
|
141
|
+
throw new Misconfigured(TOOL, `Job ${job.name} has two steps named ${JSON.stringify(step.name)}`);
|
|
142
|
+
}
|
|
143
|
+
stepNames.add(step.name);
|
|
144
|
+
}
|
|
145
|
+
if (jobs.has(job.name)) {
|
|
146
|
+
throw new Misconfigured(TOOL, `Job name ${job.name} is registered twice`);
|
|
147
|
+
}
|
|
148
|
+
jobs.set(job.name, job);
|
|
149
|
+
}
|
|
150
|
+
return jobs;
|
|
151
|
+
}
|
|
152
|
+
/** The contract's retries, in Workflows' words. Both count retries. */
|
|
153
|
+
const stepConfig = (s) => ({
|
|
154
|
+
retries: {
|
|
155
|
+
limit: s.retries.limit,
|
|
156
|
+
delay: s.retries.delaySeconds * 1000,
|
|
157
|
+
backoff: s.retries.backoff,
|
|
158
|
+
},
|
|
159
|
+
timeout: s.timeoutSeconds * 1000,
|
|
160
|
+
});
|
|
161
|
+
/**
|
|
162
|
+
* One attempt of one step, inside its `step.do`. The step-result limit is
|
|
163
|
+
* checked here, before the result is returned to Workflows (rule 7): locally
|
|
164
|
+
* Workflows accepts a result above 1 MiB (docs/platform-facts.md), so the
|
|
165
|
+
* platform cannot be left to refuse it.
|
|
166
|
+
*/
|
|
167
|
+
async function attempt(s, base, maxBytes) {
|
|
168
|
+
const outcome = await s.run(base);
|
|
169
|
+
if (outcome.status === 'terminal') {
|
|
170
|
+
throw new NonRetryableError(mark('terminal', outcome.reasonCode));
|
|
171
|
+
}
|
|
172
|
+
if (bytes(JSON.stringify(outcome.result)) > maxBytes) {
|
|
173
|
+
throw new NonRetryableError(mark('result-too-large'));
|
|
174
|
+
}
|
|
175
|
+
return outcome.result;
|
|
176
|
+
}
|
|
177
|
+
/**
|
|
178
|
+
* The generic Workflow class. `registrations` is called with the Worker's
|
|
179
|
+
* `env` in each invocation, so a deps builder can close over the bindings:
|
|
180
|
+
*
|
|
181
|
+
* export const JobsWorkflow = workflowJobsEntrypoint((env: Env) => [
|
|
182
|
+
* (register) => register(selfSignUp, () => createSignUpDeps(env)),
|
|
183
|
+
* ])
|
|
184
|
+
*
|
|
185
|
+
* It must return the same registrations `createWorkflowJobs` was given.
|
|
186
|
+
*/
|
|
187
|
+
export function workflowJobsEntrypoint(registrations, options = {}) {
|
|
188
|
+
const maxBytes = options.stepResultMaxBytes ?? CLOUDFLARE_MANIFEST.stepResultMaxBytes;
|
|
189
|
+
return class JobsEntrypoint extends WorkflowEntrypoint {
|
|
190
|
+
async run(event, step) {
|
|
191
|
+
const id = event.instanceId;
|
|
192
|
+
const name = id.slice(0, Math.max(0, id.indexOf('-')));
|
|
193
|
+
const job = registry(registrations(this.env)).get(name);
|
|
194
|
+
if (job === undefined) {
|
|
195
|
+
throw new NonRetryableError(`${TOOL}: no Job is registered for ${id}`);
|
|
196
|
+
}
|
|
197
|
+
const base = {
|
|
198
|
+
instanceId: id,
|
|
199
|
+
runId: event.payload.runId,
|
|
200
|
+
unitKey: id.slice(name.length + 1),
|
|
201
|
+
input: event.payload.input,
|
|
202
|
+
};
|
|
203
|
+
const results = {};
|
|
204
|
+
// `step.do`'s `Rpc.Serializable<T>` check recurses without end on the
|
|
205
|
+
// recursive `JsonValue`, so the call is typed here instead. A JSON value
|
|
206
|
+
// is serializable by construction. `step` is an RPC stub, so its method
|
|
207
|
+
// is called on it, not bound.
|
|
208
|
+
const steps = step;
|
|
209
|
+
let exhaustion;
|
|
210
|
+
for (const s of job.steps) {
|
|
211
|
+
const context = { ...base, results: { ...results } };
|
|
212
|
+
try {
|
|
213
|
+
results[s.name] = await steps.do(stepName(s.name), stepConfig(s), async () => attempt(s, context, maxBytes));
|
|
214
|
+
}
|
|
215
|
+
catch (error) {
|
|
216
|
+
exhaustion = exhaustionOf(s.name, error);
|
|
217
|
+
break;
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
if (exhaustion === undefined) {
|
|
221
|
+
return null;
|
|
222
|
+
}
|
|
223
|
+
const handler = job.onExhausted;
|
|
224
|
+
const failed = exhaustion;
|
|
225
|
+
if (handler !== undefined) {
|
|
226
|
+
const context = { ...base, results: { ...results } };
|
|
227
|
+
await step.do(HANDLER_STEP_NAME, HANDLER_STEP, async () => {
|
|
228
|
+
await handler(context, failed);
|
|
229
|
+
return null;
|
|
230
|
+
});
|
|
231
|
+
}
|
|
232
|
+
// The instance ends `errored`, which `status` reports as `failed`.
|
|
233
|
+
throw new NonRetryableError(`${TOOL}: ${id} stopped at step ${failed.step}: ${failed.cause}`);
|
|
234
|
+
}
|
|
235
|
+
};
|
|
236
|
+
}
|
|
237
|
+
/**
|
|
238
|
+
* `Jobs` over the Workflow binding that `workflowJobsEntrypoint`'s class is
|
|
239
|
+
* bound to. Throws when it is built if a registration's name breaks the rule.
|
|
240
|
+
*/
|
|
241
|
+
export function createWorkflowJobs(options) {
|
|
242
|
+
return new WorkflowJobs(options.workflow, registry(options.registrations));
|
|
243
|
+
}
|
|
244
|
+
class WorkflowJobs {
|
|
245
|
+
workflow;
|
|
246
|
+
jobs;
|
|
247
|
+
constructor(workflow, jobs) {
|
|
248
|
+
this.workflow = workflow;
|
|
249
|
+
this.jobs = jobs;
|
|
250
|
+
}
|
|
251
|
+
async dispatch(definition, input, options) {
|
|
252
|
+
const job = this.jobs.get(definition.name);
|
|
253
|
+
if (job === undefined) {
|
|
254
|
+
throw new Misconfigured(TOOL, `Job ${definition.name} is not registered with this executor`);
|
|
255
|
+
}
|
|
256
|
+
const key = job.key(input);
|
|
257
|
+
const id = `${job.name}-${key}`;
|
|
258
|
+
if (!KEY.test(key) || id.length > ID_MAX) {
|
|
259
|
+
throw new LimitExceeded(TOOL, `key ${JSON.stringify(key)} must be [A-Za-z0-9_-], at least one character, and fit an id of ${ID_MAX}`);
|
|
260
|
+
}
|
|
261
|
+
const params = { input, runId: options.runId };
|
|
262
|
+
if (bytes(JSON.stringify(params)) > PARAMS_MAX_BYTES) {
|
|
263
|
+
throw new LimitExceeded(TOOL, `the input of ${id} is above Workflows' ${PARAMS_MAX_BYTES}-byte event payload`);
|
|
264
|
+
}
|
|
265
|
+
try {
|
|
266
|
+
await this.workflow.create({ id, params });
|
|
267
|
+
}
|
|
268
|
+
catch (e) {
|
|
269
|
+
if (alreadyExists(e)) {
|
|
270
|
+
return { status: 'already-started', id };
|
|
271
|
+
}
|
|
272
|
+
throw toFault(TOOL, 'create', e);
|
|
273
|
+
}
|
|
274
|
+
return { status: 'started', id };
|
|
275
|
+
}
|
|
276
|
+
async status(id) {
|
|
277
|
+
const name = id.slice(0, Math.max(0, id.indexOf('-')));
|
|
278
|
+
// An id that breaks the rule, or names no registered Job, was never
|
|
279
|
+
// started here. The platform is not asked.
|
|
280
|
+
if (!ID.test(id) || id.length > ID_MAX || !this.jobs.has(name)) {
|
|
281
|
+
return { status: 'unknown' };
|
|
282
|
+
}
|
|
283
|
+
let instance;
|
|
284
|
+
try {
|
|
285
|
+
instance = await this.workflow.get(id);
|
|
286
|
+
}
|
|
287
|
+
catch (e) {
|
|
288
|
+
if (notFound(e)) {
|
|
289
|
+
return { status: 'unknown' };
|
|
290
|
+
}
|
|
291
|
+
throw toFault(TOOL, 'get', e);
|
|
292
|
+
}
|
|
293
|
+
let current;
|
|
294
|
+
try {
|
|
295
|
+
current = await instance.status();
|
|
296
|
+
}
|
|
297
|
+
catch (e) {
|
|
298
|
+
throw toFault(TOOL, 'status', e);
|
|
299
|
+
}
|
|
300
|
+
switch (current.status) {
|
|
301
|
+
case 'complete':
|
|
302
|
+
return { status: 'completed' };
|
|
303
|
+
// `terminated` is an operator's stop. The handler did not run, but the
|
|
304
|
+
// instance has ended and will run nothing more.
|
|
305
|
+
case 'errored':
|
|
306
|
+
case 'terminated':
|
|
307
|
+
return { status: 'failed' };
|
|
308
|
+
case 'queued':
|
|
309
|
+
case 'running':
|
|
310
|
+
case 'paused':
|
|
311
|
+
case 'waiting':
|
|
312
|
+
case 'waitingForPause':
|
|
313
|
+
return { status: 'running' };
|
|
314
|
+
default:
|
|
315
|
+
// Workflows' own `unknown`, or a status newer than these types.
|
|
316
|
+
throw new Unavailable(TOOL, `Workflows reported status ${JSON.stringify(current.status)} for ${id}`);
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import type { CallRow, DeliveryRow, RunRow, StepRow, TaskCursor, TaskRow, UnitRow } from '../contracts/index.js';
|
|
2
|
+
/**
|
|
3
|
+
* The journal tables' rows, as both SQL adapters read them. The tables are the
|
|
4
|
+
* same on D1 and Postgres (a parity test holds them so), so the mapping lives
|
|
5
|
+
* above both rather than once in each, where the two copies would drift.
|
|
6
|
+
*
|
|
7
|
+
* A BIGINT column arrives as a string from node-postgres and as a number from
|
|
8
|
+
* D1, so every epoch or duration goes through Number(). Exact up to 2^53 ms.
|
|
9
|
+
* docs/decisions/0007.
|
|
10
|
+
*/
|
|
11
|
+
type Big = number | string;
|
|
12
|
+
export type RunRecord = {
|
|
13
|
+
run_id: string;
|
|
14
|
+
job: string;
|
|
15
|
+
trigger: string;
|
|
16
|
+
mode: string;
|
|
17
|
+
started_at: Big;
|
|
18
|
+
identity: string;
|
|
19
|
+
};
|
|
20
|
+
export type UnitRecord = {
|
|
21
|
+
run_id: string;
|
|
22
|
+
unit_key: string;
|
|
23
|
+
unit_type: string;
|
|
24
|
+
recorded_at: Big;
|
|
25
|
+
outcome: string;
|
|
26
|
+
reason_code: string | null;
|
|
27
|
+
plan_hash: string | null;
|
|
28
|
+
plan_ref: string | null;
|
|
29
|
+
duration_ms: Big;
|
|
30
|
+
external_ids: string | null;
|
|
31
|
+
};
|
|
32
|
+
export type StepRecord = {
|
|
33
|
+
run_id: string;
|
|
34
|
+
unit_key: string;
|
|
35
|
+
step: string;
|
|
36
|
+
attempt: number;
|
|
37
|
+
outcome: string;
|
|
38
|
+
reason_code: string | null;
|
|
39
|
+
duration_ms: Big;
|
|
40
|
+
recorded_at: Big;
|
|
41
|
+
};
|
|
42
|
+
export type CallRecord = {
|
|
43
|
+
run_id: string;
|
|
44
|
+
unit_key: string;
|
|
45
|
+
system: string;
|
|
46
|
+
operation: string;
|
|
47
|
+
status: string;
|
|
48
|
+
http_status: number | null;
|
|
49
|
+
idempotency_key: string | null;
|
|
50
|
+
duration_ms: Big | null;
|
|
51
|
+
};
|
|
52
|
+
export type DeliveryRecord = {
|
|
53
|
+
delivery_id: string;
|
|
54
|
+
source: string;
|
|
55
|
+
topic: string;
|
|
56
|
+
shop: string;
|
|
57
|
+
webhook_id: string;
|
|
58
|
+
body_key: string;
|
|
59
|
+
received_at: Big;
|
|
60
|
+
};
|
|
61
|
+
export type TaskRecord = {
|
|
62
|
+
delivery_id: string;
|
|
63
|
+
action: string;
|
|
64
|
+
state: string;
|
|
65
|
+
updated_at: Big;
|
|
66
|
+
reason_code: string | null;
|
|
67
|
+
};
|
|
68
|
+
/** The same defaults the memory adapter uses, so a limit means one thing. */
|
|
69
|
+
export declare const DEFAULT_UNIT_LIMIT = 100;
|
|
70
|
+
export declare const DEFAULT_RUN_LIMIT = 20;
|
|
71
|
+
export declare const toRunRow: (r: RunRecord) => RunRow;
|
|
72
|
+
export declare const toUnitRow: (r: UnitRecord) => UnitRow;
|
|
73
|
+
export declare const toStepRow: (r: StepRecord) => StepRow;
|
|
74
|
+
export declare const toCallRow: (r: CallRecord) => CallRow;
|
|
75
|
+
export declare const toDeliveryRow: (r: DeliveryRecord) => DeliveryRow;
|
|
76
|
+
export declare const toTaskRow: (r: TaskRecord) => TaskRow;
|
|
77
|
+
/** Before every real row, so a first page needs no second query. */
|
|
78
|
+
export declare const FIRST_TASK: TaskCursor;
|
|
79
|
+
export {};
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { fromEpochMs } from '../contracts/index.js';
|
|
2
|
+
/** The same defaults the memory adapter uses, so a limit means one thing. */
|
|
3
|
+
export const DEFAULT_UNIT_LIMIT = 100;
|
|
4
|
+
export const DEFAULT_RUN_LIMIT = 20;
|
|
5
|
+
/**
|
|
6
|
+
* exactOptionalPropertyTypes draws a line between "absent" and "present and
|
|
7
|
+
* undefined", and a NULL column is the first. So an optional field is spread in
|
|
8
|
+
* only when it has a value, rather than assigned undefined.
|
|
9
|
+
*/
|
|
10
|
+
const optional = (key, value) => value === null ? {} : { [key]: value };
|
|
11
|
+
export const toRunRow = (r) => ({
|
|
12
|
+
runId: r.run_id,
|
|
13
|
+
job: r.job,
|
|
14
|
+
trigger: r.trigger,
|
|
15
|
+
mode: r.mode,
|
|
16
|
+
startedAt: fromEpochMs(Number(r.started_at)),
|
|
17
|
+
identity: JSON.parse(r.identity),
|
|
18
|
+
});
|
|
19
|
+
export const toUnitRow = (r) => ({
|
|
20
|
+
runId: r.run_id,
|
|
21
|
+
unitKey: r.unit_key,
|
|
22
|
+
unitType: r.unit_type,
|
|
23
|
+
recordedAt: fromEpochMs(Number(r.recorded_at)),
|
|
24
|
+
outcome: r.outcome,
|
|
25
|
+
durationMs: Number(r.duration_ms),
|
|
26
|
+
...optional('reasonCode', r.reason_code),
|
|
27
|
+
...optional('planHash', r.plan_hash),
|
|
28
|
+
...optional('planRef', r.plan_ref),
|
|
29
|
+
...optional('externalIds', r.external_ids === null
|
|
30
|
+
? null
|
|
31
|
+
: JSON.parse(r.external_ids)),
|
|
32
|
+
});
|
|
33
|
+
export const toStepRow = (r) => ({
|
|
34
|
+
runId: r.run_id,
|
|
35
|
+
unitKey: r.unit_key,
|
|
36
|
+
step: r.step,
|
|
37
|
+
attempt: r.attempt,
|
|
38
|
+
outcome: r.outcome,
|
|
39
|
+
durationMs: Number(r.duration_ms),
|
|
40
|
+
recordedAt: fromEpochMs(Number(r.recorded_at)),
|
|
41
|
+
...optional('reasonCode', r.reason_code),
|
|
42
|
+
});
|
|
43
|
+
export const toCallRow = (r) => ({
|
|
44
|
+
runId: r.run_id,
|
|
45
|
+
unitKey: r.unit_key,
|
|
46
|
+
system: r.system,
|
|
47
|
+
operation: r.operation,
|
|
48
|
+
status: r.status,
|
|
49
|
+
...optional('httpStatus', r.http_status),
|
|
50
|
+
...optional('idempotencyKey', r.idempotency_key),
|
|
51
|
+
...optional('durationMs', r.duration_ms === null ? null : Number(r.duration_ms)),
|
|
52
|
+
});
|
|
53
|
+
export const toDeliveryRow = (r) => ({
|
|
54
|
+
deliveryId: r.delivery_id,
|
|
55
|
+
source: r.source,
|
|
56
|
+
topic: r.topic,
|
|
57
|
+
shop: r.shop,
|
|
58
|
+
webhookId: r.webhook_id,
|
|
59
|
+
bodyKey: r.body_key,
|
|
60
|
+
receivedAt: fromEpochMs(Number(r.received_at)),
|
|
61
|
+
});
|
|
62
|
+
export const toTaskRow = (r) => ({
|
|
63
|
+
deliveryId: r.delivery_id,
|
|
64
|
+
action: r.action,
|
|
65
|
+
state: r.state,
|
|
66
|
+
updatedAt: fromEpochMs(Number(r.updated_at)),
|
|
67
|
+
...optional('reasonCode', r.reason_code),
|
|
68
|
+
});
|
|
69
|
+
/** Before every real row, so a first page needs no second query. */
|
|
70
|
+
export const FIRST_TASK = {
|
|
71
|
+
updatedAt: fromEpochMs(Number.MIN_SAFE_INTEGER),
|
|
72
|
+
deliveryId: '',
|
|
73
|
+
action: '',
|
|
74
|
+
};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { BlobKey, BlobStore, PutOptions } from '../../contracts/index.js';
|
|
2
|
+
export declare class MemoryBlobStore implements BlobStore {
|
|
3
|
+
#private;
|
|
4
|
+
put(key: BlobKey, body: Uint8Array | string, _options?: PutOptions): Promise<void>;
|
|
5
|
+
get(key: BlobKey): Promise<Uint8Array | undefined>;
|
|
6
|
+
getText(key: BlobKey): Promise<string | undefined>;
|
|
7
|
+
delete(key: BlobKey): Promise<void>;
|
|
8
|
+
list(prefix: string): Promise<readonly BlobKey[]>;
|
|
9
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export class MemoryBlobStore {
|
|
2
|
+
#blobs = new Map();
|
|
3
|
+
async put(key, body, _options) {
|
|
4
|
+
this.#blobs.set(key, typeof body === 'string' ? new TextEncoder().encode(body) : body);
|
|
5
|
+
}
|
|
6
|
+
async get(key) {
|
|
7
|
+
return this.#blobs.get(key);
|
|
8
|
+
}
|
|
9
|
+
async getText(key) {
|
|
10
|
+
const b = this.#blobs.get(key);
|
|
11
|
+
return b === undefined ? undefined : new TextDecoder().decode(b);
|
|
12
|
+
}
|
|
13
|
+
async delete(key) {
|
|
14
|
+
this.#blobs.delete(key);
|
|
15
|
+
}
|
|
16
|
+
async list(prefix) {
|
|
17
|
+
return [...this.#blobs.keys()].filter((k) => k.startsWith(prefix)).sort();
|
|
18
|
+
}
|
|
19
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { Cache, CacheKey, Clock } from '../../contracts/index.js';
|
|
2
|
+
export type MemoryCacheOptions = {
|
|
3
|
+
readonly clock: Clock;
|
|
4
|
+
readonly minTtlSeconds: number;
|
|
5
|
+
};
|
|
6
|
+
export declare class MemoryCache implements Cache {
|
|
7
|
+
#private;
|
|
8
|
+
private readonly o;
|
|
9
|
+
constructor(o: MemoryCacheOptions);
|
|
10
|
+
get(key: CacheKey): Promise<string | undefined>;
|
|
11
|
+
put(key: CacheKey, value: string, ttlSeconds: number): Promise<void>;
|
|
12
|
+
delete(key: CacheKey): Promise<void>;
|
|
13
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { LimitExceeded, checkDuration, plusSeconds, } from '../../contracts/index.js';
|
|
2
|
+
export class MemoryCache {
|
|
3
|
+
o;
|
|
4
|
+
#entries = new Map();
|
|
5
|
+
constructor(o) {
|
|
6
|
+
this.o = o;
|
|
7
|
+
}
|
|
8
|
+
async get(key) {
|
|
9
|
+
const entry = this.#entries.get(key);
|
|
10
|
+
if (entry === undefined) {
|
|
11
|
+
return undefined;
|
|
12
|
+
}
|
|
13
|
+
// Inclusive: at exactly expiresAt the value is gone.
|
|
14
|
+
if (entry.expiresAt <= this.o.clock.now()) {
|
|
15
|
+
this.#entries.delete(key);
|
|
16
|
+
return undefined;
|
|
17
|
+
}
|
|
18
|
+
return entry.value;
|
|
19
|
+
}
|
|
20
|
+
async put(key, value, ttlSeconds) {
|
|
21
|
+
// Before the manifest check, which cannot catch it: NaN < minTtlSeconds is
|
|
22
|
+
// false, so a NaN ttl would pass and the value would never expire.
|
|
23
|
+
checkDuration('cache', 'ttlSeconds', ttlSeconds);
|
|
24
|
+
// The ADAPTER enforces its own manifest. Never the caller.
|
|
25
|
+
if (ttlSeconds < this.o.minTtlSeconds) {
|
|
26
|
+
throw new LimitExceeded('cache', `ttlSeconds ${ttlSeconds} is below cacheMinTtlSeconds ${this.o.minTtlSeconds}`);
|
|
27
|
+
}
|
|
28
|
+
this.#entries.set(key, {
|
|
29
|
+
value,
|
|
30
|
+
expiresAt: plusSeconds(this.o.clock.now(), ttlSeconds),
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
async delete(key) {
|
|
34
|
+
this.#entries.delete(key);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { systemClock } from '../system-clock.js';
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export * from './clock.js';
|
|
2
|
+
export * from './queue.js';
|
|
3
|
+
export * from './ledger.js';
|
|
4
|
+
export * from './blob-store.js';
|
|
5
|
+
export * from './journal.js';
|
|
6
|
+
export * from './logger.js';
|
|
7
|
+
export * from './manifest.js';
|
|
8
|
+
export * from './session-storage.js';
|
|
9
|
+
export * from './cache.js';
|
|
10
|
+
export * from './toolkit.js';
|
|
11
|
+
export * from './jobs.js';
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export * from './clock.js';
|
|
2
|
+
export * from './queue.js';
|
|
3
|
+
export * from './ledger.js';
|
|
4
|
+
export * from './blob-store.js';
|
|
5
|
+
export * from './journal.js';
|
|
6
|
+
export * from './logger.js';
|
|
7
|
+
export * from './manifest.js';
|
|
8
|
+
export * from './session-storage.js';
|
|
9
|
+
export * from './cache.js';
|
|
10
|
+
export * from './toolkit.js';
|
|
11
|
+
export * from './jobs.js';
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import type { Instant, JobInstanceId, JobRegistration, Jobs, Toolkit } from '../../contracts/index.js';
|
|
2
|
+
import type { InstanceChange, InstanceRow, Interrupt, ReferenceStore, WakeUp } from '../reference-executor.js';
|
|
3
|
+
import { LocalQueue } from './queue.js';
|
|
4
|
+
/**
|
|
5
|
+
* `job_instances` and `job_steps` (decision 0006) as two Maps. Each method is
|
|
6
|
+
* one statement of the protocol, and none of them awaits between its read
|
|
7
|
+
* and its write, so each is atomic in one isolate as the D1 statement is.
|
|
8
|
+
*/
|
|
9
|
+
export declare class MemoryJobStore implements ReferenceStore {
|
|
10
|
+
#private;
|
|
11
|
+
insert(row: InstanceRow): Promise<'inserted' | 'exists'>;
|
|
12
|
+
get(id: JobInstanceId): Promise<InstanceRow | undefined>;
|
|
13
|
+
update(id: JobInstanceId, version: number, change: InstanceChange): Promise<boolean>;
|
|
14
|
+
remove(id: JobInstanceId, cutoff: Instant): Promise<void>;
|
|
15
|
+
storeResult(id: JobInstanceId, stepIndex: number, result: string, _completedAt: Instant): Promise<void>;
|
|
16
|
+
results(id: JobInstanceId): Promise<ReadonlyMap<number, string>>;
|
|
17
|
+
due(now: Instant): Promise<readonly InstanceRow[]>;
|
|
18
|
+
removeEndedBefore(cutoff: Instant): Promise<void>;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* THE REFERENCE EXECUTOR ON THE MEMORY ADAPTER. Every local test of a Job
|
|
22
|
+
* runs here.
|
|
23
|
+
*
|
|
24
|
+
* Nothing delivers an in-process queue on its own schedule, so `settle` and
|
|
25
|
+
* `wake` are how a test or `npm run dev` drives it. They are affordances of
|
|
26
|
+
* this adapter, as `LocalQueue.drain` is, and not part of `Jobs`.
|
|
27
|
+
*/
|
|
28
|
+
export type MemoryJobs = Jobs & {
|
|
29
|
+
/**
|
|
30
|
+
* Runs the sweeper and delivers every wake-up that is due at the clock's
|
|
31
|
+
* current time, one at a time, until nothing more is due. It never moves
|
|
32
|
+
* the clock. It waits for every consumer in flight, except one that a test
|
|
33
|
+
* parked at an interruption, so a step body that has not returned keeps it
|
|
34
|
+
* from returning.
|
|
35
|
+
*/
|
|
36
|
+
settle(): Promise<void>;
|
|
37
|
+
/**
|
|
38
|
+
* Delivers one extra wake-up for the instance now, as a duplicate, early or
|
|
39
|
+
* reordered message would, and returns once it is handled. Without
|
|
40
|
+
* `stepIndex` it names the instance's current step.
|
|
41
|
+
*/
|
|
42
|
+
wake(id: JobInstanceId, stepIndex?: number): Promise<void>;
|
|
43
|
+
};
|
|
44
|
+
export type MemoryJobsOptions = {
|
|
45
|
+
readonly registrations: readonly JobRegistration[];
|
|
46
|
+
/**
|
|
47
|
+
* TEST SEAMS. A restarted process is a second executor over the same
|
|
48
|
+
* store and queue, and `interrupt` parks a consumer between two writes.
|
|
49
|
+
* An app passes none of them.
|
|
50
|
+
*/
|
|
51
|
+
readonly store?: ReferenceStore;
|
|
52
|
+
readonly queue?: LocalQueue<WakeUp>;
|
|
53
|
+
readonly interrupt?: Interrupt;
|
|
54
|
+
};
|
|
55
|
+
/**
|
|
56
|
+
* Builds the executor. It throws when a registration is refused, as for a
|
|
57
|
+
* Job name outside `[A-Za-z0-9_]{1,64}`.
|
|
58
|
+
*
|
|
59
|
+
* The toolkit supplies the clock (rule 3: backoff and leases are read from
|
|
60
|
+
* it), the logger (rule 4) and the journal its Step rows go to.
|
|
61
|
+
*/
|
|
62
|
+
export declare function createMemoryJobs(toolkit: Pick<Toolkit, 'clock' | 'logger' | 'journal'>, options: MemoryJobsOptions): MemoryJobs;
|