@promptbook/node 0.72.0-4 → 0.72.0-5
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/esm/index.es.js +127 -50
- package/esm/index.es.js.map +1 -1
- package/esm/typings/src/_packages/core.index.d.ts +4 -0
- package/esm/typings/src/collection/constructors/createCollectionFromUrl.d.ts +1 -1
- package/esm/typings/src/commands/FOREACH/ForeachJson.d.ts +5 -1
- package/esm/typings/src/conversion/pipelineStringToJsonSync.d.ts +1 -1
- package/esm/typings/src/errors/AbstractFormatError.d.ts +11 -0
- package/esm/typings/src/execution/PipelineExecutor.d.ts +1 -0
- package/esm/typings/src/execution/createPipelineExecutor/00-createPipelineExecutor.d.ts +3 -0
- package/esm/typings/src/execution/createPipelineExecutor/10-executePipeline.d.ts +3 -0
- package/esm/typings/src/execution/createPipelineExecutor/20-executeTemplate.d.ts +3 -0
- package/esm/typings/src/execution/createPipelineExecutor/{30-executeFormatCells.d.ts → 30-executeFormatSubvalues.d.ts} +2 -6
- package/esm/typings/src/execution/embeddingVectorToString.d.ts +1 -1
- package/esm/typings/src/formats/_common/FormatSubvalueDefinition.d.ts +2 -1
- package/esm/typings/src/formats/csv/CsvFormatError.d.ts +10 -0
- package/esm/typings/src/llm-providers/anthropic-claude/playground/playground.d.ts +2 -2
- package/esm/typings/src/llm-providers/openai/OpenAiAssistantExecutionTools.d.ts +1 -1
- package/esm/typings/src/llm-providers/openai/playground/playground.d.ts +1 -1
- package/esm/typings/src/types/PipelineJson/ParameterJson.d.ts +1 -1
- package/esm/typings/src/types/execution-report/ExecutionReportJson.d.ts +0 -3
- package/esm/typings/src/types/execution-report/executionReportJsonToString.d.ts +2 -1
- package/esm/typings/src/types/typeAliases.d.ts +1 -1
- package/package.json +2 -2
- package/umd/index.umd.js +127 -50
- package/umd/index.umd.js.map +1 -1
package/esm/index.es.js
CHANGED
|
@@ -15,8 +15,8 @@ import * as dotenv from 'dotenv';
|
|
|
15
15
|
/**
|
|
16
16
|
* The version of the Promptbook library
|
|
17
17
|
*/
|
|
18
|
-
var PROMPTBOOK_VERSION = '0.72.0-
|
|
19
|
-
// TODO:[main] !!!! List here all the versions and annotate + put into script
|
|
18
|
+
var PROMPTBOOK_VERSION = '0.72.0-4';
|
|
19
|
+
// TODO: [main] !!!! List here all the versions and annotate + put into script
|
|
20
20
|
|
|
21
21
|
/*! *****************************************************************************
|
|
22
22
|
Copyright (c) Microsoft Corporation.
|
|
@@ -516,7 +516,7 @@ function pipelineJsonToString(pipelineJson) {
|
|
|
516
516
|
commands.push("PIPELINE URL ".concat(pipelineUrl));
|
|
517
517
|
}
|
|
518
518
|
commands.push("PROMPTBOOK VERSION ".concat(promptbookVersion));
|
|
519
|
-
// TODO:[main] !!! This increase size of the bundle and is probbably not necessary
|
|
519
|
+
// TODO: [main] !!! This increase size of the bundle and is probbably not necessary
|
|
520
520
|
pipelineString = prettifyMarkdown(pipelineString);
|
|
521
521
|
try {
|
|
522
522
|
for (var _g = __values(parameters.filter(function (_a) {
|
|
@@ -664,12 +664,12 @@ function pipelineJsonToString(pipelineJson) {
|
|
|
664
664
|
pipelineString += '```' + contentLanguage;
|
|
665
665
|
pipelineString += '\n';
|
|
666
666
|
pipelineString += spaceTrim$1(content);
|
|
667
|
-
// <- TODO:[main] !!! Escape
|
|
667
|
+
// <- TODO: [main] !!! Escape
|
|
668
668
|
// <- TODO: [🧠] Some clear strategy how to spaceTrim the blocks
|
|
669
669
|
pipelineString += '\n';
|
|
670
670
|
pipelineString += '```';
|
|
671
671
|
pipelineString += '\n\n';
|
|
672
|
-
pipelineString += "`-> {".concat(resultingParameterName, "}`"); // <- TODO:[main] !!! If the parameter here has description, add it and use templateParameterJsonToString
|
|
672
|
+
pipelineString += "`-> {".concat(resultingParameterName, "}`"); // <- TODO: [main] !!! If the parameter here has description, add it and use templateParameterJsonToString
|
|
673
673
|
}
|
|
674
674
|
}
|
|
675
675
|
catch (e_3_1) { e_3 = { error: e_3_1 }; }
|
|
@@ -903,7 +903,7 @@ function isValidPromptbookVersion(version) {
|
|
|
903
903
|
if ( /* version === '1.0.0' || */version === '2.0.0' || version === '3.0.0') {
|
|
904
904
|
return false;
|
|
905
905
|
}
|
|
906
|
-
// <- TODO:[main] !!! Check isValidPromptbookVersion against PROMPTBOOK_VERSIONS
|
|
906
|
+
// <- TODO: [main] !!! Check isValidPromptbookVersion against PROMPTBOOK_VERSIONS
|
|
907
907
|
return true;
|
|
908
908
|
}
|
|
909
909
|
|
|
@@ -2554,7 +2554,7 @@ function extractParameterNamesFromTemplate(template) {
|
|
|
2554
2554
|
// Note: [🍭] Fixing dependent subparameterName from FOREACH command
|
|
2555
2555
|
if (foreach !== undefined) {
|
|
2556
2556
|
try {
|
|
2557
|
-
for (var _l = __values(foreach.
|
|
2557
|
+
for (var _l = __values(foreach.inputSubparameterNames), _m = _l.next(); !_m.done; _m = _l.next()) {
|
|
2558
2558
|
var subparameterName = _m.value;
|
|
2559
2559
|
if (parameterNames.has(subparameterName)) {
|
|
2560
2560
|
parameterNames.delete(subparameterName);
|
|
@@ -2669,6 +2669,42 @@ function TODO_USE() {
|
|
|
2669
2669
|
}
|
|
2670
2670
|
}
|
|
2671
2671
|
|
|
2672
|
+
/**
|
|
2673
|
+
* This error indicates problems parsing the format value
|
|
2674
|
+
*
|
|
2675
|
+
* For example, when the format value is not a valid JSON or CSV
|
|
2676
|
+
* This is not thrown directly but in extended classes
|
|
2677
|
+
*
|
|
2678
|
+
* @public exported from `@promptbook/core`
|
|
2679
|
+
*/
|
|
2680
|
+
var AbstractFormatError = /** @class */ (function (_super) {
|
|
2681
|
+
__extends(AbstractFormatError, _super);
|
|
2682
|
+
// Note: To allow instanceof do not put here error `name`
|
|
2683
|
+
// public readonly name = 'AbstractFormatError';
|
|
2684
|
+
function AbstractFormatError(message) {
|
|
2685
|
+
var _this = _super.call(this, message) || this;
|
|
2686
|
+
Object.setPrototypeOf(_this, AbstractFormatError.prototype);
|
|
2687
|
+
return _this;
|
|
2688
|
+
}
|
|
2689
|
+
return AbstractFormatError;
|
|
2690
|
+
}(Error));
|
|
2691
|
+
|
|
2692
|
+
/**
|
|
2693
|
+
* This error indicates problem with parsing of CSV
|
|
2694
|
+
*
|
|
2695
|
+
* @public exported from `@promptbook/core`
|
|
2696
|
+
*/
|
|
2697
|
+
var CsvFormatError = /** @class */ (function (_super) {
|
|
2698
|
+
__extends(CsvFormatError, _super);
|
|
2699
|
+
function CsvFormatError(message) {
|
|
2700
|
+
var _this = _super.call(this, message) || this;
|
|
2701
|
+
_this.name = 'CsvFormatError';
|
|
2702
|
+
Object.setPrototypeOf(_this, CsvFormatError.prototype);
|
|
2703
|
+
return _this;
|
|
2704
|
+
}
|
|
2705
|
+
return CsvFormatError;
|
|
2706
|
+
}(AbstractFormatError));
|
|
2707
|
+
|
|
2672
2708
|
/**
|
|
2673
2709
|
* @@@
|
|
2674
2710
|
*
|
|
@@ -2689,7 +2725,7 @@ var CsvFormatDefinition = {
|
|
|
2689
2725
|
formatName: 'CSV',
|
|
2690
2726
|
aliases: ['SPREADSHEET', 'TABLE'],
|
|
2691
2727
|
isValid: function (value, settings, schema) {
|
|
2692
|
-
// TODO:
|
|
2728
|
+
// TODO: Implement CSV validation
|
|
2693
2729
|
TODO_USE(value /* <- TODO: Use value here */);
|
|
2694
2730
|
TODO_USE(settings /* <- TODO: Use settings here */);
|
|
2695
2731
|
TODO_USE(schema /* <- TODO: Use schema here */);
|
|
@@ -2710,7 +2746,7 @@ var CsvFormatDefinition = {
|
|
|
2710
2746
|
subvalueDefinitions: [
|
|
2711
2747
|
{
|
|
2712
2748
|
subvalueName: 'ROW',
|
|
2713
|
-
mapValues: function (value, settings, mapCallback) {
|
|
2749
|
+
mapValues: function (value, outputParameterName, settings, mapCallback) {
|
|
2714
2750
|
return __awaiter(this, void 0, void 0, function () {
|
|
2715
2751
|
var csv, mappedData;
|
|
2716
2752
|
var _this = this;
|
|
@@ -2719,24 +2755,22 @@ var CsvFormatDefinition = {
|
|
|
2719
2755
|
case 0:
|
|
2720
2756
|
csv = parse(value, __assign(__assign({}, settings), MANDATORY_CSV_SETTINGS));
|
|
2721
2757
|
if (csv.errors.length !== 0) {
|
|
2722
|
-
throw new
|
|
2723
|
-
spaceTrim$1(function (block) { return "\n CSV parsing error\n\n ".concat(block(csv.errors.map(function (error) { return error.message; }).join('\n\n')), "\n "); }));
|
|
2758
|
+
throw new CsvFormatError(spaceTrim$1(function (block) { return "\n CSV parsing error\n\n ".concat(block(csv.errors.map(function (error) { return error.message; }).join('\n\n')), "\n "); }));
|
|
2724
2759
|
}
|
|
2725
2760
|
return [4 /*yield*/, Promise.all(csv.data.map(function (row, index) { return __awaiter(_this, void 0, void 0, function () {
|
|
2726
|
-
var _a;
|
|
2727
|
-
var
|
|
2728
|
-
return __generator(this, function (
|
|
2729
|
-
switch (
|
|
2761
|
+
var _a, _b;
|
|
2762
|
+
var _c;
|
|
2763
|
+
return __generator(this, function (_d) {
|
|
2764
|
+
switch (_d.label) {
|
|
2730
2765
|
case 0:
|
|
2766
|
+
if (row[outputParameterName]) {
|
|
2767
|
+
throw new CsvFormatError("Can not overwrite existing column \"".concat(outputParameterName, "\" in CSV row"));
|
|
2768
|
+
}
|
|
2731
2769
|
_a = [__assign({}, row)];
|
|
2732
|
-
|
|
2733
|
-
|
|
2734
|
-
// <- TODO: !!!!!! Check name collisions
|
|
2770
|
+
_c = {};
|
|
2771
|
+
_b = outputParameterName;
|
|
2735
2772
|
return [4 /*yield*/, mapCallback(row, index)];
|
|
2736
|
-
case 1: return [2 /*return*/,
|
|
2737
|
-
// <- TODO: !!!!!! Dynamic new column name and position
|
|
2738
|
-
// <- TODO: !!!!!! Check name collisions
|
|
2739
|
-
_c.sent(), _b)])))];
|
|
2773
|
+
case 1: return [2 /*return*/, __assign.apply(void 0, _a.concat([(_c[_b] = _d.sent(), _c)]))];
|
|
2740
2774
|
}
|
|
2741
2775
|
});
|
|
2742
2776
|
}); }))];
|
|
@@ -2750,7 +2784,7 @@ var CsvFormatDefinition = {
|
|
|
2750
2784
|
},
|
|
2751
2785
|
{
|
|
2752
2786
|
subvalueName: 'CELL',
|
|
2753
|
-
mapValues: function (value, settings, mapCallback) {
|
|
2787
|
+
mapValues: function (value, outputParameterName, settings, mapCallback) {
|
|
2754
2788
|
return __awaiter(this, void 0, void 0, function () {
|
|
2755
2789
|
var csv, mappedData;
|
|
2756
2790
|
var _this = this;
|
|
@@ -2759,8 +2793,7 @@ var CsvFormatDefinition = {
|
|
|
2759
2793
|
case 0:
|
|
2760
2794
|
csv = parse(value, __assign(__assign({}, settings), MANDATORY_CSV_SETTINGS));
|
|
2761
2795
|
if (csv.errors.length !== 0) {
|
|
2762
|
-
throw new
|
|
2763
|
-
spaceTrim$1(function (block) { return "\n CSV parsing error\n\n ".concat(block(csv.errors.map(function (error) { return error.message; }).join('\n\n')), "\n "); }));
|
|
2796
|
+
throw new CsvFormatError(spaceTrim$1(function (block) { return "\n CSV parsing error\n\n ".concat(block(csv.errors.map(function (error) { return error.message; }).join('\n\n')), "\n "); }));
|
|
2764
2797
|
}
|
|
2765
2798
|
return [4 /*yield*/, Promise.all(csv.data.map(function (row, rowIndex) { return __awaiter(_this, void 0, void 0, function () {
|
|
2766
2799
|
var _this = this;
|
|
@@ -2877,7 +2910,7 @@ var TextFormatDefinition = {
|
|
|
2877
2910
|
subvalueDefinitions: [
|
|
2878
2911
|
{
|
|
2879
2912
|
subvalueName: 'LINE',
|
|
2880
|
-
mapValues: function (value, settings, mapCallback) {
|
|
2913
|
+
mapValues: function (value, outputParameterName, settings, mapCallback) {
|
|
2881
2914
|
return __awaiter(this, void 0, void 0, function () {
|
|
2882
2915
|
var lines, mappedLines;
|
|
2883
2916
|
return __generator(this, function (_a) {
|
|
@@ -3445,7 +3478,9 @@ function executeAttempts(options) {
|
|
|
3445
3478
|
title: template.title,
|
|
3446
3479
|
pipelineUrl: "".concat(preparedPipeline.pipelineUrl
|
|
3447
3480
|
? preparedPipeline.pipelineUrl
|
|
3448
|
-
: 'anonymous' /* <- TODO: [🧠] How to deal with anonymous pipelines, do here some auto-url like SHA-256 based ad-hoc identifier? */, "#").concat(template.name
|
|
3481
|
+
: 'anonymous' /* <- TODO: [🧠] How to deal with anonymous pipelines, do here some auto-url like SHA-256 based ad-hoc identifier? */, "#").concat(template.name
|
|
3482
|
+
// <- TODO: Here should be maybe also subformat index to distinguish between same template with different subformat values
|
|
3483
|
+
),
|
|
3449
3484
|
parameters: parameters,
|
|
3450
3485
|
content: preparedContent,
|
|
3451
3486
|
modelRequirements: modelRequirements,
|
|
@@ -3749,7 +3784,7 @@ function executeAttempts(options) {
|
|
|
3749
3784
|
*
|
|
3750
3785
|
* @private internal utility of `createPipelineExecutor`
|
|
3751
3786
|
*/
|
|
3752
|
-
function
|
|
3787
|
+
function executeFormatSubvalues(options) {
|
|
3753
3788
|
return __awaiter(this, void 0, void 0, function () {
|
|
3754
3789
|
var template, jokerParameterNames, parameters, priority, pipelineIdentification, settings, parameterValue, formatDefinition, subvalueDefinition, formatSettings, resultString;
|
|
3755
3790
|
var _this = this;
|
|
@@ -3787,18 +3822,18 @@ function executeFormatCells(options) {
|
|
|
3787
3822
|
}
|
|
3788
3823
|
if (formatDefinition.formatName === 'CSV') {
|
|
3789
3824
|
formatSettings = settings.csvSettings;
|
|
3790
|
-
// <- TODO:
|
|
3825
|
+
// <- TODO: [🤹♂️] More universal, make simmilar pattern for other formats for example \n vs \r\n in text
|
|
3791
3826
|
}
|
|
3792
|
-
return [4 /*yield*/, subvalueDefinition.mapValues(parameterValue, formatSettings, function (subparameters, index) { return __awaiter(_this, void 0, void 0, function () {
|
|
3827
|
+
return [4 /*yield*/, subvalueDefinition.mapValues(parameterValue, template.foreach.outputSubparameterName, formatSettings, function (subparameters, index) { return __awaiter(_this, void 0, void 0, function () {
|
|
3793
3828
|
var mappedParameters, allSubparameters, subresultString;
|
|
3794
3829
|
return __generator(this, function (_a) {
|
|
3795
3830
|
switch (_a.label) {
|
|
3796
3831
|
case 0:
|
|
3797
|
-
// TODO:
|
|
3798
|
-
// TODO:
|
|
3832
|
+
// TODO: [🤹♂️][🪂] Limit to N concurrent executions
|
|
3833
|
+
// TODO: When done [🐚] Report progress also for each subvalue here
|
|
3799
3834
|
try {
|
|
3800
3835
|
mappedParameters = mapAvailableToExpectedParameters({
|
|
3801
|
-
expectedParameters: Object.fromEntries(template.foreach.
|
|
3836
|
+
expectedParameters: Object.fromEntries(template.foreach.inputSubparameterNames.map(function (subparameterName) { return [subparameterName, null]; })),
|
|
3802
3837
|
availableParameters: subparameters,
|
|
3803
3838
|
});
|
|
3804
3839
|
}
|
|
@@ -3825,10 +3860,6 @@ function executeFormatCells(options) {
|
|
|
3825
3860
|
});
|
|
3826
3861
|
});
|
|
3827
3862
|
}
|
|
3828
|
-
/**
|
|
3829
|
-
* TODO: !!!!!! Make pipelineIdentification more precise
|
|
3830
|
-
* TODO: !!!!!! How FOREACH execution looks in the report
|
|
3831
|
-
*/
|
|
3832
3863
|
|
|
3833
3864
|
/**
|
|
3834
3865
|
* @@@
|
|
@@ -4022,7 +4053,7 @@ function executeTemplate(options) {
|
|
|
4022
4053
|
preparedContent = (currentTemplate.preparedContent || '{content}')
|
|
4023
4054
|
.split('{content}')
|
|
4024
4055
|
.join(currentTemplate.content);
|
|
4025
|
-
return [4 /*yield*/,
|
|
4056
|
+
return [4 /*yield*/, executeFormatSubvalues({
|
|
4026
4057
|
jokerParameterNames: jokerParameterNames,
|
|
4027
4058
|
priority: priority,
|
|
4028
4059
|
maxAttempts: maxAttempts,
|
|
@@ -4062,6 +4093,9 @@ function executeTemplate(options) {
|
|
|
4062
4093
|
/**
|
|
4063
4094
|
* TODO: [🤹♂️]
|
|
4064
4095
|
*/
|
|
4096
|
+
/**
|
|
4097
|
+
* TODO: [🐚] Change onProgress to object that represents the running execution, can be subscribed via RxJS to and also awaited
|
|
4098
|
+
*/
|
|
4065
4099
|
|
|
4066
4100
|
/**
|
|
4067
4101
|
* @@@
|
|
@@ -4413,6 +4447,9 @@ function executePipeline(options) {
|
|
|
4413
4447
|
});
|
|
4414
4448
|
});
|
|
4415
4449
|
}
|
|
4450
|
+
/**
|
|
4451
|
+
* TODO: [🐚] Change onProgress to object that represents the running execution, can be subscribed via RxJS to and also awaited
|
|
4452
|
+
*/
|
|
4416
4453
|
|
|
4417
4454
|
/**
|
|
4418
4455
|
* Creates executor function from pipeline and execution tools.
|
|
@@ -4470,6 +4507,9 @@ function createPipelineExecutor(options) {
|
|
|
4470
4507
|
}); };
|
|
4471
4508
|
return pipelineExecutor;
|
|
4472
4509
|
}
|
|
4510
|
+
/**
|
|
4511
|
+
* TODO: [🐚] Change onProgress to object that represents the running execution, can be subscribed via RxJS to and also awaited
|
|
4512
|
+
*/
|
|
4473
4513
|
|
|
4474
4514
|
/**
|
|
4475
4515
|
* @@@
|
|
@@ -4521,7 +4561,7 @@ function prepareKnowledgeFromMarkdown(knowledgeContent /* <- TODO: [🖖] (?mayb
|
|
|
4521
4561
|
outputParameters = result.outputParameters;
|
|
4522
4562
|
knowledgePiecesRaw = outputParameters.knowledgePieces;
|
|
4523
4563
|
knowledgeTextPieces = (knowledgePiecesRaw || '').split('\n---\n');
|
|
4524
|
-
// <- TODO:[main] !!!!! Smarter split and filter out empty pieces
|
|
4564
|
+
// <- TODO: [main] !!!!! Smarter split and filter out empty pieces
|
|
4525
4565
|
if (isVerbose) {
|
|
4526
4566
|
console.info('knowledgeTextPieces:', knowledgeTextPieces);
|
|
4527
4567
|
}
|
|
@@ -4871,7 +4911,7 @@ function prepareTemplates(pipeline, options) {
|
|
|
4871
4911
|
case 0:
|
|
4872
4912
|
_a = options.maxParallelCount, maxParallelCount = _a === void 0 ? MAX_PARALLEL_COUNT : _a;
|
|
4873
4913
|
templates = pipeline.templates, parameters = pipeline.parameters, knowledgePiecesCount = pipeline.knowledgePiecesCount;
|
|
4874
|
-
// TODO:[main] !!!!! Apply samples to each template (if missing and is for the template defined)
|
|
4914
|
+
// TODO: [main] !!!!! Apply samples to each template (if missing and is for the template defined)
|
|
4875
4915
|
TODO_USE(parameters);
|
|
4876
4916
|
templatesPrepared = new Array(
|
|
4877
4917
|
// <- TODO: [🧱] Implement in a functional (not new Class) way
|
|
@@ -5075,7 +5115,7 @@ var knowledgeCommandParser = {
|
|
|
5075
5115
|
if (sourceContent === '') {
|
|
5076
5116
|
throw new ParseError("Source is not defined");
|
|
5077
5117
|
}
|
|
5078
|
-
// TODO:[main] !!!! Following checks should be applied every link in the `sourceContent`
|
|
5118
|
+
// TODO: [main] !!!! Following checks should be applied every link in the `sourceContent`
|
|
5079
5119
|
if (sourceContent.startsWith('http://')) {
|
|
5080
5120
|
throw new ParseError("Source is not secure");
|
|
5081
5121
|
}
|
|
@@ -5828,8 +5868,10 @@ var foreachCommandParser = {
|
|
|
5828
5868
|
*/
|
|
5829
5869
|
examples: [
|
|
5830
5870
|
'FOREACH Text Line `{customers}` -> `{customer}`',
|
|
5831
|
-
'
|
|
5832
|
-
'
|
|
5871
|
+
'FOREACH Csv Cell `{customers}` -> `{cell}`',
|
|
5872
|
+
'FOREACH Csv Row `{customers}` -> `{firstName}`, `{lastName}`, `+{email}`',
|
|
5873
|
+
'FOR Text Line `{customers}` -> `{customer}`',
|
|
5874
|
+
'EACH Text Line `{customers}` -> `{customer}`',
|
|
5833
5875
|
],
|
|
5834
5876
|
/**
|
|
5835
5877
|
* Parses the FOREACH command
|
|
@@ -5863,20 +5905,49 @@ var foreachCommandParser = {
|
|
|
5863
5905
|
throw new ParseError("FOREACH command must have '->' to assign the value to the parameter");
|
|
5864
5906
|
}
|
|
5865
5907
|
var parameterName = validateParameterName(parameterNameArg);
|
|
5866
|
-
var
|
|
5908
|
+
var outputSubparameterName = null;
|
|
5909
|
+
// TODO: [4] DRY
|
|
5910
|
+
var inputSubparameterNames = args
|
|
5867
5911
|
.slice(4)
|
|
5868
5912
|
.map(function (parameterName) { return parameterName.split(',').join(' ').trim(); })
|
|
5913
|
+
.filter(function (parameterName) { return !parameterName.includes('+'); })
|
|
5869
5914
|
.filter(function (parameterName) { return parameterName !== ''; })
|
|
5870
5915
|
.map(validateParameterName);
|
|
5871
|
-
|
|
5872
|
-
|
|
5916
|
+
// TODO: [4] DRY
|
|
5917
|
+
var outputSubparameterNames = args
|
|
5918
|
+
.slice(4)
|
|
5919
|
+
.map(function (parameterName) { return parameterName.split(',').join(' ').trim(); })
|
|
5920
|
+
.filter(function (parameterName) { return parameterName.includes('+'); })
|
|
5921
|
+
.map(function (parameterName) { return parameterName.split('+').join(''); })
|
|
5922
|
+
.map(validateParameterName);
|
|
5923
|
+
if (outputSubparameterNames.length === 1) {
|
|
5924
|
+
outputSubparameterName = outputSubparameterNames[0];
|
|
5925
|
+
}
|
|
5926
|
+
else if (outputSubparameterNames.length > 1) {
|
|
5927
|
+
throw new ParseError("FOREACH command can not have more than one output subparameter");
|
|
5928
|
+
}
|
|
5929
|
+
if (inputSubparameterNames.length === 0) {
|
|
5930
|
+
throw new ParseError("FOREACH command must have at least one input subparameter");
|
|
5931
|
+
}
|
|
5932
|
+
if (outputSubparameterName === null) {
|
|
5933
|
+
// TODO: Following code should be unhardcoded from here and moved to the format definition
|
|
5934
|
+
if (formatName === 'CSV' && subformatName === 'CELL') {
|
|
5935
|
+
outputSubparameterName = 'newCell';
|
|
5936
|
+
}
|
|
5937
|
+
else if (formatName === 'TEXT' && subformatName === 'LINE') {
|
|
5938
|
+
outputSubparameterName = 'newLine';
|
|
5939
|
+
}
|
|
5940
|
+
else {
|
|
5941
|
+
throw new ParseError(spaceTrim$1("\n FOREACH ".concat(formatName, " ").concat(subformatName, " must specify output subparameter\n\n Correct example:\n - FOREACH ").concat(formatName, " ").concat(subformatName, " {").concat(parameterName, "} -> {inputSubparameterName1}, {inputSubparameterName2}, +{outputSubparameterName}\n\n ")));
|
|
5942
|
+
}
|
|
5873
5943
|
}
|
|
5874
5944
|
return {
|
|
5875
5945
|
type: 'FOREACH',
|
|
5876
5946
|
formatName: formatName,
|
|
5877
5947
|
subformatName: subformatName,
|
|
5878
5948
|
parameterName: parameterName,
|
|
5879
|
-
|
|
5949
|
+
inputSubparameterNames: inputSubparameterNames,
|
|
5950
|
+
outputSubparameterName: outputSubparameterName,
|
|
5880
5951
|
};
|
|
5881
5952
|
},
|
|
5882
5953
|
/**
|
|
@@ -5885,10 +5956,16 @@ var foreachCommandParser = {
|
|
|
5885
5956
|
* Note: `$` is used to indicate that this function mutates given `templateJson`
|
|
5886
5957
|
*/
|
|
5887
5958
|
$applyToTemplateJson: function (command, $templateJson, $pipelineJson) {
|
|
5888
|
-
var formatName = command.formatName, subformatName = command.subformatName, parameterName = command.parameterName,
|
|
5959
|
+
var formatName = command.formatName, subformatName = command.subformatName, parameterName = command.parameterName, inputSubparameterNames = command.inputSubparameterNames, outputSubparameterName = command.outputSubparameterName;
|
|
5889
5960
|
// TODO: [🍭] Detect double use
|
|
5890
5961
|
// TODO: [🍭] Detect usage with JOKER and don't allow it
|
|
5891
|
-
$templateJson.foreach = {
|
|
5962
|
+
$templateJson.foreach = {
|
|
5963
|
+
formatName: formatName,
|
|
5964
|
+
subformatName: subformatName,
|
|
5965
|
+
parameterName: parameterName,
|
|
5966
|
+
inputSubparameterNames: inputSubparameterNames,
|
|
5967
|
+
outputSubparameterName: outputSubparameterName,
|
|
5968
|
+
};
|
|
5892
5969
|
keepUnused($pipelineJson); // <- TODO: [🧠] Maybe register subparameter from foreach into parameters of the pipeline
|
|
5893
5970
|
// Note: [🍭] FOREACH apply has some sideeffects on different places in codebase
|
|
5894
5971
|
},
|
|
@@ -7710,7 +7787,7 @@ function pipelineStringToJsonSync(pipelineString) {
|
|
|
7710
7787
|
return $asDeeplyFrozenSerializableJson('pipelineJson', $pipelineJson);
|
|
7711
7788
|
}
|
|
7712
7789
|
/**
|
|
7713
|
-
* TODO:[main] !!!! Warn if used only sync version
|
|
7790
|
+
* TODO: [main] !!!! Warn if used only sync version
|
|
7714
7791
|
* TODO: [🚞] Report here line/column of error
|
|
7715
7792
|
* TODO: Use spaceTrim more effectively
|
|
7716
7793
|
* TODO: [🧠] Parameter flags - isInput, isOutput, isInternal
|