@promptbook/pdf 0.78.0-0 → 0.78.2
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 +228 -186
- package/esm/index.es.js.map +1 -1
- package/esm/typings/src/_packages/core.index.d.ts +4 -0
- 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 +228 -186
- 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/pdf`
|
|
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
|
@@ -20,7 +20,7 @@ var BOOK_LANGUAGE_VERSION = '1.0.0';
|
|
|
20
20
|
*
|
|
21
21
|
* @see https://github.com/webgptorg/promptbook
|
|
22
22
|
*/
|
|
23
|
-
var PROMPTBOOK_ENGINE_VERSION = '0.
|
|
23
|
+
var PROMPTBOOK_ENGINE_VERSION = '0.78.1';
|
|
24
24
|
/**
|
|
25
25
|
* TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
|
|
26
26
|
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
@@ -446,198 +446,25 @@ function just(value) {
|
|
|
446
446
|
}
|
|
447
447
|
|
|
448
448
|
/**
|
|
449
|
-
*
|
|
450
|
-
*
|
|
451
|
-
* Note: `$` is used to indicate that this function is not a pure function - it mutates given object
|
|
452
|
-
* Note: This function mutates the object and returns the original (but mutated-deep-freezed) object
|
|
449
|
+
* Name for the Promptbook
|
|
453
450
|
*
|
|
454
|
-
*
|
|
455
|
-
* @public exported from `@promptbook/utils`
|
|
456
|
-
*/
|
|
457
|
-
function $deepFreeze(objectValue) {
|
|
458
|
-
var e_1, _a;
|
|
459
|
-
var propertyNames = Object.getOwnPropertyNames(objectValue);
|
|
460
|
-
try {
|
|
461
|
-
for (var propertyNames_1 = __values(propertyNames), propertyNames_1_1 = propertyNames_1.next(); !propertyNames_1_1.done; propertyNames_1_1 = propertyNames_1.next()) {
|
|
462
|
-
var propertyName = propertyNames_1_1.value;
|
|
463
|
-
var value = objectValue[propertyName];
|
|
464
|
-
if (value && typeof value === 'object') {
|
|
465
|
-
$deepFreeze(value);
|
|
466
|
-
}
|
|
467
|
-
}
|
|
468
|
-
}
|
|
469
|
-
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
470
|
-
finally {
|
|
471
|
-
try {
|
|
472
|
-
if (propertyNames_1_1 && !propertyNames_1_1.done && (_a = propertyNames_1.return)) _a.call(propertyNames_1);
|
|
473
|
-
}
|
|
474
|
-
finally { if (e_1) throw e_1.error; }
|
|
475
|
-
}
|
|
476
|
-
return Object.freeze(objectValue);
|
|
477
|
-
}
|
|
478
|
-
/**
|
|
479
|
-
* TODO: [🧠] Is there a way how to meaningfully test this utility
|
|
480
|
-
*/
|
|
481
|
-
|
|
482
|
-
/**
|
|
483
|
-
* This error type indicates that the error should not happen and its last check before crashing with some other error
|
|
451
|
+
* TODO: [🗽] Unite branding and make single place for it
|
|
484
452
|
*
|
|
485
453
|
* @public exported from `@promptbook/core`
|
|
486
454
|
*/
|
|
487
|
-
var
|
|
488
|
-
__extends(UnexpectedError, _super);
|
|
489
|
-
function UnexpectedError(message) {
|
|
490
|
-
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;
|
|
491
|
-
_this.name = 'UnexpectedError';
|
|
492
|
-
Object.setPrototypeOf(_this, UnexpectedError.prototype);
|
|
493
|
-
return _this;
|
|
494
|
-
}
|
|
495
|
-
return UnexpectedError;
|
|
496
|
-
}(Error));
|
|
497
|
-
|
|
455
|
+
var NAME = "Promptbook";
|
|
498
456
|
/**
|
|
499
|
-
*
|
|
500
|
-
* If not, throws an UnexpectedError with a rich error message and tracking
|
|
501
|
-
*
|
|
502
|
-
* - Almost all primitives are serializable BUT:
|
|
503
|
-
* - `undefined` is not serializable
|
|
504
|
-
* - `NaN` is not serializable
|
|
505
|
-
* - Objects and arrays are serializable if all their properties are serializable
|
|
506
|
-
* - Functions are not serializable
|
|
507
|
-
* - Circular references are not serializable
|
|
508
|
-
* - `Date` objects are not serializable
|
|
509
|
-
* - `Map` and `Set` objects are not serializable
|
|
510
|
-
* - `RegExp` objects are not serializable
|
|
511
|
-
* - `Error` objects are not serializable
|
|
512
|
-
* - `Symbol` objects are not serializable
|
|
513
|
-
* - And much more...
|
|
457
|
+
* Email of the responsible person
|
|
514
458
|
*
|
|
515
|
-
* @
|
|
516
|
-
* @public exported from `@promptbook/utils`
|
|
517
|
-
*/
|
|
518
|
-
function checkSerializableAsJson(name, value) {
|
|
519
|
-
var e_1, _a;
|
|
520
|
-
if (value === undefined) {
|
|
521
|
-
throw new UnexpectedError("".concat(name, " is undefined"));
|
|
522
|
-
}
|
|
523
|
-
else if (value === null) {
|
|
524
|
-
return;
|
|
525
|
-
}
|
|
526
|
-
else if (typeof value === 'boolean') {
|
|
527
|
-
return;
|
|
528
|
-
}
|
|
529
|
-
else if (typeof value === 'number' && !isNaN(value)) {
|
|
530
|
-
return;
|
|
531
|
-
}
|
|
532
|
-
else if (typeof value === 'string') {
|
|
533
|
-
return;
|
|
534
|
-
}
|
|
535
|
-
else if (typeof value === 'symbol') {
|
|
536
|
-
throw new UnexpectedError("".concat(name, " is symbol"));
|
|
537
|
-
}
|
|
538
|
-
else if (typeof value === 'function') {
|
|
539
|
-
throw new UnexpectedError("".concat(name, " is function"));
|
|
540
|
-
}
|
|
541
|
-
else if (typeof value === 'object' && Array.isArray(value)) {
|
|
542
|
-
for (var i = 0; i < value.length; i++) {
|
|
543
|
-
checkSerializableAsJson("".concat(name, "[").concat(i, "]"), value[i]);
|
|
544
|
-
}
|
|
545
|
-
}
|
|
546
|
-
else if (typeof value === 'object') {
|
|
547
|
-
if (value instanceof Date) {
|
|
548
|
-
throw new UnexpectedError(spaceTrim$1("\n ".concat(name, " is Date\n\n Use `string_date_iso8601` instead\n ")));
|
|
549
|
-
}
|
|
550
|
-
else if (value instanceof Map) {
|
|
551
|
-
throw new UnexpectedError("".concat(name, " is Map"));
|
|
552
|
-
}
|
|
553
|
-
else if (value instanceof Set) {
|
|
554
|
-
throw new UnexpectedError("".concat(name, " is Set"));
|
|
555
|
-
}
|
|
556
|
-
else if (value instanceof RegExp) {
|
|
557
|
-
throw new UnexpectedError("".concat(name, " is RegExp"));
|
|
558
|
-
}
|
|
559
|
-
else if (value instanceof Error) {
|
|
560
|
-
throw new UnexpectedError(spaceTrim$1("\n ".concat(name, " is unserialized Error\n\n Use function `serializeError`\n ")));
|
|
561
|
-
}
|
|
562
|
-
else {
|
|
563
|
-
try {
|
|
564
|
-
for (var _b = __values(Object.entries(value)), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
565
|
-
var _d = __read(_c.value, 2), subName = _d[0], subValue = _d[1];
|
|
566
|
-
if (subValue === undefined) {
|
|
567
|
-
// Note: undefined in object is serializable - it is just omited
|
|
568
|
-
continue;
|
|
569
|
-
}
|
|
570
|
-
checkSerializableAsJson("".concat(name, ".").concat(subName), subValue);
|
|
571
|
-
}
|
|
572
|
-
}
|
|
573
|
-
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
574
|
-
finally {
|
|
575
|
-
try {
|
|
576
|
-
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
577
|
-
}
|
|
578
|
-
finally { if (e_1) throw e_1.error; }
|
|
579
|
-
}
|
|
580
|
-
try {
|
|
581
|
-
JSON.stringify(value); // <- TODO: [0]
|
|
582
|
-
}
|
|
583
|
-
catch (error) {
|
|
584
|
-
if (!(error instanceof Error)) {
|
|
585
|
-
throw error;
|
|
586
|
-
}
|
|
587
|
-
throw new UnexpectedError(spaceTrim$1(function (block) { return "\n ".concat(name, " is not serializable\n\n ").concat(block(error.toString()), "\n "); }));
|
|
588
|
-
}
|
|
589
|
-
/*
|
|
590
|
-
TODO: [0] Is there some more elegant way to check circular references?
|
|
591
|
-
const seen = new Set();
|
|
592
|
-
const stack = [{ value }];
|
|
593
|
-
while (stack.length > 0) {
|
|
594
|
-
const { value } = stack.pop()!;
|
|
595
|
-
if (typeof value === 'object' && value !== null) {
|
|
596
|
-
if (seen.has(value)) {
|
|
597
|
-
throw new UnexpectedError(`${name} has circular reference`);
|
|
598
|
-
}
|
|
599
|
-
seen.add(value);
|
|
600
|
-
if (Array.isArray(value)) {
|
|
601
|
-
stack.push(...value.map((value) => ({ value })));
|
|
602
|
-
} else {
|
|
603
|
-
stack.push(...Object.values(value).map((value) => ({ value })));
|
|
604
|
-
}
|
|
605
|
-
}
|
|
606
|
-
}
|
|
607
|
-
*/
|
|
608
|
-
return;
|
|
609
|
-
}
|
|
610
|
-
}
|
|
611
|
-
else {
|
|
612
|
-
throw new UnexpectedError("".concat(name, " is unknown"));
|
|
613
|
-
}
|
|
614
|
-
}
|
|
615
|
-
/**
|
|
616
|
-
* TODO: [🧠][🛣] More elegant way to tracking than passing `name`
|
|
617
|
-
* TODO: [🧠][main] !!! In-memory cache of same values to prevent multiple checks
|
|
618
|
-
* Note: [🐠] This is how `checkSerializableAsJson` + `isSerializableAsJson` together can just retun true/false or rich error message
|
|
459
|
+
* @public exported from `@promptbook/core`
|
|
619
460
|
*/
|
|
620
|
-
|
|
461
|
+
var ADMIN_EMAIL = 'me@pavolhejny.com';
|
|
621
462
|
/**
|
|
622
|
-
*
|
|
623
|
-
* @@@
|
|
463
|
+
* Name of the responsible person for the Promptbook on GitHub
|
|
624
464
|
*
|
|
625
|
-
*
|
|
626
|
-
*
|
|
627
|
-
* @param name - Name of the object for debugging purposes
|
|
628
|
-
* @param objectValue - Object to be deeply frozen
|
|
629
|
-
* @returns The same object as the input, but deeply frozen
|
|
630
|
-
* @private this is in comparison to `deepFreeze` a more specific utility and maybe not very good practice to use without specific reason and considerations
|
|
631
|
-
*/
|
|
632
|
-
function $asDeeplyFrozenSerializableJson(name, objectValue) {
|
|
633
|
-
checkSerializableAsJson(name, objectValue);
|
|
634
|
-
return $deepFreeze(objectValue);
|
|
635
|
-
}
|
|
636
|
-
/**
|
|
637
|
-
* TODO: [🧠][🛣] More elegant way to tracking than passing `name`
|
|
638
|
-
* TODO: [🧠] Is there a way how to meaningfully test this utility
|
|
465
|
+
* @public exported from `@promptbook/core`
|
|
639
466
|
*/
|
|
640
|
-
|
|
467
|
+
var ADMIN_GITHUB_NAME = 'hejny';
|
|
641
468
|
// <- TODO: [🧠] Better system for generator warnings - not always "code" and "by `@promptbook/cli`"
|
|
642
469
|
/**
|
|
643
470
|
* The maximum number of iterations for a loops
|
|
@@ -689,7 +516,8 @@ var REPLACING_NONCE = 'u$k42k%!V2zo34w7Fu#@QUHYPW';
|
|
|
689
516
|
*
|
|
690
517
|
* @public exported from `@promptbook/core`
|
|
691
518
|
*/
|
|
692
|
-
var RESERVED_PARAMETER_NAMES =
|
|
519
|
+
var RESERVED_PARAMETER_NAMES =
|
|
520
|
+
/* !!!!!! $asDeeplyFrozenSerializableJson('RESERVED_PARAMETER_NAMES', _____ as const); */ [
|
|
693
521
|
'content',
|
|
694
522
|
'context',
|
|
695
523
|
'knowledge',
|
|
@@ -699,7 +527,7 @@ var RESERVED_PARAMETER_NAMES = $asDeeplyFrozenSerializableJson('RESERVED_PARAMET
|
|
|
699
527
|
// <- TODO: list here all command names
|
|
700
528
|
// <- TODO: Add more like 'date', 'modelName',...
|
|
701
529
|
// <- TODO: Add [emoji] + instructions ACRY when adding new reserved parameter
|
|
702
|
-
]
|
|
530
|
+
];
|
|
703
531
|
/**
|
|
704
532
|
* @@@
|
|
705
533
|
*
|
|
@@ -786,6 +614,40 @@ var PipelineLogicError = /** @class */ (function (_super) {
|
|
|
786
614
|
return PipelineLogicError;
|
|
787
615
|
}(Error));
|
|
788
616
|
|
|
617
|
+
/**
|
|
618
|
+
* Make error report URL for the given error
|
|
619
|
+
*
|
|
620
|
+
* @private !!!!!!
|
|
621
|
+
*/
|
|
622
|
+
function getErrorReportUrl(error) {
|
|
623
|
+
var report = {
|
|
624
|
+
title: "\uD83D\uDC1C Error report from ".concat(NAME),
|
|
625
|
+
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 "); }),
|
|
626
|
+
};
|
|
627
|
+
var reportUrl = new URL("https://github.com/webgptorg/promptbook/issues/new");
|
|
628
|
+
reportUrl.searchParams.set('labels', 'bug');
|
|
629
|
+
reportUrl.searchParams.set('assignees', ADMIN_GITHUB_NAME);
|
|
630
|
+
reportUrl.searchParams.set('title', report.title);
|
|
631
|
+
reportUrl.searchParams.set('body', report.body);
|
|
632
|
+
return reportUrl;
|
|
633
|
+
}
|
|
634
|
+
|
|
635
|
+
/**
|
|
636
|
+
* This error type indicates that the error should not happen and its last check before crashing with some other error
|
|
637
|
+
*
|
|
638
|
+
* @public exported from `@promptbook/core`
|
|
639
|
+
*/
|
|
640
|
+
var UnexpectedError = /** @class */ (function (_super) {
|
|
641
|
+
__extends(UnexpectedError, _super);
|
|
642
|
+
function UnexpectedError(message) {
|
|
643
|
+
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;
|
|
644
|
+
_this.name = 'UnexpectedError';
|
|
645
|
+
Object.setPrototypeOf(_this, UnexpectedError.prototype);
|
|
646
|
+
return _this;
|
|
647
|
+
}
|
|
648
|
+
return UnexpectedError;
|
|
649
|
+
}(Error));
|
|
650
|
+
|
|
789
651
|
/**
|
|
790
652
|
* Tests if given string is valid semantic version
|
|
791
653
|
*
|
|
@@ -1266,6 +1128,183 @@ function extractParameterNames(template) {
|
|
|
1266
1128
|
return parameterNames;
|
|
1267
1129
|
}
|
|
1268
1130
|
|
|
1131
|
+
/**
|
|
1132
|
+
* @@@
|
|
1133
|
+
*
|
|
1134
|
+
* Note: `$` is used to indicate that this function is not a pure function - it mutates given object
|
|
1135
|
+
* Note: This function mutates the object and returns the original (but mutated-deep-freezed) object
|
|
1136
|
+
*
|
|
1137
|
+
* @returns The same object as the input, but deeply frozen
|
|
1138
|
+
* @public exported from `@promptbook/utils`
|
|
1139
|
+
*/
|
|
1140
|
+
function $deepFreeze(objectValue) {
|
|
1141
|
+
var e_1, _a;
|
|
1142
|
+
var propertyNames = Object.getOwnPropertyNames(objectValue);
|
|
1143
|
+
try {
|
|
1144
|
+
for (var propertyNames_1 = __values(propertyNames), propertyNames_1_1 = propertyNames_1.next(); !propertyNames_1_1.done; propertyNames_1_1 = propertyNames_1.next()) {
|
|
1145
|
+
var propertyName = propertyNames_1_1.value;
|
|
1146
|
+
var value = objectValue[propertyName];
|
|
1147
|
+
if (value && typeof value === 'object') {
|
|
1148
|
+
$deepFreeze(value);
|
|
1149
|
+
}
|
|
1150
|
+
}
|
|
1151
|
+
}
|
|
1152
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
1153
|
+
finally {
|
|
1154
|
+
try {
|
|
1155
|
+
if (propertyNames_1_1 && !propertyNames_1_1.done && (_a = propertyNames_1.return)) _a.call(propertyNames_1);
|
|
1156
|
+
}
|
|
1157
|
+
finally { if (e_1) throw e_1.error; }
|
|
1158
|
+
}
|
|
1159
|
+
return Object.freeze(objectValue);
|
|
1160
|
+
}
|
|
1161
|
+
/**
|
|
1162
|
+
* TODO: [🧠] Is there a way how to meaningfully test this utility
|
|
1163
|
+
*/
|
|
1164
|
+
|
|
1165
|
+
/**
|
|
1166
|
+
* Checks if the value is [🚉] serializable as JSON
|
|
1167
|
+
* If not, throws an UnexpectedError with a rich error message and tracking
|
|
1168
|
+
*
|
|
1169
|
+
* - Almost all primitives are serializable BUT:
|
|
1170
|
+
* - `undefined` is not serializable
|
|
1171
|
+
* - `NaN` is not serializable
|
|
1172
|
+
* - Objects and arrays are serializable if all their properties are serializable
|
|
1173
|
+
* - Functions are not serializable
|
|
1174
|
+
* - Circular references are not serializable
|
|
1175
|
+
* - `Date` objects are not serializable
|
|
1176
|
+
* - `Map` and `Set` objects are not serializable
|
|
1177
|
+
* - `RegExp` objects are not serializable
|
|
1178
|
+
* - `Error` objects are not serializable
|
|
1179
|
+
* - `Symbol` objects are not serializable
|
|
1180
|
+
* - And much more...
|
|
1181
|
+
*
|
|
1182
|
+
* @throws UnexpectedError if the value is not serializable as JSON
|
|
1183
|
+
* @public exported from `@promptbook/utils`
|
|
1184
|
+
*/
|
|
1185
|
+
function checkSerializableAsJson(name, value) {
|
|
1186
|
+
var e_1, _a;
|
|
1187
|
+
if (value === undefined) {
|
|
1188
|
+
throw new UnexpectedError("".concat(name, " is undefined"));
|
|
1189
|
+
}
|
|
1190
|
+
else if (value === null) {
|
|
1191
|
+
return;
|
|
1192
|
+
}
|
|
1193
|
+
else if (typeof value === 'boolean') {
|
|
1194
|
+
return;
|
|
1195
|
+
}
|
|
1196
|
+
else if (typeof value === 'number' && !isNaN(value)) {
|
|
1197
|
+
return;
|
|
1198
|
+
}
|
|
1199
|
+
else if (typeof value === 'string') {
|
|
1200
|
+
return;
|
|
1201
|
+
}
|
|
1202
|
+
else if (typeof value === 'symbol') {
|
|
1203
|
+
throw new UnexpectedError("".concat(name, " is symbol"));
|
|
1204
|
+
}
|
|
1205
|
+
else if (typeof value === 'function') {
|
|
1206
|
+
throw new UnexpectedError("".concat(name, " is function"));
|
|
1207
|
+
}
|
|
1208
|
+
else if (typeof value === 'object' && Array.isArray(value)) {
|
|
1209
|
+
for (var i = 0; i < value.length; i++) {
|
|
1210
|
+
checkSerializableAsJson("".concat(name, "[").concat(i, "]"), value[i]);
|
|
1211
|
+
}
|
|
1212
|
+
}
|
|
1213
|
+
else if (typeof value === 'object') {
|
|
1214
|
+
if (value instanceof Date) {
|
|
1215
|
+
throw new UnexpectedError(spaceTrim$1("\n ".concat(name, " is Date\n\n Use `string_date_iso8601` instead\n ")));
|
|
1216
|
+
}
|
|
1217
|
+
else if (value instanceof Map) {
|
|
1218
|
+
throw new UnexpectedError("".concat(name, " is Map"));
|
|
1219
|
+
}
|
|
1220
|
+
else if (value instanceof Set) {
|
|
1221
|
+
throw new UnexpectedError("".concat(name, " is Set"));
|
|
1222
|
+
}
|
|
1223
|
+
else if (value instanceof RegExp) {
|
|
1224
|
+
throw new UnexpectedError("".concat(name, " is RegExp"));
|
|
1225
|
+
}
|
|
1226
|
+
else if (value instanceof Error) {
|
|
1227
|
+
throw new UnexpectedError(spaceTrim$1("\n ".concat(name, " is unserialized Error\n\n Use function `serializeError`\n ")));
|
|
1228
|
+
}
|
|
1229
|
+
else {
|
|
1230
|
+
try {
|
|
1231
|
+
for (var _b = __values(Object.entries(value)), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
1232
|
+
var _d = __read(_c.value, 2), subName = _d[0], subValue = _d[1];
|
|
1233
|
+
if (subValue === undefined) {
|
|
1234
|
+
// Note: undefined in object is serializable - it is just omited
|
|
1235
|
+
continue;
|
|
1236
|
+
}
|
|
1237
|
+
checkSerializableAsJson("".concat(name, ".").concat(subName), subValue);
|
|
1238
|
+
}
|
|
1239
|
+
}
|
|
1240
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
1241
|
+
finally {
|
|
1242
|
+
try {
|
|
1243
|
+
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
1244
|
+
}
|
|
1245
|
+
finally { if (e_1) throw e_1.error; }
|
|
1246
|
+
}
|
|
1247
|
+
try {
|
|
1248
|
+
JSON.stringify(value); // <- TODO: [0]
|
|
1249
|
+
}
|
|
1250
|
+
catch (error) {
|
|
1251
|
+
if (!(error instanceof Error)) {
|
|
1252
|
+
throw error;
|
|
1253
|
+
}
|
|
1254
|
+
throw new UnexpectedError(spaceTrim$1(function (block) { return "\n ".concat(name, " is not serializable\n\n ").concat(block(error.toString()), "\n "); }));
|
|
1255
|
+
}
|
|
1256
|
+
/*
|
|
1257
|
+
TODO: [0] Is there some more elegant way to check circular references?
|
|
1258
|
+
const seen = new Set();
|
|
1259
|
+
const stack = [{ value }];
|
|
1260
|
+
while (stack.length > 0) {
|
|
1261
|
+
const { value } = stack.pop()!;
|
|
1262
|
+
if (typeof value === 'object' && value !== null) {
|
|
1263
|
+
if (seen.has(value)) {
|
|
1264
|
+
throw new UnexpectedError(`${name} has circular reference`);
|
|
1265
|
+
}
|
|
1266
|
+
seen.add(value);
|
|
1267
|
+
if (Array.isArray(value)) {
|
|
1268
|
+
stack.push(...value.map((value) => ({ value })));
|
|
1269
|
+
} else {
|
|
1270
|
+
stack.push(...Object.values(value).map((value) => ({ value })));
|
|
1271
|
+
}
|
|
1272
|
+
}
|
|
1273
|
+
}
|
|
1274
|
+
*/
|
|
1275
|
+
return;
|
|
1276
|
+
}
|
|
1277
|
+
}
|
|
1278
|
+
else {
|
|
1279
|
+
throw new UnexpectedError("".concat(name, " is unknown"));
|
|
1280
|
+
}
|
|
1281
|
+
}
|
|
1282
|
+
/**
|
|
1283
|
+
* TODO: [🧠][🛣] More elegant way to tracking than passing `name`
|
|
1284
|
+
* TODO: [🧠][main] !!! In-memory cache of same values to prevent multiple checks
|
|
1285
|
+
* Note: [🐠] This is how `checkSerializableAsJson` + `isSerializableAsJson` together can just retun true/false or rich error message
|
|
1286
|
+
*/
|
|
1287
|
+
|
|
1288
|
+
/**
|
|
1289
|
+
* @@@
|
|
1290
|
+
* @@@
|
|
1291
|
+
*
|
|
1292
|
+
* Note: This function mutates the object and returns the original (but mutated-deep-freezed) object
|
|
1293
|
+
*
|
|
1294
|
+
* @param name - Name of the object for debugging purposes
|
|
1295
|
+
* @param objectValue - Object to be deeply frozen
|
|
1296
|
+
* @returns The same object as the input, but deeply frozen
|
|
1297
|
+
* @private this is in comparison to `deepFreeze` a more specific utility and maybe not very good practice to use without specific reason and considerations
|
|
1298
|
+
*/
|
|
1299
|
+
function $asDeeplyFrozenSerializableJson(name, objectValue) {
|
|
1300
|
+
checkSerializableAsJson(name, objectValue);
|
|
1301
|
+
return $deepFreeze(objectValue);
|
|
1302
|
+
}
|
|
1303
|
+
/**
|
|
1304
|
+
* TODO: [🧠][🛣] More elegant way to tracking than passing `name`
|
|
1305
|
+
* TODO: [🧠] Is there a way how to meaningfully test this utility
|
|
1306
|
+
*/
|
|
1307
|
+
|
|
1269
1308
|
/**
|
|
1270
1309
|
* Unprepare just strips the preparation data of the pipeline
|
|
1271
1310
|
*
|
|
@@ -3563,6 +3602,7 @@ function preparePipeline(pipeline, tools, options) {
|
|
|
3563
3602
|
*/
|
|
3564
3603
|
function extractVariablesFromScript(script) {
|
|
3565
3604
|
var variables = new Set();
|
|
3605
|
+
var originalScript = script;
|
|
3566
3606
|
script = "(()=>{".concat(script, "})()");
|
|
3567
3607
|
try {
|
|
3568
3608
|
for (var i = 0; i < 100 /* <- TODO: This limit to configuration */; i++)
|
|
@@ -3594,7 +3634,9 @@ function extractVariablesFromScript(script) {
|
|
|
3594
3634
|
if (!(error instanceof Error)) {
|
|
3595
3635
|
throw error;
|
|
3596
3636
|
}
|
|
3597
|
-
throw new ParseError(spaceTrim(function (block) { return "\n Can not extract variables from the script\n\n ".concat(block(error.toString()), "}\n
|
|
3637
|
+
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)
|
|
3638
|
+
.map(function (variableName, i) { return "".concat(i + 1, ") ").concat(variableName); })
|
|
3639
|
+
.join('\n'), "\n\n\n The script:\n\n ```javascript\n ").concat(block(originalScript), "\n ```\n "); }));
|
|
3598
3640
|
}
|
|
3599
3641
|
return variables;
|
|
3600
3642
|
}
|