okmodel 0.1.1 → 0.2.1

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 (181) hide show
  1. package/README.md +32 -16
  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/object.d.ts +1 -0
  13. package/dist/contracts/catalog/types.d.ts +15 -8
  14. package/dist/contracts/connection.d.ts +13 -0
  15. package/dist/contracts/driver.d.ts +18 -5
  16. package/dist/contracts/error.d.ts +17 -1
  17. package/dist/contracts/generator.d.ts +63 -0
  18. package/dist/contracts/index.d.ts +2 -2
  19. package/dist/contracts/index.js +1 -1
  20. package/dist/contracts/internal.js +11 -9
  21. package/dist/contracts/location.d.ts +24 -0
  22. package/dist/contracts/rows.d.ts +15 -0
  23. package/dist/dialects/pg/archive-bind.d.ts +22 -0
  24. package/dist/dialects/pg/column.d.ts +126 -9
  25. package/dist/dialects/pg/compile.d.ts +1 -0
  26. package/dist/dialects/pg/custom.d.ts +6 -0
  27. package/dist/dialects/pg/filter-parse.d.ts +19 -0
  28. package/dist/dialects/pg/filters.d.ts +19 -0
  29. package/dist/dialects/pg/index.d.ts +11 -2
  30. package/dist/dialects/pg/index.js +159 -1063
  31. package/dist/dialects/pg/keys.d.ts +19 -3
  32. package/dist/dialects/pg/model.d.ts +223 -2
  33. package/dist/dialects/pg/operator-fit.d.ts +86 -0
  34. package/dist/dialects/pg/operators.d.ts +39 -1
  35. package/dist/dialects/pg/ops/arr-append.d.ts +9 -0
  36. package/dist/dialects/pg/ops/arr-ns.d.ts +7 -0
  37. package/dist/dialects/pg/ops/arr-remove.d.ts +9 -0
  38. package/dist/dialects/pg/ops/containedBy.d.ts +9 -0
  39. package/dist/dialects/pg/ops/contains.d.ts +8 -4
  40. package/dist/dialects/pg/ops/hasAnyKey.d.ts +8 -0
  41. package/dist/dialects/pg/ops/hasKey.d.ts +8 -0
  42. package/dist/dialects/pg/ops/json-ns.d.ts +6 -0
  43. package/dist/dialects/pg/ops/json-set.d.ts +12 -0
  44. package/dist/dialects/pg/ops/matches.d.ts +16 -0
  45. package/dist/dialects/pg/ops/overlaps.d.ts +9 -0
  46. package/dist/dialects/pg/ops/path.d.ts +13 -0
  47. package/dist/dialects/pg/preset.d.ts +76 -0
  48. package/dist/dialects/pg/relations.d.ts +59 -2
  49. package/dist/dialects/pg/schema.d.ts +109 -5
  50. package/dist/dialects/pg/table.d.ts +130 -11
  51. package/dist/dialects/pg/temporal.d.ts +9 -7
  52. package/dist/dialects/pg/tenancy.d.ts +94 -0
  53. package/dist/dialects/pg/through.d.ts +21 -0
  54. package/dist/dialects/pg/trait.d.ts +141 -0
  55. package/dist/dialects/pg/where.d.ts +37 -0
  56. package/dist/runtime/aggregate.d.ts +25 -0
  57. package/dist/runtime/archive-handle.d.ts +18 -0
  58. package/dist/runtime/archive-rules.d.ts +12 -0
  59. package/dist/runtime/archive.d.ts +73 -0
  60. package/dist/runtime/batch.d.ts +20 -0
  61. package/dist/runtime/client.d.ts +114 -5
  62. package/dist/runtime/conflict.d.ts +2 -1
  63. package/dist/runtime/exposure.d.ts +27 -0
  64. package/dist/runtime/hookm.d.ts +39 -0
  65. package/dist/runtime/ids/index.d.ts +11 -0
  66. package/dist/runtime/ids/index.js +193 -0
  67. package/dist/runtime/ids/okid-extended.d.ts +19 -0
  68. package/dist/runtime/ids/okid-generator.d.ts +21 -0
  69. package/dist/runtime/ids/okid-shared.d.ts +89 -0
  70. package/dist/runtime/ids/okid.d.ts +24 -0
  71. package/dist/runtime/ids/uuid.d.ts +21 -0
  72. package/dist/runtime/lock.d.ts +22 -0
  73. package/dist/runtime/operator-sql.d.ts +8 -0
  74. package/dist/runtime/page.d.ts +25 -0
  75. package/dist/runtime/pg/bun.d.ts +30 -0
  76. package/dist/runtime/pg/bun.js +52 -0
  77. package/dist/runtime/pg/pg.d.ts +29 -0
  78. package/dist/runtime/pg/pg.js +52 -0
  79. package/dist/runtime/pg/pglite.js +16 -17
  80. package/dist/runtime/pg/postgresjs.js +14 -24
  81. package/dist/runtime/plan.d.ts +146 -7
  82. package/dist/runtime/preset-stack.d.ts +17 -0
  83. package/dist/runtime/presets.d.ts +48 -0
  84. package/dist/runtime/read-stream.d.ts +26 -0
  85. package/dist/runtime/safety/index.d.ts +159 -0
  86. package/dist/runtime/safety/index.js +294 -0
  87. package/dist/runtime/safety-hook.d.ts +42 -0
  88. package/dist/runtime/server-check.d.ts +34 -0
  89. package/dist/runtime/tenancy/index.d.ts +37 -0
  90. package/dist/runtime/tenancy/index.js +365 -0
  91. package/dist/runtime/trait-read.d.ts +30 -0
  92. package/dist/runtime/traits/index.d.ts +128 -0
  93. package/dist/runtime/traits/index.js +509 -0
  94. package/dist/runtime/transaction.d.ts +19 -0
  95. package/dist/runtime/tx.d.ts +22 -7
  96. package/dist/runtime/types.d.ts +376 -27
  97. package/dist/runtime/validate/bind.d.ts +11 -0
  98. package/dist/runtime/validate/closed.d.ts +16 -0
  99. package/dist/runtime/validate/engine.d.ts +41 -0
  100. package/dist/runtime/validate/hook.d.ts +17 -0
  101. package/dist/runtime/validate/index.d.ts +21 -0
  102. package/dist/runtime/validate/index.js +175 -0
  103. package/dist/runtime/validate/load.d.ts +13 -0
  104. package/dist/runtime/validate/places.d.ts +41 -0
  105. package/dist/runtime/validate/rules.d.ts +108 -0
  106. package/dist/runtime/validate/surface.d.ts +102 -0
  107. package/dist/runtime/write.d.ts +30 -5
  108. package/dist/shared/{fgqgsb5z.js → 0qkxbm1f.js} +2 -2
  109. package/dist/shared/0v1g424p.js +26 -0
  110. package/dist/shared/10tjenmd.js +210 -0
  111. package/dist/shared/{xqbhg6cn.js → 1dp5knt7.js} +95 -10
  112. package/dist/shared/38crxbgn.js +229 -0
  113. package/dist/shared/3a5ne750.js +158 -0
  114. package/dist/shared/4b9da9d7.js +138 -0
  115. package/dist/shared/4e4c6vq2.js +62 -0
  116. package/dist/shared/{x5x59srr.js → 4jzzghr6.js} +416 -83
  117. package/dist/shared/{ycwz42az.js → 52szzakm.js} +6 -26
  118. package/dist/shared/{05w44d8g.js → 5z4q2zda.js} +567 -18
  119. package/dist/shared/672t5vym.js +12 -0
  120. package/dist/shared/7m88x3e9.js +45 -0
  121. package/dist/shared/7mht49yd.js +1091 -0
  122. package/dist/shared/{mtkwv8wx.js → 7p2wbz7f.js} +1 -1
  123. package/dist/shared/83eaefwr.js +10 -0
  124. package/dist/shared/96ps4g1z.js +32 -0
  125. package/dist/shared/97g2jnrw.js +76 -0
  126. package/dist/shared/{xy79j5hq.js → 9k6vetvf.js} +25 -36
  127. package/dist/shared/{w8samvk1.js → a1gdp7j9.js} +1 -1
  128. package/dist/shared/a5sxz52y.js +13 -0
  129. package/dist/shared/{dynq16vb.js → b066g80h.js} +8 -6
  130. package/dist/shared/cstgkzdx.js +154 -0
  131. package/dist/shared/{523ft3e8.js → d04j53v8.js} +6 -5
  132. package/dist/shared/{y9m15dfv.js → d2whjz4k.js} +15 -9
  133. package/dist/shared/dd4f8mnx.js +307 -0
  134. package/dist/shared/e6wg00wd.js +164 -0
  135. package/dist/shared/e7a268fy.js +195 -0
  136. package/dist/shared/{kprcwaha.js → eaxwrgby.js} +4 -3
  137. package/dist/shared/{dkn3y60a.js → ecdzej21.js} +76 -112
  138. package/dist/shared/{hadrfb9h.js → edwqqryd.js} +17 -14
  139. package/dist/shared/{m3ypagh5.js → eqmtn1bj.js} +57 -5
  140. package/dist/shared/g1b5zzj9.js +75 -0
  141. package/dist/shared/g9f0zqce.js +376 -0
  142. package/dist/shared/ge03bfca.js +64 -0
  143. package/dist/shared/{yd1kzwn2.js → jns2wx4t.js} +55 -12
  144. package/dist/shared/k3ted12y.js +33 -0
  145. package/dist/shared/k7dwkhvq.js +31 -0
  146. package/dist/shared/{hd293j9g.js → kyxb62mc.js} +14 -2
  147. package/dist/shared/m9tv7xn7.js +404 -0
  148. package/dist/shared/mrq77sgw.js +55 -0
  149. package/dist/shared/mxmcdsh5.js +450 -0
  150. package/dist/shared/n442h54c.js +14 -0
  151. package/dist/shared/n47rd821.js +442 -0
  152. package/dist/shared/n4jqhpqz.js +27 -0
  153. package/dist/shared/{mkjmqjv4.js → nfzc5z0w.js} +2 -104
  154. package/dist/shared/nsva2a6b.js +42 -0
  155. package/dist/shared/ps43134h.js +69 -0
  156. package/dist/shared/{8b04d28c.js → py3nh7jy.js} +2 -2
  157. package/dist/shared/qa5dsc7z.js +86 -0
  158. package/dist/shared/{g5fhqmwe.js → qxa0yb9j.js} +6 -4
  159. package/dist/shared/r6nwkxnt.js +86 -0
  160. package/dist/shared/{jjb7yht9.js → rtnaqre0.js} +3 -3
  161. package/dist/shared/rwmrejjz.js +26 -0
  162. package/dist/shared/{zhc5vmgf.js → s6gqfn5j.js} +2 -2
  163. package/dist/shared/sacqha1y.js +70 -0
  164. package/dist/shared/{qk3hxfja.js → sfh4pk75.js} +5 -5
  165. package/dist/shared/{j5cn2963.js → t4tbsy9h.js} +13 -64
  166. package/dist/shared/{ngk8gj61.js → tbszx8mz.js} +15 -1
  167. package/dist/shared/v18jva5b.js +90 -0
  168. package/dist/shared/x9v1qgeb.js +201 -0
  169. package/dist/shared/xatfg0gn.js +193 -0
  170. package/dist/shared/xkz8g6by.js +225 -0
  171. package/dist/shared/{rgs0st28.js → xrfnq5k8.js} +237 -434
  172. package/dist/shared/ytg3xf9p.js +149 -0
  173. package/dist/shared/yw5c610b.js +48 -0
  174. package/dist/shared/zd93g3rq.js +31 -0
  175. package/dist/shared/zt8y0wzb.js +132 -0
  176. package/dist/shared/{p0cbr3g2.js → zwmqxb0g.js} +1 -1
  177. package/dist/tooling/cli.js +14 -10
  178. package/dist/tooling/migrate/commands.d.ts +10 -0
  179. package/dist/tooling/migrate/engine.d.ts +36 -0
  180. package/package.json +41 -4
  181. package/dist/shared/gk7cs7sp.js +0 -566
@@ -0,0 +1,193 @@
1
+ import {
2
+ clientGenerator
3
+ } from "../../shared/rwmrejjz.js";
4
+
5
+ // src/runtime/ids/uuid.ts
6
+ var HEX = "0123456789abcdef";
7
+ var uuidv4 = clientGenerator(() => crypto.randomUUID(), "uuidv4");
8
+ var uuidv7 = clientGenerator(mintUuidV7, "uuidv7");
9
+ function mintUuidV7() {
10
+ const bytes = new Uint8Array(16);
11
+ crypto.getRandomValues(bytes);
12
+ const now = Date.now();
13
+ bytes[0] = Math.floor(now / 2 ** 40) & 255;
14
+ bytes[1] = Math.floor(now / 2 ** 32) & 255;
15
+ bytes[2] = Math.floor(now / 2 ** 24) & 255;
16
+ bytes[3] = Math.floor(now / 2 ** 16) & 255;
17
+ bytes[4] = Math.floor(now / 2 ** 8) & 255;
18
+ bytes[5] = now & 255;
19
+ const sixth = bytes[6] ?? 0;
20
+ const eighth = bytes[8] ?? 0;
21
+ bytes[6] = sixth & 15 | 112;
22
+ bytes[8] = eighth & 63 | 128;
23
+ return formatUuid(bytes);
24
+ }
25
+ function formatUuid(bytes) {
26
+ let out = "";
27
+ for (let index = 0;index < 16; index += 1) {
28
+ if (index === 4 || index === 6 || index === 8 || index === 10)
29
+ out += "-";
30
+ const byte = bytes[index] ?? 0;
31
+ out += HEX[byte >> 4];
32
+ out += HEX[byte & 15];
33
+ }
34
+ return out;
35
+ }
36
+ // src/runtime/ids/okid-shared.ts
37
+ var OKID_DEFAULT_CHARS = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ-_";
38
+ var OKID_LOOKALIKE_CHARS = "1lI0Oouv5Ss";
39
+ var OKID_ALPHABET = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_";
40
+ var OKID_SORTABLE_ALPHABET = "-0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz";
41
+ var OKID_DEFAULT_LENGTH = 21;
42
+ var OKID_MIN_LENGTH = 8;
43
+ var OKID_MAX_LENGTH = 128;
44
+ var OKID_SORTABLE_MIN_LENGTH = 16;
45
+ var OKID_MAX_PREFIX_LENGTH = 32;
46
+ function assertLength(length, min, label) {
47
+ if (!Number.isInteger(length)) {
48
+ throw new RangeError(`okid: ${label} must be an integer, got ${length}`);
49
+ }
50
+ if (length < min || length > OKID_MAX_LENGTH) {
51
+ throw new RangeError(`okid: ${label} ${length} is out of range [${min}, ${OKID_MAX_LENGTH}]`);
52
+ }
53
+ }
54
+
55
+ // src/runtime/ids/okid-extended.ts
56
+ var GROUPS = {
57
+ numbers: "0123456789",
58
+ lowercase: "abcdefghijklmnopqrstuvwxyz",
59
+ uppercase: "ABCDEFGHIJKLMNOPQRSTUVWXYZ",
60
+ symbols: "-_"
61
+ };
62
+ var ALPHABET_CACHE = new Map;
63
+ function resolveAlphabet(numbers, lowercase, uppercase, symbols, lookAlikes) {
64
+ const key = (numbers ? 1 : 0) | (lowercase ? 2 : 0) | (uppercase ? 4 : 0) | (symbols ? 8 : 0) | (lookAlikes ? 0 : 16);
65
+ const cached = ALPHABET_CACHE.get(key);
66
+ if (cached)
67
+ return cached;
68
+ let chars = "";
69
+ if (numbers)
70
+ chars += GROUPS.numbers;
71
+ if (lowercase)
72
+ chars += GROUPS.lowercase;
73
+ if (uppercase)
74
+ chars += GROUPS.uppercase;
75
+ if (symbols)
76
+ chars += GROUPS.symbols;
77
+ if (!chars) {
78
+ throw new RangeError("okid: alphabet is empty — enable at least one character group");
79
+ }
80
+ if (!lookAlikes) {
81
+ chars = [...chars].filter((c) => !OKID_LOOKALIKE_CHARS.includes(c)).join("");
82
+ }
83
+ const rawSize = chars.length;
84
+ const size = 1 << Math.ceil(Math.log2(rawSize));
85
+ const resolved = { chars, size: rawSize, mask: size - 1 };
86
+ ALPHABET_CACHE.set(key, resolved);
87
+ return resolved;
88
+ }
89
+ function encodeAlphabet(alphabet, length) {
90
+ const { chars, size, mask } = alphabet;
91
+ const bytes = new Uint8Array(length + Math.ceil(length >> 2));
92
+ crypto.getRandomValues(bytes.subarray(0, length));
93
+ let out = "";
94
+ let i = 0;
95
+ while (out.length < length && i < bytes.length) {
96
+ const byte = bytes[i++];
97
+ if ((byte & mask) < size)
98
+ out += chars[byte & mask];
99
+ }
100
+ return out;
101
+ }
102
+ function encodeTimestamp(nowMs) {
103
+ let t = nowMs % 2 ** 48;
104
+ let out = "";
105
+ for (let i = 0;i < 8; i++) {
106
+ out = OKID_SORTABLE_ALPHABET[t & 63] + out;
107
+ t = Math.floor(t / 64);
108
+ }
109
+ return out;
110
+ }
111
+ function assertPrefix(prefix) {
112
+ if (prefix.length > OKID_MAX_PREFIX_LENGTH) {
113
+ throw new RangeError(`okid: prefix length ${prefix.length} exceeds max ${OKID_MAX_PREFIX_LENGTH}`);
114
+ }
115
+ for (const char of prefix) {
116
+ if (!OKID_ALPHABET.includes(char)) {
117
+ throw new RangeError(`okid: prefix contains invalid character ${JSON.stringify(char)} — use characters from OKID_ALPHABET`);
118
+ }
119
+ }
120
+ }
121
+ function okidWithOptions(options) {
122
+ const {
123
+ length = OKID_DEFAULT_LENGTH,
124
+ prefix = "",
125
+ sortable = false,
126
+ lowercase = true,
127
+ uppercase = true,
128
+ numbers = true,
129
+ symbols = true,
130
+ lookAlikes = true
131
+ } = options;
132
+ if (prefix)
133
+ assertPrefix(prefix);
134
+ let body;
135
+ if (sortable) {
136
+ assertLength(length, OKID_SORTABLE_MIN_LENGTH, "length");
137
+ const alphabet = resolveAlphabet(true, true, true, true, true);
138
+ body = encodeTimestamp(Date.now()) + encodeAlphabet(alphabet, length - 8);
139
+ } else {
140
+ assertLength(length, OKID_MIN_LENGTH, "length");
141
+ body = encodeAlphabet(resolveAlphabet(numbers, lowercase, uppercase, symbols, lookAlikes), length);
142
+ }
143
+ return prefix ? prefix + body : body;
144
+ }
145
+
146
+ // src/runtime/ids/okid.ts
147
+ function okid(options = OKID_DEFAULT_LENGTH) {
148
+ if (typeof options === "number") {
149
+ assertLength(options, OKID_MIN_LENGTH, "length");
150
+ const bytes = new Uint8Array(options);
151
+ crypto.getRandomValues(bytes);
152
+ let out = "";
153
+ for (let i = 0;i < options; i++)
154
+ out += OKID_DEFAULT_CHARS[bytes[i] & 63];
155
+ return out;
156
+ }
157
+ return okidWithOptions(options);
158
+ }
159
+
160
+ // src/runtime/ids/okid-generator.ts
161
+ function okid2(options) {
162
+ const stored = optionsRecord(options);
163
+ return clientGenerator(() => options === undefined ? okid() : okid(options), "okid", stored);
164
+ }
165
+ function optionsRecord(options) {
166
+ if (options === undefined)
167
+ return;
168
+ if (typeof options === "number")
169
+ return { length: options };
170
+ const stored = {};
171
+ if (options.length !== undefined)
172
+ stored.length = options.length;
173
+ if (options.prefix !== undefined)
174
+ stored.prefix = options.prefix;
175
+ if (options.sortable !== undefined)
176
+ stored.sortable = options.sortable;
177
+ if (options.lowercase !== undefined)
178
+ stored.lowercase = options.lowercase;
179
+ if (options.uppercase !== undefined)
180
+ stored.uppercase = options.uppercase;
181
+ if (options.numbers !== undefined)
182
+ stored.numbers = options.numbers;
183
+ if (options.symbols !== undefined)
184
+ stored.symbols = options.symbols;
185
+ if (options.lookAlikes !== undefined)
186
+ stored.lookAlikes = options.lookAlikes;
187
+ return stored;
188
+ }
189
+ export {
190
+ okid2 as okid,
191
+ uuidv4,
192
+ uuidv7
193
+ };
@@ -0,0 +1,19 @@
1
+ /**
2
+ * Vendored from okengine `src/okid-extended.ts` (Apache-2.0).
3
+ *
4
+ * okengine stays the source of truth. `bun run okid-drift` fails when this
5
+ * copy or the sibling okengine files leave the recorded hashes. Imports use
6
+ * the `.js` specifier this package resolves.
7
+ */
8
+ /**
9
+ * `okid({ … })` options path — sortable, prefix, and alphabet toggles.
10
+ *
11
+ * Kept off the kernel edge profile. `okid()` and `okid(length)` never load it.
12
+ */
13
+ import { type OkidOptions } from "./okid-shared.js";
14
+ /**
15
+ * Generate an id from an options object.
16
+ *
17
+ * @param options - Length, prefix, sortable, and alphabet toggles
18
+ */
19
+ export declare function okidWithOptions(options: OkidOptions): string;
@@ -0,0 +1,21 @@
1
+ /**
2
+ * OKID as a client generator.
3
+ *
4
+ * Calling {@link okid} does not mint an id. It returns a function that mints
5
+ * one id per call, so `.default(okid({ prefix }))` fills each inserted row.
6
+ * The vendored {@link mintOkid} is what that function calls.
7
+ */
8
+ import { type ClientGenerator } from "../../contracts/generator.js";
9
+ import { type OkidOptions } from "./okid.js";
10
+ export type { OkidOptions } from "./okid.js";
11
+ /**
12
+ * Binds OKID options into a client generator.
13
+ *
14
+ * `okid()` and `okid(length)` use the default alphabet. `okid({ prefix,
15
+ * sortable, length })` keeps those options for every row. Sortable ids embed
16
+ * the creation time. An OKID column is `text` with collation `C`.
17
+ *
18
+ * @param options - Body length, or prefix, sortable, and alphabet toggles
19
+ * @returns A generator. Call it to mint one id
20
+ */
21
+ export declare function okid(options?: number | OkidOptions): ClientGenerator<string>;
@@ -0,0 +1,89 @@
1
+ /**
2
+ * Vendored from okengine `src/okid-shared.ts` (Apache-2.0).
3
+ *
4
+ * okengine stays the source of truth. `bun run okid-drift` fails when this
5
+ * copy or the sibling okengine files leave the recorded hashes.
6
+ */
7
+ /**
8
+ * OKID constants and the options-path encoder.
9
+ *
10
+ * The default `okid()` / `okid(length)` hot path does not import the
11
+ * alphabet resolver — only these constants and {@link assertLength}.
12
+ */
13
+ /**
14
+ * Default `okid()` / `okid(length)` alphabet.
15
+ *
16
+ * Same 64-character set and order as
17
+ * `resolveAlphabet(true, true, true, true, true)` (numbers, lowercase,
18
+ * uppercase, symbols). Power-of-two size, so a bitmask is unbiased.
19
+ */
20
+ export declare const OKID_DEFAULT_CHARS = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ-_";
21
+ /**
22
+ * Characters removed when `lookAlikes` is disabled (human transcription).
23
+ */
24
+ export declare const OKID_LOOKALIKE_CHARS = "1lI0Oouv5Ss";
25
+ /** Default URL-safe alphabet: Base64URL charset in its conventional order. */
26
+ export declare const OKID_ALPHABET = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_";
27
+ /**
28
+ * Codepoint-ordered variant of {@link OKID_ALPHABET}: identical characters,
29
+ * sorted by code unit so plain string comparison equals value comparison.
30
+ * The default Base64URL order is NOT lexicographic (`_` sorts between `Z`
31
+ * and `a`), which would silently break time ordering — so the sortable
32
+ * encoder always uses this order.
33
+ *
34
+ * Kept as a literal (not `[...OKID_ALPHABET].sort().join("")`) so the public
35
+ * JSR API stays fast-type / explicitly typed.
36
+ */
37
+ export declare const OKID_SORTABLE_ALPHABET: string;
38
+ /** Default id length — 21 chars × 6 bits = 126 bits of entropy. */
39
+ export declare const OKID_DEFAULT_LENGTH = 21;
40
+ /** Shortest permitted id length (8 chars ≈ 48 bits entropy floor). */
41
+ export declare const OKID_MIN_LENGTH = 8;
42
+ /** Longest permitted id length. */
43
+ export declare const OKID_MAX_LENGTH = 128;
44
+ /** Sortable ids need ≥ 16: 8 timestamp chars alone would leave no randomness. */
45
+ export declare const OKID_SORTABLE_MIN_LENGTH = 16;
46
+ /** Longest permitted semantic {@link OkidOptions.prefix}. */
47
+ export declare const OKID_MAX_PREFIX_LENGTH = 32;
48
+ /** Options for {@link okid}. All alphabet toggles default to included. */
49
+ export interface OkidOptions {
50
+ /**
51
+ * Generated body length (default {@link OKID_DEFAULT_LENGTH}). Does not
52
+ * include {@link prefix} — the returned string is `prefix + body`.
53
+ */
54
+ readonly length?: number;
55
+ /**
56
+ * Fixed semantic label prepended to the body (e.g. `"usr_"`, `"evt_"`).
57
+ * Characters must belong to {@link OKID_ALPHABET}; max
58
+ * {@link OKID_MAX_PREFIX_LENGTH}. Empty / omitted means no label.
59
+ */
60
+ readonly prefix?: string;
61
+ /**
62
+ * Prefix the body with a 48-bit epoch-ms timestamp (exactly 8 chars) so
63
+ * lexicographic order tracks creation time across milliseconds. Alphabet
64
+ * toggles are ignored under this mode — see {@link OKID_SORTABLE_ALPHABET}.
65
+ * Combines with {@link prefix}: `prefix + timestamp + random`.
66
+ */
67
+ readonly sortable?: boolean;
68
+ /** Include `a-z` (default true). */
69
+ readonly lowercase?: boolean;
70
+ /** Include `A-Z` (default true). */
71
+ readonly uppercase?: boolean;
72
+ /** Include `0-9` (default true). */
73
+ readonly numbers?: boolean;
74
+ /** Include `-` and `_` (default true). */
75
+ readonly symbols?: boolean;
76
+ /**
77
+ * Include visually confusable characters (`1lI0Oouv5Ss`, default true).
78
+ * Set `false` to drop them for human transcription.
79
+ */
80
+ readonly lookAlikes?: boolean;
81
+ }
82
+ /**
83
+ * Assert `length` is a valid integer within bounds for the requested mode.
84
+ *
85
+ * @param length - Requested length
86
+ * @param min - Mode-specific minimum
87
+ * @param label - Option name used in the error message
88
+ */
89
+ export declare function assertLength(length: number, min: number, label: string): void;
@@ -0,0 +1,24 @@
1
+ /**
2
+ * Vendored from okengine `src/okid.ts` (Apache-2.0).
3
+ *
4
+ * okengine stays the source of truth. `bun run okid-drift` fails when this
5
+ * copy or the sibling okengine files leave the recorded hashes. The only
6
+ * local change is a static import of the options path, so the file has no
7
+ * okengine dependency and stays synchronous.
8
+ */
9
+ import { type OkidOptions } from "./okid-shared.js";
10
+ export type { OkidOptions } from "./okid-shared.js";
11
+ export { OKID_ALPHABET, OKID_DEFAULT_LENGTH, OKID_LOOKALIKE_CHARS, OKID_MAX_LENGTH, OKID_MAX_PREFIX_LENGTH, OKID_MIN_LENGTH, OKID_SORTABLE_ALPHABET, OKID_SORTABLE_MIN_LENGTH, } from "./okid-shared.js";
12
+ /**
13
+ * Generate an OKE-native id.
14
+ *
15
+ * Accepts either a bare length or an options object; the bare-number form is
16
+ * the hot path and skips all option resolution beyond validation.
17
+ *
18
+ * @param options - Length in chars, or {@link OkidOptions}
19
+ * @returns A URL-safe id: the generated body, optionally preceded by
20
+ * {@link OkidOptions.prefix}
21
+ * @throws RangeError on invalid input (non-integer, out-of-range length,
22
+ * invalid prefix, empty alphabet)
23
+ */
24
+ export declare function okid(options?: number | OkidOptions): string;
@@ -0,0 +1,21 @@
1
+ /**
2
+ * UUID client generators.
3
+ *
4
+ * `uuidv4` is `crypto.randomUUID()`. `uuidv7` is ours, so a server older than
5
+ * Postgres 18 can still have time-ordered ids without a database function.
6
+ */
7
+ import { type ClientGenerator } from "../../contracts/generator.js";
8
+ /**
9
+ * One random UUID, version 4.
10
+ *
11
+ * @returns Canonical 8-4-4-4-12 text
12
+ */
13
+ export declare const uuidv4: ClientGenerator<string>;
14
+ /**
15
+ * One time-ordered UUID, version 7.
16
+ *
17
+ * The first 48 bits are the Unix epoch in milliseconds. The rest is random.
18
+ *
19
+ * @returns Canonical 8-4-4-4-12 text
20
+ */
21
+ export declare const uuidv7: ClientGenerator<string>;
@@ -0,0 +1,22 @@
1
+ /**
2
+ * Row locks on `find` (spec §15): `lock: "update" | "share"` and
3
+ * `wait: "nowait" | "skip"`.
4
+ *
5
+ * A lock lives as long as its transaction, so it exists inside `tx()` only
6
+ * (OKM1830 outside one). The lock clause is the end of the statement and names
7
+ * the table alone (`for update of t`), so a to-one include does not lock the
8
+ * related row. Loaded on the first `find` that names `lock` or `wait`.
9
+ */
10
+ import { type Mods, type Session } from "./client.js";
11
+ import { type ArchiveView } from "./plan.js";
12
+ /**
13
+ * Builds the handle for one locking `find`.
14
+ *
15
+ * @param session - Client session. It must belong to a transaction
16
+ * @param table - Table name
17
+ * @param options - `find` options plus `lock` and `wait`
18
+ * @param mods - `.all` reason and presets
19
+ * @param view - Archive visibility
20
+ * @returns A handle that resolves to the locked rows
21
+ */
22
+ export declare function build(session: Session, table: string, options: object, mods: Mods, view: ArchiveView | undefined): Promise<unknown> & Record<string, unknown>;
@@ -0,0 +1,8 @@
1
+ /**
2
+ * SQL for the 0.2 operators.
3
+ *
4
+ * Loaded on the first query that uses one, so a client that only compares
5
+ * and filters text does not pay for it at startup. Text `contains` stays in
6
+ * the planner as `LIKE`.
7
+ */
8
+ export {};
@@ -0,0 +1,25 @@
1
+ /**
2
+ * Keyset pages (spec sections 10 and 12).
3
+ *
4
+ * A page is a `find` with three changes: the order ends in the primary key, the
5
+ * limit is one more than the page size, and an `after` condition replaces
6
+ * offset. The tenant and active-set predicates are the planner's, so they
7
+ * apply to every page the same way. This module loads on the first `page()`.
8
+ *
9
+ * The cursor holds the order it was made for and the values of the last row as
10
+ * the database wrote them. Those are text, not decoded values, so a timestamp
11
+ * keeps its microseconds and no row is skipped or repeated.
12
+ */
13
+ import { type Mods, type Session } from "./client.js";
14
+ import { type ArchiveView } from "./plan.js";
15
+ /**
16
+ * Builds the handle for one `page()` call.
17
+ *
18
+ * @param session - Client session
19
+ * @param table - Table name
20
+ * @param options - `where`, `select`, `orderBy`, `limit`, `include`, and `after`
21
+ * @param mods - Signal and timeout
22
+ * @param view - Archive visibility
23
+ * @returns A handle that resolves to `{ items, next }`
24
+ */
25
+ export declare function build(session: Session, table: string, options: object, mods: Mods, view: ArchiveView | undefined): Promise<unknown> & Record<string, unknown>;
@@ -0,0 +1,30 @@
1
+ /**
2
+ * `connect` for Bun.sql (`okmodel/pg/bun`).
3
+ *
4
+ * One URL or an existing pool is one endpoint. The client is typed by the
5
+ * schema passed in. This entry runs on Bun. Node cannot load the `bun` import
6
+ * inside the adapter.
7
+ */
8
+ import type { DriverPool } from "../../contracts/driver.js";
9
+ import type { QuerySchema } from "../../dialects/pg/model.js";
10
+ import { type BunSqlConfig } from "../../adapters/pg/bunsql.js";
11
+ import type { ConnectOptions, Connected } from "../types.js";
12
+ export { open, type BunSqlConfig, type BunSqlTls } from "../../adapters/pg/bunsql.js";
13
+ export { capabilities, hasCapability, readCapability } from "../../adapters/pg/bunsql.js";
14
+ export { DriverError } from "../../adapters/error.js";
15
+ /** A connection string or a pool from {@link open}. */
16
+ export type BunSqlTarget = string | DriverPool;
17
+ /** Driver options `connect` forwards to {@link open}. */
18
+ export type BunSqlConnectOptions<S extends QuerySchema> = ConnectOptions<S> & Omit<BunSqlConfig, "url">;
19
+ /**
20
+ * Connects one Postgres endpoint through Bun.sql and returns a client for `schema`.
21
+ *
22
+ * Named prepared statements are off unless `prepared` is `"named"`.
23
+ * `prepared: "named"` is not for transaction-mode poolers.
24
+ *
25
+ * @typeParam S - Schema
26
+ * @param target - URL or an existing pool
27
+ * @param options - Schema, errors, logger, and driver options
28
+ * @returns The client. Await `connected` for the dialect check
29
+ */
30
+ export declare function connect<const S extends QuerySchema>(target: BunSqlTarget, options: BunSqlConnectOptions<S>): Connected<S>;
@@ -0,0 +1,52 @@
1
+ import {
2
+ DriverError2
3
+ } from "../../shared/kyxb62mc.js";
4
+ import {
5
+ open5
6
+ } from "../../shared/ytg3xf9p.js";
7
+ import {
8
+ BUNSQL_CAPABILITIES,
9
+ readCapability2,
10
+ hasCapability2
11
+ } from "../../shared/9k6vetvf.js";
12
+ import {
13
+ createClient
14
+ } from "../../shared/mxmcdsh5.js";
15
+
16
+ // src/runtime/pg/bun.ts
17
+ function connect(target, options) {
18
+ const owned = !isPool(target);
19
+ const pool = isPool(target) ? target : open5({
20
+ url: target,
21
+ ...options.max !== undefined ? { max: options.max } : {},
22
+ ...options.timeouts !== undefined ? { timeouts: options.timeouts } : {},
23
+ ...options.prepared !== undefined ? { prepared: options.prepared } : {},
24
+ ...options.searchPath !== undefined ? { searchPath: options.searchPath } : {},
25
+ ...options.ssl !== undefined ? { ssl: options.ssl } : {}
26
+ });
27
+ return createClient(options.schema, pool, {
28
+ ownsPool: owned,
29
+ http: options.errors?.http,
30
+ includeValues: options.errors?.includeValues,
31
+ logger: options.logger,
32
+ signal: options.signal,
33
+ timeout: options.timeout,
34
+ timeouts: options.timeouts,
35
+ hookm: options.hookm,
36
+ catalog: options.catalog,
37
+ catalogDir: options.catalogDir,
38
+ requireMeta: options.requireMeta,
39
+ generators: options.generators
40
+ });
41
+ }
42
+ function isPool(target) {
43
+ return typeof target === "object" && "execute" in target && "capabilities" in target;
44
+ }
45
+ export {
46
+ DriverError2 as DriverError,
47
+ BUNSQL_CAPABILITIES as capabilities,
48
+ connect,
49
+ hasCapability2 as hasCapability,
50
+ open5 as open,
51
+ readCapability2 as readCapability
52
+ };
@@ -0,0 +1,29 @@
1
+ /**
2
+ * `connect` for node-postgres (`okmodel/pg/pg`).
3
+ *
4
+ * One URL or an existing pool is one endpoint. The client is typed by the
5
+ * schema passed in, not by `Register`.
6
+ */
7
+ import type { DriverPool } from "../../contracts/driver.js";
8
+ import type { QuerySchema } from "../../dialects/pg/model.js";
9
+ import { type NodePostgresConfig } from "../../adapters/pg/nodepostgres.js";
10
+ import type { ConnectOptions, Connected } from "../types.js";
11
+ export { open, type NodePostgresConfig } from "../../adapters/pg/nodepostgres.js";
12
+ export { capabilities, hasCapability, readCapability } from "../../adapters/pg/nodepostgres.js";
13
+ export { DriverError } from "../../adapters/error.js";
14
+ /** A connection string or a pool from {@link open}. */
15
+ export type NodePostgresTarget = string | DriverPool;
16
+ /** Driver options `connect` forwards to {@link open}. */
17
+ export type NodePostgresConnectOptions<S extends QuerySchema> = ConnectOptions<S> & Omit<NodePostgresConfig, "url">;
18
+ /**
19
+ * Connects one Postgres endpoint through node-postgres and returns a client for `schema`.
20
+ *
21
+ * Named prepared statements are off unless `prepared` is `"named"`.
22
+ * `prepared: "named"` is not for transaction-mode poolers.
23
+ *
24
+ * @typeParam S - Schema
25
+ * @param target - URL or an existing pool
26
+ * @param options - Schema, errors, logger, and driver options
27
+ * @returns The client. Await `connected` for the dialect check
28
+ */
29
+ export declare function connect<const S extends QuerySchema>(target: NodePostgresTarget, options: NodePostgresConnectOptions<S>): Connected<S>;
@@ -0,0 +1,52 @@
1
+ import {
2
+ DriverError2
3
+ } from "../../shared/kyxb62mc.js";
4
+ import {
5
+ open4
6
+ } from "../../shared/38crxbgn.js";
7
+ import {
8
+ NODE_POSTGRES_CAPABILITIES,
9
+ readCapability2,
10
+ hasCapability2
11
+ } from "../../shared/9k6vetvf.js";
12
+ import {
13
+ createClient
14
+ } from "../../shared/mxmcdsh5.js";
15
+
16
+ // src/runtime/pg/pg.ts
17
+ function connect(target, options) {
18
+ const owned = !isPool(target);
19
+ const pool = isPool(target) ? target : open4({
20
+ url: target,
21
+ ...options.max !== undefined ? { max: options.max } : {},
22
+ ...options.timeouts !== undefined ? { timeouts: options.timeouts } : {},
23
+ ...options.prepared !== undefined ? { prepared: options.prepared } : {},
24
+ ...options.searchPath !== undefined ? { searchPath: options.searchPath } : {},
25
+ ...options.ssl !== undefined ? { ssl: options.ssl } : {}
26
+ });
27
+ return createClient(options.schema, pool, {
28
+ ownsPool: owned,
29
+ http: options.errors?.http,
30
+ includeValues: options.errors?.includeValues,
31
+ logger: options.logger,
32
+ signal: options.signal,
33
+ timeout: options.timeout,
34
+ timeouts: options.timeouts,
35
+ hookm: options.hookm,
36
+ catalog: options.catalog,
37
+ catalogDir: options.catalogDir,
38
+ requireMeta: options.requireMeta,
39
+ generators: options.generators
40
+ });
41
+ }
42
+ function isPool(target) {
43
+ return typeof target === "object" && "execute" in target && "capabilities" in target;
44
+ }
45
+ export {
46
+ DriverError2 as DriverError,
47
+ NODE_POSTGRES_CAPABILITIES as capabilities,
48
+ connect,
49
+ hasCapability2 as hasCapability,
50
+ open4 as open,
51
+ readCapability2 as readCapability
52
+ };
@@ -1,39 +1,38 @@
1
1
  import {
2
2
  DriverError2
3
- } from "../../shared/hd293j9g.js";
3
+ } from "../../shared/kyxb62mc.js";
4
4
  import {
5
5
  open3
6
- } from "../../shared/fgqgsb5z.js";
7
- import {
8
- createClient
9
- } from "../../shared/rgs0st28.js";
6
+ } from "../../shared/0qkxbm1f.js";
10
7
  import {
11
8
  PGLITE_CAPABILITIES,
12
9
  readCapability2,
13
10
  hasCapability2
14
- } from "../../shared/xy79j5hq.js";
11
+ } from "../../shared/9k6vetvf.js";
12
+ import {
13
+ createClient
14
+ } from "../../shared/mxmcdsh5.js";
15
15
 
16
16
  // src/runtime/pg/pglite.ts
17
17
  async function connect(target, options) {
18
- const shared = {
18
+ const pool = isPool(target) ? target : await open3({
19
+ ...target !== undefined ? { dataDir: target } : {},
20
+ ...options.timeouts !== undefined ? { timeouts: options.timeouts } : {}
21
+ });
22
+ return createClient(options.schema, pool, {
23
+ ownsPool: !isPool(target),
19
24
  http: options.errors?.http,
20
25
  includeValues: options.errors?.includeValues,
21
26
  logger: options.logger,
22
27
  signal: options.signal,
23
28
  requireMeta: options.requireMeta,
24
29
  timeout: options.timeout,
30
+ timeouts: options.timeouts,
31
+ hookm: options.hookm,
25
32
  catalog: options.catalog,
26
- catalogDir: options.catalogDir
27
- };
28
- if (isPool(target)) {
29
- return createClient(options.schema, target, { ...shared, ownsPool: false });
30
- }
31
- const dataDir = target;
32
- const pool = await open3({
33
- ...dataDir !== undefined ? { dataDir } : {},
34
- ...options.timeouts !== undefined ? { timeouts: options.timeouts } : {}
33
+ catalogDir: options.catalogDir,
34
+ generators: options.generators
35
35
  });
36
- return createClient(options.schema, pool, { ...shared, ownsPool: true });
37
36
  }
38
37
  function isPool(target) {
39
38
  return typeof target === "object" && target !== null && "execute" in target && "capabilities" in target;