@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
package/ffi/util.js ADDED
@@ -0,0 +1,32 @@
1
+ import { SQLITE3_DONE, SQLITE3_MISUSE, SQLITE3_OK } from "./constants.js";
2
+ import ffi from "./ffi.js";
3
+ const { sqlite3_errmsg, sqlite3_errstr } = ffi;
4
+ export const encoder = new TextEncoder();
5
+ export function toCString(str) {
6
+ return encoder.encode(str + '\0');
7
+ }
8
+ export function isObject(value) {
9
+ return typeof value === 'object' && value !== null;
10
+ }
11
+ export class SqliteError extends Error {
12
+ code;
13
+ name;
14
+ constructor(code = 1, message = 'Unknown Error'){
15
+ super(`${code}: ${message}`), this.code = code, this.name = 'SqliteError';
16
+ }
17
+ }
18
+ export function unwrap(code, db) {
19
+ if (code === SQLITE3_OK || code === SQLITE3_DONE) return;
20
+ if (code === SQLITE3_MISUSE) {
21
+ throw new SqliteError(code, 'SQLite3 API misuse');
22
+ } else if (db !== undefined) {
23
+ const errmsg = sqlite3_errmsg(db);
24
+ if (errmsg === null) throw new SqliteError(code);
25
+ throw new Error(Deno.UnsafePointerView.getCString(errmsg));
26
+ } else {
27
+ throw new SqliteError(code, Deno.UnsafePointerView.getCString(sqlite3_errstr(code)));
28
+ }
29
+ }
30
+ export const buf = Deno.UnsafePointerView.getArrayBuffer;
31
+ export const readCstr = Deno.UnsafePointerView.getCString;
32
+ //# sourceMappingURL=util.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"util.js","sources":["./util.ts"],"names":[],"mappings":"AAAA,SAAS,YAAY,EAAE,cAAc,EAAE,UAAU,yBAAwB;AACzE,OAAO,oBAAmB;AAE1B,MAAM,EACJ,cAAc,EACd,cAAc,EACf,GAAG;AAEJ,OAAO,MAAM,UAAU,IAAI,cAAa;AAExC,OAAO,SAAS,UAAU,GAAW;EACnC,OAAO,QAAQ,MAAM,CAAC,MAAM;AAC9B;AAEA,OAAO,SAAS,SAAS,KAAc;EACrC,OAAO,OAAO,UAAU,YAAY,UAAU;AAChD;AAEA,OAAO,MAAM,oBAAoB;;EACtB,KAAoB;EAE7B,YACE,AAAO,OAAe,CAAC,EACvB,UAAkB,eAAe,CACjC;IACA,KAAK,CAAC,GAAG,KAAK,EAAE,EAAE,SAAS,QAHpB,OAAA,WAHA,OAAO;EAOhB;AACF;AAEA,OAAO,SAAS,OAAO,IAAY,EAAE,EAAsB;EACzD,IAAI,SAAS,cAAc,SAAS,cAAc;EAClD,IAAI,SAAS,gBAAgB;IAC3B,MAAM,IAAI,YAAY,MAAM;EAC9B,OAAO,IAAI,OAAO,WAAW;IAC3B,MAAM,SAAS,eAAe;IAC9B,IAAI,WAAW,MAAM,MAAM,IAAI,YAAY;IAC3C,MAAM,IAAI,MAAM,KAAK,iBAAiB,CAAC,UAAU,CAAC;EACpD,OAAO;IACL,MAAM,IAAI,YACR,MACA,KAAK,iBAAiB,CAAC,UAAU,CAAC,eAAe;EAErD;AACF;AAEA,OAAO,MAAM,MAAM,KAAK,iBAAiB,CAAC,cAAc,CAAA;AAExD,OAAO,MAAM,WAAW,KAAK,iBAAiB,CAAC,UAAU,CAAA"}
package/ffi/util.ts ADDED
@@ -0,0 +1,48 @@
1
+ import { SQLITE3_DONE, SQLITE3_MISUSE, SQLITE3_OK } from './constants.js'
2
+ import ffi from './ffi.js'
3
+
4
+ const {
5
+ sqlite3_errmsg,
6
+ sqlite3_errstr,
7
+ } = ffi
8
+
9
+ export const encoder = new TextEncoder()
10
+
11
+ export function toCString(str: string): Uint8Array<ArrayBuffer> {
12
+ return encoder.encode(str + '\0')
13
+ }
14
+
15
+ export function isObject(value: unknown): boolean {
16
+ return typeof value === 'object' && value !== null
17
+ }
18
+
19
+ export class SqliteError extends Error {
20
+ override name = 'SqliteError'
21
+
22
+ constructor(
23
+ public code: number = 1,
24
+ message: string = 'Unknown Error',
25
+ ) {
26
+ super(`${code}: ${message}`)
27
+ }
28
+ }
29
+
30
+ export function unwrap(code: number, db?: Deno.PointerValue): void {
31
+ if (code === SQLITE3_OK || code === SQLITE3_DONE) return
32
+ if (code === SQLITE3_MISUSE) {
33
+ throw new SqliteError(code, 'SQLite3 API misuse')
34
+ } else if (db !== undefined) {
35
+ const errmsg = sqlite3_errmsg(db)
36
+ if (errmsg === null) throw new SqliteError(code)
37
+ throw new Error(Deno.UnsafePointerView.getCString(errmsg))
38
+ } else {
39
+ throw new SqliteError(
40
+ code,
41
+ Deno.UnsafePointerView.getCString(sqlite3_errstr(code)!),
42
+ )
43
+ }
44
+ }
45
+
46
+ export const buf = Deno.UnsafePointerView.getArrayBuffer
47
+
48
+ export const readCstr = Deno.UnsafePointerView.getCString
package/follow.js ADDED
@@ -0,0 +1,342 @@
1
+ // A graph's schema follows its vocabulary wherever the graph is opened for
2
+ // writing (D-121389). Everything a file needs is one composed schema, and the
3
+ // schema has one print. A file records each print it has been brought to, as
4
+ // the `server_meta` row `schema:<print>`; an opener whose print is recorded
5
+ // opens with no DDL and no write lock, and one whose print is missing runs the
6
+ // pass that brings the file to it, then records it. A recorded print stays
7
+ // recorded while the file only grows, so a process still running the
8
+ // vocabulary a landing replaced finds its own print and changes nothing; a
9
+ // pass that sheds what its vocabulary stopped naming forgets the others.
10
+ //
11
+ // Two openers that find the same print missing both run the pass: every step
12
+ // of it reads the file under the write lock before it changes anything, so the
13
+ // second one finds nothing left to do. An index over a populated table, a
14
+ // text index over one, and a big table's refit are written down instead, for
15
+ // the effects worker to do in windows (./owe.ts).
16
+ import { catalogue, render, stored } from "@yaks/sql/core";
17
+ import { col, field, lit, notNull, select, tagOf } from "@yaks/sql";
18
+ import { sha256 } from "@yaks/graph/sha256";
19
+ import { analyzedAt, installation, installed, meta, PRINTED, printed, prints, SCHEMA } from "./meta.js";
20
+ import { unit } from "./unit.js";
21
+ import { build, holds as rowed } from "./owe.js";
22
+ import { plan, planned } from "./plan.js";
23
+ import { behind, declares, exact } from "./ddl.js";
24
+ import { tables } from "./layout.js";
25
+ import { recorded, unraised } from "./raise.js";
26
+ import { columns, columnsBy, componentTables, pinned, words } from "./physical.js";
27
+ /** The print of a composed schema: a store's own print (`Store.print`) and
28
+ * every further statement the file needs, rendered. */ export let printOf = (store, stmts)=>sha256([
29
+ store,
30
+ ...stmts.map((s)=>render(s).sql)
31
+ ].join(';\n'));
32
+ /** What `Store.print` says, known from the vocabulary alone: for a host that
33
+ * composes its print before it binds the store it will open with it, the way
34
+ * a yaks.app store keeps one print per vocabulary it has seen. */ export let printFor = (vocab, derived = {}, file = false)=>plan(vocab, derived, file).print;
35
+ /** {@link printFor}, digested by the platform: a host that can wait before it
36
+ * binds the store it opens asks this first, and the store finds its print
37
+ * made rather than digesting a hundred kilobytes of statements in script. */ export let printing = (vocab, derived = {}, file = false)=>planned(vocab, derived, file).then((p)=>p.print);
38
+ // A column as `add column` takes it onto a standing table: SQLite refuses a
39
+ // key or a unique column there, a NOT NULL without a literal default, and a
40
+ // default that is an expression. The CHECK waits for the table's refit, since
41
+ // adding one reads every row; admission holds the writes meanwhile.
42
+ let added = (c)=>{
43
+ let d = c.default?.t == 'lit' ? c.default : undefined;
44
+ return {
45
+ name: c.name,
46
+ type: c.type,
47
+ notNull: c.notNull && !!d,
48
+ default: d,
49
+ ref: c.ref
50
+ };
51
+ };
52
+ /** The `add column` statements the tables `stmts` create are missing where
53
+ * they already stand: `create table if not exists` does nothing to a table
54
+ * that is there, so a column a table gained after it was made arrives here.
55
+ * `held` is the schema as it stood before `stmts` ran (`catalogue`): a table
56
+ * it lacks was made whole by the first statement naming it, and one it holds
57
+ * as a statement declares it has every column, so neither is asked about. */ export let grow = (driver, stmts, held = catalogue(driver))=>{
58
+ let stood = new Map(held.map((o)=>[
59
+ o.name,
60
+ o.sql
61
+ ]));
62
+ let made = new Set();
63
+ return stmts.flatMap((s)=>{
64
+ if (s.t != 'create table') return [];
65
+ if (!stood.has(s.name) && !made.has(s.name)) {
66
+ made.add(s.name);
67
+ return [];
68
+ }
69
+ if (declares(stood.get(s.name) ?? null, s, driver.stored?.v)) return [];
70
+ let has = new Set(driver.query({
71
+ t: 'pragma',
72
+ name: 'table_info',
73
+ arg: s.name
74
+ }).map((r)=>String(r.name)));
75
+ if (!has.size) return [];
76
+ return s.cols.filter((c)=>!has.has(c.name)).map((c)=>({
77
+ t: 'alter table',
78
+ table: s.name,
79
+ add: added(c)
80
+ }));
81
+ });
82
+ };
83
+ /** Run `stmts`, each of which only adds what is missing, then the columns
84
+ * their standing tables lack, in one unit under the write lock. An index over
85
+ * a populated table is owed rather than built, and a unique index the rows
86
+ * already there break is left unbuilt and returned for the caller to report
87
+ * (./owe.ts). */ export let add = (driver, stmts)=>unit(driver, ()=>{
88
+ let held = catalogue(driver);
89
+ let left = build(driver, stmts);
90
+ for (let s of grow(driver, stmts, held))driver.query(s);
91
+ return left;
92
+ });
93
+ // Whether any row of `name` holds a value in its column `c`.
94
+ let valued = (driver, name, c)=>{
95
+ let v = driver.stored?.v;
96
+ return driver.query(select({
97
+ cols: [
98
+ lit(1)
99
+ ],
100
+ from: {
101
+ t: 'table',
102
+ name: v ? stored(v, name) : name,
103
+ physical: true
104
+ },
105
+ where: notNull(col(v ? stored(v, name, c) : c)),
106
+ limit: lit(1)
107
+ })).length > 0;
108
+ };
109
+ let dropOf = (kind, name)=>({
110
+ t: 'drop',
111
+ kind,
112
+ name,
113
+ ifExists: true
114
+ });
115
+ // The statements dropping `seat`: each view and trigger naming its table, or
116
+ // each index, trigger and view naming the table and its column, which SQLite
117
+ // refuses a column's drop for while they stand and a table's drop leaves
118
+ // standing over nothing, and then the table or the column.
119
+ let unseating = (driver, [t, c])=>[
120
+ ...catalogue(driver).flatMap((o)=>{
121
+ if (o.type == 'table' || o.sql == null || !c && o.type == 'index') {
122
+ return [];
123
+ }
124
+ let said = words(o.sql);
125
+ let v = driver.stored?.v;
126
+ let name = v ? stored(v, t) : t;
127
+ let prop = c && v ? stored(v, t, c) : c;
128
+ let names = said.has(name.toLowerCase()) && (!prop || said.has(prop.toLowerCase()));
129
+ return names ? [
130
+ dropOf(o.type, o.name)
131
+ ] : [];
132
+ }),
133
+ c ? {
134
+ t: 'alter table',
135
+ table: t,
136
+ drop: c
137
+ } : {
138
+ t: 'drop',
139
+ kind: 'table',
140
+ name: t,
141
+ ifExists: true
142
+ }
143
+ ];
144
+ // The view or trigger SQLite says will not stand once a column goes, which a
145
+ // reading of the file did not find naming it: one over a table that is gone,
146
+ // or one that names the column in a way its words do not show.
147
+ let blocker = (e)=>{
148
+ let said = e instanceof Error ? e.message : String(e);
149
+ let [, kind, name] = said.match(/error in (view|trigger) ([^\s:]+)/i) ?? [];
150
+ return kind ? dropOf(kind.toLowerCase(), name) : undefined;
151
+ };
152
+ // Run `stmts` in one unit; where SQLite names a view or a trigger that stops
153
+ // them, run them again with it dropped first, once for each such.
154
+ let run = (driver, stmts)=>{
155
+ for(let first = [];;){
156
+ try {
157
+ return unit(driver, ()=>{
158
+ for (let s of [
159
+ ...first,
160
+ ...stmts
161
+ ])driver.query(s);
162
+ });
163
+ } catch (e) {
164
+ let more = blocker(e);
165
+ let again = more && first.some((s)=>render(s).sql == render(more).sql);
166
+ if (!more || again) throw e;
167
+ first = [
168
+ ...first,
169
+ more
170
+ ];
171
+ }
172
+ }
173
+ };
174
+ // Where something may have changed what a store's install made (a drop that
175
+ // took an index, a trigger or a view, or a writer that keeps no print), the
176
+ // schema its receipt says goes, so the next install looks at the file rather
177
+ // than taking it as it left it. The planner statistics it keeps beside stay.
178
+ let unreceipted = (driver)=>{
179
+ let held = installation(driver);
180
+ if (!held?.schema) return;
181
+ if (held.statistics) analyzedAt(driver, '', held.statistics);
182
+ else meta(driver).del(SCHEMA);
183
+ };
184
+ // Where the file's schema moved under what it recorded (a drop), it stands at
185
+ // no print it recorded but `kept`: its tables are surveyed again, its install
186
+ // receipt goes, and so does every other print, so the next opener of any of
187
+ // them runs its pass over the file as it now is.
188
+ let moved = (driver, kept)=>{
189
+ recorded(driver);
190
+ unreceipted(driver);
191
+ for (let p of prints(driver)){
192
+ if (p != kept) meta(driver).del(PRINTED + p);
193
+ }
194
+ };
195
+ /** Drop each of `seats` the file holds, a component's table or a column,
196
+ * whatever it holds, in one unit: for a host contracting what its words
197
+ * decided to let go of. Each view and trigger naming a table goes with it,
198
+ * and each index, trigger and view naming a column, which SQLite refuses the
199
+ * drop for while they stand; the next pass (`install`) makes again what the
200
+ * schema still wants of those. */ export let unseat = (driver, seats)=>{
201
+ let held = seats.filter(([t, c])=>{
202
+ let cols = columns(driver, t);
203
+ return c ? cols.includes(c) : cols.length > 0;
204
+ });
205
+ if (!held.length) return;
206
+ unit(driver, ()=>{
207
+ for (let seat of held)run(driver, unseating(driver, seat));
208
+ moved(driver);
209
+ });
210
+ };
211
+ /** The drops of what a file holds that `named` stopped naming ({@link
212
+ * unseat}): a component table (./physical.ts `componentTables`) no statement
213
+ * makes and no word names, once it holds no rows, and a column the statement
214
+ * making its table lacks, once no row holds a value in it. A table that holds
215
+ * a row, a column that holds a value, and a column its table's own definition
216
+ * holds in place (./physical.ts `pinned`) stay as they stand. */ export let shed = (driver, { vocab, beside = [] })=>{
217
+ let made = new Map();
218
+ for (let s of [
219
+ ...plan(vocab, {}, !!driver.file).raised,
220
+ ...beside
221
+ ]){
222
+ if (s.t != 'create table') continue;
223
+ let cols = made.get(s.name) ?? new Set();
224
+ for (let c of s.cols)cols.add(c.name.toLowerCase());
225
+ made.set(s.name, cols);
226
+ }
227
+ let gone = componentTables(driver, [
228
+ ...made.keys(),
229
+ ...vocab.all
230
+ ]).filter((name)=>!rowed(driver, name, 1));
231
+ let defined = new Map(catalogue(driver).map((o)=>[
232
+ o.name,
233
+ o.sql ?? ''
234
+ ]));
235
+ let unnamed = componentTables(driver, [], [
236
+ ...made.keys()
237
+ ]).flatMap((name)=>{
238
+ let sql = defined.get(name);
239
+ let held = pinned(sql ?? '');
240
+ return columnsBy(driver, name, sql).filter((c)=>{
241
+ let low = c.toLowerCase();
242
+ return !made.get(name).has(low) && !held.has(stored(vocab, name, c).toLowerCase()) && !valued(driver, name, c);
243
+ }).map((c)=>[
244
+ name,
245
+ c
246
+ ]);
247
+ });
248
+ return [
249
+ ...gone.map((name)=>[
250
+ name
251
+ ]),
252
+ ...unnamed
253
+ ];
254
+ };
255
+ // Drop one seat whole, or, where SQLite refuses it (a key, a unique column, a
256
+ // check on another column naming it), leave it standing. Whether it went.
257
+ let shedding = (driver, seat)=>{
258
+ try {
259
+ run(driver, unseating(driver, seat));
260
+ return true;
261
+ } catch (e) {
262
+ if (/cannot drop|error in table/i.test(String(e))) return false;
263
+ throw e;
264
+ }
265
+ };
266
+ /** Bring a file to the composed schema `print` names: nothing, where the file
267
+ * has recorded it; otherwise `pass`, which adds what is missing, and then the
268
+ * record. A pass that left something it could not do (a table it could not
269
+ * fit) answers false, and the print stays unrecorded so the next opener tries
270
+ * again. True when the pass ran.
271
+ *
272
+ * Given what the schema names, the pass first sheds what the file holds
273
+ * beyond it ({@link shed}), which the pass makes again where the schema still
274
+ * wants it (a view or a trigger that named a column shed with it). What SQLite
275
+ * refuses to drop stands, and the pass runs over it. A file
276
+ * that shed something no longer stands at any other print it recorded, so
277
+ * those are forgotten: an opener of the vocabulary that named it runs its pass
278
+ * again. A host whose vocabulary may shrink for a while and grow back (an
279
+ * application's older release, a rollback away) gives nothing, and the file
280
+ * keeps all it holds. */ export let follow = (driver, print, pass, named)=>{
281
+ if (printed(driver, print)) return false;
282
+ if (named) {
283
+ unit(driver, ()=>{
284
+ let drops = shed(driver, named).filter((seat)=>shedding(driver, seat));
285
+ if (!drops.length) return;
286
+ moved(driver, print);
287
+ });
288
+ }
289
+ if (pass() === false) return true;
290
+ unit(driver, ()=>meta(driver).set(PRINTED + print, new Date().toISOString()));
291
+ return true;
292
+ };
293
+ /** Forget that a file stands at `print`, so its next opener runs the pass
294
+ * again: for a host whose file something that keeps no print may have changed,
295
+ * the way a yaks.app store's older release, still a rollback away, installs
296
+ * over whatever a print stands for. The store's own install receipt is
297
+ * forgotten with it, so that install looks at the file again too. */ export let forget = (driver, print)=>{
298
+ if (!printed(driver, print) && !installed(driver)) return;
299
+ unit(driver, ()=>{
300
+ meta(driver).del(PRINTED + print);
301
+ unreceipted(driver);
302
+ });
303
+ };
304
+ /**
305
+ * What a reader binds over a file no writer has brought to its vocabulary yet:
306
+ * each stored property whose column the file's table lacks, read as null, the
307
+ * way an entity reads a property it was never given, and each component whose
308
+ * table the file lacks, read as a table no entity wears (@yaks/sql
309
+ * `absent`). A reader never changes the schema, so it reads what the file
310
+ * holds. Nothing, where the store's tables are as this vocabulary makes them,
311
+ * which costs the store's print and one read of `server_meta`.
312
+ */ export let lacking = (driver, vocab, derived = {}, physical = false)=>{
313
+ let mark = installed(driver)?.split(' ')[0];
314
+ // Installed as this vocabulary says, the file lacks no column, and no table
315
+ // but those of the words nothing has written yet (./raise.ts).
316
+ if (!physical && mark == plan(vocab, derived, !!driver.file).print) {
317
+ return {
318
+ derived: {},
319
+ absent: unraised(driver, vocab)
320
+ };
321
+ }
322
+ // Only a table declared otherwise than the vocabulary does can lack a
323
+ // column, so only those are asked about, two statements each, rather than
324
+ // every table on every open.
325
+ let kept = exact(driver, vocab);
326
+ let was = behind(driver, vocab, kept);
327
+ let held = tables(vocab);
328
+ return {
329
+ absent: held.filter((comp)=>!kept.has(comp) && !(comp in was)),
330
+ derived: Object.fromEntries(held.filter((comp)=>comp in was).flatMap((comp)=>{
331
+ let has = new Set(was[comp].cols.map((r)=>String(r.name)));
332
+ return vocab.props(comp).map((p)=>vocab.prop(comp, p)).filter((c)=>!c.computed && !has.has(field(c.prop)) && !derived[`${comp}.${c.prop}`]).map((c)=>[
333
+ `${comp}.${c.prop}`,
334
+ {
335
+ tag: tagOf(c),
336
+ expr: ()=>lit(null)
337
+ }
338
+ ]);
339
+ }))
340
+ };
341
+ };
342
+ //# sourceMappingURL=follow.js.map
package/follow.js.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"file":"follow.js","sources":["./follow.ts"],"names":[],"mappings":"AAAA,2EAA2E;AAC3E,8EAA8E;AAC9E,6EAA6E;AAC7E,4EAA4E;AAC5E,+EAA+E;AAC/E,2EAA2E;AAC3E,qEAAqE;AACrE,2EAA2E;AAC3E,yEAAyE;AACzE,EAAE;AACF,6EAA6E;AAC7E,+EAA+E;AAC/E,0EAA0E;AAC1E,6EAA6E;AAC7E,kDAAkD;AAElD,SACE,SAAS,EAGT,MAAM,EAGN,MAAM,8BAC0B;AAClC,SACE,GAAG,EAEH,KAAK,EACL,GAAG,EACH,OAAO,EACP,MAAM,EACN,KAAK,yBACsB;AAE7B,SAAS,MAAM,kCAAuC;AACtD,SACE,UAAU,EACV,YAAY,EACZ,SAAS,EACT,IAAI,EACJ,OAAO,EACP,OAAO,EACP,MAAM,EACN,MAAM,oBACU;AAClB,SAAS,IAAI,oBAAmB;AAChC,SAAS,KAAK,EAAE,SAAS,KAAK,mBAAkB;AAChD,SAAS,IAAI,EAAE,OAAO,oBAAmB;AACzC,SAAS,MAAM,EAAE,QAAQ,EAAE,KAAK,mBAAkB;AAClD,SAAS,MAAM,sBAAqB;AACpC,SAAS,QAAQ,EAAE,QAAQ,qBAAoB;AAC/C,SACE,OAAO,EACP,SAAS,EACT,eAAe,EACf,MAAM,EACN,KAAK,wBACe;AAEtB;qDACqD,GACrD,OAAO,IAAI,UAAU,CAAC,OAAe,QACnC,OAAO;IAAC;OAAU,MAAM,GAAG,CAAC,CAAC,IAAM,OAAO,GAAG,GAAG;GAAE,CAAC,I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