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.
- package/README.md +727 -37
- 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/enum.d.ts +31 -4
- package/dist/contracts/catalog/extension.d.ts +61 -0
- package/dist/contracts/catalog/object.d.ts +1 -0
- package/dist/contracts/catalog/privilege.d.ts +64 -0
- package/dist/contracts/catalog/routine.d.ts +56 -0
- package/dist/contracts/catalog/types.d.ts +179 -18
- package/dist/contracts/catalog/view.d.ts +73 -0
- 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 +129 -10
- package/dist/dialects/pg/compile.d.ts +1 -0
- package/dist/dialects/pg/custom.d.ts +6 -0
- package/dist/dialects/pg/ddl.d.ts +65 -1
- package/dist/dialects/pg/enum.d.ts +10 -8
- package/dist/dialects/pg/ext/citext.d.ts +14 -0
- package/dist/dialects/pg/ext/citext.js +11 -0
- package/dist/dialects/pg/ext/index.d.ts +52 -0
- package/dist/dialects/pg/ext/index.js +6 -0
- package/dist/dialects/pg/ext/pg-trgm.d.ts +53 -0
- package/dist/dialects/pg/ext/pg-trgm.js +42 -0
- package/dist/dialects/pg/filter-parse.d.ts +19 -0
- package/dist/dialects/pg/filters.d.ts +19 -0
- package/dist/dialects/pg/fn/index.d.ts +107 -0
- package/dist/dialects/pg/fn/index.js +175 -0
- package/dist/dialects/pg/fn/touch.d.ts +14 -0
- package/dist/dialects/pg/index.d.ts +11 -2
- package/dist/dialects/pg/index.js +243 -1062
- package/dist/dialects/pg/introspect.d.ts +10 -1
- 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 +46 -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/role/check.d.ts +45 -0
- package/dist/dialects/pg/role/index.d.ts +50 -0
- package/dist/dialects/pg/role/sql.d.ts +44 -0
- package/dist/dialects/pg/schema.d.ts +109 -5
- package/dist/dialects/pg/table.d.ts +137 -11
- package/dist/dialects/pg/temporal.d.ts +9 -7
- package/dist/dialects/pg/tenancy.d.ts +103 -0
- package/dist/dialects/pg/through.d.ts +21 -0
- package/dist/dialects/pg/trait.d.ts +141 -0
- package/dist/dialects/pg/view/client.d.ts +30 -0
- package/dist/dialects/pg/view/depend.d.ts +35 -0
- package/dist/dialects/pg/view/index.d.ts +114 -0
- package/dist/dialects/pg/view/index.js +289 -0
- package/dist/dialects/pg/view/scratch.d.ts +21 -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 +368 -0
- package/dist/runtime/trait-read.d.ts +30 -0
- package/dist/runtime/traits/index.d.ts +133 -0
- package/dist/runtime/traits/index.js +646 -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/01yr20s5.js +149 -0
- package/dist/shared/0jc3ffzf.js +154 -0
- package/dist/shared/0v1g424p.js +26 -0
- package/dist/shared/1g0drakv.js +225 -0
- package/dist/shared/{kprcwaha.js → 1tfdfvhh.js} +5 -3
- package/dist/shared/{05w44d8g.js → 2ssqrv66.js} +767 -715
- package/dist/shared/3ekj9x92.js +210 -0
- package/dist/shared/49ypnfwt.js +1122 -0
- package/dist/shared/4e4c6vq2.js +62 -0
- package/dist/shared/4m9fn52z.js +70 -0
- package/dist/shared/{ycwz42az.js → 52szzakm.js} +6 -26
- package/dist/shared/5nmdenb6.js +1229 -0
- package/dist/shared/672t5vym.js +12 -0
- package/dist/shared/6bazvqwm.js +86 -0
- package/dist/shared/6w5j844a.js +201 -0
- package/dist/shared/{fgqgsb5z.js → 75xkjv0t.js} +2 -2
- package/dist/shared/7fvtrkwr.js +84 -0
- package/dist/shared/7m88x3e9.js +45 -0
- package/dist/shared/{mtkwv8wx.js → 7p2wbz7f.js} +1 -1
- package/dist/shared/83eaefwr.js +10 -0
- package/dist/shared/94ez8kzh.js +19 -0
- package/dist/shared/96ps4g1z.js +32 -0
- package/dist/shared/{xqbhg6cn.js → 999ade2q.js} +95 -10
- package/dist/shared/9m80mkac.js +158 -0
- package/dist/shared/9x25fxhc.js +150 -0
- package/dist/shared/a5sxz52y.js +13 -0
- package/dist/shared/axhk06q1.js +156 -0
- package/dist/shared/{dynq16vb.js → b066g80h.js} +8 -6
- package/dist/shared/bqha5cg6.js +229 -0
- package/dist/shared/bryqk9k9.js +31 -0
- package/dist/shared/c8aghh05.js +442 -0
- package/dist/shared/c9z5g0fm.js +309 -0
- package/dist/shared/{m3ypagh5.js → dbjej1tw.js} +124 -15
- package/dist/shared/dyj86cmj.js +69 -0
- package/dist/shared/e6wg00wd.js +164 -0
- package/dist/shared/{hadrfb9h.js → edwqqryd.js} +17 -14
- package/dist/shared/{qk3hxfja.js → fptpmvxp.js} +5 -5
- package/dist/shared/fs0ex00p.js +76 -0
- package/dist/shared/{jjb7yht9.js → g4f5kcx9.js} +3 -3
- package/dist/shared/gjthds9j.js +48 -0
- package/dist/shared/hcmdtwgh.js +102 -0
- package/dist/shared/{g5fhqmwe.js → jkc6ws1p.js} +6 -56
- package/dist/shared/{yd1kzwn2.js → jns2wx4t.js} +55 -12
- package/dist/shared/k34e0xf2.js +450 -0
- package/dist/shared/k3ted12y.js +33 -0
- package/dist/shared/k7dwkhvq.js +31 -0
- package/dist/shared/{8b04d28c.js → kgnc8grt.js} +2 -2
- package/dist/shared/{hd293j9g.js → kyxb62mc.js} +14 -2
- package/dist/shared/m78s7898.js +376 -0
- package/dist/shared/m9tv7xn7.js +404 -0
- package/dist/shared/meck53jv.js +99 -0
- package/dist/shared/mt5wswjz.js +90 -0
- package/dist/shared/n0dgs0pb.js +75 -0
- package/dist/shared/n442h54c.js +14 -0
- package/dist/shared/n4jqhpqz.js +27 -0
- package/dist/shared/n7mcc1gk.js +132 -0
- package/dist/shared/ne02ng5c.js +68 -0
- package/dist/shared/{mkjmqjv4.js → nfzc5z0w.js} +2 -104
- package/dist/shared/nsva2a6b.js +42 -0
- package/dist/shared/p24x2334.js +195 -0
- package/dist/shared/qbxzvwwc.js +88 -0
- package/dist/shared/{w8samvk1.js → qybh48nd.js} +1 -1
- package/dist/shared/r6nwkxnt.js +86 -0
- package/dist/shared/{xy79j5hq.js → rrstp3kb.js} +25 -36
- package/dist/shared/rwmrejjz.js +26 -0
- package/dist/shared/{zhc5vmgf.js → s6gqfn5j.js} +2 -2
- package/dist/shared/{523ft3e8.js → scwxrpx2.js} +7 -5
- package/dist/shared/{j5cn2963.js → t4tbsy9h.js} +13 -64
- package/dist/shared/{y9m15dfv.js → t616ynfn.js} +544 -32
- package/dist/shared/{ngk8gj61.js → tbszx8mz.js} +15 -1
- package/dist/shared/th14ygv2.js +69 -0
- package/dist/shared/tmbdywx0.js +178 -0
- package/dist/shared/ty3v3hfk.js +64 -0
- package/dist/shared/wekze34d.js +246 -0
- package/dist/shared/x6wysh83.js +1132 -0
- package/dist/shared/{rgs0st28.js → xrfnq5k8.js} +237 -434
- package/dist/shared/{x5x59srr.js → xva8v7qk.js} +416 -83
- package/dist/shared/{dkn3y60a.js → xw1d69vd.js} +76 -112
- package/dist/shared/y005b761.js +112 -0
- package/dist/shared/ydaz1sv3.js +55 -0
- package/dist/shared/{p0cbr3g2.js → zwmqxb0g.js} +1 -1
- package/dist/tooling/cli.js +40 -12
- package/dist/tooling/migrate/apply.d.ts +16 -0
- package/dist/tooling/migrate/commands.d.ts +12 -1
- package/dist/tooling/migrate/config.d.ts +8 -0
- package/dist/tooling/migrate/doctor.d.ts +25 -0
- package/dist/tooling/migrate/drift.d.ts +19 -0
- package/dist/tooling/migrate/engine.d.ts +36 -0
- package/dist/tooling/migrate/ext.d.ts +17 -0
- package/dist/tooling/migrate/extensions.d.ts +51 -0
- package/dist/tooling/migrate/managed.d.ts +17 -0
- package/dist/tooling/migrate/plan.d.ts +14 -1
- package/dist/tooling/migrate/project.d.ts +25 -1
- package/dist/tooling/migrate/type-name.d.ts +19 -0
- package/package.json +61 -4
- package/dist/shared/gk7cs7sp.js +0 -566
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
import {
|
|
2
|
+
noticeBuffer,
|
|
3
|
+
WireSession,
|
|
4
|
+
cursorStream
|
|
5
|
+
} from "./0jc3ffzf.js";
|
|
6
|
+
import {
|
|
7
|
+
BUNSQL_CAPABILITIES,
|
|
8
|
+
driverErrors,
|
|
9
|
+
rejectClosed,
|
|
10
|
+
mapFailure,
|
|
11
|
+
runCall
|
|
12
|
+
} from "./rrstp3kb.js";
|
|
13
|
+
|
|
14
|
+
// src/adapters/pg/bunsql.ts
|
|
15
|
+
import { SQL } from "bun";
|
|
16
|
+
function open5(config) {
|
|
17
|
+
const max = config.max ?? 10;
|
|
18
|
+
const acquireMs = config.timeouts?.acquire;
|
|
19
|
+
const counters = { reserved: 0, busy: 0, reservedBusy: 0, waiting: 0 };
|
|
20
|
+
const notices = noticeBuffer();
|
|
21
|
+
let closed = false;
|
|
22
|
+
const isClosed = () => closed;
|
|
23
|
+
const named = config.prepared === "named";
|
|
24
|
+
const parked = [];
|
|
25
|
+
const sql = new SQL(config.url, {
|
|
26
|
+
max,
|
|
27
|
+
idleTimeout: 0,
|
|
28
|
+
maxLifetime: 0,
|
|
29
|
+
prepare: named,
|
|
30
|
+
bigint: false,
|
|
31
|
+
connectionTimeout: 5,
|
|
32
|
+
connection: {
|
|
33
|
+
application_name: "okmodel",
|
|
34
|
+
...config.searchPath !== undefined ? { search_path: config.searchPath } : {}
|
|
35
|
+
},
|
|
36
|
+
...config.ssl !== undefined ? { tls: config.ssl } : {}
|
|
37
|
+
});
|
|
38
|
+
const root = new WireSession((text, params) => send2(sql, text, params), notices, isClosed, false, () => {
|
|
39
|
+
counters.busy += 1;
|
|
40
|
+
}, () => {
|
|
41
|
+
counters.busy = Math.max(0, counters.busy - 1);
|
|
42
|
+
});
|
|
43
|
+
const held = { sql, parked, acquireMs, counters, notices, isClosed };
|
|
44
|
+
const checkout = () => closed ? rejectClosed() : import("./fs0ex00p.js").then((mod) => mod.checkout(held));
|
|
45
|
+
return {
|
|
46
|
+
capabilities: BUNSQL_CAPABILITIES,
|
|
47
|
+
execute(text, params, options) {
|
|
48
|
+
return runCall(closed, options, async (watch) => {
|
|
49
|
+
await releaseParked(parked);
|
|
50
|
+
return root.query(text, params, watch);
|
|
51
|
+
});
|
|
52
|
+
},
|
|
53
|
+
async batch(statements, options) {
|
|
54
|
+
const connection = await checkout();
|
|
55
|
+
try {
|
|
56
|
+
return await connection.batch(statements, options);
|
|
57
|
+
} finally {
|
|
58
|
+
await connection.release();
|
|
59
|
+
}
|
|
60
|
+
},
|
|
61
|
+
reserve: () => checkout(),
|
|
62
|
+
stream(text, params) {
|
|
63
|
+
return stream(text, params);
|
|
64
|
+
},
|
|
65
|
+
listen(channel, onNotify) {
|
|
66
|
+
return listen(channel, onNotify);
|
|
67
|
+
},
|
|
68
|
+
stats: () => statsOf(counters, max),
|
|
69
|
+
async close() {
|
|
70
|
+
closed = true;
|
|
71
|
+
await releaseParked(parked);
|
|
72
|
+
await sql.close();
|
|
73
|
+
}
|
|
74
|
+
};
|
|
75
|
+
function stream(text, params) {
|
|
76
|
+
return async function* () {
|
|
77
|
+
const connection = await checkout();
|
|
78
|
+
try {
|
|
79
|
+
yield* cursorStream((statement, values) => connection.execute(statement, values), text, params);
|
|
80
|
+
} finally {
|
|
81
|
+
await connection.release();
|
|
82
|
+
}
|
|
83
|
+
}();
|
|
84
|
+
}
|
|
85
|
+
async function listen(channel, onNotify) {
|
|
86
|
+
if (closed)
|
|
87
|
+
return rejectClosed();
|
|
88
|
+
await releaseParked(parked);
|
|
89
|
+
const subscription = await sql.listen(channel, onNotify);
|
|
90
|
+
return async () => {
|
|
91
|
+
await subscription.unlisten();
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
function send2(sql, text, params) {
|
|
96
|
+
if (params === undefined || params.length === 0)
|
|
97
|
+
return sql.unsafe(text).raw();
|
|
98
|
+
return sql.unsafe(text, [...params]).raw();
|
|
99
|
+
}
|
|
100
|
+
async function reserve(sql, acquireMs, counters) {
|
|
101
|
+
counters.waiting += 1;
|
|
102
|
+
try {
|
|
103
|
+
if (acquireMs === undefined)
|
|
104
|
+
return await sql.reserve();
|
|
105
|
+
return await sql.reserve({ signal: AbortSignal.timeout(acquireMs) });
|
|
106
|
+
} catch (error) {
|
|
107
|
+
if (isAbort(error)) {
|
|
108
|
+
const errors = await driverErrors();
|
|
109
|
+
throw errors.acquireTimeout();
|
|
110
|
+
}
|
|
111
|
+
throw await mapFailure(error);
|
|
112
|
+
} finally {
|
|
113
|
+
counters.waiting = Math.max(0, counters.waiting - 1);
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
async function park(parked, reserved) {
|
|
117
|
+
parked.push(reserved);
|
|
118
|
+
while (parked.length > 1) {
|
|
119
|
+
const extra = parked.shift();
|
|
120
|
+
if (extra !== undefined)
|
|
121
|
+
await releaseReserved(extra);
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
async function releaseParked(parked) {
|
|
125
|
+
const pending = parked.splice(0);
|
|
126
|
+
for (const reserved of pending)
|
|
127
|
+
await releaseReserved(reserved);
|
|
128
|
+
}
|
|
129
|
+
function releaseReserved(reserved) {
|
|
130
|
+
const done = reserved.release();
|
|
131
|
+
return done instanceof Promise ? done.then(() => {
|
|
132
|
+
return;
|
|
133
|
+
}) : Promise.resolve();
|
|
134
|
+
}
|
|
135
|
+
function isAbort(error) {
|
|
136
|
+
if (!(error instanceof Error))
|
|
137
|
+
return false;
|
|
138
|
+
return error.name === "AbortError" || error.name === "TimeoutError";
|
|
139
|
+
}
|
|
140
|
+
function statsOf(counters, size) {
|
|
141
|
+
return {
|
|
142
|
+
size,
|
|
143
|
+
idle: Math.max(0, size - counters.reserved - counters.busy),
|
|
144
|
+
inflight: counters.busy + counters.reservedBusy,
|
|
145
|
+
waiting: counters.waiting
|
|
146
|
+
};
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
export { open5, send2, reserve, park };
|
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
import {
|
|
2
|
+
driverErrors,
|
|
3
|
+
rejectClosed,
|
|
4
|
+
nextTransactionDepth,
|
|
5
|
+
EMPTY_NOTICES,
|
|
6
|
+
resultFrom
|
|
7
|
+
} from "./rrstp3kb.js";
|
|
8
|
+
|
|
9
|
+
// src/adapters/pg/session.ts
|
|
10
|
+
function quoteIdent2(name) {
|
|
11
|
+
return `"${name.replaceAll('"', '""')}"`;
|
|
12
|
+
}
|
|
13
|
+
function noticeBuffer() {
|
|
14
|
+
let notices;
|
|
15
|
+
return {
|
|
16
|
+
push(notice) {
|
|
17
|
+
const severity = notice.severity ?? "";
|
|
18
|
+
const message = notice.message ?? "";
|
|
19
|
+
const code = notice.code !== undefined && notice.code.length > 0 ? notice.code : undefined;
|
|
20
|
+
const entry = code === undefined ? { severity, message } : { severity, message, code };
|
|
21
|
+
(notices ??= []).push(entry);
|
|
22
|
+
},
|
|
23
|
+
start() {
|
|
24
|
+
return notices?.length ?? 0;
|
|
25
|
+
},
|
|
26
|
+
since(start) {
|
|
27
|
+
if (notices === undefined || notices.length === start)
|
|
28
|
+
return EMPTY_NOTICES;
|
|
29
|
+
return notices.slice(start);
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
class WireSession {
|
|
35
|
+
canCancel;
|
|
36
|
+
transactionDepth = 0;
|
|
37
|
+
local = new Set;
|
|
38
|
+
send;
|
|
39
|
+
notices;
|
|
40
|
+
isClosed;
|
|
41
|
+
onEnter;
|
|
42
|
+
onLeave;
|
|
43
|
+
shared;
|
|
44
|
+
constructor(send, notices, isClosed, canCancel, onEnter, onLeave, shared) {
|
|
45
|
+
this.send = send;
|
|
46
|
+
this.notices = notices;
|
|
47
|
+
this.isClosed = isClosed;
|
|
48
|
+
this.canCancel = canCancel;
|
|
49
|
+
this.onEnter = onEnter;
|
|
50
|
+
this.onLeave = onLeave;
|
|
51
|
+
this.shared = shared;
|
|
52
|
+
}
|
|
53
|
+
query(text, params, watch) {
|
|
54
|
+
if (this.isClosed())
|
|
55
|
+
return rejectClosed();
|
|
56
|
+
const start = this.notices.start();
|
|
57
|
+
this.onEnter();
|
|
58
|
+
const pending = this.send(text, params);
|
|
59
|
+
if (watch === undefined) {
|
|
60
|
+
return pending.then((result) => {
|
|
61
|
+
this.onLeave();
|
|
62
|
+
this.note(text);
|
|
63
|
+
return resultFrom(result, this.notices.since(start));
|
|
64
|
+
}, (error) => {
|
|
65
|
+
this.onLeave();
|
|
66
|
+
return driverErrors().then((errors) => Promise.reject(errors.mapDriverError(error)));
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
return this.watched(pending, watch, start, text);
|
|
70
|
+
}
|
|
71
|
+
inTransaction() {
|
|
72
|
+
return this.transactionDepth > 0;
|
|
73
|
+
}
|
|
74
|
+
abandon() {
|
|
75
|
+
this.transactionDepth = 0;
|
|
76
|
+
}
|
|
77
|
+
depth() {
|
|
78
|
+
return this.transactionDepth;
|
|
79
|
+
}
|
|
80
|
+
cancel() {
|
|
81
|
+
for (const pending of this.local)
|
|
82
|
+
pending.cancel?.();
|
|
83
|
+
}
|
|
84
|
+
note(text) {
|
|
85
|
+
this.transactionDepth = nextTransactionDepth(this.transactionDepth, text);
|
|
86
|
+
}
|
|
87
|
+
track(pending) {
|
|
88
|
+
this.local.add(pending);
|
|
89
|
+
this.shared?.add(pending);
|
|
90
|
+
}
|
|
91
|
+
untrack(pending) {
|
|
92
|
+
this.local.delete(pending);
|
|
93
|
+
this.shared?.delete(pending);
|
|
94
|
+
}
|
|
95
|
+
watched(pending, watch, start, text) {
|
|
96
|
+
this.track(pending);
|
|
97
|
+
const onAbort = () => {
|
|
98
|
+
pending.cancel?.();
|
|
99
|
+
};
|
|
100
|
+
if (watch.signal.aborted)
|
|
101
|
+
onAbort();
|
|
102
|
+
else
|
|
103
|
+
watch.signal.addEventListener("abort", onAbort, { once: true });
|
|
104
|
+
return pending.then((result) => {
|
|
105
|
+
this.finishWatched(pending, watch, onAbort);
|
|
106
|
+
const why = watch.reason();
|
|
107
|
+
if (why === "timeout" || why === "cancelled")
|
|
108
|
+
return classify(why, watch);
|
|
109
|
+
this.note(text);
|
|
110
|
+
return resultFrom(result, this.notices.since(start));
|
|
111
|
+
}, (error) => {
|
|
112
|
+
this.finishWatched(pending, watch, onAbort);
|
|
113
|
+
return classify(error, watch);
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
finishWatched(pending, watch, onAbort) {
|
|
117
|
+
this.onLeave();
|
|
118
|
+
this.untrack(pending);
|
|
119
|
+
watch.signal.removeEventListener("abort", onAbort);
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
async function* cursorStream(run, text, params) {
|
|
123
|
+
const name = "okm_stream";
|
|
124
|
+
await run("BEGIN");
|
|
125
|
+
try {
|
|
126
|
+
await run(`DECLARE ${name} NO SCROLL CURSOR FOR ${text}`, params);
|
|
127
|
+
for (;; ) {
|
|
128
|
+
const chunk = await run(`FETCH 64 FROM ${name}`);
|
|
129
|
+
if (chunk.rows.length === 0)
|
|
130
|
+
break;
|
|
131
|
+
yield chunk.rows;
|
|
132
|
+
}
|
|
133
|
+
} finally {
|
|
134
|
+
await run("ROLLBACK").catch(() => {
|
|
135
|
+
return;
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
async function classify(error, watch) {
|
|
140
|
+
const errors = await driverErrors();
|
|
141
|
+
if (error instanceof errors.DriverError)
|
|
142
|
+
return Promise.reject(error);
|
|
143
|
+
const why = typeof error === "string" ? error : watch.reason();
|
|
144
|
+
if (why === "timeout") {
|
|
145
|
+
return Promise.reject(errors.timedOut(typeof error === "string" ? undefined : error));
|
|
146
|
+
}
|
|
147
|
+
const code = errors.errorField(error, "code") ?? errors.errorField(error, "errno");
|
|
148
|
+
if (why === "cancelled" || code === "57014") {
|
|
149
|
+
return Promise.reject(errors.cancelled(typeof error === "string" ? undefined : error));
|
|
150
|
+
}
|
|
151
|
+
return Promise.reject(errors.mapDriverError(error));
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
export { quoteIdent2, noticeBuffer, WireSession, cursorStream };
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import {
|
|
2
|
+
OkmError2
|
|
3
|
+
} from "./52szzakm.js";
|
|
4
|
+
|
|
5
|
+
// src/dialects/pg/filter-parse.ts
|
|
6
|
+
function parseQuery(allow, sort, query) {
|
|
7
|
+
if (typeof query !== "object" || query === null || Array.isArray(query)) {
|
|
8
|
+
throw new OkmError2("OKM1121", "filters parse expects an object of fields.");
|
|
9
|
+
}
|
|
10
|
+
const where = {};
|
|
11
|
+
let orderBy;
|
|
12
|
+
for (const key of Object.keys(query)) {
|
|
13
|
+
const value = query[key];
|
|
14
|
+
if (key === "sort" && typeof value === "string" && sort.includes(value)) {
|
|
15
|
+
orderBy = { [value]: "asc" };
|
|
16
|
+
continue;
|
|
17
|
+
}
|
|
18
|
+
if (allow[key]?.includes("eq") === true && (value === null || typeof value !== "object")) {
|
|
19
|
+
where[key] = value;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
return orderBy === undefined ? { where } : { where, orderBy };
|
|
23
|
+
}
|
|
24
|
+
export {
|
|
25
|
+
parseQuery
|
|
26
|
+
};
|
|
@@ -0,0 +1,225 @@
|
|
|
1
|
+
import {
|
|
2
|
+
required
|
|
3
|
+
} from "./c9z5g0fm.js";
|
|
4
|
+
import {
|
|
5
|
+
definition,
|
|
6
|
+
rejected
|
|
7
|
+
} from "./tmbdywx0.js";
|
|
8
|
+
|
|
9
|
+
// src/dialects/pg/temporal.ts
|
|
10
|
+
var TEMPORAL_MISSING = "Date and time codecs need the Temporal global. okmodel does not ship a polyfill. Use a runtime that provides Temporal, or assign a polyfill to globalThis.Temporal before using these columns.";
|
|
11
|
+
function requireTemporal() {
|
|
12
|
+
const temporal = globalThis.Temporal;
|
|
13
|
+
if (typeof temporal !== "object" || temporal === null || !("Instant" in temporal)) {
|
|
14
|
+
rejected(TEMPORAL_MISSING);
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
function timePrecision(precision, role) {
|
|
18
|
+
if (precision === undefined) {
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
if (!Number.isInteger(precision) || precision < 0 || precision > 6) {
|
|
22
|
+
definition(`${role} precision ${String(precision)} must be an integer from 0 to 6.`);
|
|
23
|
+
}
|
|
24
|
+
return precision;
|
|
25
|
+
}
|
|
26
|
+
function encodeInstant(value, precision) {
|
|
27
|
+
requireTemporal();
|
|
28
|
+
if (precision === undefined) {
|
|
29
|
+
return value.toString();
|
|
30
|
+
}
|
|
31
|
+
return value.toString({ fractionalSecondDigits: precision });
|
|
32
|
+
}
|
|
33
|
+
function decodeInstant(wire) {
|
|
34
|
+
requireTemporal();
|
|
35
|
+
try {
|
|
36
|
+
return Temporal.Instant.from(wire);
|
|
37
|
+
} catch {
|
|
38
|
+
rejected(`timestamptz ${wire} must be an ISO-8601 instant, for example 2020-01-01T00:00:00Z.`);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
function encodeDateTime(value, precision) {
|
|
42
|
+
requireTemporal();
|
|
43
|
+
if (precision === undefined) {
|
|
44
|
+
return value.toString();
|
|
45
|
+
}
|
|
46
|
+
return value.toString({ fractionalSecondDigits: precision });
|
|
47
|
+
}
|
|
48
|
+
function decodeDateTime(wire) {
|
|
49
|
+
requireTemporal();
|
|
50
|
+
try {
|
|
51
|
+
return Temporal.PlainDateTime.from(wire);
|
|
52
|
+
} catch {
|
|
53
|
+
rejected(`timestamp ${wire} must be an ISO-8601 date-time without a zone, for example 2020-01-01T00:00:00.`);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
function encodeDate(value) {
|
|
57
|
+
requireTemporal();
|
|
58
|
+
return value.toString();
|
|
59
|
+
}
|
|
60
|
+
function decodeDate(wire) {
|
|
61
|
+
requireTemporal();
|
|
62
|
+
try {
|
|
63
|
+
return Temporal.PlainDate.from(wire);
|
|
64
|
+
} catch {
|
|
65
|
+
rejected(`date ${wire} must be YYYY-MM-DD.`);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
function encodeTime(value, precision) {
|
|
69
|
+
requireTemporal();
|
|
70
|
+
if (precision === undefined) {
|
|
71
|
+
return value.toString();
|
|
72
|
+
}
|
|
73
|
+
return value.toString({ fractionalSecondDigits: precision });
|
|
74
|
+
}
|
|
75
|
+
function decodeTime(wire) {
|
|
76
|
+
requireTemporal();
|
|
77
|
+
try {
|
|
78
|
+
return Temporal.PlainTime.from(wire);
|
|
79
|
+
} catch {
|
|
80
|
+
rejected(`time ${wire} must be a time of day, for example 00:00:00.`);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
function encodeTimeZone(value, precision) {
|
|
84
|
+
requireTemporal();
|
|
85
|
+
if (!offsetText().test(value.offset)) {
|
|
86
|
+
rejected(`timetz offset ${value.offset} must be ±HH:MM.`);
|
|
87
|
+
}
|
|
88
|
+
return `${encodeTime(value.time, precision)}${value.offset}`;
|
|
89
|
+
}
|
|
90
|
+
function decodeTimeZone(wire) {
|
|
91
|
+
const match = timeZoneText().exec(wire);
|
|
92
|
+
const time = match?.[1];
|
|
93
|
+
const hours = match?.[2];
|
|
94
|
+
if (time === undefined || hours === undefined) {
|
|
95
|
+
rejected(`timetz ${wire} must be a time of day plus ±HH or ±HH:MM, for example 00:00:00+00.`);
|
|
96
|
+
}
|
|
97
|
+
return { time: decodeTime(time), offset: `${hours}:${match?.[3] ?? "00"}` };
|
|
98
|
+
}
|
|
99
|
+
function encodeDuration(value) {
|
|
100
|
+
requireTemporal();
|
|
101
|
+
const text = value.toString();
|
|
102
|
+
return text.startsWith("-") ? text.slice(1).replace(/\d+(?:\.\d+)?(?=[A-Z])/g, "-$&") : text;
|
|
103
|
+
}
|
|
104
|
+
function decodeDuration(wire) {
|
|
105
|
+
requireTemporal();
|
|
106
|
+
const fields = {};
|
|
107
|
+
const rest = wire.replace(/([+-]?\d+) (year|mon|day)s?|([+-]?)(\d+):(\d{2}):(\d{2})(?:\.(\d{1,6}))?/g, (_part, count, unit, sign, h = "", m = "", s = "", f = "") => {
|
|
108
|
+
if (count !== undefined && unit !== undefined) {
|
|
109
|
+
fields[`${unit === "mon" ? "month" : unit}s`] = Number(count);
|
|
110
|
+
return "";
|
|
111
|
+
}
|
|
112
|
+
const micros = Number(f.padEnd(6, "0"));
|
|
113
|
+
const flip = sign === "-" ? -1 : 1;
|
|
114
|
+
fields.hours = flip * Number(h);
|
|
115
|
+
fields.minutes = flip * Number(m);
|
|
116
|
+
fields.seconds = flip * Number(s);
|
|
117
|
+
fields.milliseconds = flip * Math.trunc(micros / 1000);
|
|
118
|
+
fields.microseconds = flip * (micros % 1000);
|
|
119
|
+
return "";
|
|
120
|
+
});
|
|
121
|
+
try {
|
|
122
|
+
return Temporal.Duration.from(rest.trim() === "" && wire !== "" ? fields : wire);
|
|
123
|
+
} catch {
|
|
124
|
+
rejected(`interval ${wire} must be what Postgres sends (for example 01:30:00 or 1 day 02:03:04) or an ISO-8601 duration (PT1H). Parts of different signs are not one Temporal.Duration.`);
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
function intervalFields(fields) {
|
|
128
|
+
switch (fields) {
|
|
129
|
+
case "year":
|
|
130
|
+
case "month":
|
|
131
|
+
case "day":
|
|
132
|
+
case "hour":
|
|
133
|
+
case "minute":
|
|
134
|
+
case "second":
|
|
135
|
+
case "year to month":
|
|
136
|
+
case "day to hour":
|
|
137
|
+
case "day to minute":
|
|
138
|
+
case "day to second":
|
|
139
|
+
case "hour to minute":
|
|
140
|
+
case "hour to second":
|
|
141
|
+
case "minute to second":
|
|
142
|
+
return fields;
|
|
143
|
+
default:
|
|
144
|
+
definition(`interval fields ${fields} must be one of: year, month, day, hour, minute, second, year to month, day to hour, day to minute, day to second, hour to minute, hour to second, minute to second.`);
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
function offsetText() {
|
|
148
|
+
offsetPattern ??= /^[+-]\d{2}:\d{2}$/;
|
|
149
|
+
return offsetPattern;
|
|
150
|
+
}
|
|
151
|
+
function timeZoneText() {
|
|
152
|
+
timeZonePattern ??= /^(.+?)([+-]\d{2})(?::(\d{2}))?$/;
|
|
153
|
+
return timeZonePattern;
|
|
154
|
+
}
|
|
155
|
+
var offsetPattern;
|
|
156
|
+
var timeZonePattern;
|
|
157
|
+
|
|
158
|
+
// src/dialects/pg/time.ts
|
|
159
|
+
function timestamptz2(precision) {
|
|
160
|
+
const digits = timePrecision(precision, "timestamptz");
|
|
161
|
+
return required({
|
|
162
|
+
baseType: timed("timestamptz", digits),
|
|
163
|
+
encode: (value) => encodeInstant(value, digits),
|
|
164
|
+
decode: decodeInstant,
|
|
165
|
+
accepts: ["Temporal.Instant"],
|
|
166
|
+
sqlForm: "quote"
|
|
167
|
+
});
|
|
168
|
+
}
|
|
169
|
+
function timestamp2(precision) {
|
|
170
|
+
const digits = timePrecision(precision, "timestamp");
|
|
171
|
+
return required({
|
|
172
|
+
baseType: timed("timestamp", digits),
|
|
173
|
+
encode: (value) => encodeDateTime(value, digits),
|
|
174
|
+
decode: decodeDateTime,
|
|
175
|
+
accepts: ["Temporal.PlainDateTime"],
|
|
176
|
+
sqlForm: "quote"
|
|
177
|
+
});
|
|
178
|
+
}
|
|
179
|
+
function date2() {
|
|
180
|
+
return required({
|
|
181
|
+
baseType: "date",
|
|
182
|
+
encode: encodeDate,
|
|
183
|
+
decode: decodeDate,
|
|
184
|
+
accepts: ["Temporal.PlainDate"],
|
|
185
|
+
sqlForm: "quote"
|
|
186
|
+
});
|
|
187
|
+
}
|
|
188
|
+
function time2(precision) {
|
|
189
|
+
const digits = timePrecision(precision, "time");
|
|
190
|
+
return required({
|
|
191
|
+
baseType: timed("time", digits),
|
|
192
|
+
encode: (value) => encodeTime(value, digits),
|
|
193
|
+
decode: decodeTime,
|
|
194
|
+
accepts: ["Temporal.PlainTime"],
|
|
195
|
+
sqlForm: "quote"
|
|
196
|
+
});
|
|
197
|
+
}
|
|
198
|
+
function timetz2(precision) {
|
|
199
|
+
const digits = timePrecision(precision, "timetz");
|
|
200
|
+
return required({
|
|
201
|
+
baseType: timed("timetz", digits),
|
|
202
|
+
encode: (value) => encodeTimeZone(value, digits),
|
|
203
|
+
decode: decodeTimeZone,
|
|
204
|
+
accepts: ["Object"],
|
|
205
|
+
sqlForm: "quote"
|
|
206
|
+
});
|
|
207
|
+
}
|
|
208
|
+
function interval2(fields) {
|
|
209
|
+
const qualifier = fields === undefined ? undefined : intervalFields(fields);
|
|
210
|
+
return required({
|
|
211
|
+
baseType: qualifier === undefined ? "interval" : `interval ${qualifier}`,
|
|
212
|
+
encode: encodeDuration,
|
|
213
|
+
decode: decodeDuration,
|
|
214
|
+
accepts: ["Temporal.Duration"],
|
|
215
|
+
sqlForm: "quote"
|
|
216
|
+
});
|
|
217
|
+
}
|
|
218
|
+
function timed(name, precision) {
|
|
219
|
+
if (precision === undefined) {
|
|
220
|
+
return name;
|
|
221
|
+
}
|
|
222
|
+
return `${name}(${String(precision)})`;
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
export { encodeInstant, decodeInstant, encodeDate, decodeDate, timestamptz2, timestamp2, date2, time2, timetz2, interval2 };
|
|
@@ -1,8 +1,10 @@
|
|
|
1
|
-
import"./
|
|
1
|
+
import"./t616ynfn.js";
|
|
2
|
+
import"./n442h54c.js";
|
|
2
3
|
import {
|
|
3
4
|
listTargets,
|
|
4
5
|
loadConfig
|
|
5
|
-
} from "./
|
|
6
|
+
} from "./5nmdenb6.js";
|
|
7
|
+
import"./2ssqrv66.js";
|
|
6
8
|
|
|
7
9
|
// src/tooling/migrate/dev.ts
|
|
8
10
|
import { mkdirSync } from "node:fs";
|
|
@@ -15,7 +17,7 @@ async function devProject(cwd) {
|
|
|
15
17
|
`;
|
|
16
18
|
const directory = join(cwd, config.out ?? ".okm", "dev-db");
|
|
17
19
|
mkdirSync(directory, { recursive: true });
|
|
18
|
-
const { open } = await import("./
|
|
20
|
+
const { open } = await import("./kgnc8grt.js");
|
|
19
21
|
const pool = await open({ dataDir: directory });
|
|
20
22
|
try {
|
|
21
23
|
await pool.execute("select 1");
|