@gesslar/toolkit 0.6.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 (48) 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 +4 -4
  5. package/src/lib/DirectoryObject.js +1 -1
  6. package/src/lib/FS.js +10 -0
  7. package/src/lib/Glog.js +9 -7
  8. package/src/lib/Sass.js +6 -1
  9. package/src/lib/Tantrum.js +43 -0
  10. package/src/lib/TypeSpec.js +11 -7
  11. package/src/lib/Util.js +61 -0
  12. package/src/lib/Valid.js +24 -6
  13. package/src/types/index.d.ts +17 -23
  14. package/src/types/index.d.ts.map +1 -0
  15. package/src/types/lib/Cache.d.ts +28 -0
  16. package/src/types/lib/Cache.d.ts.map +1 -0
  17. package/src/types/lib/Collection.d.ts +246 -0
  18. package/src/types/lib/Collection.d.ts.map +1 -0
  19. package/src/types/lib/Contract.d.ts +72 -0
  20. package/src/types/lib/Contract.d.ts.map +1 -0
  21. package/src/types/lib/Data.d.ts +189 -0
  22. package/src/types/lib/Data.d.ts.map +1 -0
  23. package/src/types/lib/DirectoryObject.d.ts +148 -0
  24. package/src/types/lib/DirectoryObject.d.ts.map +1 -0
  25. package/src/types/lib/FS.d.ts +70 -0
  26. package/src/types/lib/FS.d.ts.map +1 -0
  27. package/src/types/lib/FileObject.d.ts +189 -0
  28. package/src/types/lib/FileObject.d.ts.map +1 -0
  29. package/src/types/lib/Glog.d.ts +113 -0
  30. package/src/types/lib/Glog.d.ts.map +1 -0
  31. package/src/types/lib/Logger.d.ts +46 -0
  32. package/src/types/lib/Logger.d.ts.map +1 -0
  33. package/src/types/lib/Sass.d.ts +62 -0
  34. package/src/types/lib/Sass.d.ts.map +1 -0
  35. package/src/types/lib/Schemer.d.ts +23 -0
  36. package/src/types/lib/Schemer.d.ts.map +1 -0
  37. package/src/types/lib/Tantrum.d.ts +50 -0
  38. package/src/types/lib/Tantrum.d.ts.map +1 -0
  39. package/src/types/lib/Term.d.ts +103 -0
  40. package/src/types/lib/Term.d.ts.map +1 -0
  41. package/src/types/lib/Terms.d.ts +24 -0
  42. package/src/types/lib/Terms.d.ts.map +1 -0
  43. package/src/types/lib/TypeSpec.d.ts +92 -0
  44. package/src/types/lib/TypeSpec.d.ts.map +1 -0
  45. package/src/types/lib/Util.d.ts +197 -0
  46. package/src/types/lib/Util.d.ts.map +1 -0
  47. package/src/types/lib/Valid.d.ts +33 -0
  48. package/src/types/lib/Valid.d.ts.map +1 -0
@@ -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,GAAC,SAAS,CAqB7B;IAED;;;;;;;OAOG;IACH,mBAJW,KAAK,CAAC,OAAO,CAAC,UACd,KAAK,CAAC,OAAO,CAAC,GACZ,KAAK,CAAC,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC,CAMrC;IAED;;;;;;OAMG;IACH,oBAHW,KAAK,CAAC,KA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;IACH,2BAJW,MAAM,QACN,KAAK,CAAC,MAAM,CAAC,SACb,OAAO,QAiBjB;IAED;;;;;OAKG;IACH,+BAHc,MAAM,EAAA,GACP,MAAM,CAqBlB;IAED;;;;;OAKG;IACH,6BAHW,MAAM,GACJ,MAAM,CAmBlB;IAED;;;;;;;OAOG;IACH,2BALW,MAAM,eACN,CAAS,IAAO,EAAP,OAAO,KAAG,OAAO,WAC1B,OAAO,GACL,OAAO,CAAC,MAAM,CAAC,CAe3B;IAED;;;;;;OAMG;IACH,8BAJW,OAAO,QACP,KAAK,CAAC,OAAO,CAAC,IAAC,CAAS,IAAc,EAAd,KAAK,CAAC,OAAO,CAAC,KAAG,OAAO,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,GAAC,KAAK,CAAC,OAAO,CAAC,CAAA,GAC7E,OAAO,CAAC,MAAM,CAAC,CA0C3B;IAED;;;;;;;;OAQG;IACH,sBALW,KAAK,CAAC,OAAO,CAAC,WACd,KAAK,CAAC,OAAO,CAAC,GACZ,KAAK,CAAC,OAAO,CAAC,CAW1B;IAED;;;;;;;;OAQG;IACH,2BALW,KAAK,CAAC,OAAO,CAAC,WACd,KAAK,CAAC,OAAO,CAAC,GACZ,KAAK,CAAC,OAAO,CAAC,CAY1B;IAED;;;;;;;;OAQG;IACH,0BALW,KAAK,CAAC,OAAO,CAAC,WACd,KAAK,CAAC,OAAO,CAAC,GACZ,KAAK,CAAC,OAAO,CAAC,CAiB1B;IAED;;;;;;;OAOG;IACH,iCAJW,KAAK,CAAC,MAAM,CAAC,GACX,MAAM,CA0BlB;IAED;;;;;;OAMG;IACH,iCAHW,KAAK,CAAC,MAAM,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"}
@@ -0,0 +1,189 @@
1
+ export default class Data {
2
+ /**
3
+ * Array of JavaScript primitive type names.
4
+ * Includes basic types and object categories from the typeof operator.
5
+ *
6
+ * @type {Array<string>}
7
+ */
8
+ static primitives: Array<string>;
9
+ /**
10
+ * Array of JavaScript constructor names for built-in objects.
11
+ * Includes common object types and typed arrays.
12
+ *
13
+ * @type {Array<string>}
14
+ */
15
+ static constructors: Array<string>;
16
+ /**
17
+ * Combined array of all supported data types (primitives and constructors in
18
+ * lowercase).
19
+ *
20
+ * Used for type validation throughout the utility functions.
21
+ *
22
+ * @type {Array<string>}
23
+ */
24
+ static dataTypes: Array<string>;
25
+ /**
26
+ * Array of type names that can be checked for emptiness.
27
+ * These types have meaningful empty states that can be tested.
28
+ *
29
+ * @type {Array<string>}
30
+ */
31
+ static emptyableTypes: Array<string>;
32
+ /**
33
+ * Appends a string to another string if it does not already end with it.
34
+ *
35
+ * @param {string} string - The string to append to
36
+ * @param {string} append - The string to append
37
+ * @returns {string} The appended string
38
+ */
39
+ static appendString(string: string, append: string): string;
40
+ /**
41
+ * Prepends a string to another string if it does not already start with it.
42
+ *
43
+ * @param {string} string - The string to prepend to
44
+ * @param {string} prepend - The string to prepend
45
+ * @returns {string} The prepended string
46
+ */
47
+ static prependString(string: string, prepend: string): string;
48
+ /**
49
+ * Creates a type spec from a string. A type spec is an array of objects
50
+ * defining the type of a value and whether an array is expected.
51
+ *
52
+ * @param {string} string - The string to parse into a type spec.
53
+ * @param {object} options - Additional options for parsing.
54
+ * @returns {Array<object>} An array of type specs.
55
+ */
56
+ static newTypeSpec(string: string, options: object): Array<object>;
57
+ /**
58
+ * Checks if a value is of a specified type
59
+ *
60
+ * @param {unknown} value The value to check
61
+ * @param {string|TypeSpec} type The type to check for
62
+ * @param {object} options Additional options for checking
63
+ * @returns {boolean} Whether the value is of the specified type
64
+ */
65
+ static isType(value: unknown, type: string | TypeSpec, options?: object): boolean;
66
+ /**
67
+ * Checks if a type is valid
68
+ *
69
+ * @param {string} type - The type to check
70
+ * @returns {boolean} Whether the type is valid
71
+ */
72
+ static isValidType(type: string): boolean;
73
+ /**
74
+ * Checks if a value is of a specified type. Unlike the type function, this
75
+ * function does not parse the type string, and only checks for primitive
76
+ * or constructor types.
77
+ *
78
+ * @param {unknown} value - The value to check
79
+ * @param {string} type - The type to check for
80
+ * @returns {boolean} Whether the value is of the specified type
81
+ */
82
+ static isBaseType(value: unknown, type: string): boolean;
83
+ /**
84
+ * Returns the type of a value, whether it be a primitive, object, or function.
85
+ *
86
+ * @param {unknown} value - The value to check
87
+ * @returns {string} The type of the value
88
+ */
89
+ static typeOf(value: unknown): string;
90
+ /**
91
+ * Checks a value is undefined or null.
92
+ *
93
+ * @param {unknown} value The value to check
94
+ * @returns {boolean} Whether the value is undefined or null
95
+ */
96
+ static isNothing(value: unknown): boolean;
97
+ /**
98
+ * Checks if a value is empty. This function is used to check if an object,
99
+ * array, or string is empty. Null and undefined values are considered empty.
100
+ *
101
+ * @param {unknown} value The value to check
102
+ * @param {boolean} checkForNothing Whether to check for null or undefined
103
+ * values
104
+ * @returns {boolean} Whether the value is empty
105
+ */
106
+ static isEmpty(value: unknown, checkForNothing?: boolean): boolean;
107
+ /**
108
+ * Freezes an object and all of its properties recursively.
109
+ *
110
+ * @param {object} obj The object to freeze.
111
+ * @returns {object} The frozen object.
112
+ */
113
+ static deepFreezeObject(obj: object): object;
114
+ /**
115
+ * Ensures that a nested path of objects exists within the given object.
116
+ * Creates empty objects along the path if they don't exist.
117
+ *
118
+ * @param {object} obj - The object to check/modify
119
+ * @param {Array<string>} keys - Array of keys representing the path to ensure
120
+ * @returns {object} Reference to the deepest nested object in the path
121
+ */
122
+ static assureObjectPath(obj: object, keys: Array<string>): object;
123
+ /**
124
+ * Sets a value in a nested object structure using an array of keys; creating
125
+ * the structure if it does not exist.
126
+ *
127
+ * @param {object} obj - The target object to set the value in
128
+ * @param {Array<string>} keys - Array of keys representing the path to the target property
129
+ * @param {unknown} value - The value to set at the target location
130
+ */
131
+ static setNestedValue(obj: object, keys: Array<string>, value: unknown): void;
132
+ /**
133
+ * Deeply merges two or more objects. Arrays are replaced, not merged.
134
+ *
135
+ * @param {...object} sources - Objects to merge (left to right)
136
+ * @returns {object} The merged object
137
+ */
138
+ static mergeObject(...sources: object[]): object;
139
+ /**
140
+ * Filters an array asynchronously using a predicate function.
141
+ * Applies the predicate to all items in parallel and returns filtered results.
142
+ *
143
+ * @param {Array<unknown>} arr - The array to filter
144
+ * @param {(value: unknown) => Promise<boolean>} predicate - Async predicate function that returns a promise resolving to boolean
145
+ * @returns {Promise<Array<unknown>>} Promise resolving to the filtered array
146
+ */
147
+ static asyncFilter(arr: Array<unknown>, predicate: (value: unknown) => Promise<boolean>): Promise<Array<unknown>>;
148
+ /**
149
+ * Ensures a value is within a specified range.
150
+ *
151
+ * @param {number} val - The value to check.
152
+ * @param {number} min - The minimum value.
153
+ * @param {number} max - The maximum value.
154
+ * @returns {number} The value, constrained within the range of `min` to `max`.
155
+ */
156
+ static clamp(val: number, min: number, max: number): number;
157
+ /**
158
+ * Checks if a value is within a specified range (inclusive).
159
+ *
160
+ * @param {number} val - The value to check.
161
+ * @param {number} min - The minimum value (inclusive).
162
+ * @param {number} max - The maximum value (inclusive).
163
+ * @returns {boolean} True if the value is within the range, false otherwise.
164
+ */
165
+ static clamped(val: number, min: number, max: number): boolean;
166
+ /**
167
+ * Checks if a value is a plain object - created with object literals {},
168
+ * new Object(), or Object.create(null).
169
+ *
170
+ * Distinguishes plain objects from objects created by custom constructors, built-ins,
171
+ * or primitives. Plain objects only have Object.prototype or null in their prototype chain.
172
+ *
173
+ * @param {unknown} value - The value to check
174
+ * @returns {boolean} True if the value is a plain object, false otherwise
175
+ *
176
+ * @example
177
+ * isPlainObject({}) // true
178
+ * isPlainObject(new Object()) // true
179
+ * isPlainObject(Object.create(null)) // true
180
+ * isPlainObject([]) // false
181
+ * isPlainObject(new Date()) // false
182
+ * isPlainObject(null) // false
183
+ * isPlainObject("string") // false
184
+ * isPlainObject(class Person{}) // false
185
+ */
186
+ static isPlainObject(value: unknown): boolean;
187
+ }
188
+ import TypeSpec from "./TypeSpec.js";
189
+ //# sourceMappingURL=Data.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Data.d.ts","sourceRoot":"","sources":["../../lib/Data.js"],"names":[],"mappings":"AAUA;IACA;;;;;OAKG;IACD,mBAFQ,KAAK,CAAC,MAAM,CAAC,CAgBnB;IAEF;;;;;OAKG;IACH,qBAFU,KAAK,CAAC,MAAM,CAAC,CAmBrB;IAEF;;;;;;;OAOG;IACH,kBAFU,KAAK,CAAC,MAAM,CAAC,CAKrB;IAEF;;;;;OAKG;IACH,uBAFU,KAAK,CAAC,MAAM,CAAC,CAE6C;IAEpE;;;;;;OAMG;IACH,4BAJW,MAAM,UACN,MAAM,GACJ,MAAM,CAIlB;IAED;;;;;;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