@platforma-sdk/model 1.48.14 → 1.50.0
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/dist/bconfig/lambdas.d.ts +8 -1
- package/dist/bconfig/lambdas.d.ts.map +1 -1
- package/dist/block_state_util.cjs.map +1 -1
- package/dist/block_state_util.d.ts +3 -3
- package/dist/block_state_util.d.ts.map +1 -1
- package/dist/block_state_util.js.map +1 -1
- package/dist/builder.cjs +157 -78
- package/dist/builder.cjs.map +1 -1
- package/dist/builder.d.ts +48 -21
- package/dist/builder.d.ts.map +1 -1
- package/dist/builder.js +157 -78
- package/dist/builder.js.map +1 -1
- package/dist/internal.cjs.map +1 -1
- package/dist/internal.d.ts +2 -2
- package/dist/internal.d.ts.map +1 -1
- package/dist/internal.js.map +1 -1
- package/dist/package.json.cjs +1 -1
- package/dist/package.json.js +1 -1
- package/dist/platforma.d.ts +5 -5
- package/dist/platforma.d.ts.map +1 -1
- package/dist/raw_globals.cjs.map +1 -1
- package/dist/raw_globals.d.ts +2 -2
- package/dist/raw_globals.d.ts.map +1 -1
- package/dist/raw_globals.js.map +1 -1
- package/package.json +7 -7
- package/src/bconfig/lambdas.ts +10 -1
- package/src/block_state_util.ts +3 -3
- package/src/builder.ts +212 -202
- package/src/internal.ts +2 -2
- package/src/platforma.ts +5 -5
- package/src/raw_globals.ts +2 -2
- package/src/typing.test.ts +7 -7
|
@@ -21,11 +21,18 @@ export type ConfigRenderLambdaFlags = {
|
|
|
21
21
|
* nobody is actively monitoring rendered values. Like file upload progress, that triggers upload itself.
|
|
22
22
|
* */
|
|
23
23
|
isActive?: boolean;
|
|
24
|
+
/**
|
|
25
|
+
* If true, result will be wrapped with additional status information,
|
|
26
|
+
* such as stability status and explicit error
|
|
27
|
+
*/
|
|
28
|
+
withStatus?: boolean;
|
|
24
29
|
};
|
|
25
30
|
/** Creates branded Cfg type */
|
|
26
|
-
export interface ConfigRenderLambda<
|
|
31
|
+
export interface ConfigRenderLambda<Return = unknown> extends ConfigRenderLambdaFlags {
|
|
27
32
|
/** Type marker */
|
|
28
33
|
__renderLambda: true;
|
|
34
|
+
/** Phantom property for type inference. Never set at runtime. */
|
|
35
|
+
__phantomReturn?: Return;
|
|
29
36
|
/** Reference to a callback registered inside the model code. */
|
|
30
37
|
handle: string;
|
|
31
38
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"lambdas.d.ts","sourceRoot":"","sources":["../../src/bconfig/lambdas.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,eAAe,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC;AAE5E,MAAM,MAAM,cAAc,CAAC,IAAI,EAAE,OAAO,GAAG,SAAS,IAAI;IACtD,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,KAAK,EAAE,IAAI,CAAC;IACrB,QAAQ,CAAC,GAAG,EAAE,OAAO,CAAC;CACvB,CAAC;AAEF,MAAM,MAAM,MAAM,CAAC,IAAI,EAAE,OAAO,GAAG,SAAS,IAAI,cAAc,CAAC,IAAI,EAAE,OAAO,CAAC,GAAG;IAC9E,QAAQ,CAAC,KAAK,EAAE,eAAe,CAAC;IAChC,QAAQ,CAAC,QAAQ,EAAE,eAAe,CAAC;CACpC,CAAC;AAEF,MAAM,MAAM,cAAc,CAAC,GAAG,SAAS,WAAW,EAAE,IAAI,EAAE,OAAO,GAAG,SAAS,IAAI,YAAY,CAC3F,GAAG,EACH,MAAM,CAAC,IAAI,EAAE,OAAO,CAAC,CACtB,CAAC;AAEF,wEAAwE;AACxE,MAAM,MAAM,uBAAuB,GAAG;IACpC;;;SAGK;IACL,SAAS,CAAC,EAAE,OAAO,CAAC;IAEpB;;;SAGK;IACL,QAAQ,CAAC,EAAE,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"lambdas.d.ts","sourceRoot":"","sources":["../../src/bconfig/lambdas.ts"],"names":[],"mappings":"AAA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AC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"block_state_util.cjs","sources":["../src/block_state_util.ts"],"sourcesContent":["import type { BlockOutputsBase,
|
|
1
|
+
{"version":3,"file":"block_state_util.cjs","sources":["../src/block_state_util.ts"],"sourcesContent":["import type { BlockOutputsBase, OutputWithStatus } from '@milaboratories/pl-model-common';\nimport type { ErrorLike } from '@milaboratories/pl-error-like';\n\nexport class OutputError extends Error {\n constructor(\n public readonly errors: ErrorLike[],\n public readonly moreErrors: boolean,\n ) {\n super(`${errors.length}${moreErrors ? '+' : ''} errors, first error: ` + errors[0].message);\n }\n}\n\nexport function readOutput<T>(outputValue: OutputWithStatus<T>): T {\n if (!outputValue.ok) throw new OutputError(outputValue.errors, outputValue.moreErrors);\n return outputValue.value;\n}\n\ntype ExtractValueType<V extends OutputWithStatus<unknown>> = Extract<V, { ok: true }>['value'];\ntype SimpleOutputs<Outputs extends BlockOutputsBase> = {\n [Key in keyof Outputs]: ExtractValueType<Outputs[Key]>;\n};\n\nexport function wrapOutputs<Outputs extends BlockOutputsBase>(\n outputs: Outputs,\n): SimpleOutputs<Outputs> {\n return new Proxy(outputs, {\n get(target, key: string) {\n return readOutput(target[key]);\n },\n }) as SimpleOutputs<Outputs>;\n}\n"],"names":[],"mappings":";;AAGM,MAAO,WAAY,SAAQ,KAAK,CAAA;AAElB,IAAA,MAAA;AACA,IAAA,UAAA;IAFlB,WAAA,CACkB,MAAmB,EACnB,UAAmB,EAAA;QAEnC,KAAK,CAAC,CAAA,EAAG,MAAM,CAAC,MAAM,GAAG,UAAU,GAAG,GAAG,GAAG,EAAE,CAAA,sBAAA,CAAwB,GAAG,MAAM,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC;QAH3E,IAAA,CAAA,MAAM,GAAN,MAAM;QACN,IAAA,CAAA,UAAU,GAAV,UAAU;IAG5B;AACD;AAEK,SAAU,UAAU,CAAI,WAAgC,EAAA;IAC5D,IAAI,CAAC,WAAW,CAAC,EAAE;QAAE,MAAM,IAAI,WAAW,CAAC,WAAW,CAAC,MAAM,EAAE,WAAW,CAAC,UAAU,CAAC;IACtF,OAAO,WAAW,CAAC,KAAK;AAC1B;AAOM,SAAU,WAAW,CACzB,OAAgB,EAAA;AAEhB,IAAA,OAAO,IAAI,KAAK,CAAC,OAAO,EAAE;QACxB,GAAG,CAAC,MAAM,EAAE,GAAW,EAAA;AACrB,YAAA,OAAO,UAAU,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;QAChC,CAAC;AACF,KAAA,CAA2B;AAC9B;;;;;;"}
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import type { BlockOutputsBase,
|
|
1
|
+
import type { BlockOutputsBase, OutputWithStatus } from '@milaboratories/pl-model-common';
|
|
2
2
|
import type { ErrorLike } from '@milaboratories/pl-error-like';
|
|
3
3
|
export declare class OutputError extends Error {
|
|
4
4
|
readonly errors: ErrorLike[];
|
|
5
5
|
readonly moreErrors: boolean;
|
|
6
6
|
constructor(errors: ErrorLike[], moreErrors: boolean);
|
|
7
7
|
}
|
|
8
|
-
export declare function readOutput<T>(outputValue:
|
|
9
|
-
type ExtractValueType<V extends
|
|
8
|
+
export declare function readOutput<T>(outputValue: OutputWithStatus<T>): T;
|
|
9
|
+
type ExtractValueType<V extends OutputWithStatus<unknown>> = Extract<V, {
|
|
10
10
|
ok: true;
|
|
11
11
|
}>['value'];
|
|
12
12
|
type SimpleOutputs<Outputs extends BlockOutputsBase> = {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"block_state_util.d.ts","sourceRoot":"","sources":["../src/block_state_util.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,
|
|
1
|
+
{"version":3,"file":"block_state_util.d.ts","sourceRoot":"","sources":["../src/block_state_util.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,MAAM,iCAAiC,CAAC;AAC1F,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,+BAA+B,CAAC;AAE/D,qBAAa,WAAY,SAAQ,KAAK;aAElB,MAAM,EAAE,SAAS,EAAE;aACnB,UAAU,EAAE,OAAO;gBADnB,MAAM,EAAE,SAAS,EAAE,EACnB,UAAU,EAAE,OAAO;CAItC;AAED,wBAAgB,UAAU,CAAC,CAAC,EAAE,WAAW,EAAE,gBAAgB,CAAC,CAAC,CAAC,GAAG,CAAC,CAGjE;AAED,KAAK,gBAAgB,CAAC,CAAC,SAAS,gBAAgB,CAAC,OAAO,CAAC,IAAI,OAAO,CAAC,CAAC,EAAE;IAAE,EAAE,EAAE,IAAI,CAAA;CAAE,CAAC,CAAC,OAAO,CAAC,CAAC;AAC/F,KAAK,aAAa,CAAC,OAAO,SAAS,gBAAgB,IAAI;KACpD,GAAG,IAAI,MAAM,OAAO,GAAG,gBAAgB,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;CACvD,CAAC;AAEF,wBAAgB,WAAW,CAAC,OAAO,SAAS,gBAAgB,EAC1D,OAAO,EAAE,OAAO,GACf,aAAa,CAAC,OAAO,CAAC,CAMxB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"block_state_util.js","sources":["../src/block_state_util.ts"],"sourcesContent":["import type { BlockOutputsBase,
|
|
1
|
+
{"version":3,"file":"block_state_util.js","sources":["../src/block_state_util.ts"],"sourcesContent":["import type { BlockOutputsBase, OutputWithStatus } from '@milaboratories/pl-model-common';\nimport type { ErrorLike } from '@milaboratories/pl-error-like';\n\nexport class OutputError extends Error {\n constructor(\n public readonly errors: ErrorLike[],\n public readonly moreErrors: boolean,\n ) {\n super(`${errors.length}${moreErrors ? '+' : ''} errors, first error: ` + errors[0].message);\n }\n}\n\nexport function readOutput<T>(outputValue: OutputWithStatus<T>): T {\n if (!outputValue.ok) throw new OutputError(outputValue.errors, outputValue.moreErrors);\n return outputValue.value;\n}\n\ntype ExtractValueType<V extends OutputWithStatus<unknown>> = Extract<V, { ok: true }>['value'];\ntype SimpleOutputs<Outputs extends BlockOutputsBase> = {\n [Key in keyof Outputs]: ExtractValueType<Outputs[Key]>;\n};\n\nexport function wrapOutputs<Outputs extends BlockOutputsBase>(\n outputs: Outputs,\n): SimpleOutputs<Outputs> {\n return new Proxy(outputs, {\n get(target, key: string) {\n return readOutput(target[key]);\n },\n }) as SimpleOutputs<Outputs>;\n}\n"],"names":[],"mappings":"AAGM,MAAO,WAAY,SAAQ,KAAK,CAAA;AAElB,IAAA,MAAA;AACA,IAAA,UAAA;IAFlB,WAAA,CACkB,MAAmB,EACnB,UAAmB,EAAA;QAEnC,KAAK,CAAC,CAAA,EAAG,MAAM,CAAC,MAAM,GAAG,UAAU,GAAG,GAAG,GAAG,EAAE,CAAA,sBAAA,CAAwB,GAAG,MAAM,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC;QAH3E,IAAA,CAAA,MAAM,GAAN,MAAM;QACN,IAAA,CAAA,UAAU,GAAV,UAAU;IAG5B;AACD;AAEK,SAAU,UAAU,CAAI,WAAgC,EAAA;IAC5D,IAAI,CAAC,WAAW,CAAC,EAAE;QAAE,MAAM,IAAI,WAAW,CAAC,WAAW,CAAC,MAAM,EAAE,WAAW,CAAC,UAAU,CAAC;IACtF,OAAO,WAAW,CAAC,KAAK;AAC1B;AAOM,SAAU,WAAW,CACzB,OAAgB,EAAA;AAEhB,IAAA,OAAO,IAAI,KAAK,CAAC,OAAO,EAAE;QACxB,GAAG,CAAC,MAAM,EAAE,GAAW,EAAA;AACrB,YAAA,OAAO,UAAU,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;QAChC,CAAC;AACF,KAAA,CAA2B;AAC9B;;;;"}
|
package/dist/builder.cjs
CHANGED
|
@@ -8,72 +8,88 @@ require('./render/util/label.cjs');
|
|
|
8
8
|
require('canonicalize');
|
|
9
9
|
var version = require('./version.cjs');
|
|
10
10
|
var normalization = require('./bconfig/normalization.cjs');
|
|
11
|
+
var types = require('./bconfig/types.cjs');
|
|
11
12
|
|
|
12
13
|
/** Main entry point that each block should use in it's "config" module. Don't forget
|
|
13
14
|
* to call {@link done()} at the end of configuration. Value returned by this builder must be
|
|
14
15
|
* exported as constant with name "platforma" from the "config" module. */
|
|
15
16
|
class BlockModel {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
this._initialArgs = _initialArgs;
|
|
28
|
-
this._initialUiState = _initialUiState;
|
|
29
|
-
this._outputs = _outputs;
|
|
30
|
-
this._inputsValid = _inputsValid;
|
|
31
|
-
this._sections = _sections;
|
|
32
|
-
this._title = _title;
|
|
33
|
-
this._enrichmentTargets = _enrichmentTargets;
|
|
34
|
-
this._featureFlags = _featureFlags;
|
|
35
|
-
}
|
|
36
|
-
static INITIAL_BLOCK_FEATURE_FLAGS = {
|
|
37
|
-
supportsLazyState: true,
|
|
38
|
-
requiresUIAPIVersion: 1,
|
|
39
|
-
requiresModelAPIVersion: 1,
|
|
40
|
-
};
|
|
17
|
+
config;
|
|
18
|
+
constructor(config) {
|
|
19
|
+
this.config = config;
|
|
20
|
+
}
|
|
21
|
+
static get INITIAL_BLOCK_FEATURE_FLAGS() {
|
|
22
|
+
return {
|
|
23
|
+
supportsLazyState: true,
|
|
24
|
+
requiresUIAPIVersion: 1,
|
|
25
|
+
requiresModelAPIVersion: 1,
|
|
26
|
+
};
|
|
27
|
+
}
|
|
41
28
|
static create(renderingMode = 'Heavy') {
|
|
42
|
-
return new BlockModel(
|
|
29
|
+
return new BlockModel({
|
|
30
|
+
renderingMode,
|
|
31
|
+
initialUiState: {},
|
|
32
|
+
outputs: {},
|
|
33
|
+
inputsValid: actions.getImmediate(true),
|
|
34
|
+
sections: actions.getImmediate([]),
|
|
35
|
+
featureFlags: BlockModel.INITIAL_BLOCK_FEATURE_FLAGS,
|
|
36
|
+
});
|
|
43
37
|
}
|
|
44
38
|
output(key, cfgOrRf, flags = {}) {
|
|
45
39
|
if (typeof cfgOrRf === 'function') {
|
|
46
40
|
const handle = `output#${key}`;
|
|
47
41
|
internal.tryRegisterCallback(handle, () => cfgOrRf(new api.RenderCtx()));
|
|
48
|
-
return new BlockModel(
|
|
49
|
-
...this.
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
42
|
+
return new BlockModel({
|
|
43
|
+
...this.config,
|
|
44
|
+
outputs: {
|
|
45
|
+
...this.config.outputs,
|
|
46
|
+
[key]: {
|
|
47
|
+
__renderLambda: true,
|
|
48
|
+
handle,
|
|
49
|
+
...flags,
|
|
50
|
+
},
|
|
54
51
|
},
|
|
55
|
-
}
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
else {
|
|
55
|
+
return new BlockModel({
|
|
56
|
+
...this.config,
|
|
57
|
+
outputs: {
|
|
58
|
+
...this.config.outputs,
|
|
59
|
+
[key]: cfgOrRf,
|
|
60
|
+
},
|
|
61
|
+
});
|
|
56
62
|
}
|
|
57
|
-
else
|
|
58
|
-
return new BlockModel(this._renderingMode, this._initialArgs, this._initialUiState, {
|
|
59
|
-
...this._outputs,
|
|
60
|
-
[key]: cfgOrRf,
|
|
61
|
-
}, this._inputsValid, this._sections, this._title, this._enrichmentTargets, this._featureFlags);
|
|
62
63
|
}
|
|
63
64
|
/** Shortcut for {@link output} with retentive flag set to true. */
|
|
64
65
|
retentiveOutput(key, rf) {
|
|
65
66
|
return this.output(key, rf, { retentive: true });
|
|
66
67
|
}
|
|
68
|
+
/** Shortcut for {@link output} with withStatus flag set to true. */
|
|
69
|
+
outputWithStatus(key, rf) {
|
|
70
|
+
return this.output(key, rf, { withStatus: true });
|
|
71
|
+
}
|
|
72
|
+
/** Shortcut for {@link output} with retentive and withStatus flags set to true. */
|
|
73
|
+
retentiveOutputWithStatus(key, rf) {
|
|
74
|
+
return this.output(key, rf, { retentive: true, withStatus: true });
|
|
75
|
+
}
|
|
67
76
|
argsValid(cfgOrRf) {
|
|
68
77
|
if (typeof cfgOrRf === 'function') {
|
|
69
78
|
internal.tryRegisterCallback('inputsValid', () => cfgOrRf(new api.RenderCtx()));
|
|
70
|
-
return new BlockModel(
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
79
|
+
return new BlockModel({
|
|
80
|
+
...this.config,
|
|
81
|
+
inputsValid: {
|
|
82
|
+
__renderLambda: true,
|
|
83
|
+
handle: 'inputsValid',
|
|
84
|
+
},
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
else {
|
|
88
|
+
return new BlockModel({
|
|
89
|
+
...this.config,
|
|
90
|
+
inputsValid: cfgOrRf,
|
|
91
|
+
});
|
|
74
92
|
}
|
|
75
|
-
else
|
|
76
|
-
return new BlockModel(this._renderingMode, this._initialArgs, this._initialUiState, this._outputs, cfgOrRf, this._sections, this._title, this._enrichmentTargets, this._featureFlags);
|
|
77
93
|
}
|
|
78
94
|
sections(arrOrCfgOrRf) {
|
|
79
95
|
if (Array.isArray(arrOrCfgOrRf)) {
|
|
@@ -81,34 +97,82 @@ class BlockModel {
|
|
|
81
97
|
}
|
|
82
98
|
else if (typeof arrOrCfgOrRf === 'function') {
|
|
83
99
|
internal.tryRegisterCallback('sections', () => arrOrCfgOrRf(new api.RenderCtx()));
|
|
84
|
-
return new BlockModel(
|
|
100
|
+
return new BlockModel({
|
|
101
|
+
...this.config,
|
|
102
|
+
sections: {
|
|
103
|
+
__renderLambda: true,
|
|
104
|
+
handle: 'sections',
|
|
105
|
+
},
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
else {
|
|
109
|
+
return new BlockModel({
|
|
110
|
+
...this.config,
|
|
111
|
+
sections: arrOrCfgOrRf,
|
|
112
|
+
});
|
|
85
113
|
}
|
|
86
|
-
else
|
|
87
|
-
return new BlockModel(this._renderingMode, this._initialArgs, this._initialUiState, this._outputs, this._inputsValid, arrOrCfgOrRf, this._title, this._enrichmentTargets, this._featureFlags);
|
|
88
114
|
}
|
|
89
115
|
/** Sets a rendering function to derive block title, shown for the block in the left blocks-overview panel. */
|
|
90
116
|
title(rf) {
|
|
91
117
|
internal.tryRegisterCallback('title', () => rf(new api.RenderCtx()));
|
|
92
|
-
return new BlockModel(
|
|
118
|
+
return new BlockModel({
|
|
119
|
+
...this.config,
|
|
120
|
+
title: {
|
|
121
|
+
__renderLambda: true,
|
|
122
|
+
handle: 'title',
|
|
123
|
+
},
|
|
124
|
+
});
|
|
125
|
+
}
|
|
126
|
+
subtitle(rf) {
|
|
127
|
+
internal.tryRegisterCallback('subtitle', () => rf(new api.RenderCtx()));
|
|
128
|
+
return new BlockModel({
|
|
129
|
+
...this.config,
|
|
130
|
+
subtitle: {
|
|
131
|
+
__renderLambda: true,
|
|
132
|
+
handle: 'subtitle',
|
|
133
|
+
},
|
|
134
|
+
});
|
|
135
|
+
}
|
|
136
|
+
tags(rf) {
|
|
137
|
+
internal.tryRegisterCallback('tags', () => rf(new api.RenderCtx()));
|
|
138
|
+
return new BlockModel({
|
|
139
|
+
...this.config,
|
|
140
|
+
tags: {
|
|
141
|
+
__renderLambda: true,
|
|
142
|
+
handle: 'tags',
|
|
143
|
+
},
|
|
144
|
+
});
|
|
93
145
|
}
|
|
94
146
|
/**
|
|
95
147
|
* Sets initial args for the block, this value must be specified.
|
|
96
148
|
* @deprecated use {@link withArgs}
|
|
97
149
|
* */
|
|
98
150
|
initialArgs(value) {
|
|
99
|
-
return
|
|
151
|
+
return this.withArgs(value);
|
|
100
152
|
}
|
|
101
153
|
/** Sets initial args for the block, this value must be specified. */
|
|
102
|
-
withArgs(
|
|
103
|
-
return new BlockModel(
|
|
154
|
+
withArgs(initialArgs) {
|
|
155
|
+
return new BlockModel({
|
|
156
|
+
...this.config,
|
|
157
|
+
initialArgs,
|
|
158
|
+
});
|
|
104
159
|
}
|
|
105
160
|
/** Defines type and sets initial value for block UiState. */
|
|
106
|
-
withUiState(
|
|
107
|
-
return new BlockModel(
|
|
161
|
+
withUiState(initialUiState) {
|
|
162
|
+
return new BlockModel({
|
|
163
|
+
...this.config,
|
|
164
|
+
initialUiState,
|
|
165
|
+
});
|
|
108
166
|
}
|
|
109
167
|
/** Sets or overrides feature flags for the block. */
|
|
110
168
|
withFeatureFlags(flags) {
|
|
111
|
-
return new BlockModel(
|
|
169
|
+
return new BlockModel({
|
|
170
|
+
...this.config,
|
|
171
|
+
featureFlags: {
|
|
172
|
+
...this.config.featureFlags,
|
|
173
|
+
...flags,
|
|
174
|
+
},
|
|
175
|
+
});
|
|
112
176
|
}
|
|
113
177
|
/**
|
|
114
178
|
* Defines how to derive list of upstream references this block is meant to enrich with its exports from block args.
|
|
@@ -116,49 +180,64 @@ class BlockModel {
|
|
|
116
180
|
*/
|
|
117
181
|
enriches(lambda) {
|
|
118
182
|
internal.tryRegisterCallback('enrichmentTargets', lambda);
|
|
119
|
-
return new BlockModel(
|
|
183
|
+
return new BlockModel({
|
|
184
|
+
...this.config,
|
|
185
|
+
enrichmentTargets: {
|
|
186
|
+
__renderLambda: true,
|
|
187
|
+
handle: 'enrichmentTargets',
|
|
188
|
+
},
|
|
189
|
+
});
|
|
120
190
|
}
|
|
121
191
|
/** Renders all provided block settings into a pre-configured platforma API
|
|
122
192
|
* instance, that can be used in frontend to interact with block state, and
|
|
123
193
|
* other features provided by the platforma to the block. */
|
|
124
|
-
done(apiVersion) {
|
|
125
|
-
const requiresUIAPIVersion = apiVersion ?? 1;
|
|
194
|
+
done(apiVersion = 1) {
|
|
126
195
|
return this.withFeatureFlags({
|
|
127
|
-
...this.
|
|
128
|
-
requiresUIAPIVersion,
|
|
129
|
-
})
|
|
196
|
+
...this.config.featureFlags,
|
|
197
|
+
requiresUIAPIVersion: apiVersion,
|
|
198
|
+
}).#done();
|
|
130
199
|
}
|
|
131
|
-
|
|
132
|
-
if (this.
|
|
200
|
+
#done() {
|
|
201
|
+
if (this.config.initialArgs === undefined)
|
|
133
202
|
throw new Error('Initial arguments not set.');
|
|
134
203
|
const config = {
|
|
135
204
|
v3: {
|
|
136
205
|
sdkVersion: version.PlatformaSDKVersion,
|
|
137
|
-
renderingMode: this.
|
|
138
|
-
initialArgs: this.
|
|
139
|
-
initialUiState: this.
|
|
140
|
-
inputsValid: this.
|
|
141
|
-
sections: this.
|
|
142
|
-
title: this.
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
206
|
+
renderingMode: this.config.renderingMode,
|
|
207
|
+
initialArgs: this.config.initialArgs,
|
|
208
|
+
initialUiState: this.config.initialUiState,
|
|
209
|
+
inputsValid: this.config.inputsValid,
|
|
210
|
+
sections: this.config.sections,
|
|
211
|
+
title: this.config.title,
|
|
212
|
+
subtitle: this.config.subtitle,
|
|
213
|
+
tags: this.config.tags,
|
|
214
|
+
outputs: this.config.outputs,
|
|
215
|
+
enrichmentTargets: this.config.enrichmentTargets,
|
|
216
|
+
featureFlags: this.config.featureFlags,
|
|
146
217
|
},
|
|
147
218
|
// fields below are added to allow previous desktop versions read generated configs
|
|
148
219
|
sdkVersion: version.PlatformaSDKVersion,
|
|
149
|
-
renderingMode: this.
|
|
150
|
-
initialArgs: this.
|
|
151
|
-
inputsValid: normalization.downgradeCfgOrLambda(this.
|
|
152
|
-
sections: normalization.downgradeCfgOrLambda(this.
|
|
153
|
-
outputs: Object.fromEntries(Object.entries(this.
|
|
220
|
+
renderingMode: this.config.renderingMode,
|
|
221
|
+
initialArgs: this.config.initialArgs,
|
|
222
|
+
inputsValid: normalization.downgradeCfgOrLambda(this.config.inputsValid),
|
|
223
|
+
sections: normalization.downgradeCfgOrLambda(this.config.sections),
|
|
224
|
+
outputs: Object.fromEntries(Object.entries(this.config.outputs).map(([key, value]) => [key, normalization.downgradeCfgOrLambda(value)])),
|
|
154
225
|
};
|
|
155
|
-
globalThis.platformaApiVersion =
|
|
226
|
+
globalThis.platformaApiVersion = this.config.featureFlags.requiresUIAPIVersion;
|
|
156
227
|
if (!internal.isInUI())
|
|
157
228
|
// we are in the configuration rendering routine, not in actual UI
|
|
158
229
|
return { config };
|
|
159
230
|
// normal operation inside the UI
|
|
160
231
|
else
|
|
161
|
-
return
|
|
232
|
+
return {
|
|
233
|
+
...internal.getPlatformaInstance({ sdkVersion: version.PlatformaSDKVersion, apiVersion: platformaApiVersion }),
|
|
234
|
+
blockModelInfo: {
|
|
235
|
+
outputs: Object.fromEntries(Object.entries(this.config.outputs)
|
|
236
|
+
.map(([key, value]) => [key, {
|
|
237
|
+
withStatus: Boolean(types.isConfigLambda(value) && value.withStatus),
|
|
238
|
+
}])),
|
|
239
|
+
},
|
|
240
|
+
};
|
|
162
241
|
}
|
|
163
242
|
}
|
|
164
243
|
|
package/dist/builder.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"builder.cjs","sources":["../src/builder.ts"],"sourcesContent":["import type { BlockRenderingMode, BlockSection, ValueOrErrors, AnyFunction, PlRef, BlockCodeKnownFeatureFlags, BlockConfigContainer } from '@milaboratories/pl-model-common';\nimport type { Checked, ConfigResult, TypedConfig } from './config';\nimport { getImmediate } from './config';\nimport { getPlatformaInstance, isInUI, tryRegisterCallback } from './internal';\nimport type { Platforma, PlatformaApiVersion, PlatformaV1, PlatformaV2 } from './platforma';\nimport type { InferRenderFunctionReturn, RenderFunction } from './render';\nimport { RenderCtx } from './render';\nimport { PlatformaSDKVersion } from './version';\nimport type {\n TypedConfigOrConfigLambda,\n ConfigRenderLambda,\n StdCtxArgsOnly,\n DeriveHref,\n ResolveCfgType,\n ExtractFunctionHandleReturn,\n ConfigRenderLambdaFlags,\n} from './bconfig';\nimport {\n downgradeCfgOrLambda,\n} from './bconfig';\n\ntype SectionsExpectedType = readonly BlockSection[];\n\ntype SectionsCfgChecked<Cfg extends TypedConfig, Args, UiState> = Checked<\n Cfg,\n ConfigResult<Cfg, StdCtxArgsOnly<Args, UiState>> extends SectionsExpectedType ? true : false\n>;\n\n// TODO (Unused type in code)\n// type SectionsRFChecked<RF extends Function> = Checked<\n// RF,\n// InferRenderFunctionReturn<RF> extends SectionsExpectedType ? true : false\n// >;\n\ntype InputsValidExpectedType = boolean;\n\ntype InputsValidCfgChecked<Cfg extends TypedConfig, Args, UiState> = Checked<\n Cfg,\n ConfigResult<Cfg, StdCtxArgsOnly<Args, UiState>> extends InputsValidExpectedType ? true : false\n>;\n\n// TODO (Unused type in code)\n// type InputsValidRFChecked<RF extends Function> = Checked<\n// RF,\n// InferRenderFunctionReturn<RF> extends InputsValidExpectedType ? true : false\n// >;\n\ntype NoOb = Record<string, never>;\n\n/** Main entry point that each block should use in it's \"config\" module. Don't forget\n * to call {@link done()} at the end of configuration. Value returned by this builder must be\n * exported as constant with name \"platforma\" from the \"config\" module. */\nexport class BlockModel<\n Args,\n OutputsCfg extends Record<string, TypedConfigOrConfigLambda>,\n UiState,\n Href extends `/${string}` = '/',\n> {\n private constructor(\n private readonly _renderingMode: BlockRenderingMode,\n private readonly _initialArgs: Args | undefined,\n private readonly _initialUiState: UiState,\n private readonly _outputs: OutputsCfg,\n private readonly _inputsValid: TypedConfigOrConfigLambda,\n private readonly _sections: TypedConfigOrConfigLambda,\n private readonly _title: ConfigRenderLambda | undefined,\n private readonly _enrichmentTargets: ConfigRenderLambda | undefined,\n private readonly _featureFlags: BlockCodeKnownFeatureFlags,\n ) {}\n\n public static readonly INITIAL_BLOCK_FEATURE_FLAGS: BlockCodeKnownFeatureFlags = {\n supportsLazyState: true,\n requiresUIAPIVersion: 1,\n requiresModelAPIVersion: 1,\n };\n\n /** Initiates configuration builder */\n public static create(renderingMode: BlockRenderingMode): BlockModel<NoOb, {}, NoOb>;\n /** Initiates configuration builder */\n public static create(): BlockModel<NoOb, {}, NoOb>;\n /**\n * Initiates configuration builder\n * @deprecated use create method without generic parameter\n */\n public static create<Args>(renderingMode: BlockRenderingMode): BlockModel<Args, {}, NoOb>;\n /**\n * Initiates configuration builder\n * @deprecated use create method without generic parameter\n */\n public static create<Args>(): BlockModel<Args, {}, NoOb>;\n public static create(renderingMode: BlockRenderingMode = 'Heavy'): BlockModel<NoOb, {}, NoOb> {\n return new BlockModel<NoOb, {}, NoOb>(\n renderingMode,\n undefined,\n {},\n {},\n getImmediate(true),\n getImmediate([]),\n undefined,\n undefined,\n { ...BlockModel.INITIAL_BLOCK_FEATURE_FLAGS },\n );\n }\n\n /**\n * Add output cell to the configuration\n *\n * @param key output cell name, that can be later used to retrieve the rendered value\n * @param cfg configuration describing how to render cell value from the blocks\n * workflow outputs\n * @deprecated use lambda-based API\n * */\n public output<const Key extends string, const Cfg extends TypedConfig>(\n key: Key,\n cfg: Cfg\n ): BlockModel<Args, OutputsCfg & { [K in Key]: Cfg }, UiState, Href>;\n /**\n * Add output cell to the configuration\n *\n * @param key output cell name, that can be later used to retrieve the rendered value\n * @param rf callback calculating output value using context, that allows to access\n * workflows outputs and interact with platforma drivers\n * @param flags additional flags that may alter lambda rendering procedure\n * */\n public output<const Key extends string, const RF extends RenderFunction<Args, UiState>>(\n key: Key,\n rf: RF,\n flags?: ConfigRenderLambdaFlags\n ): BlockModel<\n Args,\n OutputsCfg & { [K in Key]: ConfigRenderLambda<InferRenderFunctionReturn<RF>> },\n UiState,\n Href\n >;\n public output(\n key: string,\n cfgOrRf: TypedConfig | AnyFunction,\n flags: ConfigRenderLambdaFlags = {},\n ): BlockModel<Args, OutputsCfg, UiState, Href> {\n if (typeof cfgOrRf === 'function') {\n const handle = `output#${key}`;\n tryRegisterCallback(handle, () => cfgOrRf(new RenderCtx()));\n return new BlockModel(\n this._renderingMode,\n this._initialArgs,\n this._initialUiState,\n {\n ...this._outputs,\n [key]: {\n __renderLambda: true,\n handle,\n ...flags,\n } satisfies ConfigRenderLambda,\n },\n this._inputsValid,\n this._sections,\n this._title,\n this._enrichmentTargets,\n this._featureFlags,\n );\n } else\n return new BlockModel(\n this._renderingMode,\n this._initialArgs,\n this._initialUiState,\n {\n ...this._outputs,\n [key]: cfgOrRf,\n },\n this._inputsValid,\n this._sections,\n this._title,\n this._enrichmentTargets,\n this._featureFlags,\n );\n }\n\n /** Shortcut for {@link output} with retentive flag set to true. */\n public retentiveOutput<const Key extends string, const RF extends RenderFunction<Args, UiState>>(\n key: Key,\n rf: RF,\n ): BlockModel<\n Args,\n OutputsCfg & { [K in Key]: ConfigRenderLambda<InferRenderFunctionReturn<RF>> },\n UiState,\n Href\n > {\n return this.output(key, rf, { retentive: true });\n }\n\n /** Sets custom configuration predicate on the block args at which block can be executed\n * @deprecated use lambda-based API */\n public argsValid<Cfg extends TypedConfig>(\n cfg: Cfg & InputsValidCfgChecked<Cfg, Args, UiState>\n ): BlockModel<Args, OutputsCfg, UiState, Href>;\n /** Sets custom configuration predicate on the block args at which block can be executed */\n public argsValid<RF extends RenderFunction<Args, UiState, boolean>>(\n rf: RF\n ): BlockModel<Args, OutputsCfg, UiState, Href>;\n public argsValid(\n cfgOrRf: TypedConfig | AnyFunction,\n ): BlockModel<Args, OutputsCfg, UiState, `/${string}`> {\n if (typeof cfgOrRf === 'function') {\n tryRegisterCallback('inputsValid', () => cfgOrRf(new RenderCtx()));\n return new BlockModel<Args, OutputsCfg, UiState>(\n this._renderingMode,\n this._initialArgs,\n this._initialUiState,\n this._outputs,\n {\n __renderLambda: true,\n handle: 'inputsValid',\n } satisfies ConfigRenderLambda,\n this._sections,\n this._title,\n this._enrichmentTargets,\n this._featureFlags,\n );\n } else\n return new BlockModel<Args, OutputsCfg, UiState>(\n this._renderingMode,\n this._initialArgs,\n this._initialUiState,\n this._outputs,\n cfgOrRf,\n this._sections,\n this._title,\n this._enrichmentTargets,\n this._featureFlags,\n );\n }\n\n /** Sets the config to generate list of section in the left block overviews panel\n * @deprecated use lambda-based API */\n public sections<const S extends SectionsExpectedType>(\n rf: S\n ): BlockModel<Args, OutputsCfg, UiState, DeriveHref<S>>;\n /** Sets the config to generate list of section in the left block overviews panel */\n public sections<\n const Ret extends SectionsExpectedType,\n const RF extends RenderFunction<Args, UiState, Ret>,\n >(rf: RF): BlockModel<Args, OutputsCfg, UiState, DeriveHref<ReturnType<RF>>>;\n public sections<const Cfg extends TypedConfig>(\n cfg: Cfg & SectionsCfgChecked<Cfg, Args, UiState>\n ): BlockModel<\n Args,\n OutputsCfg,\n UiState,\n DeriveHref<ConfigResult<Cfg, StdCtxArgsOnly<Args, UiState>>>\n >;\n public sections(\n arrOrCfgOrRf: SectionsExpectedType | TypedConfig | AnyFunction,\n ): BlockModel<Args, OutputsCfg, UiState, `/${string}`> {\n if (Array.isArray(arrOrCfgOrRf)) {\n return this.sections(getImmediate(arrOrCfgOrRf));\n } else if (typeof arrOrCfgOrRf === 'function') {\n tryRegisterCallback('sections', () => arrOrCfgOrRf(new RenderCtx()));\n return new BlockModel<Args, OutputsCfg, UiState>(\n this._renderingMode,\n this._initialArgs,\n this._initialUiState,\n this._outputs,\n this._inputsValid,\n { __renderLambda: true, handle: 'sections' } as ConfigRenderLambda,\n this._title,\n this._enrichmentTargets,\n this._featureFlags,\n );\n } else\n return new BlockModel<Args, OutputsCfg, UiState>(\n this._renderingMode,\n this._initialArgs,\n this._initialUiState,\n this._outputs,\n this._inputsValid,\n arrOrCfgOrRf as TypedConfig,\n this._title,\n this._enrichmentTargets,\n this._featureFlags,\n );\n }\n\n /** Sets a rendering function to derive block title, shown for the block in the left blocks-overview panel. */\n public title(\n rf: RenderFunction<Args, UiState, string>,\n ): BlockModel<Args, OutputsCfg, UiState, Href> {\n tryRegisterCallback('title', () => rf(new RenderCtx()));\n return new BlockModel<Args, OutputsCfg, UiState, Href>(\n this._renderingMode,\n this._initialArgs,\n this._initialUiState,\n this._outputs,\n this._inputsValid,\n this._sections,\n { __renderLambda: true, handle: 'title' } as ConfigRenderLambda,\n this._enrichmentTargets,\n this._featureFlags,\n );\n }\n\n /**\n * Sets initial args for the block, this value must be specified.\n * @deprecated use {@link withArgs}\n * */\n public initialArgs(value: Args): BlockModel<Args, OutputsCfg, UiState, Href> {\n return new BlockModel<Args, OutputsCfg, UiState, Href>(\n this._renderingMode,\n value,\n this._initialUiState,\n this._outputs,\n this._inputsValid,\n this._sections,\n this._title,\n this._enrichmentTargets,\n this._featureFlags,\n );\n }\n\n /** Sets initial args for the block, this value must be specified. */\n public withArgs<Args>(initialValue: Args): BlockModel<Args, OutputsCfg, UiState, Href> {\n return new BlockModel<Args, OutputsCfg, UiState, Href>(\n this._renderingMode,\n initialValue,\n this._initialUiState,\n this._outputs,\n this._inputsValid,\n this._sections,\n this._title,\n this._enrichmentTargets,\n this._featureFlags,\n );\n }\n\n /** Defines type and sets initial value for block UiState. */\n public withUiState<UiState>(initialValue: UiState): BlockModel<Args, OutputsCfg, UiState, Href> {\n return new BlockModel<Args, OutputsCfg, UiState, Href>(\n this._renderingMode,\n this._initialArgs,\n initialValue,\n this._outputs,\n this._inputsValid,\n this._sections,\n this._title,\n this._enrichmentTargets,\n this._featureFlags,\n );\n }\n\n /** Sets or overrides feature flags for the block. */\n public withFeatureFlags(flags: Partial<BlockCodeKnownFeatureFlags>): BlockModel<Args, OutputsCfg, UiState, Href> {\n return new BlockModel<Args, OutputsCfg, UiState, Href>(\n this._renderingMode,\n this._initialArgs,\n this._initialUiState,\n this._outputs,\n this._inputsValid,\n this._sections,\n this._title,\n this._enrichmentTargets,\n { ...this._featureFlags, ...flags },\n );\n }\n\n /**\n * Defines how to derive list of upstream references this block is meant to enrich with its exports from block args.\n * Influences dependency graph construction.\n */\n public enriches(\n lambda: (args: Args) => PlRef[],\n ): BlockModel<Args, OutputsCfg, UiState, Href> {\n tryRegisterCallback('enrichmentTargets', lambda);\n return new BlockModel<Args, OutputsCfg, UiState, Href>(\n this._renderingMode,\n this._initialArgs,\n this._initialUiState,\n this._outputs,\n this._inputsValid,\n this._sections,\n this._title,\n { __renderLambda: true, handle: 'enrichmentTargets' } as ConfigRenderLambda,\n this._featureFlags,\n );\n }\n\n public done(apiVersion?: 1): PlatformaV1<\n Args,\n InferOutputsFromConfigs<Args, OutputsCfg, UiState>,\n UiState,\n Href\n >;\n\n public done(apiVersion: 2): PlatformaV2<\n Args,\n InferOutputsFromConfigs<Args, OutputsCfg, UiState>,\n UiState,\n Href\n >;\n\n /** Renders all provided block settings into a pre-configured platforma API\n * instance, that can be used in frontend to interact with block state, and\n * other features provided by the platforma to the block. */\n public done(apiVersion?: PlatformaApiVersion): Platforma<\n Args,\n InferOutputsFromConfigs<Args, OutputsCfg, UiState>,\n UiState,\n Href\n > {\n const requiresUIAPIVersion = apiVersion ?? 1;\n return this.withFeatureFlags({\n ...this._featureFlags,\n requiresUIAPIVersion,\n })._done(requiresUIAPIVersion);\n }\n\n public _done(apiVersion: PlatformaApiVersion): Platforma<\n Args,\n InferOutputsFromConfigs<Args, OutputsCfg, UiState>,\n UiState,\n Href\n > {\n if (this._initialArgs === undefined) throw new Error('Initial arguments not set.');\n\n const config: BlockConfigContainer = {\n v3: {\n sdkVersion: PlatformaSDKVersion,\n renderingMode: this._renderingMode,\n initialArgs: this._initialArgs,\n initialUiState: this._initialUiState,\n inputsValid: this._inputsValid,\n sections: this._sections,\n title: this._title,\n outputs: this._outputs,\n enrichmentTargets: this._enrichmentTargets,\n featureFlags: this._featureFlags,\n },\n\n // fields below are added to allow previous desktop versions read generated configs\n sdkVersion: PlatformaSDKVersion,\n renderingMode: this._renderingMode,\n initialArgs: this._initialArgs,\n inputsValid: downgradeCfgOrLambda(this._inputsValid),\n sections: downgradeCfgOrLambda(this._sections),\n outputs: Object.fromEntries(\n Object.entries(this._outputs).map(([key, value]) => [key, downgradeCfgOrLambda(value)]),\n ),\n };\n\n globalThis.platformaApiVersion = apiVersion;\n\n if (!isInUI())\n // we are in the configuration rendering routine, not in actual UI\n return { config } as any;\n // normal operation inside the UI\n else return getPlatformaInstance({ sdkVersion: PlatformaSDKVersion, apiVersion: platformaApiVersion }) as any;\n }\n}\n\nexport type InferOutputType<CfgOrFH, Args, UiState> = CfgOrFH extends TypedConfig\n ? ResolveCfgType<CfgOrFH, Args, UiState>\n : CfgOrFH extends ConfigRenderLambda\n ? ExtractFunctionHandleReturn<CfgOrFH>\n : never;\n\ntype InferOutputsFromConfigs<\n Args,\n OutputsCfg extends Record<string, TypedConfigOrConfigLambda>,\n UiState,\n> = {\n [Key in keyof OutputsCfg]: ValueOrErrors<InferOutputType<OutputsCfg[Key], Args, UiState>>;\n};\n"],"names":["getImmediate","tryRegisterCallback","RenderCtx","PlatformaSDKVersion","downgradeCfgOrLambda","isInUI","getPlatformaInstance"],"mappings":";;;;;;;;;;;AAiDA;;AAE0E;MAC7D,UAAU,CAAA;AAOF,IAAA,cAAA;AACA,IAAA,YAAA;AACA,IAAA,eAAA;AACA,IAAA,QAAA;AACA,IAAA,YAAA;AACA,IAAA,SAAA;AACA,IAAA,MAAA;AACA,IAAA,kBAAA;AACA,IAAA,aAAA;AATnB,IAAA,WAAA,CACmB,cAAkC,EAClC,YAA8B,EAC9B,eAAwB,EACxB,QAAoB,EACpB,YAAuC,EACvC,SAAoC,EACpC,MAAsC,EACtC,kBAAkD,EAClD,aAAyC,EAAA;QARzC,IAAA,CAAA,cAAc,GAAd,cAAc;QACd,IAAA,CAAA,YAAY,GAAZ,YAAY;QACZ,IAAA,CAAA,eAAe,GAAf,eAAe;QACf,IAAA,CAAA,QAAQ,GAAR,QAAQ;QACR,IAAA,CAAA,YAAY,GAAZ,YAAY;QACZ,IAAA,CAAA,SAAS,GAAT,SAAS;QACT,IAAA,CAAA,MAAM,GAAN,MAAM;QACN,IAAA,CAAA,kBAAkB,GAAlB,kBAAkB;QAClB,IAAA,CAAA,aAAa,GAAb,aAAa;IAC7B;IAEI,OAAgB,2BAA2B,GAA+B;AAC/E,QAAA,iBAAiB,EAAE,IAAI;AACvB,QAAA,oBAAoB,EAAE,CAAC;AACvB,QAAA,uBAAuB,EAAE,CAAC;KAC3B;AAgBM,IAAA,OAAO,MAAM,CAAC,aAAA,GAAoC,OAAO,EAAA;AAC9D,QAAA,OAAO,IAAI,UAAU,CACnB,aAAa,EACb,SAAS,EACT,EAAE,EACF,EAAE,EACFA,oBAAY,CAAC,IAAI,CAAC,EAClBA,oBAAY,CAAC,EAAE,CAAC,EAChB,S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,MAAM,EAAS;;;AAErB,YAAA,OAAOC,6BAAoB,CAAC,EAAE,UAAU,EAAEH,2BAAmB,EAAE,UAAU,EAAE,mBAAmB,EAAE,CAAQ;IAC/G;;;;;"}
|
|
1
|
+
{"version":3,"file":"builder.cjs","sources":["../src/builder.ts"],"sourcesContent":["import type { BlockRenderingMode, BlockSection, AnyFunction, PlRef, BlockCodeKnownFeatureFlags, BlockConfigContainer, OutputWithStatus } from '@milaboratories/pl-model-common';\nimport type { Checked, ConfigResult, TypedConfig } from './config';\nimport { getImmediate } from './config';\nimport { getPlatformaInstance, isInUI, tryRegisterCallback } from './internal';\nimport type { Platforma, PlatformaApiVersion, PlatformaV1, PlatformaV2 } from './platforma';\nimport type { InferRenderFunctionReturn, RenderFunction } from './render';\nimport { RenderCtx } from './render';\nimport { PlatformaSDKVersion } from './version';\nimport type {\n TypedConfigOrConfigLambda,\n ConfigRenderLambda,\n StdCtxArgsOnly,\n DeriveHref,\n ResolveCfgType,\n ExtractFunctionHandleReturn,\n ConfigRenderLambdaFlags,\n} from './bconfig';\nimport {\n downgradeCfgOrLambda,\n isConfigLambda,\n} from './bconfig';\n\ntype SectionsExpectedType = readonly BlockSection[];\n\ntype SectionsCfgChecked<Cfg extends TypedConfig, Args, UiState> = Checked<\n Cfg,\n ConfigResult<Cfg, StdCtxArgsOnly<Args, UiState>> extends SectionsExpectedType ? true : false\n>;\n\n// TODO (Unused type in code)\n// type SectionsRFChecked<RF extends Function> = Checked<\n// RF,\n// InferRenderFunctionReturn<RF> extends SectionsExpectedType ? true : false\n// >;\n\ntype InputsValidExpectedType = boolean;\n\ntype InputsValidCfgChecked<Cfg extends TypedConfig, Args, UiState> = Checked<\n Cfg,\n ConfigResult<Cfg, StdCtxArgsOnly<Args, UiState>> extends InputsValidExpectedType ? true : false\n>;\n\n// TODO (Unused type in code)\n// type InputsValidRFChecked<RF extends Function> = Checked<\n// RF,\n// InferRenderFunctionReturn<RF> extends InputsValidExpectedType ? true : false\n// >;\n\ntype NoOb = Record<string, never>;\n\n/** Main entry point that each block should use in it's \"config\" module. Don't forget\n * to call {@link done()} at the end of configuration. Value returned by this builder must be\n * exported as constant with name \"platforma\" from the \"config\" module. */\nexport class BlockModel<\n Args,\n OutputsCfg extends Record<string, TypedConfigOrConfigLambda>,\n UiState,\n Href extends `/${string}` = '/',\n> {\n private constructor(\n private config: {\n readonly renderingMode: BlockRenderingMode;\n readonly initialArgs?: Args;\n readonly initialUiState: UiState;\n readonly outputs: OutputsCfg;\n readonly inputsValid: TypedConfigOrConfigLambda;\n readonly sections: TypedConfigOrConfigLambda;\n readonly title?: ConfigRenderLambda;\n readonly subtitle?: ConfigRenderLambda;\n readonly tags?: ConfigRenderLambda;\n readonly enrichmentTargets?: ConfigRenderLambda;\n readonly featureFlags: BlockCodeKnownFeatureFlags;\n },\n ) {}\n\n public static get INITIAL_BLOCK_FEATURE_FLAGS(): BlockCodeKnownFeatureFlags {\n return {\n supportsLazyState: true,\n requiresUIAPIVersion: 1,\n requiresModelAPIVersion: 1,\n };\n }\n\n /** Initiates configuration builder */\n public static create(renderingMode: BlockRenderingMode): BlockModel<NoOb, {}, NoOb>;\n /** Initiates configuration builder */\n public static create(): BlockModel<NoOb, {}, NoOb>;\n /**\n * Initiates configuration builder\n * @deprecated use create method without generic parameter\n */\n public static create<Args>(renderingMode: BlockRenderingMode): BlockModel<Args, {}, NoOb>;\n /**\n * Initiates configuration builder\n * @deprecated use create method without generic parameter\n */\n public static create<Args>(): BlockModel<Args, {}, NoOb>;\n public static create(renderingMode: BlockRenderingMode = 'Heavy'): BlockModel<NoOb, {}, NoOb> {\n return new BlockModel<NoOb, {}, NoOb>({\n renderingMode,\n initialUiState: {},\n outputs: {},\n inputsValid: getImmediate(true),\n sections: getImmediate([]),\n featureFlags: BlockModel.INITIAL_BLOCK_FEATURE_FLAGS,\n });\n }\n\n /**\n * Add output cell to the configuration\n *\n * @param key output cell name, that can be later used to retrieve the rendered value\n * @param cfg configuration describing how to render cell value from the blocks\n * workflow outputs\n * @deprecated use lambda-based API\n * */\n public output<const Key extends string, const Cfg extends TypedConfig>(\n key: Key,\n cfg: Cfg\n ): BlockModel<Args, OutputsCfg & { [K in Key]: Cfg }, UiState, Href>;\n /**\n * Add output cell wrapped with additional status information to the configuration\n *\n * @param key output cell name, that can be later used to retrieve the rendered value\n * @param rf callback calculating output value using context, that allows to access\n * workflows outputs and interact with platforma drivers\n * @param flags additional flags that may alter lambda rendering procedure\n * */\n public output<const Key extends string, const RF extends RenderFunction<Args, UiState>>(\n key: Key,\n rf: RF,\n flags: ConfigRenderLambdaFlags & { withStatus: true }\n ): BlockModel<\n Args,\n OutputsCfg & { [K in Key]: ConfigRenderLambda<InferRenderFunctionReturn<RF>> & { withStatus: true } },\n UiState,\n Href\n >;\n /**\n * Add output cell to the configuration\n *\n * @param key output cell name, that can be later used to retrieve the rendered value\n * @param rf callback calculating output value using context, that allows to access\n * workflows outputs and interact with platforma drivers\n * @param flags additional flags that may alter lambda rendering procedure\n * */\n public output<const Key extends string, const RF extends RenderFunction<Args, UiState>>(\n key: Key,\n rf: RF,\n flags?: ConfigRenderLambdaFlags\n ): BlockModel<\n Args,\n OutputsCfg & { [K in Key]: ConfigRenderLambda<InferRenderFunctionReturn<RF>> },\n UiState,\n Href\n >;\n public output(\n key: string,\n cfgOrRf: TypedConfig | AnyFunction,\n flags: ConfigRenderLambdaFlags = {},\n ): BlockModel<Args, OutputsCfg, UiState, Href> {\n if (typeof cfgOrRf === 'function') {\n const handle = `output#${key}`;\n tryRegisterCallback(handle, () => cfgOrRf(new RenderCtx()));\n return new BlockModel({\n ...this.config,\n outputs: {\n ...this.config.outputs,\n [key]: {\n __renderLambda: true,\n handle,\n ...flags,\n },\n },\n });\n } else {\n return new BlockModel({\n ...this.config,\n outputs: {\n ...this.config.outputs,\n [key]: cfgOrRf,\n },\n });\n }\n }\n\n /** Shortcut for {@link output} with retentive flag set to true. */\n public retentiveOutput<const Key extends string, const RF extends RenderFunction<Args, UiState>>(\n key: Key,\n rf: RF,\n ) {\n return this.output(key, rf, { retentive: true });\n }\n\n /** Shortcut for {@link output} with withStatus flag set to true. */\n public outputWithStatus<const Key extends string, const RF extends RenderFunction<Args, UiState>>(\n key: Key,\n rf: RF,\n ) {\n return this.output(key, rf, { withStatus: true });\n }\n\n /** Shortcut for {@link output} with retentive and withStatus flags set to true. */\n public retentiveOutputWithStatus<const Key extends string, const RF extends RenderFunction<Args, UiState>>(\n key: Key,\n rf: RF,\n ) {\n return this.output(key, rf, { retentive: true, withStatus: true });\n }\n\n /** Sets custom configuration predicate on the block args at which block can be executed\n * @deprecated use lambda-based API */\n public argsValid<Cfg extends TypedConfig>(\n cfg: Cfg & InputsValidCfgChecked<Cfg, Args, UiState>\n ): BlockModel<Args, OutputsCfg, UiState, Href>;\n /** Sets custom configuration predicate on the block args at which block can be executed */\n public argsValid<RF extends RenderFunction<Args, UiState, boolean>>(\n rf: RF\n ): BlockModel<Args, OutputsCfg, UiState, Href>;\n public argsValid(\n cfgOrRf: TypedConfig | AnyFunction,\n ): BlockModel<Args, OutputsCfg, UiState, `/${string}`> {\n if (typeof cfgOrRf === 'function') {\n tryRegisterCallback('inputsValid', () => cfgOrRf(new RenderCtx()));\n return new BlockModel<Args, OutputsCfg, UiState>({\n ...this.config,\n inputsValid: {\n __renderLambda: true,\n handle: 'inputsValid',\n },\n });\n } else {\n return new BlockModel<Args, OutputsCfg, UiState>({\n ...this.config,\n inputsValid: cfgOrRf,\n });\n }\n }\n\n /** Sets the config to generate list of section in the left block overviews panel\n * @deprecated use lambda-based API */\n public sections<const S extends SectionsExpectedType>(\n rf: S\n ): BlockModel<Args, OutputsCfg, UiState, DeriveHref<S>>;\n /** Sets the config to generate list of section in the left block overviews panel */\n public sections<\n const Ret extends SectionsExpectedType,\n const RF extends RenderFunction<Args, UiState, Ret>,\n >(rf: RF): BlockModel<Args, OutputsCfg, UiState, DeriveHref<ReturnType<RF>>>;\n public sections<const Cfg extends TypedConfig>(\n cfg: Cfg & SectionsCfgChecked<Cfg, Args, UiState>\n ): BlockModel<\n Args,\n OutputsCfg,\n UiState,\n DeriveHref<ConfigResult<Cfg, StdCtxArgsOnly<Args, UiState>>>\n >;\n public sections(\n arrOrCfgOrRf: SectionsExpectedType | TypedConfig | AnyFunction,\n ): BlockModel<Args, OutputsCfg, UiState, `/${string}`> {\n if (Array.isArray(arrOrCfgOrRf)) {\n return this.sections(getImmediate(arrOrCfgOrRf));\n } else if (typeof arrOrCfgOrRf === 'function') {\n tryRegisterCallback('sections', () => arrOrCfgOrRf(new RenderCtx()));\n return new BlockModel<Args, OutputsCfg, UiState>({\n ...this.config,\n sections: {\n __renderLambda: true,\n handle: 'sections',\n },\n });\n } else {\n return new BlockModel<Args, OutputsCfg, UiState>({\n ...this.config,\n sections: arrOrCfgOrRf as TypedConfig,\n });\n }\n }\n\n /** Sets a rendering function to derive block title, shown for the block in the left blocks-overview panel. */\n public title(\n rf: RenderFunction<Args, UiState, string>,\n ): BlockModel<Args, OutputsCfg, UiState, Href> {\n tryRegisterCallback('title', () => rf(new RenderCtx()));\n return new BlockModel<Args, OutputsCfg, UiState, Href>({\n ...this.config,\n title: {\n __renderLambda: true,\n handle: 'title',\n },\n });\n }\n\n public subtitle(\n rf: RenderFunction<Args, UiState, string>,\n ): BlockModel<Args, OutputsCfg, UiState, Href> {\n tryRegisterCallback('subtitle', () => rf(new RenderCtx()));\n return new BlockModel<Args, OutputsCfg, UiState, Href>({\n ...this.config,\n subtitle: {\n __renderLambda: true,\n handle: 'subtitle',\n },\n });\n }\n\n public tags(\n rf: RenderFunction<Args, UiState, string[]>,\n ): BlockModel<Args, OutputsCfg, UiState, Href> {\n tryRegisterCallback('tags', () => rf(new RenderCtx()));\n return new BlockModel<Args, OutputsCfg, UiState, Href>({\n ...this.config,\n tags: {\n __renderLambda: true,\n handle: 'tags',\n },\n });\n }\n\n /**\n * Sets initial args for the block, this value must be specified.\n * @deprecated use {@link withArgs}\n * */\n public initialArgs(value: Args): BlockModel<Args, OutputsCfg, UiState, Href> {\n return this.withArgs(value);\n }\n\n /** Sets initial args for the block, this value must be specified. */\n public withArgs<Args>(initialArgs: Args): BlockModel<Args, OutputsCfg, UiState, Href> {\n return new BlockModel<Args, OutputsCfg, UiState, Href>({\n ...this.config,\n initialArgs,\n });\n }\n\n /** Defines type and sets initial value for block UiState. */\n public withUiState<UiState>(initialUiState: UiState): BlockModel<Args, OutputsCfg, UiState, Href> {\n return new BlockModel<Args, OutputsCfg, UiState, Href>({\n ...this.config,\n initialUiState,\n });\n }\n\n /** Sets or overrides feature flags for the block. */\n public withFeatureFlags(flags: Partial<BlockCodeKnownFeatureFlags>): BlockModel<Args, OutputsCfg, UiState, Href> {\n return new BlockModel<Args, OutputsCfg, UiState, Href>({\n ...this.config,\n featureFlags: {\n ...this.config.featureFlags,\n ...flags,\n },\n });\n }\n\n /**\n * Defines how to derive list of upstream references this block is meant to enrich with its exports from block args.\n * Influences dependency graph construction.\n */\n public enriches(\n lambda: (args: Args) => PlRef[],\n ): BlockModel<Args, OutputsCfg, UiState, Href> {\n tryRegisterCallback('enrichmentTargets', lambda);\n return new BlockModel<Args, OutputsCfg, UiState, Href>({\n ...this.config,\n enrichmentTargets: {\n __renderLambda: true,\n handle: 'enrichmentTargets',\n },\n });\n }\n\n public done(apiVersion?: 1): PlatformaExtended<PlatformaV1<\n Args,\n InferOutputsFromConfigs<Args, OutputsCfg, UiState>,\n UiState,\n Href\n >>;\n\n public done(apiVersion: 2): PlatformaExtended<PlatformaV2<\n Args,\n InferOutputsFromConfigs<Args, OutputsCfg, UiState>,\n UiState,\n Href\n >>;\n\n /** Renders all provided block settings into a pre-configured platforma API\n * instance, that can be used in frontend to interact with block state, and\n * other features provided by the platforma to the block. */\n public done(apiVersion: PlatformaApiVersion = 1): PlatformaExtended<Platforma<\n Args,\n InferOutputsFromConfigs<Args, OutputsCfg, UiState>,\n UiState,\n Href\n >> {\n return this.withFeatureFlags({\n ...this.config.featureFlags,\n requiresUIAPIVersion: apiVersion,\n }).#done();\n }\n\n #done(): PlatformaExtended<Platforma<\n Args,\n InferOutputsFromConfigs<Args, OutputsCfg, UiState>,\n UiState,\n Href\n >> {\n if (this.config.initialArgs === undefined) throw new Error('Initial arguments not set.');\n\n const config: BlockConfigContainer = {\n v3: {\n sdkVersion: PlatformaSDKVersion,\n renderingMode: this.config.renderingMode,\n initialArgs: this.config.initialArgs,\n initialUiState: this.config.initialUiState,\n inputsValid: this.config.inputsValid,\n sections: this.config.sections,\n title: this.config.title,\n subtitle: this.config.subtitle,\n tags: this.config.tags,\n outputs: this.config.outputs,\n enrichmentTargets: this.config.enrichmentTargets,\n featureFlags: this.config.featureFlags,\n },\n\n // fields below are added to allow previous desktop versions read generated configs\n sdkVersion: PlatformaSDKVersion,\n renderingMode: this.config.renderingMode,\n initialArgs: this.config.initialArgs,\n inputsValid: downgradeCfgOrLambda(this.config.inputsValid),\n sections: downgradeCfgOrLambda(this.config.sections),\n outputs: Object.fromEntries(\n Object.entries(this.config.outputs).map(([key, value]) => [key, downgradeCfgOrLambda(value)]),\n ),\n };\n\n globalThis.platformaApiVersion = this.config.featureFlags.requiresUIAPIVersion as PlatformaApiVersion;\n\n if (!isInUI())\n // we are in the configuration rendering routine, not in actual UI\n return { config } as any;\n // normal operation inside the UI\n else return {\n ...getPlatformaInstance({ sdkVersion: PlatformaSDKVersion, apiVersion: platformaApiVersion }),\n blockModelInfo: {\n outputs: Object.fromEntries(\n Object.entries(this.config.outputs)\n .map(([key, value]) => [key, {\n withStatus: Boolean(isConfigLambda(value) && value.withStatus),\n }]),\n ),\n },\n };\n }\n}\n\nexport type InferOutputType<CfgOrFH, Args, UiState> = CfgOrFH extends TypedConfig\n ? ResolveCfgType<CfgOrFH, Args, UiState>\n : CfgOrFH extends ConfigRenderLambda\n ? ExtractFunctionHandleReturn<CfgOrFH>\n : never;\n\ntype InferOutputsFromConfigs<\n Args,\n OutputsCfg extends Record<string, TypedConfigOrConfigLambda>,\n UiState,\n> = {\n [Key in keyof OutputsCfg]:\n & OutputWithStatus<InferOutputType<OutputsCfg[Key], Args, UiState>>\n & { __unwrap: (OutputsCfg[Key] extends { withStatus: true } ? false : true) };\n};\n\nexport type PlatformaExtended<Pl extends Platforma = Platforma> = Pl & {\n blockModelInfo: BlockModelInfo;\n};\n\nexport type BlockModelInfo = {\n outputs: Record<string, {\n withStatus: boolean;\n }>;\n};\n"],"names":["getImmediate","tryRegisterCallback","RenderCtx","PlatformaSDKVersion","downgradeCfgOrLambda","isInUI","getPlatformaInstance","isConfigLambda"],"mappings":";;;;;;;;;;;;AAkDA;;AAE0E;MAC7D,UAAU,CAAA;AAOX,IAAA,MAAA;AADV,IAAA,WAAA,CACU,MAYP,EAAA;QAZO,IAAA,CAAA,MAAM,GAAN,MAAM;IAab;AAEI,IAAA,WAAW,2BAA2B,GAAA;QAC3C,OAAO;AACL,YAAA,iBAAiB,EAAE,IAAI;AACvB,YAAA,oBAAoB,EAAE,CAAC;AACvB,YAAA,uBAAuB,EAAE,CAAC;SAC3B;IACH;AAgBO,IAAA,OAAO,MAAM,CAAC,aAAA,GAAoC,OAAO,EAAA;QAC9D,OAAO,IAAI,UAAU,CAAiB;YACpC,aAAa;AACb,YAAA,cAAc,EAAE,EAAE;AAClB,YAAA,OAAO,EAAE,EAAE;AACX,YAAA,WAAW,EAAEA,oBAAY,CAAC,IAAI,CAAC;AAC/B,YAAA,QAAQ,EAAEA,oBAAY,CAAC,EAAE,CAAC;YAC1B,YAAY,EAAE,UAAU,CAAC,2BAA2B;AACrD,SAAA,CAAC;IACJ;AAkDO,IAAA,MAAM,CACX,GAAW,EACX,OAAkC,EAClC,QAAiC,EAAE,EAAA;AAEnC,QAAA,IAAI,OAAO,OAAO,KAAK,UAAU,EAAE;AACjC,YAAA,MAAM,MAAM,GAAG,CAAA,OAAA,EAAU,GAAG,EAAE;AAC9B,YAAAC,4BAAmB,CAAC,MAAM,EAAE,MAAM,OAAO,CAAC,IAAIC,aAAS,EAAE,CAAC,CAAC;Y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6 +1,6 @@
|
|
|
1
|
-
import type { BlockRenderingMode, BlockSection,
|
|
1
|
+
import type { BlockRenderingMode, BlockSection, PlRef, BlockCodeKnownFeatureFlags, OutputWithStatus } from '@milaboratories/pl-model-common';
|
|
2
2
|
import type { Checked, ConfigResult, TypedConfig } from './config';
|
|
3
|
-
import type { Platforma,
|
|
3
|
+
import type { Platforma, PlatformaV1, PlatformaV2 } from './platforma';
|
|
4
4
|
import type { InferRenderFunctionReturn, RenderFunction } from './render';
|
|
5
5
|
import type { TypedConfigOrConfigLambda, ConfigRenderLambda, StdCtxArgsOnly, DeriveHref, ResolveCfgType, ExtractFunctionHandleReturn, ConfigRenderLambdaFlags } from './bconfig';
|
|
6
6
|
type SectionsExpectedType = readonly BlockSection[];
|
|
@@ -12,17 +12,10 @@ type NoOb = Record<string, never>;
|
|
|
12
12
|
* to call {@link done()} at the end of configuration. Value returned by this builder must be
|
|
13
13
|
* exported as constant with name "platforma" from the "config" module. */
|
|
14
14
|
export declare class BlockModel<Args, OutputsCfg extends Record<string, TypedConfigOrConfigLambda>, UiState, Href extends `/${string}` = '/'> {
|
|
15
|
-
private
|
|
16
|
-
private
|
|
17
|
-
private readonly _initialUiState;
|
|
18
|
-
private readonly _outputs;
|
|
19
|
-
private readonly _inputsValid;
|
|
20
|
-
private readonly _sections;
|
|
21
|
-
private readonly _title;
|
|
22
|
-
private readonly _enrichmentTargets;
|
|
23
|
-
private readonly _featureFlags;
|
|
15
|
+
#private;
|
|
16
|
+
private config;
|
|
24
17
|
private constructor();
|
|
25
|
-
static
|
|
18
|
+
static get INITIAL_BLOCK_FEATURE_FLAGS(): BlockCodeKnownFeatureFlags;
|
|
26
19
|
/** Initiates configuration builder */
|
|
27
20
|
static create(renderingMode: BlockRenderingMode): BlockModel<NoOb, {}, NoOb>;
|
|
28
21
|
/** Initiates configuration builder */
|
|
@@ -48,6 +41,21 @@ export declare class BlockModel<Args, OutputsCfg extends Record<string, TypedCon
|
|
|
48
41
|
output<const Key extends string, const Cfg extends TypedConfig>(key: Key, cfg: Cfg): BlockModel<Args, OutputsCfg & {
|
|
49
42
|
[K in Key]: Cfg;
|
|
50
43
|
}, UiState, Href>;
|
|
44
|
+
/**
|
|
45
|
+
* Add output cell wrapped with additional status information to the configuration
|
|
46
|
+
*
|
|
47
|
+
* @param key output cell name, that can be later used to retrieve the rendered value
|
|
48
|
+
* @param rf callback calculating output value using context, that allows to access
|
|
49
|
+
* workflows outputs and interact with platforma drivers
|
|
50
|
+
* @param flags additional flags that may alter lambda rendering procedure
|
|
51
|
+
* */
|
|
52
|
+
output<const Key extends string, const RF extends RenderFunction<Args, UiState>>(key: Key, rf: RF, flags: ConfigRenderLambdaFlags & {
|
|
53
|
+
withStatus: true;
|
|
54
|
+
}): BlockModel<Args, OutputsCfg & {
|
|
55
|
+
[K in Key]: ConfigRenderLambda<InferRenderFunctionReturn<RF>> & {
|
|
56
|
+
withStatus: true;
|
|
57
|
+
};
|
|
58
|
+
}, UiState, Href>;
|
|
51
59
|
/**
|
|
52
60
|
* Add output cell to the configuration
|
|
53
61
|
*
|
|
@@ -60,9 +68,15 @@ export declare class BlockModel<Args, OutputsCfg extends Record<string, TypedCon
|
|
|
60
68
|
[K in Key]: ConfigRenderLambda<InferRenderFunctionReturn<RF>>;
|
|
61
69
|
}, UiState, Href>;
|
|
62
70
|
/** Shortcut for {@link output} with retentive flag set to true. */
|
|
63
|
-
retentiveOutput<const Key extends string, const RF extends RenderFunction<Args, UiState>>(key: Key, rf: RF): BlockModel<Args, OutputsCfg & {
|
|
64
|
-
|
|
65
|
-
|
|
71
|
+
retentiveOutput<const Key extends string, const RF extends RenderFunction<Args, UiState>>(key: Key, rf: RF): BlockModel<Args, OutputsCfg & { [K in Key]: ConfigRenderLambda<InferRenderFunctionReturn<RF>>; }, UiState, Href>;
|
|
72
|
+
/** Shortcut for {@link output} with withStatus flag set to true. */
|
|
73
|
+
outputWithStatus<const Key extends string, const RF extends RenderFunction<Args, UiState>>(key: Key, rf: RF): BlockModel<Args, OutputsCfg & { [K in Key]: ConfigRenderLambda<InferRenderFunctionReturn<RF>> & {
|
|
74
|
+
withStatus: true;
|
|
75
|
+
}; }, UiState, Href>;
|
|
76
|
+
/** Shortcut for {@link output} with retentive and withStatus flags set to true. */
|
|
77
|
+
retentiveOutputWithStatus<const Key extends string, const RF extends RenderFunction<Args, UiState>>(key: Key, rf: RF): BlockModel<Args, OutputsCfg & { [K in Key]: ConfigRenderLambda<InferRenderFunctionReturn<RF>> & {
|
|
78
|
+
withStatus: true;
|
|
79
|
+
}; }, UiState, Href>;
|
|
66
80
|
/** Sets custom configuration predicate on the block args at which block can be executed
|
|
67
81
|
* @deprecated use lambda-based API */
|
|
68
82
|
argsValid<Cfg extends TypedConfig>(cfg: Cfg & InputsValidCfgChecked<Cfg, Args, UiState>): BlockModel<Args, OutputsCfg, UiState, Href>;
|
|
@@ -76,15 +90,17 @@ export declare class BlockModel<Args, OutputsCfg extends Record<string, TypedCon
|
|
|
76
90
|
sections<const Cfg extends TypedConfig>(cfg: Cfg & SectionsCfgChecked<Cfg, Args, UiState>): BlockModel<Args, OutputsCfg, UiState, DeriveHref<ConfigResult<Cfg, StdCtxArgsOnly<Args, UiState>>>>;
|
|
77
91
|
/** Sets a rendering function to derive block title, shown for the block in the left blocks-overview panel. */
|
|
78
92
|
title(rf: RenderFunction<Args, UiState, string>): BlockModel<Args, OutputsCfg, UiState, Href>;
|
|
93
|
+
subtitle(rf: RenderFunction<Args, UiState, string>): BlockModel<Args, OutputsCfg, UiState, Href>;
|
|
94
|
+
tags(rf: RenderFunction<Args, UiState, string[]>): BlockModel<Args, OutputsCfg, UiState, Href>;
|
|
79
95
|
/**
|
|
80
96
|
* Sets initial args for the block, this value must be specified.
|
|
81
97
|
* @deprecated use {@link withArgs}
|
|
82
98
|
* */
|
|
83
99
|
initialArgs(value: Args): BlockModel<Args, OutputsCfg, UiState, Href>;
|
|
84
100
|
/** Sets initial args for the block, this value must be specified. */
|
|
85
|
-
withArgs<Args>(
|
|
101
|
+
withArgs<Args>(initialArgs: Args): BlockModel<Args, OutputsCfg, UiState, Href>;
|
|
86
102
|
/** Defines type and sets initial value for block UiState. */
|
|
87
|
-
withUiState<UiState>(
|
|
103
|
+
withUiState<UiState>(initialUiState: UiState): BlockModel<Args, OutputsCfg, UiState, Href>;
|
|
88
104
|
/** Sets or overrides feature flags for the block. */
|
|
89
105
|
withFeatureFlags(flags: Partial<BlockCodeKnownFeatureFlags>): BlockModel<Args, OutputsCfg, UiState, Href>;
|
|
90
106
|
/**
|
|
@@ -92,13 +108,24 @@ export declare class BlockModel<Args, OutputsCfg extends Record<string, TypedCon
|
|
|
92
108
|
* Influences dependency graph construction.
|
|
93
109
|
*/
|
|
94
110
|
enriches(lambda: (args: Args) => PlRef[]): BlockModel<Args, OutputsCfg, UiState, Href>;
|
|
95
|
-
done(apiVersion?: 1): PlatformaV1<Args, InferOutputsFromConfigs<Args, OutputsCfg, UiState>, UiState, Href
|
|
96
|
-
done(apiVersion: 2): PlatformaV2<Args, InferOutputsFromConfigs<Args, OutputsCfg, UiState>, UiState, Href
|
|
97
|
-
_done(apiVersion: PlatformaApiVersion): Platforma<Args, InferOutputsFromConfigs<Args, OutputsCfg, UiState>, UiState, Href>;
|
|
111
|
+
done(apiVersion?: 1): PlatformaExtended<PlatformaV1<Args, InferOutputsFromConfigs<Args, OutputsCfg, UiState>, UiState, Href>>;
|
|
112
|
+
done(apiVersion: 2): PlatformaExtended<PlatformaV2<Args, InferOutputsFromConfigs<Args, OutputsCfg, UiState>, UiState, Href>>;
|
|
98
113
|
}
|
|
99
114
|
export type InferOutputType<CfgOrFH, Args, UiState> = CfgOrFH extends TypedConfig ? ResolveCfgType<CfgOrFH, Args, UiState> : CfgOrFH extends ConfigRenderLambda ? ExtractFunctionHandleReturn<CfgOrFH> : never;
|
|
100
115
|
type InferOutputsFromConfigs<Args, OutputsCfg extends Record<string, TypedConfigOrConfigLambda>, UiState> = {
|
|
101
|
-
[Key in keyof OutputsCfg]:
|
|
116
|
+
[Key in keyof OutputsCfg]: OutputWithStatus<InferOutputType<OutputsCfg[Key], Args, UiState>> & {
|
|
117
|
+
__unwrap: (OutputsCfg[Key] extends {
|
|
118
|
+
withStatus: true;
|
|
119
|
+
} ? false : true);
|
|
120
|
+
};
|
|
121
|
+
};
|
|
122
|
+
export type PlatformaExtended<Pl extends Platforma = Platforma> = Pl & {
|
|
123
|
+
blockModelInfo: BlockModelInfo;
|
|
124
|
+
};
|
|
125
|
+
export type BlockModelInfo = {
|
|
126
|
+
outputs: Record<string, {
|
|
127
|
+
withStatus: boolean;
|
|
128
|
+
}>;
|
|
102
129
|
};
|
|
103
130
|
export {};
|
|
104
131
|
//# sourceMappingURL=builder.d.ts.map
|