@yaks/durable-object 0.0.0-stage → 0.2.36
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/LICENSE +202 -0
- package/README.md +554 -2
- package/_dist/alarm.d.ts +35 -0
- package/_dist/alarm.d.ts.map +1 -0
- package/_dist/ceiling.d.ts +167 -0
- package/_dist/ceiling.d.ts.map +1 -0
- package/_dist/compose.d.ts +79 -0
- package/_dist/compose.d.ts.map +1 -0
- package/_dist/copy.d.ts +67 -0
- package/_dist/copy.d.ts.map +1 -0
- package/_dist/door.d.ts +172 -0
- package/_dist/door.d.ts.map +1 -0
- package/_dist/job.d.ts +26 -0
- package/_dist/job.d.ts.map +1 -0
- package/_dist/keys.d.ts +14 -0
- package/_dist/keys.d.ts.map +1 -0
- package/_dist/mod.d.ts +65 -0
- package/_dist/mod.d.ts.map +1 -0
- package/_dist/object.d.ts +75 -0
- package/_dist/object.d.ts.map +1 -0
- package/_dist/profile.d.ts +32 -0
- package/_dist/profile.d.ts.map +1 -0
- package/_dist/query-memory.d.ts +27 -0
- package/_dist/query-memory.d.ts.map +1 -0
- package/_dist/resets.d.ts +208 -0
- package/_dist/resets.d.ts.map +1 -0
- package/_dist/rewind.d.ts +21 -0
- package/_dist/rewind.d.ts.map +1 -0
- package/_dist/sockets.d.ts +90 -0
- package/_dist/sockets.d.ts.map +1 -0
- package/_dist/sql.d.ts +72 -0
- package/_dist/sql.d.ts.map +1 -0
- package/_dist/store.d.ts +8 -0
- package/_dist/store.d.ts.map +1 -0
- package/alarm.js +126 -0
- package/alarm.js.map +1 -0
- package/alarm.ts +188 -0
- package/ceiling.js +536 -0
- package/ceiling.js.map +1 -0
- package/ceiling.ts +681 -0
- package/compose.js +201 -0
- package/compose.js.map +1 -0
- package/compose.ts +249 -0
- package/copy.js +394 -0
- package/copy.js.map +1 -0
- package/copy.ts +413 -0
- package/deno.json +1 -0
- package/door.js +364 -0
- package/door.js.map +1 -0
- package/door.ts +542 -0
- package/example.ts +108 -0
- package/holds.js +85 -0
- package/holds.js.map +1 -0
- package/holds.ts +72 -0
- package/job.js +151 -0
- package/job.js.map +1 -0
- package/job.ts +166 -0
- package/keys.js +59 -0
- package/keys.js.map +1 -0
- package/keys.ts +85 -0
- package/mod.js +65 -0
- package/mod.js.map +1 -0
- package/mod.ts +167 -0
- package/object.js +247 -0
- package/object.js.map +1 -0
- package/object.ts +385 -0
- package/package.json +68 -4
- package/profile.js +131 -0
- package/profile.js.map +1 -0
- package/profile.ts +150 -0
- package/query-memory.js +157 -0
- package/query-memory.js.map +1 -0
- package/query-memory.ts +240 -0
- package/resets.js +302 -0
- package/resets.js.map +1 -0
- package/resets.ts +353 -0
- package/rewind.js +68 -0
- package/rewind.js.map +1 -0
- package/rewind.ts +91 -0
- package/sockets.js +749 -0
- package/sockets.js.map +1 -0
- package/sockets.ts +991 -0
- package/sql.js +221 -0
- package/sql.js.map +1 -0
- package/sql.ts +330 -0
- package/store.js +58 -0
- package/store.js.map +1 -0
- package/store.ts +80 -0
- package/watches.js +8 -0
- package/watches.js.map +1 -0
- package/watches.ts +23 -0
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
/** A span of time and the rows an object may read and write within it. */ export type Window = {
|
|
2
|
+
ms: number;
|
|
3
|
+
read: number;
|
|
4
|
+
written: number;
|
|
5
|
+
};
|
|
6
|
+
/** What a window spent since it began, as an object keeps it past its
|
|
7
|
+
* instance. */ export type Spent = {
|
|
8
|
+
ms: number;
|
|
9
|
+
since: number;
|
|
10
|
+
read: number;
|
|
11
|
+
written: number;
|
|
12
|
+
/** What each lane's work spent of it ({@link Ceiling.lane}). */ lanes?: Record<string, {
|
|
13
|
+
read: number;
|
|
14
|
+
written: number;
|
|
15
|
+
}>;
|
|
16
|
+
/** The window was opened by {@link Ceiling.resume}. */ resumed?: boolean;
|
|
17
|
+
};
|
|
18
|
+
/** A minute and an hour. At Cloudflare's prices ($0.001 a million rows read,
|
|
19
|
+
* $1.00 a million written,
|
|
20
|
+
* https://developers.cloudflare.com/durable-objects/platform/pricing/) an
|
|
21
|
+
* object that refuses costs at most $0.20 of reads and $0.50 of writes in an
|
|
22
|
+
* hour of its window, and one statement more. The week before these were set
|
|
23
|
+
* (2026-11-03 to 11-10, Cloudflare's analytics) the platform's directory
|
|
24
|
+
* peaked at 13.7 million rows read in a minute and 15.6 million in an hour,
|
|
25
|
+
* and no object but the tracker in its storm wrote 100,000 in a minute. */ export declare let WINDOWS: Window[];
|
|
26
|
+
/** The rows one statement reads before it can be a scan. */ export declare let SCAN: number;
|
|
27
|
+
/** How many times what its answer represents or it wrote a scan reads. */ export declare let FAR: number;
|
|
28
|
+
type Kind = 'read' | 'written';
|
|
29
|
+
/** One statement read far more rows than its answer represents. */ export declare class Scan extends Error {
|
|
30
|
+
name: string;
|
|
31
|
+
}
|
|
32
|
+
/** An object's statements passed a window's rows. */ export declare class Runaway extends Error {
|
|
33
|
+
name: string;
|
|
34
|
+
}
|
|
35
|
+
/** A statement refused because its object is past a window: the caller's to
|
|
36
|
+
* send again once `retry.after` milliseconds have run, and no defect of its
|
|
37
|
+
* own, since the `Runaway` that stopped the object was told when it happened.
|
|
38
|
+
* `retry.defer` says the wait is no failure: @yaks/effects runs the attempt
|
|
39
|
+
* again as the same one, as it does a handler's `defer`. */ export declare class Stopped extends Error {
|
|
40
|
+
name: string;
|
|
41
|
+
status: number;
|
|
42
|
+
retry: {
|
|
43
|
+
after: number;
|
|
44
|
+
defer: true;
|
|
45
|
+
};
|
|
46
|
+
constructor(after: number, kind: Kind, window?: {
|
|
47
|
+
ms: number;
|
|
48
|
+
limit: number;
|
|
49
|
+
spent: number;
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
/** Whether a failure is a statement an object refused as `Stopped`, met in
|
|
53
|
+
* that object or through its stub. An RPC hands its caller a new error with
|
|
54
|
+
* the name, message and own properties it was thrown with, never its class
|
|
55
|
+
* (https://developers.cloudflare.com/workers/runtime-apis/rpc/error-handling/,
|
|
56
|
+
* from compatibility date 2026-04-21), so it is known by those: its name and
|
|
57
|
+
* the wait it asks for. Another package's error of the same name asks none.
|
|
58
|
+
*
|
|
59
|
+
* ```ts
|
|
60
|
+
* import { equal } from '@yaks/testing'
|
|
61
|
+
* import { crossed } from './testing.ts'
|
|
62
|
+
* let stop = new Stopped(42_000, 'written'), over = crossed(stop)
|
|
63
|
+
* equal([stopped(stop), stopped(over), over instanceof Stopped], [true, true, false])
|
|
64
|
+
* equal(over.message, stop.message)
|
|
65
|
+
* equal(stopped(over) && over.retry, { after: 42_000, defer: true })
|
|
66
|
+
* equal(stopped(Object.assign(Error('esbuild ended'), { name: 'Stopped' })), false)
|
|
67
|
+
* ```
|
|
68
|
+
*/ export declare let stopped: (error: unknown) => error is Stopped;
|
|
69
|
+
/** What a report is filed under: `fault` groups its occurrences on one bug
|
|
70
|
+
* (a scan by its statement, a runaway by which rows), and `tags` name the
|
|
71
|
+
* statement. The host adds which object. */ export type Told = {
|
|
72
|
+
fault: string;
|
|
73
|
+
tags: Record<string, string>;
|
|
74
|
+
};
|
|
75
|
+
export type Report = (error: Scan | Runaway, told: Told) => void;
|
|
76
|
+
export type Options = {
|
|
77
|
+
windows?: Window[];
|
|
78
|
+
now?: () => number;
|
|
79
|
+
/** Where a scan and a runaway go; each is also said on the console. */ report?: Report;
|
|
80
|
+
/** Whether a statement past a window is refused, or only reported. */ refuse?: boolean;
|
|
81
|
+
/** What an earlier instance of the object kept, asked at its first
|
|
82
|
+
* statement. */ kept?: () => Spent[] | undefined;
|
|
83
|
+
/** Keep what the windows spent past this instance: at half and all of
|
|
84
|
+
* the object's allowance, and after a lane spends rows. */ keep?: (spent: Spent[]) => void;
|
|
85
|
+
};
|
|
86
|
+
/** One statement as the driver counts it. `shape` is asked only of a
|
|
87
|
+
* statement costly enough to name. */ export type Counted = {
|
|
88
|
+
shape: () => string;
|
|
89
|
+
rowsRead: number;
|
|
90
|
+
rowsWritten: number;
|
|
91
|
+
returned: number;
|
|
92
|
+
/** Selected input rows represented by aggregate answers, when known. */ matched?: number;
|
|
93
|
+
};
|
|
94
|
+
export type Ceiling = {
|
|
95
|
+
/** Refuse a statement while its object is stopped. */ admit: (writing: boolean) => void;
|
|
96
|
+
count: (statement: Counted) => void;
|
|
97
|
+
/** What a statement would be refused with now, if anything. */ refusal: (writing?: boolean) => Stopped | null;
|
|
98
|
+
/** How long until a statement is admitted, in ms: 0 when one is now. */ stopped: (writing?: boolean) => number;
|
|
99
|
+
/** How long until the object has spent under `share` of every window's
|
|
100
|
+
* rows, read and written, in ms: 0 when it has now. Work that can wait (a
|
|
101
|
+
* store's mover) asks it before it spends more, and leaves the rest of each
|
|
102
|
+
* window to the object's requests. `written` reserves a prospective unit;
|
|
103
|
+
* Infinity means it cannot fit even in an empty window at that share. With
|
|
104
|
+
* a `lane`, the share is of what that lane's own work spent ({@link lane}),
|
|
105
|
+
* so one lane's backlog never spends another's allowance. `burst` is how
|
|
106
|
+
* many milliseconds of a window's share are available in advance. With a
|
|
107
|
+
* burst shorter than the window, its share becomes available over time. */ under: (share: number, written?: number, lane?: string, burst?: number) => number;
|
|
108
|
+
/** Run `body` as a lane's work, across awaits until it settles. The lane
|
|
109
|
+
* counts ordinary and free statements and keeps its spend when it ends. */ lane: <T>(name: string, body: () => T) => T;
|
|
110
|
+
/** Run statements a stopped object must still take: `body`'s own, and
|
|
111
|
+
* those of the work it awaits until it settles. What they cost is told,
|
|
112
|
+
* and stops nothing. */ free: <T>(body: () => T) => T;
|
|
113
|
+
/** Run work the object takes whatever it costs, once: its schema, an index
|
|
114
|
+
* no window can hold. Like {@link free} it stops nothing, across awaits;
|
|
115
|
+
* its rows count against no window and are never told as a runaway, only
|
|
116
|
+
* as a scan. Work it awaits that runs `free` is told as free work is. */ take: <T>(body: () => T) => T;
|
|
117
|
+
/** Refuse nothing from now on, and go on telling: for an object whose
|
|
118
|
+
* stopping costs more than its rows. */ spare: () => void;
|
|
119
|
+
/** Current window counters, including those kept by an earlier instance. */ spent: () => Spent[];
|
|
120
|
+
/** Start fresh windows after an operator repairs a runaway, except one an
|
|
121
|
+
* earlier resume opened, which stands until it ends; return the old
|
|
122
|
+
* counters. */ resume: () => Spent[];
|
|
123
|
+
};
|
|
124
|
+
/** An object's ceiling: its windows, and what it has told.
|
|
125
|
+
*
|
|
126
|
+
* ```ts
|
|
127
|
+
* import { ceiling, Stopped } from './ceiling.ts'
|
|
128
|
+
* import { equal, throws } from '@yaks/testing'
|
|
129
|
+
*
|
|
130
|
+
* let at = 0, said: string[] = []
|
|
131
|
+
* let c = ceiling({
|
|
132
|
+
* windows: [{ ms: 60_000, read: 1_000_000, written: 100 }],
|
|
133
|
+
* now: () => at,
|
|
134
|
+
* report: (e, told) => said.push(`${e.name} ${told.fault}`),
|
|
135
|
+
* refuse: true,
|
|
136
|
+
* })
|
|
137
|
+
* let ran = (rowsRead: number, returned = 0, rowsWritten = 0) =>
|
|
138
|
+
* c.count({ shape: () => 'select "t"', rowsRead, rowsWritten, returned })
|
|
139
|
+
* ran(200_000, 3)
|
|
140
|
+
* equal(said.map((s) => s.split('|')[0]), ['Scan scan'])
|
|
141
|
+
* c.admit(false)
|
|
142
|
+
* ran(900_000, 900_000)
|
|
143
|
+
* equal(said.at(-1), 'Runaway runaway|read')
|
|
144
|
+
* equal((await throws(() => c.admit(false))) instanceof Stopped, true)
|
|
145
|
+
* equal(c.free(() => (c.admit(true), 'kept')), 'kept')
|
|
146
|
+
* equal(c.stopped(), 60_000)
|
|
147
|
+
* at = 60_000
|
|
148
|
+
* c.admit(false)
|
|
149
|
+
* ```
|
|
150
|
+
*/ export declare let ceiling: (_dts_1: never) => Ceiling;
|
|
151
|
+
/** The synchronous key-value storage of a SQLite-backed object
|
|
152
|
+
* (`ctx.storage.kv`), as far as a ceiling keeps its windows in it. */ export type Kv = {
|
|
153
|
+
get(key: string): unknown;
|
|
154
|
+
put(key: string, value: unknown): void;
|
|
155
|
+
delete?(key: string): boolean | void;
|
|
156
|
+
};
|
|
157
|
+
/** The ceiling of the object whose storage this is. A host names its
|
|
158
|
+
* reporter and whether it refuses once, as it is constructed, before its
|
|
159
|
+
* first driver; a storage nobody spoke for is counted and reported on the
|
|
160
|
+
* console.
|
|
161
|
+
*
|
|
162
|
+
* ```ts
|
|
163
|
+
* // bounded(ctx.storage, { report, refuse: true })
|
|
164
|
+
* // let sql = driver(ctx.storage) // counted against it
|
|
165
|
+
* ```
|
|
166
|
+
*/ export declare let bounded: (durable: object, options?: Options) => Ceiling;
|
|
167
|
+
//# sourceMappingURL=ceiling.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ceiling.d.ts","sources":["../ceiling.ts"],"names":[],"mappings":"AA0CA,wEAAwE,GACxE,YAAY;EAAW,IAAI,MAAM;EAAE,MAAM,MAAM;EAAE,SAAS,MAAM;;AAEhE;aACa,GACb,YAAY;EACV,IAAI,MAAM;EACV,OAAO,MAAM;EACb,MAAM,MAAM;EACZ,SAAS,MAAM;EACf,8DAA8D,GAC9D,QAAQ,OAAO,MAAM;IAAI,MAAM,MAAM;IAAE,SAAS,MAAM;;EACtD,qDAAqD,GACrD,UAAU,OAAO;;AAGnB;;;;;;;yEAOyE,GACzE,OAAO,YAAI,SAAS,SAGnB;AAED,0DAA0D,GAC1D,OAAO,YAAI,aAAc;AACzB,wEAAwE,GACxE,OAAO,YAAI,YAAS;KAUf,OAAO,SAAS;AAgBrB,iEAAiE,GACjE,OAAO,cAAM,aAAa;EACf,aAAa;AACxB;AAEA,mDAAmD,GACnD,OAAO,cAAM,gBAAgB;EAClB,aAAgB;AAC3B;AAEA;;;;0DAI0D,GAC1D,OAAO,cAAM,gBAAgB;EAClB,aAAgB;EACzB,eAAY;EACZ;IAAS,OAAO,MAAM;IAAE,OAAO,IAAI;IAAE;EACrC,YACE,OAAO,MAAM,EACb,MAAM,IAAI,EACV;IAAW,IAAI,MAAM;IAAE,OAAO,MAAM;IAAE,OAAO,MAAM;GAAE;AAczD;AAEA;;;;;;;;;;;;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AAM,EAAE,OAAO,OAAO,GAAG,IAAI;EACtC,QAAQ,KAAK,MAAM,GAAG,OAAO,GAAG,IAAI;;AAsCtC;;;;;;;;;CASC,GACD,OAAO,YAAI,UAAW,SAAS,MAAM,EAAE,UAAU,YAAU,QAO1D"}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* An object's graph, composed from a named config through @yaks/host: what
|
|
3
|
+
* one kind of object holds is data (its config, the roles it serves, and where
|
|
4
|
+
* its plugins' facets load from), so two kinds that differ only by their
|
|
5
|
+
* plugins are the one class given two configs.
|
|
6
|
+
*
|
|
7
|
+
* - {@link planned} imports the facets a config's roles serve once an
|
|
8
|
+
* isolate (@yaks/host `prepare`), and assembles them once a vocabulary
|
|
9
|
+
* (`assemble`): every instance of a kind shares its plan, and binds it to
|
|
10
|
+
* its own storage.
|
|
11
|
+
* - {@link lent} is what an object lends what it composes. It hosts no
|
|
12
|
+
* process, so nothing it composes runs a duty, ends a process or keeps a
|
|
13
|
+
* secret past the instance.
|
|
14
|
+
* - {@link composed} is the whole {@link Spec}: the graph over the object's
|
|
15
|
+
* SQLite (`./store.ts`) with its blobs beside it, `api({graph, subs})` as
|
|
16
|
+
* its door and `/ws` as its sockets, and its wakes and effects pool as the
|
|
17
|
+
* works its alarm runs (`./alarm.ts`).
|
|
18
|
+
*
|
|
19
|
+
* ```ts
|
|
20
|
+
* import { Durable } from '@yaks/durable-object/object'
|
|
21
|
+
* import { composed } from '@yaks/durable-object/compose'
|
|
22
|
+
* import { durable } from './testing.ts'
|
|
23
|
+
* import { assertEquals } from '@std/assert'
|
|
24
|
+
*
|
|
25
|
+
* let config = { plugins: ['shelf'] }
|
|
26
|
+
* let load = () =>
|
|
27
|
+
* Promise.resolve({
|
|
28
|
+
* docs: [{
|
|
29
|
+
* $defs: {
|
|
30
|
+
* book: { component: true, properties: { title: { type: 'string' } } },
|
|
31
|
+
* },
|
|
32
|
+
* }],
|
|
33
|
+
* })
|
|
34
|
+
* let ctx = { storage: durable(), acceptWebSocket() {}, getWebSockets: () => [] }
|
|
35
|
+
* let shelf = new Durable(ctx, composed(config, load))
|
|
36
|
+
* await shelf.fetch(
|
|
37
|
+
* new Request('https://do/apply', {
|
|
38
|
+
* method: 'POST',
|
|
39
|
+
* body: JSON.stringify([{ entity: { eid: 'b' }, book: { title: 'Dune' } }]),
|
|
40
|
+
* }),
|
|
41
|
+
* )
|
|
42
|
+
* let read = await shelf.fetch(new Request('https://do/query?q=.book'))
|
|
43
|
+
* assertEquals((await read.json())[0].book, { title: 'Dune' })
|
|
44
|
+
* ```
|
|
45
|
+
*
|
|
46
|
+
* @module
|
|
47
|
+
*/ import type { Load, Role } from "@yaks/host";
|
|
48
|
+
import type { Config } from "@yaks/host/config";
|
|
49
|
+
import type { Words } from "@yaks/host/words";
|
|
50
|
+
import { type Assembly, type Binding } from "@yaks/host/assembly";
|
|
51
|
+
import { type Blobs } from "@yaks/blob";
|
|
52
|
+
import type { Spec } from "./object.js";
|
|
53
|
+
/** A kind's plan, once its facets are imported: its assembly under `words`,
|
|
54
|
+
* made once a vocabulary, or under the words its facets declare. */ export type Assembling = (words?: Words) => Assembly;
|
|
55
|
+
/** What one kind of object composes: its facets, imported when first
|
|
56
|
+
* asked. */ export type Kind = () => Promise<Assembling>;
|
|
57
|
+
/** What an object serves unless its config says otherwise: its graph, and
|
|
58
|
+
* the effects its alarm works. */ export declare let ROLES: readonly Role[];
|
|
59
|
+
/** The plan for `config`'s `roles`, with facets from `load`, made once an
|
|
60
|
+
* isolate. One whose import failed is imported again by the next to ask. */ export declare let planned: (config: Config, load: Load, roles?: readonly Role[]) => Kind;
|
|
61
|
+
/** What an object lends the plugins it composes, as `me`, its bodies kept in
|
|
62
|
+
* `blobs`. */ export declare let lent: (me: string, blobs: Blobs) => Binding['host'];
|
|
63
|
+
/** How {@link composed} composes. */ export type Composing = {
|
|
64
|
+
/** The roles served ({@link ROLES} by default). */ roles?: readonly Role[];
|
|
65
|
+
/** The words the graph speaks, where the object knows them before its
|
|
66
|
+
* facets do. */ words?: Words;
|
|
67
|
+
/** A failure the object caught, by its entry (the console by default). */ report?: Spec['report'];
|
|
68
|
+
/** The deploy the object runs (`Spec.version`). */ version?: string;
|
|
69
|
+
};
|
|
70
|
+
/**
|
|
71
|
+
* The spec of an object composed from `config`, with facets from `load`: its
|
|
72
|
+
* graph over the object's SQLite, schema and blobs installed as it opens; its
|
|
73
|
+
* door `api({graph, subs, db})`, which keeps its receipts in the object's
|
|
74
|
+
* SQLite and hands `/ws` to its sockets; and as its
|
|
75
|
+
* works, the wakes due (@yaks/wake `tick`) and the effects pool, each
|
|
76
|
+
* answering when it is next owed. A write that moves a wake or owes a run arms
|
|
77
|
+
* the alarm.
|
|
78
|
+
*/ export declare let composed: (config: Config, load: Load, options?: Composing) => Spec;
|
|
79
|
+
//# sourceMappingURL=compose.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"compose.d.ts","sources":["../compose.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA8CC,GAED,cAAoB,IAAI,EAAE,IAAI,0BAA+B;AAC7D,cAAc,MAAM,iCAAsC;AAC1D,cAAc,KAAK,gCAAqC;AACxD,SAEE,KAAK,QAAQ,EACb,KAAK,OAAO,mCAEyB;AAGvC,SAAS,KAAK,KAAK,0BAAwD;AAM3E,cAAuB,IAAI,sBAAqB;AAEhD;kEACkE,GAClE,YAAY,cAAc,QAAQ,UAAU;AAE5C;UACU,GACV,YAAY,aAAa,QAAQ;AAEjC;gCACgC,GAChC,OAAO,YAAI,gBAAgB,OAA6B;AAMxD;0EAC0E,GAC1E,OAAO,YAAI,UACT,QAAQ,QACR,MAAM,MACN,iBAAgB,WACf,KAyBF;AAED;YACY,GACZ,OAAO,YAAI,OAAQ,IAAI,MAAM,EAAE,OAAO,UAAQ,QAAQ,QAUpD;AAEF,mCAAmC,GACnC,YAAY;EACV,iDAAiD,GACjD,iBAAiB;EACjB;gBACc,GACd,QAAQ;EACR,wEAAwE,GACxE,SAAS,KAAK;EACd,iDAAiD,GACjD,UAAU,MAAM;;AAGlB;;;;;;;;CAQC,GACD,OAAO,YAAI,WACT,QAAQ,QACR,MAAM,MACN,UAAS,cACR,KA+CF"}
|
package/_dist/copy.d.ts
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { type Driver } from "@yaks/sql";
|
|
2
|
+
/** A value on its way between objects: a blob travels as base64. */ export type Cell = string | number | null | {
|
|
3
|
+
bytes: string;
|
|
4
|
+
};
|
|
5
|
+
export type Cursor = number | string | null;
|
|
6
|
+
/** Everything a far end must make before rows reach it, and after. */ export type Plan = {
|
|
7
|
+
tables: {
|
|
8
|
+
name: string;
|
|
9
|
+
sql: string;
|
|
10
|
+
cols: string[];
|
|
11
|
+
key?: string;
|
|
12
|
+
}[];
|
|
13
|
+
/** views, made once the rows are in: a full-text index may read one */ views: string[];
|
|
14
|
+
/** indexes and triggers, made last */ after: string[];
|
|
15
|
+
/** full-text indexes, made and rebuilt from their content tables */ fts: {
|
|
16
|
+
name: string;
|
|
17
|
+
sql: string;
|
|
18
|
+
}[];
|
|
19
|
+
/** where each AUTOINCREMENT table's counter stands */ sequences: {
|
|
20
|
+
name: string;
|
|
21
|
+
seq: number;
|
|
22
|
+
}[];
|
|
23
|
+
};
|
|
24
|
+
/** How far a table has been read, and what it holds so far. */ export type Copied = {
|
|
25
|
+
rows: number;
|
|
26
|
+
digest: number;
|
|
27
|
+
};
|
|
28
|
+
type Table = Plan['tables'][number];
|
|
29
|
+
/** The cursor before a table's first copy page. */ export declare let first: (t: Table) => Cursor;
|
|
30
|
+
/** What this object's file is made of. A table without a rowid uses its
|
|
31
|
+
* primary key to page through rows. */ export declare let plan: (driver: Driver) => Plan;
|
|
32
|
+
/** One table of the plan, as `plan` would give it, or null when the plan has
|
|
33
|
+
* none of that name: what a page of it asks, without a plan's every table. */ export declare let planFor: (driver: Driver, name: string) => Plan['tables'][number] | null;
|
|
34
|
+
/** A table not yet read. */ export declare let raised: () => Copied;
|
|
35
|
+
/** The next rows of a table after a rowid, up to `until` when one is named,
|
|
36
|
+
* each led by its rowid, and the tally with them in it. A page stops at
|
|
37
|
+
* `limit` rows or near `bytes`, so an answer stays small whatever its rows
|
|
38
|
+
* hold; `ended` says nothing is left to ask past it. */ export declare let page: (driver: Driver, t: Plan['tables'][number], after: Cursor, held: Copied, limit?: number, until?: Cursor) => {
|
|
39
|
+
rows: Cell[][];
|
|
40
|
+
last: Cursor;
|
|
41
|
+
held: Copied;
|
|
42
|
+
ended: boolean;
|
|
43
|
+
};
|
|
44
|
+
/** Each table's last rowid as it stands, 0 for an empty one, so a reader
|
|
45
|
+
* can ask a long table in ranges at once. */ export declare let tips: (driver: Driver, p: Plan) => Record<string, number>;
|
|
46
|
+
/** One run of a table's rows, its digest and where it ends. */ export type Chunk = {
|
|
47
|
+
table: string;
|
|
48
|
+
after: Cursor;
|
|
49
|
+
/** the last rowid in the run; null runs past every rowid the far end holds */ last: Cursor;
|
|
50
|
+
held: Copied;
|
|
51
|
+
};
|
|
52
|
+
/** Every table as runs of `size` rows with their digests. Each table's last run
|
|
53
|
+
* stands for everything past the rows it has, so rows the far end holds that
|
|
54
|
+
* this end no longer does read as a difference too. */ export declare let chunks: (driver: Driver, p: Plan, size?: number) => Chunk[];
|
|
55
|
+
/** Those of a source's chunks that this end holds differently. */ export declare let stale: (driver: Driver, p: Plan, source: Chunk[]) => Chunk[];
|
|
56
|
+
/** A source's rows for a chunk. */ export declare let reread: (driver: Driver, p: Plan, c: Chunk) => Cell[][];
|
|
57
|
+
/** A chunk's rows put in place of what this end holds there. */ export declare let overwritten: (driver: Driver, p: Plan, c: Chunk, rows: Cell[][]) => void;
|
|
58
|
+
/** What a whole table holds, read as `page` reads it. */ export declare let tallied: (driver: Driver, t: Plan['tables'][number]) => Copied;
|
|
59
|
+
/** The far end's first step: its tables made, empty, with foreign keys off for
|
|
60
|
+
* this connection until `ending` turns them back on. */ export declare let copied: (driver: Driver, p: Plan) => void;
|
|
61
|
+
/** Fit the far end's tables to a newer plan before comparing ranges. Keep
|
|
62
|
+
* rows in tables whose definitions still match. If the schema moved, leave
|
|
63
|
+
* indexes, triggers and views for `ending` once the rows agree. */ export declare let align: (driver: Driver, p: Plan) => boolean;
|
|
64
|
+
/** Rows into their table, under the rowids they have always had. */ export declare let arrived: (driver: Driver, t: Plan['tables'][number], rows: Cell[][]) => void;
|
|
65
|
+
/** The far end's last step: indexes, triggers, views, counters and statistics,
|
|
66
|
+
* and foreign keys on. */ export declare let ending: (driver: Driver, p: Plan) => void;
|
|
67
|
+
//# sourceMappingURL=copy.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"copy.d.ts","sources":["../copy.ts"],"names":[],"mappings":"AAcA,SAIE,KAAK,MAAM,yBAUgB;AAK7B,kEAAkE,GAClE,YAAY,OAAO,MAAM,GAAG,MAAM,GAAG,IAAI;EAAK,OAAO,MAAM;;AAC3D,YAAY,SAAS,MAAM,GAAG,MAAM,GAAG,IAAI;AAE3C,oEAAoE,GACpE,YAAY;EACV;IAAU,MAAM,MAAM;IAAE,KAAK,MAAM;IAAE,MAAM,MAAM;IAAI,MAAM,MAAM;;EACjE,qEAAqE,GACrE,OAAO,MAAM;EACb,oCAAoC,GACpC,OAAO,MAAM;EACb,kEAAkE,GAClE;IAAO,MAAM,MAAM;IAAE,KAAK,MAAM;;EAChC,oDAAoD,GACpD;IAAa,MAAM,MAAM;IAAE,KAAK,MAAM;;;AAGxC,6DAA6D,GAC7D,YAAY;EAAW,MAAM,MAAM;EAAE,QAAQ,MAAM;;KAG9C,QAAQ,KAAK,UAAU,MAAM;AAElC,iDAAiD,GACjD,OAAO,YAAI,QAAS,GAAG,UAAQ,OAA0B;AAUzD;qCACqC,GACrC,OAAO,YAAI,OAAQ,QAAQ,WAAS,KAoBnC;AAED;4EAC4E,GAC5E,OAAO,YAAI,UACT,QA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,SAAO,IAAI,CAwBlD"}
|
package/_dist/door.d.ts
ADDED
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
import { IDEMPOTENCY } from "@yaks/api/headers";
|
|
2
|
+
import { type Clock, type Hold } from "@yaks/fp";
|
|
3
|
+
/** A Durable Object stub: one object, reachable by fetch. */ export type Stub = {
|
|
4
|
+
fetch(req: Request, init?: Pick<RequestInit, 'signal'>): Promise<Response>;
|
|
5
|
+
};
|
|
6
|
+
/** A Durable Object namespace binding, the part of it a door uses. */ export type Namespace = {
|
|
7
|
+
idFromName(name: string): unknown;
|
|
8
|
+
get(id: unknown, options?: {
|
|
9
|
+
locationHint?: string;
|
|
10
|
+
}): Stub;
|
|
11
|
+
};
|
|
12
|
+
/**
|
|
13
|
+
* The stub for the object a name stands in, created where `hint` says (a
|
|
14
|
+
* Cloudflare location hint, such as `'enam'`). The runtime reads a hint only
|
|
15
|
+
* at an object's first get and never moves an object, so where the first get
|
|
16
|
+
* placed it is where it answers from, for good.
|
|
17
|
+
*
|
|
18
|
+
* A stub is an I/O object the runtime binds to the request that took it, so
|
|
19
|
+
* take one per call: getting one costs nothing.
|
|
20
|
+
*
|
|
21
|
+
* ```ts
|
|
22
|
+
* import { assertEquals } from '@std/assert'
|
|
23
|
+
* let got: unknown[] = []
|
|
24
|
+
* let ns = {
|
|
25
|
+
* idFromName: (name: string) => `id:${name}`,
|
|
26
|
+
* get: (...args: unknown[]) => (got.push(args), { fetch: () => Promise.resolve(new Response()) }),
|
|
27
|
+
* }
|
|
28
|
+
* stubOf(ns, 'ada', 'enam')
|
|
29
|
+
* stubOf(ns, 'bo')
|
|
30
|
+
* assertEquals(got, [['id:ada', { locationHint: 'enam' }], ['id:bo']])
|
|
31
|
+
* ```
|
|
32
|
+
*/ export declare let stubOf: (ns: Namespace, name: string, hint?: string) => Stub;
|
|
33
|
+
/** A call's options: `replayable: false` says it must not be sent twice. */ export type Call = {
|
|
34
|
+
replayable?: boolean;
|
|
35
|
+
};
|
|
36
|
+
/** A door onto one object: a path, its init and the headers this call sets,
|
|
37
|
+
* answered by the object. An init that is a Request carries its method, body
|
|
38
|
+
* and headers across, which is how a socket upgrade reaches the object with
|
|
39
|
+
* its `Upgrade` header on it. `consume` reads the answer with `read`. */ export type Door = {
|
|
40
|
+
(path: string, init?: RequestInit | Request, headers?: Record<string, string>, options?: Call) : Promise<Response>;
|
|
41
|
+
consume<T>(path: string, read: (response: Response) => T | Promise<T>, init?: RequestInit | Request, headers?: Record<string, string>, options?: Call): Promise<T>;
|
|
42
|
+
};
|
|
43
|
+
/** Whatever answers a request: a stub, or the object itself in-process. */ export type Send = (req: Request) => Promise<Response>;
|
|
44
|
+
/**
|
|
45
|
+
* An object's door onto itself: each call waits a `turn` of its event loop
|
|
46
|
+
* before `send` answers it. In-process a call is a method call that settles on
|
|
47
|
+
* microtasks alone, so a job asking read after read held the object for the
|
|
48
|
+
* whole job, and every request waiting on the object waited that long: the
|
|
49
|
+
* directory's trash sweep held every door on the platform for 18 s (T-4061).
|
|
50
|
+
* Its calls still run in order; the requests waiting run between them. The
|
|
51
|
+
* runtime gives the turn (the next task: Node's `setImmediate` where it has
|
|
52
|
+
* one), since not every Worker that loads this module has it.
|
|
53
|
+
*
|
|
54
|
+
* ```ts
|
|
55
|
+
* import { assertEquals } from '@std/assert'
|
|
56
|
+
* import { setImmediate } from 'node:timers'
|
|
57
|
+
* let next = () => new Promise<void>((go) => void setImmediate(go))
|
|
58
|
+
* let seen: string[] = []
|
|
59
|
+
* let itself = yielding(() => {
|
|
60
|
+
* seen.push('job')
|
|
61
|
+
* return Promise.resolve(new Response())
|
|
62
|
+
* }, next)
|
|
63
|
+
* setImmediate(() => seen.push('waiting'))
|
|
64
|
+
* await itself(new Request('http://store/query'))
|
|
65
|
+
* assertEquals(seen, ['waiting', 'job'])
|
|
66
|
+
* ```
|
|
67
|
+
*/ export declare let yielding: (send: Send, turn: () => Promise<void>) => Send;
|
|
68
|
+
/**
|
|
69
|
+
* A door that builds each request from scratch and hands it to `send`: the
|
|
70
|
+
* init's headers named in `scrub` are dropped, then the call's own headers
|
|
71
|
+
* set. `send` sees the request last, so what it sets is the final word.
|
|
72
|
+
*
|
|
73
|
+
* ```ts
|
|
74
|
+
* import { assertEquals } from '@std/assert'
|
|
75
|
+
* let door = doorOf((req) => Promise.resolve(new Response(
|
|
76
|
+
* `${new URL(req.url).pathname} ${req.headers.get('x-who')}`,
|
|
77
|
+
* )), ['x-who'])
|
|
78
|
+
* let visitor = new Request('http://visitor', { headers: { 'x-who': 'me' } })
|
|
79
|
+
* assertEquals(await door.consume('/query', (r) => r.text(), visitor), '/query null')
|
|
80
|
+
* assertEquals(await (await door('/query', visitor, { 'x-who': 'kernel' })).text(), '/query kernel')
|
|
81
|
+
* ```
|
|
82
|
+
*/ export declare let doorOf: (send: Send, scrub?: string[]) => Door;
|
|
83
|
+
/** Share finite reads accepted by `reads` and queued before `turn` sends them,
|
|
84
|
+
* each caller receiving its own bytes. A read already sent answers no later
|
|
85
|
+
* caller: its snapshot may predate that caller. So one read of a request
|
|
86
|
+
* travels at a time: whoever asks it meanwhile shares the next, sent once it
|
|
87
|
+
* lands, as passengers board the next lift rather than the one already
|
|
88
|
+
* moving. However many callers ask one read together, the object answers it
|
|
89
|
+
* once a round trip. A write or an excluded read separates batches. `hold`
|
|
90
|
+
* keeps the opener's trip alive past its own request. With a shorter
|
|
91
|
+
* `headStart`, a batch can send after that much time behind a slow trip.
|
|
92
|
+
* A caller sharing its first batch can also join a fresh batch after that
|
|
93
|
+
* wait. The original sender can still finish.
|
|
94
|
+
*
|
|
95
|
+
* Callers are often different requests, and a Worker settles a promise only
|
|
96
|
+
* in the request that made it: one request's wake to another is dropped once
|
|
97
|
+
* the sleeper's request ends (@yaks/fp `Scope`). So no caller awaits or
|
|
98
|
+
* settles another's promise. The caller that opens a batch sends it from its
|
|
99
|
+
* own request, and its answer lands on the batch as a value: the bytes, which
|
|
100
|
+
* each caller makes its own response from, or the failure. The opener hears
|
|
101
|
+
* its own send land; every other caller looks for it every `beat` ms on its
|
|
102
|
+
* own clock (@yaks/fp `waitFor`).
|
|
103
|
+
*
|
|
104
|
+
* What runs in another request is dropped, without a word, once that request
|
|
105
|
+
* ends: a batch whose opener ended before sending it, or whose trip never
|
|
106
|
+
* lands, would answer nobody. So a caller unanswered for `patience` ms
|
|
107
|
+
* (`heard` on `clock`) presumes its batch lost and boards again from its own
|
|
108
|
+
* request once, and an opener aborts a trip of its own still out then. `wait`
|
|
109
|
+
* wraps the caller's full wait, so a host can name it. */ export declare let coalesced: (door: Door, reads: (request: Request) => boolean, _dts_1: never) => Door;
|
|
110
|
+
export { IDEMPOTENCY };
|
|
111
|
+
/**
|
|
112
|
+
* The reset an answer carries, as the runtime throws it, or null. An object
|
|
113
|
+
* the runtime resets mid-request can still answer, and it answers the reset as
|
|
114
|
+
* it answers any error, in a 500's refusal body (@yaks/api `refuse`), so the
|
|
115
|
+
* words the runtime meant as "fetch again" would reach the caller as a
|
|
116
|
+
* failure. An object that ran out of memory answers the same way.
|
|
117
|
+
*
|
|
118
|
+
* ```ts
|
|
119
|
+
* import { assertEquals } from '@std/assert'
|
|
120
|
+
* let said = (message: string) => Response.json({ message }, { status: 500 })
|
|
121
|
+
* assertEquals((await reset(said('Network connection lost.')))?.message, 'Network connection lost.')
|
|
122
|
+
* assertEquals(await reset(said('boot failed')), null)
|
|
123
|
+
* assertEquals(await reset(new Response('Network connection lost.')), null)
|
|
124
|
+
* ```
|
|
125
|
+
*/ export declare let reset: (r: Response) => Promise<Error | null>;
|
|
126
|
+
/** An answer, with a reset in it thrown as the runtime throws one. */ export declare let thrown: (r: Response) => Promise<Response>;
|
|
127
|
+
/** The most bytes of an answer {@link received} reads whole. */ export declare let WHOLE: any;
|
|
128
|
+
/** Whether an answer is read whole where it arrives: a finite one, no larger
|
|
129
|
+
* than {@link WHOLE} by the length it declares. A live stream (ndjson, SSE or
|
|
130
|
+
* a socket) is handed on as it comes, since its reader owns its lifetime, and
|
|
131
|
+
* so is a file, which declares more: it is never held whole. */ export declare let finite: (r: Response) => boolean;
|
|
132
|
+
/** Mark an answer made in this process. It has no remote hop whose reset
|
|
133
|
+
* could cut off its body after the headers arrived. */ export declare let inProcess: (r: Response) => Response;
|
|
134
|
+
/** Read a {@link finite} answer whole inside the retry that sent it, so a
|
|
135
|
+
* restart cutting off its body is sent again. */ export declare let received: (r: Response) => Promise<Response>;
|
|
136
|
+
/** What `resending` is told: `report` hears a kill for the object's limits or
|
|
137
|
+
* a refusal for memory, the failures no retry should hide, with the path
|
|
138
|
+
* that met it; `settled` may answer a call whose resends ran
|
|
139
|
+
* out, in place of its last failure; `wait` waits out each pause
|
|
140
|
+
* (`retried`). */ export type Resend = {
|
|
141
|
+
report?: (error: unknown, path: string) => void;
|
|
142
|
+
settled?: (failure: unknown, path: string) => Response | null;
|
|
143
|
+
wait?: (ms: number) => Promise<void>;
|
|
144
|
+
};
|
|
145
|
+
/**
|
|
146
|
+
* A door that sends a call again when the object never ran it (`unserved`):
|
|
147
|
+
* the runtime reset the object or lost the call, thrown or answered
|
|
148
|
+
* (`reset`), or dropped it from an overloaded object's queue, as `retried`
|
|
149
|
+
* paces it. A call is
|
|
150
|
+
* sent again only when that is safe: its request can be built again (no
|
|
151
|
+
* streamed body, and not `replayable: false`), and each carries one
|
|
152
|
+
* `IDEMPOTENCY` key across its sends, so an object that applied it before its
|
|
153
|
+
* answer was lost answers the next as it answered the first. A caller that
|
|
154
|
+
* will send the call again itself names the key, and the door keeps it.
|
|
155
|
+
*
|
|
156
|
+
* An answer is read whole inside the retry, so a restart that cuts off its
|
|
157
|
+
* body is sent again too; a stream is handed on as it comes. A caller that
|
|
158
|
+
* reads the answer (`consume`) reads it inside the same retry, so a read
|
|
159
|
+
* failing in the runtime's opaque words is sent again, and a write is not.
|
|
160
|
+
*
|
|
161
|
+
* ```ts
|
|
162
|
+
* import { assertEquals } from '@std/assert'
|
|
163
|
+
* let sends = 0
|
|
164
|
+
* let door = resending(doorOf(() =>
|
|
165
|
+
* Promise.resolve(++sends < 2
|
|
166
|
+
* ? Response.json({ message: 'Network connection lost.' }, { status: 500 })
|
|
167
|
+
* : new Response('ok'))
|
|
168
|
+
* ), { wait: () => Promise.resolve() })
|
|
169
|
+
* assertEquals([await (await door('/query')).text(), sends], ['ok', 2])
|
|
170
|
+
* ```
|
|
171
|
+
*/ export declare let resending: (door: Door, o?: Resend) => Door;
|
|
172
|
+
//# sourceMappingURL=door.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"door.d.ts","sources":["../door.ts"],"names":[],"mappings":"AAYA,SAAS,WAAW,iCAAsC;AAC1D,SACE,KAAK,KAAK,EAEV,KAAK,IAAI,wBAKiB;AAU5B,2DAA2D,GAC3D,YAAY;EACV,MAAM,KAAK,SAAS,OAAO,KAAK,aAAa,YAAY,QAAQ;;AAGnE,oEAAoE,GACpE,YAAY;EACV,WAAW,MAAM,MAAM,GAAG,OAAO;EACjC,IAAI,IAAI,OAAO,EAAE;IAAY,eAAe,MAAM;MAAK;;AAGzD;;;;;;;;;;;;;;;;;;;;CAoBC,GACD,OAAO,YAAI,SAAU,IAAI,WAAW,MAAM,MAAM,EAAE,OAAO,MAAM,KAAG,KAGjE;AAED,0EAA0E,GAC1E,YAAY;EAAS,aAAa,OAAO;;AAEzC;;;uEAGuE,GACvE,YAAY;GAER,MAAM,MAAM,EACZ,OAAO,cAAc,SACrB,UAAU,OAAO,MAAM,EAAE,MAAM,GAC/B,UAAU,QACT,QAAQ;EACX,QAAQ,GACN,MAAM,MAAM,EACZ,OAAO,UAAU,aAAa,IAAI,QAAQ,IAC1C,OAAO,cAAc,SACrB,UAAU,OAAO,MAAM,EAAE,MAAM,GAC/B,UAAU,OACT,QAAQ;;AAGb,yEAAyE,GACzE,YAAY,QAAQ,KAAK,YAAY,QAAQ;AAE7C;;;;;;;;;;;;;;;;;;;;;;;CAuBC,GACD,OAAO,YAAI,WACR,MAAM,MAAM,YAAY,QAAQ,IAAI,MAAI,KAGxC;AAEH;;;;;;;;;;;;;;CAcC,GACD,OAAO,YAAI,SAAU,MAAM,MAAM,QAAO,MAAM,OAAU,KAmBvD;AAkCD;;;;;;;;;;;;;;;;;;;;;;;;;;wDA0BwD,GACxD,OAAO,YAAI,YACT,MAAM,MACN,QAAQ,SAAS,YAAY,OAAO,EACpC,kBAiBC,KA2IF;AAID,SAAS,WAAW,GAAE;AAEtB;;;;;;;;;;;;;;CAcC,GACD,OAAO,YAAI,QAAe,GAAG,aAAW,QAAQ,QAAQ,IAAI,EAY3D;AAED,oEAAoE,GACpE,OAAO,YAAI,SAAgB,GAAG,aAAW,QAAQ,UAIhD;AAED,8DAA8D,GAC9D,OAAO,YAAI,WAAmB;AAE9B;;;8DAG8D,GAC9D,OAAO,YAAI,SAAU,GAAG,aAAW,OAAO,CAGa;AAIvD;qDACqD,GACrD,OAAO,YAAI,YAAa,GAAG,aAAW,SAGrC;AAED;+CAC+C,GAC/C,OAAO,YAAI,WAAkB,GAAG,aAAW,QAAQ,UACsB;AAOzE;;;;gBAIgB,GAChB,YAAY;EACV,UAAU,OAAO,OAAO,EAAE,MAAM,MAAM,KAAK,IAAI;EAC/C,WAAW,SAAS,OAAO,EAAE,MAAM,MAAM,KAAK,WAAW,IAAI;EAC7D,QAAQ,IAAI,MAAM,KAAK,QAAQ,IAAI;;AAGrC;;;;;;;;;;;;;;;;;;;;;;;;;;CA0BC,GACD,OAAO,YAAI,YAAa,MAAM,MAAM,IAAG,WAAc,KAoDpD"}
|
package/_dist/job.d.ts
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/** A single, replayable job: run by a caller that waits for it, and by its
|
|
2
|
+
* object's alarm, which takes it up after an interruption or, for one asked
|
|
3
|
+
* to start later, once that time comes. @module */ import { type Clock } from "@yaks/fp";
|
|
4
|
+
import type { Kv } from "./ceiling.js";
|
|
5
|
+
type Job<I, O> = {
|
|
6
|
+
/** Record the job, unless one stands, and wait up to `wait` for its
|
|
7
|
+
* answer, running it in this call. One nobody waits on starts in the
|
|
8
|
+
* alarm, `after` from now. */ ask(input: I, wait: number, after?: number): Promise<O | null>;
|
|
9
|
+
work(): Promise<number | null>;
|
|
10
|
+
};
|
|
11
|
+
type Options = {
|
|
12
|
+
time?: Clock;
|
|
13
|
+
attempts?: number;
|
|
14
|
+
keep: number;
|
|
15
|
+
};
|
|
16
|
+
/** Named {@link Job}s: each asked for by its name, worked by one alarm. */ export type Jobs<I, O> = {
|
|
17
|
+
ask(name: string, input: I, wait: number, after?: number): Promise<O | null>;
|
|
18
|
+
work(): Promise<number | null>;
|
|
19
|
+
};
|
|
20
|
+
export declare let job: <I, O extends object>(keys: Kv, key: string, arm: (at: number) => Promise<void>, run: (input: I) => Promise<O>, failed: (input: I, reason: string, error?: unknown) => O, retry: (error: unknown) => number | undefined, {}: Options) => Job<I, O>;
|
|
21
|
+
/** Many {@link job}s in one object, each by its name, kept under `key` and a
|
|
22
|
+
* list of the names it holds there, so one alarm works them all. An object
|
|
23
|
+
* holding the jobs of many inputs is made once, where an object per input is
|
|
24
|
+
* made for each, keeping its first caller waiting. A job whose answer has
|
|
25
|
+
* expired leaves the list. */ export declare let jobs: <I, O extends object>(keys: Kv, key: string, arm: (at: number) => Promise<void>, run: (input: I) => Promise<O>, failed: (input: I, reason: string, error?: unknown) => O, retry: (error: unknown) => number | undefined, options: Options) => Jobs<I, O>;
|
|
26
|
+
//# sourceMappingURL=job.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"job.d.ts","sources":["../job.ts"],"names":[],"mappings":"AAAA;;iDAEiD,GACjD,SAAS,KAAK,KAAK,wBAAyD;AAC5E,cAAc,EAAE,uBAAsB;KAKjC,IAAI,GAAG;EACV;;8BAE4B,GAC5B,IAAI,OAAO,GAAG,MAAM,MAAM,EAAE,QAAQ,MAAM,GAAG,QAAQ,IAAI,IAAI;EAC7D,QAAQ,QAAQ,MAAM,GAAG,IAAI;;KAG1B;EAAY,OAAO;EAAO,WAAW,MAAM;EAAE,MAAM,MAAM;;AAE9D,yEAAyE,GACzE,YAAY,KAAK,GAAG;EAClB,IAAI,MAAM,MAAM,EAAE,OAAO,GAAG,MAAM,MAAM,EAAE,QAAQ,MAAM,GAAG,QAAQ,IAAI,IAAI;EAC3E,QAAQ,QAAQ,MAAM,GAAG,IAAI;;AAG/B,OAAO,YAAI,MAAO,GAAG,UAAU,MAAM,EACnC,MAAM,IACN,KAAK,MAAM,EACX,MAAM,IAAI,MAAM,KAAK,QAAQ,IAAI,GACjC,MAAM,OAAO,MAAM,QAAQ,IAC3B,SAAS,OAAO,GAAG,QAAQ,MAAM,EAAE,QAAQ,OAAO,KAAK,GACvD,QAAQ,OAAO,OAAO,KAAK,MAAM,GAAG,SAAS,EAC7C,IAAuC,OAAO,KAC7C,IAAI,GAAG,GAuFT;AAED;;;;4BAI4B,GAC5B,OAAO,YAAI,OAAQ,GAAG,UAAU,MAAM,EACpC,MAAM,IACN,KAAK,MAAM,EACX,MAAM,IAAI,MAAM,KAAK,QAAQ,IAAI,GACjC,MAAM,OAAO,MAAM,QAAQ,IAC3B,SAAS,OAAO,GAAG,QAAQ,MAAM,EAAE,QAAQ,OAAO,KAAK,GACvD,QAAQ,OAAO,OAAO,KAAK,MAAM,GAAG,SAAS,EAC7C,SAAS,YACR,KAAK,GAAG,GA8BV"}
|
package/_dist/keys.d.ts
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/** The async key-value methods of a Durable Object's storage, single keys
|
|
2
|
+
* at a time. */ export type Keys = {
|
|
3
|
+
get<T>(key: string): Promise<T | undefined>;
|
|
4
|
+
put(key: string, value: unknown): Promise<void>;
|
|
5
|
+
delete(key: string): Promise<boolean>;
|
|
6
|
+
list<T>(options?: {
|
|
7
|
+
prefix?: string;
|
|
8
|
+
limit?: number;
|
|
9
|
+
}): Promise<Map<string, T>>;
|
|
10
|
+
};
|
|
11
|
+
/** `storage`'s async key-value methods, each counted against the ceiling of
|
|
12
|
+
* the object whose storage it is: the one its host named first, as a
|
|
13
|
+
* driver's statements are. */ export declare let keys: (storage: Keys) => Keys;
|
|
14
|
+
//# sourceMappingURL=keys.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"keys.d.ts","sources":["../keys.ts"],"names":[],"mappings":"AAkCA;cACc,GACd,YAAY;EACV,IAAI,GAAG,KAAK,MAAM,GAAG,QAAQ,IAAI,SAAS;EAC1C,IAAI,KAAK,MAAM,EAAE,OAAO,OAAO,GAAG,QAAQ,IAAI;EAC9C,OAAO,KAAK,MAAM,GAAG,QAAQ,OAAO;EACpC,KAAK,GACH;IAAY,SAAS,MAAM;IAAE,QAAQ,MAAM;MAC1C,QAAQ,IAAI,MAAM,EAAE;;AAGzB;;4BAE4B,GAC5B,OAAO,YAAI,OAAQ,SAAS,SAAO,KAoClC"}
|
package/_dist/mod.d.ts
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @yaks/durable-object — a yaks graph inside a Cloudflare **Durable Object**:
|
|
3
|
+
* its embedded SQLite is the storage, and its hibernatable WebSockets are the
|
|
4
|
+
* live-sync fan-out.
|
|
5
|
+
*
|
|
6
|
+
* A Durable Object is a single-threaded, strongly-consistent home for one
|
|
7
|
+
* graph. `ctx.storage.sql` is a synchronous SQLite engine, so
|
|
8
|
+
* {@link https://jsr.io/@yaks/graph | @yaks/graph}'s `apply()` stays
|
|
9
|
+
* synchronous here; `ctx.storage.transactionSync` is the transaction it runs
|
|
10
|
+
* its in-transaction phases inside.
|
|
11
|
+
*
|
|
12
|
+
* ## Two halves
|
|
13
|
+
* {@link storage} implements the `Storage` interface — in one line of
|
|
14
|
+
* composition:
|
|
15
|
+
* {@link driver} turns the object's SQLite into a
|
|
16
|
+
* {@link https://jsr.io/@yaks/sql | @yaks/sql} `Driver`, and @yaks/sqlite over it
|
|
17
|
+
* owns the schema, the compiled reads, the patches and the cascading deletes.
|
|
18
|
+
* No SQL is written twice.
|
|
19
|
+
*
|
|
20
|
+
* {@link sockets} is the plumbing between the object's WebSockets and
|
|
21
|
+
* {@link https://jsr.io/@yaks/api | @yaks/api}'s subscriptions — accept a
|
|
22
|
+
* socket for hibernation, pass its frames to the registry, and rebuild the
|
|
23
|
+
* subscriptions of a woken object from what its sockets hold. What a
|
|
24
|
+
* subscription means lives in @yaks/api; only the Cloudflare-specific plumbing
|
|
25
|
+
* is here.
|
|
26
|
+
*
|
|
27
|
+
* ```ts
|
|
28
|
+
* import { graph } from '@yaks/graph'
|
|
29
|
+
* import { api, subscriptions } from '@yaks/api'
|
|
30
|
+
* import { sockets, storage } from '@yaks/durable-object'
|
|
31
|
+
*
|
|
32
|
+
* // let store = storage(ctx.storage, vocab)
|
|
33
|
+
* // store.install()
|
|
34
|
+
* // let g = graph({ storage: store, vocab })
|
|
35
|
+
* // let subs = subscriptions(g)
|
|
36
|
+
* // let live = sockets(subs, ctx)
|
|
37
|
+
* // let handler = api({ graph: g, subs })
|
|
38
|
+
* ```
|
|
39
|
+
*
|
|
40
|
+
* {@link Durable} is the whole object as a class, the one place a class is
|
|
41
|
+
* the platform's requirement: a spec opens its graph, door and sockets, and
|
|
42
|
+
* {@link clock} works everything it does on its own time from its one alarm.
|
|
43
|
+
*
|
|
44
|
+
* And from the caller's side, the door to an object: {@link stubOf} takes a
|
|
45
|
+
* namespace's stub by name, placed where a hint says; {@link doorOf} builds
|
|
46
|
+
* every request through it from scratch; and {@link resending} sends a call
|
|
47
|
+
* again when the runtime reset the object or lost the call, while that is
|
|
48
|
+
* safe.
|
|
49
|
+
*
|
|
50
|
+
* @module
|
|
51
|
+
*/ export { clearStorage, driver, type DurableSql, type DurableStorage, freely, type Measure, type Observe, prohibited, reserved, type Sample, type SqlCursor, type SqlValue } from "./sql.js";
|
|
52
|
+
export { queryJson, queryMemory, QueryPage } from "./query-memory.js";
|
|
53
|
+
export { align, arrived, type Cell, type Chunk, chunks, type Copied, copied, type Cursor, ending, first, overwritten, page, type Plan, plan, planFor, raised, reread, stale, tallied, tips } from "./copy.js";
|
|
54
|
+
export { storage, type Store } from "./store.js";
|
|
55
|
+
export { type Keys, keys } from "./keys.js";
|
|
56
|
+
export { job, type Jobs, jobs } from "./job.js";
|
|
57
|
+
export { type Alarms, BACKSTOP, type Clock, clock, RETRY, SLICE, type Work } from "./alarm.js";
|
|
58
|
+
export { Durable, type Opened, type Spec, type State } from "./object.js";
|
|
59
|
+
export { type Assembling, composed, type Composing, type Kind, lent, planned, ROLES } from "./compose.js";
|
|
60
|
+
export { type Call, type Door, doorOf, finite, IDEMPOTENCY, type Namespace, received, type Resend, resending, reset, type Send, type Stub, stubOf, thrown, WHOLE } from "./door.js";
|
|
61
|
+
export { backoff, evicted, jittered, killed, LOOK, moved, opaque, type Own, replaced, retried, starved, vacating } from "./resets.js";
|
|
62
|
+
export { profile, type Summary } from "./profile.js";
|
|
63
|
+
export { bounded, type Ceiling, ceiling, FAR, type Kv, type Report, Runaway, SCAN, Scan, type Spent, Stopped, stopped, type Told, type Window, WINDOWS } from "./ceiling.js";
|
|
64
|
+
export { type Hibernation, socketRenewals, type Sockets, sockets, type Wire } from "./sockets.js";
|
|
65
|
+
//# sourceMappingURL=mod.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mod.d.ts","sources":["../mod.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAkDC,GAED,SACE,YAAY,EACZ,MAAM,EACN,KAAK,UAAU,EACf,KAAK,cAAc,EACnB,MAAM,EACN,KAAK,OAAO,EACZ,KAAK,OAAO,EACZ,UAAU,EACV,QAAQ,EACR,KAAK,MAAM,EACX,KAAK,SAAS,EACd,KAAK,QAAQ,mBACE;AACjB,SAAS,SAAS,EAAE,WAAW,EAAE,SAAS,4BAA2B;AACrE,SACE,KAAK,EACL,OAAO,EACP,KAAK,IAAI,EACT,KAAK,KAAK,EACV,MAAM,EACN,KAAK,MAAM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