okmodel 0.1.1 → 0.3.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 (228) hide show
  1. package/README.md +727 -37
  2. package/dist/adapters/capabilities.d.ts +34 -0
  3. package/dist/adapters/pg/bunsql-extra.d.ts +17 -0
  4. package/dist/adapters/pg/bunsql.d.ts +60 -0
  5. package/dist/adapters/pg/call.d.ts +2 -12
  6. package/dist/adapters/pg/nodepostgres-extra.d.ts +18 -0
  7. package/dist/adapters/pg/nodepostgres.d.ts +57 -0
  8. package/dist/adapters/pg/postgres-extra.d.ts +50 -1
  9. package/dist/adapters/pg/postgresjs.d.ts +0 -4
  10. package/dist/adapters/pg/session.d.ts +94 -0
  11. package/dist/adapters/pg/watch.d.ts +18 -0
  12. package/dist/contracts/catalog/enum.d.ts +31 -4
  13. package/dist/contracts/catalog/extension.d.ts +61 -0
  14. package/dist/contracts/catalog/object.d.ts +1 -0
  15. package/dist/contracts/catalog/privilege.d.ts +64 -0
  16. package/dist/contracts/catalog/routine.d.ts +56 -0
  17. package/dist/contracts/catalog/types.d.ts +179 -18
  18. package/dist/contracts/catalog/view.d.ts +73 -0
  19. package/dist/contracts/connection.d.ts +13 -0
  20. package/dist/contracts/driver.d.ts +18 -5
  21. package/dist/contracts/error.d.ts +17 -1
  22. package/dist/contracts/generator.d.ts +63 -0
  23. package/dist/contracts/index.d.ts +2 -2
  24. package/dist/contracts/index.js +1 -1
  25. package/dist/contracts/internal.js +11 -9
  26. package/dist/contracts/location.d.ts +24 -0
  27. package/dist/contracts/rows.d.ts +15 -0
  28. package/dist/dialects/pg/archive-bind.d.ts +22 -0
  29. package/dist/dialects/pg/column.d.ts +129 -10
  30. package/dist/dialects/pg/compile.d.ts +1 -0
  31. package/dist/dialects/pg/custom.d.ts +6 -0
  32. package/dist/dialects/pg/ddl.d.ts +65 -1
  33. package/dist/dialects/pg/enum.d.ts +10 -8
  34. package/dist/dialects/pg/ext/citext.d.ts +14 -0
  35. package/dist/dialects/pg/ext/citext.js +11 -0
  36. package/dist/dialects/pg/ext/index.d.ts +52 -0
  37. package/dist/dialects/pg/ext/index.js +6 -0
  38. package/dist/dialects/pg/ext/pg-trgm.d.ts +53 -0
  39. package/dist/dialects/pg/ext/pg-trgm.js +42 -0
  40. package/dist/dialects/pg/filter-parse.d.ts +19 -0
  41. package/dist/dialects/pg/filters.d.ts +19 -0
  42. package/dist/dialects/pg/fn/index.d.ts +107 -0
  43. package/dist/dialects/pg/fn/index.js +175 -0
  44. package/dist/dialects/pg/fn/touch.d.ts +14 -0
  45. package/dist/dialects/pg/index.d.ts +11 -2
  46. package/dist/dialects/pg/index.js +243 -1062
  47. package/dist/dialects/pg/introspect.d.ts +10 -1
  48. package/dist/dialects/pg/keys.d.ts +19 -3
  49. package/dist/dialects/pg/model.d.ts +223 -2
  50. package/dist/dialects/pg/operator-fit.d.ts +86 -0
  51. package/dist/dialects/pg/operators.d.ts +46 -1
  52. package/dist/dialects/pg/ops/arr-append.d.ts +9 -0
  53. package/dist/dialects/pg/ops/arr-ns.d.ts +7 -0
  54. package/dist/dialects/pg/ops/arr-remove.d.ts +9 -0
  55. package/dist/dialects/pg/ops/containedBy.d.ts +9 -0
  56. package/dist/dialects/pg/ops/contains.d.ts +8 -4
  57. package/dist/dialects/pg/ops/hasAnyKey.d.ts +8 -0
  58. package/dist/dialects/pg/ops/hasKey.d.ts +8 -0
  59. package/dist/dialects/pg/ops/json-ns.d.ts +6 -0
  60. package/dist/dialects/pg/ops/json-set.d.ts +12 -0
  61. package/dist/dialects/pg/ops/matches.d.ts +16 -0
  62. package/dist/dialects/pg/ops/overlaps.d.ts +9 -0
  63. package/dist/dialects/pg/ops/path.d.ts +13 -0
  64. package/dist/dialects/pg/preset.d.ts +76 -0
  65. package/dist/dialects/pg/relations.d.ts +59 -2
  66. package/dist/dialects/pg/role/check.d.ts +45 -0
  67. package/dist/dialects/pg/role/index.d.ts +50 -0
  68. package/dist/dialects/pg/role/sql.d.ts +44 -0
  69. package/dist/dialects/pg/schema.d.ts +109 -5
  70. package/dist/dialects/pg/table.d.ts +137 -11
  71. package/dist/dialects/pg/temporal.d.ts +9 -7
  72. package/dist/dialects/pg/tenancy.d.ts +103 -0
  73. package/dist/dialects/pg/through.d.ts +21 -0
  74. package/dist/dialects/pg/trait.d.ts +141 -0
  75. package/dist/dialects/pg/view/client.d.ts +30 -0
  76. package/dist/dialects/pg/view/depend.d.ts +35 -0
  77. package/dist/dialects/pg/view/index.d.ts +114 -0
  78. package/dist/dialects/pg/view/index.js +289 -0
  79. package/dist/dialects/pg/view/scratch.d.ts +21 -0
  80. package/dist/dialects/pg/where.d.ts +37 -0
  81. package/dist/runtime/aggregate.d.ts +25 -0
  82. package/dist/runtime/archive-handle.d.ts +18 -0
  83. package/dist/runtime/archive-rules.d.ts +12 -0
  84. package/dist/runtime/archive.d.ts +73 -0
  85. package/dist/runtime/batch.d.ts +20 -0
  86. package/dist/runtime/client.d.ts +114 -5
  87. package/dist/runtime/conflict.d.ts +2 -1
  88. package/dist/runtime/exposure.d.ts +27 -0
  89. package/dist/runtime/hookm.d.ts +39 -0
  90. package/dist/runtime/ids/index.d.ts +11 -0
  91. package/dist/runtime/ids/index.js +193 -0
  92. package/dist/runtime/ids/okid-extended.d.ts +19 -0
  93. package/dist/runtime/ids/okid-generator.d.ts +21 -0
  94. package/dist/runtime/ids/okid-shared.d.ts +89 -0
  95. package/dist/runtime/ids/okid.d.ts +24 -0
  96. package/dist/runtime/ids/uuid.d.ts +21 -0
  97. package/dist/runtime/lock.d.ts +22 -0
  98. package/dist/runtime/operator-sql.d.ts +8 -0
  99. package/dist/runtime/page.d.ts +25 -0
  100. package/dist/runtime/pg/bun.d.ts +30 -0
  101. package/dist/runtime/pg/bun.js +52 -0
  102. package/dist/runtime/pg/pg.d.ts +29 -0
  103. package/dist/runtime/pg/pg.js +52 -0
  104. package/dist/runtime/pg/pglite.js +16 -17
  105. package/dist/runtime/pg/postgresjs.js +14 -24
  106. package/dist/runtime/plan.d.ts +146 -7
  107. package/dist/runtime/preset-stack.d.ts +17 -0
  108. package/dist/runtime/presets.d.ts +48 -0
  109. package/dist/runtime/read-stream.d.ts +26 -0
  110. package/dist/runtime/safety/index.d.ts +159 -0
  111. package/dist/runtime/safety/index.js +294 -0
  112. package/dist/runtime/safety-hook.d.ts +42 -0
  113. package/dist/runtime/server-check.d.ts +34 -0
  114. package/dist/runtime/tenancy/index.d.ts +37 -0
  115. package/dist/runtime/tenancy/index.js +368 -0
  116. package/dist/runtime/trait-read.d.ts +30 -0
  117. package/dist/runtime/traits/index.d.ts +133 -0
  118. package/dist/runtime/traits/index.js +646 -0
  119. package/dist/runtime/transaction.d.ts +19 -0
  120. package/dist/runtime/tx.d.ts +22 -7
  121. package/dist/runtime/types.d.ts +376 -27
  122. package/dist/runtime/validate/bind.d.ts +11 -0
  123. package/dist/runtime/validate/closed.d.ts +16 -0
  124. package/dist/runtime/validate/engine.d.ts +41 -0
  125. package/dist/runtime/validate/hook.d.ts +17 -0
  126. package/dist/runtime/validate/index.d.ts +21 -0
  127. package/dist/runtime/validate/index.js +175 -0
  128. package/dist/runtime/validate/load.d.ts +13 -0
  129. package/dist/runtime/validate/places.d.ts +41 -0
  130. package/dist/runtime/validate/rules.d.ts +108 -0
  131. package/dist/runtime/validate/surface.d.ts +102 -0
  132. package/dist/runtime/write.d.ts +30 -5
  133. package/dist/shared/01yr20s5.js +149 -0
  134. package/dist/shared/0jc3ffzf.js +154 -0
  135. package/dist/shared/0v1g424p.js +26 -0
  136. package/dist/shared/1g0drakv.js +225 -0
  137. package/dist/shared/{kprcwaha.js → 1tfdfvhh.js} +5 -3
  138. package/dist/shared/{05w44d8g.js → 2ssqrv66.js} +767 -715
  139. package/dist/shared/3ekj9x92.js +210 -0
  140. package/dist/shared/49ypnfwt.js +1122 -0
  141. package/dist/shared/4e4c6vq2.js +62 -0
  142. package/dist/shared/4m9fn52z.js +70 -0
  143. package/dist/shared/{ycwz42az.js → 52szzakm.js} +6 -26
  144. package/dist/shared/5nmdenb6.js +1229 -0
  145. package/dist/shared/672t5vym.js +12 -0
  146. package/dist/shared/6bazvqwm.js +86 -0
  147. package/dist/shared/6w5j844a.js +201 -0
  148. package/dist/shared/{fgqgsb5z.js → 75xkjv0t.js} +2 -2
  149. package/dist/shared/7fvtrkwr.js +84 -0
  150. package/dist/shared/7m88x3e9.js +45 -0
  151. package/dist/shared/{mtkwv8wx.js → 7p2wbz7f.js} +1 -1
  152. package/dist/shared/83eaefwr.js +10 -0
  153. package/dist/shared/94ez8kzh.js +19 -0
  154. package/dist/shared/96ps4g1z.js +32 -0
  155. package/dist/shared/{xqbhg6cn.js → 999ade2q.js} +95 -10
  156. package/dist/shared/9m80mkac.js +158 -0
  157. package/dist/shared/9x25fxhc.js +150 -0
  158. package/dist/shared/a5sxz52y.js +13 -0
  159. package/dist/shared/axhk06q1.js +156 -0
  160. package/dist/shared/{dynq16vb.js → b066g80h.js} +8 -6
  161. package/dist/shared/bqha5cg6.js +229 -0
  162. package/dist/shared/bryqk9k9.js +31 -0
  163. package/dist/shared/c8aghh05.js +442 -0
  164. package/dist/shared/c9z5g0fm.js +309 -0
  165. package/dist/shared/{m3ypagh5.js → dbjej1tw.js} +124 -15
  166. package/dist/shared/dyj86cmj.js +69 -0
  167. package/dist/shared/e6wg00wd.js +164 -0
  168. package/dist/shared/{hadrfb9h.js → edwqqryd.js} +17 -14
  169. package/dist/shared/{qk3hxfja.js → fptpmvxp.js} +5 -5
  170. package/dist/shared/fs0ex00p.js +76 -0
  171. package/dist/shared/{jjb7yht9.js → g4f5kcx9.js} +3 -3
  172. package/dist/shared/gjthds9j.js +48 -0
  173. package/dist/shared/hcmdtwgh.js +102 -0
  174. package/dist/shared/{g5fhqmwe.js → jkc6ws1p.js} +6 -56
  175. package/dist/shared/{yd1kzwn2.js → jns2wx4t.js} +55 -12
  176. package/dist/shared/k34e0xf2.js +450 -0
  177. package/dist/shared/k3ted12y.js +33 -0
  178. package/dist/shared/k7dwkhvq.js +31 -0
  179. package/dist/shared/{8b04d28c.js → kgnc8grt.js} +2 -2
  180. package/dist/shared/{hd293j9g.js → kyxb62mc.js} +14 -2
  181. package/dist/shared/m78s7898.js +376 -0
  182. package/dist/shared/m9tv7xn7.js +404 -0
  183. package/dist/shared/meck53jv.js +99 -0
  184. package/dist/shared/mt5wswjz.js +90 -0
  185. package/dist/shared/n0dgs0pb.js +75 -0
  186. package/dist/shared/n442h54c.js +14 -0
  187. package/dist/shared/n4jqhpqz.js +27 -0
  188. package/dist/shared/n7mcc1gk.js +132 -0
  189. package/dist/shared/ne02ng5c.js +68 -0
  190. package/dist/shared/{mkjmqjv4.js → nfzc5z0w.js} +2 -104
  191. package/dist/shared/nsva2a6b.js +42 -0
  192. package/dist/shared/p24x2334.js +195 -0
  193. package/dist/shared/qbxzvwwc.js +88 -0
  194. package/dist/shared/{w8samvk1.js → qybh48nd.js} +1 -1
  195. package/dist/shared/r6nwkxnt.js +86 -0
  196. package/dist/shared/{xy79j5hq.js → rrstp3kb.js} +25 -36
  197. package/dist/shared/rwmrejjz.js +26 -0
  198. package/dist/shared/{zhc5vmgf.js → s6gqfn5j.js} +2 -2
  199. package/dist/shared/{523ft3e8.js → scwxrpx2.js} +7 -5
  200. package/dist/shared/{j5cn2963.js → t4tbsy9h.js} +13 -64
  201. package/dist/shared/{y9m15dfv.js → t616ynfn.js} +544 -32
  202. package/dist/shared/{ngk8gj61.js → tbszx8mz.js} +15 -1
  203. package/dist/shared/th14ygv2.js +69 -0
  204. package/dist/shared/tmbdywx0.js +178 -0
  205. package/dist/shared/ty3v3hfk.js +64 -0
  206. package/dist/shared/wekze34d.js +246 -0
  207. package/dist/shared/x6wysh83.js +1132 -0
  208. package/dist/shared/{rgs0st28.js → xrfnq5k8.js} +237 -434
  209. package/dist/shared/{x5x59srr.js → xva8v7qk.js} +416 -83
  210. package/dist/shared/{dkn3y60a.js → xw1d69vd.js} +76 -112
  211. package/dist/shared/y005b761.js +112 -0
  212. package/dist/shared/ydaz1sv3.js +55 -0
  213. package/dist/shared/{p0cbr3g2.js → zwmqxb0g.js} +1 -1
  214. package/dist/tooling/cli.js +40 -12
  215. package/dist/tooling/migrate/apply.d.ts +16 -0
  216. package/dist/tooling/migrate/commands.d.ts +12 -1
  217. package/dist/tooling/migrate/config.d.ts +8 -0
  218. package/dist/tooling/migrate/doctor.d.ts +25 -0
  219. package/dist/tooling/migrate/drift.d.ts +19 -0
  220. package/dist/tooling/migrate/engine.d.ts +36 -0
  221. package/dist/tooling/migrate/ext.d.ts +17 -0
  222. package/dist/tooling/migrate/extensions.d.ts +51 -0
  223. package/dist/tooling/migrate/managed.d.ts +17 -0
  224. package/dist/tooling/migrate/plan.d.ts +14 -1
  225. package/dist/tooling/migrate/project.d.ts +25 -1
  226. package/dist/tooling/migrate/type-name.d.ts +19 -0
  227. package/package.json +61 -4
  228. package/dist/shared/gk7cs7sp.js +0 -566
@@ -2,9 +2,10 @@
2
2
  * Column builder shared by every Postgres type.
3
3
  *
4
4
  * Modifiers allocate a new builder when called. Importing this module does
5
- * not build a codec table. `.validate()` stays a slot for P26.
5
+ * not build a codec table. `.validate()` stores rules and does not run them.
6
6
  */
7
- import { type ReferentialAction } from "../../contracts/catalog/types.js";
7
+ import { type CatalogObject, type Namespace, type Provenance, type ReferentialAction } from "../../contracts/catalog/types.js";
8
+ import { type ClientFill } from "../../contracts/generator.js";
8
9
  /** Flags that decide the row, insert, and update shapes of one column. */
9
10
  export type ColumnFlags = {
10
11
  readonly nullable: boolean;
@@ -13,6 +14,8 @@ export type ColumnFlags = {
13
14
  readonly guarded: boolean;
14
15
  readonly hidden: boolean;
15
16
  readonly omitWrite: boolean;
17
+ /** Absent from update. Insert still follows {@link InsertKind}. */
18
+ readonly omitUpdate: boolean;
16
19
  };
17
20
  /** Flags for a required column with no default. */
18
21
  export type PlainFlags = {
@@ -22,8 +25,9 @@ export type PlainFlags = {
22
25
  readonly guarded: false;
23
26
  readonly hidden: false;
24
27
  readonly omitWrite: false;
28
+ readonly omitUpdate: false;
25
29
  };
26
- /** Flags for {@link id}. Insert and update omit it. */
30
+ /** Flags for {@link id} when the database fills the value. Insert and update omit it. */
27
31
  export type IdFlags = {
28
32
  readonly nullable: false;
29
33
  readonly hasDefault: true;
@@ -31,6 +35,21 @@ export type IdFlags = {
31
35
  readonly guarded: true;
32
36
  readonly hidden: false;
33
37
  readonly omitWrite: true;
38
+ readonly omitUpdate: true;
39
+ };
40
+ /**
41
+ * Flags for {@link id} with `default: "none"`.
42
+ *
43
+ * Insert requires the value. Update omits it.
44
+ */
45
+ export type IdSuppliedFlags = {
46
+ readonly nullable: false;
47
+ readonly hasDefault: false;
48
+ readonly generated: false;
49
+ readonly guarded: false;
50
+ readonly hidden: false;
51
+ readonly omitWrite: false;
52
+ readonly omitUpdate: true;
34
53
  };
35
54
  /** Flags for {@link identity}. The database fills the value. */
36
55
  export type IdentityFlags = {
@@ -40,6 +59,7 @@ export type IdentityFlags = {
40
59
  readonly guarded: false;
41
60
  readonly hidden: false;
42
61
  readonly omitWrite: true;
62
+ readonly omitUpdate: true;
43
63
  };
44
64
  /**
45
65
  * Turns one flag on.
@@ -58,6 +78,14 @@ export type FlagTrue<TFlags extends ColumnFlags, K extends keyof ColumnFlags> =
58
78
  export type WithGenerated<TFlags extends ColumnFlags> = {
59
79
  readonly [P in keyof TFlags]: P extends "generated" | "hasDefault" ? true : TFlags[P];
60
80
  };
81
+ /**
82
+ * Omits a column from update and leaves insert unchanged.
83
+ *
84
+ * @typeParam TFlags - Current flags
85
+ */
86
+ export type WithUpdateGuard<TFlags extends ColumnFlags> = {
87
+ readonly [P in keyof TFlags]: P extends "omitUpdate" ? true : TFlags[P];
88
+ };
61
89
  /** How a default expression is spelled in the catalog. */
62
90
  export type SqlForm = "raw" | "quote" | "json" | "jsonb" | "cast";
63
91
  /**
@@ -70,7 +98,14 @@ export type ReferenceModifier = {
70
98
  readonly table: string;
71
99
  readonly onDelete?: ReferentialAction;
72
100
  readonly onUpdate?: ReferentialAction;
101
+ /** Target columns. Several columns make a composite foreign key. */
73
102
  readonly columns?: readonly string[];
103
+ /**
104
+ * Other local columns in the foreign key, after this column.
105
+ *
106
+ * Set when the key is composite. Absent on a single-column reference.
107
+ */
108
+ readonly along?: readonly string[];
74
109
  };
75
110
  /**
76
111
  * Options for {@link ColumnBuilder.references}.
@@ -81,7 +116,7 @@ export type ReferenceOptions = {
81
116
  readonly columns?: readonly string[];
82
117
  };
83
118
  /**
84
- * Validation rules, stored when a later prompt adds `.validate()`.
119
+ * Validation rules stored on the column. Nothing here interprets them.
85
120
  */
86
121
  export type ValidateModifier = {
87
122
  readonly rules: readonly unknown[];
@@ -114,7 +149,7 @@ export type ColumnInsert<TFlags extends ColumnFlags, TValue> = InsertKind<TFlags
114
149
  * @typeParam TFlags - Column flags
115
150
  * @typeParam TValue - Scalar or array value
116
151
  */
117
- export type ColumnUpdate<TFlags extends ColumnFlags, TValue> = InsertKind<TFlags> extends "omit" ? never : TFlags["nullable"] extends true ? TValue | null | undefined : TValue | undefined;
152
+ export type ColumnUpdate<TFlags extends ColumnFlags, TValue> = TFlags["omitUpdate"] extends true ? never : InsertKind<TFlags> extends "omit" ? never : TFlags["nullable"] extends true ? TValue | null | undefined : TValue | undefined;
118
153
  /**
119
154
  * Row shape of a builder.
120
155
  *
@@ -141,6 +176,20 @@ export type ColumnState<TValue> = {
141
176
  readonly hasDefault: boolean;
142
177
  readonly defaultSql: string | undefined;
143
178
  readonly defaultValue: unknown;
179
+ /**
180
+ * Client generator. Absent from the catalog and its hash.
181
+ *
182
+ * The catalog output labels it `client`. Insert fills the column when the
183
+ * caller omits it.
184
+ */
185
+ readonly clientDefault: ClientFill | undefined;
186
+ /** Column collation. Omitted from the catalog when unset. */
187
+ readonly collation: string | undefined;
188
+ /**
189
+ * `implicit` is a bare `t.id()`. `schema({ defaults: { id } })` may replace
190
+ * it. `column` is a choice on that column and wins.
191
+ */
192
+ readonly idSource: "implicit" | "column" | undefined;
144
193
  readonly identity: {
145
194
  readonly always: boolean;
146
195
  } | undefined;
@@ -158,7 +207,10 @@ export type ColumnState<TValue> = {
158
207
  } | undefined;
159
208
  readonly guarded: boolean;
160
209
  readonly hidden: boolean;
210
+ /** Redacted in logs, errors, and `inspect()`. Not part of the catalog hash. */
211
+ readonly sensitive: boolean;
161
212
  readonly omitWrite: boolean;
213
+ readonly omitUpdate: boolean;
162
214
  readonly renamedFrom: string | undefined;
163
215
  readonly sqlName: string | undefined;
164
216
  readonly comment: string | undefined;
@@ -169,6 +221,7 @@ export type ColumnState<TValue> = {
169
221
  readonly domain: {
170
222
  readonly base: string;
171
223
  readonly check: string;
224
+ readonly emit?: (namespace: Namespace, provenance: Provenance, objects: CatalogObject[]) => void;
172
225
  } | undefined;
173
226
  readonly primaryKey: boolean;
174
227
  readonly typeLabel: string | undefined;
@@ -179,6 +232,11 @@ export type ColumnState<TValue> = {
179
232
  readonly decode: (wire: string) => TValue;
180
233
  readonly elementEncode: (value: unknown) => string;
181
234
  readonly elementDecode: (wire: string) => unknown;
235
+ /**
236
+ * Object kinds the codec takes as input, named by `Object.prototype.toString`
237
+ * (`"Array"`, `"Temporal.Instant"`). Absent when the codec takes only scalars.
238
+ */
239
+ readonly accepts: readonly string[] | undefined;
182
240
  };
183
241
  /** Fields a scalar builder sets. Flags are passed beside the codec. */
184
242
  export type OpenColumn<TValue> = {
@@ -189,10 +247,15 @@ export type OpenColumn<TValue> = {
189
247
  readonly guarded: boolean;
190
248
  readonly hidden: boolean;
191
249
  readonly omitWrite: boolean;
250
+ readonly omitUpdate?: boolean;
192
251
  readonly encode: (value: TValue) => string;
193
252
  readonly decode: (wire: string) => TValue;
253
+ readonly accepts?: readonly string[];
194
254
  readonly sqlForm: SqlForm;
195
255
  readonly defaultSql?: string;
256
+ readonly clientDefault?: ClientFill;
257
+ readonly collation?: string;
258
+ readonly idSource?: "implicit" | "column";
196
259
  readonly identity?: {
197
260
  readonly always: boolean;
198
261
  };
@@ -202,6 +265,7 @@ export type OpenColumn<TValue> = {
202
265
  readonly domain?: {
203
266
  readonly base: string;
204
267
  readonly check: string;
268
+ readonly emit?: (namespace: Namespace, provenance: Provenance, objects: CatalogObject[]) => void;
205
269
  };
206
270
  readonly primaryKey?: boolean;
207
271
  readonly typeLabel?: string;
@@ -248,12 +312,16 @@ export declare class ColumnBuilder<TValue, TFlags extends ColumnFlags> {
248
312
  */
249
313
  nullable(): ColumnBuilder<TValue, FlagTrue<TFlags, "nullable">>;
250
314
  /**
251
- * Stores a JavaScript default. The catalog receives its SQL spelling.
315
+ * Stores a literal database default, or a client generator.
316
+ *
317
+ * A literal is written into the catalog as SQL. A function is a client
318
+ * generator: insert fills the column when it is omitted, and the catalog
319
+ * stores no default. Pass `uuidv4`, `uuidv7`, `okid(...)`, or any function.
252
320
  *
253
- * @param value - Default value
321
+ * @param value - Literal default, or a function that returns one value
254
322
  * @returns The same column, with a default
255
323
  */
256
- default(value: TFlags["nullable"] extends true ? TValue | null : TValue): ColumnBuilder<TValue, FlagTrue<TFlags, "hasDefault">>;
324
+ default(value: (TFlags["nullable"] extends true ? TValue | null : TValue) | (() => TValue)): ColumnBuilder<TValue, FlagTrue<TFlags, "hasDefault">>;
257
325
  /**
258
326
  * Stores a SQL default expression as written.
259
327
  *
@@ -262,14 +330,26 @@ export declare class ColumnBuilder<TValue, TFlags extends ColumnFlags> {
262
330
  */
263
331
  defaultSql(expression: string): ColumnBuilder<TValue, FlagTrue<TFlags, "hasDefault">>;
264
332
  /**
265
- * Records a unique constraint. Tenancy later reads `global`.
333
+ * Makes this column the table's primary key.
334
+ *
335
+ * Insert still accepts the value. Update omits it. A composite key is the
336
+ * `primaryKey` option on `table()`, not a second call.
337
+ *
338
+ * @returns The same column, as a primary key
339
+ */
340
+ primaryKey(): ColumnBuilder<TValue, WithUpdateGuard<TFlags>>;
341
+ /**
342
+ * Records a unique constraint.
343
+ *
344
+ * On a tenant table the key is included, unless `global` names a reason.
345
+ * `global: "reason"` and `{ global: true, reason }` are the same opt-out.
266
346
  *
267
347
  * @param options - Exemption reason, and whether the unique ignores the tenant key
268
348
  * @returns The same column
269
349
  */
270
350
  unique(options?: {
271
351
  readonly reason?: string;
272
- readonly global?: boolean;
352
+ readonly global?: boolean | string;
273
353
  }): ColumnBuilder<TValue, TFlags>;
274
354
  /**
275
355
  * Narrows a string column to a literal union.
@@ -303,9 +383,33 @@ export declare class ColumnBuilder<TValue, TFlags extends ColumnFlags> {
303
383
  /**
304
384
  * Excludes the column from the default row.
305
385
  *
386
+ * A named `select` still returns it. Includes never do.
387
+ *
306
388
  * @returns The same column, hidden
307
389
  */
308
390
  hidden(): ColumnBuilder<TValue, FlagTrue<TFlags, "hidden">>;
391
+ /**
392
+ * Redacts the value in logs, errors, and `inspect()`.
393
+ *
394
+ * The stored value is unchanged. A read that selects the column still
395
+ * returns it. The catalog hash does not include this flag.
396
+ *
397
+ * @returns The same column, sensitive
398
+ */
399
+ sensitive(): ColumnBuilder<TValue, TFlags>;
400
+ /**
401
+ * Stores validation rules or one Standard Schema.
402
+ *
403
+ * The rules are stored. They run only when validation is enabled and the
404
+ * engine has loaded. A field listed here and in the table `validate`
405
+ * section is OKM1030, reported by `okm check`.
406
+ *
407
+ * @param rules - Rule list, or one Standard Schema
408
+ * @returns The same column, with the rules stored
409
+ */
410
+ validate(rules: readonly unknown[] | {
411
+ readonly "~standard": unknown;
412
+ }): ColumnBuilder<TValue, TFlags>;
309
413
  /**
310
414
  * Points this column at another table.
311
415
  *
@@ -384,3 +488,18 @@ export declare function formatType(baseType: string, dims: number): string;
384
488
  * @returns A default expression
385
489
  */
386
490
  export declare function sqlOf<TValue>(state: ColumnState<TValue>, value: TValue): string;
491
+ /**
492
+ * Returns a column with a cleared unique flag or a replaced reference.
493
+ *
494
+ * `okmodel/tenancy` uses this while rewriting tables. `schema()` then compiles
495
+ * the result with the ordinary unique and foreign-key paths.
496
+ *
497
+ * @param column - Column to copy
498
+ * @param patch - Unique or primary flag to drop, or the reference to store
499
+ * @returns A new column builder
500
+ */
501
+ export declare function retarget<TValue, TFlags extends ColumnFlags>(column: ColumnBuilder<TValue, TFlags>, patch: {
502
+ readonly dropUnique?: boolean;
503
+ readonly dropPrimary?: boolean;
504
+ readonly references?: ReferenceModifier;
505
+ }): ColumnBuilder<TValue, TFlags>;
@@ -12,6 +12,7 @@ export type CompilableColumn = {
12
12
  readonly dims: number;
13
13
  readonly nullable: boolean;
14
14
  readonly defaultSql: string | undefined;
15
+ readonly collation: string | undefined;
15
16
  readonly identity: {
16
17
  readonly always: boolean;
17
18
  } | undefined;
@@ -16,6 +16,12 @@ export declare function custom<TValue>(spec: {
16
16
  readonly sqlType: string;
17
17
  readonly encode: (value: TValue) => string;
18
18
  readonly decode: (wire: string) => TValue;
19
+ /**
20
+ * Object kinds the codec takes, as `Object.prototype.toString` names them: `"Object"`
21
+ * for a plain object, `"Array"`, `"Temporal.Instant"`. Omit it when `TValue` is a
22
+ * scalar: every object is then rejected (OKM1121).
23
+ */
24
+ readonly accepts?: readonly string[];
19
25
  readonly extension?: string;
20
26
  readonly sqlForm?: SqlForm;
21
27
  }): ColumnBuilder<TValue, PlainFlags>;
@@ -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, SequenceObject, TableObject } from "../../contracts/catalog/types.js";
7
+ import type { Catalog, CatalogObject, ColumnObject, FunctionObject, MaterializedViewObject, SequenceObject, TableObject, ViewObject } from "../../contracts/catalog/types.js";
8
8
  /**
9
9
  * Quotes one identifier.
10
10
  *
@@ -23,6 +23,15 @@ 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
+ * Reports whether an index belongs to a view or a materialized view.
28
+ *
29
+ * Those indexes are created after the view, not with the tables.
30
+ *
31
+ * @param object - Catalog object
32
+ * @returns `true` when an index edge points at a view
33
+ */
34
+ export declare function ownedByView(object: CatalogObject): boolean;
26
35
  /**
27
36
  * SQL that drops one object.
28
37
  *
@@ -42,6 +51,53 @@ export declare function dropObjectSql(object: CatalogObject, schema: string): st
42
51
  * @returns The statement
43
52
  */
44
53
  export declare function createObjectSql(object: CatalogObject, schema: string): string | undefined;
54
+ /**
55
+ * `CREATE` or `CREATE OR REPLACE` for one function.
56
+ *
57
+ * A compatible signature change uses replace. The body is the stored source,
58
+ * or the `BEGIN ATOMIC` block when the function is atomic.
59
+ *
60
+ * @param object - Function to render
61
+ * @param schema - Concrete schema name
62
+ * @param replace - `CREATE OR REPLACE` when true
63
+ * @returns The statement
64
+ */
65
+ export declare function functionSql(object: FunctionObject, schema: string, replace: boolean): string;
66
+ /**
67
+ * `CREATE` or `CREATE OR REPLACE` for one view.
68
+ *
69
+ * Appending columns is replace. The query is the stored text.
70
+ *
71
+ * @param object - View to render
72
+ * @param schema - Concrete schema name
73
+ * @param replace - `CREATE OR REPLACE` when true
74
+ * @returns The statement
75
+ */
76
+ export declare function viewSql(object: ViewObject, schema: string, replace: boolean): string;
77
+ /**
78
+ * `CREATE MATERIALIZED VIEW ... WITH NO DATA`.
79
+ *
80
+ * Populate is a separate planned step. This statement does not read the table.
81
+ *
82
+ * @param object - Materialized view to render
83
+ * @param schema - Concrete schema name
84
+ * @returns The statement
85
+ */
86
+ export declare function materializedViewSql(object: MaterializedViewObject, schema: string): string;
87
+ /**
88
+ * `REFRESH MATERIALIZED VIEW`.
89
+ *
90
+ * A view created `WITH NO DATA` is empty, and Postgres rejects `CONCURRENTLY`
91
+ * until it has been populated once. The plan's populate step passes
92
+ * `populated: false`. A later refresh uses `CONCURRENTLY` when the declaration
93
+ * asked for it.
94
+ *
95
+ * @param object - Materialized view to refresh
96
+ * @param schema - Concrete schema name
97
+ * @param populated - `true` when the view already holds rows
98
+ * @returns The statement
99
+ */
100
+ export declare function refreshMaterializedViewSql(object: MaterializedViewObject, schema: string, populated?: boolean): string;
45
101
  /**
46
102
  * In-place column changes: type, nullability, and default.
47
103
  *
@@ -68,3 +124,11 @@ export declare function identitySequence(sequence: SequenceObject, source: Catal
68
124
  * @returns The statement
69
125
  */
70
126
  export declare function createTableSql(tableObject: TableObject, source: Catalog, schema: string): string;
127
+ /**
128
+ * Quotes a schema-qualified name.
129
+ *
130
+ * @param schema - Concrete schema name
131
+ * @param name - Object name
132
+ * @returns `"schema"."name"`
133
+ */
134
+ export declare function qualify(schema: string, name: string): string;
@@ -2,7 +2,7 @@
2
2
  * Enum and domain columns.
3
3
  *
4
4
  * The catalog column type is the type name. Compile records a dependency on
5
- * the enum, and `schema()` stores that enum as a catalog type.
5
+ * the type, and the column's `emit` adds that type when the catalog is built.
6
6
  */
7
7
  import { type ColumnBuilder, type ColumnFlags, type PlainFlags } from "./column.js";
8
8
  /**
@@ -17,14 +17,16 @@ import { type ColumnBuilder, type ColumnFlags, type PlainFlags } from "./column.
17
17
  */
18
18
  export declare function enumColumn<const TValues extends readonly string[]>(name: string, values: TValues): ColumnBuilder<TValues[number], PlainFlags>;
19
19
  /**
20
- * A named domain over a scalar column.
20
+ * A named domain over a column type.
21
21
  *
22
- * Domains are not catalog objects in this version. Calling the builder fails
23
- * with OKM1061 until 0.3, when a domain becomes a `type` subkind (D141).
22
+ * The TypeScript row type and the codec are the base column's. The catalog
23
+ * column type is the domain name, and the domain is a `type` object (D141).
24
+ * An enum base is OKM1060. Changing the base type of an existing domain is
25
+ * OKM1020 when the plan is built.
24
26
  *
25
27
  * @param name - Domain name
26
- * @param base - Scalar column the domain is based on
27
- * @param check - Domain check expression
28
- * @returns A domain column with the base codec, once 0.3 supports it
28
+ * @param base - Column the domain is based on
29
+ * @param check - Domain check expression, stored as written
30
+ * @returns A domain column
29
31
  */
30
- export declare function domain<TValue, TFlags extends ColumnFlags>(_name: string, _base: ColumnBuilder<TValue, TFlags>, _check: string): ColumnBuilder<TValue, PlainFlags>;
32
+ export declare function domain<TValue, TFlags extends ColumnFlags>(name: string, base: ColumnBuilder<TValue, TFlags>, check: string): ColumnBuilder<TValue, TFlags>;
@@ -0,0 +1,14 @@
1
+ /**
2
+ * The `citext` extension.
3
+ *
4
+ * Case-insensitive equality is the column's ordinary `eq` once the type is
5
+ * `citext`. This module declares the extension so that column can build.
6
+ */
7
+ import { type Extension, type ExtensionOptions } from "./index.js";
8
+ /**
9
+ * Declares `citext`.
10
+ *
11
+ * @param options - Schema and version pin. The version differs by Postgres major, so the default is unpinned.
12
+ * @returns The extension object
13
+ */
14
+ export declare function citext(options?: ExtensionOptions): Extension;
@@ -0,0 +1,11 @@
1
+ import {
2
+ extension2
3
+ } from "../../../shared/7fvtrkwr.js";
4
+
5
+ // src/dialects/pg/ext/citext.ts
6
+ function citext(options = {}) {
7
+ return extension2("citext", options);
8
+ }
9
+ export {
10
+ citext
11
+ };
@@ -0,0 +1,52 @@
1
+ /**
2
+ * `okmodel/ext`.
3
+ *
4
+ * `extension()` returns an object that produces its own catalog record.
5
+ * Duplicate and undeclared-use checks run here. Core only asks each declared
6
+ * object for its records.
7
+ */
8
+ import type { ExtensionObject } from "../../../contracts/catalog/types.js";
9
+ /** Options on {@link extension}. */
10
+ export type ExtensionOptions = {
11
+ /** Exact pin (`1.6`) or a floor (`>=0.7`). Omitted means unpinned. */
12
+ readonly version?: string;
13
+ /** Install schema. The default is `public`. */
14
+ readonly schema?: string;
15
+ /**
16
+ * Whether the extension may move.
17
+ *
18
+ * The default is `true`. A move of a non-relocatable extension is OKM1814.
19
+ */
20
+ readonly relocatable?: boolean;
21
+ };
22
+ /**
23
+ * One declared extension.
24
+ *
25
+ * Methods on a built-in, such as `pgTrgm.similar`, are the typed API. They
26
+ * are not stored in the catalog record.
27
+ */
28
+ export type Extension = {
29
+ readonly name: string;
30
+ readonly schema: string;
31
+ readonly relocatable: boolean;
32
+ readonly version?: string;
33
+ /**
34
+ * Catalog records for this declaration.
35
+ *
36
+ * @param peers - The `schema({ extensions })` list
37
+ * @param built - Objects the schema has already staged
38
+ * @returns The extension record
39
+ */
40
+ contribute(peers: unknown, built: unknown): readonly ExtensionObject[];
41
+ };
42
+ /**
43
+ * Declares an extension by name.
44
+ *
45
+ * A bare declaration has the full lifecycle and no typed operators. Built-ins
46
+ * wrap this and add their own methods.
47
+ *
48
+ * @param name - Extension name, such as `citext` or `vector`
49
+ * @param options - Schema, version pin, and whether it may move
50
+ * @returns The definition object `schema({ extensions })` stores
51
+ */
52
+ export declare function extension(name: string, options?: ExtensionOptions): Extension;
@@ -0,0 +1,6 @@
1
+ import {
2
+ extension2
3
+ } from "../../../shared/7fvtrkwr.js";
4
+ export {
5
+ extension2 as extension
6
+ };
@@ -0,0 +1,53 @@
1
+ /**
2
+ * The `pg_trgm` extension.
3
+ *
4
+ * `similar` and `wordSimilar` are where-operators. Their SQL lives in the
5
+ * lazy operator module. Index methods set the catalog `expression` to a
6
+ * `using …` tail; the core index factory does not grow a `using` field.
7
+ */
8
+ import { type Tagged } from "../operators.js";
9
+ import type { IndexCall } from "../table.js";
10
+ import { type Extension, type ExtensionOptions } from "./index.js";
11
+ /** Operand stored on a trigram operator. */
12
+ export type TrigramQuery = {
13
+ readonly query: string;
14
+ readonly schema: string;
15
+ };
16
+ /** `pg_trgm` plus its operators and index methods. */
17
+ export type PgTrgm = Extension & {
18
+ /**
19
+ * `column % query`.
20
+ *
21
+ * @param query - The text to compare
22
+ * @returns A tagged where-operator
23
+ */
24
+ similar(query: string): Tagged<"similar", TrigramQuery>;
25
+ /**
26
+ * `column <% query`.
27
+ *
28
+ * @param query - The text to compare
29
+ * @returns A tagged where-operator
30
+ */
31
+ wordSimilar(query: string): Tagged<"wordSimilar", TrigramQuery>;
32
+ /**
33
+ * A GIN index with `gin_trgm_ops`.
34
+ *
35
+ * @param column - SQL column name
36
+ * @returns An index call whose expression is the `using` tail
37
+ */
38
+ gin(column: string): IndexCall;
39
+ /**
40
+ * A GiST index with `gist_trgm_ops`.
41
+ *
42
+ * @param column - SQL column name
43
+ * @returns An index call whose expression is the `using` tail
44
+ */
45
+ gist(column: string): IndexCall;
46
+ };
47
+ /**
48
+ * Declares `pg_trgm`.
49
+ *
50
+ * @param options - Schema and version pin
51
+ * @returns The extension object and its operators
52
+ */
53
+ export declare function pgTrgm(options?: ExtensionOptions): PgTrgm;
@@ -0,0 +1,42 @@
1
+ import {
2
+ extension2
3
+ } from "../../../shared/7fvtrkwr.js";
4
+ import {
5
+ tag
6
+ } from "../../../shared/cn0n68ft.js";
7
+
8
+ // src/dialects/pg/ext/pg-trgm.ts
9
+ function pgTrgm(options = {}) {
10
+ const declared = extension2("pg_trgm", options);
11
+ const schema = declared.schema;
12
+ return {
13
+ ...declared,
14
+ similar(query) {
15
+ return tag("similar", { query, schema });
16
+ },
17
+ wordSimilar(query) {
18
+ return tag("wordSimilar", { query, schema });
19
+ },
20
+ gin(column) {
21
+ return usingIndex(column, "gin", "gin_trgm_ops");
22
+ },
23
+ gist(column) {
24
+ return usingIndex(column, "gist", "gist_trgm_ops");
25
+ }
26
+ };
27
+ }
28
+ function usingIndex(column, method, opclass) {
29
+ const quoted = `"${column.replaceAll('"', '""')}"`;
30
+ const call = {
31
+ columns: [column],
32
+ isUnique: false,
33
+ expression: `using ${method} (${quoted} ${opclass})`,
34
+ unique() {
35
+ return call;
36
+ }
37
+ };
38
+ return call;
39
+ }
40
+ export {
41
+ pgTrgm
42
+ };
@@ -0,0 +1,19 @@
1
+ /**
2
+ * Turns an allowlisted request object into `where` and `orderBy`.
3
+ *
4
+ * Loaded the first time `parse()` is called. `filters()` validates the spec
5
+ * before this module exists.
6
+ */
7
+ import type { ParsedFilters } from "./table.js";
8
+ /**
9
+ * Reads one request object.
10
+ *
11
+ * A plain value is equality when `eq` is allowlisted. `sort` is a field name
12
+ * from the sort list. JSON cannot add an operator.
13
+ *
14
+ * @param allow - Fields and the operators each one accepts
15
+ * @param sort - Fields a caller may sort by
16
+ * @param query - One request object
17
+ * @returns Filters a caller can spread into `find`
18
+ */
19
+ export declare function parseQuery(allow: Readonly<Record<string, readonly string[]>>, sort: readonly string[], query: unknown): ParsedFilters;
@@ -0,0 +1,19 @@
1
+ /**
2
+ * Allowlisted filters. The checks run when `filters()` is called.
3
+ *
4
+ * A hidden field in `allow`, `sort`, or `relations` is OKM1123. The parser
5
+ * loads on the first `parse()`.
6
+ */
7
+ import type { FilterSpec, ParsedFilters } from "./table.js";
8
+ /**
9
+ * Checks an allowlist and returns `parse`.
10
+ *
11
+ * @param table - Table the filters belong to
12
+ * @param relations - Relation calls stored on the table, when it has any
13
+ * @param spec - Allow, sort, and relation fields
14
+ * @param hiddenFields - `table.field` keys recorded while tables were defined
15
+ * @returns A parser for one request object
16
+ */
17
+ export declare function openFilters(table: string, relations: unknown, spec: FilterSpec, hiddenFields: ReadonlySet<string>): {
18
+ parse(query: unknown): Promise<ParsedFilters>;
19
+ };