@yaks/api 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.
Files changed (152) hide show
  1. package/LICENSE +202 -0
  2. package/README.md +956 -2
  3. package/_dist/actor.d.ts +59 -0
  4. package/_dist/actor.d.ts.map +1 -0
  5. package/_dist/address.d.ts +33 -0
  6. package/_dist/address.d.ts.map +1 -0
  7. package/_dist/asset.d.ts +15 -0
  8. package/_dist/asset.d.ts.map +1 -0
  9. package/_dist/batches.d.ts +4 -0
  10. package/_dist/batches.d.ts.map +1 -0
  11. package/_dist/body.d.ts +7 -0
  12. package/_dist/body.d.ts.map +1 -0
  13. package/_dist/deno.d.ts +38 -0
  14. package/_dist/deno.d.ts.map +1 -0
  15. package/_dist/doors.d.ts +134 -0
  16. package/_dist/doors.d.ts.map +1 -0
  17. package/_dist/graph.d.ts +17 -0
  18. package/_dist/graph.d.ts.map +1 -0
  19. package/_dist/headers.d.ts +5 -0
  20. package/_dist/headers.d.ts.map +1 -0
  21. package/_dist/log.d.ts +253 -0
  22. package/_dist/log.d.ts.map +1 -0
  23. package/_dist/mod.d.ts +71 -0
  24. package/_dist/mod.d.ts.map +1 -0
  25. package/_dist/publish.d.ts +7 -0
  26. package/_dist/publish.d.ts.map +1 -0
  27. package/_dist/reached.d.ts +145 -0
  28. package/_dist/reached.d.ts.map +1 -0
  29. package/_dist/receipts.d.ts +153 -0
  30. package/_dist/receipts.d.ts.map +1 -0
  31. package/_dist/refuse.d.ts +51 -0
  32. package/_dist/refuse.d.ts.map +1 -0
  33. package/_dist/relay.d.ts +3 -0
  34. package/_dist/relay.d.ts.map +1 -0
  35. package/_dist/request.d.ts +79 -0
  36. package/_dist/request.d.ts.map +1 -0
  37. package/_dist/requests.d.ts +7 -0
  38. package/_dist/requests.d.ts.map +1 -0
  39. package/_dist/route.d.ts +71 -0
  40. package/_dist/route.d.ts.map +1 -0
  41. package/_dist/routed.d.ts +33 -0
  42. package/_dist/routed.d.ts.map +1 -0
  43. package/_dist/routes.d.ts +46 -0
  44. package/_dist/routes.d.ts.map +1 -0
  45. package/_dist/save.d.ts +6 -0
  46. package/_dist/save.d.ts.map +1 -0
  47. package/_dist/socket.d.ts +73 -0
  48. package/_dist/socket.d.ts.map +1 -0
  49. package/_dist/subs.d.ts +134 -0
  50. package/_dist/subs.d.ts.map +1 -0
  51. package/_dist/timing.d.ts +8 -0
  52. package/_dist/timing.d.ts.map +1 -0
  53. package/_dist/tools.d.ts +80 -0
  54. package/_dist/tools.d.ts.map +1 -0
  55. package/_dist/vocab.d.ts +6 -0
  56. package/_dist/vocab.d.ts.map +1 -0
  57. package/access.js +32 -0
  58. package/access.js.map +1 -0
  59. package/access.ts +42 -0
  60. package/actor.js +75 -0
  61. package/actor.js.map +1 -0
  62. package/actor.ts +106 -0
  63. package/address.js +42 -0
  64. package/address.js.map +1 -0
  65. package/address.ts +49 -0
  66. package/admission.js +71 -0
  67. package/admission.js.map +1 -0
  68. package/admission.ts +64 -0
  69. package/asset.js +37 -0
  70. package/asset.js.map +1 -0
  71. package/asset.ts +47 -0
  72. package/batches.js +92 -0
  73. package/batches.js.map +1 -0
  74. package/batches.ts +96 -0
  75. package/body.js +51 -0
  76. package/body.js.map +1 -0
  77. package/body.ts +82 -0
  78. package/deno.js +88 -0
  79. package/deno.js.map +1 -0
  80. package/deno.json +1 -0
  81. package/deno.ts +150 -0
  82. package/doors.js +435 -0
  83. package/doors.js.map +1 -0
  84. package/doors.ts +570 -0
  85. package/graph.js +12 -0
  86. package/graph.js.map +1 -0
  87. package/graph.ts +23 -0
  88. package/headers.js +5 -0
  89. package/headers.js.map +1 -0
  90. package/headers.ts +9 -0
  91. package/interest.js +224 -0
  92. package/interest.js.map +1 -0
  93. package/interest.ts +264 -0
  94. package/log.js +1011 -0
  95. package/log.js.map +1 -0
  96. package/log.ts +1035 -0
  97. package/mod.js +69 -0
  98. package/mod.js.map +1 -0
  99. package/mod.ts +142 -0
  100. package/package.json +75 -4
  101. package/peer_query.js +164 -0
  102. package/peer_query.js.map +1 -0
  103. package/peer_query.ts +158 -0
  104. package/publish.js +7 -0
  105. package/publish.js.map +1 -0
  106. package/publish.ts +16 -0
  107. package/reached.js +456 -0
  108. package/reached.js.map +1 -0
  109. package/reached.ts +549 -0
  110. package/receipts.js +543 -0
  111. package/receipts.js.map +1 -0
  112. package/receipts.ts +749 -0
  113. package/refuse.js +120 -0
  114. package/refuse.js.map +1 -0
  115. package/refuse.ts +179 -0
  116. package/relay.js +249 -0
  117. package/relay.js.map +1 -0
  118. package/relay.ts +284 -0
  119. package/request.js +218 -0
  120. package/request.js.map +1 -0
  121. package/request.ts +235 -0
  122. package/requests.js +250 -0
  123. package/requests.js.map +1 -0
  124. package/requests.ts +257 -0
  125. package/route.js +139 -0
  126. package/route.js.map +1 -0
  127. package/route.ts +228 -0
  128. package/routed.js +25 -0
  129. package/routed.js.map +1 -0
  130. package/routed.ts +53 -0
  131. package/routes.js +154 -0
  132. package/routes.js.map +1 -0
  133. package/routes.ts +201 -0
  134. package/save.js +341 -0
  135. package/save.js.map +1 -0
  136. package/save.ts +393 -0
  137. package/socket.js +398 -0
  138. package/socket.js.map +1 -0
  139. package/socket.ts +496 -0
  140. package/subs.js +2295 -0
  141. package/subs.js.map +1 -0
  142. package/subs.ts +2979 -0
  143. package/timing.js +17 -0
  144. package/timing.js.map +1 -0
  145. package/timing.ts +26 -0
  146. package/tools.js +251 -0
  147. package/tools.js.map +1 -0
  148. package/tools.ts +315 -0
  149. package/vocab.js +18 -0
  150. package/vocab.js.map +1 -0
  151. package/vocab.json +93 -0
  152. package/vocab.ts +18 -0
@@ -0,0 +1,59 @@
1
+ import type { Actor } from "@yaks/graph";
2
+ /**
3
+ * How the application names the writer of a request: the actor making it, or
4
+ * `null` for nobody. Throwing
5
+ * {@link https://jsr.io/@yaks/api/doc/~/Unauthorized | Unauthorized} answers
6
+ * the request with a 401.
7
+ *
8
+ * An actor is the pair a write is stamped with — `by` the identity it acts
9
+ * for, and `via` whatever it came through: a session, a connector, or the
10
+ * server itself. An application that knows only the identity returns only
11
+ * `by`.
12
+ *
13
+ * It runs on every request the handler answers — a read, a write and a
14
+ * WebSocket upgrade alike — so an application that restricts reads restricts
15
+ * them here. A door that has already read the request's body hands what it
16
+ * said as `message` (the MCP door's JSON-RPC message), so the caller a body
17
+ * names is answered without reading it twice.
18
+ *
19
+ * ```ts
20
+ * declare let memberOf: (key: string) => string
21
+ *
22
+ * let authenticate = (request: Request) => {
23
+ * let key = request.headers.get('authorization')
24
+ * return key ? { by: memberOf(key) } : null
25
+ * }
26
+ * ```
27
+ */ export type Authenticate = (request: Request, message?: unknown) => Actor | null | Promise<Actor | null>;
28
+ export { signed } from "@yaks/graph/provenance";
29
+ /** The header a request names the run behind it in: the fleet's own name
30
+ * for the instrument behind a write, never a credential. */ export declare let VIA: string;
31
+ /**
32
+ * Callers named by another graph's door: a request naming a run in `x-via` is
33
+ * whoever the door at `url` says it is (its `GET /who`, read for its `by` and
34
+ * `via` alone), so a graph that keeps no sessions of its own, such as the
35
+ * box's tracker, signs a session's writes as the graph that keeps them does.
36
+ * A request naming none is nobody here.
37
+ *
38
+ * ```ts
39
+ * import { api, asking } from '@yaks/api'
40
+ * import { graph } from '@yaks/graph'
41
+ * import { ram } from '@yaks/ram'
42
+ * import { loadVocab } from '@yaks/vocab'
43
+ * import { assertEquals } from '@std/assert'
44
+ *
45
+ * const vocab = loadVocab({ $defs: {} })
46
+ * const box = api({
47
+ * graph: graph({ vocab, storage: ram(vocab) }),
48
+ * authenticate: (r) => ({ by: 'agent', via: r.headers.get('x-via')! }),
49
+ * })
50
+ * const who = asking('http://box.test', async (url, init) =>
51
+ * box(new Request(url, init)))
52
+ * const request = new Request('http://tracker.test/apply', {
53
+ * headers: { 'x-via': 'run' },
54
+ * })
55
+ * assertEquals(await who(request), { by: 'agent', via: 'run' })
56
+ * assertEquals(await who(new Request('http://tracker.test/apply')), null)
57
+ * ```
58
+ */ export declare let asking: (url: string, go?: typeof fetch) => Authenticate;
59
+ //# sourceMappingURL=actor.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"actor.d.ts","sources":["../actor.ts"],"names":[],"mappings":"AAaA,cAAc,KAAK,2BAAgC;AAEnD;;;;;;;;;;;;;;;;;;;;;;;;;CAyBC,GACD,YAAY,gBACV,SAAS,SACT,UAAU,OAAO,KACd,QAAQ,IAAI,GAAG,QAAQ,QAAQ,IAAI;AAOxC,SAAS,MAAM,sCAA2C;AAE1D;0DAC0D,GAC1D,OAAO,YAAI,YAAa;AAExB;;;;;;;;;;;;;;;;;;;;;;;;;;;CA2BC,GACD,OAAO,YAAI,SAAU,KAAK,MAAM,EAAE,YAAW,UAAgB,aAoB5D"}
@@ -0,0 +1,33 @@
1
+ /** The port `serve` listens on when neither the call nor the config names
2
+ * one. */ export declare let PORT: number;
3
+ /** The interface `serve` binds when neither the call nor the config names
4
+ * one: this machine alone. A server that answers every request as the machine
5
+ * itself (@yaks/cli's `doorman`) is offered to a network only when a config
6
+ * says so. */ export declare let HOSTNAME: string;
7
+ /** The header a request names the graph file it means in: a server serving
8
+ * another answers it 421 and runs nothing (./tools.ts), so a command whose
9
+ * config shares a port with another graph's never reaches that graph. */ export declare let DB: string;
10
+ /** The header a request asks for a tool's answer drawn as text in, as the
11
+ * server's own views draw it (@yaks/mcp `Options.text`): what a command not
12
+ * writing to a terminal prints, sent so the command loads no views. A server
13
+ * that drew it says the header back; one that did not answers as it does
14
+ * every client. */ export declare let TEXT: string;
15
+ /** Where a client on this machine reaches the server a config serves: its
16
+ * port, else {@link PORT}, at its hostname, or this machine's own address
17
+ * where it names none or every interface.
18
+ *
19
+ * ```ts
20
+ * import { assertEquals } from '@std/assert'
21
+ * import { served } from '@yaks/api/address'
22
+ *
23
+ * assertEquals(served({}), 'http://127.0.0.1:8787')
24
+ * assertEquals(
25
+ * served({ port: 5173, hostname: '0.0.0.0' }),
26
+ * 'http://127.0.0.1:5173',
27
+ * )
28
+ * ```
29
+ */ export declare let served: (config: {
30
+ port?: number;
31
+ hostname?: string;
32
+ }) => string;
33
+ //# sourceMappingURL=address.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"address.d.ts","sources":["../address.ts"],"names":[],"mappings":"AAKA;QACQ,GACR,OAAO,YAAI,aAAW;AAEtB;;;YAGY,GACZ,OAAO,YAAI,iBAAsB;AAEjC;;uEAEuE,GACvE,OAAO,YAAI,WAAe;AAE1B;;;;iBAIiB,GACjB,OAAO,YAAI,aAAmB;AAE9B;;;;;;;;;;;;;;CAcC,GACD,OAAO,YAAI,SACT;EAAU,OAAO,MAAM;EAAE,WAAW,MAAM;MACzC,MAAM,CAIR"}
@@ -0,0 +1,15 @@
1
+ /** The text of the file at `url`.
2
+ *
3
+ * ```ts
4
+ * import { assert } from '@std/assert'
5
+ * assert((await text(new URL('./asset.ts', import.meta.url))).includes('raw-imports'))
6
+ * ```
7
+ */ export declare let text: (url: URL) => Promise<string>;
8
+ /** The bytes of the file at `url`.
9
+ *
10
+ * ```ts
11
+ * import { assertEquals } from '@std/assert'
12
+ * assertEquals((await bytes(new URL('data:,yak'))).length, 3)
13
+ * ```
14
+ */ export declare let bytes: (url: URL) => Promise<Uint8Array<ArrayBuffer>>;
15
+ //# sourceMappingURL=asset.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"asset.d.ts","sources":["../asset.ts"],"names":[],"mappings":"AAiBA;;;;;;CAMC,GACD,OAAO,YAAI,OAAc,KAAK,QAAM,QAAQ,MAAM,EAC0B;AAE5E;;;;;;CAMC,GACD,OAAO,YAAI,QAAe,KAAK,QAAM,QAAQ,WAAW,cAKrD"}
@@ -0,0 +1,4 @@
1
+ import { type Bundle } from "@yaks/graph";
2
+ /** Send a large write a batch at a time, retaining a separate receipt for
3
+ * each batch when the caller supplied a key. */ export declare let applyBatches: (bundles: Bundle[], headers: Record<string, string>, send: (body: string, headers: Record<string, string>) => Promise<Bundle[]>) => Promise<Bundle[]>;
4
+ //# sourceMappingURL=batches.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"batches.d.ts","sources":["../batches.ts"],"names":[],"mappings":"AAAA,SAAS,KAAK,MAAM,2BAAwC;AA+D5D;8CAC8C,GAC9C,OAAO,YAAI,eACT,SAAS,UACT,SAAS,OAAO,MAAM,EAAE,MAAM,GAC9B,OAAO,MAAM,MAAM,EAAE,SAAS,OAAO,MAAM,EAAE,MAAM,MAAM,QAAQ,cAChE,QAAQ,UA0BV"}
@@ -0,0 +1,7 @@
1
+ import { Refused } from "@yaks/graph/errors";
2
+ /** Receive the complete body, refusing an upload its client interrupted. */ export declare let readBody: (request: Request) => Promise<string>;
3
+ /** Whether a request carries a newline-delimited bulk import. */ export declare let poured: (request: Request) => boolean;
4
+ /** A write whose input needs the streaming wire or a smaller batch. */ export declare let writeSize: () => Refused;
5
+ /** Read one atomic JSON or binary batch, rejecting before buffering it whole
6
+ * if it exceeds the limit. */ export declare let writeBytes: (request: Request) => Promise<Uint8Array<ArrayBuffer>>;
7
+ //# sourceMappingURL=body.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"body.d.ts","sources":["../body.ts"],"names":[],"mappings":"AAEA,SAAS,OAAO,kCAAuC;AAqBvD,0EAA0E,GAC1E,OAAO,YAAI,WAAY,SAAS,YAAU,QAAQ,MAAM,EACZ;AAK5C,+DAA+D,GAC/D,OAAO,YAAI,SAAU,SAAS,YAAU,OAAO,CAC+B;AAE9E,qEAAqE,GACrE,OAAO,YAAI,iBAAgB,QAGxB;AAwBH;4BAC4B,GAC5B,OAAO,YAAI,aACT,SAAS,YACR,QAAQ,WAAW,cAerB"}
@@ -0,0 +1,38 @@
1
+ import type { Upgrade } from "./socket.js";
2
+ /**
3
+ * Deno's WebSocket upgrade, as an {@link Upgrade}. The default for `/ws`; on
4
+ * any other runtime it throws, and the application passes its own.
5
+ *
6
+ * ```ts ignore
7
+ * Deno.serve(api({ graph, upgrade: denoUpgrade }))
8
+ * ```
9
+ */ export declare let denoUpgrade: Upgrade;
10
+ /** What a runtime gives back for a port it is now listening on: the promise
11
+ * that settles once it has stopped, and the way to ask it to stop. */ export type Listener = {
12
+ finished: Promise<void>;
13
+ shutdown: () => Promise<void>;
14
+ };
15
+ /** Where a server ended up listening. */ export type Addr = {
16
+ hostname: string;
17
+ port: number;
18
+ };
19
+ /** The transport's peer address, supplied by the listener rather than HTTP headers. */ export type Peer = {
20
+ remoteAddr: Addr;
21
+ };
22
+ /** A request together with the connection it arrived on. */ export type Incoming = (request: Request, peer: Peer) => Response | Promise<Response>;
23
+ /** How this package asks a runtime to listen on a port. `reusePort` lets
24
+ * another server that asks the same way listen on it too (SO_REUSEPORT, Linux
25
+ * only; Deno needs `--unstable-net`), so a replacement can start answering
26
+ * before the server it replaces stops. */ export type Listen = (opts: {
27
+ port: number;
28
+ hostname?: string;
29
+ reusePort?: boolean;
30
+ onListen?: (addr: Addr) => void;
31
+ }, handler: Incoming) => Listener;
32
+ /**
33
+ * Deno's own server, as a {@link Listen} — what the `serve` tool binds a port
34
+ * with (./tools.ts). A runtime that binds its own port, such as a Cloudflare
35
+ * Worker, has no `Deno.serve` and nothing for that tool to do, so this throws
36
+ * there rather than pretending to listen.
37
+ */ export declare let denoListen: Listen;
38
+ //# sourceMappingURL=deno.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"deno.d.ts","sources":["../deno.ts"],"names":[],"mappings":"AAWA,cAAsB,OAAO,sBAAqB;AA8BlD;;;;;;;CAOC,GACD,OAAO,YAAI,aAAa,QAMvB;AAED;oEACoE,GACpE,YAAY;EACV,UAAU,QAAQ,IAAI;EACtB,gBAAgB,QAAQ,IAAI;;AAG9B,uCAAuC,GACvC,YAAY;EAAS,UAAU,MAAM;EAAE,MAAM,MAAM;;AAEnD,qFAAqF,GACrF,YAAY;EAAS,YAAY;;AAEjC,0DAA0D,GAC1D,YAAY,YACV,SAAS,SACT,MAAM,SACH,WAAW,QAAQ;AAExB;;;wCAGwC,GACxC,YAAY,UACV;EACE,MAAM,MAAM;EACZ,WAAW,MAAM;EACjB,YAAY,OAAO;EACnB,YAAY,MAAM,SAAS,IAAI;GAEjC,SAAS,aACN;AAeL;;;;;CAKC,GACD,OAAO,YAAI,YAAY,OAQtB"}
@@ -0,0 +1,134 @@
1
+ import type { Actor, Bundle, Graph, ReadOpts } from "@yaks/graph";
2
+ import type { Driver } from "@yaks/sql";
3
+ import { type Authenticate } from "./actor.js";
4
+ import { poured } from "./body.js";
5
+ import { type Tags } from "./refuse.js";
6
+ import { type Door, type Mark } from "./receipts.js";
7
+ /** The HTTP write options, checked before a body or stream can commit. */ export declare let writeOptions: (request: Request, extra?: string[]) => {
8
+ check: boolean;
9
+ };
10
+ /** Context the application gives each incoming write before authentication
11
+ * signs it. Streaming imports call it once per chunk, including checks. */ export type WriteContext = (request: Request, bundles: Bundle[]) => Bundle[] | Promise<Bundle[]>;
12
+ /**
13
+ * How many bundles go into one transaction when an import arrives one bundle
14
+ * per line. It is the width the D1 adapter's round-trip limit counts — 50
15
+ * bundles cost the same two round trips as one (packages/d1 `hops_test.ts`) —
16
+ * so a chunk is as wide as the network carries for free.
17
+ */ export declare let CHUNK: number;
18
+ export { poured };
19
+ /**
20
+ * `POST /apply` with `content-type: application/x-ndjson` — one bundle per
21
+ * line, applied in chunks of up to {@link CHUNK} bundles and answered as
22
+ * each chunk commits. Large lines fill a chunk sooner. Blank lines are
23
+ * skipped, and a single line that exceeds the batch size is refused.
24
+ *
25
+ * The response is line for line: a bundle a plugin adds alongside the ones
26
+ * sent (an archetype descriptor, an entity deleted by a cascade) is the
27
+ * graph's own bookkeeping, not a line the importer wrote, and is left out.
28
+ *
29
+ * The status is 200 whatever happens, because the first bundles have already
30
+ * been written to the response before a later line can be refused. So a
31
+ * refusal is the last line of the body instead — what `apply()` threw, plus
32
+ * two numbers:
33
+ *
34
+ * ```json
35
+ * {"error":"Refused","message":"unknown property:
36
+ * book.colour","line":137,"committed":100}
37
+ * ```
38
+ *
39
+ * `line` is the 1-based line the offending bundle was on, and `committed` how
40
+ * many bundles were written before it. Nothing after that line is read.
41
+ * (Under `?check=1` every chunk is rolled back, so `committed` counts what
42
+ * would have been written.)
43
+ *
44
+ * **An alias resolves within its own chunk and nowhere else.** A bundle
45
+ * naming `$x` and the bundle minting it have to fall in the same run of
46
+ * {@link CHUNK} lines and the same byte window.
47
+ */ export declare let pour: (graph: Graph, request: Request, who: Actor | null, activity?: object, context?: WriteContext, opts?: ReadOpts, params?: string[], tags?: Tags) => Response;
48
+ /** A request its host trusts, such as the platform's own bookkeeping: who it
49
+ * writes as, and the graph it writes through, which admits the server-owned
50
+ * properties and stands the caller's guards down. Only a trusted write may
51
+ * keep the last write's provenance (`?stamp=0`). */ export type Trusted = {
52
+ graph: Graph;
53
+ actor: Actor | null;
54
+ };
55
+ /** What an apply door is built of: the graph a caller writes and how they
56
+ * read it, and what its host decides around a commit, given as data. Each is
57
+ * read as a request needs it, so a host whose graph is built again with each
58
+ * incarnation lends one door for all of them. */ export type Applying = {
59
+ /** the graph a caller writes */ graph: Graph;
60
+ /** Runtime activity stays keyed by the composed graph, not a read overlay. */ activity?: object;
61
+ /** who is writing (default: nobody) */ authenticate?: Authenticate;
62
+ /** The caller's view of the graph, which a write's answer is read in. A
63
+ * `person` here outranks the one `authenticate` names. */ read?: (request: Request) => ReadOpts | undefined | Promise<ReadOpts | undefined>;
64
+ /** Caller write context, applied to JSON batches and every import chunk. */ write?: WriteContext;
65
+ /** Additional apply query parameters interpreted by this host. */ writeParams?: string[];
66
+ /** Which requests the host trusts, and how ({@link Trusted}); `undefined`
67
+ * for every other, which `authenticate` signs. */ trust?: (request: Request) => Trusted | undefined;
68
+ /** Today's authority to write, which throws for a caller who may not: asked
69
+ * of a durable outbox write before a kept answer is told without the graph
70
+ * deciding again (default: `authenticate`). A trusted request holds it. */ authorize?: (request: Request) => unknown;
71
+ /** The host's door over its write log (./receipts.ts `door`), which keeps
72
+ * its receipts with the input it could not commit yet. */ log?: Pick<Door, 'bound' | 'applying'>;
73
+ /** The host's write log, for a door with no door over it: SQL on the
74
+ * graph's own connection, where a keyed write's receipt is inserted in the
75
+ * transaction that commits it (./receipts.ts `received`). Composed graphs
76
+ * register their log through the API graph facet, so their doors omit this. */ db?: Driver;
77
+ /** The identity that owns a keyed write in this door's log. Defaults to
78
+ * the authenticated writer. A door can keep receipts across changes in
79
+ * the instrument that signs those writes. */ receiptActor?: Actor;
80
+ /** What the host adds to each failure this door reports (./refuse.ts
81
+ * `Tags`, `faults`), such as which of its stores it is: read as one is. */ tags?: () => Tags;
82
+ };
83
+ /** A host's apply door ({@link applier}). */ export type Applier = {
84
+ /** `POST /apply`: a batch in, as applied out, in the caller's view, or as
85
+ * the log keeps it when `mark` names the write to the log. It never throws:
86
+ * a refusal is answered at its status, and a constraint the batch broke is
87
+ * its refusal. */ apply: (request: Request, mark?: Mark) => Promise<Response>;
88
+ /** Today's authority to write ({@link Applying} `authorize`). */ authorize: (request: Request) => Promise<void>;
89
+ /** A canonical answer as its caller sees it: a kept write's, told again. */ answer: (request: Request, response: Response) => Promise<Response>;
90
+ };
91
+ /**
92
+ * `POST /apply` — a JSON array of bundles in, that array as applied out. The
93
+ * response body is the array `apply()` returned, including server-written
94
+ * stamps and any entity a cascading delete took with it.
95
+ *
96
+ * `?check=1` asks only whether the array would be accepted: every phase runs
97
+ * and the transaction is rolled back, so nothing is written and no effect
98
+ * observes it, while a refusal is still a refusal. That is what lets one batch be spread over several graphs — ask them all, then commit.
99
+ *
100
+ * A binary envelope is decoded in the graph's words, whether it came as sent
101
+ * or as a write log keeps it (./log.ts `taken`). `content-type:
102
+ * application/x-ndjson` is the same endpoint for an import too big to hold in
103
+ * memory — see {@link pour}.
104
+ *
105
+ * ```ts
106
+ * import { equal } from '@yaks/testing'
107
+ * import { graph } from '@yaks/graph'
108
+ * import { ram } from '@yaks/ram'
109
+ * import { loadVocab } from '@yaks/vocab'
110
+ * import { applier } from './doors.ts'
111
+ * let vocab = loadVocab({ $defs: { doc: { component: true, type: 'object',
112
+ * properties: { title: { type: 'string' } } } } })
113
+ * let g = graph({ vocab, storage: ram(vocab) })
114
+ * let door = applier({ graph: g })
115
+ * let sent = (body: unknown) => new Request('http://g/apply', {
116
+ * method: 'POST', body: JSON.stringify(body),
117
+ * })
118
+ * let r = await door.apply(sent([{ entity: { eid: 'a' }, doc: { title: 'A' } }]))
119
+ * equal(r.status, 200)
120
+ * equal((await door.apply(sent({}))).status, 400)
121
+ * ```
122
+ */ export declare let applier: (o: Applying) => Applier;
123
+ /** Shape a query's published bundles before writing them to the wire. */ export type ListQuery = (rows: Bundle[], request: Request) => Bundle[] | Promise<Bundle[]>;
124
+ /**
125
+ * `GET /query?q=…` or `POST /query` — a query string in, the bundles it
126
+ * selects out.
127
+ *
128
+ * Unless the query asks for a reduction. `.count`, `.distinct=prop` and
129
+ * `.tally=prop` are questions about the selection rather than about its
130
+ * members, and the store answers each with one SQL statement (`rows()` rather
131
+ * than `read()`); the response body is then `{"count":n}`, `{"distinct":[…]}`
132
+ * or `{"tally":{…}}`.
133
+ */ export declare let ask: (graph: Graph, request: Request, activity?: object, opts?: ReadOpts, list?: ListQuery) => Promise<Response>;
134
+ //# sourceMappingURL=doors.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"doors.d.ts","sources":["../doors.ts"],"names":[],"mappings":"AAYA,cAAc,KAAK,EAAa,MAAM,EAAE,KAAK,EAAE,QAAQ,2BAAgC;AAEvF,cAAc,MAAM,yBAA8B;AAIlD,SAAS,KAAK,YAAY,qBAA4B;AACtD,SAAqB,MAAM,oBAAqD;AAChF,SAAuC,KAAK,IAAI,sBAAqB;AAUrE,SAAS,KAAK,IAAI,EAAE,KAAK,IAAI,wBAAiC;AAI9D,wEAAwE,GACxE,OAAO,YAAI,eACT,SAAS,SACT,QAAO,MAAM;EACV,OAAO,OAAO;EAIlB;AAED;yEACyE,GACzE,YAAY,gBACV,SAAS,SACT,SAAS,aACN,WAAW,QAAQ;AAExB;;;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O,UACP,OAAO,cACN,QAAQ,UA0BV"}
@@ -0,0 +1,17 @@
1
+ import type { Plugin } from "@yaks/graph";
2
+ import type { Driver } from "@yaks/sql";
3
+ import { type Authenticate } from "./actor.js";
4
+ /** What this facet reads off its host: the statements of the store's own
5
+ * connection, where it has SQL, which its write log is kept over. */ export type Hosting = {
6
+ storage: {
7
+ statements?: Driver;
8
+ };
9
+ };
10
+ /** A keyed write's receipt, inserted in the transaction that commits it, on
11
+ * a host with SQL; a host with none refuses a keyed write at the door. */ export declare let plugins: (host: Hosting) => Plugin[];
12
+ /** A host whose options name `who`, another graph's base URL, asks that
13
+ * graph's door who a request is from (./actor.ts `asking`); one naming none
14
+ * leaves the question to another plugin. */ export declare let authenticate: (_host: unknown, options: {
15
+ who?: string;
16
+ }) => Authenticate | undefined;
17
+ //# sourceMappingURL=graph.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"graph.d.ts","sources":["../graph.ts"],"names":[],"mappings":"AAEA,cAAc,MAAM,2BAAgC;AACpD,cAAc,MAAM,yBAA8B;AAClD,SAAiB,KAAK,YAAY,qBAAoB;AAGtD;mEACmE,GACnE,YAAY;EAAY;IAAW,aAAa;;;AAEhD;wEACwE,GACxE,OAAO,YAAI,UAAW,MAAM,YAAU,SAC8B;AAEpE;;0CAE0C,GAC1C,OAAO,YAAI,eACT,OAAO,OAAO,EACd;EAAW,MAAM,MAAM;MACtB,eAAe,SAAS,CAAiD"}
@@ -0,0 +1,5 @@
1
+ /** The header a caller names one write by, across its sends. */ export declare let IDEMPOTENCY: string;
2
+ /** Prefix for a durable write owned by the page's person across web processes.
3
+ * Older keys keep their original receipt namespace. */ export declare let PERSON_OUTBOX: string;
4
+ /** The header a door adds to a failure already reported at its source. */ export declare let FILED: string;
5
+ //# sourceMappingURL=headers.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"headers.d.ts","sources":["../headers.ts"],"names":[],"mappings":"AAAA,8DAA8D,GAC9D,OAAO,YAAI,aAAa,MAAM,CAAoB;AAElD;qDACqD,GACrD,OAAO,YAAI,sBAAgC;AAE3C,wEAAwE,GACxE,OAAO,YAAI,OAAO,MAAM,CAAgB"}
package/_dist/log.d.ts ADDED
@@ -0,0 +1,253 @@
1
+ /**
2
+ * The write log: a host's keyed writes and their receipts, and the input it
3
+ * could not commit yet, kept in plain SQLite tables beside its graph.
4
+ *
5
+ * - A live keyed request commits its mutation and receipt in one graph
6
+ * transaction ({@link landing}). Successful input needs no earlier pending
7
+ * or running row: the caller holds it until acknowledged, and a resend after
8
+ * a reset either finds the exact committed answer or applies an uncommitted
9
+ * mutation.
10
+ * - Input that cannot commit is kept with its headers and body, so a host that
11
+ * is stopped (its row ceiling's window), cannot start, or cannot apply it
12
+ * recovers without asking the caller to send it again. Pending writes replay
13
+ * oldest first, one replay at a time (`./receipts.ts` `door`), each live
14
+ * caller answered as its write lands. Failed writes wait for another incarnation;
15
+ * interrupted and legacy unreviewed attempts need explicit review. Reviewed
16
+ * retries keep their input and complete outcome forever.
17
+ * - Every keyed write is kept under its writer's name for its key
18
+ * ({@link receiptKey}), whichever door it came in at. Ordinary receipts
19
+ * expire after the resend window; browser outbox receipts and held input
20
+ * never expire.
21
+ *
22
+ * The tables belong to no vocabulary or app migration. Their place beside
23
+ * the graph makes the receipt and the mutation atomic even when the graph
24
+ * above storage cannot stand. A Store keeps its batches here, a space's
25
+ * Builder the lines a person said while it could not answer them, and every
26
+ * door of @yaks/api its keyed writes' receipts (`./receipts.ts` `received`).
27
+ *
28
+ * ```ts
29
+ * import { equal } from '@yaks/testing'
30
+ * import { open } from '@yaks/sqlite/db'
31
+ * import { done, keep, next, raise, replayed } from './log.ts'
32
+ * let db = open(':memory:')
33
+ * raise(db)
34
+ * let sent = new Request('http://store/apply', { method: 'POST', body: '[]' })
35
+ * let seq = keep(db, sent, '[]')
36
+ * equal([next(db)?.seq, await replayed(next(db)!).text()], [seq, '[]'])
37
+ * done(db, seq)
38
+ * equal(next(db), null)
39
+ * ```
40
+ *
41
+ * @module
42
+ */ import { type Actor, type Bundle } from "@yaks/graph";
43
+ import { type CreateTable, type Driver, type Stmt } from "@yaks/sql";
44
+ import type { Vocab } from "@yaks/vocab";
45
+ import { IDEMPOTENCY } from "./headers.js";
46
+ export { IDEMPOTENCY };
47
+ /** Whether headers say their body is a binary envelope. */ export declare let binaryHeaders: (headers: Headers) => boolean;
48
+ /** A write's body as the log keeps it, and its bundles as it says them before
49
+ * any decoding, which is what a secret is looked for in. A JSON body is its
50
+ * text, both times; a binary one is its envelope in base64, and the
51
+ * envelope's header with its references. An envelope that can't be read is
52
+ * refused here, while its caller still holds it.
53
+ *
54
+ * ```ts
55
+ * import { equal } from '@yaks/testing'
56
+ * import { binary, BINARY } from '@yaks/vocab/wire'
57
+ * import { opened, taken } from './log.ts'
58
+ * let raw = binary([{ entity: { eid: 'a' }, photo: { bytes: Uint8Array.of(7) } }])
59
+ * let sent = (body: BodyInit, type = BINARY) =>
60
+ * new Request('http://store/apply', { method: 'POST', headers: { 'content-type': type }, body })
61
+ * let { body, told } = await taken(sent(raw))
62
+ * equal(told, '[{"entity":{"eid":"a"},"photo":{"bytes":{"$bytes":0,"length":1}}}]')
63
+ * equal(opened(new Headers({ 'content-type': BINARY }), body), raw)
64
+ * equal(await taken(sent('[]', 'application/json')), { body: '[]', told: '[]' })
65
+ * equal(opened(new Headers(), '[]'), '[]')
66
+ * ```
67
+ */ export declare let taken: (request: Request) => Promise<{
68
+ body: string;
69
+ told: string;
70
+ }>;
71
+ /** A kept body as it was sent: the envelope of a binary one (`taken`), the
72
+ * text of any other. */ export declare let opened: (headers: Headers, body: string) => string | Uint8Array<ArrayBuffer>;
73
+ /** What a kept body says once its words are known: a binary one's envelope
74
+ * decoded in them, as a JSON one's base64 values are. Only declared binary
75
+ * properties interpret payload references.
76
+ *
77
+ * ```ts
78
+ * import { equal } from '@yaks/testing'
79
+ * import { loadVocab } from '@yaks/vocab'
80
+ * import { binary, BINARY } from '@yaks/vocab/wire'
81
+ * import { decoded, taken } from './log.ts'
82
+ * let vocab = loadVocab({ $defs: { photo: { component: true, type: 'object',
83
+ * properties: { bytes: { type: 'string', contentEncoding: 'base64' } } } } })
84
+ * let bundle = { entity: { eid: 'a' }, photo: { bytes: Uint8Array.of(7) } }
85
+ * let { body } = await taken(new Request('http://store/apply', {
86
+ * method: 'POST', headers: { 'content-type': BINARY }, body: binary([bundle]),
87
+ * }))
88
+ * equal(decoded(vocab, new Headers({ 'content-type': BINARY }), body), [bundle])
89
+ * equal(decoded(vocab, new Headers(), '[{"photo":{"bytes":{"$bytes":"Bw==","encoding":"base64"}}}]'),
90
+ * [{ photo: { bytes: Uint8Array.of(7) } }])
91
+ * ```
92
+ */ export declare let decoded: (vocab: Pick<Vocab, 'def'>, headers: Headers, body: string) => unknown;
93
+ export declare let WRITES: CreateTable;
94
+ /** The empty write log and its indexes, shared with prepared test stores. */ export declare let schema: () => Stmt[];
95
+ /** The log, raised, with every column it predates added: an object keeps its
96
+ * log across code versions, and whichever code wakes it next reads it. */ export declare let raise: (db: Driver) => void;
97
+ /** Browser outbox intents need the same answer even after hours offline. */ export declare let durable: (key: string | null) => boolean;
98
+ export declare let started: (db: Driver, seq: number) => void;
99
+ /** A started write its store stopped before it could apply it
100
+ * (`./receipts.ts` `replays`): waiting again, its try not counted, so the
101
+ * replay after the wait takes it as it was. Its transaction unwound, so
102
+ * nothing of it landed. Without `seq`, every write a reset cut off, for a
103
+ * host that hears a write only in the transaction that lands it, so a reset
104
+ * left nothing of one it started (a Builder's line). */ export declare let unstarted: (db: Driver, seq?: number) => void;
105
+ export declare let interrupted: (db: Driver) => {
106
+ running: number;
107
+ unreviewed: number;
108
+ };
109
+ /** Kept writes, with the body only when one is named for inspection. */ export declare let writes: (db: Driver, seq?: number, recent?: boolean) => Record<string, unknown>[];
110
+ /** Explicitly retry an interrupted or unreviewed write, keeping its body and
111
+ * key, and keeping its final answer beside them when it commits. */ export declare let retry: (db: Driver, seq: number) => boolean;
112
+ /** One kept write. */ export type Kept = {
113
+ seq: number;
114
+ headers: string;
115
+ body: string;
116
+ };
117
+ /** A write still held for review, without changing its state. */ export declare let kept: (db: Driver, seq: number) => Kept | undefined;
118
+ /** Whether a request is a write the log keeps: a batch to apply. A dry run
119
+ * (`?check=1`) writes nothing. */ export declare let logged: (req: Request) => boolean;
120
+ export declare let ROOM: number;
121
+ /** Whether a body fits in the log. */ export declare let fits: (body: string) => boolean;
122
+ /** Keep one write that cannot commit now; its place in the replay log. */ export declare let keep: (db: Driver, req: Request, body: string, now?: () => number) => number;
123
+ export declare let INTENT: string;
124
+ export declare let fingerprinted: (request: Request, body: string) => Request;
125
+ /**
126
+ * The key the log keeps a write under: its writer's and its sender's key as
127
+ * one name, so one writer's key never reads another's receipt. An outbox
128
+ * key's name is an outbox key too, kept for good ({@link durable}); any
129
+ * other expires after the resend window.
130
+ *
131
+ * ```ts
132
+ * import { equal } from '@yaks/testing'
133
+ * import { durable, receiptKey } from './log.ts'
134
+ * let ada = { by: 'ada' }
135
+ * equal(receiptKey(ada, 'k') == receiptKey({ by: 'bob' }, 'k'), false)
136
+ * equal(receiptKey(ada, 'k') == receiptKey(ada, 'k'), true)
137
+ * equal([durable(receiptKey(ada, 'outbox:k')), durable(receiptKey(ada, 'k'))],
138
+ * [true, false])
139
+ * ```
140
+ */ export declare let receiptKey: (writer: Actor | null, key: string) => string;
141
+ /** A request with its key named by its writer ({@link receiptKey}), as the
142
+ * log keeps it; one with no key as it is. Its body is taken along unread. */ export declare let owned: (request: Request, writer: Actor | null) => Request;
143
+ /**
144
+ * Every key the log holds as its sender said it, named by its writer
145
+ * ({@link receiptKey}), in its column and in the headers its write is
146
+ * replayed with: a log kept by code that took a key as it came. `writer` says
147
+ * who sent each, from its request's headers. How many it named; a log named
148
+ * already costs one look at the key's index.
149
+ *
150
+ * ```ts
151
+ * import { equal } from '@yaks/testing'
152
+ * import { open } from '@yaks/sqlite/db'
153
+ * import { first, keep, raise, receiptKey, rekey } from './log.ts'
154
+ * let db = open(':memory:')
155
+ * raise(db)
156
+ * let sent = new Request('http://store/apply', {
157
+ * method: 'POST', headers: { 'idempotency-key': 'k', 'x-by': 'ada' },
158
+ * })
159
+ * keep(db, sent, '[]')
160
+ * let writer = (r: Request) => ({ by: r.headers.get('x-by')! })
161
+ * equal([rekey(db, writer), rekey(db, writer)], [1, 0])
162
+ * equal(first(db, receiptKey({ by: 'ada' }, 'k'))?.seq, 1)
163
+ * ```
164
+ */ export declare let rekey: (db: Driver, writer: (request: Request) => Actor | null) => number;
165
+ /** The request a door that names its writes itself keeps a receipt under
166
+ * (`./receipts.ts` `received`): its `key` for the write ({@link
167
+ * receiptKey}), bound to the body `digest` names. */ export declare let named: (key: string, digest: string) => Request;
168
+ /** A write the log already holds under an idempotency key. */ export type Sent = {
169
+ seq: number;
170
+ state: string;
171
+ why: string;
172
+ answer: string;
173
+ audit: boolean;
174
+ };
175
+ /** The write a key was first sent with, if the log holds it. */ export declare let first: (db: Driver, key: string, request?: Request) => Sent | null;
176
+ /** Cached acceptance after the caller has checked current write authority.
177
+ * Durable requests must have been fingerprinted from their body at the door. */ export declare let remembered: (db: Driver, key: string, request: Request) => Response | null;
178
+ /** A successful live request has no earlier log row. The graph commit hook
179
+ * inserts its receipt in the same transaction as the mutation. With no receipt
180
+ * there is no committed mutation; the caller still holds its unacknowledged
181
+ * input and may resend after a reset. */ export type Receipt = {
182
+ request: Request;
183
+ };
184
+ export declare let received: (db: Driver, receipt: Receipt, answer: () => Bundle[], now?: () => number) => void;
185
+ type RetainedWrite = {
186
+ seq: number;
187
+ state: string;
188
+ body: string;
189
+ binary: boolean;
190
+ answer: string | null;
191
+ chunked: boolean;
192
+ };
193
+ /** Walk the persisted input and outcome of writes without replaying them. */ export declare let retainedWrites: (db: Driver, after: number, limit: number) => RetainedWrite[];
194
+ /** Rewrite an unchanged receipt inside the caller's transaction. */ export declare let rewriteWrite: (db: Driver, was: RetainedWrite, body: string, answer: string | null) => boolean;
195
+ /** A committed write, in its batch's own transaction: out of the log, or,
196
+ * sent with a key, kept as `applied` with its answer for a resend to be told.
197
+ * The hook receives phase patches; compose them here to keep exactly what
198
+ * `apply()` returns after the transaction. An audited retry keeps its original
199
+ * body and full answer in chunks. Ordinary large answers use chunks too,
200
+ * so every resend receives the complete canonical answer. */ export declare let landed: (db: Driver, seq: number, answer: () => Bundle[], now?: () => number) => void;
201
+ /** The oldest write still waiting after `seq`. A replay walks the log forward
202
+ * from one to the next, so it tries no write twice. */ export declare let next: (db: Driver, seq?: number) => Kept | null;
203
+ /** Whether any write is waiting. */ export declare let waiting: (db: Driver) => boolean;
204
+ /** Whether a new incarnation must settle writes before serving a read. */ export declare let recovering: (db: Driver) => boolean;
205
+ /** The write is answered: it leaves the log, unless it is kept as `applied`
206
+ * for a resend (`landed`). */ export declare let done: (db: Driver, seq: number) => void;
207
+ /** A write that failed on a store that started: set aside with why, so the
208
+ * writes behind it go on. */ export declare let aside: (db: Driver, seq: number, why: string) => void;
209
+ /** Every write set aside, waiting again: a new incarnation may be new code. */ export declare let revived: (db: Driver) => void;
210
+ /** A replay the store refused: kept, with why, and never replayed again. */ export declare let dead: (db: Driver, seq: number, why: string) => void;
211
+ /** The request a kept write was, to send `at` its door again (a Store's
212
+ * `/apply` unless said): a binary one's envelope as it came, which its
213
+ * apply door decodes ({@link decoded}). */ export declare let replayed: (k: Kept, at?: string) => Request;
214
+ /** A constraint the batch broke — a unique name already taken, a required
215
+ * column left empty — is the batch's own refusal, not the store failing, and
216
+ * SQLite says which in its message. Left a 500, such a write would wait in
217
+ * the log for code that can never apply it, and hold up every write behind
218
+ * it. */ export declare let constrained: (e: unknown) => unknown;
219
+ /** What an answer said, in its own words. */ export declare let said: (r: Response) => Promise<string>;
220
+ /** Whether a write is still in the log, waiting or set aside. */ export declare let held: (db: Driver, seq: number) => boolean;
221
+ /** Every write still in the log, oldest first: waiting, under way or set
222
+ * aside, and how many times each was tried. What a host that keeps a
223
+ * person's own words shows them of those words (a Builder's kept lines).
224
+ * One read a state, each on its own index: a log also keeps receipts, and
225
+ * an outbox's for good.
226
+ *
227
+ * ```ts
228
+ * import { equal } from '@yaks/testing'
229
+ * import { open } from '@yaks/sqlite/db'
230
+ * import { aside, keep, raise, started, unanswered } from './log.ts'
231
+ * let db = open(':memory:')
232
+ * raise(db)
233
+ * let sent = new Request('http://builder/say', { method: 'POST' })
234
+ * let one = keep(db, sent, 'one'), two = keep(db, sent, 'two')
235
+ * started(db, one)
236
+ * aside(db, one, 'unreachable')
237
+ * equal(unanswered(db).map((k) => [k.seq, k.body, k.tries]), [[one, 'one', 1], [two, 'two', 0]])
238
+ * ```
239
+ */ export declare let unanswered: (db: Driver) => (Kept & {
240
+ tries: number;
241
+ })[];
242
+ /** A kept write, as the door that sent it hears it (meta.ts): not applied
243
+ * yet, and not lost. The failure that held it back was reported where it
244
+ * happened, so this is not a defect of its own (defects.ts `refused`). A
245
+ * store that kept it while stopped says how long until it lands
246
+ * (`retry.after`, in ms), which a door passes on as `retry-after`. */ export declare class Pending extends Error {
247
+ retry?: {
248
+ after: number;
249
+ };
250
+ constructor(message: string, after?: number);
251
+ }
252
+ /** What a caller is told when its write is kept but not yet applied. */ export declare let parked: (seq: number, why: string, review?: boolean) => Response;
253
+ //# sourceMappingURL=log.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"log.d.ts","sources":["../log.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAyCC,GACD,SAAS,KAAK,KAAK,EAAE,KAAK,MAAM,2BAA+C;AAK/E,SAKE,KAAK,WAAW,EAEhB,KAAK,MAAM,EAYX,KAAK,IAAI,yBAGkB;AAC7B,cAAc,KAAK,2BAAgC;AAGnD,SAAS,WAAW,uBAAsB;AAE1C,SAAS,WAAW,GAAE;AAQtB,yDAAyD,GACzD,OAAO,YAAI,gBAAiB,SAAS,YAAU,OAAO,CACO;AAE7D;;;;;;;;;;;;;;;;;;;CAmBC,GACD,OAAO,YAA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