@velarscript-labs/sqlite 0.2.1 → 0.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +28 -0
- package/README.md +44 -12
- package/dist/index.js +1936 -0
- package/dist/index.js.map +1 -0
- package/dist/index.veli.json +7206 -0
- package/dist/velar-library.json +28 -0
- package/package.json +12 -5
- package/src/index.vel +161 -67
package/dist/index.js
ADDED
|
@@ -0,0 +1,1936 @@
|
|
|
1
|
+
// velar-standard:velar/text
|
|
2
|
+
var __velarMaxTextCodeUnits = 16 * 1024 * 1024;
|
|
3
|
+
var __velarTextNativeArray = globalThis.Array;
|
|
4
|
+
var __velarTextNativeString = globalThis.String;
|
|
5
|
+
var __velarTextNativeNumber = globalThis.Number;
|
|
6
|
+
var __velarTextNativeMath = globalThis.Math;
|
|
7
|
+
var __velarTextNativeObject = globalThis.Object;
|
|
8
|
+
var __velarTextNativeMap = globalThis.Map;
|
|
9
|
+
var __velarTextNativeTypeError = globalThis.TypeError;
|
|
10
|
+
var __velarTextNativeRangeError = globalThis.RangeError;
|
|
11
|
+
var __velarTextGetOwnPropertyDescriptor = __velarTextNativeObject.getOwnPropertyDescriptor;
|
|
12
|
+
var __velarTextRuntimeGetPrototypeOf = __velarTextGetOwnPropertyDescriptor(__velarTextNativeObject, "getPrototypeOf")?.value;
|
|
13
|
+
var __velarTextReflectApply = __velarTextGetOwnPropertyDescriptor(globalThis.Reflect, "apply")?.value;
|
|
14
|
+
var __velarTextStringPrototype = __velarTextGetOwnPropertyDescriptor(__velarTextNativeString, "prototype")?.value;
|
|
15
|
+
var __velarTextArrayIsArray = __velarTextGetOwnPropertyDescriptor(__velarTextNativeArray, "isArray")?.value;
|
|
16
|
+
var __velarTextNumberIsSafeInteger = __velarTextGetOwnPropertyDescriptor(__velarTextNativeNumber, "isSafeInteger")?.value;
|
|
17
|
+
var __velarTextNumberIsInteger = __velarTextGetOwnPropertyDescriptor(__velarTextNativeNumber, "isInteger")?.value;
|
|
18
|
+
var __velarTextMathFloor = __velarTextGetOwnPropertyDescriptor(__velarTextNativeMath, "floor")?.value;
|
|
19
|
+
var __velarTextMathMax = __velarTextGetOwnPropertyDescriptor(__velarTextNativeMath, "max")?.value;
|
|
20
|
+
var __velarTextMathMin = __velarTextGetOwnPropertyDescriptor(__velarTextNativeMath, "min")?.value;
|
|
21
|
+
var __velarNativeStringIndexOf = __velarTextGetOwnPropertyDescriptor(__velarTextStringPrototype, "indexOf")?.value;
|
|
22
|
+
var __velarNativeStringSlice = __velarTextGetOwnPropertyDescriptor(__velarTextStringPrototype, "slice")?.value;
|
|
23
|
+
var __velarNativeStringCharCodeAt = __velarTextGetOwnPropertyDescriptor(__velarTextStringPrototype, "charCodeAt")?.value;
|
|
24
|
+
var __velarNativeStringTrim = __velarTextGetOwnPropertyDescriptor(__velarTextStringPrototype, "trim")?.value;
|
|
25
|
+
var __velarNativeStringUpper = __velarTextGetOwnPropertyDescriptor(__velarTextStringPrototype, "toUpperCase")?.value;
|
|
26
|
+
var __velarNativeStringLower = __velarTextGetOwnPropertyDescriptor(__velarTextStringPrototype, "toLowerCase")?.value;
|
|
27
|
+
var __velarNativeStringSplit = __velarTextGetOwnPropertyDescriptor(__velarTextStringPrototype, "split")?.value;
|
|
28
|
+
var __velarNativeStringReplaceAll = __velarTextGetOwnPropertyDescriptor(__velarTextStringPrototype, "replaceAll")?.value;
|
|
29
|
+
var __velarNativeStringRepeat = __velarTextGetOwnPropertyDescriptor(__velarTextStringPrototype, "repeat")?.value;
|
|
30
|
+
var __velarTextMapPrototype = typeof __velarTextNativeMap === "function" ? __velarTextGetOwnPropertyDescriptor(__velarTextNativeMap, "prototype")?.value : null;
|
|
31
|
+
var __velarTextMapGet = __velarTextMapPrototype ? __velarTextGetOwnPropertyDescriptor(__velarTextMapPrototype, "get")?.value : null;
|
|
32
|
+
var __velarTextMapSet = __velarTextMapPrototype ? __velarTextGetOwnPropertyDescriptor(__velarTextMapPrototype, "set")?.value : null;
|
|
33
|
+
var __velarTextMapClear = __velarTextMapPrototype ? __velarTextGetOwnPropertyDescriptor(__velarTextMapPrototype, "clear")?.value : null;
|
|
34
|
+
var __velarTextSurrogatePattern = /[\u{10000}-\u{10FFFF}\uD800-\uDFFF]/u;
|
|
35
|
+
var __velarTextRegExpPrototype = typeof __velarTextRuntimeGetPrototypeOf === "function" ? __velarTextRuntimeGetPrototypeOf(__velarTextSurrogatePattern) : null;
|
|
36
|
+
var __velarTextSurrogateExec = __velarTextRegExpPrototype ? __velarTextGetOwnPropertyDescriptor(__velarTextRegExpPrototype, "exec")?.value : null;
|
|
37
|
+
function __velarTextCall(operation, receiver, arguments_) {
|
|
38
|
+
if (typeof operation !== "function" || typeof __velarTextReflectApply !== "function") throw new __velarTextNativeTypeError("The JavaScript text runtime is unavailable");
|
|
39
|
+
return __velarTextReflectApply(operation, receiver, arguments_);
|
|
40
|
+
}
|
|
41
|
+
var __velarTextMeasureCacheUnits = 8 * 1024 * 1024;
|
|
42
|
+
var __velarTextMeasureCache = typeof __velarTextNativeMap === "function" && typeof __velarTextMapGet === "function" && typeof __velarTextMapSet === "function" && typeof __velarTextMapClear === "function" ? new __velarTextNativeMap() : null;
|
|
43
|
+
var __velarUtf8CharCodeAt = Object.getOwnPropertyDescriptor(String.prototype, "charCodeAt")?.value;
|
|
44
|
+
var __velarUtf8ReflectApply = Object.getOwnPropertyDescriptor(Reflect, "apply")?.value;
|
|
45
|
+
var __velarTextGetOwnPropertyNames = __velarTextGetOwnPropertyDescriptor(__velarTextNativeObject, "getOwnPropertyNames")?.value;
|
|
46
|
+
var __velarTextGetOwnPropertySymbols = __velarTextGetOwnPropertyDescriptor(__velarTextNativeObject, "getOwnPropertySymbols")?.value;
|
|
47
|
+
var __velarTextGetPrototypeOf = __velarTextGetOwnPropertyDescriptor(__velarTextNativeObject, "getPrototypeOf")?.value;
|
|
48
|
+
var __velarTextObjectPrototype = __velarTextGetOwnPropertyDescriptor(__velarTextNativeObject, "prototype")?.value;
|
|
49
|
+
var __velarTextObjectCreate = __velarTextGetOwnPropertyDescriptor(__velarTextNativeObject, "create")?.value;
|
|
50
|
+
var __velarTextObjectFreeze = __velarTextGetOwnPropertyDescriptor(__velarTextNativeObject, "freeze")?.value;
|
|
51
|
+
var __velarTextArrayPrototype = __velarTextGetOwnPropertyDescriptor(__velarTextNativeArray, "prototype")?.value;
|
|
52
|
+
var __velarTextArrayJoin = __velarTextGetOwnPropertyDescriptor(__velarTextArrayPrototype, "join")?.value;
|
|
53
|
+
var __velarTextStringTrimStart = __velarTextGetOwnPropertyDescriptor(__velarTextStringPrototype, "trimStart")?.value;
|
|
54
|
+
var __velarTextStringTrimEnd = __velarTextGetOwnPropertyDescriptor(__velarTextStringPrototype, "trimEnd")?.value;
|
|
55
|
+
var __velarTextStringNormalize = __velarTextGetOwnPropertyDescriptor(__velarTextStringPrototype, "normalize")?.value;
|
|
56
|
+
var __velarTextNativeDate = globalThis.Date;
|
|
57
|
+
var __velarTextDateNow = __velarTextGetOwnPropertyDescriptor(__velarTextNativeDate, "now")?.value;
|
|
58
|
+
var nativeRegExpPrototype = __velarTextGetPrototypeOf(/(?:)/u);
|
|
59
|
+
var NativeRegExp = __velarTextGetOwnPropertyDescriptor(nativeRegExpPrototype, "constructor")?.value;
|
|
60
|
+
var nativeRegExpExec = __velarTextGetOwnPropertyDescriptor(nativeRegExpPrototype, "exec")?.value;
|
|
61
|
+
var __velarTextStringCodePointAt = __velarTextGetOwnPropertyDescriptor(__velarTextStringPrototype, "codePointAt")?.value;
|
|
62
|
+
var __velarTextStringFromCodePoint = __velarTextGetOwnPropertyDescriptor(__velarTextNativeString, "fromCodePoint")?.value;
|
|
63
|
+
var __velarTextLatinMarks = new RegExp("(?<=\\p{Script=Latin})\\p{M}+", "gu");
|
|
64
|
+
var __velarTextBaselessMarks = new RegExp("(?<![\\p{L}\\p{N}\\p{M}])\\p{M}+", "gu");
|
|
65
|
+
function fromCodePoint(value) {
|
|
66
|
+
if (!__velarTextCall(__velarTextNumberIsSafeInteger, __velarTextNativeNumber, [value]) || value < 0 || value > 1114111) {
|
|
67
|
+
throw new __velarTextNativeRangeError("fromCodePoint requires a code point from 0 through 1114111");
|
|
68
|
+
}
|
|
69
|
+
if (value >= 55296 && value <= 57343) throw new __velarTextNativeRangeError("fromCodePoint refuses surrogate halves; they are not characters on their own");
|
|
70
|
+
return __velarTextCall(__velarTextStringFromCodePoint, __velarTextNativeString, [value]);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
// velar-standard:velar/compiler-runtime-reactive-v1
|
|
74
|
+
var __velarReactiveStructureKey = null;
|
|
75
|
+
function __velarReactiveRaw(value) {
|
|
76
|
+
return value;
|
|
77
|
+
}
|
|
78
|
+
function __velarHostRaw(value) {
|
|
79
|
+
return value;
|
|
80
|
+
}
|
|
81
|
+
function __velarReactiveCollectionRead(value, key, child) {
|
|
82
|
+
return child === void 0 ? null : child;
|
|
83
|
+
}
|
|
84
|
+
function __velarReactiveCollectionTrack() {
|
|
85
|
+
}
|
|
86
|
+
function __velarReactiveCollectionLink() {
|
|
87
|
+
}
|
|
88
|
+
function __velarReactiveCollectionTrigger() {
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
// velar-standard:velar/compiler-runtime-primitives-v1
|
|
92
|
+
var __velarMaxTextCodeUnits2 = 16 * 1024 * 1024;
|
|
93
|
+
var __velarTextNativeArray2 = globalThis.Array;
|
|
94
|
+
var __velarTextNativeString2 = globalThis.String;
|
|
95
|
+
var __velarTextNativeNumber2 = globalThis.Number;
|
|
96
|
+
var __velarTextNativeMath2 = globalThis.Math;
|
|
97
|
+
var __velarTextNativeObject2 = globalThis.Object;
|
|
98
|
+
var __velarTextNativeMap2 = globalThis.Map;
|
|
99
|
+
var __velarTextNativeTypeError2 = globalThis.TypeError;
|
|
100
|
+
var __velarTextNativeRangeError2 = globalThis.RangeError;
|
|
101
|
+
var __velarTextGetOwnPropertyDescriptor2 = __velarTextNativeObject2.getOwnPropertyDescriptor;
|
|
102
|
+
var __velarTextRuntimeGetPrototypeOf2 = __velarTextGetOwnPropertyDescriptor2(__velarTextNativeObject2, "getPrototypeOf")?.value;
|
|
103
|
+
var __velarTextReflectApply2 = __velarTextGetOwnPropertyDescriptor2(globalThis.Reflect, "apply")?.value;
|
|
104
|
+
var __velarTextStringPrototype2 = __velarTextGetOwnPropertyDescriptor2(__velarTextNativeString2, "prototype")?.value;
|
|
105
|
+
var __velarTextArrayIsArray2 = __velarTextGetOwnPropertyDescriptor2(__velarTextNativeArray2, "isArray")?.value;
|
|
106
|
+
var __velarTextNumberIsSafeInteger2 = __velarTextGetOwnPropertyDescriptor2(__velarTextNativeNumber2, "isSafeInteger")?.value;
|
|
107
|
+
var __velarTextNumberIsInteger2 = __velarTextGetOwnPropertyDescriptor2(__velarTextNativeNumber2, "isInteger")?.value;
|
|
108
|
+
var __velarTextMathFloor2 = __velarTextGetOwnPropertyDescriptor2(__velarTextNativeMath2, "floor")?.value;
|
|
109
|
+
var __velarTextMathMax2 = __velarTextGetOwnPropertyDescriptor2(__velarTextNativeMath2, "max")?.value;
|
|
110
|
+
var __velarTextMathMin2 = __velarTextGetOwnPropertyDescriptor2(__velarTextNativeMath2, "min")?.value;
|
|
111
|
+
var __velarNativeStringIndexOf2 = __velarTextGetOwnPropertyDescriptor2(__velarTextStringPrototype2, "indexOf")?.value;
|
|
112
|
+
var __velarNativeStringSlice2 = __velarTextGetOwnPropertyDescriptor2(__velarTextStringPrototype2, "slice")?.value;
|
|
113
|
+
var __velarNativeStringCharCodeAt2 = __velarTextGetOwnPropertyDescriptor2(__velarTextStringPrototype2, "charCodeAt")?.value;
|
|
114
|
+
var __velarNativeStringTrim2 = __velarTextGetOwnPropertyDescriptor2(__velarTextStringPrototype2, "trim")?.value;
|
|
115
|
+
var __velarNativeStringUpper2 = __velarTextGetOwnPropertyDescriptor2(__velarTextStringPrototype2, "toUpperCase")?.value;
|
|
116
|
+
var __velarNativeStringLower2 = __velarTextGetOwnPropertyDescriptor2(__velarTextStringPrototype2, "toLowerCase")?.value;
|
|
117
|
+
var __velarNativeStringSplit2 = __velarTextGetOwnPropertyDescriptor2(__velarTextStringPrototype2, "split")?.value;
|
|
118
|
+
var __velarNativeStringReplaceAll2 = __velarTextGetOwnPropertyDescriptor2(__velarTextStringPrototype2, "replaceAll")?.value;
|
|
119
|
+
var __velarNativeStringRepeat2 = __velarTextGetOwnPropertyDescriptor2(__velarTextStringPrototype2, "repeat")?.value;
|
|
120
|
+
var __velarTextMapPrototype2 = typeof __velarTextNativeMap2 === "function" ? __velarTextGetOwnPropertyDescriptor2(__velarTextNativeMap2, "prototype")?.value : null;
|
|
121
|
+
var __velarTextMapGet2 = __velarTextMapPrototype2 ? __velarTextGetOwnPropertyDescriptor2(__velarTextMapPrototype2, "get")?.value : null;
|
|
122
|
+
var __velarTextMapSet2 = __velarTextMapPrototype2 ? __velarTextGetOwnPropertyDescriptor2(__velarTextMapPrototype2, "set")?.value : null;
|
|
123
|
+
var __velarTextMapClear2 = __velarTextMapPrototype2 ? __velarTextGetOwnPropertyDescriptor2(__velarTextMapPrototype2, "clear")?.value : null;
|
|
124
|
+
var __velarTextSurrogatePattern2 = /[\u{10000}-\u{10FFFF}\uD800-\uDFFF]/u;
|
|
125
|
+
var __velarTextRegExpPrototype2 = typeof __velarTextRuntimeGetPrototypeOf2 === "function" ? __velarTextRuntimeGetPrototypeOf2(__velarTextSurrogatePattern2) : null;
|
|
126
|
+
var __velarTextSurrogateExec2 = __velarTextRegExpPrototype2 ? __velarTextGetOwnPropertyDescriptor2(__velarTextRegExpPrototype2, "exec")?.value : null;
|
|
127
|
+
function __velarTextCall2(operation, receiver, arguments_) {
|
|
128
|
+
if (typeof operation !== "function" || typeof __velarTextReflectApply2 !== "function") throw new __velarTextNativeTypeError2("The JavaScript text runtime is unavailable");
|
|
129
|
+
return __velarTextReflectApply2(operation, receiver, arguments_);
|
|
130
|
+
}
|
|
131
|
+
function __velarTextValue(value) {
|
|
132
|
+
if (typeof value !== "string") throw new __velarTextNativeTypeError2("String methods require a string receiver");
|
|
133
|
+
if (value.length > __velarMaxTextCodeUnits2) throw new __velarTextNativeRangeError2("Strings cannot exceed 16 MiB");
|
|
134
|
+
return value;
|
|
135
|
+
}
|
|
136
|
+
function __velarTextArgument(value, name) {
|
|
137
|
+
if (typeof value !== "string") throw new __velarTextNativeTypeError2(name + " must be a string");
|
|
138
|
+
if (value.length > __velarMaxTextCodeUnits2) throw new __velarTextNativeRangeError2(name + " cannot exceed 16 MiB");
|
|
139
|
+
return value;
|
|
140
|
+
}
|
|
141
|
+
function __velarTextNextCodePointOffset(value, offset) {
|
|
142
|
+
const first = __velarTextCall2(__velarNativeStringCharCodeAt2, value, [offset]);
|
|
143
|
+
if (first < 55296 || first > 56319 || offset + 1 >= value.length) return offset + 1;
|
|
144
|
+
const second = __velarTextCall2(__velarNativeStringCharCodeAt2, value, [offset + 1]);
|
|
145
|
+
return second >= 56320 && second <= 57343 ? offset + 2 : offset + 1;
|
|
146
|
+
}
|
|
147
|
+
var __velarTextCheckpointStride = 64;
|
|
148
|
+
var __velarTextMeasureMinimumUnits = 64;
|
|
149
|
+
var __velarTextMeasureCacheEntries = 512;
|
|
150
|
+
var __velarTextMeasureCacheUnits2 = 8 * 1024 * 1024;
|
|
151
|
+
var __velarTextMeasureCache2 = typeof __velarTextNativeMap2 === "function" && typeof __velarTextMapGet2 === "function" && typeof __velarTextMapSet2 === "function" && typeof __velarTextMapClear2 === "function" ? new __velarTextNativeMap2() : null;
|
|
152
|
+
var __velarTextMeasureCacheCount = 0;
|
|
153
|
+
var __velarTextMeasureCacheHeld = 0;
|
|
154
|
+
function __velarTextMeasureText(value) {
|
|
155
|
+
if (__velarTextCall2(__velarTextSurrogateExec2, __velarTextSurrogatePattern2, [value]) === null) {
|
|
156
|
+
return { length: value.length, dense: true, checkpoints: null };
|
|
157
|
+
}
|
|
158
|
+
const checkpoints = new __velarTextNativeArray2();
|
|
159
|
+
let length = 0, offset = 0;
|
|
160
|
+
while (offset < value.length) {
|
|
161
|
+
if (length % __velarTextCheckpointStride === 0) checkpoints[length / __velarTextCheckpointStride] = offset;
|
|
162
|
+
offset = __velarTextNextCodePointOffset(value, offset);
|
|
163
|
+
length += 1;
|
|
164
|
+
}
|
|
165
|
+
return { length, dense: length === value.length, checkpoints };
|
|
166
|
+
}
|
|
167
|
+
function __velarTextMeasure(value) {
|
|
168
|
+
if (__velarTextMeasureCache2 === null || value.length < __velarTextMeasureMinimumUnits) return __velarTextMeasureText(value);
|
|
169
|
+
const cached = __velarTextCall2(__velarTextMapGet2, __velarTextMeasureCache2, [value]);
|
|
170
|
+
if (cached !== void 0) return cached;
|
|
171
|
+
const measured = __velarTextMeasureText(value);
|
|
172
|
+
if (__velarTextMeasureCacheCount >= __velarTextMeasureCacheEntries || __velarTextMeasureCacheCount > 0 && __velarTextMeasureCacheHeld + value.length > __velarTextMeasureCacheUnits2) {
|
|
173
|
+
__velarTextCall2(__velarTextMapClear2, __velarTextMeasureCache2, []);
|
|
174
|
+
__velarTextMeasureCacheCount = 0;
|
|
175
|
+
__velarTextMeasureCacheHeld = 0;
|
|
176
|
+
}
|
|
177
|
+
__velarTextCall2(__velarTextMapSet2, __velarTextMeasureCache2, [value, measured]);
|
|
178
|
+
__velarTextMeasureCacheCount += 1;
|
|
179
|
+
__velarTextMeasureCacheHeld += value.length;
|
|
180
|
+
return measured;
|
|
181
|
+
}
|
|
182
|
+
function __velarTextCodePointLength(value) {
|
|
183
|
+
return __velarTextMeasure(value).length;
|
|
184
|
+
}
|
|
185
|
+
function __velarTextIsBoundary(value, offset) {
|
|
186
|
+
if (offset <= 0 || offset >= value.length) return true;
|
|
187
|
+
const lead = __velarTextCall2(__velarNativeStringCharCodeAt2, value, [offset - 1]);
|
|
188
|
+
if (lead < 55296 || lead > 56319) return true;
|
|
189
|
+
const trail = __velarTextCall2(__velarNativeStringCharCodeAt2, value, [offset]);
|
|
190
|
+
return trail < 56320 || trail > 57343;
|
|
191
|
+
}
|
|
192
|
+
function __velarTextNeedsBoundaryCheck(search) {
|
|
193
|
+
const first = __velarTextCall2(__velarNativeStringCharCodeAt2, search, [0]);
|
|
194
|
+
if (first >= 56320 && first <= 57343) return true;
|
|
195
|
+
const last = __velarTextCall2(__velarNativeStringCharCodeAt2, search, [search.length - 1]);
|
|
196
|
+
return last >= 55296 && last <= 56319;
|
|
197
|
+
}
|
|
198
|
+
function __velarTextBoundedIndexOf(value, search, cursor) {
|
|
199
|
+
if (!__velarTextNeedsBoundaryCheck(search)) return __velarTextCall2(__velarNativeStringIndexOf2, value, [search, cursor]);
|
|
200
|
+
while (cursor <= value.length) {
|
|
201
|
+
const found = __velarTextCall2(__velarNativeStringIndexOf2, value, [search, cursor]);
|
|
202
|
+
if (found < 0) return -1;
|
|
203
|
+
if (__velarTextIsBoundary(value, found) && __velarTextIsBoundary(value, found + search.length)) return found;
|
|
204
|
+
cursor = found + 1;
|
|
205
|
+
}
|
|
206
|
+
return -1;
|
|
207
|
+
}
|
|
208
|
+
function __velarTextReplacementOutputUnits(value, search, replacement, all) {
|
|
209
|
+
let matches = 0;
|
|
210
|
+
if (search === "") matches = all ? __velarTextCodePointLength(value) + 1 : 1;
|
|
211
|
+
else {
|
|
212
|
+
let cursor = 0;
|
|
213
|
+
while (true) {
|
|
214
|
+
const index = __velarTextBoundedIndexOf(value, search, cursor);
|
|
215
|
+
if (index < 0) break;
|
|
216
|
+
matches += 1;
|
|
217
|
+
if (!all) break;
|
|
218
|
+
cursor = index + search.length;
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
if (replacement.length <= search.length || matches === 0) return value.length;
|
|
222
|
+
const growth = replacement.length - search.length;
|
|
223
|
+
if (matches > __velarTextCall2(__velarTextMathFloor2, __velarTextNativeMath2, [(__velarMaxTextCodeUnits2 - value.length) / growth])) return __velarMaxTextCodeUnits2 + 1;
|
|
224
|
+
return value.length + matches * growth;
|
|
225
|
+
}
|
|
226
|
+
function __velarStringSize(value) {
|
|
227
|
+
return __velarTextCodePointLength(__velarTextValue(value));
|
|
228
|
+
}
|
|
229
|
+
function __velarStringIsBlank(value) {
|
|
230
|
+
return __velarTextCall2(__velarNativeStringTrim2, __velarTextValue(value), []) === "";
|
|
231
|
+
}
|
|
232
|
+
function __velarStringHas(value, text) {
|
|
233
|
+
value = __velarTextValue(value);
|
|
234
|
+
text = __velarTextArgument(text, "String.has text");
|
|
235
|
+
return text === "" || __velarTextBoundedIndexOf(value, text, 0) >= 0;
|
|
236
|
+
}
|
|
237
|
+
function __velarStringReplaceAll(value, from, to) {
|
|
238
|
+
value = __velarTextValue(value);
|
|
239
|
+
from = __velarTextArgument(from, "String.replaceAll from");
|
|
240
|
+
to = __velarTextArgument(to, "String.replaceAll to");
|
|
241
|
+
if (__velarTextReplacementOutputUnits(value, from, to, true) > __velarMaxTextCodeUnits2) throw new __velarTextNativeRangeError2("String.replaceAll output cannot exceed 16 MiB");
|
|
242
|
+
if (from === "") {
|
|
243
|
+
let output2 = to;
|
|
244
|
+
let offset = 0;
|
|
245
|
+
while (offset < value.length) {
|
|
246
|
+
const next = __velarTextNextCodePointOffset(value, offset);
|
|
247
|
+
output2 += __velarTextCall2(__velarNativeStringSlice2, value, [offset, next]) + to;
|
|
248
|
+
offset = next;
|
|
249
|
+
}
|
|
250
|
+
return output2;
|
|
251
|
+
}
|
|
252
|
+
if (!__velarTextNeedsBoundaryCheck(from)) return __velarTextCall2(__velarNativeStringReplaceAll2, value, [from, () => to]);
|
|
253
|
+
let output = "";
|
|
254
|
+
let cursor = 0;
|
|
255
|
+
while (true) {
|
|
256
|
+
const found = __velarTextBoundedIndexOf(value, from, cursor);
|
|
257
|
+
if (found < 0) break;
|
|
258
|
+
output += __velarTextCall2(__velarNativeStringSlice2, value, [cursor, found]) + to;
|
|
259
|
+
cursor = found + from.length;
|
|
260
|
+
}
|
|
261
|
+
return output + __velarTextCall2(__velarNativeStringSlice2, value, [cursor]);
|
|
262
|
+
}
|
|
263
|
+
var __velarNumberNativeMath = globalThis.Math;
|
|
264
|
+
var __velarNumberNativeNumber = globalThis.Number;
|
|
265
|
+
var __velarNumberNativeObject = globalThis.Object;
|
|
266
|
+
var __velarNumberNativeTypeError = globalThis.TypeError;
|
|
267
|
+
var __velarNumberNativeRangeError = globalThis.RangeError;
|
|
268
|
+
var __velarNumberGetOwnPropertyDescriptor = __velarNumberNativeObject.getOwnPropertyDescriptor;
|
|
269
|
+
var __velarNumberReflectApply = __velarNumberGetOwnPropertyDescriptor(globalThis.Reflect, "apply")?.value;
|
|
270
|
+
var __velarNumberPrototype = __velarNumberGetOwnPropertyDescriptor(__velarNumberNativeNumber, "prototype")?.value;
|
|
271
|
+
var __velarNumberMathAbs = __velarNumberGetOwnPropertyDescriptor(__velarNumberNativeMath, "abs")?.value;
|
|
272
|
+
var __velarNumberMathRound = __velarNumberGetOwnPropertyDescriptor(__velarNumberNativeMath, "round")?.value;
|
|
273
|
+
var __velarNumberMathFloor = __velarNumberGetOwnPropertyDescriptor(__velarNumberNativeMath, "floor")?.value;
|
|
274
|
+
var __velarNumberMathCeil = __velarNumberGetOwnPropertyDescriptor(__velarNumberNativeMath, "ceil")?.value;
|
|
275
|
+
var __velarNumberIsSafeInteger = __velarNumberGetOwnPropertyDescriptor(__velarNumberNativeNumber, "isSafeInteger")?.value;
|
|
276
|
+
var __velarNumberNativeIsInteger = __velarNumberGetOwnPropertyDescriptor(__velarNumberNativeNumber, "isInteger")?.value;
|
|
277
|
+
var __velarNumberNativeIsNaN = __velarNumberGetOwnPropertyDescriptor(__velarNumberNativeNumber, "isNaN")?.value;
|
|
278
|
+
var __velarNumberNativeIsFinite = __velarNumberGetOwnPropertyDescriptor(__velarNumberNativeNumber, "isFinite")?.value;
|
|
279
|
+
var __velarNativeNumberToFixed = __velarNumberGetOwnPropertyDescriptor(__velarNumberPrototype, "toFixed")?.value;
|
|
280
|
+
function __velarNumberCall(operation, receiver, arguments_) {
|
|
281
|
+
if (typeof operation !== "function" || typeof __velarNumberReflectApply !== "function") throw new __velarNumberNativeTypeError("The JavaScript Number runtime is unavailable");
|
|
282
|
+
return __velarNumberReflectApply(operation, receiver, arguments_);
|
|
283
|
+
}
|
|
284
|
+
function __velarNumberValue(value) {
|
|
285
|
+
if (typeof value !== "number") throw new __velarNumberNativeTypeError("Number methods require a number receiver");
|
|
286
|
+
return value;
|
|
287
|
+
}
|
|
288
|
+
function __velarNumberIsInteger(value) {
|
|
289
|
+
return __velarNumberCall(__velarNumberNativeIsInteger, __velarNumberNativeNumber, [__velarNumberValue(value)]);
|
|
290
|
+
}
|
|
291
|
+
function __velarNumberIsFinite(value) {
|
|
292
|
+
return __velarNumberCall(__velarNumberNativeIsFinite, __velarNumberNativeNumber, [__velarNumberValue(value)]);
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
// velar-standard:velar/compiler-runtime-class-fields-v1
|
|
296
|
+
var __velarClassNativeObject = globalThis.Object;
|
|
297
|
+
var __velarClassNativeReflect = globalThis.Reflect;
|
|
298
|
+
var __velarClassNativeTypeError = globalThis.TypeError;
|
|
299
|
+
var __velarClassGetOwnPropertyDescriptor = __velarClassNativeObject.getOwnPropertyDescriptor;
|
|
300
|
+
var __velarClassReflectApply = __velarClassGetOwnPropertyDescriptor(__velarClassNativeReflect, "apply")?.value;
|
|
301
|
+
var __velarClassReflectGet = __velarClassGetOwnPropertyDescriptor(__velarClassNativeReflect, "get")?.value;
|
|
302
|
+
var __velarClassGetPrototypeOf = __velarClassGetOwnPropertyDescriptor(__velarClassNativeObject, "getPrototypeOf")?.value;
|
|
303
|
+
function __velarClassHostCall(operation, receiver, arguments_) {
|
|
304
|
+
if (typeof operation !== "function" || typeof __velarClassReflectApply !== "function") throw new __velarClassNativeTypeError("The JavaScript class field runtime is unavailable");
|
|
305
|
+
return __velarClassReflectApply(operation, receiver, arguments_);
|
|
306
|
+
}
|
|
307
|
+
function __velarReadInstanceField(receiver, name) {
|
|
308
|
+
const value = __velarClassHostCall(__velarClassReflectGet, __velarClassNativeReflect, [receiver, name]);
|
|
309
|
+
if (value === void 0) throw new __velarClassNativeTypeError("Field '" + name + "' was read before initialization or contains undefined");
|
|
310
|
+
return value;
|
|
311
|
+
}
|
|
312
|
+
function __velarReadPrivateField(value, name) {
|
|
313
|
+
if (value === void 0) throw new __velarClassNativeTypeError("Private field '" + name + "' was read before initialization or contains undefined");
|
|
314
|
+
return value;
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
// velar-standard:velar/compiler-runtime-narrowing-v1
|
|
318
|
+
var __velarNarrowingNativeTypeError = globalThis.TypeError;
|
|
319
|
+
var __velarNarrowingDefineProperty = globalThis.Object.defineProperty;
|
|
320
|
+
var __VelarNarrowingError = class extends __velarNarrowingNativeTypeError {
|
|
321
|
+
constructor(message) {
|
|
322
|
+
super(message);
|
|
323
|
+
this.name = "NarrowingError";
|
|
324
|
+
}
|
|
325
|
+
};
|
|
326
|
+
__velarNarrowingDefineProperty(__VelarNarrowingError, "name", { value: "NarrowingError", writable: false, enumerable: false, configurable: true });
|
|
327
|
+
function __velarNarrow(value, valid, expected, description, offset) {
|
|
328
|
+
if (!valid) throw new __VelarNarrowingError("Flow narrowing for '" + description + "' no longer holds: expected " + expected + " at source offset " + offset);
|
|
329
|
+
return value;
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
// velar-standard:velar/compiler-runtime-promises-v1
|
|
333
|
+
var __velarNormalizeGlobal = globalThis;
|
|
334
|
+
var __velarNormalizeNativeObject = globalThis.Object;
|
|
335
|
+
var __velarNormalizeNativeReflect = globalThis.Reflect;
|
|
336
|
+
var __velarNormalizeNativeWeakMap = globalThis.WeakMap;
|
|
337
|
+
var __velarNormalizeNativePromise = globalThis.Promise;
|
|
338
|
+
var __velarNormalizeNativeSymbol = globalThis.Symbol;
|
|
339
|
+
var __velarNormalizeTypeError = globalThis.TypeError;
|
|
340
|
+
var __velarNormalizeGetOwnPropertyDescriptor = __velarNormalizeNativeObject.getOwnPropertyDescriptor;
|
|
341
|
+
var __velarNormalizeGetPrototypeOf = __velarNormalizeGetOwnPropertyDescriptor(__velarNormalizeNativeObject, "getPrototypeOf")?.value;
|
|
342
|
+
var __velarNormalizeDefineProperty = __velarNormalizeGetOwnPropertyDescriptor(__velarNormalizeNativeObject, "defineProperty")?.value;
|
|
343
|
+
var __velarNormalizeApply = __velarNormalizeGetOwnPropertyDescriptor(__velarNormalizeNativeReflect, "apply")?.value;
|
|
344
|
+
var __velarNormalizeWeakMapPrototype = __velarNormalizeGetOwnPropertyDescriptor(__velarNormalizeNativeWeakMap, "prototype")?.value;
|
|
345
|
+
var __velarNormalizeWeakMapHas = __velarNormalizeGetOwnPropertyDescriptor(__velarNormalizeWeakMapPrototype, "has")?.value;
|
|
346
|
+
var __velarNormalizeWeakMapGet = __velarNormalizeGetOwnPropertyDescriptor(__velarNormalizeWeakMapPrototype, "get")?.value;
|
|
347
|
+
var __velarNormalizeWeakMapSet = __velarNormalizeGetOwnPropertyDescriptor(__velarNormalizeWeakMapPrototype, "set")?.value;
|
|
348
|
+
var __velarNormalizePromisePrototype = __velarNormalizeGetOwnPropertyDescriptor(__velarNormalizeNativePromise, "prototype")?.value;
|
|
349
|
+
var __velarNormalizePromiseThen = __velarNormalizeGetOwnPropertyDescriptor(__velarNormalizePromisePrototype, "then")?.value;
|
|
350
|
+
var __velarNormalizeSymbolFor = __velarNormalizeGetOwnPropertyDescriptor(__velarNormalizeNativeSymbol, "for")?.value;
|
|
351
|
+
function __velarNormalizeCall(operation, receiver, arguments_) {
|
|
352
|
+
if (typeof operation !== "function" || typeof __velarNormalizeApply !== "function") throw new __velarNormalizeTypeError("The JavaScript Promise normalization runtime is unavailable");
|
|
353
|
+
return __velarNormalizeApply(operation, receiver, arguments_);
|
|
354
|
+
}
|
|
355
|
+
var __velarNormalizedPromiseRegistryKey = __velarNormalizeCall(__velarNormalizeSymbolFor, __velarNormalizeNativeSymbol, ["velar.promise.normalization.v1"]);
|
|
356
|
+
var __velarNormalizedPromiseValues = (() => {
|
|
357
|
+
const descriptor = __velarNormalizeCall(__velarNormalizeGetOwnPropertyDescriptor, __velarNormalizeNativeObject, [__velarNormalizeGlobal, __velarNormalizedPromiseRegistryKey]);
|
|
358
|
+
if (descriptor) {
|
|
359
|
+
if (!("value" in descriptor) || descriptor.enumerable || descriptor.configurable || descriptor.writable) {
|
|
360
|
+
throw new __velarNormalizeTypeError("VelarScript Promise normalization registry ownership is invalid");
|
|
361
|
+
}
|
|
362
|
+
try {
|
|
363
|
+
__velarNormalizeCall(__velarNormalizeWeakMapHas, descriptor.value, [descriptor.value]);
|
|
364
|
+
} catch {
|
|
365
|
+
throw new __velarNormalizeTypeError("VelarScript Promise normalization registry is invalid");
|
|
366
|
+
}
|
|
367
|
+
return descriptor.value;
|
|
368
|
+
}
|
|
369
|
+
const registry = new __velarNormalizeNativeWeakMap();
|
|
370
|
+
__velarNormalizeCall(__velarNormalizeDefineProperty, __velarNormalizeNativeObject, [__velarNormalizeGlobal, __velarNormalizedPromiseRegistryKey, {
|
|
371
|
+
value: registry,
|
|
372
|
+
enumerable: false,
|
|
373
|
+
configurable: false,
|
|
374
|
+
writable: false
|
|
375
|
+
}]);
|
|
376
|
+
return registry;
|
|
377
|
+
})();
|
|
378
|
+
function __velarNormalizeOwnsPromise(candidate) {
|
|
379
|
+
if (typeof candidate !== "object" && typeof candidate !== "function" || candidate === null) return false;
|
|
380
|
+
let prototype;
|
|
381
|
+
try {
|
|
382
|
+
prototype = __velarNormalizeCall(__velarNormalizeGetPrototypeOf, __velarNormalizeNativeObject, [candidate]);
|
|
383
|
+
} catch {
|
|
384
|
+
return false;
|
|
385
|
+
}
|
|
386
|
+
return prototype === __velarNormalizePromisePrototype;
|
|
387
|
+
}
|
|
388
|
+
function __velarNormalizePromiseValue(value) {
|
|
389
|
+
if (typeof value !== "object" && typeof value !== "function" || value === null) throw new __velarNormalizeTypeError("Expected an actual Promise");
|
|
390
|
+
const known = __velarNormalizeCall(__velarNormalizeWeakMapGet, __velarNormalizedPromiseValues, [value]);
|
|
391
|
+
if (known) return known;
|
|
392
|
+
let settle;
|
|
393
|
+
let fail;
|
|
394
|
+
try {
|
|
395
|
+
__velarNormalizeCall(__velarNormalizePromiseThen, value, [
|
|
396
|
+
(resolved) => {
|
|
397
|
+
if (typeof settle === "function") settle(resolved ?? null);
|
|
398
|
+
},
|
|
399
|
+
(reason) => {
|
|
400
|
+
if (typeof fail === "function") fail(reason);
|
|
401
|
+
}
|
|
402
|
+
]);
|
|
403
|
+
} catch {
|
|
404
|
+
throw new __velarNormalizeTypeError("Expected an actual Promise");
|
|
405
|
+
}
|
|
406
|
+
if (typeof __velarNormalizeNativePromise !== "function") throw new __velarNormalizeTypeError("The JavaScript Promise normalization runtime is unavailable");
|
|
407
|
+
const normalized = new __velarNormalizeNativePromise((resolve, reject) => {
|
|
408
|
+
settle = resolve;
|
|
409
|
+
fail = reject;
|
|
410
|
+
});
|
|
411
|
+
if (typeof settle !== "function" || typeof fail !== "function" || !__velarNormalizeOwnsPromise(normalized)) throw new __velarNormalizeTypeError("The JavaScript Promise normalization runtime is unavailable");
|
|
412
|
+
__velarNormalizeCall(__velarNormalizeWeakMapSet, __velarNormalizedPromiseValues, [value, normalized]);
|
|
413
|
+
__velarNormalizeCall(__velarNormalizeWeakMapSet, __velarNormalizedPromiseValues, [normalized, normalized]);
|
|
414
|
+
return normalized;
|
|
415
|
+
}
|
|
416
|
+
function __velarAsyncResolvedValue(value) {
|
|
417
|
+
if (value === void 0) return null;
|
|
418
|
+
if (typeof value !== "object" && typeof value !== "function" || value === null) return value;
|
|
419
|
+
try {
|
|
420
|
+
return __velarNormalizePromiseValue(value);
|
|
421
|
+
} catch {
|
|
422
|
+
}
|
|
423
|
+
let owner = value;
|
|
424
|
+
for (let depth = 0; owner !== null && depth < 128; depth += 1) {
|
|
425
|
+
let descriptor;
|
|
426
|
+
try {
|
|
427
|
+
descriptor = __velarNormalizeCall(__velarNormalizeGetOwnPropertyDescriptor, __velarNormalizeNativeObject, [owner, "then"]);
|
|
428
|
+
} catch {
|
|
429
|
+
throw new __velarNormalizeTypeError("An async result must not expose a callable 'then' or a 'then' getter");
|
|
430
|
+
}
|
|
431
|
+
if (descriptor) {
|
|
432
|
+
if (!("value" in descriptor) || typeof descriptor.value === "function") throw new __velarNormalizeTypeError("An async result must not expose a callable 'then' or a 'then' getter");
|
|
433
|
+
return value;
|
|
434
|
+
}
|
|
435
|
+
try {
|
|
436
|
+
owner = __velarNormalizeCall(__velarNormalizeGetPrototypeOf, __velarNormalizeNativeObject, [owner]);
|
|
437
|
+
} catch {
|
|
438
|
+
throw new __velarNormalizeTypeError("An async result must have an inspectable prototype chain");
|
|
439
|
+
}
|
|
440
|
+
}
|
|
441
|
+
if (owner !== null) throw new __velarNormalizeTypeError("An async result prototype chain is too deep");
|
|
442
|
+
return value;
|
|
443
|
+
}
|
|
444
|
+
|
|
445
|
+
// velar-standard:velar/compiler-runtime-errors-v1
|
|
446
|
+
var __velarErrorNativeError = globalThis.Error;
|
|
447
|
+
var __velarErrorNativeString = globalThis.String;
|
|
448
|
+
var __velarErrorNativeObject = globalThis.Object;
|
|
449
|
+
var __velarErrorNativeReflect = globalThis.Reflect;
|
|
450
|
+
var __velarErrorNativeTypeError = globalThis.TypeError;
|
|
451
|
+
var __velarErrorGetOwnPropertyDescriptor = __velarErrorNativeObject.getOwnPropertyDescriptor;
|
|
452
|
+
var __velarErrorGetPrototypeOf = __velarErrorNativeObject.getPrototypeOf;
|
|
453
|
+
var __velarErrorReflectApply = __velarErrorGetOwnPropertyDescriptor(__velarErrorNativeReflect, "apply")?.value;
|
|
454
|
+
var __velarErrorIsErrorOperation = __velarErrorGetOwnPropertyDescriptor(__velarErrorNativeError, "isError")?.value;
|
|
455
|
+
function __velarErrorApply(operation, receiver, arguments_, label) {
|
|
456
|
+
if (typeof operation !== "function" || typeof __velarErrorReflectApply !== "function") {
|
|
457
|
+
throw new __velarErrorNativeTypeError("The JavaScript " + label + " API is unavailable");
|
|
458
|
+
}
|
|
459
|
+
return __velarErrorReflectApply(operation, receiver, arguments_);
|
|
460
|
+
}
|
|
461
|
+
function __velarIsError(value) {
|
|
462
|
+
return __velarErrorApply(__velarErrorIsErrorOperation, __velarErrorNativeError, [value], "Error.isError");
|
|
463
|
+
}
|
|
464
|
+
function __velarNormalizeError(value) {
|
|
465
|
+
if (__velarIsError(value)) return value;
|
|
466
|
+
const kind = typeof value;
|
|
467
|
+
let message;
|
|
468
|
+
if (kind === "string") message = value;
|
|
469
|
+
else if (value === null) message = "null";
|
|
470
|
+
else if (kind === "undefined") message = "undefined";
|
|
471
|
+
else if (kind === "number" || kind === "boolean" || kind === "bigint" || kind === "symbol") {
|
|
472
|
+
message = __velarErrorApply(__velarErrorNativeString, globalThis, [value], "String");
|
|
473
|
+
} else message = "A non-Error value was thrown by JavaScript";
|
|
474
|
+
return new __velarErrorNativeError(message, { cause: value });
|
|
475
|
+
}
|
|
476
|
+
var __velarAssertionNativeError = globalThis.Error;
|
|
477
|
+
var __velarAssertionDefineProperty = globalThis.Object.defineProperty;
|
|
478
|
+
var __VelarAssertionError = class extends __velarAssertionNativeError {
|
|
479
|
+
constructor(message) {
|
|
480
|
+
super(message);
|
|
481
|
+
this.name = "AssertionError";
|
|
482
|
+
}
|
|
483
|
+
};
|
|
484
|
+
__velarAssertionDefineProperty(__VelarAssertionError, "name", { value: "AssertionError", writable: false, enumerable: false, configurable: true });
|
|
485
|
+
var __velarHostErrorNativeError = globalThis.Error;
|
|
486
|
+
var __velarHostErrorDefineProperty = globalThis.Object.defineProperty;
|
|
487
|
+
var __VelarFileNotFoundError = class extends __velarHostErrorNativeError {
|
|
488
|
+
constructor(message, path = null) {
|
|
489
|
+
super(message);
|
|
490
|
+
this.name = "FileNotFoundError";
|
|
491
|
+
this.path = path;
|
|
492
|
+
}
|
|
493
|
+
};
|
|
494
|
+
__velarHostErrorDefineProperty(__VelarFileNotFoundError, "name", { value: "FileNotFoundError", writable: false, enumerable: false, configurable: true });
|
|
495
|
+
var __VelarPermissionError = class extends __velarHostErrorNativeError {
|
|
496
|
+
constructor(message, path = null) {
|
|
497
|
+
super(message);
|
|
498
|
+
this.name = "PermissionError";
|
|
499
|
+
this.path = path;
|
|
500
|
+
}
|
|
501
|
+
};
|
|
502
|
+
__velarHostErrorDefineProperty(__VelarPermissionError, "name", { value: "PermissionError", writable: false, enumerable: false, configurable: true });
|
|
503
|
+
var __VelarNotADirectoryError = class extends __velarHostErrorNativeError {
|
|
504
|
+
constructor(message, path = null) {
|
|
505
|
+
super(message);
|
|
506
|
+
this.name = "NotADirectoryError";
|
|
507
|
+
this.path = path;
|
|
508
|
+
}
|
|
509
|
+
};
|
|
510
|
+
__velarHostErrorDefineProperty(__VelarNotADirectoryError, "name", { value: "NotADirectoryError", writable: false, enumerable: false, configurable: true });
|
|
511
|
+
var __VelarFileExistsError = class extends __velarHostErrorNativeError {
|
|
512
|
+
constructor(message, path = null) {
|
|
513
|
+
super(message);
|
|
514
|
+
this.name = "FileExistsError";
|
|
515
|
+
this.path = path;
|
|
516
|
+
}
|
|
517
|
+
};
|
|
518
|
+
__velarHostErrorDefineProperty(__VelarFileExistsError, "name", { value: "FileExistsError", writable: false, enumerable: false, configurable: true });
|
|
519
|
+
var __VelarAddressInUseError = class extends __velarHostErrorNativeError {
|
|
520
|
+
constructor(message) {
|
|
521
|
+
super(message);
|
|
522
|
+
this.name = "AddressInUseError";
|
|
523
|
+
}
|
|
524
|
+
};
|
|
525
|
+
__velarHostErrorDefineProperty(__VelarAddressInUseError, "name", { value: "AddressInUseError", writable: false, enumerable: false, configurable: true });
|
|
526
|
+
|
|
527
|
+
// velar-standard:velar/compiler-runtime-types-v1
|
|
528
|
+
var __velarCollectionNativeArray = globalThis.Array;
|
|
529
|
+
var __velarCollectionNativeMap = globalThis.Map;
|
|
530
|
+
var __velarCollectionNativeSet = globalThis.Set;
|
|
531
|
+
var __velarCollectionNativeObject = globalThis.Object;
|
|
532
|
+
var __velarCollectionNativeReflect = globalThis.Reflect;
|
|
533
|
+
var __velarCollectionNativeWeakMap = globalThis.WeakMap;
|
|
534
|
+
var __velarCollectionNativeTypeError = globalThis.TypeError;
|
|
535
|
+
var __velarCollectionGetOwnPropertyDescriptor = __velarCollectionNativeObject.getOwnPropertyDescriptor;
|
|
536
|
+
var __velarCollectionReflectApply = __velarCollectionGetOwnPropertyDescriptor(__velarCollectionNativeReflect, "apply")?.value;
|
|
537
|
+
var __velarCollectionArrayIsArray = __velarCollectionGetOwnPropertyDescriptor(__velarCollectionNativeArray, "isArray")?.value;
|
|
538
|
+
var __velarCollectionGetPrototypeOf = __velarCollectionGetOwnPropertyDescriptor(__velarCollectionNativeObject, "getPrototypeOf")?.value;
|
|
539
|
+
var __velarCollectionObjectPrototype = __velarCollectionGetOwnPropertyDescriptor(__velarCollectionNativeObject, "prototype")?.value;
|
|
540
|
+
var __velarCollectionMapPrototype = __velarCollectionGetOwnPropertyDescriptor(__velarCollectionNativeMap, "prototype")?.value;
|
|
541
|
+
var __velarCollectionSetPrototype = __velarCollectionGetOwnPropertyDescriptor(__velarCollectionNativeSet, "prototype")?.value;
|
|
542
|
+
var __velarCollectionMapSize = __velarCollectionGetOwnPropertyDescriptor(__velarCollectionMapPrototype, "size")?.get;
|
|
543
|
+
var __velarCollectionSetSize = __velarCollectionGetOwnPropertyDescriptor(__velarCollectionSetPrototype, "size")?.get;
|
|
544
|
+
function __velarCollectionHostCall(operation, receiver, arguments_) {
|
|
545
|
+
if (typeof operation !== "function" || typeof __velarCollectionReflectApply !== "function") throw new __velarCollectionNativeTypeError("The JavaScript collection runtime is unavailable");
|
|
546
|
+
return __velarCollectionReflectApply(operation, receiver, arguments_);
|
|
547
|
+
}
|
|
548
|
+
var __velarCollectionWeakMapPrototype = __velarCollectionGetOwnPropertyDescriptor(__velarCollectionNativeWeakMap, "prototype")?.value;
|
|
549
|
+
var __velarCollectionWeakMapGetOperation = __velarCollectionGetOwnPropertyDescriptor(__velarCollectionWeakMapPrototype, "get")?.value;
|
|
550
|
+
var __velarCollectionWeakMapSetOperation = __velarCollectionGetOwnPropertyDescriptor(__velarCollectionWeakMapPrototype, "set")?.value;
|
|
551
|
+
var __velarCollectionBrands = new __velarCollectionNativeWeakMap();
|
|
552
|
+
function __velarCollectionBrand(value) {
|
|
553
|
+
if (value === null || typeof value !== "object" && typeof value !== "function") return 0;
|
|
554
|
+
const known = __velarCollectionHostCall(__velarCollectionWeakMapGetOperation, __velarCollectionBrands, [value]);
|
|
555
|
+
if (known !== void 0) return known;
|
|
556
|
+
let brand = 0;
|
|
557
|
+
try {
|
|
558
|
+
__velarCollectionHostCall(__velarCollectionMapSize, value, []);
|
|
559
|
+
brand = 1;
|
|
560
|
+
} catch {
|
|
561
|
+
try {
|
|
562
|
+
__velarCollectionHostCall(__velarCollectionSetSize, value, []);
|
|
563
|
+
brand = 2;
|
|
564
|
+
} catch {
|
|
565
|
+
brand = 0;
|
|
566
|
+
}
|
|
567
|
+
}
|
|
568
|
+
__velarCollectionHostCall(__velarCollectionWeakMapSetOperation, __velarCollectionBrands, [value, brand]);
|
|
569
|
+
return brand;
|
|
570
|
+
}
|
|
571
|
+
function __velarIsMap(value) {
|
|
572
|
+
return __velarCollectionBrand(value) === 1;
|
|
573
|
+
}
|
|
574
|
+
function __velarIsSet(value) {
|
|
575
|
+
return __velarCollectionBrand(value) === 2;
|
|
576
|
+
}
|
|
577
|
+
var __velarCollectionOwnNames = __velarCollectionGetOwnPropertyDescriptor(__velarCollectionNativeObject, "getOwnPropertyNames")?.value;
|
|
578
|
+
var __velarCollectionOwnSymbols = __velarCollectionGetOwnPropertyDescriptor(__velarCollectionNativeObject, "getOwnPropertySymbols")?.value;
|
|
579
|
+
var __velarCollectionOwnKeys = __velarCollectionGetOwnPropertyDescriptor(__velarCollectionNativeReflect, "ownKeys")?.value;
|
|
580
|
+
var __velarCollectionMapEntries = __velarCollectionGetOwnPropertyDescriptor(__velarCollectionMapPrototype, "entries")?.value;
|
|
581
|
+
var __velarCollectionSetValues = __velarCollectionGetOwnPropertyDescriptor(__velarCollectionSetPrototype, "values")?.value;
|
|
582
|
+
var __velarCollectionMapIteratorPrototype = __velarCollectionHostCall(__velarCollectionGetPrototypeOf, __velarCollectionNativeObject, [__velarCollectionHostCall(__velarCollectionMapEntries, new __velarCollectionNativeMap(), [])]);
|
|
583
|
+
var __velarCollectionSetIteratorPrototype = __velarCollectionHostCall(__velarCollectionGetPrototypeOf, __velarCollectionNativeObject, [__velarCollectionHostCall(__velarCollectionSetValues, new __velarCollectionNativeSet(), [])]);
|
|
584
|
+
var __velarCollectionMapIteratorNext = __velarCollectionGetOwnPropertyDescriptor(__velarCollectionMapIteratorPrototype, "next")?.value;
|
|
585
|
+
var __velarCollectionSetIteratorNext = __velarCollectionGetOwnPropertyDescriptor(__velarCollectionSetIteratorPrototype, "next")?.value;
|
|
586
|
+
function __velarCollectionMapTypeIterator(value) {
|
|
587
|
+
return __velarCollectionHostCall(__velarCollectionMapEntries, value, []);
|
|
588
|
+
}
|
|
589
|
+
function __velarCollectionSetTypeIterator(value) {
|
|
590
|
+
return __velarCollectionHostCall(__velarCollectionSetValues, value, []);
|
|
591
|
+
}
|
|
592
|
+
function __velarCollectionMapTypeNext(iterator) {
|
|
593
|
+
return __velarCollectionHostCall(__velarCollectionMapIteratorNext, iterator, []);
|
|
594
|
+
}
|
|
595
|
+
function __velarCollectionSetTypeNext(iterator) {
|
|
596
|
+
return __velarCollectionHostCall(__velarCollectionSetIteratorNext, iterator, []);
|
|
597
|
+
}
|
|
598
|
+
var __velarTypeNativeWeakSet = globalThis.WeakSet;
|
|
599
|
+
var __velarTypeNativeObject = globalThis.Object;
|
|
600
|
+
var __velarTypeNativeTypeError = globalThis.TypeError;
|
|
601
|
+
var __velarTypeGetOwnPropertyDescriptor = __velarTypeNativeObject.getOwnPropertyDescriptor;
|
|
602
|
+
var __velarTypeDefineProperty = __velarTypeNativeObject.defineProperty;
|
|
603
|
+
var __velarTypeReflectApply = __velarTypeGetOwnPropertyDescriptor(globalThis.Reflect, "apply")?.value;
|
|
604
|
+
var __velarTypeSymbolFor = globalThis.Symbol.for;
|
|
605
|
+
var __velarTypeWeakSetPrototype = __velarTypeGetOwnPropertyDescriptor(__velarTypeNativeWeakSet, "prototype")?.value;
|
|
606
|
+
var __velarTypeWeakSetHas = __velarTypeGetOwnPropertyDescriptor(__velarTypeWeakSetPrototype, "has")?.value;
|
|
607
|
+
var __velarTypeWeakSetAdd = __velarTypeGetOwnPropertyDescriptor(__velarTypeWeakSetPrototype, "add")?.value;
|
|
608
|
+
function __velarTypeCall(operation, receiver, arguments_) {
|
|
609
|
+
if (typeof operation !== "function" || typeof __velarTypeReflectApply !== "function") throw new __velarTypeNativeTypeError("The JavaScript runtime Type registry API is unavailable");
|
|
610
|
+
return __velarTypeReflectApply(operation, receiver, arguments_);
|
|
611
|
+
}
|
|
612
|
+
var __velarRuntimeTypeRegistryKey = __velarTypeCall(__velarTypeSymbolFor, globalThis.Symbol, ["velar.type.registry.v1"]);
|
|
613
|
+
var __velarRuntimeTypeRegistry = (() => {
|
|
614
|
+
const descriptor = __velarTypeGetOwnPropertyDescriptor(globalThis, __velarRuntimeTypeRegistryKey);
|
|
615
|
+
if (descriptor) {
|
|
616
|
+
if (!("value" in descriptor) || descriptor.enumerable || descriptor.configurable || descriptor.writable) {
|
|
617
|
+
throw new __velarTypeNativeTypeError("VelarScript runtime type registry descriptor is invalid");
|
|
618
|
+
}
|
|
619
|
+
try {
|
|
620
|
+
__velarTypeCall(__velarTypeWeakSetHas, descriptor.value, [descriptor.value]);
|
|
621
|
+
} catch {
|
|
622
|
+
throw new __velarTypeNativeTypeError("VelarScript runtime type registry is invalid");
|
|
623
|
+
}
|
|
624
|
+
return descriptor.value;
|
|
625
|
+
}
|
|
626
|
+
const registry = new __velarTypeNativeWeakSet();
|
|
627
|
+
__velarTypeCall(__velarTypeDefineProperty, __velarTypeNativeObject, [globalThis, __velarRuntimeTypeRegistryKey, {
|
|
628
|
+
value: registry,
|
|
629
|
+
enumerable: false,
|
|
630
|
+
configurable: false,
|
|
631
|
+
writable: false
|
|
632
|
+
}]);
|
|
633
|
+
return registry;
|
|
634
|
+
})();
|
|
635
|
+
function __velarRegisterRuntimeType(value) {
|
|
636
|
+
__velarTypeCall(__velarTypeWeakSetAdd, __velarRuntimeTypeRegistry, [value]);
|
|
637
|
+
return value;
|
|
638
|
+
}
|
|
639
|
+
var __velarValidationNativeWeakMap = globalThis.WeakMap;
|
|
640
|
+
var __velarValidationNativeSet = globalThis.Set;
|
|
641
|
+
var __velarValidationNativePromise = globalThis.Promise;
|
|
642
|
+
var __velarValidationNativeFunction = globalThis.Function;
|
|
643
|
+
var __velarValidationNativeSymbol = globalThis.Symbol;
|
|
644
|
+
var __velarValidationWeakMapPrototype = __velarCollectionGetOwnPropertyDescriptor(__velarValidationNativeWeakMap, "prototype")?.value;
|
|
645
|
+
var __velarValidationSetPrototype = __velarCollectionGetOwnPropertyDescriptor(__velarValidationNativeSet, "prototype")?.value;
|
|
646
|
+
var __velarValidationFunctionPrototype = __velarCollectionGetOwnPropertyDescriptor(__velarValidationNativeFunction, "prototype")?.value;
|
|
647
|
+
var __velarValidationHasInstanceSymbol = __velarCollectionGetOwnPropertyDescriptor(__velarValidationNativeSymbol, "hasInstance")?.value;
|
|
648
|
+
var __velarValidationWeakMapGetOperation = __velarCollectionGetOwnPropertyDescriptor(__velarValidationWeakMapPrototype, "get")?.value;
|
|
649
|
+
var __velarValidationWeakMapSetOperation = __velarCollectionGetOwnPropertyDescriptor(__velarValidationWeakMapPrototype, "set")?.value;
|
|
650
|
+
var __velarValidationWeakMapDeleteOperation = __velarCollectionGetOwnPropertyDescriptor(__velarValidationWeakMapPrototype, "delete")?.value;
|
|
651
|
+
var __velarValidationSetHasOperation = __velarCollectionGetOwnPropertyDescriptor(__velarValidationSetPrototype, "has")?.value;
|
|
652
|
+
var __velarValidationSetAddOperation = __velarCollectionGetOwnPropertyDescriptor(__velarValidationSetPrototype, "add")?.value;
|
|
653
|
+
var __velarValidationSetDeleteOperation = __velarCollectionGetOwnPropertyDescriptor(__velarValidationSetPrototype, "delete")?.value;
|
|
654
|
+
var __velarValidationSetSizeOperation = __velarCollectionGetOwnPropertyDescriptor(__velarValidationSetPrototype, "size")?.get;
|
|
655
|
+
var __velarValidationFunctionHasInstanceOperation = __velarCollectionGetOwnPropertyDescriptor(__velarValidationFunctionPrototype, __velarValidationHasInstanceSymbol)?.value;
|
|
656
|
+
var __velarValidationFreezeOperation = __velarCollectionGetOwnPropertyDescriptor(__velarCollectionNativeObject, "freeze")?.value;
|
|
657
|
+
var __velarValidationDefinePropertyOperation = __velarCollectionGetOwnPropertyDescriptor(__velarCollectionNativeObject, "defineProperty")?.value;
|
|
658
|
+
var __velarValidationMapSetOperation = __velarCollectionGetOwnPropertyDescriptor(__velarCollectionMapPrototype, "set")?.value;
|
|
659
|
+
var __velarValidationMapGetOperation = __velarCollectionGetOwnPropertyDescriptor(__velarCollectionMapPrototype, "get")?.value;
|
|
660
|
+
function __velarValidationState() {
|
|
661
|
+
return { active: new __velarValidationNativeWeakMap(), depth: 0, copies: null, copy: __velarValidationCopy };
|
|
662
|
+
}
|
|
663
|
+
function __velarValidationSet() {
|
|
664
|
+
return new __velarValidationNativeSet();
|
|
665
|
+
}
|
|
666
|
+
function __velarValidationWeakMapGet(value, key) {
|
|
667
|
+
return __velarCollectionHostCall(__velarValidationWeakMapGetOperation, value, [key]);
|
|
668
|
+
}
|
|
669
|
+
function __velarValidationWeakMapSet(value, key, item) {
|
|
670
|
+
return __velarCollectionHostCall(__velarValidationWeakMapSetOperation, value, [key, item]);
|
|
671
|
+
}
|
|
672
|
+
function __velarValidationMapGet(value, key) {
|
|
673
|
+
return __velarCollectionHostCall(__velarValidationMapGetOperation, value, [key]);
|
|
674
|
+
}
|
|
675
|
+
function __velarValidationMapSet(value, key, item) {
|
|
676
|
+
return __velarCollectionHostCall(__velarValidationMapSetOperation, value, [key, item]);
|
|
677
|
+
}
|
|
678
|
+
function __velarValidationSetAdd(value, item) {
|
|
679
|
+
return __velarCollectionHostCall(__velarValidationSetAddOperation, value, [item]);
|
|
680
|
+
}
|
|
681
|
+
function __velarValidationIsArray(value) {
|
|
682
|
+
return __velarCollectionHostCall(__velarCollectionArrayIsArray, __velarCollectionNativeArray, [value]);
|
|
683
|
+
}
|
|
684
|
+
function __velarValidationOwnDescriptor(value, key) {
|
|
685
|
+
return __velarCollectionHostCall(__velarCollectionGetOwnPropertyDescriptor, __velarCollectionNativeObject, [value, key]);
|
|
686
|
+
}
|
|
687
|
+
function __velarValidationIsInstance(value, constructor) {
|
|
688
|
+
return __velarCollectionHostCall(__velarValidationFunctionHasInstanceOperation, constructor, [value]);
|
|
689
|
+
}
|
|
690
|
+
function __velarValidationFreeze(value) {
|
|
691
|
+
return __velarCollectionHostCall(__velarValidationFreezeOperation, __velarCollectionNativeObject, [value]);
|
|
692
|
+
}
|
|
693
|
+
function __velarValidationIsPlainObject(value) {
|
|
694
|
+
const prototype = __velarCollectionHostCall(__velarCollectionGetPrototypeOf, __velarCollectionNativeObject, [value]);
|
|
695
|
+
if (prototype === null) return true;
|
|
696
|
+
return __velarCollectionHostCall(__velarCollectionGetPrototypeOf, __velarCollectionNativeObject, [prototype]) === null;
|
|
697
|
+
}
|
|
698
|
+
var __velarValidationCopy = {
|
|
699
|
+
seen(state, value, plan) {
|
|
700
|
+
if (state.copies === null) return void 0;
|
|
701
|
+
const plans = __velarValidationWeakMapGet(state.copies, value);
|
|
702
|
+
return plans === void 0 ? void 0 : __velarValidationMapGet(plans, plan);
|
|
703
|
+
},
|
|
704
|
+
remember(state, value, copy, plan) {
|
|
705
|
+
if (state.copies === null) state.copies = new __velarValidationNativeWeakMap();
|
|
706
|
+
let plans = __velarValidationWeakMapGet(state.copies, value);
|
|
707
|
+
if (plans === void 0) {
|
|
708
|
+
plans = new __velarCollectionNativeMap();
|
|
709
|
+
__velarValidationWeakMapSet(state.copies, value, plans);
|
|
710
|
+
}
|
|
711
|
+
__velarValidationMapSet(plans, plan, copy);
|
|
712
|
+
return copy;
|
|
713
|
+
},
|
|
714
|
+
object(state, value, plan) {
|
|
715
|
+
return __velarValidationCopy.remember(state, value, {}, plan);
|
|
716
|
+
},
|
|
717
|
+
// Fields are written through defineProperty so a field literally named
|
|
718
|
+
// '__proto__' lands as an own data property instead of retargeting the
|
|
719
|
+
// copy's prototype, and so every copied field is an ordinary mutable
|
|
720
|
+
// enumerable data property whatever the source's descriptor said.
|
|
721
|
+
field(target, name, value) {
|
|
722
|
+
__velarCollectionHostCall(__velarValidationDefinePropertyOperation, __velarCollectionNativeObject, [target, name, { value, writable: true, enumerable: true, configurable: true }]);
|
|
723
|
+
},
|
|
724
|
+
// A null element callback means the element position has nothing to copy —
|
|
725
|
+
// a primitive, an enum member, a class instance, or an opaque 'unknown'.
|
|
726
|
+
// 'plan' is the container position's own stable identity: the emitter hoists
|
|
727
|
+
// one function per distinct copy plan and hands it in as both the element
|
|
728
|
+
// callback and the key this memo files the copy under.
|
|
729
|
+
listOf(value, state, item, plan) {
|
|
730
|
+
const found = __velarValidationCopy.seen(state, value, plan);
|
|
731
|
+
if (found !== void 0) return found;
|
|
732
|
+
const result = __velarValidationCopy.remember(state, value, [], plan);
|
|
733
|
+
const length = __velarValidationOwnDescriptor(value, "length")?.value ?? 0;
|
|
734
|
+
for (let index = 0; index < length; index += 1) {
|
|
735
|
+
const descriptor = __velarValidationOwnDescriptor(value, index);
|
|
736
|
+
result[index] = item === null ? descriptor?.value : item(descriptor?.value, state);
|
|
737
|
+
}
|
|
738
|
+
return result;
|
|
739
|
+
},
|
|
740
|
+
setOf(value, state, item, plan) {
|
|
741
|
+
const found = __velarValidationCopy.seen(state, value, plan);
|
|
742
|
+
if (found !== void 0) return found;
|
|
743
|
+
const result = __velarValidationCopy.remember(state, value, __velarValidationSet(), plan);
|
|
744
|
+
const iterator = __velarCollectionSetTypeIterator(value);
|
|
745
|
+
while (true) {
|
|
746
|
+
const step = __velarCollectionSetTypeNext(iterator);
|
|
747
|
+
if (step.done) break;
|
|
748
|
+
__velarValidationSetAdd(result, item === null ? step.value : item(step.value, state));
|
|
749
|
+
}
|
|
750
|
+
return result;
|
|
751
|
+
},
|
|
752
|
+
mapOf(value, state, key, item, plan) {
|
|
753
|
+
const found = __velarValidationCopy.seen(state, value, plan);
|
|
754
|
+
if (found !== void 0) return found;
|
|
755
|
+
const result = __velarValidationCopy.remember(state, value, new __velarCollectionNativeMap(), plan);
|
|
756
|
+
const iterator = __velarCollectionMapTypeIterator(value);
|
|
757
|
+
while (true) {
|
|
758
|
+
const step = __velarCollectionMapTypeNext(iterator);
|
|
759
|
+
if (step.done) break;
|
|
760
|
+
const entry = step.value;
|
|
761
|
+
__velarValidationMapSet(result, key === null ? entry[0] : key(entry[0], state), item === null ? entry[1] : item(entry[1], state));
|
|
762
|
+
}
|
|
763
|
+
return result;
|
|
764
|
+
},
|
|
765
|
+
recordOf(value, state, item, plan) {
|
|
766
|
+
const found = __velarValidationCopy.seen(state, value, plan);
|
|
767
|
+
if (found !== void 0) return found;
|
|
768
|
+
const result = __velarValidationCopy.remember(state, value, {}, plan);
|
|
769
|
+
const keys = __velarCollectionHostCall(__velarCollectionOwnKeys, __velarCollectionNativeReflect, [value]);
|
|
770
|
+
for (let index = 0; index < keys.length; index += 1) {
|
|
771
|
+
const name = keys[index];
|
|
772
|
+
if (typeof name !== "string") continue;
|
|
773
|
+
const descriptor = __velarValidationOwnDescriptor(value, name);
|
|
774
|
+
if (!descriptor?.enumerable || !("value" in descriptor)) continue;
|
|
775
|
+
__velarValidationCopy.field(result, name, item === null ? descriptor.value : item(descriptor.value, state));
|
|
776
|
+
}
|
|
777
|
+
return result;
|
|
778
|
+
},
|
|
779
|
+
// A generic instantiation supplies a predicate per type argument but no copy
|
|
780
|
+
// plan, and a structural or union position is validated as a shape the
|
|
781
|
+
// predicate did not fully decide. Both copy the plain data they can see:
|
|
782
|
+
// arrays, Maps, Sets, and plain objects recurse; anything else — a class
|
|
783
|
+
// instance, a promise, a function, a binary buffer — is not plain data and
|
|
784
|
+
// passes through by reference.
|
|
785
|
+
plain(value, state) {
|
|
786
|
+
if (value === null || typeof value !== "object") return value;
|
|
787
|
+
const found = __velarValidationCopy.seen(state, value, __velarValidationCopy.plain);
|
|
788
|
+
if (found !== void 0) return found;
|
|
789
|
+
if (__velarValidationIsArray(value)) return __velarValidationCopy.listOf(value, state, __velarValidationCopy.plain, __velarValidationCopy.plain);
|
|
790
|
+
if (__velarIsMap(value)) return __velarValidationCopy.mapOf(value, state, __velarValidationCopy.plain, __velarValidationCopy.plain, __velarValidationCopy.plain);
|
|
791
|
+
if (__velarIsSet(value)) return __velarValidationCopy.setOf(value, state, __velarValidationCopy.plain, __velarValidationCopy.plain);
|
|
792
|
+
if (!__velarValidationIsPlainObject(value)) return value;
|
|
793
|
+
return __velarValidationCopy.recordOf(value, state, __velarValidationCopy.plain, __velarValidationCopy.plain);
|
|
794
|
+
},
|
|
795
|
+
// A Type object from a target extension, or one emitted by an older build,
|
|
796
|
+
// may carry no copy plan; the structural copy is what is left to fall back on.
|
|
797
|
+
// A Type that does answer 'copy' owns its own plan identity — a declared
|
|
798
|
+
// record files under its copy function, an instantiation under its arguments
|
|
799
|
+
// — so nothing is threaded in from here.
|
|
800
|
+
through(type, value, state) {
|
|
801
|
+
const operation = type === null || type === void 0 ? void 0 : type.copy;
|
|
802
|
+
if (typeof operation !== "function") return __velarValidationCopy.plain(value, state);
|
|
803
|
+
return __velarCollectionHostCall(operation, type, [value, state]);
|
|
804
|
+
}
|
|
805
|
+
};
|
|
806
|
+
function __velarValidationRejectionHint(value) {
|
|
807
|
+
if (value === null || typeof value !== "object" || __velarValidationIsArray(value) || __velarValidationIsPlainObject(value)) return "";
|
|
808
|
+
return "; a record accepts only plain data objects \u2014 project the fields into a record first, for example {x: instance.x}";
|
|
809
|
+
}
|
|
810
|
+
var __velarValidationErrorDefineProperty = globalThis.Object.defineProperty;
|
|
811
|
+
var __VelarValidationError = class extends __velarCollectionNativeTypeError {
|
|
812
|
+
constructor(message, detail) {
|
|
813
|
+
super(message);
|
|
814
|
+
this.name = "ValidationError";
|
|
815
|
+
this.path = detail?.path ?? null;
|
|
816
|
+
this.field = detail?.field ?? null;
|
|
817
|
+
this.reason = detail?.reason ?? null;
|
|
818
|
+
}
|
|
819
|
+
};
|
|
820
|
+
__velarValidationErrorDefineProperty(__VelarValidationError, "name", { value: "ValidationError", writable: false, enumerable: false, configurable: true });
|
|
821
|
+
|
|
822
|
+
// velar-standard:velar/compiler-runtime-collections-v1
|
|
823
|
+
var __velarCollectionNativeArray2 = globalThis.Array;
|
|
824
|
+
var __velarCollectionNativeMap2 = globalThis.Map;
|
|
825
|
+
var __velarCollectionNativeSet2 = globalThis.Set;
|
|
826
|
+
var __velarCollectionNativeObject2 = globalThis.Object;
|
|
827
|
+
var __velarCollectionNativeReflect2 = globalThis.Reflect;
|
|
828
|
+
var __velarCollectionNativeWeakMap2 = globalThis.WeakMap;
|
|
829
|
+
var __velarCollectionNativeTypeError2 = globalThis.TypeError;
|
|
830
|
+
var __velarCollectionGetOwnPropertyDescriptor2 = __velarCollectionNativeObject2.getOwnPropertyDescriptor;
|
|
831
|
+
var __velarCollectionReflectApply2 = __velarCollectionGetOwnPropertyDescriptor2(__velarCollectionNativeReflect2, "apply")?.value;
|
|
832
|
+
var __velarCollectionArrayIsArray2 = __velarCollectionGetOwnPropertyDescriptor2(__velarCollectionNativeArray2, "isArray")?.value;
|
|
833
|
+
var __velarCollectionGetPrototypeOf2 = __velarCollectionGetOwnPropertyDescriptor2(__velarCollectionNativeObject2, "getPrototypeOf")?.value;
|
|
834
|
+
var __velarCollectionObjectPrototype2 = __velarCollectionGetOwnPropertyDescriptor2(__velarCollectionNativeObject2, "prototype")?.value;
|
|
835
|
+
var __velarCollectionMapPrototype2 = __velarCollectionGetOwnPropertyDescriptor2(__velarCollectionNativeMap2, "prototype")?.value;
|
|
836
|
+
var __velarCollectionSetPrototype2 = __velarCollectionGetOwnPropertyDescriptor2(__velarCollectionNativeSet2, "prototype")?.value;
|
|
837
|
+
var __velarCollectionMapSize2 = __velarCollectionGetOwnPropertyDescriptor2(__velarCollectionMapPrototype2, "size")?.get;
|
|
838
|
+
var __velarCollectionSetSize2 = __velarCollectionGetOwnPropertyDescriptor2(__velarCollectionSetPrototype2, "size")?.get;
|
|
839
|
+
function __velarCollectionHostCall2(operation, receiver, arguments_) {
|
|
840
|
+
if (typeof operation !== "function" || typeof __velarCollectionReflectApply2 !== "function") throw new __velarCollectionNativeTypeError2("The JavaScript collection runtime is unavailable");
|
|
841
|
+
return __velarCollectionReflectApply2(operation, receiver, arguments_);
|
|
842
|
+
}
|
|
843
|
+
var __velarCollectionWeakMapPrototype2 = __velarCollectionGetOwnPropertyDescriptor2(__velarCollectionNativeWeakMap2, "prototype")?.value;
|
|
844
|
+
var __velarCollectionWeakMapGetOperation2 = __velarCollectionGetOwnPropertyDescriptor2(__velarCollectionWeakMapPrototype2, "get")?.value;
|
|
845
|
+
var __velarCollectionWeakMapSetOperation2 = __velarCollectionGetOwnPropertyDescriptor2(__velarCollectionWeakMapPrototype2, "set")?.value;
|
|
846
|
+
var __velarCollectionBrands2 = new __velarCollectionNativeWeakMap2();
|
|
847
|
+
var __velarCollectionListNativeNumber = globalThis.Number;
|
|
848
|
+
var __velarCollectionListNativeMath = globalThis.Math;
|
|
849
|
+
var __velarCollectionListNativeRangeError = globalThis.RangeError;
|
|
850
|
+
var __velarCollectionListArrayPrototype = __velarCollectionGetOwnPropertyDescriptor2(__velarCollectionNativeArray2, "prototype")?.value;
|
|
851
|
+
var __velarCollectionListOwnNamesOperation = __velarCollectionGetOwnPropertyDescriptor2(__velarCollectionNativeObject2, "getOwnPropertyNames")?.value;
|
|
852
|
+
var __velarCollectionListOwnSymbolsOperation = __velarCollectionGetOwnPropertyDescriptor2(__velarCollectionNativeObject2, "getOwnPropertySymbols")?.value;
|
|
853
|
+
var __velarCollectionListDefinePropertyOperation = __velarCollectionGetOwnPropertyDescriptor2(__velarCollectionNativeObject2, "defineProperty")?.value;
|
|
854
|
+
var __velarCollectionListObjectIsOperation = __velarCollectionGetOwnPropertyDescriptor2(__velarCollectionNativeObject2, "is")?.value;
|
|
855
|
+
var __velarCollectionListIntegerOperation = __velarCollectionGetOwnPropertyDescriptor2(__velarCollectionListNativeNumber, "isInteger")?.value;
|
|
856
|
+
var __velarCollectionListNaNOperation = __velarCollectionGetOwnPropertyDescriptor2(__velarCollectionListNativeNumber, "isNaN")?.value;
|
|
857
|
+
var __velarCollectionListFiniteOperation = __velarCollectionGetOwnPropertyDescriptor2(__velarCollectionListNativeNumber, "isFinite")?.value;
|
|
858
|
+
var __velarCollectionListMaximumOperation = __velarCollectionGetOwnPropertyDescriptor2(__velarCollectionListNativeMath, "max")?.value;
|
|
859
|
+
var __velarCollectionListMinimumOperation = __velarCollectionGetOwnPropertyDescriptor2(__velarCollectionListNativeMath, "min")?.value;
|
|
860
|
+
var __velarCollectionListJoinOperation = __velarCollectionGetOwnPropertyDescriptor2(__velarCollectionListArrayPrototype, "join")?.value;
|
|
861
|
+
var __velarCollectionListSortOperation = __velarCollectionGetOwnPropertyDescriptor2(__velarCollectionListArrayPrototype, "sort")?.value;
|
|
862
|
+
var __velarCollectionListReverseOperation = __velarCollectionGetOwnPropertyDescriptor2(__velarCollectionListArrayPrototype, "reverse")?.value;
|
|
863
|
+
function __velarCollectionListIsArray(value) {
|
|
864
|
+
return __velarCollectionHostCall2(__velarCollectionArrayIsArray2, __velarCollectionNativeArray2, [value]);
|
|
865
|
+
}
|
|
866
|
+
function __velarCollectionListGetOwnPropertyDescriptor(value, key) {
|
|
867
|
+
return __velarCollectionHostCall2(__velarCollectionGetOwnPropertyDescriptor2, __velarCollectionNativeObject2, [value, key]);
|
|
868
|
+
}
|
|
869
|
+
function __velarCollectionListOwnNames(value) {
|
|
870
|
+
return __velarCollectionHostCall2(__velarCollectionListOwnNamesOperation, __velarCollectionNativeObject2, [value]);
|
|
871
|
+
}
|
|
872
|
+
function __velarCollectionListOwnSymbols(value) {
|
|
873
|
+
return __velarCollectionHostCall2(__velarCollectionListOwnSymbolsOperation, __velarCollectionNativeObject2, [value]);
|
|
874
|
+
}
|
|
875
|
+
function __velarCollectionListDefineProperty(value, key, descriptor) {
|
|
876
|
+
return __velarCollectionHostCall2(__velarCollectionListDefinePropertyOperation, __velarCollectionNativeObject2, [value, key, descriptor]);
|
|
877
|
+
}
|
|
878
|
+
function __velarCollectionListIsInteger(value) {
|
|
879
|
+
return __velarCollectionHostCall2(__velarCollectionListIntegerOperation, __velarCollectionListNativeNumber, [value]);
|
|
880
|
+
}
|
|
881
|
+
var __velarCollectionSetMapNativeRangeError = globalThis.RangeError;
|
|
882
|
+
var __velarCollectionSetMapFreezeOperation = __velarCollectionGetOwnPropertyDescriptor2(__velarCollectionNativeObject2, "freeze")?.value;
|
|
883
|
+
var __velarCollectionSetAddOperation = __velarCollectionGetOwnPropertyDescriptor2(__velarCollectionSetPrototype2, "add")?.value;
|
|
884
|
+
var __velarCollectionSetHasOperation = __velarCollectionGetOwnPropertyDescriptor2(__velarCollectionSetPrototype2, "has")?.value;
|
|
885
|
+
var __velarCollectionSetDeleteOperation = __velarCollectionGetOwnPropertyDescriptor2(__velarCollectionSetPrototype2, "delete")?.value;
|
|
886
|
+
var __velarCollectionSetClearOperation = __velarCollectionGetOwnPropertyDescriptor2(__velarCollectionSetPrototype2, "clear")?.value;
|
|
887
|
+
var __velarCollectionSetValuesOperation = __velarCollectionGetOwnPropertyDescriptor2(__velarCollectionSetPrototype2, "values")?.value;
|
|
888
|
+
var __velarCollectionMapGetOperation = __velarCollectionGetOwnPropertyDescriptor2(__velarCollectionMapPrototype2, "get")?.value;
|
|
889
|
+
var __velarCollectionMapSetOperation = __velarCollectionGetOwnPropertyDescriptor2(__velarCollectionMapPrototype2, "set")?.value;
|
|
890
|
+
var __velarCollectionMapHasOperation = __velarCollectionGetOwnPropertyDescriptor2(__velarCollectionMapPrototype2, "has")?.value;
|
|
891
|
+
var __velarCollectionMapDeleteOperation = __velarCollectionGetOwnPropertyDescriptor2(__velarCollectionMapPrototype2, "delete")?.value;
|
|
892
|
+
var __velarCollectionMapClearOperation = __velarCollectionGetOwnPropertyDescriptor2(__velarCollectionMapPrototype2, "clear")?.value;
|
|
893
|
+
var __velarCollectionMapKeysOperation = __velarCollectionGetOwnPropertyDescriptor2(__velarCollectionMapPrototype2, "keys")?.value;
|
|
894
|
+
var __velarCollectionMapValuesOperation = __velarCollectionGetOwnPropertyDescriptor2(__velarCollectionMapPrototype2, "values")?.value;
|
|
895
|
+
var __velarCollectionMapEntriesOperation = __velarCollectionGetOwnPropertyDescriptor2(__velarCollectionMapPrototype2, "entries")?.value;
|
|
896
|
+
var __velarCollectionSetMapMapIteratorPrototype = __velarCollectionHostCall2(__velarCollectionGetPrototypeOf2, __velarCollectionNativeObject2, [__velarCollectionHostCall2(__velarCollectionMapEntriesOperation, new __velarCollectionNativeMap2(), [])]);
|
|
897
|
+
var __velarCollectionSetMapSetIteratorPrototype = __velarCollectionHostCall2(__velarCollectionGetPrototypeOf2, __velarCollectionNativeObject2, [__velarCollectionHostCall2(__velarCollectionSetValuesOperation, new __velarCollectionNativeSet2(), [])]);
|
|
898
|
+
var __velarCollectionSetMapMapIteratorNext = __velarCollectionGetOwnPropertyDescriptor2(__velarCollectionSetMapMapIteratorPrototype, "next")?.value;
|
|
899
|
+
var __velarCollectionSetMapSetIteratorNext = __velarCollectionGetOwnPropertyDescriptor2(__velarCollectionSetMapSetIteratorPrototype, "next")?.value;
|
|
900
|
+
var __velarCollectionRecordNativeRangeError = globalThis.RangeError;
|
|
901
|
+
var __velarCollectionRecordOwnNamesOperation = __velarCollectionGetOwnPropertyDescriptor2(__velarCollectionNativeObject2, "getOwnPropertyNames")?.value;
|
|
902
|
+
var __velarCollectionRecordOwnSymbolsOperation = __velarCollectionGetOwnPropertyDescriptor2(__velarCollectionNativeObject2, "getOwnPropertySymbols")?.value;
|
|
903
|
+
var __velarCollectionRecordDefinePropertyOperation = __velarCollectionGetOwnPropertyDescriptor2(__velarCollectionNativeObject2, "defineProperty")?.value;
|
|
904
|
+
var __velarCollectionRecordObjectIsOperation = __velarCollectionGetOwnPropertyDescriptor2(__velarCollectionNativeObject2, "is")?.value;
|
|
905
|
+
var __velarCollectionRecordDeletePropertyOperation = __velarCollectionGetOwnPropertyDescriptor2(__velarCollectionNativeReflect2, "deleteProperty")?.value;
|
|
906
|
+
var __velarCollectionRecordFreezeOperation = __velarCollectionGetOwnPropertyDescriptor2(__velarCollectionNativeObject2, "freeze")?.value;
|
|
907
|
+
|
|
908
|
+
// velar-standard:velar/compiler-runtime-collection-lowering-v1
|
|
909
|
+
var __velarMaxCollectionItems = 1e6;
|
|
910
|
+
var __velarCollectionValue = (value) => value === void 0 ? null : value;
|
|
911
|
+
var __velarListNativeWeakMap = globalThis.WeakMap;
|
|
912
|
+
var __velarListWeakMapPrototype = __velarCollectionListGetOwnPropertyDescriptor(__velarListNativeWeakMap, "prototype")?.value;
|
|
913
|
+
var __velarListWeakMapGetOperation = __velarCollectionListGetOwnPropertyDescriptor(__velarListWeakMapPrototype, "get")?.value;
|
|
914
|
+
var __velarListWeakMapSetOperation = __velarCollectionListGetOwnPropertyDescriptor(__velarListWeakMapPrototype, "set")?.value;
|
|
915
|
+
var __velarListMemos = new __velarListNativeWeakMap();
|
|
916
|
+
var __velarListIsFrozenOperation = __velarCollectionListGetOwnPropertyDescriptor(__velarCollectionNativeObject2, "isFrozen")?.value;
|
|
917
|
+
function __velarListRejectFrozen(value, name) {
|
|
918
|
+
if (__velarCollectionHostCall2(__velarListIsFrozenOperation, __velarCollectionNativeObject2, [value])) {
|
|
919
|
+
throw new __velarCollectionNativeTypeError2(name + " received a frozen JavaScript array; copy it on the JavaScript side \u2014 [...values] \u2014 before passing it to VelarScript");
|
|
920
|
+
}
|
|
921
|
+
}
|
|
922
|
+
function __velarListMemo(value) {
|
|
923
|
+
return __velarCollectionHostCall2(__velarListWeakMapGetOperation, __velarListMemos, [value]);
|
|
924
|
+
}
|
|
925
|
+
function __velarListIsOwned(value) {
|
|
926
|
+
const memo = __velarListMemo(value);
|
|
927
|
+
return memo !== void 0 && memo === value.length;
|
|
928
|
+
}
|
|
929
|
+
function __velarAdoptList(value) {
|
|
930
|
+
__velarCollectionHostCall2(__velarListWeakMapSetOperation, __velarListMemos, [value, value.length]);
|
|
931
|
+
return value;
|
|
932
|
+
}
|
|
933
|
+
function __velarMarkCheckedList(value) {
|
|
934
|
+
__velarCollectionHostCall2(__velarListWeakMapSetOperation, __velarListMemos, [value, ~value.length]);
|
|
935
|
+
return value;
|
|
936
|
+
}
|
|
937
|
+
function __velarMarkOwnedList(value) {
|
|
938
|
+
const memo = __velarListMemo(value);
|
|
939
|
+
return memo !== void 0 && memo < 0 ? __velarMarkCheckedList(value) : __velarAdoptList(value);
|
|
940
|
+
}
|
|
941
|
+
function __velarListRequireMutableLength(value, name) {
|
|
942
|
+
const lengthDescriptor = __velarCollectionListGetOwnPropertyDescriptor(value, "length");
|
|
943
|
+
if (!lengthDescriptor || !lengthDescriptor.writable || lengthDescriptor.enumerable || lengthDescriptor.configurable || !("value" in lengthDescriptor)) throw new __velarCollectionNativeTypeError2(name + " requires an ordinary mutable List length");
|
|
944
|
+
}
|
|
945
|
+
function __velarValidateDenseList(value, name) {
|
|
946
|
+
value = __velarReactiveRaw(value);
|
|
947
|
+
if (!__velarCollectionListIsArray(value) || value.length > __velarMaxCollectionItems || __velarCollectionListOwnSymbols(value).length > 0 || __velarCollectionListOwnNames(value).length !== value.length + 1) {
|
|
948
|
+
throw new __velarCollectionNativeTypeError2(name + " requires a dense VelarScript List");
|
|
949
|
+
}
|
|
950
|
+
__velarListRejectFrozen(value, name);
|
|
951
|
+
__velarListRequireMutableLength(value, name);
|
|
952
|
+
for (let index = 0; index < value.length; index += 1) {
|
|
953
|
+
const descriptor = __velarCollectionListGetOwnPropertyDescriptor(value, index);
|
|
954
|
+
if (!descriptor?.enumerable || !descriptor.configurable || !descriptor.writable || !("value" in descriptor)) throw new __velarCollectionNativeTypeError2(name + " requires ordinary mutable List data elements");
|
|
955
|
+
}
|
|
956
|
+
return __velarMarkCheckedList(value);
|
|
957
|
+
}
|
|
958
|
+
function __velarListTier(value) {
|
|
959
|
+
const memo = __velarListMemo(value);
|
|
960
|
+
if (memo === void 0) return 0;
|
|
961
|
+
if (memo === value.length) return 1;
|
|
962
|
+
return ~memo === value.length ? 2 : 0;
|
|
963
|
+
}
|
|
964
|
+
function __velarValidateListTier(value, name, tier) {
|
|
965
|
+
if (tier === 1) return value;
|
|
966
|
+
if (tier === 0) return __velarValidateDenseList(value, name);
|
|
967
|
+
__velarListRequireMutableLength(value, name);
|
|
968
|
+
return value;
|
|
969
|
+
}
|
|
970
|
+
function __velarValidateOwnedList(value, name) {
|
|
971
|
+
value = __velarReactiveRaw(value);
|
|
972
|
+
return __velarValidateListTier(value, name, __velarListTier(value));
|
|
973
|
+
}
|
|
974
|
+
function __velarValidateMutableList(value, name) {
|
|
975
|
+
value = __velarReactiveRaw(value);
|
|
976
|
+
const tier = __velarListTier(value);
|
|
977
|
+
if (tier === 0) return __velarValidateDenseList(value, name);
|
|
978
|
+
__velarListRequireMutableLength(value, name);
|
|
979
|
+
return value;
|
|
980
|
+
}
|
|
981
|
+
function __velarCheckedListElement(value, index, name) {
|
|
982
|
+
const descriptor = __velarCollectionListGetOwnPropertyDescriptor(value, index);
|
|
983
|
+
if (!descriptor?.enumerable || !descriptor.configurable || !descriptor.writable || !("value" in descriptor)) throw new __velarCollectionNativeTypeError2(name + " requires ordinary mutable List data elements");
|
|
984
|
+
return descriptor.value;
|
|
985
|
+
}
|
|
986
|
+
function __velarOwnedListElement(value, index, name) {
|
|
987
|
+
const element = value[index];
|
|
988
|
+
return element === void 0 ? __velarCheckedListElement(value, index, name) : element;
|
|
989
|
+
}
|
|
990
|
+
function __velarListElement(value, index, name, owned) {
|
|
991
|
+
return owned ? __velarOwnedListElement(value, index, name) : __velarCheckedListElement(value, index, name);
|
|
992
|
+
}
|
|
993
|
+
function __velarCopyList(value, name) {
|
|
994
|
+
value = __velarValidateOwnedList(value, name);
|
|
995
|
+
const owned = __velarListIsOwned(value);
|
|
996
|
+
const output = [];
|
|
997
|
+
for (let index = 0; index < value.length; index += 1) output[index] = __velarCollectionValue(__velarListElement(value, index, name, owned));
|
|
998
|
+
return __velarAdoptList(output);
|
|
999
|
+
}
|
|
1000
|
+
var __velarListNativeString = globalThis.String;
|
|
1001
|
+
var __velarListStringPrototype = __velarCollectionListGetOwnPropertyDescriptor(__velarListNativeString, "prototype")?.value;
|
|
1002
|
+
var __velarListStringCharCodeAt = __velarCollectionListGetOwnPropertyDescriptor(__velarListStringPrototype, "charCodeAt")?.value;
|
|
1003
|
+
var __velarListSurrogatePattern = /[\uD800-\uDFFF]/;
|
|
1004
|
+
var __velarListRegExpPrototype = __velarCollectionHostCall2(__velarCollectionGetPrototypeOf2, __velarCollectionNativeObject2, [__velarListSurrogatePattern]);
|
|
1005
|
+
var __velarListSurrogateExecOperation = __velarCollectionListGetOwnPropertyDescriptor(__velarListRegExpPrototype, "exec")?.value;
|
|
1006
|
+
function __velarListSize(value) {
|
|
1007
|
+
value = __velarValidateOwnedList(value, "List size");
|
|
1008
|
+
__velarReactiveCollectionTrack(value, __velarReactiveStructureKey);
|
|
1009
|
+
return value.length;
|
|
1010
|
+
}
|
|
1011
|
+
var __VelarIndexError = class extends __velarCollectionListNativeRangeError {
|
|
1012
|
+
constructor(message) {
|
|
1013
|
+
super(message);
|
|
1014
|
+
this.name = "IndexError";
|
|
1015
|
+
}
|
|
1016
|
+
};
|
|
1017
|
+
__velarCollectionListDefineProperty(__VelarIndexError, "name", { value: "IndexError", writable: false, enumerable: false, configurable: true });
|
|
1018
|
+
function __velarStrictListIndex(value, requested) {
|
|
1019
|
+
if (!__velarCollectionListIsInteger(requested)) throw new __VelarIndexError("List index must be an in-range integer");
|
|
1020
|
+
const index = requested < 0 ? value.length + requested : requested;
|
|
1021
|
+
if (index < 0 || index >= value.length) throw new __VelarIndexError("List index must be an in-range integer");
|
|
1022
|
+
return index;
|
|
1023
|
+
}
|
|
1024
|
+
function __velarListIndexGet(value, index) {
|
|
1025
|
+
value = __velarReactiveRaw(value);
|
|
1026
|
+
const tier = __velarListTier(value);
|
|
1027
|
+
if (tier === 1) {
|
|
1028
|
+
index = __velarStrictListIndex(value, index);
|
|
1029
|
+
return __velarReactiveCollectionRead(value, index, __velarOwnedListElement(value, index, "List index"));
|
|
1030
|
+
}
|
|
1031
|
+
value = __velarValidateListTier(value, "List index", tier);
|
|
1032
|
+
index = __velarStrictListIndex(value, index);
|
|
1033
|
+
return __velarReactiveCollectionRead(value, index, __velarCheckedListElement(value, index, "List index"));
|
|
1034
|
+
}
|
|
1035
|
+
function __velarListAppend(value, item) {
|
|
1036
|
+
value = __velarValidateMutableList(value, "List.append");
|
|
1037
|
+
if (value.length >= __velarMaxCollectionItems) throw new __velarCollectionListNativeRangeError("A List cannot exceed 1000000 items");
|
|
1038
|
+
item = __velarReactiveRaw(item);
|
|
1039
|
+
const index = value.length;
|
|
1040
|
+
__velarCollectionListDefineProperty(value, index, { value: item, writable: true, enumerable: true, configurable: true });
|
|
1041
|
+
__velarReactiveCollectionLink(value, item);
|
|
1042
|
+
__velarReactiveCollectionTrigger(value, index, true, true, index);
|
|
1043
|
+
__velarMarkOwnedList(value);
|
|
1044
|
+
return null;
|
|
1045
|
+
}
|
|
1046
|
+
function __velarListMap(value, transform) {
|
|
1047
|
+
const items = __velarCopyList(value, "List.map");
|
|
1048
|
+
__velarReactiveCollectionTrack(value);
|
|
1049
|
+
const output = new __velarCollectionNativeArray2(items.length);
|
|
1050
|
+
for (let index = 0; index < items.length; index += 1) {
|
|
1051
|
+
const item = transform(__velarReactiveCollectionRead(value, index, items[index]));
|
|
1052
|
+
output[index] = item === void 0 ? null : __velarReactiveRaw(item);
|
|
1053
|
+
}
|
|
1054
|
+
return __velarAdoptList(output);
|
|
1055
|
+
}
|
|
1056
|
+
|
|
1057
|
+
// src/src/index.vel
|
|
1058
|
+
import { DatabaseExecutor, DatabaseStatement, trustedSql } from "@velarscript-labs/database";
|
|
1059
|
+
|
|
1060
|
+
// velar-embedded:src/index.2ibbmz.embedded-1.js
|
|
1061
|
+
import { AsyncLocalStorage } from "node:async_hooks";
|
|
1062
|
+
import { Worker } from "node:worker_threads";
|
|
1063
|
+
var TOKEN = Object.freeze({});
|
|
1064
|
+
var connectionStates = /* @__PURE__ */ new WeakMap();
|
|
1065
|
+
var transactionStates = /* @__PURE__ */ new WeakMap();
|
|
1066
|
+
var transactionContext = new AsyncLocalStorage();
|
|
1067
|
+
var NativeSqliteError = class extends Error {
|
|
1068
|
+
constructor(message = "SQLite operation failed", sqliteCode = null, operation = "unknown", retryable = false) {
|
|
1069
|
+
super(message);
|
|
1070
|
+
this.name = "NativeSqliteError";
|
|
1071
|
+
this.sqliteCode = sqliteCode;
|
|
1072
|
+
this.operation = operation;
|
|
1073
|
+
this.retryable = retryable;
|
|
1074
|
+
}
|
|
1075
|
+
};
|
|
1076
|
+
var NativeSqliteBackpressureError = class extends NativeSqliteError {
|
|
1077
|
+
constructor(message = "SQLite queue is full") {
|
|
1078
|
+
super(message, "SQLITE_BACKPRESSURE", "queue", true);
|
|
1079
|
+
this.name = "NativeSqliteBackpressureError";
|
|
1080
|
+
}
|
|
1081
|
+
};
|
|
1082
|
+
var NativeSqliteConcurrencyError = class extends NativeSqliteError {
|
|
1083
|
+
constructor(message = "SQLite connection cannot be used from its transaction callback") {
|
|
1084
|
+
super(message, "SQLITE_CONCURRENCY", "transaction", true);
|
|
1085
|
+
this.name = "NativeSqliteConcurrencyError";
|
|
1086
|
+
}
|
|
1087
|
+
};
|
|
1088
|
+
function integer(value, fallback, minimum, maximum, label) {
|
|
1089
|
+
const selected = value == null ? fallback : value;
|
|
1090
|
+
if (!Number.isSafeInteger(selected) || selected < minimum || selected > maximum) {
|
|
1091
|
+
throw new TypeError(label + " must be an integer from " + minimum + " through " + maximum);
|
|
1092
|
+
}
|
|
1093
|
+
return selected;
|
|
1094
|
+
}
|
|
1095
|
+
function checkedOptions(value) {
|
|
1096
|
+
if (value === null || typeof value !== "object" || Array.isArray(value)) throw new TypeError("SQLite options must be a record");
|
|
1097
|
+
const allowed = /* @__PURE__ */ new Set(["busyTimeoutMilliseconds", "queueCapacity", "maxRows", "maxResultBytes", "statementCacheCapacity", "journalMode", "readOnly"]);
|
|
1098
|
+
for (const key of Object.keys(value)) if (!allowed.has(key)) throw new TypeError("Unknown SQLite option " + key);
|
|
1099
|
+
const journalModes = /* @__PURE__ */ new Set(["delete", "truncate", "persist", "memory", "wal", "off"]);
|
|
1100
|
+
const journalMode = value.journalMode == null ? null : value.journalMode;
|
|
1101
|
+
if (journalMode !== null && (typeof journalMode !== "string" || !journalModes.has(journalMode))) throw new TypeError("SQLite journalMode must name a supported mode");
|
|
1102
|
+
if (value.readOnly != null && typeof value.readOnly !== "boolean") throw new TypeError("SQLite readOnly must be bool");
|
|
1103
|
+
if (value.readOnly === true && journalMode !== null) throw new TypeError("SQLite readOnly connections cannot change journalMode");
|
|
1104
|
+
return {
|
|
1105
|
+
busyTimeoutMilliseconds: integer(value.busyTimeoutMilliseconds, 2e3, 1, 6e4, "SQLite busy timeout"),
|
|
1106
|
+
queueCapacity: integer(value.queueCapacity, 64, 1, 1024, "SQLite queue capacity"),
|
|
1107
|
+
maxRows: integer(value.maxRows, 1e4, 1, 1e6, "SQLite row limit"),
|
|
1108
|
+
maxResultBytes: integer(value.maxResultBytes, 64 * 1024 * 1024, 1, 128 * 1024 * 1024, "SQLite result byte limit"),
|
|
1109
|
+
statementCacheCapacity: integer(value.statementCacheCapacity, 128, 1, 1024, "SQLite statement cache capacity"),
|
|
1110
|
+
journalMode,
|
|
1111
|
+
readOnly: value.readOnly === true
|
|
1112
|
+
};
|
|
1113
|
+
}
|
|
1114
|
+
function workerMain() {
|
|
1115
|
+
const { Buffer } = (0, globalThis.require)("node:buffer");
|
|
1116
|
+
const { parentPort, workerData } = (0, globalThis.require)("node:worker_threads");
|
|
1117
|
+
const { DatabaseSync, constants } = (0, globalThis.require)("node:sqlite");
|
|
1118
|
+
const { parseStmt } = (0, globalThis.require)("sqlite3-parser");
|
|
1119
|
+
let database = null;
|
|
1120
|
+
let statements = null;
|
|
1121
|
+
let closed = false;
|
|
1122
|
+
function failure(message, code, operation, retryable = false) {
|
|
1123
|
+
const error = new Error(message);
|
|
1124
|
+
error.code = code;
|
|
1125
|
+
error.operation = operation;
|
|
1126
|
+
error.retryable = retryable;
|
|
1127
|
+
return error;
|
|
1128
|
+
}
|
|
1129
|
+
function errorData(error, operation) {
|
|
1130
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
1131
|
+
const rawCode = error && typeof error === "object" ? error.errstr ?? error.code ?? null : null;
|
|
1132
|
+
const code = rawCode == null ? null : String(rawCode);
|
|
1133
|
+
const upper = code == null ? "" : code.toUpperCase();
|
|
1134
|
+
return {
|
|
1135
|
+
message,
|
|
1136
|
+
sqliteCode: code,
|
|
1137
|
+
operation: error && typeof error.operation === "string" ? error.operation : operation,
|
|
1138
|
+
retryable: error && error.retryable === true || upper.includes("BUSY") || upper.includes("LOCKED")
|
|
1139
|
+
};
|
|
1140
|
+
}
|
|
1141
|
+
function parameter(value, budget) {
|
|
1142
|
+
if (value === null) return null;
|
|
1143
|
+
if (typeof value === "boolean") return value ? 1 : 0;
|
|
1144
|
+
if (typeof value === "string") {
|
|
1145
|
+
budget.value += Buffer.byteLength(value, "utf8");
|
|
1146
|
+
return value;
|
|
1147
|
+
}
|
|
1148
|
+
if (typeof value === "number") {
|
|
1149
|
+
if (!Number.isFinite(value)) throw failure("SQLite number parameters must be finite", "SQLITE_INPUT", "params");
|
|
1150
|
+
if (Number.isInteger(value) && !Number.isSafeInteger(value)) throw failure("SQLite integer parameters must be safe integers", "SQLITE_INPUT", "params");
|
|
1151
|
+
budget.value += 8;
|
|
1152
|
+
return value;
|
|
1153
|
+
}
|
|
1154
|
+
if (value instanceof Uint8Array) {
|
|
1155
|
+
budget.value += value.byteLength;
|
|
1156
|
+
return value;
|
|
1157
|
+
}
|
|
1158
|
+
throw failure("SQLite parameters support only null, bool, string, finite number, and Bytes", "SQLITE_INPUT", "params");
|
|
1159
|
+
}
|
|
1160
|
+
function parameters(value) {
|
|
1161
|
+
if (!Array.isArray(value) || value.length > 999) throw failure("SQLite parameters must be a List with at most 999 values", "SQLITE_INPUT", "params");
|
|
1162
|
+
const budget = { value: 0 };
|
|
1163
|
+
const output = value.map((item) => parameter(item, budget));
|
|
1164
|
+
if (budget.value > workerData.maxResultBytes) throw failure("SQLite parameters exceed the connection byte limit", "SQLITE_INPUT", "params");
|
|
1165
|
+
return output;
|
|
1166
|
+
}
|
|
1167
|
+
function statementParts(rawFragments, rawParameters, operation) {
|
|
1168
|
+
if (!Array.isArray(rawFragments) || rawFragments.length !== rawParameters.length + 1 || rawFragments.length > 1e3) {
|
|
1169
|
+
throw failure("SQLite statements require exactly one more SQL fragment than bound parameters", "SQLITE_INPUT", operation);
|
|
1170
|
+
}
|
|
1171
|
+
let sourceBytes = 0;
|
|
1172
|
+
const fragments = rawFragments.map((fragment) => {
|
|
1173
|
+
if (typeof fragment !== "string" || fragment.includes("\0") || fragment.includes("?")) {
|
|
1174
|
+
throw failure("SQLite SQL fragments must be text without NUL or raw parameter placeholders", "SQLITE_INPUT", operation);
|
|
1175
|
+
}
|
|
1176
|
+
sourceBytes += Buffer.byteLength(fragment, "utf8");
|
|
1177
|
+
return fragment;
|
|
1178
|
+
});
|
|
1179
|
+
if (sourceBytes === 0 || sourceBytes > 1024 * 1024) throw failure("SQLite SQL must be non-empty text no longer than 1 MiB", "SQLITE_INPUT", operation);
|
|
1180
|
+
const bound = parameters(rawParameters);
|
|
1181
|
+
const source = fragments.join("?");
|
|
1182
|
+
const parsed = parseStmt(source);
|
|
1183
|
+
if (parsed.status !== "ok") {
|
|
1184
|
+
const message = parsed.errors.length === 0 ? "invalid statement" : parsed.errors[0].message;
|
|
1185
|
+
throw failure("SQLite requires exactly one valid statement: " + message, "SQLITE_INPUT", operation);
|
|
1186
|
+
}
|
|
1187
|
+
return { fragments, bound };
|
|
1188
|
+
}
|
|
1189
|
+
function count(value, label) {
|
|
1190
|
+
const number = typeof value === "bigint" ? Number(value) : value;
|
|
1191
|
+
if (!Number.isSafeInteger(number) || number < 0) throw failure(label + " is outside VelarScript's safe integer range", "SQLITE_INTEGER_RANGE", "result");
|
|
1192
|
+
return number;
|
|
1193
|
+
}
|
|
1194
|
+
function resultValue(value, budget, field) {
|
|
1195
|
+
if (value === null) return null;
|
|
1196
|
+
if (typeof value === "string") {
|
|
1197
|
+
budget.value += Buffer.byteLength(value, "utf8");
|
|
1198
|
+
return value;
|
|
1199
|
+
}
|
|
1200
|
+
if (typeof value === "number") {
|
|
1201
|
+
if (!Number.isFinite(value)) throw failure("SQLite returned a non-finite number in " + field, "SQLITE_RESULT", "result");
|
|
1202
|
+
budget.value += 8;
|
|
1203
|
+
return value;
|
|
1204
|
+
}
|
|
1205
|
+
if (typeof value === "bigint") {
|
|
1206
|
+
const number = Number(value);
|
|
1207
|
+
if (!Number.isSafeInteger(number)) throw failure("SQLite returned an integer outside VelarScript's safe range in " + field, "SQLITE_INTEGER_RANGE", "result");
|
|
1208
|
+
budget.value += 8;
|
|
1209
|
+
return number;
|
|
1210
|
+
}
|
|
1211
|
+
if (value instanceof Uint8Array) {
|
|
1212
|
+
budget.value += value.byteLength;
|
|
1213
|
+
return value;
|
|
1214
|
+
}
|
|
1215
|
+
throw failure("SQLite returned an unsupported value in " + field, "SQLITE_RESULT", "result");
|
|
1216
|
+
}
|
|
1217
|
+
function resultRow(value, budget) {
|
|
1218
|
+
if (value === null || typeof value !== "object" || Array.isArray(value)) throw failure("SQLite returned a non-record row", "SQLITE_RESULT", "result");
|
|
1219
|
+
const output = /* @__PURE__ */ Object.create(null);
|
|
1220
|
+
for (const key of Object.keys(value)) {
|
|
1221
|
+
budget.value += Buffer.byteLength(key, "utf8");
|
|
1222
|
+
output[key] = resultValue(value[key], budget, key);
|
|
1223
|
+
if (budget.value > workerData.maxResultBytes) throw failure("SQLite result exceeds the connection byte limit", "SQLITE_RESULT_LIMIT", "result");
|
|
1224
|
+
}
|
|
1225
|
+
return output;
|
|
1226
|
+
}
|
|
1227
|
+
function execute(message) {
|
|
1228
|
+
const statement = statementParts(message.fragments, message.params, "execute");
|
|
1229
|
+
const result = statements.run(statement.fragments, ...statement.bound);
|
|
1230
|
+
return count(result.changes, "SQLite affected row count");
|
|
1231
|
+
}
|
|
1232
|
+
function one(message) {
|
|
1233
|
+
const statement = statementParts(message.fragments, message.params, "one");
|
|
1234
|
+
const row = statements.get(statement.fragments, ...statement.bound);
|
|
1235
|
+
if (row === void 0) return null;
|
|
1236
|
+
return resultRow(row, { value: 0 });
|
|
1237
|
+
}
|
|
1238
|
+
function all(message) {
|
|
1239
|
+
const statement = statementParts(message.fragments, message.params, "all");
|
|
1240
|
+
const rows = [];
|
|
1241
|
+
const budget = { value: 0 };
|
|
1242
|
+
for (const row of statements.iterate(statement.fragments, ...statement.bound)) {
|
|
1243
|
+
if (rows.length >= workerData.maxRows) throw failure("SQLite result exceeds the connection row limit", "SQLITE_ROW_LIMIT", "all");
|
|
1244
|
+
rows.push(resultRow(row, budget));
|
|
1245
|
+
}
|
|
1246
|
+
return rows;
|
|
1247
|
+
}
|
|
1248
|
+
function dispatch(message) {
|
|
1249
|
+
if (closed) throw failure("SQLite connection is closed", "SQLITE_CLOSED", message.operation);
|
|
1250
|
+
if (message.operation === "execute") return execute(message);
|
|
1251
|
+
if (message.operation === "one") return one(message);
|
|
1252
|
+
if (message.operation === "all") return all(message);
|
|
1253
|
+
if (message.operation === "begin") {
|
|
1254
|
+
if (database.isTransaction) throw failure("SQLite transaction is already active", "SQLITE_TRANSACTION", "begin", true);
|
|
1255
|
+
database.exec("BEGIN IMMEDIATE");
|
|
1256
|
+
return null;
|
|
1257
|
+
}
|
|
1258
|
+
if (message.operation === "commit") {
|
|
1259
|
+
if (!database.isTransaction) throw failure("SQLite transaction is not active", "SQLITE_TRANSACTION", "commit");
|
|
1260
|
+
database.exec("COMMIT");
|
|
1261
|
+
return null;
|
|
1262
|
+
}
|
|
1263
|
+
if (message.operation === "rollback") {
|
|
1264
|
+
if (database.isTransaction) database.exec("ROLLBACK");
|
|
1265
|
+
return null;
|
|
1266
|
+
}
|
|
1267
|
+
if (message.operation === "close") {
|
|
1268
|
+
try {
|
|
1269
|
+
if (database.isTransaction) database.exec("ROLLBACK");
|
|
1270
|
+
} finally {
|
|
1271
|
+
database.close();
|
|
1272
|
+
closed = true;
|
|
1273
|
+
}
|
|
1274
|
+
return null;
|
|
1275
|
+
}
|
|
1276
|
+
throw failure("Unknown SQLite operation", "SQLITE_PROTOCOL", String(message.operation));
|
|
1277
|
+
}
|
|
1278
|
+
try {
|
|
1279
|
+
database = new DatabaseSync(workerData.path, {
|
|
1280
|
+
timeout: workerData.busyTimeoutMilliseconds,
|
|
1281
|
+
readOnly: workerData.readOnly,
|
|
1282
|
+
enableForeignKeyConstraints: true,
|
|
1283
|
+
enableDoubleQuotedStringLiterals: false,
|
|
1284
|
+
allowExtension: false,
|
|
1285
|
+
readBigInts: true,
|
|
1286
|
+
allowBareNamedParameters: false,
|
|
1287
|
+
allowUnknownNamedParameters: false,
|
|
1288
|
+
defensive: true,
|
|
1289
|
+
limits: {
|
|
1290
|
+
length: workerData.maxResultBytes,
|
|
1291
|
+
sqlLength: 1024 * 1024,
|
|
1292
|
+
column: 2e3,
|
|
1293
|
+
exprDepth: 1e3,
|
|
1294
|
+
compoundSelect: 500,
|
|
1295
|
+
vdbeOp: 25e4,
|
|
1296
|
+
functionArg: 1e3,
|
|
1297
|
+
attach: 0,
|
|
1298
|
+
likePatternLength: 5e4,
|
|
1299
|
+
variableNumber: 999,
|
|
1300
|
+
triggerDepth: 100
|
|
1301
|
+
}
|
|
1302
|
+
});
|
|
1303
|
+
database.enableDefensive(true);
|
|
1304
|
+
database.enableLoadExtension(false);
|
|
1305
|
+
database.setAuthorizer((actionCode, arg1, arg2) => {
|
|
1306
|
+
if (actionCode === constants.SQLITE_ATTACH || actionCode === constants.SQLITE_DETACH) return constants.SQLITE_DENY;
|
|
1307
|
+
if (actionCode === constants.SQLITE_FUNCTION && typeof arg2 === "string" && arg2.toLowerCase() === "load_extension") return constants.SQLITE_DENY;
|
|
1308
|
+
return constants.SQLITE_OK;
|
|
1309
|
+
});
|
|
1310
|
+
statements = database.createTagStore(workerData.statementCacheCapacity);
|
|
1311
|
+
if (workerData.journalMode !== null) database.exec("PRAGMA journal_mode = " + workerData.journalMode.toUpperCase());
|
|
1312
|
+
parentPort.postMessage({ kind: "ready" });
|
|
1313
|
+
} catch (error) {
|
|
1314
|
+
parentPort.postMessage({ kind: "ready", error: errorData(error, "open") });
|
|
1315
|
+
parentPort.close();
|
|
1316
|
+
return;
|
|
1317
|
+
}
|
|
1318
|
+
parentPort.on("message", (message) => {
|
|
1319
|
+
try {
|
|
1320
|
+
const value = dispatch(message);
|
|
1321
|
+
parentPort.postMessage({ kind: "response", id: message.id, value });
|
|
1322
|
+
if (message.operation === "close") parentPort.close();
|
|
1323
|
+
} catch (error) {
|
|
1324
|
+
parentPort.postMessage({ kind: "response", id: message.id, error: errorData(error, message.operation) });
|
|
1325
|
+
}
|
|
1326
|
+
});
|
|
1327
|
+
}
|
|
1328
|
+
function nativeError(value) {
|
|
1329
|
+
return new NativeSqliteError(value.message, value.sqliteCode, value.operation, value.retryable);
|
|
1330
|
+
}
|
|
1331
|
+
function failPending(state, error) {
|
|
1332
|
+
if (state.readyReject !== null) {
|
|
1333
|
+
state.readyReject(error);
|
|
1334
|
+
state.readyReject = null;
|
|
1335
|
+
state.readyResolve = null;
|
|
1336
|
+
}
|
|
1337
|
+
for (const pending of state.pending.values()) pending.reject(error);
|
|
1338
|
+
state.pending.clear();
|
|
1339
|
+
}
|
|
1340
|
+
function request(state, operation, fragments = [""], params = []) {
|
|
1341
|
+
if (state.closed) return Promise.reject(new NativeSqliteError("SQLite connection is closed", "SQLITE_CLOSED", operation));
|
|
1342
|
+
const id = state.nextId++;
|
|
1343
|
+
return new Promise((resolve, reject) => {
|
|
1344
|
+
state.pending.set(id, { resolve, reject });
|
|
1345
|
+
try {
|
|
1346
|
+
state.worker.postMessage({ id, operation, fragments, params });
|
|
1347
|
+
} catch (error) {
|
|
1348
|
+
state.pending.delete(id);
|
|
1349
|
+
reject(error);
|
|
1350
|
+
}
|
|
1351
|
+
});
|
|
1352
|
+
}
|
|
1353
|
+
function stateOf(connection) {
|
|
1354
|
+
const state = connectionStates.get(connection);
|
|
1355
|
+
if (!state) throw new TypeError("Invalid SQLite connection");
|
|
1356
|
+
return state;
|
|
1357
|
+
}
|
|
1358
|
+
function transactionStateOf(transaction) {
|
|
1359
|
+
const state = transactionStates.get(transaction);
|
|
1360
|
+
if (!state || !state.active) throw new NativeSqliteConcurrencyError("SQLite transaction is no longer active");
|
|
1361
|
+
return state;
|
|
1362
|
+
}
|
|
1363
|
+
function transactionRequest(transaction, operation, fragments = [""], params = []) {
|
|
1364
|
+
const state = transactionStateOf(transaction);
|
|
1365
|
+
if (state.busy) return Promise.reject(new NativeSqliteConcurrencyError("SQLite transaction operations must be awaited one at a time"));
|
|
1366
|
+
state.busy = true;
|
|
1367
|
+
return request(state.connection, operation, fragments, params).finally(() => {
|
|
1368
|
+
state.busy = false;
|
|
1369
|
+
});
|
|
1370
|
+
}
|
|
1371
|
+
function enqueue(state, operation) {
|
|
1372
|
+
if (state.closed || state.closing) return Promise.reject(new NativeSqliteError("SQLite connection is closed", "SQLITE_CLOSED", "queue"));
|
|
1373
|
+
if (transactionContext.getStore() === state) return Promise.reject(new NativeSqliteConcurrencyError());
|
|
1374
|
+
if (state.queued >= state.queueCapacity) return Promise.reject(new NativeSqliteBackpressureError());
|
|
1375
|
+
state.queued += 1;
|
|
1376
|
+
const running = state.tail.then(operation, operation);
|
|
1377
|
+
state.tail = running.then(() => null, () => null);
|
|
1378
|
+
return running.finally(() => {
|
|
1379
|
+
state.queued -= 1;
|
|
1380
|
+
});
|
|
1381
|
+
}
|
|
1382
|
+
var NativeSqliteTransaction = class {
|
|
1383
|
+
constructor(token, state) {
|
|
1384
|
+
if (token !== TOKEN) throw new TypeError("SQLite transactions are created by connection.transaction");
|
|
1385
|
+
transactionStates.set(this, state);
|
|
1386
|
+
}
|
|
1387
|
+
execute(fragments, params = []) {
|
|
1388
|
+
return transactionRequest(this, "execute", fragments, params);
|
|
1389
|
+
}
|
|
1390
|
+
one(fragments, params = []) {
|
|
1391
|
+
return transactionRequest(this, "one", fragments, params);
|
|
1392
|
+
}
|
|
1393
|
+
all(fragments, params = []) {
|
|
1394
|
+
return transactionRequest(this, "all", fragments, params);
|
|
1395
|
+
}
|
|
1396
|
+
};
|
|
1397
|
+
var NativeSqliteConnection = class {
|
|
1398
|
+
constructor(token, state) {
|
|
1399
|
+
if (token !== TOKEN) throw new TypeError("Use openSqlite to create a SQLite connection");
|
|
1400
|
+
connectionStates.set(this, state);
|
|
1401
|
+
}
|
|
1402
|
+
execute(fragments, params = []) {
|
|
1403
|
+
const state = stateOf(this);
|
|
1404
|
+
return enqueue(state, () => request(state, "execute", fragments, params));
|
|
1405
|
+
}
|
|
1406
|
+
one(fragments, params = []) {
|
|
1407
|
+
const state = stateOf(this);
|
|
1408
|
+
return enqueue(state, () => request(state, "one", fragments, params));
|
|
1409
|
+
}
|
|
1410
|
+
all(fragments, params = []) {
|
|
1411
|
+
const state = stateOf(this);
|
|
1412
|
+
return enqueue(state, () => request(state, "all", fragments, params));
|
|
1413
|
+
}
|
|
1414
|
+
transaction(operation) {
|
|
1415
|
+
if (typeof operation !== "function") return Promise.reject(new TypeError("SQLite transaction requires an async operation"));
|
|
1416
|
+
const state = stateOf(this);
|
|
1417
|
+
return enqueue(state, async () => {
|
|
1418
|
+
await request(state, "begin");
|
|
1419
|
+
const transactionState = { connection: state, active: true, busy: false };
|
|
1420
|
+
const transaction = new NativeSqliteTransaction(TOKEN, transactionState);
|
|
1421
|
+
try {
|
|
1422
|
+
await transactionContext.run(state, () => operation(transaction));
|
|
1423
|
+
await transactionRequest(transaction, "commit");
|
|
1424
|
+
transactionState.active = false;
|
|
1425
|
+
return null;
|
|
1426
|
+
} catch (error) {
|
|
1427
|
+
try {
|
|
1428
|
+
if (transactionState.active) await transactionRequest(transaction, "rollback");
|
|
1429
|
+
} catch {
|
|
1430
|
+
state.closing = true;
|
|
1431
|
+
state.worker.terminate();
|
|
1432
|
+
} finally {
|
|
1433
|
+
transactionState.active = false;
|
|
1434
|
+
}
|
|
1435
|
+
throw error;
|
|
1436
|
+
}
|
|
1437
|
+
});
|
|
1438
|
+
}
|
|
1439
|
+
close() {
|
|
1440
|
+
const state = stateOf(this);
|
|
1441
|
+
if (state.closePromise !== null) return state.closePromise;
|
|
1442
|
+
if (transactionContext.getStore() === state) return Promise.reject(new NativeSqliteConcurrencyError("SQLite connection cannot close inside its transaction callback"));
|
|
1443
|
+
state.closing = true;
|
|
1444
|
+
state.closePromise = state.tail.then(async () => {
|
|
1445
|
+
try {
|
|
1446
|
+
if (!state.closed) await request(state, "close");
|
|
1447
|
+
await state.exited;
|
|
1448
|
+
} finally {
|
|
1449
|
+
state.closed = true;
|
|
1450
|
+
}
|
|
1451
|
+
});
|
|
1452
|
+
return state.closePromise;
|
|
1453
|
+
}
|
|
1454
|
+
};
|
|
1455
|
+
async function openNativeSqlite(path, options = {}) {
|
|
1456
|
+
if (typeof path !== "string" || path.trim() === "" || path.length > 4096 || path.includes("\0")) throw new TypeError("SQLite path must be non-empty bounded text");
|
|
1457
|
+
const checked = checkedOptions(options);
|
|
1458
|
+
const source = "(" + workerMain.toString() + ")()";
|
|
1459
|
+
const worker = new Worker(source, { eval: true, workerData: { path, ...checked } });
|
|
1460
|
+
let readyResolve;
|
|
1461
|
+
let readyReject;
|
|
1462
|
+
let exitResolve;
|
|
1463
|
+
const ready = new Promise((resolve, reject) => {
|
|
1464
|
+
readyResolve = resolve;
|
|
1465
|
+
readyReject = reject;
|
|
1466
|
+
});
|
|
1467
|
+
const exited = new Promise((resolve) => {
|
|
1468
|
+
exitResolve = resolve;
|
|
1469
|
+
});
|
|
1470
|
+
const state = {
|
|
1471
|
+
worker,
|
|
1472
|
+
readyResolve,
|
|
1473
|
+
readyReject,
|
|
1474
|
+
exited,
|
|
1475
|
+
pending: /* @__PURE__ */ new Map(),
|
|
1476
|
+
nextId: 1,
|
|
1477
|
+
queueCapacity: checked.queueCapacity,
|
|
1478
|
+
queued: 0,
|
|
1479
|
+
tail: Promise.resolve(),
|
|
1480
|
+
closing: false,
|
|
1481
|
+
closed: false,
|
|
1482
|
+
closePromise: null
|
|
1483
|
+
};
|
|
1484
|
+
worker.on("message", (message) => {
|
|
1485
|
+
if (message.kind === "ready") {
|
|
1486
|
+
const resolve = state.readyResolve;
|
|
1487
|
+
const reject = state.readyReject;
|
|
1488
|
+
state.readyResolve = null;
|
|
1489
|
+
state.readyReject = null;
|
|
1490
|
+
if (message.error) reject(nativeError(message.error));
|
|
1491
|
+
else resolve();
|
|
1492
|
+
return;
|
|
1493
|
+
}
|
|
1494
|
+
if (message.kind !== "response") return;
|
|
1495
|
+
const pending = state.pending.get(message.id);
|
|
1496
|
+
if (!pending) return;
|
|
1497
|
+
state.pending.delete(message.id);
|
|
1498
|
+
if (message.error) pending.reject(nativeError(message.error));
|
|
1499
|
+
else pending.resolve(message.value);
|
|
1500
|
+
});
|
|
1501
|
+
worker.on("error", (error) => {
|
|
1502
|
+
state.closed = true;
|
|
1503
|
+
failPending(state, new NativeSqliteError(error.message, "SQLITE_WORKER", "worker"));
|
|
1504
|
+
});
|
|
1505
|
+
worker.on("exit", (code) => {
|
|
1506
|
+
exitResolve(code);
|
|
1507
|
+
if (code !== 0 && !state.closed) {
|
|
1508
|
+
state.closed = true;
|
|
1509
|
+
failPending(state, new NativeSqliteError("SQLite Worker exited with code " + code, "SQLITE_WORKER", "worker"));
|
|
1510
|
+
}
|
|
1511
|
+
});
|
|
1512
|
+
await ready;
|
|
1513
|
+
return new NativeSqliteConnection(TOKEN, state);
|
|
1514
|
+
}
|
|
1515
|
+
|
|
1516
|
+
// src/src/index.vel
|
|
1517
|
+
var SqliteJournalMode = __velarRegisterRuntimeType(__velarValidationFreeze({
|
|
1518
|
+
delete: "delete",
|
|
1519
|
+
truncate: "truncate",
|
|
1520
|
+
persist: "persist",
|
|
1521
|
+
memory: "memory",
|
|
1522
|
+
wal: "wal",
|
|
1523
|
+
off: "off",
|
|
1524
|
+
is(value) {
|
|
1525
|
+
return value === "delete" || value === "truncate" || value === "persist" || value === "memory" || value === "wal" || value === "off";
|
|
1526
|
+
},
|
|
1527
|
+
parse(value) {
|
|
1528
|
+
if (!SqliteJournalMode.is(value)) {
|
|
1529
|
+
throw new __VelarValidationError("Value does not match SqliteJournalMode", { path: "SqliteJournalMode" });
|
|
1530
|
+
}
|
|
1531
|
+
return value;
|
|
1532
|
+
},
|
|
1533
|
+
copy(value) {
|
|
1534
|
+
return value;
|
|
1535
|
+
},
|
|
1536
|
+
values() {
|
|
1537
|
+
return ["delete", "truncate", "persist", "memory", "wal", "off"];
|
|
1538
|
+
}
|
|
1539
|
+
}));
|
|
1540
|
+
function __velarTypeExplain_SqliteOptions(value) {
|
|
1541
|
+
if (value === null || typeof value !== "object" || __velarValidationIsArray(value) || !__velarValidationIsPlainObject(value)) {
|
|
1542
|
+
return { path: "SqliteOptions", field: null, reason: "the value is not a record" };
|
|
1543
|
+
}
|
|
1544
|
+
{
|
|
1545
|
+
const __velarExplainField = __velarValidationOwnDescriptor(value, "busyTimeoutMilliseconds");
|
|
1546
|
+
if (__velarExplainField !== void 0 && !(__velarExplainField.enumerable && "value" in __velarExplainField && (__velarExplainField.value == null || typeof __velarExplainField.value === "number"))) {
|
|
1547
|
+
return { path: "SqliteOptions.busyTimeoutMilliseconds", field: "busyTimeoutMilliseconds", reason: "field 'busyTimeoutMilliseconds' does not match number?" };
|
|
1548
|
+
}
|
|
1549
|
+
}
|
|
1550
|
+
{
|
|
1551
|
+
const __velarExplainField = __velarValidationOwnDescriptor(value, "queueCapacity");
|
|
1552
|
+
if (__velarExplainField !== void 0 && !(__velarExplainField.enumerable && "value" in __velarExplainField && (__velarExplainField.value == null || typeof __velarExplainField.value === "number"))) {
|
|
1553
|
+
return { path: "SqliteOptions.queueCapacity", field: "queueCapacity", reason: "field 'queueCapacity' does not match number?" };
|
|
1554
|
+
}
|
|
1555
|
+
}
|
|
1556
|
+
{
|
|
1557
|
+
const __velarExplainField = __velarValidationOwnDescriptor(value, "maxRows");
|
|
1558
|
+
if (__velarExplainField !== void 0 && !(__velarExplainField.enumerable && "value" in __velarExplainField && (__velarExplainField.value == null || typeof __velarExplainField.value === "number"))) {
|
|
1559
|
+
return { path: "SqliteOptions.maxRows", field: "maxRows", reason: "field 'maxRows' does not match number?" };
|
|
1560
|
+
}
|
|
1561
|
+
}
|
|
1562
|
+
{
|
|
1563
|
+
const __velarExplainField = __velarValidationOwnDescriptor(value, "maxResultBytes");
|
|
1564
|
+
if (__velarExplainField !== void 0 && !(__velarExplainField.enumerable && "value" in __velarExplainField && (__velarExplainField.value == null || typeof __velarExplainField.value === "number"))) {
|
|
1565
|
+
return { path: "SqliteOptions.maxResultBytes", field: "maxResultBytes", reason: "field 'maxResultBytes' does not match number?" };
|
|
1566
|
+
}
|
|
1567
|
+
}
|
|
1568
|
+
{
|
|
1569
|
+
const __velarExplainField = __velarValidationOwnDescriptor(value, "statementCacheCapacity");
|
|
1570
|
+
if (__velarExplainField !== void 0 && !(__velarExplainField.enumerable && "value" in __velarExplainField && (__velarExplainField.value == null || typeof __velarExplainField.value === "number"))) {
|
|
1571
|
+
return { path: "SqliteOptions.statementCacheCapacity", field: "statementCacheCapacity", reason: "field 'statementCacheCapacity' does not match number?" };
|
|
1572
|
+
}
|
|
1573
|
+
}
|
|
1574
|
+
{
|
|
1575
|
+
const __velarExplainField = __velarValidationOwnDescriptor(value, "journalMode");
|
|
1576
|
+
if (__velarExplainField !== void 0 && !(__velarExplainField.enumerable && "value" in __velarExplainField && (__velarExplainField.value == null || SqliteJournalMode.is(__velarExplainField.value)))) {
|
|
1577
|
+
return { path: "SqliteOptions.journalMode", field: "journalMode", reason: "field 'journalMode' does not match SqliteJournalMode?" };
|
|
1578
|
+
}
|
|
1579
|
+
}
|
|
1580
|
+
{
|
|
1581
|
+
const __velarExplainField = __velarValidationOwnDescriptor(value, "readOnly");
|
|
1582
|
+
if (__velarExplainField !== void 0 && !(__velarExplainField.enumerable && "value" in __velarExplainField && (__velarExplainField.value == null || typeof __velarExplainField.value === "boolean"))) {
|
|
1583
|
+
return { path: "SqliteOptions.readOnly", field: "readOnly", reason: "field 'readOnly' does not match bool?" };
|
|
1584
|
+
}
|
|
1585
|
+
}
|
|
1586
|
+
return { path: "SqliteOptions", field: null, reason: null };
|
|
1587
|
+
}
|
|
1588
|
+
function __velarTypeCheck_SqliteOptions(value) {
|
|
1589
|
+
if (value === null || typeof value !== "object" || __velarValidationIsArray(value) || !__velarValidationIsPlainObject(value)) return false;
|
|
1590
|
+
const __velarField0 = __velarValidationOwnDescriptor(value, "busyTimeoutMilliseconds");
|
|
1591
|
+
const __velarField1 = __velarValidationOwnDescriptor(value, "queueCapacity");
|
|
1592
|
+
const __velarField2 = __velarValidationOwnDescriptor(value, "maxRows");
|
|
1593
|
+
const __velarField3 = __velarValidationOwnDescriptor(value, "maxResultBytes");
|
|
1594
|
+
const __velarField4 = __velarValidationOwnDescriptor(value, "statementCacheCapacity");
|
|
1595
|
+
const __velarField5 = __velarValidationOwnDescriptor(value, "journalMode");
|
|
1596
|
+
const __velarField6 = __velarValidationOwnDescriptor(value, "readOnly");
|
|
1597
|
+
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")) && (__velarField4 === void 0 || __velarField4?.enumerable && "value" in __velarField4 && (__velarField4.value == null || typeof __velarField4.value === "number")) && (__velarField5 === void 0 || __velarField5?.enumerable && "value" in __velarField5 && (__velarField5.value == null || SqliteJournalMode.is(__velarField5.value))) && (__velarField6 === void 0 || __velarField6?.enumerable && "value" in __velarField6 && (__velarField6.value == null || typeof __velarField6.value === "boolean")));
|
|
1598
|
+
}
|
|
1599
|
+
function __velarTypeCopy_SqliteOptions(value, __state, __velarCopyPlan) {
|
|
1600
|
+
const __velarCopySeen = __state.copy.seen(__state, value, __velarCopyPlan);
|
|
1601
|
+
if (__velarCopySeen !== void 0) return __velarCopySeen;
|
|
1602
|
+
const __velarCopy = __state.copy.object(__state, value, __velarCopyPlan);
|
|
1603
|
+
{
|
|
1604
|
+
const __velarCopyField = __velarValidationOwnDescriptor(value, "busyTimeoutMilliseconds");
|
|
1605
|
+
if (__velarCopyField !== void 0) __state.copy.field(__velarCopy, "busyTimeoutMilliseconds", __velarCopyField.value);
|
|
1606
|
+
}
|
|
1607
|
+
{
|
|
1608
|
+
const __velarCopyField = __velarValidationOwnDescriptor(value, "queueCapacity");
|
|
1609
|
+
if (__velarCopyField !== void 0) __state.copy.field(__velarCopy, "queueCapacity", __velarCopyField.value);
|
|
1610
|
+
}
|
|
1611
|
+
{
|
|
1612
|
+
const __velarCopyField = __velarValidationOwnDescriptor(value, "maxRows");
|
|
1613
|
+
if (__velarCopyField !== void 0) __state.copy.field(__velarCopy, "maxRows", __velarCopyField.value);
|
|
1614
|
+
}
|
|
1615
|
+
{
|
|
1616
|
+
const __velarCopyField = __velarValidationOwnDescriptor(value, "maxResultBytes");
|
|
1617
|
+
if (__velarCopyField !== void 0) __state.copy.field(__velarCopy, "maxResultBytes", __velarCopyField.value);
|
|
1618
|
+
}
|
|
1619
|
+
{
|
|
1620
|
+
const __velarCopyField = __velarValidationOwnDescriptor(value, "statementCacheCapacity");
|
|
1621
|
+
if (__velarCopyField !== void 0) __state.copy.field(__velarCopy, "statementCacheCapacity", __velarCopyField.value);
|
|
1622
|
+
}
|
|
1623
|
+
{
|
|
1624
|
+
const __velarCopyField = __velarValidationOwnDescriptor(value, "journalMode");
|
|
1625
|
+
if (__velarCopyField !== void 0) __state.copy.field(__velarCopy, "journalMode", __velarCopyField.value);
|
|
1626
|
+
}
|
|
1627
|
+
{
|
|
1628
|
+
const __velarCopyField = __velarValidationOwnDescriptor(value, "readOnly");
|
|
1629
|
+
if (__velarCopyField !== void 0) __state.copy.field(__velarCopy, "readOnly", __velarCopyField.value);
|
|
1630
|
+
}
|
|
1631
|
+
return __velarCopy;
|
|
1632
|
+
}
|
|
1633
|
+
var SqliteOptions = __velarRegisterRuntimeType(__velarValidationFreeze({
|
|
1634
|
+
is(value) {
|
|
1635
|
+
return __velarTypeCheck_SqliteOptions(value);
|
|
1636
|
+
},
|
|
1637
|
+
parse(value) {
|
|
1638
|
+
if (!__velarTypeCheck_SqliteOptions(value)) {
|
|
1639
|
+
const __velarDetail = __velarTypeExplain_SqliteOptions(value);
|
|
1640
|
+
throw new __VelarValidationError("Value does not match SqliteOptions" + (__velarDetail.reason ? " \u2014 " + __velarDetail.reason : "") + __velarValidationRejectionHint(value), __velarDetail);
|
|
1641
|
+
}
|
|
1642
|
+
return __velarTypeCopy_SqliteOptions(value, __velarValidationState(), __velarTypeCopy_SqliteOptions);
|
|
1643
|
+
},
|
|
1644
|
+
copy(value, __state = __velarValidationState(), __velarCopyPlan = __velarTypeCopy_SqliteOptions) {
|
|
1645
|
+
return __velarTypeCopy_SqliteOptions(value, __state, __velarCopyPlan);
|
|
1646
|
+
}
|
|
1647
|
+
}));
|
|
1648
|
+
var SqliteError = class extends Error {
|
|
1649
|
+
constructor(message, sqliteCode = null, operation = "unknown", retryable = false) {
|
|
1650
|
+
super(message);
|
|
1651
|
+
this.name = "SqliteError";
|
|
1652
|
+
const self = this;
|
|
1653
|
+
self.sqliteCode = sqliteCode ?? null;
|
|
1654
|
+
self.operation = operation;
|
|
1655
|
+
self.retryable = retryable;
|
|
1656
|
+
}
|
|
1657
|
+
};
|
|
1658
|
+
var SqliteBackpressureError = class extends SqliteError {
|
|
1659
|
+
constructor(message = "SQLite queue is full") {
|
|
1660
|
+
super(message, "SQLITE_BACKPRESSURE", "queue", true);
|
|
1661
|
+
this.name = "SqliteBackpressureError";
|
|
1662
|
+
const self = this;
|
|
1663
|
+
}
|
|
1664
|
+
};
|
|
1665
|
+
var SqliteConcurrencyError = class extends SqliteError {
|
|
1666
|
+
constructor(message = "SQLite connection cannot be used from its transaction callback") {
|
|
1667
|
+
super(message, "SQLITE_CONCURRENCY", "transaction", true);
|
|
1668
|
+
this.name = "SqliteConcurrencyError";
|
|
1669
|
+
const self = this;
|
|
1670
|
+
}
|
|
1671
|
+
};
|
|
1672
|
+
function sqliteFailure(error) {
|
|
1673
|
+
if (error instanceof NativeSqliteBackpressureError) {
|
|
1674
|
+
return new SqliteBackpressureError(((__velarValue) => __velarNarrow(__velarValue, __velarValidationIsInstance(__velarValue, NativeSqliteBackpressureError), "NativeSqliteBackpressureError", "error", 24269))(error).message);
|
|
1675
|
+
}
|
|
1676
|
+
if (error instanceof NativeSqliteConcurrencyError) {
|
|
1677
|
+
return new SqliteConcurrencyError(((__velarValue) => __velarNarrow(__velarValue, __velarValidationIsInstance(__velarValue, NativeSqliteConcurrencyError), "NativeSqliteConcurrencyError", "error", 24368))(error).message);
|
|
1678
|
+
}
|
|
1679
|
+
if (error instanceof NativeSqliteError) {
|
|
1680
|
+
return new SqliteError(((__velarValue) => __velarNarrow(__velarValue, __velarValidationIsInstance(__velarValue, NativeSqliteError), "NativeSqliteError", "error", 24445))(error).message, ((__velarValue) => __velarNarrow(__velarValue, __velarValidationIsInstance(__velarValue, NativeSqliteError), "NativeSqliteError", "error", 24460))(error).sqliteCode ?? null, ((__velarValue) => __velarNarrow(__velarValue, __velarValidationIsInstance(__velarValue, NativeSqliteError), "NativeSqliteError", "error", 24478))(error).operation, ((__velarValue) => __velarNarrow(__velarValue, __velarValidationIsInstance(__velarValue, NativeSqliteError), "NativeSqliteError", "error", 24495))(error).retryable);
|
|
1681
|
+
}
|
|
1682
|
+
return new SqliteError(error.message);
|
|
1683
|
+
}
|
|
1684
|
+
function sqliteLiteral(value) {
|
|
1685
|
+
if ((value ?? null) === null) {
|
|
1686
|
+
return trustedSql("NULL");
|
|
1687
|
+
}
|
|
1688
|
+
if (typeof (value ?? null) === "boolean") {
|
|
1689
|
+
return trustedSql(((__velarValue) => __velarNarrow(__velarValue, typeof __velarValue === "boolean", "bool", "value", 24937))(value) ? "1" : "0");
|
|
1690
|
+
}
|
|
1691
|
+
if (typeof (value ?? null) === "string") {
|
|
1692
|
+
return trustedSql("'" + __velarStringReplaceAll(((__velarValue) => __velarNarrow(__velarValue, typeof __velarValue === "string", "string", "value", 25012))(value), "'", "''") + "'");
|
|
1693
|
+
}
|
|
1694
|
+
if (typeof (value ?? null) === "number") {
|
|
1695
|
+
if (!__velarNumberIsFinite(((__velarValue) => __velarNarrow(__velarValue, typeof __velarValue === "number", "number", "value", 25086))(value))) {
|
|
1696
|
+
throw new __VelarAssertionError("SQLite numeric literals must be finite");
|
|
1697
|
+
}
|
|
1698
|
+
if (!(!__velarNumberIsInteger(((__velarValue) => __velarNarrow(__velarValue, typeof __velarValue === "number", "number", "value", 25168))(value)) || ((__velarValue) => __velarNarrow(__velarValue, typeof __velarValue === "number", "number", "value", 25190))(value) >= -9007199254740991 && ((__velarValue) => __velarNarrow(__velarValue, typeof __velarValue === "number", "number", "value", 25221))(value) <= 9007199254740991)) {
|
|
1699
|
+
throw new __VelarAssertionError("SQLite integer literals must be safe integers");
|
|
1700
|
+
}
|
|
1701
|
+
return trustedSql(String(((__velarValue) => __velarNarrow(__velarValue, typeof __velarValue === "number", "number", "value", 25331))(value)));
|
|
1702
|
+
}
|
|
1703
|
+
throw new Error("SQLite literals support only null, bool, string, and finite number");
|
|
1704
|
+
}
|
|
1705
|
+
function sqliteIdentifier(value) {
|
|
1706
|
+
if (!(!__velarStringIsBlank(value) && __velarStringSize(value) <= 255 && !__velarStringHas(value, fromCodePoint(0)))) {
|
|
1707
|
+
throw new __VelarAssertionError("SQLite identifiers must be non-blank text with no NUL and no longer than 255 characters");
|
|
1708
|
+
}
|
|
1709
|
+
return trustedSql('"' + __velarStringReplaceAll(value, '"', '""') + '"');
|
|
1710
|
+
}
|
|
1711
|
+
var SqliteTransaction = class {
|
|
1712
|
+
#native;
|
|
1713
|
+
constructor(native) {
|
|
1714
|
+
this.#native = native;
|
|
1715
|
+
const self = this;
|
|
1716
|
+
}
|
|
1717
|
+
async execute(statement) {
|
|
1718
|
+
const self = this;
|
|
1719
|
+
const data = statement.data();
|
|
1720
|
+
try {
|
|
1721
|
+
return await __velarNormalizePromiseValue(__velarReadPrivateField(self.#native, "native").execute(data.fragments, data.parameters));
|
|
1722
|
+
} catch (error) {
|
|
1723
|
+
error = __velarNormalizeError(error);
|
|
1724
|
+
if (error instanceof NativeSqliteError) {
|
|
1725
|
+
throw sqliteFailure(((__velarValue) => __velarNarrow(__velarValue, __velarValidationIsInstance(__velarValue, NativeSqliteError), "NativeSqliteError", "error", 26288))(error));
|
|
1726
|
+
}
|
|
1727
|
+
throw new SqliteError(__velarReadInstanceField(error, "message"));
|
|
1728
|
+
}
|
|
1729
|
+
}
|
|
1730
|
+
executor() {
|
|
1731
|
+
const self = this;
|
|
1732
|
+
async function executeStatement(statement) {
|
|
1733
|
+
return await __velarNormalizePromiseValue(self.execute(statement));
|
|
1734
|
+
}
|
|
1735
|
+
async function oneRow(statement) {
|
|
1736
|
+
const data = statement.data();
|
|
1737
|
+
try {
|
|
1738
|
+
return __velarAsyncResolvedValue(await __velarNormalizePromiseValue(__velarReadPrivateField(self.#native, "native").one(data.fragments, data.parameters)));
|
|
1739
|
+
} catch (error) {
|
|
1740
|
+
error = __velarNormalizeError(error);
|
|
1741
|
+
if (error instanceof NativeSqliteError) {
|
|
1742
|
+
throw sqliteFailure(((__velarValue) => __velarNarrow(__velarValue, __velarValidationIsInstance(__velarValue, NativeSqliteError), "NativeSqliteError", "error", 26909))(error));
|
|
1743
|
+
}
|
|
1744
|
+
throw new SqliteError(__velarReadInstanceField(error, "message"));
|
|
1745
|
+
}
|
|
1746
|
+
}
|
|
1747
|
+
async function allRows(statement) {
|
|
1748
|
+
const data = statement.data();
|
|
1749
|
+
try {
|
|
1750
|
+
return __velarAsyncResolvedValue(await __velarNormalizePromiseValue(__velarReadPrivateField(self.#native, "native").all(data.fragments, data.parameters)));
|
|
1751
|
+
} catch (error) {
|
|
1752
|
+
error = __velarNormalizeError(error);
|
|
1753
|
+
if (error instanceof NativeSqliteError) {
|
|
1754
|
+
throw sqliteFailure(((__velarValue) => __velarNarrow(__velarValue, __velarValidationIsInstance(__velarValue, NativeSqliteError), "NativeSqliteError", "error", 27289))(error));
|
|
1755
|
+
}
|
|
1756
|
+
throw new SqliteError(__velarReadInstanceField(error, "message"));
|
|
1757
|
+
}
|
|
1758
|
+
}
|
|
1759
|
+
return { execute: executeStatement, one: oneRow, all: allRows };
|
|
1760
|
+
}
|
|
1761
|
+
async one(statement, RowType) {
|
|
1762
|
+
const self = this;
|
|
1763
|
+
const data = statement.data();
|
|
1764
|
+
try {
|
|
1765
|
+
const row = await __velarNormalizePromiseValue(__velarReadPrivateField(self.#native, "native").one(data.fragments, data.parameters));
|
|
1766
|
+
if ((row ?? null) === null) {
|
|
1767
|
+
return null;
|
|
1768
|
+
}
|
|
1769
|
+
return __velarAsyncResolvedValue(RowType.parse(row ?? null));
|
|
1770
|
+
} catch (error) {
|
|
1771
|
+
error = __velarNormalizeError(error);
|
|
1772
|
+
if (error instanceof NativeSqliteError) {
|
|
1773
|
+
throw sqliteFailure(((__velarValue) => __velarNarrow(__velarValue, __velarValidationIsInstance(__velarValue, NativeSqliteError), "NativeSqliteError", "error", 27817))(error));
|
|
1774
|
+
}
|
|
1775
|
+
throw new SqliteError(__velarReadInstanceField(error, "message"));
|
|
1776
|
+
}
|
|
1777
|
+
}
|
|
1778
|
+
async all(statement, RowType) {
|
|
1779
|
+
const self = this;
|
|
1780
|
+
const data = statement.data();
|
|
1781
|
+
try {
|
|
1782
|
+
const rows = await __velarNormalizePromiseValue(__velarReadPrivateField(self.#native, "native").all(data.fragments, data.parameters));
|
|
1783
|
+
return __velarAsyncResolvedValue(__velarListMap(rows, (row) => RowType.parse(row ?? null)));
|
|
1784
|
+
} catch (error) {
|
|
1785
|
+
error = __velarNormalizeError(error);
|
|
1786
|
+
if (error instanceof NativeSqliteError) {
|
|
1787
|
+
throw sqliteFailure(((__velarValue) => __velarNarrow(__velarValue, __velarValidationIsInstance(__velarValue, NativeSqliteError), "NativeSqliteError", "error", 28237))(error));
|
|
1788
|
+
}
|
|
1789
|
+
throw new SqliteError(__velarReadInstanceField(error, "message"));
|
|
1790
|
+
}
|
|
1791
|
+
}
|
|
1792
|
+
};
|
|
1793
|
+
var SqliteConnection = class {
|
|
1794
|
+
#native;
|
|
1795
|
+
constructor(native) {
|
|
1796
|
+
this.#native = native;
|
|
1797
|
+
const self = this;
|
|
1798
|
+
}
|
|
1799
|
+
async execute(statement) {
|
|
1800
|
+
const self = this;
|
|
1801
|
+
const data = statement.data();
|
|
1802
|
+
try {
|
|
1803
|
+
return await __velarNormalizePromiseValue(__velarReadPrivateField(self.#native, "native").execute(data.fragments, data.parameters));
|
|
1804
|
+
} catch (error) {
|
|
1805
|
+
error = __velarNormalizeError(error);
|
|
1806
|
+
if (error instanceof NativeSqliteError) {
|
|
1807
|
+
throw sqliteFailure(((__velarValue) => __velarNarrow(__velarValue, __velarValidationIsInstance(__velarValue, NativeSqliteError), "NativeSqliteError", "error", 28690))(error));
|
|
1808
|
+
}
|
|
1809
|
+
throw new SqliteError(__velarReadInstanceField(error, "message"));
|
|
1810
|
+
}
|
|
1811
|
+
}
|
|
1812
|
+
executor() {
|
|
1813
|
+
const self = this;
|
|
1814
|
+
async function executeStatement(statement) {
|
|
1815
|
+
return await __velarNormalizePromiseValue(self.execute(statement));
|
|
1816
|
+
}
|
|
1817
|
+
async function oneRow(statement) {
|
|
1818
|
+
const data = statement.data();
|
|
1819
|
+
try {
|
|
1820
|
+
return __velarAsyncResolvedValue(await __velarNormalizePromiseValue(__velarReadPrivateField(self.#native, "native").one(data.fragments, data.parameters)));
|
|
1821
|
+
} catch (error) {
|
|
1822
|
+
error = __velarNormalizeError(error);
|
|
1823
|
+
if (error instanceof NativeSqliteError) {
|
|
1824
|
+
throw sqliteFailure(((__velarValue) => __velarNarrow(__velarValue, __velarValidationIsInstance(__velarValue, NativeSqliteError), "NativeSqliteError", "error", 29310))(error));
|
|
1825
|
+
}
|
|
1826
|
+
throw new SqliteError(__velarReadInstanceField(error, "message"));
|
|
1827
|
+
}
|
|
1828
|
+
}
|
|
1829
|
+
async function allRows(statement) {
|
|
1830
|
+
const data = statement.data();
|
|
1831
|
+
try {
|
|
1832
|
+
return __velarAsyncResolvedValue(await __velarNormalizePromiseValue(__velarReadPrivateField(self.#native, "native").all(data.fragments, data.parameters)));
|
|
1833
|
+
} catch (error) {
|
|
1834
|
+
error = __velarNormalizeError(error);
|
|
1835
|
+
if (error instanceof NativeSqliteError) {
|
|
1836
|
+
throw sqliteFailure(((__velarValue) => __velarNarrow(__velarValue, __velarValidationIsInstance(__velarValue, NativeSqliteError), "NativeSqliteError", "error", 29690))(error));
|
|
1837
|
+
}
|
|
1838
|
+
throw new SqliteError(__velarReadInstanceField(error, "message"));
|
|
1839
|
+
}
|
|
1840
|
+
}
|
|
1841
|
+
return { execute: executeStatement, one: oneRow, all: allRows };
|
|
1842
|
+
}
|
|
1843
|
+
async one(statement, RowType) {
|
|
1844
|
+
const self = this;
|
|
1845
|
+
const data = statement.data();
|
|
1846
|
+
try {
|
|
1847
|
+
const row = await __velarNormalizePromiseValue(__velarReadPrivateField(self.#native, "native").one(data.fragments, data.parameters));
|
|
1848
|
+
if ((row ?? null) === null) {
|
|
1849
|
+
return null;
|
|
1850
|
+
}
|
|
1851
|
+
return __velarAsyncResolvedValue(RowType.parse(row ?? null));
|
|
1852
|
+
} catch (error) {
|
|
1853
|
+
error = __velarNormalizeError(error);
|
|
1854
|
+
if (error instanceof NativeSqliteError) {
|
|
1855
|
+
throw sqliteFailure(((__velarValue) => __velarNarrow(__velarValue, __velarValidationIsInstance(__velarValue, NativeSqliteError), "NativeSqliteError", "error", 30218))(error));
|
|
1856
|
+
}
|
|
1857
|
+
throw new SqliteError(__velarReadInstanceField(error, "message"));
|
|
1858
|
+
}
|
|
1859
|
+
}
|
|
1860
|
+
async all(statement, RowType) {
|
|
1861
|
+
const self = this;
|
|
1862
|
+
const data = statement.data();
|
|
1863
|
+
try {
|
|
1864
|
+
const rows = await __velarNormalizePromiseValue(__velarReadPrivateField(self.#native, "native").all(data.fragments, data.parameters));
|
|
1865
|
+
return __velarAsyncResolvedValue(__velarListMap(rows, (row) => RowType.parse(row ?? null)));
|
|
1866
|
+
} catch (error) {
|
|
1867
|
+
error = __velarNormalizeError(error);
|
|
1868
|
+
if (error instanceof NativeSqliteError) {
|
|
1869
|
+
throw sqliteFailure(((__velarValue) => __velarNarrow(__velarValue, __velarValidationIsInstance(__velarValue, NativeSqliteError), "NativeSqliteError", "error", 30638))(error));
|
|
1870
|
+
}
|
|
1871
|
+
throw new SqliteError(__velarReadInstanceField(error, "message"));
|
|
1872
|
+
}
|
|
1873
|
+
}
|
|
1874
|
+
async transaction(operation) {
|
|
1875
|
+
const self = this;
|
|
1876
|
+
const results = __velarAdoptList([]);
|
|
1877
|
+
async function run(native) {
|
|
1878
|
+
__velarListAppend(results, await __velarNormalizePromiseValue(operation(new SqliteTransaction(native))));
|
|
1879
|
+
return null;
|
|
1880
|
+
}
|
|
1881
|
+
try {
|
|
1882
|
+
await __velarNormalizePromiseValue(__velarReadPrivateField(self.#native, "native").transaction(run));
|
|
1883
|
+
if (!(__velarListSize(results) === 1)) {
|
|
1884
|
+
throw new __VelarAssertionError("SQLite transaction did not return exactly one result");
|
|
1885
|
+
}
|
|
1886
|
+
return __velarAsyncResolvedValue(__velarListIndexGet(results, 0));
|
|
1887
|
+
} catch (error) {
|
|
1888
|
+
error = __velarNormalizeError(error);
|
|
1889
|
+
if (error instanceof NativeSqliteError) {
|
|
1890
|
+
throw sqliteFailure(((__velarValue) => __velarNarrow(__velarValue, __velarValidationIsInstance(__velarValue, NativeSqliteError), "NativeSqliteError", "error", 31225))(error));
|
|
1891
|
+
}
|
|
1892
|
+
throw error;
|
|
1893
|
+
}
|
|
1894
|
+
}
|
|
1895
|
+
async close() {
|
|
1896
|
+
const self = this;
|
|
1897
|
+
try {
|
|
1898
|
+
await __velarNormalizePromiseValue(__velarReadPrivateField(self.#native, "native").close());
|
|
1899
|
+
} catch (error) {
|
|
1900
|
+
error = __velarNormalizeError(error);
|
|
1901
|
+
if (error instanceof NativeSqliteError) {
|
|
1902
|
+
throw sqliteFailure(((__velarValue) => __velarNarrow(__velarValue, __velarValidationIsInstance(__velarValue, NativeSqliteError), "NativeSqliteError", "error", 31431))(error));
|
|
1903
|
+
}
|
|
1904
|
+
throw new SqliteError(__velarReadInstanceField(error, "message"));
|
|
1905
|
+
}
|
|
1906
|
+
return null;
|
|
1907
|
+
}
|
|
1908
|
+
async ["__velar:dispose"]() {
|
|
1909
|
+
const self = this;
|
|
1910
|
+
await __velarNormalizePromiseValue(self.close());
|
|
1911
|
+
return null;
|
|
1912
|
+
}
|
|
1913
|
+
};
|
|
1914
|
+
async function openSqlite(path, options = {}) {
|
|
1915
|
+
try {
|
|
1916
|
+
return __velarAsyncResolvedValue(new SqliteConnection(await __velarNormalizePromiseValue(openNativeSqlite(__velarHostRaw(path), __velarHostRaw(options)))));
|
|
1917
|
+
} catch (error) {
|
|
1918
|
+
error = __velarNormalizeError(error);
|
|
1919
|
+
if (error instanceof NativeSqliteError) {
|
|
1920
|
+
throw sqliteFailure(((__velarValue) => __velarNarrow(__velarValue, __velarValidationIsInstance(__velarValue, NativeSqliteError), "NativeSqliteError", "error", 31786))(error));
|
|
1921
|
+
}
|
|
1922
|
+
throw new SqliteError(__velarReadInstanceField(error, "message"));
|
|
1923
|
+
}
|
|
1924
|
+
}
|
|
1925
|
+
export {
|
|
1926
|
+
SqliteBackpressureError,
|
|
1927
|
+
SqliteConcurrencyError,
|
|
1928
|
+
SqliteConnection,
|
|
1929
|
+
SqliteError,
|
|
1930
|
+
SqliteJournalMode,
|
|
1931
|
+
SqliteOptions,
|
|
1932
|
+
SqliteTransaction,
|
|
1933
|
+
openSqlite,
|
|
1934
|
+
sqliteIdentifier,
|
|
1935
|
+
sqliteLiteral
|
|
1936
|
+
};
|