@promptbook/markdown-utils 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 +235 -193
- 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 +1 -1
- package/umd/index.umd.js +235 -193
- 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/markdown-utils`
|
|
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
|
|
@@ -619,204 +619,31 @@ function just(value) {
|
|
|
619
619
|
}
|
|
620
620
|
|
|
621
621
|
/**
|
|
622
|
-
*
|
|
623
|
-
*
|
|
624
|
-
* Note: `$` is used to indicate that this function is not a pure function - it mutates given object
|
|
625
|
-
* Note: This function mutates the object and returns the original (but mutated-deep-freezed) object
|
|
626
|
-
*
|
|
627
|
-
* @returns The same object as the input, but deeply frozen
|
|
628
|
-
* @public exported from `@promptbook/utils`
|
|
629
|
-
*/
|
|
630
|
-
function $deepFreeze(objectValue) {
|
|
631
|
-
var e_1, _a;
|
|
632
|
-
var propertyNames = Object.getOwnPropertyNames(objectValue);
|
|
633
|
-
try {
|
|
634
|
-
for (var propertyNames_1 = __values(propertyNames), propertyNames_1_1 = propertyNames_1.next(); !propertyNames_1_1.done; propertyNames_1_1 = propertyNames_1.next()) {
|
|
635
|
-
var propertyName = propertyNames_1_1.value;
|
|
636
|
-
var value = objectValue[propertyName];
|
|
637
|
-
if (value && typeof value === 'object') {
|
|
638
|
-
$deepFreeze(value);
|
|
639
|
-
}
|
|
640
|
-
}
|
|
641
|
-
}
|
|
642
|
-
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
643
|
-
finally {
|
|
644
|
-
try {
|
|
645
|
-
if (propertyNames_1_1 && !propertyNames_1_1.done && (_a = propertyNames_1.return)) _a.call(propertyNames_1);
|
|
646
|
-
}
|
|
647
|
-
finally { if (e_1) throw e_1.error; }
|
|
648
|
-
}
|
|
649
|
-
return Object.freeze(objectValue);
|
|
650
|
-
}
|
|
651
|
-
/**
|
|
652
|
-
* TODO: [🧠] Is there a way how to meaningfully test this utility
|
|
653
|
-
*/
|
|
654
|
-
|
|
655
|
-
/**
|
|
656
|
-
* This error type indicates that the error should not happen and its last check before crashing with some other error
|
|
622
|
+
* Warning message for the generated sections and files files
|
|
657
623
|
*
|
|
658
|
-
* @
|
|
624
|
+
* @private within the repository
|
|
659
625
|
*/
|
|
660
|
-
var
|
|
661
|
-
__extends(UnexpectedError, _super);
|
|
662
|
-
function UnexpectedError(message) {
|
|
663
|
-
var _this = _super.call(this, spaceTrim$1(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;
|
|
664
|
-
_this.name = 'UnexpectedError';
|
|
665
|
-
Object.setPrototypeOf(_this, UnexpectedError.prototype);
|
|
666
|
-
return _this;
|
|
667
|
-
}
|
|
668
|
-
return UnexpectedError;
|
|
669
|
-
}(Error));
|
|
670
|
-
|
|
626
|
+
var GENERATOR_WARNING = "\u26A0\uFE0F WARNING: This code has been generated so that any manual changes will be overwritten";
|
|
671
627
|
/**
|
|
672
|
-
*
|
|
673
|
-
* If not, throws an UnexpectedError with a rich error message and tracking
|
|
628
|
+
* Name for the Promptbook
|
|
674
629
|
*
|
|
675
|
-
*
|
|
676
|
-
* - `undefined` is not serializable
|
|
677
|
-
* - `NaN` is not serializable
|
|
678
|
-
* - Objects and arrays are serializable if all their properties are serializable
|
|
679
|
-
* - Functions are not serializable
|
|
680
|
-
* - Circular references are not serializable
|
|
681
|
-
* - `Date` objects are not serializable
|
|
682
|
-
* - `Map` and `Set` objects are not serializable
|
|
683
|
-
* - `RegExp` objects are not serializable
|
|
684
|
-
* - `Error` objects are not serializable
|
|
685
|
-
* - `Symbol` objects are not serializable
|
|
686
|
-
* - And much more...
|
|
630
|
+
* TODO: [🗽] Unite branding and make single place for it
|
|
687
631
|
*
|
|
688
|
-
* @
|
|
689
|
-
* @public exported from `@promptbook/utils`
|
|
690
|
-
*/
|
|
691
|
-
function checkSerializableAsJson(name, value) {
|
|
692
|
-
var e_1, _a;
|
|
693
|
-
if (value === undefined) {
|
|
694
|
-
throw new UnexpectedError("".concat(name, " is undefined"));
|
|
695
|
-
}
|
|
696
|
-
else if (value === null) {
|
|
697
|
-
return;
|
|
698
|
-
}
|
|
699
|
-
else if (typeof value === 'boolean') {
|
|
700
|
-
return;
|
|
701
|
-
}
|
|
702
|
-
else if (typeof value === 'number' && !isNaN(value)) {
|
|
703
|
-
return;
|
|
704
|
-
}
|
|
705
|
-
else if (typeof value === 'string') {
|
|
706
|
-
return;
|
|
707
|
-
}
|
|
708
|
-
else if (typeof value === 'symbol') {
|
|
709
|
-
throw new UnexpectedError("".concat(name, " is symbol"));
|
|
710
|
-
}
|
|
711
|
-
else if (typeof value === 'function') {
|
|
712
|
-
throw new UnexpectedError("".concat(name, " is function"));
|
|
713
|
-
}
|
|
714
|
-
else if (typeof value === 'object' && Array.isArray(value)) {
|
|
715
|
-
for (var i = 0; i < value.length; i++) {
|
|
716
|
-
checkSerializableAsJson("".concat(name, "[").concat(i, "]"), value[i]);
|
|
717
|
-
}
|
|
718
|
-
}
|
|
719
|
-
else if (typeof value === 'object') {
|
|
720
|
-
if (value instanceof Date) {
|
|
721
|
-
throw new UnexpectedError(spaceTrim("\n ".concat(name, " is Date\n\n Use `string_date_iso8601` instead\n ")));
|
|
722
|
-
}
|
|
723
|
-
else if (value instanceof Map) {
|
|
724
|
-
throw new UnexpectedError("".concat(name, " is Map"));
|
|
725
|
-
}
|
|
726
|
-
else if (value instanceof Set) {
|
|
727
|
-
throw new UnexpectedError("".concat(name, " is Set"));
|
|
728
|
-
}
|
|
729
|
-
else if (value instanceof RegExp) {
|
|
730
|
-
throw new UnexpectedError("".concat(name, " is RegExp"));
|
|
731
|
-
}
|
|
732
|
-
else if (value instanceof Error) {
|
|
733
|
-
throw new UnexpectedError(spaceTrim("\n ".concat(name, " is unserialized Error\n\n Use function `serializeError`\n ")));
|
|
734
|
-
}
|
|
735
|
-
else {
|
|
736
|
-
try {
|
|
737
|
-
for (var _b = __values(Object.entries(value)), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
738
|
-
var _d = __read(_c.value, 2), subName = _d[0], subValue = _d[1];
|
|
739
|
-
if (subValue === undefined) {
|
|
740
|
-
// Note: undefined in object is serializable - it is just omited
|
|
741
|
-
continue;
|
|
742
|
-
}
|
|
743
|
-
checkSerializableAsJson("".concat(name, ".").concat(subName), subValue);
|
|
744
|
-
}
|
|
745
|
-
}
|
|
746
|
-
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
747
|
-
finally {
|
|
748
|
-
try {
|
|
749
|
-
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
750
|
-
}
|
|
751
|
-
finally { if (e_1) throw e_1.error; }
|
|
752
|
-
}
|
|
753
|
-
try {
|
|
754
|
-
JSON.stringify(value); // <- TODO: [0]
|
|
755
|
-
}
|
|
756
|
-
catch (error) {
|
|
757
|
-
if (!(error instanceof Error)) {
|
|
758
|
-
throw error;
|
|
759
|
-
}
|
|
760
|
-
throw new UnexpectedError(spaceTrim(function (block) { return "\n ".concat(name, " is not serializable\n\n ").concat(block(error.toString()), "\n "); }));
|
|
761
|
-
}
|
|
762
|
-
/*
|
|
763
|
-
TODO: [0] Is there some more elegant way to check circular references?
|
|
764
|
-
const seen = new Set();
|
|
765
|
-
const stack = [{ value }];
|
|
766
|
-
while (stack.length > 0) {
|
|
767
|
-
const { value } = stack.pop()!;
|
|
768
|
-
if (typeof value === 'object' && value !== null) {
|
|
769
|
-
if (seen.has(value)) {
|
|
770
|
-
throw new UnexpectedError(`${name} has circular reference`);
|
|
771
|
-
}
|
|
772
|
-
seen.add(value);
|
|
773
|
-
if (Array.isArray(value)) {
|
|
774
|
-
stack.push(...value.map((value) => ({ value })));
|
|
775
|
-
} else {
|
|
776
|
-
stack.push(...Object.values(value).map((value) => ({ value })));
|
|
777
|
-
}
|
|
778
|
-
}
|
|
779
|
-
}
|
|
780
|
-
*/
|
|
781
|
-
return;
|
|
782
|
-
}
|
|
783
|
-
}
|
|
784
|
-
else {
|
|
785
|
-
throw new UnexpectedError("".concat(name, " is unknown"));
|
|
786
|
-
}
|
|
787
|
-
}
|
|
788
|
-
/**
|
|
789
|
-
* TODO: [🧠][🛣] More elegant way to tracking than passing `name`
|
|
790
|
-
* TODO: [🧠][main] !!! In-memory cache of same values to prevent multiple checks
|
|
791
|
-
* Note: [🐠] This is how `checkSerializableAsJson` + `isSerializableAsJson` together can just retun true/false or rich error message
|
|
632
|
+
* @public exported from `@promptbook/core`
|
|
792
633
|
*/
|
|
793
|
-
|
|
634
|
+
var NAME = "Promptbook";
|
|
794
635
|
/**
|
|
795
|
-
*
|
|
796
|
-
* @@@
|
|
636
|
+
* Email of the responsible person
|
|
797
637
|
*
|
|
798
|
-
*
|
|
799
|
-
*
|
|
800
|
-
* @param name - Name of the object for debugging purposes
|
|
801
|
-
* @param objectValue - Object to be deeply frozen
|
|
802
|
-
* @returns The same object as the input, but deeply frozen
|
|
803
|
-
* @private this is in comparison to `deepFreeze` a more specific utility and maybe not very good practice to use without specific reason and considerations
|
|
804
|
-
*/
|
|
805
|
-
function $asDeeplyFrozenSerializableJson(name, objectValue) {
|
|
806
|
-
checkSerializableAsJson(name, objectValue);
|
|
807
|
-
return $deepFreeze(objectValue);
|
|
808
|
-
}
|
|
809
|
-
/**
|
|
810
|
-
* TODO: [🧠][🛣] More elegant way to tracking than passing `name`
|
|
811
|
-
* TODO: [🧠] Is there a way how to meaningfully test this utility
|
|
638
|
+
* @public exported from `@promptbook/core`
|
|
812
639
|
*/
|
|
813
|
-
|
|
640
|
+
var ADMIN_EMAIL = 'me@pavolhejny.com';
|
|
814
641
|
/**
|
|
815
|
-
*
|
|
642
|
+
* Name of the responsible person for the Promptbook on GitHub
|
|
816
643
|
*
|
|
817
|
-
* @
|
|
644
|
+
* @public exported from `@promptbook/core`
|
|
818
645
|
*/
|
|
819
|
-
var
|
|
646
|
+
var ADMIN_GITHUB_NAME = 'hejny';
|
|
820
647
|
/**
|
|
821
648
|
* When the title is not provided, the default title is used
|
|
822
649
|
*
|
|
@@ -874,7 +701,8 @@ var REPLACING_NONCE = 'u$k42k%!V2zo34w7Fu#@QUHYPW';
|
|
|
874
701
|
*
|
|
875
702
|
* @public exported from `@promptbook/core`
|
|
876
703
|
*/
|
|
877
|
-
var RESERVED_PARAMETER_NAMES =
|
|
704
|
+
var RESERVED_PARAMETER_NAMES =
|
|
705
|
+
/* !!!!!! $asDeeplyFrozenSerializableJson('RESERVED_PARAMETER_NAMES', _____ as const); */ [
|
|
878
706
|
'content',
|
|
879
707
|
'context',
|
|
880
708
|
'knowledge',
|
|
@@ -884,7 +712,7 @@ var RESERVED_PARAMETER_NAMES = $asDeeplyFrozenSerializableJson('RESERVED_PARAMET
|
|
|
884
712
|
// <- TODO: list here all command names
|
|
885
713
|
// <- TODO: Add more like 'date', 'modelName',...
|
|
886
714
|
// <- TODO: Add [emoji] + instructions ACRY when adding new reserved parameter
|
|
887
|
-
]
|
|
715
|
+
];
|
|
888
716
|
/**
|
|
889
717
|
* @@@
|
|
890
718
|
*
|
|
@@ -952,6 +780,40 @@ var PipelineLogicError = /** @class */ (function (_super) {
|
|
|
952
780
|
return PipelineLogicError;
|
|
953
781
|
}(Error));
|
|
954
782
|
|
|
783
|
+
/**
|
|
784
|
+
* Make error report URL for the given error
|
|
785
|
+
*
|
|
786
|
+
* @private !!!!!!
|
|
787
|
+
*/
|
|
788
|
+
function getErrorReportUrl(error) {
|
|
789
|
+
var report = {
|
|
790
|
+
title: "\uD83D\uDC1C Error report from ".concat(NAME),
|
|
791
|
+
body: spaceTrim(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 "); }),
|
|
792
|
+
};
|
|
793
|
+
var reportUrl = new URL("https://github.com/webgptorg/promptbook/issues/new");
|
|
794
|
+
reportUrl.searchParams.set('labels', 'bug');
|
|
795
|
+
reportUrl.searchParams.set('assignees', ADMIN_GITHUB_NAME);
|
|
796
|
+
reportUrl.searchParams.set('title', report.title);
|
|
797
|
+
reportUrl.searchParams.set('body', report.body);
|
|
798
|
+
return reportUrl;
|
|
799
|
+
}
|
|
800
|
+
|
|
801
|
+
/**
|
|
802
|
+
* This error type indicates that the error should not happen and its last check before crashing with some other error
|
|
803
|
+
*
|
|
804
|
+
* @public exported from `@promptbook/core`
|
|
805
|
+
*/
|
|
806
|
+
var UnexpectedError = /** @class */ (function (_super) {
|
|
807
|
+
__extends(UnexpectedError, _super);
|
|
808
|
+
function UnexpectedError(message) {
|
|
809
|
+
var _this = _super.call(this, spaceTrim$1(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;
|
|
810
|
+
_this.name = 'UnexpectedError';
|
|
811
|
+
Object.setPrototypeOf(_this, UnexpectedError.prototype);
|
|
812
|
+
return _this;
|
|
813
|
+
}
|
|
814
|
+
return UnexpectedError;
|
|
815
|
+
}(Error));
|
|
816
|
+
|
|
955
817
|
/**
|
|
956
818
|
* Tests if given string is valid semantic version
|
|
957
819
|
*
|
|
@@ -1432,6 +1294,183 @@ function extractParameterNames(template) {
|
|
|
1432
1294
|
return parameterNames;
|
|
1433
1295
|
}
|
|
1434
1296
|
|
|
1297
|
+
/**
|
|
1298
|
+
* @@@
|
|
1299
|
+
*
|
|
1300
|
+
* Note: `$` is used to indicate that this function is not a pure function - it mutates given object
|
|
1301
|
+
* Note: This function mutates the object and returns the original (but mutated-deep-freezed) object
|
|
1302
|
+
*
|
|
1303
|
+
* @returns The same object as the input, but deeply frozen
|
|
1304
|
+
* @public exported from `@promptbook/utils`
|
|
1305
|
+
*/
|
|
1306
|
+
function $deepFreeze(objectValue) {
|
|
1307
|
+
var e_1, _a;
|
|
1308
|
+
var propertyNames = Object.getOwnPropertyNames(objectValue);
|
|
1309
|
+
try {
|
|
1310
|
+
for (var propertyNames_1 = __values(propertyNames), propertyNames_1_1 = propertyNames_1.next(); !propertyNames_1_1.done; propertyNames_1_1 = propertyNames_1.next()) {
|
|
1311
|
+
var propertyName = propertyNames_1_1.value;
|
|
1312
|
+
var value = objectValue[propertyName];
|
|
1313
|
+
if (value && typeof value === 'object') {
|
|
1314
|
+
$deepFreeze(value);
|
|
1315
|
+
}
|
|
1316
|
+
}
|
|
1317
|
+
}
|
|
1318
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
1319
|
+
finally {
|
|
1320
|
+
try {
|
|
1321
|
+
if (propertyNames_1_1 && !propertyNames_1_1.done && (_a = propertyNames_1.return)) _a.call(propertyNames_1);
|
|
1322
|
+
}
|
|
1323
|
+
finally { if (e_1) throw e_1.error; }
|
|
1324
|
+
}
|
|
1325
|
+
return Object.freeze(objectValue);
|
|
1326
|
+
}
|
|
1327
|
+
/**
|
|
1328
|
+
* TODO: [🧠] Is there a way how to meaningfully test this utility
|
|
1329
|
+
*/
|
|
1330
|
+
|
|
1331
|
+
/**
|
|
1332
|
+
* Checks if the value is [🚉] serializable as JSON
|
|
1333
|
+
* If not, throws an UnexpectedError with a rich error message and tracking
|
|
1334
|
+
*
|
|
1335
|
+
* - Almost all primitives are serializable BUT:
|
|
1336
|
+
* - `undefined` is not serializable
|
|
1337
|
+
* - `NaN` is not serializable
|
|
1338
|
+
* - Objects and arrays are serializable if all their properties are serializable
|
|
1339
|
+
* - Functions are not serializable
|
|
1340
|
+
* - Circular references are not serializable
|
|
1341
|
+
* - `Date` objects are not serializable
|
|
1342
|
+
* - `Map` and `Set` objects are not serializable
|
|
1343
|
+
* - `RegExp` objects are not serializable
|
|
1344
|
+
* - `Error` objects are not serializable
|
|
1345
|
+
* - `Symbol` objects are not serializable
|
|
1346
|
+
* - And much more...
|
|
1347
|
+
*
|
|
1348
|
+
* @throws UnexpectedError if the value is not serializable as JSON
|
|
1349
|
+
* @public exported from `@promptbook/utils`
|
|
1350
|
+
*/
|
|
1351
|
+
function checkSerializableAsJson(name, value) {
|
|
1352
|
+
var e_1, _a;
|
|
1353
|
+
if (value === undefined) {
|
|
1354
|
+
throw new UnexpectedError("".concat(name, " is undefined"));
|
|
1355
|
+
}
|
|
1356
|
+
else if (value === null) {
|
|
1357
|
+
return;
|
|
1358
|
+
}
|
|
1359
|
+
else if (typeof value === 'boolean') {
|
|
1360
|
+
return;
|
|
1361
|
+
}
|
|
1362
|
+
else if (typeof value === 'number' && !isNaN(value)) {
|
|
1363
|
+
return;
|
|
1364
|
+
}
|
|
1365
|
+
else if (typeof value === 'string') {
|
|
1366
|
+
return;
|
|
1367
|
+
}
|
|
1368
|
+
else if (typeof value === 'symbol') {
|
|
1369
|
+
throw new UnexpectedError("".concat(name, " is symbol"));
|
|
1370
|
+
}
|
|
1371
|
+
else if (typeof value === 'function') {
|
|
1372
|
+
throw new UnexpectedError("".concat(name, " is function"));
|
|
1373
|
+
}
|
|
1374
|
+
else if (typeof value === 'object' && Array.isArray(value)) {
|
|
1375
|
+
for (var i = 0; i < value.length; i++) {
|
|
1376
|
+
checkSerializableAsJson("".concat(name, "[").concat(i, "]"), value[i]);
|
|
1377
|
+
}
|
|
1378
|
+
}
|
|
1379
|
+
else if (typeof value === 'object') {
|
|
1380
|
+
if (value instanceof Date) {
|
|
1381
|
+
throw new UnexpectedError(spaceTrim("\n ".concat(name, " is Date\n\n Use `string_date_iso8601` instead\n ")));
|
|
1382
|
+
}
|
|
1383
|
+
else if (value instanceof Map) {
|
|
1384
|
+
throw new UnexpectedError("".concat(name, " is Map"));
|
|
1385
|
+
}
|
|
1386
|
+
else if (value instanceof Set) {
|
|
1387
|
+
throw new UnexpectedError("".concat(name, " is Set"));
|
|
1388
|
+
}
|
|
1389
|
+
else if (value instanceof RegExp) {
|
|
1390
|
+
throw new UnexpectedError("".concat(name, " is RegExp"));
|
|
1391
|
+
}
|
|
1392
|
+
else if (value instanceof Error) {
|
|
1393
|
+
throw new UnexpectedError(spaceTrim("\n ".concat(name, " is unserialized Error\n\n Use function `serializeError`\n ")));
|
|
1394
|
+
}
|
|
1395
|
+
else {
|
|
1396
|
+
try {
|
|
1397
|
+
for (var _b = __values(Object.entries(value)), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
1398
|
+
var _d = __read(_c.value, 2), subName = _d[0], subValue = _d[1];
|
|
1399
|
+
if (subValue === undefined) {
|
|
1400
|
+
// Note: undefined in object is serializable - it is just omited
|
|
1401
|
+
continue;
|
|
1402
|
+
}
|
|
1403
|
+
checkSerializableAsJson("".concat(name, ".").concat(subName), subValue);
|
|
1404
|
+
}
|
|
1405
|
+
}
|
|
1406
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
1407
|
+
finally {
|
|
1408
|
+
try {
|
|
1409
|
+
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
1410
|
+
}
|
|
1411
|
+
finally { if (e_1) throw e_1.error; }
|
|
1412
|
+
}
|
|
1413
|
+
try {
|
|
1414
|
+
JSON.stringify(value); // <- TODO: [0]
|
|
1415
|
+
}
|
|
1416
|
+
catch (error) {
|
|
1417
|
+
if (!(error instanceof Error)) {
|
|
1418
|
+
throw error;
|
|
1419
|
+
}
|
|
1420
|
+
throw new UnexpectedError(spaceTrim(function (block) { return "\n ".concat(name, " is not serializable\n\n ").concat(block(error.toString()), "\n "); }));
|
|
1421
|
+
}
|
|
1422
|
+
/*
|
|
1423
|
+
TODO: [0] Is there some more elegant way to check circular references?
|
|
1424
|
+
const seen = new Set();
|
|
1425
|
+
const stack = [{ value }];
|
|
1426
|
+
while (stack.length > 0) {
|
|
1427
|
+
const { value } = stack.pop()!;
|
|
1428
|
+
if (typeof value === 'object' && value !== null) {
|
|
1429
|
+
if (seen.has(value)) {
|
|
1430
|
+
throw new UnexpectedError(`${name} has circular reference`);
|
|
1431
|
+
}
|
|
1432
|
+
seen.add(value);
|
|
1433
|
+
if (Array.isArray(value)) {
|
|
1434
|
+
stack.push(...value.map((value) => ({ value })));
|
|
1435
|
+
} else {
|
|
1436
|
+
stack.push(...Object.values(value).map((value) => ({ value })));
|
|
1437
|
+
}
|
|
1438
|
+
}
|
|
1439
|
+
}
|
|
1440
|
+
*/
|
|
1441
|
+
return;
|
|
1442
|
+
}
|
|
1443
|
+
}
|
|
1444
|
+
else {
|
|
1445
|
+
throw new UnexpectedError("".concat(name, " is unknown"));
|
|
1446
|
+
}
|
|
1447
|
+
}
|
|
1448
|
+
/**
|
|
1449
|
+
* TODO: [🧠][🛣] More elegant way to tracking than passing `name`
|
|
1450
|
+
* TODO: [🧠][main] !!! In-memory cache of same values to prevent multiple checks
|
|
1451
|
+
* Note: [🐠] This is how `checkSerializableAsJson` + `isSerializableAsJson` together can just retun true/false or rich error message
|
|
1452
|
+
*/
|
|
1453
|
+
|
|
1454
|
+
/**
|
|
1455
|
+
* @@@
|
|
1456
|
+
* @@@
|
|
1457
|
+
*
|
|
1458
|
+
* Note: This function mutates the object and returns the original (but mutated-deep-freezed) object
|
|
1459
|
+
*
|
|
1460
|
+
* @param name - Name of the object for debugging purposes
|
|
1461
|
+
* @param objectValue - Object to be deeply frozen
|
|
1462
|
+
* @returns The same object as the input, but deeply frozen
|
|
1463
|
+
* @private this is in comparison to `deepFreeze` a more specific utility and maybe not very good practice to use without specific reason and considerations
|
|
1464
|
+
*/
|
|
1465
|
+
function $asDeeplyFrozenSerializableJson(name, objectValue) {
|
|
1466
|
+
checkSerializableAsJson(name, objectValue);
|
|
1467
|
+
return $deepFreeze(objectValue);
|
|
1468
|
+
}
|
|
1469
|
+
/**
|
|
1470
|
+
* TODO: [🧠][🛣] More elegant way to tracking than passing `name`
|
|
1471
|
+
* TODO: [🧠] Is there a way how to meaningfully test this utility
|
|
1472
|
+
*/
|
|
1473
|
+
|
|
1435
1474
|
/**
|
|
1436
1475
|
* Unprepare just strips the preparation data of the pipeline
|
|
1437
1476
|
*
|
|
@@ -3745,6 +3784,7 @@ function preparePipeline(pipeline, tools, options) {
|
|
|
3745
3784
|
*/
|
|
3746
3785
|
function extractVariablesFromScript(script) {
|
|
3747
3786
|
var variables = new Set();
|
|
3787
|
+
var originalScript = script;
|
|
3748
3788
|
script = "(()=>{".concat(script, "})()");
|
|
3749
3789
|
try {
|
|
3750
3790
|
for (var i = 0; i < 100 /* <- TODO: This limit to configuration */; i++)
|
|
@@ -3776,7 +3816,9 @@ function extractVariablesFromScript(script) {
|
|
|
3776
3816
|
if (!(error instanceof Error)) {
|
|
3777
3817
|
throw error;
|
|
3778
3818
|
}
|
|
3779
|
-
throw new ParseError(spaceTrim$1(function (block) { return "\n Can not extract variables from the script\n\n ".concat(block(error.toString()), "}\n
|
|
3819
|
+
throw new ParseError(spaceTrim$1(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)
|
|
3820
|
+
.map(function (variableName, i) { return "".concat(i + 1, ") ").concat(variableName); })
|
|
3821
|
+
.join('\n'), "\n\n\n The script:\n\n ```javascript\n ").concat(block(originalScript), "\n ```\n "); }));
|
|
3780
3822
|
}
|
|
3781
3823
|
return variables;
|
|
3782
3824
|
}
|
|
@@ -5875,11 +5917,11 @@ function addAutoGeneratedSection(content, options) {
|
|
|
5875
5917
|
var placeForSection = removeContentComments(content).match(/^##.*$/im);
|
|
5876
5918
|
if (placeForSection !== null) {
|
|
5877
5919
|
var _a = __read(placeForSection, 1), heading_1 = _a[0];
|
|
5878
|
-
return content.replace(heading_1, spaceTrim$1(function (block) { return "\n ".concat(block(contentToInsert), "\n
|
|
5920
|
+
return content.replace(heading_1, spaceTrim$1(function (block) { return "\n ".concat(block(contentToInsert), "\n\n ").concat(block(heading_1), "\n "); }));
|
|
5879
5921
|
}
|
|
5880
5922
|
console.warn("No place where to put the section <!--".concat(sectionName, "-->, using the end of the file"));
|
|
5881
|
-
// <- TODO: [🚎] Some better way how to get warnings from pipeline parsing / logic
|
|
5882
|
-
return spaceTrim$1(function (block) { return "\n ".concat(block(content), "\n
|
|
5923
|
+
// <- TODO: [🚎][💩] Some better way how to get warnings from pipeline parsing / logic
|
|
5924
|
+
return spaceTrim$1(function (block) { return "\n ".concat(block(content), "\n\n ").concat(block(contentToInsert), "\n "); });
|
|
5883
5925
|
}
|
|
5884
5926
|
/**
|
|
5885
5927
|
* TODO: [🏛] This can be part of markdown builder
|