okmodel 0.5.1 → 0.7.0

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 (233) hide show
  1. package/README.md +100 -1116
  2. package/dist/adapters/capabilities.d.ts +3 -0
  3. package/dist/adapters/failure.d.ts +13 -2
  4. package/dist/adapters/lazy-errors.d.ts +22 -0
  5. package/dist/adapters/pg/bunsql-extra.d.ts +54 -3
  6. package/dist/adapters/pg/bunsql.d.ts +14 -1
  7. package/dist/adapters/pg/cursor.d.ts +17 -0
  8. package/dist/adapters/pg/no-inflight-timeout.d.ts +20 -0
  9. package/dist/adapters/pg/nodepostgres-extra.d.ts +22 -1
  10. package/dist/adapters/pg/nodepostgres.d.ts +12 -0
  11. package/dist/adapters/pg/pglite-wire.d.ts +24 -0
  12. package/dist/adapters/pg/pglite.d.ts +10 -0
  13. package/dist/adapters/pg/postgres-extra.d.ts +41 -3
  14. package/dist/adapters/pg/reserved.d.ts +42 -0
  15. package/dist/adapters/pg/session.d.ts +0 -18
  16. package/dist/contracts/catalog/document.d.ts +19 -5
  17. package/dist/contracts/catalog/object.d.ts +2 -1
  18. package/dist/contracts/catalog/policy.d.ts +48 -0
  19. package/dist/contracts/catalog/types.d.ts +25 -1
  20. package/dist/contracts/catalog/view.d.ts +2 -0
  21. package/dist/contracts/connection.d.ts +7 -6
  22. package/dist/contracts/internal.js +1 -1
  23. package/dist/contracts/location.d.ts +10 -0
  24. package/dist/dialects/pg/column.d.ts +13 -2
  25. package/dist/dialects/pg/ddl.d.ts +37 -1
  26. package/dist/dialects/pg/emit.d.ts +19 -1
  27. package/dist/dialects/pg/errors.d.ts +32 -1
  28. package/dist/dialects/pg/ext/citext.js +1 -1
  29. package/dist/dialects/pg/ext/index.js +1 -1
  30. package/dist/dialects/pg/ext/pg-trgm.js +1 -1
  31. package/dist/dialects/pg/filter-parse.d.ts +5 -4
  32. package/dist/dialects/pg/floor.d.ts +68 -0
  33. package/dist/dialects/pg/fn/index.js +2 -2
  34. package/dist/dialects/pg/index.d.ts +8 -2
  35. package/dist/dialects/pg/index.js +67 -171
  36. package/dist/dialects/pg/introspect.d.ts +7 -0
  37. package/dist/dialects/pg/keys.d.ts +11 -8
  38. package/dist/dialects/pg/model.d.ts +47 -2
  39. package/dist/dialects/pg/morph.d.ts +43 -0
  40. package/dist/dialects/pg/operator-fit.d.ts +2 -2
  41. package/dist/dialects/pg/operators.d.ts +14 -7
  42. package/dist/dialects/pg/ops/bucket.d.ts +65 -0
  43. package/dist/dialects/pg/ops/inc.d.ts +2 -2
  44. package/dist/dialects/pg/ops/matches.d.ts +9 -12
  45. package/dist/dialects/pg/ops/relevance.d.ts +13 -0
  46. package/dist/dialects/pg/ops/search-query.d.ts +22 -0
  47. package/dist/dialects/pg/ops/window.d.ts +103 -0
  48. package/dist/dialects/pg/owner.d.ts +42 -0
  49. package/dist/dialects/pg/path-endpoint.d.ts +20 -0
  50. package/dist/dialects/pg/preset.d.ts +1 -1
  51. package/dist/dialects/pg/relations.d.ts +100 -3
  52. package/dist/dialects/pg/role/check.d.ts +3 -0
  53. package/dist/dialects/pg/role/index.d.ts +71 -6
  54. package/dist/dialects/pg/role/sql.d.ts +11 -0
  55. package/dist/dialects/pg/schema.d.ts +33 -3
  56. package/dist/dialects/pg/table.d.ts +25 -3
  57. package/dist/dialects/pg/tenancy.d.ts +45 -3
  58. package/dist/dialects/pg/view/client.d.ts +19 -1
  59. package/dist/dialects/pg/view/index.d.ts +4 -0
  60. package/dist/dialects/pg/view/index.js +21 -178
  61. package/dist/dialects/pg/view/refresh.d.ts +24 -0
  62. package/dist/runtime/aggregate.d.ts +8 -2
  63. package/dist/runtime/batch.d.ts +1 -1
  64. package/dist/runtime/bucket-group.d.ts +70 -0
  65. package/dist/runtime/conflict.d.ts +24 -6
  66. package/dist/runtime/drift.d.ts +9 -0
  67. package/dist/runtime/include.d.ts +0 -8
  68. package/dist/runtime/inflight.d.ts +14 -0
  69. package/dist/runtime/page.d.ts +4 -1
  70. package/dist/runtime/pg/bun.js +12 -5
  71. package/dist/runtime/pg/pg.js +5 -5
  72. package/dist/runtime/pg/pglite.d.ts +1 -0
  73. package/dist/runtime/pg/pglite.js +9 -8
  74. package/dist/runtime/pg/postgresjs.js +5 -5
  75. package/dist/runtime/plan.d.ts +113 -15
  76. package/dist/runtime/predicate.d.ts +19 -0
  77. package/dist/runtime/read-stream.d.ts +13 -16
  78. package/dist/runtime/result-name.d.ts +17 -0
  79. package/dist/runtime/safety/index.js +1 -1
  80. package/dist/runtime/server-check.d.ts +3 -3
  81. package/dist/runtime/sort-bind.d.ts +21 -0
  82. package/dist/runtime/sort.d.ts +56 -0
  83. package/dist/runtime/sync.d.ts +70 -0
  84. package/dist/runtime/tenancy/composite.d.ts +26 -0
  85. package/dist/runtime/tenancy/context.d.ts +16 -0
  86. package/dist/runtime/tenancy/index.d.ts +9 -5
  87. package/dist/runtime/tenancy/index.js +1511 -38
  88. package/dist/runtime/tenancy/path.d.ts +87 -0
  89. package/dist/runtime/tenancy/rls.d.ts +67 -0
  90. package/dist/runtime/tenancy/via.d.ts +22 -0
  91. package/dist/runtime/text-search.d.ts +20 -0
  92. package/dist/runtime/traits/index.d.ts +80 -0
  93. package/dist/runtime/traits/index.js +187 -17
  94. package/dist/runtime/tree.d.ts +38 -0
  95. package/dist/runtime/types.d.ts +231 -23
  96. package/dist/runtime/validate/index.js +4 -4
  97. package/dist/runtime/version.d.ts +39 -0
  98. package/dist/runtime/window.d.ts +21 -0
  99. package/dist/runtime/write.d.ts +55 -3
  100. package/dist/shared/{krxx77g0.js → 14vx95q4.js} +12 -18
  101. package/dist/shared/1est4ezg.js +313 -0
  102. package/dist/shared/{4az561fn.js → 1qa0qajz.js} +8 -23
  103. package/dist/shared/1w508jbr.js +1611 -0
  104. package/dist/shared/2c13q96h.js +18 -0
  105. package/dist/shared/2d3xq4ps.js +9 -0
  106. package/dist/shared/2shdbn8q.js +23 -0
  107. package/dist/shared/{t4tbsy9h.js → 358zsv4r.js} +1 -1
  108. package/dist/shared/3v7t1yrv.js +208 -0
  109. package/dist/shared/5e3tf63j.js +220 -0
  110. package/dist/shared/5fe3kbsh.js +10 -0
  111. package/dist/shared/5v3xf80k.js +37 -0
  112. package/dist/shared/{51mvgj8w.js → 63qtkrca.js} +130 -3
  113. package/dist/shared/{gbtcc2d7.js → 67txcrcw.js} +62 -66
  114. package/dist/shared/79dt02vc.js +12 -0
  115. package/dist/shared/{v36c5g6p.js → 7k9grvf6.js} +407 -14
  116. package/dist/shared/7kms6fvj.js +20 -0
  117. package/dist/shared/7mnme5tn.js +8 -0
  118. package/dist/shared/7n7ddwt4.js +6 -0
  119. package/dist/shared/{87jvvhnt.js → 81ebdx9p.js} +48 -68
  120. package/dist/shared/{szm0cksa.js → 8skf0cam.js} +34 -6
  121. package/dist/shared/{gjthds9j.js → 9628a9xt.js} +1 -1
  122. package/dist/shared/9a4ae4p8.js +31 -0
  123. package/dist/shared/{8xsbagad.js → 9s0ypp87.js} +88 -7
  124. package/dist/shared/9y3mmmh1.js +436 -0
  125. package/dist/shared/ab9gmbwy.js +213 -0
  126. package/dist/shared/{sycnx8gt.js → ax7qv55k.js} +18 -8
  127. package/dist/shared/{f5cw5q5r.js → aytqh5y2.js} +6 -4
  128. package/dist/shared/{fancm5pt.js → b5pftnn2.js} +138 -15
  129. package/dist/shared/{efmy2gcg.js → b76b8d95.js} +2 -2
  130. package/dist/shared/bdk4sty6.js +58 -0
  131. package/dist/shared/{32zqc1dw.js → bg3rym3g.js} +63 -32
  132. package/dist/shared/{0t22wwh1.js → bm22fvzr.js} +16 -14
  133. package/dist/shared/bz84tkzm.js +342 -0
  134. package/dist/shared/{31vm914h.js → cm3w0ywp.js} +15 -16
  135. package/dist/shared/cn957f8d.js +179 -0
  136. package/dist/shared/{pf0d8f77.js → cnkky55j.js} +25 -14
  137. package/dist/shared/{5fqx9yh4.js → dk8v79p3.js} +3 -1
  138. package/dist/shared/{nkaxvt9q.js → dkxgzaqd.js} +224 -19
  139. package/dist/shared/dzj09cye.js +10 -0
  140. package/dist/shared/{4m9fn52z.js → ed0b8k4s.js} +1 -1
  141. package/dist/shared/{z2rnngj4.js → ek2wt2dz.js} +8 -5
  142. package/dist/shared/exn3sd90.js +359 -0
  143. package/dist/shared/g6evj1j3.js +66 -0
  144. package/dist/shared/ga9j92qj.js +25 -0
  145. package/dist/shared/{qv2ydck9.js → gs74dbj5.js} +651 -76
  146. package/dist/shared/gzaveazc.js +285 -0
  147. package/dist/shared/{8rsy3hxz.js → h15jx9bc.js} +1 -1
  148. package/dist/shared/{dyj86cmj.js → hyh73qk6.js} +3 -3
  149. package/dist/shared/je4axnm8.js +22 -0
  150. package/dist/shared/{ycatkxmq.js → jgqj11w4.js} +1 -1
  151. package/dist/shared/{6qd27mx0.js → jvd0mqag.js} +5 -5
  152. package/dist/shared/jznfax0y.js +155 -0
  153. package/dist/shared/{cgbamx3e.js → kb2sdhfb.js} +7 -4
  154. package/dist/shared/{ps7a6h14.js → kr0jzbw2.js} +12 -8
  155. package/dist/shared/{janx09m5.js → ktz42yez.js} +20 -8
  156. package/dist/shared/{gde73es6.js → m6p12kbr.js} +56 -55
  157. package/dist/shared/{r6nwkxnt.js → m7n9h2a5.js} +4 -4
  158. package/dist/shared/{672t5vym.js → mss6ctgv.js} +2 -2
  159. package/dist/shared/{nxdp2ze3.js → mtaszv5a.js} +144 -12
  160. package/dist/shared/n816peh1.js +45 -0
  161. package/dist/shared/nbw1z4yd.js +18 -0
  162. package/dist/shared/{cctw17hj.js → p6qc5gcp.js} +38 -34
  163. package/dist/shared/{6rk2gen5.js → pbp1ss85.js} +20 -17
  164. package/dist/shared/pt94kz7f.js +6 -0
  165. package/dist/shared/{wq9n6pwr.js → pz6rj8ay.js} +82 -9
  166. package/dist/shared/q5c6ngn3.js +13 -0
  167. package/dist/shared/{8bwbwy8h.js → qq3899ht.js} +128 -18
  168. package/dist/shared/{8ktwd3rh.js → r3j8s5y0.js} +1 -1
  169. package/dist/shared/rhs3xe4k.js +7 -0
  170. package/dist/shared/{ntneex2a.js → rpycarcr.js} +6 -6
  171. package/dist/shared/{sdc7r2ww.js → rs73fca9.js} +8 -8
  172. package/dist/shared/{tm5ab8we.js → sfz1ksn6.js} +7 -4
  173. package/dist/shared/{6mnp99hx.js → svncdeh5.js} +16 -12
  174. package/dist/shared/{hf22e0wt.js → tbrvgw6z.js} +62 -42
  175. package/dist/shared/te5as7z7.js +622 -0
  176. package/dist/shared/{ga3sfy93.js → tsvww22q.js} +535 -200
  177. package/dist/shared/{47x8x9ze.js → ttsqgp4p.js} +20 -13
  178. package/dist/shared/{x72jb7ad.js → v8g1vgv8.js} +1 -1
  179. package/dist/shared/vb6qfyve.js +152 -0
  180. package/dist/shared/{r2sp8hrc.js → vczs8gd4.js} +22 -13
  181. package/dist/shared/{1g0drakv.js → vqrjpcqn.js} +145 -3
  182. package/dist/shared/{2pqx26h8.js → w72kgg4q.js} +31 -22
  183. package/dist/shared/{96qcj21c.js → w79hsckn.js} +16 -51
  184. package/dist/shared/wa07eas9.js +730 -0
  185. package/dist/shared/{k8v5v5wj.js → x933k9a3.js} +75 -34
  186. package/dist/shared/{cr74e96e.js → xhfsfkgk.js} +62 -28
  187. package/dist/shared/xjk7hnn5.js +272 -0
  188. package/dist/shared/{5enne4ma.js → xnxsed62.js} +66 -113
  189. package/dist/shared/xqve9598.js +53 -0
  190. package/dist/shared/{9x25fxhc.js → y34a8714.js} +1 -1
  191. package/dist/shared/{k7dwkhvq.js → y6jdds7g.js} +4 -1
  192. package/dist/shared/y6njgyda.js +249 -0
  193. package/dist/shared/{c9z5g0fm.js → ywr8hmey.js} +5 -2
  194. package/dist/shared/{g7ez901n.js → ywspezzx.js} +1 -1
  195. package/dist/shared/z7s6fpxv.js +62 -0
  196. package/dist/shared/{n7mcc1gk.js → zchaghkf.js} +4 -3
  197. package/dist/shared/{9m80mkac.js → ze4hxsmy.js} +1 -1
  198. package/dist/shared/zm0ptry0.js +40 -0
  199. package/dist/shared/{nsva2a6b.js → znm0bpp5.js} +3 -0
  200. package/dist/shared/zp9fmend.js +145 -0
  201. package/dist/shared/{y005b761.js → zy8r7qvz.js} +6 -2
  202. package/dist/tooling/cli.js +41 -15
  203. package/dist/tooling/migrate/apply.d.ts +14 -0
  204. package/dist/tooling/migrate/check.d.ts +3 -4
  205. package/dist/tooling/migrate/classify.d.ts +4 -0
  206. package/dist/tooling/migrate/config.d.ts +3 -2
  207. package/dist/tooling/migrate/engine.d.ts +3 -2
  208. package/dist/tooling/migrate/files.d.ts +11 -1
  209. package/dist/tooling/migrate/index.js +14 -14
  210. package/dist/tooling/migrate/lint.d.ts +1 -1
  211. package/dist/tooling/migrate/lost.d.ts +28 -0
  212. package/dist/tooling/migrate/paths.d.ts +14 -0
  213. package/dist/tooling/migrate/plan.d.ts +6 -3
  214. package/dist/tooling/migrate/runner.d.ts +25 -0
  215. package/dist/tooling/migrate/sandbox.d.ts +57 -0
  216. package/dist/tooling/migrate/sql-lex.d.ts +20 -3
  217. package/dist/tooling/migrate/text.d.ts +42 -0
  218. package/dist/tooling/node-version.d.ts +21 -0
  219. package/dist/tooling/testing/facts.d.ts +33 -5
  220. package/dist/tooling/testing/index.d.ts +1 -1
  221. package/dist/tooling/testing/index.js +3 -3
  222. package/dist/tooling/testing/isolation.d.ts +11 -5
  223. package/package.json +8 -3
  224. package/dist/shared/7m88x3e9.js +0 -45
  225. package/dist/shared/7zwwyh0v.js +0 -448
  226. package/dist/shared/aj2qxyhj.js +0 -90
  227. package/dist/shared/caw8b9d8.js +0 -204
  228. package/dist/shared/jwtxdj06.js +0 -76
  229. package/dist/shared/kfjp0gck.js +0 -212
  230. package/dist/shared/q58y17hy.js +0 -21
  231. package/dist/shared/qm7cdtvr.js +0 -912
  232. package/dist/shared/r8x5qhd7.js +0 -86
  233. package/dist/shared/zqrnhwsq.js +0 -31
@@ -7,8 +7,14 @@
7
7
  * every aggregate exactly as they apply to a `find`. This module loads on the
8
8
  * first `aggregate()`.
9
9
  *
10
- * Not here: `having`, `bucket`, and ordering by an aggregate. A hidden column
11
- * cannot be grouped or aggregated, so an aggregate never shows what a read hides.
10
+ * Not here: `having`, ordering by an aggregate, and the time-zone date helpers
11
+ * (tool 5). A hidden column cannot be grouped or aggregated, so an aggregate
12
+ * never shows what a read hides.
13
+ *
14
+ * `bucket()` is a tagged helper. Its validation and SQL load in their own
15
+ * chunk, and only when `groupBy` contains one. A request object cannot create
16
+ * one. A NULL timestamp is one group: the result key is present and the value
17
+ * is null.
12
18
  */
13
19
  import { type Mods, type Session } from "./client.js";
14
20
  import { type ArchiveView } from "./plan.js";
@@ -12,7 +12,7 @@ import { type Session } from "./client.js";
12
12
  * Runs write handles as one atomic unit.
13
13
  *
14
14
  * @param session - Client session
15
- * @param ops - Write handles: `insert`, `update`, `delete`, `archive`. A `restore`, or a write with `expect`, is OKM1121 (D183)
15
+ * @param ops - Write handles: `insert`, `update`, `delete`, `archive`. A `restore`, a write with `expect`, or `refresh()` is OKM1121 (D183, D239)
16
16
  * @param options - `signal` and `timeout` for the whole batch
17
17
  * @param replica - Set by `.replica()`. A batch needs the primary (OKM1840)
18
18
  * @returns One result per operation, in order
@@ -0,0 +1,70 @@
1
+ /**
2
+ * Time buckets inside `aggregate` `groupBy` (spec §10, §13 tool 4).
3
+ *
4
+ * This module loads on the first `aggregate()` whose `groupBy` contains a
5
+ * `bucket()`. A plain aggregate does not import it. A NULL timestamp is one
6
+ * group: the `as` key is present and the value is null.
7
+ */
8
+ import type { ColumnModel } from "../dialects/pg/model.js";
9
+ import { type BucketUnit } from "../dialects/pg/ops/bucket.js";
10
+ import { type Built, type Indexed, type Sink } from "./plan.js";
11
+ /** One bucket in a group list. */
12
+ export type BucketGroup = {
13
+ readonly kind: "bucket";
14
+ readonly column: ColumnModel;
15
+ readonly unit: BucketUnit;
16
+ readonly tz: string | undefined;
17
+ readonly as: string;
18
+ readonly shift: 0 | 1 | 2;
19
+ readonly clock: boolean;
20
+ };
21
+ /**
22
+ * What the aggregate chunk calls after this module loads.
23
+ *
24
+ * The aggregate chunk does not import this file. It receives the functions
25
+ * from `import()`.
26
+ */
27
+ export type BucketChunk = {
28
+ readBucket(table: Indexed, value: unknown, fields: ReadonlySet<string>, aliases: Set<string>): BucketGroup;
29
+ writeBucket(sink: Sink, outputs: Built | undefined, wrote: {
30
+ at: number;
31
+ }, group: BucketGroup): void;
32
+ writeGrouped(sink: Sink, names: readonly string[], orderBy: unknown): void;
33
+ };
34
+ /**
35
+ * Reads one `bucket()` group.
36
+ *
37
+ * Refuses a bad unit, zone, week start, or result name before any SQL.
38
+ * `__proto__`, `constructor`, `toString`, and `hasOwnProperty` are refused.
39
+ * `timestamptz` needs an IANA `tz`. `date` refuses `tz`. `timestamp` without
40
+ * a zone is refused.
41
+ *
42
+ * @param table - The grouped table
43
+ * @param value - One `groupBy` entry
44
+ * @param fields - Plain group fields already seen
45
+ * @param aliases - Bucket result names already seen
46
+ * @returns The group the statement writes
47
+ */
48
+ export declare function readBucket(table: Indexed, value: unknown, fields: ReadonlySet<string>, aliases: Set<string>): BucketGroup;
49
+ /**
50
+ * Writes one bucket expression into the select list.
51
+ *
52
+ * @param sink - Statement buffer
53
+ * @param outputs - Decode plan, absent while only marking
54
+ * @param wrote - How many select items are already written
55
+ * @param group - The bucket
56
+ */
57
+ export declare function writeBucket(sink: Sink, outputs: Built | undefined, wrote: {
58
+ at: number;
59
+ }, group: BucketGroup): void;
60
+ /**
61
+ * Groups and orders by select-list ordinals.
62
+ *
63
+ * The bucket expression is written once, in the select list. A second copy
64
+ * would bind a new `$n`, and Postgres treats that as a different expression.
65
+ *
66
+ * @param sink - Statement buffer
67
+ * @param names - Group names, in select order
68
+ * @param orderBy - Caller order, or the default group order
69
+ */
70
+ export declare function writeGrouped(sink: Sink, names: readonly string[], orderBy: unknown): void;
@@ -18,23 +18,41 @@ export type ConflictPlan = {
18
18
  * @param table - Target table
19
19
  * @param value - The option the caller passed
20
20
  * @param allow - Guarded fields this write may set
21
- * @param tenantKey - The tenant key on a tenant schema, which every unique includes
21
+ * @param tenantKey - The tenant key, or every tenant key when the schema has several. A unique that includes them matches when `on` names the other columns. The target keeps the keys, in the unique's order. Naming a key is OKM1104.
22
22
  * @returns The plan, or `undefined` for the default `"error"`
23
23
  */
24
- export declare function readConflict(table: Indexed, value: unknown, allow?: ReadonlySet<string>, tenantKey?: string): ConflictPlan | undefined;
24
+ export declare function readConflict(table: Indexed, value: unknown, allow?: ReadonlySet<string>, tenantKey?: string | readonly string[]): ConflictPlan | undefined;
25
25
  /**
26
- * Appends the conflict clause, or wraps a first-or-create insert.
26
+ * Appends the conflict clause.
27
+ *
28
+ * First-or-create is `on conflict do nothing`. It does not read the existing
29
+ * row here: that lookup is a later statement, so it sees a row another
30
+ * transaction committed while this insert waited (D246).
27
31
  *
28
32
  * @param head - `insert into … values …` without `returning`
29
33
  * @param returning - ` returning …`, including the leading space
30
34
  * @param params - Insert parameters
31
35
  * @param plan - Conflict plan
32
36
  * @param table - Target table
33
- * @param returningColumns - Columns in `returning`
34
- * @param keys - Encoded conflict-key tuples, one per inserted row. Used by `return`
35
37
  * @returns Statement text and parameters
36
38
  */
37
- export declare function finishInsert(head: string, returning: string, params: readonly (string | null)[], plan: ConflictPlan, table: Indexed, returningColumns: readonly ColumnModel[], keys: readonly (readonly (string | null)[])[]): {
39
+ export declare function finishInsert(head: string, returning: string, params: readonly (string | null)[], plan: ConflictPlan, table: Indexed): {
40
+ readonly text: string;
41
+ readonly params: (string | null)[];
42
+ };
43
+ /**
44
+ * Reads rows a first-or-create insert did not return.
45
+ *
46
+ * The conflict target is the same unique, including the tenant key. A partial
47
+ * unique on an archivable table only matches the active row.
48
+ *
49
+ * @param table - Target table
50
+ * @param keys - Conflict columns, in constraint order
51
+ * @param returningColumns - Columns the insert returns, in that order
52
+ * @param keyRows - Encoded conflict-key tuples that the insert did not return
53
+ * @returns One select
54
+ */
55
+ export declare function lookupExisting(table: Indexed, keys: readonly ColumnModel[], returningColumns: readonly ColumnModel[], keyRows: readonly (readonly (string | null)[])[]): {
38
56
  readonly text: string;
39
57
  readonly params: (string | null)[];
40
58
  };
@@ -29,3 +29,12 @@ export declare function assertCompatible(pool: DriverPool, schema: QuerySchema,
29
29
  readonly catalog?: CatalogArtifact;
30
30
  readonly catalogDir?: string;
31
31
  }, options: ExecuteOptions | undefined): Promise<void>;
32
+ /**
33
+ * Directory of `catalog.hash` and `catalog.json`.
34
+ *
35
+ * A trailing `/` or `\` is removed so the joined file name is one path.
36
+ *
37
+ * @param catalogDir - Directory the caller passed, or the default `.okm`
38
+ * @returns The directory, without a trailing slash
39
+ */
40
+ export declare function artifactDir(catalogDir: string | undefined): string;
@@ -2,14 +2,6 @@
2
2
  * LATERAL include planner. Loaded on the first include.
3
3
  */
4
4
  import { type IncludeHooks, type Plan } from "./plan.js";
5
- /**
6
- * Decodes a result that has includes.
7
- *
8
- * @param plan - Compiled plan
9
- * @param rows - Wire rows
10
- * @param table - Table the call named
11
- * @returns The call's value
12
- */
13
5
  export declare function decodeIncluded(plan: Plan, rows: readonly (readonly (string | null)[])[], table: string): unknown;
14
6
  /** Hooks the read planner calls after this module has loaded. */
15
7
  export declare const includeHooks: IncludeHooks;
@@ -0,0 +1,14 @@
1
+ /**
2
+ * Refuses a positive timeout on a driver that cannot cancel.
3
+ *
4
+ * `tx({ timeout })` and `batch({ timeout })` load this with the call. The
5
+ * connect graph does not. The OKM1120 text loads with the lazy error module.
6
+ */
7
+ import type { DriverPool } from "../contracts/driver.js";
8
+ /**
9
+ * Throws OKM1120 when `timeout` is positive and the driver cannot cancel.
10
+ *
11
+ * @param pool - Driver the call will use
12
+ * @param timeout - Milliseconds, when the caller passed one
13
+ */
14
+ export declare function refuseUncancellableTimeout(pool: DriverPool, timeout: number | undefined): Promise<void>;
@@ -20,6 +20,9 @@ import { type ArchiveView } from "./plan.js";
20
20
  * @param options - `where`, `select`, `orderBy`, `limit`, `include`, and `after`
21
21
  * @param mods - Signal and timeout
22
22
  * @param view - Archive visibility
23
+ * @param pin - Endpoint a stream already chose. Absent for `page()`
23
24
  * @returns A handle that resolves to `{ items, next }`
24
25
  */
25
- export declare function build(session: Session, table: string, options: object, mods: Mods, view: ArchiveView | undefined): Promise<unknown> & Record<string, unknown>;
26
+ export declare function build(session: Session, table: string, options: object, mods: Mods, view: ArchiveView | undefined, pin?: {
27
+ name?: string;
28
+ }): Promise<unknown> & Record<string, unknown>;
@@ -1,22 +1,27 @@
1
1
  import {
2
2
  DriverError2
3
- } from "../../shared/31vm914h.js";
3
+ } from "../../shared/cm3w0ywp.js";
4
4
  import {
5
+ markClientPool,
5
6
  open5
6
- } from "../../shared/k8v5v5wj.js";
7
+ } from "../../shared/x933k9a3.js";
7
8
  import {
8
9
  BUNSQL_CAPABILITIES,
9
10
  readCapability2,
10
11
  hasCapability2
11
- } from "../../shared/cgbamx3e.js";
12
+ } from "../../shared/kb2sdhfb.js";
12
13
  import {
13
14
  createClient
14
- } from "../../shared/hf22e0wt.js";
15
+ } from "../../shared/tbrvgw6z.js";
15
16
 
16
17
  // src/runtime/pg/bun.ts
17
18
  function connect(target, options) {
18
19
  if (typeof target === "object" && !isPool(target)) {
19
- return import("../../shared/nxdp2ze3.js").then((mod) => mod.default(target, options, open5));
20
+ return import("../../shared/mtaszv5a.js").then((mod) => mod.default(target, options, (config) => {
21
+ const pool = open5(config);
22
+ markClientPool(pool);
23
+ return pool;
24
+ }));
20
25
  }
21
26
  const owned = !isPool(target);
22
27
  const pool = isPool(target) ? target : open5({
@@ -27,6 +32,8 @@ function connect(target, options) {
27
32
  ...options.searchPath !== undefined ? { searchPath: options.searchPath } : {},
28
33
  ...options.ssl !== undefined ? { ssl: options.ssl } : {}
29
34
  });
35
+ if (!isPool(target))
36
+ markClientPool(pool);
30
37
  return createClient(options.schema, pool, {
31
38
  ownsPool: owned,
32
39
  http: options.errors?.http,
@@ -1,22 +1,22 @@
1
1
  import {
2
2
  DriverError2
3
- } from "../../shared/31vm914h.js";
3
+ } from "../../shared/cm3w0ywp.js";
4
4
  import {
5
5
  open4
6
- } from "../../shared/96qcj21c.js";
6
+ } from "../../shared/w79hsckn.js";
7
7
  import {
8
8
  NODE_POSTGRES_CAPABILITIES,
9
9
  readCapability2,
10
10
  hasCapability2
11
- } from "../../shared/cgbamx3e.js";
11
+ } from "../../shared/kb2sdhfb.js";
12
12
  import {
13
13
  createClient
14
- } from "../../shared/hf22e0wt.js";
14
+ } from "../../shared/tbrvgw6z.js";
15
15
 
16
16
  // src/runtime/pg/pg.ts
17
17
  function connect(target, options) {
18
18
  if (typeof target === "object" && !isPool(target)) {
19
- return import("../../shared/nxdp2ze3.js").then((mod) => mod.default(target, options, open4));
19
+ return import("../../shared/mtaszv5a.js").then((mod) => mod.default(target, options, open4));
20
20
  }
21
21
  const owned = !isPool(target);
22
22
  const pool = isPool(target) ? target : open4({
@@ -2,6 +2,7 @@
2
2
  * `connect` for PGlite (`okmodel/pg/pglite`).
3
3
  *
4
4
  * Opening a database is async. An existing pool is reused and not closed.
5
+ * Closing that client marks the client closed.
5
6
  * A `{ primary, replicas }` object loads the topology module. A replica URL is
6
7
  * that endpoint's data directory.
7
8
  */
@@ -1,29 +1,30 @@
1
1
  import {
2
2
  DriverError2
3
- } from "../../shared/31vm914h.js";
3
+ } from "../../shared/cm3w0ywp.js";
4
4
  import {
5
- open3
6
- } from "../../shared/87jvvhnt.js";
5
+ open3,
6
+ seal2
7
+ } from "../../shared/81ebdx9p.js";
7
8
  import {
8
9
  PGLITE_CAPABILITIES,
9
10
  readCapability2,
10
11
  hasCapability2
11
- } from "../../shared/cgbamx3e.js";
12
+ } from "../../shared/kb2sdhfb.js";
12
13
  import {
13
14
  createClient
14
- } from "../../shared/hf22e0wt.js";
15
+ } from "../../shared/tbrvgw6z.js";
15
16
 
16
17
  // src/runtime/pg/pglite.ts
17
18
  async function connect(target, options) {
18
19
  if (typeof target === "object" && !isPool(target)) {
19
- return import("../../shared/nxdp2ze3.js").then((mod) => mod.default(target, options, open3));
20
+ return import("../../shared/mtaszv5a.js").then((mod) => mod.default(target, options, open3));
20
21
  }
21
- const pool = isPool(target) ? target : await open3({
22
+ const pool = isPool(target) ? seal2(target) : await open3({
22
23
  ...target !== undefined ? { dataDir: target } : {},
23
24
  ...options.timeouts !== undefined ? { timeouts: options.timeouts } : {}
24
25
  });
25
26
  return createClient(options.schema, pool, {
26
- ownsPool: !isPool(target),
27
+ ownsPool: true,
27
28
  http: options.errors?.http,
28
29
  includeValues: options.errors?.includeValues,
29
30
  logger: options.logger,
@@ -1,22 +1,22 @@
1
1
  import {
2
2
  DriverError2
3
- } from "../../shared/31vm914h.js";
3
+ } from "../../shared/cm3w0ywp.js";
4
4
  import {
5
5
  open2
6
- } from "../../shared/krxx77g0.js";
6
+ } from "../../shared/14vx95q4.js";
7
7
  import {
8
8
  POSTGRESJS_CAPABILITIES,
9
9
  readCapability2,
10
10
  hasCapability2
11
- } from "../../shared/cgbamx3e.js";
11
+ } from "../../shared/kb2sdhfb.js";
12
12
  import {
13
13
  createClient
14
- } from "../../shared/hf22e0wt.js";
14
+ } from "../../shared/tbrvgw6z.js";
15
15
 
16
16
  // src/runtime/pg/postgresjs.ts
17
17
  function connect(target, options) {
18
18
  if (typeof target === "object" && !isPool(target)) {
19
- return import("../../shared/nxdp2ze3.js").then((mod) => mod.default(target, options, open2));
19
+ return import("../../shared/mtaszv5a.js").then((mod) => mod.default(target, options, open2));
20
20
  }
21
21
  const owned = !isPool(target);
22
22
  const pool = isPool(target) ? target : open2({
@@ -8,7 +8,7 @@ import { type QueryCode } from "../contracts/error.js";
8
8
  import { type OperatorName } from "../dialects/pg/operators.js";
9
9
  import { type ColumnModel, type QuerySchema, type RelationModel, type TableModel } from "../dialects/pg/model.js";
10
10
  /** A read the caller asked for. */
11
- export type ReadOp = "find" | "one" | "count" | "exists" | "aggregate";
11
+ export type ReadOp = "find" | "one" | "count" | "exists" | "aggregate" | "descendants" | "ancestors";
12
12
  /** Routing constraint chosen before execute. */
13
13
  export type RouteConstraint = "auto" | "primary" | "replica";
14
14
  /**
@@ -18,13 +18,14 @@ export type RouteConstraint = "auto" | "primary" | "replica";
18
18
  */
19
19
  export type CallScope = {
20
20
  readonly value: string;
21
+ readonly values?: Readonly<Record<string, string>>;
21
22
  } | {
22
23
  readonly unscoped: string;
23
24
  };
24
25
  /** Writes one more `where` condition after the tenant and active-set predicates. */
25
26
  export type Keyset = (sink: Sink, alias: string) => void;
26
27
  /** Writes the whole statement of a read the planner does not know. */
27
- export type ReadBuild = (schema: QuerySchema, table: Indexed, sink: Sink, outputs: Built | undefined, call: ReadCall) => void;
28
+ export type ReadBuild = (schema: QuerySchema, table: Indexed, sink: Sink, outputs: Built | undefined, call: ReadCall, hooks?: IncludeHooks) => void;
28
29
  /** One read call. `all` is the `.all(reason)` escape for an unbounded read. */
29
30
  export type ReadCall = {
30
31
  readonly op: ReadOp;
@@ -34,6 +35,8 @@ export type ReadCall = {
34
35
  readonly orderBy?: unknown;
35
36
  readonly limit?: unknown;
36
37
  readonly include?: unknown;
38
+ /** `find` and `count`. Rewritten to `matches` and `relevance` before SQL. */
39
+ readonly search?: unknown;
37
40
  readonly all?: string;
38
41
  /** The `after` cursor of a `page`. The condition joins the others with `and`. */
39
42
  readonly after?: Keyset;
@@ -46,6 +49,15 @@ export type ReadCall = {
46
49
  readonly timeout?: number;
47
50
  /** `"primary"` or `"replica"`. Absent means the router classifies the statement. */
48
51
  readonly route?: "primary" | "replica";
52
+ /**
53
+ * Endpoint a `.stream()` already chose.
54
+ *
55
+ * The first batch leaves `name` empty and the router fills it. Later batches
56
+ * pass the same object so they stay on that endpoint.
57
+ */
58
+ readonly pin?: {
59
+ name?: string;
60
+ };
49
61
  /** Set by `for()` or `unscoped()`. Absent on a schema with no tenancy. */
50
62
  readonly scope?: CallScope;
51
63
  /** Inspect lines from the tenancy object. Absent when the schema has no tenancy. */
@@ -94,6 +106,11 @@ export type ScalarOut = {
94
106
  readonly at: number;
95
107
  readonly decode: ((wire: string) => unknown) | undefined;
96
108
  };
109
+ /** One target inside a morph include's JSON value. */
110
+ export type MorphOut = {
111
+ readonly type: string;
112
+ readonly fields: readonly ScalarOut[];
113
+ };
97
114
  /** A nested include. `at` is a root column for `one` and the JSON column for `many`. */
98
115
  export type IncludeOut = {
99
116
  readonly name: string;
@@ -101,6 +118,15 @@ export type IncludeOut = {
101
118
  readonly at: number;
102
119
  readonly fields: readonly ScalarOut[];
103
120
  readonly nested: readonly IncludeOut[];
121
+ /**
122
+ * Set when the include is a morph.
123
+ *
124
+ * The column at `at` is one JSON array, `[type, ...fields]`, or null.
125
+ */
126
+ readonly morph?: {
127
+ readonly typeKey: string;
128
+ readonly targets: readonly MorphOut[];
129
+ };
104
130
  };
105
131
  /** Columns and includes in statement order. */
106
132
  export type Outputs = {
@@ -113,6 +139,13 @@ export type IncludeHooks = {
113
139
  read(schema: QuerySchema, table: Indexed, include: unknown, all: string | undefined): readonly ParsedInclude[];
114
140
  select(include: ParsedInclude, alias: string, sink: Sink, outputs: Built | undefined, column: number): number;
115
141
  join(schema: QuerySchema, include: ParsedInclude, sink: Sink, parentAlias: string, alias: string, depth: number): void;
142
+ /**
143
+ * Reports whether an include's `where` or `orderBy` needs the operator compiler.
144
+ *
145
+ * The root check does not walk includes. This does, and only after the
146
+ * include planner has loaded.
147
+ */
148
+ needsOperator(schema: QuerySchema, call: ReadCall): boolean;
116
149
  };
117
150
  export type Built = {
118
151
  fields: ScalarOut[];
@@ -156,8 +189,13 @@ export type Sink = {
156
189
  * @returns Names in a stable order
157
190
  */
158
191
  export declare function readOptionNames(op: ReadOp): readonly string[];
159
- /** 0.2 operator SQL. Absent until that module has been imported. */
160
- type OperatorEmit = (column: ColumnModel, ref: string, name: OperatorName, value: unknown, sink: Sink) => void;
192
+ /**
193
+ * 0.2 operator SQL. Absent until that module has been imported.
194
+ *
195
+ * `order` is set when the operator is an `orderBy` value. `relevance` writes
196
+ * its direction there; the same operator in `where` is refused by that module.
197
+ */
198
+ type OperatorEmit = (column: ColumnModel, ref: string, name: OperatorName, value: unknown, sink: Sink, order?: true) => void;
161
199
  /**
162
200
  * Installs the 0.2 operator compiler.
163
201
  *
@@ -176,6 +214,16 @@ export declare function installOperatorSql(emit: OperatorEmit): void;
176
214
  * @returns `true` when {@link installOperatorSql} has not run and the read needs it
177
215
  */
178
216
  export declare function readNeedsOperatorSql(schema: QuerySchema, call: ReadCall): boolean;
217
+ /**
218
+ * Reports whether `orderBy` holds a `relevance` value.
219
+ *
220
+ * Called before the operator compiler has loaded. The include planner uses it
221
+ * for a related table.
222
+ *
223
+ * @param orderBy - The caller's order
224
+ * @returns `true` when a value is `relevance`
225
+ */
226
+ export declare function orderHasRelevance(orderBy: unknown): boolean;
179
227
  /**
180
228
  * Writes `<table> <alias> where <link to parent>` for a to-many relation.
181
229
  *
@@ -183,6 +231,18 @@ export declare function readNeedsOperatorSql(schema: QuerySchema, call: ReadCall
183
231
  * The caller adds the related table's own predicates after it.
184
232
  */
185
233
  export declare function emitRelationFrom(schema: QuerySchema, relation: RelationModel, child: Indexed, sink: Sink, parent: string, alias: string, depth: number): void;
234
+ /**
235
+ * Reports whether a filter needs the operator compiler.
236
+ *
237
+ * Equality and text patterns do not. The include planner calls this for a
238
+ * related table.
239
+ *
240
+ * @param table - The table the filter reads
241
+ * @param value - A `where` value
242
+ * @param key - The field, when `value` is that field's operand
243
+ * @returns `true` when the operator compiler has to load
244
+ */
245
+ export declare function needsOperatorSql(table: Indexed, value: unknown, key?: string): boolean;
186
246
  /**
187
247
  * Runs registered safety rules before planning.
188
248
  *
@@ -249,6 +309,24 @@ export declare function emitJoin(sink: Sink, parent: string, child: string, rela
249
309
  export declare function emitWhere(schema: QuerySchema, table: Indexed, where: unknown, sink: Sink, alias: string, depth: number, appended?: boolean, extra?: Keyset): void;
250
310
  export declare function emitOrder(table: Indexed, orderBy: unknown, sink: Sink, alias: string): void;
251
311
  export declare function emitPrimaryOrder(table: Indexed, sink: Sink, alias: string): void;
312
+ /**
313
+ * Refuses a hidden field in `where` or `orderBy`.
314
+ *
315
+ * `"filter"` is `hidden({ filterable: true })` and is allowed here.
316
+ * Aggregate loads this on its first call and applies it before the groupBy rule.
317
+ *
318
+ * @param column - The field the caller named
319
+ */
320
+ export declare function refuseHidden(column: ColumnModel): void;
321
+ export declare function emitLimit(call: ReadCall, sink: Sink): void;
322
+ /** One target branch of a morph include. */
323
+ export type ParsedMorphTarget = {
324
+ readonly type: string;
325
+ readonly table: string;
326
+ readonly sql: string;
327
+ readonly keySql: string;
328
+ readonly columns: readonly ColumnModel[];
329
+ };
252
330
  export type ParsedInclude = {
253
331
  readonly name: string;
254
332
  readonly relation: RelationModel;
@@ -260,13 +338,35 @@ export type ParsedInclude = {
260
338
  /** Index in the projected list that is null when the related row is missing. */
261
339
  readonly anchor: number;
262
340
  readonly nested: readonly ParsedInclude[];
341
+ /**
342
+ * Set when the include is a morph.
343
+ *
344
+ * Absent on every other include, so a normal include does not carry it.
345
+ */
346
+ readonly morphTo?: {
347
+ readonly typeKey: string;
348
+ readonly typeSql: string;
349
+ readonly idSql: string;
350
+ readonly targets: readonly ParsedMorphTarget[];
351
+ };
263
352
  };
264
353
  export declare function selectedColumns(table: Indexed, select: unknown): readonly ColumnModel[];
265
354
  export declare function parseOrder(field: string, value: unknown): {
266
355
  readonly dir: "asc" | "desc";
267
356
  readonly nulls: "first" | "last";
268
357
  };
269
- export declare function rejectKeys(value: Readonly<Record<string, unknown>>, accepted: readonly string[], where: string): void;
358
+ /**
359
+ * Refuses a key that `accepted` does not list.
360
+ *
361
+ * A read passes `search`. `one` and `exists` then say to use `find` or
362
+ * `count`, instead of the generic option list.
363
+ *
364
+ * @param value - Caller options
365
+ * @param accepted - Names this call allows
366
+ * @param where - The call, named in the error
367
+ * @param search - When set, a rejected `search` key uses the read message
368
+ */
369
+ export declare function rejectKeys(value: Readonly<Record<string, unknown>>, accepted: readonly string[], where: string, search?: true): void;
270
370
  export declare function readLimit(value: unknown): number;
271
371
  /**
272
372
  * Lets an object through only when the column's codec takes it (OKM1121).
@@ -289,18 +389,15 @@ export declare function quote(name: string): string;
289
389
  export declare function list(names: readonly string[]): string;
290
390
  export declare function isRecord(value: unknown): value is Record<string, unknown>;
291
391
  /**
292
- * Whether `where` constrains a row.
392
+ * Throws OKM1121 for an `or()` that is not an array, or for an empty branch.
293
393
  *
294
- * A field value is a leaf. Anything other than `undefined` counts, including
295
- * `null`, objects, arrays, and operators. The walk does not enter a field value.
296
- * It enters the where object's own keys, `and`, `or`, and `not` when `not` is
297
- * the where itself. An `or()` branch with no predicate is OKM1121. `or([])`
298
- * matches nothing.
394
+ * The write and archive predicate walk uses the same throw. It lives here
395
+ * because the read planner throws it too, and that planner stays in this module.
299
396
  *
300
- * @param where - Caller filter, or one `and` / `or` / `not` operand
301
- * @returns `false` when the filter matches every row
397
+ * @param empty - `true` when a branch has no predicate
398
+ * @returns Never
302
399
  */
303
- export declare function effectivePredicate(where: unknown): boolean;
400
+ export declare function orFail(empty: boolean): never;
304
401
  /**
305
402
  * Records the fix text for a code thrown from a chunk that loads on first use.
306
403
  *
@@ -316,6 +413,7 @@ export declare function registerFailFix(code: QueryCode, summary: string): void;
316
413
  *
317
414
  * @param code - Spec code
318
415
  * @param message - What failed
416
+ * @param fix - Fix sentence for this call. Omitted, the sentence registered for `code` is used
319
417
  */
320
- export declare function fail(code: QueryCode, message: string): never;
418
+ export declare function fail(code: QueryCode, message: string, fix?: string): never;
321
419
  export {};
@@ -0,0 +1,19 @@
1
+ /**
2
+ * Whether a `where` constrains a row.
3
+ *
4
+ * Write and archive load this module. A read does not. The walk is the same
5
+ * one those paths used when it lived in the planner.
6
+ */
7
+ /**
8
+ * Whether `where` constrains a row.
9
+ *
10
+ * A field value is a leaf. Anything other than `undefined` counts, including
11
+ * `null`, objects, arrays, and operators. The walk does not enter a field value.
12
+ * It enters the where object's own keys, `and`, `or`, and `not` when `not` is
13
+ * the where itself. An `or()` branch with no predicate is OKM1121. `or([])`
14
+ * matches nothing.
15
+ *
16
+ * @param where - Caller filter, or one `and` / `or` / `not` operand
17
+ * @returns `false` when the filter matches every row
18
+ */
19
+ export declare function effectivePredicate(where: unknown): boolean;
@@ -1,26 +1,23 @@
1
1
  /**
2
- * Server-side read cursor.
2
+ * Keyset batches for `.stream()` (spec §10).
3
3
  *
4
4
  * Loaded the first time `.stream()` is iterated. A find that is only awaited
5
- * does not load it.
5
+ * does not load it. Each batch is one finished `page` query: fetch, yield,
6
+ * then fetch the next. A `break` does not hold a connection. A server cursor
7
+ * is not used, so the driver `stream` flag is not read.
6
8
  */
7
- import type { DriverPool } from "../contracts/driver.js";
8
- import { OkmError, type ErrorStatuses } from "../contracts/error.js";
9
- import { type Plan, type ReadCall } from "./plan.js";
9
+ import { OkmError } from "../contracts/error.js";
10
+ import { type Mods, type Session } from "./client.js";
11
+ import { type ArchiveView, type ReadCall } from "./plan.js";
10
12
  /**
11
- * Yields decoded rows from the driver's stream.
13
+ * Yields decoded rows, one keyset batch at a time.
12
14
  *
13
15
  * @param session - Connected pool and HTTP statuses
14
- * @param call - The read being streamed
15
- * @param prepare - Compiles the statement on first use
16
+ * @param call - The find being streamed
17
+ * @param mods - `.all` reason and presets
18
+ * @param view - Archive visibility
19
+ * @param batchOptions - `{ batch }`, or omitted for {@link DEFAULT_BATCH}
16
20
  * @param log - Attaches the session logger and returns the error
17
21
  * @returns One row at a time
18
22
  */
19
- export declare function streamRows(session: {
20
- readonly connected: Promise<void>;
21
- readonly pool: DriverPool;
22
- readonly http: ErrorStatuses | undefined;
23
- }, call: ReadCall, prepare: () => Promise<{
24
- readonly plan: Plan;
25
- readonly params: readonly (string | null)[];
26
- }>, log: (error: OkmError) => OkmError): AsyncIterable<unknown>;
23
+ export declare function streamRows(session: Session, call: ReadCall, mods: Mods, view: ArchiveView | undefined, batchOptions: object | undefined, log: (error: OkmError) => OkmError): AsyncIterable<unknown>;