{"version":3,"sources":["../../src/utilities/blocksToJsonMigrator.ts"],"sourcesContent":["import type {\n DynamicMigrationTemplate,\n FlattenedField,\n Payload,\n PayloadRequest,\n SanitizedConfig,\n} from 'payload'\nimport type tsTypes from 'typescript'\n\nimport { existsSync, mkdirSync, readdirSync, readFileSync, rmSync, writeFileSync } from 'fs'\nimport path from 'path'\nimport {\n APIError,\n buildVersionCollectionFields,\n buildVersionGlobalFields,\n dynamicImport,\n} from 'payload'\nimport { findConfig } from 'payload/node'\nimport { fieldShouldBeLocalized } from 'payload/shared'\n\nimport type {\n BlocksToJsonBlockToMigrate,\n BlocksToJsonEntityToMigrate,\n BlocksToJsonMigrator,\n DrizzleAdapter,\n} from '../types.js'\n\nimport { getTransaction } from './getTransaction.js'\n\nconst DEFAULT_BATCH_SIZE = 100\nconst TEMP_FOLDER_NAME = '.payload-blocks-migration'\n\nconst writeEntitiesToTempFile = (\n entities: BlocksToJsonEntityToMigrate[],\n tempFolderPath: string,\n batchIndex: number,\n): void => {\n const filePath = path.join(tempFolderPath, `entities-batch-${batchIndex}.json`)\n writeFileSync(filePath, JSON.stringify(entities, null, 2), 'utf-8')\n}\n\nconst acceptDrizzlePrompts = async (\n callPrompt: () => Promise | T,\n {\n silenceLogs = false,\n }: {\n silenceLogs?: boolean\n } = {},\n): Promise => {\n // eslint-disable-next-line @typescript-eslint/unbound-method\n const write = process.stdout.write\n\n if (silenceLogs) {\n process.stdout.write = () => true\n }\n\n const promise = callPrompt()\n\n const interval = setInterval(\n () =>\n process.stdin.emit('keypress', '\\n', {\n name: 'return',\n ctrl: false,\n }),\n 25,\n )\n\n const res = await promise\n\n if (silenceLogs) {\n process.stdout.write = write\n }\n\n clearInterval(interval)\n\n return res\n}\n\nconst entityHasBlocksField = (entity: { flattenedFields: FlattenedField[] }): boolean => {\n for (const field of entity.flattenedFields) {\n if (field.type === 'blocks') {\n return true\n }\n\n if (\n 'flattenedFields' in field &&\n entityHasBlocksField({ flattenedFields: field.flattenedFields })\n ) {\n return true\n }\n }\n\n return false\n}\n\nconst collectBlocksToMigrate = ({\n config,\n data,\n fields,\n parentAccessor,\n parentIsLocalized,\n}: {\n config: SanitizedConfig\n data: any\n fields: FlattenedField[]\n parentAccessor: (number | string)[]\n parentIsLocalized: boolean\n}): BlocksToJsonBlockToMigrate[] => {\n const result: BlocksToJsonBlockToMigrate[] = []\n\n for (const field of fields) {\n switch (field.type) {\n case 'array': {\n const arrayData = data[field.name]\n\n if (!Array.isArray(arrayData)) {\n continue\n }\n\n if (config.localization && fieldShouldBeLocalized({ field, parentIsLocalized })) {\n result.push(\n ...collectBlocksToMigrate({\n config,\n data: arrayData,\n fields: config.localization.localeCodes.map((code) => ({\n ...field,\n name: code,\n localized: false,\n })),\n parentAccessor: [...parentAccessor, field.name],\n parentIsLocalized: true,\n }),\n )\n\n continue\n }\n\n for (const [index, row] of arrayData.entries()) {\n result.push(\n ...collectBlocksToMigrate({\n config,\n data: row,\n fields: field.flattenedFields,\n parentAccessor: [...parentAccessor, field.name, index],\n parentIsLocalized,\n }),\n )\n }\n break\n }\n case 'blocks': {\n result.push({\n data: data[field.name],\n fieldAccessor: [...parentAccessor, field.name],\n })\n break\n }\n case 'group':\n case 'tab': {\n if (config.localization && fieldShouldBeLocalized({ field, parentIsLocalized })) {\n result.push(\n ...collectBlocksToMigrate({\n config,\n data: data[field.name],\n fields: config.localization.localeCodes.map((code) => ({\n ...field,\n name: code,\n localized: false,\n })),\n parentAccessor: [...parentAccessor, field.name],\n parentIsLocalized: true,\n }),\n )\n\n continue\n }\n\n result.push(\n ...collectBlocksToMigrate({\n config,\n data: data[field.name],\n fields: field.flattenedFields,\n parentAccessor: [...parentAccessor, field.name],\n parentIsLocalized,\n }),\n )\n break\n }\n default: {\n continue\n }\n }\n }\n\n return result\n}\n\nclass BlocksToJsonMigratorImpl implements BlocksToJsonMigrator {\n private readonly batchSize: number\n private tempFolderPath: string\n\n constructor(\n private readonly adapter: DrizzleAdapter,\n private readonly sanitizeStatements: (args: {\n sqlExecute: string\n statements: string[]\n }) => string,\n private readonly executeMethod: string,\n batchSize?: number,\n ) {\n this.batchSize = batchSize || DEFAULT_BATCH_SIZE\n this.tempFolderPath = path.resolve(this.adapter.migrationDir, TEMP_FOLDER_NAME)\n }\n\n private ensureTempFolder(): void {\n if (!existsSync(this.tempFolderPath)) {\n mkdirSync(this.tempFolderPath, { recursive: true })\n }\n }\n\n private *fetchEntitiesFromJsonBatches(): IterableIterator {\n if (!existsSync(this.tempFolderPath)) {\n return\n }\n\n const files = readdirSync(this.tempFolderPath)\n .filter((file) => file.startsWith('entities-batch-') && file.endsWith('.json'))\n .sort((a, b) => {\n const aNum = parseInt(a.match(/\\d+/)?.[0] || '0', 10)\n const bNum = parseInt(b.match(/\\d+/)?.[0] || '0', 10)\n return aNum - bNum\n })\n\n for (const file of files) {\n const filePath = path.join(this.tempFolderPath, file)\n const fileContent = readFileSync(filePath, 'utf-8')\n const batchEntities = JSON.parse(fileContent) as BlocksToJsonEntityToMigrate[]\n yield batchEntities\n }\n }\n\n private async migrateEntities(\n entities: BlocksToJsonEntityToMigrate[],\n req: PayloadRequest,\n ): Promise {\n this.adapter.blocksAsJSON = true\n this.resetSchema()\n await this.adapter.init()\n await this.adapter.connect()\n\n await this.syncTransactionDrizzleInstance(req)\n\n const totalEntities = entities.length\n let processed = 0\n\n for (const entity of entities) {\n switch (entity.type) {\n case 'collection': {\n await this.adapter.updateOne({\n collection: entity.slug,\n data: entity.originalData,\n joins: false,\n req,\n where: {\n id: {\n equals: entity.id,\n },\n },\n })\n break\n }\n case 'collectionVersion': {\n await this.adapter.updateVersion({\n id: entity.id,\n collection: entity.slug,\n req,\n versionData: entity.originalData as any,\n })\n\n break\n }\n case 'global': {\n await this.adapter.updateGlobal({\n slug: entity.slug,\n data: entity.originalData,\n req,\n })\n break\n }\n case 'globalVersion': {\n await this.adapter.updateGlobalVersion({\n id: entity.id,\n global: entity.slug,\n req,\n versionData: entity.originalData as any,\n })\n break\n }\n }\n\n processed++\n if (processed % this.batchSize === 0 || processed === totalEntities) {\n this.adapter.payload.logger.info(\n `Migrated ${processed}/${totalEntities} entities (${Math.round((processed / totalEntities) * 100)}%)`,\n )\n }\n }\n }\n\n private resetSchema() {\n this.adapter.schema = {}\n this.adapter.tables = {}\n this.adapter.indexes = new Set()\n this.adapter.foreignKeys = new Set()\n this.adapter.relations = {}\n this.adapter.rawTables = {}\n this.adapter.rawRelations = {}\n this.adapter.tableNameMap = new Map()\n this.adapter.enums = {}\n }\n\n private async syncTransactionDrizzleInstance(req: PayloadRequest) {\n const tsx = (await getTransaction(this.adapter, req)) as any\n\n tsx._ = this.adapter.drizzle._\n tsx.schema = this.adapter.drizzle._\n tsx.session.schema = (this.adapter.drizzle as any).session.schema\n }\n\n cleanupTempFolder(): void {\n rmSync(this.tempFolderPath, { force: true, recursive: true })\n\n this.adapter.payload.logger.info(`Cleaned up temp folder at ${this.tempFolderPath}`)\n }\n\n async collectAndSaveEntitiesToBatches(\n req: PayloadRequest,\n options?: {\n batchSize?: number\n },\n ): Promise {\n const batchSize = options?.batchSize ?? this.batchSize\n\n this.cleanupTempFolder()\n this.ensureTempFolder()\n\n this.adapter.blocksAsJSON = false\n this.resetSchema()\n await this.adapter.init()\n await this.adapter.connect()\n\n // Count total entities to migrate\n let totalExpected = 0\n for (const collection of this.adapter.payload.config.collections.filter(entityHasBlocksField)) {\n const { totalDocs } = await this.adapter.count({ collection: collection.slug })\n totalExpected += totalDocs\n\n if (collection.versions) {\n const { totalDocs: totalVersions } = await this.adapter.countVersions({\n collection: collection.slug,\n })\n totalExpected += totalVersions\n }\n }\n\n for (const globalConfig of this.adapter.payload.config.globals.filter(entityHasBlocksField)) {\n totalExpected += 1 // Global itself\n\n if (globalConfig.versions) {\n const { totalDocs: totalGlobalVersions } = await this.adapter.countGlobalVersions({\n global: globalConfig.slug,\n })\n totalExpected += totalGlobalVersions\n }\n }\n\n this.adapter.payload.logger.info(\n `Found ${totalExpected} total entities to collect and save to batches`,\n )\n\n let batchIndex = 0\n let currentBatch: BlocksToJsonEntityToMigrate[] = []\n let totalCollected = 0\n\n const flushBatch = () => {\n if (currentBatch.length > 0) {\n writeEntitiesToTempFile(currentBatch, this.tempFolderPath, batchIndex)\n const percentage =\n totalExpected > 0 ? Math.round((totalCollected / totalExpected) * 100) : 0\n this.adapter.payload.logger.info(\n `Saved batch ${batchIndex} with ${currentBatch.length} entities (${totalCollected}/${totalExpected} - ${percentage}%)`,\n )\n batchIndex++\n currentBatch = []\n }\n }\n\n const addEntity = (entity: BlocksToJsonEntityToMigrate) => {\n currentBatch.push(entity)\n totalCollected++\n if (currentBatch.length >= batchSize) {\n flushBatch()\n }\n }\n\n for (const collection of this.adapter.payload.config.collections.filter(entityHasBlocksField)) {\n let page = 1\n let hasMore = true\n\n while (hasMore) {\n const { docs, hasNextPage } = await this.adapter.find({\n collection: collection.slug,\n limit: batchSize,\n page,\n })\n\n for (const doc of docs) {\n const entity: BlocksToJsonEntityToMigrate = {\n id: doc.id,\n slug: collection.slug,\n type: 'collection',\n blocks: collectBlocksToMigrate({\n config: this.adapter.payload.config,\n data: doc,\n fields: collection.flattenedFields,\n parentAccessor: [],\n parentIsLocalized: false,\n }),\n originalData: doc,\n }\n\n addEntity(entity)\n }\n\n this.adapter.payload.logger.info(\n `Collected ${docs.length} entries from ${collection.slug} (page ${page})`,\n )\n\n hasMore = hasNextPage\n page++\n }\n\n if (collection.versions) {\n let versionPage = 1\n let hasMoreVersions = true\n\n while (hasMoreVersions) {\n const { docs: versionDocs, hasNextPage: hasNextVersionPage } =\n await this.adapter.findVersions({\n collection: collection.slug,\n limit: batchSize,\n page: versionPage,\n })\n\n for (const versionDoc of versionDocs) {\n const entity: BlocksToJsonEntityToMigrate = {\n id: versionDoc.id,\n slug: collection.slug,\n type: 'collectionVersion',\n blocks: collectBlocksToMigrate({\n config: this.adapter.payload.config,\n data: versionDoc,\n fields: buildVersionCollectionFields(this.adapter.payload.config, collection, true),\n parentAccessor: [],\n parentIsLocalized: false,\n }),\n originalData: versionDoc,\n }\n\n addEntity(entity)\n }\n\n this.adapter.payload.logger.info(\n `Collected ${versionDocs.length} versions from ${collection.slug} (page ${versionPage})`,\n )\n\n hasMoreVersions = hasNextVersionPage\n versionPage++\n }\n }\n }\n\n for (const globalConfig of this.adapter.payload.config.globals.filter(entityHasBlocksField)) {\n const globalDoc = await this.adapter.findGlobal({ slug: globalConfig.slug })\n\n const entity: BlocksToJsonEntityToMigrate = {\n slug: globalConfig.slug,\n type: 'global',\n blocks: collectBlocksToMigrate({\n config: this.adapter.payload.config,\n data: globalDoc,\n fields: globalConfig.flattenedFields,\n parentAccessor: [],\n parentIsLocalized: false,\n }),\n originalData: globalDoc,\n }\n\n addEntity(entity)\n this.adapter.payload.logger.info(`Collected global ${globalConfig.slug}`)\n\n if (globalConfig.versions) {\n let globalVersionPage = 1\n let hasMoreGlobalVersions = true\n\n while (hasMoreGlobalVersions) {\n const { docs: globalVersionDocs, hasNextPage: hasNextGlobalVersionPage } =\n await this.adapter.findGlobalVersions({\n global: globalConfig.slug,\n limit: batchSize,\n page: globalVersionPage,\n })\n\n for (const globalVersionDoc of globalVersionDocs) {\n const entity: BlocksToJsonEntityToMigrate = {\n id: globalVersionDoc.id,\n slug: globalConfig.slug,\n type: 'globalVersion',\n blocks: collectBlocksToMigrate({\n config: this.adapter.payload.config,\n data: globalVersionDoc,\n fields: buildVersionGlobalFields(this.adapter.payload.config, globalConfig, true),\n parentAccessor: [],\n parentIsLocalized: false,\n }),\n originalData: globalVersionDoc,\n }\n\n addEntity(entity)\n }\n\n this.adapter.payload.logger.info(\n `Collected ${globalVersionDocs.length} versions from global ${globalConfig.slug} (page ${globalVersionPage})`,\n )\n\n hasMoreGlobalVersions = hasNextGlobalVersionPage\n globalVersionPage++\n }\n }\n }\n\n flushBatch()\n\n this.adapter.payload.logger.info(\n `Collected total of ${totalCollected} entities across ${batchIndex} batches`,\n )\n }\n\n async getMigrationStatements(): Promise<{\n statements: string\n writeDrizzleSnapshot(filePath: string): void\n }> {\n const { generateDrizzleJson, generateMigration } = this.adapter.requireDrizzleKit()\n\n const drizzleJsonBefore = await generateDrizzleJson(this.adapter.schema)\n this.adapter.blocksAsJSON = true\n this.resetSchema()\n\n await this.adapter.init()\n const drizzleJsonAfter = await generateDrizzleJson(this.adapter.schema)\n this.adapter.blocksAsJSON = false\n this.resetSchema()\n await this.adapter.init()\n\n const statements = await acceptDrizzlePrompts(\n () => generateMigration(drizzleJsonBefore, drizzleJsonAfter),\n {\n silenceLogs: true,\n },\n )\n\n const sqlExecute = `await db.${this.executeMethod}(` + 'sql`'\n\n return {\n statements: this.sanitizeStatements({\n sqlExecute,\n statements,\n }),\n writeDrizzleSnapshot(filePath) {\n writeFileSync(`${filePath}.json`, JSON.stringify(drizzleJsonAfter, null, 2))\n },\n }\n }\n\n async migrateEntitiesFromTempFolder(\n req: PayloadRequest,\n options?: {\n clearBatches?: boolean\n },\n ): Promise {\n const clearBatches = options?.clearBatches ?? true\n\n let totalEntities = 0\n let hasEntities = false\n\n for (const entities of this.fetchEntitiesFromJsonBatches()) {\n hasEntities = true\n totalEntities += entities.length\n\n this.adapter.payload.logger.info(\n `Migrating batch with ${entities.length} entities (total: ${totalEntities})`,\n )\n\n await this.migrateEntities(entities, req)\n }\n\n if (!hasEntities) {\n this.adapter.payload.logger.warn('No entities found in temp folder to migrate')\n return\n }\n\n this.adapter.payload.logger.info(\n `Completed migration of ${totalEntities} entities from temp folder`,\n )\n\n if (clearBatches) {\n this.cleanupTempFolder()\n } else {\n this.adapter.payload.logger.info(\n `Temp folder preserved at ${this.tempFolderPath} (clearBatches: false)`,\n )\n }\n }\n\n setTempFolder(tempFolderPath: string): void {\n this.tempFolderPath = tempFolderPath\n }\n\n async updatePayloadConfigFile(): Promise {\n let configPath: string\n\n try {\n configPath = findConfig()\n } catch {\n this.adapter.payload.logger.info(\n 'updatePayloadConfigFile failed - could not find the payload config. Please set the blocksAsJSON DB adapter property manually to \"true\"',\n )\n return\n }\n\n const configFile = readFileSync(configPath, 'utf-8')\n\n const ts = await dynamicImport('typescript')\n\n const source = ts.createSourceFile(configPath, configFile, ts.ScriptTarget.ESNext)\n\n let hadChanges = false\n\n const result = ts.transform(source, [\n (ctx) => (sourceFile) => {\n const factory = ctx.factory\n\n const visit: tsTypes.Visitor = (node) => {\n if (\n ts.isPropertyAssignment(node) &&\n ts.isIdentifier(node.name) &&\n node.name.text === 'db' &&\n ts.isCallExpression(node.initializer) &&\n node.initializer.arguments.length > 0 &&\n ts.isObjectLiteralExpression(node.initializer.arguments[0])\n ) {\n const call = node.initializer\n const obj = node.initializer.arguments[0]\n\n const filteredProps = obj.properties.filter((prop) => {\n if (!ts.isPropertyAssignment(prop)) {\n return true\n }\n\n return !(ts.isIdentifier(prop.name) && prop.name.text === 'blocksAsJSON')\n })\n\n const newProperty = factory.createPropertyAssignment(\n 'blocksAsJSON',\n factory.createTrue(),\n )\n hadChanges = true\n const newObject = factory.updateObjectLiteralExpression(obj, [\n ...filteredProps,\n newProperty,\n ])\n\n const newCall = factory.updateCallExpression(\n call,\n call.expression,\n call.typeArguments,\n [newObject],\n )\n\n return factory.updatePropertyAssignment(node, node.name, newCall)\n }\n\n return ts.visitEachChild(node, visit, ctx)\n }\n\n return ts.visitNode(sourceFile, visit) as tsTypes.SourceFile\n },\n ])\n\n if (!hadChanges) {\n this.adapter.payload.logger.info(\n 'No changes made to payload config. Set blocksAsJSON to true manually.',\n )\n return\n }\n\n const printer = ts.createPrinter({ newLine: ts.NewLineKind.LineFeed })\n let output = printer.printFile(result.transformed[0])\n\n try {\n // eslint-disable-next-line @typescript-eslint/consistent-type-imports\n const prettier = await dynamicImport('prettier')\n const configPath = await prettier.resolveConfigFile()\n const config = configPath ? await prettier.resolveConfig(configPath) : {}\n output = await prettier.format(output, { ...config, parser: 'typescript' })\n } catch (err) {\n this.adapter.payload.logger.error({\n err,\n msg: 'Could not format payload config with Prettier',\n })\n }\n\n writeFileSync(configPath, output, 'utf-8')\n this.adapter.payload.logger.info(`Updated ${configPath} with blocksAsJSON: true`)\n }\n}\n\nexport const createBlocksToJsonMigrator = ({\n adapter,\n executeMethod,\n sanitizeStatements,\n}: {\n adapter: DrizzleAdapter\n executeMethod: string\n sanitizeStatements: (args: { sqlExecute: string; statements: string[] }) => string\n}): BlocksToJsonMigrator => {\n return new BlocksToJsonMigratorImpl(adapter, sanitizeStatements, executeMethod)\n}\n\nexport const getBlocksToJsonMigrator = (payload: Payload): BlocksToJsonMigrator => {\n const migrator = (payload.db as DrizzleAdapter).blocksToJsonMigrator\n\n if (!migrator) {\n throw new APIError(`blocksToJsonMigrator is not defined for ${payload.db.packageName}`)\n }\n\n return migrator\n}\n\nexport const buildDynamicPredefinedBlocksToJsonMigration = ({\n packageName,\n}: {\n packageName: string\n}): DynamicMigrationTemplate => {\n return async ({ filePath, payload }) => {\n const migrator = getBlocksToJsonMigrator(payload)\n\n const migrationStatements = await migrator.getMigrationStatements()\n\n migrationStatements.writeDrizzleSnapshot(filePath)\n\n await migrator.updatePayloadConfigFile()\n const upSQL = `\nconst migrator = getBlocksToJsonMigrator(payload)\nmigrator.setTempFolder(TEMP_FOLDER)\nawait migrator.collectAndSaveEntitiesToBatches(req, { batchSize: BATCH_SIZE })\n\n${migrationStatements.statements}\npayload.logger.info(\"Executed blocks to JSON migration statements.\")\n\nawait migrator.migrateEntitiesFromTempFolder(req, { clearBatches: true })\n `\n\n return {\n imports: `\nimport { getBlocksToJsonMigrator } from '${packageName}/migration-utils'\nimport { fileURLToPath } from 'url'\nimport path from 'path'\n\nconst filename = fileURLToPath(import.meta.url)\nconst dirname = path.dirname(filename)\n\n// Configure migration options (optional)\nconst BATCH_SIZE = 100 // Number of entities to process per batch\nconst TEMP_FOLDER = path.resolve(dirname, '${TEMP_FOLDER_NAME}') // Folder path to store migration batch\n`,\n upSQL,\n }\n }\n}\n"],"names":["existsSync","mkdirSync","readdirSync","readFileSync","rmSync","writeFileSync","path","APIError","buildVersionCollectionFields","buildVersionGlobalFields","dynamicImport","findConfig","fieldShouldBeLocalized","getTransaction","DEFAULT_BATCH_SIZE","TEMP_FOLDER_NAME","writeEntitiesToTempFile","entities","tempFolderPath","batchIndex","filePath","join","JSON","stringify","acceptDrizzlePrompts","callPrompt","silenceLogs","write","process","stdout","promise","interval","setInterval","stdin","emit","name","ctrl","res","clearInterval","entityHasBlocksField","entity","field","flattenedFields","type","collectBlocksToMigrate","config","data","fields","parentAccessor","parentIsLocalized","result","arrayData","Array","isArray","localization","push","localeCodes","map","code","localized","index","row","entries","fieldAccessor","BlocksToJsonMigratorImpl","batchSize","adapter","sanitizeStatements","executeMethod","resolve","migrationDir","ensureTempFolder","recursive","fetchEntitiesFromJsonBatches","files","filter","file","startsWith","endsWith","sort","a","b","aNum","parseInt","match","bNum","fileContent","batchEntities","parse","migrateEntities","req","blocksAsJSON","resetSchema","init","connect","syncTransactionDrizzleInstance","totalEntities","length","processed","updateOne","collection","slug","originalData","joins","where","id","equals","updateVersion","versionData","updateGlobal","updateGlobalVersion","global","payload","logger","info","Math","round","schema","tables","indexes","Set","foreignKeys","relations","rawTables","rawRelations","tableNameMap","Map","enums","tsx","_","drizzle","session","cleanupTempFolder","force","collectAndSaveEntitiesToBatches","options","totalExpected","collections","totalDocs","count","versions","totalVersions","countVersions","globalConfig","globals","totalGlobalVersions","countGlobalVersions","currentBatch","totalCollected","flushBatch","percentage","addEntity","page","hasMore","docs","hasNextPage","find","limit","doc","blocks","versionPage","hasMoreVersions","versionDocs","hasNextVersionPage","findVersions","versionDoc","globalDoc","findGlobal","globalVersionPage","hasMoreGlobalVersions","globalVersionDocs","hasNextGlobalVersionPage","findGlobalVersions","globalVersionDoc","getMigrationStatements","generateDrizzleJson","generateMigration","requireDrizzleKit","drizzleJsonBefore","drizzleJsonAfter","statements","sqlExecute","writeDrizzleSnapshot","migrateEntitiesFromTempFolder","clearBatches","hasEntities","warn","setTempFolder","updatePayloadConfigFile","configPath","configFile","ts","source","createSourceFile","ScriptTarget","ESNext","hadChanges","transform","ctx","sourceFile","factory","visit","node","isPropertyAssignment","isIdentifier","text","isCallExpression","initializer","arguments","isObjectLiteralExpression","call","obj","filteredProps","properties","prop","newProperty","createPropertyAssignment","createTrue","newObject","updateObjectLiteralExpression","newCall","updateCallExpression","expression","typeArguments","updatePropertyAssignment","visitEachChild","visitNode","printer","createPrinter","newLine","NewLineKind","LineFeed","output","printFile","transformed","prettier","resolveConfigFile","resolveConfig","format","parser","err","error","msg","createBlocksToJsonMigrator","getBlocksToJsonMigrator","migrator","db","blocksToJsonMigrator","packageName","buildDynamicPredefinedBlocksToJsonMigration","migrationStatements","upSQL","imports"],"mappings":"AASA,SAASA,UAAU,EAAEC,SAAS,EAAEC,WAAW,EAAEC,YAAY,EAAEC,MAAM,EAAEC,aAAa,QAAQ,KAAI;AAC5F,OAAOC,UAAU,OAAM;AACvB,SACEC,QAAQ,EACRC,4BAA4B,EAC5BC,wBAAwB,EACxBC,aAAa,QACR,UAAS;AAChB,SAASC,UAAU,QAAQ,eAAc;AACzC,SAASC,sBAAsB,QAAQ,iBAAgB;AASvD,SAASC,cAAc,QAAQ,sBAAqB;AAEpD,MAAMC,qBAAqB;AAC3B,MAAMC,mBAAmB;AAEzB,MAAMC,0BAA0B,CAC9BC,UACAC,gBACAC;IAEA,MAAMC,WAAWd,KAAKe,IAAI,CAACH,gBAAgB,CAAC,eAAe,EAAEC,WAAW,KAAK,CAAC;IAC9Ed,cAAce,UAAUE,KAAKC,SAAS,CAACN,UAAU,MAAM,IAAI;AAC7D;AAEA,MAAMO,uBAAuB,OAC3BC,YACA,EACEC,cAAc,KAAK,EAGpB,GAAG,CAAC,CAAC;IAEN,6DAA6D;IAC7D,MAAMC,QAAQC,QAAQC,MAAM,CAACF,KAAK;IAElC,IAAID,aAAa;QACfE,QAAQC,MAAM,CAACF,KAAK,GAAG,IAAM;IAC/B;IAEA,MAAMG,UAAUL;IAEhB,MAAMM,WAAWC,YACf,IACEJ,QAAQK,KAAK,CAACC,IAAI,CA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