@yaks/sqlite 0.0.0-stage → 0.2.36

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (289) hide show
  1. package/LICENSE +202 -0
  2. package/README.md +1596 -2
  3. package/_dist/archetype.d.ts +75 -0
  4. package/_dist/archetype.d.ts.map +1 -0
  5. package/_dist/branches.d.ts +23 -0
  6. package/_dist/branches.d.ts.map +1 -0
  7. package/_dist/budget.d.ts +52 -0
  8. package/_dist/budget.d.ts.map +1 -0
  9. package/_dist/bundle.d.ts +2 -0
  10. package/_dist/bundle.d.ts.map +1 -0
  11. package/_dist/cache.d.ts +24 -0
  12. package/_dist/cache.d.ts.map +1 -0
  13. package/_dist/catalog.d.ts +9 -0
  14. package/_dist/catalog.d.ts.map +1 -0
  15. package/_dist/check.d.ts +4 -0
  16. package/_dist/check.d.ts.map +1 -0
  17. package/_dist/db.d.ts +36 -0
  18. package/_dist/db.d.ts.map +1 -0
  19. package/_dist/ddl.d.ts +143 -0
  20. package/_dist/ddl.d.ts.map +1 -0
  21. package/_dist/doom.d.ts +22 -0
  22. package/_dist/doom.d.ts.map +1 -0
  23. package/_dist/follow.d.ts +74 -0
  24. package/_dist/follow.d.ts.map +1 -0
  25. package/_dist/history-shapes.d.ts +3 -0
  26. package/_dist/history-shapes.d.ts.map +1 -0
  27. package/_dist/history.d.ts +18 -0
  28. package/_dist/history.d.ts.map +1 -0
  29. package/_dist/inspect.d.ts +43 -0
  30. package/_dist/inspect.d.ts.map +1 -0
  31. package/_dist/jsonb.d.ts +17 -0
  32. package/_dist/jsonb.d.ts.map +1 -0
  33. package/_dist/layout.d.ts +7 -0
  34. package/_dist/layout.d.ts.map +1 -0
  35. package/_dist/ledger.d.ts +41 -0
  36. package/_dist/ledger.d.ts.map +1 -0
  37. package/_dist/meta.d.ts +89 -0
  38. package/_dist/meta.d.ts.map +1 -0
  39. package/_dist/migration.d.ts +41 -0
  40. package/_dist/migration.d.ts.map +1 -0
  41. package/_dist/mod.d.ts +201 -0
  42. package/_dist/mod.d.ts.map +1 -0
  43. package/_dist/mode.d.ts +14 -0
  44. package/_dist/mode.d.ts.map +1 -0
  45. package/_dist/overlay.d.ts +30 -0
  46. package/_dist/overlay.d.ts.map +1 -0
  47. package/_dist/owe.d.ts +180 -0
  48. package/_dist/owe.d.ts.map +1 -0
  49. package/_dist/physical.d.ts +89 -0
  50. package/_dist/physical.d.ts.map +1 -0
  51. package/_dist/point.d.ts +10 -0
  52. package/_dist/point.d.ts.map +1 -0
  53. package/_dist/raise.d.ts +22 -0
  54. package/_dist/raise.d.ts.map +1 -0
  55. package/_dist/read-db.d.ts +9 -0
  56. package/_dist/read-db.d.ts.map +1 -0
  57. package/_dist/read-store.d.ts +10 -0
  58. package/_dist/read-store.d.ts.map +1 -0
  59. package/_dist/read.d.ts +59 -0
  60. package/_dist/read.d.ts.map +1 -0
  61. package/_dist/reader.d.ts +11 -0
  62. package/_dist/reader.d.ts.map +1 -0
  63. package/_dist/rules.d.ts +19 -0
  64. package/_dist/rules.d.ts.map +1 -0
  65. package/_dist/service.d.ts +12 -0
  66. package/_dist/service.d.ts.map +1 -0
  67. package/_dist/shape.d.ts +12 -0
  68. package/_dist/shape.d.ts.map +1 -0
  69. package/_dist/statements.d.ts +4 -0
  70. package/_dist/statements.d.ts.map +1 -0
  71. package/_dist/survey.d.ts +31 -0
  72. package/_dist/survey.d.ts.map +1 -0
  73. package/_dist/tools.d.ts +15 -0
  74. package/_dist/tools.d.ts.map +1 -0
  75. package/_dist/trash.d.ts +18 -0
  76. package/_dist/trash.d.ts.map +1 -0
  77. package/_dist/unit.d.ts +11 -0
  78. package/_dist/unit.d.ts.map +1 -0
  79. package/_dist/vocab.d.ts +6 -0
  80. package/_dist/vocab.d.ts.map +1 -0
  81. package/_dist/write.d.ts +169 -0
  82. package/_dist/write.d.ts.map +1 -0
  83. package/answer.js +110 -0
  84. package/answer.js.map +1 -0
  85. package/answer.ts +122 -0
  86. package/archetype.js +730 -0
  87. package/archetype.js.map +1 -0
  88. package/archetype.ts +790 -0
  89. package/binary_cases.ts +240 -0
  90. package/branches.js +195 -0
  91. package/branches.js.map +1 -0
  92. package/branches.ts +257 -0
  93. package/budget.js +89 -0
  94. package/budget.js.map +1 -0
  95. package/budget.ts +117 -0
  96. package/builtin.js +34 -0
  97. package/builtin.js.map +1 -0
  98. package/builtin.ts +31 -0
  99. package/bundle.js +21 -0
  100. package/bundle.js.map +1 -0
  101. package/bundle.ts +22 -0
  102. package/buried.js +95 -0
  103. package/buried.js.map +1 -0
  104. package/buried.ts +124 -0
  105. package/cache.js +153 -0
  106. package/cache.js.map +1 -0
  107. package/cache.ts +154 -0
  108. package/cache_worker.ts +16 -0
  109. package/catalog.js +173 -0
  110. package/catalog.js.map +1 -0
  111. package/catalog.ts +224 -0
  112. package/check.js +80 -0
  113. package/check.js.map +1 -0
  114. package/check.ts +92 -0
  115. package/checkpoint.js +98 -0
  116. package/checkpoint.js.map +1 -0
  117. package/checkpoint.ts +129 -0
  118. package/checkpoint_worker.ts +37 -0
  119. package/db.js +170 -0
  120. package/db.js.map +1 -0
  121. package/db.ts +173 -0
  122. package/ddl.js +1441 -0
  123. package/ddl.js.map +1 -0
  124. package/ddl.ts +1508 -0
  125. package/deno.json +1 -0
  126. package/doom.js +59 -0
  127. package/doom.js.map +1 -0
  128. package/doom.ts +75 -0
  129. package/driver.js +69 -0
  130. package/driver.js.map +1 -0
  131. package/driver.ts +101 -0
  132. package/error.js +30 -0
  133. package/error.js.map +1 -0
  134. package/error.ts +46 -0
  135. package/ffi/LICENSE +202 -0
  136. package/ffi/blob.js +99 -0
  137. package/ffi/blob.js.map +1 -0
  138. package/ffi/blob.ts +156 -0
  139. package/ffi/constants.js +65 -0
  140. package/ffi/constants.js.map +1 -0
  141. package/ffi/constants.ts +67 -0
  142. package/ffi/database.js +613 -0
  143. package/ffi/database.js.map +1 -0
  144. package/ffi/database.ts +931 -0
  145. package/ffi/ffi.js +535 -0
  146. package/ffi/ffi.js.map +1 -0
  147. package/ffi/ffi.ts +604 -0
  148. package/ffi/mod.js +15 -0
  149. package/ffi/mod.js.map +1 -0
  150. package/ffi/mod.ts +28 -0
  151. package/ffi/statement.js +555 -0
  152. package/ffi/statement.js.map +1 -0
  153. package/ffi/statement.ts +788 -0
  154. package/ffi/util.js +32 -0
  155. package/ffi/util.js.map +1 -0
  156. package/ffi/util.ts +48 -0
  157. package/follow.js +342 -0
  158. package/follow.js.map +1 -0
  159. package/follow.ts +401 -0
  160. package/history-branch.js +166 -0
  161. package/history-branch.js.map +1 -0
  162. package/history-branch.ts +140 -0
  163. package/history-shapes.js +254 -0
  164. package/history-shapes.js.map +1 -0
  165. package/history-shapes.ts +268 -0
  166. package/history.js +620 -0
  167. package/history.js.map +1 -0
  168. package/history.ts +674 -0
  169. package/inspect.js +120 -0
  170. package/inspect.js.map +1 -0
  171. package/inspect.ts +164 -0
  172. package/jsonb.js +73 -0
  173. package/jsonb.js.map +1 -0
  174. package/jsonb.ts +108 -0
  175. package/layout.js +22 -0
  176. package/layout.js.map +1 -0
  177. package/layout.ts +26 -0
  178. package/ledger.js +210 -0
  179. package/ledger.js.map +1 -0
  180. package/ledger.ts +210 -0
  181. package/legacy.js +4 -0
  182. package/legacy.js.map +1 -0
  183. package/legacy.ts +3 -0
  184. package/maintenance.js +148 -0
  185. package/maintenance.js.map +1 -0
  186. package/maintenance.ts +154 -0
  187. package/measure.js +133 -0
  188. package/measure.js.map +1 -0
  189. package/measure.ts +167 -0
  190. package/measure_worker.ts +18 -0
  191. package/memo.js +1250 -0
  192. package/memo.js.map +1 -0
  193. package/memo.ts +1480 -0
  194. package/meta.js +265 -0
  195. package/meta.js.map +1 -0
  196. package/meta.ts +321 -0
  197. package/migration.js +272 -0
  198. package/migration.js.map +1 -0
  199. package/migration.ts +286 -0
  200. package/mod.js +1103 -0
  201. package/mod.js.map +1 -0
  202. package/mod.ts +1762 -0
  203. package/mode.js +192 -0
  204. package/mode.js.map +1 -0
  205. package/mode.ts +207 -0
  206. package/native.js +544 -0
  207. package/native.js.map +1 -0
  208. package/native.ts +544 -0
  209. package/overlay.js +408 -0
  210. package/overlay.js.map +1 -0
  211. package/overlay.ts +485 -0
  212. package/owe.js +719 -0
  213. package/owe.js.map +1 -0
  214. package/owe.ts +873 -0
  215. package/package.json +99 -4
  216. package/physical.js +350 -0
  217. package/physical.js.map +1 -0
  218. package/physical.ts +434 -0
  219. package/plan.js +78 -0
  220. package/plan.js.map +1 -0
  221. package/plan.ts +104 -0
  222. package/point.js +81 -0
  223. package/point.js.map +1 -0
  224. package/point.ts +52 -0
  225. package/population.js +639 -0
  226. package/population.js.map +1 -0
  227. package/population.ts +630 -0
  228. package/purge.js +117 -0
  229. package/purge.js.map +1 -0
  230. package/purge.ts +127 -0
  231. package/raise.js +270 -0
  232. package/raise.js.map +1 -0
  233. package/raise.ts +316 -0
  234. package/read-db.js +381 -0
  235. package/read-db.js.map +1 -0
  236. package/read-db.ts +282 -0
  237. package/read-store.js +74 -0
  238. package/read-store.js.map +1 -0
  239. package/read-store.ts +86 -0
  240. package/read.js +1100 -0
  241. package/read.js.map +1 -0
  242. package/read.ts +1441 -0
  243. package/reader.js +141 -0
  244. package/reader.js.map +1 -0
  245. package/reader.ts +159 -0
  246. package/rules.js +88 -0
  247. package/rules.js.map +1 -0
  248. package/rules.ts +113 -0
  249. package/service.js +27 -0
  250. package/service.js.map +1 -0
  251. package/service.ts +41 -0
  252. package/shape.js +76 -0
  253. package/shape.js.map +1 -0
  254. package/shape.ts +108 -0
  255. package/sparse_presence_fixture.ts +45 -0
  256. package/sqlitepath.js +24 -0
  257. package/sqlitepath.js.map +1 -0
  258. package/sqlitepath.ts +29 -0
  259. package/statements.js +78 -0
  260. package/statements.js.map +1 -0
  261. package/statements.ts +96 -0
  262. package/survey.js +135 -0
  263. package/survey.js.map +1 -0
  264. package/survey.ts +196 -0
  265. package/tools.js +17 -0
  266. package/tools.js.map +1 -0
  267. package/tools.ts +50 -0
  268. package/trash.js +144 -0
  269. package/trash.js.map +1 -0
  270. package/trash.ts +187 -0
  271. package/unit.js +215 -0
  272. package/unit.js.map +1 -0
  273. package/unit.ts +211 -0
  274. package/versions.js +115 -0
  275. package/versions.js.map +1 -0
  276. package/versions.ts +110 -0
  277. package/vocab.js +19 -0
  278. package/vocab.js.map +1 -0
  279. package/vocab.json +27 -0
  280. package/vocab.ts +19 -0
  281. package/watch.js +33 -0
  282. package/watch.js.map +1 -0
  283. package/watch.ts +42 -0
  284. package/write.js +1164 -0
  285. package/write.js.map +1 -0
  286. package/write.ts +1356 -0
  287. package/written.js +200 -0
  288. package/written.js.map +1 -0
  289. package/written.ts +202 -0
@@ -0,0 +1 @@
1
+ {"version":3,"file":"vocab.d.ts","sources":["../vocab.ts"],"names":[],"mappings":"AAMA,cAAc,QAAQ,2BAAgC;AAItD,mDAAmD,GACnD,OAAO,YAAI,WAAW,SAAc;AAEpC;uDACuD,GACvD,OAAO,YAAI,aAAa,MAAM,CAAuB;AAErD,yCAAyC,GACzC,OAAO,YAAI,MAAM,WAAwB"}
@@ -0,0 +1,169 @@
1
+ import type { Vocab } from "@yaks/vocab";
2
+ import type { Bundle, Comp, Entity } from "@yaks/graph";
3
+ import { type Series } from "@yaks/graph/storage";
4
+ import { type Delete, type Driver, type Expr, type Insert, type Row, type Update, type Write } from "@yaks/sql";
5
+ import { type Unsettled } from "./read.js";
6
+ type Resolve = (eid: string) => Expr;
7
+ /** What the store already knows about an eid: its number and the prefix of
8
+ * its series, and whether that identity is tombstoned. An eid with no entry
9
+ * has no entity yet. */ export type Spine = {
10
+ id: number;
11
+ num: number | null;
12
+ prefix?: string | null;
13
+ dead: boolean;
14
+ };
15
+ /** What the store knows about these eids — one statement and one bound
16
+ * parameter, whatever the batch's size (a Durable Object binds at most 100).
17
+ * An eid absent from the map has no entity; one present with `dead` is
18
+ * tombstoned, and a deleted identity is still an identity: it resolves by eid,
19
+ * and `revive` brings it back. */ export declare let spines: (driver: Driver, eids: string[]) => Map<string, Spine>;
20
+ /** The entities that are tombstoned, of those named. */ export declare let buried: (driver: Driver, eids: string[]) => Set<string>;
21
+ /**
22
+ * The statement that mints an identity, and returns what it minted.
23
+ * `do nothing` on an eid that already has an identity, so minting twice is not
24
+ * an error; RETURNING then emits no row, which is also how the caller knows
25
+ * whether this one was new. Left without a number, the spine is minted with a
26
+ * NULL one. `number` is the one the entity takes, in the series of `prefix`:
27
+ * a store seeded from another store's export adopts the ids that export
28
+ * already carries, because an entity read as `T-37574` somewhere is `T-37574`
29
+ * everywhere. The series follows — `entity_series_insert` raises its high
30
+ * water mark — so the next number given is still past it.
31
+ */ export declare let mintSql: (eid: string, number?: number, archetype?: number, prefix?: string | null) => Insert;
32
+ /** The statement that numbers a spine a reference minted, once a bundle of its
33
+ * own arrives: the number given, in the series of `prefix`. It returns what
34
+ * {@link mintSql} does, and nothing where the spine already has a number. */ export declare let numberSql: (eid: string, number: number, prefix?: string | null) => Update;
35
+ /** The identity a {@link mintSql} statement reported — the rows it returned —
36
+ * or `undefined` when the eid already had one and nothing was minted. */ export declare let minted: (rows: Row[]) => Entity | undefined;
37
+ /**
38
+ * Where an id another entity keeps as a name lives: the eid of the entity that
39
+ * would keep `T-12` as one (@yaks/alias `aliasEid`). A number given out
40
+ * before and kept as the name of what it named, once its entity was numbered
41
+ * again, is never given out again while that name stands.
42
+ */ export type Names = (prefix: string, num: number) => string;
43
+ /**
44
+ * The statement that patches one component onto one entity: insert the sent
45
+ * columns, or update just them on conflict, so an omitted property keeps what
46
+ * it held. A reference property binds its target's eid and resolves to that
47
+ * target's id in the statement. A component whose patch names no stored
48
+ * property is a tag — its row's existence is the whole fact.
49
+ *
50
+ * An INSERT…select is what makes the owner a subquery: no owner row, no
51
+ * inserted row.
52
+ *
53
+ * A tag insert is `or ignore` in both forms: existence is the whole fact it
54
+ * asserts, so a component whose table requires a column the tag cannot supply
55
+ * is a no-op rather than a failed batch. That is what keeps a server-written
56
+ * audit row — one the server writes with its own columns — impossible to create
57
+ * from a client request, without a client being able to fail the batch by
58
+ * naming it.
59
+ */ export declare let upsertSql: (v: Vocab, eid: string, comp: string, patch: Comp, absent?: boolean, resolve?: Resolve) => Insert;
60
+ /** The statement that drops one component from one entity — the row goes, the
61
+ * entity stays. */ export declare let dropSql: (eid: string, comp: string) => Delete;
62
+ /**
63
+ * The statements that patch one bundle in: a plan per component it names, a drop
64
+ * for each `null` one. Identity is minted separately (see {@link mintSql}),
65
+ * because a batch mints every eid it touches or points at before it writes
66
+ * anything.
67
+ */ export declare let patchSql: (v: Vocab, b: Bundle) => Write[];
68
+ /** The statement that clears an entity's tombstone, so the write that follows
69
+ * lands on the identity it kept. */ export declare let unburySql: (eid: string) => Delete;
70
+ /** Erase empty, unreferenced identity spines, the whole set in three
71
+ * statements whatever its size. The guard runs once per identity, in the
72
+ * write's transaction, including on a deferred adapter: a reference added
73
+ * since its read prevents erasure. The tombstones go first, unguarded, since
74
+ * an identity row is erased only once nothing keys to it; the final NOT NULL
75
+ * assertion then rolls the batch back, tombstones included, when the guard
76
+ * kept an identity, instead of reporting a repair that did not happen. */ export declare let pruneSql: (vocab: Vocab, eids: string[], held?: readonly string[]) => Write[];
77
+ /** Run an orphan repair's guarded physical erasure. */ export declare let prune: (driver: Driver, vocab: Vocab, eids: string[]) => void;
78
+ /**
79
+ * The statements that remove a set of entities: each component deletion and
80
+ * tombstone insert seeks one owner. An IN subquery lets small-table statistics
81
+ * choose a scan even for a single deletion; equality retains the primary-key
82
+ * plan. Tables arrive in declaration order and are cleared in reverse; an eid
83
+ * no entity uses tombstones nothing. Every statement fits the host bind limit.
84
+ */ export declare let removeSql: (tables: string[], entities: Entity[], at: string) => Write[];
85
+ /**
86
+ * The statements that erase a set of entities, a writer's own bookkeeping:
87
+ * their component rows as {@link removeSql} clears them, any before-image the
88
+ * trash kept of them (a patch that cleared a property keeps one), then their
89
+ * identity, with no tombstone and no pointer left to rewrite. Nothing else
90
+ * refers to such an entity, so its spine row goes with it.
91
+ */ export declare let eraseSql: (tables: string[], entities: Entity[]) => Write[];
92
+ /** Every eid these bundles touch or point at, in first-touch order — each
93
+ * bundle's own entity, then the targets of its reference properties. This is
94
+ * the order identity is minted in, so it is the order `num` follows. */ export declare let touched: (v: Vocab, bundles: Bundle[]) => string[];
95
+ /**
96
+ * The classes a unit's births are minted in. An entity is first written in a
97
+ * shape (the tables its first patch gives it) and its unit points it at the
98
+ * class it finished in (@yaks/archetype's flush, after the stamps). Minted in
99
+ * that class from the start, its last pointer restates what its mint said and
100
+ * is not written: pointing an entity rewrites every index of its spine row,
101
+ * since the pointer is a key into the spine's own table. A birth of a shape
102
+ * not seen finishing yet, or one that finishes elsewhere, is pointed as before.
103
+ */ export type Births = {
104
+ /** The archetype's integer id a birth opening holding `tables` is minted
105
+ * in, where one is known. */ class: (tables: string[]) => number | undefined;
106
+ /** `eid` was minted holding `tables`, in the archetype `id` if it says one. */ born: (eid: string, tables: string[], id?: number) => void;
107
+ /** `eid` is pointed at the archetype `id`: whether its mint said so. */ pointed: (eid: string, id: number) => boolean;
108
+ /** Whether `eid`'s mint wrote the pointer of the archetype that names
109
+ * exactly `tables`, so a birth that finished holding them owes none. */ settled: (eid: string, tables: string[]) => boolean;
110
+ /** The archetype `id` names exactly `tables`, which `eid` finished in. */ finished: (eid: string, tables: string[], id: number) => void;
111
+ };
112
+ /**
113
+ * How a store numbers its entities: not at all, by series given which letter
114
+ * each component numbers with ({@link Series}, @yaks/graph), or by the
115
+ * prefixes the vocabulary declares (`true`). An entity is numbered on the
116
+ * write that first gives it a component in the table, in the series
117
+ * `seriesOf` picks, and its letter never changes afterwards.
118
+ */ export type Numbering = boolean | Series;
119
+ /**
120
+ * Patch a batch of bundles in, in order, and return the spines this patch
121
+ * minted or numbered — each with the `num` and `prefix` it was given, as the
122
+ * statement itself reported it. A bundle for a tombstoned entity is skipped:
123
+ * bringing one back is `revive`'s, which @yaks/graph asks for first.
124
+ *
125
+ * An eid a reference only names still gets a spine, because a reference column
126
+ * holds its target's id, but that spine takes no number: it is a pointer to
127
+ * nothing, which a yaks app pointing into another app's store makes on
128
+ * purpose, and @yaks/graph brings no entity into being for it. It is numbered
129
+ * when a bundle of its own arrives, in this batch or a later one.
130
+ *
131
+ * A number is the one after the last its series gave (`entity_series`),
132
+ * stepping over one an entity holds.
133
+ *
134
+ * `moved` hears each component row this patch brought or took away, as the
135
+ * table and whether the entity holds one now: what may have moved its
136
+ * archetype (./archetype.ts `ledger`). A value-only patch says nothing.
137
+ *
138
+ * `had` is what memory says an entity held before this patch: a component
139
+ * it does not hold is written in one statement, as a new entity's are.
140
+ *
141
+ * An entity minted here takes its pointer in its mint where one is known: the
142
+ * one its own bundle names, or the class `born` says its shape finishes in
143
+ * ({@link Births}). A pointer its mint already wrote is not written again.
144
+ *
145
+ * `unsettled` says what an entity this transaction wrote holds, where the
146
+ * patch reads one (./read.ts `Unsettled`).
147
+ *
148
+ * `names` says where an id kept as another entity's name lives, so a number
149
+ * kept so is stepped over ({@link Names}).
150
+ */ export declare let patch: (driver: Driver, vocab: Vocab, bundles: Bundle[], number?: Numbering, moved?: Moved, had?: Known, born?: Births, unsettled?: Unsettled, names?: Names) => Entity[];
151
+ /** What memory says an entity holds of a component, read or written before:
152
+ * its row, with the values memory can vouch for as a read returns them,
153
+ * `null` for none, and `undefined` where memory does not know (./memo.ts). */ export type Known = (eid: string, name: string) => Comp | null | undefined;
154
+ /** What hears a component row come (`held`) or go, entity by entity. */ export type Moved = (eid: string, table: string, held: boolean) => void;
155
+ /** Bring these tombstoned entities back: each tombstone row goes, and the
156
+ * identity keeps its eid, number and integer id. No component returns; the
157
+ * patch after it gives them. An eid with no tombstone is left alone; `moved`
158
+ * hears each tombstone that went, as {@link patch} tells its rows. */ export declare let revive: (driver: Driver, eids: string[], moved?: Moved) => void;
159
+ /**
160
+ * Remove these entities: every component row they have goes, and their identity
161
+ * is tombstoned, keeping its eid and number. Exactly the entities named —
162
+ * @yaks/graph decided which they are. `held` is the tables they hold rows in,
163
+ * where the caller knows (a store that keeps archetypes reads them off the
164
+ * entities' pointers, ./archetype.ts `heldBy`); left out, it reads their
165
+ * pointers itself. An unclassified entity is a failure, never every table.
166
+ */ export declare let remove: (driver: Driver, _vocab: Vocab, entities: Entity[], held?: string[], at?: string) => void;
167
+ /** Erase these entities, rows and identity, leaving no tombstone
168
+ * ({@link eraseSql}). `held` is as {@link remove} takes it. */ export declare let erase: (driver: Driver, entities: Entity[], held?: string[]) => void;
169
+ //# sourceMappingURL=write.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"write.d.ts","sources":["../write.ts"],"names":[],"mappings":"AA6CA,cAAc,KAAK,2BAAgC;AACnD,cAAc,MAAM,EAAE,IAAI,EAAE,MAAM,2BAAgC;AAIlE,SAIE,KAAK,MAAM,mCAG0B;AACvC,SASE,KAAK,MAAM,EACX,KAAK,MAAM,EAKX,KAAK,IAAI,EAIT,KAAK,MAAM,EASX,KAAK,GAAG,EAIR,KAAK,MAAM,EAGX,KAAK,KAAK,yBACiB;AAO7B,SAAgC,KAAK,SAAS,oBAAmB;KA0B5D,WAAW,KAAK,MAAM,KAAK;AAchC;;sBAEsB,GACtB,YAAY;EACV,IAAI,MAAM;EACV,KAAK,MAAM,GAAG,IAAI;EAClB,SAAS,MAAM,GAAG,IAAI;EACtB,MAAM,OAAO;;AAGf;;;;gCAIgC,GAChC,OAAO,YAAI,SACT,QAAQ,QACR,MAAM,MAAM,OACX,IAAI,MAAM,EAAE,OAGA;AA8Bf,sDAAsD,GACtD,OAAO,YAAI,SAAU,QAAQ,QAAQ,MAAM,MAAM,OAAK,IAAI,MAAM,EAK7D;AAKH;;;;;;;;;;CAUC,GACD,OAAO,YAAI,UACT,KAAK,MAAM,EACX,SAAS,MAAM,EACf,YAAY,MAAM,EAClB,SAAQ,MAAM,GAAG,IAAI,KACpB,OAYD;AAgBF;;2EAE2E,GAC3E,OAAO,YAAI,YACT,KAAK,MAAM,EACX,QAAQ,MAAM,EACd,SAAQ,MAAM,GAAG,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GACtE,UAAU,KAAK,MAAM,EAAE,QAAQ,MAAM,OAAO,OAAO;EACnD,wEAAwE,GACxE,WAAW,KAAK,MAAM,EAAE,QAAQ,MAAM,IAAI,IAAI,MAAM,KAAK,IAAI;;AAuI/D;;;;;;CAMC,GACD,YAAY,YAAY,OAAO,GAAG;AAMlC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA+BC,GACD,OAAO,YAAI,QACT,QAAQ,QACR,OAAO,OACP,SAAS,UACT,SAAQ,WACR,QAAQ,OACR,MAAM,OACN,OAAO,QACP,YAAY,WACZ,QAAQ,UACP,SAqSF;AAmCD;;4EAE4E,GAC5E,YAAY,SAAS,KAAK,MAAM,EAAE,MAAM,MAAM,KAAK,OAAO,IAAI,GAAG,SAAS;AAQ1E,sEAAsE,GACtE,YAAY,SAAS,KAAK,MAAM,EAAE,OAAO,MAAM,EAAE,MAAM,OAAO,KAAK,IAAI;AAEvE;;;oEAGoE,GACpE,OAAO,YAAI,SAAU,QAAQ,QAAQ,MAAM,MAAM,IAAI,QAAQ,UAAQ,IAAI,CAIxE;AAED;;;;;;;CAOC,GACD,OAAO,YAAI,SACT,QAAQ,QACR,QAAQ,OACR,UAAU,UACV,OAAM,MAAM,IACZ,KAAI,MAAM,KACT,IAAI,CAEN;AAED;6DAC6D,GAC7D,OAAO,YAAI,QACT,QAAQ,QACR,UAAU,UACV,OAAM,MAAM,OACX,IAAI,CAEN"}
package/answer.js ADDED
@@ -0,0 +1,110 @@
1
+ // Query answers share their column names and scalar values. UUIDs occupy their
2
+ // sixteen content bytes, so a repeated projection fits the same byte bound as
3
+ // a small object answer without widening the cache.
4
+ let uuid = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/;
5
+ let negativeZero = Symbol('negative zero');
6
+ let hex = Array.from({
7
+ length: 256
8
+ }, (_, i)=>i.toString(16).padStart(2, '0'));
9
+ let unpack = (bytes, at)=>{
10
+ let text = '';
11
+ for(let i = at * 16; i < (at + 1) * 16; i++)text += hex[bytes[i]];
12
+ return `${text.slice(0, 8)}-${text.slice(8, 12)}-${text.slice(12, 16)}-` + `${text.slice(16, 20)}-${text.slice(20)}`;
13
+ };
14
+ /** A copied answer and its retained value bytes, bounded by the caller. */ export let packed = (rows, limit = 16 << 10)=>{
15
+ let text = JSON.stringify(rows, (_key, v)=>typeof v == 'bigint' ? String(v) : v);
16
+ let plain = ()=>text.length * 2 <= limit ? {
17
+ bytes: text.length * 2,
18
+ rows: structuredClone(rows)
19
+ } : undefined;
20
+ if (text.length * 2 <= limit) return plain();
21
+ let cols = Object.keys(rows[0]);
22
+ if (rows.length * cols.length * 2 > limit) return plain();
23
+ let unique = new Set(rows.map((r)=>r.eid));
24
+ let inline = cols[0] == 'eid' && unique.size == rows.length && rows.every((r)=>typeof r.eid == 'string' && uuid.test(r.eid));
25
+ let identity = [];
26
+ let ids = new Map(), atoms = new Map();
27
+ let values = [], bytes = [], codes = [];
28
+ for (let row of rows){
29
+ let keys = Object.keys(row);
30
+ if (keys.length != cols.length || keys.some((k, i)=>k != cols[i])) {
31
+ return plain();
32
+ }
33
+ for (let col of cols){
34
+ let value = row[col];
35
+ if (inline && col == 'eid') {
36
+ let raw = String(value).replaceAll('-', '');
37
+ for(let i = 0; i < 32; i += 2){
38
+ identity.push(parseInt(raw.slice(i, i + 2), 16));
39
+ }
40
+ continue;
41
+ }
42
+ if (value != null && typeof value == 'object' || typeof value == 'function' || typeof value == 'symbol') return plain();
43
+ if (typeof value == 'string' && uuid.test(value)) {
44
+ let id = ids.get(value);
45
+ if (id == null) {
46
+ id = ids.size;
47
+ ids.set(value, id);
48
+ let raw = value.replaceAll('-', '');
49
+ for(let i = 0; i < 32; i += 2){
50
+ bytes.push(parseInt(raw.slice(i, i + 2), 16));
51
+ }
52
+ }
53
+ codes.push(0x8000 | id);
54
+ } else {
55
+ let key = Object.is(value, -0) ? negativeZero : value;
56
+ let id = atoms.get(key);
57
+ if (id == null) {
58
+ id = values.length;
59
+ atoms.set(key, id);
60
+ values.push(value);
61
+ }
62
+ codes.push(id);
63
+ }
64
+ }
65
+ if (codes.length * 2 + bytes.length + identity.length > limit) {
66
+ return plain();
67
+ }
68
+ }
69
+ if (!inline && !ids.size || ids.size > 0x8000 || atoms.size > 0x8000) {
70
+ return plain();
71
+ }
72
+ if (inline) cols = cols.slice(1);
73
+ let eids = inline ? new Uint8Array(identity) : undefined;
74
+ let data = new Uint16Array(codes), names = new Uint8Array(bytes);
75
+ let size = data.byteLength + names.byteLength + (eids?.byteLength ?? 0) + JSON.stringify([
76
+ cols,
77
+ values
78
+ ], (_key, v)=>typeof v == 'bigint' ? String(v) : v).length * 2;
79
+ if (size > limit || size >= text.length * 2) return plain();
80
+ return {
81
+ bytes: size,
82
+ cols,
83
+ values,
84
+ names,
85
+ data,
86
+ eids
87
+ };
88
+ };
89
+ /** A fresh answer: neither a row nor a nested value aliases the kept one. */ export let copied = (answer)=>{
90
+ if ('rows' in answer) return structuredClone(answer.rows);
91
+ let { cols, values, names, data, eids } = answer;
92
+ let named = Array.from({
93
+ length: names.length / 16
94
+ }, (_, i)=>unpack(names, i));
95
+ return Array.from({
96
+ length: eids ? eids.length / 16 : data.length / cols.length
97
+ }, (_, i)=>({
98
+ ...eids ? {
99
+ eid: unpack(eids, i)
100
+ } : {},
101
+ ...Object.fromEntries(cols.map((col, j)=>{
102
+ let code = data[i * cols.length + j];
103
+ return [
104
+ col,
105
+ code & 0x8000 ? named[code & 0x7fff] : values[code]
106
+ ];
107
+ }))
108
+ }));
109
+ };
110
+ //# sourceMappingURL=answer.js.map
package/answer.js.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"file":"answer.js","sources":["./answer.ts"],"names":[],"mappings":"AAAA,+EAA+E;AAC/E,8EAA8E;AAC9E,oDAAoD;AAapD,IAAI,OAAO;AACX,IAAI,eAAe,OAAO;AAC1B,IAAI,MAAM,MAAM,IAAI,CAAC;EAAE,QAAQ;AAAI,GAAG,CAAC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AC,KAAK;QACnC,IAAI,OAAO,IAAI,CAAC,IAAI,KAAK,MAAM,GAAG,EAAE;QACpC,OAAO;UAAC;UAAK,OAAO,SAAS,KAAK,CAAC,OAAO,OAAO,GAAG,MAAM,CAAC,KAAK;SAAC;MACnE,GAAG;IACL,CAAC;AAEL,EAAC"}
package/answer.ts ADDED
@@ -0,0 +1,122 @@
1
+ // Query answers share their column names and scalar values. UUIDs occupy their
2
+ // sixteen content bytes, so a repeated projection fits the same byte bound as
3
+ // a small object answer without widening the cache.
4
+ import type { Row } from 'jsr:@yaks/sql@0.2.36/core'
5
+
6
+ export type Answer =
7
+ | { bytes: number; rows: Row[] }
8
+ | {
9
+ bytes: number
10
+ cols: string[]
11
+ values: unknown[]
12
+ names: Uint8Array
13
+ eids?: Uint8Array
14
+ data: Uint16Array
15
+ }
16
+ let uuid = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/
17
+ let negativeZero = Symbol('negative zero')
18
+ let hex = Array.from({ length: 256 }, (_, i) => i.toString(16).padStart(2, '0'))
19
+ let unpack = (bytes: Uint8Array, at: number) => {
20
+ let text = ''
21
+ for (let i = at * 16; i < (at + 1) * 16; i++) text += hex[bytes[i]]
22
+ return `${text.slice(0, 8)}-${text.slice(8, 12)}-${text.slice(12, 16)}-` +
23
+ `${text.slice(16, 20)}-${text.slice(20)}`
24
+ }
25
+
26
+ /** A copied answer and its retained value bytes, bounded by the caller. */
27
+ export let packed = (rows: Row[], limit = 16 << 10): Answer | undefined => {
28
+ let text = JSON.stringify(
29
+ rows,
30
+ (_key, v) => typeof v == 'bigint' ? String(v) : v,
31
+ )
32
+ let plain = () =>
33
+ text.length * 2 <= limit
34
+ ? { bytes: text.length * 2, rows: structuredClone(rows) }
35
+ : undefined
36
+ if (text.length * 2 <= limit) return plain()
37
+ let cols = Object.keys(rows[0])
38
+ if (rows.length * cols.length * 2 > limit) return plain()
39
+ let unique = new Set(rows.map((r) => r.eid))
40
+ let inline = cols[0] == 'eid' && unique.size == rows.length &&
41
+ rows.every((r) => typeof r.eid == 'string' && uuid.test(r.eid))
42
+ let identity: number[] = []
43
+ let ids = new Map<string, number>(), atoms = new Map<unknown, number>()
44
+ let values: unknown[] = [], bytes: number[] = [], codes: number[] = []
45
+ for (let row of rows) {
46
+ let keys = Object.keys(row)
47
+ if (keys.length != cols.length || keys.some((k, i) => k != cols[i])) {
48
+ return plain()
49
+ }
50
+ for (let col of cols) {
51
+ let value = row[col]
52
+ if (inline && col == 'eid') {
53
+ let raw = String(value).replaceAll('-', '')
54
+ for (let i = 0; i < 32; i += 2) {
55
+ identity.push(parseInt(raw.slice(i, i + 2), 16))
56
+ }
57
+ continue
58
+ }
59
+ if (
60
+ value != null && typeof value == 'object' ||
61
+ typeof value == 'function' || typeof value == 'symbol'
62
+ ) return plain()
63
+ if (typeof value == 'string' && uuid.test(value)) {
64
+ let id = ids.get(value)
65
+ if (id == null) {
66
+ id = ids.size
67
+ ids.set(value, id)
68
+ let raw = value.replaceAll('-', '')
69
+ for (let i = 0; i < 32; i += 2) {
70
+ bytes.push(parseInt(raw.slice(i, i + 2), 16))
71
+ }
72
+ }
73
+ codes.push(0x8000 | id)
74
+ } else {
75
+ let key = Object.is(value, -0) ? negativeZero : value
76
+ let id = atoms.get(key)
77
+ if (id == null) {
78
+ id = values.length
79
+ atoms.set(key, id)
80
+ values.push(value)
81
+ }
82
+ codes.push(id)
83
+ }
84
+ }
85
+ if (codes.length * 2 + bytes.length + identity.length > limit) {
86
+ return plain()
87
+ }
88
+ }
89
+ if (!inline && !ids.size || ids.size > 0x8000 || atoms.size > 0x8000) {
90
+ return plain()
91
+ }
92
+ if (inline) cols = cols.slice(1)
93
+ let eids = inline ? new Uint8Array(identity) : undefined
94
+ let data = new Uint16Array(codes), names = new Uint8Array(bytes)
95
+ let size = data.byteLength + names.byteLength + (eids?.byteLength ?? 0) +
96
+ JSON.stringify(
97
+ [cols, values],
98
+ (_key, v) => typeof v == 'bigint' ? String(v) : v,
99
+ ).length * 2
100
+ if (size > limit || size >= text.length * 2) return plain()
101
+ return { bytes: size, cols, values, names, data, eids }
102
+ }
103
+
104
+ /** A fresh answer: neither a row nor a nested value aliases the kept one. */
105
+ export let copied = (answer: Answer): Row[] => {
106
+ if ('rows' in answer) return structuredClone(answer.rows)
107
+ let { cols, values, names, data, eids } = answer
108
+ let named = Array.from(
109
+ { length: names.length / 16 },
110
+ (_, i) => unpack(names, i),
111
+ )
112
+ return Array.from(
113
+ { length: eids ? eids.length / 16 : data.length / cols.length },
114
+ (_, i) => ({
115
+ ...eids ? { eid: unpack(eids, i) } : {},
116
+ ...Object.fromEntries(cols.map((col, j) => {
117
+ let code = data[i * cols.length + j]
118
+ return [col, code & 0x8000 ? named[code & 0x7fff] : values[code]]
119
+ })),
120
+ }),
121
+ )
122
+ }