@eidos.space/eidos-file 0.1.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.
@@ -0,0 +1,119 @@
1
+ import { $ as EidosFileRowsDeleteResult, A as EidosFileFilterValue, B as EidosFileOptionValueChange, C as EidosFileCsvImportResult, D as EidosFileFilterGroup, E as EidosFileFieldType, F as EidosFileFormulaPreviewSample, G as EidosFileRowMutationResult, H as EidosFileRelationValue, I as EidosFileFormulaProperty, J as EidosFileRowPageProjection, K as EidosFileRowPage, L as EidosFileLookupAggregate, M as EidosFileFormulaPreview, N as EidosFileFormulaPreviewDependency, O as EidosFileFilterOperator, P as EidosFileFormulaPreviewInput, Q as EidosFileRowValue, R as EidosFileLookupProperty, S as EidosFileCsvImportPlan, T as EidosFileFieldPlacement, U as EidosFileRow, V as EidosFileRelationProperty, W as EidosFileRowGroupCount, X as EidosFileRowRange, Y as EidosFileRowQuery, Z as EidosFileRowUpdate, _ as EidosFileCsvExportResult, _t as EidosFileRunResult, a as CreateEidosFileOptions, at as EidosFileStorageCodec, b as EidosFileCsvImportIssue, c as CreateEidosFileSourceFieldInput, ct as EidosFileValidationIssue, d as EidosFileColumnStatConfig, dt as EidosFileViewInfo, et as EidosFileRowsMutationResult, f as EidosFileColumnStatResult, ft as ImportEidosFileFieldInput, g as EidosFileCsvExportOptions, gt as EidosFileConnection, h as EidosFileCsvExportColumn, ht as UpdateEidosFileViewInput, i as CreateEidosFileLookupFieldInput, it as EidosFileSortDirection, j as EidosFileFormulaDisplayType, k as EidosFileFilterRule, l as CreateEidosFileTableInput, lt as EidosFileValidationResult, m as EidosFileCsvColumnOverride, mt as UpdateEidosFileTableInput, n as CreateEidosFileFieldInput, nt as EidosFileSnapshot, o as CreateEidosFileReferenceInput, ot as EidosFileTableInfo, p as EidosFileColumnStatType, pt as UpdateEidosFileFieldInput, q as EidosFileRowPageOptions, r as CreateEidosFileFormulaFieldInput, rt as EidosFileSort, s as CreateEidosFileRelationFieldInput, st as EidosFileTableSnapshot, t as EidosFileRuntime, tt as EidosFileSelectOption, u as CreateEidosFileViewInput, ut as EidosFileValueKind, v as EidosFileCsvFieldType, vt as EidosFileSqlParams, w as EidosFileFieldInfo, x as EidosFileCsvImportOptions, y as EidosFileCsvImportColumn, yt as EidosFileSqlPrimitive, z as EidosFileMetadata } from "./runtime-C3bstvB8.mjs";
2
+ import { A as EIDOS_FILE_REFERENCES_TABLE, C as eidosFileSnapshot, D as EIDOS_FILE_FORMAT_VERSION, E as EIDOS_FILE_FORMAT, F as EIDOS_FILE_VIEWS_TABLE, I as SQLITE_HEADER, M as EIDOS_FILE_REQUIRED_TABLES, N as EIDOS_FILE_SCHEMA_VERSION, O as EIDOS_FILE_META_TABLE, P as EIDOS_FILE_TABLES_TABLE, S as EidosFileRuntimeDataSource, T as EIDOS_FILE_EXTENSION, _ as EidosFileSessionState, a as EidosFileHandle, b as eidosFileTypeHandler, c as EidosFileHostError, d as EidosFileReadResult, f as EidosFileRecoverySnapshot, g as EidosFileSessionPhase, h as EidosFileSession, i as EidosFileDocument, j as EIDOS_FILE_REQUIRED_META_KEYS, k as EIDOS_FILE_MIME_TYPE, l as EidosFileHostErrorCode, m as EidosFileRuntimeAdapter, n as EidosFileConflict, o as EidosFileHandlerRegistry, p as EidosFileRecoveryStore, r as EidosFileDescriptor, s as EidosFileHostCapabilities, t as EidosFileCandidateDescriptor, u as EidosFilePermissionState, v as EidosFileTypeHandler, w as EIDOS_FILE_COLUMNS_TABLE, x as EidosFileDataSource, y as EidosFileWriteOptions } from "./host-CqP1MeMK.mjs";
3
+
4
+ //#region src/column-stats.d.ts
5
+ declare function eidosFileColumnStatTypesForField(field: EidosFileFieldInfo): readonly EidosFileColumnStatType[];
6
+ declare function eidosFileColumnStatLabel(type: EidosFileColumnStatType): string;
7
+ //#endregion
8
+ //#region src/errors.d.ts
9
+ type EidosFileErrorCode = "invalid-sqlite" | "not-eidos-file" | "unsupported-format" | "invalid-schema" | "invalid-identifier" | "invalid-query" | "invalid-range" | "invalid-csv" | "protected-field" | "protected-view" | "relation-in-use" | "formula-in-use" | "lookup-in-use" | "table-not-found" | "row-not-found" | "field-not-found" | "view-not-found" | "file-exists" | "file-not-found";
10
+ declare class EidosFileError extends Error {
11
+ readonly code: EidosFileErrorCode;
12
+ constructor(code: EidosFileErrorCode, message: string);
13
+ }
14
+ //#endregion
15
+ //#region src/field-conversion.d.ts
16
+ declare const MUTABLE_BASE_FIELD_TYPES: readonly ["text", "number", "checkbox", "date", "datetime", "file", "multi-select", "rating", "select", "url"];
17
+ type MutableEidosFileFieldType = (typeof MUTABLE_BASE_FIELD_TYPES)[number];
18
+ interface EidosFileFieldValueRow {
19
+ id: string;
20
+ value: EidosFileSqlPrimitive;
21
+ }
22
+ interface EidosFileFieldConversionPlan {
23
+ property: Record<string, unknown> | null;
24
+ storageCodec: EidosFileStorageCodec;
25
+ values: Array<{
26
+ id: string;
27
+ value: EidosFileSqlPrimitive;
28
+ }>;
29
+ }
30
+ declare function isMutableEidosFileFieldType(type: EidosFileFieldType): type is MutableEidosFileFieldType;
31
+ declare function decodeEidosFileMultiSelectValues(value: EidosFileSqlPrimitive): string[];
32
+ declare function encodeEidosFileMultiSelectValues(values: readonly string[]): string | null;
33
+ declare function eidosFileFieldDisplayValues(field: EidosFileFieldInfo, value: EidosFileSqlPrimitive | boolean): string[];
34
+ declare function planEidosFileFieldConversion(field: EidosFileFieldInfo, rows: EidosFileFieldValueRow[], targetType: MutableEidosFileFieldType): EidosFileFieldConversionPlan;
35
+ //#endregion
36
+ //#region src/file-values.d.ts
37
+ declare function normalizeEidosFileAttachmentPath(value: string): string | null;
38
+ declare function decodeEidosFileAttachmentPaths(value: EidosFileRowValue | undefined): string[];
39
+ declare function encodeEidosFileAttachmentPaths(paths: readonly string[]): string | null;
40
+ //#endregion
41
+ //#region src/formula.d.ts
42
+ interface CompiledEidosFileFormula {
43
+ field: EidosFileFieldInfo;
44
+ expression: string;
45
+ dependencies: string[];
46
+ }
47
+ declare function compileEidosFileFormula(field: EidosFileFieldInfo, fields: EidosFileFieldInfo[]): CompiledEidosFileFormula;
48
+ declare function compileEidosFileFormulaFields(fields: EidosFileFieldInfo[]): CompiledEidosFileFormula[];
49
+ //#endregion
50
+ //#region src/identifiers.d.ts
51
+ declare function assertEidosFileTableId(tableId: string): string;
52
+ declare function assertEidosFileColumnName(columnName: string): string;
53
+ declare function rawTableNameForId(tableId: string): string;
54
+ declare function quoteIdentifier(identifier: string): string;
55
+ declare function createEidosFileUuid(): string;
56
+ declare function createEidosFileIdentifier(): string;
57
+ //#endregion
58
+ //#region src/json-array-values.d.ts
59
+ type EidosFileJsonArrayValue = string | number | boolean | null;
60
+ declare function decodeEidosFileJsonArray(value: EidosFileRowValue | undefined): EidosFileJsonArrayValue[];
61
+ declare function decodeEidosFileStringArray(value: EidosFileRowValue | undefined): string[];
62
+ declare function encodeEidosFileJsonArray(values: readonly EidosFileJsonArrayValue[]): string | null;
63
+ //#endregion
64
+ //#region src/lookup.d.ts
65
+ type EidosFileLookupTarget = Pick<EidosFileFieldInfo, "type"> & Partial<Pick<EidosFileFieldInfo, "property">>;
66
+ declare function eidosFileLookupStorageCodec(aggregate: EidosFileLookupAggregate): EidosFileStorageCodec;
67
+ declare function eidosFileLookupAggregateSupportsTarget(aggregate: EidosFileLookupAggregate, target: EidosFileLookupTarget): boolean;
68
+ declare function eidosFileLookupTargetDisplayType(target: EidosFileFieldType | EidosFileLookupTarget): EidosFileFormulaDisplayType;
69
+ declare function eidosFileLookupDisplayType(aggregate: EidosFileLookupAggregate, target: EidosFileFieldType | EidosFileLookupTarget): EidosFileFormulaDisplayType;
70
+ declare function eidosFileFieldStoresJsonArray(field: Pick<EidosFileFieldInfo, "storageCodec">): boolean;
71
+ //#endregion
72
+ //#region src/migrations.d.ts
73
+ declare function getEidosFileSchemaVersion(connection: EidosFileConnection): number;
74
+ declare function migrateEidosFileSchema(connection: EidosFileConnection): number;
75
+ //#endregion
76
+ //#region src/query.d.ts
77
+ interface CompiledEidosFileRowQuery {
78
+ whereSql: string;
79
+ orderSql: string;
80
+ params: EidosFileSqlParams;
81
+ }
82
+ declare function normalizeEidosFileFilter(value: unknown): EidosFileFilterGroup | null;
83
+ declare function removeEidosFileFilterField(group: EidosFileFilterGroup | null, field: string): EidosFileFilterGroup | null;
84
+ declare function normalizeEidosFileSorts(value: unknown): EidosFileSort[];
85
+ declare function normalizeEidosFileRowQuery(value: unknown): EidosFileRowQuery;
86
+ /**
87
+ * Returns the columns whose values can affect whether a row matches a query.
88
+ * Sort-only fields are intentionally excluded because counts do not depend on
89
+ * row order. Consumers can add projected/grouped columns before building a
90
+ * pruned derived-field source.
91
+ */
92
+ declare function eidosFileRowQueryPredicateColumns(fields: EidosFileFieldInfo[], query: EidosFileRowQuery): Set<string>;
93
+ /**
94
+ * Returns whether changing the supplied columns can alter the rows or ordering
95
+ * produced by a query. Derived-field dependencies are followed transitively so
96
+ * renderers do not need to duplicate Eidos File query semantics.
97
+ */
98
+ declare function eidosFileRowQueryAffectedByFieldChanges(fields: EidosFileFieldInfo[], query: EidosFileRowQuery, changedColumns: Iterable<string>): boolean;
99
+ declare function compileEidosFileRowQuery(fields: EidosFileFieldInfo[], query?: EidosFileRowQuery): CompiledEidosFileRowQuery;
100
+ //#endregion
101
+ //#region src/relation-values.d.ts
102
+ declare function decodeEidosFileRelationIds(value: EidosFileRowValue | undefined): string[];
103
+ declare function encodeEidosFileRelationIds(ids: readonly string[]): string | null;
104
+ declare function decodeEidosFileRelationDisplay(value: EidosFileRowValue | undefined): EidosFileRelationValue[];
105
+ //#endregion
106
+ //#region src/schema.d.ts
107
+ declare const EIDOS_FILE_SCHEMA_SQL: string;
108
+ declare function initializeEidosFileSchema(connection: EidosFileConnection, options?: CreateEidosFileOptions): void;
109
+ declare function setEidosFileMetadata(connection: EidosFileConnection, entries: Record<string, string | undefined>): void;
110
+ //#endregion
111
+ //#region src/select-options.d.ts
112
+ declare function parseEidosFileSelectOptions(property: Record<string, unknown> | null | undefined): EidosFileSelectOption[];
113
+ declare function assertEidosFileSelectOptions(property: Record<string, unknown> | null | undefined): EidosFileSelectOption[];
114
+ //#endregion
115
+ //#region src/validation.d.ts
116
+ declare function validateEidosFile(connection: EidosFileConnection): EidosFileValidationResult;
117
+ //#endregion
118
+ export { CompiledEidosFileFormula, CompiledEidosFileRowQuery, CreateEidosFileFieldInput, CreateEidosFileFormulaFieldInput, CreateEidosFileLookupFieldInput, CreateEidosFileOptions, CreateEidosFileReferenceInput, CreateEidosFileRelationFieldInput, CreateEidosFileSourceFieldInput, CreateEidosFileTableInput, CreateEidosFileViewInput, EIDOS_FILE_COLUMNS_TABLE, EIDOS_FILE_EXTENSION, EIDOS_FILE_FORMAT, EIDOS_FILE_FORMAT_VERSION, EIDOS_FILE_META_TABLE, EIDOS_FILE_MIME_TYPE, EIDOS_FILE_REFERENCES_TABLE, EIDOS_FILE_REQUIRED_META_KEYS, EIDOS_FILE_REQUIRED_TABLES, EIDOS_FILE_SCHEMA_SQL, EIDOS_FILE_SCHEMA_VERSION, EIDOS_FILE_TABLES_TABLE, EIDOS_FILE_VIEWS_TABLE, EidosFileCandidateDescriptor, EidosFileColumnStatConfig, EidosFileColumnStatResult, EidosFileColumnStatType, EidosFileConflict, EidosFileConnection, EidosFileCsvColumnOverride, EidosFileCsvExportColumn, EidosFileCsvExportOptions, EidosFileCsvExportResult, EidosFileCsvFieldType, EidosFileCsvImportColumn, EidosFileCsvImportIssue, EidosFileCsvImportOptions, EidosFileCsvImportPlan, EidosFileCsvImportResult, EidosFileDataSource, EidosFileDescriptor, EidosFileDocument, EidosFileError, EidosFileErrorCode, EidosFileFieldConversionPlan, EidosFileFieldInfo, EidosFileFieldPlacement, EidosFileFieldType, EidosFileFieldValueRow, EidosFileFilterGroup, EidosFileFilterOperator, EidosFileFilterRule, EidosFileFilterValue, EidosFileFormulaDisplayType, EidosFileFormulaPreview, EidosFileFormulaPreviewDependency, EidosFileFormulaPreviewInput, EidosFileFormulaPreviewSample, EidosFileFormulaProperty, EidosFileHandle, EidosFileHandlerRegistry, EidosFileHostCapabilities, EidosFileHostError, EidosFileHostErrorCode, EidosFileJsonArrayValue, EidosFileLookupAggregate, EidosFileLookupProperty, EidosFileLookupTarget, EidosFileMetadata, EidosFileOptionValueChange, EidosFilePermissionState, EidosFileReadResult, EidosFileRecoverySnapshot, EidosFileRecoveryStore, EidosFileRelationProperty, EidosFileRelationValue, EidosFileRow, EidosFileRowGroupCount, EidosFileRowMutationResult, EidosFileRowPage, EidosFileRowPageOptions, EidosFileRowPageProjection, EidosFileRowQuery, EidosFileRowRange, EidosFileRowUpdate, EidosFileRowValue, EidosFileRowsDeleteResult, EidosFileRowsMutationResult, EidosFileRunResult, EidosFileRuntime, EidosFileRuntimeAdapter, EidosFileRuntimeDataSource, EidosFileSelectOption, EidosFileSession, EidosFileSessionPhase, EidosFileSessionState, EidosFileSnapshot, EidosFileSort, EidosFileSortDirection, EidosFileSqlParams, EidosFileSqlPrimitive, EidosFileStorageCodec, EidosFileTableInfo, EidosFileTableSnapshot, EidosFileTypeHandler, EidosFileValidationIssue, EidosFileValidationResult, EidosFileValueKind, EidosFileViewInfo, EidosFileWriteOptions, ImportEidosFileFieldInput, MUTABLE_BASE_FIELD_TYPES, MutableEidosFileFieldType, SQLITE_HEADER, UpdateEidosFileFieldInput, UpdateEidosFileTableInput, UpdateEidosFileViewInput, assertEidosFileColumnName, assertEidosFileSelectOptions, assertEidosFileTableId, compileEidosFileFormula, compileEidosFileFormulaFields, compileEidosFileRowQuery, createEidosFileIdentifier, createEidosFileUuid, decodeEidosFileAttachmentPaths, decodeEidosFileJsonArray, decodeEidosFileMultiSelectValues, decodeEidosFileRelationDisplay, decodeEidosFileRelationIds, decodeEidosFileStringArray, eidosFileColumnStatLabel, eidosFileColumnStatTypesForField, eidosFileFieldDisplayValues, eidosFileFieldStoresJsonArray, eidosFileLookupAggregateSupportsTarget, eidosFileLookupDisplayType, eidosFileLookupStorageCodec, eidosFileLookupTargetDisplayType, eidosFileRowQueryAffectedByFieldChanges, eidosFileRowQueryPredicateColumns, eidosFileSnapshot, eidosFileTypeHandler, encodeEidosFileAttachmentPaths, encodeEidosFileJsonArray, encodeEidosFileMultiSelectValues, encodeEidosFileRelationIds, getEidosFileSchemaVersion, initializeEidosFileSchema, isMutableEidosFileFieldType, migrateEidosFileSchema, normalizeEidosFileAttachmentPath, normalizeEidosFileFilter, normalizeEidosFileRowQuery, normalizeEidosFileSorts, parseEidosFileSelectOptions, planEidosFileFieldConversion, quoteIdentifier, rawTableNameForId, removeEidosFileFilterField, setEidosFileMetadata, validateEidosFile };
119
+ //# sourceMappingURL=index.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.mts","names":[],"sources":["../src/column-stats.ts","../src/errors.ts","../src/field-conversion.ts","../src/file-values.ts","../src/formula.ts","../src/identifiers.ts","../src/json-array-values.ts","../src/lookup.ts","../src/migrations.ts","../src/query.ts","../src/relation-values.ts","../src/schema.ts","../src/select-options.ts","../src/validation.ts"],"mappings":";;;;iBAiFgB,gCAAA,CACd,KAAA,EAAO,kBAAA,YACG,uBAAA;AAAA,iBAkBI,wBAAA,CACd,IAAA,EAAM,uBAAA;;;KCtGI,kBAAA;AAAA,cAqBC,cAAA,SAAuB,KAAA;EAAA,SAEvB,IAAA,EAAM,kBAAA;cAAN,IAAA,EAAM,kBAAA,EACf,OAAA;AAAA;;;cCNS,wBAAA;AAAA,KAaD,yBAAA,WACF,wBAAA;AAAA,UAgBO,sBAAA;EACf,EAAA;EACA,KAAA,EAAO,qBAAA;AAAA;AAAA,UAGQ,4BAAA;EACf,QAAA,EAAU,MAAA;EACV,YAAA,EAAc,qBAAA;EACd,MAAA,EAAQ,KAAA;IAAQ,EAAA;IAAY,KAAA,EAAO,qBAAA;EAAA;AAAA;AAAA,iBAGrB,2BAAA,CACd,IAAA,EAAM,kBAAA,GACL,IAAA,IAAQ,yBAAA;AAAA,iBAIK,gCAAA,CACd,KAAA,EA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 import { a as EidosFileRuntimeDataSource, i as eidosFileTypeHandler, n as EidosFileHostError, o as eidosFileSnapshot, r as EidosFileSession, t as EidosFileHandlerRegistry } from "./host-D5kZAhga.mjs";
2
+ import { _ as encodeEidosFileJsonArray, a as decodeEidosFileMultiSelectValues, c as isMutableEidosFileFieldType, d as parseEidosFileSelectOptions, f as decodeEidosFileAttachmentPaths, g as decodeEidosFileStringArray, h as decodeEidosFileJsonArray, i as MUTABLE_BASE_FIELD_TYPES, l as planEidosFileFieldConversion, m as normalizeEidosFileAttachmentPath, n as decodeEidosFileRelationIds, o as eidosFileFieldDisplayValues, p as encodeEidosFileAttachmentPaths, r as encodeEidosFileRelationIds, s as encodeEidosFileMultiSelectValues, t as decodeEidosFileRelationDisplay, u as assertEidosFileSelectOptions, v as EidosFileError } from "./relation-values-B0JhHBjZ.mjs";
3
+ import { A as EIDOS_FILE_REQUIRED_TABLES, B as createEidosFileUuid, C as EIDOS_FILE_EXTENSION, D as EIDOS_FILE_MIME_TYPE, E as EIDOS_FILE_META_TABLE, F as eidosFileColumnStatLabel, H as rawTableNameForId, I as eidosFileColumnStatTypesForField, L as assertEidosFileColumnName, M as EIDOS_FILE_TABLES_TABLE, N as EIDOS_FILE_VIEWS_TABLE, O as EIDOS_FILE_REFERENCES_TABLE, P as SQLITE_HEADER, R as assertEidosFileTableId, S as EIDOS_FILE_COLUMNS_TABLE, T as EIDOS_FILE_FORMAT_VERSION, V as quoteIdentifier, _ as eidosFileLookupDisplayType, a as eidosFileRowQueryPredicateColumns, b as compileEidosFileFormula, c as normalizeEidosFileSorts, d as migrateEidosFileSchema, f as EIDOS_FILE_SCHEMA_SQL, g as eidosFileLookupAggregateSupportsTarget, h as eidosFileFieldStoresJsonArray, i as eidosFileRowQueryAffectedByFieldChanges, j as EIDOS_FILE_SCHEMA_VERSION, k as EIDOS_FILE_REQUIRED_META_KEYS, l as removeEidosFileFilterField, m as setEidosFileMetadata, n as validateEidosFile, o as normalizeEidosFileFilter, p as initializeEidosFileSchema, r as compileEidosFileRowQuery, s as normalizeEidosFileRowQuery, t as EidosFileRuntime, u as getEidosFileSchemaVersion, v as eidosFileLookupStorageCodec, w as EIDOS_FILE_FORMAT, x as compileEidosFileFormulaFields, y as eidosFileLookupTargetDisplayType, z as createEidosFileIdentifier } from "./runtime-CWC5y95G.mjs";
4
+ export { EIDOS_FILE_COLUMNS_TABLE, EIDOS_FILE_EXTENSION, EIDOS_FILE_FORMAT, EIDOS_FILE_FORMAT_VERSION, EIDOS_FILE_META_TABLE, EIDOS_FILE_MIME_TYPE, EIDOS_FILE_REFERENCES_TABLE, EIDOS_FILE_REQUIRED_META_KEYS, EIDOS_FILE_REQUIRED_TABLES, EIDOS_FILE_SCHEMA_SQL, EIDOS_FILE_SCHEMA_VERSION, EIDOS_FILE_TABLES_TABLE, EIDOS_FILE_VIEWS_TABLE, EidosFileError, EidosFileHandlerRegistry, EidosFileHostError, EidosFileRuntime, EidosFileRuntimeDataSource, EidosFileSession, MUTABLE_BASE_FIELD_TYPES, SQLITE_HEADER, assertEidosFileColumnName, assertEidosFileSelectOptions, assertEidosFileTableId, compileEidosFileFormula, compileEidosFileFormulaFields, compileEidosFileRowQuery, createEidosFileIdentifier, createEidosFileUuid, decodeEidosFileAttachmentPaths, decodeEidosFileJsonArray, decodeEidosFileMultiSelectValues, decodeEidosFileRelationDisplay, decodeEidosFileRelationIds, decodeEidosFileStringArray, eidosFileColumnStatLabel, eidosFileColumnStatTypesForField, eidosFileFieldDisplayValues, eidosFileFieldStoresJsonArray, eidosFileLookupAggregateSupportsTarget, eidosFileLookupDisplayType, eidosFileLookupStorageCodec, eidosFileLookupTargetDisplayType, eidosFileRowQueryAffectedByFieldChanges, eidosFileRowQueryPredicateColumns, eidosFileSnapshot, eidosFileTypeHandler, encodeEidosFileAttachmentPaths, encodeEidosFileJsonArray, encodeEidosFileMultiSelectValues, encodeEidosFileRelationIds, getEidosFileSchemaVersion, initializeEidosFileSchema, isMutableEidosFileFieldType, migrateEidosFileSchema, normalizeEidosFileAttachmentPath, normalizeEidosFileFilter, normalizeEidosFileRowQuery, normalizeEidosFileSorts, parseEidosFileSelectOptions, planEidosFileFieldConversion, quoteIdentifier, rawTableNameForId, removeEidosFileFilterField, setEidosFileMetadata, validateEidosFile };
@@ -0,0 +1,232 @@
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/json-array-values.ts
11
+ function decodeEidosFileJsonArray(value) {
12
+ if (typeof value !== "string" || value.length === 0) return [];
13
+ try {
14
+ const parsed = JSON.parse(value);
15
+ if (!Array.isArray(parsed)) return [];
16
+ return parsed.filter((entry) => entry === null || typeof entry === "string" || typeof entry === "number" || typeof entry === "boolean");
17
+ } catch {
18
+ return [];
19
+ }
20
+ }
21
+ function decodeEidosFileStringArray(value) {
22
+ return decodeEidosFileJsonArray(value).filter((entry) => typeof entry === "string");
23
+ }
24
+ function encodeEidosFileJsonArray(values) {
25
+ return values.length > 0 ? JSON.stringify(values) : null;
26
+ }
27
+ //#endregion
28
+ //#region src/file-values.ts
29
+ const EXTERNAL_REFERENCE = /^(?:https?:|data:)/i;
30
+ function normalizeEidosFileAttachmentPath(value) {
31
+ const trimmed = value.trim();
32
+ if (!trimmed || trimmed.includes("\0")) return null;
33
+ if (EXTERNAL_REFERENCE.test(trimmed)) return trimmed;
34
+ if (/^[a-z][a-z\d+.-]*:/i.test(trimmed)) return null;
35
+ const parts = trimmed.replace(/\\/g, "/").split("/");
36
+ const normalized = [];
37
+ for (const part of parts) {
38
+ if (!part || part === ".") continue;
39
+ if (part === "..") {
40
+ if (normalized.length === 0) return null;
41
+ normalized.pop();
42
+ continue;
43
+ }
44
+ normalized.push(part);
45
+ }
46
+ return normalized.length > 0 ? normalized.join("/") : null;
47
+ }
48
+ function decodeEidosFileAttachmentPaths(value) {
49
+ const candidates = decodeEidosFileStringArray(value);
50
+ const seen = /* @__PURE__ */ new Set();
51
+ return candidates.flatMap((candidate) => {
52
+ const normalized = normalizeEidosFileAttachmentPath(candidate);
53
+ if (!normalized || seen.has(normalized)) return [];
54
+ seen.add(normalized);
55
+ return [normalized];
56
+ });
57
+ }
58
+ function encodeEidosFileAttachmentPaths(paths) {
59
+ const normalized = decodeEidosFileAttachmentPaths(JSON.stringify(paths));
60
+ return normalized.length > 0 ? JSON.stringify(normalized) : null;
61
+ }
62
+ //#endregion
63
+ //#region src/select-options.ts
64
+ function parseEidosFileSelectOptions(property) {
65
+ const options = property?.options;
66
+ if (!Array.isArray(options)) return [];
67
+ return options.flatMap((option) => {
68
+ if (typeof option !== "object" || option === null || !("value" in option) || typeof option.value !== "string") return [];
69
+ return [{
70
+ value: option.value,
71
+ color: "color" in option && typeof option.color === "string" ? option.color : "default"
72
+ }];
73
+ });
74
+ }
75
+ function assertEidosFileSelectOptions(property) {
76
+ const rawOptions = property?.options;
77
+ if (!Array.isArray(rawOptions)) throw new EidosFileError("invalid-schema", "Select fields require an options array");
78
+ const options = parseEidosFileSelectOptions(property);
79
+ if (options.length !== rawOptions.length) throw new EidosFileError("invalid-schema", "Every select option requires a string value");
80
+ const values = /* @__PURE__ */ new Set();
81
+ for (const option of options) {
82
+ if (!option.value.trim()) throw new EidosFileError("invalid-schema", "Select option values cannot be empty");
83
+ if (values.has(option.value)) throw new EidosFileError("invalid-schema", `Duplicate select option value: ${option.value}`);
84
+ values.add(option.value);
85
+ }
86
+ return options;
87
+ }
88
+ //#endregion
89
+ //#region src/field-conversion.ts
90
+ const MUTABLE_BASE_FIELD_TYPES = [
91
+ "text",
92
+ "number",
93
+ "checkbox",
94
+ "date",
95
+ "datetime",
96
+ "file",
97
+ "multi-select",
98
+ "rating",
99
+ "select",
100
+ "url"
101
+ ];
102
+ const MUTABLE_TYPE_SET = new Set(MUTABLE_BASE_FIELD_TYPES);
103
+ const OPTION_COLORS = [
104
+ "gray",
105
+ "brown",
106
+ "pink",
107
+ "red",
108
+ "orange",
109
+ "yellow",
110
+ "green",
111
+ "cyan",
112
+ "blue",
113
+ "purple"
114
+ ];
115
+ function isMutableEidosFileFieldType(type) {
116
+ return MUTABLE_TYPE_SET.has(type);
117
+ }
118
+ function decodeEidosFileMultiSelectValues(value) {
119
+ return Array.from(new Set(decodeEidosFileStringArray(value).filter(Boolean)));
120
+ }
121
+ function encodeEidosFileMultiSelectValues(values) {
122
+ return encodeEidosFileJsonArray(Array.from(new Set(values.filter(Boolean))));
123
+ }
124
+ function eidosFileFieldDisplayValues(field, value) {
125
+ if (value === null) return [];
126
+ const primitiveValue = typeof value === "boolean" ? value ? 1 : 0 : value;
127
+ if (field.type === "file") return decodeEidosFileAttachmentPaths(primitiveValue);
128
+ if (field.type === "select") return [String(primitiveValue)].filter(Boolean);
129
+ if (field.type === "multi-select") return decodeEidosFileMultiSelectValues(primitiveValue);
130
+ if (field.storageCodec === "json_array") return decodeEidosFileJsonArray(primitiveValue).flatMap((entry) => entry === null ? [] : [String(entry)]);
131
+ if (field.type === "checkbox") return [value === true || value === 1 || value === "1" ? "true" : "false"];
132
+ if (primitiveValue instanceof Uint8Array) return [];
133
+ const text = String(primitiveValue).trim();
134
+ return text ? [text] : [];
135
+ }
136
+ function optionPlan(field, rows) {
137
+ const existingByName = new Map(parseEidosFileSelectOptions(field.property).map((option) => [option.value, option]));
138
+ return Array.from(new Set(rows.flatMap((row) => eidosFileFieldDisplayValues(field, row.value)))).map((name, index) => existingByName.get(name) ?? {
139
+ value: name,
140
+ color: OPTION_COLORS[index % OPTION_COLORS.length]
141
+ });
142
+ }
143
+ function defaultProperty(type, options) {
144
+ if (type === "select" || type === "multi-select") return { options };
145
+ if (type === "number") return {
146
+ format: "number",
147
+ showAs: "number",
148
+ color: "purple",
149
+ divideBy: 100,
150
+ showNumber: true
151
+ };
152
+ return null;
153
+ }
154
+ function storageCodec(type) {
155
+ if (type === "multi-select" || type === "file") return "json_array";
156
+ return "scalar";
157
+ }
158
+ function numericValue(values) {
159
+ if (values.length === 0) return null;
160
+ const parsed = Number(values[0]);
161
+ return Number.isFinite(parsed) ? parsed : null;
162
+ }
163
+ function checkboxValue(sourceValue, values) {
164
+ if (sourceValue === null) return null;
165
+ if (typeof sourceValue === "number" || typeof sourceValue === "bigint") return sourceValue === 0 || sourceValue === 0n ? 0 : 1;
166
+ const normalized = values[0]?.trim().toLowerCase();
167
+ if (!normalized) return 0;
168
+ if ([
169
+ "0",
170
+ "false",
171
+ "no",
172
+ "off",
173
+ "unchecked"
174
+ ].includes(normalized)) return 0;
175
+ return 1;
176
+ }
177
+ function convertedValue(type, sourceValue, values) {
178
+ if (sourceValue === null) return null;
179
+ if (type === "number") return numericValue(values);
180
+ if (type === "checkbox") return checkboxValue(sourceValue, values);
181
+ if (type === "rating") {
182
+ const value = numericValue(values);
183
+ return value === null ? null : Math.min(5, Math.max(0, Math.round(value)));
184
+ }
185
+ if (type === "file") return encodeEidosFileAttachmentPaths(values);
186
+ if (type === "select") return values[0] || null;
187
+ if (type === "multi-select") return encodeEidosFileMultiSelectValues(values);
188
+ return values.length > 0 ? values.join(", ") : null;
189
+ }
190
+ function planEidosFileFieldConversion(field, rows, targetType) {
191
+ return {
192
+ property: defaultProperty(targetType, targetType === "select" || targetType === "multi-select" ? optionPlan(field, rows) : []),
193
+ storageCodec: storageCodec(targetType),
194
+ values: rows.map((row) => {
195
+ const values = eidosFileFieldDisplayValues(field, row.value);
196
+ return {
197
+ id: row.id,
198
+ value: convertedValue(targetType, row.value, values)
199
+ };
200
+ })
201
+ };
202
+ }
203
+ //#endregion
204
+ //#region src/relation-values.ts
205
+ const MAX_RELATION_VALUES = 500;
206
+ function decodeEidosFileRelationIds(value) {
207
+ return Array.from(new Set(decodeEidosFileStringArray(value).map((entry) => entry.trim()).filter(Boolean).slice(0, MAX_RELATION_VALUES)));
208
+ }
209
+ function encodeEidosFileRelationIds(ids) {
210
+ const normalized = Array.from(new Set(ids.map((id) => id.trim()).filter(Boolean))).slice(0, MAX_RELATION_VALUES);
211
+ return normalized.length > 0 ? JSON.stringify(normalized) : null;
212
+ }
213
+ function decodeEidosFileRelationDisplay(value) {
214
+ if (typeof value !== "string" || value.length === 0) return [];
215
+ try {
216
+ const parsed = JSON.parse(value);
217
+ if (!Array.isArray(parsed)) return [];
218
+ return parsed.slice(0, MAX_RELATION_VALUES).flatMap((entry) => {
219
+ if (typeof entry !== "object" || entry === null || !("id" in entry) || !("title" in entry) || typeof entry.id !== "string" || typeof entry.title !== "string") return [];
220
+ return [{
221
+ id: entry.id,
222
+ title: entry.title
223
+ }];
224
+ });
225
+ } catch {
226
+ return [];
227
+ }
228
+ }
229
+ //#endregion
230
+ export { encodeEidosFileJsonArray as _, decodeEidosFileMultiSelectValues as a, isMutableEidosFileFieldType as c, parseEidosFileSelectOptions as d, decodeEidosFileAttachmentPaths as f, decodeEidosFileStringArray as g, decodeEidosFileJsonArray as h, MUTABLE_BASE_FIELD_TYPES as i, planEidosFileFieldConversion as l, normalizeEidosFileAttachmentPath as m, decodeEidosFileRelationIds as n, eidosFileFieldDisplayValues as o, encodeEidosFileAttachmentPaths as p, encodeEidosFileRelationIds as r, encodeEidosFileMultiSelectValues as s, decodeEidosFileRelationDisplay as t, assertEidosFileSelectOptions as u, EidosFileError as v };
231
+
232
+ //# sourceMappingURL=relation-values-B0JhHBjZ.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"relation-values-B0JhHBjZ.mjs","names":[],"sources":["../src/errors.ts","../src/json-array-values.ts","../src/file-values.ts","../src/select-options.ts","../src/field-conversion.ts","../src/relation-values.ts"],"sourcesContent":["export type EidosFileErrorCode =\n | \"invalid-sqlite\"\n | \"not-eidos-file\"\n | \"unsupported-format\"\n | \"invalid-schema\"\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 type { EidosFileRowValue } from \"./types\"\n\nexport type EidosFileJsonArrayValue = string | number | boolean | null\n\nexport function decodeEidosFileJsonArray(\n value: EidosFileRowValue | undefined\n): EidosFileJsonArrayValue[] {\n if (typeof value !== \"string\" || value.length === 0) return []\n try {\n const parsed: unknown = JSON.parse(value)\n if (!Array.isArray(parsed)) return []\n return parsed.filter(\n (entry): entry is EidosFileJsonArrayValue =>\n entry === null ||\n typeof entry === \"string\" ||\n typeof entry === \"number\" ||\n typeof entry === \"boolean\"\n )\n } catch {\n return []\n }\n}\n\nexport function decodeEidosFileStringArray(\n value: EidosFileRowValue | undefined\n): string[] {\n return decodeEidosFileJsonArray(value).filter(\n (entry): entry is string => typeof entry === \"string\"\n )\n}\n\nexport function encodeEidosFileJsonArray(\n values: readonly EidosFileJsonArrayValue[]\n): string | null {\n return values.length > 0 ? JSON.stringify(values) : null\n}\n","import type { EidosFileRowValue } from \"./types\"\nimport { decodeEidosFileStringArray } from \"./json-array-values\"\n\nconst EXTERNAL_REFERENCE = /^(?:https?:|data:)/i\n\nexport function normalizeEidosFileAttachmentPath(value: string): string | null {\n const trimmed = value.trim()\n if (!trimmed || trimmed.includes(\"\\0\")) return null\n if (EXTERNAL_REFERENCE.test(trimmed)) return trimmed\n if (/^[a-z][a-z\\d+.-]*:/i.test(trimmed)) 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 return normalized.length > 0 ? normalized.join(\"/\") : null\n}\n\nexport function decodeEidosFileAttachmentPaths(\n value: EidosFileRowValue | undefined\n): string[] {\n const candidates = decodeEidosFileStringArray(value)\n const seen = new Set<string>()\n return candidates.flatMap((candidate) => {\n const normalized = normalizeEidosFileAttachmentPath(candidate)\n if (!normalized || seen.has(normalized)) return []\n seen.add(normalized)\n return [normalized]\n })\n}\n\nexport function encodeEidosFileAttachmentPaths(\n paths: readonly string[]\n): string | null {\n const normalized = decodeEidosFileAttachmentPaths(JSON.stringify(paths))\n return normalized.length > 0 ? JSON.stringify(normalized) : null\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 (\n typeof option !== \"object\" ||\n option === null ||\n !(\"value\" in option) ||\n typeof option.value !== \"string\"\n ) {\n return []\n }\n return [\n {\n value: option.value,\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 (!Array.isArray(rawOptions)) {\n throw new EidosFileError(\n \"invalid-schema\",\n \"Select fields require an options 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 value\"\n )\n }\n const values = new Set<string>()\n for (const option of options) {\n if (!option.value.trim()) {\n throw new EidosFileError(\n \"invalid-schema\",\n \"Select option values cannot be empty\"\n )\n }\n if (values.has(option.value)) {\n throw new EidosFileError(\n \"invalid-schema\",\n `Duplicate select option value: ${option.value}`\n )\n }\n values.add(option.value)\n }\n return options\n}\n","import type { EidosFileSqlPrimitive } from \"./connection\"\nimport {\n decodeEidosFileAttachmentPaths,\n encodeEidosFileAttachmentPaths,\n} from \"./file-values\"\nimport {\n decodeEidosFileJsonArray,\n decodeEidosFileStringArray,\n encodeEidosFileJsonArray,\n} from \"./json-array-values\"\nimport { parseEidosFileSelectOptions } from \"./select-options\"\nimport type {\n EidosFileFieldInfo,\n EidosFileFieldType,\n EidosFileSelectOption,\n EidosFileStorageCodec,\n} from \"./types\"\n\nexport const MUTABLE_BASE_FIELD_TYPES = [\n \"text\",\n \"number\",\n \"checkbox\",\n \"date\",\n \"datetime\",\n \"file\",\n \"multi-select\",\n \"rating\",\n \"select\",\n \"url\",\n] as const satisfies readonly EidosFileFieldType[]\n\nexport type MutableEidosFileFieldType =\n (typeof MUTABLE_BASE_FIELD_TYPES)[number]\n\nconst MUTABLE_TYPE_SET = new Set<EidosFileFieldType>(MUTABLE_BASE_FIELD_TYPES)\nconst OPTION_COLORS = [\n \"gray\",\n \"brown\",\n \"pink\",\n \"red\",\n \"orange\",\n \"yellow\",\n \"green\",\n \"cyan\",\n \"blue\",\n \"purple\",\n]\n\nexport interface EidosFileFieldValueRow {\n id: string\n value: EidosFileSqlPrimitive\n}\n\nexport interface EidosFileFieldConversionPlan {\n property: Record<string, unknown> | null\n storageCodec: EidosFileStorageCodec\n values: Array<{ id: string; value: EidosFileSqlPrimitive }>\n}\n\nexport function isMutableEidosFileFieldType(\n type: EidosFileFieldType\n): type is MutableEidosFileFieldType {\n return MUTABLE_TYPE_SET.has(type)\n}\n\nexport function decodeEidosFileMultiSelectValues(\n value: EidosFileSqlPrimitive\n): string[] {\n return Array.from(new Set(decodeEidosFileStringArray(value).filter(Boolean)))\n}\n\nexport function encodeEidosFileMultiSelectValues(\n values: readonly string[]\n): string | null {\n return encodeEidosFileJsonArray(Array.from(new Set(values.filter(Boolean))))\n}\n\nexport function eidosFileFieldDisplayValues(\n field: EidosFileFieldInfo,\n value: EidosFileSqlPrimitive | boolean\n): string[] {\n if (value === null) return []\n const primitiveValue: EidosFileSqlPrimitive =\n typeof value === \"boolean\" ? (value ? 1 : 0) : value\n if (field.type === \"file\")\n return decodeEidosFileAttachmentPaths(primitiveValue)\n if (field.type === \"select\") {\n return [String(primitiveValue)].filter(Boolean)\n }\n if (field.type === \"multi-select\") {\n return decodeEidosFileMultiSelectValues(primitiveValue)\n }\n if (field.storageCodec === \"json_array\") {\n return decodeEidosFileJsonArray(primitiveValue).flatMap((entry) =>\n entry === null ? [] : [String(entry)]\n )\n }\n if (field.type === \"checkbox\") {\n return [value === true || value === 1 || value === \"1\" ? \"true\" : \"false\"]\n }\n if (primitiveValue instanceof Uint8Array) return []\n const text = String(primitiveValue).trim()\n return text ? [text] : []\n}\n\nfunction optionPlan(\n field: EidosFileFieldInfo,\n rows: EidosFileFieldValueRow[]\n): EidosFileSelectOption[] {\n const existingByName = new Map(\n parseEidosFileSelectOptions(field.property).map((option) => [\n option.value,\n option,\n ])\n )\n const names = Array.from(\n new Set(\n rows.flatMap((row) => eidosFileFieldDisplayValues(field, row.value))\n )\n )\n return names.map(\n (name, index) =>\n existingByName.get(name) ?? {\n value: name,\n color: OPTION_COLORS[index % OPTION_COLORS.length],\n }\n )\n}\n\nfunction defaultProperty(\n type: MutableEidosFileFieldType,\n options: EidosFileSelectOption[]\n): Record<string, unknown> | null {\n if (type === \"select\" || type === \"multi-select\") return { options }\n if (type === \"number\") {\n return {\n format: \"number\",\n showAs: \"number\",\n color: \"purple\",\n divideBy: 100,\n showNumber: true,\n }\n }\n return null\n}\n\nfunction storageCodec(type: MutableEidosFileFieldType): EidosFileStorageCodec {\n if (type === \"multi-select\" || type === \"file\") return \"json_array\"\n return \"scalar\"\n}\n\nfunction numericValue(values: string[]): number | null {\n if (values.length === 0) return null\n const parsed = Number(values[0])\n return Number.isFinite(parsed) ? parsed : null\n}\n\nfunction checkboxValue(\n sourceValue: EidosFileSqlPrimitive,\n values: string[]\n): number | null {\n if (sourceValue === null) return null\n if (typeof sourceValue === \"number\" || typeof sourceValue === \"bigint\") {\n return sourceValue === 0 || sourceValue === 0n ? 0 : 1\n }\n const normalized = values[0]?.trim().toLowerCase()\n if (!normalized) return 0\n if ([\"0\", \"false\", \"no\", \"off\", \"unchecked\"].includes(normalized)) return 0\n return 1\n}\n\nfunction convertedValue(\n type: MutableEidosFileFieldType,\n sourceValue: EidosFileSqlPrimitive,\n values: string[]\n): EidosFileSqlPrimitive {\n if (sourceValue === null) return null\n if (type === \"number\") return numericValue(values)\n if (type === \"checkbox\") return checkboxValue(sourceValue, values)\n if (type === \"rating\") {\n const value = numericValue(values)\n return value === null ? null : Math.min(5, Math.max(0, Math.round(value)))\n }\n if (type === \"file\") return encodeEidosFileAttachmentPaths(values)\n if (type === \"select\") {\n return values[0] || null\n }\n if (type === \"multi-select\") {\n return encodeEidosFileMultiSelectValues(values)\n }\n return values.length > 0 ? values.join(\", \") : null\n}\n\nexport function planEidosFileFieldConversion(\n field: EidosFileFieldInfo,\n rows: EidosFileFieldValueRow[],\n targetType: MutableEidosFileFieldType\n): EidosFileFieldConversionPlan {\n const options =\n targetType === \"select\" || targetType === \"multi-select\"\n ? optionPlan(field, rows)\n : []\n return {\n property: defaultProperty(targetType, options),\n storageCodec: storageCodec(targetType),\n values: rows.map((row) => {\n const values = eidosFileFieldDisplayValues(field, row.value)\n return {\n id: row.id,\n value: convertedValue(targetType, row.value, values),\n }\n }),\n }\n}\n","import type { EidosFileRelationValue, EidosFileRowValue } from \"./types\"\nimport { decodeEidosFileStringArray } from \"./json-array-values\"\n\nconst MAX_RELATION_VALUES = 500\n\nexport function decodeEidosFileRelationIds(\n value: EidosFileRowValue | undefined\n): string[] {\n return Array.from(\n new Set(\n decodeEidosFileStringArray(value)\n .map((entry) => entry.trim())\n .filter(Boolean)\n .slice(0, MAX_RELATION_VALUES)\n )\n )\n}\n\nexport function encodeEidosFileRelationIds(\n ids: readonly string[]\n): string | null {\n const normalized = Array.from(\n new Set(ids.map((id) => id.trim()).filter(Boolean))\n ).slice(0, MAX_RELATION_VALUES)\n return normalized.length > 0 ? JSON.stringify(normalized) : null\n}\n\nexport function decodeEidosFileRelationDisplay(\n value: EidosFileRowValue | undefined\n): EidosFileRelationValue[] {\n if (typeof value !== \"string\" || value.length === 0) return []\n try {\n const parsed: unknown = JSON.parse(value)\n if (!Array.isArray(parsed)) return []\n return parsed.slice(0, MAX_RELATION_VALUES).flatMap((entry) => {\n if (\n typeof entry !== \"object\" ||\n entry === null ||\n !(\"id\" in entry) ||\n !(\"title\" in entry) ||\n typeof entry.id !== \"string\" ||\n typeof entry.title !== \"string\"\n ) {\n return []\n }\n return [{ id: entry.id, title: entry.title }]\n })\n } catch {\n return []\n }\n}\n"],"mappings":";AAqBA,IAAa,iBAAb,cAAoC,MAAM;CACxC,YACE,MACA,SACA;AACA,QAAM,QAAQ;AAHL,OAAA,OAAA;AAIT,OAAK,OAAO;;;;;ACvBhB,SAAgB,yBACd,OAC2B;AAC3B,KAAI,OAAO,UAAU,YAAY,MAAM,WAAW,EAAG,QAAO,EAAE;AAC9D,KAAI;EACF,MAAM,SAAkB,KAAK,MAAM,MAAM;AACzC,MAAI,CAAC,MAAM,QAAQ,OAAO,CAAE,QAAO,EAAE;AACrC,SAAO,OAAO,QACX,UACC,UAAU,QACV,OAAO,UAAU,YACjB,OAAO,UAAU,YACjB,OAAO,UAAU,UACpB;SACK;AACN,SAAO,EAAE;;;AAIb,SAAgB,2BACd,OACU;AACV,QAAO,yBAAyB,MAAM,CAAC,QACpC,UAA2B,OAAO,UAAU,SAC9C;;AAGH,SAAgB,yBACd,QACe;AACf,QAAO,OAAO,SAAS,IAAI,KAAK,UAAU,OAAO,GAAG;;;;AC/BtD,MAAM,qBAAqB;AAE3B,SAAgB,iCAAiC,OAA8B;CAC7E,MAAM,UAAU,MAAM,MAAM;AAC5B,KAAI,CAAC,WAAW,QAAQ,SAAS,KAAK,CAAE,QAAO;AAC/C,KAAI,mBAAmB,KAAK,QAAQ,CAAE,QAAO;AAC7C,KAAI,sBAAsB,KAAK,QAAQ,CAAE,QAAO;CAEhD,MAAM,QAAQ,QAAQ,QAAQ,OAAO,IAAI,CAAC,MAAM,IAAI;CACpD,MAAM,aAAuB,EAAE;AAC/B,MAAK,MAAM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