@eidos.space/eidos-file 0.1.0 → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (43) hide show
  1. package/DEVELOPER_PLATFORM.md +49 -53
  2. package/README.md +66 -99
  3. package/dist/adapter-contract-B3p-48Yb.d.mts +1149 -0
  4. package/dist/adapter-contract-B3p-48Yb.d.mts.map +1 -0
  5. package/dist/better-sqlite3.d.mts +64 -3
  6. package/dist/better-sqlite3.d.mts.map +1 -1
  7. package/dist/better-sqlite3.mjs +387 -14
  8. package/dist/better-sqlite3.mjs.map +1 -1
  9. package/dist/browser.d.mts +4 -3
  10. package/dist/browser.d.mts.map +1 -1
  11. package/dist/browser.mjs +30 -11
  12. package/dist/browser.mjs.map +1 -1
  13. package/dist/csv-WEud-i_H.mjs +376 -0
  14. package/dist/csv-WEud-i_H.mjs.map +1 -0
  15. package/dist/csv.d.mts +1 -1
  16. package/dist/csv.d.mts.map +1 -1
  17. package/dist/csv.mjs +1 -248
  18. package/dist/index.d.mts +312 -18
  19. package/dist/index.d.mts.map +1 -1
  20. package/dist/index.mjs +3237 -4
  21. package/dist/index.mjs.map +1 -0
  22. package/dist/runtime-CMdfE7Gx.mjs +5476 -0
  23. package/dist/runtime-CMdfE7Gx.mjs.map +1 -0
  24. package/dist/runtime-DCo5E0Kr.d.mts +668 -0
  25. package/dist/runtime-DCo5E0Kr.d.mts.map +1 -0
  26. package/dist/select-options-DihMTuoa.mjs +518 -0
  27. package/dist/select-options-DihMTuoa.mjs.map +1 -0
  28. package/dist/sqlite-wasm-B86yaLG6.mjs +2000 -0
  29. package/dist/sqlite-wasm-B86yaLG6.mjs.map +1 -0
  30. package/dist/temporal-CVzLU63l.d.mts +517 -0
  31. package/dist/temporal-CVzLU63l.d.mts.map +1 -0
  32. package/package.json +2 -3
  33. package/dist/csv.mjs.map +0 -1
  34. package/dist/host-CqP1MeMK.d.mts +0 -213
  35. package/dist/host-CqP1MeMK.d.mts.map +0 -1
  36. package/dist/host-D5kZAhga.mjs +0 -478
  37. package/dist/host-D5kZAhga.mjs.map +0 -1
  38. package/dist/relation-values-B0JhHBjZ.mjs +0 -232
  39. package/dist/relation-values-B0JhHBjZ.mjs.map +0 -1
  40. package/dist/runtime-C3bstvB8.d.mts +0 -465
  41. package/dist/runtime-C3bstvB8.d.mts.map +0 -1
  42. package/dist/runtime-CWC5y95G.mjs +0 -2907
  43. package/dist/runtime-CWC5y95G.mjs.map +0 -1
@@ -0,0 +1,518 @@
1
+ //#region src/errors.ts
2
+ var EidosFileError = class extends Error {
3
+ constructor(code, message) {
4
+ super(message);
5
+ this.code = code;
6
+ this.name = "EidosFileError";
7
+ }
8
+ };
9
+ //#endregion
10
+ //#region src/canonical-json.ts
11
+ function assertUnicodeScalarString(value) {
12
+ for (let index = 0; index < value.length; index += 1) {
13
+ const code = value.charCodeAt(index);
14
+ if (code >= 55296 && code <= 56319) {
15
+ const next = value.charCodeAt(index + 1);
16
+ if (!(next >= 56320 && next <= 57343)) throw new EidosFileError("invalid-value", "I-JSON strings cannot contain unpaired surrogates");
17
+ index += 1;
18
+ } else if (code >= 56320 && code <= 57343) throw new EidosFileError("invalid-value", "I-JSON strings cannot contain unpaired surrogates");
19
+ }
20
+ }
21
+ function assertNoDuplicateJsonKeys(text) {
22
+ let index = 0;
23
+ const whitespace = () => {
24
+ while (/\s/u.test(text[index] ?? "")) index += 1;
25
+ };
26
+ const string = () => {
27
+ const start = index++;
28
+ while (index < text.length) if (text[index] === "\\") index += 2;
29
+ else if (text[index] === "\"") {
30
+ index += 1;
31
+ return JSON.parse(text.slice(start, index));
32
+ } else index += 1;
33
+ throw new EidosFileError("invalid-value", "Value is not valid JSON");
34
+ };
35
+ const value = () => {
36
+ whitespace();
37
+ if (text[index] === "\"") {
38
+ string();
39
+ return;
40
+ }
41
+ if (text[index] === "[") {
42
+ index += 1;
43
+ whitespace();
44
+ if (text[index] === "]") {
45
+ index += 1;
46
+ return;
47
+ }
48
+ while (index < text.length) {
49
+ value();
50
+ whitespace();
51
+ if (text[index] === "]") {
52
+ index += 1;
53
+ return;
54
+ }
55
+ if (text[index++] !== ",") break;
56
+ }
57
+ throw new EidosFileError("invalid-value", "Value is not valid JSON");
58
+ }
59
+ if (text[index] === "{") {
60
+ index += 1;
61
+ const keys = /* @__PURE__ */ new Set();
62
+ whitespace();
63
+ if (text[index] === "}") {
64
+ index += 1;
65
+ return;
66
+ }
67
+ while (index < text.length) {
68
+ whitespace();
69
+ if (text[index] !== "\"") break;
70
+ const key = string();
71
+ if (keys.has(key)) throw new EidosFileError("invalid-value", `Duplicate I-JSON object key: ${key}`);
72
+ keys.add(key);
73
+ whitespace();
74
+ if (text[index++] !== ":") break;
75
+ value();
76
+ whitespace();
77
+ if (text[index] === "}") {
78
+ index += 1;
79
+ return;
80
+ }
81
+ if (text[index++] !== ",") break;
82
+ }
83
+ throw new EidosFileError("invalid-value", "Value is not valid JSON");
84
+ }
85
+ while (index < text.length && !/[\s,\]}]/u.test(text[index])) index += 1;
86
+ };
87
+ value();
88
+ whitespace();
89
+ if (index !== text.length) throw new EidosFileError("invalid-value", "Value is not valid JSON");
90
+ }
91
+ function normalize(value, stack) {
92
+ if (value === null || typeof value === "boolean") return value;
93
+ if (typeof value === "string") {
94
+ assertUnicodeScalarString(value);
95
+ return value;
96
+ }
97
+ if (typeof value === "number") {
98
+ if (!Number.isFinite(value)) throw new EidosFileError("invalid-value", "Canonical JSON numbers must be finite binary64 values");
99
+ return Object.is(value, -0) ? 0 : value;
100
+ }
101
+ if (typeof value !== "object" || value === void 0) throw new EidosFileError("invalid-value", "Value is not valid I-JSON");
102
+ if (stack.has(value)) throw new EidosFileError("invalid-value", "Canonical JSON cannot be cyclic");
103
+ stack.add(value);
104
+ try {
105
+ if (Array.isArray(value)) return value.map((entry) => normalize(entry, stack));
106
+ const normalized = {};
107
+ for (const key of Object.keys(value).sort()) {
108
+ assertUnicodeScalarString(key);
109
+ normalized[key] = normalize(value[key], stack);
110
+ }
111
+ return normalized;
112
+ } finally {
113
+ stack.delete(value);
114
+ }
115
+ }
116
+ /** RFC 8785-compatible canonical serialization for the Eidos JSON subset. */
117
+ function canonicalizeEidosFileJson(value) {
118
+ return JSON.stringify(normalize(value, /* @__PURE__ */ new Set()));
119
+ }
120
+ function parseEidosFileJson(text) {
121
+ let value;
122
+ try {
123
+ assertNoDuplicateJsonKeys(text);
124
+ value = JSON.parse(text);
125
+ } catch (error) {
126
+ if (error instanceof EidosFileError) throw error;
127
+ throw new EidosFileError("invalid-value", "Value is not valid JSON");
128
+ }
129
+ return normalize(value, /* @__PURE__ */ new Set());
130
+ }
131
+ function isCanonicalEidosFileJson(text) {
132
+ try {
133
+ return canonicalizeEidosFileJson(parseEidosFileJson(text)) === text;
134
+ } catch {
135
+ return false;
136
+ }
137
+ }
138
+ //#endregion
139
+ //#region src/identifiers.ts
140
+ const UUID_V7 = /^[0-9a-f]{8}-[0-9a-f]{4}-7[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/;
141
+ function sqliteNoCase(value) {
142
+ return value.replace(/[A-Z]/g, (character) => character.toLowerCase());
143
+ }
144
+ function utf8Length(value) {
145
+ return new TextEncoder().encode(value).byteLength;
146
+ }
147
+ function utf8Prefix(value, limit) {
148
+ let result = "";
149
+ let length = 0;
150
+ for (const scalar of value) {
151
+ const scalarLength = utf8Length(scalar);
152
+ if (length + scalarLength > limit) break;
153
+ result += scalar;
154
+ length += scalarLength;
155
+ }
156
+ return result;
157
+ }
158
+ function isEidosFileUuid(value) {
159
+ return typeof value === "string" && UUID_V7.test(value);
160
+ }
161
+ function assertEidosFileUuid(value, label = "ID") {
162
+ if (!isEidosFileUuid(value)) throw new EidosFileError("invalid-value", `${label} must be a lowercase hyphenated UUIDv7`);
163
+ return value;
164
+ }
165
+ function bytesToUuid(value) {
166
+ const hex = Array.from(value, (byte) => byte.toString(16).padStart(2, "0")).join("");
167
+ return assertEidosFileUuid(`${hex.slice(0, 8)}-${hex.slice(8, 12)}-${hex.slice(12, 16)}-${hex.slice(16, 20)}-${hex.slice(20)}`);
168
+ }
169
+ let lastUuidV7Timestamp = -1;
170
+ let lastUuidV7Bytes;
171
+ function incrementUuidV7Random(bytes) {
172
+ for (let index = 15; index >= 9; index -= 1) {
173
+ if (bytes[index] < 255) {
174
+ bytes[index] = bytes[index] + 1;
175
+ return true;
176
+ }
177
+ bytes[index] = 0;
178
+ }
179
+ const variantRandom = bytes[8] & 63;
180
+ if (variantRandom < 63) {
181
+ bytes[8] = 128 | variantRandom + 1;
182
+ return true;
183
+ }
184
+ bytes[8] = 128;
185
+ if (bytes[7] < 255) {
186
+ bytes[7] = bytes[7] + 1;
187
+ return true;
188
+ }
189
+ bytes[7] = 0;
190
+ const versionRandom = bytes[6] & 15;
191
+ if (versionRandom < 15) {
192
+ bytes[6] = 112 | versionRandom + 1;
193
+ return true;
194
+ }
195
+ return false;
196
+ }
197
+ /** Runtime-epoch UUIDv7 allocator with injected time and secure entropy. */
198
+ var EidosUuidV7Generator = class {
199
+ lastTimestamp;
200
+ lastBytes;
201
+ constructor(nowInstant, randomBytes) {
202
+ this.nowInstant = nowInstant;
203
+ this.randomBytes = randomBytes;
204
+ }
205
+ next() {
206
+ const wallInstant = this.nowInstant();
207
+ const wallTimestamp = Date.parse(wallInstant);
208
+ if (!Number.isSafeInteger(wallTimestamp) || wallTimestamp < 0 || wallTimestamp > 0xffffffffffff) throw new EidosFileError("resource-limit", "Wall clock cannot be encoded as a UUIDv7 timestamp");
209
+ const timestamp = this.lastTimestamp === void 0 ? wallTimestamp : Math.max(wallTimestamp, this.lastTimestamp);
210
+ let bytes;
211
+ if (this.lastBytes && timestamp === this.lastTimestamp) {
212
+ bytes = this.lastBytes.slice();
213
+ if (!incrementUuidV7Random(bytes)) throw new EidosFileError("resource-limit", "UUIDv7 monotonic payload was exhausted for one millisecond");
214
+ } else {
215
+ const supplied = this.randomBytes(16);
216
+ if (!(supplied instanceof Uint8Array) || supplied.byteLength !== 16) throw new EidosFileError("resource-limit", "EntropyPort must return exactly the requested owned bytes");
217
+ bytes = supplied.slice();
218
+ }
219
+ let remaining = timestamp;
220
+ for (let index = 5; index >= 0; index -= 1) {
221
+ bytes[index] = remaining % 256;
222
+ remaining = Math.floor(remaining / 256);
223
+ }
224
+ bytes[6] = 112 | bytes[6] & 15;
225
+ bytes[8] = 128 | bytes[8] & 63;
226
+ this.lastTimestamp = timestamp;
227
+ this.lastBytes = bytes.slice();
228
+ return bytesToUuid(bytes);
229
+ }
230
+ };
231
+ /** Creates an RFC 9562 UUIDv7 using the current Unix millisecond timestamp. */
232
+ function createEidosFileUuid(timestamp = Date.now()) {
233
+ if (!Number.isSafeInteger(timestamp) || timestamp < 0 || timestamp > 0xffffffffffff) throw new EidosFileError("invalid-value", "UUIDv7 timestamp is out of range");
234
+ const bytes = timestamp === lastUuidV7Timestamp && lastUuidV7Bytes ? new Uint8Array(lastUuidV7Bytes) : globalThis.crypto.getRandomValues(new Uint8Array(16));
235
+ if (timestamp === lastUuidV7Timestamp && lastUuidV7Bytes && !incrementUuidV7Random(bytes)) throw new EidosFileError("resource-limit", "UUIDv7 monotonic random space was exhausted for one millisecond");
236
+ let time = timestamp;
237
+ for (let index = 5; index >= 0; index -= 1) {
238
+ bytes[index] = time % 256;
239
+ time = Math.floor(time / 256);
240
+ }
241
+ bytes[6] = 112 | bytes[6] & 15;
242
+ bytes[8] = 128 | bytes[8] & 63;
243
+ lastUuidV7Timestamp = timestamp;
244
+ lastUuidV7Bytes = new Uint8Array(bytes);
245
+ return bytesToUuid(bytes);
246
+ }
247
+ /** @deprecated Use UUID strings as stable public identifiers. */
248
+ function createEidosFileIdentifier() {
249
+ return createEidosFileUuid();
250
+ }
251
+ /** UUIDs are the only valid Table IDs in Eidos File 1.0. */
252
+ function assertEidosFileTableId(tableId) {
253
+ return assertEidosFileUuid(tableId, "Table ID");
254
+ }
255
+ function assertEidosFileDisplayName(name, label) {
256
+ if (name.length === 0 || name.includes("\0") || utf8Length(name) > 1024 || /[\uD800-\uDFFF]/u.test(Array.from(name).filter((scalar) => scalar.length === 1).join(""))) throw new EidosFileError("invalid-identifier", `${label} must be 1..1024 UTF-8 octets, contain Unicode scalar values, and exclude U+0000`);
257
+ return name;
258
+ }
259
+ function isReservedPhysicalName(kind, displayName) {
260
+ const folded = sqliteNoCase(displayName);
261
+ if (kind === "field") return [
262
+ "_id",
263
+ "_created_at",
264
+ "_updated_at"
265
+ ].includes(folded);
266
+ return [
267
+ "sqlite_",
268
+ "eidos__",
269
+ "x__"
270
+ ].some((prefix) => folded.startsWith(prefix));
271
+ }
272
+ /**
273
+ * Applies the display-first physical naming rule from Eidos File 1.0 §6.
274
+ * `existingNames` is compared using SQLite's ASCII-only NOCASE behavior.
275
+ */
276
+ function eidosFilePhysicalName(kind, displayName, stableId, existingNames = []) {
277
+ assertEidosFileDisplayName(displayName, kind === "table" ? "Table name" : "Field name");
278
+ const idHex = assertEidosFileUuid(stableId).replace(/-/g, "");
279
+ const existing = new Set(Array.from(existingNames, sqliteNoCase));
280
+ const available = (candidate) => !existing.has(sqliteNoCase(candidate));
281
+ if (kind === "table" && isReservedPhysicalName(kind, displayName)) {
282
+ for (const length of [
283
+ 8,
284
+ 12,
285
+ 32
286
+ ]) {
287
+ const prefix = `t__${idHex.slice(0, length)}__`;
288
+ const candidate = `${prefix}${utf8Prefix(displayName, 1024 - utf8Length(prefix))}`;
289
+ if (available(candidate)) return candidate;
290
+ }
291
+ throw new EidosFileError("constraint-conflict", `Unable to allocate a physical ${kind} name for “${displayName}”`);
292
+ }
293
+ if (!isReservedPhysicalName(kind, displayName) && available(displayName)) return displayName;
294
+ for (const length of [
295
+ 8,
296
+ 12,
297
+ 32
298
+ ]) {
299
+ const suffix = `__${idHex.slice(0, length)}`;
300
+ const candidate = `${utf8Prefix(displayName, 1024 - utf8Length(suffix))}${suffix}`;
301
+ if (available(candidate)) return candidate;
302
+ }
303
+ throw new EidosFileError("constraint-conflict", `Unable to allocate a physical ${kind} name for “${displayName}”`);
304
+ }
305
+ /** @deprecated Physical table names are display-first, not `tb_<id>`. */
306
+ function rawTableNameForId(tableId) {
307
+ return eidosFilePhysicalName("table", tableId, assertEidosFileTableId(tableId));
308
+ }
309
+ /** @deprecated Field display names are not restricted to bare SQL tokens. */
310
+ function assertEidosFileColumnName(columnName) {
311
+ return assertEidosFileDisplayName(columnName, "Field name");
312
+ }
313
+ function quoteIdentifier(identifier) {
314
+ if (identifier.includes("\0")) throw new EidosFileError("invalid-identifier", "SQLite identifiers must not contain U+0000");
315
+ return `"${identifier.replace(/"/g, "\"\"")}"`;
316
+ }
317
+ //#endregion
318
+ //#region src/file-values.ts
319
+ const MAX_FILE_VALUES = 1e4;
320
+ const NON_NEGATIVE_INT64 = /^(?:0|[1-9][0-9]*)$/u;
321
+ const MEDIA_TYPE = /^[!#$%&'*+.^_`|~0-9A-Za-z-]+\/[!#$%&'*+.^_`|~0-9A-Za-z-]+$/u;
322
+ const MAX_SIGNED_INT64 = 9223372036854775807n;
323
+ function isSafeEidosFileUri(uri) {
324
+ if (!uri || uri.includes("\0") || uri.includes("\\")) return false;
325
+ if (uri.startsWith("https://")) try {
326
+ return new URL(uri).protocol === "https:";
327
+ } catch {
328
+ return false;
329
+ }
330
+ if (/^[a-zA-Z][a-zA-Z0-9+.-]*:/u.test(uri) || uri.startsWith("/")) return false;
331
+ try {
332
+ const decoded = decodeURIComponent(uri);
333
+ return !decoded.startsWith("/") && !decoded.includes("\\") && !decoded.split(/[/?#]/u).includes("..");
334
+ } catch {
335
+ return false;
336
+ }
337
+ }
338
+ function assertEidosFileValues(value) {
339
+ if (!Array.isArray(value)) throw new EidosFileError("invalid-value", "File value must be a JSON array");
340
+ if (value.length > MAX_FILE_VALUES) throw new EidosFileError("resource-limit", "File value contains too many entries");
341
+ const ids = /* @__PURE__ */ new Set();
342
+ return value.map((entry) => {
343
+ if (!entry || Array.isArray(entry) || typeof entry !== "object") throw new EidosFileError("invalid-value", "File value contains an invalid entry");
344
+ const candidate = entry;
345
+ if (typeof candidate.id !== "string" || !isEidosFileUuid(candidate.id) || ids.has(candidate.id) || typeof candidate.uri !== "string" || !isSafeEidosFileUri(candidate.uri) || typeof candidate.name !== "string" || candidate.name.length === 0 || candidate.name.includes("\0") || typeof candidate.mediaType !== "string" || !MEDIA_TYPE.test(candidate.mediaType) || typeof candidate.size !== "string" || !NON_NEGATIVE_INT64.test(candidate.size) || BigInt(candidate.size) > MAX_SIGNED_INT64) throw new EidosFileError("invalid-value", "File value contains an invalid entry");
346
+ ids.add(candidate.id);
347
+ return {
348
+ ...candidate,
349
+ id: candidate.id,
350
+ uri: candidate.uri,
351
+ name: candidate.name,
352
+ mediaType: candidate.mediaType,
353
+ size: candidate.size
354
+ };
355
+ });
356
+ }
357
+ function decodeEidosFileValues(value) {
358
+ if (value === void 0 || value === null || value === "") return [];
359
+ if (typeof value !== "string") throw new EidosFileError("invalid-value", "File value must be canonical JSON");
360
+ return assertEidosFileValues(parseEidosFileJson(value));
361
+ }
362
+ function encodeEidosFileValues(values) {
363
+ return canonicalizeEidosFileJson(assertEidosFileValues([...values]));
364
+ }
365
+ function normalizeEidosFileAttachmentPath(value) {
366
+ const trimmed = value.trim();
367
+ if (!trimmed || trimmed.includes("\0")) return null;
368
+ if (trimmed.startsWith("https://")) return isSafeEidosFileUri(trimmed) ? trimmed : null;
369
+ if (/^[a-z][a-z\d+.-]*:/iu.test(trimmed) || trimmed.startsWith("/")) return null;
370
+ const parts = trimmed.replace(/\\/g, "/").split("/");
371
+ const normalized = [];
372
+ for (const part of parts) {
373
+ if (!part || part === ".") continue;
374
+ if (part === "..") {
375
+ if (normalized.length === 0) return null;
376
+ normalized.pop();
377
+ continue;
378
+ }
379
+ normalized.push(part);
380
+ }
381
+ const uri = normalized.join("/");
382
+ return isSafeEidosFileUri(uri) ? uri : null;
383
+ }
384
+ function decodeEidosFileAttachmentPaths(value) {
385
+ return decodeEidosFileValues(value).map((file) => file.uri);
386
+ }
387
+ /**
388
+ * Compatibility helper for path-oriented host pickers. Existing File IDs are
389
+ * retained by URI; new attachments receive UUIDv7 identities.
390
+ */
391
+ function encodeEidosFileAttachmentPaths(paths, previousValue) {
392
+ const previous = new Map(decodeEidosFileValues(previousValue).map((file) => [file.uri, file]));
393
+ const seen = /* @__PURE__ */ new Set();
394
+ const values = paths.flatMap((path) => {
395
+ const uri = normalizeEidosFileAttachmentPath(path);
396
+ if (!uri || seen.has(uri)) return [];
397
+ seen.add(uri);
398
+ const existing = previous.get(uri);
399
+ if (existing) return [existing];
400
+ const pathName = uri.split(/[/?#]/u).at(-1);
401
+ return [{
402
+ id: createEidosFileUuid(),
403
+ uri,
404
+ name: pathName || "attachment",
405
+ mediaType: "application/octet-stream",
406
+ size: "0"
407
+ }];
408
+ });
409
+ return values.length > 0 ? encodeEidosFileValues(values) : null;
410
+ }
411
+ //#endregion
412
+ //#region src/temporal.ts
413
+ const CANONICAL_DATE = /^\d{4}-\d{2}-\d{2}$/;
414
+ const CANONICAL_INSTANT = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{3}Z$/;
415
+ const RFC3339_INSTANT = /^(\d{4}-\d{2}-\d{2})[Tt](\d{2}):(\d{2}):(\d{2})(?:\.(\d+))?([Zz]|([+-])(\d{2}):(\d{2}))$/;
416
+ function validCalendarDate(value) {
417
+ if (!CANONICAL_DATE.test(value) || value.startsWith("0000-")) return false;
418
+ const parsed = /* @__PURE__ */ new Date(`${value}T00:00:00.000Z`);
419
+ return !Number.isNaN(parsed.getTime()) && parsed.toISOString().slice(0, 10) === value;
420
+ }
421
+ /** Returns whether a value is the canonical Eidos File calendar date. */
422
+ function isCanonicalEidosFileDate(value) {
423
+ return typeof value === "string" && validCalendarDate(value);
424
+ }
425
+ /** Returns whether a value is the canonical 24-octet Eidos File instant. */
426
+ function isCanonicalEidosFileInstant(value) {
427
+ if (typeof value !== "string" || !CANONICAL_INSTANT.test(value)) return false;
428
+ const match = RFC3339_INSTANT.exec(value);
429
+ if (!match || !validCalendarDate(match[1])) return false;
430
+ const hour = Number(match[2]);
431
+ const minute = Number(match[3]);
432
+ const second = Number(match[4]);
433
+ if (hour > 23 || minute > 59 || second > 59) return false;
434
+ const parsed = new Date(value);
435
+ return !Number.isNaN(parsed.getTime()) && parsed.toISOString() === value;
436
+ }
437
+ /** Validates an exact `YYYY-MM-DD` API/storage value. */
438
+ function normalizeEidosFileDate(value, label = "date") {
439
+ if (!isCanonicalEidosFileDate(value)) throw new EidosFileError("invalid-value", `${label} must use canonical YYYY-MM-DD text`);
440
+ return value;
441
+ }
442
+ /**
443
+ * Normalizes RFC 3339 API input to the canonical UTC millisecond form.
444
+ * Precision beyond milliseconds is rejected instead of silently truncated.
445
+ */
446
+ function normalizeEidosFileInstant(value, label = "instant") {
447
+ const match = RFC3339_INSTANT.exec(value);
448
+ if (!match || !validCalendarDate(match[1])) throw new EidosFileError("invalid-value", `${label} must be an RFC 3339 instant`);
449
+ if ((match[5] ?? "").length > 3) throw new EidosFileError("invalid-value", `${label} has sub-millisecond precision; lossy conversion was not requested`);
450
+ const hour = Number(match[2]);
451
+ const minute = Number(match[3]);
452
+ const second = Number(match[4]);
453
+ const offsetHour = match[8] === void 0 ? 0 : Number(match[8]);
454
+ const offsetMinute = match[9] === void 0 ? 0 : Number(match[9]);
455
+ if (hour > 23 || minute > 59 || second > 59 || offsetHour > 23 || offsetMinute > 59) throw new EidosFileError("invalid-value", `${label} must be an RFC 3339 instant`);
456
+ const timestamp = Date.parse(value);
457
+ if (!Number.isFinite(timestamp)) throw new EidosFileError("invalid-value", `${label} must be an RFC 3339 instant`);
458
+ const canonical = new Date(timestamp).toISOString();
459
+ if (!isCanonicalEidosFileInstant(canonical)) throw new EidosFileError("invalid-value", `${label} must resolve to a UTC year from 0001 through 9999`);
460
+ return canonical;
461
+ }
462
+ /** Returns the current canonical UTC instant. */
463
+ function currentEidosFileInstant(now = /* @__PURE__ */ new Date()) {
464
+ const value = now.toISOString();
465
+ if (!isCanonicalEidosFileInstant(value)) throw new EidosFileError("invalid-value", "Current time is outside the canonical Eidos File instant range");
466
+ return value;
467
+ }
468
+ /** SQLite CHECK body for a nullable canonical date expression. */
469
+ function eidosFileDateSqlCheck(expression) {
470
+ return `${expression} IS NULL OR (
471
+ length(CAST(${expression} AS BLOB)) = 10
472
+ AND ${expression} GLOB '[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9]'
473
+ AND substr(${expression}, 1, 4) <> '0000'
474
+ AND coalesce(strftime('%Y-%m-%d', ${expression}, '+0 days') = ${expression}, 0)
475
+ )`;
476
+ }
477
+ /** SQLite CHECK body for a nullable canonical instant expression. */
478
+ function eidosFileInstantSqlCheck(expression) {
479
+ return `${expression} IS NULL OR (
480
+ length(CAST(${expression} AS BLOB)) = 24
481
+ AND ${expression} GLOB '[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9]T[0-9][0-9]:[0-9][0-9]:[0-9][0-9].[0-9][0-9][0-9]Z'
482
+ AND substr(${expression}, 1, 4) <> '0000'
483
+ AND coalesce(strftime('%Y-%m-%dT%H:%M:%fZ', ${expression}, '+0 seconds') = ${expression}, 0)
484
+ )`;
485
+ }
486
+ //#endregion
487
+ //#region src/select-options.ts
488
+ function parseEidosFileSelectOptions(property) {
489
+ const options = property?.options;
490
+ if (!Array.isArray(options)) return [];
491
+ return options.flatMap((option) => {
492
+ if (typeof option !== "object" || option === null) return [];
493
+ const name = "name" in option && typeof option.name === "string" ? option.name : null;
494
+ if (name === null) return [];
495
+ return [{
496
+ name,
497
+ color: "color" in option && typeof option.color === "string" ? option.color : "default"
498
+ }];
499
+ });
500
+ }
501
+ function assertEidosFileSelectOptions(property) {
502
+ const rawOptions = property?.options;
503
+ if (rawOptions === void 0) return [];
504
+ if (!Array.isArray(rawOptions)) throw new EidosFileError("invalid-schema", "Select Field settings.options must be an array");
505
+ const options = parseEidosFileSelectOptions(property);
506
+ if (options.length !== rawOptions.length) throw new EidosFileError("invalid-schema", "Every Select option requires a string name");
507
+ const names = /* @__PURE__ */ new Set();
508
+ for (const option of options) {
509
+ const name = option.name;
510
+ if (names.has(name)) throw new EidosFileError("constraint-conflict", `Duplicate Select option name: ${name}`);
511
+ names.add(name);
512
+ }
513
+ return options;
514
+ }
515
+ //#endregion
516
+ export { parseEidosFileJson as A, createEidosFileUuid as C, rawTableNameForId as D, quoteIdentifier as E, canonicalizeEidosFileJson as O, createEidosFileIdentifier as S, isEidosFileUuid as T, EidosUuidV7Generator as _, eidosFileInstantSqlCheck as a, assertEidosFileTableId as b, normalizeEidosFileDate as c, decodeEidosFileAttachmentPaths as d, decodeEidosFileValues as f, normalizeEidosFileAttachmentPath as g, isSafeEidosFileUri as h, eidosFileDateSqlCheck as i, EidosFileError as j, isCanonicalEidosFileJson as k, normalizeEidosFileInstant as l, encodeEidosFileValues as m, parseEidosFileSelectOptions as n, isCanonicalEidosFileDate as o, encodeEidosFileAttachmentPaths as p, currentEidosFileInstant as r, isCanonicalEidosFileInstant as s, assertEidosFileSelectOptions as t, assertEidosFileValues as u, assertEidosFileColumnName as v, eidosFilePhysicalName as w, assertEidosFileUuid as x, assertEidosFileDisplayName as y };
517
+
518
+ //# sourceMappingURL=select-options-DihMTuoa.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"select-options-DihMTuoa.mjs","names":[],"sources":["../src/errors.ts","../src/canonical-json.ts","../src/identifiers.ts","../src/file-values.ts","../src/temporal.ts","../src/select-options.ts"],"sourcesContent":["export type EidosFileErrorCode =\n | \"invalid-sqlite\"\n | \"not-eidos-file\"\n | \"unsupported-version\"\n | \"unsupported-feature\"\n | \"invalid-schema\"\n | \"invalid-formula\"\n | \"invalid-value\"\n | \"constraint-conflict\"\n | \"dependency-cycle\"\n | \"stale-revision\"\n | \"file-conflict\"\n | \"permission-denied\"\n | \"query-limit\"\n | \"resource-limit\"\n /** @deprecated Use unsupported-version. */\n | \"unsupported-format\"\n | \"invalid-identifier\"\n | \"invalid-query\"\n | \"invalid-range\"\n | \"invalid-csv\"\n | \"protected-field\"\n | \"protected-view\"\n | \"relation-in-use\"\n | \"formula-in-use\"\n | \"lookup-in-use\"\n | \"table-not-found\"\n | \"row-not-found\"\n | \"field-not-found\"\n | \"view-not-found\"\n | \"file-exists\"\n | \"file-not-found\"\n\nexport class EidosFileError extends Error {\n constructor(\n readonly code: EidosFileErrorCode,\n message: string\n ) {\n super(message)\n this.name = \"EidosFileError\"\n }\n}\n","import { EidosFileError } from \"./errors\"\n\nexport type EidosFileJsonValue =\n | null\n | boolean\n | number\n | string\n | EidosFileJsonValue[]\n | { [key: string]: EidosFileJsonValue }\n\nfunction assertUnicodeScalarString(value: string): void {\n for (let index = 0; index < value.length; index += 1) {\n const code = value.charCodeAt(index)\n if (code >= 0xd800 && code <= 0xdbff) {\n const next = value.charCodeAt(index + 1)\n if (!(next >= 0xdc00 && next <= 0xdfff)) {\n throw new EidosFileError(\n \"invalid-value\",\n \"I-JSON strings cannot contain unpaired surrogates\"\n )\n }\n index += 1\n } else if (code >= 0xdc00 && code <= 0xdfff) {\n throw new EidosFileError(\n \"invalid-value\",\n \"I-JSON strings cannot contain unpaired surrogates\"\n )\n }\n }\n}\n\nfunction assertNoDuplicateJsonKeys(text: string): void {\n let index = 0\n const whitespace = (): void => {\n while (/\\s/u.test(text[index] ?? \"\")) index += 1\n }\n const string = (): string => {\n const start = index++\n while (index < text.length) {\n if (text[index] === \"\\\\\") {\n index += 2\n } else if (text[index] === '\"') {\n index += 1\n return JSON.parse(text.slice(start, index)) as string\n } else {\n index += 1\n }\n }\n throw new EidosFileError(\"invalid-value\", \"Value is not valid JSON\")\n }\n const value = (): void => {\n whitespace()\n if (text[index] === '\"') {\n string()\n return\n }\n if (text[index] === \"[\") {\n index += 1\n whitespace()\n if (text[index] === \"]\") {\n index += 1\n return\n }\n while (index < text.length) {\n value()\n whitespace()\n if (text[index] === \"]\") {\n index += 1\n return\n }\n if (text[index++] !== \",\") break\n }\n throw new EidosFileError(\"invalid-value\", \"Value is not valid JSON\")\n }\n if (text[index] === \"{\") {\n index += 1\n const keys = new Set<string>()\n whitespace()\n if (text[index] === \"}\") {\n index += 1\n return\n }\n while (index < text.length) {\n whitespace()\n if (text[index] !== '\"') break\n const key = string()\n if (keys.has(key)) {\n throw new EidosFileError(\n \"invalid-value\",\n `Duplicate I-JSON object key: ${key}`\n )\n }\n keys.add(key)\n whitespace()\n if (text[index++] !== \":\") break\n value()\n whitespace()\n if (text[index] === \"}\") {\n index += 1\n return\n }\n if (text[index++] !== \",\") break\n }\n throw new EidosFileError(\"invalid-value\", \"Value is not valid JSON\")\n }\n while (index < text.length && !/[\\s,\\]}]/u.test(text[index]!)) index += 1\n }\n value()\n whitespace()\n if (index !== text.length) {\n throw new EidosFileError(\"invalid-value\", \"Value is not valid JSON\")\n }\n}\n\nfunction normalize(value: unknown, stack: Set<object>): EidosFileJsonValue {\n if (value === null || typeof value === \"boolean\") {\n return value\n }\n if (typeof value === \"string\") {\n assertUnicodeScalarString(value)\n return value\n }\n if (typeof value === \"number\") {\n if (!Number.isFinite(value)) {\n throw new EidosFileError(\n \"invalid-value\",\n \"Canonical JSON numbers must be finite binary64 values\"\n )\n }\n return Object.is(value, -0) ? 0 : value\n }\n if (typeof value !== \"object\" || value === undefined) {\n throw new EidosFileError(\"invalid-value\", \"Value is not valid I-JSON\")\n }\n if (stack.has(value)) {\n throw new EidosFileError(\"invalid-value\", \"Canonical JSON cannot be cyclic\")\n }\n stack.add(value)\n try {\n if (Array.isArray(value)) {\n return value.map((entry) => normalize(entry, stack))\n }\n const normalized: Record<string, EidosFileJsonValue> = {}\n for (const key of Object.keys(value).sort()) {\n assertUnicodeScalarString(key)\n normalized[key] = normalize(\n (value as Record<string, unknown>)[key],\n stack\n )\n }\n return normalized\n } finally {\n stack.delete(value)\n }\n}\n\n/** RFC 8785-compatible canonical serialization for the Eidos JSON subset. */\nexport function canonicalizeEidosFileJson(value: unknown): string {\n return JSON.stringify(normalize(value, new Set()))\n}\n\nexport function parseEidosFileJson(text: string): EidosFileJsonValue {\n let value: unknown\n try {\n assertNoDuplicateJsonKeys(text)\n value = JSON.parse(text)\n } catch (error) {\n if (error instanceof EidosFileError) throw error\n throw new EidosFileError(\"invalid-value\", \"Value is not valid JSON\")\n }\n return normalize(value, new Set())\n}\n\nexport function isCanonicalEidosFileJson(text: string): boolean {\n try {\n return canonicalizeEidosFileJson(parseEidosFileJson(text)) === text\n } catch {\n return false\n }\n}\n","import { EidosFileError } from \"./errors\"\n\nconst UUID_V7 =\n /^[0-9a-f]{8}-[0-9a-f]{4}-7[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/\n\nfunction sqliteNoCase(value: string): string {\n return value.replace(/[A-Z]/g, (character) => character.toLowerCase())\n}\n\nfunction utf8Length(value: string): number {\n return new TextEncoder().encode(value).byteLength\n}\n\nfunction utf8Prefix(value: string, limit: number): string {\n let result = \"\"\n let length = 0\n for (const scalar of value) {\n const scalarLength = utf8Length(scalar)\n if (length + scalarLength > limit) break\n result += scalar\n length += scalarLength\n }\n return result\n}\n\nexport function isEidosFileUuid(value: unknown): value is string {\n return typeof value === \"string\" && UUID_V7.test(value)\n}\n\nexport function assertEidosFileUuid(value: string, label = \"ID\"): string {\n if (!isEidosFileUuid(value)) {\n throw new EidosFileError(\n \"invalid-value\",\n `${label} must be a lowercase hyphenated UUIDv7`\n )\n }\n return value\n}\n\nfunction bytesToUuid(value: Uint8Array): string {\n const hex = Array.from(value, (byte) =>\n byte.toString(16).padStart(2, \"0\")\n ).join(\"\")\n const uuid = `${hex.slice(0, 8)}-${hex.slice(8, 12)}-${hex.slice(12, 16)}-${hex.slice(16, 20)}-${hex.slice(20)}`\n return assertEidosFileUuid(uuid)\n}\n\nlet lastUuidV7Timestamp = -1\nlet lastUuidV7Bytes: Uint8Array | undefined\n\nfunction incrementUuidV7Random(bytes: Uint8Array): boolean {\n for (let index = 15; index >= 9; index -= 1) {\n if (bytes[index]! < 0xff) {\n bytes[index] = bytes[index]! + 1\n return true\n }\n bytes[index] = 0\n }\n const variantRandom = bytes[8]! & 0x3f\n if (variantRandom < 0x3f) {\n bytes[8] = 0x80 | (variantRandom + 1)\n return true\n }\n bytes[8] = 0x80\n if (bytes[7]! < 0xff) {\n bytes[7] = bytes[7]! + 1\n return true\n }\n bytes[7] = 0\n const versionRandom = bytes[6]! & 0x0f\n if (versionRandom < 0x0f) {\n bytes[6] = 0x70 | (versionRandom + 1)\n return true\n }\n return false\n}\n\n/** Runtime-epoch UUIDv7 allocator with injected time and secure entropy. */\nexport class EidosUuidV7Generator {\n private lastTimestamp: number | undefined\n private lastBytes: Uint8Array | undefined\n\n constructor(\n private readonly nowInstant: () => string,\n private readonly randomBytes: (length: number) => Uint8Array\n ) {}\n\n next(): string {\n const wallInstant = this.nowInstant()\n const wallTimestamp = Date.parse(wallInstant)\n if (\n !Number.isSafeInteger(wallTimestamp) ||\n wallTimestamp < 0 ||\n wallTimestamp > 0xffffffffffff\n ) {\n throw new EidosFileError(\n \"resource-limit\",\n \"Wall clock cannot be encoded as a UUIDv7 timestamp\"\n )\n }\n const timestamp =\n this.lastTimestamp === undefined\n ? wallTimestamp\n : Math.max(wallTimestamp, this.lastTimestamp)\n let bytes: Uint8Array\n if (this.lastBytes && timestamp === this.lastTimestamp) {\n bytes = this.lastBytes.slice()\n if (!incrementUuidV7Random(bytes)) {\n throw new EidosFileError(\n \"resource-limit\",\n \"UUIDv7 monotonic payload was exhausted for one millisecond\"\n )\n }\n } else {\n const supplied = this.randomBytes(16)\n if (!(supplied instanceof Uint8Array) || supplied.byteLength !== 16) {\n throw new EidosFileError(\n \"resource-limit\",\n \"EntropyPort must return exactly the requested owned bytes\"\n )\n }\n bytes = supplied.slice()\n }\n let remaining = timestamp\n for (let index = 5; index >= 0; index -= 1) {\n bytes[index] = remaining % 256\n remaining = Math.floor(remaining / 256)\n }\n bytes[6] = 0x70 | (bytes[6]! & 0x0f)\n bytes[8] = 0x80 | (bytes[8]! & 0x3f)\n this.lastTimestamp = timestamp\n this.lastBytes = bytes.slice()\n return bytesToUuid(bytes)\n }\n}\n\n/** Creates an RFC 9562 UUIDv7 using the current Unix millisecond timestamp. */\nexport function createEidosFileUuid(timestamp = Date.now()): string {\n if (\n !Number.isSafeInteger(timestamp) ||\n timestamp < 0 ||\n timestamp > 0xffffffffffff\n ) {\n throw new EidosFileError(\n \"invalid-value\",\n \"UUIDv7 timestamp is out of range\"\n )\n }\n const bytes =\n timestamp === lastUuidV7Timestamp && lastUuidV7Bytes\n ? new Uint8Array(lastUuidV7Bytes)\n : globalThis.crypto.getRandomValues(new Uint8Array(16))\n if (\n timestamp === lastUuidV7Timestamp &&\n lastUuidV7Bytes &&\n !incrementUuidV7Random(bytes)\n ) {\n throw new EidosFileError(\n \"resource-limit\",\n \"UUIDv7 monotonic random space was exhausted for one millisecond\"\n )\n }\n let time = timestamp\n for (let index = 5; index >= 0; index -= 1) {\n bytes[index] = time % 256\n time = Math.floor(time / 256)\n }\n bytes[6] = 0x70 | (bytes[6]! & 0x0f)\n bytes[8] = 0x80 | (bytes[8]! & 0x3f)\n lastUuidV7Timestamp = timestamp\n lastUuidV7Bytes = new Uint8Array(bytes)\n return bytesToUuid(bytes)\n}\n\n/** @deprecated Use UUID strings as stable public identifiers. */\nexport function createEidosFileIdentifier(): string {\n return createEidosFileUuid()\n}\n\n/** UUIDs are the only valid Table IDs in Eidos File 1.0. */\nexport function assertEidosFileTableId(tableId: string): string {\n return assertEidosFileUuid(tableId, \"Table ID\")\n}\n\nexport function assertEidosFileDisplayName(\n name: string,\n label: string\n): string {\n if (\n name.length === 0 ||\n name.includes(\"\\u0000\") ||\n utf8Length(name) > 1024 ||\n /[\\uD800-\\uDFFF]/u.test(\n Array.from(name)\n .filter((scalar) => scalar.length === 1)\n .join(\"\")\n )\n ) {\n throw new EidosFileError(\n \"invalid-identifier\",\n `${label} must be 1..1024 UTF-8 octets, contain Unicode scalar values, and exclude U+0000`\n )\n }\n return name\n}\n\nexport type EidosFilePhysicalNameKind = \"table\" | \"field\"\n\nfunction isReservedPhysicalName(\n kind: EidosFilePhysicalNameKind,\n displayName: string\n): boolean {\n const folded = sqliteNoCase(displayName)\n if (kind === \"field\") {\n return [\"_id\", \"_created_at\", \"_updated_at\"].includes(folded)\n }\n return [\"sqlite_\", \"eidos__\", \"x__\"].some((prefix) =>\n folded.startsWith(prefix)\n )\n}\n\n/**\n * Applies the display-first physical naming rule from Eidos File 1.0 §6.\n * `existingNames` is compared using SQLite's ASCII-only NOCASE behavior.\n */\nexport function eidosFilePhysicalName(\n kind: EidosFilePhysicalNameKind,\n displayName: string,\n stableId: string,\n existingNames: Iterable<string> = []\n): string {\n assertEidosFileDisplayName(\n displayName,\n kind === \"table\" ? \"Table name\" : \"Field name\"\n )\n const idHex = assertEidosFileUuid(stableId).replace(/-/g, \"\")\n const existing = new Set(Array.from(existingNames, sqliteNoCase))\n const available = (candidate: string) =>\n !existing.has(sqliteNoCase(candidate))\n if (kind === \"table\" && isReservedPhysicalName(kind, displayName)) {\n for (const length of [8, 12, 32]) {\n const prefix = `t__${idHex.slice(0, length)}__`\n const candidate = `${prefix}${utf8Prefix(\n displayName,\n 1024 - utf8Length(prefix)\n )}`\n if (available(candidate)) return candidate\n }\n throw new EidosFileError(\n \"constraint-conflict\",\n `Unable to allocate a physical ${kind} name for “${displayName}”`\n )\n }\n if (!isReservedPhysicalName(kind, displayName) && available(displayName)) {\n return displayName\n }\n for (const length of [8, 12, 32]) {\n const suffix = `__${idHex.slice(0, length)}`\n const candidate = `${utf8Prefix(\n displayName,\n 1024 - utf8Length(suffix)\n )}${suffix}`\n if (available(candidate)) return candidate\n }\n throw new EidosFileError(\n \"constraint-conflict\",\n `Unable to allocate a physical ${kind} name for “${displayName}”`\n )\n}\n\n/** @deprecated Physical table names are display-first, not `tb_<id>`. */\nexport function rawTableNameForId(tableId: string): string {\n return eidosFilePhysicalName(\n \"table\",\n tableId,\n assertEidosFileTableId(tableId)\n )\n}\n\n/** @deprecated Field display names are not restricted to bare SQL tokens. */\nexport function assertEidosFileColumnName(columnName: string): string {\n return assertEidosFileDisplayName(columnName, \"Field name\")\n}\n\nexport function quoteIdentifier(identifier: string): string {\n if (identifier.includes(\"\\u0000\")) {\n throw new EidosFileError(\n \"invalid-identifier\",\n \"SQLite identifiers must not contain U+0000\"\n )\n }\n return `\"${identifier.replace(/\"/g, '\"\"')}\"`\n}\n","import { canonicalizeEidosFileJson, parseEidosFileJson } from \"./canonical-json\"\nimport { EidosFileError } from \"./errors\"\nimport { createEidosFileUuid, isEidosFileUuid } from \"./identifiers\"\nimport type { EidosFileFileValue, EidosFileRowValue } from \"./types\"\n\nconst MAX_FILE_VALUES = 10_000\nconst NON_NEGATIVE_INT64 = /^(?:0|[1-9][0-9]*)$/u\nconst MEDIA_TYPE = /^[!#$%&'*+.^_`|~0-9A-Za-z-]+\\/[!#$%&'*+.^_`|~0-9A-Za-z-]+$/u\nconst MAX_SIGNED_INT64 = 9_223_372_036_854_775_807n\n\nexport function isSafeEidosFileUri(uri: string): boolean {\n if (!uri || uri.includes(\"\\0\") || uri.includes(\"\\\\\")) return false\n if (uri.startsWith(\"https://\")) {\n try {\n return new URL(uri).protocol === \"https:\"\n } catch {\n return false\n }\n }\n if (/^[a-zA-Z][a-zA-Z0-9+.-]*:/u.test(uri) || uri.startsWith(\"/\")) {\n return false\n }\n try {\n const decoded = decodeURIComponent(uri)\n return (\n !decoded.startsWith(\"/\") &&\n !decoded.includes(\"\\\\\") &&\n !decoded.split(/[/?#]/u).includes(\"..\")\n )\n } catch {\n return false\n }\n}\n\nexport function assertEidosFileValues(value: unknown): EidosFileFileValue[] {\n if (!Array.isArray(value)) {\n throw new EidosFileError(\"invalid-value\", \"File value must be a JSON array\")\n }\n if (value.length > MAX_FILE_VALUES) {\n throw new EidosFileError(\n \"resource-limit\",\n \"File value contains too many entries\"\n )\n }\n const ids = new Set<string>()\n return value.map((entry) => {\n if (!entry || Array.isArray(entry) || typeof entry !== \"object\") {\n throw new EidosFileError(\n \"invalid-value\",\n \"File value contains an invalid entry\"\n )\n }\n const candidate = entry as Record<string, unknown>\n if (\n typeof candidate.id !== \"string\" ||\n !isEidosFileUuid(candidate.id) ||\n ids.has(candidate.id) ||\n typeof candidate.uri !== \"string\" ||\n !isSafeEidosFileUri(candidate.uri) ||\n typeof candidate.name !== \"string\" ||\n candidate.name.length === 0 ||\n candidate.name.includes(\"\\u0000\") ||\n typeof candidate.mediaType !== \"string\" ||\n !MEDIA_TYPE.test(candidate.mediaType) ||\n typeof candidate.size !== \"string\" ||\n !NON_NEGATIVE_INT64.test(candidate.size) ||\n BigInt(candidate.size) > MAX_SIGNED_INT64\n ) {\n throw new EidosFileError(\n \"invalid-value\",\n \"File value contains an invalid entry\"\n )\n }\n ids.add(candidate.id)\n return {\n ...candidate,\n id: candidate.id,\n uri: candidate.uri,\n name: candidate.name,\n mediaType: candidate.mediaType,\n size: candidate.size,\n } as EidosFileFileValue\n })\n}\n\nexport function decodeEidosFileValues(\n value: EidosFileRowValue | undefined\n): EidosFileFileValue[] {\n if (value === undefined || value === null || value === \"\") return []\n if (typeof value !== \"string\") {\n throw new EidosFileError(\n \"invalid-value\",\n \"File value must be canonical JSON\"\n )\n }\n return assertEidosFileValues(parseEidosFileJson(value))\n}\n\nexport function encodeEidosFileValues(\n values: readonly EidosFileFileValue[]\n): string {\n return canonicalizeEidosFileJson(assertEidosFileValues([...values]))\n}\n\nexport function normalizeEidosFileAttachmentPath(value: string): string | null {\n const trimmed = value.trim()\n if (!trimmed || trimmed.includes(\"\\0\")) return null\n if (trimmed.startsWith(\"https://\")) {\n return isSafeEidosFileUri(trimmed) ? trimmed : null\n }\n if (/^[a-z][a-z\\d+.-]*:/iu.test(trimmed) || trimmed.startsWith(\"/\")) {\n return null\n }\n const parts = trimmed.replace(/\\\\/g, \"/\").split(\"/\")\n const normalized: string[] = []\n for (const part of parts) {\n if (!part || part === \".\") continue\n if (part === \"..\") {\n if (normalized.length === 0) return null\n normalized.pop()\n continue\n }\n normalized.push(part)\n }\n const uri = normalized.join(\"/\")\n return isSafeEidosFileUri(uri) ? uri : null\n}\n\nexport function decodeEidosFileAttachmentPaths(\n value: EidosFileRowValue | undefined\n): string[] {\n return decodeEidosFileValues(value).map((file) => file.uri)\n}\n\n/**\n * Compatibility helper for path-oriented host pickers. Existing File IDs are\n * retained by URI; new attachments receive UUIDv7 identities.\n */\nexport function encodeEidosFileAttachmentPaths(\n paths: readonly string[],\n previousValue?: EidosFileRowValue\n): string | null {\n const previous = new Map(\n decodeEidosFileValues(previousValue).map((file) => [file.uri, file])\n )\n const seen = new Set<string>()\n const values = paths.flatMap((path) => {\n const uri = normalizeEidosFileAttachmentPath(path)\n if (!uri || seen.has(uri)) return []\n seen.add(uri)\n const existing = previous.get(uri)\n if (existing) return [existing]\n const pathName = uri.split(/[/?#]/u).at(-1)\n return [\n {\n id: createEidosFileUuid(),\n uri,\n name: pathName || \"attachment\",\n mediaType: \"application/octet-stream\",\n size: \"0\",\n },\n ]\n })\n return values.length > 0 ? encodeEidosFileValues(values) : null\n}\n","import { EidosFileError } from \"./errors\"\n\nconst CANONICAL_DATE = /^\\d{4}-\\d{2}-\\d{2}$/\nconst CANONICAL_INSTANT = /^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}\\.\\d{3}Z$/\nconst RFC3339_INSTANT =\n /^(\\d{4}-\\d{2}-\\d{2})[Tt](\\d{2}):(\\d{2}):(\\d{2})(?:\\.(\\d+))?([Zz]|([+-])(\\d{2}):(\\d{2}))$/\n\nfunction validCalendarDate(value: string): boolean {\n if (!CANONICAL_DATE.test(value) || value.startsWith(\"0000-\")) return false\n const parsed = new Date(`${value}T00:00:00.000Z`)\n return (\n !Number.isNaN(parsed.getTime()) &&\n parsed.toISOString().slice(0, 10) === value\n )\n}\n\n/** Returns whether a value is the canonical Eidos File calendar date. */\nexport function isCanonicalEidosFileDate(value: unknown): value is string {\n return typeof value === \"string\" && validCalendarDate(value)\n}\n\n/** Returns whether a value is the canonical 24-octet Eidos File instant. */\nexport function isCanonicalEidosFileInstant(value: unknown): value is string {\n if (typeof value !== \"string\" || !CANONICAL_INSTANT.test(value)) return false\n const match = RFC3339_INSTANT.exec(value)\n if (!match || !validCalendarDate(match[1]!)) return false\n const hour = Number(match[2])\n const minute = Number(match[3])\n const second = Number(match[4])\n if (hour > 23 || minute > 59 || second > 59) return false\n const parsed = new Date(value)\n return !Number.isNaN(parsed.getTime()) && parsed.toISOString() === value\n}\n\n/** Validates an exact `YYYY-MM-DD` API/storage value. */\nexport function normalizeEidosFileDate(value: string, label = \"date\"): string {\n if (!isCanonicalEidosFileDate(value)) {\n throw new EidosFileError(\n \"invalid-value\",\n `${label} must use canonical YYYY-MM-DD text`\n )\n }\n return value\n}\n\n/**\n * Normalizes RFC 3339 API input to the canonical UTC millisecond form.\n * Precision beyond milliseconds is rejected instead of silently truncated.\n */\nexport function normalizeEidosFileInstant(\n value: string,\n label = \"instant\"\n): string {\n const match = RFC3339_INSTANT.exec(value)\n if (!match || !validCalendarDate(match[1]!)) {\n throw new EidosFileError(\n \"invalid-value\",\n `${label} must be an RFC 3339 instant`\n )\n }\n const fraction = match[5] ?? \"\"\n if (fraction.length > 3) {\n throw new EidosFileError(\n \"invalid-value\",\n `${label} has sub-millisecond precision; lossy conversion was not requested`\n )\n }\n const hour = Number(match[2])\n const minute = Number(match[3])\n const second = Number(match[4])\n const offsetHour = match[8] === undefined ? 0 : Number(match[8])\n const offsetMinute = match[9] === undefined ? 0 : Number(match[9])\n if (\n hour > 23 ||\n minute > 59 ||\n second > 59 ||\n offsetHour > 23 ||\n offsetMinute > 59\n ) {\n throw new EidosFileError(\n \"invalid-value\",\n `${label} must be an RFC 3339 instant`\n )\n }\n const timestamp = Date.parse(value)\n if (!Number.isFinite(timestamp)) {\n throw new EidosFileError(\n \"invalid-value\",\n `${label} must be an RFC 3339 instant`\n )\n }\n const canonical = new Date(timestamp).toISOString()\n if (!isCanonicalEidosFileInstant(canonical)) {\n throw new EidosFileError(\n \"invalid-value\",\n `${label} must resolve to a UTC year from 0001 through 9999`\n )\n }\n return canonical\n}\n\n/** Returns the current canonical UTC instant. */\nexport function currentEidosFileInstant(now = new Date()): string {\n const value = now.toISOString()\n if (!isCanonicalEidosFileInstant(value)) {\n throw new EidosFileError(\n \"invalid-value\",\n \"Current time is outside the canonical Eidos File instant range\"\n )\n }\n return value\n}\n\n/** SQLite CHECK body for a nullable canonical date expression. */\nexport function eidosFileDateSqlCheck(expression: string): string {\n return `${expression} IS NULL OR (\n length(CAST(${expression} AS BLOB)) = 10\n AND ${expression} GLOB '[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9]'\n AND substr(${expression}, 1, 4) <> '0000'\n AND coalesce(strftime('%Y-%m-%d', ${expression}, '+0 days') = ${expression}, 0)\n )`\n}\n\n/** SQLite CHECK body for a nullable canonical instant expression. */\nexport function eidosFileInstantSqlCheck(expression: string): string {\n return `${expression} IS NULL OR (\n length(CAST(${expression} AS BLOB)) = 24\n AND ${expression} GLOB '[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9]T[0-9][0-9]:[0-9][0-9]:[0-9][0-9].[0-9][0-9][0-9]Z'\n AND substr(${expression}, 1, 4) <> '0000'\n AND coalesce(strftime('%Y-%m-%dT%H:%M:%fZ', ${expression}, '+0 seconds') = ${expression}, 0)\n )`\n}\n","import { EidosFileError } from \"./errors\"\nimport type { EidosFileSelectOption } from \"./types\"\n\nexport function parseEidosFileSelectOptions(\n property: Record<string, unknown> | null | undefined\n): EidosFileSelectOption[] {\n const options = property?.options\n if (!Array.isArray(options)) return []\n return options.flatMap((option) => {\n if (typeof option !== \"object\" || option === null) return []\n const name =\n \"name\" in option && typeof option.name === \"string\" ? option.name : null\n if (name === null) return []\n return [\n {\n name,\n color:\n \"color\" in option && typeof option.color === \"string\"\n ? option.color\n : \"default\",\n },\n ]\n })\n}\n\nexport function assertEidosFileSelectOptions(\n property: Record<string, unknown> | null | undefined\n): EidosFileSelectOption[] {\n const rawOptions = property?.options\n if (rawOptions === undefined) return []\n if (!Array.isArray(rawOptions)) {\n throw new EidosFileError(\n \"invalid-schema\",\n \"Select Field settings.options must be an array\"\n )\n }\n const options = parseEidosFileSelectOptions(property)\n if (options.length !== rawOptions.length) {\n throw new EidosFileError(\n \"invalid-schema\",\n \"Every Select option requires a string name\"\n )\n }\n const names = new Set<string>()\n for (const option of options) {\n const name = option.name\n if (names.has(name)) {\n throw new EidosFileError(\n \"constraint-conflict\",\n `Duplicate Select option name: ${name}`\n )\n }\n names.add(name)\n }\n return options\n}\n"],"mappings":";AAiCA,IAAa,iBAAb,cAAoC,MAAM;CACxC,YACE,MACA,SACA;AACA,QAAM,QAAQ;AAHL,OAAA,OAAA;AAIT,OAAK,OAAO;;;;;AC7BhB,SAAS,0BAA0B,OAAqB;AACtD,MAAK,IAAI,QAAQ,GAAG,QAAQ,MAAM,QAAQ,SAAS,GAAG;EACpD,MAAM,OAAO,MAAM,WAAW,MAAM;AACpC,MAAI,QAAQ,SAAU,QAAQ,OAAQ;GACpC,MAAM,OAAO,MAAM,WAAW,QAAQ,EAAE;AACxC,OAAI,EAAE,QAAQ,SAAU,QAAQ,OAC9B,OAAM,IAAI,eACR,iBACA,oDACD;AAEH,YAAS;aACA,QAAQ,SAAU,QAAQ,MACnC,OAAM,IAAI,eACR,iBACA,oDACD;;;AAKP,SAAS,0BAA0B,MAAoB;CACrD,IAAI,QAAQ;CACZ,MAAM,mBAAyB;AAC7B,SAAO,MAAM,KAAK,KAAK,UAAU,GAAG,CAAE,UAAS;;CAEjD,MAAM,eAAuB;EAC3B,MAAM,QAAQ;AACd,SAAO,QAAQ,KAAK,OAClB,KAAI,KAAK,WAAW,KAClB,UAAS;WACA,KAAK,WAAW,MAAK;AAC9B,YAAS;AACT,UAAO,KAAK,MAAM,KAAK,MAAM,OAAO,MAAM,CAAC;QAE3C,UAAS;AAGb,QAAM,IAAI,eAAe,iBAAiB,0BAA0B;;CAEtE,MAAM,cAAoB;AACx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