@promptbook/website-crawler 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 +213 -159
- 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 +213 -159
- package/umd/index.umd.js.map +1 -1
|
@@ -5,6 +5,8 @@ import { createCollectionFromPromise } from '../collection/constructors/createCo
|
|
|
5
5
|
import { createCollectionFromUrl } from '../collection/constructors/createCollectionFromUrl';
|
|
6
6
|
import { createSubcollection } from '../collection/constructors/createSubcollection';
|
|
7
7
|
import { NAME } from '../config';
|
|
8
|
+
import { ADMIN_EMAIL } from '../config';
|
|
9
|
+
import { ADMIN_GITHUB_NAME } from '../config';
|
|
8
10
|
import { CLAIM } from '../config';
|
|
9
11
|
import { LOGO_LIGHT_SRC } from '../config';
|
|
10
12
|
import { LOGO_DARK_SRC } from '../config';
|
|
@@ -123,6 +125,8 @@ export { createCollectionFromPromise };
|
|
|
123
125
|
export { createCollectionFromUrl };
|
|
124
126
|
export { createSubcollection };
|
|
125
127
|
export { NAME };
|
|
128
|
+
export { ADMIN_EMAIL };
|
|
129
|
+
export { ADMIN_GITHUB_NAME };
|
|
126
130
|
export { CLAIM };
|
|
127
131
|
export { LOGO_LIGHT_SRC };
|
|
128
132
|
export { LOGO_DARK_SRC };
|
|
@@ -6,7 +6,6 @@ import type { PipelineHeadCommandParser } from '../commands/_common/types/Comman
|
|
|
6
6
|
import type { PipelineTaskCommandParser } from '../commands/_common/types/CommandParser';
|
|
7
7
|
import type { CommandParserInput } from '../commands/_common/types/CommandParser';
|
|
8
8
|
import type { CommandType } from '../commands/_common/types/CommandType';
|
|
9
|
-
import type { CommandTypeOrAlias } from '../commands/_common/types/CommandType';
|
|
10
9
|
import type { CommandUsagePlace } from '../commands/_common/types/CommandUsagePlaces';
|
|
11
10
|
import type { ExpectCommand } from '../commands/EXPECT/ExpectCommand';
|
|
12
11
|
import type { ForeachJson } from '../commands/FOREACH/ForeachJson';
|
|
@@ -266,7 +265,6 @@ export type { PipelineHeadCommandParser };
|
|
|
266
265
|
export type { PipelineTaskCommandParser };
|
|
267
266
|
export type { CommandParserInput };
|
|
268
267
|
export type { CommandType };
|
|
269
|
-
export type { CommandTypeOrAlias };
|
|
270
268
|
export type { CommandUsagePlace };
|
|
271
269
|
export type { ExpectCommand };
|
|
272
270
|
export type { ForeachJson };
|
|
@@ -12,6 +12,6 @@ export type CommandType = Command['type'];
|
|
|
12
12
|
*
|
|
13
13
|
* This is a type of the command like "KNOWLEDGE" or "PERSONA"
|
|
14
14
|
*
|
|
15
|
-
|
|
15
|
+
ex--rt type CommandTypeOrAlias = Command['type'] | Command['aliasNames'] | Command['deprecatedNames'];
|
|
16
16
|
// <- TODO: [🧘] Implement
|
|
17
17
|
*/
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import type { CsvSettings } from './formats/csv/CsvSettings';
|
|
2
2
|
import type { IntermediateFilesStrategy } from './types/IntermediateFilesStrategy';
|
|
3
|
+
import type { string_email } from './types/typeAliases';
|
|
4
|
+
import type { string_name } from './types/typeAliases';
|
|
3
5
|
import type { string_url_image } from './types/typeAliases';
|
|
4
6
|
/**
|
|
5
7
|
* Warning message for the generated sections and files files
|
|
@@ -15,6 +17,18 @@ export declare const GENERATOR_WARNING = "\u26A0\uFE0F WARNING: This code has be
|
|
|
15
17
|
* @public exported from `@promptbook/core`
|
|
16
18
|
*/
|
|
17
19
|
export declare const NAME = "Promptbook";
|
|
20
|
+
/**
|
|
21
|
+
* Email of the responsible person
|
|
22
|
+
*
|
|
23
|
+
* @public exported from `@promptbook/core`
|
|
24
|
+
*/
|
|
25
|
+
export declare const ADMIN_EMAIL: string_email;
|
|
26
|
+
/**
|
|
27
|
+
* Name of the responsible person for the Promptbook on GitHub
|
|
28
|
+
*
|
|
29
|
+
* @public exported from `@promptbook/core`
|
|
30
|
+
*/
|
|
31
|
+
export declare const ADMIN_GITHUB_NAME: string_name;
|
|
18
32
|
/**
|
|
19
33
|
* Claim for the Promptbook
|
|
20
34
|
*
|
|
@@ -24,7 +24,7 @@ export declare const OPENAI_MODELS: ReadonlyArray<AvailableModel & {
|
|
|
24
24
|
* @see https://platform.openai.com/docs/models/gpt-4-turbo-and-gpt-4
|
|
25
25
|
* @see https://openai.com/api/pricing/
|
|
26
26
|
* @see /other/playground/playground.ts
|
|
27
|
-
* TODO: [🍓] Make better
|
|
27
|
+
* TODO: [🍓][💩] Make better
|
|
28
28
|
* TODO: Change model titles to human eg: "gpt-4-turbo-2024-04-09" -> "GPT-4 Turbo (2024-04-09)"
|
|
29
29
|
* TODO: [🚸] Not all models are compatible with JSON mode, add this information here and use it
|
|
30
30
|
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
@@ -8,5 +8,5 @@ export type PipelineString = string & {
|
|
|
8
8
|
readonly _type: 'Promptbook';
|
|
9
9
|
};
|
|
10
10
|
/**
|
|
11
|
-
* TODO:
|
|
11
|
+
* TODO: [💩] Better validation (validatePipelineString) or remove branded type and make it just string
|
|
12
12
|
*/
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@promptbook/website-crawler",
|
|
3
|
-
"version": "0.78.
|
|
3
|
+
"version": "0.78.3",
|
|
4
4
|
"description": "It's time for a paradigm shift. The future of software in plain English, French or Latin",
|
|
5
5
|
"--note-0": " <- [🐊]",
|
|
6
6
|
"private": false,
|
|
@@ -54,7 +54,7 @@
|
|
|
54
54
|
"module": "./esm/index.es.js",
|
|
55
55
|
"typings": "./esm/typings/src/_packages/website-crawler.index.d.ts",
|
|
56
56
|
"peerDependencies": {
|
|
57
|
-
"@promptbook/core": "0.78.
|
|
57
|
+
"@promptbook/core": "0.78.3"
|
|
58
58
|
},
|
|
59
59
|
"dependencies": {
|
|
60
60
|
"@mozilla/readability": "0.5.0",
|
package/umd/index.umd.js
CHANGED
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
*
|
|
23
23
|
* @see https://github.com/webgptorg/promptbook
|
|
24
24
|
*/
|
|
25
|
-
var PROMPTBOOK_ENGINE_VERSION = '0.
|
|
25
|
+
var PROMPTBOOK_ENGINE_VERSION = '0.78.2';
|
|
26
26
|
/**
|
|
27
27
|
* TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
|
|
28
28
|
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
@@ -202,164 +202,25 @@
|
|
|
202
202
|
}
|
|
203
203
|
|
|
204
204
|
/**
|
|
205
|
-
*
|
|
205
|
+
* Name for the Promptbook
|
|
206
|
+
*
|
|
207
|
+
* TODO: [🗽] Unite branding and make single place for it
|
|
206
208
|
*
|
|
207
209
|
* @public exported from `@promptbook/core`
|
|
208
210
|
*/
|
|
209
|
-
var
|
|
210
|
-
__extends(UnexpectedError, _super);
|
|
211
|
-
function UnexpectedError(message) {
|
|
212
|
-
var _this = _super.call(this, spaceTrim.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;
|
|
213
|
-
_this.name = 'UnexpectedError';
|
|
214
|
-
Object.setPrototypeOf(_this, UnexpectedError.prototype);
|
|
215
|
-
return _this;
|
|
216
|
-
}
|
|
217
|
-
return UnexpectedError;
|
|
218
|
-
}(Error));
|
|
219
|
-
|
|
211
|
+
var NAME = "Promptbook";
|
|
220
212
|
/**
|
|
221
|
-
*
|
|
222
|
-
* If not, throws an UnexpectedError with a rich error message and tracking
|
|
223
|
-
*
|
|
224
|
-
* - Almost all primitives are serializable BUT:
|
|
225
|
-
* - `undefined` is not serializable
|
|
226
|
-
* - `NaN` is not serializable
|
|
227
|
-
* - Objects and arrays are serializable if all their properties are serializable
|
|
228
|
-
* - Functions are not serializable
|
|
229
|
-
* - Circular references are not serializable
|
|
230
|
-
* - `Date` objects are not serializable
|
|
231
|
-
* - `Map` and `Set` objects are not serializable
|
|
232
|
-
* - `RegExp` objects are not serializable
|
|
233
|
-
* - `Error` objects are not serializable
|
|
234
|
-
* - `Symbol` objects are not serializable
|
|
235
|
-
* - And much more...
|
|
213
|
+
* Email of the responsible person
|
|
236
214
|
*
|
|
237
|
-
* @
|
|
238
|
-
* @public exported from `@promptbook/utils`
|
|
239
|
-
*/
|
|
240
|
-
function checkSerializableAsJson(name, value) {
|
|
241
|
-
var e_1, _a;
|
|
242
|
-
if (value === undefined) {
|
|
243
|
-
throw new UnexpectedError("".concat(name, " is undefined"));
|
|
244
|
-
}
|
|
245
|
-
else if (value === null) {
|
|
246
|
-
return;
|
|
247
|
-
}
|
|
248
|
-
else if (typeof value === 'boolean') {
|
|
249
|
-
return;
|
|
250
|
-
}
|
|
251
|
-
else if (typeof value === 'number' && !isNaN(value)) {
|
|
252
|
-
return;
|
|
253
|
-
}
|
|
254
|
-
else if (typeof value === 'string') {
|
|
255
|
-
return;
|
|
256
|
-
}
|
|
257
|
-
else if (typeof value === 'symbol') {
|
|
258
|
-
throw new UnexpectedError("".concat(name, " is symbol"));
|
|
259
|
-
}
|
|
260
|
-
else if (typeof value === 'function') {
|
|
261
|
-
throw new UnexpectedError("".concat(name, " is function"));
|
|
262
|
-
}
|
|
263
|
-
else if (typeof value === 'object' && Array.isArray(value)) {
|
|
264
|
-
for (var i = 0; i < value.length; i++) {
|
|
265
|
-
checkSerializableAsJson("".concat(name, "[").concat(i, "]"), value[i]);
|
|
266
|
-
}
|
|
267
|
-
}
|
|
268
|
-
else if (typeof value === 'object') {
|
|
269
|
-
if (value instanceof Date) {
|
|
270
|
-
throw new UnexpectedError(spaceTrim__default["default"]("\n ".concat(name, " is Date\n\n Use `string_date_iso8601` instead\n ")));
|
|
271
|
-
}
|
|
272
|
-
else if (value instanceof Map) {
|
|
273
|
-
throw new UnexpectedError("".concat(name, " is Map"));
|
|
274
|
-
}
|
|
275
|
-
else if (value instanceof Set) {
|
|
276
|
-
throw new UnexpectedError("".concat(name, " is Set"));
|
|
277
|
-
}
|
|
278
|
-
else if (value instanceof RegExp) {
|
|
279
|
-
throw new UnexpectedError("".concat(name, " is RegExp"));
|
|
280
|
-
}
|
|
281
|
-
else if (value instanceof Error) {
|
|
282
|
-
throw new UnexpectedError(spaceTrim__default["default"]("\n ".concat(name, " is unserialized Error\n\n Use function `serializeError`\n ")));
|
|
283
|
-
}
|
|
284
|
-
else {
|
|
285
|
-
try {
|
|
286
|
-
for (var _b = __values(Object.entries(value)), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
287
|
-
var _d = __read(_c.value, 2), subName = _d[0], subValue = _d[1];
|
|
288
|
-
if (subValue === undefined) {
|
|
289
|
-
// Note: undefined in object is serializable - it is just omited
|
|
290
|
-
continue;
|
|
291
|
-
}
|
|
292
|
-
checkSerializableAsJson("".concat(name, ".").concat(subName), subValue);
|
|
293
|
-
}
|
|
294
|
-
}
|
|
295
|
-
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
296
|
-
finally {
|
|
297
|
-
try {
|
|
298
|
-
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
299
|
-
}
|
|
300
|
-
finally { if (e_1) throw e_1.error; }
|
|
301
|
-
}
|
|
302
|
-
try {
|
|
303
|
-
JSON.stringify(value); // <- TODO: [0]
|
|
304
|
-
}
|
|
305
|
-
catch (error) {
|
|
306
|
-
if (!(error instanceof Error)) {
|
|
307
|
-
throw error;
|
|
308
|
-
}
|
|
309
|
-
throw new UnexpectedError(spaceTrim__default["default"](function (block) { return "\n ".concat(name, " is not serializable\n\n ").concat(block(error.toString()), "\n "); }));
|
|
310
|
-
}
|
|
311
|
-
/*
|
|
312
|
-
TODO: [0] Is there some more elegant way to check circular references?
|
|
313
|
-
const seen = new Set();
|
|
314
|
-
const stack = [{ value }];
|
|
315
|
-
while (stack.length > 0) {
|
|
316
|
-
const { value } = stack.pop()!;
|
|
317
|
-
if (typeof value === 'object' && value !== null) {
|
|
318
|
-
if (seen.has(value)) {
|
|
319
|
-
throw new UnexpectedError(`${name} has circular reference`);
|
|
320
|
-
}
|
|
321
|
-
seen.add(value);
|
|
322
|
-
if (Array.isArray(value)) {
|
|
323
|
-
stack.push(...value.map((value) => ({ value })));
|
|
324
|
-
} else {
|
|
325
|
-
stack.push(...Object.values(value).map((value) => ({ value })));
|
|
326
|
-
}
|
|
327
|
-
}
|
|
328
|
-
}
|
|
329
|
-
*/
|
|
330
|
-
return;
|
|
331
|
-
}
|
|
332
|
-
}
|
|
333
|
-
else {
|
|
334
|
-
throw new UnexpectedError("".concat(name, " is unknown"));
|
|
335
|
-
}
|
|
336
|
-
}
|
|
337
|
-
/**
|
|
338
|
-
* TODO: [🧠][🛣] More elegant way to tracking than passing `name`
|
|
339
|
-
* TODO: [🧠][main] !!! In-memory cache of same values to prevent multiple checks
|
|
340
|
-
* Note: [🐠] This is how `checkSerializableAsJson` + `isSerializableAsJson` together can just retun true/false or rich error message
|
|
215
|
+
* @public exported from `@promptbook/core`
|
|
341
216
|
*/
|
|
342
|
-
|
|
217
|
+
var ADMIN_EMAIL = 'me@pavolhejny.com';
|
|
343
218
|
/**
|
|
344
|
-
*
|
|
345
|
-
* @@@
|
|
219
|
+
* Name of the responsible person for the Promptbook on GitHub
|
|
346
220
|
*
|
|
347
|
-
*
|
|
348
|
-
*
|
|
349
|
-
* @param name - Name of the object for debugging purposes
|
|
350
|
-
* @param objectValue - Object to be deeply frozen
|
|
351
|
-
* @returns The same object as the input, but deeply frozen
|
|
352
|
-
* @private this is in comparison to `deepFreeze` a more specific utility and maybe not very good practice to use without specific reason and considerations
|
|
353
|
-
*/
|
|
354
|
-
function $asDeeplyFrozenSerializableJson(name, objectValue) {
|
|
355
|
-
checkSerializableAsJson(name, objectValue);
|
|
356
|
-
return $deepFreeze(objectValue);
|
|
357
|
-
}
|
|
358
|
-
/**
|
|
359
|
-
* TODO: [🧠][🛣] More elegant way to tracking than passing `name`
|
|
360
|
-
* TODO: [🧠] Is there a way how to meaningfully test this utility
|
|
221
|
+
* @public exported from `@promptbook/core`
|
|
361
222
|
*/
|
|
362
|
-
|
|
223
|
+
var ADMIN_GITHUB_NAME = 'hejny';
|
|
363
224
|
// <- TODO: [🧠] Better system for generator warnings - not always "code" and "by `@promptbook/cli`"
|
|
364
225
|
/**
|
|
365
226
|
* The maximum number of iterations for a loops
|
|
@@ -411,7 +272,8 @@
|
|
|
411
272
|
*
|
|
412
273
|
* @public exported from `@promptbook/core`
|
|
413
274
|
*/
|
|
414
|
-
var RESERVED_PARAMETER_NAMES =
|
|
275
|
+
var RESERVED_PARAMETER_NAMES =
|
|
276
|
+
/* !!!!!! $asDeeplyFrozenSerializableJson('RESERVED_PARAMETER_NAMES', _____ as const); */ [
|
|
415
277
|
'content',
|
|
416
278
|
'context',
|
|
417
279
|
'knowledge',
|
|
@@ -421,7 +283,7 @@
|
|
|
421
283
|
// <- TODO: list here all command names
|
|
422
284
|
// <- TODO: Add more like 'date', 'modelName',...
|
|
423
285
|
// <- TODO: Add [emoji] + instructions ACRY when adding new reserved parameter
|
|
424
|
-
]
|
|
286
|
+
];
|
|
425
287
|
/**
|
|
426
288
|
* @@@
|
|
427
289
|
*
|
|
@@ -489,6 +351,40 @@
|
|
|
489
351
|
return NotYetImplementedError;
|
|
490
352
|
}(Error));
|
|
491
353
|
|
|
354
|
+
/**
|
|
355
|
+
* Make error report URL for the given error
|
|
356
|
+
*
|
|
357
|
+
* @private !!!!!!
|
|
358
|
+
*/
|
|
359
|
+
function getErrorReportUrl(error) {
|
|
360
|
+
var report = {
|
|
361
|
+
title: "\uD83D\uDC1C Error report from ".concat(NAME),
|
|
362
|
+
body: spaceTrim__default["default"](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 "); }),
|
|
363
|
+
};
|
|
364
|
+
var reportUrl = new URL("https://github.com/webgptorg/promptbook/issues/new");
|
|
365
|
+
reportUrl.searchParams.set('labels', 'bug');
|
|
366
|
+
reportUrl.searchParams.set('assignees', ADMIN_GITHUB_NAME);
|
|
367
|
+
reportUrl.searchParams.set('title', report.title);
|
|
368
|
+
reportUrl.searchParams.set('body', report.body);
|
|
369
|
+
return reportUrl;
|
|
370
|
+
}
|
|
371
|
+
|
|
372
|
+
/**
|
|
373
|
+
* This error type indicates that the error should not happen and its last check before crashing with some other error
|
|
374
|
+
*
|
|
375
|
+
* @public exported from `@promptbook/core`
|
|
376
|
+
*/
|
|
377
|
+
var UnexpectedError = /** @class */ (function (_super) {
|
|
378
|
+
__extends(UnexpectedError, _super);
|
|
379
|
+
function UnexpectedError(message) {
|
|
380
|
+
var _this = _super.call(this, spaceTrim.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;
|
|
381
|
+
_this.name = 'UnexpectedError';
|
|
382
|
+
Object.setPrototypeOf(_this, UnexpectedError.prototype);
|
|
383
|
+
return _this;
|
|
384
|
+
}
|
|
385
|
+
return UnexpectedError;
|
|
386
|
+
}(Error));
|
|
387
|
+
|
|
492
388
|
/**
|
|
493
389
|
* @@@
|
|
494
390
|
*
|
|
@@ -1934,6 +1830,149 @@
|
|
|
1934
1830
|
return parameterNames;
|
|
1935
1831
|
}
|
|
1936
1832
|
|
|
1833
|
+
/**
|
|
1834
|
+
* Checks if the value is [🚉] serializable as JSON
|
|
1835
|
+
* If not, throws an UnexpectedError with a rich error message and tracking
|
|
1836
|
+
*
|
|
1837
|
+
* - Almost all primitives are serializable BUT:
|
|
1838
|
+
* - `undefined` is not serializable
|
|
1839
|
+
* - `NaN` is not serializable
|
|
1840
|
+
* - Objects and arrays are serializable if all their properties are serializable
|
|
1841
|
+
* - Functions are not serializable
|
|
1842
|
+
* - Circular references are not serializable
|
|
1843
|
+
* - `Date` objects are not serializable
|
|
1844
|
+
* - `Map` and `Set` objects are not serializable
|
|
1845
|
+
* - `RegExp` objects are not serializable
|
|
1846
|
+
* - `Error` objects are not serializable
|
|
1847
|
+
* - `Symbol` objects are not serializable
|
|
1848
|
+
* - And much more...
|
|
1849
|
+
*
|
|
1850
|
+
* @throws UnexpectedError if the value is not serializable as JSON
|
|
1851
|
+
* @public exported from `@promptbook/utils`
|
|
1852
|
+
*/
|
|
1853
|
+
function checkSerializableAsJson(name, value) {
|
|
1854
|
+
var e_1, _a;
|
|
1855
|
+
if (value === undefined) {
|
|
1856
|
+
throw new UnexpectedError("".concat(name, " is undefined"));
|
|
1857
|
+
}
|
|
1858
|
+
else if (value === null) {
|
|
1859
|
+
return;
|
|
1860
|
+
}
|
|
1861
|
+
else if (typeof value === 'boolean') {
|
|
1862
|
+
return;
|
|
1863
|
+
}
|
|
1864
|
+
else if (typeof value === 'number' && !isNaN(value)) {
|
|
1865
|
+
return;
|
|
1866
|
+
}
|
|
1867
|
+
else if (typeof value === 'string') {
|
|
1868
|
+
return;
|
|
1869
|
+
}
|
|
1870
|
+
else if (typeof value === 'symbol') {
|
|
1871
|
+
throw new UnexpectedError("".concat(name, " is symbol"));
|
|
1872
|
+
}
|
|
1873
|
+
else if (typeof value === 'function') {
|
|
1874
|
+
throw new UnexpectedError("".concat(name, " is function"));
|
|
1875
|
+
}
|
|
1876
|
+
else if (typeof value === 'object' && Array.isArray(value)) {
|
|
1877
|
+
for (var i = 0; i < value.length; i++) {
|
|
1878
|
+
checkSerializableAsJson("".concat(name, "[").concat(i, "]"), value[i]);
|
|
1879
|
+
}
|
|
1880
|
+
}
|
|
1881
|
+
else if (typeof value === 'object') {
|
|
1882
|
+
if (value instanceof Date) {
|
|
1883
|
+
throw new UnexpectedError(spaceTrim__default["default"]("\n ".concat(name, " is Date\n\n Use `string_date_iso8601` instead\n ")));
|
|
1884
|
+
}
|
|
1885
|
+
else if (value instanceof Map) {
|
|
1886
|
+
throw new UnexpectedError("".concat(name, " is Map"));
|
|
1887
|
+
}
|
|
1888
|
+
else if (value instanceof Set) {
|
|
1889
|
+
throw new UnexpectedError("".concat(name, " is Set"));
|
|
1890
|
+
}
|
|
1891
|
+
else if (value instanceof RegExp) {
|
|
1892
|
+
throw new UnexpectedError("".concat(name, " is RegExp"));
|
|
1893
|
+
}
|
|
1894
|
+
else if (value instanceof Error) {
|
|
1895
|
+
throw new UnexpectedError(spaceTrim__default["default"]("\n ".concat(name, " is unserialized Error\n\n Use function `serializeError`\n ")));
|
|
1896
|
+
}
|
|
1897
|
+
else {
|
|
1898
|
+
try {
|
|
1899
|
+
for (var _b = __values(Object.entries(value)), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
1900
|
+
var _d = __read(_c.value, 2), subName = _d[0], subValue = _d[1];
|
|
1901
|
+
if (subValue === undefined) {
|
|
1902
|
+
// Note: undefined in object is serializable - it is just omited
|
|
1903
|
+
continue;
|
|
1904
|
+
}
|
|
1905
|
+
checkSerializableAsJson("".concat(name, ".").concat(subName), subValue);
|
|
1906
|
+
}
|
|
1907
|
+
}
|
|
1908
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
1909
|
+
finally {
|
|
1910
|
+
try {
|
|
1911
|
+
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
1912
|
+
}
|
|
1913
|
+
finally { if (e_1) throw e_1.error; }
|
|
1914
|
+
}
|
|
1915
|
+
try {
|
|
1916
|
+
JSON.stringify(value); // <- TODO: [0]
|
|
1917
|
+
}
|
|
1918
|
+
catch (error) {
|
|
1919
|
+
if (!(error instanceof Error)) {
|
|
1920
|
+
throw error;
|
|
1921
|
+
}
|
|
1922
|
+
throw new UnexpectedError(spaceTrim__default["default"](function (block) { return "\n ".concat(name, " is not serializable\n\n ").concat(block(error.toString()), "\n "); }));
|
|
1923
|
+
}
|
|
1924
|
+
/*
|
|
1925
|
+
TODO: [0] Is there some more elegant way to check circular references?
|
|
1926
|
+
const seen = new Set();
|
|
1927
|
+
const stack = [{ value }];
|
|
1928
|
+
while (stack.length > 0) {
|
|
1929
|
+
const { value } = stack.pop()!;
|
|
1930
|
+
if (typeof value === 'object' && value !== null) {
|
|
1931
|
+
if (seen.has(value)) {
|
|
1932
|
+
throw new UnexpectedError(`${name} has circular reference`);
|
|
1933
|
+
}
|
|
1934
|
+
seen.add(value);
|
|
1935
|
+
if (Array.isArray(value)) {
|
|
1936
|
+
stack.push(...value.map((value) => ({ value })));
|
|
1937
|
+
} else {
|
|
1938
|
+
stack.push(...Object.values(value).map((value) => ({ value })));
|
|
1939
|
+
}
|
|
1940
|
+
}
|
|
1941
|
+
}
|
|
1942
|
+
*/
|
|
1943
|
+
return;
|
|
1944
|
+
}
|
|
1945
|
+
}
|
|
1946
|
+
else {
|
|
1947
|
+
throw new UnexpectedError("".concat(name, " is unknown"));
|
|
1948
|
+
}
|
|
1949
|
+
}
|
|
1950
|
+
/**
|
|
1951
|
+
* TODO: [🧠][🛣] More elegant way to tracking than passing `name`
|
|
1952
|
+
* TODO: [🧠][main] !!! In-memory cache of same values to prevent multiple checks
|
|
1953
|
+
* Note: [🐠] This is how `checkSerializableAsJson` + `isSerializableAsJson` together can just retun true/false or rich error message
|
|
1954
|
+
*/
|
|
1955
|
+
|
|
1956
|
+
/**
|
|
1957
|
+
* @@@
|
|
1958
|
+
* @@@
|
|
1959
|
+
*
|
|
1960
|
+
* Note: This function mutates the object and returns the original (but mutated-deep-freezed) object
|
|
1961
|
+
*
|
|
1962
|
+
* @param name - Name of the object for debugging purposes
|
|
1963
|
+
* @param objectValue - Object to be deeply frozen
|
|
1964
|
+
* @returns The same object as the input, but deeply frozen
|
|
1965
|
+
* @private this is in comparison to `deepFreeze` a more specific utility and maybe not very good practice to use without specific reason and considerations
|
|
1966
|
+
*/
|
|
1967
|
+
function $asDeeplyFrozenSerializableJson(name, objectValue) {
|
|
1968
|
+
checkSerializableAsJson(name, objectValue);
|
|
1969
|
+
return $deepFreeze(objectValue);
|
|
1970
|
+
}
|
|
1971
|
+
/**
|
|
1972
|
+
* TODO: [🧠][🛣] More elegant way to tracking than passing `name`
|
|
1973
|
+
* TODO: [🧠] Is there a way how to meaningfully test this utility
|
|
1974
|
+
*/
|
|
1975
|
+
|
|
1937
1976
|
/**
|
|
1938
1977
|
* Unprepare just strips the preparation data of the pipeline
|
|
1939
1978
|
*
|
|
@@ -3699,6 +3738,7 @@
|
|
|
3699
3738
|
*/
|
|
3700
3739
|
function extractVariablesFromScript(script) {
|
|
3701
3740
|
var variables = new Set();
|
|
3741
|
+
var originalScript = script;
|
|
3702
3742
|
script = "(()=>{".concat(script, "})()");
|
|
3703
3743
|
try {
|
|
3704
3744
|
for (var i = 0; i < 100 /* <- TODO: This limit to configuration */; i++)
|
|
@@ -3709,20 +3749,32 @@
|
|
|
3709
3749
|
if (!(error instanceof ReferenceError)) {
|
|
3710
3750
|
throw error;
|
|
3711
3751
|
}
|
|
3712
|
-
var undefinedName = error.message.split(' ')[0];
|
|
3713
3752
|
/*
|
|
3714
3753
|
Note: Parsing the error
|
|
3754
|
+
🌟 Most devices:
|
|
3715
3755
|
[PipelineUrlError: thing is not defined]
|
|
3756
|
+
|
|
3757
|
+
🍏 iPhone`s Safari:
|
|
3758
|
+
[PipelineUrlError: Can't find variable: thing]
|
|
3716
3759
|
*/
|
|
3717
|
-
|
|
3760
|
+
var variableName = undefined;
|
|
3761
|
+
if (error.message.startsWith("Can't")) {
|
|
3762
|
+
// 🍏 Case
|
|
3763
|
+
variableName = error.message.split(' ').pop();
|
|
3764
|
+
}
|
|
3765
|
+
else {
|
|
3766
|
+
// 🌟 Case
|
|
3767
|
+
variableName = error.message.split(' ').shift();
|
|
3768
|
+
}
|
|
3769
|
+
if (variableName === undefined) {
|
|
3718
3770
|
throw error;
|
|
3719
3771
|
}
|
|
3720
|
-
if (script.includes(
|
|
3721
|
-
script = "const ".concat(
|
|
3772
|
+
if (script.includes(variableName + '(')) {
|
|
3773
|
+
script = "const ".concat(variableName, " = ()=>'';") + script;
|
|
3722
3774
|
}
|
|
3723
3775
|
else {
|
|
3724
|
-
variables.add(
|
|
3725
|
-
script = "const ".concat(
|
|
3776
|
+
variables.add(variableName);
|
|
3777
|
+
script = "const ".concat(variableName, " = '';") + script;
|
|
3726
3778
|
}
|
|
3727
3779
|
}
|
|
3728
3780
|
}
|
|
@@ -3730,7 +3782,9 @@
|
|
|
3730
3782
|
if (!(error instanceof Error)) {
|
|
3731
3783
|
throw error;
|
|
3732
3784
|
}
|
|
3733
|
-
throw new ParseError(spaceTrim.spaceTrim(function (block) { return "\n Can not extract variables from the script\n\n ".concat(block(error.toString()), "}\n
|
|
3785
|
+
throw new ParseError(spaceTrim.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)
|
|
3786
|
+
.map(function (variableName, i) { return "".concat(i + 1, ") ").concat(variableName); })
|
|
3787
|
+
.join('\n'), "\n\n\n The script:\n\n ```javascript\n ").concat(block(originalScript), "\n ```\n "); }));
|
|
3734
3788
|
}
|
|
3735
3789
|
return variables;
|
|
3736
3790
|
}
|