@promptbook/legacy-documents 0.78.0-0 → 0.78.3
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/README.md +0 -4
- package/esm/index.es.js +246 -192
- package/esm/index.es.js.map +1 -1
- package/esm/typings/src/_packages/core.index.d.ts +4 -0
- package/esm/typings/src/_packages/types.index.d.ts +0 -2
- package/esm/typings/src/commands/_common/types/CommandType.d.ts +1 -1
- package/esm/typings/src/config.d.ts +14 -0
- package/esm/typings/src/errors/utils/getErrorReportUrl.d.ts +6 -0
- package/esm/typings/src/execution/execution-report/ExecutionReportString.d.ts +1 -1
- package/esm/typings/src/llm-providers/openai/openai-models.d.ts +1 -1
- package/esm/typings/src/pipeline/PipelineString.d.ts +1 -1
- package/package.json +2 -2
- package/umd/index.umd.js +246 -192
- package/umd/index.umd.js.map +1 -1
package/README.md
CHANGED
|
@@ -23,10 +23,6 @@
|
|
|
23
23
|
|
|
24
24
|
|
|
25
25
|
|
|
26
|
-
<blockquote style="color: #ff8811">
|
|
27
|
-
<b>⚠ Warning:</b> This is a pre-release version of the library. It is not yet ready for production use. Please look at <a href="https://www.npmjs.com/package/@promptbook/core?activeTab=versions">latest stable release</a>.
|
|
28
|
-
</blockquote>
|
|
29
|
-
|
|
30
26
|
## 📦 Package `@promptbook/legacy-documents`
|
|
31
27
|
|
|
32
28
|
- Promptbooks are [divided into several](#-packages) packages, all are published from [single monorepo](https://github.com/webgptorg/promptbook).
|
package/esm/index.es.js
CHANGED
|
@@ -23,7 +23,7 @@ var BOOK_LANGUAGE_VERSION = '1.0.0';
|
|
|
23
23
|
*
|
|
24
24
|
* @see https://github.com/webgptorg/promptbook
|
|
25
25
|
*/
|
|
26
|
-
var PROMPTBOOK_ENGINE_VERSION = '0.
|
|
26
|
+
var PROMPTBOOK_ENGINE_VERSION = '0.78.2';
|
|
27
27
|
/**
|
|
28
28
|
* TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
|
|
29
29
|
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
@@ -169,198 +169,25 @@ function just(value) {
|
|
|
169
169
|
}
|
|
170
170
|
|
|
171
171
|
/**
|
|
172
|
-
*
|
|
172
|
+
* Name for the Promptbook
|
|
173
173
|
*
|
|
174
|
-
*
|
|
175
|
-
* Note: This function mutates the object and returns the original (but mutated-deep-freezed) object
|
|
176
|
-
*
|
|
177
|
-
* @returns The same object as the input, but deeply frozen
|
|
178
|
-
* @public exported from `@promptbook/utils`
|
|
179
|
-
*/
|
|
180
|
-
function $deepFreeze(objectValue) {
|
|
181
|
-
var e_1, _a;
|
|
182
|
-
var propertyNames = Object.getOwnPropertyNames(objectValue);
|
|
183
|
-
try {
|
|
184
|
-
for (var propertyNames_1 = __values(propertyNames), propertyNames_1_1 = propertyNames_1.next(); !propertyNames_1_1.done; propertyNames_1_1 = propertyNames_1.next()) {
|
|
185
|
-
var propertyName = propertyNames_1_1.value;
|
|
186
|
-
var value = objectValue[propertyName];
|
|
187
|
-
if (value && typeof value === 'object') {
|
|
188
|
-
$deepFreeze(value);
|
|
189
|
-
}
|
|
190
|
-
}
|
|
191
|
-
}
|
|
192
|
-
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
193
|
-
finally {
|
|
194
|
-
try {
|
|
195
|
-
if (propertyNames_1_1 && !propertyNames_1_1.done && (_a = propertyNames_1.return)) _a.call(propertyNames_1);
|
|
196
|
-
}
|
|
197
|
-
finally { if (e_1) throw e_1.error; }
|
|
198
|
-
}
|
|
199
|
-
return Object.freeze(objectValue);
|
|
200
|
-
}
|
|
201
|
-
/**
|
|
202
|
-
* TODO: [🧠] Is there a way how to meaningfully test this utility
|
|
203
|
-
*/
|
|
204
|
-
|
|
205
|
-
/**
|
|
206
|
-
* This error type indicates that the error should not happen and its last check before crashing with some other error
|
|
174
|
+
* TODO: [🗽] Unite branding and make single place for it
|
|
207
175
|
*
|
|
208
176
|
* @public exported from `@promptbook/core`
|
|
209
177
|
*/
|
|
210
|
-
var
|
|
211
|
-
__extends(UnexpectedError, _super);
|
|
212
|
-
function UnexpectedError(message) {
|
|
213
|
-
var _this = _super.call(this, spaceTrim(function (block) { return "\n ".concat(block(message), "\n\n Note: This error should not happen.\n It's probbably a bug in the pipeline collection\n\n Please report issue:\n https://github.com/webgptorg/promptbook/issues\n\n Or contact us on me@pavolhejny.com\n\n "); })) || this;
|
|
214
|
-
_this.name = 'UnexpectedError';
|
|
215
|
-
Object.setPrototypeOf(_this, UnexpectedError.prototype);
|
|
216
|
-
return _this;
|
|
217
|
-
}
|
|
218
|
-
return UnexpectedError;
|
|
219
|
-
}(Error));
|
|
220
|
-
|
|
178
|
+
var NAME = "Promptbook";
|
|
221
179
|
/**
|
|
222
|
-
*
|
|
223
|
-
* If not, throws an UnexpectedError with a rich error message and tracking
|
|
180
|
+
* Email of the responsible person
|
|
224
181
|
*
|
|
225
|
-
*
|
|
226
|
-
* - `undefined` is not serializable
|
|
227
|
-
* - `NaN` is not serializable
|
|
228
|
-
* - Objects and arrays are serializable if all their properties are serializable
|
|
229
|
-
* - Functions are not serializable
|
|
230
|
-
* - Circular references are not serializable
|
|
231
|
-
* - `Date` objects are not serializable
|
|
232
|
-
* - `Map` and `Set` objects are not serializable
|
|
233
|
-
* - `RegExp` objects are not serializable
|
|
234
|
-
* - `Error` objects are not serializable
|
|
235
|
-
* - `Symbol` objects are not serializable
|
|
236
|
-
* - And much more...
|
|
237
|
-
*
|
|
238
|
-
* @throws UnexpectedError if the value is not serializable as JSON
|
|
239
|
-
* @public exported from `@promptbook/utils`
|
|
240
|
-
*/
|
|
241
|
-
function checkSerializableAsJson(name, value) {
|
|
242
|
-
var e_1, _a;
|
|
243
|
-
if (value === undefined) {
|
|
244
|
-
throw new UnexpectedError("".concat(name, " is undefined"));
|
|
245
|
-
}
|
|
246
|
-
else if (value === null) {
|
|
247
|
-
return;
|
|
248
|
-
}
|
|
249
|
-
else if (typeof value === 'boolean') {
|
|
250
|
-
return;
|
|
251
|
-
}
|
|
252
|
-
else if (typeof value === 'number' && !isNaN(value)) {
|
|
253
|
-
return;
|
|
254
|
-
}
|
|
255
|
-
else if (typeof value === 'string') {
|
|
256
|
-
return;
|
|
257
|
-
}
|
|
258
|
-
else if (typeof value === 'symbol') {
|
|
259
|
-
throw new UnexpectedError("".concat(name, " is symbol"));
|
|
260
|
-
}
|
|
261
|
-
else if (typeof value === 'function') {
|
|
262
|
-
throw new UnexpectedError("".concat(name, " is function"));
|
|
263
|
-
}
|
|
264
|
-
else if (typeof value === 'object' && Array.isArray(value)) {
|
|
265
|
-
for (var i = 0; i < value.length; i++) {
|
|
266
|
-
checkSerializableAsJson("".concat(name, "[").concat(i, "]"), value[i]);
|
|
267
|
-
}
|
|
268
|
-
}
|
|
269
|
-
else if (typeof value === 'object') {
|
|
270
|
-
if (value instanceof Date) {
|
|
271
|
-
throw new UnexpectedError(spaceTrim$1("\n ".concat(name, " is Date\n\n Use `string_date_iso8601` instead\n ")));
|
|
272
|
-
}
|
|
273
|
-
else if (value instanceof Map) {
|
|
274
|
-
throw new UnexpectedError("".concat(name, " is Map"));
|
|
275
|
-
}
|
|
276
|
-
else if (value instanceof Set) {
|
|
277
|
-
throw new UnexpectedError("".concat(name, " is Set"));
|
|
278
|
-
}
|
|
279
|
-
else if (value instanceof RegExp) {
|
|
280
|
-
throw new UnexpectedError("".concat(name, " is RegExp"));
|
|
281
|
-
}
|
|
282
|
-
else if (value instanceof Error) {
|
|
283
|
-
throw new UnexpectedError(spaceTrim$1("\n ".concat(name, " is unserialized Error\n\n Use function `serializeError`\n ")));
|
|
284
|
-
}
|
|
285
|
-
else {
|
|
286
|
-
try {
|
|
287
|
-
for (var _b = __values(Object.entries(value)), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
288
|
-
var _d = __read(_c.value, 2), subName = _d[0], subValue = _d[1];
|
|
289
|
-
if (subValue === undefined) {
|
|
290
|
-
// Note: undefined in object is serializable - it is just omited
|
|
291
|
-
continue;
|
|
292
|
-
}
|
|
293
|
-
checkSerializableAsJson("".concat(name, ".").concat(subName), subValue);
|
|
294
|
-
}
|
|
295
|
-
}
|
|
296
|
-
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
297
|
-
finally {
|
|
298
|
-
try {
|
|
299
|
-
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
300
|
-
}
|
|
301
|
-
finally { if (e_1) throw e_1.error; }
|
|
302
|
-
}
|
|
303
|
-
try {
|
|
304
|
-
JSON.stringify(value); // <- TODO: [0]
|
|
305
|
-
}
|
|
306
|
-
catch (error) {
|
|
307
|
-
if (!(error instanceof Error)) {
|
|
308
|
-
throw error;
|
|
309
|
-
}
|
|
310
|
-
throw new UnexpectedError(spaceTrim$1(function (block) { return "\n ".concat(name, " is not serializable\n\n ").concat(block(error.toString()), "\n "); }));
|
|
311
|
-
}
|
|
312
|
-
/*
|
|
313
|
-
TODO: [0] Is there some more elegant way to check circular references?
|
|
314
|
-
const seen = new Set();
|
|
315
|
-
const stack = [{ value }];
|
|
316
|
-
while (stack.length > 0) {
|
|
317
|
-
const { value } = stack.pop()!;
|
|
318
|
-
if (typeof value === 'object' && value !== null) {
|
|
319
|
-
if (seen.has(value)) {
|
|
320
|
-
throw new UnexpectedError(`${name} has circular reference`);
|
|
321
|
-
}
|
|
322
|
-
seen.add(value);
|
|
323
|
-
if (Array.isArray(value)) {
|
|
324
|
-
stack.push(...value.map((value) => ({ value })));
|
|
325
|
-
} else {
|
|
326
|
-
stack.push(...Object.values(value).map((value) => ({ value })));
|
|
327
|
-
}
|
|
328
|
-
}
|
|
329
|
-
}
|
|
330
|
-
*/
|
|
331
|
-
return;
|
|
332
|
-
}
|
|
333
|
-
}
|
|
334
|
-
else {
|
|
335
|
-
throw new UnexpectedError("".concat(name, " is unknown"));
|
|
336
|
-
}
|
|
337
|
-
}
|
|
338
|
-
/**
|
|
339
|
-
* TODO: [🧠][🛣] More elegant way to tracking than passing `name`
|
|
340
|
-
* TODO: [🧠][main] !!! In-memory cache of same values to prevent multiple checks
|
|
341
|
-
* Note: [🐠] This is how `checkSerializableAsJson` + `isSerializableAsJson` together can just retun true/false or rich error message
|
|
182
|
+
* @public exported from `@promptbook/core`
|
|
342
183
|
*/
|
|
343
|
-
|
|
184
|
+
var ADMIN_EMAIL = 'me@pavolhejny.com';
|
|
344
185
|
/**
|
|
345
|
-
*
|
|
346
|
-
* @@@
|
|
347
|
-
*
|
|
348
|
-
* Note: This function mutates the object and returns the original (but mutated-deep-freezed) object
|
|
186
|
+
* Name of the responsible person for the Promptbook on GitHub
|
|
349
187
|
*
|
|
350
|
-
* @
|
|
351
|
-
* @param objectValue - Object to be deeply frozen
|
|
352
|
-
* @returns The same object as the input, but deeply frozen
|
|
353
|
-
* @private this is in comparison to `deepFreeze` a more specific utility and maybe not very good practice to use without specific reason and considerations
|
|
354
|
-
*/
|
|
355
|
-
function $asDeeplyFrozenSerializableJson(name, objectValue) {
|
|
356
|
-
checkSerializableAsJson(name, objectValue);
|
|
357
|
-
return $deepFreeze(objectValue);
|
|
358
|
-
}
|
|
359
|
-
/**
|
|
360
|
-
* TODO: [🧠][🛣] More elegant way to tracking than passing `name`
|
|
361
|
-
* TODO: [🧠] Is there a way how to meaningfully test this utility
|
|
188
|
+
* @public exported from `@promptbook/core`
|
|
362
189
|
*/
|
|
363
|
-
|
|
190
|
+
var ADMIN_GITHUB_NAME = 'hejny';
|
|
364
191
|
// <- TODO: [🧠] Better system for generator warnings - not always "code" and "by `@promptbook/cli`"
|
|
365
192
|
/**
|
|
366
193
|
* The maximum number of iterations for a loops
|
|
@@ -412,7 +239,8 @@ var REPLACING_NONCE = 'u$k42k%!V2zo34w7Fu#@QUHYPW';
|
|
|
412
239
|
*
|
|
413
240
|
* @public exported from `@promptbook/core`
|
|
414
241
|
*/
|
|
415
|
-
var RESERVED_PARAMETER_NAMES =
|
|
242
|
+
var RESERVED_PARAMETER_NAMES =
|
|
243
|
+
/* !!!!!! $asDeeplyFrozenSerializableJson('RESERVED_PARAMETER_NAMES', _____ as const); */ [
|
|
416
244
|
'content',
|
|
417
245
|
'context',
|
|
418
246
|
'knowledge',
|
|
@@ -422,7 +250,7 @@ var RESERVED_PARAMETER_NAMES = $asDeeplyFrozenSerializableJson('RESERVED_PARAMET
|
|
|
422
250
|
// <- TODO: list here all command names
|
|
423
251
|
// <- TODO: Add more like 'date', 'modelName',...
|
|
424
252
|
// <- TODO: Add [emoji] + instructions ACRY when adding new reserved parameter
|
|
425
|
-
]
|
|
253
|
+
];
|
|
426
254
|
/**
|
|
427
255
|
* @@@
|
|
428
256
|
*
|
|
@@ -522,6 +350,40 @@ var MissingToolsError = /** @class */ (function (_super) {
|
|
|
522
350
|
return MissingToolsError;
|
|
523
351
|
}(Error));
|
|
524
352
|
|
|
353
|
+
/**
|
|
354
|
+
* Make error report URL for the given error
|
|
355
|
+
*
|
|
356
|
+
* @private !!!!!!
|
|
357
|
+
*/
|
|
358
|
+
function getErrorReportUrl(error) {
|
|
359
|
+
var report = {
|
|
360
|
+
title: "\uD83D\uDC1C Error report from ".concat(NAME),
|
|
361
|
+
body: spaceTrim$1(function (block) { return "\n\n\n `".concat(error.name || 'Error', "` has occurred in the [").concat(NAME, "], please look into it @").concat(ADMIN_GITHUB_NAME, ".\n\n ```\n ").concat(block(error.message || '(no error message)'), "\n ```\n\n\n ## More info:\n\n - **Promptbook engine version:** ").concat(PROMPTBOOK_ENGINE_VERSION, "\n - **Book language version:** ").concat(BOOK_LANGUAGE_VERSION, "\n - **Time:** ").concat(new Date().toISOString(), "\n\n <details>\n <summary>Stack trace:</summary>\n\n ## Stack trace:\n\n ```stacktrace\n ").concat(block(error.stack || '(empty)'), "\n ```\n </details>\n\n "); }),
|
|
362
|
+
};
|
|
363
|
+
var reportUrl = new URL("https://github.com/webgptorg/promptbook/issues/new");
|
|
364
|
+
reportUrl.searchParams.set('labels', 'bug');
|
|
365
|
+
reportUrl.searchParams.set('assignees', ADMIN_GITHUB_NAME);
|
|
366
|
+
reportUrl.searchParams.set('title', report.title);
|
|
367
|
+
reportUrl.searchParams.set('body', report.body);
|
|
368
|
+
return reportUrl;
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
/**
|
|
372
|
+
* This error type indicates that the error should not happen and its last check before crashing with some other error
|
|
373
|
+
*
|
|
374
|
+
* @public exported from `@promptbook/core`
|
|
375
|
+
*/
|
|
376
|
+
var UnexpectedError = /** @class */ (function (_super) {
|
|
377
|
+
__extends(UnexpectedError, _super);
|
|
378
|
+
function UnexpectedError(message) {
|
|
379
|
+
var _this = _super.call(this, spaceTrim(function (block) { return "\n ".concat(block(message), "\n\n Note: This error should not happen.\n It's probbably a bug in the pipeline collection\n\n Please report issue:\n ").concat(block(getErrorReportUrl(new Error(message)).href), "\n\n Or contact us on ").concat(ADMIN_EMAIL, "\n\n "); })) || this;
|
|
380
|
+
_this.name = 'UnexpectedError';
|
|
381
|
+
Object.setPrototypeOf(_this, UnexpectedError.prototype);
|
|
382
|
+
return _this;
|
|
383
|
+
}
|
|
384
|
+
return UnexpectedError;
|
|
385
|
+
}(Error));
|
|
386
|
+
|
|
525
387
|
/**
|
|
526
388
|
* Detects if the code is running in a Node.js environment
|
|
527
389
|
*
|
|
@@ -1974,6 +1836,183 @@ function extractParameterNames(template) {
|
|
|
1974
1836
|
return parameterNames;
|
|
1975
1837
|
}
|
|
1976
1838
|
|
|
1839
|
+
/**
|
|
1840
|
+
* @@@
|
|
1841
|
+
*
|
|
1842
|
+
* Note: `$` is used to indicate that this function is not a pure function - it mutates given object
|
|
1843
|
+
* Note: This function mutates the object and returns the original (but mutated-deep-freezed) object
|
|
1844
|
+
*
|
|
1845
|
+
* @returns The same object as the input, but deeply frozen
|
|
1846
|
+
* @public exported from `@promptbook/utils`
|
|
1847
|
+
*/
|
|
1848
|
+
function $deepFreeze(objectValue) {
|
|
1849
|
+
var e_1, _a;
|
|
1850
|
+
var propertyNames = Object.getOwnPropertyNames(objectValue);
|
|
1851
|
+
try {
|
|
1852
|
+
for (var propertyNames_1 = __values(propertyNames), propertyNames_1_1 = propertyNames_1.next(); !propertyNames_1_1.done; propertyNames_1_1 = propertyNames_1.next()) {
|
|
1853
|
+
var propertyName = propertyNames_1_1.value;
|
|
1854
|
+
var value = objectValue[propertyName];
|
|
1855
|
+
if (value && typeof value === 'object') {
|
|
1856
|
+
$deepFreeze(value);
|
|
1857
|
+
}
|
|
1858
|
+
}
|
|
1859
|
+
}
|
|
1860
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
1861
|
+
finally {
|
|
1862
|
+
try {
|
|
1863
|
+
if (propertyNames_1_1 && !propertyNames_1_1.done && (_a = propertyNames_1.return)) _a.call(propertyNames_1);
|
|
1864
|
+
}
|
|
1865
|
+
finally { if (e_1) throw e_1.error; }
|
|
1866
|
+
}
|
|
1867
|
+
return Object.freeze(objectValue);
|
|
1868
|
+
}
|
|
1869
|
+
/**
|
|
1870
|
+
* TODO: [🧠] Is there a way how to meaningfully test this utility
|
|
1871
|
+
*/
|
|
1872
|
+
|
|
1873
|
+
/**
|
|
1874
|
+
* Checks if the value is [🚉] serializable as JSON
|
|
1875
|
+
* If not, throws an UnexpectedError with a rich error message and tracking
|
|
1876
|
+
*
|
|
1877
|
+
* - Almost all primitives are serializable BUT:
|
|
1878
|
+
* - `undefined` is not serializable
|
|
1879
|
+
* - `NaN` is not serializable
|
|
1880
|
+
* - Objects and arrays are serializable if all their properties are serializable
|
|
1881
|
+
* - Functions are not serializable
|
|
1882
|
+
* - Circular references are not serializable
|
|
1883
|
+
* - `Date` objects are not serializable
|
|
1884
|
+
* - `Map` and `Set` objects are not serializable
|
|
1885
|
+
* - `RegExp` objects are not serializable
|
|
1886
|
+
* - `Error` objects are not serializable
|
|
1887
|
+
* - `Symbol` objects are not serializable
|
|
1888
|
+
* - And much more...
|
|
1889
|
+
*
|
|
1890
|
+
* @throws UnexpectedError if the value is not serializable as JSON
|
|
1891
|
+
* @public exported from `@promptbook/utils`
|
|
1892
|
+
*/
|
|
1893
|
+
function checkSerializableAsJson(name, value) {
|
|
1894
|
+
var e_1, _a;
|
|
1895
|
+
if (value === undefined) {
|
|
1896
|
+
throw new UnexpectedError("".concat(name, " is undefined"));
|
|
1897
|
+
}
|
|
1898
|
+
else if (value === null) {
|
|
1899
|
+
return;
|
|
1900
|
+
}
|
|
1901
|
+
else if (typeof value === 'boolean') {
|
|
1902
|
+
return;
|
|
1903
|
+
}
|
|
1904
|
+
else if (typeof value === 'number' && !isNaN(value)) {
|
|
1905
|
+
return;
|
|
1906
|
+
}
|
|
1907
|
+
else if (typeof value === 'string') {
|
|
1908
|
+
return;
|
|
1909
|
+
}
|
|
1910
|
+
else if (typeof value === 'symbol') {
|
|
1911
|
+
throw new UnexpectedError("".concat(name, " is symbol"));
|
|
1912
|
+
}
|
|
1913
|
+
else if (typeof value === 'function') {
|
|
1914
|
+
throw new UnexpectedError("".concat(name, " is function"));
|
|
1915
|
+
}
|
|
1916
|
+
else if (typeof value === 'object' && Array.isArray(value)) {
|
|
1917
|
+
for (var i = 0; i < value.length; i++) {
|
|
1918
|
+
checkSerializableAsJson("".concat(name, "[").concat(i, "]"), value[i]);
|
|
1919
|
+
}
|
|
1920
|
+
}
|
|
1921
|
+
else if (typeof value === 'object') {
|
|
1922
|
+
if (value instanceof Date) {
|
|
1923
|
+
throw new UnexpectedError(spaceTrim$1("\n ".concat(name, " is Date\n\n Use `string_date_iso8601` instead\n ")));
|
|
1924
|
+
}
|
|
1925
|
+
else if (value instanceof Map) {
|
|
1926
|
+
throw new UnexpectedError("".concat(name, " is Map"));
|
|
1927
|
+
}
|
|
1928
|
+
else if (value instanceof Set) {
|
|
1929
|
+
throw new UnexpectedError("".concat(name, " is Set"));
|
|
1930
|
+
}
|
|
1931
|
+
else if (value instanceof RegExp) {
|
|
1932
|
+
throw new UnexpectedError("".concat(name, " is RegExp"));
|
|
1933
|
+
}
|
|
1934
|
+
else if (value instanceof Error) {
|
|
1935
|
+
throw new UnexpectedError(spaceTrim$1("\n ".concat(name, " is unserialized Error\n\n Use function `serializeError`\n ")));
|
|
1936
|
+
}
|
|
1937
|
+
else {
|
|
1938
|
+
try {
|
|
1939
|
+
for (var _b = __values(Object.entries(value)), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
1940
|
+
var _d = __read(_c.value, 2), subName = _d[0], subValue = _d[1];
|
|
1941
|
+
if (subValue === undefined) {
|
|
1942
|
+
// Note: undefined in object is serializable - it is just omited
|
|
1943
|
+
continue;
|
|
1944
|
+
}
|
|
1945
|
+
checkSerializableAsJson("".concat(name, ".").concat(subName), subValue);
|
|
1946
|
+
}
|
|
1947
|
+
}
|
|
1948
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
1949
|
+
finally {
|
|
1950
|
+
try {
|
|
1951
|
+
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
1952
|
+
}
|
|
1953
|
+
finally { if (e_1) throw e_1.error; }
|
|
1954
|
+
}
|
|
1955
|
+
try {
|
|
1956
|
+
JSON.stringify(value); // <- TODO: [0]
|
|
1957
|
+
}
|
|
1958
|
+
catch (error) {
|
|
1959
|
+
if (!(error instanceof Error)) {
|
|
1960
|
+
throw error;
|
|
1961
|
+
}
|
|
1962
|
+
throw new UnexpectedError(spaceTrim$1(function (block) { return "\n ".concat(name, " is not serializable\n\n ").concat(block(error.toString()), "\n "); }));
|
|
1963
|
+
}
|
|
1964
|
+
/*
|
|
1965
|
+
TODO: [0] Is there some more elegant way to check circular references?
|
|
1966
|
+
const seen = new Set();
|
|
1967
|
+
const stack = [{ value }];
|
|
1968
|
+
while (stack.length > 0) {
|
|
1969
|
+
const { value } = stack.pop()!;
|
|
1970
|
+
if (typeof value === 'object' && value !== null) {
|
|
1971
|
+
if (seen.has(value)) {
|
|
1972
|
+
throw new UnexpectedError(`${name} has circular reference`);
|
|
1973
|
+
}
|
|
1974
|
+
seen.add(value);
|
|
1975
|
+
if (Array.isArray(value)) {
|
|
1976
|
+
stack.push(...value.map((value) => ({ value })));
|
|
1977
|
+
} else {
|
|
1978
|
+
stack.push(...Object.values(value).map((value) => ({ value })));
|
|
1979
|
+
}
|
|
1980
|
+
}
|
|
1981
|
+
}
|
|
1982
|
+
*/
|
|
1983
|
+
return;
|
|
1984
|
+
}
|
|
1985
|
+
}
|
|
1986
|
+
else {
|
|
1987
|
+
throw new UnexpectedError("".concat(name, " is unknown"));
|
|
1988
|
+
}
|
|
1989
|
+
}
|
|
1990
|
+
/**
|
|
1991
|
+
* TODO: [🧠][🛣] More elegant way to tracking than passing `name`
|
|
1992
|
+
* TODO: [🧠][main] !!! In-memory cache of same values to prevent multiple checks
|
|
1993
|
+
* Note: [🐠] This is how `checkSerializableAsJson` + `isSerializableAsJson` together can just retun true/false or rich error message
|
|
1994
|
+
*/
|
|
1995
|
+
|
|
1996
|
+
/**
|
|
1997
|
+
* @@@
|
|
1998
|
+
* @@@
|
|
1999
|
+
*
|
|
2000
|
+
* Note: This function mutates the object and returns the original (but mutated-deep-freezed) object
|
|
2001
|
+
*
|
|
2002
|
+
* @param name - Name of the object for debugging purposes
|
|
2003
|
+
* @param objectValue - Object to be deeply frozen
|
|
2004
|
+
* @returns The same object as the input, but deeply frozen
|
|
2005
|
+
* @private this is in comparison to `deepFreeze` a more specific utility and maybe not very good practice to use without specific reason and considerations
|
|
2006
|
+
*/
|
|
2007
|
+
function $asDeeplyFrozenSerializableJson(name, objectValue) {
|
|
2008
|
+
checkSerializableAsJson(name, objectValue);
|
|
2009
|
+
return $deepFreeze(objectValue);
|
|
2010
|
+
}
|
|
2011
|
+
/**
|
|
2012
|
+
* TODO: [🧠][🛣] More elegant way to tracking than passing `name`
|
|
2013
|
+
* TODO: [🧠] Is there a way how to meaningfully test this utility
|
|
2014
|
+
*/
|
|
2015
|
+
|
|
1977
2016
|
/**
|
|
1978
2017
|
* Unprepare just strips the preparation data of the pipeline
|
|
1979
2018
|
*
|
|
@@ -3844,6 +3883,7 @@ function preparePipeline(pipeline, tools, options) {
|
|
|
3844
3883
|
*/
|
|
3845
3884
|
function extractVariablesFromScript(script) {
|
|
3846
3885
|
var variables = new Set();
|
|
3886
|
+
var originalScript = script;
|
|
3847
3887
|
script = "(()=>{".concat(script, "})()");
|
|
3848
3888
|
try {
|
|
3849
3889
|
for (var i = 0; i < 100 /* <- TODO: This limit to configuration */; i++)
|
|
@@ -3854,20 +3894,32 @@ function extractVariablesFromScript(script) {
|
|
|
3854
3894
|
if (!(error instanceof ReferenceError)) {
|
|
3855
3895
|
throw error;
|
|
3856
3896
|
}
|
|
3857
|
-
var undefinedName = error.message.split(' ')[0];
|
|
3858
3897
|
/*
|
|
3859
3898
|
Note: Parsing the error
|
|
3899
|
+
🌟 Most devices:
|
|
3860
3900
|
[PipelineUrlError: thing is not defined]
|
|
3901
|
+
|
|
3902
|
+
🍏 iPhone`s Safari:
|
|
3903
|
+
[PipelineUrlError: Can't find variable: thing]
|
|
3861
3904
|
*/
|
|
3862
|
-
|
|
3905
|
+
var variableName = undefined;
|
|
3906
|
+
if (error.message.startsWith("Can't")) {
|
|
3907
|
+
// 🍏 Case
|
|
3908
|
+
variableName = error.message.split(' ').pop();
|
|
3909
|
+
}
|
|
3910
|
+
else {
|
|
3911
|
+
// 🌟 Case
|
|
3912
|
+
variableName = error.message.split(' ').shift();
|
|
3913
|
+
}
|
|
3914
|
+
if (variableName === undefined) {
|
|
3863
3915
|
throw error;
|
|
3864
3916
|
}
|
|
3865
|
-
if (script.includes(
|
|
3866
|
-
script = "const ".concat(
|
|
3917
|
+
if (script.includes(variableName + '(')) {
|
|
3918
|
+
script = "const ".concat(variableName, " = ()=>'';") + script;
|
|
3867
3919
|
}
|
|
3868
3920
|
else {
|
|
3869
|
-
variables.add(
|
|
3870
|
-
script = "const ".concat(
|
|
3921
|
+
variables.add(variableName);
|
|
3922
|
+
script = "const ".concat(variableName, " = '';") + script;
|
|
3871
3923
|
}
|
|
3872
3924
|
}
|
|
3873
3925
|
}
|
|
@@ -3875,7 +3927,9 @@ function extractVariablesFromScript(script) {
|
|
|
3875
3927
|
if (!(error instanceof Error)) {
|
|
3876
3928
|
throw error;
|
|
3877
3929
|
}
|
|
3878
|
-
throw new ParseError(spaceTrim(function (block) { return "\n Can not extract variables from the script\n\n ".concat(block(error.toString()), "}\n
|
|
3930
|
+
throw new ParseError(spaceTrim(function (block) { return "\n Can not extract variables from the script\n\n ".concat(block(error.toString()), "}\n\n\n Found variables:\n\n ").concat(Array.from(variables)
|
|
3931
|
+
.map(function (variableName, i) { return "".concat(i + 1, ") ").concat(variableName); })
|
|
3932
|
+
.join('\n'), "\n\n\n The script:\n\n ```javascript\n ").concat(block(originalScript), "\n ```\n "); }));
|
|
3879
3933
|
}
|
|
3880
3934
|
return variables;
|
|
3881
3935
|
}
|