@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/block_storage_vm.ts
DELETED
|
@@ -1,346 +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
|
-
|
|
24
|
-
import {
|
|
25
|
-
BLOCK_STORAGE_KEY,
|
|
26
|
-
BLOCK_STORAGE_SCHEMA_VERSION,
|
|
27
|
-
type BlockStorage,
|
|
28
|
-
type MutateStoragePayload,
|
|
29
|
-
type StorageDebugView,
|
|
30
|
-
createBlockStorage,
|
|
31
|
-
getStorageData,
|
|
32
|
-
isBlockStorage,
|
|
33
|
-
normalizeBlockStorage,
|
|
34
|
-
updateStorageData,
|
|
35
|
-
} from "./block_storage";
|
|
36
|
-
import { stringifyJson, type StringifiedJson } from "@milaboratories/pl-model-common";
|
|
37
|
-
import { tryGetCfgRenderCtx, tryRegisterCallback } from "./internal";
|
|
38
|
-
|
|
39
|
-
/**
|
|
40
|
-
* Result of storage normalization
|
|
41
|
-
*/
|
|
42
|
-
export interface NormalizeStorageResult {
|
|
43
|
-
/** The normalized BlockStorage object */
|
|
44
|
-
storage: BlockStorage;
|
|
45
|
-
/** The extracted data (what developers see) */
|
|
46
|
-
data: unknown;
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
/**
|
|
50
|
-
* Normalizes raw storage data and extracts state.
|
|
51
|
-
* Handles all formats:
|
|
52
|
-
* - New BlockStorage format (has discriminator)
|
|
53
|
-
* - Legacy V1/V2 format ({ args, uiState })
|
|
54
|
-
* - Raw V3 state (any other format)
|
|
55
|
-
*
|
|
56
|
-
* @param rawStorage - Raw data from blockStorage field (may be JSON string or object)
|
|
57
|
-
* @returns Object with normalized storage and extracted state
|
|
58
|
-
*/
|
|
59
|
-
function normalizeStorage(rawStorage: unknown): NormalizeStorageResult {
|
|
60
|
-
// Handle undefined/null
|
|
61
|
-
if (rawStorage === undefined || rawStorage === null) {
|
|
62
|
-
const storage = createBlockStorage({});
|
|
63
|
-
return { storage, data: {} };
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
// Parse JSON string if needed
|
|
67
|
-
let parsed = rawStorage;
|
|
68
|
-
if (typeof rawStorage === "string") {
|
|
69
|
-
try {
|
|
70
|
-
parsed = JSON.parse(rawStorage);
|
|
71
|
-
} catch {
|
|
72
|
-
// If parsing fails, treat string as the data
|
|
73
|
-
const storage = createBlockStorage(rawStorage);
|
|
74
|
-
return { storage, data: rawStorage };
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
// Check for BlockStorage format (has discriminator)
|
|
79
|
-
if (isBlockStorage(parsed)) {
|
|
80
|
-
const storage = normalizeBlockStorage(parsed);
|
|
81
|
-
return { storage, data: getStorageData(storage) };
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
// Check for legacy V1/V2 format: { args, uiState }
|
|
85
|
-
if (isLegacyModelV1ApiFormat(parsed)) {
|
|
86
|
-
// For legacy format, the whole object IS the data
|
|
87
|
-
const storage = createBlockStorage(parsed);
|
|
88
|
-
return { storage, data: parsed };
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
// Raw V3 data - wrap it
|
|
92
|
-
const storage = createBlockStorage(parsed);
|
|
93
|
-
return { storage, data: parsed };
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
/**
|
|
97
|
-
* Applies a state update to existing storage.
|
|
98
|
-
* Used when setData is called from the frontend.
|
|
99
|
-
*
|
|
100
|
-
* @param currentStorageJson - Current storage as JSON string (must be defined)
|
|
101
|
-
* @param newData - New data from application
|
|
102
|
-
* @returns Updated storage as JSON string
|
|
103
|
-
*/
|
|
104
|
-
function applyStorageUpdate(currentStorageJson: string, payload: MutateStoragePayload): string {
|
|
105
|
-
const { storage: currentStorage } = normalizeStorage(currentStorageJson);
|
|
106
|
-
|
|
107
|
-
// Update data while preserving other storage fields (version, plugins)
|
|
108
|
-
const updatedStorage = updateStorageData(currentStorage, payload);
|
|
109
|
-
|
|
110
|
-
return JSON.stringify(updatedStorage);
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
/**
|
|
114
|
-
* Checks if data is in legacy Model API v1 format.
|
|
115
|
-
* Legacy format has { args, uiState? } at top level without the BlockStorage discriminator.
|
|
116
|
-
*/
|
|
117
|
-
function isLegacyModelV1ApiFormat(data: unknown): data is { args?: unknown } {
|
|
118
|
-
if (data === null || typeof data !== "object") return false;
|
|
119
|
-
if (isBlockStorage(data)) return false;
|
|
120
|
-
|
|
121
|
-
const obj = data as Record<string, unknown>;
|
|
122
|
-
return "args" in obj;
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
// =============================================================================
|
|
126
|
-
// Auto-register internal callbacks when module is loaded in VM
|
|
127
|
-
// =============================================================================
|
|
128
|
-
|
|
129
|
-
// Register apply update callback (requires existing storage)
|
|
130
|
-
tryRegisterCallback(
|
|
131
|
-
"__pl_storage_applyUpdate",
|
|
132
|
-
(currentStorageJson: string, payload: MutateStoragePayload) => {
|
|
133
|
-
return applyStorageUpdate(currentStorageJson, payload);
|
|
134
|
-
},
|
|
135
|
-
);
|
|
136
|
-
|
|
137
|
-
/**
|
|
138
|
-
* Gets storage debug view from raw storage data.
|
|
139
|
-
* Returns structured debug info about the storage state.
|
|
140
|
-
*
|
|
141
|
-
* @param rawStorage - Raw data from blockStorage field (may be JSON string or object)
|
|
142
|
-
* @returns JSON string with storage debug view
|
|
143
|
-
*/
|
|
144
|
-
function getStorageDebugView(rawStorage: unknown): StringifiedJson<StorageDebugView> {
|
|
145
|
-
const { storage } = normalizeStorage(rawStorage);
|
|
146
|
-
const debugView: StorageDebugView = {
|
|
147
|
-
dataVersion: storage.__dataVersion,
|
|
148
|
-
data: storage.__data,
|
|
149
|
-
};
|
|
150
|
-
return stringifyJson(debugView);
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
// Register debug view callback
|
|
154
|
-
tryRegisterCallback("__pl_storage_debugView", (rawStorage: unknown) => {
|
|
155
|
-
return getStorageDebugView(rawStorage);
|
|
156
|
-
});
|
|
157
|
-
|
|
158
|
-
// =============================================================================
|
|
159
|
-
// Migration Support
|
|
160
|
-
// =============================================================================
|
|
161
|
-
|
|
162
|
-
/**
|
|
163
|
-
* Result of storage migration.
|
|
164
|
-
* Returned by __pl_storage_migrate callback.
|
|
165
|
-
*
|
|
166
|
-
* - Error result: { error: string } - serious failure (no context, etc.)
|
|
167
|
-
* - Success result: { newStorageJson: string, info: string, warn?: string } - migration succeeded or reset to initial
|
|
168
|
-
*/
|
|
169
|
-
export type MigrationResult =
|
|
170
|
-
| { error: string }
|
|
171
|
-
| { error?: undefined; newStorageJson: string; info: string; warn?: string };
|
|
172
|
-
|
|
173
|
-
/** Result from DataModel.migrate() */
|
|
174
|
-
interface DataMigrationResult {
|
|
175
|
-
version: string;
|
|
176
|
-
data: unknown;
|
|
177
|
-
warning?: string;
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
/**
|
|
181
|
-
* Runs storage migration using the DataModel's migrate callback.
|
|
182
|
-
* This is the main entry point for the middle layer to trigger migrations.
|
|
183
|
-
*
|
|
184
|
-
* Uses the '__pl_data_upgrade' callback registered by DataModel.registerCallbacks() which:
|
|
185
|
-
* - Handles all migration logic internally
|
|
186
|
-
* - Returns { version, data, warning? } - warning present if reset to initial data
|
|
187
|
-
*
|
|
188
|
-
* @param currentStorageJson - Current storage as JSON string (or undefined)
|
|
189
|
-
* @returns MigrationResult
|
|
190
|
-
*/
|
|
191
|
-
function migrateStorage(currentStorageJson: string | undefined): MigrationResult {
|
|
192
|
-
// Get the callback registry context
|
|
193
|
-
const ctx = tryGetCfgRenderCtx();
|
|
194
|
-
if (ctx === undefined) {
|
|
195
|
-
return { error: "Not in config rendering context" };
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
// Normalize storage to get current data and version
|
|
199
|
-
const { storage: currentStorage, data: currentData } = normalizeStorage(currentStorageJson);
|
|
200
|
-
const currentVersion = currentStorage.__dataVersion;
|
|
201
|
-
|
|
202
|
-
// Helper to create storage with given data and version
|
|
203
|
-
const createStorageJson = (data: unknown, version: string): string => {
|
|
204
|
-
return JSON.stringify({
|
|
205
|
-
...currentStorage,
|
|
206
|
-
__dataVersion: version,
|
|
207
|
-
__data: data,
|
|
208
|
-
});
|
|
209
|
-
};
|
|
210
|
-
|
|
211
|
-
// Get the migrate callback (registered by DataModel.registerCallbacks())
|
|
212
|
-
const migrateCallback = ctx.callbackRegistry["__pl_data_upgrade"] as
|
|
213
|
-
| ((v: { version: string; data: unknown }) => DataMigrationResult)
|
|
214
|
-
| undefined;
|
|
215
|
-
if (typeof migrateCallback !== "function") {
|
|
216
|
-
return { error: "__pl_data_upgrade callback not found (DataModel not registered)" };
|
|
217
|
-
}
|
|
218
|
-
|
|
219
|
-
// Call the migrator's migrate function
|
|
220
|
-
let result: DataMigrationResult;
|
|
221
|
-
try {
|
|
222
|
-
result = migrateCallback({ version: currentVersion, data: currentData });
|
|
223
|
-
} catch (e) {
|
|
224
|
-
const errorMsg = e instanceof Error ? e.message : String(e);
|
|
225
|
-
return { error: `migrate() threw: ${errorMsg}` };
|
|
226
|
-
}
|
|
227
|
-
|
|
228
|
-
// Build info message
|
|
229
|
-
const info =
|
|
230
|
-
result.version === currentVersion
|
|
231
|
-
? `No migration needed (${currentVersion})`
|
|
232
|
-
: result.warning
|
|
233
|
-
? `Reset to initial data (${result.version})`
|
|
234
|
-
: `Migrated ${currentVersion}→${result.version}`;
|
|
235
|
-
|
|
236
|
-
return {
|
|
237
|
-
newStorageJson: createStorageJson(result.data, result.version),
|
|
238
|
-
info,
|
|
239
|
-
warn: result.warning,
|
|
240
|
-
};
|
|
241
|
-
}
|
|
242
|
-
|
|
243
|
-
// Register migrate callback
|
|
244
|
-
tryRegisterCallback("__pl_storage_migrate", (currentStorageJson: string | undefined) => {
|
|
245
|
-
return migrateStorage(currentStorageJson);
|
|
246
|
-
});
|
|
247
|
-
|
|
248
|
-
// =============================================================================
|
|
249
|
-
// Args Derivation from Storage
|
|
250
|
-
// =============================================================================
|
|
251
|
-
|
|
252
|
-
/**
|
|
253
|
-
* Result of args derivation from storage.
|
|
254
|
-
* Returned by __pl_args_derive and __pl_prerunArgs_derive callbacks.
|
|
255
|
-
*/
|
|
256
|
-
export type ArgsDeriveResult = { error: string } | { error?: undefined; value: unknown };
|
|
257
|
-
|
|
258
|
-
/**
|
|
259
|
-
* Derives args from storage using the registered 'args' callback.
|
|
260
|
-
* This extracts data from storage and passes it to the block's args() function.
|
|
261
|
-
*
|
|
262
|
-
* @param storageJson - Storage as JSON string
|
|
263
|
-
* @returns ArgsDeriveResult with derived args or error
|
|
264
|
-
*/
|
|
265
|
-
function deriveArgsFromStorage(storageJson: string): ArgsDeriveResult {
|
|
266
|
-
const ctx = tryGetCfgRenderCtx();
|
|
267
|
-
if (ctx === undefined) {
|
|
268
|
-
return { error: "Not in config rendering context" };
|
|
269
|
-
}
|
|
270
|
-
|
|
271
|
-
// Extract data from storage
|
|
272
|
-
const { data } = normalizeStorage(storageJson);
|
|
273
|
-
|
|
274
|
-
// Get the args callback (registered by BlockModelV3.args())
|
|
275
|
-
const argsCallback = ctx.callbackRegistry["args"] as ((data: unknown) => unknown) | undefined;
|
|
276
|
-
if (typeof argsCallback !== "function") {
|
|
277
|
-
return { error: "args callback not found" };
|
|
278
|
-
}
|
|
279
|
-
|
|
280
|
-
// Call the args callback with extracted data
|
|
281
|
-
try {
|
|
282
|
-
const result = argsCallback(data);
|
|
283
|
-
return { value: result };
|
|
284
|
-
} catch (e) {
|
|
285
|
-
const errorMsg = e instanceof Error ? e.message : String(e);
|
|
286
|
-
return { error: `args() threw: ${errorMsg}` };
|
|
287
|
-
}
|
|
288
|
-
}
|
|
289
|
-
|
|
290
|
-
// Register args derivation callback
|
|
291
|
-
tryRegisterCallback("__pl_args_derive", (storageJson: string) => {
|
|
292
|
-
return deriveArgsFromStorage(storageJson);
|
|
293
|
-
});
|
|
294
|
-
|
|
295
|
-
/**
|
|
296
|
-
* Derives prerunArgs from storage using the registered 'prerunArgs' callback.
|
|
297
|
-
* Falls back to 'args' callback if 'prerunArgs' is not defined.
|
|
298
|
-
*
|
|
299
|
-
* @param storageJson - Storage as JSON string
|
|
300
|
-
* @returns ArgsDeriveResult with derived prerunArgs or error
|
|
301
|
-
*/
|
|
302
|
-
function derivePrerunArgsFromStorage(storageJson: string): ArgsDeriveResult {
|
|
303
|
-
const ctx = tryGetCfgRenderCtx();
|
|
304
|
-
if (ctx === undefined) {
|
|
305
|
-
return { error: "Not in config rendering context" };
|
|
306
|
-
}
|
|
307
|
-
|
|
308
|
-
// Extract data from storage
|
|
309
|
-
const { data } = normalizeStorage(storageJson);
|
|
310
|
-
|
|
311
|
-
// Try prerunArgs callback first
|
|
312
|
-
const prerunArgsCallback = ctx.callbackRegistry["prerunArgs"] as
|
|
313
|
-
| ((data: unknown) => unknown)
|
|
314
|
-
| undefined;
|
|
315
|
-
if (typeof prerunArgsCallback === "function") {
|
|
316
|
-
try {
|
|
317
|
-
const result = prerunArgsCallback(data);
|
|
318
|
-
return { value: result };
|
|
319
|
-
} catch (e) {
|
|
320
|
-
const errorMsg = e instanceof Error ? e.message : String(e);
|
|
321
|
-
return { error: `prerunArgs() threw: ${errorMsg}` };
|
|
322
|
-
}
|
|
323
|
-
}
|
|
324
|
-
|
|
325
|
-
// Fall back to args callback
|
|
326
|
-
const argsCallback = ctx.callbackRegistry["args"] as ((data: unknown) => unknown) | undefined;
|
|
327
|
-
if (typeof argsCallback !== "function") {
|
|
328
|
-
return { error: "args callback not found (fallback from missing prerunArgs)" };
|
|
329
|
-
}
|
|
330
|
-
|
|
331
|
-
try {
|
|
332
|
-
const result = argsCallback(data);
|
|
333
|
-
return { value: result };
|
|
334
|
-
} catch (e) {
|
|
335
|
-
const errorMsg = e instanceof Error ? e.message : String(e);
|
|
336
|
-
return { error: `args() threw (fallback): ${errorMsg}` };
|
|
337
|
-
}
|
|
338
|
-
}
|
|
339
|
-
|
|
340
|
-
// Register prerunArgs derivation callback
|
|
341
|
-
tryRegisterCallback("__pl_prerunArgs_derive", (storageJson: string) => {
|
|
342
|
-
return derivePrerunArgsFromStorage(storageJson);
|
|
343
|
-
});
|
|
344
|
-
|
|
345
|
-
// Export discriminator key and schema version for external checks
|
|
346
|
-
export { BLOCK_STORAGE_KEY, BLOCK_STORAGE_SCHEMA_VERSION };
|
package/src/branding.ts
DELETED
package/src/sdk_info.ts
DELETED
package/src/unionize.ts
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
/** Patch for the structural object */
|
|
2
|
-
export type Patch<K, V> = {
|
|
3
|
-
/** Field name to patch */
|
|
4
|
-
readonly key: K;
|
|
5
|
-
/** New value for the field */
|
|
6
|
-
readonly value: V;
|
|
7
|
-
};
|
|
8
|
-
|
|
9
|
-
/** Creates union type of all possible shallow patches for the given structure */
|
|
10
|
-
export type Unionize<T extends Record<string, unknown>> = {
|
|
11
|
-
[K in keyof T]: Patch<K, T[K]>;
|
|
12
|
-
}[keyof T];
|