@platforma-sdk/model 1.40.6 → 1.41.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/{block_api.d.ts → block_api_v1.d.ts} +3 -3
- package/dist/block_api_v1.d.ts.map +1 -0
- package/dist/block_api_v2.d.ts +50 -0
- package/dist/block_api_v2.d.ts.map +1 -0
- package/dist/builder.d.ts +6 -5
- package/dist/builder.d.ts.map +1 -1
- package/dist/index.d.ts +2 -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 +174 -157
- package/dist/index.mjs.map +1 -1
- package/dist/internal.d.ts +2 -1
- package/dist/internal.d.ts.map +1 -1
- package/dist/platforma.d.ts +13 -3
- package/dist/platforma.d.ts.map +1 -1
- package/dist/raw_globals.d.ts +2 -2
- package/dist/raw_globals.d.ts.map +1 -1
- package/dist/version.d.ts +1 -1
- package/package.json +5 -4
- package/src/{block_api.ts → block_api_v1.ts} +2 -2
- package/src/block_api_v2.ts +69 -0
- package/src/builder.ts +48 -4
- package/src/global.d.ts +4 -1
- package/src/index.ts +2 -0
- package/src/internal.ts +2 -2
- package/src/platforma.ts +28 -4
- package/src/raw_globals.ts +18 -14
- package/dist/block_api.d.ts.map +0 -1
package/dist/internal.d.ts
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import { ValueOrErrors } from '@milaboratories/pl-model-common';
|
|
2
|
-
import { Platforma } from './platforma';
|
|
2
|
+
import { Platforma, PlatformaApiVersion } from './platforma';
|
|
3
3
|
import { 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
7
|
export declare function getPlatformaInstance<Args = unknown, Outputs extends Record<string, ValueOrErrors<unknown>> = Record<string, ValueOrErrors<unknown>>, UiState = unknown, Href extends `/${string}` = `/${string}`>(config?: {
|
|
8
8
|
sdkVersion: string;
|
|
9
|
+
apiVersion: PlatformaApiVersion;
|
|
9
10
|
}): Platforma<Args, Outputs, UiState, Href>;
|
|
10
11
|
export declare function tryGetCfgRenderCtx(): GlobalCfgRenderCtx | undefined;
|
|
11
12
|
export declare function getCfgRenderCtx(): GlobalCfgRenderCtx;
|
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,aAAa,EAAE,MAAM,iCAAiC,CAAC;AAErE,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"internal.d.ts","sourceRoot":"","sources":["../src/internal.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,iCAAiC,CAAC;AAErE,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,aAAa,CAAC,OAAO,CAAC,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,aAAa,CAAC,OAAO,CAAC,CAAC,EAC/F,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/platforma.d.ts
CHANGED
|
@@ -1,12 +1,22 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { BlockApiV1 } from './block_api_v1';
|
|
2
|
+
import { BlockApiV2 } from './block_api_v2';
|
|
2
3
|
import { BlockOutputsBase, BlockState, DriverKit, ValueOrErrors } from '@milaboratories/pl-model-common';
|
|
3
4
|
import { SdkInfo } from './sdk_info';
|
|
4
5
|
import { BlockStatePatch } from './block_state_patch';
|
|
5
|
-
/** Defines all methods to interact with the platform environment from within a block UI. */
|
|
6
|
-
export interface
|
|
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, ValueOrErrors<unknown>> = Record<string, ValueOrErrors<unknown>>, UiState = unknown, Href extends `/${string}` = `/${string}`> extends BlockApiV1<Args, Outputs, UiState, Href>, DriverKit {
|
|
7
8
|
/** Information about SDK version current platforma environment was compiled with. */
|
|
8
9
|
readonly sdkInfo: SdkInfo;
|
|
10
|
+
readonly apiVersion?: 1;
|
|
9
11
|
}
|
|
12
|
+
/** V2 version based on effective json patches pulling API */
|
|
13
|
+
export interface PlatformaV2<Args = unknown, Outputs extends Record<string, ValueOrErrors<unknown>> = Record<string, ValueOrErrors<unknown>>, UiState = unknown, Href extends `/${string}` = `/${string}`> extends BlockApiV2<Args, Outputs, UiState, Href>, DriverKit {
|
|
14
|
+
/** Information about SDK version current platforma environment was compiled with. */
|
|
15
|
+
readonly sdkInfo: SdkInfo;
|
|
16
|
+
readonly apiVersion: 2;
|
|
17
|
+
}
|
|
18
|
+
export type Platforma<Args = unknown, Outputs extends Record<string, ValueOrErrors<unknown>> = Record<string, ValueOrErrors<unknown>>, UiState = unknown, Href extends `/${string}` = `/${string}`> = PlatformaV1<Args, Outputs, UiState, Href> | PlatformaV2<Args, Outputs, UiState, Href>;
|
|
19
|
+
export type PlatformaApiVersion = Platforma['apiVersion'];
|
|
10
20
|
export type InferArgsType<Pl extends Platforma> = Pl extends Platforma<infer Args> ? Args : never;
|
|
11
21
|
export type InferOutputsType<Pl extends Platforma> = Pl extends Platforma<unknown, infer Outputs> ? Outputs : never;
|
|
12
22
|
export type InferUiState<Pl extends Platforma> = Pl extends Platforma<unknown, Record<string, ValueOrErrors<unknown>>, infer UiState> ? UiState : never;
|
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,
|
|
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,aAAa,EAAE,MAAM,iCAAiC,CAAC;AAC9G,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,aAAa,CAAC,OAAO,CAAC,CAAC,GAAG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@@
|
|
|
1
1
|
import { ValueOrErrors } from '@milaboratories/pl-model-common';
|
|
2
|
-
import { Platforma } from './platforma';
|
|
2
|
+
import { Platforma, PlatformaApiVersion } from './platforma';
|
|
3
|
+
export declare function getPlatformaApiVersion(): PlatformaApiVersion;
|
|
3
4
|
export declare function getRawPlatformaInstance<Args = unknown, Outputs extends Record<string, ValueOrErrors<unknown>> = Record<string, ValueOrErrors<unknown>>, UiState = unknown, Href extends `/${string}` = `/${string}`>(): Platforma<Args, Outputs, UiState, Href>;
|
|
4
5
|
/** Returns a global platforma instance or a provided fallback if it's not available. */
|
|
5
|
-
export declare function getPlatformaOrDefault<Args = unknown, Outputs extends Record<string, ValueOrErrors<unknown>> = Record<string, ValueOrErrors<unknown>>, UiState = unknown, Href extends `/${string}` = `/${string}`>(platforma: Platforma<Args, Outputs, UiState, Href>): Platforma<Args, Outputs, UiState, Href>;
|
|
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,aAAa,EAAE,MAAM,iCAAiC,CAAC;AAGrE,OAAO,KAAK,EAAE,SAAS,EAAE,
|
|
1
|
+
{"version":3,"file":"raw_globals.d.ts","sourceRoot":"","sources":["../src/raw_globals.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,iCAAiC,CAAC;AAGrE,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,aAAa,CAAC,OAAO,CAAC,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,aAAa,CAAC,OAAO,CAAC,CAAC,EAC/F,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/version.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export declare const PlatformaSDKVersion = "1.
|
|
1
|
+
export declare const PlatformaSDKVersion = "1.41.0";
|
|
2
2
|
//# sourceMappingURL=version.d.ts.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@platforma-sdk/model",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.41.0",
|
|
4
4
|
"description": "Platforma.bio SDK / Block Model",
|
|
5
5
|
"types": "./dist/index.d.ts",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
"utility-types": "^3.11.0",
|
|
23
23
|
"canonicalize": "~2.1.0",
|
|
24
24
|
"zod": "~3.23.8",
|
|
25
|
-
"@milaboratories/pl-model-common": "^1.
|
|
25
|
+
"@milaboratories/pl-model-common": "^1.17.0",
|
|
26
26
|
"@milaboratories/pl-error-like": "^1.12.2"
|
|
27
27
|
},
|
|
28
28
|
"devDependencies": {
|
|
@@ -32,9 +32,10 @@
|
|
|
32
32
|
"jest": "^29.7.0",
|
|
33
33
|
"@jest/globals": "^29.7.0",
|
|
34
34
|
"ts-jest": "^29.2.6",
|
|
35
|
+
"fast-json-patch": "^3.1.1",
|
|
36
|
+
"@milaboratories/helpers": "^1.6.18",
|
|
35
37
|
"@platforma-sdk/eslint-config": "1.0.3",
|
|
36
|
-
"@milaboratories/build-configs": "1.0.4"
|
|
37
|
-
"@milaboratories/helpers": "^1.6.18"
|
|
38
|
+
"@milaboratories/build-configs": "1.0.4"
|
|
38
39
|
},
|
|
39
40
|
"scripts": {
|
|
40
41
|
"type-check": "node ./scripts/save-package-version.cjs && tsc --noEmit --composite false",
|
|
@@ -5,7 +5,7 @@ import type { BlockStatePatch } from './block_state_patch';
|
|
|
5
5
|
export type CancelSubscription = () => void;
|
|
6
6
|
|
|
7
7
|
/** Defines methods to read and write current block data. */
|
|
8
|
-
export interface
|
|
8
|
+
export interface BlockApiV1<
|
|
9
9
|
Args = unknown,
|
|
10
10
|
Outputs extends BlockOutputsBase = BlockOutputsBase,
|
|
11
11
|
UiState = unknown,
|
|
@@ -69,7 +69,7 @@ export interface BlockApi<
|
|
|
69
69
|
setBlockArgsAndUiState(args: Args, state: UiState): Promise<void>;
|
|
70
70
|
|
|
71
71
|
/**
|
|
72
|
-
* Sets block
|
|
72
|
+
* Sets block navigation state.
|
|
73
73
|
* */
|
|
74
74
|
setNavigationState(state: NavigationState<Href>): Promise<void>;
|
|
75
75
|
}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
BlockOutputsBase,
|
|
3
|
+
BlockState,
|
|
4
|
+
NavigationState,
|
|
5
|
+
ValueWithUTag,
|
|
6
|
+
ValueWithUTagAndAuthor,
|
|
7
|
+
AuthorMarker,
|
|
8
|
+
ResultOrError,
|
|
9
|
+
} from '@milaboratories/pl-model-common';
|
|
10
|
+
import type { Operation } from 'fast-json-patch';
|
|
11
|
+
|
|
12
|
+
/** Defines methods to read and write current block data. */
|
|
13
|
+
export interface BlockApiV2<
|
|
14
|
+
Args = unknown,
|
|
15
|
+
Outputs extends BlockOutputsBase = BlockOutputsBase,
|
|
16
|
+
UiState = unknown,
|
|
17
|
+
Href extends `/${string}` = `/${string}`,
|
|
18
|
+
> {
|
|
19
|
+
/**
|
|
20
|
+
* Use this method to retrieve block state during UI initialization. Then use
|
|
21
|
+
* {@link onStateUpdates} method to subscribe for updates.
|
|
22
|
+
* */
|
|
23
|
+
loadBlockState(): Promise<ResultOrError<ValueWithUTag<BlockState<Args, Outputs, UiState, Href>>>>;
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Get all json patches (rfc6902) that were applied to the block state.
|
|
27
|
+
* */
|
|
28
|
+
getPatches(uTag: string): Promise<ResultOrError<ValueWithUTagAndAuthor<Operation[]>>>;
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Sets block args.
|
|
32
|
+
*
|
|
33
|
+
* This method returns when corresponding arguments are safely saved so in
|
|
34
|
+
* case the window is closed there will be no information losses. This
|
|
35
|
+
* function under the hood may delay actual persistence of the supplied
|
|
36
|
+
* arguments.
|
|
37
|
+
* */
|
|
38
|
+
setBlockArgs(args: Args, author?: AuthorMarker): Promise<ResultOrError<void>>;
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Sets block ui state.
|
|
42
|
+
*
|
|
43
|
+
* This method returns when corresponding arguments are safely saved so in
|
|
44
|
+
* case the window is closed there will be no information losses. This
|
|
45
|
+
* function under the hood may delay actual persistence of the supplied
|
|
46
|
+
* values.
|
|
47
|
+
* */
|
|
48
|
+
setBlockUiState(state: UiState, author?: AuthorMarker): Promise<ResultOrError<void>>;
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Sets block args and ui state.
|
|
52
|
+
*
|
|
53
|
+
* This method returns when corresponding arguments are safely saved so in
|
|
54
|
+
* case the window is closed there will be no information losses. This
|
|
55
|
+
* function under the hood may delay actual persistence of the supplied
|
|
56
|
+
* values.
|
|
57
|
+
* */
|
|
58
|
+
setBlockArgsAndUiState(args: Args, state: UiState, author?: AuthorMarker): Promise<ResultOrError<void>>;
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Sets block navigation state.
|
|
62
|
+
* */
|
|
63
|
+
setNavigationState(state: NavigationState<Href>): Promise<ResultOrError<void>>;
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* Disposes the block API.
|
|
67
|
+
* */
|
|
68
|
+
dispose(): Promise<ResultOrError<void>>;
|
|
69
|
+
}
|
package/src/builder.ts
CHANGED
|
@@ -2,7 +2,7 @@ import type { BlockRenderingMode, BlockSection, ValueOrErrors, AnyFunction, PlRe
|
|
|
2
2
|
import type { Checked, ConfigResult, TypedConfig } from './config';
|
|
3
3
|
import { getImmediate } from './config';
|
|
4
4
|
import { getPlatformaInstance, isInUI, tryRegisterCallback } from './internal';
|
|
5
|
-
import type { Platforma } from './platforma';
|
|
5
|
+
import type { Platforma, PlatformaApiVersion, PlatformaV1, PlatformaV2 } from './platforma';
|
|
6
6
|
import type { InferRenderFunctionReturn, RenderFunction } from './render';
|
|
7
7
|
import { RenderCtx } from './render';
|
|
8
8
|
import { PlatformaSDKVersion } from './version';
|
|
@@ -346,6 +346,21 @@ export class BlockModel<
|
|
|
346
346
|
);
|
|
347
347
|
}
|
|
348
348
|
|
|
349
|
+
/** Sets or overrides feature flags for the block. */
|
|
350
|
+
public withFeatureFlags(flags: Partial<BlockCodeKnownFeatureFlags>): BlockModel<Args, OutputsCfg, UiState, Href> {
|
|
351
|
+
return new BlockModel<Args, OutputsCfg, UiState, Href>(
|
|
352
|
+
this._renderingMode,
|
|
353
|
+
this._initialArgs,
|
|
354
|
+
this._initialUiState,
|
|
355
|
+
this._outputs,
|
|
356
|
+
this._inputsValid,
|
|
357
|
+
this._sections,
|
|
358
|
+
this._title,
|
|
359
|
+
this._enrichmentTargets,
|
|
360
|
+
{ ...this._featureFlags, ...flags },
|
|
361
|
+
);
|
|
362
|
+
}
|
|
363
|
+
|
|
349
364
|
/**
|
|
350
365
|
* Defines how to derive list of upstream references this block is meant to enrich with its exports from block args.
|
|
351
366
|
* Influences dependency graph construction.
|
|
@@ -367,10 +382,37 @@ export class BlockModel<
|
|
|
367
382
|
);
|
|
368
383
|
}
|
|
369
384
|
|
|
385
|
+
public done(apiVersion?: 1): PlatformaV1<
|
|
386
|
+
Args,
|
|
387
|
+
InferOutputsFromConfigs<Args, OutputsCfg, UiState>,
|
|
388
|
+
UiState,
|
|
389
|
+
Href
|
|
390
|
+
>;
|
|
391
|
+
|
|
392
|
+
public done(apiVersion: 2): PlatformaV2<
|
|
393
|
+
Args,
|
|
394
|
+
InferOutputsFromConfigs<Args, OutputsCfg, UiState>,
|
|
395
|
+
UiState,
|
|
396
|
+
Href
|
|
397
|
+
>;
|
|
398
|
+
|
|
370
399
|
/** Renders all provided block settings into a pre-configured platforma API
|
|
371
400
|
* instance, that can be used in frontend to interact with block state, and
|
|
372
401
|
* other features provided by the platforma to the block. */
|
|
373
|
-
public done(): Platforma<
|
|
402
|
+
public done(apiVersion?: PlatformaApiVersion): Platforma<
|
|
403
|
+
Args,
|
|
404
|
+
InferOutputsFromConfigs<Args, OutputsCfg, UiState>,
|
|
405
|
+
UiState,
|
|
406
|
+
Href
|
|
407
|
+
> {
|
|
408
|
+
const requiresUIAPIVersion = apiVersion ?? 1;
|
|
409
|
+
return this.withFeatureFlags({
|
|
410
|
+
...this._featureFlags,
|
|
411
|
+
requiresUIAPIVersion,
|
|
412
|
+
})._done(requiresUIAPIVersion);
|
|
413
|
+
}
|
|
414
|
+
|
|
415
|
+
public _done(apiVersion: PlatformaApiVersion): Platforma<
|
|
374
416
|
Args,
|
|
375
417
|
InferOutputsFromConfigs<Args, OutputsCfg, UiState>,
|
|
376
418
|
UiState,
|
|
@@ -403,11 +445,13 @@ export class BlockModel<
|
|
|
403
445
|
),
|
|
404
446
|
};
|
|
405
447
|
|
|
448
|
+
globalThis.platformaApiVersion = apiVersion;
|
|
449
|
+
|
|
406
450
|
if (!isInUI())
|
|
407
|
-
|
|
451
|
+
// we are in the configuration rendering routine, not in actual UI
|
|
408
452
|
return { config } as any;
|
|
409
453
|
// normal operation inside the UI
|
|
410
|
-
else return getPlatformaInstance({ sdkVersion: PlatformaSDKVersion }) as any;
|
|
454
|
+
else return getPlatformaInstance({ sdkVersion: PlatformaSDKVersion, apiVersion: platformaApiVersion }) as any;
|
|
411
455
|
}
|
|
412
456
|
}
|
|
413
457
|
|
package/src/global.d.ts
CHANGED
|
@@ -1,7 +1,10 @@
|
|
|
1
|
+
import type { PlatformaApiVersion } from './platforma';
|
|
2
|
+
|
|
1
3
|
declare global {
|
|
2
4
|
/** Global factory method returning platforma instance */
|
|
3
|
-
var getPlatforma: PlatformaSDKVersion;
|
|
5
|
+
var getPlatforma: PlatformaSDKVersion; // TODO: invalid type
|
|
4
6
|
var platforma: Platforma;
|
|
7
|
+
var platformaApiVersion: PlatformaApiVersion;
|
|
5
8
|
|
|
6
9
|
function getEnvironmentValue(name: string): string | undefined;
|
|
7
10
|
|
package/src/index.ts
CHANGED
|
@@ -10,6 +10,8 @@ export * from './ref_util';
|
|
|
10
10
|
export * from './render';
|
|
11
11
|
export * from './sdk_info';
|
|
12
12
|
export * from './raw_globals';
|
|
13
|
+
export * from './block_api_v1';
|
|
14
|
+
export * from './block_api_v2';
|
|
13
15
|
|
|
14
16
|
// reexporting everything from SDK model
|
|
15
17
|
export * from '@milaboratories/pl-model-common';
|
package/src/internal.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { ValueOrErrors } from '@milaboratories/pl-model-common';
|
|
2
2
|
import {} from './global';
|
|
3
|
-
import type { Platforma } from './platforma';
|
|
3
|
+
import type { Platforma, PlatformaApiVersion } from './platforma';
|
|
4
4
|
import type { FutureHandle, GlobalCfgRenderCtx } from './render/internal';
|
|
5
5
|
|
|
6
6
|
/** Utility code helping to identify whether the code is running in actual UI environment */
|
|
@@ -16,7 +16,7 @@ export function getPlatformaInstance<
|
|
|
16
16
|
Outputs extends Record<string, ValueOrErrors<unknown>> = Record<string, ValueOrErrors<unknown>>,
|
|
17
17
|
UiState = unknown,
|
|
18
18
|
Href extends `/${string}` = `/${string}`,
|
|
19
|
-
>(config?: { sdkVersion: string }): Platforma<Args, Outputs, UiState, Href> {
|
|
19
|
+
>(config?: { sdkVersion: string; apiVersion: PlatformaApiVersion }): Platforma<Args, Outputs, UiState, Href> {
|
|
20
20
|
if (config && typeof globalThis.getPlatforma === 'function')
|
|
21
21
|
return globalThis.getPlatforma(config);
|
|
22
22
|
else if (typeof globalThis.platforma !== 'undefined') return globalThis.platforma;
|
package/src/platforma.ts
CHANGED
|
@@ -1,20 +1,44 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { BlockApiV1 } from './block_api_v1';
|
|
2
|
+
import type { BlockApiV2 } from './block_api_v2';
|
|
2
3
|
import type { BlockOutputsBase, BlockState, DriverKit, ValueOrErrors } from '@milaboratories/pl-model-common';
|
|
3
4
|
import type { SdkInfo } from './sdk_info';
|
|
4
5
|
import type { BlockStatePatch } from './block_state_patch';
|
|
5
6
|
|
|
6
|
-
/** Defines all methods to interact with the platform environment from within a block UI. */
|
|
7
|
-
export interface
|
|
7
|
+
/** Defines all methods to interact with the platform environment from within a block UI. @deprecated */
|
|
8
|
+
export interface PlatformaV1<
|
|
8
9
|
Args = unknown,
|
|
9
10
|
Outputs extends Record<string, ValueOrErrors<unknown>> = Record<string, ValueOrErrors<unknown>>,
|
|
10
11
|
UiState = unknown,
|
|
11
12
|
Href extends `/${string}` = `/${string}`,
|
|
12
|
-
> extends
|
|
13
|
+
> extends BlockApiV1<Args, Outputs, UiState, Href>,
|
|
13
14
|
DriverKit {
|
|
14
15
|
/** Information about SDK version current platforma environment was compiled with. */
|
|
15
16
|
readonly sdkInfo: SdkInfo;
|
|
17
|
+
readonly apiVersion?: 1;
|
|
16
18
|
}
|
|
17
19
|
|
|
20
|
+
/** V2 version based on effective json patches pulling API */
|
|
21
|
+
export interface PlatformaV2<
|
|
22
|
+
Args = unknown,
|
|
23
|
+
Outputs extends Record<string, ValueOrErrors<unknown>> = Record<string, ValueOrErrors<unknown>>,
|
|
24
|
+
UiState = unknown,
|
|
25
|
+
Href extends `/${string}` = `/${string}`,
|
|
26
|
+
> extends BlockApiV2<Args, Outputs, UiState, Href>,
|
|
27
|
+
DriverKit {
|
|
28
|
+
/** Information about SDK version current platforma environment was compiled with. */
|
|
29
|
+
readonly sdkInfo: SdkInfo;
|
|
30
|
+
readonly apiVersion: 2;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export type Platforma<
|
|
34
|
+
Args = unknown,
|
|
35
|
+
Outputs extends Record<string, ValueOrErrors<unknown>> = Record<string, ValueOrErrors<unknown>>,
|
|
36
|
+
UiState = unknown,
|
|
37
|
+
Href extends `/${string}` = `/${string}`,
|
|
38
|
+
> = PlatformaV1<Args, Outputs, UiState, Href> | PlatformaV2<Args, Outputs, UiState, Href>;
|
|
39
|
+
|
|
40
|
+
export type PlatformaApiVersion = Platforma['apiVersion'];
|
|
41
|
+
|
|
18
42
|
export type InferArgsType<Pl extends Platforma> = Pl extends Platforma<infer Args> ? Args : never;
|
|
19
43
|
|
|
20
44
|
export type InferOutputsType<Pl extends Platforma> =
|
package/src/raw_globals.ts
CHANGED
|
@@ -1,28 +1,32 @@
|
|
|
1
1
|
import type { ValueOrErrors } from '@milaboratories/pl-model-common';
|
|
2
2
|
import {} from './global';
|
|
3
3
|
import { getPlatformaInstance } from './internal';
|
|
4
|
-
import type { Platforma } from './platforma';
|
|
4
|
+
import type { Platforma, PlatformaApiVersion } from './platforma';
|
|
5
5
|
import { PlatformaSDKVersion } from './version';
|
|
6
6
|
|
|
7
|
+
export function getPlatformaApiVersion(): PlatformaApiVersion {
|
|
8
|
+
return platformaApiVersion ?? 1; // undefined means 1 for backward compatibility
|
|
9
|
+
}
|
|
10
|
+
|
|
7
11
|
export function getRawPlatformaInstance<
|
|
8
12
|
Args = unknown,
|
|
9
13
|
Outputs extends Record<string, ValueOrErrors<unknown>> = Record<string, ValueOrErrors<unknown>>,
|
|
10
14
|
UiState = unknown,
|
|
11
15
|
Href extends `/${string}` = `/${string}`,
|
|
12
16
|
>(): Platforma<Args, Outputs, UiState, Href> {
|
|
13
|
-
return getPlatformaInstance<Args, Outputs, UiState, Href>({ sdkVersion: PlatformaSDKVersion });
|
|
17
|
+
return getPlatformaInstance<Args, Outputs, UiState, Href>({ sdkVersion: PlatformaSDKVersion, apiVersion: platformaApiVersion });
|
|
14
18
|
}
|
|
15
19
|
|
|
16
20
|
/** Returns a global platforma instance or a provided fallback if it's not available. */
|
|
17
|
-
export function getPlatformaOrDefault<
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
>(
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
}
|
|
21
|
+
// export function getPlatformaOrDefault<
|
|
22
|
+
// Args = unknown,
|
|
23
|
+
// Outputs extends Record<string, ValueOrErrors<unknown>> = Record<string, ValueOrErrors<unknown>>,
|
|
24
|
+
// UiState = unknown,
|
|
25
|
+
// Href extends `/${string}` = `/${string}`,
|
|
26
|
+
// >(): PlatformaV1<Args, Outputs, UiState, Href> | PlatformaV2<Args, Outputs, UiState, Href> {
|
|
27
|
+
// try {
|
|
28
|
+
// return getRawPlatformaInstance<Args, Outputs, UiState, Href>();
|
|
29
|
+
// } catch {
|
|
30
|
+
// return platforma;
|
|
31
|
+
// }
|
|
32
|
+
// }
|
package/dist/block_api.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"block_api.d.ts","sourceRoot":"","sources":["../src/block_api.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,UAAU,EAAE,eAAe,EAAE,MAAM,iCAAiC,CAAC;AACrG,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AAE3D,oFAAoF;AACpF,MAAM,MAAM,kBAAkB,GAAG,MAAM,IAAI,CAAC;AAE5C,4DAA4D;AAC5D,MAAM,WAAW,QAAQ,CACvB,IAAI,GAAG,OAAO,EACd,OAAO,SAAS,gBAAgB,GAAG,gBAAgB,EACnD,OAAO,GAAG,OAAO,EACjB,IAAI,SAAS,IAAI,MAAM,EAAE,GAAG,IAAI,MAAM,EAAE;IAExC;;;SAGK;IACL,cAAc,IAAI,OAAO,CAAC,UAAU,CAAC,IAAI,EAAE,OAAO,EAAE,OAAO,EAAE,IAAI,CAAC,CAAC,CAAC;IAEpE;;;;;;;;;;;;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