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
|
@@ -5,8 +5,13 @@ The FilePersistence service provides file system operations for reading and writ
|
|
|
5
5
|
## Access
|
|
6
6
|
|
|
7
7
|
```javascript
|
|
8
|
+
const libFable = require('fable');
|
|
9
|
+
const fable = new libFable({ Product: 'FilePersistDemo', ProductVersion: '1.0.0' });
|
|
10
|
+
|
|
8
11
|
// On-demand service - instantiate when needed
|
|
12
|
+
// (Browser implementation is a stub; full file system access requires Node.js.)
|
|
9
13
|
const filePersistence = fable.instantiateServiceProvider('FilePersistence');
|
|
14
|
+
console.log('filePersistence:', typeof filePersistence);
|
|
10
15
|
```
|
|
11
16
|
|
|
12
17
|
## Browser vs Node.js
|
|
@@ -21,31 +26,31 @@ Fable automatically uses the appropriate implementation:
|
|
|
21
26
|
### Read File (Async)
|
|
22
27
|
|
|
23
28
|
```javascript
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
return;
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
});
|
|
29
|
+
// Node.js reference — browser playground has no fs.
|
|
30
|
+
console.info("In Node.js:");
|
|
31
|
+
console.info(" filePersistence.readFile('/path/to/file.txt', 'utf8', (error, content) => {");
|
|
32
|
+
console.info(" if (error) { console.error('Read error:', error); return; }");
|
|
33
|
+
console.info(" console.log('Content:', content);");
|
|
34
|
+
console.info(" });");
|
|
31
35
|
```
|
|
32
36
|
|
|
33
37
|
### Read File Sync
|
|
34
38
|
|
|
35
39
|
```javascript
|
|
36
|
-
|
|
40
|
+
// Node.js reference — browser playground has no fs.
|
|
41
|
+
console.info("In Node.js:");
|
|
42
|
+
console.info(" const content = filePersistence.readFileSync('/path/to/file.txt', 'utf8');");
|
|
37
43
|
```
|
|
38
44
|
|
|
39
45
|
### Read JSON File
|
|
40
46
|
|
|
41
47
|
```javascript
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
return;
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
});
|
|
48
|
+
// Node.js reference — browser playground has no fs.
|
|
49
|
+
console.info("In Node.js:");
|
|
50
|
+
console.info(" filePersistence.readJSONFile('/path/to/data.json', (error, data) => {");
|
|
51
|
+
console.info(" if (error) { console.error('Failed to read JSON:', error); return; }");
|
|
52
|
+
console.info(" console.log('Data:', data);");
|
|
53
|
+
console.info(" });");
|
|
49
54
|
```
|
|
50
55
|
|
|
51
56
|
## Writing Files
|
|
@@ -53,33 +58,32 @@ filePersistence.readJSONFile('/path/to/data.json', (error, data) => {
|
|
|
53
58
|
### Write File (Async)
|
|
54
59
|
|
|
55
60
|
```javascript
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
return;
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
});
|
|
61
|
+
// Node.js reference — browser playground has no fs.
|
|
62
|
+
console.info("In Node.js:");
|
|
63
|
+
console.info(" filePersistence.writeFile('/path/to/file.txt', 'Hello, World!', 'utf8', (error) => {");
|
|
64
|
+
console.info(" if (error) { console.error('Write error:', error); return; }");
|
|
65
|
+
console.info(" console.log('File written successfully');");
|
|
66
|
+
console.info(" });");
|
|
63
67
|
```
|
|
64
68
|
|
|
65
69
|
### Write File Sync
|
|
66
70
|
|
|
67
71
|
```javascript
|
|
68
|
-
|
|
72
|
+
// Node.js reference — browser playground has no fs.
|
|
73
|
+
console.info("In Node.js:");
|
|
74
|
+
console.info(" filePersistence.writeFileSync('/path/to/file.txt', 'Hello, World!', 'utf8');");
|
|
69
75
|
```
|
|
70
76
|
|
|
71
77
|
### Write JSON File
|
|
72
78
|
|
|
73
79
|
```javascript
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
console.error('Failed to write JSON:', error);
|
|
79
|
-
|
|
80
|
-
}
|
|
81
|
-
console.log('JSON written successfully');
|
|
82
|
-
});
|
|
80
|
+
// Node.js reference — browser playground has no fs.
|
|
81
|
+
console.info("In Node.js:");
|
|
82
|
+
console.info(" const data = { name: 'John', age: 30 };");
|
|
83
|
+
console.info(" filePersistence.writeJSONFile('/path/to/data.json', data, (error) => {");
|
|
84
|
+
console.info(" if (error) { console.error('Failed to write JSON:', error); return; }");
|
|
85
|
+
console.info(" console.log('JSON written successfully');");
|
|
86
|
+
console.info(" });");
|
|
83
87
|
```
|
|
84
88
|
|
|
85
89
|
## CSV File Operations
|
|
@@ -87,51 +91,41 @@ filePersistence.writeJSONFile('/path/to/data.json', data, (error) => {
|
|
|
87
91
|
### Read CSV File
|
|
88
92
|
|
|
89
93
|
```javascript
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
return;
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
rows.forEach(row => {
|
|
98
|
-
console.log(row.join(', '));
|
|
99
|
-
});
|
|
100
|
-
});
|
|
94
|
+
// Node.js reference — browser playground has no fs.
|
|
95
|
+
console.info("In Node.js:");
|
|
96
|
+
console.info(" filePersistence.readCSVFile('/path/to/data.csv', (error, rows) => {");
|
|
97
|
+
console.info(" if (error) { console.error('Failed to read CSV:', error); return; }");
|
|
98
|
+
console.info(" // rows is an array of arrays");
|
|
99
|
+
console.info(" rows.forEach(row => console.log(row.join(', ')));");
|
|
100
|
+
console.info(" });");
|
|
101
101
|
```
|
|
102
102
|
|
|
103
103
|
### Read CSV to Objects
|
|
104
104
|
|
|
105
105
|
```javascript
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
return;
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
objects.forEach(obj => {
|
|
114
|
-
console.log(obj.name, obj.age);
|
|
115
|
-
});
|
|
116
|
-
});
|
|
106
|
+
// Node.js reference — browser playground has no fs.
|
|
107
|
+
console.info("In Node.js:");
|
|
108
|
+
console.info(" filePersistence.readCSVFileToObjects('/path/to/data.csv', (error, objects) => {");
|
|
109
|
+
console.info(" if (error) { console.error('Failed to read CSV:', error); return; }");
|
|
110
|
+
console.info(" // objects is an array of objects with headers as keys");
|
|
111
|
+
console.info(" objects.forEach(obj => console.log(obj.name, obj.age));");
|
|
112
|
+
console.info(" });");
|
|
117
113
|
```
|
|
118
114
|
|
|
119
115
|
### Write CSV File
|
|
120
116
|
|
|
121
117
|
```javascript
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
];
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
console.error('Failed to write CSV:', error);
|
|
131
|
-
|
|
132
|
-
}
|
|
133
|
-
console.log('CSV written successfully');
|
|
134
|
-
});
|
|
118
|
+
// Node.js reference — browser playground has no fs.
|
|
119
|
+
console.info("In Node.js:");
|
|
120
|
+
console.info(" const rows = [");
|
|
121
|
+
console.info(" ['name', 'age', 'city'],");
|
|
122
|
+
console.info(" ['John', '30', 'New York'],");
|
|
123
|
+
console.info(" ['Jane', '25', 'Los Angeles']");
|
|
124
|
+
console.info(" ];");
|
|
125
|
+
console.info(" filePersistence.writeCSVFile('/path/to/output.csv', rows, (error) => {");
|
|
126
|
+
console.info(" if (error) { console.error('Failed to write CSV:', error); return; }");
|
|
127
|
+
console.info(" console.log('CSV written successfully');");
|
|
128
|
+
console.info(" });");
|
|
135
129
|
```
|
|
136
130
|
|
|
137
131
|
## Directory Operations
|
|
@@ -139,43 +133,47 @@ filePersistence.writeCSVFile('/path/to/output.csv', rows, (error) => {
|
|
|
139
133
|
### Check if File Exists
|
|
140
134
|
|
|
141
135
|
```javascript
|
|
142
|
-
|
|
136
|
+
// Node.js reference — browser playground has no fs.
|
|
137
|
+
console.info("In Node.js:");
|
|
138
|
+
console.info(" const exists = filePersistence.fileExists('/path/to/file.txt');");
|
|
143
139
|
```
|
|
144
140
|
|
|
145
141
|
### Check if Directory Exists
|
|
146
142
|
|
|
147
143
|
```javascript
|
|
148
|
-
|
|
144
|
+
// Node.js reference — browser playground has no fs.
|
|
145
|
+
console.info("In Node.js:");
|
|
146
|
+
console.info(" const exists = filePersistence.directoryExists('/path/to/directory');");
|
|
149
147
|
```
|
|
150
148
|
|
|
151
149
|
### Create Directory
|
|
152
150
|
|
|
153
151
|
```javascript
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
return;
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
});
|
|
152
|
+
// Node.js reference — browser playground has no fs.
|
|
153
|
+
console.info("In Node.js:");
|
|
154
|
+
console.info(" filePersistence.createDirectory('/path/to/new/directory', (error) => {");
|
|
155
|
+
console.info(" if (error) { console.error('Failed to create directory:', error); return; }");
|
|
156
|
+
console.info(" console.log('Directory created');");
|
|
157
|
+
console.info(" });");
|
|
161
158
|
```
|
|
162
159
|
|
|
163
160
|
### Create Directory Sync
|
|
164
161
|
|
|
165
162
|
```javascript
|
|
166
|
-
|
|
163
|
+
// Node.js reference — browser playground has no fs.
|
|
164
|
+
console.info("In Node.js:");
|
|
165
|
+
console.info(" filePersistence.createDirectorySync('/path/to/new/directory');");
|
|
167
166
|
```
|
|
168
167
|
|
|
169
168
|
### List Directory
|
|
170
169
|
|
|
171
170
|
```javascript
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
return;
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
});
|
|
171
|
+
// Node.js reference — browser playground has no fs.
|
|
172
|
+
console.info("In Node.js:");
|
|
173
|
+
console.info(" filePersistence.listDirectory('/path/to/directory', (error, files) => {");
|
|
174
|
+
console.info(" if (error) { console.error('Failed to list directory:', error); return; }");
|
|
175
|
+
console.info(" files.forEach(file => console.log(file));");
|
|
176
|
+
console.info(" });");
|
|
179
177
|
```
|
|
180
178
|
|
|
181
179
|
## Use Cases
|
|
@@ -183,92 +181,86 @@ filePersistence.listDirectory('/path/to/directory', (error, files) => {
|
|
|
183
181
|
### Configuration Loading
|
|
184
182
|
|
|
185
183
|
```javascript
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
}
|
|
184
|
+
// Node.js reference — wraps the callback API in a Promise. Browser playground has no fs.
|
|
185
|
+
console.info("In Node.js:");
|
|
186
|
+
console.info(" function loadConfig(configPath) {");
|
|
187
|
+
console.info(" const filePersistence = fable.instantiateServiceProvider('FilePersistence');");
|
|
188
|
+
console.info(" return new Promise((resolve, reject) => {");
|
|
189
|
+
console.info(" filePersistence.readJSONFile(configPath, (error, config) => {");
|
|
190
|
+
console.info(" if (error) reject(error);");
|
|
191
|
+
console.info(" else resolve(config);");
|
|
192
|
+
console.info(" });");
|
|
193
|
+
console.info(" });");
|
|
194
|
+
console.info(" }");
|
|
196
195
|
```
|
|
197
196
|
|
|
198
197
|
### Log File Writing
|
|
199
198
|
|
|
200
199
|
```javascript
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
}
|
|
200
|
+
// Node.js reference — browser playground has no fs.
|
|
201
|
+
console.info("In Node.js:");
|
|
202
|
+
console.info(" function appendToLog(message) {");
|
|
203
|
+
console.info(" const filePersistence = fable.instantiateServiceProvider('FilePersistence');");
|
|
204
|
+
console.info(" const logPath = '/var/log/myapp/app.log';");
|
|
205
|
+
console.info(" const timestamp = new Date().toISOString();");
|
|
206
|
+
console.info(" const line = `${timestamp} - ${message}\\n`;");
|
|
207
|
+
console.info(" filePersistence.appendFile(logPath, line, 'utf8', (error) => {");
|
|
208
|
+
console.info(" if (error) console.error('Failed to write log:', error);");
|
|
209
|
+
console.info(" });");
|
|
210
|
+
console.info(" }");
|
|
211
211
|
```
|
|
212
212
|
|
|
213
213
|
### Data Export
|
|
214
214
|
|
|
215
215
|
```javascript
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
err ? reject(err) : resolve();
|
|
223
|
-
});
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
}
|
|
229
|
-
});
|
|
230
|
-
}
|
|
216
|
+
// Node.js reference — browser playground has no fs.
|
|
217
|
+
console.info("In Node.js:");
|
|
218
|
+
console.info(" async function exportData(data, format, outputPath) {");
|
|
219
|
+
console.info(" const filePersistence = fable.instantiateServiceProvider('FilePersistence');");
|
|
220
|
+
console.info(" return new Promise((resolve, reject) => {");
|
|
221
|
+
console.info(" if (format === 'json') {");
|
|
222
|
+
console.info(" filePersistence.writeJSONFile(outputPath, data, (err) => err ? reject(err) : resolve());");
|
|
223
|
+
console.info(" } else if (format === 'csv') {");
|
|
224
|
+
console.info(" filePersistence.writeCSVFile(outputPath, data, (err) => err ? reject(err) : resolve());");
|
|
225
|
+
console.info(" }");
|
|
226
|
+
console.info(" });");
|
|
227
|
+
console.info(" }");
|
|
231
228
|
```
|
|
232
229
|
|
|
233
230
|
### Batch File Processing
|
|
234
231
|
|
|
235
232
|
```javascript
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
});
|
|
252
|
-
});
|
|
253
|
-
}
|
|
233
|
+
// Node.js reference — browser playground has no fs.
|
|
234
|
+
console.info("In Node.js:");
|
|
235
|
+
console.info(" function processFiles(directory, processor) {");
|
|
236
|
+
console.info(" const filePersistence = fable.instantiateServiceProvider('FilePersistence');");
|
|
237
|
+
console.info(" filePersistence.listDirectory(directory, (error, files) => {");
|
|
238
|
+
console.info(" if (error) throw error;");
|
|
239
|
+
console.info(" files.forEach(file => {");
|
|
240
|
+
console.info(" const fullPath = `${directory}/${file}`;");
|
|
241
|
+
console.info(" filePersistence.readFile(fullPath, 'utf8', (err, content) => {");
|
|
242
|
+
console.info(" if (err) { console.error(`Failed to read ${file}:`, err); return; }");
|
|
243
|
+
console.info(" processor(file, content);");
|
|
244
|
+
console.info(" });");
|
|
245
|
+
console.info(" });");
|
|
246
|
+
console.info(" });");
|
|
247
|
+
console.info(" }");
|
|
254
248
|
```
|
|
255
249
|
|
|
256
250
|
## Error Handling
|
|
257
251
|
|
|
258
252
|
```javascript
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
console.log('Permission denied');
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
}
|
|
268
|
-
|
|
269
|
-
}
|
|
270
|
-
// Process content
|
|
271
|
-
});
|
|
253
|
+
// Node.js reference — browser playground has no fs.
|
|
254
|
+
console.info("In Node.js:");
|
|
255
|
+
console.info(" filePersistence.readFile('/nonexistent/file.txt', 'utf8', (error, content) => {");
|
|
256
|
+
console.info(" if (error) {");
|
|
257
|
+
console.info(" if (error.code === 'ENOENT') console.log('File does not exist');");
|
|
258
|
+
console.info(" else if (error.code === 'EACCES') console.log('Permission denied');");
|
|
259
|
+
console.info(" else console.error('Unexpected error:', error);");
|
|
260
|
+
console.info(" return;");
|
|
261
|
+
console.info(" }");
|
|
262
|
+
console.info(" // Process content");
|
|
263
|
+
console.info(" });");
|
|
272
264
|
```
|
|
273
265
|
|
|
274
266
|
## Notes
|