@needle-tools/addressing 0.3.4 → 0.4.0-1791982227.dramatic-tempura.8b3a85e
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/Readme.md +151 -70
- package/dist/address.d.ts +5 -0
- package/dist/address.js +25 -3
- package/dist/document/assets.d.ts +27 -0
- package/dist/document/assets.js +75 -0
- package/dist/document/collectionSelector.d.ts +9 -0
- package/dist/document/collectionSelector.js +29 -0
- package/dist/document/evaluate.d.ts +86 -0
- package/dist/document/evaluate.js +1082 -0
- package/dist/document/index.d.ts +11 -0
- package/dist/document/index.js +11 -0
- package/dist/document/inspection.d.ts +30 -0
- package/dist/document/inspection.js +130 -0
- package/dist/document/loadedDocument.d.ts +18 -0
- package/dist/document/loadedDocument.js +35 -0
- package/dist/document/references.d.ts +7 -0
- package/dist/document/references.js +36 -0
- package/dist/document/runtime.d.ts +119 -0
- package/dist/document/runtime.js +1 -0
- package/dist/document/types.d.ts +240 -0
- package/dist/document/types.js +43 -0
- package/dist/document/validation.d.ts +36 -0
- package/dist/document/validation.js +222 -0
- package/dist/document/valueCodecs.d.ts +20 -0
- package/dist/document/valueCodecs.js +3 -0
- package/dist/document/write.d.ts +31 -0
- package/dist/document/write.js +131 -0
- package/dist/id.d.ts +2 -0
- package/dist/id.js +4 -0
- package/dist/index.d.ts +2 -1
- package/dist/index.js +2 -1
- package/dist/loadedGltf.d.ts +32 -0
- package/dist/loadedGltf.js +62 -0
- package/dist/resolve.js +8 -6
- package/package.json +10 -2
- package/src/address.ts +169 -144
- package/src/anchor.ts +71 -71
- package/src/document/assets.ts +77 -0
- package/src/document/collectionSelector.ts +37 -0
- package/src/document/evaluate.ts +1111 -0
- package/src/document/index.ts +11 -0
- package/src/document/inspection.ts +123 -0
- package/src/document/loadedDocument.ts +48 -0
- package/src/document/references.ts +41 -0
- package/src/document/runtime.ts +113 -0
- package/src/document/schema.json +293 -0
- package/src/document/types.ts +265 -0
- package/src/document/validation.ts +226 -0
- package/src/document/valueCodecs.ts +23 -0
- package/src/document/write.ts +132 -0
- package/src/gltf.ts +33 -33
- package/src/hash.ts +58 -58
- package/src/id.ts +206 -201
- package/src/index.ts +49 -46
- package/src/loadedGltf.ts +93 -0
- package/src/resolve.ts +319 -317
- package/src/target.ts +126 -126
- package/src/uuid.ts +48 -48
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
export interface DocumentCollectionSelectorOptions {
|
|
2
|
+
matchesComponentType?(component: object, name: string): boolean;
|
|
3
|
+
matchesComponentGuid?(component: object, guid: string): boolean;
|
|
4
|
+
deriveComponentGuid?(referenceId: string, fileGuid: string): string;
|
|
5
|
+
referenceId?: string;
|
|
6
|
+
report?(message: string): void;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
/** Resolve an index or field qualifier; ambiguous identities never select an arbitrary member. */
|
|
10
|
+
export function resolveDocumentCollectionElement(
|
|
11
|
+
collection: readonly unknown[], selector: string, options: DocumentCollectionSelectorOptions = {},
|
|
12
|
+
): unknown {
|
|
13
|
+
if (/^\d+$/.test(selector)) return collection[Number(selector)];
|
|
14
|
+
const qualifier = /^([A-Za-z_][A-Za-z0-9_-]*):([\s\S]*)$/.exec(selector);
|
|
15
|
+
if (!qualifier) {
|
|
16
|
+
options.report?.(`"${selector}" is neither an index nor a <field>:<value> qualifier`);
|
|
17
|
+
return undefined;
|
|
18
|
+
}
|
|
19
|
+
const [, field, value] = qualifier;
|
|
20
|
+
const elements = collection.filter((element): element is Record<string, unknown> =>
|
|
21
|
+
element !== null && typeof element === "object");
|
|
22
|
+
let matches = elements.filter(element => {
|
|
23
|
+
if (field === "type") return options.matchesComponentType?.(element, value) ?? element.constructor?.name === value;
|
|
24
|
+
if (field === "guid") return options.matchesComponentGuid?.(element, value)
|
|
25
|
+
?? (element.guid === value || element.needle_editor_guid === value);
|
|
26
|
+
return element[field] === value;
|
|
27
|
+
});
|
|
28
|
+
if (!matches.length && field === "guid" && options.referenceId && options.deriveComponentGuid) {
|
|
29
|
+
const derived = options.deriveComponentGuid(options.referenceId, value);
|
|
30
|
+
matches = elements.filter(element => element.guid === derived);
|
|
31
|
+
}
|
|
32
|
+
if (matches.length > 1) {
|
|
33
|
+
options.report?.(`"${selector}" matched ${matches.length} elements ? the document must name one unambiguously`);
|
|
34
|
+
return undefined;
|
|
35
|
+
}
|
|
36
|
+
return matches[0];
|
|
37
|
+
}
|