apps 0.0.1-beta.37 → 0.0.1-beta.39

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (81) hide show
  1. package/framework-reference.json +1 -1
  2. package/js/{chunk-GHDZEEPO.js → chunk-27TDXHRX.js} +395 -82
  3. package/js/{chunk-KOOJUMLR.js → chunk-3MMG2H6M.js} +2 -2
  4. package/js/{chunk-LQBR7AI7.js → chunk-3V575NIW.js} +217 -19
  5. package/js/{chunk-U74JVKTQ.js → chunk-5NIEOXRZ.js} +7 -7
  6. package/js/{chunk-BWUHMKHQ.js → chunk-5TJA7364.js} +2 -2
  7. package/js/{chunk-7KEKFBV7.js → chunk-7CSHVXVR.js} +3 -3
  8. package/js/{chunk-3LRFKLUX.js → chunk-BO4US6DZ.js} +9 -49
  9. package/js/{chunk-A4O72Z3A.js → chunk-DKUEYTYD.js} +167 -30
  10. package/js/{chunk-ENJCQWVF.js → chunk-E4BWL7KQ.js} +3 -3
  11. package/js/{chunk-CAOHGMNW.js → chunk-F3TBO2U3.js} +7 -94
  12. package/js/{chunk-POOIHRPF.js → chunk-GHXRRFZA.js} +11 -34
  13. package/js/{chunk-RSNZDT4L.js → chunk-JTMDWPCH.js} +2 -2
  14. package/js/{chunk-YW333DH3.js → chunk-KANDIVIH.js} +4 -4
  15. package/js/{chunk-2FWXCU5I.js → chunk-KAQD3DTI.js} +1 -1
  16. package/js/{chunk-QQKHJ72Y.js → chunk-LVWX4UWK.js} +9 -9
  17. package/js/{chunk-KEZ4YZSP.js → chunk-MLHNVYHT.js} +2 -2
  18. package/js/{chunk-IJQ5LE74.js → chunk-MXDKXAY4.js} +363 -401
  19. package/js/{chunk-BI6R577B.js → chunk-P7MGDPFD.js} +2 -2
  20. package/js/{chunk-24EIFQYZ.js → chunk-PCV73KVK.js} +35 -10
  21. package/js/{chunk-JU7F4PRK.js → chunk-RIXVGVA6.js} +2 -2
  22. package/js/{chunk-D45FU4TZ.js → chunk-SDHD6J37.js} +3 -3
  23. package/js/{chunk-UCOMVHGW.js → chunk-U5PFZDVB.js} +2 -2
  24. package/js/{chunk-PHO7HXTC.js → chunk-VIU2XXA7.js} +294 -47
  25. package/js/{chunk-TADLIUEU.js → chunk-VJQXXOQ3.js} +2 -2
  26. package/js/{chunk-NHCFIWN5.js → chunk-W2NV54JD.js} +1 -1
  27. package/js/{chunk-BI45HZWM.js → chunk-YQ35E7KS.js} +1 -1
  28. package/js/{chunk-WDBUOIWV.js → chunk-ZUKBIHMK.js} +3 -3
  29. package/js/client.js +13 -17
  30. package/js/contracts.js +16 -21
  31. package/js/effect.js +19 -24
  32. package/js/graphql.js +21 -26
  33. package/js/host.js +19 -24
  34. package/js/index.js +13 -26
  35. package/js/mcp/effect.js +21 -26
  36. package/js/mcp/stdio.js +21 -26
  37. package/js/mcp.js +23 -28
  38. package/js/openapi.js +17 -21
  39. package/js/react.js +2 -3
  40. package/js/skills/effect.js +6 -7
  41. package/js/skills.js +15 -17
  42. package/js/storage/facet.js +1 -214
  43. package/js/ui/auth/contracts.js +2 -2
  44. package/js/ui/auth.js +5 -5
  45. package/js/ui/contracts.js +5 -6
  46. package/js/ui/serving.js +10 -11
  47. package/package.json +1 -2
  48. package/runtime.json +1 -1
  49. package/types/apps/src/contracts/app.d.ts +0 -2
  50. package/types/apps/src/contracts/context.d.ts +12 -11
  51. package/types/apps/src/contracts/host.d.ts +10 -8
  52. package/types/apps/src/contracts/live.d.ts +2 -0
  53. package/types/apps/src/contracts/operations.d.ts +3 -3
  54. package/types/apps/src/contracts/protocol-version.d.ts +2 -2
  55. package/types/apps/src/contracts/protocols/10.d.ts +1450 -0
  56. package/types/apps/src/contracts/protocols/4.d.ts +3 -3
  57. package/types/apps/src/contracts/protocols/5.d.ts +1 -1
  58. package/types/apps/src/contracts/protocols/6.d.ts +1 -1
  59. package/types/apps/src/contracts/protocols/7.d.ts +1 -1
  60. package/types/apps/src/contracts/sql.d.ts +58 -0
  61. package/types/apps/src/facet.d.ts +4 -5
  62. package/types/apps/src/implementation/openapi-compile.d.ts +2 -2
  63. package/types/apps/src/implementation/schema.d.ts +1 -10
  64. package/types/apps/src/implementation/sql.d.ts +66 -0
  65. package/types/apps/src/index.d.ts +1 -2
  66. package/types/telemetry/src/transport.d.ts +8 -1
  67. package/js/chunk-73AV3JVU.js +0 -186
  68. package/js/chunk-HDAQBRT5.js +0 -1254
  69. package/js/chunk-IU7CCCUC.js +0 -630
  70. package/js/chunk-NHUHTWAF.js +0 -0
  71. package/js/chunk-V5DWGYRK.js +0 -268
  72. package/js/chunk-Y3XN4X4Q.js +0 -19
  73. package/types/app-data/src/implementation/cursor.d.ts +0 -10
  74. package/types/app-data/src/implementation/index-key.d.ts +0 -7
  75. package/types/app-data/src/implementation/promise.d.ts +0 -68
  76. package/types/app-data/src/implementation/range.d.ts +0 -8
  77. package/types/app-data/src/implementation/schema.d.ts +0 -18
  78. package/types/app-data/src/implementation/sqlite.d.ts +0 -11
  79. package/types/app-data/src/index.d.ts +0 -4
  80. package/types/apps/src/contracts/storage.d.ts +0 -68
  81. package/types/apps/src/implementation/storage.d.ts +0 -15
@@ -1,1254 +0,0 @@
1
- import {
2
- Clock,
3
- Defect,
4
- ParentSpan,
5
- Prototype,
6
- Reference,
7
- Scope,
8
- Service,
9
- String as String2,
10
- TaggedError2 as TaggedError,
11
- TracerTimingEnabled,
12
- Union,
13
- add,
14
- addFinalizer,
15
- andThen,
16
- assignProperty,
17
- close,
18
- constUndefined,
19
- context,
20
- contextWith,
21
- dual,
22
- effect,
23
- endSpan,
24
- failCause,
25
- failCauseUnsafe,
26
- flatMap2 as flatMap,
27
- flow,
28
- fnUntraced,
29
- fromQueue,
30
- gen,
31
- get,
32
- getOption,
33
- getOrUndefined2 as getOrUndefined,
34
- getUnsafe,
35
- hasProperty,
36
- hash,
37
- identity,
38
- isSuccess2 as isSuccess,
39
- make3 as make,
40
- make5 as make2,
41
- makeSpanScoped,
42
- makeSpanUnsafe,
43
- makeUnsafe3 as makeUnsafe,
44
- map3 as map,
45
- match,
46
- offerUnsafe,
47
- onError,
48
- onExit,
49
- onExitPrimitive,
50
- optional,
51
- orDie,
52
- provide,
53
- provideContext,
54
- provideService,
55
- provideService2,
56
- runForkWith,
57
- runIn,
58
- scoped,
59
- serviceOption,
60
- succeed4 as succeed,
61
- suspend,
62
- sync2 as sync,
63
- tap,
64
- uninterruptibleMask,
65
- unwrap3 as unwrap,
66
- useSpan,
67
- void_2 as void_,
68
- withFiber
69
- } from "./chunk-IJQ5LE74.js";
70
-
71
- // ../../node_modules/.bun/effect@4.0.1/node_modules/effect/dist/reactivity/Reactivity.js
72
- var TypeId = "~effect/reactivity/Reactivity";
73
- var Reactivity = /* @__PURE__ */ Service("effect/reactivity/Reactivity");
74
- var make3 = /* @__PURE__ */ sync(() => {
75
- const handlers = /* @__PURE__ */ new Map();
76
- const invalidateUnsafe = (keys) => {
77
- keysToHashes(keys, (hash2) => {
78
- const set = handlers.get(hash2);
79
- if (set === void 0) return;
80
- set.forEach((run) => run());
81
- });
82
- };
83
- const invalidate2 = (keys) => contextWith((services) => {
84
- const pending = getOrUndefined(services, PendingInvalidation);
85
- if (pending) {
86
- keysToHashes(keys, (hash2) => {
87
- pending.add(hash2);
88
- });
89
- } else {
90
- invalidateUnsafe(keys);
91
- }
92
- return void_;
93
- });
94
- const mutation2 = (keys, effect2) => tap(effect2, invalidate2(keys));
95
- const registerUnsafe = (keys, handler) => {
96
- const resolvedKeys = [];
97
- keysToHashes(keys, (hash2) => {
98
- resolvedKeys.push(hash2);
99
- let set = handlers.get(hash2);
100
- if (set === void 0) {
101
- set = /* @__PURE__ */ new Set();
102
- handlers.set(hash2, set);
103
- }
104
- set.add(handler);
105
- });
106
- return () => {
107
- for (let i = 0; i < resolvedKeys.length; i++) {
108
- const set = handlers.get(resolvedKeys[i]);
109
- if (set === void 0) continue;
110
- set.delete(handler);
111
- if (set.size === 0) {
112
- handlers.delete(resolvedKeys[i]);
113
- }
114
- }
115
- };
116
- };
117
- const query = (keys, effect2) => gen(function* () {
118
- const services = yield* context();
119
- const scope2 = get(services, Scope);
120
- const results = yield* make2();
121
- const runFork = flow(runForkWith(services), runIn(scope2));
122
- let running = false;
123
- let pending = false;
124
- const handleExit = (exit) => {
125
- if (exit._tag === "Failure") {
126
- failCauseUnsafe(results, exit.cause);
127
- } else {
128
- offerUnsafe(results, exit.value);
129
- }
130
- if (pending) {
131
- pending = false;
132
- runFork(effect2).addObserver(handleExit);
133
- } else {
134
- running = false;
135
- }
136
- };
137
- function run() {
138
- if (running) {
139
- pending = true;
140
- return;
141
- }
142
- running = true;
143
- runFork(effect2).addObserver(handleExit);
144
- }
145
- const cancel = registerUnsafe(keys, run);
146
- yield* addFinalizer(scope2, sync(cancel));
147
- run();
148
- return results;
149
- });
150
- const stream = (tables, effect2) => query(tables, effect2).pipe(map(fromQueue), unwrap);
151
- const withBatch = (effect2) => suspend(() => {
152
- const pending = /* @__PURE__ */ new Set();
153
- return effect2.pipe(provideService(PendingInvalidation, pending), onExit((_) => sync(() => {
154
- pending.forEach((hash2) => {
155
- const set = handlers.get(hash2);
156
- if (set === void 0) return;
157
- set.forEach((run) => run());
158
- });
159
- })));
160
- });
161
- return Reactivity.of({
162
- [TypeId]: TypeId,
163
- mutation: mutation2,
164
- query,
165
- stream,
166
- invalidateUnsafe,
167
- invalidate: invalidate2,
168
- registerUnsafe,
169
- withBatch
170
- });
171
- });
172
- var PendingInvalidation = class extends (/* @__PURE__ */ Service()("effect/reactivity/Reactivity/PendingInvalidation")) {
173
- };
174
- var mutation = /* @__PURE__ */ dual(2, (effect2, keys) => Reactivity.use((_) => _.mutation(keys, effect2)));
175
- var invalidate = (keys) => Reactivity.use((r) => r.invalidate(keys));
176
- var layer = /* @__PURE__ */ effect(Reactivity)(make3);
177
- function stringOrHash(u) {
178
- switch (typeof u) {
179
- case "string":
180
- case "number":
181
- case "bigint":
182
- case "boolean":
183
- return String(u);
184
- default:
185
- return hash(u);
186
- }
187
- }
188
- var keysToHashes = (keys, f) => {
189
- if (Array.isArray(keys)) {
190
- for (let i = 0; i < keys.length; i++) {
191
- f(stringOrHash(keys[i]));
192
- }
193
- return;
194
- }
195
- for (const key in keys) {
196
- f(key);
197
- const ids = keys[key];
198
- for (let i = 0; i < ids.length; i++) {
199
- f(`${key}:${stringOrHash(ids[i])}`);
200
- }
201
- }
202
- };
203
-
204
- // ../../node_modules/.bun/effect@4.0.1/node_modules/effect/dist/sql/SqlError.js
205
- var TypeId2 = "~effect/sql/SqlError";
206
- var ReasonTypeId = "~effect/sql/SqlError/Reason";
207
- var ReasonFields = {
208
- cause: /* @__PURE__ */ Defect(),
209
- message: /* @__PURE__ */ optional(String2),
210
- operation: /* @__PURE__ */ optional(String2)
211
- };
212
- var ConnectionError = class extends (/* @__PURE__ */ TaggedError("effect/sql/SqlError/ConnectionError")("ConnectionError", ReasonFields)) {
213
- /**
214
- * Marks this value as a structured SQL error reason for runtime guards.
215
- *
216
- * @stability unstable
217
- * @since 4.0.0
218
- */
219
- [ReasonTypeId] = ReasonTypeId;
220
- /**
221
- * Indicates whether retrying the failed SQL operation may succeed.
222
- *
223
- * @stability unstable
224
- * @since 4.0.0
225
- */
226
- get isRetryable() {
227
- return true;
228
- }
229
- };
230
- var AuthenticationError = class extends (/* @__PURE__ */ TaggedError("effect/sql/SqlError/AuthenticationError")("AuthenticationError", ReasonFields)) {
231
- /**
232
- * Marks this value as a structured SQL error reason for runtime guards.
233
- *
234
- * @stability unstable
235
- * @since 4.0.0
236
- */
237
- [ReasonTypeId] = ReasonTypeId;
238
- /**
239
- * Indicates whether retrying the failed SQL operation may succeed.
240
- *
241
- * @stability unstable
242
- * @since 4.0.0
243
- */
244
- get isRetryable() {
245
- return false;
246
- }
247
- };
248
- var AuthorizationError = class extends (/* @__PURE__ */ TaggedError("effect/sql/SqlError/AuthorizationError")("AuthorizationError", ReasonFields)) {
249
- /**
250
- * Marks this value as a structured SQL error reason for runtime guards.
251
- *
252
- * @stability unstable
253
- * @since 4.0.0
254
- */
255
- [ReasonTypeId] = ReasonTypeId;
256
- /**
257
- * Indicates whether retrying the failed SQL operation may succeed.
258
- *
259
- * @stability unstable
260
- * @since 4.0.0
261
- */
262
- get isRetryable() {
263
- return false;
264
- }
265
- };
266
- var SqlSyntaxError = class extends (/* @__PURE__ */ TaggedError("effect/sql/SqlError/SqlSyntaxError")("SqlSyntaxError", ReasonFields)) {
267
- /**
268
- * Marks this value as a structured SQL error reason for runtime guards.
269
- *
270
- * @stability unstable
271
- * @since 4.0.0
272
- */
273
- [ReasonTypeId] = ReasonTypeId;
274
- /**
275
- * Indicates whether retrying the failed SQL operation may succeed.
276
- *
277
- * @stability unstable
278
- * @since 4.0.0
279
- */
280
- get isRetryable() {
281
- return false;
282
- }
283
- };
284
- var UniqueViolationFields = {
285
- ...ReasonFields,
286
- constraint: String2
287
- };
288
- var UniqueViolation = class extends (/* @__PURE__ */ TaggedError("effect/sql/SqlError/UniqueViolation")("UniqueViolation", UniqueViolationFields)) {
289
- /**
290
- * Marks this value as a structured SQL error reason for runtime guards.
291
- *
292
- * @stability unstable
293
- * @since 4.0.0
294
- */
295
- [ReasonTypeId] = ReasonTypeId;
296
- /**
297
- * Indicates whether retrying the failed SQL operation may succeed.
298
- *
299
- * @stability unstable
300
- * @since 4.0.0
301
- */
302
- get isRetryable() {
303
- return false;
304
- }
305
- };
306
- var ConstraintError = class extends (/* @__PURE__ */ TaggedError("effect/sql/SqlError/ConstraintError")("ConstraintError", ReasonFields)) {
307
- /**
308
- * Marks this value as a structured SQL error reason for runtime guards.
309
- *
310
- * @stability unstable
311
- * @since 4.0.0
312
- */
313
- [ReasonTypeId] = ReasonTypeId;
314
- /**
315
- * Indicates whether retrying the failed SQL operation may succeed.
316
- *
317
- * @stability unstable
318
- * @since 4.0.0
319
- */
320
- get isRetryable() {
321
- return false;
322
- }
323
- };
324
- var DeadlockError = class extends (/* @__PURE__ */ TaggedError("effect/sql/SqlError/DeadlockError")("DeadlockError", ReasonFields)) {
325
- /**
326
- * Marks this value as a structured SQL error reason for runtime guards.
327
- *
328
- * @stability unstable
329
- * @since 4.0.0
330
- */
331
- [ReasonTypeId] = ReasonTypeId;
332
- /**
333
- * Indicates whether retrying the failed SQL operation may succeed.
334
- *
335
- * @stability unstable
336
- * @since 4.0.0
337
- */
338
- get isRetryable() {
339
- return true;
340
- }
341
- };
342
- var SerializationError = class extends (/* @__PURE__ */ TaggedError("effect/sql/SqlError/SerializationError")("SerializationError", ReasonFields)) {
343
- /**
344
- * Marks this value as a structured SQL error reason for runtime guards.
345
- *
346
- * @stability unstable
347
- * @since 4.0.0
348
- */
349
- [ReasonTypeId] = ReasonTypeId;
350
- /**
351
- * Indicates whether retrying the failed SQL operation may succeed.
352
- *
353
- * @stability unstable
354
- * @since 4.0.0
355
- */
356
- get isRetryable() {
357
- return true;
358
- }
359
- };
360
- var LockTimeoutError = class extends (/* @__PURE__ */ TaggedError("effect/sql/SqlError/LockTimeoutError")("LockTimeoutError", ReasonFields)) {
361
- /**
362
- * Marks this value as a structured SQL error reason for runtime guards.
363
- *
364
- * @stability unstable
365
- * @since 4.0.0
366
- */
367
- [ReasonTypeId] = ReasonTypeId;
368
- /**
369
- * Indicates whether retrying the failed SQL operation may succeed.
370
- *
371
- * @stability unstable
372
- * @since 4.0.0
373
- */
374
- get isRetryable() {
375
- return true;
376
- }
377
- };
378
- var StatementTimeoutError = class extends (/* @__PURE__ */ TaggedError("effect/sql/SqlError/StatementTimeoutError")("StatementTimeoutError", ReasonFields)) {
379
- /**
380
- * Marks this value as a structured SQL error reason for runtime guards.
381
- *
382
- * @stability unstable
383
- * @since 4.0.0
384
- */
385
- [ReasonTypeId] = ReasonTypeId;
386
- /**
387
- * Indicates whether retrying the failed SQL operation may succeed.
388
- *
389
- * @stability unstable
390
- * @since 4.0.0
391
- */
392
- get isRetryable() {
393
- return true;
394
- }
395
- };
396
- var UnknownError = class extends (/* @__PURE__ */ TaggedError("effect/sql/SqlError/UnknownError")("UnknownError", ReasonFields)) {
397
- /**
398
- * Marks this value as a structured SQL error reason for runtime guards.
399
- *
400
- * @stability unstable
401
- * @since 4.0.0
402
- */
403
- [ReasonTypeId] = ReasonTypeId;
404
- /**
405
- * Indicates whether retrying the failed SQL operation may succeed.
406
- *
407
- * @stability unstable
408
- * @since 4.0.0
409
- */
410
- get isRetryable() {
411
- return false;
412
- }
413
- };
414
- var SqlErrorReason = /* @__PURE__ */ Union([ConnectionError, AuthenticationError, AuthorizationError, SqlSyntaxError, UniqueViolation, ConstraintError, DeadlockError, SerializationError, LockTimeoutError, StatementTimeoutError, UnknownError]);
415
- var SqlError = class extends (/* @__PURE__ */ TaggedError("effect/sql/SqlError")("SqlError", {
416
- reason: SqlErrorReason
417
- })) {
418
- /**
419
- * Marks this value as the top-level SQL error wrapper for runtime guards.
420
- *
421
- * @stability unstable
422
- * @since 4.0.0
423
- */
424
- [TypeId2] = TypeId2;
425
- /**
426
- * Exposes the structured SQL reason as the JavaScript error cause.
427
- *
428
- * @stability unstable
429
- * @since 4.0.0
430
- */
431
- cause = this.reason;
432
- /**
433
- * Uses the reason message when present, otherwise falls back to the reason tag.
434
- *
435
- * @stability unstable
436
- * @since 4.0.0
437
- */
438
- get message() {
439
- return this.reason.message || this.reason._tag;
440
- }
441
- /**
442
- * Delegates retryability to the underlying SQL error reason.
443
- *
444
- * @stability unstable
445
- * @since 4.0.0
446
- */
447
- get isRetryable() {
448
- return this.reason.isRetryable;
449
- }
450
- };
451
- var sqliteCodeFromCause = (cause) => {
452
- if (!hasProperty(cause, "code")) {
453
- return void 0;
454
- }
455
- const code = cause.code;
456
- return typeof code === "string" || typeof code === "number" ? code : void 0;
457
- };
458
- var sqliteNumericCodeFromCause = (cause) => {
459
- const code = sqliteCodeFromCause(cause);
460
- if (typeof code === "number") {
461
- return code;
462
- }
463
- if (!hasProperty(cause, "errno")) {
464
- return void 0;
465
- }
466
- const errno = cause.errno;
467
- return typeof errno === "number" ? errno : void 0;
468
- };
469
- var matchesSqliteNumericCode = (cause, expected) => {
470
- const code = sqliteCodeFromCause(cause);
471
- if (code === expected) {
472
- return true;
473
- }
474
- if (!hasProperty(cause, "errno")) {
475
- return false;
476
- }
477
- return cause.errno === expected;
478
- };
479
- var matchesSqliteCode = (code, expected) => code === expected || code.startsWith(expected + "_");
480
- var UNKNOWN_CONSTRAINT = "unknown";
481
- var SQLITE_CONSTRAINT_UNIQUE = "SQLITE_CONSTRAINT_UNIQUE";
482
- var SQLITE_CONSTRAINT_UNIQUE_CODE = 2067;
483
- var normalizeConstraintIdentifier = (identifier2) => {
484
- if (typeof identifier2 !== "string") {
485
- return UNKNOWN_CONSTRAINT;
486
- }
487
- const trimmed = identifier2.trim();
488
- return trimmed.length === 0 ? UNKNOWN_CONSTRAINT : trimmed;
489
- };
490
- var sqliteUniqueConstraintFromCause = (cause) => {
491
- if (hasProperty(cause, "constraint")) {
492
- return normalizeConstraintIdentifier(cause.constraint);
493
- }
494
- if (!hasProperty(cause, "message")) {
495
- return UNKNOWN_CONSTRAINT;
496
- }
497
- const message = cause.message;
498
- if (typeof message !== "string") {
499
- return UNKNOWN_CONSTRAINT;
500
- }
501
- const prefix = "UNIQUE constraint failed:";
502
- const index = message.indexOf(prefix);
503
- return index === -1 ? UNKNOWN_CONSTRAINT : normalizeConstraintIdentifier(message.slice(index + prefix.length));
504
- };
505
- var classifySqliteError = (cause, {
506
- message,
507
- operation
508
- } = {}) => {
509
- const props = {
510
- cause,
511
- message,
512
- operation
513
- };
514
- const code = sqliteCodeFromCause(cause);
515
- const numericCode = sqliteNumericCodeFromCause(cause);
516
- if (code === SQLITE_CONSTRAINT_UNIQUE || matchesSqliteNumericCode(cause, SQLITE_CONSTRAINT_UNIQUE_CODE)) {
517
- return new UniqueViolation({
518
- ...props,
519
- constraint: sqliteUniqueConstraintFromCause(cause)
520
- });
521
- }
522
- if (typeof code === "string") {
523
- if (matchesSqliteCode(code, "SQLITE_AUTH")) {
524
- return new AuthenticationError(props);
525
- }
526
- if (matchesSqliteCode(code, "SQLITE_PERM")) {
527
- return new AuthorizationError(props);
528
- }
529
- if (matchesSqliteCode(code, "SQLITE_CONSTRAINT")) {
530
- return new ConstraintError(props);
531
- }
532
- if (matchesSqliteCode(code, "SQLITE_BUSY") || matchesSqliteCode(code, "SQLITE_LOCKED")) {
533
- return new LockTimeoutError(props);
534
- }
535
- if (matchesSqliteCode(code, "SQLITE_CANTOPEN")) {
536
- return new ConnectionError(props);
537
- }
538
- }
539
- if (typeof numericCode === "number") {
540
- const code2 = numericCode & 255;
541
- switch (code2) {
542
- case 23:
543
- return new AuthenticationError(props);
544
- case 3:
545
- return new AuthorizationError(props);
546
- case 19:
547
- return new ConstraintError(props);
548
- case 5:
549
- case 6:
550
- return new LockTimeoutError(props);
551
- case 14:
552
- return new ConnectionError(props);
553
- default:
554
- return new UnknownError(props);
555
- }
556
- }
557
- return new UnknownError(props);
558
- };
559
-
560
- // ../../node_modules/.bun/effect@4.0.1/node_modules/effect/dist/sql/Statement.js
561
- var FragmentTypeId = "~effect/sql/Statement/Fragment";
562
- var fragment = (segments) => ({
563
- [FragmentTypeId]: FragmentTypeId,
564
- segments
565
- });
566
- var CurrentTransformer = /* @__PURE__ */ Reference("effect/sql/CurrentTransformer", {
567
- defaultValue: constUndefined
568
- });
569
- var SpanPropagationEnabled = /* @__PURE__ */ Reference("effect/sql/SpanPropagationEnabled", {
570
- defaultValue: () => false
571
- });
572
- var isFragment = (u) => hasProperty(u, FragmentTypeId);
573
- var literal = (value, params) => ({
574
- _tag: "Literal",
575
- value,
576
- params
577
- });
578
- var identifier = (value) => ({
579
- _tag: "Identifier",
580
- value
581
- });
582
- var parameter = (value) => ({
583
- _tag: "Parameter",
584
- value
585
- });
586
- var arrayHelper = (value) => ({
587
- _tag: "ArrayHelper",
588
- value
589
- });
590
- var RecordInsertHelperProto = {
591
- _tag: "RecordInsertHelper",
592
- returning(sql) {
593
- const self = Object.create(Object.getPrototypeOf(this));
594
- Object.assign(self, this, {
595
- returningIdentifier: typeof sql === "string" || isFragment(sql) ? sql : fragment([sql])
596
- });
597
- return self;
598
- }
599
- };
600
- var recordInsertHelper = (value) => Object.assign(Object.create(RecordInsertHelperProto), {
601
- value,
602
- returningIdentifier: void 0
603
- });
604
- var RecordUpdateHelperProto = {
605
- ...RecordInsertHelperProto,
606
- _tag: "RecordUpdateHelper"
607
- };
608
- var recordUpdateHelper = (value, alias) => Object.assign(Object.create(RecordUpdateHelperProto), {
609
- value,
610
- alias,
611
- returningIdentifier: void 0
612
- });
613
- var RecordUpdateHelperSingleProto = {
614
- ...RecordInsertHelperProto,
615
- _tag: "RecordUpdateHelperSingle"
616
- };
617
- var recordUpdateHelperSingle = (value, omit) => Object.assign(Object.create(RecordUpdateHelperSingleProto), {
618
- value,
619
- omit,
620
- returningIdentifier: void 0
621
- });
622
- var make4 = (acquirer, compiler, spanAttributes, transformRows, borrower) => {
623
- const cache = transformRows === void 0 ? constructorCache.noTransforms : constructorCache.transforms;
624
- if (cache.has(acquirer)) {
625
- return cache.get(acquirer);
626
- }
627
- const self = Object.assign(function sql(strings, ...args) {
628
- if (typeof strings === "string") {
629
- return identifier(strings);
630
- } else if (Array.isArray(strings) && "raw" in strings) {
631
- return statement(acquirer, compiler, strings, args, spanAttributes, transformRows, borrower);
632
- }
633
- throw "absurd";
634
- }, {
635
- unsafe(sql, params) {
636
- return makeUnsafe2([literal(sql, params)], acquirer, compiler, spanAttributes, transformRows, borrower);
637
- },
638
- literal(sql) {
639
- return fragment([literal(sql)]);
640
- },
641
- in: in_,
642
- insert(value) {
643
- return recordInsertHelper(Array.isArray(value) ? value : [value]);
644
- },
645
- update(value, omit) {
646
- return recordUpdateHelperSingle(value, omit ?? []);
647
- },
648
- updateValues(value, alias) {
649
- return recordUpdateHelper(value, alias);
650
- },
651
- and,
652
- or,
653
- csv,
654
- join,
655
- onDialect(options) {
656
- return options[compiler.dialect]();
657
- },
658
- onDialectOrElse(options) {
659
- return options[compiler.dialect] !== void 0 ? options[compiler.dialect]() : options.orElse();
660
- }
661
- });
662
- cache.set(acquirer, self);
663
- return self;
664
- };
665
- var constructorCache = {
666
- transforms: /* @__PURE__ */ new WeakMap(),
667
- noTransforms: /* @__PURE__ */ new WeakMap()
668
- };
669
- var statement = (acquirer, compiler, strings, args, spanAttributes, transformRows, borrower) => {
670
- const segments = strings[0].length > 0 ? [literal(strings[0])] : [];
671
- for (let i = 0; i < args.length; i++) {
672
- const arg = args[i];
673
- if (isFragment(arg)) {
674
- segments.push(...arg.segments);
675
- } else if (isSegment(arg)) {
676
- segments.push(arg);
677
- } else {
678
- segments.push(parameter(arg));
679
- }
680
- if (strings[i + 1].length > 0) {
681
- segments.push(literal(strings[i + 1]));
682
- }
683
- }
684
- return makeUnsafe2(segments, acquirer, compiler, spanAttributes, transformRows, borrower);
685
- };
686
- function join(lit, addParens = true, fallback = "") {
687
- const literalStatement = literal(lit);
688
- const fallbackFragment = fragment([literal(fallback)]);
689
- return (clauses) => {
690
- if (clauses.length === 0) {
691
- return fallbackFragment;
692
- } else if (clauses.length === 1) {
693
- return fragment(convertLiteralOrFragment(clauses[0]));
694
- }
695
- const segments = [];
696
- if (addParens) {
697
- segments.push(literal("("));
698
- }
699
- segments.push.apply(segments, convertLiteralOrFragment(clauses[0]));
700
- for (let i = 1; i < clauses.length; i++) {
701
- segments.push(literalStatement);
702
- segments.push.apply(segments, convertLiteralOrFragment(clauses[i]));
703
- }
704
- if (addParens) {
705
- segments.push(literal(")"));
706
- }
707
- return fragment(segments);
708
- };
709
- }
710
- var and = /* @__PURE__ */ join(" AND ", true, "1=1");
711
- var or = /* @__PURE__ */ join(" OR ", true, "1=1");
712
- var csv = function(...args) {
713
- if (args[args.length - 1].length === 0) {
714
- return emptyFragment;
715
- }
716
- if (args.length === 1) {
717
- return csvRaw(args[0]);
718
- }
719
- return fragment([literal(`${args[0]} `), ...csvRaw(args[1]).segments]);
720
- };
721
- var csvRaw = /* @__PURE__ */ join(",", false);
722
- var emptyFragment = /* @__PURE__ */ fragment([/* @__PURE__ */ literal("")]);
723
- var makeCompiler = (options) => {
724
- const self = Object.create(CompilerProto);
725
- self.options = options;
726
- self.dialect = options.dialect;
727
- self.disableTransforms = false;
728
- self.statementCache = /* @__PURE__ */ new WeakMap();
729
- self.statementCacheNoTransform = /* @__PURE__ */ new WeakMap();
730
- return self;
731
- };
732
- var CompilerProto = {
733
- compile(statement2, withoutTransform = false, placeholderOverride) {
734
- const opts = this.options;
735
- withoutTransform = withoutTransform || this.disableTransforms;
736
- const cache = withoutTransform ? this.statementCacheNoTransform : this.statementCache;
737
- const cached = cache.get(statement2);
738
- if (cached !== void 0 && placeholderOverride === void 0) {
739
- return cached;
740
- }
741
- const segments = statement2.segments;
742
- const len = segments.length;
743
- let sql = "";
744
- const binds = [];
745
- let placeholderCount = 0;
746
- const placeholder = placeholderOverride ?? ((u) => opts.placeholder(++placeholderCount, u));
747
- const placeholderNoIncrement = (u) => opts.placeholder(placeholderCount, u);
748
- const placeholders = makePlaceholdersArray(placeholder);
749
- for (let i = 0; i < len; i++) {
750
- const segment = segments[i];
751
- switch (segment._tag) {
752
- case "Literal": {
753
- sql += segment.value;
754
- if (segment.params) {
755
- binds.push.apply(binds, segment.params);
756
- }
757
- break;
758
- }
759
- case "Identifier": {
760
- sql += opts.onIdentifier(segment.value, withoutTransform);
761
- break;
762
- }
763
- case "Parameter": {
764
- sql += placeholder(segment.value);
765
- binds.push(segment.value);
766
- break;
767
- }
768
- case "ArrayHelper": {
769
- sql += `(${placeholders(segment.value)})`;
770
- binds.push.apply(binds, segment.value);
771
- break;
772
- }
773
- case "RecordInsertHelper": {
774
- const keys = Object.keys(segment.value[0]);
775
- if (opts.onInsert) {
776
- const values = new Array(segment.value.length);
777
- let placeholders2 = "";
778
- for (let i2 = 0; i2 < segment.value.length; i2++) {
779
- const row = new Array(keys.length);
780
- values[i2] = row;
781
- placeholders2 += i2 === 0 ? "(" : ",(";
782
- for (let j = 0; j < keys.length; j++) {
783
- const key = keys[j];
784
- const value = segment.value[i2][key];
785
- const primitive = extractPrimitive(value, opts.onCustom, placeholderNoIncrement, withoutTransform);
786
- row[j] = primitive;
787
- placeholders2 += j === 0 ? placeholder(value) : `,${placeholder(value)}`;
788
- }
789
- placeholders2 += ")";
790
- }
791
- const [s, b] = opts.onInsert(keys.map((_) => opts.onIdentifier(_, withoutTransform)), placeholders2, values, typeof segment.returningIdentifier === "string" ? [segment.returningIdentifier, []] : segment.returningIdentifier ? this.compile(segment.returningIdentifier, withoutTransform, placeholder) : void 0);
792
- sql += s;
793
- binds.push.apply(binds, b);
794
- } else {
795
- let placeholders2 = "";
796
- for (let i2 = 0; i2 < segment.value.length; i2++) {
797
- placeholders2 += i2 === 0 ? "(" : ",(";
798
- for (let j = 0; j < keys.length; j++) {
799
- const value = segment.value[i2][keys[j]];
800
- const primitive = extractPrimitive(value, opts.onCustom, placeholderNoIncrement, withoutTransform);
801
- binds.push(primitive);
802
- placeholders2 += j === 0 ? placeholder(value) : `,${placeholder(value)}`;
803
- }
804
- placeholders2 += ")";
805
- }
806
- sql += `${generateColumns(keys, opts.onIdentifier, withoutTransform)} VALUES ${placeholders2}`;
807
- if (typeof segment.returningIdentifier === "string") {
808
- sql += ` RETURNING ${segment.returningIdentifier}`;
809
- } else if (segment.returningIdentifier) {
810
- sql += " RETURNING ";
811
- const [s, b] = this.compile(segment.returningIdentifier, withoutTransform, placeholder);
812
- sql += s;
813
- binds.push.apply(binds, b);
814
- }
815
- }
816
- break;
817
- }
818
- case "RecordUpdateHelperSingle": {
819
- let keys = Object.keys(segment.value);
820
- if (segment.omit.length > 0) {
821
- keys = keys.filter((key) => !segment.omit.includes(key));
822
- }
823
- if (opts.onRecordUpdateSingle) {
824
- const [s, b] = opts.onRecordUpdateSingle(keys.map((_) => opts.onIdentifier(_, withoutTransform)), keys.map((key) => extractPrimitive(segment.value[key], opts.onCustom, placeholderNoIncrement, withoutTransform)), typeof segment.returningIdentifier === "string" ? [segment.returningIdentifier, []] : segment.returningIdentifier ? this.compile(segment.returningIdentifier, withoutTransform, placeholder) : void 0);
825
- sql += s;
826
- binds.push.apply(binds, b);
827
- } else {
828
- for (let i2 = 0, len2 = keys.length; i2 < len2; i2++) {
829
- const column = opts.onIdentifier(keys[i2], withoutTransform);
830
- if (i2 === 0) {
831
- sql += `${column} = ${placeholder(segment.value[keys[i2]])}`;
832
- } else {
833
- sql += `, ${column} = ${placeholder(segment.value[keys[i2]])}`;
834
- }
835
- binds.push(extractPrimitive(segment.value[keys[i2]], opts.onCustom, placeholderNoIncrement, withoutTransform));
836
- }
837
- if (typeof segment.returningIdentifier === "string") {
838
- if (this.dialect === "mssql") {
839
- sql += ` OUTPUT ${segment.returningIdentifier === "*" ? "INSERTED.*" : segment.returningIdentifier}`;
840
- } else {
841
- sql += ` RETURNING ${segment.returningIdentifier}`;
842
- }
843
- } else if (segment.returningIdentifier) {
844
- sql += this.dialect === "mssql" ? " OUTPUT " : " RETURNING ";
845
- const [s, b] = this.compile(segment.returningIdentifier, withoutTransform, placeholder);
846
- sql += s;
847
- binds.push.apply(binds, b);
848
- }
849
- }
850
- break;
851
- }
852
- case "RecordUpdateHelper": {
853
- const keys = Object.keys(segment.value[0]);
854
- const values = new Array(segment.value.length);
855
- let placeholders2 = "";
856
- for (let i2 = 0; i2 < segment.value.length; i2++) {
857
- const row = new Array(keys.length);
858
- values[i2] = row;
859
- placeholders2 += i2 === 0 ? "(" : ",(";
860
- for (let j = 0; j < keys.length; j++) {
861
- const key = keys[j];
862
- const value = segment.value[i2][key];
863
- row[j] = extractPrimitive(value, opts.onCustom, placeholderNoIncrement, withoutTransform);
864
- placeholders2 += j === 0 ? placeholder(value) : `,${placeholder(value)}`;
865
- }
866
- placeholders2 += ")";
867
- }
868
- const [s, b] = opts.onRecordUpdate(placeholders2, segment.alias, generateColumns(keys, opts.onIdentifier, withoutTransform), values, typeof segment.returningIdentifier === "string" ? [segment.returningIdentifier, []] : segment.returningIdentifier ? this.compile(segment.returningIdentifier, withoutTransform, placeholder) : void 0);
869
- sql += s;
870
- binds.push.apply(binds, b);
871
- break;
872
- }
873
- case "Custom": {
874
- const [s, b] = opts.onCustom(segment, placeholder, withoutTransform);
875
- sql += s;
876
- binds.push.apply(binds, b);
877
- break;
878
- }
879
- }
880
- }
881
- const result = [sql, binds];
882
- if (placeholderOverride !== void 0) {
883
- return result;
884
- }
885
- cache.set(statement2, result);
886
- return result;
887
- },
888
- get withoutTransform() {
889
- const self = Object.create(CompilerProto);
890
- Object.assign(self, this, {
891
- disableTransforms: true
892
- });
893
- return self;
894
- }
895
- };
896
- var makeCompilerSqlite = (transform) => makeCompiler({
897
- dialect: "sqlite",
898
- placeholder(_) {
899
- return "?";
900
- },
901
- onIdentifier: transform ? function(value, withoutTransform) {
902
- return withoutTransform ? escapeSqlite(value) : escapeSqlite(transform(value));
903
- } : escapeSqlite,
904
- onRecordUpdate() {
905
- return ["", []];
906
- },
907
- onCustom() {
908
- return ["", []];
909
- }
910
- });
911
- function defaultEscape(c) {
912
- const re = new RegExp(c, "g");
913
- const double = c + c;
914
- const dot = c + "." + c;
915
- return function(str) {
916
- return c + str.replace(re, double).replace(/\./g, dot) + c;
917
- };
918
- }
919
- var defaultTransforms = (transformer, nested = true) => {
920
- const transformValue = (value) => {
921
- if (Array.isArray(value)) {
922
- if (value.length === 0 || value[0].constructor !== Object) {
923
- return value;
924
- }
925
- return array(value);
926
- } else if (value?.constructor === Object) {
927
- return transformObject(value);
928
- }
929
- return value;
930
- };
931
- const transformObject = (obj) => {
932
- const newObj = {};
933
- for (const key of Object.keys(obj)) {
934
- assignProperty(newObj, transformer(key), transformValue(obj[key]));
935
- }
936
- return newObj;
937
- };
938
- const transformArrayNested = (rows) => {
939
- const newRows = new Array(rows.length);
940
- for (let i = 0, len = rows.length; i < len; i++) {
941
- const row = rows[i];
942
- if (Array.isArray(row)) {
943
- newRows[i] = transformArrayNested(row);
944
- } else {
945
- const obj = {};
946
- for (const [key, value] of Object.entries(row)) {
947
- assignProperty(obj, transformer(key), transformValue(value));
948
- }
949
- newRows[i] = obj;
950
- }
951
- }
952
- return newRows;
953
- };
954
- const transformArray = (rows) => {
955
- const newRows = new Array(rows.length);
956
- for (let i = 0, len = rows.length; i < len; i++) {
957
- const row = rows[i];
958
- if (Array.isArray(row)) {
959
- newRows[i] = transformArray(row);
960
- } else {
961
- const obj = {};
962
- for (const [key, value] of Object.entries(row)) {
963
- assignProperty(obj, transformer(key), value);
964
- }
965
- newRows[i] = obj;
966
- }
967
- }
968
- return newRows;
969
- };
970
- const array = nested ? transformArrayNested : transformArray;
971
- return {
972
- value: transformValue,
973
- object: transformObject,
974
- array
975
- };
976
- };
977
- var ATTR_DB_OPERATION_NAME = "db.operation.name";
978
- var ATTR_DB_QUERY_TEXT = "db.query.text";
979
- var makeUnsafe2 = (segments, acquirer, compiler, spanAttributes, transformRows, borrower) => {
980
- const self = Object.create(StatementProto);
981
- self.segments = segments;
982
- self.acquirer = acquirer;
983
- self.compiler = compiler;
984
- self.spanAttributes = spanAttributes;
985
- self.transformRows = transformRows;
986
- self.borrower = borrower;
987
- return self;
988
- };
989
- var StatementProto = {
990
- [FragmentTypeId]: FragmentTypeId,
991
- withConnection(operation, f, withoutTransform = false) {
992
- return useSpan("sql.execute", {
993
- kind: "client"
994
- }, (span) => this.withConnectionSpan(operation, f, withoutTransform, span));
995
- },
996
- withConnectionSpan(operation, f, withoutTransform, span) {
997
- return withStatement(this, span, (statement2, fiber) => {
998
- const [sql, params] = statement2.compile(withoutTransform);
999
- for (const [key, value] of this.spanAttributes) {
1000
- span.attribute(key, value);
1001
- }
1002
- span.attribute(ATTR_DB_OPERATION_NAME, operation);
1003
- span.attribute(ATTR_DB_QUERY_TEXT, sql);
1004
- const execute = this.borrower === void 0 ? scoped(flatMap(this.acquirer, (_) => f(_, sql, params))) : this.borrower((connection) => f(connection, sql, params));
1005
- return fiber.cache.tracerEnabled && fiber.getRef(SpanPropagationEnabled) ? provideService(execute, ParentSpan, span) : execute;
1006
- });
1007
- },
1008
- get withoutTransform() {
1009
- return this.withConnection("executeWithoutTransform", (connection, sql, params) => connection.execute(sql, params, void 0), true);
1010
- },
1011
- get raw() {
1012
- return this.withConnection("executeRaw", (connection, sql, params) => connection.executeRaw(sql, params), true);
1013
- },
1014
- get stream() {
1015
- const self = this;
1016
- return unwrap(flatMap(makeSpanScoped("sql.execute", {
1017
- kind: "client"
1018
- }), (span) => withStatement(self, span, (statement2, fiber) => {
1019
- const [sql, params] = statement2.compile();
1020
- for (const [key, value] of self.spanAttributes) {
1021
- span.attribute(key, value);
1022
- }
1023
- span.attribute(ATTR_DB_OPERATION_NAME, "executeStream");
1024
- span.attribute(ATTR_DB_QUERY_TEXT, sql);
1025
- const acquire = map(self.acquirer, (_) => _.executeStream(sql, params, self.transformRows));
1026
- return fiber.cache.tracerEnabled && fiber.getRef(SpanPropagationEnabled) ? succeed(provideService2(unwrap(acquire), ParentSpan, span)) : acquire;
1027
- })));
1028
- },
1029
- get values() {
1030
- return this.withConnection("executeValues", (connection, sql, params) => connection.executeValues(sql, params));
1031
- },
1032
- get valuesUnprepared() {
1033
- return this.withConnection("executeValuesUnprepared", (connection, sql, params) => connection.executeValuesUnprepared(sql, params));
1034
- },
1035
- get unprepared() {
1036
- const self = this;
1037
- return self.withConnection("executeUnprepared", (connection, sql, params) => connection.executeUnprepared(sql, params, self.transformRows));
1038
- },
1039
- .../* @__PURE__ */ Prototype({
1040
- label: "Statement",
1041
- evaluate(fiber) {
1042
- const span = makeSpanUnsafe(fiber, "sql.execute", {
1043
- kind: "client"
1044
- });
1045
- const clock = fiber.getRef(Clock);
1046
- const timingEnabled = fiber.getRef(TracerTimingEnabled);
1047
- return onExit(this.withConnectionSpan("execute", (connection, sql, params) => connection.execute(sql, params, this.transformRows), false, span), (exit) => endSpan(span, exit, clock, timingEnabled));
1048
- }
1049
- }),
1050
- compile(withoutTransform) {
1051
- return this.compiler.compile(this, withoutTransform ?? false);
1052
- },
1053
- toJSON() {
1054
- const [sql, params] = this.compile();
1055
- return {
1056
- _id: "Statement",
1057
- segments: this.segments,
1058
- sql,
1059
- params
1060
- };
1061
- }
1062
- };
1063
- var withStatement = (self, span, f) => withFiber((fiber) => {
1064
- const transform = fiber.getRef(CurrentTransformer);
1065
- if (transform === void 0) {
1066
- return f(self, fiber);
1067
- }
1068
- return flatMap(transform(self, make4(self.acquirer, self.compiler, self.spanAttributes, self.transformRows, self.borrower), fiber, span), (statement2) => f(statement2, fiber));
1069
- });
1070
- var isSegment = (u) => {
1071
- if (!hasProperty(u, "_tag")) {
1072
- return false;
1073
- }
1074
- switch (u._tag) {
1075
- case "Literal":
1076
- case "Parameter":
1077
- case "ArrayHelper":
1078
- case "RecordInsertHelper":
1079
- case "RecordUpdateHelper":
1080
- case "RecordUpdateHelperSingle":
1081
- case "Identifier":
1082
- case "Custom":
1083
- return true;
1084
- default:
1085
- return false;
1086
- }
1087
- };
1088
- function convertLiteralOrFragment(clause) {
1089
- if (typeof clause === "string") {
1090
- return [literal(clause)];
1091
- }
1092
- return clause.segments;
1093
- }
1094
- var makePlaceholdersArray = (evaluate) => (values) => {
1095
- if (values.length === 0) {
1096
- return "";
1097
- }
1098
- let result = evaluate(values[0]);
1099
- for (let i = 1; i < values.length; i++) {
1100
- result += `,${evaluate(values[i])}`;
1101
- }
1102
- return result;
1103
- };
1104
- var generateColumns = (keys, escape, withoutTransform) => {
1105
- if (keys.length === 0) {
1106
- return "()";
1107
- }
1108
- let str = `(${escape(keys[0], withoutTransform)}`;
1109
- for (let i = 1; i < keys.length; i++) {
1110
- str += `,${escape(keys[i], withoutTransform)}`;
1111
- }
1112
- return str + ")";
1113
- };
1114
- var extractPrimitive = (value, onCustom, placeholder, withoutTransform) => {
1115
- if (value === void 0) {
1116
- return null;
1117
- } else if (isFragment(value)) {
1118
- const head = value.segments[0];
1119
- if (head._tag === "Custom") {
1120
- const compiled = onCustom(head, placeholder, withoutTransform);
1121
- return compiled[1][0] ?? null;
1122
- } else if (head._tag === "Parameter") {
1123
- return head.value;
1124
- }
1125
- return null;
1126
- }
1127
- return value;
1128
- };
1129
- var escapeSqlite = /* @__PURE__ */ defaultEscape('"');
1130
- function in_() {
1131
- if (arguments.length === 1) {
1132
- return arrayHelper(arguments[0]);
1133
- }
1134
- const column = arguments[0];
1135
- const values = arguments[1];
1136
- return values.length === 0 ? neverFragment : fragment([identifier(column), literal(" IN "), arrayHelper(values)]);
1137
- }
1138
- var neverFragment = /* @__PURE__ */ fragment([/* @__PURE__ */ literal("1=0")]);
1139
-
1140
- // ../../node_modules/.bun/effect@4.0.1/node_modules/effect/dist/sql/SqlClient.js
1141
- var TypeId3 = "~effect/sql/SqlClient";
1142
- var SqlClient = /* @__PURE__ */ Service("effect/sql/SqlClient");
1143
- var clientIdCounter = 0;
1144
- var transactionSemaphoreIdCounter = 0;
1145
- var make5 = /* @__PURE__ */ fnUntraced(function* (options) {
1146
- const transactionService = options.transactionService ?? TransactionConnection(clientIdCounter++);
1147
- const getConnection = flatMap(serviceOption(transactionService), match({
1148
- onNone: () => options.acquirer,
1149
- onSome: ([conn]) => succeed(conn)
1150
- }));
1151
- const beginTransaction = options.beginTransaction ?? "BEGIN";
1152
- const commit = options.commit ?? "COMMIT";
1153
- const savepoint = options.savepoint ?? ((name) => `SAVEPOINT ${name}`);
1154
- const releaseSavepoint = options.releaseSavepoint;
1155
- const rollback = options.rollback ?? "ROLLBACK";
1156
- const rollbackSavepoint = options.rollbackSavepoint ?? ((name) => `ROLLBACK TO SAVEPOINT ${name}`);
1157
- const transactionAcquirer = options.transactionAcquirer ?? options.acquirer;
1158
- const control = options.prepareTransactionControls === true ? (conn, sql) => conn.execute(sql, [], void 0) : (conn, sql) => conn.executeUnprepared(sql, [], void 0);
1159
- const withTransaction = makeWithTransaction({
1160
- transactionService,
1161
- spanAttributes: options.spanAttributes,
1162
- acquireConnection: flatMap(make(), (scope2) => provide(transactionAcquirer, scope2).pipe(onError((cause) => close(scope2, failCause(cause))), map((conn) => [scope2, conn]))),
1163
- begin: (conn) => control(conn, beginTransaction),
1164
- savepoint: (conn, id) => control(conn, savepoint(`effect_sql_${id}`)),
1165
- releaseSavepoint: releaseSavepoint ? (conn, id) => control(conn, releaseSavepoint(`effect_sql_${id}`)) : void 0,
1166
- commit: typeof commit === "string" ? (conn) => control(conn, commit) : commit,
1167
- onCommitFailure: options.onCommitFailure,
1168
- rollback: (conn) => control(conn, rollback),
1169
- rollbackSavepoint: (conn, id) => control(conn, rollbackSavepoint(`effect_sql_${id}`))
1170
- });
1171
- const reactivity = yield* Reactivity;
1172
- const borrower = options.borrower === void 0 ? void 0 : (f) => flatMap(serviceOption(transactionService), match({
1173
- onNone: () => options.borrower(f),
1174
- onSome: ([conn]) => f(conn)
1175
- }));
1176
- const client = Object.assign(make4(getConnection, options.compiler, options.spanAttributes, options.transformRows, borrower), {
1177
- [TypeId3]: TypeId3,
1178
- safe: void 0,
1179
- withTransaction,
1180
- transactionService,
1181
- reserve: transactionAcquirer,
1182
- withoutTransforms() {
1183
- if (options.transformRows === void 0) {
1184
- return this;
1185
- }
1186
- const statement2 = make4(getConnection, options.compiler.withoutTransform, options.spanAttributes, void 0, borrower);
1187
- const client2 = Object.assign(statement2, {
1188
- ...this,
1189
- ...statement2
1190
- });
1191
- client2.safe = client2;
1192
- client2.withoutTransforms = () => client2;
1193
- return client2;
1194
- },
1195
- reactive: options.reactiveQueue ? (keys, effect2) => options.reactiveQueue(keys, effect2).pipe(map(fromQueue), unwrap) : reactivity.stream,
1196
- reactiveMailbox: options.reactiveQueue ?? reactivity.query
1197
- });
1198
- client.safe = client;
1199
- return client;
1200
- });
1201
- var makeWithTransaction = (options) => {
1202
- const transactionSemaphore = Service(`effect/sql/SqlClient/TransactionSemaphore/${transactionSemaphoreIdCounter++}`);
1203
- return (effect2) => uninterruptibleMask((restore) => useSpan("sql.transaction", {
1204
- kind: "client"
1205
- }, (span) => withFiber((fiber) => {
1206
- for (const [key, value] of options.spanAttributes) {
1207
- span.attribute(key, value);
1208
- }
1209
- const services = fiber.context;
1210
- const clock = fiber.getRef(Clock);
1211
- const connOption = getOption(services, options.transactionService);
1212
- const conn = connOption._tag === "Some" ? succeed([void 0, connOption.value[0]]) : options.acquireConnection;
1213
- const id = connOption._tag === "Some" ? connOption.value[1] + 1 : 0;
1214
- const transaction = flatMap(conn, ([scope2, conn2]) => (id === 0 ? options.begin(conn2) : options.savepoint(conn2, id)).pipe(flatMap(() => onExitPrimitive(provideContext(restore(effect2), services.pipe(add(options.transactionService, [conn2, id]), add(transactionSemaphore, makeUnsafe(1)), add(ParentSpan, span))), (exit) => {
1215
- let effect3;
1216
- if (isSuccess(exit)) {
1217
- if (id === 0) {
1218
- span.event("db.transaction.commit", clock.currentTimeNanosUnsafe());
1219
- const onCommitFailure = options.onCommitFailure;
1220
- effect3 = orDie(options.commit(conn2));
1221
- if (onCommitFailure) {
1222
- effect3 = onError(effect3, () => orDie(onCommitFailure(conn2)));
1223
- }
1224
- } else {
1225
- span.event("db.transaction.savepoint", clock.currentTimeNanosUnsafe());
1226
- effect3 = void_;
1227
- }
1228
- } else {
1229
- span.event("db.transaction.rollback", clock.currentTimeNanosUnsafe());
1230
- effect3 = orDie(id > 0 ? options.rollbackSavepoint(conn2, id) : options.rollback(conn2));
1231
- }
1232
- if (id > 0 && options.releaseSavepoint) {
1233
- effect3 = andThen(effect3, orDie(options.releaseSavepoint(conn2, id)));
1234
- }
1235
- return flatMap(effect3, () => exit);
1236
- }, true)), scope2 ? (eff) => onExitPrimitive(eff, (exit) => close(scope2, exit), true) : identity));
1237
- return id === 0 ? transaction : getUnsafe(services, transactionSemaphore).withPermit(transaction);
1238
- })));
1239
- };
1240
- var TransactionConnection = (clientId) => Service(`effect/sql/SqlClient/TransactionConnection/${clientId}`);
1241
-
1242
- export {
1243
- Reactivity,
1244
- mutation,
1245
- invalidate,
1246
- layer,
1247
- UnknownError,
1248
- SqlError,
1249
- classifySqliteError,
1250
- makeCompilerSqlite,
1251
- defaultTransforms,
1252
- SqlClient,
1253
- make5 as make
1254
- };