@milaboratories/pl-middle-layer 1.46.27 → 1.46.29

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.
@@ -111,6 +111,12 @@ async function migrateV2ToV3(tx, rid) {
111
111
  const stateR = tx.createJsonGzValue(unifiedState);
112
112
  const stateF = plClient.field(rid, blockStorageFieldName);
113
113
  tx.createField(stateF, "Dynamic", stateR);
114
+ // Initialize currentPrerunArgs from currentArgs (for legacy blocks, prerunArgs = args)
115
+ if (currentArgsRid) {
116
+ const prerunArgsR = tx.createJsonGzValue(args);
117
+ const prerunArgsF = plClient.field(rid, project_model.projectFieldName(block.id, "currentPrerunArgs"));
118
+ tx.createField(prerunArgsF, "Dynamic", prerunArgsR);
119
+ }
114
120
  }
115
121
  }
116
122
 
@@ -1 +1 @@
1
- {"version":3,"file":"migration.cjs","sources":["../../src/mutator/migration.ts"],"sourcesContent":["import type { PlClient, PlTransaction, ResourceId } from \"@milaboratories/pl-client\";\nimport type { ProjectField, ProjectStructure } from \"../model/project_model\";\nimport {\n projectFieldName,\n ProjectStructureKey,\n SchemaVersionCurrent,\n SchemaVersionKey,\n SchemaVersionV2,\n} from \"../model/project_model\";\nimport { BlockFrontendStateKeyPrefixV1, SchemaVersionV1 } from \"../model/project_model_v1\";\nimport { field, isNullResourceId } from \"@milaboratories/pl-client\";\nimport { cachedDeserialize } from \"@milaboratories/ts-helpers\";\nimport { allBlocks } from \"../model/project_model_util\";\n\n/**\n * Migrates the project to the latest schema version.\n *\n * @param pl - The client to use.\n * @param rid - The resource id of the project.\n */\nexport async function applyProjectMigrations(pl: PlClient, rid: ResourceId) {\n await pl.withWriteTx(\"ProjectMigration\", async (tx) => {\n let schemaVersion = await tx.getKValueJson<string>(rid, SchemaVersionKey);\n if (schemaVersion === SchemaVersionCurrent) return;\n\n // Apply migrations in sequence\n if (schemaVersion === SchemaVersionV1) {\n await migrateV1ToV2(tx, rid);\n schemaVersion = SchemaVersionV2;\n }\n\n if (schemaVersion === SchemaVersionV2) {\n await migrateV2ToV3(tx, rid);\n } else if (schemaVersion !== SchemaVersionV1) {\n // If we got here and it's not v1 (which was handled above), it's unknown\n throw new Error(`Unknown project schema version: ${schemaVersion}`);\n }\n\n tx.setKValue(rid, SchemaVersionKey, JSON.stringify(SchemaVersionCurrent));\n await tx.commit();\n });\n}\n\n/**\n * Migrates the project from schema version 1 to 2.\n *\n * Summary of changes:\n * - uiState is now stored in a field instead of a KV\n *\n * @param tx - The transaction to use.\n * @param rid - The resource id of the project.\n */\nasync function migrateV1ToV2(tx: PlTransaction, rid: ResourceId) {\n const [structure, allKV] = await Promise.all([\n tx.getKValueJson<ProjectStructure>(rid, ProjectStructureKey),\n tx.listKeyValues(rid),\n ]);\n const kvMap = new Map<string, Uint8Array>(allKV.map((kv) => [kv.key, kv.value]));\n for (const block of allBlocks(structure)) {\n const kvKey = BlockFrontendStateKeyPrefixV1 + block.id;\n const uiState = kvMap.get(kvKey);\n const valueJson = uiState ? cachedDeserialize(uiState) : {};\n const uiStateR = tx.createJsonGzValue(valueJson);\n const uiStateF = field(rid, projectFieldName(block.id, \"blockStorage\"));\n tx.createField(uiStateF, \"Dynamic\", uiStateR);\n tx.deleteKValue(rid, kvKey);\n }\n}\n\n/**\n * Migrates the project from schema version 2 to 3.\n *\n * Summary of changes:\n * - Introduces unified 'blockStorage' field containing { args, uiState }\n * - Adds 'currentPrerunArgs' field for staging/prerun rendering\n * - For each block:\n * 1. Read existing 'blockStorage' field (contains uiState in v2)\n * 2. Read existing 'currentArgs' field (contains args)\n * 3. Create unified state = { args: currentArgs, uiState: oldState }\n * 4. Write to new {blockId}-blockStorage field (overwrites)\n * 5. Initialize {blockId}-currentPrerunArgs (same as prodArgs for v1/v2 blocks)\n * - Note: currentArgs and prodArgs fields remain for compatibility layer\n *\n * @param tx - The transaction to use.\n * @param rid - The resource id of the project.\n */\nasync function migrateV2ToV3(tx: PlTransaction, rid: ResourceId) {\n const [structure, fullResourceState] = await Promise.all([\n tx.getKValueJson<ProjectStructure>(rid, ProjectStructureKey),\n tx.getResourceData(rid, true),\n ]);\n\n // Build a map of field name -> resource id for quick lookup\n const fieldMap = new Map<string, ResourceId>();\n for (const f of fullResourceState.fields) {\n if (!isNullResourceId(f.value)) {\n fieldMap.set(f.name, f.value);\n }\n }\n\n for (const block of allBlocks(structure)) {\n // Read existing field values\n const uiStateFieldName = projectFieldName(block.id, \"uiState\" as ProjectField[\"fieldName\"]);\n const currentArgsFieldName = projectFieldName(block.id, \"currentArgs\");\n\n const uiStateRid = fieldMap.get(uiStateFieldName);\n const currentArgsRid = fieldMap.get(currentArgsFieldName);\n\n // Read field data in parallel where available\n const [uiStateData, currentArgsData] = await Promise.all([\n uiStateRid ? tx.getResourceData(uiStateRid, false) : Promise.resolve(undefined),\n currentArgsRid ? tx.getResourceData(currentArgsRid, false) : Promise.resolve(undefined),\n ]);\n\n // Extract values - in v2, 'blockStorage' contains raw uiState, not wrapped\n const uiState = uiStateData?.data ? cachedDeserialize(uiStateData.data) : {};\n const args = currentArgsData?.data ? cachedDeserialize(currentArgsData.data) : {};\n\n // Create unified state: { args, uiState }\n const unifiedState = {\n args,\n uiState,\n };\n\n const blockStorageFieldName = projectFieldName(block.id, \"blockStorage\");\n\n // Write new unified blockStorage field (overwrite existing)\n const stateR = tx.createJsonGzValue(unifiedState);\n const stateF = field(rid, blockStorageFieldName);\n tx.createField(stateF, \"Dynamic\", stateR);\n }\n}\n"],"names":["SchemaVersionKey","SchemaVersionCurrent","SchemaVersionV1","SchemaVersionV2","ProjectStructureKey","allBlocks","BlockFrontendStateKeyPrefixV1","cachedDeserialize","field","projectFieldName","isNullResourceId"],"mappings":";;;;;;;;AAcA;;;;;AAKG;AACI,eAAe,sBAAsB,CAAC,EAAY,EAAE,GAAe,EAAA;IACxE,MAAM,EAAE,CAAC,WAAW,CAAC,kBAAkB,EAAE,OAAO,EAAE,KAAI;QACpD,IAAI,aAAa,GAAG,MAAM,EAAE,CAAC,aAA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,QAAQ,CAAC,GAAG,CAAC,gBAAgB,CAAC;QACjD,MAAM,cAAc,GAAG,QAAQ,CAAC,GAAG,CAAC,oBAAoB,CAAC;;QAGzD,MAAM,CAAC,WAAW,EAAE,eAAe,CAAC,GAAG,MAAM,OAAO,CAAC,GAAG,CAAC;AACvD,YAAA,UAAU,GAAG,EAAE,CAAC,eAAe,CAAC,UAAU,EAAE,KAAK,CAAC,GAAG,OAAO,CAAC,OAAO,CAAC,SAAS,CAAC;AAC/E,YAAA,cAAc,GAAG,EAAE,CAAC,eAAe,CAAC,cAAc,EAAE,KAAK,CAAC,GAAG,OAAO,CAAC,OAAO,CAAC,SAAS,CAAC;AACxF,SAAA,CAAC;;AAGF,QAAA,MAAM,OAAO,GAAG,WAAW,EAAE,IAAI,GAAGF,2BAAiB,CAAC,WAAW,CAAC,IAAI,CAAC,GAAG,EAAE;AAC5E,QAAA,MAAM,IAAI,GAAG,eAAe,EAAE,IAAI,GAAGA,2BAAiB,CAAC,eAAe,CAAC,IAAI,CAAC,GAAG,EAAE;;AAGjF,QAAA,MAAM,YAAY,GAAG;YACnB,IAAI;YACJ,OAAO;SACR;QAED,MAAM,qBAAqB,GAAGE,8BAAgB,CAAC,KAAK,CAAC,EAAE,EAAE,cAAc,CAAC;;QAGxE,MAAM,MAAM,GAAG,EAAE,CAAC,iBAAiB,CAAC,YAAY,CAAC;QACjD,MAAM,MAAM,GAAGD,cAAK,CAAC,GAAG,EAAE,qBAAqB,CAAC;QAChD,EAAE,CAAC,WAAW,CAAC,MAAM,EAAE,SAAS,EAAE,MAAM,CAAC;IAC3C;AACF;;;;"}
1
+ {"version":3,"file":"migration.cjs","sources":["../../src/mutator/migration.ts"],"sourcesContent":["import type { PlClient, PlTransaction, ResourceId } from \"@milaboratories/pl-client\";\nimport type { ProjectField, ProjectStructure } from \"../model/project_model\";\nimport {\n projectFieldName,\n ProjectStructureKey,\n SchemaVersionCurrent,\n SchemaVersionKey,\n SchemaVersionV2,\n} from \"../model/project_model\";\nimport { BlockFrontendStateKeyPrefixV1, SchemaVersionV1 } from \"../model/project_model_v1\";\nimport { field, isNullResourceId } from \"@milaboratories/pl-client\";\nimport { cachedDeserialize } from \"@milaboratories/ts-helpers\";\nimport { allBlocks } from \"../model/project_model_util\";\n\n/**\n * Migrates the project to the latest schema version.\n *\n * @param pl - The client to use.\n * @param rid - The resource id of the project.\n */\nexport async function applyProjectMigrations(pl: PlClient, rid: ResourceId) {\n await pl.withWriteTx(\"ProjectMigration\", async (tx) => {\n let schemaVersion = await tx.getKValueJson<string>(rid, SchemaVersionKey);\n if (schemaVersion === SchemaVersionCurrent) return;\n\n // Apply migrations in sequence\n if (schemaVersion === SchemaVersionV1) {\n await migrateV1ToV2(tx, rid);\n schemaVersion = SchemaVersionV2;\n }\n\n if (schemaVersion === SchemaVersionV2) {\n await migrateV2ToV3(tx, rid);\n } else if (schemaVersion !== SchemaVersionV1) {\n // If we got here and it's not v1 (which was handled above), it's unknown\n throw new Error(`Unknown project schema version: ${schemaVersion}`);\n }\n\n tx.setKValue(rid, SchemaVersionKey, JSON.stringify(SchemaVersionCurrent));\n await tx.commit();\n });\n}\n\n/**\n * Migrates the project from schema version 1 to 2.\n *\n * Summary of changes:\n * - uiState is now stored in a field instead of a KV\n *\n * @param tx - The transaction to use.\n * @param rid - The resource id of the project.\n */\nasync function migrateV1ToV2(tx: PlTransaction, rid: ResourceId) {\n const [structure, allKV] = await Promise.all([\n tx.getKValueJson<ProjectStructure>(rid, ProjectStructureKey),\n tx.listKeyValues(rid),\n ]);\n const kvMap = new Map<string, Uint8Array>(allKV.map((kv) => [kv.key, kv.value]));\n for (const block of allBlocks(structure)) {\n const kvKey = BlockFrontendStateKeyPrefixV1 + block.id;\n const uiState = kvMap.get(kvKey);\n const valueJson = uiState ? cachedDeserialize(uiState) : {};\n const uiStateR = tx.createJsonGzValue(valueJson);\n const uiStateF = field(rid, projectFieldName(block.id, \"blockStorage\"));\n tx.createField(uiStateF, \"Dynamic\", uiStateR);\n tx.deleteKValue(rid, kvKey);\n }\n}\n\n/**\n * Migrates the project from schema version 2 to 3.\n *\n * Summary of changes:\n * - Introduces unified 'blockStorage' field containing { args, uiState }\n * - Adds 'currentPrerunArgs' field for staging/prerun rendering\n * - For each block:\n * 1. Read existing 'blockStorage' field (contains uiState in v2)\n * 2. Read existing 'currentArgs' field (contains args)\n * 3. Create unified state = { args: currentArgs, uiState: oldState }\n * 4. Write to new {blockId}-blockStorage field (overwrites)\n * 5. Initialize {blockId}-currentPrerunArgs (same as prodArgs for v1/v2 blocks)\n * - Note: currentArgs and prodArgs fields remain for compatibility layer\n *\n * @param tx - The transaction to use.\n * @param rid - The resource id of the project.\n */\nasync function migrateV2ToV3(tx: PlTransaction, rid: ResourceId) {\n const [structure, fullResourceState] = await Promise.all([\n tx.getKValueJson<ProjectStructure>(rid, ProjectStructureKey),\n tx.getResourceData(rid, true),\n ]);\n\n // Build a map of field name -> resource id for quick lookup\n const fieldMap = new Map<string, ResourceId>();\n for (const f of fullResourceState.fields) {\n if (!isNullResourceId(f.value)) {\n fieldMap.set(f.name, f.value);\n }\n }\n\n for (const block of allBlocks(structure)) {\n // Read existing field values\n const uiStateFieldName = projectFieldName(block.id, \"uiState\" as ProjectField[\"fieldName\"]);\n const currentArgsFieldName = projectFieldName(block.id, \"currentArgs\");\n\n const uiStateRid = fieldMap.get(uiStateFieldName);\n const currentArgsRid = fieldMap.get(currentArgsFieldName);\n\n // Read field data in parallel where available\n const [uiStateData, currentArgsData] = await Promise.all([\n uiStateRid ? tx.getResourceData(uiStateRid, false) : Promise.resolve(undefined),\n currentArgsRid ? tx.getResourceData(currentArgsRid, false) : Promise.resolve(undefined),\n ]);\n\n // Extract values - in v2, 'blockStorage' contains raw uiState, not wrapped\n const uiState = uiStateData?.data ? cachedDeserialize(uiStateData.data) : {};\n const args = currentArgsData?.data ? cachedDeserialize(currentArgsData.data) : {};\n\n // Create unified state: { args, uiState }\n const unifiedState = {\n args,\n uiState,\n };\n\n const blockStorageFieldName = projectFieldName(block.id, \"blockStorage\");\n\n // Write new unified blockStorage field (overwrite existing)\n const stateR = tx.createJsonGzValue(unifiedState);\n const stateF = field(rid, blockStorageFieldName);\n tx.createField(stateF, \"Dynamic\", stateR);\n\n // Initialize currentPrerunArgs from currentArgs (for legacy blocks, prerunArgs = args)\n if (currentArgsRid) {\n const prerunArgsR = tx.createJsonGzValue(args);\n const prerunArgsF = field(rid, projectFieldName(block.id, \"currentPrerunArgs\"));\n tx.createField(prerunArgsF, \"Dynamic\", prerunArgsR);\n }\n }\n}\n"],"names":["SchemaVersionKey","SchemaVersionCurrent","SchemaVersionV1","SchemaVersionV2","ProjectStructureKey","allBlocks","BlockFrontendStateKeyPrefixV1","cachedDeserialize","field","projectFieldName","isNullResourceId"],"mappings":";;;;;;;;AAcA;;;;;AAKG;AACI,eAAe,sBAAsB,CAAC,EAAY,EAAE,GAAe,EAAA;IACxE,MAAM,EAAE,CAAC,WAAW,CAAC,kBAAkB,EAAE,OAAO,EAAE,KAAI;QACpD,IAAI,aAAa,GAAG,MAAM,EAAE,CAAC,aAAa,CAAS,GAAG,EAAEA,8BAAgB,CAAC;QACzE,IAAI,aAAa,KAAKC,kCAAoB;YAAE;;AAG5C,QAAA,IAAI,aAAa,KAAKC,gCAAe,EAAE;AACrC,YAAA,MAAM,aAAa,CAAC,EAAE,EAAE,GAAG,CAAC;YAC5B,aAAa,GAAGC,6BAAe;QACjC;AAEA,QAAA,IAAI,aAAa,KAAKA,6BAAe,EAAE;AACrC,YAAA,MAAM,aAAa,CAAC,EAAE,EAAE,GAAG,CAAC;QAC9B;AAAO,aAAA,IAAI,aAAa,KAAKD,gCAAe,EAAE;;AAE5C,YAAA,MAAM,IAAI,KAAK,CAAC,mCAAmC,aAAa,CAAA,CAAE,CAAC;QACrE;AAEA,QAAA,EAAE,CAAC,SAAS,CAAC,GAAG,EAAEF,8BAAgB,EAAE,IAAI,CAAC,SAAS,CAACC,kCAAoB,CAAC,CAAC;AACzE,QAAA,M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IAAI,GAAG,eAAe,EAAE,IAAI,GAAGA,2BAAiB,CAAC,eAAe,CAAC,IAAI,CAAC,GAAG,EAAE;;AAGjF,QAAA,MAAM,YAAY,GAAG;YACnB,IAAI;YACJ,OAAO;SACR;QAED,MAAM,qBAAqB,GAAGE,8BAAgB,CAAC,KAAK,CAAC,EAAE,EAAE,cAAc,CAAC;;QAGxE,MAAM,MAAM,GAAG,EAAE,CAAC,iBAAiB,CAAC,YAAY,CAAC;QACjD,MAAM,MAAM,GAAGD,cAAK,CAAC,GAAG,EAAE,qBAAqB,CAAC;QAChD,EAAE,CAAC,WAAW,CAAC,MAAM,EAAE,SAAS,EAAE,MAAM,CAAC;;QAGzC,IAAI,cAAc,EAAE;YAClB,MAAM,WAAW,GAAG,EAAE,CAAC,iBAAiB,CAAC,IAAI,CAAC;AAC9C,YAAA,MAAM,WAAW,GAAGA,cAAK,CAAC,GAAG,EAAEC,8BAAgB,CAAC,KAAK,CAAC,EAAE,EAAE,mBAAmB,CAAC,CAAC;YAC/E,EAAE,CAAC,WAAW,CAAC,WAAW,EAAE,SAAS,EAAE,WAAW,CAAC;QACrD;IACF;AACF;;;;"}
@@ -109,6 +109,12 @@ async function migrateV2ToV3(tx, rid) {
109
109
  const stateR = tx.createJsonGzValue(unifiedState);
110
110
  const stateF = field(rid, blockStorageFieldName);
111
111
  tx.createField(stateF, "Dynamic", stateR);
112
+ // Initialize currentPrerunArgs from currentArgs (for legacy blocks, prerunArgs = args)
113
+ if (currentArgsRid) {
114
+ const prerunArgsR = tx.createJsonGzValue(args);
115
+ const prerunArgsF = field(rid, projectFieldName(block.id, "currentPrerunArgs"));
116
+ tx.createField(prerunArgsF, "Dynamic", prerunArgsR);
117
+ }
112
118
  }
113
119
  }
114
120
 
@@ -1 +1 @@
1
- {"version":3,"file":"migration.js","sources":["../../src/mutator/migration.ts"],"sourcesContent":["import type { PlClient, PlTransaction, ResourceId } from \"@milaboratories/pl-client\";\nimport type { ProjectField, ProjectStructure } from \"../model/project_model\";\nimport {\n projectFieldName,\n ProjectStructureKey,\n SchemaVersionCurrent,\n SchemaVersionKey,\n SchemaVersionV2,\n} from \"../model/project_model\";\nimport { BlockFrontendStateKeyPrefixV1, SchemaVersionV1 } from \"../model/project_model_v1\";\nimport { field, isNullResourceId } from \"@milaboratories/pl-client\";\nimport { cachedDeserialize } from \"@milaboratories/ts-helpers\";\nimport { allBlocks } from \"../model/project_model_util\";\n\n/**\n * Migrates the project to the latest schema version.\n *\n * @param pl - The client to use.\n * @param rid - The resource id of the project.\n */\nexport async function applyProjectMigrations(pl: PlClient, rid: ResourceId) {\n await pl.withWriteTx(\"ProjectMigration\", async (tx) => {\n let schemaVersion = await tx.getKValueJson<string>(rid, SchemaVersionKey);\n if (schemaVersion === SchemaVersionCurrent) return;\n\n // Apply migrations in sequence\n if (schemaVersion === SchemaVersionV1) {\n await migrateV1ToV2(tx, rid);\n schemaVersion = SchemaVersionV2;\n }\n\n if (schemaVersion === SchemaVersionV2) {\n await migrateV2ToV3(tx, rid);\n } else if (schemaVersion !== SchemaVersionV1) {\n // If we got here and it's not v1 (which was handled above), it's unknown\n throw new Error(`Unknown project schema version: ${schemaVersion}`);\n }\n\n tx.setKValue(rid, SchemaVersionKey, JSON.stringify(SchemaVersionCurrent));\n await tx.commit();\n });\n}\n\n/**\n * Migrates the project from schema version 1 to 2.\n *\n * Summary of changes:\n * - uiState is now stored in a field instead of a KV\n *\n * @param tx - The transaction to use.\n * @param rid - The resource id of the project.\n */\nasync function migrateV1ToV2(tx: PlTransaction, rid: ResourceId) {\n const [structure, allKV] = await Promise.all([\n tx.getKValueJson<ProjectStructure>(rid, ProjectStructureKey),\n tx.listKeyValues(rid),\n ]);\n const kvMap = new Map<string, Uint8Array>(allKV.map((kv) => [kv.key, kv.value]));\n for (const block of allBlocks(structure)) {\n const kvKey = BlockFrontendStateKeyPrefixV1 + block.id;\n const uiState = kvMap.get(kvKey);\n const valueJson = uiState ? cachedDeserialize(uiState) : {};\n const uiStateR = tx.createJsonGzValue(valueJson);\n const uiStateF = field(rid, projectFieldName(block.id, \"blockStorage\"));\n tx.createField(uiStateF, \"Dynamic\", uiStateR);\n tx.deleteKValue(rid, kvKey);\n }\n}\n\n/**\n * Migrates the project from schema version 2 to 3.\n *\n * Summary of changes:\n * - Introduces unified 'blockStorage' field containing { args, uiState }\n * - Adds 'currentPrerunArgs' field for staging/prerun rendering\n * - For each block:\n * 1. Read existing 'blockStorage' field (contains uiState in v2)\n * 2. Read existing 'currentArgs' field (contains args)\n * 3. Create unified state = { args: currentArgs, uiState: oldState }\n * 4. Write to new {blockId}-blockStorage field (overwrites)\n * 5. Initialize {blockId}-currentPrerunArgs (same as prodArgs for v1/v2 blocks)\n * - Note: currentArgs and prodArgs fields remain for compatibility layer\n *\n * @param tx - The transaction to use.\n * @param rid - The resource id of the project.\n */\nasync function migrateV2ToV3(tx: PlTransaction, rid: ResourceId) {\n const [structure, fullResourceState] = await Promise.all([\n tx.getKValueJson<ProjectStructure>(rid, ProjectStructureKey),\n tx.getResourceData(rid, true),\n ]);\n\n // Build a map of field name -> resource id for quick lookup\n const fieldMap = new Map<string, ResourceId>();\n for (const f of fullResourceState.fields) {\n if (!isNullResourceId(f.value)) {\n fieldMap.set(f.name, f.value);\n }\n }\n\n for (const block of allBlocks(structure)) {\n // Read existing field values\n const uiStateFieldName = projectFieldName(block.id, \"uiState\" as ProjectField[\"fieldName\"]);\n const currentArgsFieldName = projectFieldName(block.id, \"currentArgs\");\n\n const uiStateRid = fieldMap.get(uiStateFieldName);\n const currentArgsRid = fieldMap.get(currentArgsFieldName);\n\n // Read field data in parallel where available\n const [uiStateData, currentArgsData] = await Promise.all([\n uiStateRid ? tx.getResourceData(uiStateRid, false) : Promise.resolve(undefined),\n currentArgsRid ? tx.getResourceData(currentArgsRid, false) : Promise.resolve(undefined),\n ]);\n\n // Extract values - in v2, 'blockStorage' contains raw uiState, not wrapped\n const uiState = uiStateData?.data ? cachedDeserialize(uiStateData.data) : {};\n const args = currentArgsData?.data ? cachedDeserialize(currentArgsData.data) : {};\n\n // Create unified state: { args, uiState }\n const unifiedState = {\n args,\n uiState,\n };\n\n const blockStorageFieldName = projectFieldName(block.id, \"blockStorage\");\n\n // Write new unified blockStorage field (overwrite existing)\n const stateR = tx.createJsonGzValue(unifiedState);\n const stateF = field(rid, blockStorageFieldName);\n tx.createField(stateF, \"Dynamic\", stateR);\n }\n}\n"],"names":[],"mappings":";;;;;;AAcA;;;;;AAKG;AACI,eAAe,sBAAsB,CAAC,EAAY,EAAE,GAAe,EAAA;IACxE,MAAM,EAAE,CAAC,WAAW,CAAC,kBAAkB,EAAE,OAAO,EAAE,KAAI;QACpD,IAAI,aAAa,GAAG,MAAM,EAAE,CAAC,aAAa,CAAS,GAAG,EAAE,gBAAgB,CAAC;QACzE,IAAI,aAAa,KAAK,oBAAoB;YAAE;;AAG5C,QAAA,IAAI,aAAa,KAAK,eAAe,EAAE;AACrC,YAAA,MAAM,aAAa,CAAC,EAAE,EAAE,GAAG,CAAC;YAC5B,aAAa,GAAG,eAAe;QACjC;AAEA,QAAA,IAAI,aAAa,KAAK,eAAe,EAAE;AACrC,YAAA,MAAM,aAAa,CAAC,EAAE,EAAE,GAAG,CAAC;QAC9B;AAAO,aAAA,IAAI,aAAa,KAAK,eAAe,EAAE;;AAE5C,YAAA,MAAM,IAAI,KAAK,CAAC,mCAAmC,aAAa,CAAA,CAAE,CAAC;QACrE;AAEA,QAAA,EAAE,CAAC,SAAS,CAAC,GAAG,EAAE,gBAAgB,EAAE,IAAI,CAAC,SAAS,CAAC,oBAAoB,CAAC,CAAC;AACzE,QAAA,MAAM,EAAE,CAAC,MAAM,EAAE;AACnB,IAAA,CAAC,CAAC;AACJ;AAEA;;;;;;;;AAQG;AACH,eAAe,aAAa,CAAC,EAAiB,EAAE,GAAe,EAAA;IAC7D,MAAM,CAAC,SAAS,EAAE,KAAK,CAAC,GAAG,MAAM,OAAO,CAAC,GAAG,CAAC;AAC3C,QAAA,EAAE,CAAC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AG,EAAE,CAAC,iBAAiB,CAAC,YAAY,CAAC;QACjD,MAAM,MAAM,GAAG,KAAK,CAAC,GAAG,EAAE,qBAAqB,CAAC;QAChD,EAAE,CAAC,WAAW,CAAC,MAAM,EAAE,SAAS,EAAE,MAAM,CAAC;IAC3C;AACF;;;;"}
1
+ {"version":3,"file":"migration.js","sources":["../../src/mutator/migration.ts"],"sourcesContent":["import type { PlClient, PlTransaction, ResourceId } from \"@milaboratories/pl-client\";\nimport type { ProjectField, ProjectStructure } from \"../model/project_model\";\nimport {\n projectFieldName,\n ProjectStructureKey,\n SchemaVersionCurrent,\n SchemaVersionKey,\n SchemaVersionV2,\n} from \"../model/project_model\";\nimport { BlockFrontendStateKeyPrefixV1, SchemaVersionV1 } from \"../model/project_model_v1\";\nimport { field, isNullResourceId } from \"@milaboratories/pl-client\";\nimport { cachedDeserialize } from \"@milaboratories/ts-helpers\";\nimport { allBlocks } from \"../model/project_model_util\";\n\n/**\n * Migrates the project to the latest schema version.\n *\n * @param pl - The client to use.\n * @param rid - The resource id of the project.\n */\nexport async function applyProjectMigrations(pl: PlClient, rid: ResourceId) {\n await pl.withWriteTx(\"ProjectMigration\", async (tx) => {\n let schemaVersion = await tx.getKValueJson<string>(rid, SchemaVersionKey);\n if (schemaVersion === SchemaVersionCurrent) return;\n\n // Apply migrations in sequence\n if (schemaVersion === SchemaVersionV1) {\n await migrateV1ToV2(tx, rid);\n schemaVersion = SchemaVersionV2;\n }\n\n if (schemaVersion === SchemaVersionV2) {\n await migrateV2ToV3(tx, rid);\n } else if (schemaVersion !== SchemaVersionV1) {\n // If we got here and it's not v1 (which was handled above), it's unknown\n throw new Error(`Unknown project schema version: ${schemaVersion}`);\n }\n\n tx.setKValue(rid, SchemaVersionKey, JSON.stringify(SchemaVersionCurrent));\n await tx.commit();\n });\n}\n\n/**\n * Migrates the project from schema version 1 to 2.\n *\n * Summary of changes:\n * - uiState is now stored in a field instead of a KV\n *\n * @param tx - The transaction to use.\n * @param rid - The resource id of the project.\n */\nasync function migrateV1ToV2(tx: PlTransaction, rid: ResourceId) {\n const [structure, allKV] = await Promise.all([\n tx.getKValueJson<ProjectStructure>(rid, ProjectStructureKey),\n tx.listKeyValues(rid),\n ]);\n const kvMap = new Map<string, Uint8Array>(allKV.map((kv) => [kv.key, kv.value]));\n for (const block of allBlocks(structure)) {\n const kvKey = BlockFrontendStateKeyPrefixV1 + block.id;\n const uiState = kvMap.get(kvKey);\n const valueJson = uiState ? cachedDeserialize(uiState) : {};\n const uiStateR = tx.createJsonGzValue(valueJson);\n const uiStateF = field(rid, projectFieldName(block.id, \"blockStorage\"));\n tx.createField(uiStateF, \"Dynamic\", uiStateR);\n tx.deleteKValue(rid, kvKey);\n }\n}\n\n/**\n * Migrates the project from schema version 2 to 3.\n *\n * Summary of changes:\n * - Introduces unified 'blockStorage' field containing { args, uiState }\n * - Adds 'currentPrerunArgs' field for staging/prerun rendering\n * - For each block:\n * 1. Read existing 'blockStorage' field (contains uiState in v2)\n * 2. Read existing 'currentArgs' field (contains args)\n * 3. Create unified state = { args: currentArgs, uiState: oldState }\n * 4. Write to new {blockId}-blockStorage field (overwrites)\n * 5. Initialize {blockId}-currentPrerunArgs (same as prodArgs for v1/v2 blocks)\n * - Note: currentArgs and prodArgs fields remain for compatibility layer\n *\n * @param tx - The transaction to use.\n * @param rid - The resource id of the project.\n */\nasync function migrateV2ToV3(tx: PlTransaction, rid: ResourceId) {\n const [structure, fullResourceState] = await Promise.all([\n tx.getKValueJson<ProjectStructure>(rid, ProjectStructureKey),\n tx.getResourceData(rid, true),\n ]);\n\n // Build a map of field name -> resource id for quick lookup\n const fieldMap = new Map<string, ResourceId>();\n for (const f of fullResourceState.fields) {\n if (!isNullResourceId(f.value)) {\n fieldMap.set(f.name, f.value);\n }\n }\n\n for (const block of allBlocks(structure)) {\n // Read existing field values\n const uiStateFieldName = projectFieldName(block.id, \"uiState\" as ProjectField[\"fieldName\"]);\n const currentArgsFieldName = projectFieldName(block.id, \"currentArgs\");\n\n const uiStateRid = fieldMap.get(uiStateFieldName);\n const currentArgsRid = fieldMap.get(currentArgsFieldName);\n\n // Read field data in parallel where available\n const [uiStateData, currentArgsData] = await Promise.all([\n uiStateRid ? tx.getResourceData(uiStateRid, false) : Promise.resolve(undefined),\n currentArgsRid ? tx.getResourceData(currentArgsRid, false) : Promise.resolve(undefined),\n ]);\n\n // Extract values - in v2, 'blockStorage' contains raw uiState, not wrapped\n const uiState = uiStateData?.data ? cachedDeserialize(uiStateData.data) : {};\n const args = currentArgsData?.data ? cachedDeserialize(currentArgsData.data) : {};\n\n // Create unified state: { args, uiState }\n const unifiedState = {\n args,\n uiState,\n };\n\n const blockStorageFieldName = projectFieldName(block.id, \"blockStorage\");\n\n // Write new unified blockStorage field (overwrite existing)\n const stateR = tx.createJsonGzValue(unifiedState);\n const stateF = field(rid, blockStorageFieldName);\n tx.createField(stateF, \"Dynamic\", stateR);\n\n // Initialize currentPrerunArgs from currentArgs (for legacy blocks, prerunArgs = args)\n if (currentArgsRid) {\n const prerunArgsR = tx.createJsonGzValue(args);\n const prerunArgsF = field(rid, projectFieldName(block.id, \"currentPrerunArgs\"));\n tx.createField(prerunArgsF, \"Dynamic\", prerunArgsR);\n }\n }\n}\n"],"names":[],"mappings":";;;;;;AAcA;;;;;AAKG;AACI,eAAe,sBAAsB,CAAC,EAAY,EAAE,GAAe,EAAA;IACxE,MAAM,EAAE,CAAC,WAAW,CAAC,kBAAkB,EAAE,OAAO,EAAE,KAAI;QACpD,IAAI,aAAa,GAAG,MAAM,EAAE,CAAC,aAAa,CAAS,GAAG,EAAE,gBAAgB,CAAC;QACzE,IAAI,aAAa,KAAK,oBAAoB;YAAE;;AAG5C,QAAA,IAAI,aAAa,KAAK,eAAe,EAAE;AACrC,YAAA,MAAM,aAAa,CAAC,EAAE,EAAE,GAAG,CAAC;YAC5B,aAAa,GAAG,eAAe;QACjC;AAEA,QAAA,IAAI,aAAa,KAAK,eAAe,EAAE;AACrC,YAAA,MAAM,aA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CAAC;AAC/E,YAAA,cAAc,GAAG,EAAE,CAAC,eAAe,CAAC,cAAc,EAAE,KAAK,CAAC,GAAG,OAAO,CAAC,OAAO,CAAC,SAAS,CAAC;AACxF,SAAA,CAAC;;AAGF,QAAA,MAAM,OAAO,GAAG,WAAW,EAAE,IAAI,GAAG,iBAAiB,CAAC,WAAW,CAAC,IAAI,CAAC,GAAG,EAAE;AAC5E,QAAA,MAAM,IAAI,GAAG,eAAe,EAAE,IAAI,GAAG,iBAAiB,CAAC,eAAe,CAAC,IAAI,CAAC,GAAG,EAAE;;AAGjF,QAAA,MAAM,YAAY,GAAG;YACnB,IAAI;YACJ,OAAO;SACR;QAED,MAAM,qBAAqB,GAAG,gBAAgB,CAAC,KAAK,CAAC,EAAE,EAAE,cAAc,CAAC;;QAGxE,MAAM,MAAM,GAAG,EAAE,CAAC,iBAAiB,CAAC,YAAY,CAAC;QACjD,MAAM,MAAM,GAAG,KAAK,CAAC,GAAG,EAAE,qBAAqB,CAAC;QAChD,EAAE,CAAC,WAAW,CAAC,MAAM,EAAE,SAAS,EAAE,MAAM,CAAC;;QAGzC,IAAI,cAAc,EAAE;YAClB,MAAM,WAAW,GAAG,EAAE,CAAC,iBAAiB,CAAC,IAAI,CAAC;AAC9C,YAAA,MAAM,WAAW,GAAG,KAAK,CAAC,GAAG,EAAE,gBAAgB,CAAC,KAAK,CAAC,EAAE,EAAE,mBAAmB,CAAC,CAAC;YAC/E,EAAE,CAAC,WAAW,CAAC,WAAW,EAAE,SAAS,EAAE,WAAW,CAAC;QACrD;IACF;AACF;;;;"}
@@ -871,8 +871,25 @@ class ProjectMutator {
871
871
  console.warn(`[migrateBlockPack] Block ${blockId} migration warning: ${migrationResult.warn}`);
872
872
  }
873
873
  this.setBlockStorageRaw(blockId, migrationResult.newStorageJson);
874
+ // Re-derive currentArgs from migrated storage (new block code + migrated data)
875
+ const deriveArgsResult = this.projectHelper.deriveArgsFromStorage(newConfig, migrationResult.newStorageJson);
876
+ if (!deriveArgsResult.error) {
877
+ this.setBlockFieldObj(blockId, "currentArgs", this.createJsonFieldValue(deriveArgsResult.value));
878
+ }
879
+ // Derive prerunArgs from the migrated storage so staging can re-render
880
+ const prerunArgs = this.projectHelper.derivePrerunArgsFromStorage(newConfig, migrationResult.newStorageJson);
881
+ if (prerunArgs !== undefined) {
882
+ this.setBlockFieldObj(blockId, "currentPrerunArgs", this.createJsonFieldValue(prerunArgs));
883
+ }
884
+ }
885
+ }
886
+ else {
887
+ // Legacy blocks (modelAPIVersion 1): prerunArgs = currentArgs
888
+ if (info.fields.currentArgs !== undefined) {
889
+ this.setBlockFieldObj(blockId, "currentPrerunArgs", info.fields.currentArgs);
874
890
  }
875
891
  }
892
+ this.blocksWithChangedInputs.add(blockId);
876
893
  // resetting staging outputs for all downstream blocks
877
894
  this.getStagingGraph().traverse("downstream", [blockId], ({ id }) => this.resetStaging(id));
878
895
  }