@kodexa-ai/document-wasm-ts 8.0.0-develop-20922720042 → 8.0.0-develop-20929633869

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,362 @@
1
+ /**
2
+ * TaxonomyAccessor - Accessor for taxonomies within a KddbDocument
3
+ *
4
+ * Provides access to taxonomy definitions stored in the document.
5
+ * Taxonomies define the structure and types of data that can be extracted,
6
+ * including taxon paths, data types, validation rules, and metadata.
7
+ *
8
+ * Taxonomies are hierarchical structures where each node (taxon) defines
9
+ * a field type with properties like data type, validation rules, and UI hints.
10
+ * Storing taxonomies in the document enables automatic taxon resolution
11
+ * when creating data attributes.
12
+ *
13
+ * Usage:
14
+ * - document.taxonomies.store(taxonomy) - Store a taxonomy definition
15
+ * - document.taxonomies.getByRef(ref) - Retrieve by reference
16
+ * - document.taxonomies.getAll() - List all taxonomies
17
+ * - document.taxonomies.getTaxonByPath(ref, path) - Get specific taxon
18
+ *
19
+ * @example
20
+ * ```typescript
21
+ * // Store a taxonomy
22
+ * const taxonomy = await doc.taxonomies.store({
23
+ * ref: "acme/invoice:1.0.0",
24
+ * name: "Invoice Schema",
25
+ * taxons: [{
26
+ * name: "Invoice",
27
+ * group: true,
28
+ * children: [{
29
+ * name: "Amount",
30
+ * taxonType: "currency",
31
+ * path: "Invoice/Amount"
32
+ * }]
33
+ * }]
34
+ * });
35
+ *
36
+ * // Create an attribute using taxon resolution
37
+ * const attr = await doc.dataAttributes.create(dataObjectId, {
38
+ * taxonomyRef: "acme/invoice:1.0.0",
39
+ * taxonPath: "Invoice/Amount",
40
+ * decimalValue: 150.00
41
+ * });
42
+ * // attr.typeAtCreation is automatically set to "currency"
43
+ * ```
44
+ */
45
+ import type { Taxonomy, Taxon } from './wasm/types';
46
+ /**
47
+ * Input type for storing a taxonomy
48
+ */
49
+ export interface TaxonomyInput {
50
+ /**
51
+ * Unique reference identifier for the taxonomy
52
+ * @example "acme/invoice:1.0.0"
53
+ */
54
+ ref: string;
55
+ /**
56
+ * Human-readable name for the taxonomy
57
+ * @example "Invoice Processing Schema"
58
+ */
59
+ name: string;
60
+ /**
61
+ * Optional version string
62
+ * @example "1.0.0"
63
+ */
64
+ version?: string;
65
+ /**
66
+ * Type of taxonomy (e.g., "EXTRACTION", "LABELING")
67
+ */
68
+ type?: string;
69
+ /**
70
+ * Whether the taxonomy is enabled
71
+ * @default true
72
+ */
73
+ enabled?: boolean;
74
+ /**
75
+ * Optional description of the taxonomy
76
+ */
77
+ description?: string;
78
+ /**
79
+ * Root-level taxons in the taxonomy hierarchy
80
+ */
81
+ taxons: TaxonInput[];
82
+ }
83
+ /**
84
+ * Input type for defining a taxon (taxonomy node)
85
+ */
86
+ export interface TaxonInput {
87
+ /**
88
+ * Optional unique identifier for the taxon
89
+ */
90
+ id?: string;
91
+ /**
92
+ * Internal name used for tag matching and path construction
93
+ * @example "LineItemAmount"
94
+ */
95
+ name: string;
96
+ /**
97
+ * Human-readable label for UI display
98
+ * @example "Line Item Amount"
99
+ */
100
+ label?: string;
101
+ /**
102
+ * External name used in exports and serialization
103
+ * @example "lineItemAmount"
104
+ */
105
+ externalName?: string;
106
+ /**
107
+ * Optional description of this taxon
108
+ */
109
+ description?: string;
110
+ /**
111
+ * Full path in taxonomy hierarchy (auto-computed if not provided)
112
+ * @example "Invoice/LineItems/Amount"
113
+ */
114
+ path?: string;
115
+ /**
116
+ * Data type for this taxon
117
+ * @example "currency", "string", "date", "boolean", "decimal"
118
+ */
119
+ taxonType?: string;
120
+ /**
121
+ * Whether this taxon represents a group (container for child taxons)
122
+ * @default false
123
+ */
124
+ group?: boolean;
125
+ /**
126
+ * Whether the taxon is enabled for extraction
127
+ * @default true
128
+ */
129
+ enabled?: boolean;
130
+ /**
131
+ * Whether the value can be null
132
+ * @default false
133
+ */
134
+ nullable?: boolean;
135
+ /**
136
+ * Display order within parent
137
+ */
138
+ order?: number;
139
+ /**
140
+ * Value extraction path type
141
+ * @example "EXTERNAL", "EXPRESSION", "METADATA"
142
+ */
143
+ valuePath?: string;
144
+ /**
145
+ * Expression for value extraction (when valuePath is "EXPRESSION")
146
+ */
147
+ expression?: string;
148
+ /**
149
+ * Semantic definition for formulas
150
+ */
151
+ semanticDefinition?: string;
152
+ /**
153
+ * Whether to evaluate post-expression after extraction
154
+ */
155
+ usePostExpression?: boolean;
156
+ /**
157
+ * Post-processing expression
158
+ */
159
+ postExpression?: string;
160
+ /**
161
+ * Whether to use fallback expression when no value found
162
+ */
163
+ enableFallbackExpression?: boolean;
164
+ /**
165
+ * Fallback expression when primary extraction fails
166
+ */
167
+ fallbackExpression?: string;
168
+ /**
169
+ * Whether this taxon can have multiple values
170
+ */
171
+ multiValue?: boolean;
172
+ /**
173
+ * Whether users can edit this value in the UI
174
+ */
175
+ userEditable?: boolean;
176
+ /**
177
+ * Type-specific feature configuration
178
+ */
179
+ typeFeatures?: Record<string, unknown>;
180
+ /**
181
+ * Additional properties
182
+ */
183
+ properties?: Record<string, unknown>;
184
+ /**
185
+ * Generic metadata
186
+ */
187
+ metadata?: Record<string, unknown>;
188
+ /**
189
+ * Child taxons in the hierarchy
190
+ */
191
+ children?: TaxonInput[];
192
+ }
193
+ /**
194
+ * TaxonomyAccessor - access taxonomies stored in a document
195
+ *
196
+ * This is an internal accessor class. Access via document.taxonomies property.
197
+ */
198
+ export declare class TaxonomyAccessor {
199
+ private documentRef;
200
+ constructor(documentRef: number);
201
+ /**
202
+ * Store or update a taxonomy in the document
203
+ *
204
+ * If a taxonomy with the same ref already exists, it will be updated.
205
+ * The taxon hierarchy paths are automatically computed if not provided.
206
+ *
207
+ * @param taxonomy The taxonomy definition to store
208
+ * @returns The stored taxonomy with assigned ID
209
+ * @throws Error if storage fails
210
+ *
211
+ * @example
212
+ * ```typescript
213
+ * const stored = await doc.taxonomies.store({
214
+ * ref: "company/schema:1.0.0",
215
+ * name: "Company Schema",
216
+ * type: "EXTRACTION",
217
+ * taxons: [
218
+ * {
219
+ * name: "Invoice",
220
+ * group: true,
221
+ * children: [
222
+ * { name: "Number", taxonType: "string" },
223
+ * { name: "Amount", taxonType: "currency" }
224
+ * ]
225
+ * }
226
+ * ]
227
+ * });
228
+ * ```
229
+ */
230
+ store(taxonomy: TaxonomyInput): Promise<Taxonomy>;
231
+ /**
232
+ * Get a taxonomy by its reference identifier
233
+ *
234
+ * @param ref The taxonomy reference (e.g., "kodexa/invoice:1.0.0")
235
+ * @returns The taxonomy or null if not found
236
+ *
237
+ * @example
238
+ * ```typescript
239
+ * const taxonomy = await doc.taxonomies.getByRef("acme/invoice:1.0.0");
240
+ * if (taxonomy) {
241
+ * console.log(`Found: ${taxonomy.name} with ${taxonomy.taxons.length} root taxons`);
242
+ * }
243
+ * ```
244
+ */
245
+ getByRef(ref: string): Promise<Taxonomy | null>;
246
+ /**
247
+ * Get all taxonomies stored in the document
248
+ *
249
+ * @returns Array of all taxonomies
250
+ *
251
+ * @example
252
+ * ```typescript
253
+ * const all = await doc.taxonomies.getAll();
254
+ * console.log(`Document has ${all.length} taxonomies`);
255
+ * for (const tax of all) {
256
+ * console.log(`- ${tax.ref}: ${tax.name}`);
257
+ * }
258
+ * ```
259
+ */
260
+ getAll(): Promise<Taxonomy[]>;
261
+ /**
262
+ * Delete a taxonomy by its reference
263
+ *
264
+ * @param ref The taxonomy reference to delete
265
+ * @returns true if deleted, false if not found
266
+ *
267
+ * @example
268
+ * ```typescript
269
+ * const deleted = await doc.taxonomies.delete("old/schema:1.0.0");
270
+ * if (deleted) {
271
+ * console.log("Taxonomy removed");
272
+ * }
273
+ * ```
274
+ */
275
+ delete(ref: string): Promise<boolean>;
276
+ /**
277
+ * Get a specific taxon by path within a taxonomy
278
+ *
279
+ * This is useful for looking up taxon metadata like type, label,
280
+ * or validation rules before creating attributes.
281
+ *
282
+ * @param taxonomyRef The taxonomy reference
283
+ * @param taxonPath The taxon path (e.g., "Invoice/LineItem/Amount")
284
+ * @returns The taxon or null if not found
285
+ *
286
+ * @example
287
+ * ```typescript
288
+ * const taxon = await doc.taxonomies.getTaxonByPath(
289
+ * "acme/invoice:1.0.0",
290
+ * "Invoice/LineItem/Amount"
291
+ * );
292
+ * if (taxon) {
293
+ * console.log(`Type: ${taxon.taxonType}, Label: ${taxon.label}`);
294
+ * }
295
+ * ```
296
+ */
297
+ getTaxonByPath(taxonomyRef: string, taxonPath: string): Promise<Taxon | null>;
298
+ /**
299
+ * Check if a taxonomy exists in the document
300
+ *
301
+ * @param ref The taxonomy reference to check
302
+ * @returns true if taxonomy exists
303
+ *
304
+ * @example
305
+ * ```typescript
306
+ * if (await doc.taxonomies.exists("acme/invoice:1.0.0")) {
307
+ * // Use the taxonomy for attribute creation
308
+ * } else {
309
+ * // Need to load/store the taxonomy first
310
+ * }
311
+ * ```
312
+ */
313
+ exists(ref: string): Promise<boolean>;
314
+ /**
315
+ * Get all taxon paths from a taxonomy (flattened)
316
+ *
317
+ * Useful for populating dropdowns or validating paths.
318
+ *
319
+ * @param taxonomyRef The taxonomy reference
320
+ * @returns Array of all taxon paths in the taxonomy
321
+ *
322
+ * @example
323
+ * ```typescript
324
+ * const paths = await doc.taxonomies.getAllPaths("acme/invoice:1.0.0");
325
+ * // ["Invoice", "Invoice/Number", "Invoice/Amount", "Invoice/LineItems", ...]
326
+ * ```
327
+ */
328
+ getAllPaths(taxonomyRef: string): Promise<string[]>;
329
+ /**
330
+ * Find taxons by type within a taxonomy
331
+ *
332
+ * @param taxonomyRef The taxonomy reference
333
+ * @param taxonType The taxon type to filter by (e.g., "currency", "date")
334
+ * @returns Array of matching taxons
335
+ *
336
+ * @example
337
+ * ```typescript
338
+ * const currencyFields = await doc.taxonomies.findByType(
339
+ * "acme/invoice:1.0.0",
340
+ * "currency"
341
+ * );
342
+ * console.log(`Found ${currencyFields.length} currency fields`);
343
+ * ```
344
+ */
345
+ findByType(taxonomyRef: string, taxonType: string): Promise<Taxon[]>;
346
+ /**
347
+ * Find group taxons (containers) within a taxonomy
348
+ *
349
+ * @param taxonomyRef The taxonomy reference
350
+ * @returns Array of group taxons
351
+ *
352
+ * @example
353
+ * ```typescript
354
+ * const groups = await doc.taxonomies.findGroups("acme/invoice:1.0.0");
355
+ * for (const group of groups) {
356
+ * console.log(`Group: ${group.path} has ${group.children?.length || 0} children`);
357
+ * }
358
+ * ```
359
+ */
360
+ findGroups(taxonomyRef: string): Promise<Taxon[]>;
361
+ }
362
+ //# sourceMappingURL=TaxonomyAccessor.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"TaxonomyAccessor.d.ts","sourceRoot":"","sources":["../src/TaxonomyAccessor.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2CG;AAEH,OAAO,KAAK,EAAE,QAAQ,EAAE,KAAK,EAAE,MAAM,cAAc,CAAC;AAGpD;;GAEG;AACH,MAAM,WAAW,aAAa;IAC5B;;;OAGG;IACH,GAAG,EAAE,MAAM,CAAC;IAEZ;;;OAGG;IACH,IAAI,EAAE,MAAM,CAAC;IAEb;;;OAGG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC;IAEjB;;OAEG;IACH,IAAI,CAAC,EAAE,MAAM,CAAC;IAEd;;;OAGG;IACH,OAAO,CAAC,EAAE,OAAO,CAAC;IAElB;;OAEG;IACH,WAAW,CAAC,EAAE,MAAM,CAAC;IAErB;;OAEG;IACH,MAAM,EAAE,UAAU,EAAE,CAAC;CACtB;AAED;;GAEG;AACH,MAAM,WAAW,UAAU;IACzB;;OAEG;IACH,EAAE,CAAC,EAAE,MAAM,CAAC;IAEZ;;;OAGG;IACH,IAAI,EAAE,MAAM,CAAC;IAEb;;;OAGG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC;IAEf;;;OAGG;IACH,YAAY,CAAC,EAAE,MAAM,CAAC;IAEtB;;OAEG;IACH,WAAW,CAAC,EAAE,MAAM,CAAC;IAErB;;;OAGG;IACH,IAAI,CAAC,EAAE,MAAM,CAAC;IAEd;;;OAGG;IACH,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AC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,QAAQ,GAAG,IAAI,CAAC;IAYrD;;;;;;;;;;;;;OAaG;IACG,MAAM,IAAI,OAAO,CAAC,QAAQ,EAAE,CAAC;IAYnC;;;;;;;;;;;;;OAaG;IACG,MAAM,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAS3C;;;;;;;;;;;;;;;;;;;;OAoBG;IACG,cAAc,CAAC,WAAW,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,KAAK,GAAG,IAAI,CAAC;IAYnF;;;;;;;;;;;;;;OAcG;IACG,MAAM,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAK3C;;;;;;;;;;;;;OAaG;IACG,WAAW,CAAC,WAAW,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC;IAkBzD;;;;;;;;;;;;;;;OAeG;IACG,UAAU,CAAC,WAAW,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,KAAK,EAAE,CAAC;IAkB1E;;;;;;;;;;;;;OAaG;IACG,UAAU,CAAC,WAAW,EAAE,MAAM,GAAG,OAAO,CAAC,KAAK,EAAE,CAAC;CAiBxD"}
@@ -0,0 +1,321 @@
1
+ /**
2
+ * TaxonomyAccessor - Accessor for taxonomies within a KddbDocument
3
+ *
4
+ * Provides access to taxonomy definitions stored in the document.
5
+ * Taxonomies define the structure and types of data that can be extracted,
6
+ * including taxon paths, data types, validation rules, and metadata.
7
+ *
8
+ * Taxonomies are hierarchical structures where each node (taxon) defines
9
+ * a field type with properties like data type, validation rules, and UI hints.
10
+ * Storing taxonomies in the document enables automatic taxon resolution
11
+ * when creating data attributes.
12
+ *
13
+ * Usage:
14
+ * - document.taxonomies.store(taxonomy) - Store a taxonomy definition
15
+ * - document.taxonomies.getByRef(ref) - Retrieve by reference
16
+ * - document.taxonomies.getAll() - List all taxonomies
17
+ * - document.taxonomies.getTaxonByPath(ref, path) - Get specific taxon
18
+ *
19
+ * @example
20
+ * ```typescript
21
+ * // Store a taxonomy
22
+ * const taxonomy = await doc.taxonomies.store({
23
+ * ref: "acme/invoice:1.0.0",
24
+ * name: "Invoice Schema",
25
+ * taxons: [{
26
+ * name: "Invoice",
27
+ * group: true,
28
+ * children: [{
29
+ * name: "Amount",
30
+ * taxonType: "currency",
31
+ * path: "Invoice/Amount"
32
+ * }]
33
+ * }]
34
+ * });
35
+ *
36
+ * // Create an attribute using taxon resolution
37
+ * const attr = await doc.dataAttributes.create(dataObjectId, {
38
+ * taxonomyRef: "acme/invoice:1.0.0",
39
+ * taxonPath: "Invoice/Amount",
40
+ * decimalValue: 150.00
41
+ * });
42
+ * // attr.typeAtCreation is automatically set to "currency"
43
+ * ```
44
+ */
45
+ import { getWasmHelper, getWasmInstance } from './wasm/loader';
46
+ /**
47
+ * TaxonomyAccessor - access taxonomies stored in a document
48
+ *
49
+ * This is an internal accessor class. Access via document.taxonomies property.
50
+ */
51
+ export class TaxonomyAccessor {
52
+ constructor(documentRef) {
53
+ this.documentRef = documentRef;
54
+ }
55
+ /**
56
+ * Store or update a taxonomy in the document
57
+ *
58
+ * If a taxonomy with the same ref already exists, it will be updated.
59
+ * The taxon hierarchy paths are automatically computed if not provided.
60
+ *
61
+ * @param taxonomy The taxonomy definition to store
62
+ * @returns The stored taxonomy with assigned ID
63
+ * @throws Error if storage fails
64
+ *
65
+ * @example
66
+ * ```typescript
67
+ * const stored = await doc.taxonomies.store({
68
+ * ref: "company/schema:1.0.0",
69
+ * name: "Company Schema",
70
+ * type: "EXTRACTION",
71
+ * taxons: [
72
+ * {
73
+ * name: "Invoice",
74
+ * group: true,
75
+ * children: [
76
+ * { name: "Number", taxonType: "string" },
77
+ * { name: "Amount", taxonType: "currency" }
78
+ * ]
79
+ * }
80
+ * ]
81
+ * });
82
+ * ```
83
+ */
84
+ async store(taxonomy) {
85
+ await getWasmInstance();
86
+ const g = globalThis;
87
+ if (typeof g.documentStoreTaxonomy !== 'function') {
88
+ throw new Error('documentStoreTaxonomy not available in WASM module');
89
+ }
90
+ const resultJson = g.documentStoreTaxonomy(this.documentRef, JSON.stringify(taxonomy));
91
+ if (!resultJson || resultJson === 'null') {
92
+ throw new Error('Failed to store taxonomy');
93
+ }
94
+ const helper = await getWasmHelper();
95
+ return helper.parseJsonResult(resultJson);
96
+ }
97
+ /**
98
+ * Get a taxonomy by its reference identifier
99
+ *
100
+ * @param ref The taxonomy reference (e.g., "kodexa/invoice:1.0.0")
101
+ * @returns The taxonomy or null if not found
102
+ *
103
+ * @example
104
+ * ```typescript
105
+ * const taxonomy = await doc.taxonomies.getByRef("acme/invoice:1.0.0");
106
+ * if (taxonomy) {
107
+ * console.log(`Found: ${taxonomy.name} with ${taxonomy.taxons.length} root taxons`);
108
+ * }
109
+ * ```
110
+ */
111
+ async getByRef(ref) {
112
+ await getWasmInstance();
113
+ const g = globalThis;
114
+ if (typeof g.documentGetTaxonomy !== 'function') {
115
+ throw new Error('documentGetTaxonomy not available in WASM module');
116
+ }
117
+ const resultJson = g.documentGetTaxonomy(this.documentRef, ref);
118
+ if (!resultJson || resultJson === 'null')
119
+ return null;
120
+ const helper = await getWasmHelper();
121
+ return helper.parseJsonResult(resultJson);
122
+ }
123
+ /**
124
+ * Get all taxonomies stored in the document
125
+ *
126
+ * @returns Array of all taxonomies
127
+ *
128
+ * @example
129
+ * ```typescript
130
+ * const all = await doc.taxonomies.getAll();
131
+ * console.log(`Document has ${all.length} taxonomies`);
132
+ * for (const tax of all) {
133
+ * console.log(`- ${tax.ref}: ${tax.name}`);
134
+ * }
135
+ * ```
136
+ */
137
+ async getAll() {
138
+ await getWasmInstance();
139
+ const g = globalThis;
140
+ if (typeof g.documentGetTaxonomies !== 'function') {
141
+ throw new Error('documentGetTaxonomies not available in WASM module');
142
+ }
143
+ const resultJson = g.documentGetTaxonomies(this.documentRef);
144
+ const helper = await getWasmHelper();
145
+ const taxonomies = helper.parseJsonResult(resultJson);
146
+ return Array.isArray(taxonomies) ? taxonomies : [];
147
+ }
148
+ /**
149
+ * Delete a taxonomy by its reference
150
+ *
151
+ * @param ref The taxonomy reference to delete
152
+ * @returns true if deleted, false if not found
153
+ *
154
+ * @example
155
+ * ```typescript
156
+ * const deleted = await doc.taxonomies.delete("old/schema:1.0.0");
157
+ * if (deleted) {
158
+ * console.log("Taxonomy removed");
159
+ * }
160
+ * ```
161
+ */
162
+ async delete(ref) {
163
+ await getWasmInstance();
164
+ const g = globalThis;
165
+ if (typeof g.documentDeleteTaxonomy !== 'function') {
166
+ throw new Error('documentDeleteTaxonomy not available in WASM module');
167
+ }
168
+ return g.documentDeleteTaxonomy(this.documentRef, ref);
169
+ }
170
+ /**
171
+ * Get a specific taxon by path within a taxonomy
172
+ *
173
+ * This is useful for looking up taxon metadata like type, label,
174
+ * or validation rules before creating attributes.
175
+ *
176
+ * @param taxonomyRef The taxonomy reference
177
+ * @param taxonPath The taxon path (e.g., "Invoice/LineItem/Amount")
178
+ * @returns The taxon or null if not found
179
+ *
180
+ * @example
181
+ * ```typescript
182
+ * const taxon = await doc.taxonomies.getTaxonByPath(
183
+ * "acme/invoice:1.0.0",
184
+ * "Invoice/LineItem/Amount"
185
+ * );
186
+ * if (taxon) {
187
+ * console.log(`Type: ${taxon.taxonType}, Label: ${taxon.label}`);
188
+ * }
189
+ * ```
190
+ */
191
+ async getTaxonByPath(taxonomyRef, taxonPath) {
192
+ await getWasmInstance();
193
+ const g = globalThis;
194
+ if (typeof g.documentGetTaxonByPath !== 'function') {
195
+ throw new Error('documentGetTaxonByPath not available in WASM module');
196
+ }
197
+ const resultJson = g.documentGetTaxonByPath(this.documentRef, taxonomyRef, taxonPath);
198
+ if (!resultJson || resultJson === 'null')
199
+ return null;
200
+ const helper = await getWasmHelper();
201
+ return helper.parseJsonResult(resultJson);
202
+ }
203
+ /**
204
+ * Check if a taxonomy exists in the document
205
+ *
206
+ * @param ref The taxonomy reference to check
207
+ * @returns true if taxonomy exists
208
+ *
209
+ * @example
210
+ * ```typescript
211
+ * if (await doc.taxonomies.exists("acme/invoice:1.0.0")) {
212
+ * // Use the taxonomy for attribute creation
213
+ * } else {
214
+ * // Need to load/store the taxonomy first
215
+ * }
216
+ * ```
217
+ */
218
+ async exists(ref) {
219
+ const taxonomy = await this.getByRef(ref);
220
+ return taxonomy !== null;
221
+ }
222
+ /**
223
+ * Get all taxon paths from a taxonomy (flattened)
224
+ *
225
+ * Useful for populating dropdowns or validating paths.
226
+ *
227
+ * @param taxonomyRef The taxonomy reference
228
+ * @returns Array of all taxon paths in the taxonomy
229
+ *
230
+ * @example
231
+ * ```typescript
232
+ * const paths = await doc.taxonomies.getAllPaths("acme/invoice:1.0.0");
233
+ * // ["Invoice", "Invoice/Number", "Invoice/Amount", "Invoice/LineItems", ...]
234
+ * ```
235
+ */
236
+ async getAllPaths(taxonomyRef) {
237
+ const taxonomy = await this.getByRef(taxonomyRef);
238
+ if (!taxonomy)
239
+ return [];
240
+ const paths = [];
241
+ const collectPaths = (taxons) => {
242
+ if (!taxons)
243
+ return;
244
+ for (const taxon of taxons) {
245
+ if (taxon.path) {
246
+ paths.push(taxon.path);
247
+ }
248
+ collectPaths(taxon.children);
249
+ }
250
+ };
251
+ collectPaths(taxonomy.taxons);
252
+ return paths;
253
+ }
254
+ /**
255
+ * Find taxons by type within a taxonomy
256
+ *
257
+ * @param taxonomyRef The taxonomy reference
258
+ * @param taxonType The taxon type to filter by (e.g., "currency", "date")
259
+ * @returns Array of matching taxons
260
+ *
261
+ * @example
262
+ * ```typescript
263
+ * const currencyFields = await doc.taxonomies.findByType(
264
+ * "acme/invoice:1.0.0",
265
+ * "currency"
266
+ * );
267
+ * console.log(`Found ${currencyFields.length} currency fields`);
268
+ * ```
269
+ */
270
+ async findByType(taxonomyRef, taxonType) {
271
+ const taxonomy = await this.getByRef(taxonomyRef);
272
+ if (!taxonomy)
273
+ return [];
274
+ const results = [];
275
+ const findTaxons = (taxons) => {
276
+ if (!taxons)
277
+ return;
278
+ for (const taxon of taxons) {
279
+ if (taxon.taxonType === taxonType) {
280
+ results.push(taxon);
281
+ }
282
+ findTaxons(taxon.children);
283
+ }
284
+ };
285
+ findTaxons(taxonomy.taxons);
286
+ return results;
287
+ }
288
+ /**
289
+ * Find group taxons (containers) within a taxonomy
290
+ *
291
+ * @param taxonomyRef The taxonomy reference
292
+ * @returns Array of group taxons
293
+ *
294
+ * @example
295
+ * ```typescript
296
+ * const groups = await doc.taxonomies.findGroups("acme/invoice:1.0.0");
297
+ * for (const group of groups) {
298
+ * console.log(`Group: ${group.path} has ${group.children?.length || 0} children`);
299
+ * }
300
+ * ```
301
+ */
302
+ async findGroups(taxonomyRef) {
303
+ const taxonomy = await this.getByRef(taxonomyRef);
304
+ if (!taxonomy)
305
+ return [];
306
+ const results = [];
307
+ const findGroups = (taxons) => {
308
+ if (!taxons)
309
+ return;
310
+ for (const taxon of taxons) {
311
+ if (taxon.group) {
312
+ results.push(taxon);
313
+ }
314
+ findGroups(taxon.children);
315
+ }
316
+ };
317
+ findGroups(taxonomy.taxons);
318
+ return results;
319
+ }
320
+ }
321
+ //# sourceMappingURL=TaxonomyAccessor.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"TaxonomyAccessor.js","sourceRoot":"","sources":["../src/TaxonomyAccessor.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2CG;AAGH,OAAO,EAAE,aAAa,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAoL/D;;;;GAIG;AACH,MAAM,OAAO,gBAAgB;IAG3B,YAAY,WAAmB;QAC7B,IAAI,CAAC,WAAW,GAAG,WAAW,CAAC;IACjC,CAAC;IAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;OA4BG;IACH,KAAK,CAAC,KAAK,CAAC,QAAuB;QACjC,MAAM,eAAe,EAAE,CAAC;QACxB,MAAM,CAAC,GAAG,UAAiB,CAAC;Q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