@yaks/journal 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 +522 -2
- package/_dist/backed.d.ts +9 -0
- package/_dist/backed.d.ts.map +1 -0
- package/_dist/batch.d.ts +45 -0
- package/_dist/batch.d.ts.map +1 -0
- package/_dist/feed.d.ts +108 -0
- package/_dist/feed.d.ts.map +1 -0
- package/_dist/graph.d.ts +104 -0
- package/_dist/graph.d.ts.map +1 -0
- package/_dist/kept.d.ts +63 -0
- package/_dist/kept.d.ts.map +1 -0
- package/_dist/log.d.ts +142 -0
- package/_dist/log.d.ts.map +1 -0
- package/_dist/merge.d.ts +41 -0
- package/_dist/merge.d.ts.map +1 -0
- package/_dist/mod.d.ts +101 -0
- package/_dist/mod.d.ts.map +1 -0
- package/_dist/service.d.ts +68 -0
- package/_dist/service.d.ts.map +1 -0
- package/_dist/tools.d.ts +5 -0
- package/_dist/tools.d.ts.map +1 -0
- package/_dist/undo.d.ts +48 -0
- package/_dist/undo.d.ts.map +1 -0
- package/_dist/value.d.ts +6 -0
- package/_dist/value.d.ts.map +1 -0
- package/_dist/views.d.ts +25 -0
- package/_dist/views.d.ts.map +1 -0
- package/_dist/vocab.d.ts +7 -0
- package/_dist/vocab.d.ts.map +1 -0
- package/backed.js +225 -0
- package/backed.js.map +1 -0
- package/backed.ts +274 -0
- package/batch.js +12 -0
- package/batch.js.map +1 -0
- package/batch.ts +84 -0
- package/deno.json +1 -0
- package/feed.js +295 -0
- package/feed.js.map +1 -0
- package/feed.ts +368 -0
- package/graph.js +224 -0
- package/graph.js.map +1 -0
- package/graph.ts +329 -0
- package/held.js +25 -0
- package/held.js.map +1 -0
- package/held.ts +24 -0
- package/kept.js +61 -0
- package/kept.js.map +1 -0
- package/kept.ts +100 -0
- package/log.js +1161 -0
- package/log.js.map +1 -0
- package/log.ts +1299 -0
- package/merge.js +158 -0
- package/merge.js.map +1 -0
- package/merge.ts +185 -0
- package/mod.js +101 -0
- package/mod.js.map +1 -0
- package/mod.ts +102 -0
- package/names.js +206 -0
- package/names.js.map +1 -0
- package/names.ts +230 -0
- package/package.json +52 -4
- package/page.js +160 -0
- package/page.js.map +1 -0
- package/page.ts +233 -0
- package/service.js +118 -0
- package/service.js.map +1 -0
- package/service.ts +148 -0
- package/tools.js +110 -0
- package/tools.js.map +1 -0
- package/tools.ts +113 -0
- package/undo.js +187 -0
- package/undo.js.map +1 -0
- package/undo.ts +190 -0
- package/value.js +26 -0
- package/value.js.map +1 -0
- package/value.ts +35 -0
- package/views.js +85 -0
- package/views.js.map +1 -0
- package/views.ts +91 -0
- package/vocab.js +20 -0
- package/vocab.js.map +1 -0
- package/vocab.json +308 -0
- package/vocab.ts +22 -0
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What the file keeps, as a duty: the module a server imports at
|
|
3
|
+
* `@yaks/journal/service`. Once a UTC day it measures the store's file (its
|
|
4
|
+
* storage's `measure`) and keeps the day's `kept` row, which the History page
|
|
5
|
+
* reads (./page.ts), so looking costs nothing. The row names the file it
|
|
6
|
+
* measured, so a page about the disk finds the store's file and its free
|
|
7
|
+
* pages, and holds the changes the journal holds per component, counted from
|
|
8
|
+
* its log, so the page never counts them. A store that keeps no file of
|
|
9
|
+
* pages measures nothing.
|
|
10
|
+
*
|
|
11
|
+
* @module
|
|
12
|
+
*/ import type { Bundle, Eid, Graph, Measure } from "@yaks/graph";
|
|
13
|
+
import { type Bound } from "./graph.js";
|
|
14
|
+
/** How long a pass waits for the next, in milliseconds: an hour. */ export declare let EVERY: any;
|
|
15
|
+
/** The row a day's measurement is kept in. */ export declare let keptEid: (day: string) => Eid;
|
|
16
|
+
/** What a day's row says of itself, as far as {@link owed} asks. */ export type Had = {
|
|
17
|
+
file?: unknown;
|
|
18
|
+
tables?: object;
|
|
19
|
+
changes?: unknown;
|
|
20
|
+
};
|
|
21
|
+
/**
|
|
22
|
+
* Whether a day is still to be measured: it has no row, its row does not
|
|
23
|
+
* name the file the store keeps, or it measured a journal without counting
|
|
24
|
+
* its changes.
|
|
25
|
+
*
|
|
26
|
+
* ```ts
|
|
27
|
+
* import { owed } from './service.ts'
|
|
28
|
+
* import { equal } from '@yaks/testing'
|
|
29
|
+
*
|
|
30
|
+
* equal(owed(undefined), true)
|
|
31
|
+
* equal(owed({}), false)
|
|
32
|
+
* equal(owed({}, '/a/yak.db'), true)
|
|
33
|
+
* equal(owed({ file: 'f' }, '/a/yak.db'), false)
|
|
34
|
+
* equal(owed({ tables: { journal_change: [1, 1] } }), true)
|
|
35
|
+
* equal(owed({ tables: { journal_change: [1, 1] }, changes: {} }), false)
|
|
36
|
+
* ```
|
|
37
|
+
*/ export declare let owed: (kept?: Had, path?: string) => boolean;
|
|
38
|
+
/**
|
|
39
|
+
* What a day's measurement writes: the file measured, where the store keeps
|
|
40
|
+
* one (@yaks/file's bundle for it), and the day's row naming it, with the
|
|
41
|
+
* changes the journal holds per component where it keeps one.
|
|
42
|
+
*
|
|
43
|
+
* ```ts
|
|
44
|
+
* import { keptEid, measured } from './service.ts'
|
|
45
|
+
* import { equal } from '@yaks/testing'
|
|
46
|
+
*
|
|
47
|
+
* let m = { bytes: 300, free: 0, tables: {} }
|
|
48
|
+
* let file = { entity: { eid: 'f' }, file: { path: 'a/yak.db', root: 'v' } }
|
|
49
|
+
* equal(measured('2026-10-21', 'T', m, [file]), [file, {
|
|
50
|
+
* entity: { eid: keptEid('2026-10-21') },
|
|
51
|
+
* kept: { day: '2026-10-21', at: 'T', ...m, file: 'f' },
|
|
52
|
+
* }])
|
|
53
|
+
* equal(measured('2026-10-21', 'T', m, [])[0].kept, { day: '2026-10-21', at: 'T', ...m })
|
|
54
|
+
* equal(measured('2026-10-21', 'T', m, [], { doc: 2 })[0].kept, { day: '2026-10-21', at: 'T', ...m, changes: { doc: 2 } })
|
|
55
|
+
* ```
|
|
56
|
+
*/ export declare let measured: (day: string, at: string, m: Measure, file: Bundle[], changes?: Record<string, number>) => Bundle[];
|
|
57
|
+
/** One pass: measure the file, unless the day `now` falls in has been. A
|
|
58
|
+
* file that keeps a journal has its changes counted by `held` (its log's). */ export declare let pass: (g: Graph, now?: number, signal?: AbortSignal, held?: () => Record<string, number> | Promise<Record<string, number>>) => Promise<void>;
|
|
59
|
+
/** Measure, then look again every `every`, until the signal aborts. An
|
|
60
|
+
* already aborted signal is one pass. */ export declare let service: (host: Partial<Bound> & {
|
|
61
|
+
graph: Graph;
|
|
62
|
+
report?: (error: unknown, context?: {
|
|
63
|
+
tags?: Record<string, string>;
|
|
64
|
+
}) => unknown;
|
|
65
|
+
}, options?: {
|
|
66
|
+
every?: number;
|
|
67
|
+
}, signal?: AbortSignal) => Promise<void>;
|
|
68
|
+
//# sourceMappingURL=service.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"service.d.ts","sources":["../service.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;CAWC,GACD,cAAc,MAAM,EAAE,GAAG,EAAE,KAAK,EAAE,OAAO,2BAAgC;AAKzE,SAAS,KAAK,KAAK,qBAA4B;AAG/C,kEAAkE,GAClE,OAAO,YAAI,WAAsB;AAEjC,4CAA4C,GAC5C,OAAO,YAAI,UAAW,KAAK,MAAM,KAAG,IAAiC;AAErE,kEAAkE,GAClE,YAAY;EAAQ,OAAO,OAAO;EAAE,SAAS,MAAM;EAAE,UAAU,OAAO;;AAEtE;;;;;;;;;;;;;;;;CAgBC,GACD,OAAO,YAAI,OAAQ,OAAO,KAAK,OAAO,MAAM,KAAG,OAAO,CAEM;AAE5D;;;;;;;;;;;;;;;;;;CAkBC,GACD,OAAO,YAAI,WACT,KAAK,MAAM,EACX,IAAI,MAAM,EACV,GAAG,SACH,MAAM,UACN,UAAU,OAAO,MAAM,EAAE,MAAM,MAC9B,SAYF;AAED;4EAC4E,GAC5E,OAAO,YAAI,OACT,GAAG,OACH,MAAK,MAAM,EACX,SAAS,aACT,aAAa,OAAO,MAAM,EAAE,MAAM,IAAI,QAAQ,OAAO,MAAM,EAAE,MAAM,OAClE,QAAQ,IAAI,EAcd;AAED;uCACuC,GACvC,OAAO,YAAI,UACT,MAAM,QAAQ;EACZ,OAAO;EACP,UACE,OAAO,OAAO,EACd;IAAY,OAAO,OAAO,MAAM,EAAE,MAAM;QACrC,OAAO;GAEd;EAAW,QAAQ,MAAM;GACzB,SAAQ,gBACP,QAAQ,IAAI,EAuBd"}
|
package/_dist/tools.d.ts
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { Runs } from "@yaks/graph/tools";
|
|
2
|
+
import { type Bound } from "./graph.js";
|
|
3
|
+
/** The functions behind the tools ./vocab.json declares — read over this
|
|
4
|
+
* host's storage, which is why this export is a factory. */ export declare let runs: (host: Bound) => Runs;
|
|
5
|
+
//# sourceMappingURL=tools.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tools.d.ts","sources":["../tools.ts"],"names":[],"mappings":"AAwBA,cAAc,IAAI,iCAAsC;AAKxD,SAAS,KAAK,KAAK,qBAA4B;AA4C/C;0DAC0D,GAC1D,OAAO,YAAI,OAAQ,MAAM,UAAQ,KAqChC"}
|
package/_dist/undo.d.ts
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import type { Actor, Bundle, Eid, Graph } from "@yaks/graph";
|
|
2
|
+
import type { Batch } from "./batch.js";
|
|
3
|
+
import type { Log } from "./log.js";
|
|
4
|
+
/** A refused undo: the transaction deleted an entity whose components the
|
|
5
|
+
* journal never recorded — it was written before the journal began, or only
|
|
6
|
+
* in components the journal skips — so nothing can bring it back, and bringing
|
|
7
|
+
* back the rest would leave whatever pointed at it pointing at a grave. */ export declare class Final extends Error {
|
|
8
|
+
eid: Eid;
|
|
9
|
+
seq: number;
|
|
10
|
+
/**
|
|
11
|
+
* @param eid the entity the transaction deleted
|
|
12
|
+
* @param seq the transaction it was deleted in
|
|
13
|
+
*/ constructor(eid: Eid, seq: number);
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* The transaction as committed, rebuilt from its deltas — the bundles a server
|
|
17
|
+
* pushes to its subscribers when it reads the feed, with no read of storage at
|
|
18
|
+
* all. They carry what moved, so who wrote it and when, which the `journal_tx`
|
|
19
|
+
* row already holds, are not repeated in them.
|
|
20
|
+
*/ export declare let applied: (batch: Batch) => Bundle[];
|
|
21
|
+
/** How an undo is built. */ export type UndoneOpts = {
|
|
22
|
+
/** carry a `$was` precondition on every restored property, hashed from the
|
|
23
|
+
* value the transaction left there, so that a property changed since refuses
|
|
24
|
+
* the reversal */ guard?: boolean;
|
|
25
|
+
};
|
|
26
|
+
/**
|
|
27
|
+
* The bundles that reverse a transaction: every property back to the value it
|
|
28
|
+
* held, every component that went restored with the properties it had, every
|
|
29
|
+
* component that appeared removed, every entity it deleted given back the
|
|
30
|
+
* components it held, and every entity it brought back deleted again. Throws
|
|
31
|
+
* {@link Final} if the transaction deleted an entity the journal recorded none
|
|
32
|
+
* of the components of.
|
|
33
|
+
*/ export declare let undone: (batch: Batch, opts?: UndoneOpts) => Bundle[];
|
|
34
|
+
/**
|
|
35
|
+
* Undo a committed transaction by its `seq`: read it back out of the log, build
|
|
36
|
+
* the inverse from what was written down, and apply it through the graph — so
|
|
37
|
+
* the undo is admitted, stamped and journaled like any other write:
|
|
38
|
+
* `undo(g, j)(7, { by: 'ada' })` reverses transaction 7 as `ada`.
|
|
39
|
+
*
|
|
40
|
+
* Throws {@link Final} if the transaction deleted an entity the journal holds
|
|
41
|
+
* none of the components of, and a plain `Error` if no transaction has that
|
|
42
|
+
* seq. The inverse is applied as trusted, since restoring a property the
|
|
43
|
+
* server owns is the graph's own reconstruction rather than a client's write.
|
|
44
|
+
* Every restored property carries a `$was` precondition, so a property
|
|
45
|
+
* somebody else has changed since refuses the whole reversal instead of being
|
|
46
|
+
* overwritten.
|
|
47
|
+
*/ export declare let undo: (g: Graph, j: Log) => any;
|
|
48
|
+
//# sourceMappingURL=undo.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"undo.d.ts","sources":["../undo.ts"],"names":[],"mappings":"AAmBA,cAAc,KAAK,EAAE,MAAM,EAAQ,GAAG,EAAE,KAAK,2BAAqC;AAGlF,cAAc,KAAK,qBAAoB;AACvC,cAAc,GAAG,mBAAkB;AAEnC;;;yEAGyE,GACzE,OAAO,cAAM,cAAc;EAKN,KAAK;EAAY,KAAK,MAAM;EAJ/C;;;GAGC,GACD,YAAY,AAAO,KAAK,GAAG,EAAE,AAAO,KAAK,MAAM;AAOjD;AAkGA;;;;;CAKC,GACD,OAAO,YAAI,UAAW,OAAO,UAAQ,SAAgC;AAErE,0BAA0B,GAC1B,YAAY;EACV;;kBAEgB,GAChB,QAAQ,OAAO;;AAGjB;;;;;;;CAOC,GACD,OAAO,YAAI,SAAU,OAAO,OAAO,OAAM,eAAkB,SACxB;AAEnC;;;;;;;;;;;;;CAaC,GACD,OAAO,YAAI,OACR,GAAG,OAAO,GAAG,YAQb"}
|
package/_dist/value.d.ts
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/** A value as the journal stores it: JSON, marked base64 bytes, or `null`
|
|
2
|
+
* for no value at all. JSON strings include their quotes and cannot collide
|
|
3
|
+
* with the binary prefix. */ export declare let enc: (v: unknown) => string | null;
|
|
4
|
+
/** A stored value read back. Text that is not JSON comes back as itself, so a
|
|
5
|
+
* hand-written row never throws. */ export declare let dec: (v: unknown) => unknown;
|
|
6
|
+
//# sourceMappingURL=value.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"value.d.ts","sources":["../value.ts"],"names":[],"mappings":"AAYA;;2BAE2B,GAC3B,OAAO,YAAI,MAAO,GAAG,OAAO,KAAG,MAAM,GAAG,IAAI,CAKrB;AAEvB;kCACkC,GAClC,OAAO,YAAI,MAAO,GAAG,OAAO,KAAG,OAAO,CAUrC"}
|
package/_dist/views.d.ts
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What this package draws. Anywhere: a row of an entity's history (the
|
|
3
|
+
* `history` tool, ./tools.ts) as one line, when · who · what it wrote —
|
|
4
|
+
* `2 minutes ago · yak task new Buy the cake · task; doc: Buy the cake`. In the
|
|
5
|
+
* browsing app: the History page, which the sidebar offers over the days'
|
|
6
|
+
* measurements, loaded when first drawn (./page.ts).
|
|
7
|
+
*
|
|
8
|
+
* @module
|
|
9
|
+
*/ import type { View } from "@yaks/inspect";
|
|
10
|
+
import { type Registry } from "@yaks/render";
|
|
11
|
+
// @ts-types="@yaks/ui/lucide"
|
|
12
|
+
import History from "lucide/dist/esm/icons/rotate-ccw-clock.mjs";
|
|
13
|
+
/** A history row as one line, in a list or alone. */ export declare let views: Registry;
|
|
14
|
+
/** The page, loaded when first drawn. */ export declare let inspectViews: () => Promise<View[]>;
|
|
15
|
+
/** The page the sidebar offers: what history keeps, over the days. */ export declare let destinations: readonly [{
|
|
16
|
+
readonly key: string;
|
|
17
|
+
readonly name: string;
|
|
18
|
+
readonly icon: string;
|
|
19
|
+
readonly query: string;
|
|
20
|
+
readonly view: string;
|
|
21
|
+
}];
|
|
22
|
+
/** The glyph it wears there. */ export declare let icons: {
|
|
23
|
+
readonly history: any;
|
|
24
|
+
};
|
|
25
|
+
//# sourceMappingURL=views.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"views.d.ts","sources":["../views.ts"],"names":[],"mappings":"AAAA;;;;;;;;CAQC,GACD,cAAc,IAAI,6BAAkC;AAEpD,SAAsC,KAAK,QAAQ,4BAAiC;AAEpF,8BAA8B;AAC9B,OAAO,0DAAoE;AAsD3E,mDAAmD,GACnD,OAAO,YAAI,OAAO,SAGhB;AAEF,uCAAuC,GACvC,OAAO,YAAI,oBAAmB,QAAQ,QACW;AAEjD,oEAAoE,GACpE,OAAO,YAAI;aAEP;aACA;aACA;aACA;aACA;KAEH;AAED,8BAA8B,GAC9B,OAAO,YAAI;WAAU;EAAkB"}
|
package/_dist/vocab.d.ts
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { VocabDoc } from "@yaks/vocab";
|
|
2
|
+
export { backed } from "./backed.js";
|
|
3
|
+
/** The declarations this plugin contributes. */ export declare let journalDoc: VocabDoc;
|
|
4
|
+
/** What this package is: its manifest's description, the one place it is
|
|
5
|
+
* written, which a host stamps on each document here. */ export declare let description: string;
|
|
6
|
+
/** Every document this plugin declares. */ export declare let docs: VocabDoc[];
|
|
7
|
+
//# sourceMappingURL=vocab.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"vocab.d.ts","sources":["../vocab.ts"],"names":[],"mappings":"AAOA,cAAc,QAAQ,2BAAgC;AAItD,SAAS,MAAM,sBAAqB;AAEpC,8CAA8C,GAC9C,OAAO,YAAI,YAAY,SAAc;AAErC;uDACuD,GACvD,OAAO,YAAI,aAAa,MAAM,CAAuB;AAErD,yCAAyC,GACzC,OAAO,YAAI,MAAM,WAAyB"}
|
package/backed.js
ADDED
|
@@ -0,0 +1,225 @@
|
|
|
1
|
+
// The journal read as entities. Its vocabulary declares two computed
|
|
2
|
+
// components (vocab.json): `_tx`, a committed transaction, and `_change`, one
|
|
3
|
+
// component a transaction wrote or removed. No table holds them. These are
|
|
4
|
+
// their backings (@yaks/sql `Backing`): the journal's own rows, renamed to the
|
|
5
|
+
// components' properties, which a store reads as it reads a component table —
|
|
6
|
+
// so an entity's history is `._change.target=T-5`, a session's writes are
|
|
7
|
+
// `._tx.via=S-7`, and nothing is copied, nor journaled, to answer either.
|
|
8
|
+
//
|
|
9
|
+
// A reference column already holds what a component table holds, the
|
|
10
|
+
// referent's integer id: `target`, `by` and `via` point into the entity table,
|
|
11
|
+
// and `tx` at a transaction's own id. `comp` is the `_comp` entity describing
|
|
12
|
+
// the component (@yaks/vocab), the entity whose eid is the component's
|
|
13
|
+
// identity, which is what the row recorded (./names.ts); a graph that does not
|
|
14
|
+
// describe its vocabulary, or no longer describes a component the journal
|
|
15
|
+
// names, has none to point at. A row recorded by label before identities
|
|
16
|
+
// points at the `_comp` row that label has now.
|
|
17
|
+
//
|
|
18
|
+
// `component` is the component's label, and a change's `value` its after-image
|
|
19
|
+
// keyed by its properties' labels, as the vocabulary reads the identities the
|
|
20
|
+
// rows recorded: a reader reads history in the words it reads the graph in,
|
|
21
|
+
// and a renamed word's history under its new label. The value is the
|
|
22
|
+
// properties the change wrote as one object, read from its field rows; a
|
|
23
|
+
// removal has none. A property the store keeps in another form, the address
|
|
24
|
+
// @yaks/blob keeps in place of a body, reads back through the store's `text`
|
|
25
|
+
// (@yaks/sql `Derived`), so a change says the text a reader of the graph read;
|
|
26
|
+
// where that text is no longer kept, it says what was recorded.
|
|
27
|
+
import { among, and, as, col, desc, eq, exists, fn, join, left, lit, select, sub, table, when } from "@yaks/sql/core";
|
|
28
|
+
import { names } from "./names.js";
|
|
29
|
+
let jc = (c)=>col(c, 'jc');
|
|
30
|
+
let jf = (c)=>col(c, 'jf');
|
|
31
|
+
let cc = (c)=>col(c, 'cc');
|
|
32
|
+
// The address a field row `f` recorded: its value, or, as the journal once
|
|
33
|
+
// recorded content, the eid of the entity holding it (`ref`).
|
|
34
|
+
let addressOf = (f)=>fn('coalesce', fn('json_extract', f('value'), lit('$')), sub(select({
|
|
35
|
+
cols: [
|
|
36
|
+
col('eid', 'jr')
|
|
37
|
+
],
|
|
38
|
+
from: table('entity', 'jr'),
|
|
39
|
+
where: eq(col('id', 'jr'), f('ref'))
|
|
40
|
+
})));
|
|
41
|
+
let address = addressOf(jf);
|
|
42
|
+
// Any of the names a row may hold for a word (./names.ts).
|
|
43
|
+
let any = (names)=>names.map((n)=>lit(n));
|
|
44
|
+
// One field's value as JSON: through its property's `text` where the store
|
|
45
|
+
// keeps it in another form, and as recorded otherwise.
|
|
46
|
+
let fieldOf = (derived, named)=>{
|
|
47
|
+
let recorded = fn('json', jf('value'));
|
|
48
|
+
let texts = Object.entries(derived).flatMap(([key, d])=>d.text ? [
|
|
49
|
+
[
|
|
50
|
+
key.split('.'),
|
|
51
|
+
d.text
|
|
52
|
+
]
|
|
53
|
+
] : []);
|
|
54
|
+
return texts.length ? when(texts.map(([[comp, prop], text])=>[
|
|
55
|
+
and(among(jc('component'), any(named.comps(comp))), among(jf('field'), any(named.props(comp, prop)))),
|
|
56
|
+
fn('coalesce', fn('json_quote', text(address)), recorded)
|
|
57
|
+
]), recorded) : recorded;
|
|
58
|
+
};
|
|
59
|
+
// The `_comp` a change's component names, where the graph has one: its
|
|
60
|
+
// column, and the join that reads it. The join also says the names a row may
|
|
61
|
+
// have recorded for that `_comp` (`recordedAt`), which the first term implies:
|
|
62
|
+
// so `._change.comp=<_comp>` seeks the index on `component` from the `_comp`
|
|
63
|
+
// row, and does not walk the journal back to front testing each change, which
|
|
64
|
+
// for a component written rarely is the whole journal.
|
|
65
|
+
let described = (vocab, named)=>vocab.comp('_comp') ? {
|
|
66
|
+
comp: cc('id'),
|
|
67
|
+
joins: [
|
|
68
|
+
left(table('entity', 'cc'), and(eq(cc('eid'), named.rowOf(jc('component'))), among(jc('component'), named.recordedAt(cc('eid')))))
|
|
69
|
+
]
|
|
70
|
+
} : {
|
|
71
|
+
comp: lit(null),
|
|
72
|
+
joins: []
|
|
73
|
+
};
|
|
74
|
+
// One change's present after-images as one object, keyed by label. The field
|
|
75
|
+
// rows are read in the order they were written, through their (change,
|
|
76
|
+
// ordinal) index.
|
|
77
|
+
let valueOf = (derived, named)=>when([
|
|
78
|
+
[
|
|
79
|
+
eq(jc('operation'), lit('upsert')),
|
|
80
|
+
sub(select({
|
|
81
|
+
cols: [
|
|
82
|
+
fn('json_group_object', named.propLabelOf(jf('field')), fieldOf(derived, named))
|
|
83
|
+
],
|
|
84
|
+
from: table('journal_field', 'jf'),
|
|
85
|
+
where: and(eq(jf('change'), jc('id')), eq(jf('present'), lit(1)))
|
|
86
|
+
}))
|
|
87
|
+
]
|
|
88
|
+
]);
|
|
89
|
+
// What each record tells of, by the record's own id (`id` for a change, `tx`
|
|
90
|
+
// for a transaction): every change's entity and component, by label. A scoped
|
|
91
|
+
// read sees a change when it may see that component of that entity, and a
|
|
92
|
+
// transaction when it may see one of its changes.
|
|
93
|
+
let tells = (id, named)=>select({
|
|
94
|
+
cols: [
|
|
95
|
+
as(jc(id), 'entity'),
|
|
96
|
+
as(jc('entity'), 'about'),
|
|
97
|
+
as(named.compLabelOf(jc('component')), 'component')
|
|
98
|
+
],
|
|
99
|
+
from: table('journal_change', 'jc')
|
|
100
|
+
});
|
|
101
|
+
// Component `comp` as the journal last told each entity held it (@yaks/sql
|
|
102
|
+
// `Backing.held`), which is how a scoped read judges a deleted entity: an
|
|
103
|
+
// entity whose newest change to it wrote it, and each property's newest
|
|
104
|
+
// after-image, null where that is the tombstone a removal wrote. A reference
|
|
105
|
+
// is read back to the referent's integer id, as the component's table keeps
|
|
106
|
+
// it. Start with the owner, then seek its latest change: starting with changes
|
|
107
|
+
// let a scoped get walk their history or build a bloom filter over the journal
|
|
108
|
+
// before testing two owners. This single-table relation also folds into a
|
|
109
|
+
// LEFT JOIN without materializing every owner's history.
|
|
110
|
+
let heldIn = (named)=>(comp, props)=>{
|
|
111
|
+
let jn = (c)=>col(c, 'jn');
|
|
112
|
+
let jl = (c)=>col(c, 'jl');
|
|
113
|
+
let owner = col('id', '__held');
|
|
114
|
+
let ours = (c)=>and(eq(c('entity'), owner), among(c('component'), any(named.comps(comp))));
|
|
115
|
+
let newest = ({ name, ref })=>sub(select({
|
|
116
|
+
cols: [
|
|
117
|
+
when([
|
|
118
|
+
[
|
|
119
|
+
eq(jl('present'), lit(1)),
|
|
120
|
+
ref ? sub(select({
|
|
121
|
+
cols: [
|
|
122
|
+
col('id', 'jr')
|
|
123
|
+
],
|
|
124
|
+
from: table('entity', 'jr'),
|
|
125
|
+
where: eq(col('eid', 'jr'), fn('json_extract', jl('value'), lit('$')))
|
|
126
|
+
})) : addressOf(jl)
|
|
127
|
+
]
|
|
128
|
+
])
|
|
129
|
+
],
|
|
130
|
+
from: table('journal_field', 'jl'),
|
|
131
|
+
joins: [
|
|
132
|
+
join(table('journal_change', 'jn'), eq(jn('id'), jl('change')))
|
|
133
|
+
],
|
|
134
|
+
where: and(ours(jn), among(jl('field'), any(named.props(comp, name)))),
|
|
135
|
+
order: [
|
|
136
|
+
desc(jl('id'))
|
|
137
|
+
],
|
|
138
|
+
limit: lit(1)
|
|
139
|
+
}));
|
|
140
|
+
return select({
|
|
141
|
+
cols: [
|
|
142
|
+
as(owner, 'entity'),
|
|
143
|
+
...props.map((p)=>as(newest(p), p.as))
|
|
144
|
+
],
|
|
145
|
+
from: table('entity', '__held'),
|
|
146
|
+
where: exists(select({
|
|
147
|
+
cols: [
|
|
148
|
+
lit(1)
|
|
149
|
+
],
|
|
150
|
+
from: table('journal_change', 'jc'),
|
|
151
|
+
where: and(eq(jc('operation'), lit('upsert')), eq(jc('id'), sub(select({
|
|
152
|
+
cols: [
|
|
153
|
+
fn('max', jn('id'))
|
|
154
|
+
],
|
|
155
|
+
from: table('journal_change', 'jn'),
|
|
156
|
+
where: ours(jn)
|
|
157
|
+
}))))
|
|
158
|
+
}))
|
|
159
|
+
});
|
|
160
|
+
};
|
|
161
|
+
/** The rows `_tx` and `_change` are read from: the journal's tables, a value
|
|
162
|
+
* the store keeps in another form read through `derived`, the store's read
|
|
163
|
+
* overrides. `_change` also tells what each entity last held (`held`). One
|
|
164
|
+
* registry per vocabulary and overrides, so every store given them compiles
|
|
165
|
+
* its reads once (@yaks/sql `Backing`). */ export let backed = (vocab, derived = NONE)=>{
|
|
166
|
+
let byDerived = registries.get(vocab);
|
|
167
|
+
if (!byDerived) registries.set(vocab, byDerived = new WeakMap());
|
|
168
|
+
let got = byDerived.get(derived);
|
|
169
|
+
if (!got) byDerived.set(derived, got = registry(vocab, derived));
|
|
170
|
+
return got;
|
|
171
|
+
};
|
|
172
|
+
let NONE = {};
|
|
173
|
+
let registries = new WeakMap();
|
|
174
|
+
let registry = (vocab, derived)=>{
|
|
175
|
+
let named = names(vocab);
|
|
176
|
+
let { comp, joins } = described(vocab, named);
|
|
177
|
+
let value = valueOf(derived, named);
|
|
178
|
+
return {
|
|
179
|
+
_tx: {
|
|
180
|
+
about: tells('tx', named),
|
|
181
|
+
rows: select({
|
|
182
|
+
cols: [
|
|
183
|
+
as(col('id'), 'entity'),
|
|
184
|
+
as(col('id'), 'seq'),
|
|
185
|
+
as(col('ts'), 'at'),
|
|
186
|
+
as(col('actor'), 'by'),
|
|
187
|
+
as(col('via'), 'via'),
|
|
188
|
+
as(col('host'), 'host'),
|
|
189
|
+
as(col('trace'), 'note')
|
|
190
|
+
],
|
|
191
|
+
from: table('journal_tx')
|
|
192
|
+
})
|
|
193
|
+
},
|
|
194
|
+
_change: {
|
|
195
|
+
about: tells('id', named),
|
|
196
|
+
held: heldIn(named),
|
|
197
|
+
rows: select({
|
|
198
|
+
cols: [
|
|
199
|
+
as(jc('id'), 'entity'),
|
|
200
|
+
as(jc('tx'), 'tx'),
|
|
201
|
+
as(jc('entity'), 'target'),
|
|
202
|
+
as(comp, 'comp'),
|
|
203
|
+
as(named.compLabelOf(jc('component')), 'component'),
|
|
204
|
+
as(value, 'value')
|
|
205
|
+
],
|
|
206
|
+
from: table('journal_change', 'jc'),
|
|
207
|
+
joins
|
|
208
|
+
}),
|
|
209
|
+
// `component` is a label read from what a row recorded, which no index
|
|
210
|
+
// holds: compared row by row, `._change.component=step` walked the
|
|
211
|
+
// box's whole journal, past 10 s (T-5375). The names that may read as
|
|
212
|
+
// it seek the index on `component`, and each row found is then tested.
|
|
213
|
+
select: {
|
|
214
|
+
component: (labels)=>select({
|
|
215
|
+
cols: [
|
|
216
|
+
jc('id')
|
|
217
|
+
],
|
|
218
|
+
from: table('journal_change', 'jc'),
|
|
219
|
+
where: and(among(jc('component'), named.labeled(labels)), among(named.compLabelOf(jc('component')), labels))
|
|
220
|
+
})
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
};
|
|
224
|
+
};
|
|
225
|
+
//# sourceMappingURL=backed.js.map
|
package/backed.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"backed.js","sources":["./backed.ts"],"names":[],"mappings":"AAAA,qEAAqE;AACrE,8EAA8E;AAC9E,2EAA2E;AAC3E,+EAA+E;AAC/E,8EAA8E;AAC9E,0EAA0E;AAC1E,0EAA0E;AAC1E,EAAE;AACF,qEAAqE;AACrE,+EAA+E;AAC/E,8EAA8E;AAC9E,uEAAuE;AACvE,+EAA+E;AAC/E,0EAA0E;AAC1E,yEAAyE;AACzE,gDAAgD;AAChD,EAAE;AACF,+EAA+E;AAC/E,8EAA8E;AAC9E,4EAA4E;AAC5E,qEAAqE;AACrE,yEAAyE;AACzE,4EAA4E;AAC5E,6EAA6E;AAC7E,+EAA+E;AAC/E,gEAAgE;AAEhE,SACE,KAAK,EACL,GAAG,EACH,EAAE,EACF,GAAG,EAEH,IAAI,EACJ,EAAE,EACF,MAAM,EAEN,EAAE,EACF,IAAI,EACJ,IAAI,EACJ,GAAG,EAEH,MAAM,EACN,GAAG,EACH,KAAK,EACL,IAAI,8BAC4B;AAGlC,SAAqB,KAAK,qBAAoB;AAE9C,IAAI,KAAK,CAAC,IAAc,IAAI,GAAG;AAC/B,IAAI,KAAK,CAAC,IAAc,IAAI,GAAG;AAC/B,IAAI,KAAK,CAAC,IAAc,IAAI,GAAG;AAE/B,2EAA2E;AAC3E,8DAA8D;AAC9D,IAAI,YAAY,CAAC,IACf,GACE,YACA,GAAG,gBAAgB,EAAE,UAAU,IAAI,OACnC,IAAI,OAAO;IACT,MAAM;MAAC,IAAI,OAAO;KAAM;IACxB,MAAM,MAAM,UAAU;IACtB,OAAO,GAAG,IAAI,MAAM,OAAO,EAAE;EAC/B;AAEJ,IAAI,UAAU,UAAU;AAExB,2DAA2D;AAC3D,IAAI,MAAM,CAAC,QAAoB,MAAM,GAAG,CAAC,CAAC,IAAM,IAAI;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