@gesslar/toolkit 0.5.0 → 0.7.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 (66) hide show
  1. package/package.json +8 -8
  2. package/src/lib/Collection.js +132 -17
  3. package/src/lib/Contract.js +1 -1
  4. package/src/lib/Data.js +27 -18
  5. package/src/lib/DirectoryObject.js +1 -1
  6. package/src/lib/FS.js +10 -0
  7. package/src/lib/Glog.js +27 -10
  8. package/src/lib/Logger.js +3 -0
  9. package/src/lib/Sass.js +6 -1
  10. package/src/lib/Tantrum.js +43 -0
  11. package/src/lib/TypeSpec.js +11 -7
  12. package/src/lib/Util.js +82 -0
  13. package/src/lib/Valid.js +24 -6
  14. package/src/types/Collection.d.ts +6 -1
  15. package/src/types/Contract.d.ts +27 -27
  16. package/src/types/Data.d.ts +23 -23
  17. package/src/types/FS.d.ts +3 -3
  18. package/src/types/Glog.d.ts +302 -49
  19. package/src/types/Sass.d.ts +1 -1
  20. package/src/types/Schemer.d.ts +29 -29
  21. package/src/types/Tantrum.d.ts +10 -10
  22. package/src/types/Term.d.ts +1 -1
  23. package/src/types/Terms.d.ts +21 -21
  24. package/src/types/Type.d.ts +1 -1
  25. package/src/types/Util.d.ts +20 -2
  26. package/src/types/index.d.ts +17 -23
  27. package/src/types/index.d.ts.map +1 -0
  28. package/src/types/lib/Cache.d.ts +28 -0
  29. package/src/types/lib/Cache.d.ts.map +1 -0
  30. package/src/types/lib/Collection.d.ts +246 -0
  31. package/src/types/lib/Collection.d.ts.map +1 -0
  32. package/src/types/lib/Contract.d.ts +72 -0
  33. package/src/types/lib/Contract.d.ts.map +1 -0
  34. package/src/types/lib/Data.d.ts +189 -0
  35. package/src/types/lib/Data.d.ts.map +1 -0
  36. package/src/types/lib/DirectoryObject.d.ts +148 -0
  37. package/src/types/lib/DirectoryObject.d.ts.map +1 -0
  38. package/src/types/lib/FS.d.ts +70 -0
  39. package/src/types/lib/FS.d.ts.map +1 -0
  40. package/src/types/lib/FileObject.d.ts +189 -0
  41. package/src/types/lib/FileObject.d.ts.map +1 -0
  42. package/src/types/lib/Glog.d.ts +113 -0
  43. package/src/types/lib/Glog.d.ts.map +1 -0
  44. package/src/types/lib/Logger.d.ts +46 -0
  45. package/src/types/lib/Logger.d.ts.map +1 -0
  46. package/src/types/lib/Sass.d.ts +62 -0
  47. package/src/types/lib/Sass.d.ts.map +1 -0
  48. package/src/types/lib/Schemer.d.ts +23 -0
  49. package/src/types/lib/Schemer.d.ts.map +1 -0
  50. package/src/types/lib/Tantrum.d.ts +50 -0
  51. package/src/types/lib/Tantrum.d.ts.map +1 -0
  52. package/src/types/lib/Term.d.ts +103 -0
  53. package/src/types/lib/Term.d.ts.map +1 -0
  54. package/src/types/lib/Terms.d.ts +24 -0
  55. package/src/types/lib/Terms.d.ts.map +1 -0
  56. package/src/types/lib/TypeSpec.d.ts +92 -0
  57. package/src/types/lib/TypeSpec.d.ts.map +1 -0
  58. package/src/types/lib/Util.d.ts +197 -0
  59. package/src/types/lib/Util.d.ts.map +1 -0
  60. package/src/types/lib/Valid.d.ts +33 -0
  61. package/src/types/lib/Valid.d.ts.map +1 -0
  62. package/src/lib/Action.js +0 -283
  63. package/src/lib/ActionBuilder.js +0 -144
  64. package/src/lib/ActionRunner.js +0 -79
  65. package/src/lib/Hooks.js +0 -194
  66. package/src/lib/Piper.js +0 -155
@@ -3,10 +3,10 @@
3
3
  /**
4
4
  * Terms represents an interface definition - what an action promises to provide or accept.
5
5
  * It's just the specification, not the negotiation. Contract handles the negotiation.
6
- *
6
+ *
7
7
  * Terms can be created from objects, strings (YAML/JSON), or file references.
8
8
  * File references use the format "ref://path/to/file" for loading external definitions.
9
- *
9
+ *
10
10
  * @example
11
11
  * ```typescript
12
12
  * // Create terms from object definition
@@ -21,7 +21,7 @@
21
21
  * }
22
22
  * })
23
23
  * ```
24
- *
24
+ *
25
25
  * @example
26
26
  * ```typescript
27
27
  * // Parse terms from YAML string
@@ -29,13 +29,13 @@
29
29
  * accepts:
30
30
  * type: object
31
31
  * properties:
32
- * input:
32
+ * input:
33
33
  * type: string
34
34
  * minLength: 1
35
35
  * `
36
36
  * const parsedTerms = await Terms.parse(yamlData)
37
37
  * ```
38
- *
38
+ *
39
39
  * @example
40
40
  * ```typescript
41
41
  * // Parse terms from file reference
@@ -46,9 +46,9 @@
46
46
  declare class Terms {
47
47
  /**
48
48
  * Creates a new Terms instance with the given definition
49
- *
49
+ *
50
50
  * @param definition - The terms definition object describing what is provided or accepted
51
- *
51
+ *
52
52
  * @example
53
53
  * ```typescript
54
54
  * const terms = new Terms({
@@ -56,7 +56,7 @@ declare class Terms {
56
56
  * type: "object",
57
57
  * properties: {
58
58
  * data: { type: "array", items: { type: "string" } },
59
- * metadata: {
59
+ * metadata: {
60
60
  * type: "object",
61
61
  * properties: {
62
62
  * timestamp: { type: "string", format: "date-time" }
@@ -71,15 +71,15 @@ declare class Terms {
71
71
 
72
72
  /**
73
73
  * Parses terms data from various sources, handling file references
74
- *
74
+ *
75
75
  * @param termsData - Terms data as string (YAML/JSON/file reference) or object
76
76
  * @param directoryObject - Directory context for resolving file references (required for ref:// URLs)
77
77
  * @returns Promise resolving to parsed terms data object
78
- *
78
+ *
79
79
  * @throws {Sass} If termsData is not a string or object
80
- * @throws {Sass} If string data cannot be parsed as YAML or JSON
80
+ * @throws {Sass} If string data cannot be parsed as YAML or JSON
81
81
  * @throws {Sass} If file reference cannot be loaded (missing directory or file not found)
82
- *
82
+ *
83
83
  * @example
84
84
  * ```typescript
85
85
  * // Parse from YAML string
@@ -89,9 +89,9 @@ declare class Terms {
89
89
  * pattern: "^[A-Z][a-z]+"
90
90
  * `)
91
91
  * ```
92
- *
92
+ *
93
93
  * @example
94
- * ```typescript
94
+ * ```typescript
95
95
  * // Parse from JSON string
96
96
  * const jsonTerms = await Terms.parse(`{
97
97
  * "accepts": {
@@ -101,14 +101,14 @@ declare class Terms {
101
101
  * }
102
102
  * }`)
103
103
  * ```
104
- *
104
+ *
105
105
  * @example
106
106
  * ```typescript
107
107
  * // Parse from file reference
108
108
  * const directory = new DirectoryObject("./schemas")
109
109
  * const fileTerms = await Terms.parse("ref://api-contract.yaml", directory)
110
110
  * ```
111
- *
111
+ *
112
112
  * @example
113
113
  * ```typescript
114
114
  * // Parse from object (returns as-is)
@@ -118,22 +118,22 @@ declare class Terms {
118
118
  * ```
119
119
  */
120
120
  static parse(
121
- termsData: string | object,
121
+ termsData: string | object,
122
122
  directoryObject?: import('./DirectoryObject.js').default
123
123
  ): Promise<object>
124
124
 
125
125
  /**
126
126
  * Get the terms definition object
127
- *
127
+ *
128
128
  * @returns The complete terms definition as provided to the constructor
129
- *
129
+ *
130
130
  * @example
131
131
  * ```typescript
132
132
  * const terms = new Terms({
133
133
  * accepts: { type: "string" },
134
134
  * provides: { type: "number" }
135
135
  * })
136
- *
136
+ *
137
137
  * const definition = terms.definition
138
138
  * console.log(definition.accepts) // { type: "string" }
139
139
  * console.log(definition.provides) // { type: "number" }
@@ -142,4 +142,4 @@ declare class Terms {
142
142
  get definition(): object
143
143
  }
144
144
 
145
- export default Terms
145
+ export default Terms
@@ -23,4 +23,4 @@ export default class TypeSpec {
23
23
  reduce<T>(callback: (acc: T, spec: TypeSpecDefinition) => T, initialValue: T): T
24
24
  find(callback: (spec: TypeSpecDefinition) => boolean): TypeSpecDefinition | undefined
25
25
  match(value: unknown, options?: { allowEmpty?: boolean }): boolean
26
- }
26
+ }
@@ -54,6 +54,16 @@ declare class Util {
54
54
  */
55
55
  static rightAlignText(text: string | number, width?: number): string
56
56
 
57
+ /**
58
+ * Centre-align a string inside a fixed width (pad with spaces on left).
59
+ * If the string exceeds width it is returned unchanged.
60
+ *
61
+ * @param text - Text to align.
62
+ * @param width - Target field width (default 80).
63
+ * @returns Padded string with text centred.
64
+ */
65
+ static centreAlignText(text: string | number, width?: number): string
66
+
57
67
  /**
58
68
  * Compute sha256 hash (hex) of the provided string.
59
69
  *
@@ -174,7 +184,15 @@ declare class Util {
174
184
  * @param args - Arguments to pass to event listeners
175
185
  * @returns Resolves when all listeners have completed
176
186
  */
177
- static asyncEmitAnon(emitter: { listeners(event: string): Function[], on(event: string, listener: Function): any, emit(event: string, ...args: unknown[]): any }, event: string, ...args: unknown[]): Promise<void>
187
+ static asyncEmitAnon(
188
+ emitter: {
189
+ listeners(event: string): Function[],
190
+ on(event: string, listener: Function): any,
191
+ emit(event: string, ...args: unknown[]): any
192
+ },
193
+ event: string,
194
+ ...args: unknown[]
195
+ ): Promise<void>
178
196
 
179
197
  /**
180
198
  * Determine the Levenshtein distance between two string values.
@@ -228,7 +246,7 @@ declare class Util {
228
246
  * @param trim - Whether to trim whitespace from each line (default: true)
229
247
  * @param flags - Array of regex flags to apply (default: [])
230
248
  * @returns A new RegExp object with the processed pattern
231
- *
249
+ *
232
250
  * @throws Will throw if input is not a string
233
251
  * @throws Will throw if trim is not a boolean
234
252
  * @throws Will throw if flags is not an array
@@ -1,23 +1,17 @@
1
- // Implementation: ../index.js
2
- // Core file system abstractions
3
- export { default as FileObject } from './FileObject.js'
4
- export { default as DirectoryObject } from './DirectoryObject.js'
5
- export { default as FS } from './FS.js'
6
-
7
- // Utility classes
8
- export { default as Cache } from './Cache.js'
9
- export { default as Collection } from './Collection.js'
10
- export { default as Contract } from './Contract.js'
11
- export { default as Data } from './Data.js'
12
- export { default as Glog } from './Glog.js'
13
- export { default as Sass } from './Sass.js'
14
- export { default as Schemer } from './Schemer.js'
15
- export { default as Tantrum } from './Tantrum.js'
16
- export { default as Term } from './Term.js'
17
- export { default as Terms } from './Terms.js'
18
- export { default as Type } from './Type.js'
19
- export { default as Util } from './Util.js'
20
- export { default as Valid } from './Valid.js'
21
-
22
- // Type exports
23
- export type { FileParts } from './FS.js'
1
+ export { default as FileObject } from "./lib/FileObject.js";
2
+ export { default as DirectoryObject } from "./lib/DirectoryObject.js";
3
+ export { default as FS } from "./lib/FS.js";
4
+ export { default as Cache } from "./lib/Cache.js";
5
+ export { default as Collection } from "./lib/Collection.js";
6
+ export { default as Contract } from "./lib/Contract.js";
7
+ export { default as Data } from "./lib/Data.js";
8
+ export { default as Glog } from "./lib/Glog.js";
9
+ export { default as Sass } from "./lib/Sass.js";
10
+ export { default as Schemer } from "./lib/Schemer.js";
11
+ export { default as Tantrum } from "./lib/Tantrum.js";
12
+ export { default as Term } from "./lib/Term.js";
13
+ export { default as Terms } from "./lib/Terms.js";
14
+ export { default as Type } from "./lib/TypeSpec.js";
15
+ export { default as Util } from "./lib/Util.js";
16
+ export { default as Valid } from "./lib/Valid.js";
17
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../index.js"],"names":[],"mappings":""}
@@ -0,0 +1,28 @@
1
+ /**
2
+ * File system cache with automatic invalidation based on modification time.
3
+ * Provides intelligent caching of parsed JSON5/YAML files with mtime-based
4
+ * cache invalidation to optimize performance for repeated file access.
5
+ *
6
+ * The cache eliminates redundant file reads and parsing when multiple processes
7
+ * access the same dependency files, while ensuring data freshness through
8
+ * modification time checking.
9
+ */
10
+ export default class Cache {
11
+ /**
12
+ * Loads and caches parsed file data with automatic invalidation based on
13
+ * modification time.
14
+ *
15
+ * Implements a sophisticated caching strategy that checks file modification
16
+ * times to determine whether cached data is still valid, ensuring data
17
+ * freshness while optimizing performance for repeated file access during
18
+ * parallel processing.
19
+ *
20
+ * @param {FileObject} fileObject - The file object to load and cache
21
+ * @returns {Promise<unknown>} The parsed file data (JSON5 or YAML)
22
+ * @throws {Sass} If the file cannot be found or accessed
23
+ */
24
+ loadCachedData(fileObject: FileObject): Promise<unknown>;
25
+ #private;
26
+ }
27
+ import FileObject from "./FileObject.js";
28
+ //# sourceMappingURL=Cache.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Cache.d.ts","sourceRoot":"","sources":["../../lib/Cache.js"],"names":[],"mappings":"AAGA;;;;;;;;GAQG;AACH;IAoBE;;;;;;;;;;;;OAYG;IACH,2BAJW,UAAU,GACR,OAAO,CAAC,OAAO,CAAC,CA6B5B;;CACF;uBAxEsB,iBAAiB"}
@@ -0,0 +1,246 @@
1
+ /**
2
+ * Utility class for collection operations.
3
+ * Provides static methods for working with arrays, objects, sets, and maps.
4
+ */
5
+ export default class Collection {
6
+ /**
7
+ * Evaluates an array with a predicate function, optionally in reverse order.
8
+ * Returns the first truthy result from the predicate.
9
+ *
10
+ * @param {Array<unknown>} collection - The array to evaluate
11
+ * @param {(value: unknown, index: number, array: Array<unknown>) => unknown} predicate - Function to evaluate each element
12
+ * @param {boolean} [forward] - Whether to iterate forward (true) or backward (false). Defaults to true
13
+ * @returns {unknown|undefined} The first truthy result from the predicate, or undefined
14
+ * @throws {Sass} If collection is not an array or predicate is not a function
15
+ */
16
+ static evalArray(collection: Array<unknown>, predicate: (value: unknown, index: number, array: Array<unknown>) => unknown, forward?: boolean): unknown | undefined;
17
+ /**
18
+ * Evaluates an object with a predicate function.
19
+ * Returns the first truthy result from the predicate.
20
+ *
21
+ * @param {object} collection - The object to evaluate
22
+ * @param {(value: unknown, key: string, object: object) => unknown} predicate - Function to evaluate each property
23
+ * @returns {unknown|undefined} The first truthy result from the predicate, or undefined
24
+ * @throws {Sass} If collection is not an object or predicate is not a function
25
+ */
26
+ static evalObject(collection: object, predicate: (value: unknown, key: string, object: object) => unknown): unknown | undefined;
27
+ /**
28
+ * Evaluates a Set with a predicate function.
29
+ * Returns the first truthy result from the predicate.
30
+ *
31
+ * @param {Set<unknown>} collection - The Set to evaluate
32
+ * @param {(value: unknown, set: Set<unknown>) => unknown} predicate - Function to evaluate each element
33
+ * @returns {unknown|undefined} The first truthy result from the predicate, or undefined
34
+ * @throws {Sass} If collection is not a Set or predicate is not a function
35
+ */
36
+ static evalSet(collection: Set<unknown>, predicate: (value: unknown, set: Set<unknown>) => unknown): unknown | undefined;
37
+ /**
38
+ * Evaluates a Map with a predicate function, optionally in reverse order.
39
+ * Returns the first truthy result from the predicate.
40
+ *
41
+ * @param {Map<unknown, unknown>} collection - The Map to evaluate
42
+ * @param {(value: unknown, key: unknown, map: Map<unknown, unknown>) => unknown} predicate - Function to evaluate each entry
43
+ * @param {boolean} [forward] - Whether to iterate forward (true) or backward (false). Defaults to true
44
+ * @returns {unknown|undefined} The first truthy result from the predicate, or undefined
45
+ * @throws {Sass} If collection is not a Map or predicate is not a function
46
+ */
47
+ static evalMap(collection: Map<unknown, unknown>, predicate: (value: unknown, key: unknown, map: Map<unknown, unknown>) => unknown, forward?: boolean): unknown | undefined;
48
+ /**
49
+ * Zips two arrays together into an array of pairs.
50
+ * The resulting array length equals the shorter input array.
51
+ *
52
+ * @param {Array<unknown>} array1 - The first array
53
+ * @param {Array<unknown>} array2 - The second array
54
+ * @returns {Array<[unknown, unknown]>} Array of paired elements
55
+ */
56
+ static zip(array1: Array<unknown>, array2: Array<unknown>): Array<[unknown, unknown]>;
57
+ /**
58
+ * Unzips an array of pairs into separate arrays.
59
+ * Transposes a 2D array structure.
60
+ *
61
+ * @param {Array<Array<unknown>>} array - Array of arrays to unzip
62
+ * @returns {Array<Array<unknown>>} Array of unzipped arrays, or empty array for invalid input
63
+ */
64
+ static unzip(array: Array<Array<unknown>>): Array<Array<unknown>>;
65
+ /**
66
+ * Maps an array using an async function, processing items sequentially.
67
+ * Unlike Promise.all(array.map()), this processes one item at a time.
68
+ *
69
+ * @param {Array<unknown>} array - The array to map
70
+ * @param {(item: unknown) => Promise<unknown>} asyncFn - Async function to apply to each element
71
+ * @returns {Promise<Array<unknown>>} Promise resolving to the mapped array
72
+ * @throws {Sass} If array is not an Array or asyncFn is not a function
73
+ */
74
+ static asyncMap(array: Array<unknown>, asyncFn: (item: unknown) => Promise<unknown>): Promise<Array<unknown>>;
75
+ /**
76
+ * Checks if all elements in an array are of a specified type
77
+ *
78
+ * @param {Array<unknown>} arr - The array to check
79
+ * @param {string} [type] - The type to check for (optional, defaults to the type of the first element)
80
+ * @returns {boolean} Whether all elements are of the specified type
81
+ */
82
+ static isArrayUniform(arr: Array<unknown>, type?: string): boolean;
83
+ /**
84
+ * Checks if an array is unique
85
+ *
86
+ * @param {Array<unknown>} arr - The array of which to remove duplicates
87
+ * @returns {Array<unknown>} The unique elements of the array
88
+ */
89
+ static isArrayUnique(arr: Array<unknown>): Array<unknown>;
90
+ /**
91
+ * Returns the intersection of two arrays.
92
+ *
93
+ * @param {Array<unknown>} arr1 - The first array.
94
+ * @param {Array<unknown>} arr2 - The second array.
95
+ * @returns {Array<unknown>} The intersection of the two arrays.
96
+ */
97
+ static intersection(arr1: Array<unknown>, arr2: Array<unknown>): Array<unknown>;
98
+ /**
99
+ * Checks whether two arrays have any elements in common.
100
+ *
101
+ * This function returns `true` if at least one element from `arr1` exists in
102
+ * `arr2`, and `false` otherwise. It optimizes by iterating over the shorter
103
+ * array for efficiency.
104
+ *
105
+ * Example:
106
+ * Collection.intersects([1, 2, 3], [3, 4, 5]) // returns true
107
+ * Collection.intersects(["a", "b"], ["c", "d"]) // returns false
108
+ *
109
+ * @param {Array<unknown>} arr1 - The first array to check for intersection.
110
+ * @param {Array<unknown>} arr2 - The second array to check for intersection.
111
+ * @returns {boolean} True if any element is shared between the arrays, false otherwise.
112
+ */
113
+ static intersects(arr1: Array<unknown>, arr2: Array<unknown>): boolean;
114
+ /**
115
+ * Pads an array to a specified length with a value. This operation
116
+ * occurs in-place.
117
+ *
118
+ * @param {Array<unknown>} arr - The array to pad.
119
+ * @param {number} length - The length to pad the array to.
120
+ * @param {unknown} value - The value to pad the array with.
121
+ * @param {number} [position] - The position to pad the array at. Defaults to 0
122
+ * @returns {Array<unknown>} The padded array.
123
+ */
124
+ static arrayPad(arr: Array<unknown>, length: number, value: unknown, position?: number): Array<unknown>;
125
+ /**
126
+ * Filters an array asynchronously using a predicate function.
127
+ * Applies the predicate to all items in parallel and returns filtered results.
128
+ *
129
+ * @param {Array<unknown>} arr - The array to filter
130
+ * @param {(value: unknown, index: number, array: Array<unknown>) => Promise<boolean>} predicate - Async predicate function that returns a promise resolving to boolean
131
+ * @returns {Promise<Array<unknown>>} Promise resolving to the filtered array
132
+ */
133
+ static asyncFilter(arr: Array<unknown>, predicate: (value: unknown, index: number, array: Array<unknown>) => Promise<boolean>): Promise<Array<unknown>>;
134
+ /**
135
+ * Clones an object
136
+ *
137
+ * @param {object} obj - The object to clone
138
+ * @param {boolean} freeze - Whether to freeze the cloned object
139
+ * @returns {object} The cloned object
140
+ */
141
+ static cloneObject(obj: object, freeze?: boolean): object;
142
+ /**
143
+ * Checks if an object is empty
144
+ *
145
+ * @param {object} obj - The object to check
146
+ * @returns {boolean} Whether the object is empty
147
+ */
148
+ static isObjectEmpty(obj: object): boolean;
149
+ /**
150
+ * Ensures that a nested path of objects exists within the given object.
151
+ * Creates empty objects along the path if they don't exist.
152
+ *
153
+ * @param {object} obj - The object to check/modify
154
+ * @param {Array<string>} keys - Array of keys representing the path to ensure
155
+ * @returns {object} Reference to the deepest nested object in the path
156
+ */
157
+ static assureObjectPath(obj: object, keys: Array<string>): object;
158
+ /**
159
+ * Sets a value in a nested object structure using an array of keys; creating
160
+ * the structure if it does not exist.
161
+ *
162
+ * @param {object} obj - The target object to set the value in
163
+ * @param {Array<string>} keys - Array of keys representing the path to the target property
164
+ * @param {unknown} value - The value to set at the target location
165
+ */
166
+ static setNestedValue(obj: object, keys: Array<string>, value: unknown): void;
167
+ /**
168
+ * Deeply merges two or more objects. Arrays are replaced, not merged.
169
+ *
170
+ * @param {...object} sources - Objects to merge (left to right)
171
+ * @returns {object} The merged object
172
+ */
173
+ static mergeObject(...sources: object[]): object;
174
+ /**
175
+ * Freezes an object and all of its properties recursively.
176
+ *
177
+ * @param {object} obj The object to freeze.
178
+ * @returns {object} The frozen object.
179
+ */
180
+ static deepFreezeObject(obj: object): object;
181
+ /**
182
+ * Maps an object using a transformer function
183
+ *
184
+ * @param {object} original The original object
185
+ * @param {function(unknown): unknown} transformer The transformer function
186
+ * @param {boolean} mutate Whether to mutate the original object
187
+ * @returns {Promise<object>} The mapped object
188
+ */
189
+ static mapObject(original: object, transformer: (arg0: unknown) => unknown, mutate?: boolean): Promise<object>;
190
+ /**
191
+ * Allocates an object from a source array and a spec array or function.
192
+ *
193
+ * @param {unknown} source The source array
194
+ * @param {Array<unknown>|function(Array<unknown>): Promise<Array<unknown>>|Array<unknown>} spec The spec array or function
195
+ * @returns {Promise<object>} The allocated object
196
+ */
197
+ static allocateObject(source: unknown, spec: Array<unknown> | ((arg0: Array<unknown>) => Promise<Array<unknown>> | Array<unknown>)): Promise<object>;
198
+ /**
199
+ * Trims falsy values from both ends of an array (in-place).
200
+ * Optionally preserves specific falsy values.
201
+ *
202
+ * @param {Array<unknown>} arr - The array to trim
203
+ * @param {Array<unknown>} [except] - Values to preserve even if falsy. Defaults to empty array
204
+ * @returns {Array<unknown>} The trimmed array (same reference, modified in-place)
205
+ * @throws {Sass} If arr is not an Array or except is not an Array
206
+ */
207
+ static trimArray(arr: Array<unknown>, except?: Array<unknown>): Array<unknown>;
208
+ /**
209
+ * Trims falsy values from the right end of an array (in-place).
210
+ * Optionally preserves specific falsy values.
211
+ *
212
+ * @param {Array<unknown>} arr - The array to trim
213
+ * @param {Array<unknown>} [except] - Values to preserve even if falsy. Defaults to empty array
214
+ * @returns {Array<unknown>} The trimmed array (same reference, modified in-place)
215
+ * @throws {Sass} If arr is not an Array or except is not an Array
216
+ */
217
+ static trimArrayRight(arr: Array<unknown>, except?: Array<unknown>): Array<unknown>;
218
+ /**
219
+ * Trims falsy values from the left end of an array (in-place).
220
+ * Optionally preserves specific falsy values.
221
+ *
222
+ * @param {Array<unknown>} arr - The array to trim
223
+ * @param {Array<unknown>} [except] - Values to preserve even if falsy. Defaults to empty array
224
+ * @returns {Array<unknown>} The trimmed array (same reference, modified in-place)
225
+ * @throws {Sass} If arr is not an Array or except is not an Array
226
+ */
227
+ static trimArrayLeft(arr: Array<unknown>, except?: Array<unknown>): Array<unknown>;
228
+ /**
229
+ * Transposes an array of objects into an object of arrays.
230
+ * Collects values for each key across all objects into arrays.
231
+ *
232
+ * @param {Array<object>} objects - Array of plain objects to transpose
233
+ * @returns {object} Object with keys from input objects, values as arrays
234
+ * @throws {Sass} If objects is not an Array or contains non-plain objects
235
+ */
236
+ static transposeObjects(objects: Array<object>): object;
237
+ /**
238
+ * Flattens an array (or nested array) of objects and transposes them.
239
+ * Combines flat() and transposeObjects() operations.
240
+ *
241
+ * @param {Array<object>|Array<Array<object>>} input - Array or nested array of objects
242
+ * @returns {object} Transposed object with arrays of values
243
+ */
244
+ static flattenObjectArray(input: Array<object> | Array<Array<object>>): object;
245
+ }
246
+ //# sourceMappingURL=Collection.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Collection.d.ts","sourceRoot":"","sources":["../../lib/Collection.js"],"names":[],"mappings":"AAaA;;;GAGG;AACH;IACE;;;;;;;;;OASG;IACH,6BANW,KAAK,CAAC,OAAO,CAAC,aACd,CAAC,KAAK,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,KAAK,CAAC,OAAO,CAAC,KAAK,OAAO,YACjE,OAAO,GACL,OAAO,GAAC,SAAS,CAqB7B;IAED;;;;;;;;OAQG;IACH,8BALW,MAAM,aACN,CAAC,KAAK,EAAE,OAAO,EAAE,GAAG,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,KAAK,OAAO,GACtD,OAAO,GAAC,SAAS,CAmB7B;IAED;;;;;;;;OAQG;IACH,2BALW,GAAG,CAAC,OAAO,CAAC,aACZ,CAAC,KAAK,EAAE,OAAO,EAAE,GAAG,EAAE,GAAG,CAAC,OAAO,CAAC,KAAK,OAAO,GAC5C,OAAO,GAAC,SAAS,CAmB7B;IAED;;;;;;;;;OASG;IACH,2BANW,GAAG,CAAC,OAAO,EAAE,OAAO,CAAC,aACrB,CAAC,KAAK,EAAE,OAAO,EAAE,GAAG,EAAE,OAAO,EAAE,GAAG,EAAE,GAAG,CAAC,OAAO,EAAE,OAAO,CAAC,KAAK,OAAO,YACrE,OAAO,GACL,OAAO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,CAAC,GAAC,KAAK,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,GAChC,MAAM,CAMlB;CACF"}
@@ -0,0 +1,72 @@
1
+ /**
2
+ * Contract represents a successful negotiation between Terms.
3
+ * It handles validation and compatibility checking between what
4
+ * one action provides and what another accepts.
5
+ */
6
+ export default class Contract {
7
+ /**
8
+ * Extracts the actual schema from a terms definition
9
+ *
10
+ * @param {object} definition - Terms definition with TLD descriptor
11
+ * @returns {object} Extracted schema content
12
+ * @throws {Sass} If definition structure is invalid
13
+ * @private
14
+ */
15
+ private static "__#private@#extractSchemaFromTerms";
16
+ /**
17
+ * Creates a contract from terms with schema validation
18
+ *
19
+ * @param {string} name - Contract identifier
20
+ * @param {object} termsDefinition - The terms definition
21
+ * @param {import('ajv').ValidateFunction|null} [validator] - Optional AJV schema validator function with .errors property
22
+ * @param {import('../types.js').DebugFunction} [debug] - Debug function
23
+ * @returns {Contract} New contract instance
24
+ */
25
+ static fromTerms(name: string, termsDefinition: object, validator?: import("ajv").ValidateFunction | null, debug?: any): Contract;
26
+ /**
27
+ * Creates a contract by negotiating between provider and consumer terms
28
+ *
29
+ * @param {Terms} providerTerms - What the provider offers
30
+ * @param {Terms} consumerTerms - What the consumer expects
31
+ * @param {object} options - Configuration options
32
+ * @param {import('../types.js').DebugFunction} [options.debug] - Debug function
33
+ */
34
+ constructor(providerTerms: Terms, consumerTerms: Terms, { debug }?: {
35
+ debug?: any;
36
+ });
37
+ /**
38
+ * Validates data against this contract
39
+ *
40
+ * @param {object} data - Data to validate
41
+ * @returns {boolean} True if valid
42
+ * @throws {Sass} If validation fails or contract not negotiated
43
+ */
44
+ validate(data: object): boolean;
45
+ /**
46
+ * Check if contract negotiation was successful
47
+ *
48
+ * @returns {boolean} True if negotiated
49
+ */
50
+ get isNegotiated(): boolean;
51
+ /**
52
+ * Get the provider terms (if any)
53
+ *
54
+ * @returns {Terms|null} Provider terms
55
+ */
56
+ get providerTerms(): Terms | null;
57
+ /**
58
+ * Get the consumer terms (if any)
59
+ *
60
+ * @returns {Terms|null} Consumer terms
61
+ */
62
+ get consumerTerms(): Terms | null;
63
+ /**
64
+ * Get the contract validator
65
+ *
66
+ * @returns {(data: object) => boolean|null} The contract validator function
67
+ */
68
+ get validator(): (data: object) => boolean | null;
69
+ #private;
70
+ }
71
+ import Terms from "./Terms.js";
72
+ //# sourceMappingURL=Contract.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Contract.d.ts","sourceRoot":"","sources":["../../lib/Contract.js"],"names":[],"mappings":"AAKA;;;;GAIG;AACH;IAwBE;;;;;;;OAOG;IACH,oDAgBC;IAED;;;;;;;;OAQG;IACH,uBANW,MAAM,mBACN,MAAM,cACN,OAAO,KAAK,EAAE,gBAAgB,GAAC,IAAI,gBAEjC,QAAQ,CAsBpB;IAxED;;;;;;;OAOG;IACH,2BALW,KAAK,iBACL,KAAK,cAEb;QAAsD,KAAK,GAAnD,GAAmC;KAC7C,EAQA;IA6FD;;;;;;OAMG;IACH,eAJW,MAAM,GACJ,OAAO,CAsBnB;IAsED;;;;OAIG;IACH,oBAFa,OAAO,CAInB;IAED;;;;OAIG;IACH,qBAFa,KAAK,GAAC,IAAI,CAItB;IAED;;;;OAIG;IACH,qBAFa,KAAK,GAAC,IAAI,CAItB;IAED;;;;OAIG;IACH,iBAFa,CAAC,IAAI,EAAE,MAAM,KAAK,OAAO,GAAC,IAAI,CAI1C;;CACF;kBA9PiB,YAAY"}