@yaks/ram 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.
@@ -0,0 +1,93 @@
1
+ import { type Trash, type TrashPage } from "@yaks/graph/trash";
2
+ import type { Binding, Bundle, Doom, Eid, Entity, Graves, Match, ReadOpts, Row } from "@yaks/graph";
3
+ import { type Series } from "@yaks/graph/storage";
4
+ import { type Computed, type Query } from "@yaks/match";
5
+ import { type Vocab } from "@yaks/vocab";
6
+ export type { Query };
7
+ /** Passed to every read of a store: the moment relative time phrases in a query
8
+ * (`.released=today`) resolve against. A per-call `opts` overrides it. */ export type RamOpts = {
9
+ /** the reference moment for time phrases (default: the read's own `now`) */ now?: number;
10
+ /** never assign a number, and take the `num` a patch states unchecked.
11
+ * This is what a store mirroring another graph needs — a client applying the
12
+ * bundles a server returned is being told the identity, not choosing it. An
13
+ * entity it has not been told a number for has none: a number it guessed
14
+ * could be another entity's. Off by default: a store that mirrors nothing
15
+ * owns its own numbering, and gives a stated number only where no other
16
+ * entity holds it. Such a store also keeps the computed values it is sent,
17
+ * as the graph it mirrors derived them. */ adopt?: boolean;
18
+ /** Give new entities a human-readable number. Opt-IN, with the same option
19
+ * name @yaks/sqlite uses: left out, an entity has its eid and nothing else.
20
+ * A table of letters (component → letter), or `true` for the prefixes the
21
+ * vocabulary declares, numbers each entity in the series of the components
22
+ * it is given, once, on the write that first gives it one. */ number?: boolean | Series;
23
+ /** `comp.prop` → the value for one bundle, for each property the vocabulary
24
+ * declares computed and never stores: what `.task.status=open` is answered
25
+ * with here, the way @yaks/sql answers it with a `derived` expression. A
26
+ * package that declares one ships the rule (@yaks/task `compute`). Left out,
27
+ * a query on a computed property is refused, naming it. */ computed?: Computed;
28
+ };
29
+ /**
30
+ * A transaction over the map: @yaks/graph's `Tx`, implemented synchronously.
31
+ * The store commits when the body returns and rolls back when it throws, so a
32
+ * rejected write leaves the map exactly as it found it.
33
+ */ export type Tx = {
34
+ /** a query → whole bundles, or only `comps` when named */ read: (query: Query, opts?: ReadOpts, comps?: string[]) => Bundle[];
35
+ /** lookup by id, not search: these entities as they stand, carrying the
36
+ * components `comps` names or every one. A deleted one carries `tombstone`;
37
+ * an unknown one is simply absent. */ get: (eids: Eid[], comps?: string[], opts?: ReadOpts) => Bundle[];
38
+ /** what declared rules are evaluated through: every match run against this
39
+ * graph with `bundles` folded in, as though it had been written, and nothing
40
+ * of it left behind */ bindings: (matches: Match[], bundles: Bundle[]) => Binding[][];
41
+ /** The deletion closure and references to clear, from the stored index. */ doom: (eids: Eid[]) => Doom | null;
42
+ /** apply these patches → the entities they created, each with its `num` */ patch: (bundles: Bundle[]) => Entity[];
43
+ /** Evict live payloads, not identities. A later patch keeps the same number.
44
+ * A tombstone stays; eviction is never deletion. */ evict: (eids: Eid[]) => void;
45
+ /** remove these entities: their components go, their identity is tombstoned */ remove: (entities: Entity[]) => void;
46
+ /** erase these entities, a writer's own bookkeeping: components and
47
+ * identity go, with no tombstone */ discard: (entities: Entity[]) => void;
48
+ /** Erase identities the graph has checked as empty and unreferenced. */ prune: (eids: Eid[]) => void;
49
+ /** bring these tombstoned entities back, with their identity and no
50
+ * components */ revive: (eids: Eid[]) => void;
51
+ };
52
+ /**
53
+ * A bound store: @yaks/graph's `Storage`, implemented synchronously. It has
54
+ * the same five members a database adapter has, so it satisfies `Storage`
55
+ * wherever one is wanted — and a caller using a `Store` directly never awaits
56
+ * a row.
57
+ */ export type Store = {
58
+ /** Destructive transactions retained for recovery. */ trash: (eids?: Eid[], page?: TrashPage) => Trash[];
59
+ /** Purge one retained transaction after a person explicitly chooses it. */ purgeTrash: (id: string | string[]) => void;
60
+ /** Adopt an additive vocabulary without replacing rows or their indexes. */ extend: (next: Vocab) => boolean;
61
+ /** Read a renamed vocabulary over the same records. */ reload: (next: Vocab) => boolean;
62
+ /** Whether a value this store reads for the property means its entity
63
+ * wears the component. */ worn: (comp: string, prop: string) => boolean;
64
+ /** nothing to create — installing a map is a no-op */ install: () => void;
65
+ /** a query → its entities, with `comps` only where named */ read: (query: Query, opts?: ReadOpts, comps?: string[]) => Bundle[];
66
+ /** a query → one raw `{ eid }` row per match, or an aggregate's rows */ rows: (query: Query, opts?: ReadOpts) => Row[];
67
+ /** these entities as they stand, carrying the components `comps` names or
68
+ * every one */ get: (eids: Eid[], comps?: string[], opts?: ReadOpts) => Bundle[];
69
+ /** tombstones laid before `before` that nothing refers to, oldest first,
70
+ * resuming at `after` */ buried: (before: string, page: {
71
+ after?: string;
72
+ limit: number;
73
+ referenced?: boolean;
74
+ }) => Graves;
75
+ /** run `body` in a transaction: commit on return, roll back on throw */ tx: <R>(body: (tx: Tx) => R) => R;
76
+ };
77
+ /**
78
+ * A store over a Map of bundles, bound to a vocabulary once. It is the storage
79
+ * a client graph and a fast test run on:
80
+ *
81
+ * ```ts
82
+ * import { graph } from '@yaks/graph'
83
+ * import { loadVocab } from '@yaks/vocab'
84
+ * import { docDoc } from '@yaks/doc'
85
+ * import { ram } from '@yaks/ram'
86
+ *
87
+ * let vocab = loadVocab([docDoc])
88
+ * let g = graph({ storage: ram(vocab), vocab })
89
+ * g.apply([{ entity: { eid: 'b1' }, doc: { title: 'Dune' } }])
90
+ * g.read('.kind=doc')
91
+ * ```
92
+ */ export declare let ram: (vocab: Vocab, base?: RamOpts) => Store;
93
+ //# sourceMappingURL=store.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"store.d.ts","sources":["../store.ts"],"names":[],"mappings":"AAAA,SAEE,KAAK,KAAK,EAGV,KAAK,SAAS,iCACqB;AAgCrC,cACE,OAAO,EACP,MAAM,EAEN,IAAI,EACJ,GAAG,EACH,MAAM,EACN,MAAM,EACN,KAAK,EACL,QAAQ,EACR,GAAG,2BAC0B;AAU/B,SAIE,KAAK,MAAM,mCAG0B;AACvC,SACE,KAAK,QAAQ,EAKb,KAAK,KAAK,2BAGmB;AAC/B,SAAsC,KAAK,KAAK,2BAAgC;AAIhF,cAAc,KAA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,aAAa;EACzD;yBACuB,GACvB,SACE,QAAQ,MAAM,EACd;IAAQ,QAAQ,MAAM;IAAE,OAAO,MAAM;IAAE,aAAa,OAAO;QACxD;EACL,sEAAsE,GACtE,KAAK,GAAG,OAAO,IAAI,OAAO,MAAM;;AAwDlC;;;;;;;;;;;;;;;CAeC,GACD,OAAO,YAAI,MAAO,OAAO,OAAO,OAAM,YAAe,MAk3BpD"}
package/deno.json ADDED
@@ -0,0 +1 @@
1
+ {"compilerOptions":{"lib":["dom","esnext"]},"publish":{"exclude":["**/*_test.ts","./testing.ts"]},"name":"@yaks/ram","version":"0.2.36","license":"Apache-2.0","description":"Synchronous in-memory graph storage over a Map of bundles, with queries evaluated by @yaks/match.","exports":"./mod.ts","imports":{"@yaks/ram":"./mod.ts"}}
package/mod.js ADDED
@@ -0,0 +1,37 @@
1
+ /**
2
+ * @yaks/ram — the in-memory storage adapter: a
3
+ * {@link https://jsr.io/@yaks/graph | @yaks/graph} `Storage` over a plain Map
4
+ * of bundles, fully synchronous, with no database underneath it.
5
+ *
6
+ * ## Why
7
+ * A graph needs somewhere to keep its entities. A server keeps them in SQLite;
8
+ * a page, a worker, or a test has nowhere to put a database and nothing to
9
+ * install — so this package keeps them in a Map, evaluates queries with
10
+ * {@link https://jsr.io/@yaks/match | @yaks/match}, and implements the same
11
+ * five members every other adapter does. The same `apply()`, the same query
12
+ * grammar, the same bundles.
13
+ *
14
+ * ## Use
15
+ * ```ts
16
+ * import { graph } from '@yaks/graph'
17
+ * import { ram } from '@yaks/ram'
18
+ * // let g = graph({ storage: ram(vocab), vocab })
19
+ * // g.apply([{ entity: { eid: 'b1' }, doc: { title: 'Dune' } }])
20
+ * // g.read('.kind=doc') // → the bundles, no await
21
+ * ```
22
+ *
23
+ * {@link ram} binds a {@link Store} to a vocabulary. `install()` does
24
+ * nothing — a Map has no schema. `tx()` commits when its body
25
+ * returns and rolls back when it throws, so a rejected write leaves the map
26
+ * exactly as it was.
27
+ *
28
+ * ## What it is not
29
+ * It is not a database: there is no persistence and no process boundary. Its
30
+ * indexes (by component, and by value where a query asks for one) decide how
31
+ * much a read looks at, never what it answers. A query it cannot answer
32
+ * exactly — a nearest-neighbour search, an edge listing — throws @yaks/match's
33
+ * `Unsupported`, the same error @yaks/sql throws.
34
+ *
35
+ * @module
36
+ */ export { ram } from "./store.js";
37
+ //# sourceMappingURL=mod.js.map
package/mod.js.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mod.js","sources":["./mod.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAmCC,GAED,SAAqB,GAAG,qBAAuD"}
package/mod.ts ADDED
@@ -0,0 +1,38 @@
1
+ /**
2
+ * @yaks/ram — the in-memory storage adapter: a
3
+ * {@link https://jsr.io/@yaks/graph | @yaks/graph} `Storage` over a plain Map
4
+ * of bundles, fully synchronous, with no database underneath it.
5
+ *
6
+ * ## Why
7
+ * A graph needs somewhere to keep its entities. A server keeps them in SQLite;
8
+ * a page, a worker, or a test has nowhere to put a database and nothing to
9
+ * install — so this package keeps them in a Map, evaluates queries with
10
+ * {@link https://jsr.io/@yaks/match | @yaks/match}, and implements the same
11
+ * five members every other adapter does. The same `apply()`, the same query
12
+ * grammar, the same bundles.
13
+ *
14
+ * ## Use
15
+ * ```ts
16
+ * import { graph } from '@yaks/graph'
17
+ * import { ram } from '@yaks/ram'
18
+ * // let g = graph({ storage: ram(vocab), vocab })
19
+ * // g.apply([{ entity: { eid: 'b1' }, doc: { title: 'Dune' } }])
20
+ * // g.read('.kind=doc') // → the bundles, no await
21
+ * ```
22
+ *
23
+ * {@link ram} binds a {@link Store} to a vocabulary. `install()` does
24
+ * nothing — a Map has no schema. `tx()` commits when its body
25
+ * returns and rolls back when it throws, so a rejected write leaves the map
26
+ * exactly as it was.
27
+ *
28
+ * ## What it is not
29
+ * It is not a database: there is no persistence and no process boundary. Its
30
+ * indexes (by component, and by value where a query asks for one) decide how
31
+ * much a read looks at, never what it answers. A query it cannot answer
32
+ * exactly — a nearest-neighbour search, an edge listing — throws @yaks/match's
33
+ * `Unsupported`, the same error @yaks/sql throws.
34
+ *
35
+ * @module
36
+ */
37
+
38
+ export { type Query, ram, type RamOpts, type Store, type Tx } from './store.js'
package/package.json CHANGED
@@ -1,6 +1,21 @@
1
1
  {
2
2
  "name": "@yaks/ram",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.2.36",
4
+ "homepage": "https://jsr.io/@yaks/ram",
5
+ "type": "module",
6
+ "exports": {
7
+ ".": {
8
+ "types": "./_dist/mod.d.ts",
9
+ "default": "./mod.js"
10
+ }
11
+ },
12
+ "license": "Apache-2.0",
13
+ "dependencies": {
14
+ "@yaks/fp": "0.2.36",
15
+ "@yaks/graph": "0.2.36",
16
+ "@yaks/match": "0.2.36",
17
+ "@yaks/vocab": "0.2.36"
18
+ },
19
+ "description": "Synchronous in-memory graph storage over a Map of bundles, with queries evaluated by @yaks/match.",
20
+ "repository": "https://github.com/yak-sh/yak.git"
21
+ }
package/records.js ADDED
@@ -0,0 +1,115 @@
1
+ // The stored record is keyed by vocabulary identity. Its bundle is the
2
+ // label projection shared by reads, indexes and the transaction's undo log.
3
+ let renamed = (cells, name, prop)=>{
4
+ let keys = Object.keys(cells);
5
+ for(let i = 0; i < keys.length; i++){
6
+ let key = keys[i];
7
+ let next = prop(name, key);
8
+ if (next != key) {
9
+ let entries = [];
10
+ for(let j = 0; j < i; j++)entries.push([
11
+ keys[j],
12
+ cells[keys[j]]
13
+ ]);
14
+ entries.push([
15
+ next,
16
+ cells[key]
17
+ ]);
18
+ for(let j = i + 1; j < keys.length; j++){
19
+ let key = keys[j];
20
+ entries.push([
21
+ prop(name, key),
22
+ cells[key]
23
+ ]);
24
+ }
25
+ return Object.fromEntries(entries);
26
+ }
27
+ }
28
+ return cells;
29
+ };
30
+ let named = (b, comp, prop)=>{
31
+ let entries;
32
+ let keys = Object.keys(b);
33
+ for(let i = 0; i < keys.length; i++){
34
+ let name = keys[i];
35
+ if (name == 'entity') continue;
36
+ let value = b[name];
37
+ let next = value == null || name[0] == '$' ? undefined : comp(name);
38
+ let cells = next === undefined ? undefined : renamed(value, name, prop);
39
+ if (!entries && (next != name || cells !== value)) {
40
+ entries = [];
41
+ for(let j = 0; j < i; j++){
42
+ let key = keys[j];
43
+ if (key != 'entity') entries.push([
44
+ key,
45
+ b[key]
46
+ ]);
47
+ }
48
+ }
49
+ if (entries && next !== undefined) entries.push([
50
+ next,
51
+ cells
52
+ ]);
53
+ }
54
+ return entries ? {
55
+ entity: b.entity,
56
+ ...Object.fromEntries(entries)
57
+ } : b;
58
+ };
59
+ let label = (v)=>({
60
+ comp: (c)=>{
61
+ let w = v.word(c);
62
+ return w && 'comp' in w && !w.prop ? w.comp : c;
63
+ },
64
+ prop: (c, p)=>{
65
+ let w = v.word(p);
66
+ return w && 'comp' in w && w.prop && v.stored(w.comp) == c ? w.prop : p;
67
+ }
68
+ });
69
+ export let records = (vocab)=>{
70
+ let rows = new Map();
71
+ let bundles = new WeakMap();
72
+ let recorded = new WeakMap();
73
+ let current;
74
+ let words;
75
+ let names = ()=>{
76
+ let next = vocab();
77
+ if (current !== next) words = label(current = next);
78
+ return words;
79
+ };
80
+ let read = (row)=>{
81
+ let held = bundles.get(row);
82
+ if (held) return held;
83
+ let { comp, prop } = names();
84
+ let bundle = named(row, comp, prop);
85
+ bundles.set(row, bundle);
86
+ recorded.set(bundle, row);
87
+ return bundle;
88
+ };
89
+ return {
90
+ relabel: ()=>{
91
+ bundles = new WeakMap();
92
+ },
93
+ get: (eid)=>{
94
+ let row = rows.get(eid);
95
+ return row && read(row);
96
+ },
97
+ set: (eid, bundle)=>{
98
+ let { stored } = vocab();
99
+ let row = recorded.get(bundle) ?? named(bundle, stored, stored);
100
+ rows.set(eid, row);
101
+ return read(row);
102
+ },
103
+ delete: (eid)=>rows.delete(eid),
104
+ values: function*() {
105
+ for (let row of rows.values())yield read(row);
106
+ },
107
+ [Symbol.iterator]: function*() {
108
+ for (let [eid, row] of rows)yield [
109
+ eid,
110
+ read(row)
111
+ ];
112
+ }
113
+ };
114
+ };
115
+ //# sourceMappingURL=records.js.map
package/records.js.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"file":"records.js","sources":["./records.ts"],"names":[],"mappings":"AAAA,uEAAuE;AACvE,4EAA4E;AAM5E,IAAI,UAAU,CACZ,OACA,MACA;EAEA,IAAI,OAAO,OAAO,IAAI,CAAC;EACvB,IAAK,IAAI,IAAI,GAAG,IAAI,KAAK,MAAM,EAAE,IAAK;IACpC,IAAI,MAAM,IAAI,CAAC,EAAE;IACjB,IAAI,OAAO,KAAK,MAAM;IACtB,IAAI,QAAQ,KAAK;MACf,IAAI,UAA+B,EAAE;MACrC,IAAK,IAAI,IAAI,GAAG,IAAI,GAAG,IAAK,QAAQ,IAAI,CAAC;QAAC,IAAI,CAAC,EAAE;QAAE,KAAK,CAAC,IAAI,CAAC,EAAE,CAAC;OAAC;MAClE,QAAQ,IAAI,CAAC;QAAC;QAAM,KAAK,CAAC,IAAI;OAAC;MAC/B,IAAK,IAAI,IAAI,IAAI,GAAG,IAAI,KAAK,MAAM,EAAE,IAAK;QACxC,IAAI,MAAM,IAAI,CAAC,EAAE;QACjB,QAAQ,IAAI,CAAC;UAAC,KAAK,MAAM;UAAM,KAAK,CAAC,IAAI;SAAC;MAC5C;MACA,OAAO,OAAO,WAAW,CAAC;IAC5B;EACF;EACA,OAAO;AACT;AAEA,IAAI,QAAQ,CACV,GACA,MACA;EAEA,IAAI;EACJ,IAAI,OAAO,OAAO,IAAI,CAAC;EACvB,IAAK,IAAI,IAAI,GAAG,IAAI,KAAK,MAAM,EAAE,IAAK;IACpC,IAAI,OAAO,IAAI,CAAC,EAAE;IAClB,IAAI,QAAQ,UAAU;IACtB,IAAI,QAAQ,CAAC,CAAC,KAAK;IACnB,IAAI,OAAO,SAAS,QAAQ,IAAI,CAAC,EAAE,IA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AK,MAAM;IAC9B,QAAQ,GAAG,CAAC,KAAK;IACjB,SAAS,GAAG,CAAC,QAAQ;IACrB,OAAO;EACT;EACA,OAAO;IACL,SAAS;MACP,UAAU,IAAI;IAChB;IACA,KAAK,CAAC;MACJ,IAAI,MAAM,KAAK,GAAG,CAAC;MACnB,OAAO,OAAO,KAAK;IACrB;IACA,KAAK,CAAC,KAAU;MACd,IAAI,EAAE,MAAM,EAAE,GAAG;MACjB,IAAI,MAAM,SAAS,GAAG,CAAC,WAAW,MAAM,QAAQ,QAAQ;MACxD,KAAK,GAAG,CAAC,KAAK;MACd,OAAO,KAAK;IACd;IACA,QAAQ,CAAC,MAAa,KAAK,MAAM,CAAC;IAClC,QAAQ;MACN,KAAK,IAAI,OAAO,KAAK,MAAM,GAAI,MAAM,KAAK;IAC5C;IACA,CAAC,OAAO,QAAQ,CAAC,EAAE;MACjB,KAAK,IAAI,CAAC,KAAK,IAAI,IAAI,KAAM,MAAM;QAAC;QAAK,KAAK;OAAK;IACrD;EACF;AACF,EAAC"}
package/records.ts ADDED
@@ -0,0 +1,111 @@
1
+ // The stored record is keyed by vocabulary identity. Its bundle is the
2
+ // label projection shared by reads, indexes and the transaction's undo log.
3
+ import type { Bundle, Comp, Eid } from 'jsr:@yaks/graph@0.2.36'
4
+ import type { Vocab } from 'jsr:@yaks/vocab@0.2.36'
5
+
6
+ type RecordOf = { entity: Bundle['entity']; [key: string]: Comp | undefined }
7
+
8
+ let renamed = (
9
+ cells: Comp,
10
+ name: string,
11
+ prop: (c: string, p: string) => string,
12
+ ): Comp => {
13
+ let keys = Object.keys(cells)
14
+ for (let i = 0; i < keys.length; i++) {
15
+ let key = keys[i]
16
+ let next = prop(name, key)
17
+ if (next != key) {
18
+ let entries: [string, unknown][] = []
19
+ for (let j = 0; j < i; j++) entries.push([keys[j], cells[keys[j]]])
20
+ entries.push([next, cells[key]])
21
+ for (let j = i + 1; j < keys.length; j++) {
22
+ let key = keys[j]
23
+ entries.push([prop(name, key), cells[key]])
24
+ }
25
+ return Object.fromEntries(entries)
26
+ }
27
+ }
28
+ return cells
29
+ }
30
+
31
+ let named = (
32
+ b: Bundle,
33
+ comp: (name: string) => string,
34
+ prop: (comp: string, name: string) => string,
35
+ ): RecordOf => {
36
+ let entries: [string, Comp][] | undefined
37
+ let keys = Object.keys(b)
38
+ for (let i = 0; i < keys.length; i++) {
39
+ let name = keys[i]
40
+ if (name == 'entity') continue
41
+ let value = b[name] as Comp | null | undefined
42
+ let next = value == null || name[0] == '$' ? undefined : comp(name)
43
+ let cells = next === undefined ? undefined : renamed(value!, name, prop)
44
+ if (!entries && (next != name || cells !== value)) {
45
+ entries = []
46
+ for (let j = 0; j < i; j++) {
47
+ let key = keys[j]
48
+ if (key != 'entity') entries.push([key, b[key] as Comp])
49
+ }
50
+ }
51
+ if (entries && next !== undefined) entries.push([next, cells!])
52
+ }
53
+ return entries
54
+ ? { entity: b.entity, ...Object.fromEntries(entries) }
55
+ : b as RecordOf
56
+ }
57
+
58
+ let label = (v: Vocab) => ({
59
+ comp: (c: string) => {
60
+ let w = v.word(c)
61
+ return w && 'comp' in w && !w.prop ? w.comp : c
62
+ },
63
+ prop: (c: string, p: string) => {
64
+ let w = v.word(p)
65
+ return w && 'comp' in w && w.prop && v.stored(w.comp) == c ? w.prop : p
66
+ },
67
+ })
68
+
69
+ export let records = (vocab: () => Vocab) => {
70
+ let rows = new Map<Eid, RecordOf>()
71
+ let bundles = new WeakMap<RecordOf, Bundle>()
72
+ let recorded = new WeakMap<Bundle, RecordOf>()
73
+ let current: Vocab | undefined
74
+ let words: ReturnType<typeof label>
75
+ let names = () => {
76
+ let next = vocab()
77
+ if (current !== next) words = label(current = next)
78
+ return words
79
+ }
80
+ let read = (row: RecordOf): Bundle => {
81
+ let held = bundles.get(row)
82
+ if (held) return held
83
+ let { comp, prop } = names()
84
+ let bundle = named(row, comp, prop) as Bundle
85
+ bundles.set(row, bundle)
86
+ recorded.set(bundle, row)
87
+ return bundle
88
+ }
89
+ return {
90
+ relabel: () => {
91
+ bundles = new WeakMap()
92
+ },
93
+ get: (eid: Eid) => {
94
+ let row = rows.get(eid)
95
+ return row && read(row)
96
+ },
97
+ set: (eid: Eid, bundle: Bundle) => {
98
+ let { stored } = vocab()
99
+ let row = recorded.get(bundle) ?? named(bundle, stored, stored)
100
+ rows.set(eid, row)
101
+ return read(row)
102
+ },
103
+ delete: (eid: Eid) => rows.delete(eid),
104
+ values: function* () {
105
+ for (let row of rows.values()) yield read(row)
106
+ },
107
+ [Symbol.iterator]: function* () {
108
+ for (let [eid, row] of rows) yield [eid, read(row)] as const
109
+ },
110
+ }
111
+ }
package/rules.js ADDED
@@ -0,0 +1,200 @@
1
+ // Declared rules, evaluated over the map. A rule is a query (@yaks/graph's
2
+ // join.ts parses it into a plan of patterns, one per entity), and @yaks/sqlite
3
+ // answers one by compiling the plan into a statement. This is the same answer
4
+ // worked out in memory: each pattern's filter is an ordinary query that
5
+ // @yaks/match answers over the store's own indexes, and what is left is the
6
+ // join, every pattern's entity and the values its variables took, kept where
7
+ // the variables agree.
8
+ //
9
+ // The store folds the batch in before asking (./store.ts `bindings`), so what
10
+ // this file is handed is the graph as the batch would leave it, the entities
11
+ // the batch is about, and what it removed. The first is the source a filter
12
+ // reads; the second is the anchor, since a rule is about a batch and not the
13
+ // whole graph: at least one of its patterns binds an entity the batch wrote,
14
+ // so a gated rule does not fire on every entity that ever failed its gate. The
15
+ // third answers `-comp`, the one clause no row can answer.
16
+ //
17
+ // The anchor is also the plan. An anchored pattern is read from the batch
18
+ // alone, and each pattern after it is found through what the ones before it
19
+ // bound: its entity by id, or its property through the store's keyed index.
20
+ // A keystroke's batch is one entity, so a rule over it reads a handful of
21
+ // bundles, however large the page's graph.
22
+ import { collected } from "@yaks/graph/declared";
23
+ import { filter, keyOf, matcher } from "@yaks/match";
24
+ import { Unknown } from "@yaks/vocab/runtime";
25
+ import { Refused } from "@yaks/graph/errors";
26
+ // One property, as a read of a bundle: its computed rule where the vocabulary
27
+ // derives it, else what the bundle holds.
28
+ let reader = (comp, prop, opts)=>{
29
+ let computed = opts.computed?.[`${comp}.${prop}`];
30
+ return (b, x)=>!b ? null : computed ? computed(b, x) : b[comp]?.[prop] ?? null;
31
+ };
32
+ // A bound property, followed through the references before its leaf. A path
33
+ // ending `entity.eid` reads the eid of the entity it reaches, a plain value.
34
+ let slot = (v, bind, opts)=>{
35
+ let path = bind.path.join('.');
36
+ let hops = v.aim(path);
37
+ let leaf = hops[hops.length - 1];
38
+ if (!leaf?.prop) {
39
+ throw new Unknown(path, `$${bind.name} names no property: .${path}`);
40
+ }
41
+ let spine = leaf.comp == 'entity' && leaf.prop == 'eid';
42
+ let prop = spine ? undefined : v.prop(leaf.comp, leaf.prop);
43
+ if (!prop && !spine) {
44
+ throw new Unknown(path, `no property ${path} for $${bind.name}`);
45
+ }
46
+ let reads = hops.map((h)=>reader(h.comp, h.prop, opts));
47
+ let kind = prop?.category == 'ref' ? 'id' : 'value';
48
+ if (hops.length == 1) {
49
+ let at = !prop || prop.computed ? undefined : [
50
+ leaf.comp,
51
+ leaf.prop
52
+ ];
53
+ return {
54
+ kind,
55
+ read: reads[0],
56
+ at
57
+ };
58
+ }
59
+ return {
60
+ kind,
61
+ read: (b, x)=>{
62
+ let at = b;
63
+ for (let r of reads.slice(0, -1)){
64
+ let eid = r(at, x);
65
+ at = typeof eid == 'string' ? x.of(eid) : undefined;
66
+ }
67
+ return reads[reads.length - 1](at, x);
68
+ }
69
+ };
70
+ };
71
+ let eidOf = (b)=>b.entity.eid;
72
+ // One pattern, compiled once per evaluation: the entities it selects, the test
73
+ // for one candidate, and its variables' slots. A bound property implies its
74
+ // component is worn, and a gate that it is not, as the SQL a pattern compiles
75
+ // to joins the one and left-joins the other.
76
+ let compiled = (p, v, opts)=>{
77
+ let select = matcher(p.filter, v, opts);
78
+ let test = filter(p.filter, v, opts);
79
+ let worn = p.binds.map((b)=>v.aim(b.path.join('.'))[0].comp);
80
+ let fits = (b)=>worn.every((c)=>b[c] != null) && p.gates.every((c)=>b[c] == null);
81
+ let slots = p.binds.map((b)=>[
82
+ b.name,
83
+ slot(v, b, opts)
84
+ ]);
85
+ if (p.entity) slots.unshift([
86
+ p.entity,
87
+ {
88
+ kind: 'id',
89
+ read: eidOf
90
+ }
91
+ ]);
92
+ return {
93
+ entity: p.entity,
94
+ slots,
95
+ all: (x)=>select(x).filter(fits),
96
+ one: (b, x)=>!!b && test(b, x) && fits(b)
97
+ };
98
+ };
99
+ // A candidate's variables joined to the ones already bound, or null where one
100
+ // disagrees. A variable is the same value in every slot, and nothing equals an
101
+ // absent one, as in SQL; values compare as a keyed index files them.
102
+ let joined = (slots, b, x, vars)=>{
103
+ let out = vars;
104
+ for (let [name, s] of slots){
105
+ let value = s.read(b, x);
106
+ if (name in out) {
107
+ if (value == null || keyOf(value) !== keyOf(out[name])) return null;
108
+ continue;
109
+ }
110
+ if (out === vars) out = {
111
+ ...vars
112
+ };
113
+ out[name] = value;
114
+ }
115
+ return out;
116
+ };
117
+ // One flat level of a match: its patterns joined, anchored to the batch when
118
+ // `anchor` is given.
119
+ let level = (plan, x, anchor, v, opts)=>{
120
+ let pats = plan.patterns.map((p)=>p.makes ? null : compiled(p, v, opts));
121
+ // An id and a value are not comparable, so a variable that is an entity in
122
+ // one place and a plain value in another is refused rather than coerced:
123
+ // the query is the caller's.
124
+ let kinds = new Map();
125
+ for (let [name, s] of pats.flatMap((p)=>p?.slots ?? [])){
126
+ if ((kinds.get(name) ?? s.kind) != s.kind) {
127
+ throw new Refused(`$${name} is an entity in one place and a plain value in another; ` + `end the entity's path in .entity.eid to compare its eid as a value`);
128
+ }
129
+ kinds.set(name, s.kind);
130
+ }
131
+ let live = pats.flatMap((p, i)=>p ? [
132
+ i
133
+ ] : []);
134
+ if (anchor && !live.length) return [];
135
+ let out = [];
136
+ let seen = new Set();
137
+ let entities = plan.patterns.map(()=>null);
138
+ // What a pattern could bind, given what the patterns before it bound.
139
+ let found = (p, vars)=>{
140
+ let eid = p.entity && vars[p.entity];
141
+ if (eid != null) return [
142
+ x.of(String(eid))
143
+ ];
144
+ for (let [name, s] of p.slots){
145
+ let key = s.at && keyOf(vars[name]);
146
+ if (key !== undefined && s.at && x.keyed) {
147
+ return x.keyed(s.at[0], s.at[1], key).values();
148
+ }
149
+ }
150
+ return p.all(x);
151
+ };
152
+ let walk = (order, at, vars, first)=>{
153
+ if (at == order.length) {
154
+ let row = {
155
+ entities: [
156
+ ...entities
157
+ ],
158
+ vars: Object.fromEntries(plan.vars.map((n)=>[
159
+ n,
160
+ vars[n] ?? null
161
+ ]))
162
+ };
163
+ let key = JSON.stringify(row);
164
+ if (seen.has(key)) return;
165
+ seen.add(key);
166
+ out.push(row);
167
+ return;
168
+ }
169
+ let i = order[at];
170
+ let p = pats[i];
171
+ let from = first ? [
172
+ ...first
173
+ ].map((eid)=>x.of(eid)) : found(p, vars);
174
+ for (let b of from){
175
+ if (!p.one(b, x)) continue;
176
+ let next = joined(p.slots, b, x, vars);
177
+ if (!next) continue;
178
+ entities[i] = b.entity.eid;
179
+ walk(order, at + 1, next);
180
+ }
181
+ entities[i] = null;
182
+ };
183
+ // Anchored, each pattern in turn is the one read from the batch and the rest
184
+ // are found through it; a row two turns both find is kept once.
185
+ let orders = anchor ? live.map((k)=>[
186
+ k,
187
+ ...live.filter((i)=>i != k)
188
+ ]) : [
189
+ live
190
+ ];
191
+ for (let order of orders)walk(order, 0, {}, anchor);
192
+ return out;
193
+ };
194
+ /**
195
+ * Evaluate declared rules' matches over a source (@yaks/graph `Tx.bindings`):
196
+ * each match's bindings, with its collections attached. `anchor` is the set of
197
+ * entities the batch is about, which every outer binding must touch; left out,
198
+ * the match is asked outright, as a template's invocation asks it.
199
+ */ export let bindings = (matches, x, anchor, v, opts = {})=>matches.map((m)=>collected(m, (plan, anchored)=>level(plan, x, anchored ? anchor : undefined, v, opts)));
200
+ //# sourceMappingURL=rules.js.map
package/rules.js.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"file":"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