okmodel 0.7.0 → 0.8.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 (195) hide show
  1. package/dist/adapters/capabilities.d.ts +32 -0
  2. package/dist/adapters/failure.d.ts +1 -1
  3. package/dist/adapters/pg/bun-sql.d.ts +53 -0
  4. package/dist/adapters/pg/bunsql-extra.d.ts +1 -1
  5. package/dist/adapters/pg/bunsql.d.ts +1 -1
  6. package/dist/adapters/pg/neon-extra.d.ts +18 -0
  7. package/dist/adapters/pg/neon.d.ts +104 -0
  8. package/dist/adapters/pg/no-inflight-timeout.d.ts +1 -1
  9. package/dist/contracts/error.d.ts +1 -1
  10. package/dist/dialects/pg/fn/index.d.ts +39 -1
  11. package/dist/dialects/pg/fn/index.js +118 -26
  12. package/dist/dialects/pg/index.d.ts +2 -0
  13. package/dist/dialects/pg/index.js +393 -18
  14. package/dist/dialects/pg/introspect.d.ts +11 -0
  15. package/dist/dialects/pg/operators.d.ts +1 -1
  16. package/dist/dialects/pg/ops/fragment.d.ts +119 -0
  17. package/dist/dialects/pg/ops/lane.d.ts +49 -0
  18. package/dist/dialects/pg/view/client.d.ts +14 -6
  19. package/dist/dialects/pg/view/index.d.ts +73 -1
  20. package/dist/dialects/pg/view/index.js +156 -5
  21. package/dist/dialects/pg/view/scratch.d.ts +8 -5
  22. package/dist/runtime/otel.d.ts +105 -0
  23. package/dist/runtime/otel.js +97 -0
  24. package/dist/runtime/pg/bun.js +4 -4
  25. package/dist/runtime/pg/neon.d.ts +38 -0
  26. package/dist/runtime/pg/neon.js +64 -0
  27. package/dist/runtime/pg/pg.js +4 -4
  28. package/dist/runtime/pg/pglite.js +4 -4
  29. package/dist/runtime/pg/postgresjs.js +4 -4
  30. package/dist/runtime/plan.d.ts +1 -1
  31. package/dist/runtime/sql-fragment.d.ts +43 -0
  32. package/dist/runtime/tenancy/index.js +10 -10
  33. package/dist/runtime/topology.d.ts +1 -1
  34. package/dist/runtime/traits/index.js +15 -16
  35. package/dist/runtime/types.d.ts +15 -1
  36. package/dist/runtime/validate/index.js +4 -4
  37. package/dist/shared/{mtaszv5a.js → 0wrea3jq.js} +102 -4
  38. package/dist/shared/{qq3899ht.js → 12z7aznj.js} +243 -14
  39. package/dist/shared/{w79hsckn.js → 14x60fbf.js} +5 -5
  40. package/dist/shared/{ek2wt2dz.js → 16kvjebh.js} +4 -4
  41. package/dist/shared/{svncdeh5.js → 195pzzzz.js} +8 -8
  42. package/dist/shared/{gzaveazc.js → 1d9q9cv2.js} +29 -2
  43. package/dist/shared/{jvd0mqag.js → 3449rcae.js} +5 -5
  44. package/dist/shared/{14vx95q4.js → 35q0n9tz.js} +7 -7
  45. package/dist/shared/3bb7wsqt.js +99 -0
  46. package/dist/shared/{y6njgyda.js → 3t6kw83m.js} +2 -2
  47. package/dist/shared/{81ebdx9p.js → 4m6hskg8.js} +4 -4
  48. package/dist/shared/{xhfsfkgk.js → 4vbf83xx.js} +9 -2
  49. package/dist/shared/{bg3rym3g.js → 63f4ksbz.js} +2 -2
  50. package/dist/shared/{pt94kz7f.js → 6m78c8ss.js} +1 -1
  51. package/dist/shared/{5e3tf63j.js → 760ppr76.js} +14 -6
  52. package/dist/shared/{zm0ptry0.js → 7ghwamrf.js} +1 -1
  53. package/dist/shared/{xnxsed62.js → 9dr2qnx7.js} +14 -14
  54. package/dist/shared/{h15jx9bc.js → 9dvh1dr6.js} +1 -1
  55. package/dist/shared/{q5c6ngn3.js → a62rb2da.js} +1 -1
  56. package/dist/shared/{kb2sdhfb.js → ae4j5f42.js} +17 -1
  57. package/dist/shared/agsfb86s.js +233 -0
  58. package/dist/shared/{7k9grvf6.js → b6d6p0zc.js} +5 -5
  59. package/dist/shared/{tbrvgw6z.js → bah9nbg3.js} +17 -16
  60. package/dist/shared/{5fe3kbsh.js → bnby0esn.js} +1 -1
  61. package/dist/shared/bsek72fg.js +225 -0
  62. package/dist/shared/{1w508jbr.js → bxas03mq.js} +21 -17
  63. package/dist/shared/{dk8v79p3.js → d5nmj7vv.js} +1 -1
  64. package/dist/shared/{tsvww22q.js → dpc2r7rb.js} +7 -7
  65. package/dist/shared/{vb6qfyve.js → e8zyaqvj.js} +2 -2
  66. package/dist/shared/{hyh73qk6.js → ecn8mfdq.js} +5 -5
  67. package/dist/shared/{gs74dbj5.js → f4jy1j7x.js} +27 -14
  68. package/dist/shared/{ttsqgp4p.js → fjpnhqan.js} +2 -2
  69. package/dist/shared/{xjk7hnn5.js → g5yc06ka.js} +2 -2
  70. package/dist/shared/{w72kgg4q.js → hfqmpasr.js} +6 -6
  71. package/dist/shared/{kr0jzbw2.js → hm5f8jby.js} +7 -7
  72. package/dist/shared/{dkxgzaqd.js → hqpxf4a4.js} +1 -1
  73. package/dist/shared/{cn957f8d.js → jebgrkeq.js} +3 -3
  74. package/dist/shared/{wa07eas9.js → jp36k7dp.js} +11 -11
  75. package/dist/shared/jx2m62cs.js +96 -0
  76. package/dist/shared/{sfz1ksn6.js → k86n8vq3.js} +2 -2
  77. package/dist/shared/{67txcrcw.js → kgwp4jdd.js} +4 -4
  78. package/dist/shared/{8skf0cam.js → kj9d8maq.js} +1 -1
  79. package/dist/shared/{aytqh5y2.js → m4xff2a6.js} +2 -2
  80. package/dist/shared/{zp9fmend.js → mfedzr74.js} +4 -4
  81. package/dist/shared/{ax7qv55k.js → mkrn359n.js} +60 -11
  82. package/dist/shared/{m6p12kbr.js → mnvjvqyp.js} +10 -10
  83. package/dist/shared/{1qa0qajz.js → mtw6jz76.js} +1 -1
  84. package/dist/shared/{1est4ezg.js → n05z9nwz.js} +3 -3
  85. package/dist/shared/{pbp1ss85.js → n0jmpgj1.js} +2 -2
  86. package/dist/shared/{ktz42yez.js → n41w4fbz.js} +5 -5
  87. package/dist/shared/{n816peh1.js → n454kcnw.js} +1 -1
  88. package/dist/shared/n7kg8mmx.js +61 -0
  89. package/dist/shared/{g6evj1j3.js → needfe47.js} +1 -1
  90. package/dist/shared/{2shdbn8q.js → njga14v4.js} +9 -9
  91. package/dist/shared/{vqrjpcqn.js → nmnsgj7x.js} +1 -1
  92. package/dist/shared/{b5pftnn2.js → p3xbdcvt.js} +14 -18
  93. package/dist/shared/{te5as7z7.js → p5nh3r8q.js} +3 -3
  94. package/dist/shared/{p6qc5gcp.js → pan0370z.js} +6 -6
  95. package/dist/shared/{79dt02vc.js → q0cqt2sp.js} +1 -1
  96. package/dist/shared/{5v3xf80k.js → qd9hhd8f.js} +1 -1
  97. package/dist/shared/{bm22fvzr.js → qfw14tna.js} +2 -2
  98. package/dist/shared/{9s0ypp87.js → sjk86yrx.js} +1 -1
  99. package/dist/shared/{3v7t1yrv.js → th3be82n.js} +2 -2
  100. package/dist/shared/{ed0b8k4s.js → typ3vy7t.js} +1 -1
  101. package/dist/shared/{vczs8gd4.js → v1wad97q.js} +2 -2
  102. package/dist/shared/{9628a9xt.js → vk7rag46.js} +1 -1
  103. package/dist/shared/{ze4hxsmy.js → w9ejzaqf.js} +1 -1
  104. package/dist/shared/{bz84tkzm.js → wcrheftc.js} +2 -2
  105. package/dist/shared/{ab9gmbwy.js → wvdjznah.js} +5 -5
  106. package/dist/shared/{7mnme5tn.js → wz2a78mp.js} +1 -1
  107. package/dist/shared/{9y3mmmh1.js → xfhe73sb.js} +1 -1
  108. package/dist/shared/{je4axnm8.js → z581d7ny.js} +2 -2
  109. package/dist/shared/{x933k9a3.js → zbqbmmrp.js} +10 -10
  110. package/dist/shared/{rs73fca9.js → zgex00fd.js} +6 -6
  111. package/dist/shared/{jznfax0y.js → zq1he88x.js} +4 -4
  112. package/dist/tooling/cli.js +26 -13
  113. package/dist/tooling/driver-run.js +4971 -0
  114. package/dist/tooling/driver-test.d.ts +36 -0
  115. package/dist/tooling/migrate/commands.d.ts +2 -2
  116. package/dist/tooling/migrate/index.js +9 -9
  117. package/dist/tooling/migrate/project.d.ts +3 -0
  118. package/dist/tooling/shared/03k6res6.js +210 -0
  119. package/dist/tooling/shared/08kemxjd.js +10 -0
  120. package/dist/tooling/shared/2revefqt.js +209 -0
  121. package/dist/tooling/shared/2wtvc7rw.js +1425 -0
  122. package/dist/tooling/shared/345tbc2k.js +16 -0
  123. package/dist/tooling/shared/3m1hkg7z.js +344 -0
  124. package/dist/tooling/shared/3rrw5w8f.js +81 -0
  125. package/dist/tooling/shared/3tq8pnb8.js +131 -0
  126. package/dist/tooling/shared/417zdsk7.js +194 -0
  127. package/dist/tooling/shared/4d2w25vw.js +40 -0
  128. package/dist/tooling/shared/54tqkxja.js +51 -0
  129. package/dist/tooling/shared/5bvw2nev.js +12 -0
  130. package/dist/tooling/shared/6nyfyw70.js +231 -0
  131. package/dist/tooling/shared/72fyg4zv.js +160 -0
  132. package/dist/tooling/shared/733a1tq3.js +38 -0
  133. package/dist/tooling/shared/7ae7rjmn.js +20 -0
  134. package/dist/tooling/shared/7kms6fvj.js +20 -0
  135. package/dist/tooling/shared/8sqrsw3s.js +49 -0
  136. package/dist/tooling/shared/96ps4g1z.js +32 -0
  137. package/dist/tooling/shared/9kazs5p6.js +195 -0
  138. package/dist/tooling/shared/9xzm7hjg.js +38 -0
  139. package/dist/tooling/shared/a6pp9d12.js +49 -0
  140. package/dist/tooling/shared/a7q7t4n3.js +22 -0
  141. package/dist/tooling/shared/aftb2mwr.js +18 -0
  142. package/dist/tooling/shared/bz2dqhab.js +311 -0
  143. package/dist/tooling/shared/cmptmb4f.js +12 -0
  144. package/dist/tooling/shared/ddjtfgnx.js +177 -0
  145. package/dist/tooling/shared/djydjpqt.js +261 -0
  146. package/dist/tooling/shared/dw08f3m8.js +9 -0
  147. package/dist/tooling/shared/dy672fz6.js +16 -0
  148. package/dist/tooling/shared/dzx85q70.js +66 -0
  149. package/dist/tooling/shared/ec71zqgt.js +270 -0
  150. package/dist/tooling/shared/ep8zh3bk.js +6 -0
  151. package/dist/tooling/shared/f9mphxej.js +3789 -0
  152. package/dist/tooling/shared/fb9k2qwd.js +89 -0
  153. package/dist/tooling/shared/g9ad4n80.js +211 -0
  154. package/dist/tooling/shared/gfvtj6d0.js +94 -0
  155. package/dist/tooling/shared/gmcf9cxf.js +294 -0
  156. package/dist/tooling/shared/htnaj77v.js +17 -0
  157. package/dist/tooling/shared/j9t5s12a.js +7 -0
  158. package/dist/tooling/shared/jne7b93p.js +42 -0
  159. package/dist/tooling/shared/ma2340rx.js +118 -0
  160. package/dist/tooling/shared/mtrqn2hn.js +505 -0
  161. package/dist/tooling/shared/n4jqhpqz.js +27 -0
  162. package/dist/tooling/shared/nf7jmhfa.js +20 -0
  163. package/dist/tooling/shared/p7f08ktn.js +332 -0
  164. package/dist/tooling/shared/ppnnnvj8.js +13 -0
  165. package/dist/tooling/shared/pqy21k24.js +312 -0
  166. package/dist/tooling/shared/pw8fgahx.js +69 -0
  167. package/dist/tooling/shared/pwsytxm5.js +17 -0
  168. package/dist/tooling/shared/rf83gr2d.js +94 -0
  169. package/dist/tooling/shared/rq5kk8j6.js +401 -0
  170. package/dist/tooling/shared/rs1jb051.js +12 -0
  171. package/dist/tooling/shared/smn6kz1p.js +157 -0
  172. package/dist/tooling/shared/spk1jg3r.js +1696 -0
  173. package/dist/tooling/shared/tn8gay14.js +143 -0
  174. package/dist/tooling/shared/vraj6d74.js +42 -0
  175. package/dist/tooling/shared/vs0t6qt8.js +64 -0
  176. package/dist/tooling/shared/vx86qjv8.js +150 -0
  177. package/dist/tooling/shared/w7qe8sj1.js +140 -0
  178. package/dist/tooling/shared/wt7j7nf6.js +15 -0
  179. package/dist/tooling/shared/wwnekq5n.js +6 -0
  180. package/dist/tooling/shared/xhrnjch9.js +185 -0
  181. package/dist/tooling/shared/xjs6zqtc.js +190 -0
  182. package/dist/tooling/shared/y031jct9.js +16 -0
  183. package/dist/tooling/shared/y5656f0e.js +233 -0
  184. package/dist/tooling/shared/yfr8hzhm.js +604 -0
  185. package/dist/tooling/shared/yk9mp7vb.js +250 -0
  186. package/dist/tooling/shared/yw30vnq2.js +139 -0
  187. package/dist/tooling/shared/z8d7ptht.js +618 -0
  188. package/dist/tooling/shared/zhwnfyb2.js +9 -0
  189. package/dist/tooling/shared/zvnhh1n0.js +198 -0
  190. package/dist/tooling/testing/index.js +3 -3
  191. package/package.json +14 -2
  192. package/dist/shared/y34a8714.js +0 -150
  193. package/dist/shared/zy8r7qvz.js +0 -116
  194. package/dist/shared/{ywr8hmey.js → 606g0nbf.js} +3 -3
  195. package/dist/shared/{rpycarcr.js → gcefca6p.js} +4 -4
@@ -3,20 +3,20 @@ import {
3
3
  } from "../../shared/cm3w0ywp.js";
4
4
  import {
5
5
  open4
6
- } from "../../shared/w79hsckn.js";
6
+ } from "../../shared/14x60fbf.js";
7
7
  import {
8
8
  NODE_POSTGRES_CAPABILITIES,
9
9
  readCapability2,
10
10
  hasCapability2
11
- } from "../../shared/kb2sdhfb.js";
11
+ } from "../../shared/ae4j5f42.js";
12
12
  import {
13
13
  createClient
14
- } from "../../shared/tbrvgw6z.js";
14
+ } from "../../shared/bah9nbg3.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/mtaszv5a.js").then((mod) => mod.default(target, options, open4));
19
+ return import("../../shared/0wrea3jq.js").then((mod) => mod.default(target, options, open4));
20
20
  }
21
21
  const owned = !isPool(target);
22
22
  const pool = isPool(target) ? target : open4({
@@ -4,20 +4,20 @@ import {
4
4
  import {
5
5
  open3,
6
6
  seal2
7
- } from "../../shared/81ebdx9p.js";
7
+ } from "../../shared/4m6hskg8.js";
8
8
  import {
9
9
  PGLITE_CAPABILITIES,
10
10
  readCapability2,
11
11
  hasCapability2
12
- } from "../../shared/kb2sdhfb.js";
12
+ } from "../../shared/ae4j5f42.js";
13
13
  import {
14
14
  createClient
15
- } from "../../shared/tbrvgw6z.js";
15
+ } from "../../shared/bah9nbg3.js";
16
16
 
17
17
  // src/runtime/pg/pglite.ts
18
18
  async function connect(target, options) {
19
19
  if (typeof target === "object" && !isPool(target)) {
20
- return import("../../shared/mtaszv5a.js").then((mod) => mod.default(target, options, open3));
20
+ return import("../../shared/0wrea3jq.js").then((mod) => mod.default(target, options, open3));
21
21
  }
22
22
  const pool = isPool(target) ? seal2(target) : await open3({
23
23
  ...target !== undefined ? { dataDir: target } : {},
@@ -3,20 +3,20 @@ import {
3
3
  } from "../../shared/cm3w0ywp.js";
4
4
  import {
5
5
  open2
6
- } from "../../shared/14vx95q4.js";
6
+ } from "../../shared/35q0n9tz.js";
7
7
  import {
8
8
  POSTGRESJS_CAPABILITIES,
9
9
  readCapability2,
10
10
  hasCapability2
11
- } from "../../shared/kb2sdhfb.js";
11
+ } from "../../shared/ae4j5f42.js";
12
12
  import {
13
13
  createClient
14
- } from "../../shared/tbrvgw6z.js";
14
+ } from "../../shared/bah9nbg3.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/mtaszv5a.js").then((mod) => mod.default(target, options, open2));
19
+ return import("../../shared/0wrea3jq.js").then((mod) => mod.default(target, options, open2));
20
20
  }
21
21
  const owned = !isPool(target);
22
22
  const pool = isPool(target) ? target : open2({
@@ -195,7 +195,7 @@ export declare function readOptionNames(op: ReadOp): readonly string[];
195
195
  * `order` is set when the operator is an `orderBy` value. `relevance` writes
196
196
  * its direction there; the same operator in `where` is refused by that module.
197
197
  */
198
- type OperatorEmit = (column: ColumnModel, ref: string, name: OperatorName, value: unknown, sink: Sink, order?: true) => void;
198
+ type OperatorEmit = (table: Indexed, column: ColumnModel, ref: string, name: OperatorName, value: unknown, sink: Sink, order?: true) => void;
199
199
  /**
200
200
  * Installs the 0.2 operator compiler.
201
201
  *
@@ -0,0 +1,43 @@
1
+ /**
2
+ * SQL for a composed fragment.
3
+ *
4
+ * Loaded with the operator compiler and with a `select` that contains a
5
+ * fragment. A featureless read does not import it. Parameters are bound.
6
+ * `ident` names the TypeScript field, the same name `where` uses. The compiler
7
+ * quotes that column's SQL name. A hidden field is refused. The fragment is
8
+ * parenthesized so it cannot remove the tenant predicate.
9
+ */
10
+ import { type FragmentPart } from "../dialects/pg/ops/fragment.js";
11
+ import { type Indexed, type Sink } from "./plan.js";
12
+ /**
13
+ * Writes a where fragment.
14
+ *
15
+ * `ref` is the field the fragment is attached to, already quoted and aliased.
16
+ * `fragment.column` emits that reference.
17
+ *
18
+ * @param table - The table the where field belongs to
19
+ * @param ref - `alias."column"`
20
+ * @param value - Parts the template stored
21
+ * @param sink - Statement builder
22
+ */
23
+ export declare function emitSqlValue(table: Indexed, ref: string, value: unknown, sink: Sink): void;
24
+ /**
25
+ * Writes a select fragment.
26
+ *
27
+ * There is no where field, so `fragment.column` is OKM1125.
28
+ *
29
+ * @param table - The read table
30
+ * @param parts - Parts the template stored
31
+ * @param sink - Statement builder
32
+ * @param alias - Table alias, `t` on a root read
33
+ */
34
+ export declare function emitSqlSelect(table: Indexed, parts: readonly FragmentPart[], sink: Sink, alias: string): void;
35
+ /**
36
+ * Reads a select fragment as a number.
37
+ *
38
+ * The wire is text. A value that is not a finite number is OKM1125.
39
+ *
40
+ * @param wire - Driver text
41
+ * @returns The number
42
+ */
43
+ export declare function decodeSqlNumber(wire: string): number;
@@ -2,24 +2,24 @@ import {
2
2
  markPathEndpoint
3
3
  } from "../../shared/rhs3xe4k.js";
4
4
  import {
5
- tenantPolicyExpression,
6
- unscopedPolicyExpression,
7
- policyObject
8
- } from "../../shared/bdk4sty6.js";
5
+ uuid2
6
+ } from "../../shared/ecn8mfdq.js";
9
7
  import {
10
8
  isRelationCall
11
9
  } from "../../shared/exn3sd90.js";
12
- import {
13
- uuid2
14
- } from "../../shared/hyh73qk6.js";
15
10
  import {
16
11
  index2,
17
12
  snakeCase
18
- } from "../../shared/rpycarcr.js";
13
+ } from "../../shared/gcefca6p.js";
19
14
  import {
20
15
  ColumnBuilder2,
21
16
  retarget
22
- } from "../../shared/ywr8hmey.js";
17
+ } from "../../shared/606g0nbf.js";
18
+ import {
19
+ tenantPolicyExpression,
20
+ unscopedPolicyExpression,
21
+ policyObject
22
+ } from "../../shared/bdk4sty6.js";
23
23
  import {
24
24
  definition
25
25
  } from "../../shared/tmbdywx0.js";
@@ -28,7 +28,7 @@ import {
28
28
  } from "../../shared/94ez8kzh.js";
29
29
  import {
30
30
  quote
31
- } from "../../shared/67txcrcw.js";
31
+ } from "../../shared/kgwp4jdd.js";
32
32
  import {
33
33
  assertIdentifier2
34
34
  } from "../../shared/nfzc5z0w.js";
@@ -14,7 +14,7 @@ export type RouteName = "primary" | "replica";
14
14
  /**
15
15
  * One routing choice.
16
16
  *
17
- * `onRoute` receives this. `inspect()` does not, until the dev inspector (M2).
17
+ * `onRoute` receives this. `inspect()` on a topology client shows the same reason.
18
18
  */
19
19
  export type RouteEvent = {
20
20
  /** What the statement was classified as. */
@@ -1,4 +1,7 @@
1
- import"../../shared/qq3899ht.js";
1
+ import {
2
+ functionObject,
3
+ triggerObject
4
+ } from "../../shared/12z7aznj.js";
2
5
  import {
3
6
  checkPresetNames,
4
7
  duplicatePreset
@@ -6,30 +9,26 @@ import {
6
9
  import {
7
10
  checkTrait
8
11
  } from "../../shared/n0dgs0pb.js";
9
- import {
10
- quoteIdent
11
- } from "../../shared/9s0ypp87.js";
12
12
  import {
13
13
  pathEndpoint
14
14
  } from "../../shared/rhs3xe4k.js";
15
- import {
16
- functionObject,
17
- triggerObject
18
- } from "../../shared/y34a8714.js";
19
15
  import {
20
16
  integer2,
21
17
  timestamptz2
22
- } from "../../shared/vqrjpcqn.js";
18
+ } from "../../shared/nmnsgj7x.js";
23
19
  import {
24
20
  uuid2
25
- } from "../../shared/hyh73qk6.js";
21
+ } from "../../shared/ecn8mfdq.js";
26
22
  import {
27
23
  snakeCase
28
- } from "../../shared/rpycarcr.js";
24
+ } from "../../shared/gcefca6p.js";
29
25
  import {
30
26
  ColumnBuilder2,
31
27
  retarget
32
- } from "../../shared/ywr8hmey.js";
28
+ } from "../../shared/606g0nbf.js";
29
+ import {
30
+ quoteIdent
31
+ } from "../../shared/sjk86yrx.js";
33
32
  import {
34
33
  definition,
35
34
  unavailable
@@ -42,12 +41,12 @@ import {
42
41
  queryHandle,
43
42
  attachHttp,
44
43
  settleCall
45
- } from "../../shared/tbrvgw6z.js";
44
+ } from "../../shared/bah9nbg3.js";
46
45
  import {
47
46
  installArchiveInspect,
48
47
  indexes,
49
48
  isRecord
50
- } from "../../shared/67txcrcw.js";
49
+ } from "../../shared/kgwp4jdd.js";
51
50
  import {
52
51
  fitIdentifier2
53
52
  } from "../../shared/nfzc5z0w.js";
@@ -468,7 +467,7 @@ function refuse(host, table) {
468
467
  }
469
468
  var archiveMod;
470
469
  function loadArchive() {
471
- archiveMod ??= import("../../shared/bm22fvzr.js");
470
+ archiveMod ??= import("../../shared/qfw14tna.js");
472
471
  return archiveMod;
473
472
  }
474
473
  async function settle(host, table, mods) {
@@ -736,7 +735,7 @@ function attachSort(target, ctx) {
736
735
  wrapOrder(target, "find", order);
737
736
  wrapOrder(target, "page", order);
738
737
  const view = ctx.view;
739
- target.move = (id, place) => import("../../shared/9y3mmmh1.js").then((mod) => mod.move(host, tableName, id, place, view));
738
+ target.move = (id, place) => import("../../shared/xfhe73sb.js").then((mod) => mod.move(host, tableName, id, place, view));
740
739
  }
741
740
  function wrapOrder(target, key, order) {
742
741
  const previous = target[key];
@@ -120,7 +120,7 @@ export type Selected<Row, Sel> = [Sel] extends [readonly (infer P)[]] ? [P] exte
120
120
  type HasWindow<P> = P extends Window<string, string | number> ? true : false;
121
121
  /** Result keys a window helper adds. A field name contributes nothing. */
122
122
  type WindowFields<Row, P> = Intersect<P extends Window<infer A, infer V> ? {
123
- readonly [K in A]: V extends keyof Row ? NonNullable<Row[V]> | null : number;
123
+ readonly [K in A]: V extends keyof Row ? NonNullable<Row[V]> | null : V extends number ? number : string;
124
124
  } : {}>;
125
125
  type IncludeRows<S extends QuerySchema, K extends keyof S["~byName"], Inc> = [Inc] extends [
126
126
  Record<string, unknown>
@@ -637,6 +637,20 @@ export type TableApi<S extends QuerySchema, K extends keyof S["~byName"] & strin
637
637
  readonly allow: Allow;
638
638
  }): Write<Show<RowOf<S, K>>>;
639
639
  insert(data: RequiredInsert<InsertOf<S, K>> & OptionalInsert<InsertOf<S, K>>, options?: InsertOptions<S, K>): Write<Show<RowOf<S, K>>>;
640
+ /**
641
+ * Inserts a list in one transaction. Unknown keys are dropped.
642
+ *
643
+ * `{ allow: ["id"] }` may set `id` on a client-generator primary key.
644
+ * A row that omits `id` still takes the generator. A longer `allow` list
645
+ * does not open `id` in this type.
646
+ *
647
+ * @param data - Rows. `id` is optional when `allow` is exactly `["id"]`
648
+ * @param options - Must set `allow` to `["id"]`
649
+ * @returns The inserted rows
650
+ */
651
+ insert(data: readonly (RequiredInsert<InsertOf<S, K>> & OptionalInsert<InsertOf<S, K>> & Partial<Pick<RowOf<S, K>, "id" & keyof RowOf<S, K>>>)[], options: InsertOptions<S, K> & {
652
+ readonly allow: readonly ["id"];
653
+ }): Write<readonly Show<RowOf<S, K>>[]>;
640
654
  /**
641
655
  * Inserts a list in one transaction. Unknown keys are dropped.
642
656
  *
@@ -1,12 +1,12 @@
1
1
  import {
2
2
  validationGate
3
- } from "../../shared/ze4hxsmy.js";
3
+ } from "../../shared/w9ejzaqf.js";
4
4
  import {
5
5
  addSchemaHook
6
- } from "../../shared/xnxsed62.js";
6
+ } from "../../shared/9dr2qnx7.js";
7
7
  import {
8
8
  queryHandle
9
- } from "../../shared/tbrvgw6z.js";
9
+ } from "../../shared/bah9nbg3.js";
10
10
  import {
11
11
  OkmError2
12
12
  } from "../../shared/52szzakm.js";
@@ -14,7 +14,7 @@ import {
14
14
  // src/runtime/validate/load.ts
15
15
  var engine;
16
16
  function loadEngine() {
17
- engine ??= import("../../shared/h15jx9bc.js");
17
+ engine ??= import("../../shared/9dvh1dr6.js");
18
18
  return engine;
19
19
  }
20
20
 
@@ -4,7 +4,7 @@ import {
4
4
  } from "./cnkky55j.js";
5
5
  import {
6
6
  createClient
7
- } from "./tbrvgw6z.js";
7
+ } from "./bah9nbg3.js";
8
8
  import {
9
9
  OkmError2
10
10
  } from "./52szzakm.js";
@@ -96,8 +96,7 @@ async function connectTopology(target, options, open) {
96
96
  const client = createClient(options.schema, router, { ownsPool: true, ...shared });
97
97
  const routed = client;
98
98
  routed.using = (route) => derive(options.schema, handle, router, shared, route);
99
- handles.set(routed, handle);
100
- return routed;
99
+ return instrument(routed, handle);
101
100
  } catch (error) {
102
101
  for (const endpoint of opened) {
103
102
  if (endpoint.timer !== undefined)
@@ -108,6 +107,105 @@ async function connectTopology(target, options, open) {
108
107
  throw error;
109
108
  }
110
109
  }
110
+ function instrument(client, handle, forced) {
111
+ const proxy = new Proxy(client, {
112
+ get(target, key, receiver) {
113
+ if (key === "using")
114
+ return Reflect.get(target, key, receiver);
115
+ const value = Reflect.get(target, key, receiver);
116
+ if (typeof value !== "function")
117
+ return retarget(value, handle, forced);
118
+ if (key === "tx") {
119
+ return (...args) => {
120
+ const index = typeof args[0] === "function" ? 0 : 1;
121
+ const fn = args[index];
122
+ if (typeof fn === "function") {
123
+ args[index] = (inner, ...rest) => fn(typeof inner === "object" && inner !== null ? instrument(inner, handle, "primary") : inner, ...rest);
124
+ }
125
+ return value.apply(target, args);
126
+ };
127
+ }
128
+ return (...args) => retarget(value.apply(target, args), handle, forced);
129
+ }
130
+ });
131
+ handles.set(proxy, handle);
132
+ return proxy;
133
+ }
134
+ function wrapTable(table, handle, forced) {
135
+ return new Proxy(table, {
136
+ get(target, key, receiver) {
137
+ const value = Reflect.get(target, key, receiver);
138
+ if (typeof value !== "function")
139
+ return value;
140
+ return (...args) => {
141
+ const route = forced ?? readCallRoute(args[0]);
142
+ return retarget(value.apply(target, args), handle, route);
143
+ };
144
+ }
145
+ });
146
+ }
147
+ function retarget(value, handle, route) {
148
+ if (typeof value !== "object" || value === null)
149
+ return value;
150
+ if (typeof Reflect.get(value, "inspect") === "function" && typeof Reflect.get(value, "then") === "function") {
151
+ return showReason(value, handle, route);
152
+ }
153
+ if (typeof Reflect.get(value, "find") === "function")
154
+ return wrapTable(value, handle, route);
155
+ if (typeof Reflect.get(value, "table") === "function")
156
+ return instrument(value, handle, route);
157
+ return value;
158
+ }
159
+ function showReason(query, handle, route) {
160
+ return new Proxy(query, {
161
+ get(target, key, receiver) {
162
+ const value = Reflect.get(target, key, receiver);
163
+ if (key === "inspect" && typeof value === "function") {
164
+ const inspect = value;
165
+ return () => Promise.resolve(inspect.call(target)).then(async (view) => {
166
+ if (typeof view !== "object" || view === null)
167
+ return view;
168
+ const sql = Reflect.get(view, "sql");
169
+ const text = typeof sql === "object" && sql !== null && typeof Reflect.get(sql, "text") === "string" ? Reflect.get(sql, "text") : "";
170
+ const choice = await preview(handle, text, route);
171
+ return {
172
+ ...view,
173
+ routing: {
174
+ endpoint: choice.endpoint.name,
175
+ role: choice.endpoint.role,
176
+ reason: choice.reason
177
+ }
178
+ };
179
+ });
180
+ }
181
+ if ((key === "all" || key === "required") && typeof value === "function") {
182
+ const method = value;
183
+ return (...args) => retarget(method.apply(target, args), handle, route);
184
+ }
185
+ return typeof value === "function" ? value.bind(target) : value;
186
+ }
187
+ });
188
+ }
189
+ function readCallRoute(value) {
190
+ if (typeof value !== "object" || value === null)
191
+ return;
192
+ const route = Reflect.get(value, "route");
193
+ return route === "primary" || route === "replica" ? route : undefined;
194
+ }
195
+ async function preview(handle, text, route) {
196
+ const currents = handle.endpoints.map((endpoint) => endpoint.current);
197
+ const rrLast = handle.rrLast;
198
+ try {
199
+ return await choose(handle, text, route);
200
+ } finally {
201
+ for (let index = 0;index < handle.endpoints.length; index += 1) {
202
+ const endpoint = handle.endpoints[index];
203
+ if (endpoint !== undefined)
204
+ endpoint.current = currents[index] ?? 0;
205
+ }
206
+ handle.rrLast = rrLast;
207
+ }
208
+ }
111
209
  function refuseRouting(routing) {
112
210
  if (routing === undefined)
113
211
  return;
@@ -574,7 +672,7 @@ function derive(schema, handle, router, shared, route) {
574
672
  const name = readRoute(route);
575
673
  const client = createClient(schema, force(handle, router, name), { ...shared, ownsPool: false });
576
674
  delete client.close;
577
- return client;
675
+ return instrument(client, handle, name);
578
676
  }
579
677
  function force(handle, router, route) {
580
678
  const pool = {