@platforma-sdk/model 1.8.19 → 1.9.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/container.d.ts +46 -0
- package/dist/bconfig/container.d.ts.map +1 -0
- package/dist/bconfig/index.d.ts +7 -0
- package/dist/bconfig/index.d.ts.map +1 -0
- package/dist/bconfig/lambdas.d.ts +33 -0
- package/dist/bconfig/lambdas.d.ts.map +1 -0
- package/dist/bconfig/normalization.d.ts +13 -0
- package/dist/bconfig/normalization.d.ts.map +1 -0
- package/dist/bconfig/types.d.ts +11 -0
- package/dist/bconfig/types.d.ts.map +1 -0
- package/dist/bconfig/utils.d.ts +7 -0
- package/dist/bconfig/utils.d.ts.map +1 -0
- package/dist/bconfig/v3.d.ts +30 -0
- package/dist/bconfig/v3.d.ts.map +1 -0
- package/dist/builder.d.ts +45 -65
- package/dist/builder.d.ts.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +428 -251
- package/dist/index.mjs.map +1 -1
- package/dist/internal.d.ts +3 -2
- package/dist/internal.d.ts.map +1 -1
- package/dist/platforma.d.ts +3 -2
- package/dist/platforma.d.ts.map +1 -1
- package/dist/raw_globals.d.ts.map +1 -1
- package/dist/render/accessor.d.ts +23 -0
- package/dist/render/accessor.d.ts.map +1 -1
- package/dist/render/api.d.ts +2 -0
- package/dist/render/api.d.ts.map +1 -1
- package/dist/render/internal.d.ts +4 -0
- package/dist/render/internal.d.ts.map +1 -1
- package/dist/version.d.ts +1 -1
- package/dist/version.d.ts.map +1 -1
- package/package.json +3 -3
- package/src/bconfig/container.ts +58 -0
- package/src/bconfig/index.ts +6 -0
- package/src/bconfig/lambdas.ts +44 -0
- package/src/bconfig/normalization.ts +120 -0
- package/src/bconfig/types.ts +18 -0
- package/src/bconfig/utils.ts +8 -0
- package/src/bconfig/v3.ts +46 -0
- package/src/builder.ts +165 -141
- package/src/global.d.ts +1 -1
- package/src/index.ts +1 -0
- package/src/internal.ts +1 -2
- package/src/platforma.ts +1 -2
- package/src/raw_globals.ts +2 -1
- package/src/render/accessor.ts +73 -0
- package/src/render/api.ts +22 -10
- package/src/render/internal.ts +12 -0
- package/src/typing.test.ts +5 -4
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@platforma-sdk/model",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.9.0",
|
|
4
4
|
"description": "Platforma.bio SDK / Block Model",
|
|
5
5
|
"types": "./dist/index.d.ts",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -20,11 +20,11 @@
|
|
|
20
20
|
"dependencies": {
|
|
21
21
|
"utility-types": "^3.11.0",
|
|
22
22
|
"zod": "^3.23.8",
|
|
23
|
-
"@milaboratories/pl-model-common": "^1.6.
|
|
23
|
+
"@milaboratories/pl-model-common": "^1.6.2"
|
|
24
24
|
},
|
|
25
25
|
"devDependencies": {
|
|
26
26
|
"typescript": "~5.5.4",
|
|
27
|
-
"vite": "^5.4.
|
|
27
|
+
"vite": "^5.4.11",
|
|
28
28
|
"@types/jest": "^29.5.14",
|
|
29
29
|
"jest": "^29.7.0",
|
|
30
30
|
"@jest/globals": "^29.7.0",
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { BlockRenderingMode } from '@milaboratories/pl-model-common';
|
|
2
|
+
import { Code, TypedConfigOrString } from './types';
|
|
3
|
+
import { BlockConfigV3 } from './v3';
|
|
4
|
+
|
|
5
|
+
/** Container simplifying maintenance of forward and backward compatibility */
|
|
6
|
+
export type BlockConfigContainer = {
|
|
7
|
+
/** Actual config */
|
|
8
|
+
readonly v3: Omit<BlockConfigV3, 'code'>;
|
|
9
|
+
|
|
10
|
+
/** Config code bundle */
|
|
11
|
+
readonly code?: Code;
|
|
12
|
+
|
|
13
|
+
//
|
|
14
|
+
// Fields below are used to read previous config versions
|
|
15
|
+
//
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* For backward compatibility
|
|
19
|
+
* @deprecated
|
|
20
|
+
*/
|
|
21
|
+
readonly sdkVersion?: string;
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* For backward compatibility
|
|
25
|
+
* @deprecated
|
|
26
|
+
*/
|
|
27
|
+
readonly renderingMode?: BlockRenderingMode;
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* For backward compatibility
|
|
31
|
+
* @deprecated
|
|
32
|
+
*/
|
|
33
|
+
readonly initialArgs?: unknown;
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* For backward compatibility
|
|
37
|
+
* @deprecated
|
|
38
|
+
*/
|
|
39
|
+
readonly canRun?: TypedConfigOrString;
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* For backward compatibility
|
|
43
|
+
* @deprecated
|
|
44
|
+
*/
|
|
45
|
+
readonly inputsValid?: TypedConfigOrString;
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* For backward compatibility
|
|
49
|
+
* @deprecated
|
|
50
|
+
*/
|
|
51
|
+
readonly sections?: TypedConfigOrString;
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* For backward compatibility
|
|
55
|
+
* @deprecated
|
|
56
|
+
*/
|
|
57
|
+
readonly outputs?: Record<string, TypedConfigOrString>;
|
|
58
|
+
};
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { ConfigResult, PlResourceEntry, TypedConfig } from '../config';
|
|
2
|
+
|
|
3
|
+
export type StdCtxArgsOnly<Args, UiState = undefined> = {
|
|
4
|
+
readonly $blockId: string;
|
|
5
|
+
readonly $args: Args;
|
|
6
|
+
readonly $ui: UiState;
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
export type StdCtx<Args, UiState = undefined> = StdCtxArgsOnly<Args, UiState> & {
|
|
10
|
+
readonly $prod: PlResourceEntry;
|
|
11
|
+
readonly $staging: PlResourceEntry;
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
export type ResolveCfgType<Cfg extends TypedConfig, Args, UiState = undefined> = ConfigResult<
|
|
15
|
+
Cfg,
|
|
16
|
+
StdCtx<Args, UiState>
|
|
17
|
+
>;
|
|
18
|
+
|
|
19
|
+
/** Additional information that may alter lambda rendering procedure. */
|
|
20
|
+
export type ConfigRenderLambdaFlags = {
|
|
21
|
+
/**
|
|
22
|
+
* Tells the system that corresponding computable should be created with StableOnlyRetentive rendering mode.
|
|
23
|
+
* This flag can be overriden by the system.
|
|
24
|
+
* */
|
|
25
|
+
retentive?: boolean;
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Tells the system that resulting computable has important side-effects, thus it's rendering is required even
|
|
29
|
+
* nobody is actively monitoring rendered values. Like file upload progress, that triggers upload itself.
|
|
30
|
+
* */
|
|
31
|
+
isActive?: boolean;
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
/** Creates branded Cfg type */
|
|
35
|
+
export interface ConfigRenderLambda<Return = unknown> extends ConfigRenderLambdaFlags {
|
|
36
|
+
/** Type marker */
|
|
37
|
+
__renderLambda: true;
|
|
38
|
+
|
|
39
|
+
/** Reference to a callback registered inside the model code. */
|
|
40
|
+
handle: string;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export type ExtractFunctionHandleReturn<Func extends ConfigRenderLambda> =
|
|
44
|
+
Func extends ConfigRenderLambda<infer Return> ? Return : never;
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
import { BlockConfigContainer } from './container';
|
|
2
|
+
import { isConfigLambda, TypedConfigOrConfigLambda, TypedConfigOrString } from './types';
|
|
3
|
+
import { BlockConfig } from './v3';
|
|
4
|
+
|
|
5
|
+
export function downgradeCfgOrLambda(data: TypedConfigOrConfigLambda): TypedConfigOrString;
|
|
6
|
+
export function downgradeCfgOrLambda(
|
|
7
|
+
data: TypedConfigOrConfigLambda | undefined
|
|
8
|
+
): TypedConfigOrString | undefined;
|
|
9
|
+
export function downgradeCfgOrLambda(
|
|
10
|
+
data: TypedConfigOrConfigLambda | undefined
|
|
11
|
+
): TypedConfigOrString | undefined {
|
|
12
|
+
if (data === undefined) return undefined;
|
|
13
|
+
if (isConfigLambda(data)) return data.handle;
|
|
14
|
+
return data;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
function upgradeCfgOrLambda(data: TypedConfigOrString): TypedConfigOrConfigLambda;
|
|
18
|
+
function upgradeCfgOrLambda(
|
|
19
|
+
data: TypedConfigOrString | undefined
|
|
20
|
+
): TypedConfigOrConfigLambda | undefined;
|
|
21
|
+
function upgradeCfgOrLambda(
|
|
22
|
+
data: TypedConfigOrString | undefined
|
|
23
|
+
): TypedConfigOrConfigLambda | undefined {
|
|
24
|
+
if (data === undefined) return undefined;
|
|
25
|
+
if (typeof data === 'string') return { __renderLambda: true, handle: data, retentive: false };
|
|
26
|
+
return data;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Takes universal config, and converts it into latest config structure.
|
|
31
|
+
*
|
|
32
|
+
* **Important**: This operation is not meant to be executed recusively.
|
|
33
|
+
* In no circumstance result of this function should be persisted!
|
|
34
|
+
* */
|
|
35
|
+
export function extractConfig(cfg: BlockConfigContainer): BlockConfig {
|
|
36
|
+
if (cfg.v3 !== undefined) {
|
|
37
|
+
// version 3
|
|
38
|
+
const {
|
|
39
|
+
initialArgs,
|
|
40
|
+
initialUiState,
|
|
41
|
+
inputsValid,
|
|
42
|
+
outputs,
|
|
43
|
+
renderingMode,
|
|
44
|
+
sdkVersion,
|
|
45
|
+
sections,
|
|
46
|
+
title
|
|
47
|
+
} = cfg.v3;
|
|
48
|
+
const { code } = cfg;
|
|
49
|
+
return {
|
|
50
|
+
initialArgs,
|
|
51
|
+
initialUiState,
|
|
52
|
+
inputsValid,
|
|
53
|
+
outputs,
|
|
54
|
+
renderingMode,
|
|
55
|
+
sdkVersion,
|
|
56
|
+
sections,
|
|
57
|
+
title,
|
|
58
|
+
code
|
|
59
|
+
};
|
|
60
|
+
} else if (cfg.inputsValid !== undefined) {
|
|
61
|
+
// version 2
|
|
62
|
+
const { sdkVersion, renderingMode, outputs, inputsValid, sections, initialArgs, code } = cfg;
|
|
63
|
+
const fields = Object.keys(cfg);
|
|
64
|
+
if (
|
|
65
|
+
sdkVersion === undefined ||
|
|
66
|
+
renderingMode === undefined ||
|
|
67
|
+
outputs === undefined ||
|
|
68
|
+
inputsValid === undefined ||
|
|
69
|
+
sections === undefined ||
|
|
70
|
+
initialArgs === undefined
|
|
71
|
+
)
|
|
72
|
+
throw new Error(
|
|
73
|
+
`Malformed config v2. SDK version ${sdkVersion}; Fields = ${fields.join(', ')}`
|
|
74
|
+
);
|
|
75
|
+
return {
|
|
76
|
+
sdkVersion,
|
|
77
|
+
renderingMode,
|
|
78
|
+
initialArgs,
|
|
79
|
+
outputs: Object.fromEntries(
|
|
80
|
+
Object.entries(outputs).map(([key, value]) => [key, upgradeCfgOrLambda(value)])
|
|
81
|
+
),
|
|
82
|
+
inputsValid: upgradeCfgOrLambda(inputsValid),
|
|
83
|
+
sections: upgradeCfgOrLambda(sections),
|
|
84
|
+
initialUiState: undefined,
|
|
85
|
+
code
|
|
86
|
+
};
|
|
87
|
+
} else if (cfg.renderingMode !== undefined) {
|
|
88
|
+
// version 1
|
|
89
|
+
const { sdkVersion, canRun, renderingMode, outputs, sections, initialArgs, code } = cfg;
|
|
90
|
+
const fields = Object.keys(cfg);
|
|
91
|
+
if (
|
|
92
|
+
renderingMode === undefined ||
|
|
93
|
+
outputs === undefined ||
|
|
94
|
+
canRun === undefined ||
|
|
95
|
+
sections === undefined ||
|
|
96
|
+
initialArgs === undefined
|
|
97
|
+
)
|
|
98
|
+
throw new Error(
|
|
99
|
+
`Malformed config v1. SDK version ${sdkVersion}; Fields = ${fields.join(', ')}`
|
|
100
|
+
);
|
|
101
|
+
return {
|
|
102
|
+
sdkVersion: sdkVersion ?? 'unknown',
|
|
103
|
+
renderingMode,
|
|
104
|
+
initialArgs,
|
|
105
|
+
outputs: Object.fromEntries(
|
|
106
|
+
Object.entries(outputs).map(([key, value]) => [key, upgradeCfgOrLambda(value)])
|
|
107
|
+
),
|
|
108
|
+
inputsValid: upgradeCfgOrLambda(canRun),
|
|
109
|
+
sections: upgradeCfgOrLambda(sections),
|
|
110
|
+
initialUiState: undefined,
|
|
111
|
+
code
|
|
112
|
+
};
|
|
113
|
+
} else {
|
|
114
|
+
const { sdkVersion } = cfg;
|
|
115
|
+
const fields = Object.keys(cfg);
|
|
116
|
+
throw new Error(
|
|
117
|
+
`Config format not supported: SDK = ${sdkVersion}; Fields = ${fields.join(', ')}`
|
|
118
|
+
);
|
|
119
|
+
}
|
|
120
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { TypedConfig } from '../config';
|
|
2
|
+
import { ConfigRenderLambda } from './lambdas';
|
|
3
|
+
|
|
4
|
+
export type Code = {
|
|
5
|
+
type: 'plain';
|
|
6
|
+
content: string;
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
export function isConfigLambda(
|
|
10
|
+
cfgOrFh: TypedConfigOrConfigLambda
|
|
11
|
+
): cfgOrFh is ConfigRenderLambda {
|
|
12
|
+
return (cfgOrFh as any).__renderLambda === true;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export type TypedConfigOrConfigLambda = TypedConfig | ConfigRenderLambda;
|
|
16
|
+
|
|
17
|
+
/** @deprecated */
|
|
18
|
+
export type TypedConfigOrString = TypedConfig | string;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { BlockSection } from "@milaboratories/pl-model-common";
|
|
2
|
+
|
|
3
|
+
type OnlyString<S> = S extends string ? S : '';
|
|
4
|
+
|
|
5
|
+
// prettier-ignore
|
|
6
|
+
export type DeriveHref<S> = S extends readonly BlockSection[]
|
|
7
|
+
? OnlyString<Extract<S[number], { type: 'link' }>['href']>
|
|
8
|
+
: never;
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { BlockRenderingMode } from '@milaboratories/pl-model-common';
|
|
2
|
+
import { Code, TypedConfigOrConfigLambda } from './types';
|
|
3
|
+
import { ConfigRenderLambda } from './lambdas';
|
|
4
|
+
|
|
5
|
+
export type BlockConfigV3<
|
|
6
|
+
Args = unknown,
|
|
7
|
+
UiState = unknown,
|
|
8
|
+
Outputs extends Record<string, TypedConfigOrConfigLambda> = Record<
|
|
9
|
+
string,
|
|
10
|
+
TypedConfigOrConfigLambda
|
|
11
|
+
>
|
|
12
|
+
> = {
|
|
13
|
+
/** SDK version used by the block */
|
|
14
|
+
readonly sdkVersion: string;
|
|
15
|
+
|
|
16
|
+
/** Main rendering mode for the block */
|
|
17
|
+
readonly renderingMode: BlockRenderingMode;
|
|
18
|
+
|
|
19
|
+
/** Initial value for the args when block is added to the project */
|
|
20
|
+
readonly initialArgs: Args;
|
|
21
|
+
|
|
22
|
+
/** Initial value for the args when block is added to the project */
|
|
23
|
+
readonly initialUiState: UiState;
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Config to determine whether the block can be executed with current
|
|
27
|
+
* arguments.
|
|
28
|
+
*
|
|
29
|
+
* Optional to support earlier SDK version configs.
|
|
30
|
+
* */
|
|
31
|
+
readonly inputsValid: TypedConfigOrConfigLambda;
|
|
32
|
+
|
|
33
|
+
/** Configuration to derive list of section for the left overview panel */
|
|
34
|
+
readonly sections: TypedConfigOrConfigLambda;
|
|
35
|
+
|
|
36
|
+
/** Lambda to derive block title */
|
|
37
|
+
readonly title?: ConfigRenderLambda;
|
|
38
|
+
|
|
39
|
+
/** Configuration for the output cells */
|
|
40
|
+
readonly outputs: Outputs;
|
|
41
|
+
|
|
42
|
+
/** Config code bundle */
|
|
43
|
+
readonly code?: Code;
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
export type BlockConfig = BlockConfigV3;
|