fable 3.1.71 → 3.1.73
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/docs/README.md +30 -6
- package/docs/_brand.json +18 -0
- package/docs/_playground.json +10 -0
- package/docs/_sidebar.md +2 -0
- package/docs/_version.json +3 -3
- package/docs/architecture.md +201 -39
- package/docs/index.html +6 -7
- package/docs/pict-docuserve.min.js +91 -0
- package/docs/pict-docuserve.min.js.map +1 -0
- package/docs/playground.md +38 -0
- package/docs/retold-catalog.json +1 -1
- package/docs/retold-keyword-index.json +8721 -8105
- package/docs/services/README.md +26 -9
- package/docs/services/anticipate.md +104 -40
- package/docs/services/csv-parser.md +63 -35
- package/docs/services/data-format.md +154 -49
- package/docs/services/data-generation.md +77 -16
- package/docs/services/dates.md +103 -36
- package/docs/services/environment-data.md +13 -2
- package/docs/services/expression-parser.md +280 -68
- package/docs/services/file-persistence.md +142 -150
- package/docs/services/logging.md +93 -37
- package/docs/services/logic.md +70 -22
- package/docs/services/manifest.md +114 -26
- package/docs/services/math.md +168 -63
- package/docs/services/meta-template.md +312 -158
- package/docs/services/object-cache.md +94 -11
- package/docs/services/operation.md +68 -6
- package/docs/services/progress-time.md +74 -13
- package/docs/services/progress-tracker-set.md +101 -3
- package/docs/services/rest-client.md +136 -104
- package/docs/services/settings-manager.md +133 -40
- package/docs/services/template.md +71 -22
- package/docs/services/utility.md +121 -29
- package/docs/services/uuid.md +58 -10
- package/package.json +4 -4
- package/source/services/Fable-Service-RestClient.js +204 -7
- package/test/RestClient_test.js +342 -0
- package/.claude/settings.local.json +0 -8
package/docs/services/utility.md
CHANGED
|
@@ -5,8 +5,11 @@ The Utility service provides general-purpose helper functions including object m
|
|
|
5
5
|
## Access
|
|
6
6
|
|
|
7
7
|
```javascript
|
|
8
|
+
const libFable = require('fable');
|
|
9
|
+
const fable = new libFable({ Product: 'UtilityDemo', ProductVersion: '1.0.0' });
|
|
10
|
+
|
|
8
11
|
// Auto-instantiated, available directly
|
|
9
|
-
fable.Utility
|
|
12
|
+
console.log('fable.Utility:', typeof fable.Utility);
|
|
10
13
|
```
|
|
11
14
|
|
|
12
15
|
## Object Extension
|
|
@@ -14,12 +17,16 @@ fable.Utility
|
|
|
14
17
|
Shallow merge objects (similar to `Object.assign` or lodash `_.extend`):
|
|
15
18
|
|
|
16
19
|
```javascript
|
|
20
|
+
const libFable = require('fable');
|
|
21
|
+
const fable = new libFable({ Product: 'UtilityDemo', ProductVersion: '1.0.0' });
|
|
22
|
+
|
|
17
23
|
const target = { a: 1 };
|
|
18
24
|
const source1 = { b: 2 };
|
|
19
25
|
const source2 = { c: 3 };
|
|
20
26
|
|
|
21
27
|
fable.Utility.extend(target, source1, source2);
|
|
22
28
|
// target is now { a: 1, b: 2, c: 3 }
|
|
29
|
+
console.log('target:', target);
|
|
23
30
|
```
|
|
24
31
|
|
|
25
32
|
## Template Compilation
|
|
@@ -27,11 +34,14 @@ fable.Utility.extend(target, source1, source2);
|
|
|
27
34
|
Create underscore/lodash-style templates:
|
|
28
35
|
|
|
29
36
|
```javascript
|
|
37
|
+
const libFable = require('fable');
|
|
38
|
+
const fable = new libFable({ Product: 'UtilityDemo', ProductVersion: '1.0.0' });
|
|
39
|
+
|
|
30
40
|
// Create a template function
|
|
31
41
|
const template = fable.Utility.template('Hello, <%= name %>!');
|
|
32
42
|
|
|
33
43
|
// Use it
|
|
34
|
-
template({ name: 'World' }); // Returns 'Hello, World!'
|
|
44
|
+
console.log(template({ name: 'World' })); // Returns 'Hello, World!'
|
|
35
45
|
|
|
36
46
|
// With execution code
|
|
37
47
|
const listTemplate = fable.Utility.template(`
|
|
@@ -42,7 +52,7 @@ const listTemplate = fable.Utility.template(`
|
|
|
42
52
|
</ul>
|
|
43
53
|
`);
|
|
44
54
|
|
|
45
|
-
listTemplate({ items: ['Apple', 'Banana', 'Cherry'] });
|
|
55
|
+
console.log(listTemplate({ items: ['Apple', 'Banana', 'Cherry'] }));
|
|
46
56
|
```
|
|
47
57
|
|
|
48
58
|
### Immediate Rendering
|
|
@@ -50,7 +60,10 @@ listTemplate({ items: ['Apple', 'Banana', 'Cherry'] });
|
|
|
50
60
|
Pass data as the second argument to render immediately instead of getting a function:
|
|
51
61
|
|
|
52
62
|
```javascript
|
|
53
|
-
|
|
63
|
+
const libFable = require('fable');
|
|
64
|
+
const fable = new libFable({ Product: 'UtilityDemo', ProductVersion: '1.0.0' });
|
|
65
|
+
|
|
66
|
+
console.log(fable.Utility.template('There are <%= Count %> things....', { Count: 1000 }));
|
|
54
67
|
// Returns the string 'There are 1000 things....' directly (not a function)
|
|
55
68
|
```
|
|
56
69
|
|
|
@@ -59,11 +72,14 @@ fable.Utility.template('There are <%= Count %> things....', { Count: 1000 });
|
|
|
59
72
|
Register templates for reuse:
|
|
60
73
|
|
|
61
74
|
```javascript
|
|
75
|
+
const libFable = require('fable');
|
|
76
|
+
const fable = new libFable({ Product: 'UtilityDemo', ProductVersion: '1.0.0' });
|
|
77
|
+
|
|
62
78
|
// Build and register a template
|
|
63
79
|
fable.Utility.buildHashedTemplate('greeting', 'Hello, <%= name %>!');
|
|
64
80
|
|
|
65
81
|
// Access the compiled template
|
|
66
|
-
fable.Utility.templates.greeting({ name: 'World' });
|
|
82
|
+
console.log(fable.Utility.templates.greeting({ name: 'World' }));
|
|
67
83
|
```
|
|
68
84
|
|
|
69
85
|
## Array Operations
|
|
@@ -73,10 +89,13 @@ fable.Utility.templates.greeting({ name: 'World' });
|
|
|
73
89
|
Split an array into chunks of specified size:
|
|
74
90
|
|
|
75
91
|
```javascript
|
|
76
|
-
|
|
92
|
+
const libFable = require('fable');
|
|
93
|
+
const fable = new libFable({ Product: 'UtilityDemo', ProductVersion: '1.0.0' });
|
|
94
|
+
|
|
95
|
+
console.log(fable.Utility.chunk([1, 2, 3, 4, 5, 6, 7], 3));
|
|
77
96
|
// Returns [[1, 2, 3], [4, 5, 6], [7]]
|
|
78
97
|
|
|
79
|
-
fable.Utility.chunk([1, 2, 3, 4], 2);
|
|
98
|
+
console.log(fable.Utility.chunk([1, 2, 3, 4], 2));
|
|
80
99
|
// Returns [[1, 2], [3, 4]]
|
|
81
100
|
```
|
|
82
101
|
|
|
@@ -85,21 +104,30 @@ fable.Utility.chunk([1, 2, 3, 4], 2);
|
|
|
85
104
|
Extract a portion of an array:
|
|
86
105
|
|
|
87
106
|
```javascript
|
|
88
|
-
|
|
107
|
+
const libFable = require('fable');
|
|
108
|
+
const fable = new libFable({ Product: 'UtilityDemo', ProductVersion: '1.0.0' });
|
|
109
|
+
|
|
110
|
+
console.log(fable.Utility.slice([1, 2, 3, 4, 5], 1, 4));
|
|
89
111
|
// Returns [2, 3, 4]
|
|
90
112
|
```
|
|
91
113
|
|
|
92
114
|
### Concatenate Arrays
|
|
93
115
|
|
|
94
116
|
```javascript
|
|
95
|
-
|
|
117
|
+
const libFable = require('fable');
|
|
118
|
+
const fable = new libFable({ Product: 'UtilityDemo', ProductVersion: '1.0.0' });
|
|
119
|
+
|
|
120
|
+
console.log(fable.Utility.concatenateArrays([1, 2], [3, 4], [5, 6]));
|
|
96
121
|
// Returns [1, 2, 3, 4, 5, 6]
|
|
97
122
|
```
|
|
98
123
|
|
|
99
124
|
### Flatten Arrays
|
|
100
125
|
|
|
101
126
|
```javascript
|
|
102
|
-
|
|
127
|
+
const libFable = require('fable');
|
|
128
|
+
const fable = new libFable({ Product: 'UtilityDemo', ProductVersion: '1.0.0' });
|
|
129
|
+
|
|
130
|
+
console.log(fable.Utility.flattenArrayOfSolverInputs([[1, 2], [3, 4]]));
|
|
103
131
|
// Returns [1, 2, 3, 4]
|
|
104
132
|
```
|
|
105
133
|
|
|
@@ -108,14 +136,20 @@ fable.Utility.flattenArrayOfSolverInputs([[1, 2], [3, 4]]);
|
|
|
108
136
|
### Keys to Array
|
|
109
137
|
|
|
110
138
|
```javascript
|
|
111
|
-
|
|
139
|
+
const libFable = require('fable');
|
|
140
|
+
const fable = new libFable({ Product: 'UtilityDemo', ProductVersion: '1.0.0' });
|
|
141
|
+
|
|
142
|
+
console.log(fable.Utility.objectKeysToArray({ a: 1, b: 2, c: 3 }));
|
|
112
143
|
// Returns ['a', 'b', 'c']
|
|
113
144
|
```
|
|
114
145
|
|
|
115
146
|
### Values to Array
|
|
116
147
|
|
|
117
148
|
```javascript
|
|
118
|
-
|
|
149
|
+
const libFable = require('fable');
|
|
150
|
+
const fable = new libFable({ Product: 'UtilityDemo', ProductVersion: '1.0.0' });
|
|
151
|
+
|
|
152
|
+
console.log(fable.Utility.objectValuesToArray({ a: 1, b: 2, c: 3 }));
|
|
119
153
|
// Returns [1, 2, 3]
|
|
120
154
|
```
|
|
121
155
|
|
|
@@ -124,10 +158,13 @@ fable.Utility.objectValuesToArray({ a: 1, b: 2, c: 3 });
|
|
|
124
158
|
Takes pairs of `(propertyName, valuesObject)` and zips them into an array of objects. Values are extracted from each object using `objectValuesToArray`:
|
|
125
159
|
|
|
126
160
|
```javascript
|
|
127
|
-
fable
|
|
161
|
+
const libFable = require('fable');
|
|
162
|
+
const fable = new libFable({ Product: 'UtilityDemo', ProductVersion: '1.0.0' });
|
|
163
|
+
|
|
164
|
+
console.log(fable.Utility.generateArrayOfObjectsFromSets(
|
|
128
165
|
'x', { a: 1, b: 2, c: 3 },
|
|
129
166
|
'y', { d: 4, e: 5, f: 6 }
|
|
130
|
-
);
|
|
167
|
+
));
|
|
131
168
|
// Returns [{ x: 1, y: 4 }, { x: 2, y: 5 }, { x: 3, y: 6 }]
|
|
132
169
|
```
|
|
133
170
|
|
|
@@ -140,18 +177,25 @@ Access nested object values using dot notation paths:
|
|
|
140
177
|
### Get Value
|
|
141
178
|
|
|
142
179
|
```javascript
|
|
180
|
+
const libFable = require('fable');
|
|
181
|
+
const fable = new libFable({ Product: 'UtilityDemo', ProductVersion: '1.0.0' });
|
|
182
|
+
|
|
143
183
|
const obj = { user: { profile: { name: 'John' } } };
|
|
144
184
|
|
|
145
|
-
fable.Utility.getValueByHash(obj, 'user.profile.name');
|
|
185
|
+
console.log(fable.Utility.getValueByHash(obj, 'user.profile.name'));
|
|
146
186
|
// Returns 'John'
|
|
147
187
|
```
|
|
148
188
|
|
|
149
189
|
### Set Value
|
|
150
190
|
|
|
151
191
|
```javascript
|
|
192
|
+
const libFable = require('fable');
|
|
193
|
+
const fable = new libFable({ Product: 'UtilityDemo', ProductVersion: '1.0.0' });
|
|
194
|
+
|
|
152
195
|
const obj = {};
|
|
153
196
|
fable.Utility.setValueByHash(obj, 'user.profile.name', 'John');
|
|
154
197
|
// obj is now { user: { profile: { name: 'John' } } }
|
|
198
|
+
console.log('obj:', obj);
|
|
155
199
|
```
|
|
156
200
|
|
|
157
201
|
### Get Internal Value
|
|
@@ -159,15 +203,21 @@ fable.Utility.setValueByHash(obj, 'user.profile.name', 'John');
|
|
|
159
203
|
Access values from the Fable instance itself:
|
|
160
204
|
|
|
161
205
|
```javascript
|
|
162
|
-
|
|
206
|
+
const libFable = require('fable');
|
|
207
|
+
const fable = new libFable({ Product: 'InternalDemoProduct', ProductVersion: '1.0.0' });
|
|
208
|
+
|
|
209
|
+
console.log(fable.Utility.getInternalValueByHash('settings.Product'));
|
|
163
210
|
```
|
|
164
211
|
|
|
165
212
|
### Check for Null or Empty
|
|
166
213
|
|
|
167
214
|
```javascript
|
|
168
|
-
|
|
169
|
-
fable
|
|
170
|
-
|
|
215
|
+
const libFable = require('fable');
|
|
216
|
+
const fable = new libFable({ Product: 'UtilityDemo', ProductVersion: '1.0.0' });
|
|
217
|
+
|
|
218
|
+
console.log(fable.Utility.addressIsNullOrEmpty({ name: '' }, 'name')); // true
|
|
219
|
+
console.log(fable.Utility.addressIsNullOrEmpty({ name: 'John' }, 'name')); // false
|
|
220
|
+
console.log(fable.Utility.addressIsNullOrEmpty({}, 'name')); // true
|
|
171
221
|
```
|
|
172
222
|
|
|
173
223
|
## Array Value Collection
|
|
@@ -175,16 +225,22 @@ fable.Utility.addressIsNullOrEmpty({}, 'name'); // true
|
|
|
175
225
|
### Create Value Array from Hashes
|
|
176
226
|
|
|
177
227
|
```javascript
|
|
228
|
+
const libFable = require('fable');
|
|
229
|
+
const fable = new libFable({ Product: 'UtilityDemo', ProductVersion: '1.0.0' });
|
|
230
|
+
|
|
178
231
|
const obj = { a: 1, b: 2, c: 3 };
|
|
179
|
-
fable.Utility.createValueArrayByHashes(obj, ['a', 'c']);
|
|
232
|
+
console.log(fable.Utility.createValueArrayByHashes(obj, ['a', 'c']));
|
|
180
233
|
// Returns [1, 3]
|
|
181
234
|
```
|
|
182
235
|
|
|
183
236
|
### Create Value Object from Hashes
|
|
184
237
|
|
|
185
238
|
```javascript
|
|
239
|
+
const libFable = require('fable');
|
|
240
|
+
const fable = new libFable({ Product: 'UtilityDemo', ProductVersion: '1.0.0' });
|
|
241
|
+
|
|
186
242
|
const obj = { a: 1, b: 2, c: 3, d: 4 };
|
|
187
|
-
fable.Utility.createValueObjectByHashes(obj, ['a', 'c']);
|
|
243
|
+
console.log(fable.Utility.createValueObjectByHashes(obj, ['a', 'c']));
|
|
188
244
|
// Returns { a: 1, c: 3 }
|
|
189
245
|
```
|
|
190
246
|
|
|
@@ -193,33 +249,42 @@ fable.Utility.createValueObjectByHashes(obj, ['a', 'c']);
|
|
|
193
249
|
### Find by String Includes
|
|
194
250
|
|
|
195
251
|
```javascript
|
|
252
|
+
const libFable = require('fable');
|
|
253
|
+
const fable = new libFable({ Product: 'UtilityDemo', ProductVersion: '1.0.0' });
|
|
254
|
+
|
|
196
255
|
const items = [
|
|
197
256
|
{ name: 'Apple iPhone', price: 999 },
|
|
198
257
|
{ name: 'Samsung Galaxy', price: 899 },
|
|
199
258
|
{ name: 'Google Pixel', price: 799 }
|
|
200
259
|
];
|
|
201
260
|
|
|
202
|
-
fable.Utility.findFirstValueByStringIncludes(items, 'name', 'Samsung', 'price');
|
|
261
|
+
console.log(fable.Utility.findFirstValueByStringIncludes(items, 'name', 'Samsung', 'price'));
|
|
203
262
|
// Returns 899
|
|
204
263
|
```
|
|
205
264
|
|
|
206
265
|
### Find by Exact Match
|
|
207
266
|
|
|
208
267
|
```javascript
|
|
268
|
+
const libFable = require('fable');
|
|
269
|
+
const fable = new libFable({ Product: 'UtilityDemo', ProductVersion: '1.0.0' });
|
|
270
|
+
|
|
209
271
|
const items = [
|
|
210
272
|
{ id: 1, name: 'Alice' },
|
|
211
273
|
{ id: 2, name: 'Bob' }
|
|
212
274
|
];
|
|
213
275
|
|
|
214
|
-
fable.Utility.findFirstValueByExactMatch(items, 'name', 'Bob', 'id');
|
|
276
|
+
console.log(fable.Utility.findFirstValueByExactMatch(items, 'name', 'Bob', 'id'));
|
|
215
277
|
// Returns 2
|
|
216
278
|
```
|
|
217
279
|
|
|
218
280
|
### Find Index
|
|
219
281
|
|
|
220
282
|
```javascript
|
|
221
|
-
|
|
222
|
-
fable
|
|
283
|
+
const libFable = require('fable');
|
|
284
|
+
const fable = new libFable({ Product: 'UtilityDemo', ProductVersion: '1.0.0' });
|
|
285
|
+
|
|
286
|
+
console.log(fable.Utility.findIndexInternal('5', [1, 3, 5, 7, 9], '0')); // Exact match, returns 2
|
|
287
|
+
console.log(fable.Utility.findIndexInternal('4', [1, 3, 5, 7, 9], '1')); // Ascending search, returns 2
|
|
223
288
|
```
|
|
224
289
|
|
|
225
290
|
## Sorting
|
|
@@ -227,6 +292,9 @@ fable.Utility.findIndexInternal('4', [1, 3, 5, 7, 9], '1'); // Ascending search
|
|
|
227
292
|
### Sort by External Array
|
|
228
293
|
|
|
229
294
|
```javascript
|
|
295
|
+
const libFable = require('fable');
|
|
296
|
+
const fable = new libFable({ Product: 'UtilityDemo', ProductVersion: '1.0.0' });
|
|
297
|
+
|
|
230
298
|
const values = [100, 200, 300];
|
|
231
299
|
const objects = [
|
|
232
300
|
{ label: 'C' },
|
|
@@ -234,7 +302,7 @@ const objects = [
|
|
|
234
302
|
{ label: 'B' }
|
|
235
303
|
];
|
|
236
304
|
|
|
237
|
-
fable.Utility.objectValuesSortByExternalArray(values, objects, false, 'label');
|
|
305
|
+
console.log(fable.Utility.objectValuesSortByExternalArray(values, objects, false, 'label'));
|
|
238
306
|
// Sorts values based on object labels: [200, 300, 100] (A, B, C order)
|
|
239
307
|
```
|
|
240
308
|
|
|
@@ -243,7 +311,10 @@ fable.Utility.objectValuesSortByExternalArray(values, objects, false, 'label');
|
|
|
243
311
|
Convert ISO strings to JavaScript Date objects:
|
|
244
312
|
|
|
245
313
|
```javascript
|
|
246
|
-
|
|
314
|
+
const libFable = require('fable');
|
|
315
|
+
const fable = new libFable({ Product: 'UtilityDemo', ProductVersion: '1.0.0' });
|
|
316
|
+
|
|
317
|
+
console.log(fable.Utility.isoStringToDate('2024-01-15T12:30:00.000Z'));
|
|
247
318
|
// Returns JavaScript Date object
|
|
248
319
|
```
|
|
249
320
|
|
|
@@ -254,6 +325,9 @@ fable.Utility.isoStringToDate('2024-01-15T12:30:00.000Z');
|
|
|
254
325
|
Execute functions in sequence, passing results to the next:
|
|
255
326
|
|
|
256
327
|
```javascript
|
|
328
|
+
const libFable = require('fable');
|
|
329
|
+
const fable = new libFable({ Product: 'UtilityDemo', ProductVersion: '1.0.0' });
|
|
330
|
+
|
|
257
331
|
fable.Utility.waterfall([
|
|
258
332
|
(callback) => {
|
|
259
333
|
callback(null, 'one', 'two');
|
|
@@ -268,6 +342,7 @@ fable.Utility.waterfall([
|
|
|
268
342
|
}
|
|
269
343
|
], (err, result) => {
|
|
270
344
|
// result = 'done'
|
|
345
|
+
console.log('waterfall finished — err:', err, 'result:', result);
|
|
271
346
|
});
|
|
272
347
|
```
|
|
273
348
|
|
|
@@ -276,6 +351,15 @@ fable.Utility.waterfall([
|
|
|
276
351
|
Process array items in parallel with concurrency limit:
|
|
277
352
|
|
|
278
353
|
```javascript
|
|
354
|
+
const libFable = require('fable');
|
|
355
|
+
const fable = new libFable({ Product: 'UtilityDemo', ProductVersion: '1.0.0' });
|
|
356
|
+
|
|
357
|
+
// Stub for the playground demo — real code would do real work per item
|
|
358
|
+
function processItem(item, callback) {
|
|
359
|
+
console.log('processing item', item);
|
|
360
|
+
callback(null);
|
|
361
|
+
}
|
|
362
|
+
|
|
279
363
|
fable.Utility.eachLimit(
|
|
280
364
|
[1, 2, 3, 4, 5], // Array to process
|
|
281
365
|
2, // Concurrency limit
|
|
@@ -283,7 +367,7 @@ fable.Utility.eachLimit(
|
|
|
283
367
|
processItem(item, callback);
|
|
284
368
|
},
|
|
285
369
|
(err) => { // Completion callback
|
|
286
|
-
console.log('All done');
|
|
370
|
+
console.log('All done — err:', err);
|
|
287
371
|
}
|
|
288
372
|
);
|
|
289
373
|
```
|
|
@@ -293,12 +377,20 @@ fable.Utility.eachLimit(
|
|
|
293
377
|
Direct access to the big.js library for arbitrary precision:
|
|
294
378
|
|
|
295
379
|
```javascript
|
|
380
|
+
const libFable = require('fable');
|
|
381
|
+
const fable = new libFable({ Product: 'UtilityDemo', ProductVersion: '1.0.0' });
|
|
382
|
+
|
|
296
383
|
const bigNum = new fable.Utility.bigNumber('123456789012345678901234567890');
|
|
384
|
+
console.log('bigNum:', bigNum.toString());
|
|
385
|
+
console.log('bigNum * 2:', bigNum.times(2).toString());
|
|
297
386
|
```
|
|
298
387
|
|
|
299
388
|
## Create Array from Values
|
|
300
389
|
|
|
301
390
|
```javascript
|
|
302
|
-
|
|
391
|
+
const libFable = require('fable');
|
|
392
|
+
const fable = new libFable({ Product: 'UtilityDemo', ProductVersion: '1.0.0' });
|
|
393
|
+
|
|
394
|
+
console.log(fable.Utility.createArrayFromAbsoluteValues(1, 2, 3, 4, 5));
|
|
303
395
|
// Returns [1, 2, 3, 4, 5]
|
|
304
396
|
```
|
package/docs/services/uuid.md
CHANGED
|
@@ -5,9 +5,12 @@ The UUID service generates unique identifiers with optional DataCenter and Worke
|
|
|
5
5
|
## Access
|
|
6
6
|
|
|
7
7
|
```javascript
|
|
8
|
+
const libFable = require('fable');
|
|
9
|
+
const fable = new libFable({ Product: 'UUIDDemo', ProductVersion: '1.0.0' });
|
|
10
|
+
|
|
8
11
|
// Pre-initialized, available directly
|
|
9
|
-
fable.UUID
|
|
10
|
-
fable.getUUID() // Convenience method
|
|
12
|
+
console.log('fable.UUID:', typeof fable.UUID);
|
|
13
|
+
console.log('fable.getUUID():', fable.getUUID()); // Convenience method
|
|
11
14
|
```
|
|
12
15
|
|
|
13
16
|
## Basic Usage
|
|
@@ -15,11 +18,16 @@ fable.getUUID() // Convenience method
|
|
|
15
18
|
### Generate a UUID
|
|
16
19
|
|
|
17
20
|
```javascript
|
|
21
|
+
const libFable = require('fable');
|
|
22
|
+
const fable = new libFable({ Product: 'UUIDDemo', ProductVersion: '1.0.0' });
|
|
23
|
+
|
|
18
24
|
const uuid = fable.getUUID();
|
|
25
|
+
console.log('uuid (via convenience):', uuid);
|
|
19
26
|
// Returns something like: '0x53c7c0bed0010000'
|
|
20
27
|
|
|
21
28
|
// Or via the service directly
|
|
22
|
-
const
|
|
29
|
+
const uuidDirect = fable.UUID.getUUID();
|
|
30
|
+
console.log('uuid (via service):', uuidDirect);
|
|
23
31
|
```
|
|
24
32
|
|
|
25
33
|
## Configuration
|
|
@@ -27,12 +35,15 @@ const uuid = fable.UUID.getUUID();
|
|
|
27
35
|
Configure DataCenter and Worker IDs when creating Fable:
|
|
28
36
|
|
|
29
37
|
```javascript
|
|
30
|
-
const
|
|
38
|
+
const libFable = require('fable');
|
|
39
|
+
const fable = new libFable({
|
|
31
40
|
UUID: {
|
|
32
41
|
DataCenter: 1, // 0-31
|
|
33
42
|
Worker: 5 // 0-31
|
|
34
43
|
}
|
|
35
44
|
});
|
|
45
|
+
console.log('DataCenter:', fable.UUID.datacenter, 'Worker:', fable.UUID.worker);
|
|
46
|
+
console.log('Sample UUID:', fable.getUUID());
|
|
36
47
|
```
|
|
37
48
|
|
|
38
49
|
### DataCenter and Worker
|
|
@@ -61,21 +72,30 @@ The generated UUIDs are based on the Snowflake pattern:
|
|
|
61
72
|
### Database Primary Keys
|
|
62
73
|
|
|
63
74
|
```javascript
|
|
75
|
+
const libFable = require('fable');
|
|
76
|
+
const fable = new libFable({ Product: 'UUIDDemo', ProductVersion: '1.0.0' });
|
|
77
|
+
|
|
64
78
|
const user = {
|
|
65
79
|
id: fable.getUUID(),
|
|
66
80
|
name: 'John Doe',
|
|
67
81
|
email: 'john@example.com'
|
|
68
82
|
};
|
|
83
|
+
console.log('user:', user);
|
|
69
84
|
```
|
|
70
85
|
|
|
71
86
|
### Request Tracing
|
|
72
87
|
|
|
73
88
|
```javascript
|
|
89
|
+
const libFable = require('fable');
|
|
90
|
+
const fable = new libFable({ Product: 'UUIDDemo', ProductVersion: '1.0.0' });
|
|
91
|
+
|
|
74
92
|
const requestId = fable.getUUID();
|
|
75
93
|
fable.log.info('Processing request', { requestId });
|
|
76
94
|
|
|
77
|
-
// Pass through the system
|
|
95
|
+
// Pass through the system (stubbed response object for playground demo)
|
|
96
|
+
const response = { _headers: {}, setHeader(name, value) { this._headers[name] = value; } };
|
|
78
97
|
response.setHeader('X-Request-ID', requestId);
|
|
98
|
+
console.log('response headers:', response._headers);
|
|
79
99
|
```
|
|
80
100
|
|
|
81
101
|
### Distributed Systems
|
|
@@ -83,21 +103,29 @@ response.setHeader('X-Request-ID', requestId);
|
|
|
83
103
|
Configure each node with unique DataCenter/Worker:
|
|
84
104
|
|
|
85
105
|
```javascript
|
|
106
|
+
const libFable = require('fable');
|
|
107
|
+
|
|
86
108
|
// Node 1 (DC 0, Worker 0)
|
|
87
|
-
const fable1 = new
|
|
109
|
+
const fable1 = new libFable({ UUID: { DataCenter: 0, Worker: 0 } });
|
|
88
110
|
|
|
89
111
|
// Node 2 (DC 0, Worker 1)
|
|
90
|
-
const fable2 = new
|
|
112
|
+
const fable2 = new libFable({ UUID: { DataCenter: 0, Worker: 1 } });
|
|
91
113
|
|
|
92
114
|
// Node 3 (DC 1, Worker 0)
|
|
93
|
-
const fable3 = new
|
|
115
|
+
const fable3 = new libFable({ UUID: { DataCenter: 1, Worker: 0 } });
|
|
94
116
|
|
|
95
117
|
// All nodes can generate UUIDs without collision
|
|
118
|
+
console.log('Node 1 UUID:', fable1.getUUID());
|
|
119
|
+
console.log('Node 2 UUID:', fable2.getUUID());
|
|
120
|
+
console.log('Node 3 UUID:', fable3.getUUID());
|
|
96
121
|
```
|
|
97
122
|
|
|
98
123
|
### Session IDs
|
|
99
124
|
|
|
100
125
|
```javascript
|
|
126
|
+
const libFable = require('fable');
|
|
127
|
+
const fable = new libFable({ Product: 'UUIDDemo', ProductVersion: '1.0.0' });
|
|
128
|
+
|
|
101
129
|
function createSession(userId) {
|
|
102
130
|
return {
|
|
103
131
|
sessionId: fable.getUUID(),
|
|
@@ -105,12 +133,18 @@ function createSession(userId) {
|
|
|
105
133
|
createdAt: new Date()
|
|
106
134
|
};
|
|
107
135
|
}
|
|
136
|
+
|
|
137
|
+
console.log('session:', createSession('user-42'));
|
|
108
138
|
```
|
|
109
139
|
|
|
110
140
|
### File Names
|
|
111
141
|
|
|
112
142
|
```javascript
|
|
143
|
+
const libFable = require('fable');
|
|
144
|
+
const fable = new libFable({ Product: 'UUIDDemo', ProductVersion: '1.0.0' });
|
|
145
|
+
|
|
113
146
|
const uniqueFileName = `upload_${fable.getUUID()}.jpg`;
|
|
147
|
+
console.log('uniqueFileName:', uniqueFileName);
|
|
114
148
|
```
|
|
115
149
|
|
|
116
150
|
## Properties
|
|
@@ -118,13 +152,19 @@ const uniqueFileName = `upload_${fable.getUUID()}.jpg`;
|
|
|
118
152
|
### DataCenter ID
|
|
119
153
|
|
|
120
154
|
```javascript
|
|
121
|
-
|
|
155
|
+
const libFable = require('fable');
|
|
156
|
+
const fable = new libFable({ UUID: { DataCenter: 3, Worker: 7 } });
|
|
157
|
+
|
|
158
|
+
console.log('Current DataCenter ID:', fable.UUID.datacenter);
|
|
122
159
|
```
|
|
123
160
|
|
|
124
161
|
### Worker ID
|
|
125
162
|
|
|
126
163
|
```javascript
|
|
127
|
-
|
|
164
|
+
const libFable = require('fable');
|
|
165
|
+
const fable = new libFable({ UUID: { DataCenter: 3, Worker: 7 } });
|
|
166
|
+
|
|
167
|
+
console.log('Current Worker ID:', fable.UUID.worker);
|
|
128
168
|
```
|
|
129
169
|
|
|
130
170
|
## Best Practices
|
|
@@ -152,6 +192,9 @@ Fable UUIDs are:
|
|
|
152
192
|
If migrating from UUID v4 or other formats:
|
|
153
193
|
|
|
154
194
|
```javascript
|
|
195
|
+
const libFable = require('fable');
|
|
196
|
+
const fable = new libFable({ Product: 'UUIDDemo', ProductVersion: '1.0.0' });
|
|
197
|
+
|
|
155
198
|
// Continue supporting both formats
|
|
156
199
|
function isValidId(id) {
|
|
157
200
|
return id.startsWith('0x') || /^[0-9a-f-]{36}$/i.test(id);
|
|
@@ -159,4 +202,9 @@ function isValidId(id) {
|
|
|
159
202
|
|
|
160
203
|
// Generate new IDs with Fable
|
|
161
204
|
const newId = fable.getUUID();
|
|
205
|
+
console.log('newId:', newId, '-> isValidId:', isValidId(newId));
|
|
206
|
+
|
|
207
|
+
// Check a legacy UUID v4 string as well
|
|
208
|
+
const legacy = '550e8400-e29b-41d4-a716-446655440000';
|
|
209
|
+
console.log('legacy:', legacy, '-> isValidId:', isValidId(legacy));
|
|
162
210
|
```
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "fable",
|
|
3
|
-
"version": "3.1.
|
|
3
|
+
"version": "3.1.73",
|
|
4
4
|
"description": "A service dependency injection, configuration and logging library.",
|
|
5
5
|
"main": "source/Fable.js",
|
|
6
6
|
"scripts": {
|
|
@@ -51,8 +51,8 @@
|
|
|
51
51
|
},
|
|
52
52
|
"homepage": "https://github.com/stevenvelozo/fable",
|
|
53
53
|
"devDependencies": {
|
|
54
|
-
"pict-docuserve": "^
|
|
55
|
-
"quackage": "^1.
|
|
54
|
+
"pict-docuserve": "^1.3.0",
|
|
55
|
+
"quackage": "^1.2.3"
|
|
56
56
|
},
|
|
57
57
|
"dependencies": {
|
|
58
58
|
"async.eachlimit": "^0.5.2",
|
|
@@ -65,7 +65,7 @@
|
|
|
65
65
|
"fable-log": "^3.0.18",
|
|
66
66
|
"fable-serviceproviderbase": "^3.0.19",
|
|
67
67
|
"fable-settings": "^3.0.16",
|
|
68
|
-
"fable-uuid": "^3.0.
|
|
68
|
+
"fable-uuid": "^3.0.14",
|
|
69
69
|
"manyfest": "^1.0.49",
|
|
70
70
|
"simple-get": "^4.0.1"
|
|
71
71
|
}
|