exoagent 0.0.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.
@@ -0,0 +1,26 @@
1
+ import { h as u, s as ur, t as C } from "./chunk-VBDAOXYI-BhoIkhUn.mjs";
2
+ import * as s from "fs";
3
+ import * as o from "path";
4
+
5
+ //#region node_modules/@electric-sql/pglite/dist/fs/nodefs.js
6
+ u();
7
+ var m = class extends ur {
8
+ constructor(t) {
9
+ super(t), this.rootDir = o.resolve(t), s.existsSync(o.join(this.rootDir)) || s.mkdirSync(this.rootDir);
10
+ }
11
+ async init(t, e) {
12
+ return this.pg = t, { emscriptenOpts: {
13
+ ...e,
14
+ preRun: [...e.preRun || [], (r) => {
15
+ let c = r.FS.filesystems.NODEFS;
16
+ r.FS.mkdir(C), r.FS.mount(c, { root: this.rootDir }, C);
17
+ }]
18
+ } };
19
+ }
20
+ async closeFs() {
21
+ this.pg.Module.FS.quit();
22
+ }
23
+ };
24
+
25
+ //#endregion
26
+ export { m as NodeFS };
@@ -0,0 +1,367 @@
1
+ import { d as R, f as T, g as x, h as u, i as cr, m as h, o as pr, p as U } from "./chunk-VBDAOXYI-BhoIkhUn.mjs";
2
+
3
+ //#region node_modules/@electric-sql/pglite/dist/fs/opfs-ahp.js
4
+ u();
5
+ var $ = "state.txt", G = "data", T$1 = {
6
+ DIR: 16384,
7
+ FILE: 32768
8
+ }, H, v, F, M, y, b, m, x$1, P, D, S, n, C, O, k, w, f, I, W, j, L = class extends cr {
9
+ constructor(e, { initialPoolSize: t = 1e3, maintainedPoolSize: o = 100, debug: i = !1 } = {}) {
10
+ super(e, { debug: i });
11
+ R(this, n);
12
+ R(this, H);
13
+ R(this, v);
14
+ R(this, F);
15
+ R(this, M);
16
+ R(this, y);
17
+ R(this, b, /* @__PURE__ */ new Map());
18
+ R(this, m, /* @__PURE__ */ new Map());
19
+ R(this, x$1, 0);
20
+ R(this, P, /* @__PURE__ */ new Map());
21
+ R(this, D, /* @__PURE__ */ new Map());
22
+ this.lastCheckpoint = 0;
23
+ this.checkpointInterval = 1e3 * 60;
24
+ this.poolCounter = 0;
25
+ R(this, S, /* @__PURE__ */ new Set());
26
+ this.initialPoolSize = t, this.maintainedPoolSize = o;
27
+ }
28
+ async init(e, t) {
29
+ return await T(this, n, C).call(this), super.init(e, t);
30
+ }
31
+ async syncToFs(e = !1) {
32
+ await this.maybeCheckpointState(), await this.maintainPool(), e || this.flush();
33
+ }
34
+ async closeFs() {
35
+ for (let e of h(this, m).values()) e.close();
36
+ h(this, y).flush(), h(this, y).close(), this.pg.Module.FS.quit();
37
+ }
38
+ async maintainPool(e) {
39
+ e = e || this.maintainedPoolSize;
40
+ let t = e - this.state.pool.length, o = [];
41
+ for (let i = 0; i < t; i++) o.push(new Promise(async (c) => {
42
+ ++this.poolCounter;
43
+ let a = `${(Date.now() - 1704063600).toString(16).padStart(8, "0")}-${this.poolCounter.toString(16).padStart(8, "0")}`, h$1 = await h(this, F).getFileHandle(a, { create: !0 }), d = await h$1.createSyncAccessHandle();
44
+ h(this, b).set(a, h$1), h(this, m).set(a, d), T(this, n, k).call(this, {
45
+ opp: "createPoolFile",
46
+ args: [a]
47
+ }), this.state.pool.push(a), c();
48
+ }));
49
+ for (let i = 0; i > t; i--) o.push(new Promise(async (c) => {
50
+ let a = this.state.pool.pop();
51
+ T(this, n, k).call(this, {
52
+ opp: "deletePoolFile",
53
+ args: [a]
54
+ });
55
+ let h$1 = h(this, b).get(a);
56
+ h(this, m).get(a)?.close(), await h(this, F).removeEntry(h$1.name), h(this, b).delete(a), h(this, m).delete(a), c();
57
+ }));
58
+ await Promise.all(o);
59
+ }
60
+ _createPoolFileState(e) {
61
+ this.state.pool.push(e);
62
+ }
63
+ _deletePoolFileState(e) {
64
+ let t = this.state.pool.indexOf(e);
65
+ t > -1 && this.state.pool.splice(t, 1);
66
+ }
67
+ async maybeCheckpointState() {
68
+ Date.now() - this.lastCheckpoint > this.checkpointInterval && await this.checkpointState();
69
+ }
70
+ async checkpointState() {
71
+ let e = new TextEncoder().encode(JSON.stringify(this.state));
72
+ h(this, y).truncate(0), h(this, y).write(e, { at: 0 }), h(this, y).flush(), this.lastCheckpoint = Date.now();
73
+ }
74
+ flush() {
75
+ for (let e of h(this, S)) try {
76
+ e.flush();
77
+ } catch {}
78
+ h(this, S).clear();
79
+ }
80
+ chmod(e, t) {
81
+ T(this, n, O).call(this, {
82
+ opp: "chmod",
83
+ args: [e, t]
84
+ }, () => {
85
+ this._chmodState(e, t);
86
+ });
87
+ }
88
+ _chmodState(e, t) {
89
+ let o = T(this, n, f).call(this, e);
90
+ o.mode = t;
91
+ }
92
+ close(e) {
93
+ let t = T(this, n, I).call(this, e);
94
+ h(this, P).delete(e), h(this, D).delete(t);
95
+ }
96
+ fstat(e) {
97
+ let t = T(this, n, I).call(this, e);
98
+ return this.lstat(t);
99
+ }
100
+ lstat(e) {
101
+ let t = T(this, n, f).call(this, e), o = t.type === "file" ? h(this, m).get(t.backingFilename).getSize() : 0, i = 4096;
102
+ return {
103
+ dev: 0,
104
+ ino: 0,
105
+ mode: t.mode,
106
+ nlink: 1,
107
+ uid: 0,
108
+ gid: 0,
109
+ rdev: 0,
110
+ size: o,
111
+ blksize: i,
112
+ blocks: Math.ceil(o / i),
113
+ atime: t.lastModified,
114
+ mtime: t.lastModified,
115
+ ctime: t.lastModified
116
+ };
117
+ }
118
+ mkdir(e, t) {
119
+ T(this, n, O).call(this, {
120
+ opp: "mkdir",
121
+ args: [e, t]
122
+ }, () => {
123
+ this._mkdirState(e, t);
124
+ });
125
+ }
126
+ _mkdirState(e, t) {
127
+ let o = T(this, n, w).call(this, e), i = o.pop(), c = [], a = this.state.root;
128
+ for (let d of o) {
129
+ if (c.push(e), !Object.prototype.hasOwnProperty.call(a.children, d)) if (t?.recursive) this.mkdir(c.join("/"));
130
+ else throw new p("ENOENT", "No such file or directory");
131
+ if (a.children[d].type !== "directory") throw new p("ENOTDIR", "Not a directory");
132
+ a = a.children[d];
133
+ }
134
+ if (Object.prototype.hasOwnProperty.call(a.children, i)) throw new p("EEXIST", "File exists");
135
+ let h$1 = {
136
+ type: "directory",
137
+ lastModified: Date.now(),
138
+ mode: t?.mode || T$1.DIR,
139
+ children: {}
140
+ };
141
+ a.children[i] = h$1;
142
+ }
143
+ open(e, t, o) {
144
+ if (T(this, n, f).call(this, e).type !== "file") throw new p("EISDIR", "Is a directory");
145
+ let c = T(this, n, W).call(this);
146
+ return h(this, P).set(c, e), h(this, D).set(e, c), c;
147
+ }
148
+ readdir(e) {
149
+ let t = T(this, n, f).call(this, e);
150
+ if (t.type !== "directory") throw new p("ENOTDIR", "Not a directory");
151
+ return Object.keys(t.children);
152
+ }
153
+ read(e, t, o, i, c) {
154
+ let a = T(this, n, I).call(this, e), h$1 = T(this, n, f).call(this, a);
155
+ if (h$1.type !== "file") throw new p("EISDIR", "Is a directory");
156
+ return h(this, m).get(h$1.backingFilename).read(new Uint8Array(t.buffer, o, i), { at: c });
157
+ }
158
+ rename(e, t) {
159
+ T(this, n, O).call(this, {
160
+ opp: "rename",
161
+ args: [e, t]
162
+ }, () => {
163
+ this._renameState(e, t, !0);
164
+ });
165
+ }
166
+ _renameState(e, t, o = !1) {
167
+ let i = T(this, n, w).call(this, e), c = i.pop(), a = T(this, n, f).call(this, i.join("/"));
168
+ if (!Object.prototype.hasOwnProperty.call(a.children, c)) throw new p("ENOENT", "No such file or directory");
169
+ let h$1 = T(this, n, w).call(this, t), d = h$1.pop(), l = T(this, n, f).call(this, h$1.join("/"));
170
+ if (o && Object.prototype.hasOwnProperty.call(l.children, d)) {
171
+ let u$1 = l.children[d];
172
+ h(this, m).get(u$1.backingFilename).truncate(0), this.state.pool.push(u$1.backingFilename);
173
+ }
174
+ l.children[d] = a.children[c], delete a.children[c];
175
+ }
176
+ rmdir(e) {
177
+ T(this, n, O).call(this, {
178
+ opp: "rmdir",
179
+ args: [e]
180
+ }, () => {
181
+ this._rmdirState(e);
182
+ });
183
+ }
184
+ _rmdirState(e) {
185
+ let t = T(this, n, w).call(this, e), o = t.pop(), i = T(this, n, f).call(this, t.join("/"));
186
+ if (!Object.prototype.hasOwnProperty.call(i.children, o)) throw new p("ENOENT", "No such file or directory");
187
+ let c = i.children[o];
188
+ if (c.type !== "directory") throw new p("ENOTDIR", "Not a directory");
189
+ if (Object.keys(c.children).length > 0) throw new p("ENOTEMPTY", "Directory not empty");
190
+ delete i.children[o];
191
+ }
192
+ truncate(e, t = 0) {
193
+ let o = T(this, n, f).call(this, e);
194
+ if (o.type !== "file") throw new p("EISDIR", "Is a directory");
195
+ let i = h(this, m).get(o.backingFilename);
196
+ if (!i) throw new p("ENOENT", "No such file or directory");
197
+ i.truncate(t), h(this, S).add(i);
198
+ }
199
+ unlink(e) {
200
+ T(this, n, O).call(this, {
201
+ opp: "unlink",
202
+ args: [e]
203
+ }, () => {
204
+ this._unlinkState(e, !0);
205
+ });
206
+ }
207
+ _unlinkState(e, t = !1) {
208
+ let o = T(this, n, w).call(this, e), i = o.pop(), c = T(this, n, f).call(this, o.join("/"));
209
+ if (!Object.prototype.hasOwnProperty.call(c.children, i)) throw new p("ENOENT", "No such file or directory");
210
+ let a = c.children[i];
211
+ if (a.type !== "file") throw new p("EISDIR", "Is a directory");
212
+ if (delete c.children[i], t) {
213
+ let h$1 = h(this, m).get(a.backingFilename);
214
+ h$1?.truncate(0), h(this, S).add(h$1), h(this, D).has(e) && (h(this, P).delete(h(this, D).get(e)), h(this, D).delete(e));
215
+ }
216
+ this.state.pool.push(a.backingFilename);
217
+ }
218
+ utimes(e, t, o) {
219
+ T(this, n, O).call(this, {
220
+ opp: "utimes",
221
+ args: [
222
+ e,
223
+ t,
224
+ o
225
+ ]
226
+ }, () => {
227
+ this._utimesState(e, t, o);
228
+ });
229
+ }
230
+ _utimesState(e, t, o) {
231
+ let i = T(this, n, f).call(this, e);
232
+ i.lastModified = o;
233
+ }
234
+ writeFile(e, t, o) {
235
+ let i = T(this, n, w).call(this, e), c = i.pop(), a = T(this, n, f).call(this, i.join("/"));
236
+ if (Object.prototype.hasOwnProperty.call(a.children, c)) {
237
+ let l = a.children[c];
238
+ l.lastModified = Date.now(), T(this, n, k).call(this, {
239
+ opp: "setLastModified",
240
+ args: [e, l.lastModified]
241
+ });
242
+ } else {
243
+ if (this.state.pool.length === 0) throw new Error("No more file handles available in the pool");
244
+ let l = {
245
+ type: "file",
246
+ lastModified: Date.now(),
247
+ mode: o?.mode || T$1.FILE,
248
+ backingFilename: this.state.pool.pop()
249
+ };
250
+ a.children[c] = l, T(this, n, k).call(this, {
251
+ opp: "createFileNode",
252
+ args: [e, l]
253
+ });
254
+ }
255
+ let h$1 = a.children[c], d = h(this, m).get(h$1.backingFilename);
256
+ t.length > 0 && (d.write(typeof t == "string" ? new TextEncoder().encode(t) : new Uint8Array(t), { at: 0 }), e.startsWith("/pg_wal") && h(this, S).add(d));
257
+ }
258
+ _createFileNodeState(e, t) {
259
+ let o = T(this, n, w).call(this, e), i = o.pop(), c = T(this, n, f).call(this, o.join("/"));
260
+ c.children[i] = t;
261
+ let a = this.state.pool.indexOf(t.backingFilename);
262
+ return a > -1 && this.state.pool.splice(a, 1), t;
263
+ }
264
+ _setLastModifiedState(e, t) {
265
+ let o = T(this, n, f).call(this, e);
266
+ o.lastModified = t;
267
+ }
268
+ write(e, t, o, i, c) {
269
+ let a = T(this, n, I).call(this, e), h$1 = T(this, n, f).call(this, a);
270
+ if (h$1.type !== "file") throw new p("EISDIR", "Is a directory");
271
+ let d = h(this, m).get(h$1.backingFilename);
272
+ if (!d) throw new p("EBADF", "Bad file descriptor");
273
+ let l = d.write(new Uint8Array(t, o, i), { at: c });
274
+ return a.startsWith("/pg_wal") && h(this, S).add(d), l;
275
+ }
276
+ };
277
+ H = /* @__PURE__ */ new WeakMap(), v = /* @__PURE__ */ new WeakMap(), F = /* @__PURE__ */ new WeakMap(), M = /* @__PURE__ */ new WeakMap(), y = /* @__PURE__ */ new WeakMap(), b = /* @__PURE__ */ new WeakMap(), m = /* @__PURE__ */ new WeakMap(), x$1 = /* @__PURE__ */ new WeakMap(), P = /* @__PURE__ */ new WeakMap(), D = /* @__PURE__ */ new WeakMap(), S = /* @__PURE__ */ new WeakMap(), n = /* @__PURE__ */ new WeakSet(), C = async function() {
278
+ x(this, H, await navigator.storage.getDirectory()), x(this, v, await T(this, n, j).call(this, this.dataDir, { create: !0 })), x(this, F, await T(this, n, j).call(this, G, {
279
+ from: h(this, v),
280
+ create: !0
281
+ })), x(this, M, await h(this, v).getFileHandle($, { create: !0 })), x(this, y, await h(this, M).createSyncAccessHandle());
282
+ let e = new ArrayBuffer(h(this, y).getSize());
283
+ h(this, y).read(e, { at: 0 });
284
+ let t, o = new TextDecoder().decode(e).split(`
285
+ `), i = !1;
286
+ try {
287
+ t = JSON.parse(o[0]);
288
+ } catch {
289
+ t = {
290
+ root: {
291
+ type: "directory",
292
+ lastModified: Date.now(),
293
+ mode: T$1.DIR,
294
+ children: {}
295
+ },
296
+ pool: []
297
+ }, h(this, y).truncate(0), h(this, y).write(new TextEncoder().encode(JSON.stringify(t)), { at: 0 }), i = !0;
298
+ }
299
+ this.state = t;
300
+ let c = o.slice(1).filter(Boolean).map((l) => JSON.parse(l));
301
+ for (let l of c) {
302
+ let u$1 = `_${l.opp}State`;
303
+ if (typeof this[u$1] == "function") try {
304
+ this[u$1].bind(this)(...l.args);
305
+ } catch (N) {
306
+ console.warn("Error applying OPFS AHP WAL entry", l, N);
307
+ }
308
+ }
309
+ let a = [], h$1 = async (l) => {
310
+ if (l.type === "file") try {
311
+ let u$1 = await h(this, F).getFileHandle(l.backingFilename), N = await u$1.createSyncAccessHandle();
312
+ h(this, b).set(l.backingFilename, u$1), h(this, m).set(l.backingFilename, N);
313
+ } catch (u$1) {
314
+ console.error("Error opening file handle for node", l, u$1);
315
+ }
316
+ else for (let u$1 of Object.values(l.children)) a.push(h$1(u$1));
317
+ };
318
+ await h$1(this.state.root);
319
+ let d = [];
320
+ for (let l of this.state.pool) d.push(new Promise(async (u$1) => {
321
+ h(this, b).has(l) && console.warn("File handle already exists for pool file", l);
322
+ let N = await h(this, F).getFileHandle(l), U$1 = await N.createSyncAccessHandle();
323
+ h(this, b).set(l, N), h(this, m).set(l, U$1), u$1();
324
+ }));
325
+ await Promise.all([...a, ...d]), await this.maintainPool(i ? this.initialPoolSize : this.maintainedPoolSize);
326
+ }, O = function(e, t) {
327
+ let o = T(this, n, k).call(this, e);
328
+ try {
329
+ t();
330
+ } catch (i) {
331
+ throw h(this, y).truncate(o), i;
332
+ }
333
+ }, k = function(e) {
334
+ let t = JSON.stringify(e), o = new TextEncoder().encode(`
335
+ ${t}`), i = h(this, y).getSize();
336
+ return h(this, y).write(o, { at: i }), h(this, S).add(h(this, y)), i;
337
+ }, w = function(e) {
338
+ return e.split("/").filter(Boolean);
339
+ }, f = function(e, t) {
340
+ let o = T(this, n, w).call(this, e), i = t || this.state.root;
341
+ for (let c of o) {
342
+ if (i.type !== "directory") throw new p("ENOTDIR", "Not a directory");
343
+ if (!Object.prototype.hasOwnProperty.call(i.children, c)) throw new p("ENOENT", "No such file or directory");
344
+ i = i.children[c];
345
+ }
346
+ return i;
347
+ }, I = function(e) {
348
+ let t = h(this, P).get(e);
349
+ if (!t) throw new p("EBADF", "Bad file descriptor");
350
+ return t;
351
+ }, W = function() {
352
+ let e = ++U(this, x$1)._;
353
+ for (; h(this, P).has(e);) U(this, x$1)._++;
354
+ return e;
355
+ }, j = async function(e, t) {
356
+ let o = T(this, n, w).call(this, e), i = t?.from || h(this, H);
357
+ for (let c of o) i = await i.getDirectoryHandle(c, { create: t?.create });
358
+ return i;
359
+ };
360
+ var p = class extends Error {
361
+ constructor(A, e) {
362
+ super(e), typeof A == "number" ? this.code = A : typeof A == "string" && (this.code = pr[A]);
363
+ }
364
+ };
365
+
366
+ //#endregion
367
+ export { L as OpfsAhpFS };
@@ -0,0 +1,245 @@
1
+ import * as kysely0 from "kysely";
2
+ import { CompiledQuery, Dialect, RawBuilder } from "kysely";
3
+
4
+ //#region packages/capnweb/dist/index.d.ts
5
+
6
+ declare const __RPC_TARGET_BRAND: '__RPC_TARGET_BRAND';
7
+ interface RpcTargetBranded {
8
+ [__RPC_TARGET_BRAND]: never;
9
+ }
10
+
11
+ // Types that can be used through `Stub`s
12
+
13
+ /**
14
+ * Classes which are intended to be passed by reference and called over RPC must extend
15
+ * `RpcTarget`. A class which does not extend `RpcTarget` (and which doesn't have built-in support
16
+ * from the RPC system) cannot be passed in an RPC message at all; an exception will be thrown.
17
+ *
18
+ * Note that on Cloudflare Workers, this `RpcTarget` is an alias for the one exported from the
19
+ * "cloudflare:workers" module, so they can be used interchangably.
20
+ */
21
+ interface RpcTarget extends RpcTargetBranded {}
22
+ declare const RpcTarget: {
23
+ new (): RpcTarget;
24
+ };
25
+ /**
26
+ * Empty interface used as default type parameter for sessions where the other side doesn't
27
+ * necessarily export a main interface.
28
+ */
29
+ //#endregion
30
+ //#region src/rpc-toolset.d.ts
31
+
32
+ declare const callbackMetadataKey: unique symbol;
33
+ type ToolCallback<T extends (arg: any) => unknown> = T | {
34
+ [callbackMetadataKey]: {
35
+ callback: T;
36
+ };
37
+ };
38
+ declare class RpcToolset extends RpcTarget {
39
+ constructor();
40
+ }
41
+ //#endregion
42
+ //#region src/sql/sql.d.ts
43
+ type RawSql = RawBuilder<unknown>;
44
+ //#endregion
45
+ //#region src/sql/expression.d.ts
46
+ type LiteralValue = number | string | boolean | null;
47
+ type SqlExpressionIn = LiteralValue | SqlExpression;
48
+ declare class SqlExpression extends RpcToolset {
49
+ precedence: number;
50
+ constructor(precedence?: number);
51
+ compile: () => RawSql;
52
+ or(expr: SqlExpression): BinaryExpression;
53
+ and(expr: SqlExpression): BinaryExpression;
54
+ not(): UnaryExpression;
55
+ isNull(): UnaryExpression;
56
+ isNotNull(): UnaryExpression;
57
+ '<'(expr: SqlExpression | number | string): BinaryExpression;
58
+ '<='(expr: SqlExpression | number | string): BinaryExpression;
59
+ '>'(expr: SqlExpression | number | string): BinaryExpression;
60
+ '>='(expr: SqlExpression | number | string): BinaryExpression;
61
+ '='(expr: SqlExpressionIn): BinaryExpression;
62
+ '<>'(expr: SqlExpressionIn): BinaryExpression;
63
+ '!='(expr: SqlExpressionIn): BinaryExpression;
64
+ 'LIKE'(expr: SqlExpression | string): BinaryExpression;
65
+ 'NOT LIKE'(expr: SqlExpression | string): BinaryExpression;
66
+ '+'(expr: SqlExpression | number | string): BinaryExpression;
67
+ '-'(expr: SqlExpression | number | string): BinaryExpression;
68
+ '*'(expr: SqlExpression | number | string): BinaryExpression;
69
+ '/'(expr: SqlExpression | number | string): BinaryExpression;
70
+ '%'(expr: SqlExpression | number | string): BinaryExpression;
71
+ asc(): OrderByValue;
72
+ desc(): OrderByValue;
73
+ }
74
+ declare class BinaryExpression extends SqlExpression {
75
+ private readonly left;
76
+ private readonly right;
77
+ private readonly operator;
78
+ constructor(left: SqlExpression, right: SqlExpression, operator: RawSql, precedence?: number);
79
+ compile: () => kysely0.RawBuilder<unknown>;
80
+ }
81
+ declare class UnaryExpression extends SqlExpression {
82
+ private readonly operand;
83
+ private readonly operator;
84
+ private readonly placement;
85
+ constructor(operand: SqlExpression, operator: RawSql, placement: 'prefix' | 'postfix', precedence?: number);
86
+ compile: () => kysely0.RawBuilder<unknown>;
87
+ }
88
+ declare class ColumnReferenceExpression extends SqlExpression {
89
+ readonly alias: string;
90
+ readonly column: string;
91
+ constructor(alias: string, column: string);
92
+ compile: () => kysely0.RawBuilder<unknown>;
93
+ }
94
+ declare class OrderByValue {
95
+ value: SqlExpression;
96
+ direction?: RawSql | undefined;
97
+ constructor(value: SqlExpression, direction?: RawSql | undefined);
98
+ }
99
+ //#endregion
100
+ //#region src/sql/builder.d.ts
101
+ type RowLikeRaw = {
102
+ [key: string]: SqlExpression;
103
+ };
104
+ type RowLikeRawIn = {
105
+ [key: string]: SqlExpressionIn;
106
+ };
107
+ type RowLike = RowLikeRaw | TableBase;
108
+ type RowLikeIn = RowLikeRawIn | RowLike;
109
+ type AsRowLike<R$1 extends RowLikeIn> = R$1 extends TableBase ? R$1 : { [key in keyof R$1]: R$1[key] extends SqlExpression ? R$1[key] : SqlExpression };
110
+ type NamespacedExpression<A, R$1> = (arg: A) => R$1;
111
+ type FromItem<N extends string, F extends RowLike> = {
112
+ alias: N;
113
+ toRowLike: () => F;
114
+ compile: (opts?: {
115
+ isSubquery?: boolean;
116
+ }) => RawSql;
117
+ onExpression?: SqlExpression;
118
+ };
119
+ type TableNamespace = {
120
+ [key: string]: RowLike;
121
+ };
122
+ type OrderByItem<TN extends TableNamespace> = NamespacedExpression<TN, SqlExpression | SqlExpression[] | OrderByValue | OrderByValue[] | (SqlExpression | OrderByValue)[]>;
123
+ type Tables<TN extends TableNamespace> = { [k in keyof TN & string]: {
124
+ fromItem: FromItem<k, TN[k]>;
125
+ joinType: 'inner' | 'left' | null;
126
+ on?: SqlExpression;
127
+ isLateral: boolean;
128
+ } };
129
+ type QueryBuilderParams<N extends string, TN extends TableNamespace, S extends RowLike> = {
130
+ db: Database;
131
+ alias: N;
132
+ tables: Tables<TN>;
133
+ selectRowLike: S;
134
+ whereExpression?: SqlExpression;
135
+ orderByExpressions?: OrderByValue[];
136
+ limit?: number;
137
+ offset?: number;
138
+ rawTable: TableClass<N> | undefined;
139
+ };
140
+ declare class QueryBuilder<N extends string, TN extends TableNamespace, S extends RowLike> extends RpcToolset implements FromItem<N, S> {
141
+ #private;
142
+ readonly alias: N;
143
+ private selectRowLike;
144
+ private tables;
145
+ private whereExpression?;
146
+ private orderByExpressions?;
147
+ private arg;
148
+ private rawTable;
149
+ constructor(params: QueryBuilderParams<N, TN, S>);
150
+ select<S2 extends RowLikeIn>(select: ToolCallback<(arg: TN) => S2>): QueryBuilder<N, TN, AsRowLike<S2>>;
151
+ where(where: ToolCallback<(arg: TN) => SqlExpressionIn>): QueryBuilder<N, TN, S>;
152
+ orderBy(orderBy: ToolCallback<OrderByItem<TN>>): QueryBuilder<N, TN, S>;
153
+ limit(limit: number): QueryBuilder<N, TN, S>;
154
+ offset(offset: number): QueryBuilder<N, TN, S>;
155
+ join<N2 extends string, F2 extends TableClass<N2>>(fromItem: F2 | NamespacedExpression<TN, F2>, on?: NamespacedExpression<TN & { [k in N2]: InstanceType<F2> }, SqlExpressionIn>): QueryBuilder<N, TN & { [k in N2]: InstanceType<F2> }, S>;
156
+ join<N2 extends string, F2 extends RowLike>(fromItem: FromItem<N2, F2> | NamespacedExpression<TN, FromItem<N2, F2>>, on?: NamespacedExpression<TN & { [k in N2]: F2 }, SqlExpressionIn>): QueryBuilder<N, TN & { [k in N2]: F2 }, S>;
157
+ execute(): Promise<{ [key in keyof S]: unknown }[]>;
158
+ private paramsForCopy;
159
+ toRowLike: () => S;
160
+ compile: (opts?: {
161
+ isSubquery?: boolean;
162
+ }) => kysely0.RawBuilder<unknown>;
163
+ }
164
+ declare class TableBase extends RpcToolset {
165
+ opts?: {
166
+ remapColumns?: boolean;
167
+ };
168
+ column: (this: InstanceType<TableClass<string>>, columnName: string) => ColumnReferenceExpression;
169
+ }
170
+ type TableClass<N extends string = string> = {
171
+ new (opts?: {
172
+ remapColumns?: boolean;
173
+ }): TableBase;
174
+ as: <T extends TableClass, N2 extends string>(this: T, alias: N2) => Omit<T, keyof TableClass> & TableClass<N2> & {
175
+ new (): InstanceType<T>;
176
+ };
177
+ toRowLike: <T extends TableClass>(this: T, opts?: {
178
+ remapColumns?: boolean;
179
+ }) => InstanceType<T>;
180
+ from: <T extends TableClass>(this: T) => QueryBuilder<N, { [k in N]: InstanceType<T> }, InstanceType<T>>;
181
+ on: <T extends TableClass>(this: T, on: NamespacedExpression<InstanceType<T>, SqlExpression>) => T;
182
+ compile: () => RawSql;
183
+ alias: N;
184
+ tableName: string;
185
+ onExpression?: SqlExpression;
186
+ };
187
+ declare class Database {
188
+ private dialect;
189
+ private opts?;
190
+ private kysely?;
191
+ constructor(dialect: Dialect, opts?: {
192
+ logQuery?: (raw: CompiledQuery) => void;
193
+ } | undefined);
194
+ execute(query: RawSql): Promise<unknown[]>;
195
+ Table<N extends string>(name: N): TableClass<N>;
196
+ }
197
+ //#endregion
198
+ //#region src/rpc-toolset-test-helpers.d.ts
199
+ declare class TestToolset extends RpcToolset {
200
+ add(input: {
201
+ a: number;
202
+ b: number;
203
+ }): Promise<number>;
204
+ toolset2(): Promise<TestToolset2>;
205
+ userForId({
206
+ id
207
+ }: {
208
+ id: string;
209
+ }): Promise<typeof User>;
210
+ }
211
+ declare class TestToolset2 extends RpcToolset {
212
+ subtract(input: {
213
+ a: number;
214
+ b: number;
215
+ }): Promise<number>;
216
+ }
217
+ declare const User_base: Omit<TableClass<"users">, keyof TableClass<string>> & TableClass<"user"> & (new () => {
218
+ opts?: {
219
+ remapColumns?: boolean;
220
+ };
221
+ column: (this: InstanceType<TableClass<string>>, columnName: string) => ColumnReferenceExpression;
222
+ __RPC_TARGET_BRAND: never;
223
+ });
224
+ declare class User extends User_base {
225
+ id: ColumnReferenceExpression;
226
+ name: ColumnReferenceExpression;
227
+ email: ColumnReferenceExpression;
228
+ age: ColumnReferenceExpression;
229
+ posts(): typeof Post;
230
+ }
231
+ declare const Post_base: Omit<TableClass<"posts">, keyof TableClass<string>> & TableClass<"post"> & (new () => {
232
+ opts?: {
233
+ remapColumns?: boolean;
234
+ };
235
+ column: (this: InstanceType<TableClass<string>>, columnName: string) => ColumnReferenceExpression;
236
+ __RPC_TARGET_BRAND: never;
237
+ });
238
+ declare class Post extends Post_base {
239
+ id: ColumnReferenceExpression;
240
+ userId: ColumnReferenceExpression;
241
+ title: ColumnReferenceExpression;
242
+ content: ColumnReferenceExpression;
243
+ }
244
+ //#endregion
245
+ export { Post, TestToolset, TestToolset2, User };