@athrio/loom 0.0.9 → 0.0.10
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/dist/Cache-Dv3Qogvb.js +1048 -0
- package/dist/Cache-Dv3Qogvb.js.map +1 -0
- package/dist/{LoomServer-BZL6KQOM.js → LoomServer-JbCtLtxV.js} +4 -2
- package/dist/{LoomServer-BZL6KQOM.js.map → LoomServer-JbCtLtxV.js.map} +1 -1
- package/dist/LoomStore-BGlpRj6W.js +8857 -0
- package/dist/LoomStore-BGlpRj6W.js.map +1 -0
- package/dist/NodeServices-CtEw3D6F.js +1564 -0
- package/dist/NodeServices-CtEw3D6F.js.map +1 -0
- package/dist/{LoomStore-BBRhdzet.js → SqlClient-BHo_uVyk.js} +10062 -46501
- package/dist/SqlClient-BHo_uVyk.js.map +1 -0
- package/dist/SqlError-BwVJTsti.js +408 -0
- package/dist/SqlError-BwVJTsti.js.map +1 -0
- package/dist/design-S_129JVC.js +18524 -0
- package/dist/design-S_129JVC.js.map +1 -0
- package/dist/dist-3ptbWhlX.js +202 -0
- package/dist/dist-3ptbWhlX.js.map +1 -0
- package/dist/dist-CKhPOkpR.js +27469 -0
- package/dist/dist-CKhPOkpR.js.map +1 -0
- package/dist/dist-kscTHM4c.js +151 -0
- package/dist/dist-kscTHM4c.js.map +1 -0
- package/dist/identity-DvFsrt2d.js +95 -0
- package/dist/identity-DvFsrt2d.js.map +1 -0
- package/dist/main.js +260 -1535
- package/dist/main.js.map +1 -1
- package/dist/overlay.js +80 -0
- package/dist/store-CtvrwAS8.js +3 -0
- package/dist/store-DgMmJ7v9.js +229 -0
- package/dist/store-DgMmJ7v9.js.map +1 -0
- package/dist/ui.html +103 -0
- package/dist/ui.js +79 -0
- package/package.json +3 -1
- package/dist/LoomStore-BBRhdzet.js.map +0 -1
|
@@ -0,0 +1,408 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { Bt as Defect, Fn as Union, Sn as TaggedErrorClass, ah as hasProperty, on as Number, ti as optional, vn as String } from "./SqlClient-BHo_uVyk.js";
|
|
3
|
+
//#region ../../node_modules/effect/dist/unstable/sql/SqlError.js
|
|
4
|
+
/**
|
|
5
|
+
* Defines structured failures for SQL clients and driver integrations.
|
|
6
|
+
*
|
|
7
|
+
* `SqlError` wraps the different reasons a SQL operation can fail, such as
|
|
8
|
+
* connection, authentication, authorization, syntax, constraint, or transaction
|
|
9
|
+
* problems. Each reason keeps the original cause, optional message and
|
|
10
|
+
* operation metadata, and whether retrying may succeed. This module also
|
|
11
|
+
* includes schemas, guards, a SQLite error classifier, and the
|
|
12
|
+
* `ResultLengthMismatch` error used by ordered batched SQL resolvers.
|
|
13
|
+
*
|
|
14
|
+
* @since 4.0.0
|
|
15
|
+
*/
|
|
16
|
+
var TypeId = "~effect/sql/SqlError";
|
|
17
|
+
var ReasonTypeId = "~effect/sql/SqlError/Reason";
|
|
18
|
+
var ReasonFields = {
|
|
19
|
+
cause: /*#__PURE__*/ Defect(),
|
|
20
|
+
message: /*#__PURE__*/ optional(String),
|
|
21
|
+
operation: /*#__PURE__*/ optional(String)
|
|
22
|
+
};
|
|
23
|
+
/**
|
|
24
|
+
* SQL error reason for connection or open failures; marked retryable.
|
|
25
|
+
*
|
|
26
|
+
* @category errors
|
|
27
|
+
* @since 4.0.0
|
|
28
|
+
*/
|
|
29
|
+
var ConnectionError = class extends TaggedErrorClass("effect/sql/SqlError/ConnectionError")("ConnectionError", ReasonFields) {
|
|
30
|
+
/**
|
|
31
|
+
* Marks this value as a structured SQL error reason for runtime guards.
|
|
32
|
+
*
|
|
33
|
+
* @since 4.0.0
|
|
34
|
+
*/
|
|
35
|
+
[ReasonTypeId] = ReasonTypeId;
|
|
36
|
+
/**
|
|
37
|
+
* Indicates whether retrying the failed SQL operation may succeed.
|
|
38
|
+
*
|
|
39
|
+
* @since 4.0.0
|
|
40
|
+
*/
|
|
41
|
+
get isRetryable() {
|
|
42
|
+
return true;
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
/**
|
|
46
|
+
* SQL error reason for authentication failures such as invalid credentials; not
|
|
47
|
+
* marked retryable.
|
|
48
|
+
*
|
|
49
|
+
* @category errors
|
|
50
|
+
* @since 4.0.0
|
|
51
|
+
*/
|
|
52
|
+
var AuthenticationError = class extends TaggedErrorClass("effect/sql/SqlError/AuthenticationError")("AuthenticationError", ReasonFields) {
|
|
53
|
+
/**
|
|
54
|
+
* Marks this value as a structured SQL error reason for runtime guards.
|
|
55
|
+
*
|
|
56
|
+
* @since 4.0.0
|
|
57
|
+
*/
|
|
58
|
+
[ReasonTypeId] = ReasonTypeId;
|
|
59
|
+
/**
|
|
60
|
+
* Indicates whether retrying the failed SQL operation may succeed.
|
|
61
|
+
*
|
|
62
|
+
* @since 4.0.0
|
|
63
|
+
*/
|
|
64
|
+
get isRetryable() {
|
|
65
|
+
return false;
|
|
66
|
+
}
|
|
67
|
+
};
|
|
68
|
+
/**
|
|
69
|
+
* SQL error reason for authorization or permission failures; not marked
|
|
70
|
+
* retryable.
|
|
71
|
+
*
|
|
72
|
+
* @category errors
|
|
73
|
+
* @since 4.0.0
|
|
74
|
+
*/
|
|
75
|
+
var AuthorizationError = class extends TaggedErrorClass("effect/sql/SqlError/AuthorizationError")("AuthorizationError", ReasonFields) {
|
|
76
|
+
/**
|
|
77
|
+
* Marks this value as a structured SQL error reason for runtime guards.
|
|
78
|
+
*
|
|
79
|
+
* @since 4.0.0
|
|
80
|
+
*/
|
|
81
|
+
[ReasonTypeId] = ReasonTypeId;
|
|
82
|
+
/**
|
|
83
|
+
* Indicates whether retrying the failed SQL operation may succeed.
|
|
84
|
+
*
|
|
85
|
+
* @since 4.0.0
|
|
86
|
+
*/
|
|
87
|
+
get isRetryable() {
|
|
88
|
+
return false;
|
|
89
|
+
}
|
|
90
|
+
};
|
|
91
|
+
/**
|
|
92
|
+
* SQL error reason for invalid SQL syntax; not marked retryable.
|
|
93
|
+
*
|
|
94
|
+
* @category errors
|
|
95
|
+
* @since 4.0.0
|
|
96
|
+
*/
|
|
97
|
+
var SqlSyntaxError = class extends TaggedErrorClass("effect/sql/SqlError/SqlSyntaxError")("SqlSyntaxError", ReasonFields) {
|
|
98
|
+
/**
|
|
99
|
+
* Marks this value as a structured SQL error reason for runtime guards.
|
|
100
|
+
*
|
|
101
|
+
* @since 4.0.0
|
|
102
|
+
*/
|
|
103
|
+
[ReasonTypeId] = ReasonTypeId;
|
|
104
|
+
/**
|
|
105
|
+
* Indicates whether retrying the failed SQL operation may succeed.
|
|
106
|
+
*
|
|
107
|
+
* @since 4.0.0
|
|
108
|
+
*/
|
|
109
|
+
get isRetryable() {
|
|
110
|
+
return false;
|
|
111
|
+
}
|
|
112
|
+
};
|
|
113
|
+
var UniqueViolationFields = {
|
|
114
|
+
...ReasonFields,
|
|
115
|
+
constraint: String
|
|
116
|
+
};
|
|
117
|
+
/**
|
|
118
|
+
* SQL error reason for a unique constraint violation, including the violated
|
|
119
|
+
* constraint identifier; not marked retryable.
|
|
120
|
+
*
|
|
121
|
+
* @category errors
|
|
122
|
+
* @since 4.0.0
|
|
123
|
+
*/
|
|
124
|
+
var UniqueViolation = class extends TaggedErrorClass("effect/sql/SqlError/UniqueViolation")("UniqueViolation", UniqueViolationFields) {
|
|
125
|
+
/**
|
|
126
|
+
* Marks this value as a structured SQL error reason for runtime guards.
|
|
127
|
+
*
|
|
128
|
+
* @since 4.0.0
|
|
129
|
+
*/
|
|
130
|
+
[ReasonTypeId] = ReasonTypeId;
|
|
131
|
+
/**
|
|
132
|
+
* Indicates whether retrying the failed SQL operation may succeed.
|
|
133
|
+
*
|
|
134
|
+
* @since 4.0.0
|
|
135
|
+
*/
|
|
136
|
+
get isRetryable() {
|
|
137
|
+
return false;
|
|
138
|
+
}
|
|
139
|
+
};
|
|
140
|
+
/**
|
|
141
|
+
* SQL error reason for a non-unique constraint violation; not marked retryable.
|
|
142
|
+
*
|
|
143
|
+
* @category errors
|
|
144
|
+
* @since 4.0.0
|
|
145
|
+
*/
|
|
146
|
+
var ConstraintError = class extends TaggedErrorClass("effect/sql/SqlError/ConstraintError")("ConstraintError", ReasonFields) {
|
|
147
|
+
/**
|
|
148
|
+
* Marks this value as a structured SQL error reason for runtime guards.
|
|
149
|
+
*
|
|
150
|
+
* @since 4.0.0
|
|
151
|
+
*/
|
|
152
|
+
[ReasonTypeId] = ReasonTypeId;
|
|
153
|
+
/**
|
|
154
|
+
* Indicates whether retrying the failed SQL operation may succeed.
|
|
155
|
+
*
|
|
156
|
+
* @since 4.0.0
|
|
157
|
+
*/
|
|
158
|
+
get isRetryable() {
|
|
159
|
+
return false;
|
|
160
|
+
}
|
|
161
|
+
};
|
|
162
|
+
/**
|
|
163
|
+
* SQL error reason for a database deadlock; marked retryable.
|
|
164
|
+
*
|
|
165
|
+
* @category errors
|
|
166
|
+
* @since 4.0.0
|
|
167
|
+
*/
|
|
168
|
+
var DeadlockError = class extends TaggedErrorClass("effect/sql/SqlError/DeadlockError")("DeadlockError", ReasonFields) {
|
|
169
|
+
/**
|
|
170
|
+
* Marks this value as a structured SQL error reason for runtime guards.
|
|
171
|
+
*
|
|
172
|
+
* @since 4.0.0
|
|
173
|
+
*/
|
|
174
|
+
[ReasonTypeId] = ReasonTypeId;
|
|
175
|
+
/**
|
|
176
|
+
* Indicates whether retrying the failed SQL operation may succeed.
|
|
177
|
+
*
|
|
178
|
+
* @since 4.0.0
|
|
179
|
+
*/
|
|
180
|
+
get isRetryable() {
|
|
181
|
+
return true;
|
|
182
|
+
}
|
|
183
|
+
};
|
|
184
|
+
/**
|
|
185
|
+
* SQL error reason for a transaction serialization or isolation conflict;
|
|
186
|
+
* marked retryable.
|
|
187
|
+
*
|
|
188
|
+
* @category errors
|
|
189
|
+
* @since 4.0.0
|
|
190
|
+
*/
|
|
191
|
+
var SerializationError = class extends TaggedErrorClass("effect/sql/SqlError/SerializationError")("SerializationError", ReasonFields) {
|
|
192
|
+
/**
|
|
193
|
+
* Marks this value as a structured SQL error reason for runtime guards.
|
|
194
|
+
*
|
|
195
|
+
* @since 4.0.0
|
|
196
|
+
*/
|
|
197
|
+
[ReasonTypeId] = ReasonTypeId;
|
|
198
|
+
/**
|
|
199
|
+
* Indicates whether retrying the failed SQL operation may succeed.
|
|
200
|
+
*
|
|
201
|
+
* @since 4.0.0
|
|
202
|
+
*/
|
|
203
|
+
get isRetryable() {
|
|
204
|
+
return true;
|
|
205
|
+
}
|
|
206
|
+
};
|
|
207
|
+
/**
|
|
208
|
+
* SQL error reason for timing out while waiting on a database lock; marked
|
|
209
|
+
* retryable.
|
|
210
|
+
*
|
|
211
|
+
* @category errors
|
|
212
|
+
* @since 4.0.0
|
|
213
|
+
*/
|
|
214
|
+
var LockTimeoutError = class extends TaggedErrorClass("effect/sql/SqlError/LockTimeoutError")("LockTimeoutError", ReasonFields) {
|
|
215
|
+
/**
|
|
216
|
+
* Marks this value as a structured SQL error reason for runtime guards.
|
|
217
|
+
*
|
|
218
|
+
* @since 4.0.0
|
|
219
|
+
*/
|
|
220
|
+
[ReasonTypeId] = ReasonTypeId;
|
|
221
|
+
/**
|
|
222
|
+
* Indicates whether retrying the failed SQL operation may succeed.
|
|
223
|
+
*
|
|
224
|
+
* @since 4.0.0
|
|
225
|
+
*/
|
|
226
|
+
get isRetryable() {
|
|
227
|
+
return true;
|
|
228
|
+
}
|
|
229
|
+
};
|
|
230
|
+
/**
|
|
231
|
+
* SQL error reason for a statement or query timeout; marked retryable.
|
|
232
|
+
*
|
|
233
|
+
* @category errors
|
|
234
|
+
* @since 4.0.0
|
|
235
|
+
*/
|
|
236
|
+
var StatementTimeoutError = class extends TaggedErrorClass("effect/sql/SqlError/StatementTimeoutError")("StatementTimeoutError", ReasonFields) {
|
|
237
|
+
/**
|
|
238
|
+
* Marks this value as a structured SQL error reason for runtime guards.
|
|
239
|
+
*
|
|
240
|
+
* @since 4.0.0
|
|
241
|
+
*/
|
|
242
|
+
[ReasonTypeId] = ReasonTypeId;
|
|
243
|
+
/**
|
|
244
|
+
* Indicates whether retrying the failed SQL operation may succeed.
|
|
245
|
+
*
|
|
246
|
+
* @since 4.0.0
|
|
247
|
+
*/
|
|
248
|
+
get isRetryable() {
|
|
249
|
+
return true;
|
|
250
|
+
}
|
|
251
|
+
};
|
|
252
|
+
/**
|
|
253
|
+
* SQL error reason for an unclassified database failure; not marked retryable.
|
|
254
|
+
*
|
|
255
|
+
* @category errors
|
|
256
|
+
* @since 4.0.0
|
|
257
|
+
*/
|
|
258
|
+
var UnknownError = class extends TaggedErrorClass("effect/sql/SqlError/UnknownError")("UnknownError", ReasonFields) {
|
|
259
|
+
/**
|
|
260
|
+
* Marks this value as a structured SQL error reason for runtime guards.
|
|
261
|
+
*
|
|
262
|
+
* @since 4.0.0
|
|
263
|
+
*/
|
|
264
|
+
[ReasonTypeId] = ReasonTypeId;
|
|
265
|
+
/**
|
|
266
|
+
* Indicates whether retrying the failed SQL operation may succeed.
|
|
267
|
+
*
|
|
268
|
+
* @since 4.0.0
|
|
269
|
+
*/
|
|
270
|
+
get isRetryable() {
|
|
271
|
+
return false;
|
|
272
|
+
}
|
|
273
|
+
};
|
|
274
|
+
/**
|
|
275
|
+
* Schema for encoding and decoding SQL error reasons.
|
|
276
|
+
*
|
|
277
|
+
* @category schemas
|
|
278
|
+
* @since 4.0.0
|
|
279
|
+
*/
|
|
280
|
+
var SqlErrorReason = /*#__PURE__*/ Union([
|
|
281
|
+
ConnectionError,
|
|
282
|
+
AuthenticationError,
|
|
283
|
+
AuthorizationError,
|
|
284
|
+
SqlSyntaxError,
|
|
285
|
+
UniqueViolation,
|
|
286
|
+
ConstraintError,
|
|
287
|
+
DeadlockError,
|
|
288
|
+
SerializationError,
|
|
289
|
+
LockTimeoutError,
|
|
290
|
+
StatementTimeoutError,
|
|
291
|
+
UnknownError
|
|
292
|
+
]);
|
|
293
|
+
/**
|
|
294
|
+
* Error wrapper for SQL failures whose `message`, `cause`, and `isRetryable`
|
|
295
|
+
* values are derived from its `SqlErrorReason`.
|
|
296
|
+
*
|
|
297
|
+
* @category errors
|
|
298
|
+
* @since 4.0.0
|
|
299
|
+
*/
|
|
300
|
+
var SqlError = class extends TaggedErrorClass("effect/sql/SqlError")("SqlError", { reason: SqlErrorReason }) {
|
|
301
|
+
/**
|
|
302
|
+
* Marks this value as the top-level SQL error wrapper for runtime guards.
|
|
303
|
+
*
|
|
304
|
+
* @since 4.0.0
|
|
305
|
+
*/
|
|
306
|
+
[TypeId] = TypeId;
|
|
307
|
+
/**
|
|
308
|
+
* Exposes the structured SQL reason as the JavaScript error cause.
|
|
309
|
+
*
|
|
310
|
+
* @since 4.0.0
|
|
311
|
+
*/
|
|
312
|
+
cause = this.reason;
|
|
313
|
+
/**
|
|
314
|
+
* Uses the reason message when present, otherwise falls back to the reason tag.
|
|
315
|
+
*
|
|
316
|
+
* @since 4.0.0
|
|
317
|
+
*/
|
|
318
|
+
get message() {
|
|
319
|
+
return this.reason.message || this.reason._tag;
|
|
320
|
+
}
|
|
321
|
+
/**
|
|
322
|
+
* Delegates retryability to the underlying SQL error reason.
|
|
323
|
+
*
|
|
324
|
+
* @since 4.0.0
|
|
325
|
+
*/
|
|
326
|
+
get isRetryable() {
|
|
327
|
+
return this.reason.isRetryable;
|
|
328
|
+
}
|
|
329
|
+
};
|
|
330
|
+
var sqliteCodeFromCause = (cause) => {
|
|
331
|
+
if (!hasProperty(cause, "code")) return;
|
|
332
|
+
const code = cause.code;
|
|
333
|
+
return typeof code === "string" || typeof code === "number" ? code : void 0;
|
|
334
|
+
};
|
|
335
|
+
var sqliteNumericCodeFromCause = (cause) => {
|
|
336
|
+
const code = sqliteCodeFromCause(cause);
|
|
337
|
+
if (typeof code === "number") return code;
|
|
338
|
+
if (!hasProperty(cause, "errno")) return;
|
|
339
|
+
const errno = cause.errno;
|
|
340
|
+
return typeof errno === "number" ? errno : void 0;
|
|
341
|
+
};
|
|
342
|
+
var matchesSqliteNumericCode = (cause, expected) => {
|
|
343
|
+
if (sqliteCodeFromCause(cause) === expected) return true;
|
|
344
|
+
if (!hasProperty(cause, "errno")) return false;
|
|
345
|
+
return cause.errno === expected;
|
|
346
|
+
};
|
|
347
|
+
var matchesSqliteCode = (code, expected) => code === expected || code.startsWith(expected + "_");
|
|
348
|
+
var UNKNOWN_CONSTRAINT = "unknown";
|
|
349
|
+
var SQLITE_CONSTRAINT_UNIQUE = "SQLITE_CONSTRAINT_UNIQUE";
|
|
350
|
+
var SQLITE_CONSTRAINT_UNIQUE_CODE = 2067;
|
|
351
|
+
var normalizeConstraintIdentifier = (identifier) => {
|
|
352
|
+
if (typeof identifier !== "string") return UNKNOWN_CONSTRAINT;
|
|
353
|
+
const trimmed = identifier.trim();
|
|
354
|
+
return trimmed.length === 0 ? UNKNOWN_CONSTRAINT : trimmed;
|
|
355
|
+
};
|
|
356
|
+
var sqliteUniqueConstraintFromCause = (cause) => {
|
|
357
|
+
if (hasProperty(cause, "constraint")) return normalizeConstraintIdentifier(cause.constraint);
|
|
358
|
+
if (!hasProperty(cause, "message")) return UNKNOWN_CONSTRAINT;
|
|
359
|
+
const message = cause.message;
|
|
360
|
+
if (typeof message !== "string") return UNKNOWN_CONSTRAINT;
|
|
361
|
+
const index = message.indexOf("UNIQUE constraint failed:");
|
|
362
|
+
return index === -1 ? UNKNOWN_CONSTRAINT : normalizeConstraintIdentifier(message.slice(index + 25));
|
|
363
|
+
};
|
|
364
|
+
/**
|
|
365
|
+
* Classifies a native SQLite error cause into a `SqlErrorReason` using its
|
|
366
|
+
* `code` or `errno`, with optional message and operation metadata.
|
|
367
|
+
*
|
|
368
|
+
* @category converting
|
|
369
|
+
* @since 4.0.0
|
|
370
|
+
*/
|
|
371
|
+
var classifySqliteError = (cause, { message, operation } = {}) => {
|
|
372
|
+
const props = {
|
|
373
|
+
cause,
|
|
374
|
+
message,
|
|
375
|
+
operation
|
|
376
|
+
};
|
|
377
|
+
const code = sqliteCodeFromCause(cause);
|
|
378
|
+
const numericCode = sqliteNumericCodeFromCause(cause);
|
|
379
|
+
if (code === SQLITE_CONSTRAINT_UNIQUE || matchesSqliteNumericCode(cause, SQLITE_CONSTRAINT_UNIQUE_CODE)) return new UniqueViolation({
|
|
380
|
+
...props,
|
|
381
|
+
constraint: sqliteUniqueConstraintFromCause(cause)
|
|
382
|
+
});
|
|
383
|
+
if (typeof code === "string") {
|
|
384
|
+
if (matchesSqliteCode(code, "SQLITE_AUTH")) return new AuthenticationError(props);
|
|
385
|
+
if (matchesSqliteCode(code, "SQLITE_PERM")) return new AuthorizationError(props);
|
|
386
|
+
if (matchesSqliteCode(code, "SQLITE_CONSTRAINT")) return new ConstraintError(props);
|
|
387
|
+
if (matchesSqliteCode(code, "SQLITE_BUSY") || matchesSqliteCode(code, "SQLITE_LOCKED")) return new LockTimeoutError(props);
|
|
388
|
+
if (matchesSqliteCode(code, "SQLITE_CANTOPEN")) return new ConnectionError(props);
|
|
389
|
+
}
|
|
390
|
+
if (typeof numericCode === "number") switch (numericCode & 255) {
|
|
391
|
+
case 23: return new AuthenticationError(props);
|
|
392
|
+
case 3: return new AuthorizationError(props);
|
|
393
|
+
case 19: return new ConstraintError(props);
|
|
394
|
+
case 5:
|
|
395
|
+
case 6: return new LockTimeoutError(props);
|
|
396
|
+
case 14: return new ConnectionError(props);
|
|
397
|
+
default: return new UnknownError(props);
|
|
398
|
+
}
|
|
399
|
+
return new UnknownError(props);
|
|
400
|
+
};
|
|
401
|
+
TaggedErrorClass("effect/sql/ResultLengthMismatch")("ResultLengthMismatch", {
|
|
402
|
+
expected: Number,
|
|
403
|
+
actual: Number
|
|
404
|
+
});
|
|
405
|
+
//#endregion
|
|
406
|
+
export { classifySqliteError as n, SqlError as t };
|
|
407
|
+
|
|
408
|
+
//# sourceMappingURL=SqlError-BwVJTsti.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SqlError-BwVJTsti.js","names":["Schema.String","Schema.TaggedErrorClass","Predicate.hasProperty","Schema.Number"],"sources":["../../../node_modules/effect/dist/unstable/sql/SqlError.js"],"sourcesContent":["/**\n * Defines structured failures for SQL clients and driver integrations.\n *\n * `SqlError` wraps the different reasons a SQL operation can fail, such as\n * connection, authentication, authorization, syntax, constraint, or transaction\n * problems. Each reason keeps the original cause, optional message and\n * operation metadata, and whether retrying may succeed. This module also\n * includes schemas, guards, a SQLite error classifier, and the\n * `ResultLengthMismatch` error used by ordered batched SQL resolvers.\n *\n * @since 4.0.0\n */\nimport * as Predicate from \"../../Predicate.js\";\nimport * as Schema from \"../../Schema.js\";\nconst TypeId = \"~effect/sql/SqlError\";\nconst ReasonTypeId = \"~effect/sql/SqlError/Reason\";\nconst ReasonFields = {\n cause: /*#__PURE__*/Schema.Defect(),\n message: /*#__PURE__*/Schema.optional(Schema.String),\n operation: /*#__PURE__*/Schema.optional(Schema.String)\n};\n/**\n * SQL error reason for connection or open failures; marked retryable.\n *\n * @category errors\n * @since 4.0.0\n */\nexport class ConnectionError extends /*#__PURE__*/Schema.TaggedErrorClass(\"effect/sql/SqlError/ConnectionError\")(\"ConnectionError\", ReasonFields) {\n /**\n * Marks this value as a structured SQL error reason for runtime guards.\n *\n * @since 4.0.0\n */\n [ReasonTypeId] = ReasonTypeId;\n /**\n * Indicates whether retrying the failed SQL operation may succeed.\n *\n * @since 4.0.0\n */\n get isRetryable() {\n return true;\n }\n}\n/**\n * SQL error reason for authentication failures such as invalid credentials; not\n * marked retryable.\n *\n * @category errors\n * @since 4.0.0\n */\nexport class AuthenticationError extends /*#__PURE__*/Schema.TaggedErrorClass(\"effect/sql/SqlError/AuthenticationError\")(\"AuthenticationError\", ReasonFields) {\n /**\n * Marks this value as a structured SQL error reason for runtime guards.\n *\n * @since 4.0.0\n */\n [ReasonTypeId] = ReasonTypeId;\n /**\n * Indicates whether retrying the failed SQL operation may succeed.\n *\n * @since 4.0.0\n */\n get isRetryable() {\n return false;\n }\n}\n/**\n * SQL error reason for authorization or permission failures; not marked\n * retryable.\n *\n * @category errors\n * @since 4.0.0\n */\nexport class AuthorizationError extends /*#__PURE__*/Schema.TaggedErrorClass(\"effect/sql/SqlError/AuthorizationError\")(\"AuthorizationError\", ReasonFields) {\n /**\n * Marks this value as a structured SQL error reason for runtime guards.\n *\n * @since 4.0.0\n */\n [ReasonTypeId] = ReasonTypeId;\n /**\n * Indicates whether retrying the failed SQL operation may succeed.\n *\n * @since 4.0.0\n */\n get isRetryable() {\n return false;\n }\n}\n/**\n * SQL error reason for invalid SQL syntax; not marked retryable.\n *\n * @category errors\n * @since 4.0.0\n */\nexport class SqlSyntaxError extends /*#__PURE__*/Schema.TaggedErrorClass(\"effect/sql/SqlError/SqlSyntaxError\")(\"SqlSyntaxError\", ReasonFields) {\n /**\n * Marks this value as a structured SQL error reason for runtime guards.\n *\n * @since 4.0.0\n */\n [ReasonTypeId] = ReasonTypeId;\n /**\n * Indicates whether retrying the failed SQL operation may succeed.\n *\n * @since 4.0.0\n */\n get isRetryable() {\n return false;\n }\n}\nconst UniqueViolationFields = {\n ...ReasonFields,\n constraint: Schema.String\n};\n/**\n * SQL error reason for a unique constraint violation, including the violated\n * constraint identifier; not marked retryable.\n *\n * @category errors\n * @since 4.0.0\n */\nexport class UniqueViolation extends /*#__PURE__*/Schema.TaggedErrorClass(\"effect/sql/SqlError/UniqueViolation\")(\"UniqueViolation\", UniqueViolationFields) {\n /**\n * Marks this value as a structured SQL error reason for runtime guards.\n *\n * @since 4.0.0\n */\n [ReasonTypeId] = ReasonTypeId;\n /**\n * Indicates whether retrying the failed SQL operation may succeed.\n *\n * @since 4.0.0\n */\n get isRetryable() {\n return false;\n }\n}\n/**\n * SQL error reason for a non-unique constraint violation; not marked retryable.\n *\n * @category errors\n * @since 4.0.0\n */\nexport class ConstraintError extends /*#__PURE__*/Schema.TaggedErrorClass(\"effect/sql/SqlError/ConstraintError\")(\"ConstraintError\", ReasonFields) {\n /**\n * Marks this value as a structured SQL error reason for runtime guards.\n *\n * @since 4.0.0\n */\n [ReasonTypeId] = ReasonTypeId;\n /**\n * Indicates whether retrying the failed SQL operation may succeed.\n *\n * @since 4.0.0\n */\n get isRetryable() {\n return false;\n }\n}\n/**\n * SQL error reason for a database deadlock; marked retryable.\n *\n * @category errors\n * @since 4.0.0\n */\nexport class DeadlockError extends /*#__PURE__*/Schema.TaggedErrorClass(\"effect/sql/SqlError/DeadlockError\")(\"DeadlockError\", ReasonFields) {\n /**\n * Marks this value as a structured SQL error reason for runtime guards.\n *\n * @since 4.0.0\n */\n [ReasonTypeId] = ReasonTypeId;\n /**\n * Indicates whether retrying the failed SQL operation may succeed.\n *\n * @since 4.0.0\n */\n get isRetryable() {\n return true;\n }\n}\n/**\n * SQL error reason for a transaction serialization or isolation conflict;\n * marked retryable.\n *\n * @category errors\n * @since 4.0.0\n */\nexport class SerializationError extends /*#__PURE__*/Schema.TaggedErrorClass(\"effect/sql/SqlError/SerializationError\")(\"SerializationError\", ReasonFields) {\n /**\n * Marks this value as a structured SQL error reason for runtime guards.\n *\n * @since 4.0.0\n */\n [ReasonTypeId] = ReasonTypeId;\n /**\n * Indicates whether retrying the failed SQL operation may succeed.\n *\n * @since 4.0.0\n */\n get isRetryable() {\n return true;\n }\n}\n/**\n * SQL error reason for timing out while waiting on a database lock; marked\n * retryable.\n *\n * @category errors\n * @since 4.0.0\n */\nexport class LockTimeoutError extends /*#__PURE__*/Schema.TaggedErrorClass(\"effect/sql/SqlError/LockTimeoutError\")(\"LockTimeoutError\", ReasonFields) {\n /**\n * Marks this value as a structured SQL error reason for runtime guards.\n *\n * @since 4.0.0\n */\n [ReasonTypeId] = ReasonTypeId;\n /**\n * Indicates whether retrying the failed SQL operation may succeed.\n *\n * @since 4.0.0\n */\n get isRetryable() {\n return true;\n }\n}\n/**\n * SQL error reason for a statement or query timeout; marked retryable.\n *\n * @category errors\n * @since 4.0.0\n */\nexport class StatementTimeoutError extends /*#__PURE__*/Schema.TaggedErrorClass(\"effect/sql/SqlError/StatementTimeoutError\")(\"StatementTimeoutError\", ReasonFields) {\n /**\n * Marks this value as a structured SQL error reason for runtime guards.\n *\n * @since 4.0.0\n */\n [ReasonTypeId] = ReasonTypeId;\n /**\n * Indicates whether retrying the failed SQL operation may succeed.\n *\n * @since 4.0.0\n */\n get isRetryable() {\n return true;\n }\n}\n/**\n * SQL error reason for an unclassified database failure; not marked retryable.\n *\n * @category errors\n * @since 4.0.0\n */\nexport class UnknownError extends /*#__PURE__*/Schema.TaggedErrorClass(\"effect/sql/SqlError/UnknownError\")(\"UnknownError\", ReasonFields) {\n /**\n * Marks this value as a structured SQL error reason for runtime guards.\n *\n * @since 4.0.0\n */\n [ReasonTypeId] = ReasonTypeId;\n /**\n * Indicates whether retrying the failed SQL operation may succeed.\n *\n * @since 4.0.0\n */\n get isRetryable() {\n return false;\n }\n}\n/**\n * Schema for encoding and decoding SQL error reasons.\n *\n * @category schemas\n * @since 4.0.0\n */\nexport const SqlErrorReason = /*#__PURE__*/Schema.Union([ConnectionError, AuthenticationError, AuthorizationError, SqlSyntaxError, UniqueViolation, ConstraintError, DeadlockError, SerializationError, LockTimeoutError, StatementTimeoutError, UnknownError]);\n/**\n * Error wrapper for SQL failures whose `message`, `cause`, and `isRetryable`\n * values are derived from its `SqlErrorReason`.\n *\n * @category errors\n * @since 4.0.0\n */\nexport class SqlError extends /*#__PURE__*/Schema.TaggedErrorClass(\"effect/sql/SqlError\")(\"SqlError\", {\n reason: SqlErrorReason\n}) {\n /**\n * Marks this value as the top-level SQL error wrapper for runtime guards.\n *\n * @since 4.0.0\n */\n [TypeId] = TypeId;\n /**\n * Exposes the structured SQL reason as the JavaScript error cause.\n *\n * @since 4.0.0\n */\n cause = this.reason;\n /**\n * Uses the reason message when present, otherwise falls back to the reason tag.\n *\n * @since 4.0.0\n */\n get message() {\n return this.reason.message || this.reason._tag;\n }\n /**\n * Delegates retryability to the underlying SQL error reason.\n *\n * @since 4.0.0\n */\n get isRetryable() {\n return this.reason.isRetryable;\n }\n}\n/**\n * Returns `true` when a value is a `SqlError`.\n *\n * @category guards\n * @since 4.0.0\n */\nexport const isSqlError = u => Predicate.hasProperty(u, TypeId);\n/**\n * Returns `true` when a value is a `SqlErrorReason`.\n *\n * @category guards\n * @since 4.0.0\n */\nexport const isSqlErrorReason = u => Predicate.hasProperty(u, ReasonTypeId);\nconst sqliteCodeFromCause = cause => {\n if (!Predicate.hasProperty(cause, \"code\")) {\n return undefined;\n }\n const code = cause.code;\n return typeof code === \"string\" || typeof code === \"number\" ? code : undefined;\n};\nconst sqliteNumericCodeFromCause = cause => {\n const code = sqliteCodeFromCause(cause);\n if (typeof code === \"number\") {\n return code;\n }\n if (!Predicate.hasProperty(cause, \"errno\")) {\n return undefined;\n }\n const errno = cause.errno;\n return typeof errno === \"number\" ? errno : undefined;\n};\nconst matchesSqliteNumericCode = (cause, expected) => {\n const code = sqliteCodeFromCause(cause);\n if (code === expected) {\n return true;\n }\n if (!Predicate.hasProperty(cause, \"errno\")) {\n return false;\n }\n return cause.errno === expected;\n};\nconst matchesSqliteCode = (code, expected) => code === expected || code.startsWith(expected + \"_\");\nconst UNKNOWN_CONSTRAINT = \"unknown\";\nconst SQLITE_CONSTRAINT_UNIQUE = \"SQLITE_CONSTRAINT_UNIQUE\";\nconst SQLITE_CONSTRAINT_UNIQUE_CODE = 2067;\nconst normalizeConstraintIdentifier = identifier => {\n if (typeof identifier !== \"string\") {\n return UNKNOWN_CONSTRAINT;\n }\n const trimmed = identifier.trim();\n return trimmed.length === 0 ? UNKNOWN_CONSTRAINT : trimmed;\n};\nconst sqliteUniqueConstraintFromCause = cause => {\n if (Predicate.hasProperty(cause, \"constraint\")) {\n return normalizeConstraintIdentifier(cause.constraint);\n }\n if (!Predicate.hasProperty(cause, \"message\")) {\n return UNKNOWN_CONSTRAINT;\n }\n const message = cause.message;\n if (typeof message !== \"string\") {\n return UNKNOWN_CONSTRAINT;\n }\n const prefix = \"UNIQUE constraint failed:\";\n const index = message.indexOf(prefix);\n return index === -1 ? UNKNOWN_CONSTRAINT : normalizeConstraintIdentifier(message.slice(index + prefix.length));\n};\n/**\n * Classifies a native SQLite error cause into a `SqlErrorReason` using its\n * `code` or `errno`, with optional message and operation metadata.\n *\n * @category converting\n * @since 4.0.0\n */\nexport const classifySqliteError = (cause, {\n message,\n operation\n} = {}) => {\n const props = {\n cause,\n message,\n operation\n };\n const code = sqliteCodeFromCause(cause);\n const numericCode = sqliteNumericCodeFromCause(cause);\n if (code === SQLITE_CONSTRAINT_UNIQUE || matchesSqliteNumericCode(cause, SQLITE_CONSTRAINT_UNIQUE_CODE)) {\n return new UniqueViolation({\n ...props,\n constraint: sqliteUniqueConstraintFromCause(cause)\n });\n }\n if (typeof code === \"string\") {\n if (matchesSqliteCode(code, \"SQLITE_AUTH\")) {\n return new AuthenticationError(props);\n }\n if (matchesSqliteCode(code, \"SQLITE_PERM\")) {\n return new AuthorizationError(props);\n }\n if (matchesSqliteCode(code, \"SQLITE_CONSTRAINT\")) {\n return new ConstraintError(props);\n }\n if (matchesSqliteCode(code, \"SQLITE_BUSY\") || matchesSqliteCode(code, \"SQLITE_LOCKED\")) {\n return new LockTimeoutError(props);\n }\n if (matchesSqliteCode(code, \"SQLITE_CANTOPEN\")) {\n return new ConnectionError(props);\n }\n }\n if (typeof numericCode === \"number\") {\n const code = numericCode & 0xff;\n switch (code) {\n case 23:\n return new AuthenticationError(props);\n case 3:\n return new AuthorizationError(props);\n case 19:\n return new ConstraintError(props);\n case 5:\n case 6:\n return new LockTimeoutError(props);\n case 14:\n return new ConnectionError(props);\n default:\n return new UnknownError(props);\n }\n }\n return new UnknownError(props);\n};\n/**\n * Error raised when an ordered batched SQL resolver receives a different number\n * of result rows than requests.\n *\n * @category errors\n * @since 4.0.0\n */\nexport class ResultLengthMismatch extends /*#__PURE__*/Schema.TaggedErrorClass(\"effect/sql/ResultLengthMismatch\")(\"ResultLengthMismatch\", {\n expected: Schema.Number,\n actual: Schema.Number\n}) {\n /**\n * Explains the mismatch between expected and actual batched SQL result counts.\n *\n * @since 4.0.0\n */\n get message() {\n return `Expected ${this.expected} results but got ${this.actual}`;\n }\n}\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