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
@@ -207,6 +207,12 @@ export type ColumnState<TValue> = {
207
207
  } | undefined;
208
208
  readonly guarded: boolean;
209
209
  readonly hidden: boolean;
210
+ /**
211
+ * Hidden, and allowed in `where` and `orderBy`.
212
+ *
213
+ * Absent otherwise. Not part of the catalog or its hash.
214
+ */
215
+ readonly filterable?: true;
210
216
  /** Redacted in logs, errors, and `inspect()`. Not part of the catalog hash. */
211
217
  readonly sensitive: boolean;
212
218
  readonly omitWrite: boolean;
@@ -383,11 +389,16 @@ export declare class ColumnBuilder<TValue, TFlags extends ColumnFlags> {
383
389
  /**
384
390
  * Excludes the column from the default row.
385
391
  *
386
- * A named `select` still returns it. Includes never do.
392
+ * A named `select` still returns it. Includes never do. `where` and
393
+ * `orderBy` refuse it (OKM1120) unless `filterable` is set. `filters()`
394
+ * still refuses it.
387
395
  *
396
+ * @param options - `filterable` allows the column in `where` and `orderBy`
388
397
  * @returns The same column, hidden
389
398
  */
390
- hidden(): ColumnBuilder<TValue, FlagTrue<TFlags, "hidden">>;
399
+ hidden(options?: {
400
+ readonly filterable?: boolean;
401
+ }): ColumnBuilder<TValue, FlagTrue<TFlags, "hidden">>;
391
402
  /**
392
403
  * Redacts the value in logs, errors, and `inspect()`.
393
404
  *
@@ -4,7 +4,7 @@
4
4
  * Planning and scratch comparison both render through here, so a statement
5
5
  * has one spelling.
6
6
  */
7
- import type { Catalog, CatalogObject, ColumnObject, FunctionObject, MaterializedViewObject, SequenceObject, TableObject, ViewObject } from "../../contracts/catalog/types.js";
7
+ import type { Catalog, CatalogObject, ColumnObject, FunctionObject, MaterializedViewObject, PolicyObject, SequenceObject, TableObject, ViewObject } from "../../contracts/catalog/types.js";
8
8
  /**
9
9
  * Quotes one identifier.
10
10
  *
@@ -23,6 +23,18 @@ export declare function quoteIdent(name: string): string;
23
23
  * @returns SQL statements
24
24
  */
25
25
  export declare function renderCatalog(source: Catalog, schema: string): readonly string[];
26
+ /**
27
+ * Pulls a unique constraint in front of a foreign key that references it.
28
+ *
29
+ * The primary key is created with the table. A foreign key aimed at another
30
+ * unique has to wait for that unique. Create order ties those two by name, so
31
+ * the foreign key can otherwise come first. The planner uses this for creates
32
+ * and for the list it reverses when it drops.
33
+ *
34
+ * @param objects - Create order
35
+ * @returns The same objects, with those uniques moved forward
36
+ */
37
+ export declare function uniqueBeforeForeignKey(objects: readonly CatalogObject[]): readonly CatalogObject[];
26
38
  /**
27
39
  * Reports whether an index belongs to a view or a materialized view.
28
40
  *
@@ -74,6 +86,30 @@ export declare function functionSql(object: FunctionObject, schema: string, repl
74
86
  * @returns The statement
75
87
  */
76
88
  export declare function viewSql(object: ViewObject, schema: string, replace: boolean): string;
89
+ /** One policy statement and the planner kind that classifies it. */
90
+ export type PolicyPlanStep = {
91
+ readonly sql: string;
92
+ readonly kind: "enable-rls" | "create-policy" | "drop-policy" | "disable-rls";
93
+ };
94
+ /**
95
+ * `ENABLE`, `FORCE`, and `CREATE POLICY` for one policy.
96
+ *
97
+ * The `all` command policy also enables and forces row-level security.
98
+ * The `select` policy is the unscoped read. Names are the stored identity.
99
+ *
100
+ * @param object - Policy to create
101
+ * @param schema - Concrete schema name
102
+ * @returns Statements in apply order
103
+ */
104
+ export declare function policyCreatePlan(object: PolicyObject, schema: string): readonly PolicyPlanStep[];
105
+ /**
106
+ * `DROP POLICY`, and for the `all` command policy `NO FORCE` and `DISABLE`.
107
+ *
108
+ * @param object - Policy to drop
109
+ * @param schema - Concrete schema name
110
+ * @returns Statements in apply order
111
+ */
112
+ export declare function policyDropPlan(object: PolicyObject, schema: string): readonly PolicyPlanStep[];
77
113
  /**
78
114
  * `CREATE MATERIALIZED VIEW ... WITH NO DATA`.
79
115
  *
@@ -6,6 +6,14 @@
6
6
  */
7
7
  import { type BuiltSchema } from "./schema.js";
8
8
  import { type AnyTable } from "./table.js";
9
+ /**
10
+ * Type arguments read from `t.json<T>()` and `t.jsonb<T>()` in schema source.
11
+ *
12
+ * The key is `table.field`. QA-L3 kept the wrapper for a bare `t.jsonb()`,
13
+ * which has no argument and stays `jsonb<unknown>`. The documented call
14
+ * `t.jsonb<{ published?: boolean }>()` is this map.
15
+ */
16
+ export type JsonColumnTypes = ReadonlyMap<string, string>;
9
17
  /**
10
18
  * Emits row, insert, and update interfaces for every table.
11
19
  *
@@ -13,6 +21,16 @@ import { type AnyTable } from "./table.js";
13
21
  * and `TasksUpdate`.
14
22
  *
15
23
  * @param source - Schema from {@link schema}
24
+ * @param jsonTypes - Type arguments from the schema source. Omitted, json and jsonb stay `unknown`
16
25
  * @returns Declaration text
17
26
  */
18
- export declare function emitRowTypes(source: BuiltSchema<readonly AnyTable[]>): string;
27
+ export declare function emitRowTypes(source: BuiltSchema<readonly AnyTable[]>, jsonTypes?: JsonColumnTypes): string;
28
+ /**
29
+ * Reads `t.json<T>()` and `t.jsonb<T>()` type arguments from schema source.
30
+ *
31
+ * A bare `t.jsonb()` has no argument. The key is the table name and the field.
32
+ *
33
+ * @param source - Schema source, comments removed by the caller or still present
34
+ * @returns `table.field` to the type argument text
35
+ */
36
+ export declare function jsonColumnTypes(source: string): JsonColumnTypes;
@@ -2,9 +2,30 @@
2
2
  * Maps a Postgres {@link DriverError} to an {@link OkmError} (spec §4.2, §14).
3
3
  *
4
4
  * Adapters normalise the driver into `DriverError`. They do not construct
5
- * `OkmError`. Constraint names follow the catalog: `{table}_{nameKey}_{tag}`.
5
+ * `OkmError`. `connect()` passes its schema. A reason then comes from the
6
+ * error's columns matched to a catalog object. With no catalog, the
7
+ * constraint name is parsed.
6
8
  */
9
+ import type { Catalog } from "../../contracts/catalog/types.js";
7
10
  import { OkmError, type ErrorStatuses } from "../../contracts/error.js";
11
+ /**
12
+ * Catalog and model used to name a unique, foreign key, or check.
13
+ *
14
+ * `connect()` passes the schema it already holds. The reference is enough:
15
+ * matching stays in this module.
16
+ */
17
+ export type MapPostgresErrorSchema = {
18
+ readonly catalog: Catalog;
19
+ readonly model: Readonly<Record<string, {
20
+ readonly sql: string;
21
+ readonly columns: readonly SqlField[];
22
+ }>>;
23
+ };
24
+ /** One column the reason mapper can turn back into a TypeScript field. */
25
+ type SqlField = {
26
+ readonly field: string;
27
+ readonly sql: string;
28
+ };
8
29
  /** Options for {@link mapPostgresError}. */
9
30
  export type MapPostgresErrorOptions = {
10
31
  /**
@@ -15,6 +36,15 @@ export type MapPostgresErrorOptions = {
15
36
  readonly includeValues?: boolean;
16
37
  /** Category overrides from `connect({ errors })`. */
17
38
  readonly http?: ErrorStatuses;
39
+ /**
40
+ * Schema whose catalog still has the stored name key.
41
+ *
42
+ * Columns in the error select the object. The stored name key is the
43
+ * reason. A composite key that is only the SQL column list becomes the
44
+ * TypeScript fields. With no columns, the stored name key is the reason.
45
+ * An index keeps its full name.
46
+ */
47
+ readonly schema?: MapPostgresErrorSchema;
18
48
  };
19
49
  /**
20
50
  * Maps a thrown driver error into an {@link OkmError}.
@@ -28,3 +58,4 @@ export type MapPostgresErrorOptions = {
28
58
  * @returns A categorised error
29
59
  */
30
60
  export declare function mapPostgresError(error: unknown, options?: MapPostgresErrorOptions): OkmError;
61
+ export {};
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  extension2
3
- } from "../../../shared/ycatkxmq.js";
3
+ } from "../../../shared/jgqj11w4.js";
4
4
 
5
5
  // src/dialects/pg/ext/citext.ts
6
6
  function citext(options = {}) {
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  extension2
3
- } from "../../../shared/ycatkxmq.js";
3
+ } from "../../../shared/jgqj11w4.js";
4
4
  export {
5
5
  extension2 as extension
6
6
  };
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  extension2
3
- } from "../../../shared/ycatkxmq.js";
3
+ } from "../../../shared/jgqj11w4.js";
4
4
  import {
5
5
  tag
6
6
  } from "../../../shared/cn0n68ft.js";
@@ -5,9 +5,9 @@
5
5
  * before this module exists.
6
6
  *
7
7
  * A request key is equality when the value is a scalar and `eq` is allowed.
8
- * An object value names operators: `eq`, `in` (`inList`), `notIn`, `lt`,
9
- * `lte`, `gt`, `gte`, `between`, `startsWith`, `endsWith`, `contains`,
10
- * `like`, and `ilike`. `sort` is a field name from the sort list.
8
+ * An object value names operators `parse` applies. `sort` is a field name
9
+ * from the sort list. A relation key becomes `has` over the allowlisted fields.
10
+ * A column key wins when the same name is in `allow` and `relations`.
11
11
  */
12
12
  import type { ParsedFilters } from "./table.js";
13
13
  /**
@@ -20,6 +20,7 @@ import type { ParsedFilters } from "./table.js";
20
20
  * @param allow - Fields and the operators each one accepts
21
21
  * @param sort - Fields a caller may sort by
22
22
  * @param query - One request object
23
+ * @param relations - Relation name to fields, when `filters` passed any
23
24
  * @returns Filters a caller can spread into `find`
24
25
  */
25
- export declare function parseQuery(allow: Readonly<Record<string, readonly string[]>>, sort: readonly string[], query: unknown): ParsedFilters;
26
+ export declare function parseQuery(allow: Readonly<Record<string, readonly string[]>>, sort: readonly string[], query: unknown, relations?: Readonly<Record<string, readonly string[]>>): ParsedFilters;
@@ -0,0 +1,68 @@
1
+ /**
2
+ * Postgres majors a schema may name, and the features that read them.
3
+ *
4
+ * 15–18 are the majors okmodel runs. A major outside that range is refused
5
+ * when `schema()` runs. Messages read these numbers. They do not repeat them.
6
+ */
7
+ /** Majors `minPostgres` and `requires.postgres` accept, oldest first. */
8
+ export declare const POSTGRES_MAJORS: readonly [15, 16, 17, 18];
9
+ /** A major {@link POSTGRES_MAJORS} allows. */
10
+ export type PostgresMajor = (typeof POSTGRES_MAJORS)[number];
11
+ /**
12
+ * Oldest major connect accepts when the schema names no floor.
13
+ *
14
+ * A server below this is OKM1803.
15
+ */
16
+ export declare const POSTGRES_FLOOR = 15;
17
+ /**
18
+ * `uuidv7()` database default.
19
+ *
20
+ * Add the next feature constant beside this one, and name it on the minPostgres page.
21
+ */
22
+ export declare const UUIDV7_POSTGRES = 18;
23
+ /**
24
+ * Accepts a major from {@link POSTGRES_MAJORS}.
25
+ *
26
+ * @param value - Candidate from schema input
27
+ * @returns Whether `value` is 15, 16, 17, or 18
28
+ */
29
+ export declare function isPostgresMajor(value: unknown): value is PostgresMajor;
30
+ /**
31
+ * Reads a stored `>=N` floor.
32
+ *
33
+ * `readFloor`, `refuseUuidV7`, and `acceptServer` share this parse.
34
+ *
35
+ * @param postgres - Stored or input range
36
+ * @returns The major, or `NaN` when the text is not `>=` plus digits
37
+ */
38
+ export declare function parsePostgresFloor(postgres: string | undefined): number;
39
+ /**
40
+ * Stores a major as `>=N`.
41
+ *
42
+ * @param major - Allowed major
43
+ * @returns The stored floor text
44
+ */
45
+ export declare function formatPostgresFloor(major: number): string;
46
+ /**
47
+ * Definition error for a floor outside 15–18.
48
+ *
49
+ * @returns OKM1060 message
50
+ */
51
+ export declare function minPostgresDefinition(): string;
52
+ /**
53
+ * Sentence for a `uuidv7()` default the declared floor does not allow.
54
+ *
55
+ * @returns The OKM1812 message
56
+ */
57
+ export declare function uuidv7NeedsPostgres(): string;
58
+ /**
59
+ * Connect refusal when the server is below the schema floor.
60
+ *
61
+ * OKM1802 and OKM1803 share this sentence. OKM1803 passes {@link POSTGRES_FLOOR}.
62
+ * Loaded with the connect check, not with `schema()`.
63
+ *
64
+ * @param server - Major the server reported
65
+ * @param need - Major the schema requires
66
+ * @returns The message
67
+ */
68
+ export declare function serverNeedsPostgres(server: number, need: number): string;
@@ -1,10 +1,10 @@
1
1
  import {
2
2
  functionObject,
3
3
  triggerObject
4
- } from "../../../shared/9x25fxhc.js";
4
+ } from "../../../shared/y34a8714.js";
5
5
  import {
6
6
  staticNamespace2
7
- } from "../../../shared/t4tbsy9h.js";
7
+ } from "../../../shared/358zsv4r.js";
8
8
  import {
9
9
  assertIdentifier2
10
10
  } from "../../../shared/nfzc5z0w.js";
@@ -4,8 +4,10 @@
4
4
  * Column types, codecs, picklists, `table()`, and `schema()`.
5
5
  * Each builder is a separate export so a bundle can keep only the ones it calls.
6
6
  */
7
+ export { type PostgresMajor } from "./floor.js";
7
8
  export { schema, type BuiltSchema, type SchemaCodecs, type SchemaInput, type SchemaRequires, } from "./schema.js";
8
- export { index, sql, table, type AnyTable, type ColumnHandle, type IndexCall, type SqlText, type SqlValue, type Table, type TableOptions, } from "./table.js";
9
+ export { withOwner, type DeclaredOwner } from "./owner.js";
10
+ export { index, sql, table, type AnyTable, type ColumnHandle, type IndexCall, type SqlText, type SqlValue, type FilterOperator, type Table, type TableOptions, } from "./table.js";
9
11
  export type { PresetQuery } from "./preset.js";
10
12
  export { custom } from "./custom.js";
11
13
  export { ColumnBuilder } from "./column.js";
@@ -26,6 +28,8 @@ export { domain, enumColumn as enum } from "./enum.js";
26
28
  export { t } from "./namespace.js";
27
29
  export * as arr from "./ops/arr-ns.js";
28
30
  export * as json from "./ops/json-ns.js";
31
+ export { bucket, type Bucket, type BucketUnit, type WeekStart } from "./ops/bucket.js";
32
+ export { denseRank, rank, rowNumber, runningTotal, type Window, type WindowOrder, } from "./ops/window.js";
29
33
  export { between } from "./ops/between.js";
30
34
  export { containedBy } from "./ops/containedBy.js";
31
35
  export { contains } from "./ops/contains.js";
@@ -42,6 +46,8 @@ export { ilike } from "./ops/ilike.js";
42
46
  export { inList } from "./ops/inList.js";
43
47
  export { like } from "./ops/like.js";
44
48
  export { matches } from "./ops/matches.js";
49
+ export { relevance } from "./ops/relevance.js";
50
+ export type { SearchMatch } from "./operators.js";
45
51
  export { lt } from "./ops/lt.js";
46
52
  export { lte } from "./ops/lte.js";
47
53
  export { none } from "./ops/none.js";
@@ -51,4 +57,4 @@ export { or } from "./ops/or.js";
51
57
  export { overlaps } from "./ops/overlaps.js";
52
58
  export { path } from "./ops/path.js";
53
59
  export { startsWith } from "./ops/startsWith.js";
54
- export { many, manyThrough, one, type ManyRelation, type ManyThroughRelation, type OneRelation, type RelationCall, } from "./relations.js";
60
+ export { many, manyThrough, morph, morphMany, morphTo, one, type ManyRelation, type ManyThroughRelation, type MorphManyRelation, type MorphRelation, type OneRelation, type RelationCall, } from "./relations.js";
@@ -1,9 +1,31 @@
1
+ import {
2
+ searchValue
3
+ } from "../../shared/dzj09cye.js";
4
+ import {
5
+ rowNumber2,
6
+ rank2,
7
+ denseRank2,
8
+ runningTotal2
9
+ } from "../../shared/9a4ae4p8.js";
1
10
  import {
2
11
  jsonReplacer2,
3
12
  json2,
4
13
  jsonb2
5
- } from "../../shared/gjthds9j.js";
14
+ } from "../../shared/9628a9xt.js";
15
+ import {
16
+ bucket2
17
+ } from "../../shared/nbw1z4yd.js";
6
18
  import {
19
+ withOwner2
20
+ } from "../../shared/xqve9598.js";
21
+ import {
22
+ smallint2,
23
+ integer2,
24
+ bigint2,
25
+ identity2,
26
+ encodeBigintString,
27
+ decodeBigintString,
28
+ integerToken,
7
29
  encodeInstant,
8
30
  decodeInstant,
9
31
  encodeDate,
@@ -14,25 +36,25 @@ import {
14
36
  time2,
15
37
  timetz2,
16
38
  interval2
17
- } from "../../shared/1g0drakv.js";
39
+ } from "../../shared/vqrjpcqn.js";
18
40
  import {
19
- one2,
20
- many2,
21
- manyThrough2,
22
41
  schema2
23
- } from "../../shared/5enne4ma.js";
42
+ } from "../../shared/xnxsed62.js";
24
43
  import {
25
44
  domainType
26
- } from "../../shared/g7ez901n.js";
45
+ } from "../../shared/ywspezzx.js";
46
+ import {
47
+ one2,
48
+ many2,
49
+ manyThrough2,
50
+ morph2,
51
+ morphMany2,
52
+ morphTo2
53
+ } from "../../shared/exn3sd90.js";
27
54
  import {
28
55
  id2,
29
56
  uuid2
30
- } from "../../shared/dyj86cmj.js";
31
- import {
32
- table2,
33
- index2,
34
- sql2
35
- } from "../../shared/ntneex2a.js";
57
+ } from "../../shared/hyh73qk6.js";
36
58
  import {
37
59
  text2,
38
60
  varchar2,
@@ -40,13 +62,17 @@ import {
40
62
  citext2,
41
63
  encodeText,
42
64
  decodeText
43
- } from "../../shared/4m9fn52z.js";
65
+ } from "../../shared/ed0b8k4s.js";
66
+ import {
67
+ table2,
68
+ index2,
69
+ sql2
70
+ } from "../../shared/rpycarcr.js";
44
71
  import {
45
72
  ColumnBuilder2,
46
73
  required,
47
- openColumn,
48
74
  formatType
49
- } from "../../shared/c9z5g0fm.js";
75
+ } from "../../shared/ywr8hmey.js";
50
76
  import {
51
77
  definition,
52
78
  rejected
@@ -54,7 +80,7 @@ import {
54
80
  import {
55
81
  sameNamespace2,
56
82
  compareText
57
- } from "../../shared/t4tbsy9h.js";
83
+ } from "../../shared/358zsv4r.js";
58
84
  import {
59
85
  tag
60
86
  } from "../../shared/cn0n68ft.js";
@@ -90,146 +116,6 @@ function custom(spec) {
90
116
  ...spec.extension !== undefined ? { extension: spec.extension } : {}
91
117
  });
92
118
  }
93
- // src/dialects/pg/integer.ts
94
- function smallint() {
95
- return required({
96
- baseType: "smallint",
97
- encode: (value) => integerToken(value, -32768, 32767, "smallint"),
98
- decode: (wire) => decodeBounded(wire, -32768, 32767, "smallint"),
99
- sqlForm: "raw"
100
- });
101
- }
102
- function integer() {
103
- return required({
104
- baseType: "integer",
105
- encode: (value) => integerToken(value, -2147483648, 2147483647, "integer"),
106
- decode: (wire) => decodeBounded(wire, -2147483648, 2147483647, "integer"),
107
- sqlForm: "raw"
108
- });
109
- }
110
- function bigint(options) {
111
- const mode = options?.as ?? "string";
112
- if (mode === "number") {
113
- return required({
114
- baseType: "bigint",
115
- encode: encodeBigintNumber,
116
- decode: decodeBigintNumber,
117
- sqlForm: "raw",
118
- typeLabel: "number"
119
- });
120
- }
121
- if (mode === "bigint") {
122
- return required({
123
- baseType: "bigint",
124
- encode: encodeBigintValue,
125
- decode: decodeBigintValue,
126
- sqlForm: "raw",
127
- typeLabel: "bigint"
128
- });
129
- }
130
- if (mode !== "string") {
131
- definition(`bigint as ${String(mode)} must be string, number, or bigint.`);
132
- }
133
- return required({
134
- baseType: "bigint",
135
- encode: encodeBigintString,
136
- decode: decodeBigintString,
137
- sqlForm: "raw"
138
- });
139
- }
140
- function identity(options) {
141
- const mode = options?.as ?? "string";
142
- if (mode === "number") {
143
- return openColumn({
144
- ...identityFlags(),
145
- encode: encodeBigintNumber,
146
- decode: decodeBigintNumber,
147
- typeLabel: "number"
148
- });
149
- }
150
- if (mode === "bigint") {
151
- return openColumn({
152
- ...identityFlags(),
153
- encode: encodeBigintValue,
154
- decode: decodeBigintValue,
155
- typeLabel: "bigint"
156
- });
157
- }
158
- if (mode !== "string") {
159
- definition(`identity as ${String(mode)} must be string, number, or bigint.`);
160
- }
161
- return openColumn({
162
- ...identityFlags(),
163
- encode: encodeBigintString,
164
- decode: decodeBigintString
165
- });
166
- }
167
- function encodeBigintString(value) {
168
- parseBigint(value);
169
- return value;
170
- }
171
- function decodeBigintString(wire) {
172
- return encodeBigintString(wire);
173
- }
174
- function encodeBigintNumber(value) {
175
- if (!Number.isSafeInteger(value)) {
176
- rejected(`bigint number ${String(value)} must be an integer from ${String(Number.MIN_SAFE_INTEGER)} to ${String(Number.MAX_SAFE_INTEGER)}.`);
177
- }
178
- return String(value);
179
- }
180
- function decodeBigintNumber(wire) {
181
- const parsed = parseBigint(wire);
182
- const value = Number(parsed);
183
- if (!Number.isSafeInteger(value)) {
184
- rejected(`bigint ${wire} must be an integer from ${String(Number.MIN_SAFE_INTEGER)} to ${String(Number.MAX_SAFE_INTEGER)} when as is number.`);
185
- }
186
- return value;
187
- }
188
- function encodeBigintValue(value) {
189
- return value.toString();
190
- }
191
- function decodeBigintValue(wire) {
192
- return parseBigint(wire);
193
- }
194
- function integerToken(value, min, max, role) {
195
- if (!Number.isInteger(value) || value < min || value > max) {
196
- rejected(`${role} ${String(value)} must be an integer from ${String(min)} to ${String(max)}.`);
197
- }
198
- return String(value);
199
- }
200
- function decodeBounded(wire, min, max, role) {
201
- if (!integerText().test(wire)) {
202
- rejected(`${role} ${wire} must be an integer, for example 0 or -12.`);
203
- }
204
- const value = Number(wire);
205
- integerToken(value, min, max, role);
206
- return value;
207
- }
208
- function identityFlags() {
209
- return {
210
- baseType: "bigint",
211
- nullable: false,
212
- hasDefault: true,
213
- generated: false,
214
- guarded: false,
215
- hidden: false,
216
- omitWrite: true,
217
- sqlForm: "raw",
218
- identity: { always: true },
219
- primaryKey: true
220
- };
221
- }
222
- function parseBigint(wire) {
223
- if (!integerText().test(wire)) {
224
- rejected(`bigint ${wire} must be an integer with no leading zeros, for example 0 or -12.`);
225
- }
226
- return BigInt(wire);
227
- }
228
- function integerText() {
229
- integerPattern ??= /^-?(?:0|[1-9]\d*)$/;
230
- return integerPattern;
231
- }
232
- var integerPattern;
233
119
  // src/dialects/pg/finite.ts
234
120
  function decimalText(value, role) {
235
121
  if (!Number.isFinite(value)) {
@@ -756,11 +642,11 @@ function canonicalScalar(typeName) {
756
642
  // src/dialects/pg/namespace.ts
757
643
  var t = {
758
644
  id: id2,
759
- identity,
645
+ identity: identity2,
760
646
  uuid: uuid2,
761
- smallint,
762
- integer,
763
- bigint,
647
+ smallint: smallint2,
648
+ integer: integer2,
649
+ bigint: bigint2,
764
650
  numeric,
765
651
  real,
766
652
  double,
@@ -882,11 +768,11 @@ function like(pattern) {
882
768
  }
883
769
  // src/dialects/pg/ops/matches.ts
884
770
  function matches(query, options) {
885
- return tag("matches", {
886
- query,
887
- mode: options?.mode ?? "websearch",
888
- config: options?.config
889
- });
771
+ return tag("matches", searchValue(query, options));
772
+ }
773
+ // src/dialects/pg/ops/relevance.ts
774
+ function relevance(query, options) {
775
+ return tag("relevance", searchValue(query, options));
890
776
  }
891
777
  // src/dialects/pg/ops/lt.ts
892
778
  function lt(value) {
@@ -933,8 +819,9 @@ export {
933
819
  ColumnBuilder2 as ColumnBuilder,
934
820
  exports_arr_ns as arr,
935
821
  between,
936
- bigint,
822
+ bigint2 as bigint,
937
823
  boolean,
824
+ bucket2 as bucket,
938
825
  bytea,
939
826
  char2 as char,
940
827
  cidr,
@@ -944,6 +831,7 @@ export {
944
831
  custom,
945
832
  date2 as date,
946
833
  daterange,
834
+ denseRank2 as denseRank,
947
835
  domain,
948
836
  double,
949
837
  endsWith,
@@ -956,7 +844,7 @@ export {
956
844
  hasAnyKey,
957
845
  hasKey,
958
846
  id2 as id,
959
- identity,
847
+ identity2 as identity,
960
848
  ilike,
961
849
  inList,
962
850
  inc,
@@ -964,7 +852,7 @@ export {
964
852
  inet,
965
853
  int4range,
966
854
  int8range,
967
- integer,
855
+ integer2 as integer,
968
856
  interval2 as interval,
969
857
  exports_json_ns as json,
970
858
  jsonReplacer2 as jsonReplacer,
@@ -979,6 +867,9 @@ export {
979
867
  many2 as many,
980
868
  manyThrough2 as manyThrough,
981
869
  matches,
870
+ morph2 as morph,
871
+ morphMany2 as morphMany,
872
+ morphTo2 as morphTo,
982
873
  none,
983
874
  not,
984
875
  notIn,
@@ -989,9 +880,13 @@ export {
989
880
  overlaps,
990
881
  path,
991
882
  point,
883
+ rank2 as rank,
992
884
  real,
885
+ relevance,
886
+ rowNumber2 as rowNumber,
887
+ runningTotal2 as runningTotal,
993
888
  schema2 as schema,
994
- smallint,
889
+ smallint2 as smallint,
995
890
  sql2 as sql,
996
891
  startsWith,
997
892
  t,
@@ -1004,5 +899,6 @@ export {
1004
899
  tstzrange,
1005
900
  tsvector,
1006
901
  uuid2 as uuid,
1007
- varchar2 as varchar
902
+ varchar2 as varchar,
903
+ withOwner2 as withOwner
1008
904
  };