@velarscript-labs/sqlite 0.2.1 → 0.2.2

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/index.js ADDED
@@ -0,0 +1,1512 @@
1
+ // velar-standard:velar/compiler-runtime-reactive-v1
2
+ var __velarReactiveStructureKey = null;
3
+ function __velarReactiveRaw(value) {
4
+ return value;
5
+ }
6
+ function __velarHostRaw(value) {
7
+ return value;
8
+ }
9
+ function __velarReactiveCollectionRead(value, key, child) {
10
+ return child === void 0 ? null : child;
11
+ }
12
+ function __velarReactiveCollectionTrack() {
13
+ }
14
+ function __velarReactiveCollectionLink() {
15
+ }
16
+ function __velarReactiveCollectionTrigger() {
17
+ }
18
+
19
+ // velar-standard:velar/compiler-runtime-class-fields-v1
20
+ var __velarClassNativeObject = globalThis.Object;
21
+ var __velarClassNativeReflect = globalThis.Reflect;
22
+ var __velarClassNativeTypeError = globalThis.TypeError;
23
+ var __velarClassGetOwnPropertyDescriptor = __velarClassNativeObject.getOwnPropertyDescriptor;
24
+ var __velarClassReflectApply = __velarClassGetOwnPropertyDescriptor(__velarClassNativeReflect, "apply")?.value;
25
+ var __velarClassReflectGet = __velarClassGetOwnPropertyDescriptor(__velarClassNativeReflect, "get")?.value;
26
+ var __velarClassGetPrototypeOf = __velarClassGetOwnPropertyDescriptor(__velarClassNativeObject, "getPrototypeOf")?.value;
27
+ function __velarClassHostCall(operation, receiver, arguments_) {
28
+ if (typeof operation !== "function" || typeof __velarClassReflectApply !== "function") throw new __velarClassNativeTypeError("The JavaScript class field runtime is unavailable");
29
+ return __velarClassReflectApply(operation, receiver, arguments_);
30
+ }
31
+ function __velarReadInstanceField(receiver, name) {
32
+ const value = __velarClassHostCall(__velarClassReflectGet, __velarClassNativeReflect, [receiver, name]);
33
+ if (value === void 0) throw new __velarClassNativeTypeError("Field '" + name + "' was read before initialization or contains undefined");
34
+ return value;
35
+ }
36
+ function __velarReadPrivateField(value, name) {
37
+ if (value === void 0) throw new __velarClassNativeTypeError("Private field '" + name + "' was read before initialization or contains undefined");
38
+ return value;
39
+ }
40
+
41
+ // velar-standard:velar/compiler-runtime-narrowing-v1
42
+ var __velarNarrowingNativeTypeError = globalThis.TypeError;
43
+ var __velarNarrowingDefineProperty = globalThis.Object.defineProperty;
44
+ var __VelarNarrowingError = class extends __velarNarrowingNativeTypeError {
45
+ constructor(message) {
46
+ super(message);
47
+ this.name = "NarrowingError";
48
+ }
49
+ };
50
+ __velarNarrowingDefineProperty(__VelarNarrowingError, "name", { value: "NarrowingError", writable: false, enumerable: false, configurable: true });
51
+ function __velarNarrow(value, valid, expected, description, offset) {
52
+ if (!valid) throw new __VelarNarrowingError("Flow narrowing for '" + description + "' no longer holds: expected " + expected + " at source offset " + offset);
53
+ return value;
54
+ }
55
+
56
+ // velar-standard:velar/compiler-runtime-promises-v1
57
+ var __velarNormalizeGlobal = globalThis;
58
+ var __velarNormalizeNativeObject = globalThis.Object;
59
+ var __velarNormalizeNativeReflect = globalThis.Reflect;
60
+ var __velarNormalizeNativeWeakMap = globalThis.WeakMap;
61
+ var __velarNormalizeNativePromise = globalThis.Promise;
62
+ var __velarNormalizeNativeSymbol = globalThis.Symbol;
63
+ var __velarNormalizeTypeError = globalThis.TypeError;
64
+ var __velarNormalizeGetOwnPropertyDescriptor = __velarNormalizeNativeObject.getOwnPropertyDescriptor;
65
+ var __velarNormalizeGetPrototypeOf = __velarNormalizeGetOwnPropertyDescriptor(__velarNormalizeNativeObject, "getPrototypeOf")?.value;
66
+ var __velarNormalizeDefineProperty = __velarNormalizeGetOwnPropertyDescriptor(__velarNormalizeNativeObject, "defineProperty")?.value;
67
+ var __velarNormalizeApply = __velarNormalizeGetOwnPropertyDescriptor(__velarNormalizeNativeReflect, "apply")?.value;
68
+ var __velarNormalizeWeakMapPrototype = __velarNormalizeGetOwnPropertyDescriptor(__velarNormalizeNativeWeakMap, "prototype")?.value;
69
+ var __velarNormalizeWeakMapHas = __velarNormalizeGetOwnPropertyDescriptor(__velarNormalizeWeakMapPrototype, "has")?.value;
70
+ var __velarNormalizeWeakMapGet = __velarNormalizeGetOwnPropertyDescriptor(__velarNormalizeWeakMapPrototype, "get")?.value;
71
+ var __velarNormalizeWeakMapSet = __velarNormalizeGetOwnPropertyDescriptor(__velarNormalizeWeakMapPrototype, "set")?.value;
72
+ var __velarNormalizePromisePrototype = __velarNormalizeGetOwnPropertyDescriptor(__velarNormalizeNativePromise, "prototype")?.value;
73
+ var __velarNormalizePromiseThen = __velarNormalizeGetOwnPropertyDescriptor(__velarNormalizePromisePrototype, "then")?.value;
74
+ var __velarNormalizeSymbolFor = __velarNormalizeGetOwnPropertyDescriptor(__velarNormalizeNativeSymbol, "for")?.value;
75
+ function __velarNormalizeCall(operation, receiver, arguments_) {
76
+ if (typeof operation !== "function" || typeof __velarNormalizeApply !== "function") throw new __velarNormalizeTypeError("The JavaScript Promise normalization runtime is unavailable");
77
+ return __velarNormalizeApply(operation, receiver, arguments_);
78
+ }
79
+ var __velarNormalizedPromiseRegistryKey = __velarNormalizeCall(__velarNormalizeSymbolFor, __velarNormalizeNativeSymbol, ["velar.promise.normalization.v1"]);
80
+ var __velarNormalizedPromiseValues = (() => {
81
+ const descriptor = __velarNormalizeCall(__velarNormalizeGetOwnPropertyDescriptor, __velarNormalizeNativeObject, [__velarNormalizeGlobal, __velarNormalizedPromiseRegistryKey]);
82
+ if (descriptor) {
83
+ if (!("value" in descriptor) || descriptor.enumerable || descriptor.configurable || descriptor.writable) {
84
+ throw new __velarNormalizeTypeError("VelarScript Promise normalization registry ownership is invalid");
85
+ }
86
+ try {
87
+ __velarNormalizeCall(__velarNormalizeWeakMapHas, descriptor.value, [descriptor.value]);
88
+ } catch {
89
+ throw new __velarNormalizeTypeError("VelarScript Promise normalization registry is invalid");
90
+ }
91
+ return descriptor.value;
92
+ }
93
+ const registry = new __velarNormalizeNativeWeakMap();
94
+ __velarNormalizeCall(__velarNormalizeDefineProperty, __velarNormalizeNativeObject, [__velarNormalizeGlobal, __velarNormalizedPromiseRegistryKey, {
95
+ value: registry,
96
+ enumerable: false,
97
+ configurable: false,
98
+ writable: false
99
+ }]);
100
+ return registry;
101
+ })();
102
+ function __velarNormalizeOwnsPromise(candidate) {
103
+ if (typeof candidate !== "object" && typeof candidate !== "function" || candidate === null) return false;
104
+ let prototype;
105
+ try {
106
+ prototype = __velarNormalizeCall(__velarNormalizeGetPrototypeOf, __velarNormalizeNativeObject, [candidate]);
107
+ } catch {
108
+ return false;
109
+ }
110
+ return prototype === __velarNormalizePromisePrototype;
111
+ }
112
+ function __velarNormalizePromiseValue(value) {
113
+ if (typeof value !== "object" && typeof value !== "function" || value === null) throw new __velarNormalizeTypeError("Expected an actual Promise");
114
+ const known = __velarNormalizeCall(__velarNormalizeWeakMapGet, __velarNormalizedPromiseValues, [value]);
115
+ if (known) return known;
116
+ let settle;
117
+ let fail;
118
+ try {
119
+ __velarNormalizeCall(__velarNormalizePromiseThen, value, [
120
+ (resolved) => {
121
+ if (typeof settle === "function") settle(resolved ?? null);
122
+ },
123
+ (reason) => {
124
+ if (typeof fail === "function") fail(reason);
125
+ }
126
+ ]);
127
+ } catch {
128
+ throw new __velarNormalizeTypeError("Expected an actual Promise");
129
+ }
130
+ if (typeof __velarNormalizeNativePromise !== "function") throw new __velarNormalizeTypeError("The JavaScript Promise normalization runtime is unavailable");
131
+ const normalized = new __velarNormalizeNativePromise((resolve, reject) => {
132
+ settle = resolve;
133
+ fail = reject;
134
+ });
135
+ if (typeof settle !== "function" || typeof fail !== "function" || !__velarNormalizeOwnsPromise(normalized)) throw new __velarNormalizeTypeError("The JavaScript Promise normalization runtime is unavailable");
136
+ __velarNormalizeCall(__velarNormalizeWeakMapSet, __velarNormalizedPromiseValues, [value, normalized]);
137
+ __velarNormalizeCall(__velarNormalizeWeakMapSet, __velarNormalizedPromiseValues, [normalized, normalized]);
138
+ return normalized;
139
+ }
140
+ function __velarAsyncResolvedValue(value) {
141
+ if (value === void 0) return null;
142
+ if (typeof value !== "object" && typeof value !== "function" || value === null) return value;
143
+ try {
144
+ return __velarNormalizePromiseValue(value);
145
+ } catch {
146
+ }
147
+ let owner = value;
148
+ for (let depth = 0; owner !== null && depth < 128; depth += 1) {
149
+ let descriptor;
150
+ try {
151
+ descriptor = __velarNormalizeCall(__velarNormalizeGetOwnPropertyDescriptor, __velarNormalizeNativeObject, [owner, "then"]);
152
+ } catch {
153
+ throw new __velarNormalizeTypeError("An async result must not expose a callable 'then' or a 'then' getter");
154
+ }
155
+ if (descriptor) {
156
+ if (!("value" in descriptor) || typeof descriptor.value === "function") throw new __velarNormalizeTypeError("An async result must not expose a callable 'then' or a 'then' getter");
157
+ return value;
158
+ }
159
+ try {
160
+ owner = __velarNormalizeCall(__velarNormalizeGetPrototypeOf, __velarNormalizeNativeObject, [owner]);
161
+ } catch {
162
+ throw new __velarNormalizeTypeError("An async result must have an inspectable prototype chain");
163
+ }
164
+ }
165
+ if (owner !== null) throw new __velarNormalizeTypeError("An async result prototype chain is too deep");
166
+ return value;
167
+ }
168
+
169
+ // velar-standard:velar/compiler-runtime-errors-v1
170
+ var __velarErrorNativeError = globalThis.Error;
171
+ var __velarErrorNativeString = globalThis.String;
172
+ var __velarErrorNativeObject = globalThis.Object;
173
+ var __velarErrorNativeReflect = globalThis.Reflect;
174
+ var __velarErrorNativeTypeError = globalThis.TypeError;
175
+ var __velarErrorGetOwnPropertyDescriptor = __velarErrorNativeObject.getOwnPropertyDescriptor;
176
+ var __velarErrorGetPrototypeOf = __velarErrorNativeObject.getPrototypeOf;
177
+ var __velarErrorReflectApply = __velarErrorGetOwnPropertyDescriptor(__velarErrorNativeReflect, "apply")?.value;
178
+ var __velarErrorIsErrorOperation = __velarErrorGetOwnPropertyDescriptor(__velarErrorNativeError, "isError")?.value;
179
+ function __velarErrorApply(operation, receiver, arguments_, label) {
180
+ if (typeof operation !== "function" || typeof __velarErrorReflectApply !== "function") {
181
+ throw new __velarErrorNativeTypeError("The JavaScript " + label + " API is unavailable");
182
+ }
183
+ return __velarErrorReflectApply(operation, receiver, arguments_);
184
+ }
185
+ function __velarIsError(value) {
186
+ return __velarErrorApply(__velarErrorIsErrorOperation, __velarErrorNativeError, [value], "Error.isError");
187
+ }
188
+ function __velarNormalizeError(value) {
189
+ if (__velarIsError(value)) return value;
190
+ const kind = typeof value;
191
+ let message;
192
+ if (kind === "string") message = value;
193
+ else if (value === null) message = "null";
194
+ else if (kind === "undefined") message = "undefined";
195
+ else if (kind === "number" || kind === "boolean" || kind === "bigint" || kind === "symbol") {
196
+ message = __velarErrorApply(__velarErrorNativeString, globalThis, [value], "String");
197
+ } else message = "A non-Error value was thrown by JavaScript";
198
+ return new __velarErrorNativeError(message, { cause: value });
199
+ }
200
+ var __velarAssertionNativeError = globalThis.Error;
201
+ var __velarAssertionDefineProperty = globalThis.Object.defineProperty;
202
+ var __VelarAssertionError = class extends __velarAssertionNativeError {
203
+ constructor(message) {
204
+ super(message);
205
+ this.name = "AssertionError";
206
+ }
207
+ };
208
+ __velarAssertionDefineProperty(__VelarAssertionError, "name", { value: "AssertionError", writable: false, enumerable: false, configurable: true });
209
+ var __velarHostErrorNativeError = globalThis.Error;
210
+ var __velarHostErrorDefineProperty = globalThis.Object.defineProperty;
211
+ var __VelarFileNotFoundError = class extends __velarHostErrorNativeError {
212
+ constructor(message, path = null) {
213
+ super(message);
214
+ this.name = "FileNotFoundError";
215
+ this.path = path;
216
+ }
217
+ };
218
+ __velarHostErrorDefineProperty(__VelarFileNotFoundError, "name", { value: "FileNotFoundError", writable: false, enumerable: false, configurable: true });
219
+ var __VelarPermissionError = class extends __velarHostErrorNativeError {
220
+ constructor(message, path = null) {
221
+ super(message);
222
+ this.name = "PermissionError";
223
+ this.path = path;
224
+ }
225
+ };
226
+ __velarHostErrorDefineProperty(__VelarPermissionError, "name", { value: "PermissionError", writable: false, enumerable: false, configurable: true });
227
+ var __VelarNotADirectoryError = class extends __velarHostErrorNativeError {
228
+ constructor(message, path = null) {
229
+ super(message);
230
+ this.name = "NotADirectoryError";
231
+ this.path = path;
232
+ }
233
+ };
234
+ __velarHostErrorDefineProperty(__VelarNotADirectoryError, "name", { value: "NotADirectoryError", writable: false, enumerable: false, configurable: true });
235
+ var __VelarFileExistsError = class extends __velarHostErrorNativeError {
236
+ constructor(message, path = null) {
237
+ super(message);
238
+ this.name = "FileExistsError";
239
+ this.path = path;
240
+ }
241
+ };
242
+ __velarHostErrorDefineProperty(__VelarFileExistsError, "name", { value: "FileExistsError", writable: false, enumerable: false, configurable: true });
243
+ var __VelarAddressInUseError = class extends __velarHostErrorNativeError {
244
+ constructor(message) {
245
+ super(message);
246
+ this.name = "AddressInUseError";
247
+ }
248
+ };
249
+ __velarHostErrorDefineProperty(__VelarAddressInUseError, "name", { value: "AddressInUseError", writable: false, enumerable: false, configurable: true });
250
+
251
+ // velar-standard:velar/compiler-runtime-types-v1
252
+ var __velarCollectionNativeArray = globalThis.Array;
253
+ var __velarCollectionNativeMap = globalThis.Map;
254
+ var __velarCollectionNativeSet = globalThis.Set;
255
+ var __velarCollectionNativeObject = globalThis.Object;
256
+ var __velarCollectionNativeReflect = globalThis.Reflect;
257
+ var __velarCollectionNativeWeakMap = globalThis.WeakMap;
258
+ var __velarCollectionNativeTypeError = globalThis.TypeError;
259
+ var __velarCollectionGetOwnPropertyDescriptor = __velarCollectionNativeObject.getOwnPropertyDescriptor;
260
+ var __velarCollectionReflectApply = __velarCollectionGetOwnPropertyDescriptor(__velarCollectionNativeReflect, "apply")?.value;
261
+ var __velarCollectionArrayIsArray = __velarCollectionGetOwnPropertyDescriptor(__velarCollectionNativeArray, "isArray")?.value;
262
+ var __velarCollectionGetPrototypeOf = __velarCollectionGetOwnPropertyDescriptor(__velarCollectionNativeObject, "getPrototypeOf")?.value;
263
+ var __velarCollectionObjectPrototype = __velarCollectionGetOwnPropertyDescriptor(__velarCollectionNativeObject, "prototype")?.value;
264
+ var __velarCollectionMapPrototype = __velarCollectionGetOwnPropertyDescriptor(__velarCollectionNativeMap, "prototype")?.value;
265
+ var __velarCollectionSetPrototype = __velarCollectionGetOwnPropertyDescriptor(__velarCollectionNativeSet, "prototype")?.value;
266
+ var __velarCollectionMapSize = __velarCollectionGetOwnPropertyDescriptor(__velarCollectionMapPrototype, "size")?.get;
267
+ var __velarCollectionSetSize = __velarCollectionGetOwnPropertyDescriptor(__velarCollectionSetPrototype, "size")?.get;
268
+ function __velarCollectionHostCall(operation, receiver, arguments_) {
269
+ if (typeof operation !== "function" || typeof __velarCollectionReflectApply !== "function") throw new __velarCollectionNativeTypeError("The JavaScript collection runtime is unavailable");
270
+ return __velarCollectionReflectApply(operation, receiver, arguments_);
271
+ }
272
+ var __velarCollectionWeakMapPrototype = __velarCollectionGetOwnPropertyDescriptor(__velarCollectionNativeWeakMap, "prototype")?.value;
273
+ var __velarCollectionWeakMapGetOperation = __velarCollectionGetOwnPropertyDescriptor(__velarCollectionWeakMapPrototype, "get")?.value;
274
+ var __velarCollectionWeakMapSetOperation = __velarCollectionGetOwnPropertyDescriptor(__velarCollectionWeakMapPrototype, "set")?.value;
275
+ var __velarCollectionBrands = new __velarCollectionNativeWeakMap();
276
+ function __velarCollectionBrand(value) {
277
+ if (value === null || typeof value !== "object" && typeof value !== "function") return 0;
278
+ const known = __velarCollectionHostCall(__velarCollectionWeakMapGetOperation, __velarCollectionBrands, [value]);
279
+ if (known !== void 0) return known;
280
+ let brand = 0;
281
+ try {
282
+ __velarCollectionHostCall(__velarCollectionMapSize, value, []);
283
+ brand = 1;
284
+ } catch {
285
+ try {
286
+ __velarCollectionHostCall(__velarCollectionSetSize, value, []);
287
+ brand = 2;
288
+ } catch {
289
+ brand = 0;
290
+ }
291
+ }
292
+ __velarCollectionHostCall(__velarCollectionWeakMapSetOperation, __velarCollectionBrands, [value, brand]);
293
+ return brand;
294
+ }
295
+ function __velarIsMap(value) {
296
+ return __velarCollectionBrand(value) === 1;
297
+ }
298
+ function __velarIsSet(value) {
299
+ return __velarCollectionBrand(value) === 2;
300
+ }
301
+ var __velarCollectionOwnNames = __velarCollectionGetOwnPropertyDescriptor(__velarCollectionNativeObject, "getOwnPropertyNames")?.value;
302
+ var __velarCollectionOwnSymbols = __velarCollectionGetOwnPropertyDescriptor(__velarCollectionNativeObject, "getOwnPropertySymbols")?.value;
303
+ var __velarCollectionOwnKeys = __velarCollectionGetOwnPropertyDescriptor(__velarCollectionNativeReflect, "ownKeys")?.value;
304
+ var __velarCollectionMapEntries = __velarCollectionGetOwnPropertyDescriptor(__velarCollectionMapPrototype, "entries")?.value;
305
+ var __velarCollectionSetValues = __velarCollectionGetOwnPropertyDescriptor(__velarCollectionSetPrototype, "values")?.value;
306
+ var __velarCollectionMapIteratorPrototype = __velarCollectionHostCall(__velarCollectionGetPrototypeOf, __velarCollectionNativeObject, [__velarCollectionHostCall(__velarCollectionMapEntries, new __velarCollectionNativeMap(), [])]);
307
+ var __velarCollectionSetIteratorPrototype = __velarCollectionHostCall(__velarCollectionGetPrototypeOf, __velarCollectionNativeObject, [__velarCollectionHostCall(__velarCollectionSetValues, new __velarCollectionNativeSet(), [])]);
308
+ var __velarCollectionMapIteratorNext = __velarCollectionGetOwnPropertyDescriptor(__velarCollectionMapIteratorPrototype, "next")?.value;
309
+ var __velarCollectionSetIteratorNext = __velarCollectionGetOwnPropertyDescriptor(__velarCollectionSetIteratorPrototype, "next")?.value;
310
+ function __velarCollectionMapTypeIterator(value) {
311
+ return __velarCollectionHostCall(__velarCollectionMapEntries, value, []);
312
+ }
313
+ function __velarCollectionSetTypeIterator(value) {
314
+ return __velarCollectionHostCall(__velarCollectionSetValues, value, []);
315
+ }
316
+ function __velarCollectionMapTypeNext(iterator) {
317
+ return __velarCollectionHostCall(__velarCollectionMapIteratorNext, iterator, []);
318
+ }
319
+ function __velarCollectionSetTypeNext(iterator) {
320
+ return __velarCollectionHostCall(__velarCollectionSetIteratorNext, iterator, []);
321
+ }
322
+ var __velarTypeNativeWeakSet = globalThis.WeakSet;
323
+ var __velarTypeNativeObject = globalThis.Object;
324
+ var __velarTypeNativeTypeError = globalThis.TypeError;
325
+ var __velarTypeGetOwnPropertyDescriptor = __velarTypeNativeObject.getOwnPropertyDescriptor;
326
+ var __velarTypeDefineProperty = __velarTypeNativeObject.defineProperty;
327
+ var __velarTypeReflectApply = __velarTypeGetOwnPropertyDescriptor(globalThis.Reflect, "apply")?.value;
328
+ var __velarTypeSymbolFor = globalThis.Symbol.for;
329
+ var __velarTypeWeakSetPrototype = __velarTypeGetOwnPropertyDescriptor(__velarTypeNativeWeakSet, "prototype")?.value;
330
+ var __velarTypeWeakSetHas = __velarTypeGetOwnPropertyDescriptor(__velarTypeWeakSetPrototype, "has")?.value;
331
+ var __velarTypeWeakSetAdd = __velarTypeGetOwnPropertyDescriptor(__velarTypeWeakSetPrototype, "add")?.value;
332
+ function __velarTypeCall(operation, receiver, arguments_) {
333
+ if (typeof operation !== "function" || typeof __velarTypeReflectApply !== "function") throw new __velarTypeNativeTypeError("The JavaScript runtime Type registry API is unavailable");
334
+ return __velarTypeReflectApply(operation, receiver, arguments_);
335
+ }
336
+ var __velarRuntimeTypeRegistryKey = __velarTypeCall(__velarTypeSymbolFor, globalThis.Symbol, ["velar.type.registry.v1"]);
337
+ var __velarRuntimeTypeRegistry = (() => {
338
+ const descriptor = __velarTypeGetOwnPropertyDescriptor(globalThis, __velarRuntimeTypeRegistryKey);
339
+ if (descriptor) {
340
+ if (!("value" in descriptor) || descriptor.enumerable || descriptor.configurable || descriptor.writable) {
341
+ throw new __velarTypeNativeTypeError("VelarScript runtime type registry descriptor is invalid");
342
+ }
343
+ try {
344
+ __velarTypeCall(__velarTypeWeakSetHas, descriptor.value, [descriptor.value]);
345
+ } catch {
346
+ throw new __velarTypeNativeTypeError("VelarScript runtime type registry is invalid");
347
+ }
348
+ return descriptor.value;
349
+ }
350
+ const registry = new __velarTypeNativeWeakSet();
351
+ __velarTypeCall(__velarTypeDefineProperty, __velarTypeNativeObject, [globalThis, __velarRuntimeTypeRegistryKey, {
352
+ value: registry,
353
+ enumerable: false,
354
+ configurable: false,
355
+ writable: false
356
+ }]);
357
+ return registry;
358
+ })();
359
+ function __velarRegisterRuntimeType(value) {
360
+ __velarTypeCall(__velarTypeWeakSetAdd, __velarRuntimeTypeRegistry, [value]);
361
+ return value;
362
+ }
363
+ var __velarValidationNativeWeakMap = globalThis.WeakMap;
364
+ var __velarValidationNativeSet = globalThis.Set;
365
+ var __velarValidationNativePromise = globalThis.Promise;
366
+ var __velarValidationNativeFunction = globalThis.Function;
367
+ var __velarValidationNativeSymbol = globalThis.Symbol;
368
+ var __velarValidationWeakMapPrototype = __velarCollectionGetOwnPropertyDescriptor(__velarValidationNativeWeakMap, "prototype")?.value;
369
+ var __velarValidationSetPrototype = __velarCollectionGetOwnPropertyDescriptor(__velarValidationNativeSet, "prototype")?.value;
370
+ var __velarValidationFunctionPrototype = __velarCollectionGetOwnPropertyDescriptor(__velarValidationNativeFunction, "prototype")?.value;
371
+ var __velarValidationHasInstanceSymbol = __velarCollectionGetOwnPropertyDescriptor(__velarValidationNativeSymbol, "hasInstance")?.value;
372
+ var __velarValidationWeakMapGetOperation = __velarCollectionGetOwnPropertyDescriptor(__velarValidationWeakMapPrototype, "get")?.value;
373
+ var __velarValidationWeakMapSetOperation = __velarCollectionGetOwnPropertyDescriptor(__velarValidationWeakMapPrototype, "set")?.value;
374
+ var __velarValidationWeakMapDeleteOperation = __velarCollectionGetOwnPropertyDescriptor(__velarValidationWeakMapPrototype, "delete")?.value;
375
+ var __velarValidationSetHasOperation = __velarCollectionGetOwnPropertyDescriptor(__velarValidationSetPrototype, "has")?.value;
376
+ var __velarValidationSetAddOperation = __velarCollectionGetOwnPropertyDescriptor(__velarValidationSetPrototype, "add")?.value;
377
+ var __velarValidationSetDeleteOperation = __velarCollectionGetOwnPropertyDescriptor(__velarValidationSetPrototype, "delete")?.value;
378
+ var __velarValidationSetSizeOperation = __velarCollectionGetOwnPropertyDescriptor(__velarValidationSetPrototype, "size")?.get;
379
+ var __velarValidationFunctionHasInstanceOperation = __velarCollectionGetOwnPropertyDescriptor(__velarValidationFunctionPrototype, __velarValidationHasInstanceSymbol)?.value;
380
+ var __velarValidationFreezeOperation = __velarCollectionGetOwnPropertyDescriptor(__velarCollectionNativeObject, "freeze")?.value;
381
+ var __velarValidationDefinePropertyOperation = __velarCollectionGetOwnPropertyDescriptor(__velarCollectionNativeObject, "defineProperty")?.value;
382
+ var __velarValidationMapSetOperation = __velarCollectionGetOwnPropertyDescriptor(__velarCollectionMapPrototype, "set")?.value;
383
+ var __velarValidationMapGetOperation = __velarCollectionGetOwnPropertyDescriptor(__velarCollectionMapPrototype, "get")?.value;
384
+ function __velarValidationState() {
385
+ return { active: new __velarValidationNativeWeakMap(), depth: 0, copies: null, copy: __velarValidationCopy };
386
+ }
387
+ function __velarValidationSet() {
388
+ return new __velarValidationNativeSet();
389
+ }
390
+ function __velarValidationWeakMapGet(value, key) {
391
+ return __velarCollectionHostCall(__velarValidationWeakMapGetOperation, value, [key]);
392
+ }
393
+ function __velarValidationWeakMapSet(value, key, item) {
394
+ return __velarCollectionHostCall(__velarValidationWeakMapSetOperation, value, [key, item]);
395
+ }
396
+ function __velarValidationMapGet(value, key) {
397
+ return __velarCollectionHostCall(__velarValidationMapGetOperation, value, [key]);
398
+ }
399
+ function __velarValidationMapSet(value, key, item) {
400
+ return __velarCollectionHostCall(__velarValidationMapSetOperation, value, [key, item]);
401
+ }
402
+ function __velarValidationSetAdd(value, item) {
403
+ return __velarCollectionHostCall(__velarValidationSetAddOperation, value, [item]);
404
+ }
405
+ function __velarValidationIsArray(value) {
406
+ return __velarCollectionHostCall(__velarCollectionArrayIsArray, __velarCollectionNativeArray, [value]);
407
+ }
408
+ function __velarValidationOwnDescriptor(value, key) {
409
+ return __velarCollectionHostCall(__velarCollectionGetOwnPropertyDescriptor, __velarCollectionNativeObject, [value, key]);
410
+ }
411
+ function __velarValidationIsInstance(value, constructor) {
412
+ return __velarCollectionHostCall(__velarValidationFunctionHasInstanceOperation, constructor, [value]);
413
+ }
414
+ function __velarValidationFreeze(value) {
415
+ return __velarCollectionHostCall(__velarValidationFreezeOperation, __velarCollectionNativeObject, [value]);
416
+ }
417
+ function __velarValidationIsPlainObject(value) {
418
+ const prototype = __velarCollectionHostCall(__velarCollectionGetPrototypeOf, __velarCollectionNativeObject, [value]);
419
+ if (prototype === null) return true;
420
+ return __velarCollectionHostCall(__velarCollectionGetPrototypeOf, __velarCollectionNativeObject, [prototype]) === null;
421
+ }
422
+ var __velarValidationCopy = {
423
+ seen(state, value, plan) {
424
+ if (state.copies === null) return void 0;
425
+ const plans = __velarValidationWeakMapGet(state.copies, value);
426
+ return plans === void 0 ? void 0 : __velarValidationMapGet(plans, plan);
427
+ },
428
+ remember(state, value, copy, plan) {
429
+ if (state.copies === null) state.copies = new __velarValidationNativeWeakMap();
430
+ let plans = __velarValidationWeakMapGet(state.copies, value);
431
+ if (plans === void 0) {
432
+ plans = new __velarCollectionNativeMap();
433
+ __velarValidationWeakMapSet(state.copies, value, plans);
434
+ }
435
+ __velarValidationMapSet(plans, plan, copy);
436
+ return copy;
437
+ },
438
+ object(state, value, plan) {
439
+ return __velarValidationCopy.remember(state, value, {}, plan);
440
+ },
441
+ // Fields are written through defineProperty so a field literally named
442
+ // '__proto__' lands as an own data property instead of retargeting the
443
+ // copy's prototype, and so every copied field is an ordinary mutable
444
+ // enumerable data property whatever the source's descriptor said.
445
+ field(target, name, value) {
446
+ __velarCollectionHostCall(__velarValidationDefinePropertyOperation, __velarCollectionNativeObject, [target, name, { value, writable: true, enumerable: true, configurable: true }]);
447
+ },
448
+ // A null element callback means the element position has nothing to copy —
449
+ // a primitive, an enum member, a class instance, or an opaque 'unknown'.
450
+ // 'plan' is the container position's own stable identity: the emitter hoists
451
+ // one function per distinct copy plan and hands it in as both the element
452
+ // callback and the key this memo files the copy under.
453
+ listOf(value, state, item, plan) {
454
+ const found = __velarValidationCopy.seen(state, value, plan);
455
+ if (found !== void 0) return found;
456
+ const result = __velarValidationCopy.remember(state, value, [], plan);
457
+ const length = __velarValidationOwnDescriptor(value, "length")?.value ?? 0;
458
+ for (let index = 0; index < length; index += 1) {
459
+ const descriptor = __velarValidationOwnDescriptor(value, index);
460
+ result[index] = item === null ? descriptor?.value : item(descriptor?.value, state);
461
+ }
462
+ return result;
463
+ },
464
+ setOf(value, state, item, plan) {
465
+ const found = __velarValidationCopy.seen(state, value, plan);
466
+ if (found !== void 0) return found;
467
+ const result = __velarValidationCopy.remember(state, value, __velarValidationSet(), plan);
468
+ const iterator = __velarCollectionSetTypeIterator(value);
469
+ while (true) {
470
+ const step = __velarCollectionSetTypeNext(iterator);
471
+ if (step.done) break;
472
+ __velarValidationSetAdd(result, item === null ? step.value : item(step.value, state));
473
+ }
474
+ return result;
475
+ },
476
+ mapOf(value, state, key, item, plan) {
477
+ const found = __velarValidationCopy.seen(state, value, plan);
478
+ if (found !== void 0) return found;
479
+ const result = __velarValidationCopy.remember(state, value, new __velarCollectionNativeMap(), plan);
480
+ const iterator = __velarCollectionMapTypeIterator(value);
481
+ while (true) {
482
+ const step = __velarCollectionMapTypeNext(iterator);
483
+ if (step.done) break;
484
+ const entry = step.value;
485
+ __velarValidationMapSet(result, key === null ? entry[0] : key(entry[0], state), item === null ? entry[1] : item(entry[1], state));
486
+ }
487
+ return result;
488
+ },
489
+ recordOf(value, state, item, plan) {
490
+ const found = __velarValidationCopy.seen(state, value, plan);
491
+ if (found !== void 0) return found;
492
+ const result = __velarValidationCopy.remember(state, value, {}, plan);
493
+ const keys = __velarCollectionHostCall(__velarCollectionOwnKeys, __velarCollectionNativeReflect, [value]);
494
+ for (let index = 0; index < keys.length; index += 1) {
495
+ const name = keys[index];
496
+ if (typeof name !== "string") continue;
497
+ const descriptor = __velarValidationOwnDescriptor(value, name);
498
+ if (!descriptor?.enumerable || !("value" in descriptor)) continue;
499
+ __velarValidationCopy.field(result, name, item === null ? descriptor.value : item(descriptor.value, state));
500
+ }
501
+ return result;
502
+ },
503
+ // A generic instantiation supplies a predicate per type argument but no copy
504
+ // plan, and a structural or union position is validated as a shape the
505
+ // predicate did not fully decide. Both copy the plain data they can see:
506
+ // arrays, Maps, Sets, and plain objects recurse; anything else — a class
507
+ // instance, a promise, a function, a binary buffer — is not plain data and
508
+ // passes through by reference.
509
+ plain(value, state) {
510
+ if (value === null || typeof value !== "object") return value;
511
+ const found = __velarValidationCopy.seen(state, value, __velarValidationCopy.plain);
512
+ if (found !== void 0) return found;
513
+ if (__velarValidationIsArray(value)) return __velarValidationCopy.listOf(value, state, __velarValidationCopy.plain, __velarValidationCopy.plain);
514
+ if (__velarIsMap(value)) return __velarValidationCopy.mapOf(value, state, __velarValidationCopy.plain, __velarValidationCopy.plain, __velarValidationCopy.plain);
515
+ if (__velarIsSet(value)) return __velarValidationCopy.setOf(value, state, __velarValidationCopy.plain, __velarValidationCopy.plain);
516
+ if (!__velarValidationIsPlainObject(value)) return value;
517
+ return __velarValidationCopy.recordOf(value, state, __velarValidationCopy.plain, __velarValidationCopy.plain);
518
+ },
519
+ // A Type object from a target extension, or one emitted by an older build,
520
+ // may carry no copy plan; the structural copy is what is left to fall back on.
521
+ // A Type that does answer 'copy' owns its own plan identity — a declared
522
+ // record files under its copy function, an instantiation under its arguments
523
+ // — so nothing is threaded in from here.
524
+ through(type, value, state) {
525
+ const operation = type === null || type === void 0 ? void 0 : type.copy;
526
+ if (typeof operation !== "function") return __velarValidationCopy.plain(value, state);
527
+ return __velarCollectionHostCall(operation, type, [value, state]);
528
+ }
529
+ };
530
+ function __velarValidationRejectionHint(value) {
531
+ if (value === null || typeof value !== "object" || __velarValidationIsArray(value) || __velarValidationIsPlainObject(value)) return "";
532
+ return "; a record accepts only plain data objects \u2014 project the fields into a record first, for example {x: instance.x}";
533
+ }
534
+ var __velarValidationErrorDefineProperty = globalThis.Object.defineProperty;
535
+ var __VelarValidationError = class extends __velarCollectionNativeTypeError {
536
+ constructor(message, detail) {
537
+ super(message);
538
+ this.name = "ValidationError";
539
+ this.path = detail?.path ?? null;
540
+ this.field = detail?.field ?? null;
541
+ this.reason = detail?.reason ?? null;
542
+ }
543
+ };
544
+ __velarValidationErrorDefineProperty(__VelarValidationError, "name", { value: "ValidationError", writable: false, enumerable: false, configurable: true });
545
+
546
+ // velar-standard:velar/compiler-runtime-collections-v1
547
+ var __velarCollectionNativeArray2 = globalThis.Array;
548
+ var __velarCollectionNativeMap2 = globalThis.Map;
549
+ var __velarCollectionNativeSet2 = globalThis.Set;
550
+ var __velarCollectionNativeObject2 = globalThis.Object;
551
+ var __velarCollectionNativeReflect2 = globalThis.Reflect;
552
+ var __velarCollectionNativeWeakMap2 = globalThis.WeakMap;
553
+ var __velarCollectionNativeTypeError2 = globalThis.TypeError;
554
+ var __velarCollectionGetOwnPropertyDescriptor2 = __velarCollectionNativeObject2.getOwnPropertyDescriptor;
555
+ var __velarCollectionReflectApply2 = __velarCollectionGetOwnPropertyDescriptor2(__velarCollectionNativeReflect2, "apply")?.value;
556
+ var __velarCollectionArrayIsArray2 = __velarCollectionGetOwnPropertyDescriptor2(__velarCollectionNativeArray2, "isArray")?.value;
557
+ var __velarCollectionGetPrototypeOf2 = __velarCollectionGetOwnPropertyDescriptor2(__velarCollectionNativeObject2, "getPrototypeOf")?.value;
558
+ var __velarCollectionObjectPrototype2 = __velarCollectionGetOwnPropertyDescriptor2(__velarCollectionNativeObject2, "prototype")?.value;
559
+ var __velarCollectionMapPrototype2 = __velarCollectionGetOwnPropertyDescriptor2(__velarCollectionNativeMap2, "prototype")?.value;
560
+ var __velarCollectionSetPrototype2 = __velarCollectionGetOwnPropertyDescriptor2(__velarCollectionNativeSet2, "prototype")?.value;
561
+ var __velarCollectionMapSize2 = __velarCollectionGetOwnPropertyDescriptor2(__velarCollectionMapPrototype2, "size")?.get;
562
+ var __velarCollectionSetSize2 = __velarCollectionGetOwnPropertyDescriptor2(__velarCollectionSetPrototype2, "size")?.get;
563
+ function __velarCollectionHostCall2(operation, receiver, arguments_) {
564
+ if (typeof operation !== "function" || typeof __velarCollectionReflectApply2 !== "function") throw new __velarCollectionNativeTypeError2("The JavaScript collection runtime is unavailable");
565
+ return __velarCollectionReflectApply2(operation, receiver, arguments_);
566
+ }
567
+ var __velarCollectionWeakMapPrototype2 = __velarCollectionGetOwnPropertyDescriptor2(__velarCollectionNativeWeakMap2, "prototype")?.value;
568
+ var __velarCollectionWeakMapGetOperation2 = __velarCollectionGetOwnPropertyDescriptor2(__velarCollectionWeakMapPrototype2, "get")?.value;
569
+ var __velarCollectionWeakMapSetOperation2 = __velarCollectionGetOwnPropertyDescriptor2(__velarCollectionWeakMapPrototype2, "set")?.value;
570
+ var __velarCollectionBrands2 = new __velarCollectionNativeWeakMap2();
571
+ var __velarCollectionListNativeNumber = globalThis.Number;
572
+ var __velarCollectionListNativeMath = globalThis.Math;
573
+ var __velarCollectionListNativeRangeError = globalThis.RangeError;
574
+ var __velarCollectionListArrayPrototype = __velarCollectionGetOwnPropertyDescriptor2(__velarCollectionNativeArray2, "prototype")?.value;
575
+ var __velarCollectionListOwnNamesOperation = __velarCollectionGetOwnPropertyDescriptor2(__velarCollectionNativeObject2, "getOwnPropertyNames")?.value;
576
+ var __velarCollectionListOwnSymbolsOperation = __velarCollectionGetOwnPropertyDescriptor2(__velarCollectionNativeObject2, "getOwnPropertySymbols")?.value;
577
+ var __velarCollectionListDefinePropertyOperation = __velarCollectionGetOwnPropertyDescriptor2(__velarCollectionNativeObject2, "defineProperty")?.value;
578
+ var __velarCollectionListObjectIsOperation = __velarCollectionGetOwnPropertyDescriptor2(__velarCollectionNativeObject2, "is")?.value;
579
+ var __velarCollectionListIntegerOperation = __velarCollectionGetOwnPropertyDescriptor2(__velarCollectionListNativeNumber, "isInteger")?.value;
580
+ var __velarCollectionListNaNOperation = __velarCollectionGetOwnPropertyDescriptor2(__velarCollectionListNativeNumber, "isNaN")?.value;
581
+ var __velarCollectionListFiniteOperation = __velarCollectionGetOwnPropertyDescriptor2(__velarCollectionListNativeNumber, "isFinite")?.value;
582
+ var __velarCollectionListMaximumOperation = __velarCollectionGetOwnPropertyDescriptor2(__velarCollectionListNativeMath, "max")?.value;
583
+ var __velarCollectionListMinimumOperation = __velarCollectionGetOwnPropertyDescriptor2(__velarCollectionListNativeMath, "min")?.value;
584
+ var __velarCollectionListJoinOperation = __velarCollectionGetOwnPropertyDescriptor2(__velarCollectionListArrayPrototype, "join")?.value;
585
+ var __velarCollectionListSortOperation = __velarCollectionGetOwnPropertyDescriptor2(__velarCollectionListArrayPrototype, "sort")?.value;
586
+ var __velarCollectionListReverseOperation = __velarCollectionGetOwnPropertyDescriptor2(__velarCollectionListArrayPrototype, "reverse")?.value;
587
+ function __velarCollectionListIsArray(value) {
588
+ return __velarCollectionHostCall2(__velarCollectionArrayIsArray2, __velarCollectionNativeArray2, [value]);
589
+ }
590
+ function __velarCollectionListGetOwnPropertyDescriptor(value, key) {
591
+ return __velarCollectionHostCall2(__velarCollectionGetOwnPropertyDescriptor2, __velarCollectionNativeObject2, [value, key]);
592
+ }
593
+ function __velarCollectionListOwnNames(value) {
594
+ return __velarCollectionHostCall2(__velarCollectionListOwnNamesOperation, __velarCollectionNativeObject2, [value]);
595
+ }
596
+ function __velarCollectionListOwnSymbols(value) {
597
+ return __velarCollectionHostCall2(__velarCollectionListOwnSymbolsOperation, __velarCollectionNativeObject2, [value]);
598
+ }
599
+ function __velarCollectionListDefineProperty(value, key, descriptor) {
600
+ return __velarCollectionHostCall2(__velarCollectionListDefinePropertyOperation, __velarCollectionNativeObject2, [value, key, descriptor]);
601
+ }
602
+ function __velarCollectionListIsInteger(value) {
603
+ return __velarCollectionHostCall2(__velarCollectionListIntegerOperation, __velarCollectionListNativeNumber, [value]);
604
+ }
605
+ var __velarCollectionSetMapNativeRangeError = globalThis.RangeError;
606
+ var __velarCollectionSetMapFreezeOperation = __velarCollectionGetOwnPropertyDescriptor2(__velarCollectionNativeObject2, "freeze")?.value;
607
+ var __velarCollectionSetAddOperation = __velarCollectionGetOwnPropertyDescriptor2(__velarCollectionSetPrototype2, "add")?.value;
608
+ var __velarCollectionSetHasOperation = __velarCollectionGetOwnPropertyDescriptor2(__velarCollectionSetPrototype2, "has")?.value;
609
+ var __velarCollectionSetDeleteOperation = __velarCollectionGetOwnPropertyDescriptor2(__velarCollectionSetPrototype2, "delete")?.value;
610
+ var __velarCollectionSetClearOperation = __velarCollectionGetOwnPropertyDescriptor2(__velarCollectionSetPrototype2, "clear")?.value;
611
+ var __velarCollectionSetValuesOperation = __velarCollectionGetOwnPropertyDescriptor2(__velarCollectionSetPrototype2, "values")?.value;
612
+ var __velarCollectionMapGetOperation = __velarCollectionGetOwnPropertyDescriptor2(__velarCollectionMapPrototype2, "get")?.value;
613
+ var __velarCollectionMapSetOperation = __velarCollectionGetOwnPropertyDescriptor2(__velarCollectionMapPrototype2, "set")?.value;
614
+ var __velarCollectionMapHasOperation = __velarCollectionGetOwnPropertyDescriptor2(__velarCollectionMapPrototype2, "has")?.value;
615
+ var __velarCollectionMapDeleteOperation = __velarCollectionGetOwnPropertyDescriptor2(__velarCollectionMapPrototype2, "delete")?.value;
616
+ var __velarCollectionMapClearOperation = __velarCollectionGetOwnPropertyDescriptor2(__velarCollectionMapPrototype2, "clear")?.value;
617
+ var __velarCollectionMapKeysOperation = __velarCollectionGetOwnPropertyDescriptor2(__velarCollectionMapPrototype2, "keys")?.value;
618
+ var __velarCollectionMapValuesOperation = __velarCollectionGetOwnPropertyDescriptor2(__velarCollectionMapPrototype2, "values")?.value;
619
+ var __velarCollectionMapEntriesOperation = __velarCollectionGetOwnPropertyDescriptor2(__velarCollectionMapPrototype2, "entries")?.value;
620
+ var __velarCollectionSetMapMapIteratorPrototype = __velarCollectionHostCall2(__velarCollectionGetPrototypeOf2, __velarCollectionNativeObject2, [__velarCollectionHostCall2(__velarCollectionMapEntriesOperation, new __velarCollectionNativeMap2(), [])]);
621
+ var __velarCollectionSetMapSetIteratorPrototype = __velarCollectionHostCall2(__velarCollectionGetPrototypeOf2, __velarCollectionNativeObject2, [__velarCollectionHostCall2(__velarCollectionSetValuesOperation, new __velarCollectionNativeSet2(), [])]);
622
+ var __velarCollectionSetMapMapIteratorNext = __velarCollectionGetOwnPropertyDescriptor2(__velarCollectionSetMapMapIteratorPrototype, "next")?.value;
623
+ var __velarCollectionSetMapSetIteratorNext = __velarCollectionGetOwnPropertyDescriptor2(__velarCollectionSetMapSetIteratorPrototype, "next")?.value;
624
+ var __velarCollectionRecordNativeRangeError = globalThis.RangeError;
625
+ var __velarCollectionRecordOwnNamesOperation = __velarCollectionGetOwnPropertyDescriptor2(__velarCollectionNativeObject2, "getOwnPropertyNames")?.value;
626
+ var __velarCollectionRecordOwnSymbolsOperation = __velarCollectionGetOwnPropertyDescriptor2(__velarCollectionNativeObject2, "getOwnPropertySymbols")?.value;
627
+ var __velarCollectionRecordDefinePropertyOperation = __velarCollectionGetOwnPropertyDescriptor2(__velarCollectionNativeObject2, "defineProperty")?.value;
628
+ var __velarCollectionRecordObjectIsOperation = __velarCollectionGetOwnPropertyDescriptor2(__velarCollectionNativeObject2, "is")?.value;
629
+ var __velarCollectionRecordDeletePropertyOperation = __velarCollectionGetOwnPropertyDescriptor2(__velarCollectionNativeReflect2, "deleteProperty")?.value;
630
+ var __velarCollectionRecordFreezeOperation = __velarCollectionGetOwnPropertyDescriptor2(__velarCollectionNativeObject2, "freeze")?.value;
631
+
632
+ // velar-standard:velar/compiler-runtime-collection-lowering-v1
633
+ var __velarMaxCollectionItems = 1e6;
634
+ var __velarCollectionValue = (value) => value === void 0 ? null : value;
635
+ var __velarListNativeWeakMap = globalThis.WeakMap;
636
+ var __velarListWeakMapPrototype = __velarCollectionListGetOwnPropertyDescriptor(__velarListNativeWeakMap, "prototype")?.value;
637
+ var __velarListWeakMapGetOperation = __velarCollectionListGetOwnPropertyDescriptor(__velarListWeakMapPrototype, "get")?.value;
638
+ var __velarListWeakMapSetOperation = __velarCollectionListGetOwnPropertyDescriptor(__velarListWeakMapPrototype, "set")?.value;
639
+ var __velarListMemos = new __velarListNativeWeakMap();
640
+ var __velarListIsFrozenOperation = __velarCollectionListGetOwnPropertyDescriptor(__velarCollectionNativeObject2, "isFrozen")?.value;
641
+ function __velarListRejectFrozen(value, name) {
642
+ if (__velarCollectionHostCall2(__velarListIsFrozenOperation, __velarCollectionNativeObject2, [value])) {
643
+ throw new __velarCollectionNativeTypeError2(name + " received a frozen JavaScript array; copy it on the JavaScript side \u2014 [...values] \u2014 before passing it to VelarScript");
644
+ }
645
+ }
646
+ function __velarListMemo(value) {
647
+ return __velarCollectionHostCall2(__velarListWeakMapGetOperation, __velarListMemos, [value]);
648
+ }
649
+ function __velarListIsOwned(value) {
650
+ const memo = __velarListMemo(value);
651
+ return memo !== void 0 && memo === value.length;
652
+ }
653
+ function __velarAdoptList(value) {
654
+ __velarCollectionHostCall2(__velarListWeakMapSetOperation, __velarListMemos, [value, value.length]);
655
+ return value;
656
+ }
657
+ function __velarMarkCheckedList(value) {
658
+ __velarCollectionHostCall2(__velarListWeakMapSetOperation, __velarListMemos, [value, ~value.length]);
659
+ return value;
660
+ }
661
+ function __velarMarkOwnedList(value) {
662
+ const memo = __velarListMemo(value);
663
+ return memo !== void 0 && memo < 0 ? __velarMarkCheckedList(value) : __velarAdoptList(value);
664
+ }
665
+ function __velarListRequireMutableLength(value, name) {
666
+ const lengthDescriptor = __velarCollectionListGetOwnPropertyDescriptor(value, "length");
667
+ if (!lengthDescriptor || !lengthDescriptor.writable || lengthDescriptor.enumerable || lengthDescriptor.configurable || !("value" in lengthDescriptor)) throw new __velarCollectionNativeTypeError2(name + " requires an ordinary mutable List length");
668
+ }
669
+ function __velarValidateDenseList(value, name) {
670
+ value = __velarReactiveRaw(value);
671
+ if (!__velarCollectionListIsArray(value) || value.length > __velarMaxCollectionItems || __velarCollectionListOwnSymbols(value).length > 0 || __velarCollectionListOwnNames(value).length !== value.length + 1) {
672
+ throw new __velarCollectionNativeTypeError2(name + " requires a dense VelarScript List");
673
+ }
674
+ __velarListRejectFrozen(value, name);
675
+ __velarListRequireMutableLength(value, name);
676
+ for (let index = 0; index < value.length; index += 1) {
677
+ const descriptor = __velarCollectionListGetOwnPropertyDescriptor(value, index);
678
+ if (!descriptor?.enumerable || !descriptor.configurable || !descriptor.writable || !("value" in descriptor)) throw new __velarCollectionNativeTypeError2(name + " requires ordinary mutable List data elements");
679
+ }
680
+ return __velarMarkCheckedList(value);
681
+ }
682
+ function __velarListTier(value) {
683
+ const memo = __velarListMemo(value);
684
+ if (memo === void 0) return 0;
685
+ if (memo === value.length) return 1;
686
+ return ~memo === value.length ? 2 : 0;
687
+ }
688
+ function __velarValidateListTier(value, name, tier) {
689
+ if (tier === 1) return value;
690
+ if (tier === 0) return __velarValidateDenseList(value, name);
691
+ __velarListRequireMutableLength(value, name);
692
+ return value;
693
+ }
694
+ function __velarValidateOwnedList(value, name) {
695
+ value = __velarReactiveRaw(value);
696
+ return __velarValidateListTier(value, name, __velarListTier(value));
697
+ }
698
+ function __velarValidateMutableList(value, name) {
699
+ value = __velarReactiveRaw(value);
700
+ const tier = __velarListTier(value);
701
+ if (tier === 0) return __velarValidateDenseList(value, name);
702
+ __velarListRequireMutableLength(value, name);
703
+ return value;
704
+ }
705
+ function __velarCheckedListElement(value, index, name) {
706
+ const descriptor = __velarCollectionListGetOwnPropertyDescriptor(value, index);
707
+ if (!descriptor?.enumerable || !descriptor.configurable || !descriptor.writable || !("value" in descriptor)) throw new __velarCollectionNativeTypeError2(name + " requires ordinary mutable List data elements");
708
+ return descriptor.value;
709
+ }
710
+ function __velarOwnedListElement(value, index, name) {
711
+ const element = value[index];
712
+ return element === void 0 ? __velarCheckedListElement(value, index, name) : element;
713
+ }
714
+ function __velarListElement(value, index, name, owned) {
715
+ return owned ? __velarOwnedListElement(value, index, name) : __velarCheckedListElement(value, index, name);
716
+ }
717
+ function __velarCopyList(value, name) {
718
+ value = __velarValidateOwnedList(value, name);
719
+ const owned = __velarListIsOwned(value);
720
+ const output = [];
721
+ for (let index = 0; index < value.length; index += 1) output[index] = __velarCollectionValue(__velarListElement(value, index, name, owned));
722
+ return __velarAdoptList(output);
723
+ }
724
+ var __velarListNativeString = globalThis.String;
725
+ var __velarListStringPrototype = __velarCollectionListGetOwnPropertyDescriptor(__velarListNativeString, "prototype")?.value;
726
+ var __velarListStringCharCodeAt = __velarCollectionListGetOwnPropertyDescriptor(__velarListStringPrototype, "charCodeAt")?.value;
727
+ var __velarListSurrogatePattern = /[\uD800-\uDFFF]/;
728
+ var __velarListRegExpPrototype = __velarCollectionHostCall2(__velarCollectionGetPrototypeOf2, __velarCollectionNativeObject2, [__velarListSurrogatePattern]);
729
+ var __velarListSurrogateExecOperation = __velarCollectionListGetOwnPropertyDescriptor(__velarListRegExpPrototype, "exec")?.value;
730
+ function __velarListSize(value) {
731
+ value = __velarValidateOwnedList(value, "List size");
732
+ __velarReactiveCollectionTrack(value, __velarReactiveStructureKey);
733
+ return value.length;
734
+ }
735
+ var __VelarIndexError = class extends __velarCollectionListNativeRangeError {
736
+ constructor(message) {
737
+ super(message);
738
+ this.name = "IndexError";
739
+ }
740
+ };
741
+ __velarCollectionListDefineProperty(__VelarIndexError, "name", { value: "IndexError", writable: false, enumerable: false, configurable: true });
742
+ function __velarStrictListIndex(value, requested) {
743
+ if (!__velarCollectionListIsInteger(requested)) throw new __VelarIndexError("List index must be an in-range integer");
744
+ const index = requested < 0 ? value.length + requested : requested;
745
+ if (index < 0 || index >= value.length) throw new __VelarIndexError("List index must be an in-range integer");
746
+ return index;
747
+ }
748
+ function __velarListIndexGet(value, index) {
749
+ value = __velarReactiveRaw(value);
750
+ const tier = __velarListTier(value);
751
+ if (tier === 1) {
752
+ index = __velarStrictListIndex(value, index);
753
+ return __velarReactiveCollectionRead(value, index, __velarOwnedListElement(value, index, "List index"));
754
+ }
755
+ value = __velarValidateListTier(value, "List index", tier);
756
+ index = __velarStrictListIndex(value, index);
757
+ return __velarReactiveCollectionRead(value, index, __velarCheckedListElement(value, index, "List index"));
758
+ }
759
+ function __velarListAppend(value, item) {
760
+ value = __velarValidateMutableList(value, "List.append");
761
+ if (value.length >= __velarMaxCollectionItems) throw new __velarCollectionListNativeRangeError("A List cannot exceed 1000000 items");
762
+ item = __velarReactiveRaw(item);
763
+ const index = value.length;
764
+ __velarCollectionListDefineProperty(value, index, { value: item, writable: true, enumerable: true, configurable: true });
765
+ __velarReactiveCollectionLink(value, item);
766
+ __velarReactiveCollectionTrigger(value, index, true, true, index);
767
+ __velarMarkOwnedList(value);
768
+ return null;
769
+ }
770
+ function __velarListMap(value, transform) {
771
+ const items = __velarCopyList(value, "List.map");
772
+ __velarReactiveCollectionTrack(value);
773
+ const output = new __velarCollectionNativeArray2(items.length);
774
+ for (let index = 0; index < items.length; index += 1) {
775
+ const item = transform(__velarReactiveCollectionRead(value, index, items[index]));
776
+ output[index] = item === void 0 ? null : __velarReactiveRaw(item);
777
+ }
778
+ return __velarAdoptList(output);
779
+ }
780
+
781
+ // src/src/index.vel
782
+ import { DatabaseExecutor } from "@velarscript-labs/database";
783
+
784
+ // velar-embedded:src/index.2ibbmz.embedded-1.js
785
+ import { AsyncLocalStorage } from "node:async_hooks";
786
+ import { Worker } from "node:worker_threads";
787
+ var TOKEN = Object.freeze({});
788
+ var connectionStates = /* @__PURE__ */ new WeakMap();
789
+ var transactionStates = /* @__PURE__ */ new WeakMap();
790
+ var transactionContext = new AsyncLocalStorage();
791
+ var NativeSqliteError = class extends Error {
792
+ constructor(message = "SQLite operation failed", sqliteCode = null, operation = "unknown", retryable = false) {
793
+ super(message);
794
+ this.name = "NativeSqliteError";
795
+ this.sqliteCode = sqliteCode;
796
+ this.operation = operation;
797
+ this.retryable = retryable;
798
+ }
799
+ };
800
+ var NativeSqliteBackpressureError = class extends NativeSqliteError {
801
+ constructor(message = "SQLite queue is full") {
802
+ super(message, "SQLITE_BACKPRESSURE", "queue", true);
803
+ this.name = "NativeSqliteBackpressureError";
804
+ }
805
+ };
806
+ var NativeSqliteConcurrencyError = class extends NativeSqliteError {
807
+ constructor(message = "SQLite connection cannot be used from its transaction callback") {
808
+ super(message, "SQLITE_CONCURRENCY", "transaction", true);
809
+ this.name = "NativeSqliteConcurrencyError";
810
+ }
811
+ };
812
+ function integer(value, fallback, minimum, maximum, label) {
813
+ const selected = value == null ? fallback : value;
814
+ if (!Number.isSafeInteger(selected) || selected < minimum || selected > maximum) {
815
+ throw new TypeError(label + " must be an integer from " + minimum + " through " + maximum);
816
+ }
817
+ return selected;
818
+ }
819
+ function checkedOptions(value) {
820
+ if (value === null || typeof value !== "object" || Array.isArray(value)) throw new TypeError("SQLite options must be a record");
821
+ const allowed = /* @__PURE__ */ new Set(["busyTimeoutMilliseconds", "queueCapacity", "maxRows", "maxResultBytes"]);
822
+ for (const key of Object.keys(value)) if (!allowed.has(key)) throw new TypeError("Unknown SQLite option " + key);
823
+ return {
824
+ busyTimeoutMilliseconds: integer(value.busyTimeoutMilliseconds, 2e3, 1, 6e4, "SQLite busy timeout"),
825
+ queueCapacity: integer(value.queueCapacity, 64, 1, 1024, "SQLite queue capacity"),
826
+ maxRows: integer(value.maxRows, 1e4, 1, 1e6, "SQLite row limit"),
827
+ maxResultBytes: integer(value.maxResultBytes, 64 * 1024 * 1024, 1, 128 * 1024 * 1024, "SQLite result byte limit")
828
+ };
829
+ }
830
+ function workerMain() {
831
+ const { Buffer } = (0, globalThis.require)("node:buffer");
832
+ const { parentPort, workerData } = (0, globalThis.require)("node:worker_threads");
833
+ const { DatabaseSync } = (0, globalThis.require)("node:sqlite");
834
+ let database = null;
835
+ let closed = false;
836
+ function failure(message, code, operation, retryable = false) {
837
+ const error = new Error(message);
838
+ error.code = code;
839
+ error.operation = operation;
840
+ error.retryable = retryable;
841
+ return error;
842
+ }
843
+ function errorData(error, operation) {
844
+ const message = error instanceof Error ? error.message : String(error);
845
+ const rawCode = error && typeof error === "object" ? error.errstr ?? error.code ?? null : null;
846
+ const code = rawCode == null ? null : String(rawCode);
847
+ const upper = code == null ? "" : code.toUpperCase();
848
+ return {
849
+ message,
850
+ sqliteCode: code,
851
+ operation: error && typeof error.operation === "string" ? error.operation : operation,
852
+ retryable: error && error.retryable === true || upper.includes("BUSY") || upper.includes("LOCKED")
853
+ };
854
+ }
855
+ function sqlText(value, operation) {
856
+ if (typeof value !== "string" || value.length === 0 || value.length > 1024 * 1024 || value.includes("\0")) {
857
+ throw failure("SQLite SQL must be non-empty text no longer than 1 MiB", "SQLITE_INPUT", operation);
858
+ }
859
+ return value;
860
+ }
861
+ function parameter(value, budget) {
862
+ if (value === null) return null;
863
+ if (typeof value === "boolean") return value ? 1 : 0;
864
+ if (typeof value === "string") {
865
+ budget.value += Buffer.byteLength(value, "utf8");
866
+ return value;
867
+ }
868
+ if (typeof value === "number") {
869
+ if (!Number.isFinite(value)) throw failure("SQLite number parameters must be finite", "SQLITE_INPUT", "params");
870
+ if (Number.isInteger(value) && !Number.isSafeInteger(value)) throw failure("SQLite integer parameters must be safe integers", "SQLITE_INPUT", "params");
871
+ budget.value += 8;
872
+ return value;
873
+ }
874
+ if (value instanceof Uint8Array) {
875
+ budget.value += value.byteLength;
876
+ return value;
877
+ }
878
+ throw failure("SQLite parameters support only null, bool, string, finite number, and Bytes", "SQLITE_INPUT", "params");
879
+ }
880
+ function parameters(value) {
881
+ if (!Array.isArray(value) || value.length > 999) throw failure("SQLite parameters must be a List with at most 999 values", "SQLITE_INPUT", "params");
882
+ const budget = { value: 0 };
883
+ const output = value.map((item) => parameter(item, budget));
884
+ if (budget.value > workerData.maxResultBytes) throw failure("SQLite parameters exceed the connection byte limit", "SQLITE_INPUT", "params");
885
+ return output;
886
+ }
887
+ function count(value, label) {
888
+ const number = typeof value === "bigint" ? Number(value) : value;
889
+ if (!Number.isSafeInteger(number) || number < 0) throw failure(label + " is outside VelarScript's safe integer range", "SQLITE_INTEGER_RANGE", "result");
890
+ return number;
891
+ }
892
+ function resultValue(value, budget, field) {
893
+ if (value === null) return null;
894
+ if (typeof value === "string") {
895
+ budget.value += Buffer.byteLength(value, "utf8");
896
+ return value;
897
+ }
898
+ if (typeof value === "number") {
899
+ if (!Number.isFinite(value)) throw failure("SQLite returned a non-finite number in " + field, "SQLITE_RESULT", "result");
900
+ budget.value += 8;
901
+ return value;
902
+ }
903
+ if (typeof value === "bigint") {
904
+ const number = Number(value);
905
+ if (!Number.isSafeInteger(number)) throw failure("SQLite returned an integer outside VelarScript's safe range in " + field, "SQLITE_INTEGER_RANGE", "result");
906
+ budget.value += 8;
907
+ return number;
908
+ }
909
+ if (value instanceof Uint8Array) {
910
+ budget.value += value.byteLength;
911
+ return value;
912
+ }
913
+ throw failure("SQLite returned an unsupported value in " + field, "SQLITE_RESULT", "result");
914
+ }
915
+ function resultRow(value, budget) {
916
+ if (value === null || typeof value !== "object" || Array.isArray(value)) throw failure("SQLite returned a non-record row", "SQLITE_RESULT", "result");
917
+ const output = /* @__PURE__ */ Object.create(null);
918
+ for (const key of Object.keys(value)) {
919
+ budget.value += Buffer.byteLength(key, "utf8");
920
+ output[key] = resultValue(value[key], budget, key);
921
+ if (budget.value > workerData.maxResultBytes) throw failure("SQLite result exceeds the connection byte limit", "SQLITE_RESULT_LIMIT", "result");
922
+ }
923
+ return output;
924
+ }
925
+ function statement(sql, operation) {
926
+ const prepared = database.prepare(sqlText(sql, operation));
927
+ if (typeof prepared.setReadBigInts === "function") prepared.setReadBigInts(true);
928
+ return prepared;
929
+ }
930
+ function execute(message) {
931
+ const prepared = statement(message.sql, "execute");
932
+ const result = prepared.run(...parameters(message.params));
933
+ return count(result.changes, "SQLite affected row count");
934
+ }
935
+ function one(message) {
936
+ const prepared = statement(message.sql, "one");
937
+ const row = prepared.get(...parameters(message.params));
938
+ if (row === void 0) return null;
939
+ return resultRow(row, { value: 0 });
940
+ }
941
+ function all(message) {
942
+ const prepared = statement(message.sql, "all");
943
+ const rows = [];
944
+ const budget = { value: 0 };
945
+ for (const row of prepared.iterate(...parameters(message.params))) {
946
+ if (rows.length >= workerData.maxRows) throw failure("SQLite result exceeds the connection row limit", "SQLITE_ROW_LIMIT", "all");
947
+ rows.push(resultRow(row, budget));
948
+ }
949
+ return rows;
950
+ }
951
+ function dispatch(message) {
952
+ if (closed) throw failure("SQLite connection is closed", "SQLITE_CLOSED", message.operation);
953
+ if (message.operation === "execute") return execute(message);
954
+ if (message.operation === "one") return one(message);
955
+ if (message.operation === "all") return all(message);
956
+ if (message.operation === "begin") {
957
+ if (database.isTransaction) throw failure("SQLite transaction is already active", "SQLITE_TRANSACTION", "begin", true);
958
+ database.exec("BEGIN IMMEDIATE");
959
+ return null;
960
+ }
961
+ if (message.operation === "commit") {
962
+ if (!database.isTransaction) throw failure("SQLite transaction is not active", "SQLITE_TRANSACTION", "commit");
963
+ database.exec("COMMIT");
964
+ return null;
965
+ }
966
+ if (message.operation === "rollback") {
967
+ if (database.isTransaction) database.exec("ROLLBACK");
968
+ return null;
969
+ }
970
+ if (message.operation === "close") {
971
+ try {
972
+ if (database.isTransaction) database.exec("ROLLBACK");
973
+ } finally {
974
+ database.close();
975
+ closed = true;
976
+ }
977
+ return null;
978
+ }
979
+ throw failure("Unknown SQLite operation", "SQLITE_PROTOCOL", String(message.operation));
980
+ }
981
+ try {
982
+ database = new DatabaseSync(workerData.path, { timeout: workerData.busyTimeoutMilliseconds });
983
+ database.exec("PRAGMA foreign_keys = ON");
984
+ parentPort.postMessage({ kind: "ready" });
985
+ } catch (error) {
986
+ parentPort.postMessage({ kind: "ready", error: errorData(error, "open") });
987
+ parentPort.close();
988
+ return;
989
+ }
990
+ parentPort.on("message", (message) => {
991
+ try {
992
+ const value = dispatch(message);
993
+ parentPort.postMessage({ kind: "response", id: message.id, value });
994
+ if (message.operation === "close") parentPort.close();
995
+ } catch (error) {
996
+ parentPort.postMessage({ kind: "response", id: message.id, error: errorData(error, message.operation) });
997
+ }
998
+ });
999
+ }
1000
+ function nativeError(value) {
1001
+ return new NativeSqliteError(value.message, value.sqliteCode, value.operation, value.retryable);
1002
+ }
1003
+ function failPending(state, error) {
1004
+ if (state.readyReject !== null) {
1005
+ state.readyReject(error);
1006
+ state.readyReject = null;
1007
+ state.readyResolve = null;
1008
+ }
1009
+ for (const pending of state.pending.values()) pending.reject(error);
1010
+ state.pending.clear();
1011
+ }
1012
+ function request(state, operation, sql = "", params = []) {
1013
+ if (state.closed) return Promise.reject(new NativeSqliteError("SQLite connection is closed", "SQLITE_CLOSED", operation));
1014
+ const id = state.nextId++;
1015
+ return new Promise((resolve, reject) => {
1016
+ state.pending.set(id, { resolve, reject });
1017
+ try {
1018
+ state.worker.postMessage({ id, operation, sql, params });
1019
+ } catch (error) {
1020
+ state.pending.delete(id);
1021
+ reject(error);
1022
+ }
1023
+ });
1024
+ }
1025
+ function stateOf(connection) {
1026
+ const state = connectionStates.get(connection);
1027
+ if (!state) throw new TypeError("Invalid SQLite connection");
1028
+ return state;
1029
+ }
1030
+ function transactionStateOf(transaction) {
1031
+ const state = transactionStates.get(transaction);
1032
+ if (!state || !state.active) throw new NativeSqliteConcurrencyError("SQLite transaction is no longer active");
1033
+ return state;
1034
+ }
1035
+ function transactionRequest(transaction, operation, sql = "", params = []) {
1036
+ const state = transactionStateOf(transaction);
1037
+ if (state.busy) return Promise.reject(new NativeSqliteConcurrencyError("SQLite transaction operations must be awaited one at a time"));
1038
+ state.busy = true;
1039
+ return request(state.connection, operation, sql, params).finally(() => {
1040
+ state.busy = false;
1041
+ });
1042
+ }
1043
+ function enqueue(state, operation) {
1044
+ if (state.closed || state.closing) return Promise.reject(new NativeSqliteError("SQLite connection is closed", "SQLITE_CLOSED", "queue"));
1045
+ if (transactionContext.getStore() === state) return Promise.reject(new NativeSqliteConcurrencyError());
1046
+ if (state.queued >= state.queueCapacity) return Promise.reject(new NativeSqliteBackpressureError());
1047
+ state.queued += 1;
1048
+ const running = state.tail.then(operation, operation);
1049
+ state.tail = running.then(() => null, () => null);
1050
+ return running.finally(() => {
1051
+ state.queued -= 1;
1052
+ });
1053
+ }
1054
+ var NativeSqliteTransaction = class {
1055
+ constructor(token, state) {
1056
+ if (token !== TOKEN) throw new TypeError("SQLite transactions are created by connection.transaction");
1057
+ transactionStates.set(this, state);
1058
+ }
1059
+ execute(sql, params = []) {
1060
+ return transactionRequest(this, "execute", sql, params);
1061
+ }
1062
+ one(sql, params = []) {
1063
+ return transactionRequest(this, "one", sql, params);
1064
+ }
1065
+ all(sql, params = []) {
1066
+ return transactionRequest(this, "all", sql, params);
1067
+ }
1068
+ };
1069
+ var NativeSqliteConnection = class {
1070
+ constructor(token, state) {
1071
+ if (token !== TOKEN) throw new TypeError("Use openSqlite to create a SQLite connection");
1072
+ connectionStates.set(this, state);
1073
+ }
1074
+ execute(sql, params = []) {
1075
+ const state = stateOf(this);
1076
+ return enqueue(state, () => request(state, "execute", sql, params));
1077
+ }
1078
+ one(sql, params = []) {
1079
+ const state = stateOf(this);
1080
+ return enqueue(state, () => request(state, "one", sql, params));
1081
+ }
1082
+ all(sql, params = []) {
1083
+ const state = stateOf(this);
1084
+ return enqueue(state, () => request(state, "all", sql, params));
1085
+ }
1086
+ transaction(operation) {
1087
+ if (typeof operation !== "function") return Promise.reject(new TypeError("SQLite transaction requires an async operation"));
1088
+ const state = stateOf(this);
1089
+ return enqueue(state, async () => {
1090
+ await request(state, "begin");
1091
+ const transactionState = { connection: state, active: true, busy: false };
1092
+ const transaction = new NativeSqliteTransaction(TOKEN, transactionState);
1093
+ try {
1094
+ await transactionContext.run(state, () => operation(transaction));
1095
+ await transactionRequest(transaction, "commit");
1096
+ transactionState.active = false;
1097
+ return null;
1098
+ } catch (error) {
1099
+ try {
1100
+ if (transactionState.active) await transactionRequest(transaction, "rollback");
1101
+ } catch {
1102
+ state.closing = true;
1103
+ state.worker.terminate();
1104
+ } finally {
1105
+ transactionState.active = false;
1106
+ }
1107
+ throw error;
1108
+ }
1109
+ });
1110
+ }
1111
+ close() {
1112
+ const state = stateOf(this);
1113
+ if (state.closePromise !== null) return state.closePromise;
1114
+ if (transactionContext.getStore() === state) return Promise.reject(new NativeSqliteConcurrencyError("SQLite connection cannot close inside its transaction callback"));
1115
+ state.closing = true;
1116
+ state.closePromise = state.tail.then(async () => {
1117
+ try {
1118
+ if (!state.closed) await request(state, "close");
1119
+ await state.exited;
1120
+ } finally {
1121
+ state.closed = true;
1122
+ }
1123
+ });
1124
+ return state.closePromise;
1125
+ }
1126
+ };
1127
+ async function openNativeSqlite(path, options = {}) {
1128
+ if (typeof path !== "string" || path.trim() === "" || path.length > 4096 || path.includes("\0")) throw new TypeError("SQLite path must be non-empty bounded text");
1129
+ const checked = checkedOptions(options);
1130
+ const source = "(" + workerMain.toString() + ")()";
1131
+ const worker = new Worker(source, { eval: true, workerData: { path, ...checked } });
1132
+ let readyResolve;
1133
+ let readyReject;
1134
+ let exitResolve;
1135
+ const ready = new Promise((resolve, reject) => {
1136
+ readyResolve = resolve;
1137
+ readyReject = reject;
1138
+ });
1139
+ const exited = new Promise((resolve) => {
1140
+ exitResolve = resolve;
1141
+ });
1142
+ const state = {
1143
+ worker,
1144
+ readyResolve,
1145
+ readyReject,
1146
+ exited,
1147
+ pending: /* @__PURE__ */ new Map(),
1148
+ nextId: 1,
1149
+ queueCapacity: checked.queueCapacity,
1150
+ queued: 0,
1151
+ tail: Promise.resolve(),
1152
+ closing: false,
1153
+ closed: false,
1154
+ closePromise: null
1155
+ };
1156
+ worker.on("message", (message) => {
1157
+ if (message.kind === "ready") {
1158
+ const resolve = state.readyResolve;
1159
+ const reject = state.readyReject;
1160
+ state.readyResolve = null;
1161
+ state.readyReject = null;
1162
+ if (message.error) reject(nativeError(message.error));
1163
+ else resolve();
1164
+ return;
1165
+ }
1166
+ if (message.kind !== "response") return;
1167
+ const pending = state.pending.get(message.id);
1168
+ if (!pending) return;
1169
+ state.pending.delete(message.id);
1170
+ if (message.error) pending.reject(nativeError(message.error));
1171
+ else pending.resolve(message.value);
1172
+ });
1173
+ worker.on("error", (error) => {
1174
+ state.closed = true;
1175
+ failPending(state, new NativeSqliteError(error.message, "SQLITE_WORKER", "worker"));
1176
+ });
1177
+ worker.on("exit", (code) => {
1178
+ exitResolve(code);
1179
+ if (code !== 0 && !state.closed) {
1180
+ state.closed = true;
1181
+ failPending(state, new NativeSqliteError("SQLite Worker exited with code " + code, "SQLITE_WORKER", "worker"));
1182
+ }
1183
+ });
1184
+ await ready;
1185
+ return new NativeSqliteConnection(TOKEN, state);
1186
+ }
1187
+
1188
+ // src/src/index.vel
1189
+ function __velarTypeExplain_SqliteOptions(value) {
1190
+ if (value === null || typeof value !== "object" || __velarValidationIsArray(value) || !__velarValidationIsPlainObject(value)) {
1191
+ return { path: "SqliteOptions", field: null, reason: "the value is not a record" };
1192
+ }
1193
+ {
1194
+ const __velarExplainField = __velarValidationOwnDescriptor(value, "busyTimeoutMilliseconds");
1195
+ if (__velarExplainField !== void 0 && !(__velarExplainField.enumerable && "value" in __velarExplainField && (__velarExplainField.value == null || typeof __velarExplainField.value === "number"))) {
1196
+ return { path: "SqliteOptions.busyTimeoutMilliseconds", field: "busyTimeoutMilliseconds", reason: "field 'busyTimeoutMilliseconds' does not match number?" };
1197
+ }
1198
+ }
1199
+ {
1200
+ const __velarExplainField = __velarValidationOwnDescriptor(value, "queueCapacity");
1201
+ if (__velarExplainField !== void 0 && !(__velarExplainField.enumerable && "value" in __velarExplainField && (__velarExplainField.value == null || typeof __velarExplainField.value === "number"))) {
1202
+ return { path: "SqliteOptions.queueCapacity", field: "queueCapacity", reason: "field 'queueCapacity' does not match number?" };
1203
+ }
1204
+ }
1205
+ {
1206
+ const __velarExplainField = __velarValidationOwnDescriptor(value, "maxRows");
1207
+ if (__velarExplainField !== void 0 && !(__velarExplainField.enumerable && "value" in __velarExplainField && (__velarExplainField.value == null || typeof __velarExplainField.value === "number"))) {
1208
+ return { path: "SqliteOptions.maxRows", field: "maxRows", reason: "field 'maxRows' does not match number?" };
1209
+ }
1210
+ }
1211
+ {
1212
+ const __velarExplainField = __velarValidationOwnDescriptor(value, "maxResultBytes");
1213
+ if (__velarExplainField !== void 0 && !(__velarExplainField.enumerable && "value" in __velarExplainField && (__velarExplainField.value == null || typeof __velarExplainField.value === "number"))) {
1214
+ return { path: "SqliteOptions.maxResultBytes", field: "maxResultBytes", reason: "field 'maxResultBytes' does not match number?" };
1215
+ }
1216
+ }
1217
+ return { path: "SqliteOptions", field: null, reason: null };
1218
+ }
1219
+ function __velarTypeCheck_SqliteOptions(value) {
1220
+ if (value === null || typeof value !== "object" || __velarValidationIsArray(value) || !__velarValidationIsPlainObject(value)) return false;
1221
+ const __velarField0 = __velarValidationOwnDescriptor(value, "busyTimeoutMilliseconds");
1222
+ const __velarField1 = __velarValidationOwnDescriptor(value, "queueCapacity");
1223
+ const __velarField2 = __velarValidationOwnDescriptor(value, "maxRows");
1224
+ const __velarField3 = __velarValidationOwnDescriptor(value, "maxResultBytes");
1225
+ return !!((__velarField0 === void 0 || __velarField0?.enumerable && "value" in __velarField0 && (__velarField0.value == null || typeof __velarField0.value === "number")) && (__velarField1 === void 0 || __velarField1?.enumerable && "value" in __velarField1 && (__velarField1.value == null || typeof __velarField1.value === "number")) && (__velarField2 === void 0 || __velarField2?.enumerable && "value" in __velarField2 && (__velarField2.value == null || typeof __velarField2.value === "number")) && (__velarField3 === void 0 || __velarField3?.enumerable && "value" in __velarField3 && (__velarField3.value == null || typeof __velarField3.value === "number")));
1226
+ }
1227
+ function __velarTypeCopy_SqliteOptions(value, __state, __velarCopyPlan) {
1228
+ const __velarCopySeen = __state.copy.seen(__state, value, __velarCopyPlan);
1229
+ if (__velarCopySeen !== void 0) return __velarCopySeen;
1230
+ const __velarCopy = __state.copy.object(__state, value, __velarCopyPlan);
1231
+ {
1232
+ const __velarCopyField = __velarValidationOwnDescriptor(value, "busyTimeoutMilliseconds");
1233
+ if (__velarCopyField !== void 0) __state.copy.field(__velarCopy, "busyTimeoutMilliseconds", __velarCopyField.value);
1234
+ }
1235
+ {
1236
+ const __velarCopyField = __velarValidationOwnDescriptor(value, "queueCapacity");
1237
+ if (__velarCopyField !== void 0) __state.copy.field(__velarCopy, "queueCapacity", __velarCopyField.value);
1238
+ }
1239
+ {
1240
+ const __velarCopyField = __velarValidationOwnDescriptor(value, "maxRows");
1241
+ if (__velarCopyField !== void 0) __state.copy.field(__velarCopy, "maxRows", __velarCopyField.value);
1242
+ }
1243
+ {
1244
+ const __velarCopyField = __velarValidationOwnDescriptor(value, "maxResultBytes");
1245
+ if (__velarCopyField !== void 0) __state.copy.field(__velarCopy, "maxResultBytes", __velarCopyField.value);
1246
+ }
1247
+ return __velarCopy;
1248
+ }
1249
+ var SqliteOptions = __velarRegisterRuntimeType(__velarValidationFreeze({
1250
+ is(value) {
1251
+ return __velarTypeCheck_SqliteOptions(value);
1252
+ },
1253
+ parse(value) {
1254
+ if (!__velarTypeCheck_SqliteOptions(value)) {
1255
+ const __velarDetail = __velarTypeExplain_SqliteOptions(value);
1256
+ throw new __VelarValidationError("Value does not match SqliteOptions" + (__velarDetail.reason ? " \u2014 " + __velarDetail.reason : "") + __velarValidationRejectionHint(value), __velarDetail);
1257
+ }
1258
+ return __velarTypeCopy_SqliteOptions(value, __velarValidationState(), __velarTypeCopy_SqliteOptions);
1259
+ },
1260
+ copy(value, __state = __velarValidationState(), __velarCopyPlan = __velarTypeCopy_SqliteOptions) {
1261
+ return __velarTypeCopy_SqliteOptions(value, __state, __velarCopyPlan);
1262
+ }
1263
+ }));
1264
+ var SqliteError = class extends Error {
1265
+ constructor(message, sqliteCode = null, operation = "unknown", retryable = false) {
1266
+ super(message);
1267
+ this.name = "SqliteError";
1268
+ const self = this;
1269
+ self.sqliteCode = sqliteCode ?? null;
1270
+ self.operation = operation;
1271
+ self.retryable = retryable;
1272
+ }
1273
+ };
1274
+ var SqliteBackpressureError = class extends SqliteError {
1275
+ constructor(message = "SQLite queue is full") {
1276
+ super(message, "SQLITE_BACKPRESSURE", "queue", true);
1277
+ this.name = "SqliteBackpressureError";
1278
+ const self = this;
1279
+ }
1280
+ };
1281
+ var SqliteConcurrencyError = class extends SqliteError {
1282
+ constructor(message = "SQLite connection cannot be used from its transaction callback") {
1283
+ super(message, "SQLITE_CONCURRENCY", "transaction", true);
1284
+ this.name = "SqliteConcurrencyError";
1285
+ const self = this;
1286
+ }
1287
+ };
1288
+ function sqliteFailure(error) {
1289
+ if (error instanceof NativeSqliteBackpressureError) {
1290
+ return new SqliteBackpressureError(((__velarValue) => __velarNarrow(__velarValue, __velarValidationIsInstance(__velarValue, NativeSqliteBackpressureError), "NativeSqliteBackpressureError", "error", 20523))(error).message);
1291
+ }
1292
+ if (error instanceof NativeSqliteConcurrencyError) {
1293
+ return new SqliteConcurrencyError(((__velarValue) => __velarNarrow(__velarValue, __velarValidationIsInstance(__velarValue, NativeSqliteConcurrencyError), "NativeSqliteConcurrencyError", "error", 20622))(error).message);
1294
+ }
1295
+ if (error instanceof NativeSqliteError) {
1296
+ return new SqliteError(((__velarValue) => __velarNarrow(__velarValue, __velarValidationIsInstance(__velarValue, NativeSqliteError), "NativeSqliteError", "error", 20699))(error).message, ((__velarValue) => __velarNarrow(__velarValue, __velarValidationIsInstance(__velarValue, NativeSqliteError), "NativeSqliteError", "error", 20714))(error).sqliteCode ?? null, ((__velarValue) => __velarNarrow(__velarValue, __velarValidationIsInstance(__velarValue, NativeSqliteError), "NativeSqliteError", "error", 20732))(error).operation, ((__velarValue) => __velarNarrow(__velarValue, __velarValidationIsInstance(__velarValue, NativeSqliteError), "NativeSqliteError", "error", 20749))(error).retryable);
1297
+ }
1298
+ return new SqliteError(error.message);
1299
+ }
1300
+ var SqliteTransaction = class {
1301
+ #native;
1302
+ constructor(native) {
1303
+ this.#native = native;
1304
+ const self = this;
1305
+ }
1306
+ async execute(sql, params = __velarAdoptList([])) {
1307
+ const self = this;
1308
+ try {
1309
+ return await __velarNormalizePromiseValue(__velarReadPrivateField(self.#native, "native").execute(sql, params));
1310
+ } catch (error) {
1311
+ error = __velarNormalizeError(error);
1312
+ if (error instanceof NativeSqliteError) {
1313
+ throw sqliteFailure(((__velarValue) => __velarNarrow(__velarValue, __velarValidationIsInstance(__velarValue, NativeSqliteError), "NativeSqliteError", "error", 21160))(error));
1314
+ }
1315
+ throw new SqliteError(__velarReadInstanceField(error, "message"));
1316
+ }
1317
+ }
1318
+ executor() {
1319
+ const self = this;
1320
+ async function executeStatement(text, parameters) {
1321
+ return await __velarNormalizePromiseValue(self.execute(text, parameters));
1322
+ }
1323
+ async function oneRow(text, parameters) {
1324
+ try {
1325
+ return __velarAsyncResolvedValue(await __velarNormalizePromiseValue(__velarReadPrivateField(self.#native, "native").one(text, parameters)));
1326
+ } catch (error) {
1327
+ error = __velarNormalizeError(error);
1328
+ if (error instanceof NativeSqliteError) {
1329
+ throw sqliteFailure(((__velarValue) => __velarNarrow(__velarValue, __velarValidationIsInstance(__velarValue, NativeSqliteError), "NativeSqliteError", "error", 21753))(error));
1330
+ }
1331
+ throw new SqliteError(__velarReadInstanceField(error, "message"));
1332
+ }
1333
+ }
1334
+ async function allRows(text, parameters) {
1335
+ try {
1336
+ return __velarAsyncResolvedValue(await __velarNormalizePromiseValue(__velarReadPrivateField(self.#native, "native").all(text, parameters)));
1337
+ } catch (error) {
1338
+ error = __velarNormalizeError(error);
1339
+ if (error instanceof NativeSqliteError) {
1340
+ throw sqliteFailure(((__velarValue) => __velarNarrow(__velarValue, __velarValidationIsInstance(__velarValue, NativeSqliteError), "NativeSqliteError", "error", 22087))(error));
1341
+ }
1342
+ throw new SqliteError(__velarReadInstanceField(error, "message"));
1343
+ }
1344
+ }
1345
+ return { execute: executeStatement, one: oneRow, all: allRows };
1346
+ }
1347
+ async one(sql, RowType, params = __velarAdoptList([])) {
1348
+ const self = this;
1349
+ try {
1350
+ const row = await __velarNormalizePromiseValue(__velarReadPrivateField(self.#native, "native").one(sql, params));
1351
+ if ((row ?? null) === null) {
1352
+ return null;
1353
+ }
1354
+ return __velarAsyncResolvedValue(RowType.parse(row ?? null));
1355
+ } catch (error) {
1356
+ error = __velarNormalizeError(error);
1357
+ if (error instanceof NativeSqliteError) {
1358
+ throw sqliteFailure(((__velarValue) => __velarNarrow(__velarValue, __velarValidationIsInstance(__velarValue, NativeSqliteError), "NativeSqliteError", "error", 22568))(error));
1359
+ }
1360
+ throw new SqliteError(__velarReadInstanceField(error, "message"));
1361
+ }
1362
+ }
1363
+ async all(sql, RowType, params = __velarAdoptList([])) {
1364
+ const self = this;
1365
+ try {
1366
+ const rows = await __velarNormalizePromiseValue(__velarReadPrivateField(self.#native, "native").all(sql, params));
1367
+ return __velarAsyncResolvedValue(__velarListMap(rows, (row) => RowType.parse(row ?? null)));
1368
+ } catch (error) {
1369
+ error = __velarNormalizeError(error);
1370
+ if (error instanceof NativeSqliteError) {
1371
+ throw sqliteFailure(((__velarValue) => __velarNarrow(__velarValue, __velarValidationIsInstance(__velarValue, NativeSqliteError), "NativeSqliteError", "error", 22941))(error));
1372
+ }
1373
+ throw new SqliteError(__velarReadInstanceField(error, "message"));
1374
+ }
1375
+ }
1376
+ };
1377
+ var SqliteConnection = class {
1378
+ #native;
1379
+ constructor(native) {
1380
+ this.#native = native;
1381
+ const self = this;
1382
+ }
1383
+ async execute(sql, params = __velarAdoptList([])) {
1384
+ const self = this;
1385
+ try {
1386
+ return await __velarNormalizePromiseValue(__velarReadPrivateField(self.#native, "native").execute(sql, params));
1387
+ } catch (error) {
1388
+ error = __velarNormalizeError(error);
1389
+ if (error instanceof NativeSqliteError) {
1390
+ throw sqliteFailure(((__velarValue) => __velarNarrow(__velarValue, __velarValidationIsInstance(__velarValue, NativeSqliteError), "NativeSqliteError", "error", 23347))(error));
1391
+ }
1392
+ throw new SqliteError(__velarReadInstanceField(error, "message"));
1393
+ }
1394
+ }
1395
+ executor() {
1396
+ const self = this;
1397
+ async function executeStatement(text, parameters) {
1398
+ return await __velarNormalizePromiseValue(self.execute(text, parameters));
1399
+ }
1400
+ async function oneRow(text, parameters) {
1401
+ try {
1402
+ return __velarAsyncResolvedValue(await __velarNormalizePromiseValue(__velarReadPrivateField(self.#native, "native").one(text, parameters)));
1403
+ } catch (error) {
1404
+ error = __velarNormalizeError(error);
1405
+ if (error instanceof NativeSqliteError) {
1406
+ throw sqliteFailure(((__velarValue) => __velarNarrow(__velarValue, __velarValidationIsInstance(__velarValue, NativeSqliteError), "NativeSqliteError", "error", 23939))(error));
1407
+ }
1408
+ throw new SqliteError(__velarReadInstanceField(error, "message"));
1409
+ }
1410
+ }
1411
+ async function allRows(text, parameters) {
1412
+ try {
1413
+ return __velarAsyncResolvedValue(await __velarNormalizePromiseValue(__velarReadPrivateField(self.#native, "native").all(text, parameters)));
1414
+ } catch (error) {
1415
+ error = __velarNormalizeError(error);
1416
+ if (error instanceof NativeSqliteError) {
1417
+ throw sqliteFailure(((__velarValue) => __velarNarrow(__velarValue, __velarValidationIsInstance(__velarValue, NativeSqliteError), "NativeSqliteError", "error", 24273))(error));
1418
+ }
1419
+ throw new SqliteError(__velarReadInstanceField(error, "message"));
1420
+ }
1421
+ }
1422
+ return { execute: executeStatement, one: oneRow, all: allRows };
1423
+ }
1424
+ async one(sql, RowType, params = __velarAdoptList([])) {
1425
+ const self = this;
1426
+ try {
1427
+ const row = await __velarNormalizePromiseValue(__velarReadPrivateField(self.#native, "native").one(sql, params));
1428
+ if ((row ?? null) === null) {
1429
+ return null;
1430
+ }
1431
+ return __velarAsyncResolvedValue(RowType.parse(row ?? null));
1432
+ } catch (error) {
1433
+ error = __velarNormalizeError(error);
1434
+ if (error instanceof NativeSqliteError) {
1435
+ throw sqliteFailure(((__velarValue) => __velarNarrow(__velarValue, __velarValidationIsInstance(__velarValue, NativeSqliteError), "NativeSqliteError", "error", 24754))(error));
1436
+ }
1437
+ throw new SqliteError(__velarReadInstanceField(error, "message"));
1438
+ }
1439
+ }
1440
+ async all(sql, RowType, params = __velarAdoptList([])) {
1441
+ const self = this;
1442
+ try {
1443
+ const rows = await __velarNormalizePromiseValue(__velarReadPrivateField(self.#native, "native").all(sql, params));
1444
+ return __velarAsyncResolvedValue(__velarListMap(rows, (row) => RowType.parse(row ?? null)));
1445
+ } catch (error) {
1446
+ error = __velarNormalizeError(error);
1447
+ if (error instanceof NativeSqliteError) {
1448
+ throw sqliteFailure(((__velarValue) => __velarNarrow(__velarValue, __velarValidationIsInstance(__velarValue, NativeSqliteError), "NativeSqliteError", "error", 25127))(error));
1449
+ }
1450
+ throw new SqliteError(__velarReadInstanceField(error, "message"));
1451
+ }
1452
+ }
1453
+ async transaction(operation) {
1454
+ const self = this;
1455
+ const results = __velarAdoptList([]);
1456
+ async function run(native) {
1457
+ __velarListAppend(results, await __velarNormalizePromiseValue(operation(new SqliteTransaction(native))));
1458
+ return null;
1459
+ }
1460
+ try {
1461
+ await __velarNormalizePromiseValue(__velarReadPrivateField(self.#native, "native").transaction(run));
1462
+ if (!(__velarListSize(results) === 1)) {
1463
+ throw new __VelarAssertionError("SQLite transaction did not return exactly one result");
1464
+ }
1465
+ return __velarAsyncResolvedValue(__velarListIndexGet(results, 0));
1466
+ } catch (error) {
1467
+ error = __velarNormalizeError(error);
1468
+ if (error instanceof NativeSqliteError) {
1469
+ throw sqliteFailure(((__velarValue) => __velarNarrow(__velarValue, __velarValidationIsInstance(__velarValue, NativeSqliteError), "NativeSqliteError", "error", 25714))(error));
1470
+ }
1471
+ throw error;
1472
+ }
1473
+ }
1474
+ async close() {
1475
+ const self = this;
1476
+ try {
1477
+ await __velarNormalizePromiseValue(__velarReadPrivateField(self.#native, "native").close());
1478
+ } catch (error) {
1479
+ error = __velarNormalizeError(error);
1480
+ if (error instanceof NativeSqliteError) {
1481
+ throw sqliteFailure(((__velarValue) => __velarNarrow(__velarValue, __velarValidationIsInstance(__velarValue, NativeSqliteError), "NativeSqliteError", "error", 25920))(error));
1482
+ }
1483
+ throw new SqliteError(__velarReadInstanceField(error, "message"));
1484
+ }
1485
+ return null;
1486
+ }
1487
+ async ["__velar:dispose"]() {
1488
+ const self = this;
1489
+ await __velarNormalizePromiseValue(self.close());
1490
+ return null;
1491
+ }
1492
+ };
1493
+ async function openSqlite(path, options = {}) {
1494
+ try {
1495
+ return __velarAsyncResolvedValue(new SqliteConnection(await __velarNormalizePromiseValue(openNativeSqlite(__velarHostRaw(path), __velarHostRaw(options)))));
1496
+ } catch (error) {
1497
+ error = __velarNormalizeError(error);
1498
+ if (error instanceof NativeSqliteError) {
1499
+ throw sqliteFailure(((__velarValue) => __velarNarrow(__velarValue, __velarValidationIsInstance(__velarValue, NativeSqliteError), "NativeSqliteError", "error", 26275))(error));
1500
+ }
1501
+ throw new SqliteError(__velarReadInstanceField(error, "message"));
1502
+ }
1503
+ }
1504
+ export {
1505
+ SqliteBackpressureError,
1506
+ SqliteConcurrencyError,
1507
+ SqliteConnection,
1508
+ SqliteError,
1509
+ SqliteOptions,
1510
+ SqliteTransaction,
1511
+ openSqlite
1512
+ };