@platforma-sdk/model 1.54.10 → 1.55.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/normalization.cjs +8 -1
- package/dist/bconfig/normalization.cjs.map +1 -1
- package/dist/bconfig/normalization.d.ts.map +1 -1
- package/dist/bconfig/normalization.js +8 -1
- package/dist/bconfig/normalization.js.map +1 -1
- package/dist/block_api_v3.d.ts +2 -2
- package/dist/block_api_v3.d.ts.map +1 -1
- package/dist/block_migrations.cjs +246 -214
- package/dist/block_migrations.cjs.map +1 -1
- package/dist/block_migrations.d.ts +180 -158
- package/dist/block_migrations.d.ts.map +1 -1
- package/dist/block_migrations.js +247 -214
- package/dist/block_migrations.js.map +1 -1
- package/dist/block_model.cjs +85 -35
- package/dist/block_model.cjs.map +1 -1
- package/dist/block_model.d.ts +66 -38
- package/dist/block_model.d.ts.map +1 -1
- package/dist/block_model.js +86 -36
- package/dist/block_model.js.map +1 -1
- package/dist/{builder.cjs → block_model_legacy.cjs} +2 -2
- package/dist/block_model_legacy.cjs.map +1 -0
- package/dist/{builder.d.ts → block_model_legacy.d.ts} +1 -1
- package/dist/block_model_legacy.d.ts.map +1 -0
- package/dist/{builder.js → block_model_legacy.js} +2 -2
- package/dist/block_model_legacy.js.map +1 -0
- package/dist/block_state_patch.d.ts +11 -1
- package/dist/block_state_patch.d.ts.map +1 -1
- package/dist/block_storage.cjs +126 -109
- package/dist/block_storage.cjs.map +1 -1
- package/dist/block_storage.d.ts +109 -112
- package/dist/block_storage.d.ts.map +1 -1
- package/dist/block_storage.js +126 -101
- package/dist/block_storage.js.map +1 -1
- package/dist/block_storage_callbacks.cjs +227 -0
- package/dist/block_storage_callbacks.cjs.map +1 -0
- package/dist/block_storage_callbacks.d.ts +113 -0
- package/dist/block_storage_callbacks.d.ts.map +1 -0
- package/dist/block_storage_callbacks.js +218 -0
- package/dist/block_storage_callbacks.js.map +1 -0
- package/dist/block_storage_facade.cjs +104 -0
- package/dist/block_storage_facade.cjs.map +1 -0
- package/dist/block_storage_facade.d.ts +168 -0
- package/dist/block_storage_facade.d.ts.map +1 -0
- package/dist/block_storage_facade.js +99 -0
- package/dist/block_storage_facade.js.map +1 -0
- package/dist/components/PlDataTable/state-migration.cjs.map +1 -1
- package/dist/components/PlDataTable/state-migration.js.map +1 -1
- package/dist/components/PlDataTable/table.cjs +11 -2
- package/dist/components/PlDataTable/table.cjs.map +1 -1
- package/dist/components/PlDataTable/table.d.ts.map +1 -1
- package/dist/components/PlDataTable/table.js +12 -3
- package/dist/components/PlDataTable/table.js.map +1 -1
- package/dist/components/PlDataTable/v5.d.ts +7 -4
- package/dist/components/PlDataTable/v5.d.ts.map +1 -1
- package/dist/filters/converters/filterToQuery.cjs +3 -4
- package/dist/filters/converters/filterToQuery.cjs.map +1 -1
- package/dist/filters/converters/filterToQuery.d.ts +1 -1
- package/dist/filters/converters/filterToQuery.d.ts.map +1 -1
- package/dist/filters/converters/filterToQuery.js +3 -4
- package/dist/filters/converters/filterToQuery.js.map +1 -1
- package/dist/filters/distill.cjs.map +1 -1
- package/dist/filters/distill.d.ts +3 -2
- package/dist/filters/distill.d.ts.map +1 -1
- package/dist/filters/distill.js.map +1 -1
- package/dist/filters/traverse.cjs +7 -3
- package/dist/filters/traverse.cjs.map +1 -1
- package/dist/filters/traverse.d.ts +14 -12
- package/dist/filters/traverse.d.ts.map +1 -1
- package/dist/filters/traverse.js +7 -3
- package/dist/filters/traverse.js.map +1 -1
- package/dist/index.cjs +13 -14
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +8 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +6 -4
- package/dist/index.js.map +1 -1
- package/dist/package.json.cjs +1 -1
- package/dist/package.json.js +1 -1
- package/dist/platforma.d.ts +11 -4
- package/dist/platforma.d.ts.map +1 -1
- package/dist/plugin_model.cjs +171 -0
- package/dist/plugin_model.cjs.map +1 -0
- package/dist/plugin_model.d.ts +162 -0
- package/dist/plugin_model.d.ts.map +1 -0
- package/dist/plugin_model.js +169 -0
- package/dist/plugin_model.js.map +1 -0
- package/dist/render/api.cjs +20 -21
- package/dist/render/api.cjs.map +1 -1
- package/dist/render/api.d.ts +8 -8
- package/dist/render/api.d.ts.map +1 -1
- package/dist/render/api.js +20 -21
- package/dist/render/api.js.map +1 -1
- package/dist/render/internal.cjs.map +1 -1
- package/dist/render/internal.d.ts +1 -1
- package/dist/render/internal.d.ts.map +1 -1
- package/dist/render/internal.js.map +1 -1
- package/dist/version.cjs +4 -0
- package/dist/version.cjs.map +1 -1
- package/dist/version.d.ts +4 -0
- package/dist/version.d.ts.map +1 -1
- package/dist/version.js +4 -1
- package/dist/version.js.map +1 -1
- package/package.json +6 -6
- package/src/bconfig/normalization.ts +8 -1
- package/src/block_api_v3.ts +2 -2
- package/src/block_migrations.test.ts +141 -171
- package/src/block_migrations.ts +300 -285
- package/src/block_model.ts +205 -95
- package/src/{builder.ts → block_model_legacy.ts} +1 -1
- package/src/block_state_patch.ts +13 -1
- package/src/block_storage.test.ts +283 -95
- package/src/block_storage.ts +199 -188
- package/src/block_storage_callbacks.ts +326 -0
- package/src/block_storage_facade.ts +199 -0
- package/src/components/PlDataTable/state-migration.ts +4 -4
- package/src/components/PlDataTable/table.ts +16 -3
- package/src/components/PlDataTable/v5.ts +9 -5
- package/src/filters/converters/filterToQuery.ts +8 -7
- package/src/filters/distill.ts +19 -11
- package/src/filters/traverse.ts +44 -24
- package/src/index.ts +7 -3
- package/src/platforma.ts +26 -7
- package/src/plugin_model.test.ts +168 -0
- package/src/plugin_model.ts +242 -0
- package/src/render/api.ts +26 -24
- package/src/render/internal.ts +1 -1
- package/src/typing.test.ts +1 -1
- package/src/version.ts +8 -0
- package/dist/block_storage_vm.cjs +0 -262
- package/dist/block_storage_vm.cjs.map +0 -1
- package/dist/block_storage_vm.d.ts +0 -59
- package/dist/block_storage_vm.d.ts.map +0 -1
- package/dist/block_storage_vm.js +0 -258
- package/dist/block_storage_vm.js.map +0 -1
- package/dist/branding.d.ts +0 -7
- package/dist/branding.d.ts.map +0 -1
- package/dist/builder.cjs.map +0 -1
- package/dist/builder.d.ts.map +0 -1
- package/dist/builder.js.map +0 -1
- package/dist/sdk_info.cjs +0 -10
- package/dist/sdk_info.cjs.map +0 -1
- package/dist/sdk_info.d.ts +0 -5
- package/dist/sdk_info.d.ts.map +0 -1
- package/dist/sdk_info.js +0 -8
- package/dist/sdk_info.js.map +0 -1
- package/dist/unionize.d.ts +0 -12
- package/dist/unionize.d.ts.map +0 -1
- package/src/block_storage_vm.ts +0 -346
- package/src/branding.ts +0 -4
- package/src/sdk_info.ts +0 -9
- package/src/unionize.ts +0 -12
package/src/render/api.ts
CHANGED
|
@@ -533,40 +533,40 @@ export class ResultPool implements ColumnProvider, AxisLabelProvider {
|
|
|
533
533
|
}
|
|
534
534
|
|
|
535
535
|
/** Main entry point to the API available within model lambdas (like outputs, sections, etc..) */
|
|
536
|
-
export abstract class RenderCtxBase<Args, Data> {
|
|
536
|
+
export abstract class RenderCtxBase<Args = unknown, Data = unknown> {
|
|
537
537
|
protected readonly ctx: GlobalCfgRenderCtx;
|
|
538
538
|
|
|
539
539
|
constructor() {
|
|
540
540
|
this.ctx = getCfgRenderCtx();
|
|
541
541
|
}
|
|
542
542
|
|
|
543
|
-
private
|
|
543
|
+
private dataCache?: { v: Data };
|
|
544
544
|
|
|
545
545
|
public get data(): Data {
|
|
546
|
-
if (this.
|
|
546
|
+
if (this.dataCache === undefined) {
|
|
547
547
|
const raw = this.ctx.data;
|
|
548
548
|
const value = typeof raw === "function" ? raw() : raw;
|
|
549
|
-
this.
|
|
549
|
+
this.dataCache = { v: value ? JSON.parse(value) : ({} as Data) };
|
|
550
550
|
}
|
|
551
|
-
return this.
|
|
551
|
+
return this.dataCache.v;
|
|
552
552
|
}
|
|
553
553
|
|
|
554
554
|
// lazy rendering because this feature is rarely used
|
|
555
|
-
private
|
|
555
|
+
private activeArgsCache?: { v?: Args };
|
|
556
556
|
|
|
557
557
|
/**
|
|
558
558
|
* Returns args snapshot the block was executed for (i.e. when "Run" button was pressed).
|
|
559
559
|
* Returns undefined, if block was never executed or stopped mid-way execution, so that the result was cleared.
|
|
560
560
|
* */
|
|
561
561
|
public get activeArgs(): Args | undefined {
|
|
562
|
-
if (this.
|
|
562
|
+
if (this.activeArgsCache === undefined) {
|
|
563
563
|
const raw = this.ctx.activeArgs;
|
|
564
564
|
const value = typeof raw === "function" ? raw() : raw;
|
|
565
|
-
this.
|
|
565
|
+
this.activeArgsCache = {
|
|
566
566
|
v: value ? JSON.parse(value) : undefined,
|
|
567
567
|
};
|
|
568
568
|
}
|
|
569
|
-
return this.
|
|
569
|
+
return this.activeArgsCache.v;
|
|
570
570
|
}
|
|
571
571
|
|
|
572
572
|
// /** Can be used to determine features provided by the desktop instance. */
|
|
@@ -711,41 +711,43 @@ export abstract class RenderCtxBase<Args, Data> {
|
|
|
711
711
|
}
|
|
712
712
|
|
|
713
713
|
/** Main entry point to the API available within model lambdas (like outputs, sections, etc..) for v3+ blocks */
|
|
714
|
-
export class RenderCtx<Args, Data> extends RenderCtxBase<Args, Data> {
|
|
715
|
-
private
|
|
714
|
+
export class RenderCtx<Args = unknown, Data = unknown> extends RenderCtxBase<Args, Data> {
|
|
715
|
+
private argsCache?: { v: Args | undefined };
|
|
716
716
|
public get args(): Args | undefined {
|
|
717
|
-
if (this.
|
|
717
|
+
if (this.argsCache === undefined) {
|
|
718
718
|
const raw = this.ctx.args;
|
|
719
719
|
const value = typeof raw === "function" ? raw() : raw;
|
|
720
|
-
|
|
721
|
-
this._argsCache = { v: value === undefined ? undefined : JSON.parse(value) };
|
|
720
|
+
this.argsCache = { v: value === undefined ? undefined : JSON.parse(value) };
|
|
722
721
|
}
|
|
723
|
-
return this.
|
|
722
|
+
return this.argsCache.v;
|
|
724
723
|
}
|
|
725
724
|
}
|
|
726
725
|
|
|
727
726
|
/** Render context for legacy v1/v2 blocks - provides backward compatibility */
|
|
728
|
-
export class RenderCtxLegacy<Args, UiState> extends RenderCtxBase<
|
|
729
|
-
|
|
727
|
+
export class RenderCtxLegacy<Args = unknown, UiState = unknown> extends RenderCtxBase<
|
|
728
|
+
Args,
|
|
729
|
+
UiState
|
|
730
|
+
> {
|
|
731
|
+
private argsCache?: { v: Args };
|
|
730
732
|
|
|
731
733
|
public get args(): Args {
|
|
732
|
-
if (this.
|
|
734
|
+
if (this.argsCache === undefined) {
|
|
733
735
|
const raw = this.ctx.args;
|
|
734
736
|
const value = typeof raw === "function" ? raw() : raw;
|
|
735
|
-
this.
|
|
737
|
+
this.argsCache = { v: JSON.parse(value) };
|
|
736
738
|
}
|
|
737
|
-
return this.
|
|
739
|
+
return this.argsCache.v;
|
|
738
740
|
}
|
|
739
741
|
|
|
740
|
-
private
|
|
742
|
+
private uiStateCache?: { v: UiState };
|
|
741
743
|
|
|
742
744
|
public get uiState(): UiState {
|
|
743
|
-
if (this.
|
|
745
|
+
if (this.uiStateCache === undefined) {
|
|
744
746
|
const raw = this.ctx.uiState!;
|
|
745
747
|
const value = typeof raw === "function" ? raw() : raw;
|
|
746
|
-
this.
|
|
748
|
+
this.uiStateCache = { v: value ? JSON.parse(value) : ({} as UiState) };
|
|
747
749
|
}
|
|
748
|
-
return this.
|
|
750
|
+
return this.uiStateCache.v;
|
|
749
751
|
}
|
|
750
752
|
}
|
|
751
753
|
|
package/src/render/internal.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { Optional } from "utility-types";
|
|
2
|
-
import type { Branded } from "
|
|
2
|
+
import type { Branded } from "@milaboratories/pl-model-common";
|
|
3
3
|
import type { CommonFieldTraverseOps, FieldTraversalStep, ResourceType } from "./traversal_ops";
|
|
4
4
|
import type {
|
|
5
5
|
ArchiveFormat,
|
package/src/typing.test.ts
CHANGED
|
@@ -6,7 +6,7 @@ import {
|
|
|
6
6
|
} from "@milaboratories/pl-model-common";
|
|
7
7
|
import { expect, test } from "vitest";
|
|
8
8
|
import { DeriveHref, StdCtx } from "./bconfig";
|
|
9
|
-
import { BlockModel } from "./
|
|
9
|
+
import { BlockModel } from "./block_model_legacy";
|
|
10
10
|
import {
|
|
11
11
|
Args,
|
|
12
12
|
ConfigResult,
|
package/src/version.ts
CHANGED
|
@@ -1,262 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
var block_storage = require('./block_storage.cjs');
|
|
4
|
-
var plModelCommon = require('@milaboratories/pl-model-common');
|
|
5
|
-
var internal = require('./internal.cjs');
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* BlockStorage VM Integration - Internal module for VM-based storage operations.
|
|
9
|
-
*
|
|
10
|
-
* This module auto-registers internal callbacks that the middle layer can invoke
|
|
11
|
-
* to perform storage transformations. Block developers never interact with these
|
|
12
|
-
* directly - they only see `state`.
|
|
13
|
-
*
|
|
14
|
-
* Registered callbacks (all prefixed with `__pl_` for internal SDK use):
|
|
15
|
-
* - `__pl_storage_applyUpdate`: (currentStorageJson, payload) => updatedStorageJson
|
|
16
|
-
* - `__pl_storage_debugView`: (rawStorage) => JSON string with storage debug view
|
|
17
|
-
* - `__pl_storage_migrate`: (currentStorageJson) => MigrationResult
|
|
18
|
-
* - `__pl_args_derive`: (storageJson) => ArgsDeriveResult
|
|
19
|
-
* - `__pl_prerunArgs_derive`: (storageJson) => ArgsDeriveResult
|
|
20
|
-
*
|
|
21
|
-
* Callbacks registered by DataModel.registerCallbacks():
|
|
22
|
-
* - `__pl_data_initial`: () => initial data
|
|
23
|
-
* - `__pl_data_upgrade`: (versioned) => DataMigrationResult
|
|
24
|
-
* - `__pl_storage_initial`: () => initial BlockStorage as JSON string
|
|
25
|
-
*
|
|
26
|
-
* @module block_storage_vm
|
|
27
|
-
* @internal
|
|
28
|
-
*/
|
|
29
|
-
/**
|
|
30
|
-
* Normalizes raw storage data and extracts state.
|
|
31
|
-
* Handles all formats:
|
|
32
|
-
* - New BlockStorage format (has discriminator)
|
|
33
|
-
* - Legacy V1/V2 format ({ args, uiState })
|
|
34
|
-
* - Raw V3 state (any other format)
|
|
35
|
-
*
|
|
36
|
-
* @param rawStorage - Raw data from blockStorage field (may be JSON string or object)
|
|
37
|
-
* @returns Object with normalized storage and extracted state
|
|
38
|
-
*/
|
|
39
|
-
function normalizeStorage(rawStorage) {
|
|
40
|
-
// Handle undefined/null
|
|
41
|
-
if (rawStorage === undefined || rawStorage === null) {
|
|
42
|
-
const storage = block_storage.createBlockStorage({});
|
|
43
|
-
return { storage, data: {} };
|
|
44
|
-
}
|
|
45
|
-
// Parse JSON string if needed
|
|
46
|
-
let parsed = rawStorage;
|
|
47
|
-
if (typeof rawStorage === "string") {
|
|
48
|
-
try {
|
|
49
|
-
parsed = JSON.parse(rawStorage);
|
|
50
|
-
}
|
|
51
|
-
catch {
|
|
52
|
-
// If parsing fails, treat string as the data
|
|
53
|
-
const storage = block_storage.createBlockStorage(rawStorage);
|
|
54
|
-
return { storage, data: rawStorage };
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
// Check for BlockStorage format (has discriminator)
|
|
58
|
-
if (block_storage.isBlockStorage(parsed)) {
|
|
59
|
-
const storage = block_storage.normalizeBlockStorage(parsed);
|
|
60
|
-
return { storage, data: block_storage.getStorageData(storage) };
|
|
61
|
-
}
|
|
62
|
-
// Check for legacy V1/V2 format: { args, uiState }
|
|
63
|
-
if (isLegacyModelV1ApiFormat(parsed)) {
|
|
64
|
-
// For legacy format, the whole object IS the data
|
|
65
|
-
const storage = block_storage.createBlockStorage(parsed);
|
|
66
|
-
return { storage, data: parsed };
|
|
67
|
-
}
|
|
68
|
-
// Raw V3 data - wrap it
|
|
69
|
-
const storage = block_storage.createBlockStorage(parsed);
|
|
70
|
-
return { storage, data: parsed };
|
|
71
|
-
}
|
|
72
|
-
/**
|
|
73
|
-
* Applies a state update to existing storage.
|
|
74
|
-
* Used when setData is called from the frontend.
|
|
75
|
-
*
|
|
76
|
-
* @param currentStorageJson - Current storage as JSON string (must be defined)
|
|
77
|
-
* @param newData - New data from application
|
|
78
|
-
* @returns Updated storage as JSON string
|
|
79
|
-
*/
|
|
80
|
-
function applyStorageUpdate(currentStorageJson, payload) {
|
|
81
|
-
const { storage: currentStorage } = normalizeStorage(currentStorageJson);
|
|
82
|
-
// Update data while preserving other storage fields (version, plugins)
|
|
83
|
-
const updatedStorage = block_storage.updateStorageData(currentStorage, payload);
|
|
84
|
-
return JSON.stringify(updatedStorage);
|
|
85
|
-
}
|
|
86
|
-
/**
|
|
87
|
-
* Checks if data is in legacy Model API v1 format.
|
|
88
|
-
* Legacy format has { args, uiState? } at top level without the BlockStorage discriminator.
|
|
89
|
-
*/
|
|
90
|
-
function isLegacyModelV1ApiFormat(data) {
|
|
91
|
-
if (data === null || typeof data !== "object")
|
|
92
|
-
return false;
|
|
93
|
-
if (block_storage.isBlockStorage(data))
|
|
94
|
-
return false;
|
|
95
|
-
const obj = data;
|
|
96
|
-
return "args" in obj;
|
|
97
|
-
}
|
|
98
|
-
// =============================================================================
|
|
99
|
-
// Auto-register internal callbacks when module is loaded in VM
|
|
100
|
-
// =============================================================================
|
|
101
|
-
// Register apply update callback (requires existing storage)
|
|
102
|
-
internal.tryRegisterCallback("__pl_storage_applyUpdate", (currentStorageJson, payload) => {
|
|
103
|
-
return applyStorageUpdate(currentStorageJson, payload);
|
|
104
|
-
});
|
|
105
|
-
/**
|
|
106
|
-
* Gets storage debug view from raw storage data.
|
|
107
|
-
* Returns structured debug info about the storage state.
|
|
108
|
-
*
|
|
109
|
-
* @param rawStorage - Raw data from blockStorage field (may be JSON string or object)
|
|
110
|
-
* @returns JSON string with storage debug view
|
|
111
|
-
*/
|
|
112
|
-
function getStorageDebugView(rawStorage) {
|
|
113
|
-
const { storage } = normalizeStorage(rawStorage);
|
|
114
|
-
const debugView = {
|
|
115
|
-
dataVersion: storage.__dataVersion,
|
|
116
|
-
data: storage.__data,
|
|
117
|
-
};
|
|
118
|
-
return plModelCommon.stringifyJson(debugView);
|
|
119
|
-
}
|
|
120
|
-
// Register debug view callback
|
|
121
|
-
internal.tryRegisterCallback("__pl_storage_debugView", (rawStorage) => {
|
|
122
|
-
return getStorageDebugView(rawStorage);
|
|
123
|
-
});
|
|
124
|
-
/**
|
|
125
|
-
* Runs storage migration using the DataModel's migrate callback.
|
|
126
|
-
* This is the main entry point for the middle layer to trigger migrations.
|
|
127
|
-
*
|
|
128
|
-
* Uses the '__pl_data_upgrade' callback registered by DataModel.registerCallbacks() which:
|
|
129
|
-
* - Handles all migration logic internally
|
|
130
|
-
* - Returns { version, data, warning? } - warning present if reset to initial data
|
|
131
|
-
*
|
|
132
|
-
* @param currentStorageJson - Current storage as JSON string (or undefined)
|
|
133
|
-
* @returns MigrationResult
|
|
134
|
-
*/
|
|
135
|
-
function migrateStorage(currentStorageJson) {
|
|
136
|
-
// Get the callback registry context
|
|
137
|
-
const ctx = internal.tryGetCfgRenderCtx();
|
|
138
|
-
if (ctx === undefined) {
|
|
139
|
-
return { error: "Not in config rendering context" };
|
|
140
|
-
}
|
|
141
|
-
// Normalize storage to get current data and version
|
|
142
|
-
const { storage: currentStorage, data: currentData } = normalizeStorage(currentStorageJson);
|
|
143
|
-
const currentVersion = currentStorage.__dataVersion;
|
|
144
|
-
// Helper to create storage with given data and version
|
|
145
|
-
const createStorageJson = (data, version) => {
|
|
146
|
-
return JSON.stringify({
|
|
147
|
-
...currentStorage,
|
|
148
|
-
__dataVersion: version,
|
|
149
|
-
__data: data,
|
|
150
|
-
});
|
|
151
|
-
};
|
|
152
|
-
// Get the migrate callback (registered by DataModel.registerCallbacks())
|
|
153
|
-
const migrateCallback = ctx.callbackRegistry["__pl_data_upgrade"];
|
|
154
|
-
if (typeof migrateCallback !== "function") {
|
|
155
|
-
return { error: "__pl_data_upgrade callback not found (DataModel not registered)" };
|
|
156
|
-
}
|
|
157
|
-
// Call the migrator's migrate function
|
|
158
|
-
let result;
|
|
159
|
-
try {
|
|
160
|
-
result = migrateCallback({ version: currentVersion, data: currentData });
|
|
161
|
-
}
|
|
162
|
-
catch (e) {
|
|
163
|
-
const errorMsg = e instanceof Error ? e.message : String(e);
|
|
164
|
-
return { error: `migrate() threw: ${errorMsg}` };
|
|
165
|
-
}
|
|
166
|
-
// Build info message
|
|
167
|
-
const info = result.version === currentVersion
|
|
168
|
-
? `No migration needed (${currentVersion})`
|
|
169
|
-
: result.warning
|
|
170
|
-
? `Reset to initial data (${result.version})`
|
|
171
|
-
: `Migrated ${currentVersion}→${result.version}`;
|
|
172
|
-
return {
|
|
173
|
-
newStorageJson: createStorageJson(result.data, result.version),
|
|
174
|
-
info,
|
|
175
|
-
warn: result.warning,
|
|
176
|
-
};
|
|
177
|
-
}
|
|
178
|
-
// Register migrate callback
|
|
179
|
-
internal.tryRegisterCallback("__pl_storage_migrate", (currentStorageJson) => {
|
|
180
|
-
return migrateStorage(currentStorageJson);
|
|
181
|
-
});
|
|
182
|
-
/**
|
|
183
|
-
* Derives args from storage using the registered 'args' callback.
|
|
184
|
-
* This extracts data from storage and passes it to the block's args() function.
|
|
185
|
-
*
|
|
186
|
-
* @param storageJson - Storage as JSON string
|
|
187
|
-
* @returns ArgsDeriveResult with derived args or error
|
|
188
|
-
*/
|
|
189
|
-
function deriveArgsFromStorage(storageJson) {
|
|
190
|
-
const ctx = internal.tryGetCfgRenderCtx();
|
|
191
|
-
if (ctx === undefined) {
|
|
192
|
-
return { error: "Not in config rendering context" };
|
|
193
|
-
}
|
|
194
|
-
// Extract data from storage
|
|
195
|
-
const { data } = normalizeStorage(storageJson);
|
|
196
|
-
// Get the args callback (registered by BlockModelV3.args())
|
|
197
|
-
const argsCallback = ctx.callbackRegistry["args"];
|
|
198
|
-
if (typeof argsCallback !== "function") {
|
|
199
|
-
return { error: "args callback not found" };
|
|
200
|
-
}
|
|
201
|
-
// Call the args callback with extracted data
|
|
202
|
-
try {
|
|
203
|
-
const result = argsCallback(data);
|
|
204
|
-
return { value: result };
|
|
205
|
-
}
|
|
206
|
-
catch (e) {
|
|
207
|
-
const errorMsg = e instanceof Error ? e.message : String(e);
|
|
208
|
-
return { error: `args() threw: ${errorMsg}` };
|
|
209
|
-
}
|
|
210
|
-
}
|
|
211
|
-
// Register args derivation callback
|
|
212
|
-
internal.tryRegisterCallback("__pl_args_derive", (storageJson) => {
|
|
213
|
-
return deriveArgsFromStorage(storageJson);
|
|
214
|
-
});
|
|
215
|
-
/**
|
|
216
|
-
* Derives prerunArgs from storage using the registered 'prerunArgs' callback.
|
|
217
|
-
* Falls back to 'args' callback if 'prerunArgs' is not defined.
|
|
218
|
-
*
|
|
219
|
-
* @param storageJson - Storage as JSON string
|
|
220
|
-
* @returns ArgsDeriveResult with derived prerunArgs or error
|
|
221
|
-
*/
|
|
222
|
-
function derivePrerunArgsFromStorage(storageJson) {
|
|
223
|
-
const ctx = internal.tryGetCfgRenderCtx();
|
|
224
|
-
if (ctx === undefined) {
|
|
225
|
-
return { error: "Not in config rendering context" };
|
|
226
|
-
}
|
|
227
|
-
// Extract data from storage
|
|
228
|
-
const { data } = normalizeStorage(storageJson);
|
|
229
|
-
// Try prerunArgs callback first
|
|
230
|
-
const prerunArgsCallback = ctx.callbackRegistry["prerunArgs"];
|
|
231
|
-
if (typeof prerunArgsCallback === "function") {
|
|
232
|
-
try {
|
|
233
|
-
const result = prerunArgsCallback(data);
|
|
234
|
-
return { value: result };
|
|
235
|
-
}
|
|
236
|
-
catch (e) {
|
|
237
|
-
const errorMsg = e instanceof Error ? e.message : String(e);
|
|
238
|
-
return { error: `prerunArgs() threw: ${errorMsg}` };
|
|
239
|
-
}
|
|
240
|
-
}
|
|
241
|
-
// Fall back to args callback
|
|
242
|
-
const argsCallback = ctx.callbackRegistry["args"];
|
|
243
|
-
if (typeof argsCallback !== "function") {
|
|
244
|
-
return { error: "args callback not found (fallback from missing prerunArgs)" };
|
|
245
|
-
}
|
|
246
|
-
try {
|
|
247
|
-
const result = argsCallback(data);
|
|
248
|
-
return { value: result };
|
|
249
|
-
}
|
|
250
|
-
catch (e) {
|
|
251
|
-
const errorMsg = e instanceof Error ? e.message : String(e);
|
|
252
|
-
return { error: `args() threw (fallback): ${errorMsg}` };
|
|
253
|
-
}
|
|
254
|
-
}
|
|
255
|
-
// Register prerunArgs derivation callback
|
|
256
|
-
internal.tryRegisterCallback("__pl_prerunArgs_derive", (storageJson) => {
|
|
257
|
-
return derivePrerunArgsFromStorage(storageJson);
|
|
258
|
-
});
|
|
259
|
-
|
|
260
|
-
exports.BLOCK_STORAGE_KEY = block_storage.BLOCK_STORAGE_KEY;
|
|
261
|
-
exports.BLOCK_STORAGE_SCHEMA_VERSION = block_storage.BLOCK_STORAGE_SCHEMA_VERSION;
|
|
262
|
-
//# sourceMappingURL=block_storage_vm.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"block_storage_vm.cjs","sources":["../src/block_storage_vm.ts"],"sourcesContent":["/**\n * BlockStorage VM Integration - Internal module for VM-based storage operations.\n *\n * This module auto-registers internal callbacks that the middle layer can invoke\n * to perform storage transformations. Block developers never interact with these\n * directly - they only see `state`.\n *\n * Registered callbacks (all prefixed with `__pl_` for internal SDK use):\n * - `__pl_storage_applyUpdate`: (currentStorageJson, payload) => updatedStorageJson\n * - `__pl_storage_debugView`: (rawStorage) => JSON string with storage debug view\n * - `__pl_storage_migrate`: (currentStorageJson) => MigrationResult\n * - `__pl_args_derive`: (storageJson) => ArgsDeriveResult\n * - `__pl_prerunArgs_derive`: (storageJson) => ArgsDeriveResult\n *\n * Callbacks registered by DataModel.registerCallbacks():\n * - `__pl_data_initial`: () => initial data\n * - `__pl_data_upgrade`: (versioned) => DataMigrationResult\n * - `__pl_storage_initial`: () => initial BlockStorage as JSON string\n *\n * @module block_storage_vm\n * @internal\n */\n\nimport {\n BLOCK_STORAGE_KEY,\n BLOCK_STORAGE_SCHEMA_VERSION,\n type BlockStorage,\n type MutateStoragePayload,\n type StorageDebugView,\n createBlockStorage,\n getStorageData,\n isBlockStorage,\n normalizeBlockStorage,\n updateStorageData,\n} from \"./block_storage\";\nimport { stringifyJson, type StringifiedJson } from \"@milaboratories/pl-model-common\";\nimport { tryGetCfgRenderCtx, tryRegisterCallback } from \"./internal\";\n\n/**\n * Result of storage normalization\n */\nexport interface NormalizeStorageResult {\n /** The normalized BlockStorage object */\n storage: BlockStorage;\n /** The extracted data (what developers see) */\n data: unknown;\n}\n\n/**\n * Normalizes raw storage data and extracts state.\n * Handles all formats:\n * - New BlockStorage format (has discriminator)\n * - Legacy V1/V2 format ({ args, uiState })\n * - Raw V3 state (any other format)\n *\n * @param rawStorage - Raw data from blockStorage field (may be JSON string or object)\n * @returns Object with normalized storage and extracted state\n */\nfunction normalizeStorage(rawStorage: unknown): NormalizeStorageResult {\n // Handle undefined/null\n if (rawStorage === undefined || rawStorage === null) {\n const storage = createBlockStorage({});\n return { storage, data: {} };\n }\n\n // Parse JSON string if needed\n let parsed = rawStorage;\n if (typeof rawStorage === \"string\") {\n try {\n parsed = JSON.parse(rawStorage);\n } catch {\n // If parsing fails, treat string as the data\n const storage = createBlockStorage(rawStorage);\n return { storage, data: rawStorage };\n }\n }\n\n // Check for BlockStorage format (has discriminator)\n if (isBlockStorage(parsed)) {\n const storage = normalizeBlockStorage(parsed);\n return { storage, data: getStorageData(storage) };\n }\n\n // Check for legacy V1/V2 format: { args, uiState }\n if (isLegacyModelV1ApiFormat(parsed)) {\n // For legacy format, the whole object IS the data\n const storage = createBlockStorage(parsed);\n return { storage, data: parsed };\n }\n\n // Raw V3 data - wrap it\n const storage = createBlockStorage(parsed);\n return { storage, data: parsed };\n}\n\n/**\n * Applies a state update to existing storage.\n * Used when setData is called from the frontend.\n *\n * @param currentStorageJson - Current storage as JSON string (must be defined)\n * @param newData - New data from application\n * @returns Updated storage as JSON string\n */\nfunction applyStorageUpdate(currentStorageJson: string, payload: MutateStoragePayload): string {\n const { storage: currentStorage } = normalizeStorage(currentStorageJson);\n\n // Update data while preserving other storage fields (version, plugins)\n const updatedStorage = updateStorageData(currentStorage, payload);\n\n return JSON.stringify(updatedStorage);\n}\n\n/**\n * Checks if data is in legacy Model API v1 format.\n * Legacy format has { args, uiState? } at top level without the BlockStorage discriminator.\n */\nfunction isLegacyModelV1ApiFormat(data: unknown): data is { args?: unknown } {\n if (data === null || typeof data !== \"object\") return false;\n if (isBlockStorage(data)) return false;\n\n const obj = data as Record<string, unknown>;\n return \"args\" in obj;\n}\n\n// =============================================================================\n// Auto-register internal callbacks when module is loaded in VM\n// =============================================================================\n\n// Register apply update callback (requires existing storage)\ntryRegisterCallback(\n \"__pl_storage_applyUpdate\",\n (currentStorageJson: string, payload: MutateStoragePayload) => {\n return applyStorageUpdate(currentStorageJson, payload);\n },\n);\n\n/**\n * Gets storage debug view from raw storage data.\n * Returns structured debug info about the storage state.\n *\n * @param rawStorage - Raw data from blockStorage field (may be JSON string or object)\n * @returns JSON string with storage debug view\n */\nfunction getStorageDebugView(rawStorage: unknown): StringifiedJson<StorageDebugView> {\n const { storage } = normalizeStorage(rawStorage);\n const debugView: StorageDebugView = {\n dataVersion: storage.__dataVersion,\n data: storage.__data,\n };\n return stringifyJson(debugView);\n}\n\n// Register debug view callback\ntryRegisterCallback(\"__pl_storage_debugView\", (rawStorage: unknown) => {\n return getStorageDebugView(rawStorage);\n});\n\n// =============================================================================\n// Migration Support\n// =============================================================================\n\n/**\n * Result of storage migration.\n * Returned by __pl_storage_migrate callback.\n *\n * - Error result: { error: string } - serious failure (no context, etc.)\n * - Success result: { newStorageJson: string, info: string, warn?: string } - migration succeeded or reset to initial\n */\nexport type MigrationResult =\n | { error: string }\n | { error?: undefined; newStorageJson: string; info: string; warn?: string };\n\n/** Result from DataModel.migrate() */\ninterface DataMigrationResult {\n version: string;\n data: unknown;\n warning?: string;\n}\n\n/**\n * Runs storage migration using the DataModel's migrate callback.\n * This is the main entry point for the middle layer to trigger migrations.\n *\n * Uses the '__pl_data_upgrade' callback registered by DataModel.registerCallbacks() which:\n * - Handles all migration logic internally\n * - Returns { version, data, warning? } - warning present if reset to initial data\n *\n * @param currentStorageJson - Current storage as JSON string (or undefined)\n * @returns MigrationResult\n */\nfunction migrateStorage(currentStorageJson: string | undefined): MigrationResult {\n // Get the callback registry context\n const ctx = tryGetCfgRenderCtx();\n if (ctx === undefined) {\n return { error: \"Not in config rendering context\" };\n }\n\n // Normalize storage to get current data and version\n const { storage: currentStorage, data: currentData } = normalizeStorage(currentStorageJson);\n const currentVersion = currentStorage.__dataVersion;\n\n // Helper to create storage with given data and version\n const createStorageJson = (data: unknown, version: string): string => {\n return JSON.stringify({\n ...currentStorage,\n __dataVersion: version,\n __data: data,\n });\n };\n\n // Get the migrate callback (registered by DataModel.registerCallbacks())\n const migrateCallback = ctx.callbackRegistry[\"__pl_data_upgrade\"] as\n | ((v: { version: string; data: unknown }) => DataMigrationResult)\n | undefined;\n if (typeof migrateCallback !== \"function\") {\n return { error: \"__pl_data_upgrade callback not found (DataModel not registered)\" };\n }\n\n // Call the migrator's migrate function\n let result: DataMigrationResult;\n try {\n result = migrateCallback({ version: currentVersion, data: currentData });\n } catch (e) {\n const errorMsg = e instanceof Error ? e.message : String(e);\n return { error: `migrate() threw: ${errorMsg}` };\n }\n\n // Build info message\n const info =\n result.version === currentVersion\n ? `No migration needed (${currentVersion})`\n : result.warning\n ? `Reset to initial data (${result.version})`\n : `Migrated ${currentVersion}→${result.version}`;\n\n return {\n newStorageJson: createStorageJson(result.data, result.version),\n info,\n warn: result.warning,\n };\n}\n\n// Register migrate callback\ntryRegisterCallback(\"__pl_storage_migrate\", (currentStorageJson: string | undefined) => {\n return migrateStorage(currentStorageJson);\n});\n\n// =============================================================================\n// Args Derivation from Storage\n// =============================================================================\n\n/**\n * Result of args derivation from storage.\n * Returned by __pl_args_derive and __pl_prerunArgs_derive callbacks.\n */\nexport type ArgsDeriveResult = { error: string } | { error?: undefined; value: unknown };\n\n/**\n * Derives args from storage using the registered 'args' callback.\n * This extracts data from storage and passes it to the block's args() function.\n *\n * @param storageJson - Storage as JSON string\n * @returns ArgsDeriveResult with derived args or error\n */\nfunction deriveArgsFromStorage(storageJson: string): ArgsDeriveResult {\n const ctx = tryGetCfgRenderCtx();\n if (ctx === undefined) {\n return { error: \"Not in config rendering context\" };\n }\n\n // Extract data from storage\n const { data } = normalizeStorage(storageJson);\n\n // Get the args callback (registered by BlockModelV3.args())\n const argsCallback = ctx.callbackRegistry[\"args\"] as ((data: unknown) => unknown) | undefined;\n if (typeof argsCallback !== \"function\") {\n return { error: \"args callback not found\" };\n }\n\n // Call the args callback with extracted data\n try {\n const result = argsCallback(data);\n return { value: result };\n } catch (e) {\n const errorMsg = e instanceof Error ? e.message : String(e);\n return { error: `args() threw: ${errorMsg}` };\n }\n}\n\n// Register args derivation callback\ntryRegisterCallback(\"__pl_args_derive\", (storageJson: string) => {\n return deriveArgsFromStorage(storageJson);\n});\n\n/**\n * Derives prerunArgs from storage using the registered 'prerunArgs' callback.\n * Falls back to 'args' callback if 'prerunArgs' is not defined.\n *\n * @param storageJson - Storage as JSON string\n * @returns ArgsDeriveResult with derived prerunArgs or error\n */\nfunction derivePrerunArgsFromStorage(storageJson: string): ArgsDeriveResult {\n const ctx = tryGetCfgRenderCtx();\n if (ctx === undefined) {\n return { error: \"Not in config rendering context\" };\n }\n\n // Extract data from storage\n const { data } = normalizeStorage(storageJson);\n\n // Try prerunArgs callback first\n const prerunArgsCallback = ctx.callbackRegistry[\"prerunArgs\"] as\n | ((data: unknown) => unknown)\n | undefined;\n if (typeof prerunArgsCallback === \"function\") {\n try {\n const result = prerunArgsCallback(data);\n return { value: result };\n } catch (e) {\n const errorMsg = e instanceof Error ? e.message : String(e);\n return { error: `prerunArgs() threw: ${errorMsg}` };\n }\n }\n\n // Fall back to args callback\n const argsCallback = ctx.callbackRegistry[\"args\"] as ((data: unknown) => unknown) | undefined;\n if (typeof argsCallback !== \"function\") {\n return { error: \"args callback not found (fallback from missing prerunArgs)\" };\n }\n\n try {\n const result = argsCallback(data);\n return { value: result };\n } catch (e) {\n const errorMsg = e instanceof Error ? e.message : String(e);\n return { error: `args() threw (fallback): ${errorMsg}` };\n }\n}\n\n// Register prerunArgs derivation callback\ntryRegisterCallback(\"__pl_prerunArgs_derive\", (storageJson: string) => {\n return derivePrerunArgsFromStorage(storageJson);\n});\n\n// Export discriminator key and schema version for external checks\nexport { BLOCK_STORAGE_KEY, BLOCK_STORAGE_SCHEMA_VERSION };\n"],"names":["createBlockStorage","isBlockStorage","normalizeBlockStorage","getStorageData","updateStorageData","tryRegisterCallback","stringifyJson","tryGetCfgRenderCtx"],"mappings":";;;;;;AAAA;;;;;;;;;;;;;;;;;;;;;AAqBG;AA2BH;;;;;;;;;AASG;AACH,SAAS,gBAAgB,CAAC,UAAmB,EAAA;;IAE3C,IAAI,UAAU,KAAK,SAAS,IAAI,UAAU,KAAK,IAAI,EAAE;AACnD,QAAA,MAAM,OAAO,GAAGA,gCAAkB,CAAC,EAAE,CAAC;AACtC,QAAA,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,EAAE,EAAE;IAC9B;;IAGA,IAAI,MAAM,GAAG,UAAU;AACvB,IAAA,IAAI,OAAO,UAAU,KAAK,QAAQ,EAAE;AAClC,QAAA,IAAI;AACF,YAAA,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,UAAU,CAAC;QACjC;AAAE,QAAA,MAAM;;AAEN,YAAA,MAAM,OAAO,GAAGA,gCAAkB,CAAC,UAAU,CAAC;AAC9C,YAAA,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,UAAU,EAAE;QACtC;IACF;;AAGA,IAAA,IAAIC,4BAAc,CAAC,MAAM,CAAC,EAAE;AAC1B,QAAA,MAAM,OAAO,GAAGC,mCAAqB,CAAC,MAAM,CAAC;QAC7C,OAAO,EAAE,OAAO,EAAE,IAAI,EAAEC,4BAAc,CAAC,OAAO,CAAC,EAAE;IACnD;;AAGA,IAAA,IAAI,wBAAwB,CAAC,MAAM,CAAC,EAAE;;AAEpC,QAAA,MAAM,OAAO,GAAGH,gCAAkB,CAAC,MAAM,CAAC;AAC1C,QA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AAC,CAAC,OAAO,GAAG,MAAM,CAAC,CAAC,CAAC;AAC3D,QAAA,OAAO,EAAE,KAAK,EAAE,4BAA4B,QAAQ,CAAA,CAAE,EAAE;IAC1D;AACF;AAEA;AACAF,4BAAmB,CAAC,wBAAwB,EAAE,CAAC,WAAmB,KAAI;AACpE,IAAA,OAAO,2BAA2B,CAAC,WAAW,CAAC;AACjD,CAAC,CAAC;;;;;"}
|
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* BlockStorage VM Integration - Internal module for VM-based storage operations.
|
|
3
|
-
*
|
|
4
|
-
* This module auto-registers internal callbacks that the middle layer can invoke
|
|
5
|
-
* to perform storage transformations. Block developers never interact with these
|
|
6
|
-
* directly - they only see `state`.
|
|
7
|
-
*
|
|
8
|
-
* Registered callbacks (all prefixed with `__pl_` for internal SDK use):
|
|
9
|
-
* - `__pl_storage_applyUpdate`: (currentStorageJson, payload) => updatedStorageJson
|
|
10
|
-
* - `__pl_storage_debugView`: (rawStorage) => JSON string with storage debug view
|
|
11
|
-
* - `__pl_storage_migrate`: (currentStorageJson) => MigrationResult
|
|
12
|
-
* - `__pl_args_derive`: (storageJson) => ArgsDeriveResult
|
|
13
|
-
* - `__pl_prerunArgs_derive`: (storageJson) => ArgsDeriveResult
|
|
14
|
-
*
|
|
15
|
-
* Callbacks registered by DataModel.registerCallbacks():
|
|
16
|
-
* - `__pl_data_initial`: () => initial data
|
|
17
|
-
* - `__pl_data_upgrade`: (versioned) => DataMigrationResult
|
|
18
|
-
* - `__pl_storage_initial`: () => initial BlockStorage as JSON string
|
|
19
|
-
*
|
|
20
|
-
* @module block_storage_vm
|
|
21
|
-
* @internal
|
|
22
|
-
*/
|
|
23
|
-
import { BLOCK_STORAGE_KEY, BLOCK_STORAGE_SCHEMA_VERSION, type BlockStorage } from "./block_storage";
|
|
24
|
-
/**
|
|
25
|
-
* Result of storage normalization
|
|
26
|
-
*/
|
|
27
|
-
export interface NormalizeStorageResult {
|
|
28
|
-
/** The normalized BlockStorage object */
|
|
29
|
-
storage: BlockStorage;
|
|
30
|
-
/** The extracted data (what developers see) */
|
|
31
|
-
data: unknown;
|
|
32
|
-
}
|
|
33
|
-
/**
|
|
34
|
-
* Result of storage migration.
|
|
35
|
-
* Returned by __pl_storage_migrate callback.
|
|
36
|
-
*
|
|
37
|
-
* - Error result: { error: string } - serious failure (no context, etc.)
|
|
38
|
-
* - Success result: { newStorageJson: string, info: string, warn?: string } - migration succeeded or reset to initial
|
|
39
|
-
*/
|
|
40
|
-
export type MigrationResult = {
|
|
41
|
-
error: string;
|
|
42
|
-
} | {
|
|
43
|
-
error?: undefined;
|
|
44
|
-
newStorageJson: string;
|
|
45
|
-
info: string;
|
|
46
|
-
warn?: string;
|
|
47
|
-
};
|
|
48
|
-
/**
|
|
49
|
-
* Result of args derivation from storage.
|
|
50
|
-
* Returned by __pl_args_derive and __pl_prerunArgs_derive callbacks.
|
|
51
|
-
*/
|
|
52
|
-
export type ArgsDeriveResult = {
|
|
53
|
-
error: string;
|
|
54
|
-
} | {
|
|
55
|
-
error?: undefined;
|
|
56
|
-
value: unknown;
|
|
57
|
-
};
|
|
58
|
-
export { BLOCK_STORAGE_KEY, BLOCK_STORAGE_SCHEMA_VERSION };
|
|
59
|
-
//# sourceMappingURL=block_storage_vm.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"block_storage_vm.d.ts","sourceRoot":"","sources":["../src/block_storage_vm.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AAEH,OAAO,EACL,iBAAiB,EACjB,4BAA4B,EAC5B,KAAK,YAAY,EAQlB,MAAM,iBAAiB,CAAC;AAIzB;;GAEG;AACH,MAAM,WAAW,sBAAsB;IACrC,yCAAyC;IACzC,OAAO,EAAE,YAAY,CAAC;IACtB,+CAA+C;IAC/C,IAAI,EAAE,OAAO,CAAC;CACf;AAmHD;;;;;;GAMG;AACH,MAAM,MAAM,eAAe,GACvB;IAAE,KAAK,EAAE,MAAM,CAAA;CAAE,GACjB;IAAE,KAAK,CAAC,EAAE,SAAS,CAAC;IAAC,cAAc,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAC;IAAC,IAAI,CAAC,EAAE,MAAM,CAAA;CAAE,CAAC;AAiF/E;;;GAGG;AACH,MAAM,MAAM,gBAAgB,GAAG;IAAE,KAAK,EAAE,MAAM,CAAA;CAAE,GAAG;IAAE,KAAK,CAAC,EAAE,SAAS,CAAC;IAAC,KAAK,EAAE,OAAO,CAAA;CAAE,CAAC;AA0FzF,OAAO,EAAE,iBAAiB,EAAE,4BAA4B,EAAE,CAAC"}
|