@opendatalabs/personal-server-ts-core 1.40.0 → 1.41.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.
Files changed (92) hide show
  1. package/dist/api/index.d.ts +7 -1
  2. package/dist/api/index.d.ts.map +1 -1
  3. package/dist/api/index.js +32 -12
  4. package/dist/api/index.js.map +1 -1
  5. package/dist/legacy-projection/index.d.ts +9 -0
  6. package/dist/legacy-projection/index.d.ts.map +1 -1
  7. package/dist/legacy-projection/index.js +4 -0
  8. package/dist/legacy-projection/index.js.map +1 -1
  9. package/dist/localdb/alias-projection.d.ts +107 -0
  10. package/dist/localdb/alias-projection.d.ts.map +1 -0
  11. package/dist/localdb/alias-projection.js +416 -0
  12. package/dist/localdb/alias-projection.js.map +1 -0
  13. package/dist/localdb/alias-sized.d.ts +36 -0
  14. package/dist/localdb/alias-sized.d.ts.map +1 -0
  15. package/dist/localdb/alias-sized.js +60 -0
  16. package/dist/localdb/alias-sized.js.map +1 -0
  17. package/dist/localdb/alias-view.d.ts +36 -0
  18. package/dist/localdb/alias-view.d.ts.map +1 -0
  19. package/dist/localdb/alias-view.js +72 -0
  20. package/dist/localdb/alias-view.js.map +1 -0
  21. package/dist/localdb/alias-window.d.ts +100 -0
  22. package/dist/localdb/alias-window.d.ts.map +1 -0
  23. package/dist/localdb/alias-window.js +286 -0
  24. package/dist/localdb/alias-window.js.map +1 -0
  25. package/dist/localdb/delete.d.ts +13 -3
  26. package/dist/localdb/delete.d.ts.map +1 -1
  27. package/dist/localdb/delete.js +23 -9
  28. package/dist/localdb/delete.js.map +1 -1
  29. package/dist/localdb/index.d.ts +2 -1
  30. package/dist/localdb/index.d.ts.map +1 -1
  31. package/dist/localdb/index.js +1 -0
  32. package/dist/localdb/index.js.map +1 -1
  33. package/dist/localdb/legacy-import.js +6 -1
  34. package/dist/localdb/legacy-import.js.map +1 -1
  35. package/dist/localdb/listing.d.ts +6 -0
  36. package/dist/localdb/listing.d.ts.map +1 -1
  37. package/dist/localdb/listing.js +24 -4
  38. package/dist/localdb/listing.js.map +1 -1
  39. package/dist/localdb/log-batch.d.ts +7 -0
  40. package/dist/localdb/log-batch.d.ts.map +1 -1
  41. package/dist/localdb/log-batch.js +12 -2
  42. package/dist/localdb/log-batch.js.map +1 -1
  43. package/dist/localdb/log-erase.d.ts +7 -11
  44. package/dist/localdb/log-erase.d.ts.map +1 -1
  45. package/dist/localdb/log-erase.js +20 -6
  46. package/dist/localdb/log-erase.js.map +1 -1
  47. package/dist/localdb/log-publish.d.ts.map +1 -1
  48. package/dist/localdb/log-publish.js +2 -2
  49. package/dist/localdb/log-publish.js.map +1 -1
  50. package/dist/localdb/purge.d.ts +7 -1
  51. package/dist/localdb/purge.d.ts.map +1 -1
  52. package/dist/localdb/purge.js +18 -5
  53. package/dist/localdb/purge.js.map +1 -1
  54. package/dist/localdb/query.d.ts +59 -2
  55. package/dist/localdb/query.d.ts.map +1 -1
  56. package/dist/localdb/query.js +82 -0
  57. package/dist/localdb/query.js.map +1 -1
  58. package/dist/localdb/read-selection.d.ts +1 -22
  59. package/dist/localdb/read-selection.d.ts.map +1 -1
  60. package/dist/localdb/read-selection.js +0 -66
  61. package/dist/localdb/read-selection.js.map +1 -1
  62. package/dist/localdb/resolve.d.ts +66 -4
  63. package/dist/localdb/resolve.d.ts.map +1 -1
  64. package/dist/localdb/resolve.js +234 -173
  65. package/dist/localdb/resolve.js.map +1 -1
  66. package/dist/localdb/sync.d.ts +3 -1
  67. package/dist/localdb/sync.d.ts.map +1 -1
  68. package/dist/localdb/sync.js +13 -3
  69. package/dist/localdb/sync.js.map +1 -1
  70. package/dist/localdb/transfer-memory.d.ts +3 -2
  71. package/dist/localdb/transfer-memory.d.ts.map +1 -1
  72. package/dist/localdb/transfer-memory.js +4 -3
  73. package/dist/localdb/transfer-memory.js.map +1 -1
  74. package/dist/stream-sync/send-gate.d.ts +4 -2
  75. package/dist/stream-sync/send-gate.d.ts.map +1 -1
  76. package/dist/stream-sync/send-gate.js +22 -3
  77. package/dist/stream-sync/send-gate.js.map +1 -1
  78. package/dist/stream-sync/storage-retry.d.ts +3 -2
  79. package/dist/stream-sync/storage-retry.d.ts.map +1 -1
  80. package/dist/stream-sync/storage-retry.js +2 -2
  81. package/dist/stream-sync/storage-retry.js.map +1 -1
  82. package/dist/stream-sync-read/index.d.ts +1 -1
  83. package/dist/stream-sync-read/index.d.ts.map +1 -1
  84. package/dist/stream-sync-read/service.d.ts +19 -0
  85. package/dist/stream-sync-read/service.d.ts.map +1 -1
  86. package/dist/stream-sync-read/service.js.map +1 -1
  87. package/dist/test-support/memory-oracle.d.ts +5 -0
  88. package/dist/test-support/memory-oracle.d.ts.map +1 -1
  89. package/dist/test-support/memory-oracle.js +140 -0
  90. package/dist/test-support/memory-oracle.js.map +1 -1
  91. package/dist-test/tsconfig.tsbuildinfo +1 -1
  92. package/package.json +2 -2
@@ -0,0 +1,36 @@
1
+ import type { AliasViewCheck } from "./alias-view.js";
2
+ import type { AliasRecordQuery, SizedRecord, StoredRecord } from "./query.js";
3
+ /**
4
+ * Stored bytes of bodies read in one batch when the whole stream is held
5
+ * anyway (its memory reserved as a whole): a parent stream, an other stream or
6
+ * a whole projection. The batch only bounds the statement's result.
7
+ */
8
+ export declare const WHOLE_STREAM_BATCH_BYTES: number;
9
+ /** What a read sized a stream at, and so reserved memory for. */
10
+ export interface StreamLimits {
11
+ readonly rows: number;
12
+ readonly bytes: number;
13
+ readonly maxBytes: number;
14
+ }
15
+ /** A body and the size and hash it was read against. */
16
+ export interface SizedBody {
17
+ readonly record: StoredRecord;
18
+ readonly sized: SizedRecord;
19
+ }
20
+ /**
21
+ * Read every body of a stream, a batch at a time, each batch of at most
22
+ * `batchBytes` sized bytes (one record, if that is larger). Each batch is
23
+ * read by a statement that returns a record only while it still has the hash
24
+ * and size it was sized with, so no batch takes more bytes than its sizes add
25
+ * up to. The whole read stays inside `limits`, the sizes the memory was
26
+ * reserved for.
27
+ *
28
+ * A record that is missing, changed or grown, or a stream that is larger than
29
+ * `limits`, means the rows are not those the read reserved memory for:
30
+ * `PartialViewMoved`, the read to be asked again. Nothing in it depends on the
31
+ * change marks, so it holds whatever the marks say. `signal` ends the read:
32
+ * it is checked before each row and each batch, so a scan nobody waits for
33
+ * stops where it is.
34
+ */
35
+ export declare function sizedBodies(query: AliasRecordQuery, connectionId: string, stream: string, limits: StreamLimits, batchBytes: number, current: AliasViewCheck, signal?: AbortSignal): AsyncGenerator<SizedBody[]>;
36
+ //# sourceMappingURL=alias-sized.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"alias-sized.d.ts","sourceRoot":"","sources":["../../src/localdb/alias-sized.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AAEtD,OAAO,KAAK,EAAE,gBAAgB,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAE9E;;;;GAIG;AACH,eAAO,MAAM,wBAAwB,QAAc,CAAC;AAEpD,iEAAiE;AACjE,MAAM,WAAW,YAAY;IAC3B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;CAC3B;AAED,wDAAwD;AACxD,MAAM,WAAW,SAAS;IACxB,QAAQ,CAAC,MAAM,EAAE,YAAY,CAAC;IAC9B,QAAQ,CAAC,KAAK,EAAE,WAAW,CAAC;CAC7B;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAuB,WAAW,CAChC,KAAK,EAAE,gBAAgB,EACvB,YAAY,EAAE,MAAM,EACpB,MAAM,EAAE,MAAM,EACd,MAAM,EAAE,YAAY,EACpB,UAAU,EAAE,MAAM,EAClB,OAAO,EAAE,cAAc,EACvB,MAAM,CAAC,EAAE,WAAW,GACnB,cAAc,CAAC,SAAS,EAAE,CAAC,CAyC7B"}
@@ -0,0 +1,60 @@
1
+ import { PartialViewMoved } from "./partial-read.js";
2
+ /**
3
+ * Stored bytes of bodies read in one batch when the whole stream is held
4
+ * anyway (its memory reserved as a whole): a parent stream, an other stream or
5
+ * a whole projection. The batch only bounds the statement's result.
6
+ */
7
+ export const WHOLE_STREAM_BATCH_BYTES = 1024 * 1024;
8
+ /**
9
+ * Read every body of a stream, a batch at a time, each batch of at most
10
+ * `batchBytes` sized bytes (one record, if that is larger). Each batch is
11
+ * read by a statement that returns a record only while it still has the hash
12
+ * and size it was sized with, so no batch takes more bytes than its sizes add
13
+ * up to. The whole read stays inside `limits`, the sizes the memory was
14
+ * reserved for.
15
+ *
16
+ * A record that is missing, changed or grown, or a stream that is larger than
17
+ * `limits`, means the rows are not those the read reserved memory for:
18
+ * `PartialViewMoved`, the read to be asked again. Nothing in it depends on the
19
+ * change marks, so it holds whatever the marks say. `signal` ends the read:
20
+ * it is checked before each row and each batch, so a scan nobody waits for
21
+ * stops where it is.
22
+ */
23
+ export async function* sizedBodies(query, connectionId, stream, limits, batchBytes, current, signal) {
24
+ let batch = [];
25
+ let batchSize = 0;
26
+ let rows = 0;
27
+ let bytes = 0;
28
+ const flush = async () => {
29
+ signal?.throwIfAborted();
30
+ const records = await query.recordsByHash(connectionId, stream, batch, current.guard);
31
+ if (records.length !== batch.length)
32
+ throw new PartialViewMoved();
33
+ const sizes = new Map(batch.map((s) => [s.pkHash, s]));
34
+ batch = [];
35
+ batchSize = 0;
36
+ return records.map((record) => ({
37
+ record,
38
+ sized: sizes.get(record.pkHash),
39
+ }));
40
+ };
41
+ for await (const size of query.recordSizes(connectionId, stream)) {
42
+ // A read nobody waits for stops here, not at the end of its scan.
43
+ signal?.throwIfAborted();
44
+ rows += 1;
45
+ bytes += size.bytes;
46
+ if (rows > limits.rows ||
47
+ bytes > limits.bytes ||
48
+ size.bytes > limits.maxBytes) {
49
+ throw new PartialViewMoved();
50
+ }
51
+ if (batch.length > 0 && batchSize + size.bytes > batchBytes) {
52
+ yield await flush();
53
+ }
54
+ batch.push(size);
55
+ batchSize += size.bytes;
56
+ }
57
+ if (batch.length > 0)
58
+ yield await flush();
59
+ }
60
+ //# sourceMappingURL=alias-sized.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"alias-sized.js","sourceRoot":"","sources":["../../src/localdb/alias-sized.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AAGrD;;;;GAIG;AACH,MAAM,CAAC,MAAM,wBAAwB,GAAG,IAAI,GAAG,IAAI,CAAC;AAepD;;;;;;;;;;;;;;GAcG;AACH,MAAM,CAAC,KAAK,SAAS,CAAC,CAAC,WAAW,CAChC,KAAuB,EACvB,YAAoB,EACpB,MAAc,EACd,MAAoB,EACpB,UAAkB,EAClB,OAAuB,EACvB,MAAoB;IAEpB,IAAI,KAAK,GAAkB,EAAE,CAAC;IAC9B,IAAI,SAAS,GAAG,CAAC,CAAC;IAClB,IAAI,IAAI,GAAG,CAAC,CAAC;IACb,IAAI,KAAK,GAAG,CAAC,CAAC;IACd,MAAM,KAAK,GAAG,KAAK,IAA0B,EAAE;QAC7C,MAAM,EAAE,cAAc,EAAE,CAAC;QACzB,MAAM,OAAO,GAAG,MAAM,KAAK,CAAC,aAAa,CACvC,YAAY,EACZ,MAAM,EACN,KAAK,EACL,OAAO,CAAC,KAAK,CACd,CAAC;QACF,IAAI,OAAO,CAAC,MAAM,KAAK,KAAK,CAAC,MAAM;YAAE,MAAM,IAAI,gBAAgB,EAAE,CAAC;QAClE,MAAM,KAAK,GAAG,IAAI,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC;QACvD,KAAK,GAAG,EAAE,CAAC;QACX,SAAS,GAAG,CAAC,CAAC;QACd,OAAO,OAAO,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC;YAC9B,MAAM;YACN,KAAK,EAAE,KAAK,CAAC,GAAG,CAAC,MAAM,CAAC,MAAM,CAAE;SACjC,CAAC,CAAC,CAAC;IACN,CAAC,CAAC;IACF,IAAI,KAAK,EAAE,MAAM,IAAI,IAAI,KAAK,CAAC,WAAW,CAAC,YAAY,EAAE,MAAM,CAAC,EAAE,CAAC;QACjE,kEAAkE;QAClE,MAAM,EAAE,cAAc,EAAE,CAAC;QACzB,IAAI,IAAI,CAAC,CAAC;QACV,KAAK,IAAI,IAAI,CAAC,KAAK,CAAC;QACpB,IACE,IAAI,GAAG,MAAM,CAAC,IAAI;YAClB,KAAK,GAAG,MAAM,CAAC,KAAK;YACpB,IAAI,CAAC,KAAK,GAAG,MAAM,CAAC,QAAQ,EAC5B,CAAC;YACD,MAAM,IAAI,gBAAgB,EAAE,CAAC;QAC/B,CAAC;QACD,IAAI,KAAK,CAAC,MAAM,GAAG,CAAC,IAAI,SAAS,GAAG,IAAI,CAAC,KAAK,GAAG,UAAU,EAAE,CAAC;YAC5D,MAAM,MAAM,KAAK,EAAE,CAAC;QACtB,CAAC;QACD,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QACjB,SAAS,IAAI,IAAI,CAAC,KAAK,CAAC;IAC1B,CAAC;IACD,IAAI,KAAK,CAAC,MAAM,GAAG,CAAC;QAAE,MAAM,MAAM,KAAK,EAAE,CAAC;AAC5C,CAAC"}
@@ -0,0 +1,36 @@
1
+ import type { SqlDriver, SqlReader } from "./driver.js";
2
+ import { type StatementGuard } from "./query.js";
3
+ import type { Connection, Stream } from "./read-selection.js";
4
+ /**
5
+ * The state of a connection's streams a paged alias read is built on. The read
6
+ * pages its rows after its queue turn ends, so it must know that none of them
7
+ * changed since it began: `pinAliasStreams` takes the epochs before the heads
8
+ * are read, and `aliasViewCheck` says whether those heads, the connection and
9
+ * the epochs are still the ones the read was decided on (the rule of
10
+ * `completePage`, over several streams).
11
+ */
12
+ export declare function pinAliasStreams(db: SqlDriver, connectionId: string, streams: readonly string[]): Promise<ReadonlyMap<string, number>>;
13
+ /**
14
+ * The epochs of the streams' change marks, read and nothing written: for a
15
+ * check that must not wait for the database's writer (a scope listing).
16
+ * `pinAliasStreams` also clears a mark's flag, so that any later change moves
17
+ * the epoch. Here a flag that is set stays set, and a change after the read
18
+ * moves the epoch only once another reader has cleared it: the check is exact
19
+ * against the heads and the connection, and best effort against a row that
20
+ * changes under an unchanged head.
21
+ */
22
+ export declare function readAliasEpochs(db: SqlDriver, connectionId: string, streams: readonly string[]): Promise<ReadonlyMap<string, number>>;
23
+ /**
24
+ * True while every installed head, its epoch and the connection are as pinned.
25
+ * `guard` is the same test as a condition of one statement: a read of bodies
26
+ * that carries it returns none once the view has moved, so a body is never
27
+ * read from rows that changed after they were sized.
28
+ */
29
+ export interface AliasViewCheck {
30
+ (): Promise<boolean>;
31
+ readonly guard: StatementGuard;
32
+ }
33
+ export declare function aliasViewCheck(db: SqlReader, connection: Connection, installed: readonly Stream[], epochs: ReadonlyMap<string, number>): AliasViewCheck;
34
+ /** Ends a body whose view moved: the reader sees an aborted read and asks again. */
35
+ export declare function assertViewCurrent(check: AliasViewCheck): Promise<void>;
36
+ //# sourceMappingURL=alias-view.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"alias-view.d.ts","sourceRoot":"","sources":["../../src/localdb/alias-view.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACxD,OAAO,EAAwB,KAAK,cAAc,EAAE,MAAM,YAAY,CAAC;AAGvE,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAE9D;;;;;;;GAOG;AACH,wBAAsB,eAAe,CACnC,EAAE,EAAE,SAAS,EACb,YAAY,EAAE,MAAM,EACpB,OAAO,EAAE,SAAS,MAAM,EAAE,GACzB,OAAO,CAAC,WAAW,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAMtC;AAED;;;;;;;;GAQG;AACH,wBAAsB,eAAe,CACnC,EAAE,EAAE,SAAS,EACb,YAAY,EAAE,MAAM,EACpB,OAAO,EAAE,SAAS,MAAM,EAAE,GACzB,OAAO,CAAC,WAAW,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAMtC;AAED;;;;;GAKG;AACH,MAAM,WAAW,cAAc;IAC7B,IAAI,OAAO,CAAC,OAAO,CAAC,CAAC;IACrB,QAAQ,CAAC,KAAK,EAAE,cAAc,CAAC;CAChC;AAED,wBAAgB,cAAc,CAC5B,EAAE,EAAE,SAAS,EACb,UAAU,EAAE,UAAU,EACtB,SAAS,EAAE,SAAS,MAAM,EAAE,EAC5B,MAAM,EAAE,WAAW,CAAC,MAAM,EAAE,MAAM,CAAC,GAClC,cAAc,CAsChB;AAED,oFAAoF;AACpF,wBAAsB,iBAAiB,CAAC,KAAK,EAAE,cAAc,GAAG,OAAO,CAAC,IAAI,CAAC,CAE5E"}
@@ -0,0 +1,72 @@
1
+ import { MAX_STATEMENT_PARAMS } from "./query.js";
2
+ import { pinStream, readMark } from "./complete-read.js";
3
+ import { PartialViewMoved } from "./partial-read.js";
4
+ /**
5
+ * The state of a connection's streams a paged alias read is built on. The read
6
+ * pages its rows after its queue turn ends, so it must know that none of them
7
+ * changed since it began: `pinAliasStreams` takes the epochs before the heads
8
+ * are read, and `aliasViewCheck` says whether those heads, the connection and
9
+ * the epochs are still the ones the read was decided on (the rule of
10
+ * `completePage`, over several streams).
11
+ */
12
+ export async function pinAliasStreams(db, connectionId, streams) {
13
+ const epochs = new Map();
14
+ for (const stream of streams) {
15
+ epochs.set(stream, await pinStream(db, connectionId, stream));
16
+ }
17
+ return epochs;
18
+ }
19
+ /**
20
+ * The epochs of the streams' change marks, read and nothing written: for a
21
+ * check that must not wait for the database's writer (a scope listing).
22
+ * `pinAliasStreams` also clears a mark's flag, so that any later change moves
23
+ * the epoch. Here a flag that is set stays set, and a change after the read
24
+ * moves the epoch only once another reader has cleared it: the check is exact
25
+ * against the heads and the connection, and best effort against a row that
26
+ * changes under an unchanged head.
27
+ */
28
+ export async function readAliasEpochs(db, connectionId, streams) {
29
+ const epochs = new Map();
30
+ for (const stream of streams) {
31
+ epochs.set(stream, (await readMark(db, connectionId, stream)).epoch);
32
+ }
33
+ return epochs;
34
+ }
35
+ export function aliasViewCheck(db, connection, installed, epochs) {
36
+ const heads = installed.map(() => `EXISTS (SELECT 1 FROM stream_state s WHERE s.connection_id = ? AND s.stream = ?
37
+ AND s.head_version = ? AND s.head_data_hash = ?)
38
+ AND COALESCE((SELECT m.epoch FROM stream_change_marks m
39
+ WHERE m.connection_id = ? AND m.stream = ?), 0) = ?`);
40
+ const condition = `(
41
+ EXISTS (SELECT 1 FROM connections c WHERE c.connection_id = ? AND c.generation = ?
42
+ AND c.control_state = 'active' AND c.deleted_at IS NULL
43
+ AND NOT EXISTS (SELECT 1 FROM delete_intents d WHERE d.connector = c.connector))
44
+ ${heads.map((h) => `AND ${h}`).join("\n ")})`;
45
+ const sql = `SELECT ${condition} AS ok`;
46
+ const params = [
47
+ connection.connection_id,
48
+ connection.generation,
49
+ ...installed.flatMap((s) => [
50
+ connection.connection_id,
51
+ s.stream,
52
+ s.installed_version,
53
+ s.head_data_hash,
54
+ connection.connection_id,
55
+ s.stream,
56
+ epochs.get(s.stream) ?? 0,
57
+ ]),
58
+ ];
59
+ if (params.length > MAX_STATEMENT_PARAMS) {
60
+ throw new Error(`alias view check: ${installed.length} streams need ${params.length} bound parameters, and a statement may bind ${MAX_STATEMENT_PARAMS}`);
61
+ }
62
+ return Object.assign(async () => {
63
+ const [row] = await db.query(sql, params);
64
+ return row?.ok === 1;
65
+ }, { guard: { sql: condition, params } });
66
+ }
67
+ /** Ends a body whose view moved: the reader sees an aborted read and asks again. */
68
+ export async function assertViewCurrent(check) {
69
+ if (!(await check()))
70
+ throw new PartialViewMoved();
71
+ }
72
+ //# sourceMappingURL=alias-view.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"alias-view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AC,WAAW,CAAC,GAAG,CAAC;IACzD,MAAM,GAAG,GAAG,UAAU,SAAS,QAAQ,CAAC;IACxC,MAAM,MAAM,GAAG;QACb,UAAU,CAAC,aAAa;QACxB,UAAU,CAAC,UAAU;QACrB,GAAG,SAAS,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC;YAC1B,UAAU,CAAC,aAAa;YACxB,CAAC,CAAC,MAAM;YACR,CAAC,CAAC,iBAAiB;YACnB,CAAC,CAAC,cAAe;YACjB,UAAU,CAAC,aAAa;YACxB,CAAC,CAAC,MAAM;YACR,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC;SAC1B,CAAC;KACH,CAAC;IACF,IAAI,MAAM,CAAC,MAAM,GAAG,oBAAoB,EAAE,CAAC;QACzC,MAAM,IAAI,KAAK,CACb,qBAAqB,SAAS,CAAC,MAAM,iBAAiB,MAAM,CAAC,MAAM,+CAA+C,oBAAoB,EAAE,CACzI,CAAC;IACJ,CAAC;IACD,OAAO,MAAM,CAAC,MAAM,CAClB,KAAK,IAAI,EAAE;QACT,MAAM,CAAC,GAAG,CAAC,GAAG,MAAM,EAAE,CAAC,KAAK,CAAiB,GAAG,EAAE,MAAM,CAAC,CAAC;QAC1D,OAAO,GAAG,EAAE,EAAE,KAAK,CAAC,CAAC;IACvB,CAAC,EACD,EAAE,KAAK,EAAE,EAAE,GAAG,EAAE,SAAS,EAAE,MAAM,EAAE,EAAE,CACtC,CAAC;AACJ,CAAC;AAED,oFAAoF;AACpF,MAAM,CAAC,KAAK,UAAU,iBAAiB,CAAC,KAAqB;IAC3D,IAAI,CAAC,CAAC,MAAM,KAAK,EAAE,CAAC;QAAE,MAAM,IAAI,gBAAgB,EAAE,CAAC;AACrD,CAAC"}
@@ -0,0 +1,100 @@
1
+ import type { StreamSyncBlobs } from "../stream-sync/ports.js";
2
+ import { type AliasViewCheck } from "./alias-view.js";
3
+ import type { AliasRecordQuery } from "./query.js";
4
+ import type { AliasDiagnostic, AliasWindow, LocalAliasTarget } from "./resolve.js";
5
+ /**
6
+ * A windowed alias read: the projection of a binding that builds one output
7
+ * element per parent row, computed a window of parents at a time.
8
+ *
9
+ * What it holds, and why that is the governor's to give. The read keeps an
10
+ * index of the whole input (every parent row, and for each parent the key
11
+ * hashes of its children) and one window's rows, parsed. Both are charged to
12
+ * the store's byte budget (`StorageAccessPolicy.maxBytesInFlight`) in one
13
+ * reservation, taken while the read holds nothing: under pressure the read
14
+ * waits for its turn. The window is a chunk of that reservation: a parent whose
15
+ * own rows are larger than a chunk is a window of its own, and takes the
16
+ * larger reservation it needs, up to the governor's limit. Past the limit the
17
+ * read is not windowed (`AliasTooLarge`) and the caller reads the input whole,
18
+ * as main does: a parent and its children are one window, and a windowed read
19
+ * never asks for more than the limit.
20
+ *
21
+ * Nothing is held before it is reserved. The children are indexed a batch of
22
+ * bodies at a time (their join key is read from the body: shared SQL has no
23
+ * JSON functions), each batch no larger than the reservation's chunk, so the
24
+ * bodies in memory are the ones the reservation was taken for. A larger
25
+ * reservation is asked for with the index dropped, then the index is built
26
+ * again under it: a read that waits holds neither a reservation nor an index.
27
+ */
28
+ export type AliasMemory = Pick<StreamSyncBlobs, "governor">;
29
+ /**
30
+ * Heap bytes held for each byte of stored JSON while its window is projected:
31
+ * the text read, its parsed objects, the projected copy and the serialized
32
+ * element. An estimate, so the budget is charged for what a window really
33
+ * takes rather than for the size of its text. The windowed read's large-account
34
+ * test reports the heap it measured against what was held.
35
+ */
36
+ export declare const HEAP_PER_STORED_BYTE = 4;
37
+ /**
38
+ * The most a windowed read asks the governor for is its limit, whatever the
39
+ * data: the governor grants a request above its limit when it is idle, and an
40
+ * alias read must never be that request. A read that would need more (an index
41
+ * larger than the limit, or one parent whose rows with their children are) is
42
+ * not windowed, and is decided before the group is loaded. `bytes` are the
43
+ * stored bytes the window would hold. The caller reads the input whole, which
44
+ * serves what main served and refuses (`too_large`) what main refused.
45
+ */
46
+ export declare class AliasTooLarge extends Error {
47
+ readonly bytes: number;
48
+ constructor(bytes: number);
49
+ }
50
+ /**
51
+ * What an in-memory read of `bytes` stored bytes is charged: its heap, up to
52
+ * its share of the budget. A read that builds the whole body holds what main
53
+ * held (a body is at most `ARRAY_BUDGET`); the charge keeps the governor's line
54
+ * moving for uploads, and is never a request the governor would grant above its
55
+ * limit.
56
+ */
57
+ export declare const wholeReadCharge: (memory: AliasMemory, bytes: number) => number;
58
+ export type WindowOutcome = {
59
+ readonly ok: true;
60
+ readonly payload: Record<string, unknown>;
61
+ readonly diagnostics: readonly AliasDiagnostic[];
62
+ } | {
63
+ readonly ok: false;
64
+ readonly error: {
65
+ readonly kind: string;
66
+ };
67
+ };
68
+ export interface WindowedInput {
69
+ readonly query: AliasRecordQuery;
70
+ readonly connectionId: string;
71
+ readonly binding: LocalAliasTarget;
72
+ readonly window: AliasWindow;
73
+ /** The streams the read serves, installed and complete. */
74
+ readonly fetched: readonly string[];
75
+ readonly now: string;
76
+ readonly memory: AliasMemory;
77
+ /**
78
+ * Whether the rows read are still those the read was decided on. Every read
79
+ * of bodies carries its `guard`, so a body is read from the state it was
80
+ * sized in or not at all.
81
+ */
82
+ readonly current: AliasViewCheck;
83
+ /** Ends a wait for memory: the read leaves the governor's line. */
84
+ readonly signal?: AbortSignal;
85
+ }
86
+ export interface WindowedRead {
87
+ /** The projection of each window, in the output order of the parents. */
88
+ windows(): AsyncGenerator<WindowOutcome, void>;
89
+ /** Give the memory back. Safe to call twice. */
90
+ release(): void;
91
+ }
92
+ /**
93
+ * Open a windowed read: size and take its memory, index the input and plan its
94
+ * windows. `null` when the input cannot be windowed, because a row has no
95
+ * usable key or a child names no parent (`LegacyProjectionWindow`: a caller
96
+ * must refuse such input rather than window it); the caller then projects the
97
+ * input whole.
98
+ */
99
+ export declare function openWindowed(input: WindowedInput): Promise<WindowedRead | null>;
100
+ //# sourceMappingURL=alias-window.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"alias-window.d.ts","sourceR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WAAW,CAAC;IAC7B,2DAA2D;IAC3D,QAAQ,CAAC,OAAO,EAAE,SAAS,MAAM,EAAE,CAAC;IACpC,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,MAAM,EAAE,WAAW,CAAC;IAC7B;;;;OAIG;IACH,QAAQ,CAAC,OAAO,EAAE,cAAc,CAAC;IACjC,mEAAmE;IACnE,QAAQ,CAAC,MAAM,CAAC,EAAE,WAAW,CAAC;CAC/B;AAED,MAAM,WAAW,YAAY;IAC3B,yEAAyE;IACzE,OAAO,IAAI,cAAc,CAAC,aAAa,EAAE,IAAI,CAAC,CAAC;IAC/C,gDAAgD;IAChD,OAAO,IAAI,IAAI,CAAC;CACjB;AAoBD;;;;;;GAMG;AACH,wBAAsB,YAAY,CAChC,KAAK,EAAE,aAAa,GACnB,OAAO,CAAC,YAAY,GAAG,IAAI,CAAC,CAsG9B"}
@@ -0,0 +1,286 @@
1
+ import { sizedBodies, WHOLE_STREAM_BATCH_BYTES, } from "./alias-sized.js";
2
+ import { assertViewCurrent } from "./alias-view.js";
3
+ import { PartialViewMoved } from "./partial-read.js";
4
+ import { holdMemory } from "./transfer-memory.js";
5
+ /**
6
+ * Heap bytes held for each byte of stored JSON while its window is projected:
7
+ * the text read, its parsed objects, the projected copy and the serialized
8
+ * element. An estimate, so the budget is charged for what a window really
9
+ * takes rather than for the size of its text. The windowed read's large-account
10
+ * test reports the heap it measured against what was held.
11
+ */
12
+ export const HEAP_PER_STORED_BYTE = 4;
13
+ /**
14
+ * Heap bytes the index keeps for each parent beyond what 4x its stored JSON
15
+ * covers: the `Parent` object, its slot in the key map and that slot's group.
16
+ * A parent whose body is a few bytes costs more than four times its body.
17
+ * Measured with `node --expose-gc`: 100,000 parents of body `{"id":"c0000000"}`
18
+ * (17 stored bytes, charged 68) grew the live heap by 173 bytes each, after
19
+ * a full collection, over `JSON.parse`, the `Parent` object, a `Map` slot and
20
+ * an empty `ChildGroup`. The next multiple of 64 above that, so a larger
21
+ * parent, which the 4x already over-covers, is charged a little too much and
22
+ * a small one is not charged too little.
23
+ */
24
+ const OBJECT_BYTES_PER_PARENT = 192;
25
+ /**
26
+ * Heap bytes one child row costs the index: its sized record (a 64-character
27
+ * key hash and a 64-character body hash, which the body statement checks) and
28
+ * the slot that holds it.
29
+ */
30
+ const INDEX_BYTES_PER_CHILD = 256;
31
+ /**
32
+ * The share of the budget one windowed read takes for its working set. The
33
+ * rest stays free for uploads, which draw on the same budget, so a long read
34
+ * does not stop a publish. It sizes the chunk only: a read that needs more
35
+ * than its share (a parent with more rows than a chunk) takes what it needs,
36
+ * up to the governor's limit.
37
+ */
38
+ const READ_SHARE = 0.5;
39
+ /**
40
+ * The most a windowed read asks the governor for is its limit, whatever the
41
+ * data: the governor grants a request above its limit when it is idle, and an
42
+ * alias read must never be that request. A read that would need more (an index
43
+ * larger than the limit, or one parent whose rows with their children are) is
44
+ * not windowed, and is decided before the group is loaded. `bytes` are the
45
+ * stored bytes the window would hold. The caller reads the input whole, which
46
+ * serves what main served and refuses (`too_large`) what main refused.
47
+ */
48
+ export class AliasTooLarge extends Error {
49
+ bytes;
50
+ constructor(bytes) {
51
+ super(`alias window: a read of ${bytes} stored bytes exceeds the budget`);
52
+ this.bytes = bytes;
53
+ this.name = "AliasTooLarge";
54
+ }
55
+ }
56
+ /**
57
+ * What an in-memory read of `bytes` stored bytes is charged: its heap, up to
58
+ * its share of the budget. A read that builds the whole body holds what main
59
+ * held (a body is at most `ARRAY_BUDGET`); the charge keeps the governor's line
60
+ * moving for uploads, and is never a request the governor would grant above its
61
+ * limit.
62
+ */
63
+ export const wholeReadCharge = (memory, bytes) => Math.min(bytes * HEAP_PER_STORED_BYTE, Math.floor(memory.governor.limitBytes * READ_SHARE));
64
+ const isObject = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
65
+ /** A key a window can join on: a string or a number. */
66
+ const joinable = (value) => typeof value === "string" || typeof value === "number";
67
+ /**
68
+ * Open a windowed read: size and take its memory, index the input and plan its
69
+ * windows. `null` when the input cannot be windowed, because a row has no
70
+ * usable key or a child names no parent (`LegacyProjectionWindow`: a caller
71
+ * must refuse such input rather than window it); the caller then projects the
72
+ * input whole.
73
+ */
74
+ export async function openWindowed(input) {
75
+ const { query, connectionId, window, fetched } = input;
76
+ if (!fetched.includes(window.parentStream))
77
+ return null;
78
+ const hasChildren = fetched.includes(window.childStream);
79
+ const others = fetched.filter((s) => s !== window.parentStream && s !== window.childStream);
80
+ // What each stream was sized at: the reservation is taken for these, and
81
+ // every body statement below stays inside them.
82
+ const limits = new Map();
83
+ for (const stream of [window.parentStream, ...others]) {
84
+ limits.set(stream, await query.streamStats(connectionId, stream));
85
+ }
86
+ const childStats = hasChildren
87
+ ? await query.streamStats(connectionId, window.childStream)
88
+ : { rows: 0, bytes: 0, maxBytes: 0 };
89
+ limits.set(window.childStream, childStats);
90
+ let otherBytes = 0;
91
+ for (const stream of others)
92
+ otherBytes += limits.get(stream).bytes;
93
+ const parentStats = limits.get(window.parentStream);
94
+ // What the index and the whole of the other streams cost, and then the
95
+ // chunk: what is left of the read's share, as source bytes of one window.
96
+ const fixed = (parentStats.bytes + otherBytes) * HEAP_PER_STORED_BYTE +
97
+ parentStats.rows * OBJECT_BYTES_PER_PARENT +
98
+ childStats.rows * INDEX_BYTES_PER_CHILD;
99
+ const share = Math.floor(input.memory.governor.limitBytes * READ_SHARE);
100
+ const chunk = Math.max(0, Math.floor((share - fixed) / HEAP_PER_STORED_BYTE));
101
+ // While the children are indexed, a batch of their bodies is in memory: no
102
+ // more than a chunk, or one body if that is larger.
103
+ const scan = Math.max(chunk, childStats.maxBytes);
104
+ let held = fixed + scan * HEAP_PER_STORED_BYTE;
105
+ const limit = input.memory.governor.limitBytes;
106
+ // Decided on the sizes alone, before a row is read or a byte reserved: the
107
+ // index and one batch of bodies do not fit the budget.
108
+ if (held > limit)
109
+ throw new AliasTooLarge(Math.ceil(held / HEAP_PER_STORED_BYTE));
110
+ let reservation = await holdMemory(input.memory, held, 0, input.signal);
111
+ const release = () => {
112
+ reservation?.();
113
+ reservation = undefined;
114
+ };
115
+ try {
116
+ for (;;) {
117
+ const attempt = await indexAndPlan(input, others, hasChildren, limits, scan, chunk, fixed, held);
118
+ if (attempt.kind === "unwindowable") {
119
+ // Rows a moved view hid can only make the input look unwindowable.
120
+ await assertViewCurrent(input.current);
121
+ release();
122
+ return null;
123
+ }
124
+ if (attempt.kind === "fits") {
125
+ // The reservation is what the largest window needs, no more.
126
+ reservation?.shrink(attempt.need);
127
+ await assertViewCurrent(input.current);
128
+ const { parents, children, otherRecords, plan } = attempt;
129
+ return {
130
+ windows: () => runWindows(input, parents, children, otherRecords, plan, hasChildren),
131
+ release,
132
+ };
133
+ }
134
+ // The largest window needs more than is held. The index was dropped
135
+ // with the attempt: hold nothing while the larger reservation waits,
136
+ // then build the index again under it. On a view that has not moved the
137
+ // same rows give the same plan, so the second attempt fits. A window
138
+ // that needs more than the budget is refused: the plan is known now, and
139
+ // a parent with its children is one window that cannot be split.
140
+ await assertViewCurrent(input.current);
141
+ if (attempt.need > limit) {
142
+ throw new AliasTooLarge(Math.ceil(attempt.need / HEAP_PER_STORED_BYTE));
143
+ }
144
+ release();
145
+ held = attempt.need;
146
+ reservation = await holdMemory(input.memory, held, 0, input.signal);
147
+ }
148
+ }
149
+ catch (error) {
150
+ release();
151
+ throw error;
152
+ }
153
+ }
154
+ /**
155
+ * Index the input and plan its windows under `held` bytes. When the largest
156
+ * window needs more than that, the answer is the size alone: the index is the
157
+ * frame's, and gone when it returns.
158
+ */
159
+ async function indexAndPlan(input, others, hasChildren, limits, scan, chunk, fixed, held) {
160
+ const indexed = await indexInput(input, others, hasChildren, limits, scan);
161
+ if (indexed === null)
162
+ return { kind: "unwindowable" };
163
+ const { parents, children } = indexed;
164
+ parents.sort((a, b) => input.window.parentOrder(a.data, b.data));
165
+ const plan = planWindows(parents, children, chunk);
166
+ const need = fixed +
167
+ HEAP_PER_STORED_BYTE * plan.reduce((m, w) => Math.max(m, w.chars), 0);
168
+ return need <= held
169
+ ? { kind: "fits", need, ...indexed, plan }
170
+ : { kind: "larger", need };
171
+ }
172
+ async function indexInput(input, others, hasChildren, limits, scan) {
173
+ const { query, connectionId, window } = input;
174
+ const parents = [];
175
+ const children = new Map();
176
+ // Parents and other streams are held whole, under the memory reserved for
177
+ // their stored size: each is read by sized batches inside that size.
178
+ const bodies = (stream) => sizedBodies(query, connectionId, stream, limits.get(stream), WHOLE_STREAM_BATCH_BYTES, input.current, input.signal);
179
+ for await (const batch of bodies(window.parentStream)) {
180
+ for (const { record } of batch) {
181
+ const data = JSON.parse(record.body);
182
+ if (!isObject(data))
183
+ return null;
184
+ const key = data[window.parentKey];
185
+ if (!joinable(key) || children.has(key))
186
+ return null;
187
+ children.set(key, { sized: [], chars: 0 });
188
+ parents.push({ data, key, chars: record.body.length });
189
+ }
190
+ }
191
+ if (hasChildren && !(await indexChildren(input, children, limits, scan))) {
192
+ return null;
193
+ }
194
+ const otherRecords = [];
195
+ for (const stream of others) {
196
+ for await (const batch of bodies(stream)) {
197
+ for (const { record } of batch) {
198
+ otherRecords.push({
199
+ stream,
200
+ data: JSON.parse(record.body),
201
+ });
202
+ }
203
+ }
204
+ }
205
+ return { parents, children, otherRecords };
206
+ }
207
+ /**
208
+ * Add each child's sized record to its parent's group. The bodies are read,
209
+ * to find the key they name, `scan` stored bytes at a time (a body larger than
210
+ * that, alone) and are not kept. False when a child names no parent or is not
211
+ * an object.
212
+ */
213
+ async function indexChildren(input, children, limits, scan) {
214
+ const { query, connectionId, window } = input;
215
+ // The children's bodies are not held whole: only a batch of them, so no
216
+ // limit on their total, but their count (what the index was charged for)
217
+ // and each one's size (what `scan` was taken for) stay inside what was sized.
218
+ const childLimits = {
219
+ ...limits.get(window.childStream),
220
+ bytes: Number.POSITIVE_INFINITY,
221
+ };
222
+ for await (const batch of sizedBodies(query, connectionId, window.childStream, childLimits, scan, input.current, input.signal)) {
223
+ for (const { record, sized } of batch) {
224
+ const data = JSON.parse(record.body);
225
+ if (!isObject(data))
226
+ return false;
227
+ const group = children.get(data[window.childKey]);
228
+ if (!group)
229
+ return false;
230
+ group.sized.push(sized);
231
+ group.chars += sized.bytes;
232
+ }
233
+ }
234
+ return true;
235
+ }
236
+ /** Cut the parents, in order, into windows of about `chunk` stored characters. */
237
+ function planWindows(parents, children, chunk) {
238
+ const plan = [];
239
+ let from = 0;
240
+ let chars = 0;
241
+ parents.forEach((parent, i) => {
242
+ const own = parent.chars + children.get(parent.key).chars;
243
+ if (i > from && chars + own > chunk) {
244
+ plan.push({ from, to: i, chars });
245
+ from = i;
246
+ chars = 0;
247
+ }
248
+ chars += own;
249
+ });
250
+ if (parents.length > from)
251
+ plan.push({ from, to: parents.length, chars });
252
+ return plan;
253
+ }
254
+ async function* runWindows(input, parents, children, otherRecords, plan, hasChildren) {
255
+ const { query, connectionId, window, binding, now, fetched } = input;
256
+ for (const { from, to } of plan) {
257
+ input.signal?.throwIfAborted();
258
+ const inWindow = parents.slice(from, to);
259
+ const sized = inWindow.flatMap((p) => children.get(p.key).sized);
260
+ const rows = hasChildren && sized.length > 0
261
+ ? await query.recordsByHash(connectionId, window.childStream, sized, input.current.guard)
262
+ : [];
263
+ // A row gone, changed or grown since the index was read: the view moved.
264
+ if (rows.length !== sized.length)
265
+ throw new PartialViewMoved();
266
+ // Checked after the rows are read, so every one of them is a pinned row.
267
+ await assertViewCurrent(input.current);
268
+ const records = [
269
+ ...inWindow.map((p) => ({ stream: window.parentStream, data: p.data })),
270
+ ...rows.map((row) => ({
271
+ stream: window.childStream,
272
+ data: JSON.parse(row.body),
273
+ })),
274
+ ...otherRecords,
275
+ ];
276
+ const projected = binding.project(records, now, fetched);
277
+ yield projected.ok
278
+ ? {
279
+ ok: true,
280
+ payload: projected.payload,
281
+ diagnostics: projected.diagnostics ?? [],
282
+ }
283
+ : projected;
284
+ }
285
+ }
286
+ //# sourceMappingURL=alias-window.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"al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