@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
package/_dist/feed.d.ts
ADDED
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import type { Bundle, Plugin } from "@yaks/graph";
|
|
2
|
+
import { type Row, type Stmt } from "@yaks/sql";
|
|
3
|
+
import type { Rows } from "./log.js";
|
|
4
|
+
/** How long a commit stays in the feed, in ms: far longer than a follower
|
|
5
|
+
* that is still running ever falls behind. */ export declare let KEEP: any;
|
|
6
|
+
/** The feed's table, which a writing host adds with the rest of its composed
|
|
7
|
+
* schema (./graph.ts `schema`). Its id is the cursor. */ export declare let feedDdl: () => Stmt[];
|
|
8
|
+
/**
|
|
9
|
+
* What a commit wrote to one entity, as the feed keeps it: the properties it
|
|
10
|
+
* wrote of each component, `null` for a component it removed, or `$delete`
|
|
11
|
+
* where the entity went. The values stay where the graph keeps them, and a
|
|
12
|
+
* follower reads them there ({@link filled}).
|
|
13
|
+
*/ export type Wrote = {
|
|
14
|
+
entity: Bundle['entity'];
|
|
15
|
+
$delete?: true;
|
|
16
|
+
[comp: string]: string[] | null | true | Bundle['entity'] | undefined;
|
|
17
|
+
};
|
|
18
|
+
/**
|
|
19
|
+
* A commit as the feed keeps it: one {@link Wrote} per entity.
|
|
20
|
+
*
|
|
21
|
+
* ```ts
|
|
22
|
+
* import { assertEquals } from '@std/assert'
|
|
23
|
+
*
|
|
24
|
+
* assertEquals(
|
|
25
|
+
* wrote([
|
|
26
|
+
* { entity: { eid: 'p1' }, page: { title: 'Hi' }, $was: {} },
|
|
27
|
+
* { entity: { eid: 'p1' }, updated: { by: 'ada' }, pin: null },
|
|
28
|
+
* { entity: { eid: 'n1' }, $delete: true },
|
|
29
|
+
* ]),
|
|
30
|
+
* [
|
|
31
|
+
* { entity: { eid: 'p1' }, page: ['title'], updated: ['by'], pin: null },
|
|
32
|
+
* { entity: { eid: 'n1' }, $delete: true },
|
|
33
|
+
* ],
|
|
34
|
+
* )
|
|
35
|
+
* ```
|
|
36
|
+
*/ export declare let wrote: (bundles: Bundle[]) => Wrote[];
|
|
37
|
+
/** Reads entities as they stand, carrying the components named (@yaks/graph
|
|
38
|
+
* `Storage.get`). */ export type Read = (eids: string[], comps: string[]) => Bundle[] | Promise<Bundle[]>;
|
|
39
|
+
/**
|
|
40
|
+
* The commits a follower heard, each entity's bundle holding what the graph
|
|
41
|
+
* holds now of what the commit wrote, in one read for all of them. A
|
|
42
|
+
* component the entity no longer holds, or an entity since deleted, reads as
|
|
43
|
+
* removed, and a property it no longer holds as `null`: the later commit that
|
|
44
|
+
* removed it is heard too, so the patches still end where the graph is.
|
|
45
|
+
*
|
|
46
|
+
* ```ts
|
|
47
|
+
* import { assertEquals } from '@std/assert'
|
|
48
|
+
*
|
|
49
|
+
* let now = [{ entity: { eid: 'p1' }, page: { title: 'Hi', text: 'x' } }]
|
|
50
|
+
* assertEquals(
|
|
51
|
+
* filled([[
|
|
52
|
+
* { entity: { eid: 'p1' }, page: ['title', 'lede'], pin: ['at'] },
|
|
53
|
+
* { entity: { eid: 'n1' }, $delete: true },
|
|
54
|
+
* ]], () => now),
|
|
55
|
+
* [[
|
|
56
|
+
* { entity: { eid: 'p1' }, page: { title: 'Hi', lede: null }, pin: null },
|
|
57
|
+
* { entity: { eid: 'n1' }, $delete: true },
|
|
58
|
+
* ]],
|
|
59
|
+
* )
|
|
60
|
+
* ```
|
|
61
|
+
*/ export declare let filled: (txs: Wrote[][], read: Read) => Bundle[][] | Promise<Bundle[][]>;
|
|
62
|
+
/** One commit another host made: its place in the feed, and what it wrote
|
|
63
|
+
* ({@link wrote}). */ export type Heard = {
|
|
64
|
+
seq: number;
|
|
65
|
+
wrote: Wrote[];
|
|
66
|
+
};
|
|
67
|
+
/** The feed bound to one store, as one host. */ export type FeedRows = Row[] | Promise<Row[]>;
|
|
68
|
+
type Answer<T, V> = T extends Promise<unknown> ? Promise<V> : V;
|
|
69
|
+
type Page = {
|
|
70
|
+
seq: number;
|
|
71
|
+
wrote?: Wrote[];
|
|
72
|
+
}[];
|
|
73
|
+
export type Feed<T extends FeedRows = FeedRows> = {
|
|
74
|
+
/** who this feed writes as: the one host (a graph opened by one process or
|
|
75
|
+
* thread) whose commits it records, so a follower can skip its own */ host: string;
|
|
76
|
+
/** write one commit down inside the caller's own transaction, and prune
|
|
77
|
+
* what has been kept long enough */ write: (wrote: Wrote[]) => void;
|
|
78
|
+
/** the newest commit's seq, or 0 */ tip: () => Answer<T, number>;
|
|
79
|
+
/** the commits after a cursor, oldest first, at most `n`; one this host
|
|
80
|
+
* made comes without what it wrote */ since: (cursor: number, n: number) => Answer<T, Page>;
|
|
81
|
+
};
|
|
82
|
+
/** How a feed is bound to a store. */ export type FeedOpts<T extends FeedRows = Row[]> = {
|
|
83
|
+
/** the statement runner, over the graph's own transaction */ rows: Rows;
|
|
84
|
+
/** committed reads, where another connection answers them; writes stay on
|
|
85
|
+
* `rows`, inside the committing transaction */ read?: (statement: Stmt) => T;
|
|
86
|
+
/** the host it writes as (default: a fresh id) */ host?: string;
|
|
87
|
+
/** how long a commit is kept, in ms (default {@link KEEP}) */ keep?: number;
|
|
88
|
+
/** the clock, in ms (default `Date.now`) */ now?: () => number;
|
|
89
|
+
};
|
|
90
|
+
/** Bind the feed to a store: `feedOf({ rows: (s) => db.query(s) })`. */ export declare let feedOf: <T extends FeedRows = Row[]>(o: FeedOpts<T>) => Feed<T>;
|
|
91
|
+
/** The plugin that writes each commit into the feed, as the last thing inside
|
|
92
|
+
* its transaction. */ export declare let feeder: (f: Feed) => Plugin;
|
|
93
|
+
/** How a follower reads. */ export type FollowOpts = {
|
|
94
|
+
/** the seq to start after (default: the feed's tip when the follower is
|
|
95
|
+
* made, so it reports only what commits from then on) */ from?: number;
|
|
96
|
+
/** the most commits one page reads, so a burst of writes elsewhere is
|
|
97
|
+
* worked through a page at a time (default 100) */ page?: number;
|
|
98
|
+
/** told how many commits were pruned before this follower read them: it
|
|
99
|
+
* was away longer than they are kept */ missed?: (n: number) => void;
|
|
100
|
+
};
|
|
101
|
+
/**
|
|
102
|
+
* A follower of a feed: each call answers the commits made since the last call
|
|
103
|
+
* by any host but the feed's own, oldest first. The cursor moves past this
|
|
104
|
+
* host's own commits without reading them, and past another's only once it is
|
|
105
|
+
* read: a read that fails ends the call with what came before it, and the next
|
|
106
|
+
* call starts again at the one that failed, throwing if it still fails.
|
|
107
|
+
*/ export declare let follow: <T extends FeedRows>(f: Feed<T>, opts?: FollowOpts) => () => Answer<T, Heard[]>;
|
|
108
|
+
//# sourceMappingURL=feed.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"feed.d.ts","sources":["../feed.ts"],"names":[],"mappings":"AAuBA,cAAc,MAAM,EAAE,MAAM,2BAAgC;AAE5D,SAUE,KAAK,GAAG,EAER,KAAK,IAAI,yBAIkB;AAC7B,cAAc,IAAI,mBAAkB;AAIpC;4CAC4C,GAC5C,OAAO,YAAI,UAAkB;AAE7B;uDACuD,GACvD,OAAO,YAAI,eAAc,OAUvB;AAEF;;;;;CAKC,GACD,YAAY;EACV,QAAQ,OAAO;EACf,UAAU,IAAI;GACb,MAAM,MAAM,GAAG,MAAM,KAAK,IAAI,GAAG,IAAI,GAAG,OAAO,YAAY,SAAS;;AAGvE;;;;;;;;;;;;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KAAK,IACR,OAAM,qBACC,OAAO,GAAG,SA6ClB"}
|
package/_dist/graph.d.ts
ADDED
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import type { Bundle, News, Plugin } from "@yaks/graph";
|
|
2
|
+
import { type Derived, type History, type Row, type Statements, type Stmt } from "@yaks/sql";
|
|
3
|
+
import type { Vocab } from "@yaks/vocab";
|
|
4
|
+
import { type Log } from "./mod.js";
|
|
5
|
+
import { type Feed, type Read } from "./feed.js";
|
|
6
|
+
/** What a log is bound to: the host's storage, its vocabulary, which names
|
|
7
|
+
* what the log's rows record (./log.ts `LogOpts.vocab`), and the read
|
|
8
|
+
* overrides its store was opened with, so a value the store keeps in another
|
|
9
|
+
* form reads back the way the graph reads it (./log.ts `LogOpts.derived`). */ export type Bound = {
|
|
10
|
+
storage: {
|
|
11
|
+
statements?: Statements;
|
|
12
|
+
};
|
|
13
|
+
vocab: Vocab;
|
|
14
|
+
derived?: Derived;
|
|
15
|
+
reader?: {
|
|
16
|
+
statements?: {
|
|
17
|
+
query: (statement: Stmt) => Row[] | Promise<Row[]>;
|
|
18
|
+
};
|
|
19
|
+
storage?: {
|
|
20
|
+
get: Read;
|
|
21
|
+
};
|
|
22
|
+
tool?: (name: string, call: Bundle) => Promise<Bundle[]>;
|
|
23
|
+
};
|
|
24
|
+
};
|
|
25
|
+
/** The log bound to a host: the three tables, read and written over that
|
|
26
|
+
* host's storage transaction, as that host. The same host gets the same log. */ export declare let logFor: (host: Bound) => Log;
|
|
27
|
+
/** The feed bound to a host, written as the host its log writes as. The same
|
|
28
|
+
* host gets the same feed. */ export declare let feedFor: (host: Bound) => Feed;
|
|
29
|
+
/** The journal's tables and the feed's, and the words of the host's
|
|
30
|
+
* vocabulary (./names.ts), which a writing host adds with the rest of its
|
|
31
|
+
* composed schema; a store an older journal made gains the columns it
|
|
32
|
+
* predates there (@yaks/sqlite `grow`). */ export declare let schema: (host: {
|
|
33
|
+
vocab: Vocab;
|
|
34
|
+
}) => Stmt[];
|
|
35
|
+
/**
|
|
36
|
+
* Which aspects of history a config switches on (D-130964), each covering the
|
|
37
|
+
* components not declared `journal: false`:
|
|
38
|
+
*
|
|
39
|
+
* - `attribution`: a `journal_change` row per component each transaction
|
|
40
|
+
* wrote or removed, under its `journal_tx` row (when, by whom, through what).
|
|
41
|
+
* - `versions`: the store keeps every version a write replaces (@yaks/sqlite
|
|
42
|
+
* `History`), each naming its transaction.
|
|
43
|
+
*
|
|
44
|
+
* Naming either turns history to them, each on unless set false:
|
|
45
|
+
* `{"use": "@yaks/journal", "with": {"versions": true}}`. Naming neither is
|
|
46
|
+
* the journal before versions, attribution with every value as a
|
|
47
|
+
* `journal_field` row, until the box's journal moves into versions.
|
|
48
|
+
* `{"with": {"components": ["space", "member"]}}` keeps the history of those
|
|
49
|
+
* components alone. `{"with": {"feed": false}}` writes no feed, for a store
|
|
50
|
+
* no other host writes to (a Durable Object is its store's only host).
|
|
51
|
+
*/ export type Aspects = {
|
|
52
|
+
attribution: boolean;
|
|
53
|
+
versions: boolean;
|
|
54
|
+
values: boolean;
|
|
55
|
+
};
|
|
56
|
+
export declare let aspects: (options?: Record<string, unknown>) => Aspects;
|
|
57
|
+
/** What a store keeps versions with, where `versions` is on: the statement
|
|
58
|
+
* that takes a transaction's id, as a `journal_tx` row whose writer the
|
|
59
|
+
* journal fills in as it records the transaction, and the newest one's. */ export declare let history: (options?: Record<string, unknown>) => History | undefined;
|
|
60
|
+
/** A store keeping versions requires the journal from then on: a writer
|
|
61
|
+
* without it would change live rows and keep nothing they replaced. */ export declare let required: (options?: Record<string, unknown>) => boolean;
|
|
62
|
+
/** Bind the hooks over the tables the installer prepared: the journal,
|
|
63
|
+
* recording what the host's vocabulary keeps as history, as its aspects say,
|
|
64
|
+
* and the feed, carrying every commit to the other hosts. */ export declare let plugins: (host: Bound, options?: Record<string, unknown>) => Plugin[];
|
|
65
|
+
/** How often a host looks for what other hosts committed, in ms, unless the
|
|
66
|
+
* config says (`{"use": "@yaks/journal", "with": {"every": 50}}`). */ export declare let EVERY: number;
|
|
67
|
+
/** What a feed hands what it heard to, all of it at once; it may take its
|
|
68
|
+
* time, and what is heard meanwhile waits for the next call. */ export type Each = (news: News) => void | Promise<void>;
|
|
69
|
+
/** How many times news the consumer failed on is offered again before it is
|
|
70
|
+
* reported and passed over, so news that can never be taken does not hold
|
|
71
|
+
* back everything after it; the consumer is then told it missed some. */ export declare let TRIES: number;
|
|
72
|
+
/**
|
|
73
|
+
* The commits other hosts made to this store, handed to `each` as bundles of
|
|
74
|
+
* what each wrote, its values read from the graph as they stand (./feed.ts
|
|
75
|
+
* `filled`), oldest first, from the moment `each` is given until the
|
|
76
|
+
* returned function is called or the host stops. What a subscription registry
|
|
77
|
+
* or a cache is fed so it also sees writes its own graph did not make: a `yak`
|
|
78
|
+
* command's beside `yak serve`, or a worker's serving the effects role.
|
|
79
|
+
* Whatever goes wrong on the way is the host's to report.
|
|
80
|
+
*
|
|
81
|
+
* The feed is read every `every` ms however long the consumer takes, so a
|
|
82
|
+
* slow consumer is handed more at once rather than left behind what the store
|
|
83
|
+
* keeps (./feed.ts `KEEP`). What still never reaches it (a process asleep past
|
|
84
|
+
* that, news passed over) comes with `missed`, and the consumer reads again
|
|
85
|
+
* what it holds: it ends up correct on its own.
|
|
86
|
+
*
|
|
87
|
+
* A look reads through the host's reader, and the consumer may take its time:
|
|
88
|
+
* stopping cancels the next look, and the host's release (`defer`) waits out
|
|
89
|
+
* the one under way, so no read outlives the plugins into a closed reader.
|
|
90
|
+
* A host whose options say `feed: false` is offered none.
|
|
91
|
+
*/ export declare let feed: (host: Bound & {
|
|
92
|
+
storage: {
|
|
93
|
+
get: Read;
|
|
94
|
+
};
|
|
95
|
+
stopping: AbortSignal;
|
|
96
|
+
report?: (error: unknown) => void | Promise<void>;
|
|
97
|
+
defer?: (release: () => void | Promise<void>) => void;
|
|
98
|
+
}, options?: {
|
|
99
|
+
every?: number;
|
|
100
|
+
timer?: Timer;
|
|
101
|
+
feed?: boolean;
|
|
102
|
+
}) => ((each: Each) => () => void) | undefined;
|
|
103
|
+
/** What a feed schedules its next look with, and how it cancels it. */ export type Timer = (fn: () => void | Promise<void>, ms: number) => () => void;
|
|
104
|
+
//# sourceMappingURL=graph.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"graph.d.ts","sources":["../graph.ts"],"names":[],"mappings":"AAYA,cAAc,MAAM,EAAE,IAAI,EAAE,MAAM,2BAAgC;AAClE,SAGE,KAAK,OAAO,EAEZ,KAAK,OAAO,EAEZ,KAAK,GAAG,EAER,KAAK,UAAU,EAEf,KAAK,IAAI,yBAEkB;AAC7B,cAAc,KAAK,2BAAgC;AACnD,SAGE,KAAK,GAAG,mBAIO;AACjB,SACE,KAAK,IAAI,EAMT,KAAK,IAAI,oBAEO;AAKlB;;;4EAG4E,GAC5E,YAAY;EACV;IAAW,aAAa;;EACxB,OAAO;EACP,UAAU;EACV;IACE;MAAe,QAAQ,WAAW,SAAS,QAAQ,QAAQ;;IAC3D;MAAY,KAAK;;IACjB,QAAQ,MAAM,MAAM,EAAE,MAAM,WAAW,QAAQ;;;AASnD;8EAC8E,GAC9E,OAAO,YAAI,SAAU,MAAM,UAAQ,IAalC;AAED;4BAC4B,GAC5B,OAAO,YAAI,UAAW,MAAM,UAAQ,KAenC;AAED;;;yCAGyC,GACzC,OAAO,YAAI,SAAU;EAAQ,OAAO;MAAU,OAG7C;AAED;;;;;;;;;;;;;;;;CAgBC,GACD,YAAY;EACV,aAAa,OAAO;EACpB,UAAU,OAAO;EACjB,QAAQ,OAAO;;AAGjB,OAAO,YAAI,UAAW,UAAS,OAAO,MAAM,EAAE,OAAO,MAAS,QAOJ;AAE1D;;yEAEyE,GACzE,OAAO,YAAI,UAAW,UAAU,OAAO,MAAM,EAAE,OAAO,MAAI,UAAU,SAAS,CAe9D;AAEf;qEACqE,GACrE,OAAO,YAAI,WAAY,UAAU,OAAO,MAAM,EAAE,OAAO,MAAI,OAAO,CACvC;AAE3B;;2DAE2D,GAC3D,OAAO,YAAI,UACT,MAAM,OACN,UAAU,OAAO,MAAM,EAAE,OAAO,MAC/B,SAiBF;AAED;oEACoE,GACpE,OAAO,YAAI,cAAW;AAEtB;8DAC8D,GAC9D,YAAY,QAAQ,MAAM,SAAS,IAAI,GAAG,QAAQ,IAAI;AAEtD;;uEAEuE,GACvE,OAAO,YAAI,cAAS;AAEpB;;;;;;;;;;;;;;;;;;;CAmBC,GACD,OAAO,YAAI,OACT,MAAM;EACJ;IAAW,KAAK;;EAChB,UAAU;EACV,UAAU,OAAO,OAAO,KAAK,IAAI,GAAG,QAAQ,IAAI;EAChD,SAAS,eAAe,IAAI,GAAG,QAAQ,IAAI,MAAM,IAAI;GAEvD;EAAW,QAAQ,MAAM;EAAE,QAAQ;EAAO,OAAO,OAAO;QACrD,MAAM,eAAe,IAAI,IAAI,SAAS,CA+ExC;AAEH,qEAAqE,GACrE,YAAY,SACV,UAAU,IAAI,GAAG,QAAQ,IAAI,GAC7B,IAAI,MAAM,WACD,IAAI"}
|
package/_dist/kept.d.ts
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What a day's `kept` row says (./service.ts), as the History page reads it:
|
|
3
|
+
* which tables are history, what history kept, how many changes it held, and
|
|
4
|
+
* what it kept per change and per day between two measurements. Pure.
|
|
5
|
+
*
|
|
6
|
+
* History is the journal's tables (`journal_*`) and each component's
|
|
7
|
+
* versions, which the store keeps beside the component's table as
|
|
8
|
+
* `<comp>$versions`.
|
|
9
|
+
*
|
|
10
|
+
* @module
|
|
11
|
+
*/ import type { Bundle } from "@yaks/graph";
|
|
12
|
+
/** One day's measurement. */ export type Kept = {
|
|
13
|
+
day: string;
|
|
14
|
+
at: string;
|
|
15
|
+
bytes: number;
|
|
16
|
+
free: number;
|
|
17
|
+
tables: Record<string, [bytes: number, rows: number]>;
|
|
18
|
+
/** the changes the journal held, by component name */ changes?: Record<string, number>;
|
|
19
|
+
};
|
|
20
|
+
/** The table the journal keeps a row in per change. */ export declare let CHANGES: string;
|
|
21
|
+
/** A bundle's `kept`, if it has one. */ export declare let keptOf: (b: Bundle) => Kept | undefined;
|
|
22
|
+
/**
|
|
23
|
+
* Whether a table is history's, and the component whose versions it holds.
|
|
24
|
+
*
|
|
25
|
+
* ```ts
|
|
26
|
+
* import { historic, versioned } from './kept.ts'
|
|
27
|
+
* import { equal } from '@yaks/testing'
|
|
28
|
+
*
|
|
29
|
+
* equal([historic('journal_field'), historic('doc$versions'), historic('doc')], [true, true, false])
|
|
30
|
+
* equal([versioned('doc$versions'), versioned('doc')], ['doc', undefined])
|
|
31
|
+
* ```
|
|
32
|
+
*/ export declare let historic: (table: string) => boolean;
|
|
33
|
+
/** The component a `<comp>$versions` table keeps the versions of. */ export declare let versioned: (table: string) => string | undefined;
|
|
34
|
+
/**
|
|
35
|
+
* The bytes history kept, and the changes the journal held.
|
|
36
|
+
*
|
|
37
|
+
* ```ts
|
|
38
|
+
* import { changes, history, type Kept } from './kept.ts'
|
|
39
|
+
* import { equal } from '@yaks/testing'
|
|
40
|
+
*
|
|
41
|
+
* let k: Kept = { day: '2026-10-21', at: '', bytes: 100, free: 0, tables: { doc: [10, 2], journal_change: [30, 3], doc$versions: [20, 4] } }
|
|
42
|
+
* equal([history(k), changes(k)], [50, 3])
|
|
43
|
+
* ```
|
|
44
|
+
*/ export declare let history: (k: Kept) => number;
|
|
45
|
+
/** The changes the journal held. */ export declare let changes: (k: Kept) => number;
|
|
46
|
+
/**
|
|
47
|
+
* Between an older measurement and a newer one: the bytes history kept per
|
|
48
|
+
* change written between them, and `of`'s growth a day. Undefined where
|
|
49
|
+
* nothing was written between them.
|
|
50
|
+
*
|
|
51
|
+
* ```ts
|
|
52
|
+
* import { history, type Kept, perChange, perDay } from './kept.ts'
|
|
53
|
+
* import { equal } from '@yaks/testing'
|
|
54
|
+
*
|
|
55
|
+
* let a: Kept = { day: '2026-10-20', at: '2026-10-20T04:00:00Z', bytes: 1000, free: 0, tables: { journal_change: [100, 10] } }
|
|
56
|
+
* let b: Kept = { day: '2026-10-22', at: '2026-10-22T04:00:00Z', bytes: 3000, free: 0, tables: { journal_change: [1570, 20] } }
|
|
57
|
+
* equal(perChange(a, b), 147)
|
|
58
|
+
* equal(perDay(a, b, history), 735)
|
|
59
|
+
* equal(perChange(a, a), undefined)
|
|
60
|
+
* ```
|
|
61
|
+
*/ export declare let perChange: (older: Kept, newer: Kept) => number | undefined;
|
|
62
|
+
/** `of`'s growth a day, between an older measurement and a newer one. */ export declare let perDay: (older: Kept, newer: Kept, of: (k: Kept) => number) => number | undefined;
|
|
63
|
+
//# sourceMappingURL=kept.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"kept.d.ts","sources":["../kept.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;CAUC,GACD,cAAc,MAAM,2BAAgC;AAEpD,2BAA2B,GAC3B,YAAY;EACV,KAAK,MAAM;EACX,IAAI,MAAM;EACV,OAAO,MAAM;EACb,MAAM,MAAM;EACZ,QAAQ,OAAO,MAAM,GAAG,OAAO,MAAM,EAAE,MAAM,MAAM;EACnD,oDAAoD,GACpD,UAAU,OAAO,MAAM,EAAE,MAAM;;AAGjC,qDAAqD,GACrD,OAAO,YAAI,gBAA0B;AAIrC,sCAAsC,GACtC,OAAO,YAAI,SAAU,GAAG,WAAS,OAAO,SAAS,CAA8B;AAE/E;;;;;;;;;;CAUC,GACD,OAAO,YAAI,WAAY,OAAO,MAAM,KAAG,OAAO,CACM;AAEpD,mEAAmE,GACnE,OAAO,YAAI,YAAa,OAAO,MAAM,KAAG,MAAM,GAAG,SAAS,CACW;AAErE;;;;;;;;;;CAUC,GACD,OAAO,YAAI,UAAW,GAAG,SAAO,MAAM,CAInC;AAEH,kCAAkC,GAClC,OAAO,YAAI,UAAW,GAAG,SAAO,MAAM,CAA+B;AAErE;;;;;;;;;;;;;;;CAeC,GACD,OAAO,YAAI,YAAa,OAAO,MAAM,OAAO,SAAO,MAAM,GAAG,SAAS,CAGpE;AAED,uEAAuE,GACvE,OAAO,YAAI,SACT,OAAO,MACP,OAAO,MACP,KAAK,GAAG,SAAS,MAAM,KACtB,MAAM,GAAG,SAAS,CAGpB"}
|
package/_dist/log.d.ts
ADDED
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
import type { Bundle, Comp, Eid, Plugin } from "@yaks/graph";
|
|
2
|
+
import type { Vocab } from "@yaks/vocab";
|
|
3
|
+
import { type Derived, type Drop, type Row, type Stmt } from "@yaks/sql";
|
|
4
|
+
import type { Batch, Entry, Patch } from "./batch.js";
|
|
5
|
+
import { dec, enc } from "./value.js";
|
|
6
|
+
/** A statement, run for its rows: the whole of what the caller has to supply.
|
|
7
|
+
* A write goes through it too — `insert … returning id` returns a row. */ export type Rows = (s: Stmt) => Row[];
|
|
8
|
+
/**
|
|
9
|
+
* A property whose text the graph already stores once, under a content address.
|
|
10
|
+
* The journal then records that address and points at the graph's bytes instead
|
|
11
|
+
* of repeating them — the difference between a log that keeps every revision of
|
|
12
|
+
* every document and one that keeps a row per revision.
|
|
13
|
+
*/ export type Cas = {
|
|
14
|
+
/** is this property content-addressed? */ at: (comp: string, prop: string) => boolean;
|
|
15
|
+
/** store the text and return the id the journal records */ put: (text: string) => number;
|
|
16
|
+
/** the table holding the content, and its key and value columns */ table: string;
|
|
17
|
+
key: string;
|
|
18
|
+
value: string;
|
|
19
|
+
};
|
|
20
|
+
/**
|
|
21
|
+
* One recorded value a {@link Log.seek} found: where it sits in the log,
|
|
22
|
+
* the value as stored, and the content address when the property is
|
|
23
|
+
* content-addressed.
|
|
24
|
+
*/ export type Hit = {
|
|
25
|
+
/** the row's own id — what a redaction names to rewrite it */ field: number;
|
|
26
|
+
/** the entity the value was written about */ target: Eid | null;
|
|
27
|
+
/** the component and property it belongs to */ comp: string;
|
|
28
|
+
prop: string;
|
|
29
|
+
/** the transaction it was written by, and when that committed */ seq: number;
|
|
30
|
+
at: string;
|
|
31
|
+
/** the value as recorded, decoded */ value: unknown;
|
|
32
|
+
/** the content it refs, when the property is content-addressed */ content: Eid | null;
|
|
33
|
+
};
|
|
34
|
+
/** How the log is bound to a store. */ export type LogOpts = {
|
|
35
|
+
/** the statement runner — the whole of what the caller supplies */ rows: Rows;
|
|
36
|
+
/** the store's vocabulary: its rows record each word by the identity this
|
|
37
|
+
* gives it, and read back the label it gives (./names.ts) */ vocab: Vocab;
|
|
38
|
+
/** the entity table: where an eid becomes the integer the tables store */ spine?: {
|
|
39
|
+
table?: string;
|
|
40
|
+
id?: string;
|
|
41
|
+
eid?: string;
|
|
42
|
+
};
|
|
43
|
+
/** content-addressed properties, if the graph has any */ cas?: Cas;
|
|
44
|
+
/** the store's read overrides (@yaks/sql `Derived`, the ones it was opened
|
|
45
|
+
* with): a property whose stored value reads as something else — the
|
|
46
|
+
* address @yaks/blob keeps in place of a body — is recorded as stored and
|
|
47
|
+
* read back through its `text`, so history and undo hold what a reader of
|
|
48
|
+
* the graph sees and what a writer writes */ derived?: Derived;
|
|
49
|
+
/** who this log writes as: the one host (a graph opened by one process or
|
|
50
|
+
* thread) whose transactions it records, so history can tell one host's
|
|
51
|
+
* from another's. Default: a fresh id, one per log. */ host?: string;
|
|
52
|
+
};
|
|
53
|
+
export declare let ddl: (vocab: Vocab, spine?: string) => Stmt[];
|
|
54
|
+
/** What {@link ddl} raised, dropped, for a store that keeps no journal: its
|
|
55
|
+
* tables in the reverse of the order they were raised, so each goes before the
|
|
56
|
+
* one it refers to (SQLite drops a table still referred to by deleting its
|
|
57
|
+
* rows one at a time, and refuses where a reference holds one), and each
|
|
58
|
+
* table's indexes with it. */ export declare let dropDdl: () => Drop[];
|
|
59
|
+
/** Which rows a transaction is written down as, beside its own row: a
|
|
60
|
+
* `journal_change` row per component it wrote or removed (`changes`, the
|
|
61
|
+
* attribution aspect), and a `journal_field` row per value (`values`, the
|
|
62
|
+
* journal before versions). `seq` is the id the store's history took for it,
|
|
63
|
+
* whose row is already there to fill in. */ export type Recording = {
|
|
64
|
+
seq?: number;
|
|
65
|
+
changes?: boolean;
|
|
66
|
+
values?: boolean;
|
|
67
|
+
/** the branch the transaction wrote to, where it wrote to one */ branch?: number;
|
|
68
|
+
};
|
|
69
|
+
/** The log bound to one store: the writer, and the questions a journal is kept
|
|
70
|
+
* in order to answer. */ export type Log = {
|
|
71
|
+
/** Deliberately erase exact entities' recorded values, keeping other
|
|
72
|
+
* subjects in the same transaction. Returns removed logical values. */ purge: (eids: Eid[]) => Bundle[];
|
|
73
|
+
/** Candidate strings still named by surviving recorded values. */ retained: (values: string[]) => string[];
|
|
74
|
+
/** the host this log writes as ({@link LogOpts.host}) */ host: string;
|
|
75
|
+
/** write one transaction down inside the caller's own transaction; returns
|
|
76
|
+
* its seq. `as` writes it under the transaction id the store's history
|
|
77
|
+
* already took for it ({@link Recording.seq}); `record` says which of its
|
|
78
|
+
* rows to write. */ write: (meta: {
|
|
79
|
+
at: string;
|
|
80
|
+
by?: Eid | null;
|
|
81
|
+
via?: Eid | null;
|
|
82
|
+
note?: string | null;
|
|
83
|
+
}, applied: Patch[], record?: Recording) => number;
|
|
84
|
+
/** one transaction's operations, whole or cut to one entity, in applied
|
|
85
|
+
* order */ patches: (seq: number, target?: Eid) => Patch[];
|
|
86
|
+
/** the transactions that touched one entity, newest first, cut to it */ entries: (target: Eid, n?: number) => Entry[];
|
|
87
|
+
/** every transaction one instrument wrote, newest first, whole */ by: (via: Eid, n?: number) => Entry[];
|
|
88
|
+
/** the transactions after a cursor, oldest first, at most `n` when given */ since: (cursor?: number, n?: number) => Entry[];
|
|
89
|
+
/** one transaction as a Batch, both sides of every movement */ at: (seq: number) => Batch | undefined;
|
|
90
|
+
/** what happened to one entity, oldest first, as Batch */ history: (target: Eid, n?: number) => Batch[];
|
|
91
|
+
/** one entity's components as of just before a transaction */ before: (target: Eid, seq: number) => Record<string, Comp>;
|
|
92
|
+
/** the last transaction that touched one entity, or 0 */ latest: (target: Eid) => number;
|
|
93
|
+
/** every recorded write of one property, oldest first */ wrote: (comp: string, prop: string) => {
|
|
94
|
+
target: Eid;
|
|
95
|
+
value: unknown;
|
|
96
|
+
seq: number;
|
|
97
|
+
}[];
|
|
98
|
+
/** the highest seq the log holds, or 0 */ tip: () => number;
|
|
99
|
+
/** the changes the log holds, by the component each wrote or removed */ held: () => Record<string, number>;
|
|
100
|
+
/** has anything touched this entity since a given transaction? */ touchedSince: (target: Eid, seq: number) => boolean;
|
|
101
|
+
/** does the log still read its text through this content? */ holds: (ref: number) => boolean;
|
|
102
|
+
/** every recorded value containing this text, oldest first */ seek: (text: string) => Hit[];
|
|
103
|
+
/** rewrite one recorded inline value in place */ scrubValue: (field: number, value: string) => void;
|
|
104
|
+
/** point one recorded content-addressed value at different content */ scrubRef: (field: number, ref: number) => void;
|
|
105
|
+
/** Journal metadata rows still pointing at an exact entity identity. */ refs: (target: Eid) => number;
|
|
106
|
+
/** Repair a malformed identity in journal metadata, preserving every entry. */ retarget: (from: Eid, to: Eid) => void;
|
|
107
|
+
};
|
|
108
|
+
/**
|
|
109
|
+
* Bind the log to a store: `log({ rows: (s) => db.query(s) })`. Its `write`
|
|
110
|
+
* records one transaction inside the caller's own, `history(eid)` is every
|
|
111
|
+
* transaction that touched an entity, oldest first, and `since(cursor)` is
|
|
112
|
+
* every transaction after a cursor.
|
|
113
|
+
*/ export declare let log: (opts: LogOpts) => Log;
|
|
114
|
+
export { dec, enc };
|
|
115
|
+
/**
|
|
116
|
+
* The log as a plugin, so that a graph keeps a journal by listing it:
|
|
117
|
+
* `graph({ storage, vocab, plugins: [journal(log({ rows }), vocab)] })`.
|
|
118
|
+
*
|
|
119
|
+
* Its `journal` hook records the transaction as applied — one row per
|
|
120
|
+
* component the bundles patched or removed, in the order they arrived — under
|
|
121
|
+
* its writer. A batch carrying more than one writer's work is recorded as one
|
|
122
|
+
* transaction per writer, each holding what its entities' bundles wrote
|
|
123
|
+
* (@yaks/graph `writers`), so an entity's history names who wrote it, as its
|
|
124
|
+
* stamps do.
|
|
125
|
+
*
|
|
126
|
+
* A component the vocabulary declares `journal: false` is not recorded: a
|
|
127
|
+
* process's own bookkeeping, such as the stamps or an effect run. Nor is the
|
|
128
|
+
* deletion of an entity that held nothing else, so such an entity leaves no
|
|
129
|
+
* trace at all. That is the one thing read before the write: on the
|
|
130
|
+
* `precondition` phase, what each entity a bundle deletes holds, gathered with
|
|
131
|
+
* the batch's other reads (`wants`).
|
|
132
|
+
*
|
|
133
|
+
* `components` narrows it to the ones named, for a store whose history is
|
|
134
|
+
* about a few of its words while the rest are written often: the others are
|
|
135
|
+
* left out as `journal: false` ones are.
|
|
136
|
+
*/ export declare let journal: (n: Log, vocab: Vocab, opts?: {
|
|
137
|
+
now?: () => string;
|
|
138
|
+
name?: string;
|
|
139
|
+
record?: Recording;
|
|
140
|
+
components?: string[];
|
|
141
|
+
}) => Plugin;
|
|
142
|
+
//# sourceMappingURL=log.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"log.d.ts","sources":["../log.ts"],"names":[],"mappings":"AA4BA,cAEE,MAAM,EACN,IAAI,EACJ,GAAG,EAEH,MAAM,2BAEuB;AAM/B,cAAc,KAAK,2BAAgC;AACnD,SASE,KAAK,OAAO,EAEZ,KAAK,IAAI,EAiBT,KAAK,GAAG,EAGR,KAAK,IAAI,yBAIkB;AAC7B,cAAc,KAAK,EAAS,KAAK,EAAE,KAAK,qBAAoB;AAC5D,SAAS,GAAG,EAAE,GAAG,qBAAoB;AAIrC;wEACwE,GACxE,YAAY,QAAQ,GAAG,SAAS;AAEhC;;;;;CAKC,GACD,YAAY;EACV,wCAAwC,GACxC,KAAK,MAAM,MAAM,EAAE,MAAM,MAAM,KAAK,OAAO;EAC3C,yDAAyD,GACzD,MAAM,MAAM,MAAM,KAAK,MAAM;EAC7B,iEAAiE,GACjE,OAAO,MAAM;EACb,KAAK,MAAM;EACX,OAAO,MAAM;;AAGf;;;;CAIC,GACD,YAAY;EACV,4DAA4D,GAC5D,OAAO,M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|
+
import type { Vocab } from "@yaks/vocab";
|
|
4
|
+
/** A property both the branch and main changed since the fork, to different
|
|
5
|
+
* values: each side's value, null where it holds none. */ export type Conflict = {
|
|
6
|
+
eid: Eid;
|
|
7
|
+
comp: string;
|
|
8
|
+
prop: string;
|
|
9
|
+
fork: unknown;
|
|
10
|
+
branch: unknown;
|
|
11
|
+
main: unknown;
|
|
12
|
+
};
|
|
13
|
+
/** Which side's value a conflict takes. With `main`, the value main held
|
|
14
|
+
* when the pick was made: a main that has moved since is a value the picker
|
|
15
|
+
* never saw, so the pick settles nothing and the conflict stands again, and
|
|
16
|
+
* of several picks of one property, the one made seeing main as it stands
|
|
17
|
+
* is taken. */ export type Choice = {
|
|
18
|
+
eid: Eid;
|
|
19
|
+
comp: string;
|
|
20
|
+
prop: string;
|
|
21
|
+
take: 'branch' | 'main';
|
|
22
|
+
main?: unknown;
|
|
23
|
+
};
|
|
24
|
+
/** A merge, worked out: the conflicts no pick settles, and the bundles that
|
|
25
|
+
* write it to main, which are empty while any conflict stands. */ export type Merged = {
|
|
26
|
+
conflicts: Conflict[];
|
|
27
|
+
bundles: Bundle[];
|
|
28
|
+
};
|
|
29
|
+
/**
|
|
30
|
+
* A branch's changes merged onto main, three ways per property, with `picks`
|
|
31
|
+
* settling conflicts: the conflicts left, and the bundles that write the merge
|
|
32
|
+
* as one batch once none is.
|
|
33
|
+
*/ export declare let merged: (vocab: Vocab, changes: Change[], picks?: Choice[]) => Merged;
|
|
34
|
+
/**
|
|
35
|
+
* Merge a branch into main: `merge(g)(id, picks, actor)` reads branch `id`'s
|
|
36
|
+
* changes, merges them with `picks`, and, where no conflict is left, writes
|
|
37
|
+
* them to main through `g` as one batch, as `actor`. Answers what was worked
|
|
38
|
+
* out; its bundles are what was written, none while a conflict stands. The
|
|
39
|
+
* branch itself is left as it is.
|
|
40
|
+
*/ export declare let merge: (g: Graph) => any;
|
|
41
|
+
//# sourceMappingURL=merge.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"merge.d.ts","sources":["../merge.ts"],"names":[],"mappings":"AAyBA,cAAc,KAAK,EAAE,MAAM,EAAQ,GAAG,EAAE,KAAK,2BAAqC;AAElF,cAAc,MAAM,mCAAwC;AAG5D,cAAc,KAAK,2BAAgC;AAGnD;wDACwD,GACxD,YAAY;EACV,KAAK;EACL,MAAM,MAAM;EACZ,MAAM,MAAM;EACZ,MAAM,OAAO;EACb,QAAQ,OAAO;EACf,MAAM,OAAO;;AAGf;;;;aAIa,GACb,YAAY;EACV,KAAK;EACL,MAAM,MAAM;EACZ,MAAM,MAAM;EACZ,MAAM,WAAW;EACjB,OAAO,OAAO;;AAGhB;gEACgE,GAChE,YAAY;EAAW,WAAW;EAAY,SAAS;;AA0FvD;;;;CAIC,GACD,OAAO,YAAI,SACT,OAAO,OACP,SAAS,UACT,QAAO,aACN,OAQF;AAED;;;;;;CAMC,GACD,OAAO,YAAI,QACR,GAAG,cAQH"}
|
package/_dist/mod.d.ts
ADDED
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @yaks/journal — who wrote what, and when: attribution and history for a
|
|
3
|
+
* {@link https://jsr.io/@yaks/graph | @yaks/graph}, with undo falling out of
|
|
4
|
+
* the same record, and a feed that carries every commit to the other hosts
|
|
5
|
+
* that opened the store.
|
|
6
|
+
*
|
|
7
|
+
* Take a page several people edit. Somebody renames it, somebody else rewrites
|
|
8
|
+
* a paragraph, somebody deletes a note attached to it. Afterwards the page
|
|
9
|
+
* holds only where it ended up — which is the question a graph answers well,
|
|
10
|
+
* and not the question being asked. This package writes the other one down.
|
|
11
|
+
*
|
|
12
|
+
* Throughout, a transaction is one call to `graph.apply()`: a list of bundles
|
|
13
|
+
* that all commit or none do. The type for a recorded one is {@link Batch},
|
|
14
|
+
* and its `seq` is its position in the total order.
|
|
15
|
+
*
|
|
16
|
+
* ## What it records
|
|
17
|
+
* Three append-only tables beside the graph's own. They hold no entities of
|
|
18
|
+
* their own — no eid, no minted id, never in a bundle or a client cache: they
|
|
19
|
+
* are the record of what was applied, not part of it.
|
|
20
|
+
*
|
|
21
|
+
* - `journal_tx` — one row per committed transaction: its id is both the total
|
|
22
|
+
* order and the cursor, with the timestamp and the actor from the
|
|
23
|
+
* transaction's `$actor` (one row per writer, where its bundles name more
|
|
24
|
+
* than one);
|
|
25
|
+
* - `journal_change` — one ordered row per component that transaction patched
|
|
26
|
+
* or removed;
|
|
27
|
+
* - `journal_field` — one ordered after-image per property that row wrote.
|
|
28
|
+
*
|
|
29
|
+
* After-images only. The before-value a history read needs is rebuilt from the
|
|
30
|
+
* entity's own rows in the log, a read bounded to one entity and never a table
|
|
31
|
+
* scan, which is what keeps the log about a third of the size of one that
|
|
32
|
+
* stores both sides. The rows go in inside the caller's transaction: a
|
|
33
|
+
* transaction that was refused leaves no trace, and one that committed always
|
|
34
|
+
* has a row.
|
|
35
|
+
*
|
|
36
|
+
* ## What it returns
|
|
37
|
+
* ```ts
|
|
38
|
+
* import { graph } from '@yaks/graph'
|
|
39
|
+
* import { storage } from '@yaks/sqlite'
|
|
40
|
+
* import { open } from '@yaks/sqlite/db'
|
|
41
|
+
* import { loadVocab } from '@yaks/vocab'
|
|
42
|
+
* import { ddl, journal, log, undo } from '@yaks/journal'
|
|
43
|
+
*
|
|
44
|
+
* let title = { type: 'string' }
|
|
45
|
+
* let vocab = loadVocab([{
|
|
46
|
+
* $defs: { page: { component: true, properties: { title } } },
|
|
47
|
+
* }])
|
|
48
|
+
* let db = open(':memory:')
|
|
49
|
+
* let store = storage(db, vocab)
|
|
50
|
+
* store.install()
|
|
51
|
+
* for (let s of ddl(vocab)) db.query(s)
|
|
52
|
+
* let j = log({ rows: (s) => db.query(s), vocab })
|
|
53
|
+
* let g = graph({ storage: store, vocab, plugins: [journal(j, vocab)] })
|
|
54
|
+
*
|
|
55
|
+
* let ada = '00000000-0000-4000-8000-000000000001'
|
|
56
|
+
* g.apply([{ entity: { eid: 'p1' }, page: { title: 'Kickoff' },
|
|
57
|
+
* $actor: { by: ada } }])
|
|
58
|
+
*
|
|
59
|
+
* j.history('p1') // every transaction that touched the page, oldest first
|
|
60
|
+
* j.since(0) // the feed: the transactions after a cursor, oldest first
|
|
61
|
+
* undo(g, j)(1) // the inverse, applied — and journaled in its turn
|
|
62
|
+
* ```
|
|
63
|
+
*
|
|
64
|
+
* - {@link Log.history} — the changes to one entity, in order, each with the
|
|
65
|
+
* identity that wrote it and when it committed.
|
|
66
|
+
* - {@link undo} — the inverse of a transaction, applied through the graph, so
|
|
67
|
+
* an undo is a write like any other and undoing it is a redo. An entity the
|
|
68
|
+
* transaction deleted comes back with the components the journal recorded,
|
|
69
|
+
* and with whatever the delete cascaded; one it recorded none of refuses
|
|
70
|
+
* the undo ({@link Final}).
|
|
71
|
+
* - {@link Log.since} — the transactions after a cursor, oldest first.
|
|
72
|
+
* {@link applied} turns one back into the bundles it committed; a consumer
|
|
73
|
+
* that stores the cursor before it does the work runs effects at most once.
|
|
74
|
+
* - {@link follow} — the feed as one host sees it: every commit another host
|
|
75
|
+
* made to the same store since the last look, as what it wrote
|
|
76
|
+
* ({@link wrote}), journaled or not, its values read from the graph
|
|
77
|
+
* ({@link filled}). Each {@link Feed} writes as one host,
|
|
78
|
+
* so a graph's subscribers can be told of the commits its own `effect` phase
|
|
79
|
+
* never saw: another process's, another thread's. The feed keeps a commit
|
|
80
|
+
* for minutes ({@link KEEP}); it is how hosts hear each other, not history.
|
|
81
|
+
* - {@link backed} — the journal read as entities: `_tx` and `_change`, the
|
|
82
|
+
* computed components its vocabulary declares, queried like any other
|
|
83
|
+
* (`._change.target=T-5`) from the journal's own rows.
|
|
84
|
+
*
|
|
85
|
+
* ## What it is not
|
|
86
|
+
* It is not a backup and not a state machine: it records what moved, not the
|
|
87
|
+
* whole entity, so a graph journaled from its first write can answer anything
|
|
88
|
+
* about its past and one that started journaling later answers only from there
|
|
89
|
+
* on. It imports no platform API — the caller hands in one function,
|
|
90
|
+
* `rows(sql, params)` — so the same journal runs on a server, in a worker, and
|
|
91
|
+
* over an embedded database.
|
|
92
|
+
*
|
|
93
|
+
* @module
|
|
94
|
+
*/ export * from "./value.js";
|
|
95
|
+
export * from "./batch.js";
|
|
96
|
+
export * from "./log.js";
|
|
97
|
+
export * from "./undo.js";
|
|
98
|
+
export * from "./merge.js";
|
|
99
|
+
export * from "./feed.js";
|
|
100
|
+
export * from "./backed.js";
|
|
101
|
+
//# sourceMappingURL=mod.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mod.d.ts","sources":["../mod.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA6FC,GAED,2BAA0B;AAC1B,2BAA0B;AAC1B,yBAAwB;AACxB,0BAAyB;AACzB,2BAA0B;AAC1B,0BAAyB;AACzB,4BAA2B"}
|