@milaboratories/pl-middle-layer 1.43.8 → 1.43.10
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/middle_layer/middle_layer.cjs +1 -1
- package/dist/middle_layer/middle_layer.cjs.map +1 -1
- package/dist/middle_layer/middle_layer.js +1 -1
- package/dist/middle_layer/middle_layer.js.map +1 -1
- package/dist/middle_layer/project.cjs +33 -24
- package/dist/middle_layer/project.cjs.map +1 -1
- package/dist/middle_layer/project.d.ts +1 -0
- package/dist/middle_layer/project.d.ts.map +1 -1
- package/dist/middle_layer/project.js +33 -24
- package/dist/middle_layer/project.js.map +1 -1
- package/dist/mutator/project.cjs +3 -3
- package/dist/mutator/project.cjs.map +1 -1
- package/dist/mutator/project.d.ts +1 -1
- package/dist/mutator/project.d.ts.map +1 -1
- package/dist/mutator/project.js +3 -3
- package/dist/mutator/project.js.map +1 -1
- package/package.json +14 -14
- package/src/middle_layer/middle_layer.ts +1 -1
- package/src/middle_layer/project.ts +32 -21
- package/src/mutator/project.ts +3 -2
|
@@ -66,12 +66,15 @@ class Project {
|
|
|
66
66
|
this.refreshLoopResult = this.refreshLoop();
|
|
67
67
|
this.activeConfigs = activeConfigs(projectTree.entry(), env);
|
|
68
68
|
}
|
|
69
|
+
get projectLockId() {
|
|
70
|
+
return 'project:' + this.rid.toString();
|
|
71
|
+
}
|
|
69
72
|
async refreshLoop() {
|
|
70
73
|
while (!this.destroyed) {
|
|
71
74
|
try {
|
|
72
75
|
await withProject(this.env.projectHelper, this.env.pl, this.rid, (prj) => {
|
|
73
76
|
prj.doRefresh(this.env.ops.stagingRenderingRate);
|
|
74
|
-
});
|
|
77
|
+
}, { name: 'doRefresh', lockId: this.projectLockId });
|
|
75
78
|
await this.activeConfigs.getValue();
|
|
76
79
|
await setTimeout(this.env.ops.projectRefreshInterval, this.abortController.signal);
|
|
77
80
|
// Block computables houskeeping
|
|
@@ -112,18 +115,24 @@ class Project {
|
|
|
112
115
|
const preparedBp = await this.env.bpPreparer.prepare(blockPackSpec);
|
|
113
116
|
const blockCfgContainer = await this.env.bpPreparer.getBlockConfigContainer(blockPackSpec);
|
|
114
117
|
const blockCfg = extractConfig(blockCfgContainer); // full content of this var should never be persisted
|
|
115
|
-
await withProjectAuthored(this.env.projectHelper, this.env.pl, this.rid, author, (mut) =>
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
118
|
+
await withProjectAuthored(this.env.projectHelper, this.env.pl, this.rid, author, (mut) => {
|
|
119
|
+
return mut.addBlock({
|
|
120
|
+
id: blockId,
|
|
121
|
+
label: blockLabel,
|
|
122
|
+
renderingMode: blockCfg.renderingMode,
|
|
123
|
+
}, {
|
|
124
|
+
args: canonicalize(blockCfg.initialArgs),
|
|
125
|
+
uiState: canonicalize(blockCfg.initialUiState),
|
|
126
|
+
blockPack: preparedBp,
|
|
127
|
+
}, before);
|
|
119
128
|
}, {
|
|
120
|
-
|
|
121
|
-
uiState: canonicalize(blockCfg.initialUiState),
|
|
122
|
-
blockPack: preparedBp,
|
|
123
|
-
}, before), { retryOptions: {
|
|
129
|
+
retryOptions: {
|
|
124
130
|
...DefaultRetryOptions,
|
|
125
131
|
backoffMultiplier: DefaultRetryOptions.backoffMultiplier * 1.1,
|
|
126
|
-
}
|
|
132
|
+
},
|
|
133
|
+
name: 'addBlock',
|
|
134
|
+
lockId: this.projectLockId,
|
|
135
|
+
});
|
|
127
136
|
await this.projectTree.refreshState();
|
|
128
137
|
return blockId;
|
|
129
138
|
}
|
|
@@ -140,7 +149,7 @@ class Project {
|
|
|
140
149
|
* @return returns newly created block id
|
|
141
150
|
* */
|
|
142
151
|
async duplicateBlock(originalBlockId, before, author = undefined, newBlockId = randomUUID()) {
|
|
143
|
-
await withProjectAuthored(this.env.projectHelper, this.env.pl, this.rid, author, (mut) => mut.duplicateBlock(originalBlockId, newBlockId, before));
|
|
152
|
+
await withProjectAuthored(this.env.projectHelper, this.env.pl, this.rid, author, (mut) => mut.duplicateBlock(originalBlockId, newBlockId, before), { name: 'duplicateBlock', lockId: this.projectLockId });
|
|
144
153
|
await this.projectTree.refreshState();
|
|
145
154
|
return newBlockId;
|
|
146
155
|
}
|
|
@@ -151,12 +160,12 @@ class Project {
|
|
|
151
160
|
async updateBlockPack(blockId, blockPackSpec, resetArgs = false, author) {
|
|
152
161
|
const preparedBp = await this.env.bpPreparer.prepare(blockPackSpec);
|
|
153
162
|
const blockCfg = extractConfig(await this.env.bpPreparer.getBlockConfigContainer(blockPackSpec));
|
|
154
|
-
await withProjectAuthored(this.env.projectHelper, this.env.pl, this.rid, author, (mut) => mut.migrateBlockPack(blockId, preparedBp, resetArgs ? { args: blockCfg.initialArgs, uiState: blockCfg.initialUiState } : undefined));
|
|
163
|
+
await withProjectAuthored(this.env.projectHelper, this.env.pl, this.rid, author, (mut) => mut.migrateBlockPack(blockId, preparedBp, resetArgs ? { args: blockCfg.initialArgs, uiState: blockCfg.initialUiState } : undefined), { name: 'updateBlockPack', lockId: this.projectLockId });
|
|
155
164
|
await this.projectTree.refreshState();
|
|
156
165
|
}
|
|
157
166
|
/** Deletes a block with all associated data. */
|
|
158
167
|
async deleteBlock(blockId, author) {
|
|
159
|
-
await withProjectAuthored(this.env.projectHelper, this.env.pl, this.rid, author, (mut) => mut.deleteBlock(blockId));
|
|
168
|
+
await withProjectAuthored(this.env.projectHelper, this.env.pl, this.rid, author, (mut) => mut.deleteBlock(blockId), { name: 'deleteBlock', lockId: this.projectLockId });
|
|
160
169
|
this.navigationStates.deleteBlock(blockId);
|
|
161
170
|
await this.projectTree.refreshState();
|
|
162
171
|
}
|
|
@@ -170,10 +179,10 @@ class Project {
|
|
|
170
179
|
await withProjectAuthored(this.env.projectHelper, this.env.pl, this.rid, author, (mut) => {
|
|
171
180
|
const currentStructure = mut.structure;
|
|
172
181
|
if (currentStructure.groups.length !== 1)
|
|
173
|
-
throw new Error('Unexpected project structure, non-
|
|
182
|
+
throw new Error('Unexpected project structure, non-singular block group');
|
|
174
183
|
const currentGroup = currentStructure.groups[0];
|
|
175
184
|
if (currentGroup.blocks.length !== blocks.length)
|
|
176
|
-
throw new Error(`
|
|
185
|
+
throw new Error(`Length mismatch: ${currentGroup.blocks.length} !== ${blocks.length}`);
|
|
177
186
|
if (new Set(blocks).size !== blocks.length)
|
|
178
187
|
throw new Error(`Repeated block ids`);
|
|
179
188
|
const newStructure = {
|
|
@@ -191,7 +200,7 @@ class Project {
|
|
|
191
200
|
],
|
|
192
201
|
};
|
|
193
202
|
mut.updateStructure(newStructure);
|
|
194
|
-
});
|
|
203
|
+
}, { name: 'reorderBlocks', lockId: this.projectLockId });
|
|
195
204
|
await this.projectTree.refreshState();
|
|
196
205
|
}
|
|
197
206
|
/**
|
|
@@ -200,7 +209,7 @@ class Project {
|
|
|
200
209
|
* stale state.
|
|
201
210
|
* */
|
|
202
211
|
async runBlock(blockId) {
|
|
203
|
-
await withProject(this.env.projectHelper, this.env.pl, this.rid, (mut) => mut.renderProduction([blockId], true));
|
|
212
|
+
await withProject(this.env.projectHelper, this.env.pl, this.rid, (mut) => mut.renderProduction([blockId], true), { name: 'runBlock', lockId: this.projectLockId });
|
|
204
213
|
await this.projectTree.refreshState();
|
|
205
214
|
}
|
|
206
215
|
/**
|
|
@@ -209,7 +218,7 @@ class Project {
|
|
|
209
218
|
* calculated.
|
|
210
219
|
* */
|
|
211
220
|
async stopBlock(blockId) {
|
|
212
|
-
await withProject(this.env.projectHelper, this.env.pl, this.rid, (mut) => mut.stopProduction(blockId));
|
|
221
|
+
await withProject(this.env.projectHelper, this.env.pl, this.rid, (mut) => mut.stopProduction(blockId), { name: 'stopBlock', lockId: this.projectLockId });
|
|
213
222
|
await this.projectTree.refreshState();
|
|
214
223
|
}
|
|
215
224
|
// /** Update block label. */
|
|
@@ -226,7 +235,7 @@ class Project {
|
|
|
226
235
|
* in collaborative editing scenario.
|
|
227
236
|
* */
|
|
228
237
|
async setBlockArgs(blockId, args, author) {
|
|
229
|
-
await withProjectAuthored(this.env.projectHelper, this.env.pl, this.rid, author, (mut) => mut.setStates([{ blockId, args }]));
|
|
238
|
+
await withProjectAuthored(this.env.projectHelper, this.env.pl, this.rid, author, (mut) => mut.setStates([{ blockId, args }]), { name: 'setBlockArgs', lockId: this.projectLockId });
|
|
230
239
|
await this.projectTree.refreshState();
|
|
231
240
|
}
|
|
232
241
|
/**
|
|
@@ -236,7 +245,7 @@ class Project {
|
|
|
236
245
|
* in collaborative editing scenario.
|
|
237
246
|
* */
|
|
238
247
|
async setUiState(blockId, uiState, author) {
|
|
239
|
-
await withProjectAuthored(this.env.projectHelper, this.env.pl, this.rid, author, (mut) => mut.setStates([{ blockId, uiState }]));
|
|
248
|
+
await withProjectAuthored(this.env.projectHelper, this.env.pl, this.rid, author, (mut) => mut.setStates([{ blockId, uiState }]), { name: 'setUiState', lockId: this.projectLockId });
|
|
240
249
|
await this.projectTree.refreshState();
|
|
241
250
|
}
|
|
242
251
|
/**
|
|
@@ -255,14 +264,14 @@ class Project {
|
|
|
255
264
|
async setBlockArgsAndUiState(blockId, args, uiState, author) {
|
|
256
265
|
await withProjectAuthored(this.env.projectHelper, this.env.pl, this.rid, author, (mut) => {
|
|
257
266
|
mut.setStates([{ blockId, args, uiState }]);
|
|
258
|
-
});
|
|
267
|
+
}, { name: 'setBlockArgsAndUiState', lockId: this.projectLockId });
|
|
259
268
|
await this.projectTree.refreshState();
|
|
260
269
|
}
|
|
261
270
|
/** Update block settings */
|
|
262
271
|
async setBlockSettings(blockId, newValue) {
|
|
263
272
|
await withProjectAuthored(this.env.projectHelper, this.env.pl, this.rid, undefined, (mut) => {
|
|
264
273
|
mut.setBlockSettings(blockId, newValue);
|
|
265
|
-
});
|
|
274
|
+
}, { name: 'setBlockSettings' });
|
|
266
275
|
await this.projectTree.refreshState();
|
|
267
276
|
}
|
|
268
277
|
/** Resets arguments and ui state of the block to initial state */
|
|
@@ -275,7 +284,7 @@ class Project {
|
|
|
275
284
|
const config = extractConfig(cachedDeserialize(notEmpty(bpData.data)).config);
|
|
276
285
|
await withProjectAuthored(this.env.projectHelper, tx, this.rid, author, (prj) => {
|
|
277
286
|
prj.setStates([{ blockId, args: config.initialArgs, uiState: config.initialUiState }]);
|
|
278
|
-
});
|
|
287
|
+
}, { name: 'resetBlockArgsAndUiState', lockId: this.projectLockId });
|
|
279
288
|
await tx.commit();
|
|
280
289
|
});
|
|
281
290
|
await this.projectTree.refreshState();
|
|
@@ -362,7 +371,7 @@ class Project {
|
|
|
362
371
|
// Applying migrations to the project resource, if needed
|
|
363
372
|
await applyProjectMigrations(env.pl, rid);
|
|
364
373
|
// Doing a no-op mutation to apply all migration and schema fixes
|
|
365
|
-
await withProject(env.projectHelper, env.pl, rid, (_) => { });
|
|
374
|
+
await withProject(env.projectHelper, env.pl, rid, (_) => { }, { name: 'init' });
|
|
366
375
|
// Loading project tree
|
|
367
376
|
const projectTree = await SynchronizedTreeState.init(env.pl, rid, {
|
|
368
377
|
...env.ops.defaultTreeOptions,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"project.js","sources":["../../src/middle_layer/project.ts"],"sourcesContent":["import type { MiddleLayerEnvironment } from './middle_layer';\nimport type {\n FieldData,\n OptionalAnyResourceId,\n ResourceId,\n} from '@milaboratories/pl-client';\nimport {\n DefaultRetryOptions,\n ensureResourceIdNotNull,\n field,\n isNotFoundError,\n isTimeoutOrCancelError,\n Pl,\n resourceIdToString,\n} from '@milaboratories/pl-client';\nimport type { ComputableStableDefined, ComputableValueOrErrors } from '@milaboratories/computable';\nimport { Computable } from '@milaboratories/computable';\nimport { projectOverview } from './project_overview';\nimport type { BlockPackSpecAny } from '../model';\nimport { randomUUID } from 'node:crypto';\nimport { withProject, withProjectAuthored } from '../mutator/project';\nimport type { ExtendedResourceData } from '@milaboratories/pl-tree';\nimport { SynchronizedTreeState, treeDumpStats } from '@milaboratories/pl-tree';\nimport { setTimeout } from 'node:timers/promises';\nimport { frontendData } from './frontend_path';\nimport type { NavigationState } from '@milaboratories/pl-model-common';\nimport { blockArgsAndUiState, blockOutputs } from './block';\nimport type { FrontendData } from '../model/frontend';\nimport type { ProjectStructure } from '../model/project_model';\nimport { projectFieldName } from '../model/project_model';\nimport { cachedDeserialize, notEmpty } from '@milaboratories/ts-helpers';\nimport type { BlockPackInfo } from '../model/block_pack';\nimport type {\n ProjectOverview,\n AuthorMarker,\n BlockStateInternal,\n BlockSettings,\n} from '@milaboratories/pl-model-middle-layer';\nimport { activeConfigs } from './active_cfg';\nimport { NavigationStates } from './navigation_states';\nimport { extractConfig } from '@platforma-sdk/model';\nimport fs from 'node:fs/promises';\nimport canonicalize from 'canonicalize';\nimport type { ProjectOverviewLight } from './project_overview_light';\nimport { projectOverviewLight } from './project_overview_light';\nimport { applyProjectMigrations } from '../mutator/migration';\n\ntype BlockStateComputables = {\n readonly fullState: Computable<BlockStateInternal>;\n};\n\nfunction stringifyForDump(object: unknown): string {\n return JSON.stringify(object, (key, value) => {\n if (typeof value === 'bigint')\n return resourceIdToString(value as OptionalAnyResourceId);\n else if (\n ArrayBuffer.isView(value)\n || value instanceof Int8Array\n || value instanceof Uint8Array\n || value instanceof Uint8ClampedArray\n || value instanceof Int16Array\n || value instanceof Uint16Array\n || value instanceof Int32Array\n || value instanceof Uint32Array\n || value instanceof Float32Array\n || value instanceof Float64Array\n || value instanceof BigInt64Array\n || value instanceof BigUint64Array\n )\n return Buffer.from(value.buffer, value.byteOffset, value.byteLength).toString('base64');\n else if (Buffer.isBuffer(value))\n return value.toString('base64');\n\n return value;\n });\n}\n\n/** Data access object, to manipulate and read single opened (!) project data. */\nexport class Project {\n /** Underlying pl resource id */\n public readonly rid: ResourceId;\n\n /** Data for the left panel, contain basic information about block status. */\n public readonly overview: ComputableStableDefined<ProjectOverview>;\n private readonly overviewLight: Computable<ProjectOverviewLight>;\n\n private readonly navigationStates = new NavigationStates();\n // null is set for deleted blocks\n private readonly blockComputables = new Map<string, BlockStateComputables | null>();\n\n private readonly blockFrontends = new Map<string, ComputableStableDefined<FrontendData>>();\n private readonly activeConfigs: Computable<unknown[]>;\n private readonly refreshLoopResult: Promise<void>;\n\n private readonly abortController = new AbortController();\n private destroyed = false;\n\n constructor(\n private readonly env: MiddleLayerEnvironment,\n rid: ResourceId,\n private readonly projectTree: SynchronizedTreeState,\n ) {\n this.overview = projectOverview(\n projectTree.entry(),\n this.navigationStates,\n env,\n ).withPreCalculatedValueTree();\n this.overviewLight = projectOverviewLight(projectTree.entry())\n .withPreCalculatedValueTree();\n this.rid = rid;\n this.refreshLoopResult = this.refreshLoop();\n this.activeConfigs = activeConfigs(projectTree.entry(), env);\n }\n\n private async refreshLoop(): Promise<void> {\n while (!this.destroyed) {\n try {\n await withProject(this.env.projectHelper, this.env.pl, this.rid, (prj) => {\n prj.doRefresh(this.env.ops.stagingRenderingRate);\n });\n await this.activeConfigs.getValue();\n await setTimeout(this.env.ops.projectRefreshInterval, this.abortController.signal);\n\n // Block computables houskeeping\n const overviewLight = await this.overviewLight.getValue();\n const existingBlocks = new Set(overviewLight.listOfBlocks);\n // Doing cleanup for deleted blocks\n for (const blockId of this.blockComputables.keys()) {\n if (!existingBlocks.has(blockId)) {\n const computable = this.blockComputables.get(blockId);\n if (computable !== undefined && computable !== null) computable.fullState.resetState();\n this.blockComputables.set(blockId, null);\n }\n }\n } catch (e: unknown) {\n if (isNotFoundError(e)) {\n console.warn(\n 'project refresh routine terminated, because project was externally deleted',\n );\n break;\n } else if (!isTimeoutOrCancelError(e))\n throw new Error('Unexpected exception', { cause: e });\n }\n }\n }\n\n /**\n * Adds new block to the project.\n *\n * @param blockLabel block label / title visible to the user\n * @param blockPackSpec object describing the \"block type\", read more in the type docs\n * @param before id of the block to insert new block before\n * @param blockId internal id to be assigned for the block, this arg can be omitted\n * then, randomly generated UUID will be assigned automatically\n *\n * @return returns newly created block id\n * */\n public async addBlock(\n blockLabel: string,\n blockPackSpec: BlockPackSpecAny,\n before?: string,\n author: AuthorMarker | undefined = undefined,\n blockId: string = randomUUID(),\n ): Promise<string> {\n const preparedBp = await this.env.bpPreparer.prepare(blockPackSpec);\n const blockCfgContainer = await this.env.bpPreparer.getBlockConfigContainer(blockPackSpec);\n const blockCfg = extractConfig(blockCfgContainer); // full content of this var should never be persisted\n await withProjectAuthored(this.env.projectHelper, this.env.pl, this.rid, author, (mut) =>\n mut.addBlock(\n {\n id: blockId,\n label: blockLabel,\n renderingMode: blockCfg.renderingMode,\n },\n {\n args: canonicalize(blockCfg.initialArgs)!,\n uiState: canonicalize(blockCfg.initialUiState)!,\n blockPack: preparedBp,\n },\n before,\n ),\n { retryOptions: {\n ...DefaultRetryOptions,\n backoffMultiplier: DefaultRetryOptions.backoffMultiplier * 1.1,\n } },\n );\n await this.projectTree.refreshState();\n\n return blockId;\n }\n\n /**\n * Duplicates an existing block by copying all its fields and state.\n * This method works at the mutator level for efficient block copying.\n *\n * @param originalBlockId id of the block to duplicate\n * @param before id of the block to insert new block before\n * @param author author marker for the duplication operation\n * @param newBlockId internal id to be assigned for the duplicated block,\n * if omitted, a randomly generated UUID will be assigned\n *\n * @return returns newly created block id\n * */\n public async duplicateBlock(\n originalBlockId: string,\n before?: string,\n author: AuthorMarker | undefined = undefined,\n newBlockId: string = randomUUID(),\n ): Promise<string> {\n await withProjectAuthored(this.env.projectHelper, this.env.pl, this.rid, author, (mut) =>\n mut.duplicateBlock(originalBlockId, newBlockId, before),\n );\n await this.projectTree.refreshState();\n\n return newBlockId;\n }\n\n /**\n * Update block to new block pack, optionally resetting args and ui state to\n * initial values\n * */\n public async updateBlockPack(\n blockId: string,\n blockPackSpec: BlockPackSpecAny,\n resetArgs: boolean = false,\n author?: AuthorMarker,\n ): Promise<void> {\n const preparedBp = await this.env.bpPreparer.prepare(blockPackSpec);\n const blockCfg = extractConfig(await this.env.bpPreparer.getBlockConfigContainer(blockPackSpec));\n await withProjectAuthored(this.env.projectHelper, this.env.pl, this.rid, author, (mut) =>\n mut.migrateBlockPack(\n blockId,\n preparedBp,\n resetArgs ? { args: blockCfg.initialArgs, uiState: blockCfg.initialUiState } : undefined,\n ),\n );\n await this.projectTree.refreshState();\n }\n\n /** Deletes a block with all associated data. */\n public async deleteBlock(blockId: string, author?: AuthorMarker): Promise<void> {\n await withProjectAuthored(this.env.projectHelper, this.env.pl, this.rid, author, (mut) => mut.deleteBlock(blockId));\n this.navigationStates.deleteBlock(blockId);\n await this.projectTree.refreshState();\n }\n\n /**\n * Updates block order according to the given array of block ids.\n *\n * Provided array must contain exactly the same set of ids current project cosists of,\n * an error will be thrown instead.\n */\n public async reorderBlocks(blocks: string[], author?: AuthorMarker): Promise<void> {\n await withProjectAuthored(this.env.projectHelper, this.env.pl, this.rid, author, (mut) => {\n const currentStructure = mut.structure;\n if (currentStructure.groups.length !== 1)\n throw new Error('Unexpected project structure, non-sinular block group');\n const currentGroup = currentStructure.groups[0];\n if (currentGroup.blocks.length !== blocks.length)\n throw new Error(`Lengh mismatch: ${currentGroup.blocks.length} !== ${blocks.length}`);\n if (new Set<string>(blocks).size !== blocks.length) throw new Error(`Repeated block ids`);\n const newStructure: ProjectStructure = {\n groups: [\n {\n id: currentGroup.id,\n label: currentGroup.label,\n blocks: blocks.map((blockId) => {\n const block = currentGroup.blocks.find((b) => b.id === blockId);\n if (block === undefined) throw new Error(`Can't find block: ${blockId}`);\n return block;\n }),\n },\n ],\n };\n mut.updateStructure(newStructure);\n });\n await this.projectTree.refreshState();\n }\n\n /**\n * Renders production part of the block starting all connected heavy computations.\n * Upstream blocks of the specified block will be started automatically if in\n * stale state.\n * */\n public async runBlock(blockId: string): Promise<void> {\n await withProject(this.env.projectHelper, this.env.pl, this.rid, (mut) => mut.renderProduction([blockId], true));\n await this.projectTree.refreshState();\n }\n\n /**\n * Stops the block if it is running by destroying its production state. All\n * its downstreams will also be destroyed or moved to limbo if already\n * calculated.\n * */\n public async stopBlock(blockId: string): Promise<void> {\n await withProject(this.env.projectHelper, this.env.pl, this.rid, (mut) => mut.stopProduction(blockId));\n await this.projectTree.refreshState();\n }\n\n // /** Update block label. */\n // public async setBlockLabel(blockId: string, label: string, author?: AuthorMarker) {\n // await withProjectAuthored(this.env.pl, this.rid, author, (mut) => {\n // mut.setBlockLabel(blockId, label);\n // });\n // await this.projectTree.refreshState();\n // }\n\n /**\n * Sets block args, and changes whole project state accordingly.\n * Along with setting arguments one can specify author marker, that will be\n * transactionally associated with the block, to facilitate conflict resolution\n * in collaborative editing scenario.\n * */\n public async setBlockArgs(blockId: string, args: unknown, author?: AuthorMarker) {\n await withProjectAuthored(this.env.projectHelper, this.env.pl, this.rid, author, (mut) =>\n mut.setStates([{ blockId, args }]),\n );\n await this.projectTree.refreshState();\n }\n\n /**\n * Sets ui block state associated with the block.\n * Along with setting arguments one can specify author marker, that will be\n * transactionally associated with the block, to facilitate conflict resolution\n * in collaborative editing scenario.\n * */\n public async setUiState(blockId: string, uiState: unknown, author?: AuthorMarker) {\n await withProjectAuthored(this.env.projectHelper, this.env.pl, this.rid, author, (mut) =>\n mut.setStates([{ blockId, uiState }]),\n );\n await this.projectTree.refreshState();\n }\n\n /**\n * Sets navigation state.\n * */\n // eslint-disable-next-line @typescript-eslint/require-await\n public async setNavigationState(blockId: string, state: NavigationState): Promise<void> {\n this.navigationStates.setState(blockId, state);\n }\n\n /**\n * Sets block args and ui state, and changes the whole project state accordingly.\n * Along with setting arguments one can specify author marker, that will be\n * transactionally associated with the block, to facilitate conflict resolution\n * in collaborative editing scenario.\n * */\n public async setBlockArgsAndUiState(\n blockId: string,\n args: unknown,\n uiState: unknown,\n author?: AuthorMarker,\n ) {\n await withProjectAuthored(this.env.projectHelper, this.env.pl, this.rid, author, (mut) => {\n mut.setStates([{ blockId, args, uiState }]);\n });\n await this.projectTree.refreshState();\n }\n\n /** Update block settings */\n public async setBlockSettings(blockId: string, newValue: BlockSettings) {\n await withProjectAuthored(this.env.projectHelper, this.env.pl, this.rid, undefined, (mut) => {\n mut.setBlockSettings(blockId, newValue);\n });\n await this.projectTree.refreshState();\n }\n\n /** Resets arguments and ui state of the block to initial state */\n public async resetBlockArgsAndUiState(blockId: string, author?: AuthorMarker): Promise<void> {\n await this.env.pl.withWriteTx('BlockInputsReset', async (tx) => {\n // reading default arg values from block pack\n const bpHolderRid = ensureResourceIdNotNull(\n (await tx.getField(field(this.rid, projectFieldName(blockId, 'blockPack')))).value,\n );\n const bpRid = ensureResourceIdNotNull(\n (await tx.getField(field(bpHolderRid, Pl.HolderRefField))).value,\n );\n const bpData = await tx.getResourceData(bpRid, false);\n const config = extractConfig(cachedDeserialize<BlockPackInfo>(notEmpty(bpData.data)).config);\n await withProjectAuthored(this.env.projectHelper, tx, this.rid, author, (prj) => {\n prj.setStates([{ blockId, args: config.initialArgs, uiState: config.initialUiState }]);\n });\n await tx.commit();\n });\n await this.projectTree.refreshState();\n }\n\n private getBlockComputables(blockId: string): BlockStateComputables {\n const cached = this.blockComputables.get(blockId);\n if (cached === null) throw new Error(`Block ${blockId} is deleted`);\n if (cached === undefined) {\n // state consists of inputs (args + ui state) and outputs\n const outputs = blockOutputs(this.projectTree.entry(), blockId, this.env);\n const fullState = Computable.make(\n (ctx) => {\n return {\n argsAndUiState: blockArgsAndUiState(this.projectTree.entry(), blockId, ctx),\n outputs,\n navigationState: this.navigationStates.getState(blockId),\n overview: this.overview,\n };\n },\n {\n postprocessValue: (v) => {\n const sdkVersion = v.overview?.blocks?.find((b) => b.id == blockId)?.sdkVersion;\n const toString = sdkVersion && shouldStillUseStringErrors(sdkVersion);\n const newOutputs = toString && v.outputs !== undefined\n ? convertErrorsToStrings(v.outputs)\n : v.outputs;\n\n return {\n ...v.argsAndUiState,\n outputs: newOutputs,\n navigationState: v.navigationState,\n } as BlockStateInternal;\n },\n },\n );\n\n const computables: BlockStateComputables = {\n fullState: fullState.withPreCalculatedValueTree(),\n };\n\n this.blockComputables.set(blockId, computables);\n\n return computables;\n }\n return cached;\n }\n\n /**\n * Returns a computable, that can be used to retrieve and watch full block state,\n * including outputs, arguments, ui state.\n * */\n public getBlockState(blockId: string): Computable<BlockStateInternal> {\n return this.getBlockComputables(blockId).fullState;\n }\n\n /**\n * Returns a computable, that can be used to retrieve and watch path of the\n * folder containing frontend code.\n * */\n public getBlockFrontend(blockId: string): ComputableStableDefined<FrontendData> {\n const cached = this.blockFrontends.get(blockId);\n if (cached === undefined) {\n const fd = frontendData(\n this.projectTree.entry(),\n blockId,\n this.env,\n ).withPreCalculatedValueTree();\n this.blockFrontends.set(blockId, fd);\n return fd;\n }\n return cached;\n }\n\n /** Called by middle layer on close */\n public async destroy(): Promise<void> {\n // terminating the project service loop\n this.destroyed = true;\n this.abortController.abort();\n await this.refreshLoopResult;\n\n // terminating the synchronized project tree\n await this.projectTree.terminate();\n\n // the following will deregister all external resource holders, like\n // downloaded files, running uploads and alike\n this.overview.resetState();\n this.blockFrontends.forEach((c) => c.resetState());\n this.blockComputables.forEach((c) => {\n if (c !== null) c.fullState.resetState();\n });\n this.activeConfigs.resetState();\n }\n\n /** @deprecated */\n public async destroyAndAwaitTermination(): Promise<void> {\n await this.destroy();\n }\n\n public static async init(env: MiddleLayerEnvironment, rid: ResourceId): Promise<Project> {\n // Applying migrations to the project resource, if needed\n await applyProjectMigrations(env.pl, rid);\n\n // Doing a no-op mutation to apply all migration and schema fixes\n await withProject(env.projectHelper, env.pl, rid, (_) => {});\n\n // Loading project tree\n const projectTree = await SynchronizedTreeState.init(\n env.pl,\n rid,\n {\n ...env.ops.defaultTreeOptions,\n pruning: projectTreePruning,\n },\n env.logger,\n );\n\n if (env.ops.debugOps.dumpInitialTreeState) {\n const state = projectTree.dumpState();\n state.sort((a, b) => (b.data?.byteLength ?? 0) - (a.data?.byteLength ?? 0));\n const stats = treeDumpStats(state);\n await fs.writeFile(`${resourceIdToString(rid)}.json`, stringifyForDump(state));\n await fs.writeFile(`${resourceIdToString(rid)}.stats.json`, stringifyForDump(stats));\n }\n\n return new Project(env, rid, projectTree);\n }\n}\n\nfunction projectTreePruning(r: ExtendedResourceData): FieldData[] {\n // console.log(\n // JSON.stringify(\n // { ...r, kv: [], data: undefined } satisfies ExtendedResourceData,\n // (_, v) => {\n // if (typeof v === 'bigint') return v.toString();\n // return v;\n // }\n // )\n // );\n if (r.type.name.startsWith('StreamWorkdir/'))\n return [];\n switch (r.type.name) {\n case 'BlockPackCustom':\n return r.fields.filter((f) => f.name !== 'template');\n case 'UserProject':\n return r.fields.filter((f) => !f.name.startsWith('__serviceTemplate'));\n case 'Blob':\n return [];\n default:\n return r.fields;\n }\n}\n\n/** Returns true if sdk version of the block is old and we need to convert\n * ErrorLike errors to strings like it was.\n * We need it for keeping old blocks and new UI compatibility. */\nfunction shouldStillUseStringErrors(sdkVersion: string): boolean {\n return !isVersionGreater(sdkVersion, '1.26.0');\n}\n\n/** Checks if sdk version is greater that a target version. */\nfunction isVersionGreater(sdkVersion: string, targetVersion: string): boolean {\n const version = sdkVersion.split('.').map(Number);\n const target = targetVersion.split('.').map(Number);\n\n return (\n version[0] > target[0]\n || (version[0] === target[0] && version[1] > target[1])\n || (version[0] === target[0] && version[1] === target[1] && version[2] > target[2])\n );\n};\n\n/** Converts ErrorLike errors to strings in the outputs like it was in old ML versions. */\nfunction convertErrorsToStrings(\n outputs: Record<string, ComputableValueOrErrors<unknown>>,\n): Record<string, ComputableValueOrErrors<unknown>> {\n const result: Record<string, ComputableValueOrErrors<unknown>> = {};\n for (const [key, val] of Object.entries(outputs)) {\n if (val.ok) {\n result[key] = val;\n continue;\n }\n\n result[key] = {\n ok: false,\n errors: val.errors.map((e) => {\n if (typeof e === 'string') {\n return e;\n } else if (e.type == 'PlError' && e.fullMessage !== undefined) {\n return e.fullMessage;\n }\n return e.message;\n }),\n moreErrors: val.moreErrors,\n };\n }\n\n return result;\n}\n"],"names":["fs"],"mappings":";;;;;;;;;;;;;;;;;;;AAmDA,SAAS,gBAAgB,CAAC,MAAe,EAAA;IACvC,OAAO,IAAI,CAAC,SAAS,CAAC,MAAM,EAAE,CAAC,GAAG,EAAE,KAAK,KAAI;QAC3C,IAAI,OAAO,KAAK,KAAK,Q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E,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,KAAI;AAC3B,gBAAA,IAAI,OAAO,CAAC,KAAK,QAAQ,EAAE;AACzB,oBAAA,OAAO,CAAC;gBACV;AAAO,qBAAA,IAAI,CAAC,CAAC,IAAI,IAAI,SAAS,IAAI,CAAC,CAAC,WAAW,KAAK,SAAS,EAAE;oBAC7D,OAAO,CAAC,CAAC,WAAW;gBACtB;gBACA,OAAO,CAAC,CAAC,OAAO;AAClB,YAAA,CAAC,CAAC;YACF,UAAU,EAAE,GAAG,CAAC,UAAU;SAC3B;IACH;AAEA,IAAA,OAAO,MAAM;AACf;;;;"}
|
|
1
|
+
{"version":3,"file":"project.js","sources":["../../src/middle_layer/project.ts"],"sourcesContent":["import type { MiddleLayerEnvironment } from './middle_layer';\nimport type {\n FieldData,\n OptionalAnyResourceId,\n ResourceId,\n} from '@milaboratories/pl-client';\nimport {\n DefaultRetryOptions,\n ensureResourceIdNotNull,\n field,\n isNotFoundError,\n isTimeoutOrCancelError,\n Pl,\n resourceIdToString,\n} from '@milaboratories/pl-client';\nimport type { ComputableStableDefined, ComputableValueOrErrors } from '@milaboratories/computable';\nimport { Computable } from '@milaboratories/computable';\nimport { projectOverview } from './project_overview';\nimport type { BlockPackSpecAny } from '../model';\nimport { randomUUID } from 'node:crypto';\nimport { withProject, withProjectAuthored } from '../mutator/project';\nimport type { ExtendedResourceData } from '@milaboratories/pl-tree';\nimport { SynchronizedTreeState, treeDumpStats } from '@milaboratories/pl-tree';\nimport { setTimeout } from 'node:timers/promises';\nimport { frontendData } from './frontend_path';\nimport type { NavigationState } from '@milaboratories/pl-model-common';\nimport { blockArgsAndUiState, blockOutputs } from './block';\nimport type { FrontendData } from '../model/frontend';\nimport type { ProjectStructure } from '../model/project_model';\nimport { projectFieldName } from '../model/project_model';\nimport { cachedDeserialize, notEmpty } from '@milaboratories/ts-helpers';\nimport type { BlockPackInfo } from '../model/block_pack';\nimport type {\n ProjectOverview,\n AuthorMarker,\n BlockStateInternal,\n BlockSettings,\n} from '@milaboratories/pl-model-middle-layer';\nimport { activeConfigs } from './active_cfg';\nimport { NavigationStates } from './navigation_states';\nimport { extractConfig } from '@platforma-sdk/model';\nimport fs from 'node:fs/promises';\nimport canonicalize from 'canonicalize';\nimport type { ProjectOverviewLight } from './project_overview_light';\nimport { projectOverviewLight } from './project_overview_light';\nimport { applyProjectMigrations } from '../mutator/migration';\n\ntype BlockStateComputables = {\n readonly fullState: Computable<BlockStateInternal>;\n};\n\nfunction stringifyForDump(object: unknown): string {\n return JSON.stringify(object, (key, value) => {\n if (typeof value === 'bigint')\n return resourceIdToString(value as OptionalAnyResourceId);\n else if (\n ArrayBuffer.isView(value)\n || value instanceof Int8Array\n || value instanceof Uint8Array\n || value instanceof Uint8ClampedArray\n || value instanceof Int16Array\n || value instanceof Uint16Array\n || value instanceof Int32Array\n || value instanceof Uint32Array\n || value instanceof Float32Array\n || value instanceof Float64Array\n || value instanceof BigInt64Array\n || value instanceof BigUint64Array\n )\n return Buffer.from(value.buffer, value.byteOffset, value.byteLength).toString('base64');\n else if (Buffer.isBuffer(value))\n return value.toString('base64');\n\n return value;\n });\n}\n\n/** Data access object, to manipulate and read single opened (!) project data. */\nexport class Project {\n /** Underlying pl resource id */\n public readonly rid: ResourceId;\n\n /** Data for the left panel, contain basic information about block status. */\n public readonly overview: ComputableStableDefined<ProjectOverview>;\n private readonly overviewLight: Computable<ProjectOverviewLight>;\n\n private readonly navigationStates = new NavigationStates();\n // null is set for deleted blocks\n private readonly blockComputables = new Map<string, BlockStateComputables | null>();\n\n private readonly blockFrontends = new Map<string, ComputableStableDefined<FrontendData>>();\n private readonly activeConfigs: Computable<unknown[]>;\n private readonly refreshLoopResult: Promise<void>;\n\n private readonly abortController = new AbortController();\n private destroyed = false;\n\n constructor(\n private readonly env: MiddleLayerEnvironment,\n rid: ResourceId,\n private readonly projectTree: SynchronizedTreeState,\n ) {\n this.overview = projectOverview(\n projectTree.entry(),\n this.navigationStates,\n env,\n ).withPreCalculatedValueTree();\n this.overviewLight = projectOverviewLight(projectTree.entry())\n .withPreCalculatedValueTree();\n this.rid = rid;\n this.refreshLoopResult = this.refreshLoop();\n this.activeConfigs = activeConfigs(projectTree.entry(), env);\n }\n\n get projectLockId(): string {\n return 'project:' + this.rid.toString();\n }\n\n private async refreshLoop(): Promise<void> {\n while (!this.destroyed) {\n try {\n await withProject(this.env.projectHelper, this.env.pl, this.rid, (prj) => {\n prj.doRefresh(this.env.ops.stagingRenderingRate);\n }, { name: 'doRefresh', lockId: this.projectLockId });\n await this.activeConfigs.getValue();\n await setTimeout(this.env.ops.projectRefreshInterval, this.abortController.signal);\n\n // Block computables houskeeping\n const overviewLight = await this.overviewLight.getValue();\n const existingBlocks = new Set(overviewLight.listOfBlocks);\n // Doing cleanup for deleted blocks\n for (const blockId of this.blockComputables.keys()) {\n if (!existingBlocks.has(blockId)) {\n const computable = this.blockComputables.get(blockId);\n if (computable !== undefined && computable !== null) computable.fullState.resetState();\n this.blockComputables.set(blockId, null);\n }\n }\n } catch (e: unknown) {\n if (isNotFoundError(e)) {\n console.warn(\n 'project refresh routine terminated, because project was externally deleted',\n );\n break;\n } else if (!isTimeoutOrCancelError(e))\n throw new Error('Unexpected exception', { cause: e });\n }\n }\n }\n\n /**\n * Adds new block to the project.\n *\n * @param blockLabel block label / title visible to the user\n * @param blockPackSpec object describing the \"block type\", read more in the type docs\n * @param before id of the block to insert new block before\n * @param blockId internal id to be assigned for the block, this arg can be omitted\n * then, randomly generated UUID will be assigned automatically\n *\n * @return returns newly created block id\n * */\n public async addBlock(\n blockLabel: string,\n blockPackSpec: BlockPackSpecAny,\n before?: string,\n author: AuthorMarker | undefined = undefined,\n blockId: string = randomUUID(),\n ): Promise<string> {\n const preparedBp = await this.env.bpPreparer.prepare(blockPackSpec);\n const blockCfgContainer = await this.env.bpPreparer.getBlockConfigContainer(blockPackSpec);\n const blockCfg = extractConfig(blockCfgContainer); // full content of this var should never be persisted\n await withProjectAuthored(this.env.projectHelper, this.env.pl, this.rid, author, (mut) => {\n return mut.addBlock(\n {\n id: blockId,\n label: blockLabel,\n renderingMode: blockCfg.renderingMode,\n },\n {\n args: canonicalize(blockCfg.initialArgs)!,\n uiState: canonicalize(blockCfg.initialUiState)!,\n blockPack: preparedBp,\n },\n before,\n );\n },\n {\n retryOptions: {\n ...DefaultRetryOptions,\n backoffMultiplier: DefaultRetryOptions.backoffMultiplier * 1.1,\n },\n name: 'addBlock',\n lockId: this.projectLockId,\n });\n\n await this.projectTree.refreshState();\n\n return blockId;\n }\n\n /**\n * Duplicates an existing block by copying all its fields and state.\n * This method works at the mutator level for efficient block copying.\n *\n * @param originalBlockId id of the block to duplicate\n * @param before id of the block to insert new block before\n * @param author author marker for the duplication operation\n * @param newBlockId internal id to be assigned for the duplicated block,\n * if omitted, a randomly generated UUID will be assigned\n *\n * @return returns newly created block id\n * */\n public async duplicateBlock(\n originalBlockId: string,\n before?: string,\n author: AuthorMarker | undefined = undefined,\n newBlockId: string = randomUUID(),\n ): Promise<string> {\n await withProjectAuthored(this.env.projectHelper, this.env.pl, this.rid, author, (mut) =>\n mut.duplicateBlock(originalBlockId, newBlockId, before),\n { name: 'duplicateBlock', lockId: this.projectLockId },\n );\n await this.projectTree.refreshState();\n\n return newBlockId;\n }\n\n /**\n * Update block to new block pack, optionally resetting args and ui state to\n * initial values\n * */\n public async updateBlockPack(\n blockId: string,\n blockPackSpec: BlockPackSpecAny,\n resetArgs: boolean = false,\n author?: AuthorMarker,\n ): Promise<void> {\n const preparedBp = await this.env.bpPreparer.prepare(blockPackSpec);\n const blockCfg = extractConfig(await this.env.bpPreparer.getBlockConfigContainer(blockPackSpec));\n await withProjectAuthored(this.env.projectHelper, this.env.pl, this.rid, author, (mut) =>\n mut.migrateBlockPack(\n blockId,\n preparedBp,\n resetArgs ? { args: blockCfg.initialArgs, uiState: blockCfg.initialUiState } : undefined,\n ),\n { name: 'updateBlockPack', lockId: this.projectLockId },\n );\n await this.projectTree.refreshState();\n }\n\n /** Deletes a block with all associated data. */\n public async deleteBlock(blockId: string, author?: AuthorMarker): Promise<void> {\n await withProjectAuthored(this.env.projectHelper, this.env.pl, this.rid, author, (mut) => mut.deleteBlock(blockId), { name: 'deleteBlock', lockId: this.projectLockId });\n this.navigationStates.deleteBlock(blockId);\n await this.projectTree.refreshState();\n }\n\n /**\n * Updates block order according to the given array of block ids.\n *\n * Provided array must contain exactly the same set of ids current project cosists of,\n * an error will be thrown instead.\n */\n public async reorderBlocks(blocks: string[], author?: AuthorMarker): Promise<void> {\n await withProjectAuthored(this.env.projectHelper, this.env.pl, this.rid, author, (mut) => {\n const currentStructure = mut.structure;\n if (currentStructure.groups.length !== 1)\n throw new Error('Unexpected project structure, non-singular block group');\n const currentGroup = currentStructure.groups[0];\n if (currentGroup.blocks.length !== blocks.length)\n throw new Error(`Length mismatch: ${currentGroup.blocks.length} !== ${blocks.length}`);\n if (new Set<string>(blocks).size !== blocks.length) throw new Error(`Repeated block ids`);\n const newStructure: ProjectStructure = {\n groups: [\n {\n id: currentGroup.id,\n label: currentGroup.label,\n blocks: blocks.map((blockId) => {\n const block = currentGroup.blocks.find((b) => b.id === blockId);\n if (block === undefined) throw new Error(`Can't find block: ${blockId}`);\n return block;\n }),\n },\n ],\n };\n mut.updateStructure(newStructure);\n }, { name: 'reorderBlocks', lockId: this.projectLockId });\n await this.projectTree.refreshState();\n }\n\n /**\n * Renders production part of the block starting all connected heavy computations.\n * Upstream blocks of the specified block will be started automatically if in\n * stale state.\n * */\n public async runBlock(blockId: string): Promise<void> {\n await withProject(this.env.projectHelper, this.env.pl, this.rid, (mut) => mut.renderProduction([blockId], true), { name: 'runBlock', lockId: this.projectLockId });\n await this.projectTree.refreshState();\n }\n\n /**\n * Stops the block if it is running by destroying its production state. All\n * its downstreams will also be destroyed or moved to limbo if already\n * calculated.\n * */\n public async stopBlock(blockId: string): Promise<void> {\n await withProject(this.env.projectHelper, this.env.pl, this.rid, (mut) => mut.stopProduction(blockId), { name: 'stopBlock', lockId: this.projectLockId });\n await this.projectTree.refreshState();\n }\n\n // /** Update block label. */\n // public async setBlockLabel(blockId: string, label: string, author?: AuthorMarker) {\n // await withProjectAuthored(this.env.pl, this.rid, author, (mut) => {\n // mut.setBlockLabel(blockId, label);\n // });\n // await this.projectTree.refreshState();\n // }\n\n /**\n * Sets block args, and changes whole project state accordingly.\n * Along with setting arguments one can specify author marker, that will be\n * transactionally associated with the block, to facilitate conflict resolution\n * in collaborative editing scenario.\n * */\n public async setBlockArgs(blockId: string, args: unknown, author?: AuthorMarker) {\n await withProjectAuthored(this.env.projectHelper, this.env.pl, this.rid, author, (mut) =>\n mut.setStates([{ blockId, args }]),\n { name: 'setBlockArgs', lockId: this.projectLockId });\n await this.projectTree.refreshState();\n }\n\n /**\n * Sets ui block state associated with the block.\n * Along with setting arguments one can specify author marker, that will be\n * transactionally associated with the block, to facilitate conflict resolution\n * in collaborative editing scenario.\n * */\n public async setUiState(blockId: string, uiState: unknown, author?: AuthorMarker) {\n await withProjectAuthored(this.env.projectHelper, this.env.pl, this.rid, author, (mut) =>\n mut.setStates([{ blockId, uiState }]),\n { name: 'setUiState', lockId: this.projectLockId });\n await this.projectTree.refreshState();\n }\n\n /**\n * Sets navigation state.\n * */\n // eslint-disable-next-line @typescript-eslint/require-await\n public async setNavigationState(blockId: string, state: NavigationState): Promise<void> {\n this.navigationStates.setState(blockId, state);\n }\n\n /**\n * Sets block args and ui state, and changes the whole project state accordingly.\n * Along with setting arguments one can specify author marker, that will be\n * transactionally associated with the block, to facilitate conflict resolution\n * in collaborative editing scenario.\n * */\n public async setBlockArgsAndUiState(\n blockId: string,\n args: unknown,\n uiState: unknown,\n author?: AuthorMarker,\n ) {\n await withProjectAuthored(this.env.projectHelper, this.env.pl, this.rid, author, (mut) => {\n mut.setStates([{ blockId, args, uiState }]);\n }, { name: 'setBlockArgsAndUiState', lockId: this.projectLockId });\n await this.projectTree.refreshState();\n }\n\n /** Update block settings */\n public async setBlockSettings(blockId: string, newValue: BlockSettings) {\n await withProjectAuthored(this.env.projectHelper, this.env.pl, this.rid, undefined, (mut) => {\n mut.setBlockSettings(blockId, newValue);\n }, { name: 'setBlockSettings' });\n await this.projectTree.refreshState();\n }\n\n /** Resets arguments and ui state of the block to initial state */\n public async resetBlockArgsAndUiState(blockId: string, author?: AuthorMarker): Promise<void> {\n await this.env.pl.withWriteTx('BlockInputsReset', async (tx) => {\n // reading default arg values from block pack\n const bpHolderRid = ensureResourceIdNotNull(\n (await tx.getField(field(this.rid, projectFieldName(blockId, 'blockPack')))).value,\n );\n const bpRid = ensureResourceIdNotNull(\n (await tx.getField(field(bpHolderRid, Pl.HolderRefField))).value,\n );\n const bpData = await tx.getResourceData(bpRid, false);\n const config = extractConfig(cachedDeserialize<BlockPackInfo>(notEmpty(bpData.data)).config);\n await withProjectAuthored(this.env.projectHelper, tx, this.rid, author, (prj) => {\n prj.setStates([{ blockId, args: config.initialArgs, uiState: config.initialUiState }]);\n }, { name: 'resetBlockArgsAndUiState', lockId: this.projectLockId });\n await tx.commit();\n });\n await this.projectTree.refreshState();\n }\n\n private getBlockComputables(blockId: string): BlockStateComputables {\n const cached = this.blockComputables.get(blockId);\n if (cached === null) throw new Error(`Block ${blockId} is deleted`);\n if (cached === undefined) {\n // state consists of inputs (args + ui state) and outputs\n const outputs = blockOutputs(this.projectTree.entry(), blockId, this.env);\n const fullState = Computable.make(\n (ctx) => {\n return {\n argsAndUiState: blockArgsAndUiState(this.projectTree.entry(), blockId, ctx),\n outputs,\n navigationState: this.navigationStates.getState(blockId),\n overview: this.overview,\n };\n },\n {\n postprocessValue: (v) => {\n const sdkVersion = v.overview?.blocks?.find((b) => b.id == blockId)?.sdkVersion;\n const toString = sdkVersion && shouldStillUseStringErrors(sdkVersion);\n const newOutputs = toString && v.outputs !== undefined\n ? convertErrorsToStrings(v.outputs)\n : v.outputs;\n\n return {\n ...v.argsAndUiState,\n outputs: newOutputs,\n navigationState: v.navigationState,\n } as BlockStateInternal;\n },\n },\n );\n\n const computables: BlockStateComputables = {\n fullState: fullState.withPreCalculatedValueTree(),\n };\n\n this.blockComputables.set(blockId, computables);\n\n return computables;\n }\n return cached;\n }\n\n /**\n * Returns a computable, that can be used to retrieve and watch full block state,\n * including outputs, arguments, ui state.\n * */\n public getBlockState(blockId: string): Computable<BlockStateInternal> {\n return this.getBlockComputables(blockId).fullState;\n }\n\n /**\n * Returns a computable, that can be used to retrieve and watch path of the\n * folder containing frontend code.\n * */\n public getBlockFrontend(blockId: string): ComputableStableDefined<FrontendData> {\n const cached = this.blockFrontends.get(blockId);\n if (cached === undefined) {\n const fd = frontendData(\n this.projectTree.entry(),\n blockId,\n this.env,\n ).withPreCalculatedValueTree();\n this.blockFrontends.set(blockId, fd);\n return fd;\n }\n return cached;\n }\n\n /** Called by middle layer on close */\n public async destroy(): Promise<void> {\n // terminating the project service loop\n this.destroyed = true;\n this.abortController.abort();\n await this.refreshLoopResult;\n\n // terminating the synchronized project tree\n await this.projectTree.terminate();\n\n // the following will deregister all external resource holders, like\n // downloaded files, running uploads and alike\n this.overview.resetState();\n this.blockFrontends.forEach((c) => c.resetState());\n this.blockComputables.forEach((c) => {\n if (c !== null) c.fullState.resetState();\n });\n this.activeConfigs.resetState();\n }\n\n /** @deprecated */\n public async destroyAndAwaitTermination(): Promise<void> {\n await this.destroy();\n }\n\n public static async init(env: MiddleLayerEnvironment, rid: ResourceId): Promise<Project> {\n // Applying migrations to the project resource, if needed\n await applyProjectMigrations(env.pl, rid);\n\n // Doing a no-op mutation to apply all migration and schema fixes\n await withProject(env.projectHelper, env.pl, rid, (_) => {}, { name: 'init' });\n\n // Loading project tree\n const projectTree = await SynchronizedTreeState.init(\n env.pl,\n rid,\n {\n ...env.ops.defaultTreeOptions,\n pruning: projectTreePruning,\n },\n env.logger,\n );\n\n if (env.ops.debugOps.dumpInitialTreeState) {\n const state = projectTree.dumpState();\n state.sort((a, b) => (b.data?.byteLength ?? 0) - (a.data?.byteLength ?? 0));\n const stats = treeDumpStats(state);\n await fs.writeFile(`${resourceIdToString(rid)}.json`, stringifyForDump(state));\n await fs.writeFile(`${resourceIdToString(rid)}.stats.json`, stringifyForDump(stats));\n }\n\n return new Project(env, rid, projectTree);\n }\n}\n\nfunction projectTreePruning(r: ExtendedResourceData): FieldData[] {\n // console.log(\n // JSON.stringify(\n // { ...r, kv: [], data: undefined } satisfies ExtendedResourceData,\n // (_, v) => {\n // if (typeof v === 'bigint') return v.toString();\n // return v;\n // }\n // )\n // );\n if (r.type.name.startsWith('StreamWorkdir/'))\n return [];\n switch (r.type.name) {\n case 'BlockPackCustom':\n return r.fields.filter((f) => f.name !== 'template');\n case 'UserProject':\n return r.fields.filter((f) => !f.name.startsWith('__serviceTemplate'));\n case 'Blob':\n return [];\n default:\n return r.fields;\n }\n}\n\n/** Returns true if sdk version of the block is old and we need to convert\n * ErrorLike errors to strings like it was.\n * We need it for keeping old blocks and new UI compatibility. */\nfunction shouldStillUseStringErrors(sdkVersion: string): boolean {\n return !isVersionGreater(sdkVersion, '1.26.0');\n}\n\n/** Checks if sdk version is greater that a target version. */\nfunction isVersionGreater(sdkVersion: string, targetVersion: string): boolean {\n const version = sdkVersion.split('.').map(Number);\n const target = targetVersion.split('.').map(Number);\n\n return (\n version[0] > target[0]\n || (version[0] === target[0] && version[1] > target[1])\n || (version[0] === target[0] && version[1] === target[1] && version[2] > target[2])\n );\n};\n\n/** Converts ErrorLike errors to strings in the outputs like it was in old ML versions. */\nfunction convertErrorsToStrings(\n outputs: Record<string, ComputableValueOrErrors<unknown>>,\n): Record<string, ComputableValueOrErrors<unknown>> {\n const result: Record<string, ComputableValueOrErrors<unknown>> = {};\n for (const [key, val] of Object.entries(outputs)) {\n if (val.ok) {\n result[key] = val;\n continue;\n }\n\n result[key] = {\n ok: false,\n errors: val.errors.map((e) => {\n if (typeof e === 'string') {\n return e;\n } else if (e.type == 'PlError' && e.fullMessage !== undefined) {\n return e.fullMessage;\n }\n return e.message;\n }),\n moreErrors: val.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AG;AACZ,YAAA,EAAE,EAAE,KAAK;YACT,MAAM,EAAE,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,KAAI;AAC3B,gBAAA,IAAI,OAAO,CAAC,KAAK,QAAQ,EAAE;AACzB,oBAAA,OAAO,CAAC;gBACV;AAAO,qBAAA,IAAI,CAAC,CAAC,IAAI,IAAI,SAAS,IAAI,CAAC,CAAC,WAAW,KAAK,SAAS,EAAE;oBAC7D,OAAO,CAAC,CAAC,WAAW;gBACtB;gBACA,OAAO,CAAC,CAAC,OAAO;AAClB,YAAA,CAAC,CAAC;YACF,UAAU,EAAE,GAAG,CAAC,UAAU;SAC3B;IACH;AAEA,IAAA,OAAO,MAAM;AACf;;;;"}
|
package/dist/mutator/project.cjs
CHANGED
|
@@ -964,12 +964,12 @@ async function createProject(tx, meta = project_model.InitialBlockMeta) {
|
|
|
964
964
|
tx.createField(plClient.field(prj, project_model.getServiceTemplateField(ctxExportTplEnvelope.hash)), 'Dynamic', plClient.Pl.wrapInHolder(tx, template_loading.loadTemplate(tx, ctxExportTplEnvelope.spec)));
|
|
965
965
|
return prj;
|
|
966
966
|
}
|
|
967
|
-
async function withProject(projectHelper, txOrPl, rid, cb) {
|
|
968
|
-
return withProjectAuthored(projectHelper, txOrPl, rid, undefined, cb);
|
|
967
|
+
async function withProject(projectHelper, txOrPl, rid, cb, ops) {
|
|
968
|
+
return withProjectAuthored(projectHelper, txOrPl, rid, undefined, cb, ops);
|
|
969
969
|
}
|
|
970
970
|
async function withProjectAuthored(projectHelper, txOrPl, rid, author, cb, ops = {}) {
|
|
971
971
|
if (txOrPl instanceof plClient.PlClient) {
|
|
972
|
-
return await txOrPl.withWriteTx('ProjectAction', async (tx) => {
|
|
972
|
+
return await txOrPl.withWriteTx('ProjectAction' + (ops.name ? `: ${ops.name}` : ''), async (tx) => {
|
|
973
973
|
const mut = await ProjectMutator.load(projectHelper, tx, rid, author);
|
|
974
974
|
const result = await cb(mut);
|
|
975
975
|
if (!mut.wasModified)
|