@capybara-hq/plugin-device-local 0.0.0-stage → 0.1.0-rc.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/.capybara-plugin/plugin.json +45 -0
- package/LICENSE +202 -0
- package/NOTICE +2 -0
- package/README.md +104 -2
- package/THIRD-PARTY-NOTICES.txt +26 -0
- package/dist/index.mjs +4881 -0
- package/guides/connect.md +51 -0
- package/guides/connect.zh.md +38 -0
- package/icon.svg +1 -0
- package/migrations/0001_init.sql +40 -0
- package/package.json +19 -4
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,4881 @@
|
|
|
1
|
+
import { createRequire as __capybaraCreateRequire } from "node:module";
|
|
2
|
+
import { fileURLToPath as __capybaraFileURLToPath } from "node:url";
|
|
3
|
+
import { dirname as __capybaraPathDirname } from "node:path";
|
|
4
|
+
const require = __capybaraCreateRequire(import.meta.url);
|
|
5
|
+
const __capybara_filename = __capybaraFileURLToPath(import.meta.url);
|
|
6
|
+
const __capybara_dirname = __capybaraPathDirname(__capybara_filename);
|
|
7
|
+
|
|
8
|
+
// src/index.ts
|
|
9
|
+
import {
|
|
10
|
+
DEVICE_PROVIDER_EXTENSION_POINT,
|
|
11
|
+
defineExtension
|
|
12
|
+
} from "@capybara-hq/plugin-sdk";
|
|
13
|
+
import { DEVICE_DIAL_IN_PROTOCOL } from "@capybara-hq/plugin-sdk/device-protocol";
|
|
14
|
+
|
|
15
|
+
// src/hello.ts
|
|
16
|
+
import {
|
|
17
|
+
parseDeviceFrame
|
|
18
|
+
} from "@capybara-hq/plugin-sdk/device-protocol";
|
|
19
|
+
|
|
20
|
+
// src/owner-report.ts
|
|
21
|
+
import {
|
|
22
|
+
parseOwnerCeilingReport
|
|
23
|
+
} from "@capybara-hq/plugin-sdk/device-protocol";
|
|
24
|
+
function storedOwnerReportOf(v) {
|
|
25
|
+
if (typeof v !== "object" || v === null || Array.isArray(v)) return null;
|
|
26
|
+
const o = v;
|
|
27
|
+
let report;
|
|
28
|
+
try {
|
|
29
|
+
report = parseOwnerCeilingReport(o.report);
|
|
30
|
+
} catch {
|
|
31
|
+
return null;
|
|
32
|
+
}
|
|
33
|
+
if (typeof o.observedAt !== "string") return null;
|
|
34
|
+
if (o.via !== "hello" && o.via !== "policy" && o.via !== "bind") return null;
|
|
35
|
+
const b = o.blocked;
|
|
36
|
+
return {
|
|
37
|
+
report,
|
|
38
|
+
observedAt: o.observedAt,
|
|
39
|
+
via: o.via,
|
|
40
|
+
...b && b.reason === "conflict" && typeof b.sequence === "number" && typeof b.at === "string" && {
|
|
41
|
+
blocked: { reason: "conflict", sequence: b.sequence, at: b.at }
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
var canonicalReport = (r) => ({
|
|
46
|
+
version: r.version,
|
|
47
|
+
revision: r.revision,
|
|
48
|
+
sequence: r.sequence,
|
|
49
|
+
outsideSandbox: r.outsideSandbox,
|
|
50
|
+
network: r.network,
|
|
51
|
+
allowedDomains: [...r.allowedDomains],
|
|
52
|
+
restrictedProjectReach: r.restrictedProjectReach
|
|
53
|
+
});
|
|
54
|
+
var sameOwnerReport = (a, b) => JSON.stringify(canonicalReport(a)) === JSON.stringify(canonicalReport(b));
|
|
55
|
+
function decideOwnerReport(stored, incoming) {
|
|
56
|
+
if (stored === null) return "record";
|
|
57
|
+
const prev = stored.report;
|
|
58
|
+
if (incoming.sequence > prev.sequence) return "record";
|
|
59
|
+
if (incoming.sequence < prev.sequence) return "stale";
|
|
60
|
+
return sameOwnerReport(incoming, prev) ? "same" : "conflict";
|
|
61
|
+
}
|
|
62
|
+
var FAIL_CLOSED = {
|
|
63
|
+
outsideSandbox: false,
|
|
64
|
+
restrictedProjectReach: "workspace",
|
|
65
|
+
allowedDomains: [],
|
|
66
|
+
network: "allowlist"
|
|
67
|
+
};
|
|
68
|
+
function ownerFactsOf(stored) {
|
|
69
|
+
if (stored === null) return { state: "missing", ...FAIL_CLOSED, revision: null, sequence: null };
|
|
70
|
+
if (stored.blocked)
|
|
71
|
+
return {
|
|
72
|
+
state: "blocked",
|
|
73
|
+
...FAIL_CLOSED,
|
|
74
|
+
revision: stored.report.revision,
|
|
75
|
+
sequence: stored.report.sequence
|
|
76
|
+
};
|
|
77
|
+
return {
|
|
78
|
+
state: "report",
|
|
79
|
+
outsideSandbox: stored.report.outsideSandbox,
|
|
80
|
+
restrictedProjectReach: stored.report.restrictedProjectReach,
|
|
81
|
+
allowedDomains: [...stored.report.allowedDomains],
|
|
82
|
+
network: stored.report.network,
|
|
83
|
+
revision: stored.report.revision,
|
|
84
|
+
sequence: stored.report.sequence
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
function applyOwnerReport(stored, incoming, via, now) {
|
|
88
|
+
const decision = decideOwnerReport(stored, incoming);
|
|
89
|
+
if (decision === "record")
|
|
90
|
+
return { outcome: "recorded", next: { report: incoming, observedAt: now, via } };
|
|
91
|
+
if (decision === "stale" || stored === null) return { outcome: "stale" };
|
|
92
|
+
if (decision === "same") {
|
|
93
|
+
const { blocked: _cleared, ...kept } = stored;
|
|
94
|
+
return { outcome: "same", next: { ...kept, observedAt: now } };
|
|
95
|
+
}
|
|
96
|
+
return {
|
|
97
|
+
outcome: "conflict",
|
|
98
|
+
next: { ...stored, blocked: { reason: "conflict", sequence: incoming.sequence, at: now } }
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
// src/report.ts
|
|
103
|
+
import { createHash } from "node:crypto";
|
|
104
|
+
import { parseSandboxPermissionSupport } from "@capybara-hq/plugin-sdk/device-protocol";
|
|
105
|
+
function closedSupport(unavailableReason) {
|
|
106
|
+
return parseSandboxPermissionSupport({
|
|
107
|
+
version: 2,
|
|
108
|
+
boundary: "operation",
|
|
109
|
+
restricted: null,
|
|
110
|
+
network: { openPublic: false, allowlist: false, perOperationHosts: false },
|
|
111
|
+
outsideSandbox: false,
|
|
112
|
+
background: false,
|
|
113
|
+
unavailableReason
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
var canonicalSupport = (s) => {
|
|
117
|
+
const p = parseSandboxPermissionSupport(s);
|
|
118
|
+
return {
|
|
119
|
+
version: p.version,
|
|
120
|
+
boundary: p.boundary,
|
|
121
|
+
restricted: p.restricted && {
|
|
122
|
+
filesystem: p.restricted.filesystem,
|
|
123
|
+
network: p.restricted.network,
|
|
124
|
+
native: p.restricted.native,
|
|
125
|
+
concurrentScopes: p.restricted.concurrentScopes
|
|
126
|
+
},
|
|
127
|
+
network: {
|
|
128
|
+
openPublic: p.network.openPublic,
|
|
129
|
+
allowlist: p.network.allowlist,
|
|
130
|
+
perOperationHosts: p.network.perOperationHosts
|
|
131
|
+
},
|
|
132
|
+
outsideSandbox: p.outsideSandbox,
|
|
133
|
+
background: p.background,
|
|
134
|
+
unavailableReason: p.unavailableReason ?? null
|
|
135
|
+
};
|
|
136
|
+
};
|
|
137
|
+
function revisionFacts(c, b) {
|
|
138
|
+
const owner = c ? ownerFactsOf(c.ownerReport) : null;
|
|
139
|
+
return {
|
|
140
|
+
v: 1,
|
|
141
|
+
connection: c && {
|
|
142
|
+
epoch: c.machineEpoch,
|
|
143
|
+
mode: c.mode,
|
|
144
|
+
roots: [c.roots.workspace, c.roots.skills, c.roots.tmp],
|
|
145
|
+
home: c.home,
|
|
146
|
+
owner: owner && {
|
|
147
|
+
state: owner.state,
|
|
148
|
+
sequence: owner.sequence,
|
|
149
|
+
revision: owner.revision,
|
|
150
|
+
outsideSandbox: owner.outsideSandbox,
|
|
151
|
+
reach: owner.restrictedProjectReach,
|
|
152
|
+
network: owner.network,
|
|
153
|
+
allowedDomains: [...owner.allowedDomains].sort()
|
|
154
|
+
}
|
|
155
|
+
},
|
|
156
|
+
binding: b && {
|
|
157
|
+
generation: b.generation,
|
|
158
|
+
status: b.status,
|
|
159
|
+
unattested: b.unattested === true,
|
|
160
|
+
runtime: b.installed && {
|
|
161
|
+
runtimeHash: b.installed.runtimeIdentity.runtimeHash,
|
|
162
|
+
helperHash: b.installed.runtimeIdentity.helperHash,
|
|
163
|
+
imageFingerprint: b.installed.runtimeIdentity.imageFingerprint
|
|
164
|
+
},
|
|
165
|
+
support: b.installed && canonicalSupport(b.installed.permissionSupport)
|
|
166
|
+
}
|
|
167
|
+
};
|
|
168
|
+
}
|
|
169
|
+
var revisionOf = (c, b) => createHash("sha256").update(JSON.stringify(revisionFacts(c, b))).digest("hex");
|
|
170
|
+
var hosts = (n) => n === 1 ? { en: "1 allowed host", zh: "允许 1 个主机" } : { en: `${n} allowed hosts`, zh: `允许 ${n} 个主机` };
|
|
171
|
+
function describe(c, owner) {
|
|
172
|
+
const docker = c.mode === "docker";
|
|
173
|
+
if (owner.state !== "report")
|
|
174
|
+
return {
|
|
175
|
+
en: "The computer's owner settings are unreadable or arrived out of order, so it runs as narrowly as possible (workspace only, never outside the sandbox) until it reports them again.",
|
|
176
|
+
zh: "电脑所有者的设置无法读取或报告顺序异常,在重新报告前按最窄的方式运行(只用工作区,从不在沙箱外运行)。"
|
|
177
|
+
};
|
|
178
|
+
const reach = owner.restrictedProjectReach === "os-user" ? {
|
|
179
|
+
en: "Reads the whole computer except secrets; writes only in the project",
|
|
180
|
+
zh: "读取整台电脑(密钥除外),只在项目中写入"
|
|
181
|
+
} : { en: "Reads and writes only in its workspace", zh: "只在工作区内读写" };
|
|
182
|
+
const outside = owner.outsideSandbox ? {
|
|
183
|
+
en: "runs outside the sandbox only per approved call",
|
|
184
|
+
zh: "仅对批准的单次调用在沙箱外运行"
|
|
185
|
+
} : { en: "never runs outside the sandbox", zh: "从不在沙箱外运行" };
|
|
186
|
+
const net = owner.network === "open" ? { en: "the open internet", zh: "开放的互联网" } : hosts(owner.allowedDomains.length);
|
|
187
|
+
return {
|
|
188
|
+
en: `${docker ? "In a Docker container: " : ""}${reach.en}; ${outside.en}; network: ${net.en}.`,
|
|
189
|
+
zh: `${docker ? "在 Docker 容器中:" : ""}${reach.zh};${outside.zh};网络:${net.zh}。`
|
|
190
|
+
};
|
|
191
|
+
}
|
|
192
|
+
function limitsOf(c, owner) {
|
|
193
|
+
const lines = [
|
|
194
|
+
{ label: { en: "Mode", zh: "模式" }, value: c.mode },
|
|
195
|
+
{
|
|
196
|
+
label: { en: "Outside the sandbox", zh: "沙箱外运行" },
|
|
197
|
+
value: owner.outsideSandbox ? "per approved call" : "off"
|
|
198
|
+
},
|
|
199
|
+
{
|
|
200
|
+
label: { en: "Project reach", zh: "项目范围" },
|
|
201
|
+
value: owner.restrictedProjectReach === "os-user" ? "machine" : "workspace"
|
|
202
|
+
},
|
|
203
|
+
{ label: { en: "Network", zh: "网络" }, value: owner.network }
|
|
204
|
+
];
|
|
205
|
+
if (owner.network === "allowlist")
|
|
206
|
+
lines.push({
|
|
207
|
+
label: { en: "Allowed hosts", zh: "允许的主机" },
|
|
208
|
+
value: String(owner.allowedDomains.length)
|
|
209
|
+
});
|
|
210
|
+
return lines;
|
|
211
|
+
}
|
|
212
|
+
function deviceReportOf(c, b) {
|
|
213
|
+
const revision = revisionOf(c, b);
|
|
214
|
+
if (!c)
|
|
215
|
+
return {
|
|
216
|
+
revision,
|
|
217
|
+
description: {
|
|
218
|
+
en: "Waiting for the computer to connect with capybara-device.",
|
|
219
|
+
zh: "等待电脑用 capybara-device 连接。"
|
|
220
|
+
},
|
|
221
|
+
home: null,
|
|
222
|
+
limits: [],
|
|
223
|
+
reset: false
|
|
224
|
+
};
|
|
225
|
+
const owner = ownerFactsOf(c.ownerReport);
|
|
226
|
+
return {
|
|
227
|
+
revision,
|
|
228
|
+
description: describe(c, owner),
|
|
229
|
+
// the base of an auto-mode project's relative path on the owner's own system (OS mode)
|
|
230
|
+
home: c.mode === "os" ? c.home : null,
|
|
231
|
+
limits: limitsOf(c, owner),
|
|
232
|
+
// the files are the machine owner's directory: the provider never resets them
|
|
233
|
+
reset: false
|
|
234
|
+
};
|
|
235
|
+
}
|
|
236
|
+
function supportOf(h, c, b) {
|
|
237
|
+
const generation = h.generation;
|
|
238
|
+
if (typeof generation !== "string")
|
|
239
|
+
return closedSupport("The instance handle is not a connected machine's instance");
|
|
240
|
+
if (b?.status !== "installed" || !b.installed)
|
|
241
|
+
return closedSupport("The instance's binding on the machine is not complete yet; retry");
|
|
242
|
+
if (!c)
|
|
243
|
+
return closedSupport("The machine has not said hello yet; connect it with capybara-device");
|
|
244
|
+
const owner = ownerFactsOf(c.ownerReport);
|
|
245
|
+
const attested = b.installed.permissionSupport;
|
|
246
|
+
return parseSandboxPermissionSupport({
|
|
247
|
+
...attested,
|
|
248
|
+
// never wider than the owner allows now (a ceiling change since the binding narrows it)
|
|
249
|
+
outsideSandbox: attested.outsideSandbox && owner.outsideSandbox,
|
|
250
|
+
// the open public internet only while the owner's sandbox network is open (an allowlist, or
|
|
251
|
+
// blocked or missing facts, narrow every command's egress on the machine)
|
|
252
|
+
network: {
|
|
253
|
+
...attested.network,
|
|
254
|
+
openPublic: attested.network.openPublic && owner.state === "report" && owner.network === "open"
|
|
255
|
+
}
|
|
256
|
+
});
|
|
257
|
+
}
|
|
258
|
+
async function reportFor(store, device) {
|
|
259
|
+
const connection = await store.connectionOf(device.deviceId, device.orgId);
|
|
260
|
+
const s = await store.state(device.deviceId);
|
|
261
|
+
if (!connection && s.connection) return deviceReportOf(null, null);
|
|
262
|
+
return deviceReportOf(connection, s.binding);
|
|
263
|
+
}
|
|
264
|
+
async function supportFor(store, h) {
|
|
265
|
+
const { connection, binding } = await store.state(h.id);
|
|
266
|
+
return supportOf(h, connection, binding);
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
// src/hello.ts
|
|
270
|
+
var DEVICE_ID = /^[A-Za-z0-9_-]{1,128}$/;
|
|
271
|
+
var GENERATION = /^[0-9]{1,16}$/;
|
|
272
|
+
var MAX_HOME_CHARS = 4096;
|
|
273
|
+
var MAX_MESSAGE_CHARS = 200;
|
|
274
|
+
var errMsg = (e) => e instanceof Error ? e.message : String(e);
|
|
275
|
+
var refuse = (code, message) => ({
|
|
276
|
+
ok: false,
|
|
277
|
+
code,
|
|
278
|
+
message: message.slice(0, MAX_MESSAGE_CHARS)
|
|
279
|
+
});
|
|
280
|
+
var sameRuntime = (a, b) => a.runtimeHash === b.runtimeHash && a.helperHash === b.helperHash && a.imageFingerprint === b.imageFingerprint;
|
|
281
|
+
function decideHello(s, deviceId, hello, conn, now) {
|
|
282
|
+
const gen = hello.instanceGeneration;
|
|
283
|
+
if (gen !== null && !GENERATION.test(gen))
|
|
284
|
+
return refuse(
|
|
285
|
+
"local.invalid_hello",
|
|
286
|
+
"The hello's instance generation is not a decimal integer"
|
|
287
|
+
);
|
|
288
|
+
if (hello.home !== void 0 && hello.home.length > MAX_HOME_CHARS)
|
|
289
|
+
return refuse("local.invalid_hello", "The hello's home directory is too long");
|
|
290
|
+
const b = s.binding;
|
|
291
|
+
if (gen !== null && b && BigInt(gen) > BigInt(b.generation))
|
|
292
|
+
return refuse(
|
|
293
|
+
"local.identity_mismatch",
|
|
294
|
+
"The machine names an instance generation this deployment never bound; sign in again"
|
|
295
|
+
);
|
|
296
|
+
const stored = s.connection;
|
|
297
|
+
const sameMachine = stored !== null && stored.machineId === conn.machineId;
|
|
298
|
+
const installed = b?.status === "installed" ? b.installed : void 0;
|
|
299
|
+
const namesInstalled = (stored === null || sameMachine) && installed !== void 0 && gen === b?.generation;
|
|
300
|
+
if (namesInstalled && hello.runtimeIdentity && !sameRuntime(hello.runtimeIdentity, installed.runtimeIdentity))
|
|
301
|
+
return refuse(
|
|
302
|
+
"local.identity_mismatch",
|
|
303
|
+
"The machine's runtime identity differs from the one its instance was bound under"
|
|
304
|
+
);
|
|
305
|
+
let epoch;
|
|
306
|
+
let applied;
|
|
307
|
+
if (sameMachine) {
|
|
308
|
+
epoch = stored.machineEpoch;
|
|
309
|
+
applied = applyOwnerReport(stored.ownerReport, hello.ownerCeiling, "hello", now);
|
|
310
|
+
if (applied.outcome === "stale")
|
|
311
|
+
return refuse(
|
|
312
|
+
"local.stale_owner_report",
|
|
313
|
+
"The machine's owner report is older than the one recorded; restart capybara-device or sign in again"
|
|
314
|
+
);
|
|
315
|
+
if (applied.outcome === "conflict")
|
|
316
|
+
return refuse(
|
|
317
|
+
"local.owner_report_conflict",
|
|
318
|
+
"The machine's owner report conflicts with the one recorded under the same sequence; sign in again"
|
|
319
|
+
);
|
|
320
|
+
} else {
|
|
321
|
+
epoch = stored ? stored.machineEpoch + 1 : 0;
|
|
322
|
+
applied = {
|
|
323
|
+
outcome: "recorded",
|
|
324
|
+
next: { report: hello.ownerCeiling, observedAt: now, via: "hello" }
|
|
325
|
+
};
|
|
326
|
+
}
|
|
327
|
+
const connection = {
|
|
328
|
+
deviceId,
|
|
329
|
+
orgId: stored?.orgId ?? null,
|
|
330
|
+
machineId: conn.machineId,
|
|
331
|
+
connectionId: conn.connectionId,
|
|
332
|
+
machineEpoch: epoch,
|
|
333
|
+
mode: hello.mode,
|
|
334
|
+
roots: { workspace: hello.roots.workspace, skills: hello.roots.skills, tmp: hello.roots.tmp },
|
|
335
|
+
home: hello.home ?? null,
|
|
336
|
+
sessionIsolation: hello.sessionIsolation,
|
|
337
|
+
features: [...hello.features ?? []],
|
|
338
|
+
permissionSupport: hello.permissionSupport,
|
|
339
|
+
ownerReport: applied.next ?? stored?.ownerReport ?? null,
|
|
340
|
+
instanceGeneration: gen,
|
|
341
|
+
runtimeIdentity: hello.runtimeIdentity ?? null
|
|
342
|
+
};
|
|
343
|
+
let binding;
|
|
344
|
+
if (b && installed) {
|
|
345
|
+
if (namesInstalled && hello.runtimeIdentity) {
|
|
346
|
+
const { unattested: _attested, ...kept } = b;
|
|
347
|
+
binding = {
|
|
348
|
+
...kept,
|
|
349
|
+
installed: { ...installed, permissionSupport: hello.permissionSupport }
|
|
350
|
+
};
|
|
351
|
+
} else if (!b.unattested) {
|
|
352
|
+
binding = { ...b, unattested: true };
|
|
353
|
+
}
|
|
354
|
+
}
|
|
355
|
+
return { result: applied.outcome, connection, ...binding && { binding } };
|
|
356
|
+
}
|
|
357
|
+
var validConnection = (conn) => {
|
|
358
|
+
const c = conn;
|
|
359
|
+
return typeof c?.machineId === "string" && c.machineId.length > 0 && typeof c.connectionId === "string" && c.connectionId.length > 0;
|
|
360
|
+
};
|
|
361
|
+
var isRecorded = (c, conn) => c.machineId === conn?.machineId && c.connectionId === conn?.connectionId;
|
|
362
|
+
function createDialInHandler(ctx, store, now = () => (/* @__PURE__ */ new Date()).toISOString()) {
|
|
363
|
+
const tell = async (deviceId) => {
|
|
364
|
+
try {
|
|
365
|
+
await ctx.devices.reportChanged(deviceId);
|
|
366
|
+
} catch (e) {
|
|
367
|
+
ctx.log.warn("could not tell the kernel the device report changed", {
|
|
368
|
+
deviceId,
|
|
369
|
+
error: errMsg(e)
|
|
370
|
+
});
|
|
371
|
+
}
|
|
372
|
+
};
|
|
373
|
+
const change = async (deviceId, fn) => {
|
|
374
|
+
let moved = false;
|
|
375
|
+
const out = await store.change(deviceId, (s) => {
|
|
376
|
+
const c = fn(s);
|
|
377
|
+
if ("ok" in c) return { result: c };
|
|
378
|
+
const before = revisionOf(s.connection, s.binding);
|
|
379
|
+
moved = before !== revisionOf(c.connection ?? s.connection, c.binding ?? s.binding);
|
|
380
|
+
return c;
|
|
381
|
+
});
|
|
382
|
+
if (moved) await tell(deviceId);
|
|
383
|
+
return out;
|
|
384
|
+
};
|
|
385
|
+
return {
|
|
386
|
+
async onHello(deviceId, body, signal, conn) {
|
|
387
|
+
signal.throwIfAborted();
|
|
388
|
+
if (typeof deviceId !== "string" || !DEVICE_ID.test(deviceId))
|
|
389
|
+
return refuse("local.invalid_hello", "The device id is not one this provider serves");
|
|
390
|
+
if (!validConnection(conn))
|
|
391
|
+
return refuse("local.invalid_hello", "The connection names no machine");
|
|
392
|
+
let hello;
|
|
393
|
+
try {
|
|
394
|
+
hello = parseDeviceFrame(body, "hello");
|
|
395
|
+
} catch (e) {
|
|
396
|
+
return refuse("local.invalid_hello", `Invalid hello: ${errMsg(e)}`);
|
|
397
|
+
}
|
|
398
|
+
const out = await change(deviceId, (s) => decideHello(s, deviceId, hello, conn, now()));
|
|
399
|
+
if (typeof out === "object" && out !== null && "ok" in out) {
|
|
400
|
+
ctx.log.info("refused a machine's hello", { deviceId, code: out.code });
|
|
401
|
+
return out;
|
|
402
|
+
}
|
|
403
|
+
return { ok: true };
|
|
404
|
+
},
|
|
405
|
+
/**
|
|
406
|
+
* A `policy` event: the owner changed the machine's ceiling while connected. Recorded through
|
|
407
|
+
* the owner-report rule (stale ignored, conflicting blocks); an invalid body is logged and
|
|
408
|
+
* dropped (the kernel keeps the connection; the machine's own enforcement stands), and so is a
|
|
409
|
+
* frame of any connection other than the one whose hello was recorded last.
|
|
410
|
+
*/
|
|
411
|
+
async onFrame(deviceId, frame, conn) {
|
|
412
|
+
let event;
|
|
413
|
+
try {
|
|
414
|
+
event = parseDeviceFrame(frame, "event");
|
|
415
|
+
} catch (e) {
|
|
416
|
+
ctx.log.warn("dropped an invalid frame from a machine", { deviceId, error: errMsg(e) });
|
|
417
|
+
return;
|
|
418
|
+
}
|
|
419
|
+
await change(deviceId, (s) => {
|
|
420
|
+
if (!s.connection || !isRecorded(s.connection, conn)) return { result: "none" };
|
|
421
|
+
const applied = applyOwnerReport(
|
|
422
|
+
s.connection.ownerReport,
|
|
423
|
+
event.ownerCeiling,
|
|
424
|
+
"policy",
|
|
425
|
+
now()
|
|
426
|
+
);
|
|
427
|
+
if (applied.outcome === "conflict")
|
|
428
|
+
ctx.log.warn("a machine's owner report conflicts with the recorded one", { deviceId });
|
|
429
|
+
return applied.next ? { result: applied.outcome, connection: { ...s.connection, ownerReport: applied.next } } : { result: applied.outcome };
|
|
430
|
+
});
|
|
431
|
+
},
|
|
432
|
+
/**
|
|
433
|
+
* A revoked machine: when it is the recorded one, the epoch moves on, so what was approved
|
|
434
|
+
* against it no longer stands (a close of an older machine changes nothing). `replaced` names
|
|
435
|
+
* the closing connection's machine, which is the recorded one both when the same machine took
|
|
436
|
+
* the device over with a newer connection and when the device signed in from another machine:
|
|
437
|
+
* the close changes nothing, and the next hello tells the two apart by its machine id (another
|
|
438
|
+
* machine moves the epoch, {@link decideHello}). A deleted device's rows go with its file
|
|
439
|
+
* system (`destroyFileSystem`).
|
|
440
|
+
*/
|
|
441
|
+
onClose(deviceId, reason, conn) {
|
|
442
|
+
if (reason !== "revoked") return;
|
|
443
|
+
return change(
|
|
444
|
+
deviceId,
|
|
445
|
+
(s) => s.connection && s.connection.machineId === conn?.machineId ? {
|
|
446
|
+
result: void 0,
|
|
447
|
+
connection: { ...s.connection, machineEpoch: s.connection.machineEpoch + 1 }
|
|
448
|
+
} : { result: void 0 }
|
|
449
|
+
).then(
|
|
450
|
+
() => void 0,
|
|
451
|
+
(e) => ctx.log.warn("could not record a revoked machine", { deviceId, error: errMsg(e) })
|
|
452
|
+
);
|
|
453
|
+
}
|
|
454
|
+
};
|
|
455
|
+
}
|
|
456
|
+
|
|
457
|
+
// src/pg-rows.ts
|
|
458
|
+
import {
|
|
459
|
+
parseOwnerCeilingReport as parseOwnerCeilingReport2,
|
|
460
|
+
parseSandboxPermissionSupport as parseSandboxPermissionSupport2
|
|
461
|
+
} from "@capybara-hq/plugin-sdk/device-protocol";
|
|
462
|
+
|
|
463
|
+
// ../../node_modules/.pnpm/kysely@0.29.8/node_modules/kysely/dist/util/object-utils.js
|
|
464
|
+
function isUndefined(obj) {
|
|
465
|
+
return typeof obj === "undefined" || obj === void 0;
|
|
466
|
+
}
|
|
467
|
+
function isString(obj) {
|
|
468
|
+
return typeof obj === "string";
|
|
469
|
+
}
|
|
470
|
+
function isNumber(obj) {
|
|
471
|
+
return typeof obj === "number";
|
|
472
|
+
}
|
|
473
|
+
function isBoolean(obj) {
|
|
474
|
+
return typeof obj === "boolean";
|
|
475
|
+
}
|
|
476
|
+
function isNull(obj) {
|
|
477
|
+
return obj === null;
|
|
478
|
+
}
|
|
479
|
+
function isBigInt(obj) {
|
|
480
|
+
return typeof obj === "bigint";
|
|
481
|
+
}
|
|
482
|
+
function isFunction(obj) {
|
|
483
|
+
return typeof obj === "function";
|
|
484
|
+
}
|
|
485
|
+
function isObject(obj) {
|
|
486
|
+
return typeof obj === "object" && obj !== null;
|
|
487
|
+
}
|
|
488
|
+
function freeze(obj) {
|
|
489
|
+
return Object.freeze(obj);
|
|
490
|
+
}
|
|
491
|
+
function asArray(arg) {
|
|
492
|
+
if (isReadonlyArray(arg)) {
|
|
493
|
+
return arg;
|
|
494
|
+
} else {
|
|
495
|
+
return [arg];
|
|
496
|
+
}
|
|
497
|
+
}
|
|
498
|
+
function isReadonlyArray(arg) {
|
|
499
|
+
return Array.isArray(arg);
|
|
500
|
+
}
|
|
501
|
+
function getMessage(error) {
|
|
502
|
+
return error instanceof Error ? error.message : String(error);
|
|
503
|
+
}
|
|
504
|
+
|
|
505
|
+
// ../../node_modules/.pnpm/kysely@0.29.8/node_modules/kysely/dist/operation-node/identifier-node.js
|
|
506
|
+
var IdentifierNode = freeze({
|
|
507
|
+
is(node) {
|
|
508
|
+
return node.kind === "IdentifierNode";
|
|
509
|
+
},
|
|
510
|
+
create(name) {
|
|
511
|
+
return freeze({
|
|
512
|
+
kind: "IdentifierNode",
|
|
513
|
+
name
|
|
514
|
+
});
|
|
515
|
+
}
|
|
516
|
+
});
|
|
517
|
+
|
|
518
|
+
// ../../node_modules/.pnpm/kysely@0.29.8/node_modules/kysely/dist/operation-node/schemable-identifier-node.js
|
|
519
|
+
var SchemableIdentifierNode = freeze({
|
|
520
|
+
is(node) {
|
|
521
|
+
return node.kind === "SchemableIdentifierNode";
|
|
522
|
+
},
|
|
523
|
+
create(identifier) {
|
|
524
|
+
return freeze({
|
|
525
|
+
kind: "SchemableIdentifierNode",
|
|
526
|
+
identifier: IdentifierNode.create(identifier)
|
|
527
|
+
});
|
|
528
|
+
},
|
|
529
|
+
createWithSchema(schema, identifier) {
|
|
530
|
+
return freeze({
|
|
531
|
+
kind: "SchemableIdentifierNode",
|
|
532
|
+
schema: IdentifierNode.create(schema),
|
|
533
|
+
identifier: IdentifierNode.create(identifier)
|
|
534
|
+
});
|
|
535
|
+
}
|
|
536
|
+
});
|
|
537
|
+
|
|
538
|
+
// ../../node_modules/.pnpm/kysely@0.29.8/node_modules/kysely/dist/operation-node/alias-node.js
|
|
539
|
+
var AliasNode = freeze({
|
|
540
|
+
is(node) {
|
|
541
|
+
return node.kind === "AliasNode";
|
|
542
|
+
},
|
|
543
|
+
create(node, alias) {
|
|
544
|
+
return freeze({
|
|
545
|
+
kind: "AliasNode",
|
|
546
|
+
node,
|
|
547
|
+
alias
|
|
548
|
+
});
|
|
549
|
+
}
|
|
550
|
+
});
|
|
551
|
+
|
|
552
|
+
// ../../node_modules/.pnpm/kysely@0.29.8/node_modules/kysely/dist/operation-node/table-node.js
|
|
553
|
+
var TableNode = freeze({
|
|
554
|
+
is(node) {
|
|
555
|
+
return node.kind === "TableNode";
|
|
556
|
+
},
|
|
557
|
+
create(table) {
|
|
558
|
+
return freeze({
|
|
559
|
+
kind: "TableNode",
|
|
560
|
+
table: SchemableIdentifierNode.create(table)
|
|
561
|
+
});
|
|
562
|
+
},
|
|
563
|
+
createWithSchema(schema, table) {
|
|
564
|
+
return freeze({
|
|
565
|
+
kind: "TableNode",
|
|
566
|
+
table: SchemableIdentifierNode.createWithSchema(schema, table)
|
|
567
|
+
});
|
|
568
|
+
}
|
|
569
|
+
});
|
|
570
|
+
|
|
571
|
+
// ../../node_modules/.pnpm/kysely@0.29.8/node_modules/kysely/dist/operation-node/operation-node-source.js
|
|
572
|
+
function isOperationNodeSource(obj) {
|
|
573
|
+
return isObject(obj) && isFunction(obj.toOperationNode);
|
|
574
|
+
}
|
|
575
|
+
|
|
576
|
+
// ../../node_modules/.pnpm/kysely@0.29.8/node_modules/kysely/dist/expression/expression.js
|
|
577
|
+
function isExpression(obj) {
|
|
578
|
+
return isObject(obj) && "expressionType" in obj && isOperationNodeSource(obj);
|
|
579
|
+
}
|
|
580
|
+
function isAliasedExpression(obj) {
|
|
581
|
+
return isObject(obj) && "expression" in obj && isString(obj.alias) && isOperationNodeSource(obj);
|
|
582
|
+
}
|
|
583
|
+
|
|
584
|
+
// ../../node_modules/.pnpm/kysely@0.29.8/node_modules/kysely/dist/operation-node/select-modifier-node.js
|
|
585
|
+
var SelectModifierNode = freeze({
|
|
586
|
+
is(node) {
|
|
587
|
+
return node.kind === "SelectModifierNode";
|
|
588
|
+
},
|
|
589
|
+
create(modifier, of) {
|
|
590
|
+
return freeze({
|
|
591
|
+
kind: "SelectModifierNode",
|
|
592
|
+
modifier,
|
|
593
|
+
of
|
|
594
|
+
});
|
|
595
|
+
},
|
|
596
|
+
createWithExpression(modifier) {
|
|
597
|
+
return freeze({
|
|
598
|
+
kind: "SelectModifierNode",
|
|
599
|
+
rawModifier: modifier
|
|
600
|
+
});
|
|
601
|
+
}
|
|
602
|
+
});
|
|
603
|
+
|
|
604
|
+
// ../../node_modules/.pnpm/kysely@0.29.8/node_modules/kysely/dist/operation-node/and-node.js
|
|
605
|
+
var AndNode = freeze({
|
|
606
|
+
is(node) {
|
|
607
|
+
return node.kind === "AndNode";
|
|
608
|
+
},
|
|
609
|
+
create(left, right) {
|
|
610
|
+
return freeze({
|
|
611
|
+
kind: "AndNode",
|
|
612
|
+
left,
|
|
613
|
+
right
|
|
614
|
+
});
|
|
615
|
+
}
|
|
616
|
+
});
|
|
617
|
+
|
|
618
|
+
// ../../node_modules/.pnpm/kysely@0.29.8/node_modules/kysely/dist/operation-node/or-node.js
|
|
619
|
+
var OrNode = freeze({
|
|
620
|
+
is(node) {
|
|
621
|
+
return node.kind === "OrNode";
|
|
622
|
+
},
|
|
623
|
+
create(left, right) {
|
|
624
|
+
return freeze({
|
|
625
|
+
kind: "OrNode",
|
|
626
|
+
left,
|
|
627
|
+
right
|
|
628
|
+
});
|
|
629
|
+
}
|
|
630
|
+
});
|
|
631
|
+
|
|
632
|
+
// ../../node_modules/.pnpm/kysely@0.29.8/node_modules/kysely/dist/operation-node/on-node.js
|
|
633
|
+
var OnNode = freeze({
|
|
634
|
+
is(node) {
|
|
635
|
+
return node.kind === "OnNode";
|
|
636
|
+
},
|
|
637
|
+
create(filter) {
|
|
638
|
+
return freeze({
|
|
639
|
+
kind: "OnNode",
|
|
640
|
+
on: filter
|
|
641
|
+
});
|
|
642
|
+
},
|
|
643
|
+
cloneWithOperation(onNode, operator, operation) {
|
|
644
|
+
return freeze({
|
|
645
|
+
...onNode,
|
|
646
|
+
on: operator === "And" ? AndNode.create(onNode.on, operation) : OrNode.create(onNode.on, operation)
|
|
647
|
+
});
|
|
648
|
+
}
|
|
649
|
+
});
|
|
650
|
+
|
|
651
|
+
// ../../node_modules/.pnpm/kysely@0.29.8/node_modules/kysely/dist/operation-node/join-node.js
|
|
652
|
+
var JoinNode = freeze({
|
|
653
|
+
is(node) {
|
|
654
|
+
return node.kind === "JoinNode";
|
|
655
|
+
},
|
|
656
|
+
create(joinType, table) {
|
|
657
|
+
return freeze({
|
|
658
|
+
kind: "JoinNode",
|
|
659
|
+
joinType,
|
|
660
|
+
table,
|
|
661
|
+
on: void 0
|
|
662
|
+
});
|
|
663
|
+
},
|
|
664
|
+
createWithOn(joinType, table, on) {
|
|
665
|
+
return freeze({
|
|
666
|
+
kind: "JoinNode",
|
|
667
|
+
joinType,
|
|
668
|
+
table,
|
|
669
|
+
on: OnNode.create(on)
|
|
670
|
+
});
|
|
671
|
+
},
|
|
672
|
+
cloneWithOn(joinNode, operation) {
|
|
673
|
+
return freeze({
|
|
674
|
+
...joinNode,
|
|
675
|
+
on: joinNode.on ? OnNode.cloneWithOperation(joinNode.on, "And", operation) : OnNode.create(operation)
|
|
676
|
+
});
|
|
677
|
+
}
|
|
678
|
+
});
|
|
679
|
+
|
|
680
|
+
// ../../node_modules/.pnpm/kysely@0.29.8/node_modules/kysely/dist/operation-node/binary-operation-node.js
|
|
681
|
+
var BinaryOperationNode = freeze({
|
|
682
|
+
is(node) {
|
|
683
|
+
return node.kind === "BinaryOperationNode";
|
|
684
|
+
},
|
|
685
|
+
create(leftOperand, operator, rightOperand) {
|
|
686
|
+
return freeze({
|
|
687
|
+
kind: "BinaryOperationNode",
|
|
688
|
+
leftOperand,
|
|
689
|
+
operator,
|
|
690
|
+
rightOperand
|
|
691
|
+
});
|
|
692
|
+
}
|
|
693
|
+
});
|
|
694
|
+
|
|
695
|
+
// ../../node_modules/.pnpm/kysely@0.29.8/node_modules/kysely/dist/operation-node/operator-node.js
|
|
696
|
+
var COMPARISON_OPERATORS_DICTIONARY = freeze({
|
|
697
|
+
"=": true,
|
|
698
|
+
"==": true,
|
|
699
|
+
"!=": true,
|
|
700
|
+
"<>": true,
|
|
701
|
+
">": true,
|
|
702
|
+
">=": true,
|
|
703
|
+
"<": true,
|
|
704
|
+
"<=": true,
|
|
705
|
+
in: true,
|
|
706
|
+
"not in": true,
|
|
707
|
+
is: true,
|
|
708
|
+
"is not": true,
|
|
709
|
+
like: true,
|
|
710
|
+
"not like": true,
|
|
711
|
+
match: true,
|
|
712
|
+
ilike: true,
|
|
713
|
+
"not ilike": true,
|
|
714
|
+
"@>": true,
|
|
715
|
+
"<@": true,
|
|
716
|
+
"^@": true,
|
|
717
|
+
"&&": true,
|
|
718
|
+
"?": true,
|
|
719
|
+
"?&": true,
|
|
720
|
+
"?|": true,
|
|
721
|
+
"!<": true,
|
|
722
|
+
"!>": true,
|
|
723
|
+
"<=>": true,
|
|
724
|
+
"!~": true,
|
|
725
|
+
"~": true,
|
|
726
|
+
"~*": true,
|
|
727
|
+
"!~*": true,
|
|
728
|
+
"@@": true,
|
|
729
|
+
"@@@": true,
|
|
730
|
+
"!!": true,
|
|
731
|
+
"<->": true,
|
|
732
|
+
regexp: true,
|
|
733
|
+
"is distinct from": true,
|
|
734
|
+
"is not distinct from": true
|
|
735
|
+
});
|
|
736
|
+
var COMPARISON_OPERATORS = Object.keys(COMPARISON_OPERATORS_DICTIONARY);
|
|
737
|
+
var ARITHMETIC_OPERATORS_DICTIONARY = freeze({
|
|
738
|
+
"+": true,
|
|
739
|
+
"-": true,
|
|
740
|
+
"*": true,
|
|
741
|
+
"/": true,
|
|
742
|
+
"%": true,
|
|
743
|
+
"^": true,
|
|
744
|
+
"&": true,
|
|
745
|
+
"|": true,
|
|
746
|
+
"#": true,
|
|
747
|
+
"<<": true,
|
|
748
|
+
">>": true
|
|
749
|
+
});
|
|
750
|
+
var ARITHMETIC_OPERATORS = Object.keys(ARITHMETIC_OPERATORS_DICTIONARY);
|
|
751
|
+
var JSON_OPERATORS_DICTIONARY = freeze({
|
|
752
|
+
"->": true,
|
|
753
|
+
"->>": true
|
|
754
|
+
});
|
|
755
|
+
var JSON_OPERATORS = Object.keys(JSON_OPERATORS_DICTIONARY);
|
|
756
|
+
var BINARY_OPERATORS_DICTIONARY = freeze({
|
|
757
|
+
...COMPARISON_OPERATORS_DICTIONARY,
|
|
758
|
+
...ARITHMETIC_OPERATORS_DICTIONARY,
|
|
759
|
+
"||": true
|
|
760
|
+
});
|
|
761
|
+
var BINARY_OPERATORS = Object.keys(BINARY_OPERATORS_DICTIONARY);
|
|
762
|
+
var UNARY_FILTER_OPERATORS_DICTIONARY = freeze({
|
|
763
|
+
exists: true,
|
|
764
|
+
"not exists": true
|
|
765
|
+
});
|
|
766
|
+
var UNARY_FILTER_OPERATORS = Object.keys(UNARY_FILTER_OPERATORS_DICTIONARY);
|
|
767
|
+
var UNARY_OPERATORS_DICTIONARY = freeze({
|
|
768
|
+
...UNARY_FILTER_OPERATORS_DICTIONARY,
|
|
769
|
+
"-": true,
|
|
770
|
+
not: true
|
|
771
|
+
});
|
|
772
|
+
var UNARY_OPERATORS = Object.keys(UNARY_OPERATORS_DICTIONARY);
|
|
773
|
+
var OPERATORS = [
|
|
774
|
+
...BINARY_OPERATORS,
|
|
775
|
+
...JSON_OPERATORS,
|
|
776
|
+
...UNARY_OPERATORS,
|
|
777
|
+
"between",
|
|
778
|
+
"between symmetric"
|
|
779
|
+
];
|
|
780
|
+
var OperatorNode = freeze({
|
|
781
|
+
is(node) {
|
|
782
|
+
return node.kind === "OperatorNode";
|
|
783
|
+
},
|
|
784
|
+
create(operator) {
|
|
785
|
+
return freeze({
|
|
786
|
+
kind: "OperatorNode",
|
|
787
|
+
operator
|
|
788
|
+
});
|
|
789
|
+
}
|
|
790
|
+
});
|
|
791
|
+
function isBinaryOperator(op) {
|
|
792
|
+
return isString(op) && BINARY_OPERATORS_DICTIONARY[op];
|
|
793
|
+
}
|
|
794
|
+
function isJSONOperator(op) {
|
|
795
|
+
return isString(op) && JSON_OPERATORS_DICTIONARY[op];
|
|
796
|
+
}
|
|
797
|
+
function isUnaryOperator(op) {
|
|
798
|
+
return isString(op) && UNARY_OPERATORS_DICTIONARY[op];
|
|
799
|
+
}
|
|
800
|
+
|
|
801
|
+
// ../../node_modules/.pnpm/kysely@0.29.8/node_modules/kysely/dist/operation-node/column-node.js
|
|
802
|
+
var ColumnNode = freeze({
|
|
803
|
+
is(node) {
|
|
804
|
+
return node.kind === "ColumnNode";
|
|
805
|
+
},
|
|
806
|
+
create(column) {
|
|
807
|
+
return freeze({
|
|
808
|
+
kind: "ColumnNode",
|
|
809
|
+
column: IdentifierNode.create(column)
|
|
810
|
+
});
|
|
811
|
+
}
|
|
812
|
+
});
|
|
813
|
+
|
|
814
|
+
// ../../node_modules/.pnpm/kysely@0.29.8/node_modules/kysely/dist/operation-node/select-all-node.js
|
|
815
|
+
var SelectAllNode = freeze({
|
|
816
|
+
is(node) {
|
|
817
|
+
return node.kind === "SelectAllNode";
|
|
818
|
+
},
|
|
819
|
+
create() {
|
|
820
|
+
return freeze({
|
|
821
|
+
kind: "SelectAllNode"
|
|
822
|
+
});
|
|
823
|
+
}
|
|
824
|
+
});
|
|
825
|
+
|
|
826
|
+
// ../../node_modules/.pnpm/kysely@0.29.8/node_modules/kysely/dist/operation-node/reference-node.js
|
|
827
|
+
var ReferenceNode = freeze({
|
|
828
|
+
is(node) {
|
|
829
|
+
return node.kind === "ReferenceNode";
|
|
830
|
+
},
|
|
831
|
+
create(column, table) {
|
|
832
|
+
return freeze({
|
|
833
|
+
kind: "ReferenceNode",
|
|
834
|
+
table,
|
|
835
|
+
column
|
|
836
|
+
});
|
|
837
|
+
},
|
|
838
|
+
createSelectAll(table) {
|
|
839
|
+
return freeze({
|
|
840
|
+
kind: "ReferenceNode",
|
|
841
|
+
table,
|
|
842
|
+
column: SelectAllNode.create()
|
|
843
|
+
});
|
|
844
|
+
}
|
|
845
|
+
});
|
|
846
|
+
|
|
847
|
+
// ../../node_modules/.pnpm/kysely@0.29.8/node_modules/kysely/dist/dynamic/dynamic-reference-builder.js
|
|
848
|
+
function isDynamicReferenceBuilder(obj) {
|
|
849
|
+
return isObject(obj) && isOperationNodeSource(obj) && isString(obj.dynamicReference);
|
|
850
|
+
}
|
|
851
|
+
|
|
852
|
+
// ../../node_modules/.pnpm/kysely@0.29.8/node_modules/kysely/dist/operation-node/order-by-item-node.js
|
|
853
|
+
var OrderByItemNode = freeze({
|
|
854
|
+
is(node) {
|
|
855
|
+
return node.kind === "OrderByItemNode";
|
|
856
|
+
},
|
|
857
|
+
create(orderBy, direction) {
|
|
858
|
+
return freeze({
|
|
859
|
+
kind: "OrderByItemNode",
|
|
860
|
+
orderBy,
|
|
861
|
+
direction
|
|
862
|
+
});
|
|
863
|
+
},
|
|
864
|
+
cloneWith(node, props) {
|
|
865
|
+
return freeze({
|
|
866
|
+
...node,
|
|
867
|
+
...props
|
|
868
|
+
});
|
|
869
|
+
}
|
|
870
|
+
});
|
|
871
|
+
|
|
872
|
+
// ../../node_modules/.pnpm/kysely@0.29.8/node_modules/kysely/dist/operation-node/raw-node.js
|
|
873
|
+
var RawNode = freeze({
|
|
874
|
+
is(node) {
|
|
875
|
+
return node.kind === "RawNode";
|
|
876
|
+
},
|
|
877
|
+
create(sqlFragments, parameters) {
|
|
878
|
+
return freeze({
|
|
879
|
+
kind: "RawNode",
|
|
880
|
+
sqlFragments: freeze(sqlFragments),
|
|
881
|
+
parameters: freeze(parameters)
|
|
882
|
+
});
|
|
883
|
+
},
|
|
884
|
+
createWithSql(sql2) {
|
|
885
|
+
return RawNode.create([sql2], []);
|
|
886
|
+
},
|
|
887
|
+
createWithChild(child) {
|
|
888
|
+
return RawNode.create(["", ""], [child]);
|
|
889
|
+
},
|
|
890
|
+
createWithChildren(children) {
|
|
891
|
+
return RawNode.create(new Array(children.length + 1).fill(""), children);
|
|
892
|
+
}
|
|
893
|
+
});
|
|
894
|
+
|
|
895
|
+
// ../../node_modules/.pnpm/kysely@0.29.8/node_modules/kysely/dist/operation-node/collate-node.js
|
|
896
|
+
var CollateNode = freeze({
|
|
897
|
+
is(node) {
|
|
898
|
+
return node.kind === "CollateNode";
|
|
899
|
+
},
|
|
900
|
+
create(collation) {
|
|
901
|
+
return freeze({
|
|
902
|
+
kind: "CollateNode",
|
|
903
|
+
collation: IdentifierNode.create(collation)
|
|
904
|
+
});
|
|
905
|
+
}
|
|
906
|
+
});
|
|
907
|
+
|
|
908
|
+
// ../../node_modules/.pnpm/kysely@0.29.8/node_modules/kysely/dist/query-builder/order-by-item-builder.js
|
|
909
|
+
var OrderByItemBuilder = class _OrderByItemBuilder {
|
|
910
|
+
#props;
|
|
911
|
+
constructor(props) {
|
|
912
|
+
this.#props = freeze(props);
|
|
913
|
+
}
|
|
914
|
+
/**
|
|
915
|
+
* Adds `desc` to the `order by` item.
|
|
916
|
+
*
|
|
917
|
+
* See {@link asc} for the opposite.
|
|
918
|
+
*/
|
|
919
|
+
desc() {
|
|
920
|
+
return new _OrderByItemBuilder({
|
|
921
|
+
node: OrderByItemNode.cloneWith(this.#props.node, {
|
|
922
|
+
direction: RawNode.createWithSql("desc")
|
|
923
|
+
})
|
|
924
|
+
});
|
|
925
|
+
}
|
|
926
|
+
/**
|
|
927
|
+
* Adds `asc` to the `order by` item.
|
|
928
|
+
*
|
|
929
|
+
* See {@link desc} for the opposite.
|
|
930
|
+
*/
|
|
931
|
+
asc() {
|
|
932
|
+
return new _OrderByItemBuilder({
|
|
933
|
+
node: OrderByItemNode.cloneWith(this.#props.node, {
|
|
934
|
+
direction: RawNode.createWithSql("asc")
|
|
935
|
+
})
|
|
936
|
+
});
|
|
937
|
+
}
|
|
938
|
+
/**
|
|
939
|
+
* Adds `nulls last` to the `order by` item.
|
|
940
|
+
*
|
|
941
|
+
* This is only supported by some dialects like PostgreSQL and SQLite.
|
|
942
|
+
*
|
|
943
|
+
* See {@link nullsFirst} for the opposite.
|
|
944
|
+
*/
|
|
945
|
+
nullsLast() {
|
|
946
|
+
return new _OrderByItemBuilder({
|
|
947
|
+
node: OrderByItemNode.cloneWith(this.#props.node, { nulls: "last" })
|
|
948
|
+
});
|
|
949
|
+
}
|
|
950
|
+
/**
|
|
951
|
+
* Adds `nulls first` to the `order by` item.
|
|
952
|
+
*
|
|
953
|
+
* This is only supported by some dialects like PostgreSQL and SQLite.
|
|
954
|
+
*
|
|
955
|
+
* See {@link nullsLast} for the opposite.
|
|
956
|
+
*/
|
|
957
|
+
nullsFirst() {
|
|
958
|
+
return new _OrderByItemBuilder({
|
|
959
|
+
node: OrderByItemNode.cloneWith(this.#props.node, { nulls: "first" })
|
|
960
|
+
});
|
|
961
|
+
}
|
|
962
|
+
/**
|
|
963
|
+
* Adds `collate <collationName>` to the `order by` item.
|
|
964
|
+
*/
|
|
965
|
+
collate(collation) {
|
|
966
|
+
return new _OrderByItemBuilder({
|
|
967
|
+
node: OrderByItemNode.cloneWith(this.#props.node, {
|
|
968
|
+
collation: CollateNode.create(collation)
|
|
969
|
+
})
|
|
970
|
+
});
|
|
971
|
+
}
|
|
972
|
+
toOperationNode() {
|
|
973
|
+
return this.#props.node;
|
|
974
|
+
}
|
|
975
|
+
};
|
|
976
|
+
|
|
977
|
+
// ../../node_modules/.pnpm/kysely@0.29.8/node_modules/kysely/dist/util/log-once.js
|
|
978
|
+
var LOGGED_MESSAGES = /* @__PURE__ */ new Set();
|
|
979
|
+
function logOnce(message) {
|
|
980
|
+
if (LOGGED_MESSAGES.has(message)) {
|
|
981
|
+
return;
|
|
982
|
+
}
|
|
983
|
+
LOGGED_MESSAGES.add(message);
|
|
984
|
+
console.log(message);
|
|
985
|
+
}
|
|
986
|
+
|
|
987
|
+
// ../../node_modules/.pnpm/kysely@0.29.8/node_modules/kysely/dist/parser/order-by-parser.js
|
|
988
|
+
function isOrderByDirection(thing) {
|
|
989
|
+
return thing === "asc" || thing === "desc";
|
|
990
|
+
}
|
|
991
|
+
function parseOrderBy(args) {
|
|
992
|
+
if (args.length === 2) {
|
|
993
|
+
return [parseOrderByItem(args[0], args[1])];
|
|
994
|
+
}
|
|
995
|
+
if (args.length === 1) {
|
|
996
|
+
const [orderBy] = args;
|
|
997
|
+
if (Array.isArray(orderBy)) {
|
|
998
|
+
logOnce("orderBy(array) is deprecated, use multiple orderBy calls instead.");
|
|
999
|
+
return orderBy.map((item) => parseOrderByItem(item));
|
|
1000
|
+
}
|
|
1001
|
+
return [parseOrderByItem(orderBy)];
|
|
1002
|
+
}
|
|
1003
|
+
throw new Error(`Invalid number of arguments at order by! expected 1-2, received ${args.length}`);
|
|
1004
|
+
}
|
|
1005
|
+
function parseOrderByItem(expr, modifiers) {
|
|
1006
|
+
const parsedRef = parseOrderByExpression(expr);
|
|
1007
|
+
if (OrderByItemNode.is(parsedRef)) {
|
|
1008
|
+
if (modifiers) {
|
|
1009
|
+
throw new Error("Cannot specify direction twice!");
|
|
1010
|
+
}
|
|
1011
|
+
return parsedRef;
|
|
1012
|
+
}
|
|
1013
|
+
return parseOrderByWithModifiers(parsedRef, modifiers);
|
|
1014
|
+
}
|
|
1015
|
+
function parseOrderByExpression(expr) {
|
|
1016
|
+
if (isExpressionOrFactory(expr)) {
|
|
1017
|
+
return parseExpression(expr);
|
|
1018
|
+
}
|
|
1019
|
+
if (isDynamicReferenceBuilder(expr)) {
|
|
1020
|
+
return expr.toOperationNode();
|
|
1021
|
+
}
|
|
1022
|
+
const [ref, direction] = expr.split(" ");
|
|
1023
|
+
if (direction) {
|
|
1024
|
+
logOnce("`orderBy('column asc')` is deprecated. Use `orderBy('column', 'asc')` instead.");
|
|
1025
|
+
return parseOrderByWithModifiers(parseStringReference(ref), direction);
|
|
1026
|
+
}
|
|
1027
|
+
return parseStringReference(expr);
|
|
1028
|
+
}
|
|
1029
|
+
function parseOrderByWithModifiers(expr, modifiers) {
|
|
1030
|
+
if (typeof modifiers === "string") {
|
|
1031
|
+
if (!isOrderByDirection(modifiers)) {
|
|
1032
|
+
throw new Error(`Invalid order by direction: ${modifiers}`);
|
|
1033
|
+
}
|
|
1034
|
+
return OrderByItemNode.create(expr, RawNode.createWithSql(modifiers));
|
|
1035
|
+
}
|
|
1036
|
+
if (isExpression(modifiers)) {
|
|
1037
|
+
logOnce("`orderBy(..., expr)` is deprecated. Use `orderBy(..., 'asc')` or `orderBy(..., (ob) => ...)` instead.");
|
|
1038
|
+
return OrderByItemNode.create(expr, modifiers.toOperationNode());
|
|
1039
|
+
}
|
|
1040
|
+
const node = OrderByItemNode.create(expr);
|
|
1041
|
+
if (!modifiers) {
|
|
1042
|
+
return node;
|
|
1043
|
+
}
|
|
1044
|
+
return modifiers(new OrderByItemBuilder({ node })).toOperationNode();
|
|
1045
|
+
}
|
|
1046
|
+
|
|
1047
|
+
// ../../node_modules/.pnpm/kysely@0.29.8/node_modules/kysely/dist/operation-node/json-reference-node.js
|
|
1048
|
+
var JSONReferenceNode = freeze({
|
|
1049
|
+
is(node) {
|
|
1050
|
+
return node.kind === "JSONReferenceNode";
|
|
1051
|
+
},
|
|
1052
|
+
create(reference, traversal) {
|
|
1053
|
+
return freeze({
|
|
1054
|
+
kind: "JSONReferenceNode",
|
|
1055
|
+
reference,
|
|
1056
|
+
traversal
|
|
1057
|
+
});
|
|
1058
|
+
},
|
|
1059
|
+
cloneWithTraversal(node, traversal) {
|
|
1060
|
+
return freeze({
|
|
1061
|
+
...node,
|
|
1062
|
+
traversal
|
|
1063
|
+
});
|
|
1064
|
+
}
|
|
1065
|
+
});
|
|
1066
|
+
|
|
1067
|
+
// ../../node_modules/.pnpm/kysely@0.29.8/node_modules/kysely/dist/operation-node/json-operator-chain-node.js
|
|
1068
|
+
var JSONOperatorChainNode = freeze({
|
|
1069
|
+
is(node) {
|
|
1070
|
+
return node.kind === "JSONOperatorChainNode";
|
|
1071
|
+
},
|
|
1072
|
+
create(operator) {
|
|
1073
|
+
return freeze({
|
|
1074
|
+
kind: "JSONOperatorChainNode",
|
|
1075
|
+
operator,
|
|
1076
|
+
values: freeze([])
|
|
1077
|
+
});
|
|
1078
|
+
},
|
|
1079
|
+
cloneWithValue(node, value) {
|
|
1080
|
+
return freeze({
|
|
1081
|
+
...node,
|
|
1082
|
+
values: freeze([...node.values, value])
|
|
1083
|
+
});
|
|
1084
|
+
}
|
|
1085
|
+
});
|
|
1086
|
+
|
|
1087
|
+
// ../../node_modules/.pnpm/kysely@0.29.8/node_modules/kysely/dist/operation-node/json-path-node.js
|
|
1088
|
+
var JSONPathNode = freeze({
|
|
1089
|
+
is(node) {
|
|
1090
|
+
return node.kind === "JSONPathNode";
|
|
1091
|
+
},
|
|
1092
|
+
create(inOperator) {
|
|
1093
|
+
return freeze({
|
|
1094
|
+
kind: "JSONPathNode",
|
|
1095
|
+
inOperator,
|
|
1096
|
+
pathLegs: freeze([])
|
|
1097
|
+
});
|
|
1098
|
+
},
|
|
1099
|
+
cloneWithLeg(jsonPathNode, pathLeg) {
|
|
1100
|
+
return freeze({
|
|
1101
|
+
...jsonPathNode,
|
|
1102
|
+
pathLegs: freeze([...jsonPathNode.pathLegs, pathLeg])
|
|
1103
|
+
});
|
|
1104
|
+
}
|
|
1105
|
+
});
|
|
1106
|
+
|
|
1107
|
+
// ../../node_modules/.pnpm/kysely@0.29.8/node_modules/kysely/dist/parser/reference-parser.js
|
|
1108
|
+
function parseSimpleReferenceExpression(exp) {
|
|
1109
|
+
if (isString(exp)) {
|
|
1110
|
+
return parseStringReference(exp);
|
|
1111
|
+
}
|
|
1112
|
+
return exp.toOperationNode();
|
|
1113
|
+
}
|
|
1114
|
+
function parseReferenceExpressionOrList(arg) {
|
|
1115
|
+
if (isReadonlyArray(arg)) {
|
|
1116
|
+
return arg.map((it) => parseReferenceExpression(it));
|
|
1117
|
+
} else {
|
|
1118
|
+
return [parseReferenceExpression(arg)];
|
|
1119
|
+
}
|
|
1120
|
+
}
|
|
1121
|
+
function parseReferenceExpression(exp) {
|
|
1122
|
+
if (isExpressionOrFactory(exp)) {
|
|
1123
|
+
return parseExpression(exp);
|
|
1124
|
+
}
|
|
1125
|
+
return parseSimpleReferenceExpression(exp);
|
|
1126
|
+
}
|
|
1127
|
+
function parseJSONReference(ref, op) {
|
|
1128
|
+
if (isJSONOperator(op)) {
|
|
1129
|
+
return JSONReferenceNode.create(parseStringReference(ref), JSONOperatorChainNode.create(OperatorNode.create(op)));
|
|
1130
|
+
}
|
|
1131
|
+
if (op === "->$" || op === "->>$") {
|
|
1132
|
+
return JSONReferenceNode.create(parseStringReference(ref), JSONPathNode.create(OperatorNode.create(op.slice(0, -1))));
|
|
1133
|
+
}
|
|
1134
|
+
throw new Error(`Invalid JSON operator: ${op}`);
|
|
1135
|
+
}
|
|
1136
|
+
function parseStringReference(ref) {
|
|
1137
|
+
const COLUMN_SEPARATOR = ".";
|
|
1138
|
+
if (!ref.includes(COLUMN_SEPARATOR)) {
|
|
1139
|
+
return ReferenceNode.create(ColumnNode.create(ref));
|
|
1140
|
+
}
|
|
1141
|
+
const parts = ref.split(COLUMN_SEPARATOR).map(trim);
|
|
1142
|
+
if (parts.length === 3) {
|
|
1143
|
+
return parseStringReferenceWithTableAndSchema(parts);
|
|
1144
|
+
}
|
|
1145
|
+
if (parts.length === 2) {
|
|
1146
|
+
return parseStringReferenceWithTable(parts);
|
|
1147
|
+
}
|
|
1148
|
+
throw new Error(`invalid column reference ${ref}`);
|
|
1149
|
+
}
|
|
1150
|
+
function parseAliasedStringReference(ref) {
|
|
1151
|
+
const ALIAS_SEPARATOR = " as ";
|
|
1152
|
+
if (ref.includes(ALIAS_SEPARATOR)) {
|
|
1153
|
+
const [columnRef, alias] = ref.split(ALIAS_SEPARATOR).map(trim);
|
|
1154
|
+
return AliasNode.create(parseStringReference(columnRef), IdentifierNode.create(alias));
|
|
1155
|
+
} else {
|
|
1156
|
+
return parseStringReference(ref);
|
|
1157
|
+
}
|
|
1158
|
+
}
|
|
1159
|
+
function parseStringReferenceWithTableAndSchema(parts) {
|
|
1160
|
+
const [schema, table, column] = parts;
|
|
1161
|
+
return ReferenceNode.create(ColumnNode.create(column), TableNode.createWithSchema(schema, table));
|
|
1162
|
+
}
|
|
1163
|
+
function parseStringReferenceWithTable(parts) {
|
|
1164
|
+
const [table, column] = parts;
|
|
1165
|
+
return ReferenceNode.create(ColumnNode.create(column), TableNode.create(table));
|
|
1166
|
+
}
|
|
1167
|
+
function trim(str) {
|
|
1168
|
+
return str.trim();
|
|
1169
|
+
}
|
|
1170
|
+
|
|
1171
|
+
// ../../node_modules/.pnpm/kysely@0.29.8/node_modules/kysely/dist/operation-node/primitive-value-list-node.js
|
|
1172
|
+
var PrimitiveValueListNode = freeze({
|
|
1173
|
+
is(node) {
|
|
1174
|
+
return node.kind === "PrimitiveValueListNode";
|
|
1175
|
+
},
|
|
1176
|
+
create(values) {
|
|
1177
|
+
return freeze({
|
|
1178
|
+
kind: "PrimitiveValueListNode",
|
|
1179
|
+
values: freeze([...values])
|
|
1180
|
+
});
|
|
1181
|
+
}
|
|
1182
|
+
});
|
|
1183
|
+
|
|
1184
|
+
// ../../node_modules/.pnpm/kysely@0.29.8/node_modules/kysely/dist/operation-node/value-list-node.js
|
|
1185
|
+
var ValueListNode = freeze({
|
|
1186
|
+
is(node) {
|
|
1187
|
+
return node.kind === "ValueListNode";
|
|
1188
|
+
},
|
|
1189
|
+
create(values) {
|
|
1190
|
+
return freeze({
|
|
1191
|
+
kind: "ValueListNode",
|
|
1192
|
+
values: freeze(values)
|
|
1193
|
+
});
|
|
1194
|
+
}
|
|
1195
|
+
});
|
|
1196
|
+
|
|
1197
|
+
// ../../node_modules/.pnpm/kysely@0.29.8/node_modules/kysely/dist/operation-node/value-node.js
|
|
1198
|
+
var ValueNode = freeze({
|
|
1199
|
+
is(node) {
|
|
1200
|
+
return node.kind === "ValueNode";
|
|
1201
|
+
},
|
|
1202
|
+
create(value) {
|
|
1203
|
+
return freeze({
|
|
1204
|
+
kind: "ValueNode",
|
|
1205
|
+
value
|
|
1206
|
+
});
|
|
1207
|
+
},
|
|
1208
|
+
createImmediate(value) {
|
|
1209
|
+
return freeze({
|
|
1210
|
+
kind: "ValueNode",
|
|
1211
|
+
value,
|
|
1212
|
+
immediate: true
|
|
1213
|
+
});
|
|
1214
|
+
}
|
|
1215
|
+
});
|
|
1216
|
+
|
|
1217
|
+
// ../../node_modules/.pnpm/kysely@0.29.8/node_modules/kysely/dist/parser/value-parser.js
|
|
1218
|
+
function parseValueExpressionOrList(arg) {
|
|
1219
|
+
if (isReadonlyArray(arg)) {
|
|
1220
|
+
return parseValueExpressionList(arg);
|
|
1221
|
+
}
|
|
1222
|
+
return parseValueExpression(arg);
|
|
1223
|
+
}
|
|
1224
|
+
function parseValueExpression(exp) {
|
|
1225
|
+
if (isExpressionOrFactory(exp)) {
|
|
1226
|
+
return parseExpression(exp);
|
|
1227
|
+
}
|
|
1228
|
+
return ValueNode.create(exp);
|
|
1229
|
+
}
|
|
1230
|
+
function isSafeImmediateValue(value) {
|
|
1231
|
+
return isNumber(value) || isBoolean(value) || isNull(value);
|
|
1232
|
+
}
|
|
1233
|
+
function parseSafeImmediateValue(value) {
|
|
1234
|
+
if (!isSafeImmediateValue(value)) {
|
|
1235
|
+
throw new Error(`unsafe immediate value ${JSON.stringify(value)}`);
|
|
1236
|
+
}
|
|
1237
|
+
return ValueNode.createImmediate(value);
|
|
1238
|
+
}
|
|
1239
|
+
function parseValueExpressionList(arg) {
|
|
1240
|
+
if (arg.some(isExpressionOrFactory)) {
|
|
1241
|
+
return ValueListNode.create(arg.map((it) => parseValueExpression(it)));
|
|
1242
|
+
}
|
|
1243
|
+
return PrimitiveValueListNode.create(arg);
|
|
1244
|
+
}
|
|
1245
|
+
|
|
1246
|
+
// ../../node_modules/.pnpm/kysely@0.29.8/node_modules/kysely/dist/operation-node/parens-node.js
|
|
1247
|
+
var ParensNode = freeze({
|
|
1248
|
+
is(node) {
|
|
1249
|
+
return node.kind === "ParensNode";
|
|
1250
|
+
},
|
|
1251
|
+
create(node) {
|
|
1252
|
+
return freeze({
|
|
1253
|
+
kind: "ParensNode",
|
|
1254
|
+
node
|
|
1255
|
+
});
|
|
1256
|
+
}
|
|
1257
|
+
});
|
|
1258
|
+
|
|
1259
|
+
// ../../node_modules/.pnpm/kysely@0.29.8/node_modules/kysely/dist/parser/binary-operation-parser.js
|
|
1260
|
+
function parseValueBinaryOperationOrExpression(args) {
|
|
1261
|
+
if (args.length === 3) {
|
|
1262
|
+
return parseValueBinaryOperation(args[0], args[1], args[2]);
|
|
1263
|
+
} else if (args.length === 1) {
|
|
1264
|
+
return parseValueExpression(args[0]);
|
|
1265
|
+
}
|
|
1266
|
+
throw new Error(`invalid arguments: ${JSON.stringify(args)}`);
|
|
1267
|
+
}
|
|
1268
|
+
function parseValueBinaryOperation(left, operator, right) {
|
|
1269
|
+
if (isIsOperator(operator) && needsIsOperator(right)) {
|
|
1270
|
+
return BinaryOperationNode.create(parseReferenceExpression(left), parseBinaryOperator(operator), ValueNode.createImmediate(right));
|
|
1271
|
+
}
|
|
1272
|
+
return BinaryOperationNode.create(parseReferenceExpression(left), parseBinaryOperator(operator), parseValueExpressionOrList(right));
|
|
1273
|
+
}
|
|
1274
|
+
function parseReferentialBinaryOperation(left, operator, right) {
|
|
1275
|
+
return BinaryOperationNode.create(parseReferenceExpression(left), parseBinaryOperator(operator), parseReferenceExpression(right));
|
|
1276
|
+
}
|
|
1277
|
+
function parseFilterObject(obj, combinator) {
|
|
1278
|
+
return parseFilterList(Object.entries(obj).filter(([, v]) => !isUndefined(v)).map(([k, v]) => parseValueBinaryOperation(k, needsIsOperator(v) ? "is" : "=", v)), combinator);
|
|
1279
|
+
}
|
|
1280
|
+
function parseFilterList(list, combinator, withParens = true) {
|
|
1281
|
+
const combine = combinator === "and" ? AndNode.create : OrNode.create;
|
|
1282
|
+
if (list.length === 0) {
|
|
1283
|
+
return BinaryOperationNode.create(ValueNode.createImmediate(1), OperatorNode.create("="), ValueNode.createImmediate(combinator === "and" ? 1 : 0));
|
|
1284
|
+
}
|
|
1285
|
+
let node = toOperationNode(list[0]);
|
|
1286
|
+
for (let i = 1; i < list.length; ++i) {
|
|
1287
|
+
node = combine(node, toOperationNode(list[i]));
|
|
1288
|
+
}
|
|
1289
|
+
if (list.length > 1 && withParens) {
|
|
1290
|
+
return ParensNode.create(node);
|
|
1291
|
+
}
|
|
1292
|
+
return node;
|
|
1293
|
+
}
|
|
1294
|
+
function isIsOperator(operator) {
|
|
1295
|
+
return operator === "is" || operator === "is not";
|
|
1296
|
+
}
|
|
1297
|
+
function needsIsOperator(value) {
|
|
1298
|
+
return isNull(value) || isBoolean(value);
|
|
1299
|
+
}
|
|
1300
|
+
function parseBinaryOperator(operator) {
|
|
1301
|
+
if (isBinaryOperator(operator)) {
|
|
1302
|
+
return OperatorNode.create(operator);
|
|
1303
|
+
}
|
|
1304
|
+
if (isOperationNodeSource(operator)) {
|
|
1305
|
+
return operator.toOperationNode();
|
|
1306
|
+
}
|
|
1307
|
+
throw new Error(`invalid operator ${JSON.stringify(operator)}`);
|
|
1308
|
+
}
|
|
1309
|
+
function toOperationNode(nodeOrSource) {
|
|
1310
|
+
return isOperationNodeSource(nodeOrSource) ? nodeOrSource.toOperationNode() : nodeOrSource;
|
|
1311
|
+
}
|
|
1312
|
+
|
|
1313
|
+
// ../../node_modules/.pnpm/kysely@0.29.8/node_modules/kysely/dist/operation-node/order-by-node.js
|
|
1314
|
+
var OrderByNode = freeze({
|
|
1315
|
+
is(node) {
|
|
1316
|
+
return node.kind === "OrderByNode";
|
|
1317
|
+
},
|
|
1318
|
+
create(items) {
|
|
1319
|
+
return freeze({
|
|
1320
|
+
kind: "OrderByNode",
|
|
1321
|
+
items: freeze([...items])
|
|
1322
|
+
});
|
|
1323
|
+
},
|
|
1324
|
+
cloneWithItems(orderBy, items) {
|
|
1325
|
+
return freeze({
|
|
1326
|
+
...orderBy,
|
|
1327
|
+
items: freeze([...orderBy.items, ...items])
|
|
1328
|
+
});
|
|
1329
|
+
}
|
|
1330
|
+
});
|
|
1331
|
+
|
|
1332
|
+
// ../../node_modules/.pnpm/kysely@0.29.8/node_modules/kysely/dist/operation-node/partition-by-node.js
|
|
1333
|
+
var PartitionByNode = freeze({
|
|
1334
|
+
is(node) {
|
|
1335
|
+
return node.kind === "PartitionByNode";
|
|
1336
|
+
},
|
|
1337
|
+
create(items) {
|
|
1338
|
+
return freeze({
|
|
1339
|
+
kind: "PartitionByNode",
|
|
1340
|
+
items: freeze(items)
|
|
1341
|
+
});
|
|
1342
|
+
},
|
|
1343
|
+
cloneWithItems(partitionBy, items) {
|
|
1344
|
+
return freeze({
|
|
1345
|
+
...partitionBy,
|
|
1346
|
+
items: freeze([...partitionBy.items, ...items])
|
|
1347
|
+
});
|
|
1348
|
+
}
|
|
1349
|
+
});
|
|
1350
|
+
|
|
1351
|
+
// ../../node_modules/.pnpm/kysely@0.29.8/node_modules/kysely/dist/operation-node/over-node.js
|
|
1352
|
+
var OverNode = freeze({
|
|
1353
|
+
is(node) {
|
|
1354
|
+
return node.kind === "OverNode";
|
|
1355
|
+
},
|
|
1356
|
+
create() {
|
|
1357
|
+
return freeze({
|
|
1358
|
+
kind: "OverNode"
|
|
1359
|
+
});
|
|
1360
|
+
},
|
|
1361
|
+
cloneWithOrderByItems(overNode, items) {
|
|
1362
|
+
return freeze({
|
|
1363
|
+
...overNode,
|
|
1364
|
+
orderBy: overNode.orderBy ? OrderByNode.cloneWithItems(overNode.orderBy, items) : OrderByNode.create(items)
|
|
1365
|
+
});
|
|
1366
|
+
},
|
|
1367
|
+
cloneWithPartitionByItems(overNode, items) {
|
|
1368
|
+
return freeze({
|
|
1369
|
+
...overNode,
|
|
1370
|
+
partitionBy: overNode.partitionBy ? PartitionByNode.cloneWithItems(overNode.partitionBy, items) : PartitionByNode.create(items)
|
|
1371
|
+
});
|
|
1372
|
+
}
|
|
1373
|
+
});
|
|
1374
|
+
|
|
1375
|
+
// ../../node_modules/.pnpm/kysely@0.29.8/node_modules/kysely/dist/operation-node/from-node.js
|
|
1376
|
+
var FromNode = freeze({
|
|
1377
|
+
is(node) {
|
|
1378
|
+
return node.kind === "FromNode";
|
|
1379
|
+
},
|
|
1380
|
+
create(froms) {
|
|
1381
|
+
return freeze({
|
|
1382
|
+
kind: "FromNode",
|
|
1383
|
+
froms: freeze(froms)
|
|
1384
|
+
});
|
|
1385
|
+
},
|
|
1386
|
+
cloneWithFroms(from, froms) {
|
|
1387
|
+
return freeze({
|
|
1388
|
+
...from,
|
|
1389
|
+
froms: freeze([...from.froms, ...froms])
|
|
1390
|
+
});
|
|
1391
|
+
}
|
|
1392
|
+
});
|
|
1393
|
+
|
|
1394
|
+
// ../../node_modules/.pnpm/kysely@0.29.8/node_modules/kysely/dist/operation-node/group-by-node.js
|
|
1395
|
+
var GroupByNode = freeze({
|
|
1396
|
+
is(node) {
|
|
1397
|
+
return node.kind === "GroupByNode";
|
|
1398
|
+
},
|
|
1399
|
+
create(items) {
|
|
1400
|
+
return freeze({
|
|
1401
|
+
kind: "GroupByNode",
|
|
1402
|
+
items: freeze(items)
|
|
1403
|
+
});
|
|
1404
|
+
},
|
|
1405
|
+
cloneWithItems(groupBy, items) {
|
|
1406
|
+
return freeze({
|
|
1407
|
+
...groupBy,
|
|
1408
|
+
items: freeze([...groupBy.items, ...items])
|
|
1409
|
+
});
|
|
1410
|
+
}
|
|
1411
|
+
});
|
|
1412
|
+
|
|
1413
|
+
// ../../node_modules/.pnpm/kysely@0.29.8/node_modules/kysely/dist/operation-node/having-node.js
|
|
1414
|
+
var HavingNode = freeze({
|
|
1415
|
+
is(node) {
|
|
1416
|
+
return node.kind === "HavingNode";
|
|
1417
|
+
},
|
|
1418
|
+
create(filter) {
|
|
1419
|
+
return freeze({
|
|
1420
|
+
kind: "HavingNode",
|
|
1421
|
+
having: filter
|
|
1422
|
+
});
|
|
1423
|
+
},
|
|
1424
|
+
cloneWithOperation(havingNode, operator, operation) {
|
|
1425
|
+
return freeze({
|
|
1426
|
+
...havingNode,
|
|
1427
|
+
having: operator === "And" ? AndNode.create(havingNode.having, operation) : OrNode.create(havingNode.having, operation)
|
|
1428
|
+
});
|
|
1429
|
+
}
|
|
1430
|
+
});
|
|
1431
|
+
|
|
1432
|
+
// ../../node_modules/.pnpm/kysely@0.29.8/node_modules/kysely/dist/operation-node/insert-query-node.js
|
|
1433
|
+
var InsertQueryNode = freeze({
|
|
1434
|
+
is(node) {
|
|
1435
|
+
return node.kind === "InsertQueryNode";
|
|
1436
|
+
},
|
|
1437
|
+
create(into, withNode, replace) {
|
|
1438
|
+
return freeze({
|
|
1439
|
+
kind: "InsertQueryNode",
|
|
1440
|
+
into,
|
|
1441
|
+
...withNode && { with: withNode },
|
|
1442
|
+
replace
|
|
1443
|
+
});
|
|
1444
|
+
},
|
|
1445
|
+
createWithoutInto() {
|
|
1446
|
+
return freeze({
|
|
1447
|
+
kind: "InsertQueryNode"
|
|
1448
|
+
});
|
|
1449
|
+
},
|
|
1450
|
+
cloneWith(insertQuery, props) {
|
|
1451
|
+
return freeze({
|
|
1452
|
+
...insertQuery,
|
|
1453
|
+
...props
|
|
1454
|
+
});
|
|
1455
|
+
}
|
|
1456
|
+
});
|
|
1457
|
+
|
|
1458
|
+
// ../../node_modules/.pnpm/kysely@0.29.8/node_modules/kysely/dist/operation-node/list-node.js
|
|
1459
|
+
var ListNode = freeze({
|
|
1460
|
+
is(node) {
|
|
1461
|
+
return node.kind === "ListNode";
|
|
1462
|
+
},
|
|
1463
|
+
create(items) {
|
|
1464
|
+
return freeze({
|
|
1465
|
+
kind: "ListNode",
|
|
1466
|
+
items: freeze(items)
|
|
1467
|
+
});
|
|
1468
|
+
}
|
|
1469
|
+
});
|
|
1470
|
+
|
|
1471
|
+
// ../../node_modules/.pnpm/kysely@0.29.8/node_modules/kysely/dist/operation-node/update-query-node.js
|
|
1472
|
+
var UpdateQueryNode = freeze({
|
|
1473
|
+
is(node) {
|
|
1474
|
+
return node.kind === "UpdateQueryNode";
|
|
1475
|
+
},
|
|
1476
|
+
create(tables, withNode) {
|
|
1477
|
+
return freeze({
|
|
1478
|
+
kind: "UpdateQueryNode",
|
|
1479
|
+
// For backwards compatibility, use the raw table node when there's only one table
|
|
1480
|
+
// and don't rename the property to something like `tables`.
|
|
1481
|
+
table: tables.length === 1 ? tables[0] : ListNode.create(tables),
|
|
1482
|
+
...withNode && { with: withNode }
|
|
1483
|
+
});
|
|
1484
|
+
},
|
|
1485
|
+
createWithoutTable() {
|
|
1486
|
+
return freeze({
|
|
1487
|
+
kind: "UpdateQueryNode"
|
|
1488
|
+
});
|
|
1489
|
+
},
|
|
1490
|
+
cloneWithFromItems(updateQuery, fromItems) {
|
|
1491
|
+
return freeze({
|
|
1492
|
+
...updateQuery,
|
|
1493
|
+
from: updateQuery.from ? FromNode.cloneWithFroms(updateQuery.from, fromItems) : FromNode.create(fromItems)
|
|
1494
|
+
});
|
|
1495
|
+
},
|
|
1496
|
+
cloneWithUpdates(updateQuery, updates) {
|
|
1497
|
+
return freeze({
|
|
1498
|
+
...updateQuery,
|
|
1499
|
+
updates: updateQuery.updates ? freeze([...updateQuery.updates, ...updates]) : updates
|
|
1500
|
+
});
|
|
1501
|
+
},
|
|
1502
|
+
cloneWithLimit(updateQuery, limit) {
|
|
1503
|
+
return freeze({
|
|
1504
|
+
...updateQuery,
|
|
1505
|
+
limit
|
|
1506
|
+
});
|
|
1507
|
+
}
|
|
1508
|
+
});
|
|
1509
|
+
|
|
1510
|
+
// ../../node_modules/.pnpm/kysely@0.29.8/node_modules/kysely/dist/operation-node/using-node.js
|
|
1511
|
+
var UsingNode = freeze({
|
|
1512
|
+
is(node) {
|
|
1513
|
+
return node.kind === "UsingNode";
|
|
1514
|
+
},
|
|
1515
|
+
create(tables) {
|
|
1516
|
+
return freeze({
|
|
1517
|
+
kind: "UsingNode",
|
|
1518
|
+
tables: freeze(tables)
|
|
1519
|
+
});
|
|
1520
|
+
},
|
|
1521
|
+
cloneWithTables(using, tables) {
|
|
1522
|
+
return freeze({
|
|
1523
|
+
...using,
|
|
1524
|
+
tables: freeze([...using.tables, ...tables])
|
|
1525
|
+
});
|
|
1526
|
+
}
|
|
1527
|
+
});
|
|
1528
|
+
|
|
1529
|
+
// ../../node_modules/.pnpm/kysely@0.29.8/node_modules/kysely/dist/operation-node/delete-query-node.js
|
|
1530
|
+
var DeleteQueryNode = freeze({
|
|
1531
|
+
is(node) {
|
|
1532
|
+
return node.kind === "DeleteQueryNode";
|
|
1533
|
+
},
|
|
1534
|
+
create(fromItems, withNode) {
|
|
1535
|
+
return freeze({
|
|
1536
|
+
kind: "DeleteQueryNode",
|
|
1537
|
+
from: FromNode.create(fromItems),
|
|
1538
|
+
...withNode && { with: withNode }
|
|
1539
|
+
});
|
|
1540
|
+
},
|
|
1541
|
+
// TODO: remove in v0.29
|
|
1542
|
+
/**
|
|
1543
|
+
* @deprecated Use `QueryNode.cloneWithoutOrderBy` instead.
|
|
1544
|
+
*/
|
|
1545
|
+
cloneWithOrderByItems: (node, items) => QueryNode.cloneWithOrderByItems(node, items),
|
|
1546
|
+
// TODO: remove in v0.29
|
|
1547
|
+
/**
|
|
1548
|
+
* @deprecated Use `QueryNode.cloneWithoutOrderBy` instead.
|
|
1549
|
+
*/
|
|
1550
|
+
cloneWithoutOrderBy: (node) => QueryNode.cloneWithoutOrderBy(node),
|
|
1551
|
+
cloneWithLimit(deleteNode, limit) {
|
|
1552
|
+
return freeze({
|
|
1553
|
+
...deleteNode,
|
|
1554
|
+
limit
|
|
1555
|
+
});
|
|
1556
|
+
},
|
|
1557
|
+
cloneWithoutLimit(deleteNode) {
|
|
1558
|
+
return freeze({
|
|
1559
|
+
...deleteNode,
|
|
1560
|
+
limit: void 0
|
|
1561
|
+
});
|
|
1562
|
+
},
|
|
1563
|
+
cloneWithUsing(deleteNode, tables) {
|
|
1564
|
+
return freeze({
|
|
1565
|
+
...deleteNode,
|
|
1566
|
+
using: deleteNode.using !== void 0 ? UsingNode.cloneWithTables(deleteNode.using, tables) : UsingNode.create(tables)
|
|
1567
|
+
});
|
|
1568
|
+
}
|
|
1569
|
+
});
|
|
1570
|
+
|
|
1571
|
+
// ../../node_modules/.pnpm/kysely@0.29.8/node_modules/kysely/dist/operation-node/where-node.js
|
|
1572
|
+
var WhereNode = freeze({
|
|
1573
|
+
is(node) {
|
|
1574
|
+
return node.kind === "WhereNode";
|
|
1575
|
+
},
|
|
1576
|
+
create(filter) {
|
|
1577
|
+
return freeze({
|
|
1578
|
+
kind: "WhereNode",
|
|
1579
|
+
where: filter
|
|
1580
|
+
});
|
|
1581
|
+
},
|
|
1582
|
+
cloneWithOperation(whereNode, operator, operation) {
|
|
1583
|
+
return freeze({
|
|
1584
|
+
...whereNode,
|
|
1585
|
+
where: operator === "And" ? AndNode.create(whereNode.where, operation) : OrNode.create(whereNode.where, operation)
|
|
1586
|
+
});
|
|
1587
|
+
}
|
|
1588
|
+
});
|
|
1589
|
+
|
|
1590
|
+
// ../../node_modules/.pnpm/kysely@0.29.8/node_modules/kysely/dist/operation-node/returning-node.js
|
|
1591
|
+
var ReturningNode = freeze({
|
|
1592
|
+
is(node) {
|
|
1593
|
+
return node.kind === "ReturningNode";
|
|
1594
|
+
},
|
|
1595
|
+
create(selections) {
|
|
1596
|
+
return freeze({
|
|
1597
|
+
kind: "ReturningNode",
|
|
1598
|
+
selections: freeze(selections)
|
|
1599
|
+
});
|
|
1600
|
+
},
|
|
1601
|
+
cloneWithSelections(returning, selections) {
|
|
1602
|
+
return freeze({
|
|
1603
|
+
...returning,
|
|
1604
|
+
selections: returning.selections ? freeze([...returning.selections, ...selections]) : freeze(selections)
|
|
1605
|
+
});
|
|
1606
|
+
}
|
|
1607
|
+
});
|
|
1608
|
+
|
|
1609
|
+
// ../../node_modules/.pnpm/kysely@0.29.8/node_modules/kysely/dist/operation-node/explain-node.js
|
|
1610
|
+
var ExplainNode = freeze({
|
|
1611
|
+
is(node) {
|
|
1612
|
+
return node.kind === "ExplainNode";
|
|
1613
|
+
},
|
|
1614
|
+
create(format, options) {
|
|
1615
|
+
return freeze({
|
|
1616
|
+
kind: "ExplainNode",
|
|
1617
|
+
format,
|
|
1618
|
+
options
|
|
1619
|
+
});
|
|
1620
|
+
}
|
|
1621
|
+
});
|
|
1622
|
+
|
|
1623
|
+
// ../../node_modules/.pnpm/kysely@0.29.8/node_modules/kysely/dist/operation-node/when-node.js
|
|
1624
|
+
var WhenNode = freeze({
|
|
1625
|
+
is(node) {
|
|
1626
|
+
return node.kind === "WhenNode";
|
|
1627
|
+
},
|
|
1628
|
+
create(condition) {
|
|
1629
|
+
return freeze({
|
|
1630
|
+
kind: "WhenNode",
|
|
1631
|
+
condition
|
|
1632
|
+
});
|
|
1633
|
+
},
|
|
1634
|
+
cloneWithResult(whenNode, result) {
|
|
1635
|
+
return freeze({
|
|
1636
|
+
...whenNode,
|
|
1637
|
+
result
|
|
1638
|
+
});
|
|
1639
|
+
}
|
|
1640
|
+
});
|
|
1641
|
+
|
|
1642
|
+
// ../../node_modules/.pnpm/kysely@0.29.8/node_modules/kysely/dist/operation-node/merge-query-node.js
|
|
1643
|
+
var MergeQueryNode = freeze({
|
|
1644
|
+
is(node) {
|
|
1645
|
+
return node.kind === "MergeQueryNode";
|
|
1646
|
+
},
|
|
1647
|
+
create(into, withNode) {
|
|
1648
|
+
return freeze({
|
|
1649
|
+
kind: "MergeQueryNode",
|
|
1650
|
+
into,
|
|
1651
|
+
...withNode && { with: withNode }
|
|
1652
|
+
});
|
|
1653
|
+
},
|
|
1654
|
+
cloneWithUsing(mergeNode, using) {
|
|
1655
|
+
return freeze({
|
|
1656
|
+
...mergeNode,
|
|
1657
|
+
using
|
|
1658
|
+
});
|
|
1659
|
+
},
|
|
1660
|
+
cloneWithWhen(mergeNode, when) {
|
|
1661
|
+
return freeze({
|
|
1662
|
+
...mergeNode,
|
|
1663
|
+
whens: mergeNode.whens ? freeze([...mergeNode.whens, when]) : freeze([when])
|
|
1664
|
+
});
|
|
1665
|
+
},
|
|
1666
|
+
cloneWithThen(mergeNode, then) {
|
|
1667
|
+
return freeze({
|
|
1668
|
+
...mergeNode,
|
|
1669
|
+
whens: mergeNode.whens ? freeze([
|
|
1670
|
+
...mergeNode.whens.slice(0, -1),
|
|
1671
|
+
WhenNode.cloneWithResult(mergeNode.whens[mergeNode.whens.length - 1], then)
|
|
1672
|
+
]) : void 0
|
|
1673
|
+
});
|
|
1674
|
+
}
|
|
1675
|
+
});
|
|
1676
|
+
|
|
1677
|
+
// ../../node_modules/.pnpm/kysely@0.29.8/node_modules/kysely/dist/operation-node/output-node.js
|
|
1678
|
+
var OutputNode = freeze({
|
|
1679
|
+
is(node) {
|
|
1680
|
+
return node.kind === "OutputNode";
|
|
1681
|
+
},
|
|
1682
|
+
create(selections) {
|
|
1683
|
+
return freeze({
|
|
1684
|
+
kind: "OutputNode",
|
|
1685
|
+
selections: freeze(selections)
|
|
1686
|
+
});
|
|
1687
|
+
},
|
|
1688
|
+
cloneWithSelections(output, selections) {
|
|
1689
|
+
return freeze({
|
|
1690
|
+
...output,
|
|
1691
|
+
selections: output.selections ? freeze([...output.selections, ...selections]) : freeze(selections)
|
|
1692
|
+
});
|
|
1693
|
+
}
|
|
1694
|
+
});
|
|
1695
|
+
|
|
1696
|
+
// ../../node_modules/.pnpm/kysely@0.29.8/node_modules/kysely/dist/operation-node/query-node.js
|
|
1697
|
+
var QueryNode = freeze({
|
|
1698
|
+
is(node) {
|
|
1699
|
+
return SelectQueryNode.is(node) || InsertQueryNode.is(node) || UpdateQueryNode.is(node) || DeleteQueryNode.is(node) || MergeQueryNode.is(node);
|
|
1700
|
+
},
|
|
1701
|
+
cloneWithEndModifier(node, modifier) {
|
|
1702
|
+
return freeze({
|
|
1703
|
+
...node,
|
|
1704
|
+
endModifiers: node.endModifiers ? freeze([...node.endModifiers, modifier]) : freeze([modifier])
|
|
1705
|
+
});
|
|
1706
|
+
},
|
|
1707
|
+
cloneWithWhere(node, operation) {
|
|
1708
|
+
return freeze({
|
|
1709
|
+
...node,
|
|
1710
|
+
where: node.where ? WhereNode.cloneWithOperation(node.where, "And", operation) : WhereNode.create(operation)
|
|
1711
|
+
});
|
|
1712
|
+
},
|
|
1713
|
+
cloneWithJoin(node, join) {
|
|
1714
|
+
return freeze({
|
|
1715
|
+
...node,
|
|
1716
|
+
joins: node.joins ? freeze([...node.joins, join]) : freeze([join])
|
|
1717
|
+
});
|
|
1718
|
+
},
|
|
1719
|
+
cloneWithReturning(node, selections) {
|
|
1720
|
+
return freeze({
|
|
1721
|
+
...node,
|
|
1722
|
+
returning: node.returning ? ReturningNode.cloneWithSelections(node.returning, selections) : ReturningNode.create(selections)
|
|
1723
|
+
});
|
|
1724
|
+
},
|
|
1725
|
+
cloneWithoutReturning(node) {
|
|
1726
|
+
return freeze({
|
|
1727
|
+
...node,
|
|
1728
|
+
returning: void 0
|
|
1729
|
+
});
|
|
1730
|
+
},
|
|
1731
|
+
cloneWithoutWhere(node) {
|
|
1732
|
+
return freeze({
|
|
1733
|
+
...node,
|
|
1734
|
+
where: void 0
|
|
1735
|
+
});
|
|
1736
|
+
},
|
|
1737
|
+
cloneWithExplain(node, format, options) {
|
|
1738
|
+
return freeze({
|
|
1739
|
+
...node,
|
|
1740
|
+
explain: ExplainNode.create(format, options?.toOperationNode())
|
|
1741
|
+
});
|
|
1742
|
+
},
|
|
1743
|
+
cloneWithTop(node, top) {
|
|
1744
|
+
return freeze({
|
|
1745
|
+
...node,
|
|
1746
|
+
top
|
|
1747
|
+
});
|
|
1748
|
+
},
|
|
1749
|
+
cloneWithOutput(node, selections) {
|
|
1750
|
+
return freeze({
|
|
1751
|
+
...node,
|
|
1752
|
+
output: node.output ? OutputNode.cloneWithSelections(node.output, selections) : OutputNode.create(selections)
|
|
1753
|
+
});
|
|
1754
|
+
},
|
|
1755
|
+
cloneWithOrderByItems(node, items) {
|
|
1756
|
+
return freeze({
|
|
1757
|
+
...node,
|
|
1758
|
+
orderBy: node.orderBy ? OrderByNode.cloneWithItems(node.orderBy, items) : OrderByNode.create(items)
|
|
1759
|
+
});
|
|
1760
|
+
},
|
|
1761
|
+
cloneWithoutOrderBy(node) {
|
|
1762
|
+
return freeze({
|
|
1763
|
+
...node,
|
|
1764
|
+
orderBy: void 0
|
|
1765
|
+
});
|
|
1766
|
+
}
|
|
1767
|
+
});
|
|
1768
|
+
|
|
1769
|
+
// ../../node_modules/.pnpm/kysely@0.29.8/node_modules/kysely/dist/operation-node/select-query-node.js
|
|
1770
|
+
var SelectQueryNode = freeze({
|
|
1771
|
+
is(node) {
|
|
1772
|
+
return node.kind === "SelectQueryNode";
|
|
1773
|
+
},
|
|
1774
|
+
create(withNode) {
|
|
1775
|
+
return freeze({
|
|
1776
|
+
kind: "SelectQueryNode",
|
|
1777
|
+
...withNode && { with: withNode }
|
|
1778
|
+
});
|
|
1779
|
+
},
|
|
1780
|
+
createFrom(fromItems, withNode) {
|
|
1781
|
+
return freeze({
|
|
1782
|
+
kind: "SelectQueryNode",
|
|
1783
|
+
from: FromNode.create(fromItems),
|
|
1784
|
+
...withNode && { with: withNode }
|
|
1785
|
+
});
|
|
1786
|
+
},
|
|
1787
|
+
cloneWithSelections(select, selections) {
|
|
1788
|
+
return freeze({
|
|
1789
|
+
...select,
|
|
1790
|
+
selections: select.selections ? freeze([...select.selections, ...selections]) : freeze(selections)
|
|
1791
|
+
});
|
|
1792
|
+
},
|
|
1793
|
+
cloneWithDistinctOn(select, expressions) {
|
|
1794
|
+
return freeze({
|
|
1795
|
+
...select,
|
|
1796
|
+
distinctOn: select.distinctOn ? freeze([...select.distinctOn, ...expressions]) : freeze(expressions)
|
|
1797
|
+
});
|
|
1798
|
+
},
|
|
1799
|
+
cloneWithFrontModifier(select, modifier) {
|
|
1800
|
+
return freeze({
|
|
1801
|
+
...select,
|
|
1802
|
+
frontModifiers: select.frontModifiers ? freeze([...select.frontModifiers, modifier]) : freeze([modifier])
|
|
1803
|
+
});
|
|
1804
|
+
},
|
|
1805
|
+
// TODO: remove in v0.29
|
|
1806
|
+
/**
|
|
1807
|
+
* @deprecated Use `QueryNode.cloneWithoutOrderBy` instead.
|
|
1808
|
+
*/
|
|
1809
|
+
cloneWithOrderByItems: (node, items) => QueryNode.cloneWithOrderByItems(node, items),
|
|
1810
|
+
cloneWithGroupByItems(selectNode, items) {
|
|
1811
|
+
return freeze({
|
|
1812
|
+
...selectNode,
|
|
1813
|
+
groupBy: selectNode.groupBy ? GroupByNode.cloneWithItems(selectNode.groupBy, items) : GroupByNode.create(items)
|
|
1814
|
+
});
|
|
1815
|
+
},
|
|
1816
|
+
cloneWithLimit(selectNode, limit) {
|
|
1817
|
+
return freeze({
|
|
1818
|
+
...selectNode,
|
|
1819
|
+
limit
|
|
1820
|
+
});
|
|
1821
|
+
},
|
|
1822
|
+
cloneWithOffset(selectNode, offset) {
|
|
1823
|
+
return freeze({
|
|
1824
|
+
...selectNode,
|
|
1825
|
+
offset
|
|
1826
|
+
});
|
|
1827
|
+
},
|
|
1828
|
+
cloneWithFetch(selectNode, fetch) {
|
|
1829
|
+
return freeze({
|
|
1830
|
+
...selectNode,
|
|
1831
|
+
fetch
|
|
1832
|
+
});
|
|
1833
|
+
},
|
|
1834
|
+
cloneWithHaving(selectNode, operation) {
|
|
1835
|
+
return freeze({
|
|
1836
|
+
...selectNode,
|
|
1837
|
+
having: selectNode.having ? HavingNode.cloneWithOperation(selectNode.having, "And", operation) : HavingNode.create(operation)
|
|
1838
|
+
});
|
|
1839
|
+
},
|
|
1840
|
+
cloneWithSetOperations(selectNode, setOperations) {
|
|
1841
|
+
return freeze({
|
|
1842
|
+
...selectNode,
|
|
1843
|
+
setOperations: selectNode.setOperations ? freeze([...selectNode.setOperations, ...setOperations]) : freeze([...setOperations])
|
|
1844
|
+
});
|
|
1845
|
+
},
|
|
1846
|
+
cloneWithoutSelections(select) {
|
|
1847
|
+
return freeze({
|
|
1848
|
+
...select,
|
|
1849
|
+
selections: []
|
|
1850
|
+
});
|
|
1851
|
+
},
|
|
1852
|
+
cloneWithoutLimit(select) {
|
|
1853
|
+
return freeze({
|
|
1854
|
+
...select,
|
|
1855
|
+
limit: void 0
|
|
1856
|
+
});
|
|
1857
|
+
},
|
|
1858
|
+
cloneWithoutOffset(select) {
|
|
1859
|
+
return freeze({
|
|
1860
|
+
...select,
|
|
1861
|
+
offset: void 0
|
|
1862
|
+
});
|
|
1863
|
+
},
|
|
1864
|
+
// TODO: remove in v0.29
|
|
1865
|
+
/**
|
|
1866
|
+
* @deprecated Use `QueryNode.cloneWithoutOrderBy` instead.
|
|
1867
|
+
*/
|
|
1868
|
+
cloneWithoutOrderBy: (node) => QueryNode.cloneWithoutOrderBy(node),
|
|
1869
|
+
cloneWithoutGroupBy(select) {
|
|
1870
|
+
return freeze({
|
|
1871
|
+
...select,
|
|
1872
|
+
groupBy: void 0
|
|
1873
|
+
});
|
|
1874
|
+
}
|
|
1875
|
+
});
|
|
1876
|
+
|
|
1877
|
+
// ../../node_modules/.pnpm/kysely@0.29.8/node_modules/kysely/dist/query-builder/join-builder.js
|
|
1878
|
+
var JoinBuilder = class _JoinBuilder {
|
|
1879
|
+
#props;
|
|
1880
|
+
constructor(props) {
|
|
1881
|
+
this.#props = freeze(props);
|
|
1882
|
+
}
|
|
1883
|
+
on(...args) {
|
|
1884
|
+
return new _JoinBuilder({
|
|
1885
|
+
...this.#props,
|
|
1886
|
+
joinNode: JoinNode.cloneWithOn(this.#props.joinNode, parseValueBinaryOperationOrExpression(args))
|
|
1887
|
+
});
|
|
1888
|
+
}
|
|
1889
|
+
/**
|
|
1890
|
+
* Just like {@link WhereInterface.whereRef} but adds an item to the join's
|
|
1891
|
+
* `on` clause instead.
|
|
1892
|
+
*
|
|
1893
|
+
* See {@link WhereInterface.whereRef} for documentation and examples.
|
|
1894
|
+
*/
|
|
1895
|
+
onRef(lhs, op, rhs) {
|
|
1896
|
+
return new _JoinBuilder({
|
|
1897
|
+
...this.#props,
|
|
1898
|
+
joinNode: JoinNode.cloneWithOn(this.#props.joinNode, parseReferentialBinaryOperation(lhs, op, rhs))
|
|
1899
|
+
});
|
|
1900
|
+
}
|
|
1901
|
+
/**
|
|
1902
|
+
* Adds `on true`.
|
|
1903
|
+
*/
|
|
1904
|
+
onTrue() {
|
|
1905
|
+
return new _JoinBuilder({
|
|
1906
|
+
...this.#props,
|
|
1907
|
+
joinNode: JoinNode.cloneWithOn(this.#props.joinNode, RawNode.createWithSql("true"))
|
|
1908
|
+
});
|
|
1909
|
+
}
|
|
1910
|
+
/**
|
|
1911
|
+
* Simply calls the provided function passing `this` as the only argument. `$call` returns
|
|
1912
|
+
* what the provided function returns.
|
|
1913
|
+
*/
|
|
1914
|
+
$call(func) {
|
|
1915
|
+
return func(this);
|
|
1916
|
+
}
|
|
1917
|
+
toOperationNode() {
|
|
1918
|
+
return this.#props.joinNode;
|
|
1919
|
+
}
|
|
1920
|
+
};
|
|
1921
|
+
|
|
1922
|
+
// ../../node_modules/.pnpm/kysely@0.29.8/node_modules/kysely/dist/operation-node/partition-by-item-node.js
|
|
1923
|
+
var PartitionByItemNode = freeze({
|
|
1924
|
+
is(node) {
|
|
1925
|
+
return node.kind === "PartitionByItemNode";
|
|
1926
|
+
},
|
|
1927
|
+
create(partitionBy) {
|
|
1928
|
+
return freeze({
|
|
1929
|
+
kind: "PartitionByItemNode",
|
|
1930
|
+
partitionBy
|
|
1931
|
+
});
|
|
1932
|
+
}
|
|
1933
|
+
});
|
|
1934
|
+
|
|
1935
|
+
// ../../node_modules/.pnpm/kysely@0.29.8/node_modules/kysely/dist/parser/partition-by-parser.js
|
|
1936
|
+
function parsePartitionBy(partitionBy) {
|
|
1937
|
+
return parseReferenceExpressionOrList(partitionBy).map(PartitionByItemNode.create);
|
|
1938
|
+
}
|
|
1939
|
+
|
|
1940
|
+
// ../../node_modules/.pnpm/kysely@0.29.8/node_modules/kysely/dist/query-builder/over-builder.js
|
|
1941
|
+
var OverBuilder = class _OverBuilder {
|
|
1942
|
+
#props;
|
|
1943
|
+
constructor(props) {
|
|
1944
|
+
this.#props = freeze(props);
|
|
1945
|
+
}
|
|
1946
|
+
orderBy(...args) {
|
|
1947
|
+
return new _OverBuilder({
|
|
1948
|
+
overNode: OverNode.cloneWithOrderByItems(this.#props.overNode, parseOrderBy(args))
|
|
1949
|
+
});
|
|
1950
|
+
}
|
|
1951
|
+
clearOrderBy() {
|
|
1952
|
+
return new _OverBuilder({
|
|
1953
|
+
overNode: QueryNode.cloneWithoutOrderBy(this.#props.overNode)
|
|
1954
|
+
});
|
|
1955
|
+
}
|
|
1956
|
+
partitionBy(partitionBy) {
|
|
1957
|
+
return new _OverBuilder({
|
|
1958
|
+
overNode: OverNode.cloneWithPartitionByItems(this.#props.overNode, parsePartitionBy(partitionBy))
|
|
1959
|
+
});
|
|
1960
|
+
}
|
|
1961
|
+
/**
|
|
1962
|
+
* Simply calls the provided function passing `this` as the only argument. `$call` returns
|
|
1963
|
+
* what the provided function returns.
|
|
1964
|
+
*/
|
|
1965
|
+
$call(func) {
|
|
1966
|
+
return func(this);
|
|
1967
|
+
}
|
|
1968
|
+
toOperationNode() {
|
|
1969
|
+
return this.#props.overNode;
|
|
1970
|
+
}
|
|
1971
|
+
};
|
|
1972
|
+
|
|
1973
|
+
// ../../node_modules/.pnpm/kysely@0.29.8/node_modules/kysely/dist/operation-node/selection-node.js
|
|
1974
|
+
var SelectionNode = freeze({
|
|
1975
|
+
is(node) {
|
|
1976
|
+
return node.kind === "SelectionNode";
|
|
1977
|
+
},
|
|
1978
|
+
create(selection) {
|
|
1979
|
+
return freeze({
|
|
1980
|
+
kind: "SelectionNode",
|
|
1981
|
+
selection
|
|
1982
|
+
});
|
|
1983
|
+
},
|
|
1984
|
+
createSelectAll() {
|
|
1985
|
+
return freeze({
|
|
1986
|
+
kind: "SelectionNode",
|
|
1987
|
+
selection: SelectAllNode.create()
|
|
1988
|
+
});
|
|
1989
|
+
},
|
|
1990
|
+
createSelectAllFromTable(table) {
|
|
1991
|
+
return freeze({
|
|
1992
|
+
kind: "SelectionNode",
|
|
1993
|
+
selection: ReferenceNode.createSelectAll(table)
|
|
1994
|
+
});
|
|
1995
|
+
}
|
|
1996
|
+
});
|
|
1997
|
+
|
|
1998
|
+
// ../../node_modules/.pnpm/kysely@0.29.8/node_modules/kysely/dist/parser/select-parser.js
|
|
1999
|
+
function parseSelectArg(selection) {
|
|
2000
|
+
if (isFunction(selection)) {
|
|
2001
|
+
return parseSelectArg(selection(expressionBuilder()));
|
|
2002
|
+
} else if (isReadonlyArray(selection)) {
|
|
2003
|
+
return selection.map((it) => parseSelectExpression(it));
|
|
2004
|
+
} else {
|
|
2005
|
+
return [parseSelectExpression(selection)];
|
|
2006
|
+
}
|
|
2007
|
+
}
|
|
2008
|
+
function parseSelectExpression(selection) {
|
|
2009
|
+
if (isString(selection)) {
|
|
2010
|
+
return SelectionNode.create(parseAliasedStringReference(selection));
|
|
2011
|
+
} else if (isDynamicReferenceBuilder(selection)) {
|
|
2012
|
+
return SelectionNode.create(selection.toOperationNode());
|
|
2013
|
+
} else {
|
|
2014
|
+
return SelectionNode.create(parseAliasedExpression(selection));
|
|
2015
|
+
}
|
|
2016
|
+
}
|
|
2017
|
+
function parseSelectAll(table) {
|
|
2018
|
+
if (!table) {
|
|
2019
|
+
return [SelectionNode.createSelectAll()];
|
|
2020
|
+
} else if (Array.isArray(table)) {
|
|
2021
|
+
return table.map(parseSelectAllArg);
|
|
2022
|
+
} else {
|
|
2023
|
+
return [parseSelectAllArg(table)];
|
|
2024
|
+
}
|
|
2025
|
+
}
|
|
2026
|
+
function parseSelectAllArg(table) {
|
|
2027
|
+
if (isString(table)) {
|
|
2028
|
+
return SelectionNode.createSelectAllFromTable(parseTable(table));
|
|
2029
|
+
}
|
|
2030
|
+
throw new Error(`invalid value selectAll expression: ${JSON.stringify(table)}`);
|
|
2031
|
+
}
|
|
2032
|
+
|
|
2033
|
+
// ../../node_modules/.pnpm/kysely@0.29.8/node_modules/kysely/dist/query-builder/no-result-error.js
|
|
2034
|
+
var NoResultError = class extends Error {
|
|
2035
|
+
/**
|
|
2036
|
+
* The operation node tree of the query that was executed.
|
|
2037
|
+
*/
|
|
2038
|
+
node;
|
|
2039
|
+
constructor(node) {
|
|
2040
|
+
super("no result");
|
|
2041
|
+
this.node = node;
|
|
2042
|
+
}
|
|
2043
|
+
};
|
|
2044
|
+
function isNoResultErrorConstructor(fn) {
|
|
2045
|
+
return Object.prototype.hasOwnProperty.call(fn, "prototype");
|
|
2046
|
+
}
|
|
2047
|
+
|
|
2048
|
+
// ../../node_modules/.pnpm/kysely@0.29.8/node_modules/kysely/dist/operation-node/top-node.js
|
|
2049
|
+
var TopNode = freeze({
|
|
2050
|
+
is(node) {
|
|
2051
|
+
return node.kind === "TopNode";
|
|
2052
|
+
},
|
|
2053
|
+
create(expression, modifiers) {
|
|
2054
|
+
return freeze({
|
|
2055
|
+
kind: "TopNode",
|
|
2056
|
+
expression,
|
|
2057
|
+
modifiers
|
|
2058
|
+
});
|
|
2059
|
+
}
|
|
2060
|
+
});
|
|
2061
|
+
|
|
2062
|
+
// ../../node_modules/.pnpm/kysely@0.29.8/node_modules/kysely/dist/parser/top-parser.js
|
|
2063
|
+
function parseTop(expression, modifiers) {
|
|
2064
|
+
if (!isNumber(expression) && !isBigInt(expression)) {
|
|
2065
|
+
throw new Error(`Invalid top expression: ${expression}`);
|
|
2066
|
+
}
|
|
2067
|
+
if (!isUndefined(modifiers) && !isTopModifiers(modifiers)) {
|
|
2068
|
+
throw new Error(`Invalid top modifiers: ${modifiers}`);
|
|
2069
|
+
}
|
|
2070
|
+
return TopNode.create(expression, modifiers);
|
|
2071
|
+
}
|
|
2072
|
+
function isTopModifiers(modifiers) {
|
|
2073
|
+
return modifiers === "percent" || modifiers === "with ties" || modifiers === "percent with ties";
|
|
2074
|
+
}
|
|
2075
|
+
|
|
2076
|
+
// ../../node_modules/.pnpm/kysely@0.29.8/node_modules/kysely/dist/operation-node/limit-node.js
|
|
2077
|
+
var LimitNode = freeze({
|
|
2078
|
+
is(node) {
|
|
2079
|
+
return node.kind === "LimitNode";
|
|
2080
|
+
},
|
|
2081
|
+
create(limit) {
|
|
2082
|
+
return freeze({
|
|
2083
|
+
kind: "LimitNode",
|
|
2084
|
+
limit
|
|
2085
|
+
});
|
|
2086
|
+
}
|
|
2087
|
+
});
|
|
2088
|
+
|
|
2089
|
+
// ../../node_modules/.pnpm/kysely@0.29.8/node_modules/kysely/dist/util/random-string.js
|
|
2090
|
+
var CHARS = [
|
|
2091
|
+
"A",
|
|
2092
|
+
"B",
|
|
2093
|
+
"C",
|
|
2094
|
+
"D",
|
|
2095
|
+
"E",
|
|
2096
|
+
"F",
|
|
2097
|
+
"G",
|
|
2098
|
+
"H",
|
|
2099
|
+
"I",
|
|
2100
|
+
"J",
|
|
2101
|
+
"K",
|
|
2102
|
+
"L",
|
|
2103
|
+
"M",
|
|
2104
|
+
"N",
|
|
2105
|
+
"O",
|
|
2106
|
+
"P",
|
|
2107
|
+
"Q",
|
|
2108
|
+
"R",
|
|
2109
|
+
"S",
|
|
2110
|
+
"T",
|
|
2111
|
+
"U",
|
|
2112
|
+
"V",
|
|
2113
|
+
"W",
|
|
2114
|
+
"X",
|
|
2115
|
+
"Y",
|
|
2116
|
+
"Z",
|
|
2117
|
+
"a",
|
|
2118
|
+
"b",
|
|
2119
|
+
"c",
|
|
2120
|
+
"d",
|
|
2121
|
+
"e",
|
|
2122
|
+
"f",
|
|
2123
|
+
"g",
|
|
2124
|
+
"h",
|
|
2125
|
+
"i",
|
|
2126
|
+
"j",
|
|
2127
|
+
"k",
|
|
2128
|
+
"l",
|
|
2129
|
+
"m",
|
|
2130
|
+
"n",
|
|
2131
|
+
"o",
|
|
2132
|
+
"p",
|
|
2133
|
+
"q",
|
|
2134
|
+
"r",
|
|
2135
|
+
"s",
|
|
2136
|
+
"t",
|
|
2137
|
+
"u",
|
|
2138
|
+
"v",
|
|
2139
|
+
"w",
|
|
2140
|
+
"x",
|
|
2141
|
+
"y",
|
|
2142
|
+
"z",
|
|
2143
|
+
"0",
|
|
2144
|
+
"1",
|
|
2145
|
+
"2",
|
|
2146
|
+
"3",
|
|
2147
|
+
"4",
|
|
2148
|
+
"5",
|
|
2149
|
+
"6",
|
|
2150
|
+
"7",
|
|
2151
|
+
"8",
|
|
2152
|
+
"9"
|
|
2153
|
+
];
|
|
2154
|
+
function randomString(length) {
|
|
2155
|
+
let chars = "";
|
|
2156
|
+
for (let i = 0; i < length; ++i) {
|
|
2157
|
+
chars += randomChar();
|
|
2158
|
+
}
|
|
2159
|
+
return chars;
|
|
2160
|
+
}
|
|
2161
|
+
function randomChar() {
|
|
2162
|
+
return CHARS[~~(Math.random() * CHARS.length)];
|
|
2163
|
+
}
|
|
2164
|
+
|
|
2165
|
+
// ../../node_modules/.pnpm/kysely@0.29.8/node_modules/kysely/dist/util/query-id.js
|
|
2166
|
+
function createQueryId() {
|
|
2167
|
+
return new LazyQueryId();
|
|
2168
|
+
}
|
|
2169
|
+
var LazyQueryId = class {
|
|
2170
|
+
#queryId;
|
|
2171
|
+
get queryId() {
|
|
2172
|
+
if (this.#queryId === void 0) {
|
|
2173
|
+
this.#queryId = randomString(8);
|
|
2174
|
+
}
|
|
2175
|
+
return this.#queryId;
|
|
2176
|
+
}
|
|
2177
|
+
};
|
|
2178
|
+
|
|
2179
|
+
// ../../node_modules/.pnpm/kysely@0.29.8/node_modules/kysely/dist/util/deferred.js
|
|
2180
|
+
var Deferred = class {
|
|
2181
|
+
#promise;
|
|
2182
|
+
#resolve;
|
|
2183
|
+
#reject;
|
|
2184
|
+
constructor() {
|
|
2185
|
+
this.#promise = new Promise((resolve, reject) => {
|
|
2186
|
+
this.#reject = reject;
|
|
2187
|
+
this.#resolve = resolve;
|
|
2188
|
+
});
|
|
2189
|
+
}
|
|
2190
|
+
get promise() {
|
|
2191
|
+
return this.#promise;
|
|
2192
|
+
}
|
|
2193
|
+
resolve = (value) => {
|
|
2194
|
+
this.#resolve?.(value);
|
|
2195
|
+
this.#resolve = this.#reject = void 0;
|
|
2196
|
+
};
|
|
2197
|
+
reject = (reason) => {
|
|
2198
|
+
this.#reject?.(reason);
|
|
2199
|
+
this.#reject = this.#resolve = void 0;
|
|
2200
|
+
};
|
|
2201
|
+
};
|
|
2202
|
+
|
|
2203
|
+
// ../../node_modules/.pnpm/kysely@0.29.8/node_modules/kysely/dist/util/provide-controlled-connection.js
|
|
2204
|
+
async function provideControlledConnection(connectionProvider, options) {
|
|
2205
|
+
const connectionDefer = new Deferred();
|
|
2206
|
+
const connectionReleaseDefer = new Deferred();
|
|
2207
|
+
void connectionProvider.provideConnection(async (connection) => {
|
|
2208
|
+
connectionDefer.resolve(connection);
|
|
2209
|
+
return await connectionReleaseDefer.promise;
|
|
2210
|
+
}, options).catch((ex) => connectionDefer.reject(ex));
|
|
2211
|
+
return freeze({
|
|
2212
|
+
connection: await connectionDefer.promise,
|
|
2213
|
+
release: connectionReleaseDefer.resolve
|
|
2214
|
+
});
|
|
2215
|
+
}
|
|
2216
|
+
|
|
2217
|
+
// ../../node_modules/.pnpm/kysely@0.29.8/node_modules/kysely/dist/util/abort.js
|
|
2218
|
+
function getInflightQueryAbortHandler(abortStrategy = "ignore query", connection, beforeThrow) {
|
|
2219
|
+
if (abortStrategy === "ignore query") {
|
|
2220
|
+
return;
|
|
2221
|
+
}
|
|
2222
|
+
if (abortStrategy === "cancel query") {
|
|
2223
|
+
const handler = connection.cancelQuery;
|
|
2224
|
+
if (!handler) {
|
|
2225
|
+
beforeThrow();
|
|
2226
|
+
throwUnsupportedInflightQueryAbortStrategyError(abortStrategy, connection.killSession ? "kill session" : void 0);
|
|
2227
|
+
}
|
|
2228
|
+
return handler.bind(connection);
|
|
2229
|
+
}
|
|
2230
|
+
if (abortStrategy === "kill session") {
|
|
2231
|
+
const handler = connection.killSession;
|
|
2232
|
+
if (!handler) {
|
|
2233
|
+
beforeThrow();
|
|
2234
|
+
throwUnsupportedInflightQueryAbortStrategyError(abortStrategy, connection.cancelQuery ? "cancel query" : void 0);
|
|
2235
|
+
}
|
|
2236
|
+
return handler.bind(connection);
|
|
2237
|
+
}
|
|
2238
|
+
beforeThrow();
|
|
2239
|
+
throw new Error(`Unexpected \`inflightQueryAbortStrategy\`: "${abortStrategy}"`);
|
|
2240
|
+
}
|
|
2241
|
+
function throwUnsupportedInflightQueryAbortStrategyError(abortStrategy, alt) {
|
|
2242
|
+
throw new Error(`This dialect doesn't support \`inflightQueryAbortStrategy\` "${abortStrategy}". Use "${"ignore query"}"${alt ? ` or "${alt}"` : ""} instead.`);
|
|
2243
|
+
}
|
|
2244
|
+
function assertNotAborted(signal, timing, beforeThrow) {
|
|
2245
|
+
if (signal?.aborted) {
|
|
2246
|
+
beforeThrow?.();
|
|
2247
|
+
throwReasonWithTiming(signal.reason, timing);
|
|
2248
|
+
}
|
|
2249
|
+
}
|
|
2250
|
+
function throwReasonWithTiming(reason, timing) {
|
|
2251
|
+
decorateWithTiming(reason, timing);
|
|
2252
|
+
throw reason;
|
|
2253
|
+
}
|
|
2254
|
+
var ABORTED = {};
|
|
2255
|
+
function printBackgroundFail(name) {
|
|
2256
|
+
return (reason) => console.error(`\`${name}\` failed in the background after abortion: ${getMessage(reason)}`);
|
|
2257
|
+
}
|
|
2258
|
+
function decorateWithTiming(reason, timing) {
|
|
2259
|
+
if (reason !== null && typeof reason === "object" && !Object.isFrozen(reason)) {
|
|
2260
|
+
Object.defineProperty(reason, "__kysely_timing__", {
|
|
2261
|
+
configurable: true,
|
|
2262
|
+
enumerable: false,
|
|
2263
|
+
value: timing,
|
|
2264
|
+
writable: false
|
|
2265
|
+
});
|
|
2266
|
+
}
|
|
2267
|
+
}
|
|
2268
|
+
|
|
2269
|
+
// ../../node_modules/.pnpm/kysely@0.29.8/node_modules/kysely/dist/query-executor/query-executor-base.js
|
|
2270
|
+
var NO_PLUGINS = freeze([]);
|
|
2271
|
+
var QueryExecutorBase = class {
|
|
2272
|
+
#plugins;
|
|
2273
|
+
constructor(plugins = NO_PLUGINS) {
|
|
2274
|
+
this.#plugins = plugins;
|
|
2275
|
+
}
|
|
2276
|
+
get plugins() {
|
|
2277
|
+
return this.#plugins;
|
|
2278
|
+
}
|
|
2279
|
+
transformQuery(node, queryId) {
|
|
2280
|
+
for (const plugin2 of this.#plugins) {
|
|
2281
|
+
const transformedNode = plugin2.transformQuery({ node, queryId });
|
|
2282
|
+
if (transformedNode.kind === node.kind) {
|
|
2283
|
+
node = transformedNode;
|
|
2284
|
+
} else {
|
|
2285
|
+
throw new Error([
|
|
2286
|
+
`KyselyPlugin.transformQuery must return a node`,
|
|
2287
|
+
`of the same kind that was given to it.`,
|
|
2288
|
+
`The plugin was given a ${node.kind}`,
|
|
2289
|
+
`but it returned a ${transformedNode.kind}`
|
|
2290
|
+
].join(" "));
|
|
2291
|
+
}
|
|
2292
|
+
}
|
|
2293
|
+
return node;
|
|
2294
|
+
}
|
|
2295
|
+
async executeQuery(compiledQuery, options) {
|
|
2296
|
+
const { inflightQueryAbortStrategy = "ignore query", signal } = options || {};
|
|
2297
|
+
if (!signal) {
|
|
2298
|
+
const result = await this.provideConnection(async (connection2) => {
|
|
2299
|
+
return await connection2.executeQuery(compiledQuery);
|
|
2300
|
+
}, options);
|
|
2301
|
+
return await this.#transformResult(result, compiledQuery.queryId);
|
|
2302
|
+
}
|
|
2303
|
+
assertNotAborted(signal, "before query execution");
|
|
2304
|
+
options = freeze({ signal });
|
|
2305
|
+
const { connection, release } = await provideControlledConnection(this, options);
|
|
2306
|
+
const controlConnectionProvider = this.provideConnection.bind(this);
|
|
2307
|
+
const { promise: abortPromise, resolve } = new Deferred();
|
|
2308
|
+
const abortListener = () => resolve(ABORTED);
|
|
2309
|
+
signal.addEventListener("abort", abortListener, { once: true });
|
|
2310
|
+
try {
|
|
2311
|
+
assertNotAborted(signal, "before query execution", release);
|
|
2312
|
+
const inflightQueryAbortHandler = getInflightQueryAbortHandler(inflightQueryAbortStrategy, connection, release);
|
|
2313
|
+
if (inflightQueryAbortHandler && connection.collectSessionInfo) {
|
|
2314
|
+
assertNotAborted(signal, "before query execution", release);
|
|
2315
|
+
const collectPromise = connection.collectSessionInfo();
|
|
2316
|
+
const result2 = await Promise.race([abortPromise, collectPromise]).catch((error) => {
|
|
2317
|
+
release();
|
|
2318
|
+
throw error;
|
|
2319
|
+
});
|
|
2320
|
+
if (result2 === ABORTED) {
|
|
2321
|
+
void collectPromise.catch(printBackgroundFail("collectSessionInfo")).finally(release);
|
|
2322
|
+
throwReasonWithTiming(signal.reason, "before query execution");
|
|
2323
|
+
}
|
|
2324
|
+
}
|
|
2325
|
+
const queryPromise = connection.executeQuery(compiledQuery, options);
|
|
2326
|
+
const result = await Promise.race([abortPromise, queryPromise]).catch((error) => {
|
|
2327
|
+
release();
|
|
2328
|
+
throw error;
|
|
2329
|
+
});
|
|
2330
|
+
if (result === ABORTED) {
|
|
2331
|
+
void Promise.allSettled([
|
|
2332
|
+
queryPromise.catch(printBackgroundFail("query")),
|
|
2333
|
+
inflightQueryAbortHandler?.(controlConnectionProvider).catch(printBackgroundFail("inflightQueryAbortHandler"))
|
|
2334
|
+
]).finally(release);
|
|
2335
|
+
throwReasonWithTiming(signal.reason, "during query execution");
|
|
2336
|
+
} else {
|
|
2337
|
+
release();
|
|
2338
|
+
}
|
|
2339
|
+
const transformPromise = this.#transformResult(result, compiledQuery.queryId, options);
|
|
2340
|
+
const transformedResult = await Promise.race([
|
|
2341
|
+
abortPromise,
|
|
2342
|
+
transformPromise
|
|
2343
|
+
]);
|
|
2344
|
+
if (transformedResult === ABORTED) {
|
|
2345
|
+
transformPromise.catch(printBackgroundFail("plugins.transformResult"));
|
|
2346
|
+
throwReasonWithTiming(signal.reason, "during result transformation");
|
|
2347
|
+
}
|
|
2348
|
+
return transformedResult;
|
|
2349
|
+
} finally {
|
|
2350
|
+
resolve(ABORTED);
|
|
2351
|
+
signal.removeEventListener("abort", abortListener);
|
|
2352
|
+
}
|
|
2353
|
+
}
|
|
2354
|
+
async *stream(compiledQuery, chunkSize, options) {
|
|
2355
|
+
const { signal } = options || {};
|
|
2356
|
+
if (!signal) {
|
|
2357
|
+
const { connection: connection2, release: release2 } = await provideControlledConnection(this);
|
|
2358
|
+
try {
|
|
2359
|
+
for await (const result of connection2.streamQuery(compiledQuery, chunkSize)) {
|
|
2360
|
+
yield await this.#transformResult(result, compiledQuery.queryId, options);
|
|
2361
|
+
}
|
|
2362
|
+
} finally {
|
|
2363
|
+
release2();
|
|
2364
|
+
}
|
|
2365
|
+
return;
|
|
2366
|
+
}
|
|
2367
|
+
options = freeze({ signal });
|
|
2368
|
+
assertNotAborted(signal, "before connection acquisition");
|
|
2369
|
+
const { connection, release } = await provideControlledConnection(this, options);
|
|
2370
|
+
const { promise: abortPromise, resolve } = new Deferred();
|
|
2371
|
+
const abortListener = () => resolve(ABORTED);
|
|
2372
|
+
signal.addEventListener("abort", abortListener, { once: true });
|
|
2373
|
+
let asyncIterator;
|
|
2374
|
+
let releasePrerequisite;
|
|
2375
|
+
assertNotAborted(signal, "before query streaming", release);
|
|
2376
|
+
const { queryId } = compiledQuery;
|
|
2377
|
+
try {
|
|
2378
|
+
asyncIterator = connection.streamQuery(compiledQuery, chunkSize, options);
|
|
2379
|
+
while (true) {
|
|
2380
|
+
assertNotAborted(signal, "during query streaming");
|
|
2381
|
+
const nextPromise = asyncIterator.next();
|
|
2382
|
+
const result = await Promise.race([abortPromise, nextPromise]);
|
|
2383
|
+
if (result === ABORTED) {
|
|
2384
|
+
releasePrerequisite = nextPromise.catch(printBackgroundFail("iterator.next"));
|
|
2385
|
+
throwReasonWithTiming(signal.reason, "during query streaming");
|
|
2386
|
+
}
|
|
2387
|
+
if (result.done) {
|
|
2388
|
+
break;
|
|
2389
|
+
}
|
|
2390
|
+
const transformPromise = this.#transformResult(result.value, queryId, options);
|
|
2391
|
+
const transformedResult = await Promise.race([
|
|
2392
|
+
abortPromise,
|
|
2393
|
+
transformPromise
|
|
2394
|
+
]);
|
|
2395
|
+
if (transformedResult === ABORTED) {
|
|
2396
|
+
releasePrerequisite = transformPromise.catch(printBackgroundFail("plugins.transformResult"));
|
|
2397
|
+
throwReasonWithTiming(signal.reason, "during result transformation");
|
|
2398
|
+
}
|
|
2399
|
+
yield transformedResult;
|
|
2400
|
+
}
|
|
2401
|
+
} finally {
|
|
2402
|
+
resolve(ABORTED);
|
|
2403
|
+
signal.removeEventListener("abort", abortListener);
|
|
2404
|
+
const cleanup = (asyncIterator?.return?.() || Promise.resolve()).finally(() => releasePrerequisite).finally(release);
|
|
2405
|
+
if (!releasePrerequisite) {
|
|
2406
|
+
await cleanup;
|
|
2407
|
+
}
|
|
2408
|
+
}
|
|
2409
|
+
}
|
|
2410
|
+
async #transformResult(result, queryId, options) {
|
|
2411
|
+
const { signal } = options || {};
|
|
2412
|
+
for (const plugin2 of this.#plugins) {
|
|
2413
|
+
result = await plugin2.transformResult(freeze({ queryId, result, signal }));
|
|
2414
|
+
}
|
|
2415
|
+
return result;
|
|
2416
|
+
}
|
|
2417
|
+
};
|
|
2418
|
+
|
|
2419
|
+
// ../../node_modules/.pnpm/kysely@0.29.8/node_modules/kysely/dist/query-executor/noop-query-executor.js
|
|
2420
|
+
var NoopQueryExecutor = class _NoopQueryExecutor extends QueryExecutorBase {
|
|
2421
|
+
get adapter() {
|
|
2422
|
+
throw new Error("this query cannot be compiled to SQL");
|
|
2423
|
+
}
|
|
2424
|
+
compileQuery() {
|
|
2425
|
+
throw new Error("this query cannot be compiled to SQL");
|
|
2426
|
+
}
|
|
2427
|
+
provideConnection() {
|
|
2428
|
+
throw new Error("this query cannot be executed");
|
|
2429
|
+
}
|
|
2430
|
+
withConnectionProvider() {
|
|
2431
|
+
throw new Error("this query cannot have a connection provider");
|
|
2432
|
+
}
|
|
2433
|
+
withPlugin(plugin2) {
|
|
2434
|
+
return new _NoopQueryExecutor([...this.plugins, plugin2]);
|
|
2435
|
+
}
|
|
2436
|
+
withPlugins(plugins) {
|
|
2437
|
+
return new _NoopQueryExecutor([...this.plugins, ...plugins]);
|
|
2438
|
+
}
|
|
2439
|
+
withPluginAtFront(plugin2) {
|
|
2440
|
+
return new _NoopQueryExecutor([plugin2, ...this.plugins]);
|
|
2441
|
+
}
|
|
2442
|
+
withoutPlugins() {
|
|
2443
|
+
return new _NoopQueryExecutor([]);
|
|
2444
|
+
}
|
|
2445
|
+
};
|
|
2446
|
+
var NOOP_QUERY_EXECUTOR = new NoopQueryExecutor();
|
|
2447
|
+
|
|
2448
|
+
// ../../node_modules/.pnpm/kysely@0.29.8/node_modules/kysely/dist/parser/parse-utils.js
|
|
2449
|
+
function createJoinBuilder(joinType, table) {
|
|
2450
|
+
return new JoinBuilder({
|
|
2451
|
+
joinNode: JoinNode.create(joinType, parseTableExpression(table))
|
|
2452
|
+
});
|
|
2453
|
+
}
|
|
2454
|
+
function createOverBuilder() {
|
|
2455
|
+
return new OverBuilder({
|
|
2456
|
+
overNode: OverNode.create()
|
|
2457
|
+
});
|
|
2458
|
+
}
|
|
2459
|
+
|
|
2460
|
+
// ../../node_modules/.pnpm/kysely@0.29.8/node_modules/kysely/dist/parser/join-parser.js
|
|
2461
|
+
function parseJoin(joinType, args) {
|
|
2462
|
+
if (args.length === 3) {
|
|
2463
|
+
return parseSingleOnJoin(joinType, args[0], args[1], args[2]);
|
|
2464
|
+
} else if (args.length === 2) {
|
|
2465
|
+
return parseCallbackJoin(joinType, args[0], args[1]);
|
|
2466
|
+
} else if (args.length === 1) {
|
|
2467
|
+
return parseOnlessJoin(joinType, args[0]);
|
|
2468
|
+
} else {
|
|
2469
|
+
throw new Error("not implemented");
|
|
2470
|
+
}
|
|
2471
|
+
}
|
|
2472
|
+
function parseCallbackJoin(joinType, from, callback) {
|
|
2473
|
+
return callback(createJoinBuilder(joinType, from)).toOperationNode();
|
|
2474
|
+
}
|
|
2475
|
+
function parseSingleOnJoin(joinType, from, lhsColumn, rhsColumn) {
|
|
2476
|
+
return JoinNode.createWithOn(joinType, parseTableExpression(from), parseReferentialBinaryOperation(lhsColumn, "=", rhsColumn));
|
|
2477
|
+
}
|
|
2478
|
+
function parseOnlessJoin(joinType, from) {
|
|
2479
|
+
return JoinNode.create(joinType, parseTableExpression(from));
|
|
2480
|
+
}
|
|
2481
|
+
|
|
2482
|
+
// ../../node_modules/.pnpm/kysely@0.29.8/node_modules/kysely/dist/operation-node/offset-node.js
|
|
2483
|
+
var OffsetNode = freeze({
|
|
2484
|
+
is(node) {
|
|
2485
|
+
return node.kind === "OffsetNode";
|
|
2486
|
+
},
|
|
2487
|
+
create(offset) {
|
|
2488
|
+
return freeze({
|
|
2489
|
+
kind: "OffsetNode",
|
|
2490
|
+
offset
|
|
2491
|
+
});
|
|
2492
|
+
}
|
|
2493
|
+
});
|
|
2494
|
+
|
|
2495
|
+
// ../../node_modules/.pnpm/kysely@0.29.8/node_modules/kysely/dist/operation-node/group-by-item-node.js
|
|
2496
|
+
var GroupByItemNode = freeze({
|
|
2497
|
+
is(node) {
|
|
2498
|
+
return node.kind === "GroupByItemNode";
|
|
2499
|
+
},
|
|
2500
|
+
create(groupBy) {
|
|
2501
|
+
return freeze({
|
|
2502
|
+
kind: "GroupByItemNode",
|
|
2503
|
+
groupBy
|
|
2504
|
+
});
|
|
2505
|
+
}
|
|
2506
|
+
});
|
|
2507
|
+
|
|
2508
|
+
// ../../node_modules/.pnpm/kysely@0.29.8/node_modules/kysely/dist/parser/group-by-parser.js
|
|
2509
|
+
function parseGroupBy(groupBy) {
|
|
2510
|
+
groupBy = isFunction(groupBy) ? groupBy(expressionBuilder()) : groupBy;
|
|
2511
|
+
return parseReferenceExpressionOrList(groupBy).map(GroupByItemNode.create);
|
|
2512
|
+
}
|
|
2513
|
+
|
|
2514
|
+
// ../../node_modules/.pnpm/kysely@0.29.8/node_modules/kysely/dist/operation-node/set-operation-node.js
|
|
2515
|
+
var SetOperationNode = freeze({
|
|
2516
|
+
is(node) {
|
|
2517
|
+
return node.kind === "SetOperationNode";
|
|
2518
|
+
},
|
|
2519
|
+
create(operator, expression, all) {
|
|
2520
|
+
return freeze({
|
|
2521
|
+
kind: "SetOperationNode",
|
|
2522
|
+
operator,
|
|
2523
|
+
expression,
|
|
2524
|
+
all
|
|
2525
|
+
});
|
|
2526
|
+
}
|
|
2527
|
+
});
|
|
2528
|
+
|
|
2529
|
+
// ../../node_modules/.pnpm/kysely@0.29.8/node_modules/kysely/dist/parser/set-operation-parser.js
|
|
2530
|
+
function parseSetOperations(operator, expression, all) {
|
|
2531
|
+
if (isFunction(expression)) {
|
|
2532
|
+
expression = expression(createExpressionBuilder());
|
|
2533
|
+
}
|
|
2534
|
+
if (!isReadonlyArray(expression)) {
|
|
2535
|
+
expression = [expression];
|
|
2536
|
+
}
|
|
2537
|
+
return expression.map((expr) => SetOperationNode.create(operator, parseExpression(expr), all));
|
|
2538
|
+
}
|
|
2539
|
+
|
|
2540
|
+
// ../../node_modules/.pnpm/kysely@0.29.8/node_modules/kysely/dist/expression/expression-wrapper.js
|
|
2541
|
+
var ExpressionWrapper = class _ExpressionWrapper {
|
|
2542
|
+
#node;
|
|
2543
|
+
constructor(node) {
|
|
2544
|
+
this.#node = node;
|
|
2545
|
+
}
|
|
2546
|
+
/** @private */
|
|
2547
|
+
get expressionType() {
|
|
2548
|
+
return void 0;
|
|
2549
|
+
}
|
|
2550
|
+
as(alias) {
|
|
2551
|
+
return new AliasedExpressionWrapper(this, alias);
|
|
2552
|
+
}
|
|
2553
|
+
or(...args) {
|
|
2554
|
+
return new OrWrapper(OrNode.create(this.#node, parseValueBinaryOperationOrExpression(args)));
|
|
2555
|
+
}
|
|
2556
|
+
and(...args) {
|
|
2557
|
+
return new AndWrapper(AndNode.create(this.#node, parseValueBinaryOperationOrExpression(args)));
|
|
2558
|
+
}
|
|
2559
|
+
/**
|
|
2560
|
+
* Change the output type of the expression.
|
|
2561
|
+
*
|
|
2562
|
+
* This method call doesn't change the SQL in any way. This methods simply
|
|
2563
|
+
* returns a copy of this `ExpressionWrapper` with a new output type.
|
|
2564
|
+
*/
|
|
2565
|
+
$castTo() {
|
|
2566
|
+
return new _ExpressionWrapper(this.#node);
|
|
2567
|
+
}
|
|
2568
|
+
/**
|
|
2569
|
+
* Omit null from the expression's type.
|
|
2570
|
+
*
|
|
2571
|
+
* This function can be useful in cases where you know an expression can't be
|
|
2572
|
+
* null, but Kysely is unable to infer it.
|
|
2573
|
+
*
|
|
2574
|
+
* This method call doesn't change the SQL in any way. This methods simply
|
|
2575
|
+
* returns a copy of `this` with a new output type.
|
|
2576
|
+
*/
|
|
2577
|
+
$notNull() {
|
|
2578
|
+
return new _ExpressionWrapper(this.#node);
|
|
2579
|
+
}
|
|
2580
|
+
toOperationNode() {
|
|
2581
|
+
return this.#node;
|
|
2582
|
+
}
|
|
2583
|
+
};
|
|
2584
|
+
var AliasedExpressionWrapper = class {
|
|
2585
|
+
#expr;
|
|
2586
|
+
#alias;
|
|
2587
|
+
constructor(expr, alias) {
|
|
2588
|
+
this.#expr = expr;
|
|
2589
|
+
this.#alias = alias;
|
|
2590
|
+
}
|
|
2591
|
+
/** @private */
|
|
2592
|
+
get expression() {
|
|
2593
|
+
return this.#expr;
|
|
2594
|
+
}
|
|
2595
|
+
/** @private */
|
|
2596
|
+
get alias() {
|
|
2597
|
+
return this.#alias;
|
|
2598
|
+
}
|
|
2599
|
+
toOperationNode() {
|
|
2600
|
+
return AliasNode.create(this.#expr.toOperationNode(), isOperationNodeSource(this.#alias) ? this.#alias.toOperationNode() : IdentifierNode.create(this.#alias));
|
|
2601
|
+
}
|
|
2602
|
+
};
|
|
2603
|
+
var OrWrapper = class _OrWrapper {
|
|
2604
|
+
#node;
|
|
2605
|
+
constructor(node) {
|
|
2606
|
+
this.#node = node;
|
|
2607
|
+
}
|
|
2608
|
+
/** @private */
|
|
2609
|
+
get expressionType() {
|
|
2610
|
+
return void 0;
|
|
2611
|
+
}
|
|
2612
|
+
as(alias) {
|
|
2613
|
+
return new AliasedExpressionWrapper(this, alias);
|
|
2614
|
+
}
|
|
2615
|
+
or(...args) {
|
|
2616
|
+
return new _OrWrapper(OrNode.create(this.#node, parseValueBinaryOperationOrExpression(args)));
|
|
2617
|
+
}
|
|
2618
|
+
/**
|
|
2619
|
+
* Change the output type of the expression.
|
|
2620
|
+
*
|
|
2621
|
+
* This method call doesn't change the SQL in any way. This methods simply
|
|
2622
|
+
* returns a copy of this `OrWrapper` with a new output type.
|
|
2623
|
+
*/
|
|
2624
|
+
$castTo() {
|
|
2625
|
+
return new _OrWrapper(this.#node);
|
|
2626
|
+
}
|
|
2627
|
+
toOperationNode() {
|
|
2628
|
+
return ParensNode.create(this.#node);
|
|
2629
|
+
}
|
|
2630
|
+
};
|
|
2631
|
+
var AndWrapper = class _AndWrapper {
|
|
2632
|
+
#node;
|
|
2633
|
+
constructor(node) {
|
|
2634
|
+
this.#node = node;
|
|
2635
|
+
}
|
|
2636
|
+
/** @private */
|
|
2637
|
+
get expressionType() {
|
|
2638
|
+
return void 0;
|
|
2639
|
+
}
|
|
2640
|
+
as(alias) {
|
|
2641
|
+
return new AliasedExpressionWrapper(this, alias);
|
|
2642
|
+
}
|
|
2643
|
+
and(...args) {
|
|
2644
|
+
return new _AndWrapper(AndNode.create(this.#node, parseValueBinaryOperationOrExpression(args)));
|
|
2645
|
+
}
|
|
2646
|
+
/**
|
|
2647
|
+
* Change the output type of the expression.
|
|
2648
|
+
*
|
|
2649
|
+
* This method call doesn't change the SQL in any way. This methods simply
|
|
2650
|
+
* returns a copy of this `AndWrapper` with a new output type.
|
|
2651
|
+
*/
|
|
2652
|
+
$castTo() {
|
|
2653
|
+
return new _AndWrapper(this.#node);
|
|
2654
|
+
}
|
|
2655
|
+
toOperationNode() {
|
|
2656
|
+
return ParensNode.create(this.#node);
|
|
2657
|
+
}
|
|
2658
|
+
};
|
|
2659
|
+
|
|
2660
|
+
// ../../node_modules/.pnpm/kysely@0.29.8/node_modules/kysely/dist/operation-node/fetch-node.js
|
|
2661
|
+
var FetchNode = freeze({
|
|
2662
|
+
is(node) {
|
|
2663
|
+
return node.kind === "FetchNode";
|
|
2664
|
+
},
|
|
2665
|
+
create(rowCount, modifier) {
|
|
2666
|
+
return {
|
|
2667
|
+
kind: "FetchNode",
|
|
2668
|
+
rowCount: ValueNode.create(rowCount),
|
|
2669
|
+
modifier
|
|
2670
|
+
};
|
|
2671
|
+
}
|
|
2672
|
+
});
|
|
2673
|
+
|
|
2674
|
+
// ../../node_modules/.pnpm/kysely@0.29.8/node_modules/kysely/dist/parser/fetch-parser.js
|
|
2675
|
+
function parseFetch(rowCount, modifier) {
|
|
2676
|
+
if (!isNumber(rowCount) && !isBigInt(rowCount)) {
|
|
2677
|
+
throw new Error(`Invalid fetch row count: ${rowCount}`);
|
|
2678
|
+
}
|
|
2679
|
+
if (!isFetchModifier(modifier)) {
|
|
2680
|
+
throw new Error(`Invalid fetch modifier: ${modifier}`);
|
|
2681
|
+
}
|
|
2682
|
+
return FetchNode.create(rowCount, modifier);
|
|
2683
|
+
}
|
|
2684
|
+
function isFetchModifier(value) {
|
|
2685
|
+
return value === "only" || value === "with ties";
|
|
2686
|
+
}
|
|
2687
|
+
|
|
2688
|
+
// ../../node_modules/.pnpm/kysely@0.29.8/node_modules/kysely/dist/query-builder/select-query-builder.js
|
|
2689
|
+
var _a;
|
|
2690
|
+
var SelectQueryBuilderImpl = class {
|
|
2691
|
+
#props;
|
|
2692
|
+
constructor(props) {
|
|
2693
|
+
this.#props = freeze(props);
|
|
2694
|
+
}
|
|
2695
|
+
get expressionType() {
|
|
2696
|
+
return void 0;
|
|
2697
|
+
}
|
|
2698
|
+
get isSelectQueryBuilder() {
|
|
2699
|
+
return true;
|
|
2700
|
+
}
|
|
2701
|
+
where(...args) {
|
|
2702
|
+
return new _a({
|
|
2703
|
+
...this.#props,
|
|
2704
|
+
queryNode: QueryNode.cloneWithWhere(this.#props.queryNode, parseValueBinaryOperationOrExpression(args))
|
|
2705
|
+
});
|
|
2706
|
+
}
|
|
2707
|
+
whereRef(lhs, op, rhs) {
|
|
2708
|
+
return new _a({
|
|
2709
|
+
...this.#props,
|
|
2710
|
+
queryNode: QueryNode.cloneWithWhere(this.#props.queryNode, parseReferentialBinaryOperation(lhs, op, rhs))
|
|
2711
|
+
});
|
|
2712
|
+
}
|
|
2713
|
+
having(...args) {
|
|
2714
|
+
return new _a({
|
|
2715
|
+
...this.#props,
|
|
2716
|
+
queryNode: SelectQueryNode.cloneWithHaving(this.#props.queryNode, parseValueBinaryOperationOrExpression(args))
|
|
2717
|
+
});
|
|
2718
|
+
}
|
|
2719
|
+
havingRef(lhs, op, rhs) {
|
|
2720
|
+
return new _a({
|
|
2721
|
+
...this.#props,
|
|
2722
|
+
queryNode: SelectQueryNode.cloneWithHaving(this.#props.queryNode, parseReferentialBinaryOperation(lhs, op, rhs))
|
|
2723
|
+
});
|
|
2724
|
+
}
|
|
2725
|
+
select(selection) {
|
|
2726
|
+
return new _a({
|
|
2727
|
+
...this.#props,
|
|
2728
|
+
queryNode: SelectQueryNode.cloneWithSelections(this.#props.queryNode, parseSelectArg(selection))
|
|
2729
|
+
});
|
|
2730
|
+
}
|
|
2731
|
+
distinctOn(selection) {
|
|
2732
|
+
return new _a({
|
|
2733
|
+
...this.#props,
|
|
2734
|
+
queryNode: SelectQueryNode.cloneWithDistinctOn(this.#props.queryNode, parseReferenceExpressionOrList(selection))
|
|
2735
|
+
});
|
|
2736
|
+
}
|
|
2737
|
+
modifyFront(modifier) {
|
|
2738
|
+
return new _a({
|
|
2739
|
+
...this.#props,
|
|
2740
|
+
queryNode: SelectQueryNode.cloneWithFrontModifier(this.#props.queryNode, SelectModifierNode.createWithExpression(modifier.toOperationNode()))
|
|
2741
|
+
});
|
|
2742
|
+
}
|
|
2743
|
+
modifyEnd(modifier) {
|
|
2744
|
+
return new _a({
|
|
2745
|
+
...this.#props,
|
|
2746
|
+
queryNode: QueryNode.cloneWithEndModifier(this.#props.queryNode, SelectModifierNode.createWithExpression(modifier.toOperationNode()))
|
|
2747
|
+
});
|
|
2748
|
+
}
|
|
2749
|
+
distinct() {
|
|
2750
|
+
return new _a({
|
|
2751
|
+
...this.#props,
|
|
2752
|
+
queryNode: SelectQueryNode.cloneWithFrontModifier(this.#props.queryNode, SelectModifierNode.create("Distinct"))
|
|
2753
|
+
});
|
|
2754
|
+
}
|
|
2755
|
+
forUpdate(of) {
|
|
2756
|
+
return new _a({
|
|
2757
|
+
...this.#props,
|
|
2758
|
+
queryNode: QueryNode.cloneWithEndModifier(this.#props.queryNode, SelectModifierNode.create("ForUpdate", of ? asArray(of).map(parseTable) : void 0))
|
|
2759
|
+
});
|
|
2760
|
+
}
|
|
2761
|
+
forShare(of) {
|
|
2762
|
+
return new _a({
|
|
2763
|
+
...this.#props,
|
|
2764
|
+
queryNode: QueryNode.cloneWithEndModifier(this.#props.queryNode, SelectModifierNode.create("ForShare", of ? asArray(of).map(parseTable) : void 0))
|
|
2765
|
+
});
|
|
2766
|
+
}
|
|
2767
|
+
forKeyShare(of) {
|
|
2768
|
+
return new _a({
|
|
2769
|
+
...this.#props,
|
|
2770
|
+
queryNode: QueryNode.cloneWithEndModifier(this.#props.queryNode, SelectModifierNode.create("ForKeyShare", of ? asArray(of).map(parseTable) : void 0))
|
|
2771
|
+
});
|
|
2772
|
+
}
|
|
2773
|
+
forNoKeyUpdate(of) {
|
|
2774
|
+
return new _a({
|
|
2775
|
+
...this.#props,
|
|
2776
|
+
queryNode: QueryNode.cloneWithEndModifier(this.#props.queryNode, SelectModifierNode.create("ForNoKeyUpdate", of ? asArray(of).map(parseTable) : void 0))
|
|
2777
|
+
});
|
|
2778
|
+
}
|
|
2779
|
+
skipLocked() {
|
|
2780
|
+
return new _a({
|
|
2781
|
+
...this.#props,
|
|
2782
|
+
queryNode: QueryNode.cloneWithEndModifier(this.#props.queryNode, SelectModifierNode.create("SkipLocked"))
|
|
2783
|
+
});
|
|
2784
|
+
}
|
|
2785
|
+
noWait() {
|
|
2786
|
+
return new _a({
|
|
2787
|
+
...this.#props,
|
|
2788
|
+
queryNode: QueryNode.cloneWithEndModifier(this.#props.queryNode, SelectModifierNode.create("NoWait"))
|
|
2789
|
+
});
|
|
2790
|
+
}
|
|
2791
|
+
selectAll(table) {
|
|
2792
|
+
return new _a({
|
|
2793
|
+
...this.#props,
|
|
2794
|
+
queryNode: SelectQueryNode.cloneWithSelections(this.#props.queryNode, parseSelectAll(table))
|
|
2795
|
+
});
|
|
2796
|
+
}
|
|
2797
|
+
innerJoin(...args) {
|
|
2798
|
+
return this.#join("InnerJoin", args);
|
|
2799
|
+
}
|
|
2800
|
+
leftJoin(...args) {
|
|
2801
|
+
return this.#join("LeftJoin", args);
|
|
2802
|
+
}
|
|
2803
|
+
rightJoin(...args) {
|
|
2804
|
+
return this.#join("RightJoin", args);
|
|
2805
|
+
}
|
|
2806
|
+
fullJoin(...args) {
|
|
2807
|
+
return this.#join("FullJoin", args);
|
|
2808
|
+
}
|
|
2809
|
+
crossJoin(...args) {
|
|
2810
|
+
return this.#join("CrossJoin", args);
|
|
2811
|
+
}
|
|
2812
|
+
innerJoinLateral(...args) {
|
|
2813
|
+
return this.#join("LateralInnerJoin", args);
|
|
2814
|
+
}
|
|
2815
|
+
leftJoinLateral(...args) {
|
|
2816
|
+
return this.#join("LateralLeftJoin", args);
|
|
2817
|
+
}
|
|
2818
|
+
crossJoinLateral(...args) {
|
|
2819
|
+
return this.#join("LateralCrossJoin", args);
|
|
2820
|
+
}
|
|
2821
|
+
crossApply(...args) {
|
|
2822
|
+
return this.#join("CrossApply", args);
|
|
2823
|
+
}
|
|
2824
|
+
outerApply(...args) {
|
|
2825
|
+
return this.#join("OuterApply", args);
|
|
2826
|
+
}
|
|
2827
|
+
#join(joinType, args) {
|
|
2828
|
+
return new _a({
|
|
2829
|
+
...this.#props,
|
|
2830
|
+
queryNode: QueryNode.cloneWithJoin(this.#props.queryNode, parseJoin(joinType, args))
|
|
2831
|
+
});
|
|
2832
|
+
}
|
|
2833
|
+
orderBy(...args) {
|
|
2834
|
+
return new _a({
|
|
2835
|
+
...this.#props,
|
|
2836
|
+
queryNode: QueryNode.cloneWithOrderByItems(this.#props.queryNode, parseOrderBy(args))
|
|
2837
|
+
});
|
|
2838
|
+
}
|
|
2839
|
+
groupBy(groupBy) {
|
|
2840
|
+
return new _a({
|
|
2841
|
+
...this.#props,
|
|
2842
|
+
queryNode: SelectQueryNode.cloneWithGroupByItems(this.#props.queryNode, parseGroupBy(groupBy))
|
|
2843
|
+
});
|
|
2844
|
+
}
|
|
2845
|
+
limit(limit) {
|
|
2846
|
+
return new _a({
|
|
2847
|
+
...this.#props,
|
|
2848
|
+
queryNode: SelectQueryNode.cloneWithLimit(this.#props.queryNode, LimitNode.create(parseValueExpression(limit)))
|
|
2849
|
+
});
|
|
2850
|
+
}
|
|
2851
|
+
offset(offset) {
|
|
2852
|
+
return new _a({
|
|
2853
|
+
...this.#props,
|
|
2854
|
+
queryNode: SelectQueryNode.cloneWithOffset(this.#props.queryNode, OffsetNode.create(parseValueExpression(offset)))
|
|
2855
|
+
});
|
|
2856
|
+
}
|
|
2857
|
+
fetch(rowCount, modifier = "only") {
|
|
2858
|
+
return new _a({
|
|
2859
|
+
...this.#props,
|
|
2860
|
+
queryNode: SelectQueryNode.cloneWithFetch(this.#props.queryNode, parseFetch(rowCount, modifier))
|
|
2861
|
+
});
|
|
2862
|
+
}
|
|
2863
|
+
top(expression, modifiers) {
|
|
2864
|
+
return new _a({
|
|
2865
|
+
...this.#props,
|
|
2866
|
+
queryNode: QueryNode.cloneWithTop(this.#props.queryNode, parseTop(expression, modifiers))
|
|
2867
|
+
});
|
|
2868
|
+
}
|
|
2869
|
+
union(expression) {
|
|
2870
|
+
return new _a({
|
|
2871
|
+
...this.#props,
|
|
2872
|
+
queryNode: SelectQueryNode.cloneWithSetOperations(this.#props.queryNode, parseSetOperations("union", expression, false))
|
|
2873
|
+
});
|
|
2874
|
+
}
|
|
2875
|
+
unionAll(expression) {
|
|
2876
|
+
return new _a({
|
|
2877
|
+
...this.#props,
|
|
2878
|
+
queryNode: SelectQueryNode.cloneWithSetOperations(this.#props.queryNode, parseSetOperations("union", expression, true))
|
|
2879
|
+
});
|
|
2880
|
+
}
|
|
2881
|
+
intersect(expression) {
|
|
2882
|
+
return new _a({
|
|
2883
|
+
...this.#props,
|
|
2884
|
+
queryNode: SelectQueryNode.cloneWithSetOperations(this.#props.queryNode, parseSetOperations("intersect", expression, false))
|
|
2885
|
+
});
|
|
2886
|
+
}
|
|
2887
|
+
intersectAll(expression) {
|
|
2888
|
+
return new _a({
|
|
2889
|
+
...this.#props,
|
|
2890
|
+
queryNode: SelectQueryNode.cloneWithSetOperations(this.#props.queryNode, parseSetOperations("intersect", expression, true))
|
|
2891
|
+
});
|
|
2892
|
+
}
|
|
2893
|
+
except(expression) {
|
|
2894
|
+
return new _a({
|
|
2895
|
+
...this.#props,
|
|
2896
|
+
queryNode: SelectQueryNode.cloneWithSetOperations(this.#props.queryNode, parseSetOperations("except", expression, false))
|
|
2897
|
+
});
|
|
2898
|
+
}
|
|
2899
|
+
exceptAll(expression) {
|
|
2900
|
+
return new _a({
|
|
2901
|
+
...this.#props,
|
|
2902
|
+
queryNode: SelectQueryNode.cloneWithSetOperations(this.#props.queryNode, parseSetOperations("except", expression, true))
|
|
2903
|
+
});
|
|
2904
|
+
}
|
|
2905
|
+
as(alias) {
|
|
2906
|
+
return new AliasedSelectQueryBuilderImpl(this, alias);
|
|
2907
|
+
}
|
|
2908
|
+
clearSelect() {
|
|
2909
|
+
return new _a({
|
|
2910
|
+
...this.#props,
|
|
2911
|
+
queryNode: SelectQueryNode.cloneWithoutSelections(this.#props.queryNode)
|
|
2912
|
+
});
|
|
2913
|
+
}
|
|
2914
|
+
clearWhere() {
|
|
2915
|
+
return new _a({
|
|
2916
|
+
...this.#props,
|
|
2917
|
+
queryNode: QueryNode.cloneWithoutWhere(this.#props.queryNode)
|
|
2918
|
+
});
|
|
2919
|
+
}
|
|
2920
|
+
clearLimit() {
|
|
2921
|
+
return new _a({
|
|
2922
|
+
...this.#props,
|
|
2923
|
+
queryNode: SelectQueryNode.cloneWithoutLimit(this.#props.queryNode)
|
|
2924
|
+
});
|
|
2925
|
+
}
|
|
2926
|
+
clearOffset() {
|
|
2927
|
+
return new _a({
|
|
2928
|
+
...this.#props,
|
|
2929
|
+
queryNode: SelectQueryNode.cloneWithoutOffset(this.#props.queryNode)
|
|
2930
|
+
});
|
|
2931
|
+
}
|
|
2932
|
+
clearOrderBy() {
|
|
2933
|
+
return new _a({
|
|
2934
|
+
...this.#props,
|
|
2935
|
+
queryNode: QueryNode.cloneWithoutOrderBy(this.#props.queryNode)
|
|
2936
|
+
});
|
|
2937
|
+
}
|
|
2938
|
+
clearGroupBy() {
|
|
2939
|
+
return new _a({
|
|
2940
|
+
...this.#props,
|
|
2941
|
+
queryNode: SelectQueryNode.cloneWithoutGroupBy(this.#props.queryNode)
|
|
2942
|
+
});
|
|
2943
|
+
}
|
|
2944
|
+
$call(func) {
|
|
2945
|
+
return func(this);
|
|
2946
|
+
}
|
|
2947
|
+
$if(condition, func) {
|
|
2948
|
+
if (condition) {
|
|
2949
|
+
return func(this);
|
|
2950
|
+
}
|
|
2951
|
+
return new _a({
|
|
2952
|
+
...this.#props
|
|
2953
|
+
});
|
|
2954
|
+
}
|
|
2955
|
+
$castTo() {
|
|
2956
|
+
return new _a(this.#props);
|
|
2957
|
+
}
|
|
2958
|
+
$narrowType() {
|
|
2959
|
+
return new _a(this.#props);
|
|
2960
|
+
}
|
|
2961
|
+
$assertType() {
|
|
2962
|
+
return new _a(this.#props);
|
|
2963
|
+
}
|
|
2964
|
+
$asTuple() {
|
|
2965
|
+
return new ExpressionWrapper(this.toOperationNode());
|
|
2966
|
+
}
|
|
2967
|
+
$asScalar() {
|
|
2968
|
+
return new ExpressionWrapper(this.toOperationNode());
|
|
2969
|
+
}
|
|
2970
|
+
withPlugin(plugin2) {
|
|
2971
|
+
return new _a({
|
|
2972
|
+
...this.#props,
|
|
2973
|
+
executor: this.#props.executor.withPlugin(plugin2)
|
|
2974
|
+
});
|
|
2975
|
+
}
|
|
2976
|
+
toOperationNode() {
|
|
2977
|
+
return this.#props.executor.transformQuery(this.#props.queryNode, this.#props.queryId);
|
|
2978
|
+
}
|
|
2979
|
+
compile() {
|
|
2980
|
+
return this.#props.executor.compileQuery(this.toOperationNode(), this.#props.queryId);
|
|
2981
|
+
}
|
|
2982
|
+
async execute(options) {
|
|
2983
|
+
const compiledQuery = this.compile();
|
|
2984
|
+
const result = await this.#props.executor.executeQuery(compiledQuery, options);
|
|
2985
|
+
return result.rows;
|
|
2986
|
+
}
|
|
2987
|
+
async executeTakeFirst(options) {
|
|
2988
|
+
const [result] = await this.execute(options);
|
|
2989
|
+
return result;
|
|
2990
|
+
}
|
|
2991
|
+
async executeTakeFirstOrThrow(errorConstructorOrOptions) {
|
|
2992
|
+
if (typeof errorConstructorOrOptions === "function") {
|
|
2993
|
+
errorConstructorOrOptions = {
|
|
2994
|
+
errorConstructor: errorConstructorOrOptions
|
|
2995
|
+
};
|
|
2996
|
+
}
|
|
2997
|
+
const result = await this.executeTakeFirst(errorConstructorOrOptions);
|
|
2998
|
+
if (result === void 0) {
|
|
2999
|
+
const errorConstructor = errorConstructorOrOptions?.errorConstructor ?? NoResultError;
|
|
3000
|
+
const error = isNoResultErrorConstructor(errorConstructor) ? new errorConstructor(this.toOperationNode()) : errorConstructor(this.toOperationNode());
|
|
3001
|
+
throw error;
|
|
3002
|
+
}
|
|
3003
|
+
return result;
|
|
3004
|
+
}
|
|
3005
|
+
async *stream(chunkSizeOrOptions) {
|
|
3006
|
+
if (typeof chunkSizeOrOptions !== "object") {
|
|
3007
|
+
chunkSizeOrOptions = {
|
|
3008
|
+
chunkSize: chunkSizeOrOptions
|
|
3009
|
+
};
|
|
3010
|
+
}
|
|
3011
|
+
const compiledQuery = this.compile();
|
|
3012
|
+
const stream = this.#props.executor.stream(compiledQuery, chunkSizeOrOptions.chunkSize ?? 100, chunkSizeOrOptions);
|
|
3013
|
+
for await (const item of stream) {
|
|
3014
|
+
yield* item.rows;
|
|
3015
|
+
}
|
|
3016
|
+
}
|
|
3017
|
+
async explain(format, options) {
|
|
3018
|
+
const builder = new _a({
|
|
3019
|
+
...this.#props,
|
|
3020
|
+
queryNode: QueryNode.cloneWithExplain(this.#props.queryNode, format, options)
|
|
3021
|
+
});
|
|
3022
|
+
return await builder.execute();
|
|
3023
|
+
}
|
|
3024
|
+
};
|
|
3025
|
+
_a = SelectQueryBuilderImpl;
|
|
3026
|
+
function createSelectQueryBuilder(props) {
|
|
3027
|
+
return new SelectQueryBuilderImpl(props);
|
|
3028
|
+
}
|
|
3029
|
+
var AliasedSelectQueryBuilderImpl = class {
|
|
3030
|
+
#queryBuilder;
|
|
3031
|
+
#alias;
|
|
3032
|
+
constructor(queryBuilder, alias) {
|
|
3033
|
+
this.#queryBuilder = queryBuilder;
|
|
3034
|
+
this.#alias = alias;
|
|
3035
|
+
}
|
|
3036
|
+
get expression() {
|
|
3037
|
+
return this.#queryBuilder;
|
|
3038
|
+
}
|
|
3039
|
+
get alias() {
|
|
3040
|
+
return this.#alias;
|
|
3041
|
+
}
|
|
3042
|
+
get isAliasedSelectQueryBuilder() {
|
|
3043
|
+
return true;
|
|
3044
|
+
}
|
|
3045
|
+
toOperationNode() {
|
|
3046
|
+
return AliasNode.create(this.#queryBuilder.toOperationNode(), IdentifierNode.create(this.#alias));
|
|
3047
|
+
}
|
|
3048
|
+
};
|
|
3049
|
+
|
|
3050
|
+
// ../../node_modules/.pnpm/kysely@0.29.8/node_modules/kysely/dist/operation-node/aggregate-function-node.js
|
|
3051
|
+
var AggregateFunctionNode = freeze({
|
|
3052
|
+
is(node) {
|
|
3053
|
+
return node.kind === "AggregateFunctionNode";
|
|
3054
|
+
},
|
|
3055
|
+
create(aggregateFunction, aggregated = []) {
|
|
3056
|
+
return freeze({
|
|
3057
|
+
kind: "AggregateFunctionNode",
|
|
3058
|
+
func: aggregateFunction,
|
|
3059
|
+
aggregated
|
|
3060
|
+
});
|
|
3061
|
+
},
|
|
3062
|
+
cloneWithDistinct(aggregateFunctionNode) {
|
|
3063
|
+
return freeze({
|
|
3064
|
+
...aggregateFunctionNode,
|
|
3065
|
+
distinct: true
|
|
3066
|
+
});
|
|
3067
|
+
},
|
|
3068
|
+
cloneWithOrderBy(aggregateFunctionNode, orderItems, withinGroup = false) {
|
|
3069
|
+
const prop = withinGroup ? "withinGroup" : "orderBy";
|
|
3070
|
+
return freeze({
|
|
3071
|
+
...aggregateFunctionNode,
|
|
3072
|
+
[prop]: aggregateFunctionNode[prop] ? OrderByNode.cloneWithItems(aggregateFunctionNode[prop], orderItems) : OrderByNode.create(orderItems)
|
|
3073
|
+
});
|
|
3074
|
+
},
|
|
3075
|
+
cloneWithFilter(aggregateFunctionNode, filter) {
|
|
3076
|
+
return freeze({
|
|
3077
|
+
...aggregateFunctionNode,
|
|
3078
|
+
filter: aggregateFunctionNode.filter ? WhereNode.cloneWithOperation(aggregateFunctionNode.filter, "And", filter) : WhereNode.create(filter)
|
|
3079
|
+
});
|
|
3080
|
+
},
|
|
3081
|
+
cloneWithOrFilter(aggregateFunctionNode, filter) {
|
|
3082
|
+
return freeze({
|
|
3083
|
+
...aggregateFunctionNode,
|
|
3084
|
+
filter: aggregateFunctionNode.filter ? WhereNode.cloneWithOperation(aggregateFunctionNode.filter, "Or", filter) : WhereNode.create(filter)
|
|
3085
|
+
});
|
|
3086
|
+
},
|
|
3087
|
+
cloneWithOver(aggregateFunctionNode, over) {
|
|
3088
|
+
return freeze({
|
|
3089
|
+
...aggregateFunctionNode,
|
|
3090
|
+
over
|
|
3091
|
+
});
|
|
3092
|
+
}
|
|
3093
|
+
});
|
|
3094
|
+
|
|
3095
|
+
// ../../node_modules/.pnpm/kysely@0.29.8/node_modules/kysely/dist/operation-node/function-node.js
|
|
3096
|
+
var FunctionNode = freeze({
|
|
3097
|
+
is(node) {
|
|
3098
|
+
return node.kind === "FunctionNode";
|
|
3099
|
+
},
|
|
3100
|
+
create(func, args) {
|
|
3101
|
+
return freeze({
|
|
3102
|
+
kind: "FunctionNode",
|
|
3103
|
+
func,
|
|
3104
|
+
arguments: args
|
|
3105
|
+
});
|
|
3106
|
+
}
|
|
3107
|
+
});
|
|
3108
|
+
|
|
3109
|
+
// ../../node_modules/.pnpm/kysely@0.29.8/node_modules/kysely/dist/query-builder/aggregate-function-builder.js
|
|
3110
|
+
var AggregateFunctionBuilder = class _AggregateFunctionBuilder {
|
|
3111
|
+
#props;
|
|
3112
|
+
constructor(props) {
|
|
3113
|
+
this.#props = freeze(props);
|
|
3114
|
+
}
|
|
3115
|
+
/** @private */
|
|
3116
|
+
get expressionType() {
|
|
3117
|
+
return void 0;
|
|
3118
|
+
}
|
|
3119
|
+
/**
|
|
3120
|
+
* Returns an aliased version of the function.
|
|
3121
|
+
*
|
|
3122
|
+
* In addition to slapping `as "the_alias"` to the end of the SQL,
|
|
3123
|
+
* this method also provides strict typing:
|
|
3124
|
+
*
|
|
3125
|
+
* ```ts
|
|
3126
|
+
* const result = await db
|
|
3127
|
+
* .selectFrom('person')
|
|
3128
|
+
* .select(
|
|
3129
|
+
* (eb) => eb.fn.count<number>('id').as('person_count')
|
|
3130
|
+
* )
|
|
3131
|
+
* .executeTakeFirstOrThrow()
|
|
3132
|
+
*
|
|
3133
|
+
* // `person_count: number` field exists in the result type.
|
|
3134
|
+
* console.log(result.person_count)
|
|
3135
|
+
* ```
|
|
3136
|
+
*
|
|
3137
|
+
* The generated SQL (PostgreSQL):
|
|
3138
|
+
*
|
|
3139
|
+
* ```sql
|
|
3140
|
+
* select count("id") as "person_count"
|
|
3141
|
+
* from "person"
|
|
3142
|
+
* ```
|
|
3143
|
+
*/
|
|
3144
|
+
as(alias) {
|
|
3145
|
+
return new AliasedAggregateFunctionBuilder(this, alias);
|
|
3146
|
+
}
|
|
3147
|
+
/**
|
|
3148
|
+
* Adds a `distinct` clause inside the function.
|
|
3149
|
+
*
|
|
3150
|
+
* ### Examples
|
|
3151
|
+
*
|
|
3152
|
+
* ```ts
|
|
3153
|
+
* const result = await db
|
|
3154
|
+
* .selectFrom('person')
|
|
3155
|
+
* .select((eb) =>
|
|
3156
|
+
* eb.fn.count<number>('first_name').distinct().as('first_name_count')
|
|
3157
|
+
* )
|
|
3158
|
+
* .executeTakeFirstOrThrow()
|
|
3159
|
+
* ```
|
|
3160
|
+
*
|
|
3161
|
+
* The generated SQL (PostgreSQL):
|
|
3162
|
+
*
|
|
3163
|
+
* ```sql
|
|
3164
|
+
* select count(distinct "first_name") as "first_name_count"
|
|
3165
|
+
* from "person"
|
|
3166
|
+
* ```
|
|
3167
|
+
*/
|
|
3168
|
+
distinct() {
|
|
3169
|
+
return new _AggregateFunctionBuilder({
|
|
3170
|
+
...this.#props,
|
|
3171
|
+
aggregateFunctionNode: AggregateFunctionNode.cloneWithDistinct(this.#props.aggregateFunctionNode)
|
|
3172
|
+
});
|
|
3173
|
+
}
|
|
3174
|
+
orderBy(...args) {
|
|
3175
|
+
return new _AggregateFunctionBuilder({
|
|
3176
|
+
...this.#props,
|
|
3177
|
+
aggregateFunctionNode: QueryNode.cloneWithOrderByItems(this.#props.aggregateFunctionNode, parseOrderBy(args))
|
|
3178
|
+
});
|
|
3179
|
+
}
|
|
3180
|
+
clearOrderBy() {
|
|
3181
|
+
return new _AggregateFunctionBuilder({
|
|
3182
|
+
...this.#props,
|
|
3183
|
+
aggregateFunctionNode: QueryNode.cloneWithoutOrderBy(this.#props.aggregateFunctionNode)
|
|
3184
|
+
});
|
|
3185
|
+
}
|
|
3186
|
+
withinGroupOrderBy(...args) {
|
|
3187
|
+
return new _AggregateFunctionBuilder({
|
|
3188
|
+
...this.#props,
|
|
3189
|
+
aggregateFunctionNode: AggregateFunctionNode.cloneWithOrderBy(this.#props.aggregateFunctionNode, parseOrderBy(args), true)
|
|
3190
|
+
});
|
|
3191
|
+
}
|
|
3192
|
+
filterWhere(...args) {
|
|
3193
|
+
return new _AggregateFunctionBuilder({
|
|
3194
|
+
...this.#props,
|
|
3195
|
+
aggregateFunctionNode: AggregateFunctionNode.cloneWithFilter(this.#props.aggregateFunctionNode, parseValueBinaryOperationOrExpression(args))
|
|
3196
|
+
});
|
|
3197
|
+
}
|
|
3198
|
+
/**
|
|
3199
|
+
* Adds a `filter` clause with a nested `where` clause after the function, where
|
|
3200
|
+
* both sides of the operator are references to columns.
|
|
3201
|
+
*
|
|
3202
|
+
* Similar to {@link WhereInterface}'s `whereRef` method.
|
|
3203
|
+
*
|
|
3204
|
+
* ### Examples
|
|
3205
|
+
*
|
|
3206
|
+
* Count people with same first and last names versus general public:
|
|
3207
|
+
*
|
|
3208
|
+
* ```ts
|
|
3209
|
+
* const result = await db
|
|
3210
|
+
* .selectFrom('person')
|
|
3211
|
+
* .select((eb) => [
|
|
3212
|
+
* eb.fn
|
|
3213
|
+
* .count<number>('id')
|
|
3214
|
+
* .filterWhereRef('first_name', '=', 'last_name')
|
|
3215
|
+
* .as('repeat_name_count'),
|
|
3216
|
+
* eb.fn.count<number>('id').as('total_count'),
|
|
3217
|
+
* ])
|
|
3218
|
+
* .executeTakeFirstOrThrow()
|
|
3219
|
+
* ```
|
|
3220
|
+
*
|
|
3221
|
+
* The generated SQL (PostgreSQL):
|
|
3222
|
+
*
|
|
3223
|
+
* ```sql
|
|
3224
|
+
* select
|
|
3225
|
+
* count("id") filter(where "first_name" = "last_name") as "repeat_name_count",
|
|
3226
|
+
* count("id") as "total_count"
|
|
3227
|
+
* from "person"
|
|
3228
|
+
* ```
|
|
3229
|
+
*/
|
|
3230
|
+
filterWhereRef(lhs, op, rhs) {
|
|
3231
|
+
return new _AggregateFunctionBuilder({
|
|
3232
|
+
...this.#props,
|
|
3233
|
+
aggregateFunctionNode: AggregateFunctionNode.cloneWithFilter(this.#props.aggregateFunctionNode, parseReferentialBinaryOperation(lhs, op, rhs))
|
|
3234
|
+
});
|
|
3235
|
+
}
|
|
3236
|
+
/**
|
|
3237
|
+
* Adds an `over` clause (window functions) after the function.
|
|
3238
|
+
*
|
|
3239
|
+
* ### Examples
|
|
3240
|
+
*
|
|
3241
|
+
* ```ts
|
|
3242
|
+
* const result = await db
|
|
3243
|
+
* .selectFrom('person')
|
|
3244
|
+
* .select(
|
|
3245
|
+
* (eb) => eb.fn.avg<number>('age').over().as('average_age')
|
|
3246
|
+
* )
|
|
3247
|
+
* .execute()
|
|
3248
|
+
* ```
|
|
3249
|
+
*
|
|
3250
|
+
* The generated SQL (PostgreSQL):
|
|
3251
|
+
*
|
|
3252
|
+
* ```sql
|
|
3253
|
+
* select avg("age") over() as "average_age"
|
|
3254
|
+
* from "person"
|
|
3255
|
+
* ```
|
|
3256
|
+
*
|
|
3257
|
+
* Also supports passing a callback that returns an over builder,
|
|
3258
|
+
* allowing to add partition by and sort by clauses inside over.
|
|
3259
|
+
*
|
|
3260
|
+
* ```ts
|
|
3261
|
+
* const result = await db
|
|
3262
|
+
* .selectFrom('person')
|
|
3263
|
+
* .select(
|
|
3264
|
+
* (eb) => eb.fn.avg<number>('age').over(
|
|
3265
|
+
* ob => ob.partitionBy('last_name').orderBy('first_name', 'asc')
|
|
3266
|
+
* ).as('average_age')
|
|
3267
|
+
* )
|
|
3268
|
+
* .execute()
|
|
3269
|
+
* ```
|
|
3270
|
+
*
|
|
3271
|
+
* The generated SQL (PostgreSQL):
|
|
3272
|
+
*
|
|
3273
|
+
* ```sql
|
|
3274
|
+
* select avg("age") over(partition by "last_name" order by "first_name" asc) as "average_age"
|
|
3275
|
+
* from "person"
|
|
3276
|
+
* ```
|
|
3277
|
+
*/
|
|
3278
|
+
over(over) {
|
|
3279
|
+
const builder = createOverBuilder();
|
|
3280
|
+
return new _AggregateFunctionBuilder({
|
|
3281
|
+
...this.#props,
|
|
3282
|
+
aggregateFunctionNode: AggregateFunctionNode.cloneWithOver(this.#props.aggregateFunctionNode, (over ? over(builder) : builder).toOperationNode())
|
|
3283
|
+
});
|
|
3284
|
+
}
|
|
3285
|
+
/**
|
|
3286
|
+
* Simply calls the provided function passing `this` as the only argument. `$call` returns
|
|
3287
|
+
* what the provided function returns.
|
|
3288
|
+
*/
|
|
3289
|
+
$call(func) {
|
|
3290
|
+
return func(this);
|
|
3291
|
+
}
|
|
3292
|
+
/**
|
|
3293
|
+
* Casts the expression to the given type.
|
|
3294
|
+
*
|
|
3295
|
+
* This method call doesn't change the SQL in any way. This methods simply
|
|
3296
|
+
* returns a copy of this `AggregateFunctionBuilder` with a new output type.
|
|
3297
|
+
*/
|
|
3298
|
+
$castTo() {
|
|
3299
|
+
return new _AggregateFunctionBuilder(this.#props);
|
|
3300
|
+
}
|
|
3301
|
+
/**
|
|
3302
|
+
* Omit null from the expression's type.
|
|
3303
|
+
*
|
|
3304
|
+
* This function can be useful in cases where you know an expression can't be
|
|
3305
|
+
* null, but Kysely is unable to infer it.
|
|
3306
|
+
*
|
|
3307
|
+
* This method call doesn't change the SQL in any way. This methods simply
|
|
3308
|
+
* returns a copy of `this` with a new output type.
|
|
3309
|
+
*/
|
|
3310
|
+
$notNull() {
|
|
3311
|
+
return new _AggregateFunctionBuilder(this.#props);
|
|
3312
|
+
}
|
|
3313
|
+
toOperationNode() {
|
|
3314
|
+
return this.#props.aggregateFunctionNode;
|
|
3315
|
+
}
|
|
3316
|
+
};
|
|
3317
|
+
var AliasedAggregateFunctionBuilder = class {
|
|
3318
|
+
#aggregateFunctionBuilder;
|
|
3319
|
+
#alias;
|
|
3320
|
+
constructor(aggregateFunctionBuilder, alias) {
|
|
3321
|
+
this.#aggregateFunctionBuilder = aggregateFunctionBuilder;
|
|
3322
|
+
this.#alias = alias;
|
|
3323
|
+
}
|
|
3324
|
+
/** @private */
|
|
3325
|
+
get expression() {
|
|
3326
|
+
return this.#aggregateFunctionBuilder;
|
|
3327
|
+
}
|
|
3328
|
+
/** @private */
|
|
3329
|
+
get alias() {
|
|
3330
|
+
return this.#alias;
|
|
3331
|
+
}
|
|
3332
|
+
toOperationNode() {
|
|
3333
|
+
return AliasNode.create(this.#aggregateFunctionBuilder.toOperationNode(), IdentifierNode.create(this.#alias));
|
|
3334
|
+
}
|
|
3335
|
+
};
|
|
3336
|
+
|
|
3337
|
+
// ../../node_modules/.pnpm/kysely@0.29.8/node_modules/kysely/dist/query-builder/function-module.js
|
|
3338
|
+
function createFunctionModule() {
|
|
3339
|
+
const fn = (name, args) => {
|
|
3340
|
+
return new ExpressionWrapper(FunctionNode.create(name, parseReferenceExpressionOrList(args ?? [])));
|
|
3341
|
+
};
|
|
3342
|
+
const agg = (name, args) => {
|
|
3343
|
+
return new AggregateFunctionBuilder({
|
|
3344
|
+
aggregateFunctionNode: AggregateFunctionNode.create(name, args ? parseReferenceExpressionOrList(args) : void 0)
|
|
3345
|
+
});
|
|
3346
|
+
};
|
|
3347
|
+
return Object.assign(fn, {
|
|
3348
|
+
agg,
|
|
3349
|
+
avg(column) {
|
|
3350
|
+
return agg("avg", [column]);
|
|
3351
|
+
},
|
|
3352
|
+
coalesce(...values) {
|
|
3353
|
+
return fn("coalesce", values);
|
|
3354
|
+
},
|
|
3355
|
+
count(column) {
|
|
3356
|
+
return agg("count", [column]);
|
|
3357
|
+
},
|
|
3358
|
+
countAll(table) {
|
|
3359
|
+
return new AggregateFunctionBuilder({
|
|
3360
|
+
aggregateFunctionNode: AggregateFunctionNode.create("count", parseSelectAll(table))
|
|
3361
|
+
});
|
|
3362
|
+
},
|
|
3363
|
+
max(column) {
|
|
3364
|
+
return agg("max", [column]);
|
|
3365
|
+
},
|
|
3366
|
+
min(column) {
|
|
3367
|
+
return agg("min", [column]);
|
|
3368
|
+
},
|
|
3369
|
+
sum(column) {
|
|
3370
|
+
return agg("sum", [column]);
|
|
3371
|
+
},
|
|
3372
|
+
any(column) {
|
|
3373
|
+
return fn("any", [column]);
|
|
3374
|
+
},
|
|
3375
|
+
jsonAgg(table) {
|
|
3376
|
+
return new AggregateFunctionBuilder({
|
|
3377
|
+
aggregateFunctionNode: AggregateFunctionNode.create("json_agg", [
|
|
3378
|
+
isString(table) ? parseTable(table) : table.toOperationNode()
|
|
3379
|
+
])
|
|
3380
|
+
});
|
|
3381
|
+
},
|
|
3382
|
+
toJson(table) {
|
|
3383
|
+
return new ExpressionWrapper(FunctionNode.create("to_json", [
|
|
3384
|
+
isString(table) ? parseTable(table) : table.toOperationNode()
|
|
3385
|
+
]));
|
|
3386
|
+
}
|
|
3387
|
+
});
|
|
3388
|
+
}
|
|
3389
|
+
|
|
3390
|
+
// ../../node_modules/.pnpm/kysely@0.29.8/node_modules/kysely/dist/operation-node/unary-operation-node.js
|
|
3391
|
+
var UnaryOperationNode = freeze({
|
|
3392
|
+
is(node) {
|
|
3393
|
+
return node.kind === "UnaryOperationNode";
|
|
3394
|
+
},
|
|
3395
|
+
create(operator, operand) {
|
|
3396
|
+
return freeze({
|
|
3397
|
+
kind: "UnaryOperationNode",
|
|
3398
|
+
operator,
|
|
3399
|
+
operand
|
|
3400
|
+
});
|
|
3401
|
+
}
|
|
3402
|
+
});
|
|
3403
|
+
|
|
3404
|
+
// ../../node_modules/.pnpm/kysely@0.29.8/node_modules/kysely/dist/parser/unary-operation-parser.js
|
|
3405
|
+
function parseUnaryOperation(operator, operand) {
|
|
3406
|
+
if (isUnaryOperator(operator)) {
|
|
3407
|
+
return UnaryOperationNode.create(OperatorNode.create(operator), parseReferenceExpression(operand));
|
|
3408
|
+
}
|
|
3409
|
+
throw new Error(`invalid unary operator ${JSON.stringify(operator)}`);
|
|
3410
|
+
}
|
|
3411
|
+
|
|
3412
|
+
// ../../node_modules/.pnpm/kysely@0.29.8/node_modules/kysely/dist/operation-node/case-node.js
|
|
3413
|
+
var CaseNode = freeze({
|
|
3414
|
+
is(node) {
|
|
3415
|
+
return node.kind === "CaseNode";
|
|
3416
|
+
},
|
|
3417
|
+
create(value) {
|
|
3418
|
+
return freeze({
|
|
3419
|
+
kind: "CaseNode",
|
|
3420
|
+
value
|
|
3421
|
+
});
|
|
3422
|
+
},
|
|
3423
|
+
cloneWithWhen(caseNode, when) {
|
|
3424
|
+
return freeze({
|
|
3425
|
+
...caseNode,
|
|
3426
|
+
when: freeze(caseNode.when ? [...caseNode.when, when] : [when])
|
|
3427
|
+
});
|
|
3428
|
+
},
|
|
3429
|
+
cloneWithThen(caseNode, then) {
|
|
3430
|
+
return freeze({
|
|
3431
|
+
...caseNode,
|
|
3432
|
+
when: caseNode.when ? freeze([
|
|
3433
|
+
...caseNode.when.slice(0, -1),
|
|
3434
|
+
WhenNode.cloneWithResult(caseNode.when[caseNode.when.length - 1], then)
|
|
3435
|
+
]) : void 0
|
|
3436
|
+
});
|
|
3437
|
+
},
|
|
3438
|
+
cloneWith(caseNode, props) {
|
|
3439
|
+
return freeze({
|
|
3440
|
+
...caseNode,
|
|
3441
|
+
...props
|
|
3442
|
+
});
|
|
3443
|
+
}
|
|
3444
|
+
});
|
|
3445
|
+
|
|
3446
|
+
// ../../node_modules/.pnpm/kysely@0.29.8/node_modules/kysely/dist/query-builder/case-builder.js
|
|
3447
|
+
var CaseBuilder = class {
|
|
3448
|
+
#props;
|
|
3449
|
+
constructor(props) {
|
|
3450
|
+
this.#props = freeze(props);
|
|
3451
|
+
}
|
|
3452
|
+
when(...args) {
|
|
3453
|
+
return new CaseThenBuilder({
|
|
3454
|
+
...this.#props,
|
|
3455
|
+
node: CaseNode.cloneWithWhen(this.#props.node, WhenNode.create(parseValueBinaryOperationOrExpression(args)))
|
|
3456
|
+
});
|
|
3457
|
+
}
|
|
3458
|
+
whenRef(lhs, op, rhs) {
|
|
3459
|
+
return new CaseThenBuilder({
|
|
3460
|
+
...this.#props,
|
|
3461
|
+
node: CaseNode.cloneWithWhen(this.#props.node, WhenNode.create(parseReferentialBinaryOperation(lhs, op, rhs)))
|
|
3462
|
+
});
|
|
3463
|
+
}
|
|
3464
|
+
};
|
|
3465
|
+
var CaseThenBuilder = class {
|
|
3466
|
+
#props;
|
|
3467
|
+
constructor(props) {
|
|
3468
|
+
this.#props = freeze(props);
|
|
3469
|
+
}
|
|
3470
|
+
then(valueExpression) {
|
|
3471
|
+
return new CaseWhenBuilder({
|
|
3472
|
+
...this.#props,
|
|
3473
|
+
node: CaseNode.cloneWithThen(this.#props.node, isSafeImmediateValue(valueExpression) ? parseSafeImmediateValue(valueExpression) : parseValueExpression(valueExpression))
|
|
3474
|
+
});
|
|
3475
|
+
}
|
|
3476
|
+
/**
|
|
3477
|
+
* Adds a `then` clause to the `case` statement where the value is a reference to a column.
|
|
3478
|
+
*
|
|
3479
|
+
* See {@link then} for value-first variant.
|
|
3480
|
+
*
|
|
3481
|
+
* A `thenRef` call can be followed by {@link Whenable.when}, {@link Whenable.whenRef},
|
|
3482
|
+
* {@link CaseWhenBuilder.else}, {@link CaseWhenBuilder.elseRef},
|
|
3483
|
+
* {@link CaseWhenBuilder.end} or {@link CaseWhenBuilder.endCase} call.
|
|
3484
|
+
*/
|
|
3485
|
+
thenRef(expression) {
|
|
3486
|
+
return new CaseWhenBuilder({
|
|
3487
|
+
...this.#props,
|
|
3488
|
+
node: CaseNode.cloneWithThen(this.#props.node, parseReferenceExpression(expression))
|
|
3489
|
+
});
|
|
3490
|
+
}
|
|
3491
|
+
};
|
|
3492
|
+
var CaseWhenBuilder = class {
|
|
3493
|
+
#props;
|
|
3494
|
+
constructor(props) {
|
|
3495
|
+
this.#props = freeze(props);
|
|
3496
|
+
}
|
|
3497
|
+
when(...args) {
|
|
3498
|
+
return new CaseThenBuilder({
|
|
3499
|
+
...this.#props,
|
|
3500
|
+
node: CaseNode.cloneWithWhen(this.#props.node, WhenNode.create(parseValueBinaryOperationOrExpression(args)))
|
|
3501
|
+
});
|
|
3502
|
+
}
|
|
3503
|
+
whenRef(lhs, op, rhs) {
|
|
3504
|
+
return new CaseThenBuilder({
|
|
3505
|
+
...this.#props,
|
|
3506
|
+
node: CaseNode.cloneWithWhen(this.#props.node, WhenNode.create(parseReferentialBinaryOperation(lhs, op, rhs)))
|
|
3507
|
+
});
|
|
3508
|
+
}
|
|
3509
|
+
else(valueExpression) {
|
|
3510
|
+
return new CaseEndBuilder({
|
|
3511
|
+
...this.#props,
|
|
3512
|
+
node: CaseNode.cloneWith(this.#props.node, {
|
|
3513
|
+
else: isSafeImmediateValue(valueExpression) ? parseSafeImmediateValue(valueExpression) : parseValueExpression(valueExpression)
|
|
3514
|
+
})
|
|
3515
|
+
});
|
|
3516
|
+
}
|
|
3517
|
+
/**
|
|
3518
|
+
* Adds an `else` clause to the `case` statement where the value is a reference to a column.
|
|
3519
|
+
*
|
|
3520
|
+
* See {@link else} for value-first variant.
|
|
3521
|
+
*
|
|
3522
|
+
* An `elseRef` call must be followed by an {@link Endable.end} or {@link Endable.endCase} call.
|
|
3523
|
+
*/
|
|
3524
|
+
elseRef(expression) {
|
|
3525
|
+
return new CaseEndBuilder({
|
|
3526
|
+
...this.#props,
|
|
3527
|
+
node: CaseNode.cloneWith(this.#props.node, {
|
|
3528
|
+
else: parseReferenceExpression(expression)
|
|
3529
|
+
})
|
|
3530
|
+
});
|
|
3531
|
+
}
|
|
3532
|
+
end() {
|
|
3533
|
+
return new ExpressionWrapper(CaseNode.cloneWith(this.#props.node, { isStatement: false }));
|
|
3534
|
+
}
|
|
3535
|
+
endCase() {
|
|
3536
|
+
return new ExpressionWrapper(CaseNode.cloneWith(this.#props.node, { isStatement: true }));
|
|
3537
|
+
}
|
|
3538
|
+
};
|
|
3539
|
+
var CaseEndBuilder = class {
|
|
3540
|
+
#props;
|
|
3541
|
+
constructor(props) {
|
|
3542
|
+
this.#props = freeze(props);
|
|
3543
|
+
}
|
|
3544
|
+
end() {
|
|
3545
|
+
return new ExpressionWrapper(CaseNode.cloneWith(this.#props.node, { isStatement: false }));
|
|
3546
|
+
}
|
|
3547
|
+
endCase() {
|
|
3548
|
+
return new ExpressionWrapper(CaseNode.cloneWith(this.#props.node, { isStatement: true }));
|
|
3549
|
+
}
|
|
3550
|
+
};
|
|
3551
|
+
|
|
3552
|
+
// ../../node_modules/.pnpm/kysely@0.29.8/node_modules/kysely/dist/operation-node/json-path-leg-node.js
|
|
3553
|
+
var JSONPathLegNode = freeze({
|
|
3554
|
+
is(node) {
|
|
3555
|
+
return node.kind === "JSONPathLegNode";
|
|
3556
|
+
},
|
|
3557
|
+
create(type, value) {
|
|
3558
|
+
return freeze({
|
|
3559
|
+
kind: "JSONPathLegNode",
|
|
3560
|
+
type,
|
|
3561
|
+
value
|
|
3562
|
+
});
|
|
3563
|
+
}
|
|
3564
|
+
});
|
|
3565
|
+
|
|
3566
|
+
// ../../node_modules/.pnpm/kysely@0.29.8/node_modules/kysely/dist/query-builder/json-path-builder.js
|
|
3567
|
+
var HASH_NEGATIVE_INDEX_REGEX = /^#-\d+$/;
|
|
3568
|
+
var JSONPathBuilder = class {
|
|
3569
|
+
#node;
|
|
3570
|
+
constructor(node) {
|
|
3571
|
+
this.#node = node;
|
|
3572
|
+
}
|
|
3573
|
+
/**
|
|
3574
|
+
* Access an element of a JSON array in a specific location.
|
|
3575
|
+
*
|
|
3576
|
+
* Since there's no guarantee an element exists in the given array location, the
|
|
3577
|
+
* resulting type is always nullable. If you're sure the element exists, you
|
|
3578
|
+
* should use {@link SelectQueryBuilder.$assertType} to narrow the type safely.
|
|
3579
|
+
*
|
|
3580
|
+
* See also {@link key} to access properties of JSON objects.
|
|
3581
|
+
*
|
|
3582
|
+
* ### Examples
|
|
3583
|
+
*
|
|
3584
|
+
* ```ts
|
|
3585
|
+
* await db.selectFrom('person')
|
|
3586
|
+
* .select(eb =>
|
|
3587
|
+
* eb.ref('nicknames', '->').at(0).as('primary_nickname')
|
|
3588
|
+
* )
|
|
3589
|
+
* .execute()
|
|
3590
|
+
* ```
|
|
3591
|
+
*
|
|
3592
|
+
* The generated SQL (PostgreSQL):
|
|
3593
|
+
*
|
|
3594
|
+
* ```sql
|
|
3595
|
+
* select "nicknames"->0 as "primary_nickname" from "person"
|
|
3596
|
+
*```
|
|
3597
|
+
*
|
|
3598
|
+
* Combined with {@link key}:
|
|
3599
|
+
*
|
|
3600
|
+
* ```ts
|
|
3601
|
+
* db.selectFrom('person').select(eb =>
|
|
3602
|
+
* eb.ref('experience', '->').at(0).key('role').as('first_role')
|
|
3603
|
+
* )
|
|
3604
|
+
* ```
|
|
3605
|
+
*
|
|
3606
|
+
* The generated SQL (PostgreSQL):
|
|
3607
|
+
*
|
|
3608
|
+
* ```sql
|
|
3609
|
+
* select "experience"->0->'role' as "first_role" from "person"
|
|
3610
|
+
* ```
|
|
3611
|
+
*
|
|
3612
|
+
* You can use `'last'` to access the last element of the array in MySQL:
|
|
3613
|
+
*
|
|
3614
|
+
* ```ts
|
|
3615
|
+
* db.selectFrom('person').select(eb =>
|
|
3616
|
+
* eb.ref('nicknames', '->$').at('last').as('last_nickname')
|
|
3617
|
+
* )
|
|
3618
|
+
* ```
|
|
3619
|
+
*
|
|
3620
|
+
* The generated SQL (MySQL):
|
|
3621
|
+
*
|
|
3622
|
+
* ```sql
|
|
3623
|
+
* select `nicknames`->'$[last]' as `last_nickname` from `person`
|
|
3624
|
+
* ```
|
|
3625
|
+
*
|
|
3626
|
+
* Or `'#-1'` in SQLite:
|
|
3627
|
+
*
|
|
3628
|
+
* ```ts
|
|
3629
|
+
* db.selectFrom('person').select(eb =>
|
|
3630
|
+
* eb.ref('nicknames', '->>$').at('#-1').as('last_nickname')
|
|
3631
|
+
* )
|
|
3632
|
+
* ```
|
|
3633
|
+
*
|
|
3634
|
+
* The generated SQL (SQLite):
|
|
3635
|
+
*
|
|
3636
|
+
* ```sql
|
|
3637
|
+
* select "nicknames"->>'$[#-1]' as `last_nickname` from `person`
|
|
3638
|
+
* ```
|
|
3639
|
+
*/
|
|
3640
|
+
at(index) {
|
|
3641
|
+
if (typeof index !== "number" && typeof index !== "string" || typeof index === "number" && !Number.isInteger(index) || typeof index === "string" && index !== "last" && !HASH_NEGATIVE_INDEX_REGEX.test(index)) {
|
|
3642
|
+
throw new Error(`Unexpected index value in .at(...): ${index}`);
|
|
3643
|
+
}
|
|
3644
|
+
return this.#createBuilderWithPathLeg("ArrayLocation", index);
|
|
3645
|
+
}
|
|
3646
|
+
/**
|
|
3647
|
+
* Access a property of a JSON object.
|
|
3648
|
+
*
|
|
3649
|
+
* If a field is optional, the resulting type will be nullable.
|
|
3650
|
+
*
|
|
3651
|
+
* See also {@link at} to access elements of JSON arrays.
|
|
3652
|
+
*
|
|
3653
|
+
* ### Examples
|
|
3654
|
+
*
|
|
3655
|
+
* ```ts
|
|
3656
|
+
* db.selectFrom('person').select(eb =>
|
|
3657
|
+
* eb.ref('address', '->').key('city').as('city')
|
|
3658
|
+
* )
|
|
3659
|
+
* ```
|
|
3660
|
+
*
|
|
3661
|
+
* The generated SQL (PostgreSQL):
|
|
3662
|
+
*
|
|
3663
|
+
* ```sql
|
|
3664
|
+
* select "address"->'city' as "city" from "person"
|
|
3665
|
+
* ```
|
|
3666
|
+
*
|
|
3667
|
+
* Going deeper:
|
|
3668
|
+
*
|
|
3669
|
+
* ```ts
|
|
3670
|
+
* db.selectFrom('person').select(eb =>
|
|
3671
|
+
* eb.ref('profile', '->$').key('website').key('url').as('website_url')
|
|
3672
|
+
* )
|
|
3673
|
+
* ```
|
|
3674
|
+
*
|
|
3675
|
+
* The generated SQL (MySQL):
|
|
3676
|
+
*
|
|
3677
|
+
* ```sql
|
|
3678
|
+
* select `profile`->'$.website.url' as `website_url` from `person`
|
|
3679
|
+
* ```
|
|
3680
|
+
*
|
|
3681
|
+
* Combined with {@link at}:
|
|
3682
|
+
*
|
|
3683
|
+
* ```ts
|
|
3684
|
+
* db.selectFrom('person').select(eb =>
|
|
3685
|
+
* eb.ref('profile', '->').key('addresses').at(0).key('city').as('city')
|
|
3686
|
+
* )
|
|
3687
|
+
* ```
|
|
3688
|
+
*
|
|
3689
|
+
* The generated SQL (PostgreSQL):
|
|
3690
|
+
*
|
|
3691
|
+
* ```sql
|
|
3692
|
+
* select "profile"->'addresses'->0->'city' as "city" from "person"
|
|
3693
|
+
* ```
|
|
3694
|
+
*/
|
|
3695
|
+
key(key) {
|
|
3696
|
+
return this.#createBuilderWithPathLeg("Member", key);
|
|
3697
|
+
}
|
|
3698
|
+
#createBuilderWithPathLeg(legType, value) {
|
|
3699
|
+
if (JSONReferenceNode.is(this.#node)) {
|
|
3700
|
+
return new TraversedJSONPathBuilder(JSONReferenceNode.cloneWithTraversal(this.#node, JSONPathNode.is(this.#node.traversal) ? JSONPathNode.cloneWithLeg(this.#node.traversal, JSONPathLegNode.create(legType, value)) : JSONOperatorChainNode.cloneWithValue(this.#node.traversal, ValueNode.createImmediate(value))));
|
|
3701
|
+
}
|
|
3702
|
+
return new TraversedJSONPathBuilder(JSONPathNode.cloneWithLeg(this.#node, JSONPathLegNode.create(legType, value)));
|
|
3703
|
+
}
|
|
3704
|
+
};
|
|
3705
|
+
var TraversedJSONPathBuilder = class _TraversedJSONPathBuilder extends JSONPathBuilder {
|
|
3706
|
+
#node;
|
|
3707
|
+
constructor(node) {
|
|
3708
|
+
super(node);
|
|
3709
|
+
this.#node = node;
|
|
3710
|
+
}
|
|
3711
|
+
/** @private */
|
|
3712
|
+
get expressionType() {
|
|
3713
|
+
return void 0;
|
|
3714
|
+
}
|
|
3715
|
+
as(alias) {
|
|
3716
|
+
return new AliasedJSONPathBuilder(this, alias);
|
|
3717
|
+
}
|
|
3718
|
+
/**
|
|
3719
|
+
* Change the output type of the json path.
|
|
3720
|
+
*
|
|
3721
|
+
* This method call doesn't change the SQL in any way. This methods simply
|
|
3722
|
+
* returns a copy of this `JSONPathBuilder` with a new output type.
|
|
3723
|
+
*/
|
|
3724
|
+
$castTo() {
|
|
3725
|
+
return new _TraversedJSONPathBuilder(this.#node);
|
|
3726
|
+
}
|
|
3727
|
+
$notNull() {
|
|
3728
|
+
return new _TraversedJSONPathBuilder(this.#node);
|
|
3729
|
+
}
|
|
3730
|
+
toOperationNode() {
|
|
3731
|
+
return this.#node;
|
|
3732
|
+
}
|
|
3733
|
+
};
|
|
3734
|
+
var AliasedJSONPathBuilder = class {
|
|
3735
|
+
#jsonPath;
|
|
3736
|
+
#alias;
|
|
3737
|
+
constructor(jsonPath, alias) {
|
|
3738
|
+
this.#jsonPath = jsonPath;
|
|
3739
|
+
this.#alias = alias;
|
|
3740
|
+
}
|
|
3741
|
+
/** @private */
|
|
3742
|
+
get expression() {
|
|
3743
|
+
return this.#jsonPath;
|
|
3744
|
+
}
|
|
3745
|
+
/** @private */
|
|
3746
|
+
get alias() {
|
|
3747
|
+
return this.#alias;
|
|
3748
|
+
}
|
|
3749
|
+
toOperationNode() {
|
|
3750
|
+
return AliasNode.create(this.#jsonPath.toOperationNode(), isOperationNodeSource(this.#alias) ? this.#alias.toOperationNode() : IdentifierNode.create(this.#alias));
|
|
3751
|
+
}
|
|
3752
|
+
};
|
|
3753
|
+
|
|
3754
|
+
// ../../node_modules/.pnpm/kysely@0.29.8/node_modules/kysely/dist/operation-node/tuple-node.js
|
|
3755
|
+
var TupleNode = freeze({
|
|
3756
|
+
is(node) {
|
|
3757
|
+
return node.kind === "TupleNode";
|
|
3758
|
+
},
|
|
3759
|
+
create(values) {
|
|
3760
|
+
return freeze({
|
|
3761
|
+
kind: "TupleNode",
|
|
3762
|
+
values: freeze(values)
|
|
3763
|
+
});
|
|
3764
|
+
}
|
|
3765
|
+
});
|
|
3766
|
+
|
|
3767
|
+
// ../../node_modules/.pnpm/kysely@0.29.8/node_modules/kysely/dist/operation-node/data-type-node.js
|
|
3768
|
+
var SIMPLE_COLUMN_DATA_TYPES = freeze({
|
|
3769
|
+
bigint: true,
|
|
3770
|
+
bigserial: true,
|
|
3771
|
+
binary: true,
|
|
3772
|
+
blob: true,
|
|
3773
|
+
boolean: true,
|
|
3774
|
+
bytea: true,
|
|
3775
|
+
char: true,
|
|
3776
|
+
date: true,
|
|
3777
|
+
datemultirange: true,
|
|
3778
|
+
daterange: true,
|
|
3779
|
+
datetime: true,
|
|
3780
|
+
datetime2: true,
|
|
3781
|
+
decimal: true,
|
|
3782
|
+
"double precision": true,
|
|
3783
|
+
float4: true,
|
|
3784
|
+
float8: true,
|
|
3785
|
+
int2: true,
|
|
3786
|
+
int4: true,
|
|
3787
|
+
int4multirange: true,
|
|
3788
|
+
int4range: true,
|
|
3789
|
+
int8: true,
|
|
3790
|
+
int8multirange: true,
|
|
3791
|
+
int8range: true,
|
|
3792
|
+
integer: true,
|
|
3793
|
+
json: true,
|
|
3794
|
+
jsonb: true,
|
|
3795
|
+
numeric: true,
|
|
3796
|
+
nummultirange: true,
|
|
3797
|
+
numrange: true,
|
|
3798
|
+
real: true,
|
|
3799
|
+
serial: true,
|
|
3800
|
+
smallint: true,
|
|
3801
|
+
text: true,
|
|
3802
|
+
time: true,
|
|
3803
|
+
timestamp: true,
|
|
3804
|
+
timestamptz: true,
|
|
3805
|
+
timetz: true,
|
|
3806
|
+
tsmultirange: true,
|
|
3807
|
+
tsrange: true,
|
|
3808
|
+
tstzmultirange: true,
|
|
3809
|
+
tstzrange: true,
|
|
3810
|
+
uuid: true,
|
|
3811
|
+
varbinary: true,
|
|
3812
|
+
varchar: true
|
|
3813
|
+
});
|
|
3814
|
+
var COLUMN_DATA_TYPE_REGEX = freeze([
|
|
3815
|
+
/^varchar\(\d+\)$/,
|
|
3816
|
+
/^char\(\d+\)$/,
|
|
3817
|
+
/^decimal\(\d+, \d+\)$/,
|
|
3818
|
+
/^numeric\(\d+, \d+\)$/,
|
|
3819
|
+
/^binary\(\d+\)$/,
|
|
3820
|
+
/^datetime\(\d+\)$/,
|
|
3821
|
+
/^time\(\d+\)$/,
|
|
3822
|
+
/^timetz\(\d+\)$/,
|
|
3823
|
+
/^timestamp\(\d+\)$/,
|
|
3824
|
+
/^timestamptz\(\d+\)$/,
|
|
3825
|
+
/^datetime2\(\d+\)$/,
|
|
3826
|
+
/^varbinary\(\d+\)$/
|
|
3827
|
+
]);
|
|
3828
|
+
var DataTypeNode = freeze({
|
|
3829
|
+
is(node) {
|
|
3830
|
+
return node.kind === "DataTypeNode";
|
|
3831
|
+
},
|
|
3832
|
+
create(dataType) {
|
|
3833
|
+
return freeze({
|
|
3834
|
+
kind: "DataTypeNode",
|
|
3835
|
+
dataType
|
|
3836
|
+
});
|
|
3837
|
+
}
|
|
3838
|
+
});
|
|
3839
|
+
function isColumnDataType(dataType) {
|
|
3840
|
+
return SIMPLE_COLUMN_DATA_TYPES[dataType] || COLUMN_DATA_TYPE_REGEX.some((r) => r.test(dataType));
|
|
3841
|
+
}
|
|
3842
|
+
|
|
3843
|
+
// ../../node_modules/.pnpm/kysely@0.29.8/node_modules/kysely/dist/parser/data-type-parser.js
|
|
3844
|
+
function parseDataTypeExpression(dataType) {
|
|
3845
|
+
if (isOperationNodeSource(dataType)) {
|
|
3846
|
+
return dataType.toOperationNode();
|
|
3847
|
+
}
|
|
3848
|
+
if (isColumnDataType(dataType)) {
|
|
3849
|
+
return DataTypeNode.create(dataType);
|
|
3850
|
+
}
|
|
3851
|
+
throw new Error(`invalid column data type ${JSON.stringify(dataType)}`);
|
|
3852
|
+
}
|
|
3853
|
+
|
|
3854
|
+
// ../../node_modules/.pnpm/kysely@0.29.8/node_modules/kysely/dist/operation-node/cast-node.js
|
|
3855
|
+
var CastNode = freeze({
|
|
3856
|
+
is(node) {
|
|
3857
|
+
return node.kind === "CastNode";
|
|
3858
|
+
},
|
|
3859
|
+
create(expression, dataType) {
|
|
3860
|
+
return freeze({
|
|
3861
|
+
kind: "CastNode",
|
|
3862
|
+
expression,
|
|
3863
|
+
dataType
|
|
3864
|
+
});
|
|
3865
|
+
}
|
|
3866
|
+
});
|
|
3867
|
+
|
|
3868
|
+
// ../../node_modules/.pnpm/kysely@0.29.8/node_modules/kysely/dist/expression/expression-builder.js
|
|
3869
|
+
function createExpressionBuilder(executor = NOOP_QUERY_EXECUTOR) {
|
|
3870
|
+
function binary(lhs, op, rhs) {
|
|
3871
|
+
return new ExpressionWrapper(parseValueBinaryOperation(lhs, op, rhs));
|
|
3872
|
+
}
|
|
3873
|
+
function unary(op, expr) {
|
|
3874
|
+
return new ExpressionWrapper(parseUnaryOperation(op, expr));
|
|
3875
|
+
}
|
|
3876
|
+
const eb = Object.assign(binary, {
|
|
3877
|
+
fn: void 0,
|
|
3878
|
+
eb: void 0,
|
|
3879
|
+
selectFrom(table) {
|
|
3880
|
+
return createSelectQueryBuilder({
|
|
3881
|
+
queryId: createQueryId(),
|
|
3882
|
+
executor,
|
|
3883
|
+
queryNode: SelectQueryNode.createFrom(parseTableExpressionOrList(table))
|
|
3884
|
+
});
|
|
3885
|
+
},
|
|
3886
|
+
case(reference) {
|
|
3887
|
+
return new CaseBuilder({
|
|
3888
|
+
node: CaseNode.create(isUndefined(reference) ? void 0 : parseReferenceExpression(reference))
|
|
3889
|
+
});
|
|
3890
|
+
},
|
|
3891
|
+
ref(reference, op) {
|
|
3892
|
+
if (isUndefined(op)) {
|
|
3893
|
+
return new ExpressionWrapper(parseStringReference(reference));
|
|
3894
|
+
}
|
|
3895
|
+
return new JSONPathBuilder(parseJSONReference(reference, op));
|
|
3896
|
+
},
|
|
3897
|
+
jsonPath() {
|
|
3898
|
+
return new JSONPathBuilder(JSONPathNode.create());
|
|
3899
|
+
},
|
|
3900
|
+
table(table) {
|
|
3901
|
+
return new ExpressionWrapper(parseTable(table));
|
|
3902
|
+
},
|
|
3903
|
+
val(value) {
|
|
3904
|
+
return new ExpressionWrapper(parseValueExpression(value));
|
|
3905
|
+
},
|
|
3906
|
+
refTuple(...values) {
|
|
3907
|
+
return new ExpressionWrapper(TupleNode.create(values.map(parseReferenceExpression)));
|
|
3908
|
+
},
|
|
3909
|
+
tuple(...values) {
|
|
3910
|
+
return new ExpressionWrapper(TupleNode.create(values.map(parseValueExpression)));
|
|
3911
|
+
},
|
|
3912
|
+
lit(value) {
|
|
3913
|
+
return new ExpressionWrapper(parseSafeImmediateValue(value));
|
|
3914
|
+
},
|
|
3915
|
+
unary,
|
|
3916
|
+
not(expr) {
|
|
3917
|
+
return unary("not", expr);
|
|
3918
|
+
},
|
|
3919
|
+
exists(expr) {
|
|
3920
|
+
return unary("exists", expr);
|
|
3921
|
+
},
|
|
3922
|
+
neg(expr) {
|
|
3923
|
+
return unary("-", expr);
|
|
3924
|
+
},
|
|
3925
|
+
between(expr, start, end) {
|
|
3926
|
+
return new ExpressionWrapper(BinaryOperationNode.create(parseReferenceExpression(expr), OperatorNode.create("between"), AndNode.create(parseValueExpression(start), parseValueExpression(end))));
|
|
3927
|
+
},
|
|
3928
|
+
betweenSymmetric(expr, start, end) {
|
|
3929
|
+
return new ExpressionWrapper(BinaryOperationNode.create(parseReferenceExpression(expr), OperatorNode.create("between symmetric"), AndNode.create(parseValueExpression(start), parseValueExpression(end))));
|
|
3930
|
+
},
|
|
3931
|
+
and(exprs) {
|
|
3932
|
+
if (isReadonlyArray(exprs)) {
|
|
3933
|
+
return new ExpressionWrapper(parseFilterList(exprs, "and"));
|
|
3934
|
+
}
|
|
3935
|
+
return new ExpressionWrapper(parseFilterObject(exprs, "and"));
|
|
3936
|
+
},
|
|
3937
|
+
or(exprs) {
|
|
3938
|
+
if (isReadonlyArray(exprs)) {
|
|
3939
|
+
return new ExpressionWrapper(parseFilterList(exprs, "or"));
|
|
3940
|
+
}
|
|
3941
|
+
return new ExpressionWrapper(parseFilterObject(exprs, "or"));
|
|
3942
|
+
},
|
|
3943
|
+
parens(...args) {
|
|
3944
|
+
const node = parseValueBinaryOperationOrExpression(args);
|
|
3945
|
+
if (ParensNode.is(node)) {
|
|
3946
|
+
return new ExpressionWrapper(node);
|
|
3947
|
+
} else {
|
|
3948
|
+
return new ExpressionWrapper(ParensNode.create(node));
|
|
3949
|
+
}
|
|
3950
|
+
},
|
|
3951
|
+
cast(expr, dataType) {
|
|
3952
|
+
return new ExpressionWrapper(CastNode.create(parseReferenceExpression(expr), parseDataTypeExpression(dataType)));
|
|
3953
|
+
}
|
|
3954
|
+
});
|
|
3955
|
+
eb.fn = createFunctionModule();
|
|
3956
|
+
eb.eb = eb;
|
|
3957
|
+
return eb;
|
|
3958
|
+
}
|
|
3959
|
+
function expressionBuilder(_) {
|
|
3960
|
+
return createExpressionBuilder();
|
|
3961
|
+
}
|
|
3962
|
+
|
|
3963
|
+
// ../../node_modules/.pnpm/kysely@0.29.8/node_modules/kysely/dist/parser/expression-parser.js
|
|
3964
|
+
function parseExpression(exp) {
|
|
3965
|
+
if (isOperationNodeSource(exp)) {
|
|
3966
|
+
return exp.toOperationNode();
|
|
3967
|
+
} else if (isFunction(exp)) {
|
|
3968
|
+
return exp(expressionBuilder()).toOperationNode();
|
|
3969
|
+
}
|
|
3970
|
+
throw new Error(`invalid expression: ${JSON.stringify(exp)}`);
|
|
3971
|
+
}
|
|
3972
|
+
function parseAliasedExpression(exp) {
|
|
3973
|
+
if (isOperationNodeSource(exp)) {
|
|
3974
|
+
return exp.toOperationNode();
|
|
3975
|
+
} else if (isFunction(exp)) {
|
|
3976
|
+
return exp(expressionBuilder()).toOperationNode();
|
|
3977
|
+
}
|
|
3978
|
+
throw new Error(`invalid aliased expression: ${JSON.stringify(exp)}`);
|
|
3979
|
+
}
|
|
3980
|
+
function isExpressionOrFactory(obj) {
|
|
3981
|
+
return isExpression(obj) || isAliasedExpression(obj) || isFunction(obj);
|
|
3982
|
+
}
|
|
3983
|
+
|
|
3984
|
+
// ../../node_modules/.pnpm/kysely@0.29.8/node_modules/kysely/dist/dynamic/dynamic-table-builder.js
|
|
3985
|
+
function isAliasedDynamicTableBuilder(obj) {
|
|
3986
|
+
return isObject(obj) && isOperationNodeSource(obj) && isString(obj.table) && isString(obj.alias);
|
|
3987
|
+
}
|
|
3988
|
+
|
|
3989
|
+
// ../../node_modules/.pnpm/kysely@0.29.8/node_modules/kysely/dist/parser/table-parser.js
|
|
3990
|
+
function parseTableExpressionOrList(table) {
|
|
3991
|
+
if (isReadonlyArray(table)) {
|
|
3992
|
+
return table.map((it) => parseTableExpression(it));
|
|
3993
|
+
} else {
|
|
3994
|
+
return [parseTableExpression(table)];
|
|
3995
|
+
}
|
|
3996
|
+
}
|
|
3997
|
+
function parseTableExpression(table) {
|
|
3998
|
+
if (isString(table)) {
|
|
3999
|
+
return parseAliasedTable(table);
|
|
4000
|
+
} else if (isAliasedDynamicTableBuilder(table)) {
|
|
4001
|
+
return table.toOperationNode();
|
|
4002
|
+
} else {
|
|
4003
|
+
return parseAliasedExpression(table);
|
|
4004
|
+
}
|
|
4005
|
+
}
|
|
4006
|
+
function parseAliasedTable(from) {
|
|
4007
|
+
const ALIAS_SEPARATOR = " as ";
|
|
4008
|
+
if (from.includes(ALIAS_SEPARATOR)) {
|
|
4009
|
+
const [table, alias] = from.split(ALIAS_SEPARATOR).map(trim2);
|
|
4010
|
+
return AliasNode.create(parseTable(table), IdentifierNode.create(alias));
|
|
4011
|
+
} else {
|
|
4012
|
+
return parseTable(from);
|
|
4013
|
+
}
|
|
4014
|
+
}
|
|
4015
|
+
function parseTable(from) {
|
|
4016
|
+
const SCHEMA_SEPARATOR = ".";
|
|
4017
|
+
if (from.includes(SCHEMA_SEPARATOR)) {
|
|
4018
|
+
const [schema, table] = from.split(SCHEMA_SEPARATOR).map(trim2);
|
|
4019
|
+
return TableNode.createWithSchema(schema, table);
|
|
4020
|
+
} else {
|
|
4021
|
+
return TableNode.create(from);
|
|
4022
|
+
}
|
|
4023
|
+
}
|
|
4024
|
+
function trim2(str) {
|
|
4025
|
+
return str.trim();
|
|
4026
|
+
}
|
|
4027
|
+
|
|
4028
|
+
// ../../node_modules/.pnpm/kysely@0.29.8/node_modules/kysely/dist/raw-builder/raw-builder.js
|
|
4029
|
+
var RawBuilderImpl = class _RawBuilderImpl {
|
|
4030
|
+
#props;
|
|
4031
|
+
constructor(props) {
|
|
4032
|
+
this.#props = freeze(props);
|
|
4033
|
+
}
|
|
4034
|
+
get expressionType() {
|
|
4035
|
+
return void 0;
|
|
4036
|
+
}
|
|
4037
|
+
get isRawBuilder() {
|
|
4038
|
+
return true;
|
|
4039
|
+
}
|
|
4040
|
+
as(alias) {
|
|
4041
|
+
return new AliasedRawBuilderImpl(this, alias);
|
|
4042
|
+
}
|
|
4043
|
+
$castTo() {
|
|
4044
|
+
return new _RawBuilderImpl({ ...this.#props });
|
|
4045
|
+
}
|
|
4046
|
+
$notNull() {
|
|
4047
|
+
return new _RawBuilderImpl(this.#props);
|
|
4048
|
+
}
|
|
4049
|
+
withPlugin(plugin2) {
|
|
4050
|
+
return new _RawBuilderImpl({
|
|
4051
|
+
...this.#props,
|
|
4052
|
+
plugins: this.#props.plugins !== void 0 ? freeze([...this.#props.plugins, plugin2]) : freeze([plugin2])
|
|
4053
|
+
});
|
|
4054
|
+
}
|
|
4055
|
+
toOperationNode() {
|
|
4056
|
+
return this.#toOperationNode(this.#getExecutor());
|
|
4057
|
+
}
|
|
4058
|
+
compile(executorProvider) {
|
|
4059
|
+
return this.#compile(this.#getExecutor(executorProvider));
|
|
4060
|
+
}
|
|
4061
|
+
async execute(executorProvider, options) {
|
|
4062
|
+
const executor = this.#getExecutor(executorProvider);
|
|
4063
|
+
return executor.executeQuery(this.#compile(executor), options);
|
|
4064
|
+
}
|
|
4065
|
+
#getExecutor(executorProvider) {
|
|
4066
|
+
const executor = executorProvider !== void 0 ? executorProvider.getExecutor() : NOOP_QUERY_EXECUTOR;
|
|
4067
|
+
return this.#props.plugins !== void 0 ? executor.withPlugins(this.#props.plugins) : executor;
|
|
4068
|
+
}
|
|
4069
|
+
#toOperationNode(executor) {
|
|
4070
|
+
return executor.transformQuery(this.#props.rawNode, this.#props.queryId);
|
|
4071
|
+
}
|
|
4072
|
+
#compile(executor) {
|
|
4073
|
+
return executor.compileQuery(this.#toOperationNode(executor), this.#props.queryId);
|
|
4074
|
+
}
|
|
4075
|
+
};
|
|
4076
|
+
function createRawBuilder(props) {
|
|
4077
|
+
return new RawBuilderImpl(props);
|
|
4078
|
+
}
|
|
4079
|
+
var AliasedRawBuilderImpl = class {
|
|
4080
|
+
#rawBuilder;
|
|
4081
|
+
#alias;
|
|
4082
|
+
constructor(rawBuilder, alias) {
|
|
4083
|
+
this.#rawBuilder = rawBuilder;
|
|
4084
|
+
this.#alias = alias;
|
|
4085
|
+
}
|
|
4086
|
+
get expression() {
|
|
4087
|
+
return this.#rawBuilder;
|
|
4088
|
+
}
|
|
4089
|
+
get alias() {
|
|
4090
|
+
return this.#alias;
|
|
4091
|
+
}
|
|
4092
|
+
get rawBuilder() {
|
|
4093
|
+
return this.#rawBuilder;
|
|
4094
|
+
}
|
|
4095
|
+
toOperationNode() {
|
|
4096
|
+
return AliasNode.create(this.#rawBuilder.toOperationNode(), isOperationNodeSource(this.#alias) ? this.#alias.toOperationNode() : IdentifierNode.create(this.#alias));
|
|
4097
|
+
}
|
|
4098
|
+
};
|
|
4099
|
+
|
|
4100
|
+
// ../../node_modules/.pnpm/kysely@0.29.8/node_modules/kysely/dist/raw-builder/sql.js
|
|
4101
|
+
var sql = Object.assign((sqlFragments, ...parameters) => {
|
|
4102
|
+
return createRawBuilder({
|
|
4103
|
+
queryId: createQueryId(),
|
|
4104
|
+
rawNode: RawNode.create(sqlFragments, parameters?.map(parseParameter) ?? [])
|
|
4105
|
+
});
|
|
4106
|
+
}, {
|
|
4107
|
+
ref(columnReference) {
|
|
4108
|
+
return createRawBuilder({
|
|
4109
|
+
queryId: createQueryId(),
|
|
4110
|
+
rawNode: RawNode.createWithChild(parseStringReference(columnReference))
|
|
4111
|
+
});
|
|
4112
|
+
},
|
|
4113
|
+
val(value) {
|
|
4114
|
+
return createRawBuilder({
|
|
4115
|
+
queryId: createQueryId(),
|
|
4116
|
+
rawNode: RawNode.createWithChild(parseValueExpression(value))
|
|
4117
|
+
});
|
|
4118
|
+
},
|
|
4119
|
+
table(tableReference) {
|
|
4120
|
+
return createRawBuilder({
|
|
4121
|
+
queryId: createQueryId(),
|
|
4122
|
+
rawNode: RawNode.createWithChild(parseTable(tableReference))
|
|
4123
|
+
});
|
|
4124
|
+
},
|
|
4125
|
+
id(...ids) {
|
|
4126
|
+
const fragments = new Array(ids.length + 1).fill(".");
|
|
4127
|
+
fragments[0] = "";
|
|
4128
|
+
fragments[fragments.length - 1] = "";
|
|
4129
|
+
return createRawBuilder({
|
|
4130
|
+
queryId: createQueryId(),
|
|
4131
|
+
rawNode: RawNode.create(fragments, ids.map(IdentifierNode.create))
|
|
4132
|
+
});
|
|
4133
|
+
},
|
|
4134
|
+
lit(value) {
|
|
4135
|
+
return createRawBuilder({
|
|
4136
|
+
queryId: createQueryId(),
|
|
4137
|
+
rawNode: RawNode.createWithChild(ValueNode.createImmediate(value))
|
|
4138
|
+
});
|
|
4139
|
+
},
|
|
4140
|
+
raw(sql2) {
|
|
4141
|
+
return createRawBuilder({
|
|
4142
|
+
queryId: createQueryId(),
|
|
4143
|
+
rawNode: RawNode.createWithSql(sql2)
|
|
4144
|
+
});
|
|
4145
|
+
},
|
|
4146
|
+
join(array, separator = sql`, `) {
|
|
4147
|
+
const nodes = new Array(Math.max(2 * array.length - 1, 0));
|
|
4148
|
+
const sep = separator.toOperationNode();
|
|
4149
|
+
for (let i = 0; i < array.length; ++i) {
|
|
4150
|
+
nodes[2 * i] = parseParameter(array[i]);
|
|
4151
|
+
if (i !== array.length - 1) {
|
|
4152
|
+
nodes[2 * i + 1] = sep;
|
|
4153
|
+
}
|
|
4154
|
+
}
|
|
4155
|
+
return createRawBuilder({
|
|
4156
|
+
queryId: createQueryId(),
|
|
4157
|
+
rawNode: RawNode.createWithChildren(nodes)
|
|
4158
|
+
});
|
|
4159
|
+
}
|
|
4160
|
+
});
|
|
4161
|
+
function parseParameter(param) {
|
|
4162
|
+
if (isOperationNodeSource(param)) {
|
|
4163
|
+
return param.toOperationNode();
|
|
4164
|
+
}
|
|
4165
|
+
return parseValueExpression(param);
|
|
4166
|
+
}
|
|
4167
|
+
|
|
4168
|
+
// src/pg-rows.ts
|
|
4169
|
+
var HASH = /^[a-f0-9]{64}$/;
|
|
4170
|
+
var FEATURES = Object.freeze(["networkReport", "projects"]);
|
|
4171
|
+
var json = (v) => typeof v === "string" ? JSON.parse(v) : v;
|
|
4172
|
+
function identityOf(v) {
|
|
4173
|
+
const o = json(v);
|
|
4174
|
+
if (!o || typeof o !== "object") return null;
|
|
4175
|
+
const { runtimeHash, helperHash, imageFingerprint, instanceGeneration } = o;
|
|
4176
|
+
if (typeof runtimeHash !== "string" || !HASH.test(runtimeHash) || typeof helperHash !== "string" || !HASH.test(helperHash) || typeof imageFingerprint !== "string" || !HASH.test(imageFingerprint) || typeof instanceGeneration !== "string")
|
|
4177
|
+
return null;
|
|
4178
|
+
return { runtimeHash, helperHash, imageFingerprint, instanceGeneration };
|
|
4179
|
+
}
|
|
4180
|
+
function installedOf(r) {
|
|
4181
|
+
const runtimeIdentity = identityOf(r.runtime_identity);
|
|
4182
|
+
if (!runtimeIdentity) return void 0;
|
|
4183
|
+
try {
|
|
4184
|
+
return {
|
|
4185
|
+
runtimeIdentity,
|
|
4186
|
+
permissionSupport: parseSandboxPermissionSupport2(json(r.permission_support)),
|
|
4187
|
+
ownerCeiling: parseOwnerCeilingReport2(json(r.owner_ceiling))
|
|
4188
|
+
};
|
|
4189
|
+
} catch {
|
|
4190
|
+
return void 0;
|
|
4191
|
+
}
|
|
4192
|
+
}
|
|
4193
|
+
function bindingOf(r) {
|
|
4194
|
+
if (!r) return null;
|
|
4195
|
+
const installed = r.status === "installed" ? installedOf(r) : void 0;
|
|
4196
|
+
return {
|
|
4197
|
+
deviceId: String(r.device_id),
|
|
4198
|
+
instanceId: String(r.instance_id),
|
|
4199
|
+
generation: String(r.generation),
|
|
4200
|
+
bindingId: String(r.binding_id),
|
|
4201
|
+
previousGeneration: r.previous_generation === null ? null : String(r.previous_generation),
|
|
4202
|
+
// an installed row whose facts are unreadable admits nothing until a binding answer again
|
|
4203
|
+
status: installed ? "installed" : "awaiting-device",
|
|
4204
|
+
...installed && { installed },
|
|
4205
|
+
...installed && r.unattested === true && { unattested: true }
|
|
4206
|
+
};
|
|
4207
|
+
}
|
|
4208
|
+
var UNREADABLE_SUPPORT = parseSandboxPermissionSupport2({
|
|
4209
|
+
version: 2,
|
|
4210
|
+
boundary: "operation",
|
|
4211
|
+
restricted: null,
|
|
4212
|
+
network: { openPublic: false, allowlist: false, perOperationHosts: false },
|
|
4213
|
+
outsideSandbox: false,
|
|
4214
|
+
background: false,
|
|
4215
|
+
unavailableReason: "The stored hello is unreadable; the machine reports it again when it reconnects"
|
|
4216
|
+
});
|
|
4217
|
+
function connectionOf(r) {
|
|
4218
|
+
if (!r) return null;
|
|
4219
|
+
const roots = json(r.roots);
|
|
4220
|
+
if (!roots || typeof roots.workspace !== "string" || typeof roots.skills !== "string" || typeof roots.tmp !== "string" || r.mode !== "os" && r.mode !== "docker" || typeof r.machine_id !== "string" || typeof r.connection_id !== "string")
|
|
4221
|
+
return null;
|
|
4222
|
+
let permissionSupport = UNREADABLE_SUPPORT;
|
|
4223
|
+
try {
|
|
4224
|
+
permissionSupport = parseSandboxPermissionSupport2(json(r.permission_support));
|
|
4225
|
+
} catch {
|
|
4226
|
+
}
|
|
4227
|
+
const features = Array.isArray(r.features) ? r.features : [];
|
|
4228
|
+
return {
|
|
4229
|
+
deviceId: String(r.device_id),
|
|
4230
|
+
orgId: typeof r.org_id === "string" ? r.org_id : null,
|
|
4231
|
+
machineId: r.machine_id,
|
|
4232
|
+
connectionId: r.connection_id,
|
|
4233
|
+
machineEpoch: Number(r.machine_epoch),
|
|
4234
|
+
mode: r.mode,
|
|
4235
|
+
roots: { workspace: roots.workspace, skills: roots.skills, tmp: roots.tmp },
|
|
4236
|
+
home: typeof r.home === "string" ? r.home : null,
|
|
4237
|
+
sessionIsolation: r.session_isolation === true,
|
|
4238
|
+
features: FEATURES.filter((f) => features.includes(f)),
|
|
4239
|
+
permissionSupport,
|
|
4240
|
+
ownerReport: storedOwnerReportOf(json(r.owner_report)),
|
|
4241
|
+
instanceGeneration: typeof r.instance_generation === "string" ? r.instance_generation : null,
|
|
4242
|
+
runtimeIdentity: identityOf(r.runtime_identity)
|
|
4243
|
+
};
|
|
4244
|
+
}
|
|
4245
|
+
async function readIn(db, deviceId) {
|
|
4246
|
+
const [c, b] = await Promise.all([
|
|
4247
|
+
db.selectFrom("connections").selectAll().where("device_id", "=", deviceId).executeTakeFirst(),
|
|
4248
|
+
db.selectFrom("bindings").selectAll().where("device_id", "=", deviceId).executeTakeFirst()
|
|
4249
|
+
]);
|
|
4250
|
+
return { connection: connectionOf(c), binding: bindingOf(b) };
|
|
4251
|
+
}
|
|
4252
|
+
async function writeConnection(db, c) {
|
|
4253
|
+
const values = {
|
|
4254
|
+
device_id: c.deviceId,
|
|
4255
|
+
org_id: c.orgId,
|
|
4256
|
+
machine_id: c.machineId,
|
|
4257
|
+
connection_id: c.connectionId,
|
|
4258
|
+
machine_epoch: c.machineEpoch,
|
|
4259
|
+
mode: c.mode,
|
|
4260
|
+
roots: JSON.stringify(c.roots),
|
|
4261
|
+
home: c.home,
|
|
4262
|
+
session_isolation: c.sessionIsolation,
|
|
4263
|
+
features: c.features,
|
|
4264
|
+
permission_support: JSON.stringify(c.permissionSupport),
|
|
4265
|
+
owner_report: c.ownerReport === null ? null : JSON.stringify(c.ownerReport),
|
|
4266
|
+
instance_generation: c.instanceGeneration,
|
|
4267
|
+
runtime_identity: c.runtimeIdentity === null ? null : JSON.stringify(c.runtimeIdentity),
|
|
4268
|
+
updated_at: sql`now()`
|
|
4269
|
+
};
|
|
4270
|
+
const { device_id: _key, org_id: _org, ...update } = values;
|
|
4271
|
+
await db.insertInto("connections").values(values).onConflict(
|
|
4272
|
+
(oc) => oc.column("device_id").doUpdateSet({
|
|
4273
|
+
...update,
|
|
4274
|
+
// the org is learned once (connectionOf) and never moves
|
|
4275
|
+
org_id: sql`coalesce(connections.org_id, excluded.org_id)`
|
|
4276
|
+
})
|
|
4277
|
+
).execute();
|
|
4278
|
+
}
|
|
4279
|
+
async function writeBinding(db, b) {
|
|
4280
|
+
const values = {
|
|
4281
|
+
device_id: b.deviceId,
|
|
4282
|
+
instance_id: b.instanceId,
|
|
4283
|
+
generation: b.generation,
|
|
4284
|
+
binding_id: b.bindingId,
|
|
4285
|
+
previous_generation: b.previousGeneration,
|
|
4286
|
+
status: b.status,
|
|
4287
|
+
runtime_identity: b.installed ? JSON.stringify(b.installed.runtimeIdentity) : null,
|
|
4288
|
+
permission_support: b.installed ? JSON.stringify(b.installed.permissionSupport) : null,
|
|
4289
|
+
owner_ceiling: b.installed ? JSON.stringify(b.installed.ownerCeiling) : null,
|
|
4290
|
+
unattested: b.unattested === true,
|
|
4291
|
+
updated_at: sql`now()`
|
|
4292
|
+
};
|
|
4293
|
+
const { device_id: _key, ...update } = values;
|
|
4294
|
+
await db.insertInto("bindings").values(values).onConflict((oc) => oc.column("device_id").doUpdateSet(update)).execute();
|
|
4295
|
+
}
|
|
4296
|
+
var lockDevice = (trx, deviceId) => sql`SELECT pg_advisory_xact_lock(hashtextextended(${`device-local:${deviceId}`}, 0))`.execute(
|
|
4297
|
+
trx
|
|
4298
|
+
);
|
|
4299
|
+
function pgRows(db) {
|
|
4300
|
+
return {
|
|
4301
|
+
read: (deviceId) => readIn(db, deviceId),
|
|
4302
|
+
change: (deviceId, fn) => db.transaction().execute(async (trx) => {
|
|
4303
|
+
await lockDevice(trx, deviceId);
|
|
4304
|
+
const c = fn(await readIn(trx, deviceId));
|
|
4305
|
+
if (c.connection) await writeConnection(trx, c.connection);
|
|
4306
|
+
if (c.binding) await writeBinding(trx, c.binding);
|
|
4307
|
+
return c.result;
|
|
4308
|
+
}),
|
|
4309
|
+
async connectionOf(deviceId, orgId) {
|
|
4310
|
+
await db.updateTable("connections").set({ org_id: orgId }).where("device_id", "=", deviceId).where("org_id", "is", null).execute();
|
|
4311
|
+
const r = await db.selectFrom("connections").selectAll().where("device_id", "=", deviceId).where("org_id", "=", orgId).executeTakeFirst();
|
|
4312
|
+
return connectionOf(r);
|
|
4313
|
+
},
|
|
4314
|
+
forget: (deviceId) => db.transaction().execute(async (trx) => {
|
|
4315
|
+
await lockDevice(trx, deviceId);
|
|
4316
|
+
await trx.deleteFrom("connections").where("device_id", "=", deviceId).execute();
|
|
4317
|
+
await trx.deleteFrom("bindings").where("device_id", "=", deviceId).execute();
|
|
4318
|
+
})
|
|
4319
|
+
};
|
|
4320
|
+
}
|
|
4321
|
+
|
|
4322
|
+
// src/provider.ts
|
|
4323
|
+
import {
|
|
4324
|
+
DeviceOfflineError,
|
|
4325
|
+
isDeviceOfflineError,
|
|
4326
|
+
parseSandboxBrowseScope,
|
|
4327
|
+
parseSandboxOperationScope,
|
|
4328
|
+
parseSandboxPreparationScope,
|
|
4329
|
+
SandboxGoneError as SandboxGoneError2,
|
|
4330
|
+
SandboxPermissionUnsupportedError as SandboxPermissionUnsupportedError2,
|
|
4331
|
+
ToolError as ToolError2,
|
|
4332
|
+
validateAllowHost
|
|
4333
|
+
} from "@capybara-hq/plugin-sdk";
|
|
4334
|
+
|
|
4335
|
+
// src/bindings.ts
|
|
4336
|
+
import { randomUUID } from "node:crypto";
|
|
4337
|
+
import {
|
|
4338
|
+
isDeviceRequestNotSent,
|
|
4339
|
+
isSandboxPermissionUnsupportedError,
|
|
4340
|
+
isSandboxScopeDeniedError,
|
|
4341
|
+
isSandboxWorkUnsettledError
|
|
4342
|
+
} from "@capybara-hq/plugin-sdk";
|
|
4343
|
+
|
|
4344
|
+
// src/frames.ts
|
|
4345
|
+
import {
|
|
4346
|
+
FileSystemGoneError,
|
|
4347
|
+
ProjectPathRefusedError,
|
|
4348
|
+
SandboxGoneError,
|
|
4349
|
+
SandboxOperationOutcomeUnknownError,
|
|
4350
|
+
SandboxPermissionUnsupportedError,
|
|
4351
|
+
SandboxScopeDeniedError,
|
|
4352
|
+
SandboxScopeValidationError,
|
|
4353
|
+
SandboxWorkUnsettledError,
|
|
4354
|
+
ToolError
|
|
4355
|
+
} from "@capybara-hq/plugin-sdk";
|
|
4356
|
+
import {
|
|
4357
|
+
parseDeviceFrame as parseDeviceFrame2,
|
|
4358
|
+
parseOperationResult
|
|
4359
|
+
} from "@capybara-hq/plugin-sdk/device-protocol";
|
|
4360
|
+
var POLICY_REFUSAL_PREFIX = "Refused by the machine's local policy: ";
|
|
4361
|
+
var ON_MACHINE_PREFIX = "On the connected machine: ";
|
|
4362
|
+
var EXEC_DEADLINE_MARGIN_MS = 5e3;
|
|
4363
|
+
var OP_DEADLINE_MS = 3e4;
|
|
4364
|
+
var errMsg2 = (e) => e instanceof Error ? e.message : String(e);
|
|
4365
|
+
var invalidAnswer = (op, e) => new ToolError(
|
|
4366
|
+
`The connected machine sent an invalid answer to ${op} (${errMsg2(e)}); update capybara-device on that machine and retry`
|
|
4367
|
+
);
|
|
4368
|
+
function machineCall(dialIn) {
|
|
4369
|
+
return async (deviceId, op, args, opts) => {
|
|
4370
|
+
const body = parseDeviceFrame2({ op, args }, "req");
|
|
4371
|
+
const raw = await dialIn.request(deviceId, body, {
|
|
4372
|
+
timeoutMs: opts.deadlineMs,
|
|
4373
|
+
signal: opts.signal
|
|
4374
|
+
});
|
|
4375
|
+
let res;
|
|
4376
|
+
try {
|
|
4377
|
+
res = parseDeviceFrame2(raw, "res");
|
|
4378
|
+
} catch (e) {
|
|
4379
|
+
throw invalidAnswer(op, e);
|
|
4380
|
+
}
|
|
4381
|
+
if (!res.ok) throw failureOf(res.error, op);
|
|
4382
|
+
try {
|
|
4383
|
+
return parseOperationResult(op, res.result, requestOf(op, body.args));
|
|
4384
|
+
} catch (e) {
|
|
4385
|
+
throw invalidAnswer(op, e);
|
|
4386
|
+
}
|
|
4387
|
+
};
|
|
4388
|
+
}
|
|
4389
|
+
function requestOf(op, args) {
|
|
4390
|
+
if (op === "backgroundReadOutput") return args;
|
|
4391
|
+
if (op === "bindInstance") return args;
|
|
4392
|
+
return void 0;
|
|
4393
|
+
}
|
|
4394
|
+
var isProjectListing = (op) => op === "list" || op === "scan" || op === "browseList" || op === "browseScan";
|
|
4395
|
+
function failureOf(error, op) {
|
|
4396
|
+
const { kind, message } = error;
|
|
4397
|
+
switch (kind) {
|
|
4398
|
+
case "denied":
|
|
4399
|
+
return new SandboxScopeDeniedError(message);
|
|
4400
|
+
case "unsupported":
|
|
4401
|
+
return new SandboxPermissionUnsupportedError(message);
|
|
4402
|
+
case "unsettled":
|
|
4403
|
+
return new SandboxWorkUnsettledError(message);
|
|
4404
|
+
case "unknown":
|
|
4405
|
+
return new SandboxOperationOutcomeUnknownError(message);
|
|
4406
|
+
case "invalid":
|
|
4407
|
+
return new SandboxScopeValidationError(message);
|
|
4408
|
+
case "gone":
|
|
4409
|
+
return new SandboxGoneError(message);
|
|
4410
|
+
case "fs_gone":
|
|
4411
|
+
return new FileSystemGoneError(message);
|
|
4412
|
+
case "policy":
|
|
4413
|
+
if (isProjectListing(op))
|
|
4414
|
+
return new ProjectPathRefusedError({ en: `${POLICY_REFUSAL_PREFIX}${message}` });
|
|
4415
|
+
return new ToolError(
|
|
4416
|
+
`${POLICY_REFUSAL_PREFIX}${message} (ask the machine's owner to allow it, or use another way)`
|
|
4417
|
+
);
|
|
4418
|
+
default:
|
|
4419
|
+
return new ToolError(`${ON_MACHINE_PREFIX}${message} (check the path or command and retry)`);
|
|
4420
|
+
}
|
|
4421
|
+
}
|
|
4422
|
+
|
|
4423
|
+
// src/store.ts
|
|
4424
|
+
var viaOf = (c) => c ? { machineId: c.machineId, connectionId: c.connectionId } : null;
|
|
4425
|
+
var sameVia = (c, via) => c === null || via === null ? c === null && via === null : c.machineId === via.machineId && c.connectionId === via.connectionId;
|
|
4426
|
+
function storeOver(rows, now = () => (/* @__PURE__ */ new Date()).toISOString()) {
|
|
4427
|
+
return {
|
|
4428
|
+
binding: async (deviceId) => (await rows.read(deviceId)).binding,
|
|
4429
|
+
commitBinding: (binding, expectedGeneration) => rows.change(
|
|
4430
|
+
binding.deviceId,
|
|
4431
|
+
(s) => (s.binding?.generation ?? null) === expectedGeneration ? { result: true, binding } : { result: false }
|
|
4432
|
+
),
|
|
4433
|
+
installBinding: (deviceId, generation, bindingId, installed, via) => rows.change(deviceId, (s) => {
|
|
4434
|
+
const b = s.binding;
|
|
4435
|
+
if (b?.generation !== generation || b.bindingId !== bindingId) return { result: false };
|
|
4436
|
+
if (!sameVia(s.connection, via)) return { result: false };
|
|
4437
|
+
const { unattested: _attestedAgain, ...kept } = b;
|
|
4438
|
+
const binding = { ...kept, status: "installed", installed };
|
|
4439
|
+
const c = s.connection;
|
|
4440
|
+
const applied = c && applyOwnerReport(c.ownerReport, installed.ownerCeiling, "bind", now());
|
|
4441
|
+
return {
|
|
4442
|
+
result: true,
|
|
4443
|
+
binding,
|
|
4444
|
+
...c && applied?.next && { connection: { ...c, ownerReport: applied.next } }
|
|
4445
|
+
};
|
|
4446
|
+
}),
|
|
4447
|
+
state: (deviceId) => rows.read(deviceId),
|
|
4448
|
+
change: (deviceId, fn) => rows.change(deviceId, fn),
|
|
4449
|
+
connectionOf: (deviceId, orgId) => rows.connectionOf(deviceId, orgId),
|
|
4450
|
+
forget: (deviceId) => rows.forget(deviceId)
|
|
4451
|
+
};
|
|
4452
|
+
}
|
|
4453
|
+
|
|
4454
|
+
// src/bindings.ts
|
|
4455
|
+
var InstanceBindingError = class extends Error {
|
|
4456
|
+
name = "InstanceBindingError";
|
|
4457
|
+
};
|
|
4458
|
+
function nextGeneration(previous, nowMs) {
|
|
4459
|
+
const now = BigInt(Math.max(0, Math.floor(nowMs)));
|
|
4460
|
+
if (previous === null) return now.toString();
|
|
4461
|
+
const after = BigInt(previous) + 1n;
|
|
4462
|
+
return (now > after ? now : after).toString();
|
|
4463
|
+
}
|
|
4464
|
+
var sameRuntime2 = (a, b) => a.runtimeHash === b.runtimeHash && a.helperHash === b.helperHash && a.imageFingerprint === b.imageFingerprint;
|
|
4465
|
+
var requestOf2 = (b) => ({
|
|
4466
|
+
instanceId: b.instanceId,
|
|
4467
|
+
instanceGeneration: b.generation,
|
|
4468
|
+
bindingId: b.bindingId,
|
|
4469
|
+
expectedPreviousGeneration: b.previousGeneration
|
|
4470
|
+
});
|
|
4471
|
+
function createInstanceBindings(call, store, now = Date.now) {
|
|
4472
|
+
const send = async (b, signal) => {
|
|
4473
|
+
const request = requestOf2(b);
|
|
4474
|
+
const via = viaOf((await store.state(b.deviceId)).connection);
|
|
4475
|
+
const answer = await call(
|
|
4476
|
+
b.deviceId,
|
|
4477
|
+
"bindInstance",
|
|
4478
|
+
{ ...request },
|
|
4479
|
+
{ deadlineMs: OP_DEADLINE_MS, signal }
|
|
4480
|
+
);
|
|
4481
|
+
if (answer.instanceId !== request.instanceId || answer.instanceGeneration !== request.instanceGeneration || answer.bindingId !== request.bindingId || answer.runtimeIdentity.instanceGeneration !== request.instanceGeneration)
|
|
4482
|
+
throw new InstanceBindingError("The binding answer belongs to another instance generation");
|
|
4483
|
+
if (b.installed && !sameRuntime2(b.installed.runtimeIdentity, answer.runtimeIdentity))
|
|
4484
|
+
return "gone";
|
|
4485
|
+
const installed = {
|
|
4486
|
+
runtimeIdentity: answer.runtimeIdentity,
|
|
4487
|
+
permissionSupport: answer.permissionSupport,
|
|
4488
|
+
ownerCeiling: answer.ownerCeiling
|
|
4489
|
+
};
|
|
4490
|
+
if (!await store.installBinding(b.deviceId, b.generation, b.bindingId, installed, via))
|
|
4491
|
+
throw new InstanceBindingError(
|
|
4492
|
+
"The instance or the device's machine was replaced before its binding completed; retry"
|
|
4493
|
+
);
|
|
4494
|
+
const { unattested: _attestedAgain, ...kept } = b;
|
|
4495
|
+
return { ...kept, status: "installed", installed };
|
|
4496
|
+
};
|
|
4497
|
+
return {
|
|
4498
|
+
async bindNew(deviceId, signal) {
|
|
4499
|
+
signal.throwIfAborted();
|
|
4500
|
+
const current = await store.binding(deviceId);
|
|
4501
|
+
const previous = current?.generation ?? null;
|
|
4502
|
+
const binding = {
|
|
4503
|
+
deviceId,
|
|
4504
|
+
instanceId: deviceId,
|
|
4505
|
+
generation: nextGeneration(previous, now()),
|
|
4506
|
+
bindingId: randomUUID(),
|
|
4507
|
+
previousGeneration: previous,
|
|
4508
|
+
status: "awaiting-device"
|
|
4509
|
+
};
|
|
4510
|
+
if (!await store.commitBinding(binding, previous))
|
|
4511
|
+
throw new InstanceBindingError(
|
|
4512
|
+
"Another instance of this device was created at the same time; retry"
|
|
4513
|
+
);
|
|
4514
|
+
const bound = await send(binding, signal);
|
|
4515
|
+
if (bound === "gone") throw new InstanceBindingError("The new binding was not installed");
|
|
4516
|
+
return bound;
|
|
4517
|
+
},
|
|
4518
|
+
async rebind(deviceId, generation, signal) {
|
|
4519
|
+
signal.throwIfAborted();
|
|
4520
|
+
const binding = await store.binding(deviceId);
|
|
4521
|
+
if (binding?.generation !== generation) return "gone";
|
|
4522
|
+
try {
|
|
4523
|
+
return await send(binding, signal) === "gone" ? "gone" : "bound";
|
|
4524
|
+
} catch (e) {
|
|
4525
|
+
if (signal.aborted) throw e;
|
|
4526
|
+
if (isDeviceRequestNotSent(e) || isSandboxWorkUnsettledError(e)) throw e;
|
|
4527
|
+
if (isSandboxPermissionUnsupportedError(e) || isSandboxScopeDeniedError(e)) return "gone";
|
|
4528
|
+
throw e;
|
|
4529
|
+
}
|
|
4530
|
+
}
|
|
4531
|
+
};
|
|
4532
|
+
}
|
|
4533
|
+
|
|
4534
|
+
// src/provider.ts
|
|
4535
|
+
var FRAME_ENVELOPE_BYTES = 64 * 1024;
|
|
4536
|
+
var maxReadBytes = (maxFrameBytes) => Math.max(0, Math.floor((maxFrameBytes - FRAME_ENVELOPE_BYTES) / 4) * 3);
|
|
4537
|
+
async function frameCapacity(dialIn, deviceId) {
|
|
4538
|
+
let cap;
|
|
4539
|
+
try {
|
|
4540
|
+
cap = await dialIn.capacity(deviceId);
|
|
4541
|
+
} catch (e) {
|
|
4542
|
+
if (isDeviceOfflineError(e)) throw e;
|
|
4543
|
+
throw new DeviceOfflineError(deviceId, { cause: e });
|
|
4544
|
+
}
|
|
4545
|
+
if (cap === null) throw new DeviceOfflineError(deviceId);
|
|
4546
|
+
return cap.maxFrameBytes;
|
|
4547
|
+
}
|
|
4548
|
+
var OUTPUT_READ_BYTES = 65536;
|
|
4549
|
+
var NAME_PREFIX = "cap-device-";
|
|
4550
|
+
var deviceIdOfName = (name) => name.startsWith(NAME_PREFIX) && name.length > NAME_PREFIX.length ? name.slice(NAME_PREFIX.length) : void 0;
|
|
4551
|
+
function localHandle(h) {
|
|
4552
|
+
const l = h;
|
|
4553
|
+
return l.roots && l.limits && typeof l.generation === "string" ? h : void 0;
|
|
4554
|
+
}
|
|
4555
|
+
var sameRoots = (a, b) => a.workspace === b.workspace && a.skills === b.skills && a.tmp === b.tmp;
|
|
4556
|
+
var bytesOf = (b64) => new Uint8Array(Buffer.from(b64, "base64"));
|
|
4557
|
+
var b64Of = (data) => Buffer.from(data).toString("base64");
|
|
4558
|
+
var refuseRaw = (method) => async (..._args) => {
|
|
4559
|
+
throw new SandboxPermissionUnsupportedError2(
|
|
4560
|
+
`${method} without an operation scope is not available on a connected machine; run it through an admitted operation scope`
|
|
4561
|
+
);
|
|
4562
|
+
};
|
|
4563
|
+
var normalizeHost = (host) => {
|
|
4564
|
+
const h = host.toLowerCase();
|
|
4565
|
+
return h.endsWith(".") ? h.slice(0, -1) : h;
|
|
4566
|
+
};
|
|
4567
|
+
function relayer(blocked) {
|
|
4568
|
+
return blocked.map((b) => {
|
|
4569
|
+
if (b.layer !== "device") return b;
|
|
4570
|
+
const h = normalizeHost(b.host);
|
|
4571
|
+
return validateAllowHost(h).length > 0 || h.startsWith("*.") ? { ...b, layer: "address" } : b;
|
|
4572
|
+
});
|
|
4573
|
+
}
|
|
4574
|
+
function commandLimits(h, scope) {
|
|
4575
|
+
const { cpu, memoryMb, diskMb } = h.limits;
|
|
4576
|
+
const network = scope.network.kind === "open-public" ? { kind: "open-public", hosts: [] } : scope.network.kind === "allowlist" ? { kind: "allowlist", hosts: [...scope.network.hosts] } : scope.network.kind === "none" ? { kind: "allowlist", hosts: [] } : { kind: h.limits.network.kind, hosts: [...h.limits.network.hosts] };
|
|
4577
|
+
return { cpu, memoryMb, diskMb, network };
|
|
4578
|
+
}
|
|
4579
|
+
function requireLocal(h) {
|
|
4580
|
+
const l = localHandle(h);
|
|
4581
|
+
if (!l) throw new SandboxGoneError2("The instance handle is not a connected machine's instance");
|
|
4582
|
+
return l;
|
|
4583
|
+
}
|
|
4584
|
+
function createDeviceLocalProvider(ctx, store, opts = {}) {
|
|
4585
|
+
const call = machineCall(ctx.dialIn);
|
|
4586
|
+
const bindings = createInstanceBindings(call, store, opts.now);
|
|
4587
|
+
const machineCreate = async (deviceId, limits, signal) => (await call(deviceId, "create", { limits }, { deadlineMs: OP_DEADLINE_MS, signal })).roots;
|
|
4588
|
+
const endGenerationWork = async (h, signal, why) => {
|
|
4589
|
+
signal.throwIfAborted();
|
|
4590
|
+
const l = localHandle(h);
|
|
4591
|
+
if (!l) return;
|
|
4592
|
+
try {
|
|
4593
|
+
if ((await store.binding(l.id))?.generation !== l.generation) return;
|
|
4594
|
+
if (!await ctx.dialIn.online(l.id)) return;
|
|
4595
|
+
await machineCreate(l.id, l.limits, signal);
|
|
4596
|
+
} catch (e) {
|
|
4597
|
+
if (signal.aborted) throw e;
|
|
4598
|
+
if (!isDeviceOfflineError(e))
|
|
4599
|
+
ctx.log.warn(`could not end the device's work on its machine at ${why}`, {
|
|
4600
|
+
deviceId: l.id,
|
|
4601
|
+
error: e instanceof Error ? e.message : String(e)
|
|
4602
|
+
});
|
|
4603
|
+
}
|
|
4604
|
+
};
|
|
4605
|
+
const assertLive = async (h) => {
|
|
4606
|
+
const l = requireLocal(h);
|
|
4607
|
+
const b = await store.binding(l.id);
|
|
4608
|
+
if (!b || b.generation !== l.generation)
|
|
4609
|
+
throw new SandboxGoneError2("The device's machine no longer holds this instance generation");
|
|
4610
|
+
if (b.unattested)
|
|
4611
|
+
throw new SandboxGoneError2(
|
|
4612
|
+
"The machine restarted without this instance's binding (for example after an upgrade)"
|
|
4613
|
+
);
|
|
4614
|
+
return l;
|
|
4615
|
+
};
|
|
4616
|
+
const native = (h, scope, prefix, factorySignal) => {
|
|
4617
|
+
const send = (op, args, signal) => call(
|
|
4618
|
+
h.id,
|
|
4619
|
+
prefix ? prefix + op.charAt(0).toUpperCase() + op.slice(1) : op,
|
|
4620
|
+
{ scope, ...args },
|
|
4621
|
+
{ deadlineMs: OP_DEADLINE_MS, signal: AbortSignal.any([factorySignal, signal]) }
|
|
4622
|
+
);
|
|
4623
|
+
return {
|
|
4624
|
+
readFile: async (path, o) => {
|
|
4625
|
+
const cap = await frameCapacity(ctx.dialIn, h.id);
|
|
4626
|
+
const maxBytes = Math.min(o.maxBytes, maxReadBytes(cap));
|
|
4627
|
+
const r = await send("readFile", { path, maxBytes }, o.signal);
|
|
4628
|
+
return r === null ? null : { data: bytesOf(r.dataB64), truncated: r.truncated };
|
|
4629
|
+
},
|
|
4630
|
+
writeFile: async (path, data, signal) => {
|
|
4631
|
+
const cap = await frameCapacity(ctx.dialIn, h.id);
|
|
4632
|
+
if (data.byteLength > maxReadBytes(cap))
|
|
4633
|
+
throw new ToolError2(
|
|
4634
|
+
`The file is too large to send to the connected machine in one piece (${data.byteLength} bytes, at most ${maxReadBytes(cap)}); use smaller writes, or ask a platform admin to raise the dial-in frame limit`
|
|
4635
|
+
);
|
|
4636
|
+
await send("writeFile", { path, dataB64: b64Of(data) }, signal);
|
|
4637
|
+
},
|
|
4638
|
+
stat: async (path, signal) => await send("stat", { path }, signal),
|
|
4639
|
+
list: async (path, o) => await send("list", { path, limit: o.limit }, o.signal),
|
|
4640
|
+
scan: async (base, o) => await send("scan", { base }, o.signal)
|
|
4641
|
+
};
|
|
4642
|
+
};
|
|
4643
|
+
const background = {
|
|
4644
|
+
start: async (h, input, args) => {
|
|
4645
|
+
const scope = parseSandboxOperationScope(input);
|
|
4646
|
+
const l = await assertLive(h);
|
|
4647
|
+
const { signal, instanceGeneration: _generation, ...rest } = args;
|
|
4648
|
+
signal.throwIfAborted();
|
|
4649
|
+
return await call(
|
|
4650
|
+
h.id,
|
|
4651
|
+
"backgroundStart",
|
|
4652
|
+
{ scope, ...rest, limits: commandLimits(l, scope) },
|
|
4653
|
+
{ deadlineMs: args.timeoutMs + EXEC_DEADLINE_MARGIN_MS, signal }
|
|
4654
|
+
);
|
|
4655
|
+
},
|
|
4656
|
+
status: async (h, ref, signal) => await call(
|
|
4657
|
+
h.id,
|
|
4658
|
+
"backgroundStatus",
|
|
4659
|
+
{ ref },
|
|
4660
|
+
{ deadlineMs: OP_DEADLINE_MS, signal }
|
|
4661
|
+
),
|
|
4662
|
+
readOutput: async (h, ref, o) => {
|
|
4663
|
+
o.signal.throwIfAborted();
|
|
4664
|
+
const cap = await frameCapacity(ctx.dialIn, h.id);
|
|
4665
|
+
const maxBytes = Math.min(o.maxBytes, OUTPUT_READ_BYTES, maxReadBytes(cap));
|
|
4666
|
+
const r = await call(
|
|
4667
|
+
h.id,
|
|
4668
|
+
"backgroundReadOutput",
|
|
4669
|
+
{ ref, offset: o.offset, maxBytes },
|
|
4670
|
+
{ deadlineMs: OP_DEADLINE_MS, signal: o.signal }
|
|
4671
|
+
);
|
|
4672
|
+
if ("unavailable" in r) return r;
|
|
4673
|
+
return {
|
|
4674
|
+
data: bytesOf(r.dataB64),
|
|
4675
|
+
offset: r.offset,
|
|
4676
|
+
nextOffset: r.nextOffset,
|
|
4677
|
+
totalBytes: r.totalBytes
|
|
4678
|
+
};
|
|
4679
|
+
},
|
|
4680
|
+
tail: async (h, ref, o) => {
|
|
4681
|
+
const cap = await frameCapacity(ctx.dialIn, h.id);
|
|
4682
|
+
const r = await call(
|
|
4683
|
+
h.id,
|
|
4684
|
+
"backgroundTail",
|
|
4685
|
+
{ ref, maxBytes: Math.min(o.maxBytes, OUTPUT_READ_BYTES, maxReadBytes(cap)) },
|
|
4686
|
+
{ deadlineMs: OP_DEADLINE_MS, signal: o.signal }
|
|
4687
|
+
);
|
|
4688
|
+
return "unavailable" in r ? r : { data: bytesOf(r.dataB64), truncated: r.truncated };
|
|
4689
|
+
},
|
|
4690
|
+
stop: async (h, ref, o) => await call(
|
|
4691
|
+
h.id,
|
|
4692
|
+
"backgroundStop",
|
|
4693
|
+
{ ref, graceMs: o.graceMs },
|
|
4694
|
+
{ deadlineMs: OP_DEADLINE_MS, signal: o.signal }
|
|
4695
|
+
)
|
|
4696
|
+
};
|
|
4697
|
+
return {
|
|
4698
|
+
concurrentExec: true,
|
|
4699
|
+
networkAllowlist: true,
|
|
4700
|
+
sessionIsolation: false,
|
|
4701
|
+
operation: async (h, input, signal) => {
|
|
4702
|
+
const scope = parseSandboxOperationScope(input);
|
|
4703
|
+
await assertLive(h);
|
|
4704
|
+
const methods = native(h, scope, "", signal);
|
|
4705
|
+
return {
|
|
4706
|
+
...methods,
|
|
4707
|
+
exec: async (args) => {
|
|
4708
|
+
const l = requireLocal(h);
|
|
4709
|
+
const { signal: callSignal, ...rest } = args;
|
|
4710
|
+
const limits = commandLimits(l, scope);
|
|
4711
|
+
const combined = AbortSignal.any([signal, callSignal]);
|
|
4712
|
+
combined.throwIfAborted();
|
|
4713
|
+
const result = await call(
|
|
4714
|
+
h.id,
|
|
4715
|
+
"exec",
|
|
4716
|
+
{ scope, ...rest, limits },
|
|
4717
|
+
{ deadlineMs: args.timeoutMs + EXEC_DEADLINE_MARGIN_MS, signal: combined }
|
|
4718
|
+
);
|
|
4719
|
+
if (result.network?.blocked === void 0) return result;
|
|
4720
|
+
return { ...result, network: { blocked: relayer(result.network.blocked) } };
|
|
4721
|
+
}
|
|
4722
|
+
};
|
|
4723
|
+
},
|
|
4724
|
+
prepare: async (h, input, signal) => {
|
|
4725
|
+
const scope = parseSandboxPreparationScope(input);
|
|
4726
|
+
await assertLive(h);
|
|
4727
|
+
const n = native(h, scope, "prepare", signal);
|
|
4728
|
+
return {
|
|
4729
|
+
readFile: n.readFile,
|
|
4730
|
+
writeFile: n.writeFile,
|
|
4731
|
+
stat: n.stat
|
|
4732
|
+
};
|
|
4733
|
+
},
|
|
4734
|
+
browse: async (h, input, signal) => {
|
|
4735
|
+
const scope = parseSandboxBrowseScope(input);
|
|
4736
|
+
await assertLive(h);
|
|
4737
|
+
const n = native(h, scope, "browse", signal);
|
|
4738
|
+
return { stat: n.stat, list: n.list, scan: n.scan };
|
|
4739
|
+
},
|
|
4740
|
+
revokeOperation: async (h, ref, signal) => {
|
|
4741
|
+
await call(h.id, "revokeOperation", { ref }, { deadlineMs: OP_DEADLINE_MS, signal });
|
|
4742
|
+
},
|
|
4743
|
+
background,
|
|
4744
|
+
async createFileSystem(args) {
|
|
4745
|
+
args.signal.throwIfAborted();
|
|
4746
|
+
const id = deviceIdOfName(args.name);
|
|
4747
|
+
if (id === void 0) throw new Error(`not a device name: ${args.name}`);
|
|
4748
|
+
return { id };
|
|
4749
|
+
},
|
|
4750
|
+
/**
|
|
4751
|
+
* The device is deleted: its rows go (connection and binding). The files are the machine
|
|
4752
|
+
* owner's: nothing is sent to the machine (never a machine stop).
|
|
4753
|
+
*/
|
|
4754
|
+
async destroyFileSystem(fs, signal) {
|
|
4755
|
+
signal.throwIfAborted();
|
|
4756
|
+
await store.forget(fs.id);
|
|
4757
|
+
},
|
|
4758
|
+
async destroyFileSystemByName(_name, signal) {
|
|
4759
|
+
signal.throwIfAborted();
|
|
4760
|
+
},
|
|
4761
|
+
/**
|
|
4762
|
+
* Asks the machine for a new instance (it ends the older generation's background work), then
|
|
4763
|
+
* commits and binds the next generation before the handle is handed out.
|
|
4764
|
+
*/
|
|
4765
|
+
async create(args) {
|
|
4766
|
+
const id = args.fileSystem.id;
|
|
4767
|
+
if (deviceIdOfName(args.name) !== id)
|
|
4768
|
+
throw new Error(`instance ${args.name} does not belong to file system ${id}`);
|
|
4769
|
+
const roots = await machineCreate(id, args.limits, args.signal);
|
|
4770
|
+
const binding = await bindings.bindNew(id, args.signal);
|
|
4771
|
+
return { id, roots, limits: args.limits, generation: binding.generation };
|
|
4772
|
+
},
|
|
4773
|
+
/**
|
|
4774
|
+
* Needs the machine online. Ends any background work a suspension could not reach (the machine
|
|
4775
|
+
* was offline then), then re-verifies the generation's binding. `gone` (the kernel recreates the
|
|
4776
|
+
* instance) when the handle is not this provider's, the device directory's roots changed (a
|
|
4777
|
+
* new login into another directory or mode), or the generation can never be bound again.
|
|
4778
|
+
*/
|
|
4779
|
+
async resume(h, signal) {
|
|
4780
|
+
signal.throwIfAborted();
|
|
4781
|
+
const l = localHandle(h);
|
|
4782
|
+
if (!l) return "gone";
|
|
4783
|
+
if (!await ctx.dialIn.online(l.id)) throw new DeviceOfflineError(l.id);
|
|
4784
|
+
const current = await store.binding(l.id);
|
|
4785
|
+
if (current?.generation !== l.generation) return "gone";
|
|
4786
|
+
const roots = await machineCreate(l.id, l.limits, signal);
|
|
4787
|
+
if (!sameRoots(roots, l.roots)) return "gone";
|
|
4788
|
+
return await bindings.rebind(l.id, l.generation, signal) === "bound" ? "resumed" : "gone";
|
|
4789
|
+
},
|
|
4790
|
+
async suspend(h, signal) {
|
|
4791
|
+
await endGenerationWork(h, signal, "suspend");
|
|
4792
|
+
},
|
|
4793
|
+
async destroy(h, signal) {
|
|
4794
|
+
await endGenerationWork(h, signal, "destroy");
|
|
4795
|
+
},
|
|
4796
|
+
/**
|
|
4797
|
+
* No handle, so no limits to send with the machine's `create`: nothing to do. The next
|
|
4798
|
+
* `create` ends the older generation's work before it binds a new one.
|
|
4799
|
+
*/
|
|
4800
|
+
async destroyByName(_name, signal) {
|
|
4801
|
+
signal.throwIfAborted();
|
|
4802
|
+
},
|
|
4803
|
+
/** A protocol 5 machine has no broad kill: the kernel revokes exact operations instead. */
|
|
4804
|
+
async killAll(_h, signal) {
|
|
4805
|
+
signal.throwIfAborted();
|
|
4806
|
+
},
|
|
4807
|
+
async killTagged(_h, _tags, signal) {
|
|
4808
|
+
signal.throwIfAborted();
|
|
4809
|
+
},
|
|
4810
|
+
exec: refuseRaw("exec"),
|
|
4811
|
+
readFile: refuseRaw("readFile"),
|
|
4812
|
+
writeFile: refuseRaw("writeFile"),
|
|
4813
|
+
stat: refuseRaw("stat"),
|
|
4814
|
+
list: refuseRaw("list"),
|
|
4815
|
+
scan: refuseRaw("scan")
|
|
4816
|
+
};
|
|
4817
|
+
}
|
|
4818
|
+
|
|
4819
|
+
// src/index.ts
|
|
4820
|
+
var plugin = defineExtension({
|
|
4821
|
+
name: "device-local",
|
|
4822
|
+
version: "0.1.0-rc.1",
|
|
4823
|
+
// ctx.dialIn.capacity and the handlers' connection argument are the rc.56 SDK's
|
|
4824
|
+
sdk: "^0.1.0-rc.56",
|
|
4825
|
+
provides: [DEVICE_PROVIDER_EXTENSION_POINT],
|
|
4826
|
+
permissions: { dialIn: { protocol: DEVICE_DIAL_IN_PROTOCOL } },
|
|
4827
|
+
migrations: "../migrations",
|
|
4828
|
+
setup(ctx) {
|
|
4829
|
+
const store = storeOver(pgRows(ctx.db));
|
|
4830
|
+
const provider = {
|
|
4831
|
+
...createDeviceLocalProvider(ctx, store),
|
|
4832
|
+
/** From the stored rows only; the org is learned here (a hello names none). */
|
|
4833
|
+
async report(device, signal) {
|
|
4834
|
+
signal.throwIfAborted();
|
|
4835
|
+
return reportFor(store, device);
|
|
4836
|
+
},
|
|
4837
|
+
/** From the stored rows only, never a machine round trip. */
|
|
4838
|
+
async permissionSupport(h, signal) {
|
|
4839
|
+
signal.throwIfAborted();
|
|
4840
|
+
return supportFor(store, h);
|
|
4841
|
+
},
|
|
4842
|
+
dialIn: createDialInHandler(ctx, store)
|
|
4843
|
+
};
|
|
4844
|
+
ctx.provide(DEVICE_PROVIDER_EXTENSION_POINT, provider);
|
|
4845
|
+
}
|
|
4846
|
+
});
|
|
4847
|
+
var index_default = plugin;
|
|
4848
|
+
export {
|
|
4849
|
+
EXEC_DEADLINE_MARGIN_MS,
|
|
4850
|
+
FRAME_ENVELOPE_BYTES,
|
|
4851
|
+
InstanceBindingError,
|
|
4852
|
+
ON_MACHINE_PREFIX,
|
|
4853
|
+
OP_DEADLINE_MS,
|
|
4854
|
+
POLICY_REFUSAL_PREFIX,
|
|
4855
|
+
applyOwnerReport,
|
|
4856
|
+
closedSupport,
|
|
4857
|
+
commandLimits,
|
|
4858
|
+
createDeviceLocalProvider,
|
|
4859
|
+
createDialInHandler,
|
|
4860
|
+
createInstanceBindings,
|
|
4861
|
+
decideHello,
|
|
4862
|
+
decideOwnerReport,
|
|
4863
|
+
index_default as default,
|
|
4864
|
+
deviceIdOfName,
|
|
4865
|
+
deviceReportOf,
|
|
4866
|
+
failureOf,
|
|
4867
|
+
frameCapacity,
|
|
4868
|
+
machineCall,
|
|
4869
|
+
maxReadBytes,
|
|
4870
|
+
nextGeneration,
|
|
4871
|
+
ownerFactsOf,
|
|
4872
|
+
pgRows,
|
|
4873
|
+
relayer,
|
|
4874
|
+
reportFor,
|
|
4875
|
+
revisionOf,
|
|
4876
|
+
storeOver,
|
|
4877
|
+
storedOwnerReportOf,
|
|
4878
|
+
supportFor,
|
|
4879
|
+
supportOf,
|
|
4880
|
+
viaOf
|
|
4881
|
+
};
|