@platforma-sdk/model 1.49.0 → 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 +18 -1
- package/dist/builder.cjs.map +1 -1
- package/dist/builder.d.ts +41 -8
- package/dist/builder.d.ts.map +1 -1
- package/dist/builder.js +18 -1
- 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 +6 -6
- package/src/bconfig/lambdas.ts +10 -1
- package/src/block_state_util.ts +3 -3
- package/src/builder.ts +69 -17
- 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,6 +8,7 @@ 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
|
|
@@ -64,6 +65,14 @@ class BlockModel {
|
|
|
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()));
|
|
@@ -220,7 +229,15 @@ class BlockModel {
|
|
|
220
229
|
return { config };
|
|
221
230
|
// normal operation inside the UI
|
|
222
231
|
else
|
|
223
|
-
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
|
+
};
|
|
224
241
|
}
|
|
225
242
|
}
|
|
226
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 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 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 ): 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.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): 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 = 1): 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(): 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 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;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;AAgCO,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,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AAI,CAAC,MAAM,CAAC,QAAQ,CAAC;AACpD,YAAA,OAAO,EAAE,MAAM,CAAC,WAAW,CACzB,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,EAAE,KAAK,CAAC,KAAK,CAAC,GAAG,EAAEA,kCAAoB,CAAC,KAAK,CAAC,CAAC,CAAC,CAC9F;SACF;QAED,UAAU,CAAC,mBAAmB,GAAG,IAAI,CAAC,MAAM,CAAC,YAAY,CAAC,oBAA2C;QAErG,IAAI,CAACC,eAAM,EAAE;;YAEX,OAAO,EAAE,MAAM,EAAS;;;AAErB,YAAA,OAAOC,6BAAoB,CAAC,EAAE,UAAU,EAAEH,2BAAmB,EAAE,UAAU,EAAE,mBAAmB,EAAE,CAAQ;IAC/G;AACD;;;;"}
|
|
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,C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AC7F,gBAAA,cAAc,EAAE;AACd,oBAAA,OAAO,EAAE,MAAM,CAAC,WAAW,CACzB,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,OAAO;AAC/B,yBAAA,GAAG,CAAC,CAAC,CAAC,GAAG,EAAE,KAAK,CAAC,KAAK,CAAC,GAAG,EAAE;4BAC3B,UAAU,EAAE,OAAO,CAACI,oBAAc,CAAC,KAAK,CAAC,IAAI,KAAK,CAAC,UAAU,CAAC;AAC/D,yBAAA,CAAC,CAAC,CACN;AACF,iBAAA;aACF;IACH;AACD;;;;"}
|
package/dist/builder.d.ts
CHANGED
|
@@ -1,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 { PlatformaV1, PlatformaV2 } from './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[];
|
|
@@ -41,6 +41,21 @@ export declare class BlockModel<Args, OutputsCfg extends Record<string, TypedCon
|
|
|
41
41
|
output<const Key extends string, const Cfg extends TypedConfig>(key: Key, cfg: Cfg): BlockModel<Args, OutputsCfg & {
|
|
42
42
|
[K in Key]: Cfg;
|
|
43
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>;
|
|
44
59
|
/**
|
|
45
60
|
* Add output cell to the configuration
|
|
46
61
|
*
|
|
@@ -53,9 +68,15 @@ export declare class BlockModel<Args, OutputsCfg extends Record<string, TypedCon
|
|
|
53
68
|
[K in Key]: ConfigRenderLambda<InferRenderFunctionReturn<RF>>;
|
|
54
69
|
}, UiState, Href>;
|
|
55
70
|
/** Shortcut for {@link output} with retentive flag set to true. */
|
|
56
|
-
retentiveOutput<const Key extends string, const RF extends RenderFunction<Args, UiState>>(key: Key, rf: RF): BlockModel<Args, OutputsCfg & {
|
|
57
|
-
|
|
58
|
-
|
|
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>;
|
|
59
80
|
/** Sets custom configuration predicate on the block args at which block can be executed
|
|
60
81
|
* @deprecated use lambda-based API */
|
|
61
82
|
argsValid<Cfg extends TypedConfig>(cfg: Cfg & InputsValidCfgChecked<Cfg, Args, UiState>): BlockModel<Args, OutputsCfg, UiState, Href>;
|
|
@@ -87,12 +108,24 @@ export declare class BlockModel<Args, OutputsCfg extends Record<string, TypedCon
|
|
|
87
108
|
* Influences dependency graph construction.
|
|
88
109
|
*/
|
|
89
110
|
enriches(lambda: (args: Args) => PlRef[]): BlockModel<Args, OutputsCfg, UiState, Href>;
|
|
90
|
-
done(apiVersion?: 1): PlatformaV1<Args, InferOutputsFromConfigs<Args, OutputsCfg, UiState>, UiState, Href
|
|
91
|
-
done(apiVersion: 2): PlatformaV2<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>>;
|
|
92
113
|
}
|
|
93
114
|
export type InferOutputType<CfgOrFH, Args, UiState> = CfgOrFH extends TypedConfig ? ResolveCfgType<CfgOrFH, Args, UiState> : CfgOrFH extends ConfigRenderLambda ? ExtractFunctionHandleReturn<CfgOrFH> : never;
|
|
94
115
|
type InferOutputsFromConfigs<Args, OutputsCfg extends Record<string, TypedConfigOrConfigLambda>, UiState> = {
|
|
95
|
-
[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
|
+
}>;
|
|
96
129
|
};
|
|
97
130
|
export {};
|
|
98
131
|
//# sourceMappingURL=builder.d.ts.map
|
package/dist/builder.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"builder.d.ts","sourceRoot":"","sources":["../src/builder.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,YAAY,
|
|
1
|
+
{"version":3,"file":"builder.d.ts","sourceRoot":"","sources":["../src/builder.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,YAAY,EAAe,KAAK,EAAE,0BAA0B,EAAwB,gBAAgB,EAAE,MAAM,iCAAiC,CAAC;AAChL,OAAO,KAAK,EAAE,OAAO,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AAGnE,OAAO,KAAK,EAAE,SAAS,EAAuB,WAAW,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC5F,OAAO,KAAK,EAAE,yBAAyB,EAAE,cAAc,EAAE,MAAM,UAAU,CAAC;AAG1E,OAAO,KAAK,EACV,yBAAyB,EACzB,kBAAkB,EAClB,cAAc,EACd,UAAU,EACV,cAAc,EACd,2BAA2B,EAC3B,uBAAuB,EACxB,MAAM,WAAW,CAAC;AAMnB,KAAK,oBAAoB,GAAG,SAAS,YAAY,EAAE,CAAC;AAEpD,KAAK,kBAAkB,CAAC,GAAG,SAAS,WAAW,EAAE,IAAI,EAAE,OAAO,IAAI,OAAO,CACvE,GAAG,EACH,YAAY,CAAC,GAAG,EAAE,cAAc,CAAC,IAAI,EAAE,O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/builder.js
CHANGED
|
@@ -6,6 +6,7 @@ import './render/util/label.js';
|
|
|
6
6
|
import 'canonicalize';
|
|
7
7
|
import { PlatformaSDKVersion } from './version.js';
|
|
8
8
|
import { downgradeCfgOrLambda } from './bconfig/normalization.js';
|
|
9
|
+
import { isConfigLambda } from './bconfig/types.js';
|
|
9
10
|
|
|
10
11
|
/** Main entry point that each block should use in it's "config" module. Don't forget
|
|
11
12
|
* to call {@link done()} at the end of configuration. Value returned by this builder must be
|
|
@@ -62,6 +63,14 @@ class BlockModel {
|
|
|
62
63
|
retentiveOutput(key, rf) {
|
|
63
64
|
return this.output(key, rf, { retentive: true });
|
|
64
65
|
}
|
|
66
|
+
/** Shortcut for {@link output} with withStatus flag set to true. */
|
|
67
|
+
outputWithStatus(key, rf) {
|
|
68
|
+
return this.output(key, rf, { withStatus: true });
|
|
69
|
+
}
|
|
70
|
+
/** Shortcut for {@link output} with retentive and withStatus flags set to true. */
|
|
71
|
+
retentiveOutputWithStatus(key, rf) {
|
|
72
|
+
return this.output(key, rf, { retentive: true, withStatus: true });
|
|
73
|
+
}
|
|
65
74
|
argsValid(cfgOrRf) {
|
|
66
75
|
if (typeof cfgOrRf === 'function') {
|
|
67
76
|
tryRegisterCallback('inputsValid', () => cfgOrRf(new RenderCtx()));
|
|
@@ -218,7 +227,15 @@ class BlockModel {
|
|
|
218
227
|
return { config };
|
|
219
228
|
// normal operation inside the UI
|
|
220
229
|
else
|
|
221
|
-
return
|
|
230
|
+
return {
|
|
231
|
+
...getPlatformaInstance({ sdkVersion: PlatformaSDKVersion, apiVersion: platformaApiVersion }),
|
|
232
|
+
blockModelInfo: {
|
|
233
|
+
outputs: Object.fromEntries(Object.entries(this.config.outputs)
|
|
234
|
+
.map(([key, value]) => [key, {
|
|
235
|
+
withStatus: Boolean(isConfigLambda(value) && value.withStatus),
|
|
236
|
+
}])),
|
|
237
|
+
},
|
|
238
|
+
};
|
|
222
239
|
}
|
|
223
240
|
}
|
|
224
241
|
|
package/dist/builder.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"builder.js","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 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 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 ): 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.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): 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 = 1): 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(): 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 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":[],"mappings":";;;;;;;;;AAiDA;;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,EAAE,YAAY,CAAC,IAAI,CAAC;AAC/B,YAAA,QAAQ,EAAE,YAAY,CAAC,EAAE,CAAC;YAC1B,YAAY,EAAE,UAAU,CAAC,2BAA2B;AACrD,SAAA,CAAC;IACJ;AAgCO,IAAA,MAAM,CACX,GAAW,EACX,OAAkC,EAClC,QAAiC,EAAE,EAAA;AAEnC,QAAA,IAAI,OAAO,OAAO,KAAK,UAAU,EAAE;AACjC,YAAA,MAAM,M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BAAoB,CAAC,IAAI,CAAC,MAAM,CAAC,WAAW,CAAC;YAC1D,QAAQ,EAAE,oBAAoB,CAAC,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC;AACpD,YAAA,OAAO,EAAE,MAAM,CAAC,WAAW,CACzB,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,EAAE,KAAK,CAAC,KAAK,CAAC,GAAG,EAAE,oBAAoB,CAAC,KAAK,CAAC,CAAC,CAAC,CAC9F;SACF;QAED,UAAU,CAAC,mBAAmB,GAAG,IAAI,CAAC,MAAM,CAAC,YAAY,CAAC,oBAA2C;QAErG,IAAI,CAAC,MAAM,EAAE;;YAEX,OAAO,EAAE,MAAM,EAAS;;;AAErB,YAAA,OAAO,oBAAoB,CAAC,EAAE,UAAU,EAAE,mBAAmB,EAAE,UAAU,EAAE,mBAAmB,EAAE,CAAQ;IAC/G;AACD;;;;"}
|
|
1
|
+
{"version":3,"file":"builder.js","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":[],"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,EAAE,YAAY,CAAC,IAAI,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AAO,EAAE,MAAM,CAAC,WAAW,CACzB,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,OAAO;AAC/B,yBAAA,GAAG,CAAC,CAAC,CAAC,GAAG,EAAE,KAAK,CAAC,KAAK,CAAC,GAAG,EAAE;4BAC3B,UAAU,EAAE,OAAO,CAAC,cAAc,CAAC,KAAK,CAAC,IAAI,KAAK,CAAC,UAAU,CAAC;AAC/D,yBAAA,CAAC,CAAC,CACN;AACF,iBAAA;aACF;IACH;AACD;;;;"}
|
package/dist/internal.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"internal.cjs","sources":["../src/internal.ts"],"sourcesContent":["import type {
|
|
1
|
+
{"version":3,"file":"internal.cjs","sources":["../src/internal.ts"],"sourcesContent":["import type { OutputWithStatus } from '@milaboratories/pl-model-common';\nimport { } from './global';\nimport type { Platforma, PlatformaApiVersion } from './platforma';\nimport type { FutureHandle, GlobalCfgRenderCtx } from './render/internal';\n\n/** Utility code helping to identify whether the code is running in actual UI environment */\nexport function isInUI() {\n return (\n typeof globalThis.getPlatforma !== 'undefined' || typeof globalThis.platforma !== 'undefined'\n );\n}\n\n/** Utility code helping to retrieve a platforma instance form the environment */\nexport function getPlatformaInstance<\n Args = unknown,\n Outputs extends Record<string, OutputWithStatus<unknown>> = Record<string, OutputWithStatus<unknown>>,\n UiState = unknown,\n Href extends `/${string}` = `/${string}`,\n>(config?: { sdkVersion: string; apiVersion: PlatformaApiVersion }): Platforma<Args, Outputs, UiState, Href> {\n if (config && typeof globalThis.getPlatforma === 'function')\n return globalThis.getPlatforma(config);\n else if (typeof globalThis.platforma !== 'undefined') return globalThis.platforma as Platforma<Args, Outputs, UiState, Href>;\n else throw new Error('Can\\'t get platforma instance.');\n}\n\nexport function tryGetCfgRenderCtx(): GlobalCfgRenderCtx | undefined {\n if (typeof globalThis.cfgRenderCtx !== 'undefined') return globalThis.cfgRenderCtx;\n else return undefined;\n}\n\nexport function getCfgRenderCtx(): GlobalCfgRenderCtx {\n if (typeof globalThis.cfgRenderCtx !== 'undefined') return globalThis.cfgRenderCtx;\n else throw new Error('Not in config rendering context');\n}\n\nexport function tryRegisterCallback(key: string, callback: (...args: any[]) => any): boolean {\n const ctx = tryGetCfgRenderCtx();\n if (ctx === undefined) return false;\n if (key in ctx.callbackRegistry) throw new Error(`Callback with key ${key} already registered.`);\n ctx.callbackRegistry[key] = callback;\n return true;\n}\n\nconst futureResolves = new Map<string, ((value: unknown) => void)[]>();\n\nexport function registerFutureAwait(handle: FutureHandle, onResolve: (value: unknown) => void) {\n if (!(handle in getCfgRenderCtx().callbackRegistry)) {\n getCfgRenderCtx().callbackRegistry[handle] = (value: unknown) => {\n for (const res of futureResolves.get(handle)!) {\n res(value);\n }\n };\n futureResolves.set(handle, []);\n }\n futureResolves.get(handle)!.push(onResolve);\n}\n"],"names":[],"mappings":";;AAKA;SACgB,MAAM,GAAA;AACpB,IAAA,QACE,OAAO,UAAU,CAAC,YAAY,KAAK,WAAW,IAAI,OAAO,UAAU,CAAC,SAAS,KAAK,WAAW;AAEjG;AAEA;AACM,SAAU,oBAAoB,CAKlC,MAAgE,EAAA;AAChE,IAAA,IAAI,MAAM,IAAI,OAAO,UAAU,CAAC,YAAY,KAAK,UAAU;AACzD,QAAA,OAAO,UAAU,CAAC,YAAY,CAAC,MAAM,CAAC;AACnC,SAAA,IAAI,OAAO,UAAU,CAAC,SAAS,KAAK,WAAW;QAAE,OAAO,UAAU,CAAC,SAAoD;;AACvH,QAAA,MAAM,IAAI,KAAK,CAAC,gCAAgC,CAAC;AACxD;SAEgB,kBAAkB,GAAA;AAChC,IAAA,IAAI,OAAO,UAAU,CAAC,YAAY,KAAK,WAAW;QAAE,OAAO,UAAU,CAAC,YAAY;;AAC7E,QAAA,OAAO,SAAS;AACvB;SAEgB,eAAe,GAAA;AAC7B,IAAA,IAAI,OAAO,UAAU,CAAC,YAAY,KAAK,WAAW;QAAE,OAAO,UAAU,CAAC,YAAY;;AAC7E,QAAA,MAAM,IAAI,KAAK,CAAC,iCAAiC,CAAC;AACzD;AAEM,SAAU,mBAAmB,CAAC,GAAW,EAAE,QAAiC,EAAA;AAChF,IAAA,MAAM,GAAG,GAAG,kBAAkB,EAAE;IAChC,IAAI,GAAG,KAAK,SAAS;AAAE,QAAA,OAAO,KAAK;AACnC,IAAA,IAAI,GAAG,IAAI,GAAG,CAAC,gBAAgB;AAAE,QAAA,MAAM,IAAI,KAAK,CAAC,qBAAqB,GAAG,CAAA,oBAAA,CAAsB,CAAC;AAChG,IAAA,GAAG,CAAC,gBAAgB,CAAC,GAAG,CAAC,GAAG,QAAQ;AACpC,IAAA,OAAO,IAAI;AACb;AAEA,MAAM,cAAc,GAAG,IAAI,GAAG,EAAwC;AAEhE,SAAU,mBAAmB,CAAC,MAAoB,EAAE,SAAmC,EAAA;IAC3F,IAAI,EAAE,MAAM,IAAI,eAAe,EAAE,CAAC,gBAAgB,CAAC,EAAE;QACnD,eAAe,EAAE,CAAC,gBAAgB,CAAC,MAAM,CAAC,GAAG,CAAC,KAAc,KAAI;YAC9D,KAAK,MAAM,GAAG,IAAI,cAAc,CAAC,GAAG,CAAC,MAAM,CAAE,EAAE;gBAC7C,GAAG,CAAC,KAAK,CAAC;YACZ;AACF,QAAA,CAAC;AACD,QAAA,cAAc,CAAC,GAAG,CAAC,MAAM,EAAE,EAAE,CAAC;IAChC;IACA,cAAc,CAAC,GAAG,CAAC,MAAM,CAAE,CAAC,IAAI,CAAC,SAAS,CAAC;AAC7C;;;;;;;;;"}
|
package/dist/internal.d.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { OutputWithStatus } from '@milaboratories/pl-model-common';
|
|
2
2
|
import type { Platforma, PlatformaApiVersion } from './platforma';
|
|
3
3
|
import type { FutureHandle, GlobalCfgRenderCtx } from './render/internal';
|
|
4
4
|
/** Utility code helping to identify whether the code is running in actual UI environment */
|
|
5
5
|
export declare function isInUI(): boolean;
|
|
6
6
|
/** Utility code helping to retrieve a platforma instance form the environment */
|
|
7
|
-
export declare function getPlatformaInstance<Args = unknown, Outputs extends Record<string,
|
|
7
|
+
export declare function getPlatformaInstance<Args = unknown, Outputs extends Record<string, OutputWithStatus<unknown>> = Record<string, OutputWithStatus<unknown>>, UiState = unknown, Href extends `/${string}` = `/${string}`>(config?: {
|
|
8
8
|
sdkVersion: string;
|
|
9
9
|
apiVersion: PlatformaApiVersion;
|
|
10
10
|
}): Platforma<Args, Outputs, UiState, Href>;
|
package/dist/internal.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"internal.d.ts","sourceRoot":"","sources":["../src/internal.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"internal.d.ts","sourceRoot":"","sources":["../src/internal.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,iCAAiC,CAAC;AAExE,OAAO,KAAK,EAAE,SAAS,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAC;AAClE,OAAO,KAAK,EAAE,YAAY,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAC;AAE1E,4FAA4F;AAC5F,wBAAgB,MAAM,YAIrB;AAED,iFAAiF;AACjF,wBAAgB,oBAAoB,CAClC,IAAI,GAAG,OAAO,EACd,OAAO,SAAS,MAAM,CAAC,MAAM,EAAE,gBAAgB,CAAC,OAAO,CAAC,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,gBAAgB,CAAC,OAAO,CAAC,CAAC,EACrG,OAAO,GAAG,OAAO,EACjB,IAAI,SAAS,IAAI,MAAM,EAAE,GAAG,IAAI,MAAM,EAAE,EACxC,MAAM,CAAC,EAAE;IAAE,UAAU,EAAE,MAAM,CAAC;IAAC,UAAU,EAAE,mBAAmB,CAAA;CAAE,GAAG,SAAS,CAAC,IAAI,EAAE,OAAO,EAAE,OAAO,EAAE,IAAI,CAAC,CAK3G;AAED,wBAAgB,kBAAkB,IAAI,kBAAkB,GAAG,SAAS,CAGnE;AAED,wBAAgB,eAAe,IAAI,kBAAkB,CAGpD;AAED,wBAAgB,mBAAmB,CAAC,GAAG,EAAE,MAAM,EAAE,QAAQ,EAAE,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,GAAG,GAAG,OAAO,CAM3F;AAID,wBAAgB,mBAAmB,CAAC,MAAM,EAAE,YAAY,EAAE,SAAS,EAAE,CAAC,KAAK,EAAE,OAAO,KAAK,IAAI,QAU5F"}
|
package/dist/internal.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"internal.js","sources":["../src/internal.ts"],"sourcesContent":["import type {
|
|
1
|
+
{"version":3,"file":"internal.js","sources":["../src/internal.ts"],"sourcesContent":["import type { OutputWithStatus } from '@milaboratories/pl-model-common';\nimport { } from './global';\nimport type { Platforma, PlatformaApiVersion } from './platforma';\nimport type { FutureHandle, GlobalCfgRenderCtx } from './render/internal';\n\n/** Utility code helping to identify whether the code is running in actual UI environment */\nexport function isInUI() {\n return (\n typeof globalThis.getPlatforma !== 'undefined' || typeof globalThis.platforma !== 'undefined'\n );\n}\n\n/** Utility code helping to retrieve a platforma instance form the environment */\nexport function getPlatformaInstance<\n Args = unknown,\n Outputs extends Record<string, OutputWithStatus<unknown>> = Record<string, OutputWithStatus<unknown>>,\n UiState = unknown,\n Href extends `/${string}` = `/${string}`,\n>(config?: { sdkVersion: string; apiVersion: PlatformaApiVersion }): Platforma<Args, Outputs, UiState, Href> {\n if (config && typeof globalThis.getPlatforma === 'function')\n return globalThis.getPlatforma(config);\n else if (typeof globalThis.platforma !== 'undefined') return globalThis.platforma as Platforma<Args, Outputs, UiState, Href>;\n else throw new Error('Can\\'t get platforma instance.');\n}\n\nexport function tryGetCfgRenderCtx(): GlobalCfgRenderCtx | undefined {\n if (typeof globalThis.cfgRenderCtx !== 'undefined') return globalThis.cfgRenderCtx;\n else return undefined;\n}\n\nexport function getCfgRenderCtx(): GlobalCfgRenderCtx {\n if (typeof globalThis.cfgRenderCtx !== 'undefined') return globalThis.cfgRenderCtx;\n else throw new Error('Not in config rendering context');\n}\n\nexport function tryRegisterCallback(key: string, callback: (...args: any[]) => any): boolean {\n const ctx = tryGetCfgRenderCtx();\n if (ctx === undefined) return false;\n if (key in ctx.callbackRegistry) throw new Error(`Callback with key ${key} already registered.`);\n ctx.callbackRegistry[key] = callback;\n return true;\n}\n\nconst futureResolves = new Map<string, ((value: unknown) => void)[]>();\n\nexport function registerFutureAwait(handle: FutureHandle, onResolve: (value: unknown) => void) {\n if (!(handle in getCfgRenderCtx().callbackRegistry)) {\n getCfgRenderCtx().callbackRegistry[handle] = (value: unknown) => {\n for (const res of futureResolves.get(handle)!) {\n res(value);\n }\n };\n futureResolves.set(handle, []);\n }\n futureResolves.get(handle)!.push(onResolve);\n}\n"],"names":[],"mappings":"AAKA;SACgB,MAAM,GAAA;AACpB,IAAA,QACE,OAAO,UAAU,CAAC,YAAY,KAAK,WAAW,IAAI,OAAO,UAAU,CAAC,SAAS,KAAK,WAAW;AAEjG;AAEA;AACM,SAAU,oBAAoB,CAKlC,MAAgE,EAAA;AAChE,IAAA,IAAI,MAAM,IAAI,OAAO,UAAU,CAAC,YAAY,KAAK,UAAU;AACzD,QAAA,OAAO,UAAU,CAAC,YAAY,CAAC,MAAM,CAAC;AACnC,SAAA,IAAI,OAAO,UAAU,CAAC,SAAS,KAAK,WAAW;QAAE,OAAO,UAAU,CAAC,SAAoD;;AACvH,QAAA,MAAM,IAAI,KAAK,CAAC,gCAAgC,CAAC;AACxD;SAEgB,kBAAkB,GAAA;AAChC,IAAA,IAAI,OAAO,UAAU,CAAC,YAAY,KAAK,WAAW;QAAE,OAAO,UAAU,CAAC,YAAY;;AAC7E,QAAA,OAAO,SAAS;AACvB;SAEgB,eAAe,GAAA;AAC7B,IAAA,IAAI,OAAO,UAAU,CAAC,YAAY,KAAK,WAAW;QAAE,OAAO,UAAU,CAAC,YAAY;;AAC7E,QAAA,MAAM,IAAI,KAAK,CAAC,iCAAiC,CAAC;AACzD;AAEM,SAAU,mBAAmB,CAAC,GAAW,EAAE,QAAiC,EAAA;AAChF,IAAA,MAAM,GAAG,GAAG,kBAAkB,EAAE;IAChC,IAAI,GAAG,KAAK,SAAS;AAAE,QAAA,OAAO,KAAK;AACnC,IAAA,IAAI,GAAG,IAAI,GAAG,CAAC,gBAAgB;AAAE,QAAA,MAAM,IAAI,KAAK,CAAC,qBAAqB,GAAG,CAAA,oBAAA,CAAsB,CAAC;AAChG,IAAA,GAAG,CAAC,gBAAgB,CAAC,GAAG,CAAC,GAAG,QAAQ;AACpC,IAAA,OAAO,IAAI;AACb;AAEA,MAAM,cAAc,GAAG,IAAI,GAAG,EAAwC;AAEhE,SAAU,mBAAmB,CAAC,MAAoB,EAAE,SAAmC,EAAA;IAC3F,IAAI,EAAE,MAAM,IAAI,eAAe,EAAE,CAAC,gBAAgB,CAAC,EAAE;QACnD,eAAe,EAAE,CAAC,gBAAgB,CAAC,MAAM,CAAC,GAAG,CAAC,KAAc,KAAI;YAC9D,KAAK,MAAM,GAAG,IAAI,cAAc,CAAC,GAAG,CAAC,MAAM,CAAE,EAAE;gBAC7C,GAAG,CAAC,KAAK,CAAC;YACZ;AACF,QAAA,CAAC;AACD,QAAA,cAAc,CAAC,GAAG,CAAC,MAAM,EAAE,EAAE,CAAC;IAChC;IACA,cAAc,CAAC,GAAG,CAAC,MAAM,CAAE,CAAC,IAAI,CAAC,SAAS,CAAC;AAC7C;;;;"}
|
package/dist/package.json.cjs
CHANGED
package/dist/package.json.js
CHANGED
package/dist/platforma.d.ts
CHANGED
|
@@ -1,25 +1,25 @@
|
|
|
1
1
|
import type { BlockApiV1 } from './block_api_v1';
|
|
2
2
|
import type { BlockApiV2 } from './block_api_v2';
|
|
3
|
-
import type { BlockOutputsBase, BlockState, DriverKit,
|
|
3
|
+
import type { BlockOutputsBase, BlockState, DriverKit, OutputWithStatus } from '@milaboratories/pl-model-common';
|
|
4
4
|
import type { SdkInfo } from './sdk_info';
|
|
5
5
|
import type { BlockStatePatch } from './block_state_patch';
|
|
6
6
|
/** Defines all methods to interact with the platform environment from within a block UI. @deprecated */
|
|
7
|
-
export interface PlatformaV1<Args = unknown, Outputs extends Record<string,
|
|
7
|
+
export interface PlatformaV1<Args = unknown, Outputs extends Record<string, OutputWithStatus<unknown>> = Record<string, OutputWithStatus<unknown>>, UiState = unknown, Href extends `/${string}` = `/${string}`> extends BlockApiV1<Args, Outputs, UiState, Href>, DriverKit {
|
|
8
8
|
/** Information about SDK version current platforma environment was compiled with. */
|
|
9
9
|
readonly sdkInfo: SdkInfo;
|
|
10
10
|
readonly apiVersion?: 1;
|
|
11
11
|
}
|
|
12
12
|
/** V2 version based on effective json patches pulling API */
|
|
13
|
-
export interface PlatformaV2<Args = unknown, Outputs extends Record<string,
|
|
13
|
+
export interface PlatformaV2<Args = unknown, Outputs extends Record<string, OutputWithStatus<unknown>> = Record<string, OutputWithStatus<unknown>>, UiState = unknown, Href extends `/${string}` = `/${string}`> extends BlockApiV2<Args, Outputs, UiState, Href>, DriverKit {
|
|
14
14
|
/** Information about SDK version current platforma environment was compiled with. */
|
|
15
15
|
readonly sdkInfo: SdkInfo;
|
|
16
16
|
readonly apiVersion: 2;
|
|
17
17
|
}
|
|
18
|
-
export type Platforma<Args = unknown, Outputs extends Record<string,
|
|
18
|
+
export type Platforma<Args = unknown, Outputs extends Record<string, OutputWithStatus<unknown>> = Record<string, OutputWithStatus<unknown>>, UiState = unknown, Href extends `/${string}` = `/${string}`> = PlatformaV1<Args, Outputs, UiState, Href> | PlatformaV2<Args, Outputs, UiState, Href>;
|
|
19
19
|
export type PlatformaApiVersion = Platforma['apiVersion'];
|
|
20
20
|
export type InferArgsType<Pl extends Platforma> = Pl extends Platforma<infer Args> ? Args : never;
|
|
21
21
|
export type InferOutputsType<Pl extends Platforma> = Pl extends Platforma<unknown, infer Outputs> ? Outputs : never;
|
|
22
|
-
export type InferUiState<Pl extends Platforma> = Pl extends Platforma<unknown, Record<string,
|
|
22
|
+
export type InferUiState<Pl extends Platforma> = Pl extends Platforma<unknown, Record<string, OutputWithStatus<unknown>>, infer UiState> ? UiState : never;
|
|
23
23
|
export type InferHrefType<Pl extends Platforma> = Pl extends Platforma<unknown, BlockOutputsBase, unknown, infer Href> ? Href : never;
|
|
24
24
|
export type PlatformaFactory = (config: {
|
|
25
25
|
sdkVersion: string;
|
package/dist/platforma.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"platforma.d.ts","sourceRoot":"","sources":["../src/platforma.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AACjD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AACjD,OAAO,KAAK,EAAE,gBAAgB,EAAE,UAAU,EAAE,SAAS,EAAE,
|
|
1
|
+
{"version":3,"file":"platforma.d.ts","sourceRoot":"","sources":["../src/platforma.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AACjD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AACjD,OAAO,KAAK,EAAE,gBAAgB,EAAE,UAAU,EAAE,SAAS,EAAE,gBAAgB,EAAE,MAAM,iCAAiC,CAAC;AACjH,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AAC1C,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AAE3D,wGAAwG;AACxG,MAAM,WAAW,WAAW,CAC1B,IAAI,GAAG,OAAO,EACd,OAAO,SAAS,MAAM,CAAC,MAAM,EAAE,gBAAgB,CAAC,OAAO,CAAC,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,gBAAgB,CAAC,OAAO,CAAC,CAAC,EACrG,OAAO,GAAG,OAAO,EACjB,IAAI,SAAS,I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":3,"file":"raw_globals.cjs","sources":["../src/raw_globals.ts"],"sourcesContent":["import type { OutputWithStatus } from '@milaboratories/pl-model-common';\nimport {} from './global';\nimport { getPlatformaInstance } from './internal';\nimport type { Platforma, PlatformaApiVersion } from './platforma';\nimport { PlatformaSDKVersion } from './version';\n\nexport function getPlatformaApiVersion(): PlatformaApiVersion {\n return platformaApiVersion ?? 1; // undefined means 1 for backward compatibility\n}\n\nexport function getRawPlatformaInstance<\n Args = unknown,\n Outputs extends Record<string, OutputWithStatus<unknown>> = Record<string, OutputWithStatus<unknown>>,\n UiState = unknown,\n Href extends `/${string}` = `/${string}`,\n>(): Platforma<Args, Outputs, UiState, Href> {\n return getPlatformaInstance<Args, Outputs, UiState, Href>({ sdkVersion: PlatformaSDKVersion, apiVersion: platformaApiVersion });\n}\n\n/** Returns a global platforma instance or a provided fallback if it's not available. */\n// export function getPlatformaOrDefault<\n// Args = unknown,\n// Outputs extends Record<string, ValueOrErrors<unknown>> = Record<string, ValueOrErrors<unknown>>,\n// UiState = unknown,\n// Href extends `/${string}` = `/${string}`,\n// >(): PlatformaV1<Args, Outputs, UiState, Href> | PlatformaV2<Args, Outputs, UiState, Href> {\n// try {\n// return getRawPlatformaInstance<Args, Outputs, UiState, Href>();\n// } catch {\n// return platforma;\n// }\n// }\n"],"names":["getPlatformaInstance","PlatformaSDKVersion"],"mappings":";;;;;SAMgB,sBAAsB,GAAA;AACpC,IAAA,OAAO,mBAAmB,IAAI,CAAC,CAAC;AAClC;SAEgB,uBAAuB,GAAA;AAMrC,IAAA,OAAOA,6BAAoB,CAA+B,EAAE,UAAU,EAAEC,2BAAmB,EAAE,UAAU,EAAE,mBAAmB,EAAE,CAAC;AACjI;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;;;"}
|
package/dist/raw_globals.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { OutputWithStatus } from '@milaboratories/pl-model-common';
|
|
2
2
|
import type { Platforma, PlatformaApiVersion } from './platforma';
|
|
3
3
|
export declare function getPlatformaApiVersion(): PlatformaApiVersion;
|
|
4
|
-
export declare function getRawPlatformaInstance<Args = unknown, Outputs extends Record<string,
|
|
4
|
+
export declare function getRawPlatformaInstance<Args = unknown, Outputs extends Record<string, OutputWithStatus<unknown>> = Record<string, OutputWithStatus<unknown>>, UiState = unknown, Href extends `/${string}` = `/${string}`>(): Platforma<Args, Outputs, UiState, Href>;
|
|
5
5
|
/** Returns a global platforma instance or a provided fallback if it's not available. */
|
|
6
6
|
//# sourceMappingURL=raw_globals.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"raw_globals.d.ts","sourceRoot":"","sources":["../src/raw_globals.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"raw_globals.d.ts","sourceRoot":"","sources":["../src/raw_globals.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,iCAAiC,CAAC;AAGxE,OAAO,KAAK,EAAE,SAAS,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAC;AAGlE,wBAAgB,sBAAsB,IAAI,mBAAmB,CAE5D;AAED,wBAAgB,uBAAuB,CACrC,IAAI,GAAG,OAAO,EACd,OAAO,SAAS,MAAM,CAAC,MAAM,EAAE,gBAAgB,CAAC,OAAO,CAAC,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,gBAAgB,CAAC,OAAO,CAAC,CAAC,EACrG,OAAO,GAAG,OAAO,EACjB,IAAI,SAAS,IAAI,MAAM,EAAE,GAAG,IAAI,MAAM,EAAE,KACrC,SAAS,CAAC,IAAI,EAAE,OAAO,EAAE,OAAO,EAAE,IAAI,CAAC,CAE3C;AAED,wFAAwF"}
|
package/dist/raw_globals.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"raw_globals.js","sources":["../src/raw_globals.ts"],"sourcesContent":["import type {
|
|
1
|
+
{"version":3,"file":"raw_globals.js","sources":["../src/raw_globals.ts"],"sourcesContent":["import type { OutputWithStatus } from '@milaboratories/pl-model-common';\nimport {} from './global';\nimport { getPlatformaInstance } from './internal';\nimport type { Platforma, PlatformaApiVersion } from './platforma';\nimport { PlatformaSDKVersion } from './version';\n\nexport function getPlatformaApiVersion(): PlatformaApiVersion {\n return platformaApiVersion ?? 1; // undefined means 1 for backward compatibility\n}\n\nexport function getRawPlatformaInstance<\n Args = unknown,\n Outputs extends Record<string, OutputWithStatus<unknown>> = Record<string, OutputWithStatus<unknown>>,\n UiState = unknown,\n Href extends `/${string}` = `/${string}`,\n>(): Platforma<Args, Outputs, UiState, Href> {\n return getPlatformaInstance<Args, Outputs, UiState, Href>({ sdkVersion: PlatformaSDKVersion, apiVersion: platformaApiVersion });\n}\n\n/** Returns a global platforma instance or a provided fallback if it's not available. */\n// export function getPlatformaOrDefault<\n// Args = unknown,\n// Outputs extends Record<string, ValueOrErrors<unknown>> = Record<string, ValueOrErrors<unknown>>,\n// UiState = unknown,\n// Href extends `/${string}` = `/${string}`,\n// >(): PlatformaV1<Args, Outputs, UiState, Href> | PlatformaV2<Args, Outputs, UiState, Href> {\n// try {\n// return getRawPlatformaInstance<Args, Outputs, UiState, Href>();\n// } catch {\n// return platforma;\n// }\n// }\n"],"names":[],"mappings":";;;SAMgB,sBAAsB,GAAA;AACpC,IAAA,OAAO,mBAAmB,IAAI,CAAC,CAAC;AAClC;SAEgB,uBAAuB,GAAA;AAMrC,IAAA,OAAO,oBAAoB,CAA+B,EAAE,UAAU,EAAE,mBAAmB,EAAE,UAAU,EAAE,mBAAmB,EAAE,CAAC;AACjI;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;;"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@platforma-sdk/model",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.50.0",
|
|
4
4
|
"description": "Platforma.bio SDK / Block Model",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"types": "./dist/index.d.ts",
|
|
@@ -23,9 +23,9 @@
|
|
|
23
23
|
"canonicalize": "~2.1.0",
|
|
24
24
|
"es-toolkit": "^1.39.10",
|
|
25
25
|
"zod": "~3.23.8",
|
|
26
|
-
"@milaboratories/ptabler-expression-js": "1.1.
|
|
26
|
+
"@milaboratories/ptabler-expression-js": "1.1.9",
|
|
27
27
|
"@milaboratories/pl-error-like": "1.12.5",
|
|
28
|
-
"@milaboratories/pl-model-common": "1.
|
|
28
|
+
"@milaboratories/pl-model-common": "1.23.0"
|
|
29
29
|
},
|
|
30
30
|
"devDependencies": {
|
|
31
31
|
"typescript": "~5.6.3",
|
|
@@ -33,10 +33,10 @@
|
|
|
33
33
|
"@vitest/coverage-istanbul": "^4.0.16",
|
|
34
34
|
"fast-json-patch": "^3.1.1",
|
|
35
35
|
"@milaboratories/eslint-config": "1.0.5",
|
|
36
|
-
"@milaboratories/
|
|
37
|
-
"@milaboratories/
|
|
36
|
+
"@milaboratories/helpers": "1.13.0",
|
|
37
|
+
"@milaboratories/ts-configs": "1.2.0",
|
|
38
38
|
"@milaboratories/ts-builder": "1.2.1",
|
|
39
|
-
"@milaboratories/
|
|
39
|
+
"@milaboratories/build-configs": "1.2.1"
|
|
40
40
|
},
|
|
41
41
|
"scripts": {
|
|
42
42
|
"type-check": "ts-builder types --target node",
|
package/src/bconfig/lambdas.ts
CHANGED
|
@@ -29,13 +29,22 @@ export type ConfigRenderLambdaFlags = {
|
|
|
29
29
|
* nobody is actively monitoring rendered values. Like file upload progress, that triggers upload itself.
|
|
30
30
|
* */
|
|
31
31
|
isActive?: boolean;
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* If true, result will be wrapped with additional status information,
|
|
35
|
+
* such as stability status and explicit error
|
|
36
|
+
*/
|
|
37
|
+
withStatus?: boolean;
|
|
32
38
|
};
|
|
33
39
|
|
|
34
40
|
/** Creates branded Cfg type */
|
|
35
|
-
export interface ConfigRenderLambda<
|
|
41
|
+
export interface ConfigRenderLambda<Return = unknown> extends ConfigRenderLambdaFlags {
|
|
36
42
|
/** Type marker */
|
|
37
43
|
__renderLambda: true;
|
|
38
44
|
|
|
45
|
+
/** Phantom property for type inference. Never set at runtime. */
|
|
46
|
+
__phantomReturn?: Return;
|
|
47
|
+
|
|
39
48
|
/** Reference to a callback registered inside the model code. */
|
|
40
49
|
handle: string;
|
|
41
50
|
}
|
package/src/block_state_util.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
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
|
|
|
4
4
|
export class OutputError extends Error {
|
|
@@ -10,12 +10,12 @@ export class OutputError extends Error {
|
|
|
10
10
|
}
|
|
11
11
|
}
|
|
12
12
|
|
|
13
|
-
export function readOutput<T>(outputValue:
|
|
13
|
+
export function readOutput<T>(outputValue: OutputWithStatus<T>): T {
|
|
14
14
|
if (!outputValue.ok) throw new OutputError(outputValue.errors, outputValue.moreErrors);
|
|
15
15
|
return outputValue.value;
|
|
16
16
|
}
|
|
17
17
|
|
|
18
|
-
type ExtractValueType<V extends
|
|
18
|
+
type ExtractValueType<V extends OutputWithStatus<unknown>> = Extract<V, { ok: true }>['value'];
|
|
19
19
|
type SimpleOutputs<Outputs extends BlockOutputsBase> = {
|
|
20
20
|
[Key in keyof Outputs]: ExtractValueType<Outputs[Key]>;
|
|
21
21
|
};
|
package/src/builder.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { BlockRenderingMode, BlockSection,
|
|
1
|
+
import type { BlockRenderingMode, BlockSection, AnyFunction, PlRef, BlockCodeKnownFeatureFlags, BlockConfigContainer, OutputWithStatus } from '@milaboratories/pl-model-common';
|
|
2
2
|
import type { Checked, ConfigResult, TypedConfig } from './config';
|
|
3
3
|
import { getImmediate } from './config';
|
|
4
4
|
import { getPlatformaInstance, isInUI, tryRegisterCallback } from './internal';
|
|
@@ -17,6 +17,7 @@ import type {
|
|
|
17
17
|
} from './bconfig';
|
|
18
18
|
import {
|
|
19
19
|
downgradeCfgOrLambda,
|
|
20
|
+
isConfigLambda,
|
|
20
21
|
} from './bconfig';
|
|
21
22
|
|
|
22
23
|
type SectionsExpectedType = readonly BlockSection[];
|
|
@@ -117,6 +118,24 @@ export class BlockModel<
|
|
|
117
118
|
key: Key,
|
|
118
119
|
cfg: Cfg
|
|
119
120
|
): BlockModel<Args, OutputsCfg & { [K in Key]: Cfg }, UiState, Href>;
|
|
121
|
+
/**
|
|
122
|
+
* Add output cell wrapped with additional status information to the configuration
|
|
123
|
+
*
|
|
124
|
+
* @param key output cell name, that can be later used to retrieve the rendered value
|
|
125
|
+
* @param rf callback calculating output value using context, that allows to access
|
|
126
|
+
* workflows outputs and interact with platforma drivers
|
|
127
|
+
* @param flags additional flags that may alter lambda rendering procedure
|
|
128
|
+
* */
|
|
129
|
+
public output<const Key extends string, const RF extends RenderFunction<Args, UiState>>(
|
|
130
|
+
key: Key,
|
|
131
|
+
rf: RF,
|
|
132
|
+
flags: ConfigRenderLambdaFlags & { withStatus: true }
|
|
133
|
+
): BlockModel<
|
|
134
|
+
Args,
|
|
135
|
+
OutputsCfg & { [K in Key]: ConfigRenderLambda<InferRenderFunctionReturn<RF>> & { withStatus: true } },
|
|
136
|
+
UiState,
|
|
137
|
+
Href
|
|
138
|
+
>;
|
|
120
139
|
/**
|
|
121
140
|
* Add output cell to the configuration
|
|
122
141
|
*
|
|
@@ -169,15 +188,26 @@ export class BlockModel<
|
|
|
169
188
|
public retentiveOutput<const Key extends string, const RF extends RenderFunction<Args, UiState>>(
|
|
170
189
|
key: Key,
|
|
171
190
|
rf: RF,
|
|
172
|
-
)
|
|
173
|
-
Args,
|
|
174
|
-
OutputsCfg & { [K in Key]: ConfigRenderLambda<InferRenderFunctionReturn<RF>> },
|
|
175
|
-
UiState,
|
|
176
|
-
Href
|
|
177
|
-
> {
|
|
191
|
+
) {
|
|
178
192
|
return this.output(key, rf, { retentive: true });
|
|
179
193
|
}
|
|
180
194
|
|
|
195
|
+
/** Shortcut for {@link output} with withStatus flag set to true. */
|
|
196
|
+
public outputWithStatus<const Key extends string, const RF extends RenderFunction<Args, UiState>>(
|
|
197
|
+
key: Key,
|
|
198
|
+
rf: RF,
|
|
199
|
+
) {
|
|
200
|
+
return this.output(key, rf, { withStatus: true });
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
/** Shortcut for {@link output} with retentive and withStatus flags set to true. */
|
|
204
|
+
public retentiveOutputWithStatus<const Key extends string, const RF extends RenderFunction<Args, UiState>>(
|
|
205
|
+
key: Key,
|
|
206
|
+
rf: RF,
|
|
207
|
+
) {
|
|
208
|
+
return this.output(key, rf, { retentive: true, withStatus: true });
|
|
209
|
+
}
|
|
210
|
+
|
|
181
211
|
/** Sets custom configuration predicate on the block args at which block can be executed
|
|
182
212
|
* @deprecated use lambda-based API */
|
|
183
213
|
public argsValid<Cfg extends TypedConfig>(
|
|
@@ -339,41 +369,41 @@ export class BlockModel<
|
|
|
339
369
|
});
|
|
340
370
|
}
|
|
341
371
|
|
|
342
|
-
public done(apiVersion?: 1): PlatformaV1<
|
|
372
|
+
public done(apiVersion?: 1): PlatformaExtended<PlatformaV1<
|
|
343
373
|
Args,
|
|
344
374
|
InferOutputsFromConfigs<Args, OutputsCfg, UiState>,
|
|
345
375
|
UiState,
|
|
346
376
|
Href
|
|
347
|
-
|
|
377
|
+
>>;
|
|
348
378
|
|
|
349
|
-
public done(apiVersion: 2): PlatformaV2<
|
|
379
|
+
public done(apiVersion: 2): PlatformaExtended<PlatformaV2<
|
|
350
380
|
Args,
|
|
351
381
|
InferOutputsFromConfigs<Args, OutputsCfg, UiState>,
|
|
352
382
|
UiState,
|
|
353
383
|
Href
|
|
354
|
-
|
|
384
|
+
>>;
|
|
355
385
|
|
|
356
386
|
/** Renders all provided block settings into a pre-configured platforma API
|
|
357
387
|
* instance, that can be used in frontend to interact with block state, and
|
|
358
388
|
* other features provided by the platforma to the block. */
|
|
359
|
-
public done(apiVersion: PlatformaApiVersion = 1): Platforma<
|
|
389
|
+
public done(apiVersion: PlatformaApiVersion = 1): PlatformaExtended<Platforma<
|
|
360
390
|
Args,
|
|
361
391
|
InferOutputsFromConfigs<Args, OutputsCfg, UiState>,
|
|
362
392
|
UiState,
|
|
363
393
|
Href
|
|
364
|
-
|
|
394
|
+
>> {
|
|
365
395
|
return this.withFeatureFlags({
|
|
366
396
|
...this.config.featureFlags,
|
|
367
397
|
requiresUIAPIVersion: apiVersion,
|
|
368
398
|
}).#done();
|
|
369
399
|
}
|
|
370
400
|
|
|
371
|
-
#done(): Platforma<
|
|
401
|
+
#done(): PlatformaExtended<Platforma<
|
|
372
402
|
Args,
|
|
373
403
|
InferOutputsFromConfigs<Args, OutputsCfg, UiState>,
|
|
374
404
|
UiState,
|
|
375
405
|
Href
|
|
376
|
-
|
|
406
|
+
>> {
|
|
377
407
|
if (this.config.initialArgs === undefined) throw new Error('Initial arguments not set.');
|
|
378
408
|
|
|
379
409
|
const config: BlockConfigContainer = {
|
|
@@ -409,7 +439,17 @@ export class BlockModel<
|
|
|
409
439
|
// we are in the configuration rendering routine, not in actual UI
|
|
410
440
|
return { config } as any;
|
|
411
441
|
// normal operation inside the UI
|
|
412
|
-
else return
|
|
442
|
+
else return {
|
|
443
|
+
...getPlatformaInstance({ sdkVersion: PlatformaSDKVersion, apiVersion: platformaApiVersion }),
|
|
444
|
+
blockModelInfo: {
|
|
445
|
+
outputs: Object.fromEntries(
|
|
446
|
+
Object.entries(this.config.outputs)
|
|
447
|
+
.map(([key, value]) => [key, {
|
|
448
|
+
withStatus: Boolean(isConfigLambda(value) && value.withStatus),
|
|
449
|
+
}]),
|
|
450
|
+
),
|
|
451
|
+
},
|
|
452
|
+
};
|
|
413
453
|
}
|
|
414
454
|
}
|
|
415
455
|
|
|
@@ -424,5 +464,17 @@ type InferOutputsFromConfigs<
|
|
|
424
464
|
OutputsCfg extends Record<string, TypedConfigOrConfigLambda>,
|
|
425
465
|
UiState,
|
|
426
466
|
> = {
|
|
427
|
-
[Key in keyof OutputsCfg]:
|
|
467
|
+
[Key in keyof OutputsCfg]:
|
|
468
|
+
& OutputWithStatus<InferOutputType<OutputsCfg[Key], Args, UiState>>
|
|
469
|
+
& { __unwrap: (OutputsCfg[Key] extends { withStatus: true } ? false : true) };
|
|
470
|
+
};
|
|
471
|
+
|
|
472
|
+
export type PlatformaExtended<Pl extends Platforma = Platforma> = Pl & {
|
|
473
|
+
blockModelInfo: BlockModelInfo;
|
|
474
|
+
};
|
|
475
|
+
|
|
476
|
+
export type BlockModelInfo = {
|
|
477
|
+
outputs: Record<string, {
|
|
478
|
+
withStatus: boolean;
|
|
479
|
+
}>;
|
|
428
480
|
};
|
package/src/internal.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { OutputWithStatus } from '@milaboratories/pl-model-common';
|
|
2
2
|
import { } from './global';
|
|
3
3
|
import type { Platforma, PlatformaApiVersion } from './platforma';
|
|
4
4
|
import type { FutureHandle, GlobalCfgRenderCtx } from './render/internal';
|
|
@@ -13,7 +13,7 @@ export function isInUI() {
|
|
|
13
13
|
/** Utility code helping to retrieve a platforma instance form the environment */
|
|
14
14
|
export function getPlatformaInstance<
|
|
15
15
|
Args = unknown,
|
|
16
|
-
Outputs extends Record<string,
|
|
16
|
+
Outputs extends Record<string, OutputWithStatus<unknown>> = Record<string, OutputWithStatus<unknown>>,
|
|
17
17
|
UiState = unknown,
|
|
18
18
|
Href extends `/${string}` = `/${string}`,
|
|
19
19
|
>(config?: { sdkVersion: string; apiVersion: PlatformaApiVersion }): Platforma<Args, Outputs, UiState, Href> {
|
package/src/platforma.ts
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import type { BlockApiV1 } from './block_api_v1';
|
|
2
2
|
import type { BlockApiV2 } from './block_api_v2';
|
|
3
|
-
import type { BlockOutputsBase, BlockState, DriverKit,
|
|
3
|
+
import type { BlockOutputsBase, BlockState, DriverKit, OutputWithStatus } from '@milaboratories/pl-model-common';
|
|
4
4
|
import type { SdkInfo } from './sdk_info';
|
|
5
5
|
import type { BlockStatePatch } from './block_state_patch';
|
|
6
6
|
|
|
7
7
|
/** Defines all methods to interact with the platform environment from within a block UI. @deprecated */
|
|
8
8
|
export interface PlatformaV1<
|
|
9
9
|
Args = unknown,
|
|
10
|
-
Outputs extends Record<string,
|
|
10
|
+
Outputs extends Record<string, OutputWithStatus<unknown>> = Record<string, OutputWithStatus<unknown>>,
|
|
11
11
|
UiState = unknown,
|
|
12
12
|
Href extends `/${string}` = `/${string}`,
|
|
13
13
|
> extends BlockApiV1<Args, Outputs, UiState, Href>,
|
|
@@ -20,7 +20,7 @@ export interface PlatformaV1<
|
|
|
20
20
|
/** V2 version based on effective json patches pulling API */
|
|
21
21
|
export interface PlatformaV2<
|
|
22
22
|
Args = unknown,
|
|
23
|
-
Outputs extends Record<string,
|
|
23
|
+
Outputs extends Record<string, OutputWithStatus<unknown>> = Record<string, OutputWithStatus<unknown>>,
|
|
24
24
|
UiState = unknown,
|
|
25
25
|
Href extends `/${string}` = `/${string}`,
|
|
26
26
|
> extends BlockApiV2<Args, Outputs, UiState, Href>,
|
|
@@ -32,7 +32,7 @@ export interface PlatformaV2<
|
|
|
32
32
|
|
|
33
33
|
export type Platforma<
|
|
34
34
|
Args = unknown,
|
|
35
|
-
Outputs extends Record<string,
|
|
35
|
+
Outputs extends Record<string, OutputWithStatus<unknown>> = Record<string, OutputWithStatus<unknown>>,
|
|
36
36
|
UiState = unknown,
|
|
37
37
|
Href extends `/${string}` = `/${string}`,
|
|
38
38
|
> = PlatformaV1<Args, Outputs, UiState, Href> | PlatformaV2<Args, Outputs, UiState, Href>;
|
|
@@ -45,7 +45,7 @@ export type InferOutputsType<Pl extends Platforma> =
|
|
|
45
45
|
Pl extends Platforma<unknown, infer Outputs> ? Outputs : never;
|
|
46
46
|
|
|
47
47
|
export type InferUiState<Pl extends Platforma> =
|
|
48
|
-
Pl extends Platforma<unknown, Record<string,
|
|
48
|
+
Pl extends Platforma<unknown, Record<string, OutputWithStatus<unknown>>, infer UiState>
|
|
49
49
|
? UiState
|
|
50
50
|
: never;
|
|
51
51
|
|
package/src/raw_globals.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { OutputWithStatus } from '@milaboratories/pl-model-common';
|
|
2
2
|
import {} from './global';
|
|
3
3
|
import { getPlatformaInstance } from './internal';
|
|
4
4
|
import type { Platforma, PlatformaApiVersion } from './platforma';
|
|
@@ -10,7 +10,7 @@ export function getPlatformaApiVersion(): PlatformaApiVersion {
|
|
|
10
10
|
|
|
11
11
|
export function getRawPlatformaInstance<
|
|
12
12
|
Args = unknown,
|
|
13
|
-
Outputs extends Record<string,
|
|
13
|
+
Outputs extends Record<string, OutputWithStatus<unknown>> = Record<string, OutputWithStatus<unknown>>,
|
|
14
14
|
UiState = unknown,
|
|
15
15
|
Href extends `/${string}` = `/${string}`,
|
|
16
16
|
>(): Platforma<Args, Outputs, UiState, Href> {
|
package/src/typing.test.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import {
|
|
2
2
|
BlockSection,
|
|
3
3
|
LocalBlobHandleAndSize,
|
|
4
|
-
|
|
5
|
-
|
|
4
|
+
OutputWithStatus,
|
|
5
|
+
RemoteBlobHandleAndSize
|
|
6
6
|
} from '@milaboratories/pl-model-common';
|
|
7
7
|
import { expect, test } from 'vitest';
|
|
8
8
|
import { DeriveHref, StdCtx } from './bconfig';
|
|
@@ -117,8 +117,8 @@ test('test config content', () => {
|
|
|
117
117
|
assertType<
|
|
118
118
|
InferOutputsType<typeof platforma>,
|
|
119
119
|
{
|
|
120
|
-
cell1:
|
|
121
|
-
cell2:
|
|
120
|
+
cell1: OutputWithStatus<{ b: string[] }>;
|
|
121
|
+
cell2: OutputWithStatus<'v1'[]>;
|
|
122
122
|
}
|
|
123
123
|
>();
|
|
124
124
|
|
|
@@ -161,7 +161,7 @@ test('test config 2', () => {
|
|
|
161
161
|
assertType<
|
|
162
162
|
InferOutputsType<typeof platforma>,
|
|
163
163
|
{
|
|
164
|
-
cell1:
|
|
164
|
+
cell1: OutputWithStatus<{
|
|
165
165
|
b: string;
|
|
166
166
|
c: [Uint8Array, 'asd'];
|
|
167
167
|
d: string[];
|
|
@@ -169,8 +169,8 @@ test('test config 2', () => {
|
|
|
169
169
|
f: LocalBlobHandleAndSize;
|
|
170
170
|
g: RemoteBlobHandleAndSize;
|
|
171
171
|
}>;
|
|
172
|
-
cell2:
|
|
173
|
-
cell3:
|
|
172
|
+
cell2: OutputWithStatus<number>;
|
|
173
|
+
cell3: OutputWithStatus<undefined>;
|
|
174
174
|
}
|
|
175
175
|
>();
|
|
176
176
|
|