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.
- package/README.md +32 -16
- package/dist/adapters/capabilities.d.ts +34 -0
- package/dist/adapters/pg/bunsql-extra.d.ts +17 -0
- package/dist/adapters/pg/bunsql.d.ts +60 -0
- package/dist/adapters/pg/call.d.ts +2 -12
- package/dist/adapters/pg/nodepostgres-extra.d.ts +18 -0
- package/dist/adapters/pg/nodepostgres.d.ts +57 -0
- package/dist/adapters/pg/postgres-extra.d.ts +50 -1
- package/dist/adapters/pg/postgresjs.d.ts +0 -4
- package/dist/adapters/pg/session.d.ts +94 -0
- package/dist/adapters/pg/watch.d.ts +18 -0
- package/dist/contracts/catalog/object.d.ts +1 -0
- package/dist/contracts/catalog/types.d.ts +15 -8
- package/dist/contracts/connection.d.ts +13 -0
- package/dist/contracts/driver.d.ts +18 -5
- package/dist/contracts/error.d.ts +17 -1
- package/dist/contracts/generator.d.ts +63 -0
- package/dist/contracts/index.d.ts +2 -2
- package/dist/contracts/index.js +1 -1
- package/dist/contracts/internal.js +11 -9
- package/dist/contracts/location.d.ts +24 -0
- package/dist/contracts/rows.d.ts +15 -0
- package/dist/dialects/pg/archive-bind.d.ts +22 -0
- package/dist/dialects/pg/column.d.ts +126 -9
- package/dist/dialects/pg/compile.d.ts +1 -0
- package/dist/dialects/pg/custom.d.ts +6 -0
- package/dist/dialects/pg/filter-parse.d.ts +19 -0
- package/dist/dialects/pg/filters.d.ts +19 -0
- package/dist/dialects/pg/index.d.ts +11 -2
- package/dist/dialects/pg/index.js +159 -1063
- package/dist/dialects/pg/keys.d.ts +19 -3
- package/dist/dialects/pg/model.d.ts +223 -2
- package/dist/dialects/pg/operator-fit.d.ts +86 -0
- package/dist/dialects/pg/operators.d.ts +39 -1
- package/dist/dialects/pg/ops/arr-append.d.ts +9 -0
- package/dist/dialects/pg/ops/arr-ns.d.ts +7 -0
- package/dist/dialects/pg/ops/arr-remove.d.ts +9 -0
- package/dist/dialects/pg/ops/containedBy.d.ts +9 -0
- package/dist/dialects/pg/ops/contains.d.ts +8 -4
- package/dist/dialects/pg/ops/hasAnyKey.d.ts +8 -0
- package/dist/dialects/pg/ops/hasKey.d.ts +8 -0
- package/dist/dialects/pg/ops/json-ns.d.ts +6 -0
- package/dist/dialects/pg/ops/json-set.d.ts +12 -0
- package/dist/dialects/pg/ops/matches.d.ts +16 -0
- package/dist/dialects/pg/ops/overlaps.d.ts +9 -0
- package/dist/dialects/pg/ops/path.d.ts +13 -0
- package/dist/dialects/pg/preset.d.ts +76 -0
- package/dist/dialects/pg/relations.d.ts +59 -2
- package/dist/dialects/pg/schema.d.ts +109 -5
- package/dist/dialects/pg/table.d.ts +130 -11
- package/dist/dialects/pg/temporal.d.ts +9 -7
- package/dist/dialects/pg/tenancy.d.ts +94 -0
- package/dist/dialects/pg/through.d.ts +21 -0
- package/dist/dialects/pg/trait.d.ts +141 -0
- package/dist/dialects/pg/where.d.ts +37 -0
- package/dist/runtime/aggregate.d.ts +25 -0
- package/dist/runtime/archive-handle.d.ts +18 -0
- package/dist/runtime/archive-rules.d.ts +12 -0
- package/dist/runtime/archive.d.ts +73 -0
- package/dist/runtime/batch.d.ts +20 -0
- package/dist/runtime/client.d.ts +114 -5
- package/dist/runtime/conflict.d.ts +2 -1
- package/dist/runtime/exposure.d.ts +27 -0
- package/dist/runtime/hookm.d.ts +39 -0
- package/dist/runtime/ids/index.d.ts +11 -0
- package/dist/runtime/ids/index.js +193 -0
- package/dist/runtime/ids/okid-extended.d.ts +19 -0
- package/dist/runtime/ids/okid-generator.d.ts +21 -0
- package/dist/runtime/ids/okid-shared.d.ts +89 -0
- package/dist/runtime/ids/okid.d.ts +24 -0
- package/dist/runtime/ids/uuid.d.ts +21 -0
- package/dist/runtime/lock.d.ts +22 -0
- package/dist/runtime/operator-sql.d.ts +8 -0
- package/dist/runtime/page.d.ts +25 -0
- package/dist/runtime/pg/bun.d.ts +30 -0
- package/dist/runtime/pg/bun.js +52 -0
- package/dist/runtime/pg/pg.d.ts +29 -0
- package/dist/runtime/pg/pg.js +52 -0
- package/dist/runtime/pg/pglite.js +16 -17
- package/dist/runtime/pg/postgresjs.js +14 -24
- package/dist/runtime/plan.d.ts +146 -7
- package/dist/runtime/preset-stack.d.ts +17 -0
- package/dist/runtime/presets.d.ts +48 -0
- package/dist/runtime/read-stream.d.ts +26 -0
- package/dist/runtime/safety/index.d.ts +159 -0
- package/dist/runtime/safety/index.js +294 -0
- package/dist/runtime/safety-hook.d.ts +42 -0
- package/dist/runtime/server-check.d.ts +34 -0
- package/dist/runtime/tenancy/index.d.ts +37 -0
- package/dist/runtime/tenancy/index.js +365 -0
- package/dist/runtime/trait-read.d.ts +30 -0
- package/dist/runtime/traits/index.d.ts +128 -0
- package/dist/runtime/traits/index.js +509 -0
- package/dist/runtime/transaction.d.ts +19 -0
- package/dist/runtime/tx.d.ts +22 -7
- package/dist/runtime/types.d.ts +376 -27
- package/dist/runtime/validate/bind.d.ts +11 -0
- package/dist/runtime/validate/closed.d.ts +16 -0
- package/dist/runtime/validate/engine.d.ts +41 -0
- package/dist/runtime/validate/hook.d.ts +17 -0
- package/dist/runtime/validate/index.d.ts +21 -0
- package/dist/runtime/validate/index.js +175 -0
- package/dist/runtime/validate/load.d.ts +13 -0
- package/dist/runtime/validate/places.d.ts +41 -0
- package/dist/runtime/validate/rules.d.ts +108 -0
- package/dist/runtime/validate/surface.d.ts +102 -0
- package/dist/runtime/write.d.ts +30 -5
- package/dist/shared/{fgqgsb5z.js → 0qkxbm1f.js} +2 -2
- package/dist/shared/0v1g424p.js +26 -0
- package/dist/shared/10tjenmd.js +210 -0
- package/dist/shared/{xqbhg6cn.js → 1dp5knt7.js} +95 -10
- package/dist/shared/38crxbgn.js +229 -0
- package/dist/shared/3a5ne750.js +158 -0
- package/dist/shared/4b9da9d7.js +138 -0
- package/dist/shared/4e4c6vq2.js +62 -0
- package/dist/shared/{x5x59srr.js → 4jzzghr6.js} +416 -83
- package/dist/shared/{ycwz42az.js → 52szzakm.js} +6 -26
- package/dist/shared/{05w44d8g.js → 5z4q2zda.js} +567 -18
- package/dist/shared/672t5vym.js +12 -0
- package/dist/shared/7m88x3e9.js +45 -0
- package/dist/shared/7mht49yd.js +1091 -0
- package/dist/shared/{mtkwv8wx.js → 7p2wbz7f.js} +1 -1
- package/dist/shared/83eaefwr.js +10 -0
- package/dist/shared/96ps4g1z.js +32 -0
- package/dist/shared/97g2jnrw.js +76 -0
- package/dist/shared/{xy79j5hq.js → 9k6vetvf.js} +25 -36
- package/dist/shared/{w8samvk1.js → a1gdp7j9.js} +1 -1
- package/dist/shared/a5sxz52y.js +13 -0
- package/dist/shared/{dynq16vb.js → b066g80h.js} +8 -6
- package/dist/shared/cstgkzdx.js +154 -0
- package/dist/shared/{523ft3e8.js → d04j53v8.js} +6 -5
- package/dist/shared/{y9m15dfv.js → d2whjz4k.js} +15 -9
- package/dist/shared/dd4f8mnx.js +307 -0
- package/dist/shared/e6wg00wd.js +164 -0
- package/dist/shared/e7a268fy.js +195 -0
- package/dist/shared/{kprcwaha.js → eaxwrgby.js} +4 -3
- package/dist/shared/{dkn3y60a.js → ecdzej21.js} +76 -112
- package/dist/shared/{hadrfb9h.js → edwqqryd.js} +17 -14
- package/dist/shared/{m3ypagh5.js → eqmtn1bj.js} +57 -5
- package/dist/shared/g1b5zzj9.js +75 -0
- package/dist/shared/g9f0zqce.js +376 -0
- package/dist/shared/ge03bfca.js +64 -0
- package/dist/shared/{yd1kzwn2.js → jns2wx4t.js} +55 -12
- package/dist/shared/k3ted12y.js +33 -0
- package/dist/shared/k7dwkhvq.js +31 -0
- package/dist/shared/{hd293j9g.js → kyxb62mc.js} +14 -2
- package/dist/shared/m9tv7xn7.js +404 -0
- package/dist/shared/mrq77sgw.js +55 -0
- package/dist/shared/mxmcdsh5.js +450 -0
- package/dist/shared/n442h54c.js +14 -0
- package/dist/shared/n47rd821.js +442 -0
- package/dist/shared/n4jqhpqz.js +27 -0
- package/dist/shared/{mkjmqjv4.js → nfzc5z0w.js} +2 -104
- package/dist/shared/nsva2a6b.js +42 -0
- package/dist/shared/ps43134h.js +69 -0
- package/dist/shared/{8b04d28c.js → py3nh7jy.js} +2 -2
- package/dist/shared/qa5dsc7z.js +86 -0
- package/dist/shared/{g5fhqmwe.js → qxa0yb9j.js} +6 -4
- package/dist/shared/r6nwkxnt.js +86 -0
- package/dist/shared/{jjb7yht9.js → rtnaqre0.js} +3 -3
- package/dist/shared/rwmrejjz.js +26 -0
- package/dist/shared/{zhc5vmgf.js → s6gqfn5j.js} +2 -2
- package/dist/shared/sacqha1y.js +70 -0
- package/dist/shared/{qk3hxfja.js → sfh4pk75.js} +5 -5
- package/dist/shared/{j5cn2963.js → t4tbsy9h.js} +13 -64
- package/dist/shared/{ngk8gj61.js → tbszx8mz.js} +15 -1
- package/dist/shared/v18jva5b.js +90 -0
- package/dist/shared/x9v1qgeb.js +201 -0
- package/dist/shared/xatfg0gn.js +193 -0
- package/dist/shared/xkz8g6by.js +225 -0
- package/dist/shared/{rgs0st28.js → xrfnq5k8.js} +237 -434
- package/dist/shared/ytg3xf9p.js +149 -0
- package/dist/shared/yw5c610b.js +48 -0
- package/dist/shared/zd93g3rq.js +31 -0
- package/dist/shared/zt8y0wzb.js +132 -0
- package/dist/shared/{p0cbr3g2.js → zwmqxb0g.js} +1 -1
- package/dist/tooling/cli.js +14 -10
- package/dist/tooling/migrate/commands.d.ts +10 -0
- package/dist/tooling/migrate/engine.d.ts +36 -0
- package/package.json +41 -4
- package/dist/shared/gk7cs7sp.js +0 -566
|
@@ -1,13 +1,12 @@
|
|
|
1
1
|
import {
|
|
2
2
|
POSTGRESJS_CAPABILITIES,
|
|
3
|
-
driverErrors,
|
|
4
3
|
rejectClosed,
|
|
5
4
|
mapFailure,
|
|
6
5
|
nextTransactionDepth,
|
|
7
6
|
runCall,
|
|
8
7
|
EMPTY_NOTICES,
|
|
9
8
|
resultFrom
|
|
10
|
-
} from "./
|
|
9
|
+
} from "./9k6vetvf.js";
|
|
11
10
|
|
|
12
11
|
// src/adapters/pg/postgresjs.ts
|
|
13
12
|
import net from "node:net";
|
|
@@ -37,61 +36,29 @@ class PoolSockets {
|
|
|
37
36
|
this.park();
|
|
38
37
|
});
|
|
39
38
|
}
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
return release().finally(() => {
|
|
52
|
-
this.busy -= 1;
|
|
53
|
-
this.park();
|
|
54
|
-
});
|
|
55
|
-
};
|
|
56
|
-
return connection;
|
|
57
|
-
} catch (error) {
|
|
58
|
-
this.busy -= 1;
|
|
59
|
-
this.park();
|
|
60
|
-
throw error;
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
async* stream(open) {
|
|
64
|
-
this.busy += 1;
|
|
65
|
-
this.wake();
|
|
66
|
-
try {
|
|
67
|
-
yield* open();
|
|
68
|
-
} finally {
|
|
69
|
-
this.busy -= 1;
|
|
70
|
-
this.park();
|
|
71
|
-
}
|
|
39
|
+
busyGate() {
|
|
40
|
+
return {
|
|
41
|
+
enter: () => {
|
|
42
|
+
this.busy += 1;
|
|
43
|
+
this.wake();
|
|
44
|
+
},
|
|
45
|
+
leave: () => {
|
|
46
|
+
this.busy -= 1;
|
|
47
|
+
this.park();
|
|
48
|
+
}
|
|
49
|
+
};
|
|
72
50
|
}
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
await stop();
|
|
85
|
-
} finally {
|
|
86
|
-
this.listeners -= 1;
|
|
87
|
-
this.park();
|
|
88
|
-
}
|
|
89
|
-
};
|
|
90
|
-
} catch (error) {
|
|
91
|
-
this.listeners -= 1;
|
|
92
|
-
this.park();
|
|
93
|
-
throw error;
|
|
94
|
-
}
|
|
51
|
+
listenerGate() {
|
|
52
|
+
return {
|
|
53
|
+
enter: () => {
|
|
54
|
+
this.listeners += 1;
|
|
55
|
+
this.wake();
|
|
56
|
+
},
|
|
57
|
+
leave: () => {
|
|
58
|
+
this.listeners -= 1;
|
|
59
|
+
this.park();
|
|
60
|
+
}
|
|
61
|
+
};
|
|
95
62
|
}
|
|
96
63
|
wake() {
|
|
97
64
|
for (const socket of this.held)
|
|
@@ -150,7 +117,7 @@ function open2(config) {
|
|
|
150
117
|
},
|
|
151
118
|
async batch(statements, options) {
|
|
152
119
|
return sockets.occupy(async () => {
|
|
153
|
-
const { checkout } = await import("./
|
|
120
|
+
const { checkout } = await import("./1dp5knt7.js");
|
|
154
121
|
const connection = await checkout(held);
|
|
155
122
|
try {
|
|
156
123
|
return await connection.batch(statements, options);
|
|
@@ -160,21 +127,36 @@ function open2(config) {
|
|
|
160
127
|
});
|
|
161
128
|
},
|
|
162
129
|
reserve() {
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
130
|
+
const gate = sockets.busyGate();
|
|
131
|
+
gate.enter();
|
|
132
|
+
return import("./1dp5knt7.js").then((mod) => mod.holdCheckout(gate, () => mod.checkout(held)), (error) => {
|
|
133
|
+
gate.leave();
|
|
134
|
+
throw error;
|
|
166
135
|
});
|
|
167
136
|
},
|
|
168
|
-
describe: (text, params) => sockets.occupy(() => import("./
|
|
137
|
+
describe: (text, params) => sockets.occupy(() => import("./1dp5knt7.js").then((mod) => mod.describe(sql, text, params))),
|
|
169
138
|
stream(text, params) {
|
|
170
|
-
|
|
139
|
+
const gate = sockets.busyGate();
|
|
140
|
+
return async function* () {
|
|
141
|
+
gate.enter();
|
|
142
|
+
try {
|
|
143
|
+
yield* loadStream(sql, text, params);
|
|
144
|
+
} finally {
|
|
145
|
+
gate.leave();
|
|
146
|
+
}
|
|
147
|
+
}();
|
|
171
148
|
},
|
|
172
149
|
listen(channel, onNotify) {
|
|
173
|
-
|
|
150
|
+
const gate = sockets.listenerGate();
|
|
151
|
+
gate.enter();
|
|
152
|
+
return import("./1dp5knt7.js").then((mod) => mod.holdListener(gate, async () => {
|
|
174
153
|
const listening = await sql.listen(channel, onNotify);
|
|
175
154
|
return async () => {
|
|
176
155
|
await listening.unlisten();
|
|
177
156
|
};
|
|
157
|
+
}), (error) => {
|
|
158
|
+
gate.leave();
|
|
159
|
+
throw error;
|
|
178
160
|
});
|
|
179
161
|
},
|
|
180
162
|
cancel() {
|
|
@@ -228,7 +210,36 @@ class PgSession {
|
|
|
228
210
|
});
|
|
229
211
|
});
|
|
230
212
|
}
|
|
231
|
-
|
|
213
|
+
this.local.add(pending);
|
|
214
|
+
this.shared?.add(pending);
|
|
215
|
+
const onAbort = () => {
|
|
216
|
+
pending.cancel();
|
|
217
|
+
};
|
|
218
|
+
if (watch.signal.aborted)
|
|
219
|
+
onAbort();
|
|
220
|
+
else
|
|
221
|
+
watch.signal.addEventListener("abort", onAbort, { once: true });
|
|
222
|
+
return import("./1dp5knt7.js").then((mod) => mod.watchQuery(pending, watch, onAbort, {
|
|
223
|
+
start,
|
|
224
|
+
text,
|
|
225
|
+
notices: this.notices,
|
|
226
|
+
leave: () => {
|
|
227
|
+
this.leave();
|
|
228
|
+
},
|
|
229
|
+
note: (sqlText) => {
|
|
230
|
+
this.note(sqlText);
|
|
231
|
+
},
|
|
232
|
+
untrack: (item) => {
|
|
233
|
+
this.local.delete(item);
|
|
234
|
+
this.shared?.delete(item);
|
|
235
|
+
}
|
|
236
|
+
}), (error) => {
|
|
237
|
+
this.leave();
|
|
238
|
+
this.local.delete(pending);
|
|
239
|
+
this.shared?.delete(pending);
|
|
240
|
+
watch.signal.removeEventListener("abort", onAbort);
|
|
241
|
+
throw error;
|
|
242
|
+
});
|
|
232
243
|
}
|
|
233
244
|
inTransaction() {
|
|
234
245
|
return this.transactionDepth > 0;
|
|
@@ -258,43 +269,9 @@ class PgSession {
|
|
|
258
269
|
else
|
|
259
270
|
this.counters.reservedBusy = Math.max(0, this.counters.reservedBusy - 1);
|
|
260
271
|
}
|
|
261
|
-
track(pending) {
|
|
262
|
-
this.local.add(pending);
|
|
263
|
-
this.shared?.add(pending);
|
|
264
|
-
}
|
|
265
|
-
untrack(pending) {
|
|
266
|
-
this.local.delete(pending);
|
|
267
|
-
this.shared?.delete(pending);
|
|
268
|
-
}
|
|
269
|
-
watched(pending, watch, start, text) {
|
|
270
|
-
this.track(pending);
|
|
271
|
-
const onAbort = () => {
|
|
272
|
-
pending.cancel();
|
|
273
|
-
};
|
|
274
|
-
if (watch.signal.aborted)
|
|
275
|
-
onAbort();
|
|
276
|
-
else
|
|
277
|
-
watch.signal.addEventListener("abort", onAbort, { once: true });
|
|
278
|
-
return pending.then((result) => {
|
|
279
|
-
this.finishWatched(pending, watch, onAbort);
|
|
280
|
-
const why = watch.reason();
|
|
281
|
-
if (why === "timeout" || why === "cancelled")
|
|
282
|
-
return classify(why, watch);
|
|
283
|
-
this.note(text);
|
|
284
|
-
return resultFrom(result, this.notices.since(start));
|
|
285
|
-
}, (error) => {
|
|
286
|
-
this.finishWatched(pending, watch, onAbort);
|
|
287
|
-
return classify(error, watch);
|
|
288
|
-
});
|
|
289
|
-
}
|
|
290
|
-
finishWatched(pending, watch, onAbort) {
|
|
291
|
-
this.leave();
|
|
292
|
-
this.untrack(pending);
|
|
293
|
-
watch.signal.removeEventListener("abort", onAbort);
|
|
294
|
-
}
|
|
295
272
|
}
|
|
296
273
|
async function* loadStream(sql, text, params) {
|
|
297
|
-
const { stream } = await import("./
|
|
274
|
+
const { stream } = await import("./1dp5knt7.js");
|
|
298
275
|
yield* stream(sql, text, params);
|
|
299
276
|
}
|
|
300
277
|
function send(sql, text, params, named) {
|
|
@@ -307,19 +284,6 @@ function asParams(params) {
|
|
|
307
284
|
return [];
|
|
308
285
|
return params;
|
|
309
286
|
}
|
|
310
|
-
async function classify(error, watch) {
|
|
311
|
-
const errors = await driverErrors();
|
|
312
|
-
if (error instanceof errors.DriverError)
|
|
313
|
-
return Promise.reject(error);
|
|
314
|
-
const why = typeof error === "string" ? error : watch.reason();
|
|
315
|
-
if (why === "timeout")
|
|
316
|
-
return Promise.reject(errors.timedOut(typeof error === "string" ? undefined : error));
|
|
317
|
-
const code = errors.errorField(error, "code");
|
|
318
|
-
if (why === "cancelled" || code === "57014") {
|
|
319
|
-
return Promise.reject(errors.cancelled(typeof error === "string" ? undefined : error));
|
|
320
|
-
}
|
|
321
|
-
return Promise.reject(errors.mapDriverError(error));
|
|
322
|
-
}
|
|
323
287
|
function statsOf(counters, size) {
|
|
324
288
|
return {
|
|
325
289
|
size,
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import {
|
|
2
|
+
emitRelationFrom,
|
|
2
3
|
decodeResult,
|
|
3
4
|
emitJoin,
|
|
4
5
|
emitWhere,
|
|
@@ -14,13 +15,15 @@ import {
|
|
|
14
15
|
quote,
|
|
15
16
|
list,
|
|
16
17
|
isRecord,
|
|
18
|
+
registerFailFix,
|
|
17
19
|
fail
|
|
18
|
-
} from "./
|
|
20
|
+
} from "./xrfnq5k8.js";
|
|
19
21
|
import {
|
|
20
22
|
throwNamed2
|
|
21
|
-
} from "./
|
|
23
|
+
} from "./52szzakm.js";
|
|
22
24
|
|
|
23
25
|
// src/runtime/include.ts
|
|
26
|
+
registerFailFix("OKM1105", "Pass limit on the include, or call .all(reason).");
|
|
24
27
|
var INCLUDE_OPTIONS = ["all", "include", "limit", "orderBy", "select", "where"];
|
|
25
28
|
function emitIncludeSelect(include, alias, sink, outputs, column) {
|
|
26
29
|
const selected = include.columns;
|
|
@@ -130,11 +133,7 @@ function emitIncludeJoin(schema, include, sink, parentAlias, alias, depth) {
|
|
|
130
133
|
emitNestedAggregate(schema, nested, sink, childAlias, depth + 1);
|
|
131
134
|
}
|
|
132
135
|
sink.text(") as item from ");
|
|
133
|
-
|
|
134
|
-
sink.text(" ");
|
|
135
|
-
sink.text(childAlias);
|
|
136
|
-
sink.text(" where ");
|
|
137
|
-
emitJoin(sink, parentAlias, childAlias, include.relation);
|
|
136
|
+
emitRelationFrom(schema, include.relation, child, sink, parentAlias, childAlias, depth + 1);
|
|
138
137
|
emitWhere(schema, child, include.where, sink, childAlias, depth + 1, true);
|
|
139
138
|
emitOrder(child, include.orderBy, sink, childAlias);
|
|
140
139
|
if (include.orderBy === undefined && child.model.primary.length > 0) {
|
|
@@ -225,11 +224,7 @@ function emitNestedAggregate(schema, include, sink, alias, depth) {
|
|
|
225
224
|
if (include.columns.length === 0)
|
|
226
225
|
sink.text("1");
|
|
227
226
|
sink.text(") as item from ");
|
|
228
|
-
|
|
229
|
-
sink.text(" ");
|
|
230
|
-
sink.text(childAlias);
|
|
231
|
-
sink.text(" where ");
|
|
232
|
-
emitJoin(sink, alias, childAlias, include.relation);
|
|
227
|
+
emitRelationFrom(schema, include.relation, child, sink, alias, childAlias, depth);
|
|
233
228
|
emitWhere(schema, child, include.where, sink, childAlias, depth, true);
|
|
234
229
|
emitOrder(child, include.orderBy, sink, childAlias);
|
|
235
230
|
if (include.orderBy === undefined && child.model.primary.length > 0) {
|
|
@@ -242,6 +237,14 @@ function emitNestedAggregate(schema, include, sink, alias, depth) {
|
|
|
242
237
|
}
|
|
243
238
|
sink.text(") limited) ordered)");
|
|
244
239
|
}
|
|
240
|
+
function omitHidden(columns) {
|
|
241
|
+
for (const column of columns) {
|
|
242
|
+
if (!column.hidden)
|
|
243
|
+
continue;
|
|
244
|
+
return columns.filter((item) => !item.hidden);
|
|
245
|
+
}
|
|
246
|
+
return columns;
|
|
247
|
+
}
|
|
245
248
|
function readIncludes(schema, table, include, all) {
|
|
246
249
|
if (include === undefined)
|
|
247
250
|
return [];
|
|
@@ -264,7 +267,7 @@ function parseInclude(schema, name, relation, value, all) {
|
|
|
264
267
|
fail("OKM1105", `Include ${name} is to-many and has no limit. Pass limit, or call .all(reason).`);
|
|
265
268
|
}
|
|
266
269
|
const child = childIndex(schema, relation);
|
|
267
|
-
const columns = selectedColumns(child, undefined);
|
|
270
|
+
const columns = omitHidden(selectedColumns(child, undefined));
|
|
268
271
|
return {
|
|
269
272
|
name,
|
|
270
273
|
relation,
|
|
@@ -288,7 +291,7 @@ function parseInclude(schema, name, relation, value, all) {
|
|
|
288
291
|
fail("OKM1105", `Include ${name} is to-many and has no limit. Pass limit, or call .all(reason).`);
|
|
289
292
|
}
|
|
290
293
|
const child = childIndex(schema, relation);
|
|
291
|
-
const columns = selectedColumns(child, value.select);
|
|
294
|
+
const columns = omitHidden(selectedColumns(child, value.select));
|
|
292
295
|
const nestedValue = value.include;
|
|
293
296
|
const nested = nestedValue === undefined ? [] : readIncludes(schema, child, nestedValue, reason);
|
|
294
297
|
return {
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import {
|
|
2
2
|
open2
|
|
3
|
-
} from "./
|
|
3
|
+
} from "./ecdzej21.js";
|
|
4
4
|
import {
|
|
5
5
|
catalogHash2
|
|
6
|
-
} from "./
|
|
6
|
+
} from "./d2whjz4k.js";
|
|
7
|
+
import"./n442h54c.js";
|
|
7
8
|
import {
|
|
8
9
|
loadMigrations
|
|
9
|
-
} from "./
|
|
10
|
+
} from "./rtnaqre0.js";
|
|
10
11
|
import {
|
|
11
12
|
quoteIdent,
|
|
12
13
|
planMigration,
|
|
@@ -15,13 +16,63 @@ import {
|
|
|
15
16
|
selectTarget,
|
|
16
17
|
projectHead,
|
|
17
18
|
loadConfig
|
|
18
|
-
} from "./
|
|
19
|
+
} from "./5z4q2zda.js";
|
|
19
20
|
import {
|
|
20
21
|
OkmError2
|
|
21
|
-
} from "./
|
|
22
|
+
} from "./52szzakm.js";
|
|
22
23
|
|
|
23
24
|
// src/tooling/migrate/apply.ts
|
|
24
25
|
import { join } from "node:path";
|
|
26
|
+
|
|
27
|
+
// src/tooling/migrate/engine.ts
|
|
28
|
+
var IDENT = String.raw`"(?:[^"]|"")+"|[A-Za-z_][\w$]*`;
|
|
29
|
+
var DEFAULT_UUIDV7 = /\bdefault\s+uuidv7\s*\(\s*\)/i;
|
|
30
|
+
var TABLE = new RegExp(String.raw`^\s*(?:create\s+table(?:\s+if\s+not\s+exists)?|alter\s+table(?:\s+if\s+exists)?(?:\s+only)?)\s+(?:(?:${IDENT})\.)?(${IDENT})`, "i");
|
|
31
|
+
var COLUMN = new RegExp(String.raw`(${IDENT})\s+(?:uuid\b|set\s+default\b)`, "i");
|
|
32
|
+
function findUuidV7Default(migrations) {
|
|
33
|
+
for (const migration of migrations) {
|
|
34
|
+
for (let stepIndex = 0;stepIndex < migration.steps.length; stepIndex += 1) {
|
|
35
|
+
const sql = migration.steps[stepIndex]?.sql ?? "";
|
|
36
|
+
if (!DEFAULT_UUIDV7.test(sql))
|
|
37
|
+
continue;
|
|
38
|
+
return { migrationId: migration.id, stepIndex, column: columnOf(sql) };
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
async function assertUuidV7Available(connection, migrations) {
|
|
44
|
+
const found = findUuidV7Default(migrations);
|
|
45
|
+
if (found === undefined)
|
|
46
|
+
return;
|
|
47
|
+
const result = await connection.execute("select current_setting('server_version_num'), to_regprocedure('uuidv7()')::text");
|
|
48
|
+
const row = result.rows[0];
|
|
49
|
+
const major = Math.floor(Number(row?.[0] ?? "0") / 1e4);
|
|
50
|
+
const defined = row?.[1] !== null && row?.[1] !== undefined;
|
|
51
|
+
if (major >= 18 || defined)
|
|
52
|
+
return;
|
|
53
|
+
const where = found.column === undefined ? "A column" : `Column ${found.column}`;
|
|
54
|
+
throw new OkmError2("OKM1812", `${where} has a uuidv7() default (migration ${found.migrationId}, step ${String(found.stepIndex)}), and the server is PostgreSQL ${String(major)}. uuidv7() arrives in PostgreSQL 18. Nothing was changed.`, {
|
|
55
|
+
fix: {
|
|
56
|
+
summary: 'Either run PostgreSQL 18 and declare schema({ requires: { postgres: ">=18" } }), or use t.id({ default: "uuidv4" }) (or schema({ defaults: { id: "uuidv4" } })), which uses gen_random_uuid() and works on PostgreSQL 13 and newer. Then delete the migration that was not applied and generate it again.'
|
|
57
|
+
}
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
function columnOf(sql) {
|
|
61
|
+
const table = TABLE.exec(sql)?.[1];
|
|
62
|
+
if (table === undefined)
|
|
63
|
+
return;
|
|
64
|
+
const line = sql.split(`
|
|
65
|
+
`).find((text) => DEFAULT_UUIDV7.test(text));
|
|
66
|
+
const column = line === undefined ? undefined : COLUMN.exec(line)?.[1];
|
|
67
|
+
if (column === undefined)
|
|
68
|
+
return;
|
|
69
|
+
return `${unquote(table)}.${unquote(column)}`;
|
|
70
|
+
}
|
|
71
|
+
function unquote(name) {
|
|
72
|
+
return name.startsWith('"') ? name.slice(1, -1).replaceAll('""', '"') : name;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
// src/tooling/migrate/apply.ts
|
|
25
76
|
var DEFAULT_LOCK_MS = 5000;
|
|
26
77
|
var DEFAULT_STATEMENT_MS = 30000;
|
|
27
78
|
var DEFAULT_RETRIES = 3;
|
|
@@ -100,6 +151,7 @@ async function applyTarget(request) {
|
|
|
100
151
|
await lockTarget(connection, request.target);
|
|
101
152
|
locked = true;
|
|
102
153
|
request.onLocked?.();
|
|
154
|
+
await assertUuidV7Available(connection, request.migrations);
|
|
103
155
|
await connection.execute(META);
|
|
104
156
|
await connection.execute(HISTORY);
|
|
105
157
|
const done = await readDone(connection);
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import {
|
|
2
|
+
definition,
|
|
3
|
+
unavailable
|
|
4
|
+
} from "./xatfg0gn.js";
|
|
5
|
+
|
|
6
|
+
// src/dialects/pg/trait.ts
|
|
7
|
+
var TRAIT_KEYS = new Set(["fields", "name", "presets", "sealed", "touch"]);
|
|
8
|
+
function checkTrait(value, where) {
|
|
9
|
+
if (!isRecord(value))
|
|
10
|
+
definition(`${where} traits must be a list of traits.`);
|
|
11
|
+
for (const key of Object.keys(value)) {
|
|
12
|
+
if (key === "methods" || key === "requires") {
|
|
13
|
+
unavailable(`Trait option ${key} is not available yet. It arrives in 0.2.`);
|
|
14
|
+
}
|
|
15
|
+
if (!TRAIT_KEYS.has(key)) {
|
|
16
|
+
definition(`${where} trait option ${key} is not supported. Accepted options: fields, name, presets, sealed, touch.`);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
const name = value.name;
|
|
20
|
+
if (typeof name !== "string" || name.length === 0)
|
|
21
|
+
definition(`${where} trait needs a name.`);
|
|
22
|
+
const fields = value.fields;
|
|
23
|
+
if (!isRecord(fields))
|
|
24
|
+
definition(`Trait ${name} needs a fields object.`);
|
|
25
|
+
const known = Object.keys(fields);
|
|
26
|
+
readNames(value.touch, name, "touch", known);
|
|
27
|
+
readNames(value.sealed, name, "sealed", known);
|
|
28
|
+
return value;
|
|
29
|
+
}
|
|
30
|
+
function contributedFields(schemaTraits, options) {
|
|
31
|
+
const chosen = choose(options?.omitDefaults === undefined ? schemaTraits : undefined, options?.traits);
|
|
32
|
+
if (chosen === undefined)
|
|
33
|
+
return [];
|
|
34
|
+
const pairs = [];
|
|
35
|
+
const seen = new Set;
|
|
36
|
+
for (const trait of chosen) {
|
|
37
|
+
for (const field of Object.keys(trait.fields)) {
|
|
38
|
+
if (seen.has(field))
|
|
39
|
+
continue;
|
|
40
|
+
const builder = trait.fields[field];
|
|
41
|
+
if (builder === undefined)
|
|
42
|
+
continue;
|
|
43
|
+
seen.add(field);
|
|
44
|
+
pairs.push([field, builder]);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
return pairs;
|
|
48
|
+
}
|
|
49
|
+
function choose(schemaTraits, local) {
|
|
50
|
+
const shared = schemaTraits ?? [];
|
|
51
|
+
const own = local ?? [];
|
|
52
|
+
if (shared.length === 0 && own.length === 0)
|
|
53
|
+
return;
|
|
54
|
+
if (own.length === 0)
|
|
55
|
+
return shared;
|
|
56
|
+
if (shared.length === 0)
|
|
57
|
+
return own;
|
|
58
|
+
return [...shared, ...own];
|
|
59
|
+
}
|
|
60
|
+
function readNames(value, traitName, label, known) {
|
|
61
|
+
if (value === undefined)
|
|
62
|
+
return;
|
|
63
|
+
if (!Array.isArray(value))
|
|
64
|
+
definition(`Trait ${traitName} ${label} must be a list of field names.`);
|
|
65
|
+
for (const field of value) {
|
|
66
|
+
if (typeof field === "string" && known.includes(field))
|
|
67
|
+
continue;
|
|
68
|
+
definition(`Trait ${traitName} ${label} names ${String(field)}, which is not one of its fields. Accepted fields: ${known.join(", ")}.`);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
function isRecord(value) {
|
|
72
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
export { checkTrait, contributedFields };
|