@seedprotocol/sdk 0.6.9 → 0.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{BasePathResolver-B6CKqoKw.js → BasePathResolver-ndE8XTpw.js} +36 -2
- package/dist/BasePathResolver-ndE8XTpw.js.map +1 -0
- package/dist/ClientManager-DLleL_2e.js +4763 -0
- package/dist/ClientManager-DLleL_2e.js.map +1 -0
- package/dist/{ClientManager-ChcmUL47.js → Item-zBFWQDU9.js} +1119 -5893
- package/dist/Item-zBFWQDU9.js.map +1 -0
- package/dist/{ModelProperty-D79uV42p.js → ModelProperty-lth9L37R.js} +289 -101
- package/dist/ModelProperty-lth9L37R.js.map +1 -0
- package/dist/{Schema-a8uO-hIZ.js → Schema-DOhlrQ-N.js} +94 -864
- package/dist/Schema-DOhlrQ-N.js.map +1 -0
- package/dist/{SchemaValidationService-Y49vqast.js → SchemaValidationService-DDKr5piy.js} +26 -18
- package/dist/SchemaValidationService-DDKr5piy.js.map +1 -0
- package/dist/{backfillMetadataPropertyIds-CBsf7LnU.js → backfillMetadataPropertyIds-fG3ujaSh.js} +11 -6
- package/dist/backfillMetadataPropertyIds-fG3ujaSh.js.map +1 -0
- package/dist/cjs/{ModelProperty-D9FGaGuE.js → ModelProperty-BEsIHAjk.js} +260 -81
- package/dist/cjs/ModelProperty-BEsIHAjk.js.map +1 -0
- package/dist/cjs/{Schema-BiJIPLEL.js → Schema-qEp5mH1N.js} +66 -847
- package/dist/cjs/Schema-qEp5mH1N.js.map +1 -0
- package/dist/cjs/{SchemaValidationService-DtYs_CNY.js → SchemaValidationService-CWEnZmOH.js} +18 -11
- package/dist/cjs/SchemaValidationService-CWEnZmOH.js.map +1 -0
- package/dist/cjs/{backfillMetadataPropertyIds-2XaN3b9S.js → backfillMetadataPropertyIds-tw8JGMT0.js} +8 -3
- package/dist/cjs/backfillMetadataPropertyIds-tw8JGMT0.js.map +1 -0
- package/dist/cjs/{eas-CMNppmGE.js → eas-CLiV2Hmn.js} +4 -4
- package/dist/cjs/{eas-CMNppmGE.js.map → eas-CLiV2Hmn.js.map} +1 -1
- package/dist/cjs/{getItem-B6jEINjW.js → getItem-DSRtx_68.js} +2 -2
- package/dist/cjs/{getItem-B6jEINjW.js.map → getItem-DSRtx_68.js.map} +1 -1
- package/dist/cjs/getLatestVersionRow-DVizNNoI.js +59 -0
- package/dist/cjs/getLatestVersionRow-DVizNNoI.js.map +1 -0
- package/dist/cjs/{getPublishPayload-D5DhLGvN.js → getPublishPayload-D5-dYtNq.js} +249 -60
- package/dist/cjs/getPublishPayload-D5-dYtNq.js.map +1 -0
- package/dist/cjs/{getPublishUploads-DMhCCKYF.js → getPublishUploads-B5Lq6q-_.js} +20 -13
- package/dist/cjs/getPublishUploads-B5Lq6q-_.js.map +1 -0
- package/dist/cjs/{getSegmentedItemProperties-CU8rtBAo.js → getSegmentedItemProperties-giHO7R3d.js} +10 -11
- package/dist/cjs/getSegmentedItemProperties-giHO7R3d.js.map +1 -0
- package/dist/cjs/{index-DPp9rdRL.js → index-B3UDbm1C.js} +3 -3
- package/dist/cjs/index-B3UDbm1C.js.map +1 -0
- package/dist/cjs/{index-CSNtEnbF.js → index-C66AfYDG.js} +2510 -1694
- package/dist/cjs/index-C66AfYDG.js.map +1 -0
- package/dist/cjs/{property-DlKiAWt4.js → property-BVJIP7SX.js} +40 -35
- package/dist/cjs/property-BVJIP7SX.js.map +1 -0
- package/dist/cjs/resetAmbiguousLegacyItemData-BaZqUui9.js +116 -0
- package/dist/cjs/resetAmbiguousLegacyItemData-BaZqUui9.js.map +1 -0
- package/dist/cjs/resolveModelForSyncedSeed-CC6dQctx.js +49 -0
- package/dist/cjs/resolveModelForSyncedSeed-CC6dQctx.js.map +1 -0
- package/dist/cjs/syncDbWithEas-Dk96sAG-.js +873 -0
- package/dist/cjs/syncDbWithEas-Dk96sAG-.js.map +1 -0
- package/dist/{configurePlatform-CE0Vew17.js → configurePlatform-BMoPG9vY.js} +4 -4
- package/dist/{configurePlatform-CE0Vew17.js.map → configurePlatform-BMoPG9vY.js.map} +1 -1
- package/dist/db/drizzle/0015_add_model_file_id_to_seeds.sql +11 -0
- package/dist/db/drizzle/0016_add_revoked_at_to_metadata.sql +1 -0
- package/dist/db/drizzle/0017_add_revoked_at_to_versions.sql +1 -0
- package/dist/db/drizzle/0018_add_storage_settings_to_properties.sql +53 -0
- package/dist/db/drizzle/0019_add_derived_from_uid_to_metadata.sql +35 -0
- package/dist/db/drizzle/meta/0011_snapshot.json +1182 -0
- package/dist/db/drizzle/meta/0012_snapshot.json +1244 -0
- package/dist/db/drizzle/meta/0013_snapshot.json +63 -1
- package/dist/db/drizzle/meta/0014_snapshot.json +62 -0
- package/dist/db/drizzle/meta/0015_snapshot.json +1338 -0
- package/dist/db/drizzle/meta/0016_snapshot.json +1345 -0
- package/dist/db/drizzle/meta/0017_snapshot.json +1352 -0
- package/dist/db/drizzle/meta/0018_snapshot.json +1373 -0
- package/dist/db/drizzle/meta/0019_snapshot.json +1380 -0
- package/dist/db/drizzle/meta/_journal.json +35 -0
- package/dist/{db-WbrzEf7c.js → db-BJZN0a0a.js} +546 -106
- package/dist/db-BJZN0a0a.js.map +1 -0
- package/dist/{eas-CfYCu4IX.js → eas-B0hsMLqt.js} +7 -7
- package/dist/eas-B0hsMLqt.js.map +1 -0
- package/dist/errors-CrBxGWah.js +17 -0
- package/dist/errors-CrBxGWah.js.map +1 -0
- package/dist/{getItem-Br-bGNFO.js → getItem-DEh4WfHG.js} +8 -10
- package/dist/{getItem-Br-bGNFO.js.map → getItem-DEh4WfHG.js.map} +1 -1
- package/dist/getLatestVersionRow-Brrl1AnW.js +46 -0
- package/dist/getLatestVersionRow-Brrl1AnW.js.map +1 -0
- package/dist/{getPublishPayload-BIrTVUxb.js → getPublishPayload-H032DHC7.js} +263 -75
- package/dist/getPublishPayload-H032DHC7.js.map +1 -0
- package/dist/{getPublishUploads-C6cDeZdz.js → getPublishUploads-CR66RlGJ.js} +25 -17
- package/dist/{getPublishUploads-C6cDeZdz.js.map → getPublishUploads-CR66RlGJ.js.map} +1 -1
- package/dist/{getSegmentedItemProperties-BmKE71vU.js → getSegmentedItemProperties-C2EJ2G0N.js} +13 -14
- package/dist/getSegmentedItemProperties-C2EJ2G0N.js.map +1 -0
- package/dist/{index-ClSv5pTA.js → index-6bJuv5Tt.js} +12 -11
- package/dist/index-6bJuv5Tt.js.map +1 -0
- package/dist/{index-Djd3667v.js → index-B0LgJblD.js} +2 -2
- package/dist/index-B0LgJblD.js.map +1 -0
- package/dist/{index-HRHkbVQd.js → index-DtfjeuxC.js} +417 -174
- package/dist/index-DtfjeuxC.js.map +1 -0
- package/dist/index.browser-CNrqhvEA.js +4139 -0
- package/dist/index.browser-CNrqhvEA.js.map +1 -0
- package/dist/{index.node-DBtQkEfz.js → index.node-DrHiTuOr.js} +9 -4
- package/dist/index.node-DrHiTuOr.js.map +1 -0
- package/dist/main.cjs +1 -1
- package/dist/main.js +771 -521
- package/dist/main.js.map +1 -1
- package/dist/node.js +19 -15
- package/dist/node.js.map +1 -1
- package/dist/platform.browser.js +18 -3719
- package/dist/platform.browser.js.map +1 -1
- package/dist/platform.node.js +3 -3
- package/dist/{property-CQjuZ4JW.js → property-D2Nnsmm1.js} +53 -48
- package/dist/property-D2Nnsmm1.js.map +1 -0
- package/dist/resetAmbiguousLegacyItemData-BqbHNUYk.js +88 -0
- package/dist/resetAmbiguousLegacyItemData-BqbHNUYk.js.map +1 -0
- package/dist/resolveModelForSyncedSeed-DQK6JfXS.js +46 -0
- package/dist/resolveModelForSyncedSeed-DQK6JfXS.js.map +1 -0
- package/dist/seedSchema/MetadataSchema.ts +9 -0
- package/dist/seedSchema/ModelSchema.ts +5 -0
- package/dist/seedSchema/SeedSchema.ts +3 -0
- package/dist/seedSchema/VersionSchema.ts +5 -0
- package/dist/src/Item/Item.d.ts +10 -0
- package/dist/src/Item/Item.d.ts.map +1 -1
- package/dist/src/Item/service/actors/loadOrCreateItem.d.ts.map +1 -1
- package/dist/src/Item/service/actors/waitForDb.d.ts.map +1 -1
- package/dist/src/Item/service/itemMachineSingle.d.ts +3 -29
- package/dist/src/Item/service/itemMachineSingle.d.ts.map +1 -1
- package/dist/src/ItemProperty/ItemProperty.d.ts +3 -4
- package/dist/src/ItemProperty/ItemProperty.d.ts.map +1 -1
- package/dist/src/ItemProperty/service/actors/hydrateFromDb.d.ts.map +1 -1
- package/dist/src/ItemProperty/service/actors/loadOrCreateProperty.d.ts.map +1 -1
- package/dist/src/ItemProperty/service/actors/saveValueToDb/saveFile.d.ts.map +1 -1
- package/dist/src/ItemProperty/service/actors/saveValueToDb/saveHtml.d.ts.map +1 -1
- package/dist/src/ItemProperty/service/actors/saveValueToDb/saveImage.d.ts.map +1 -1
- package/dist/src/ItemProperty/service/actors/saveValueToDb/saveItemStorage.d.ts.map +1 -1
- package/dist/src/ItemProperty/service/propertyMachine.d.ts +4 -9
- package/dist/src/ItemProperty/service/propertyMachine.d.ts.map +1 -1
- package/dist/src/Model/Model.d.ts +37 -0
- package/dist/src/Model/Model.d.ts.map +1 -1
- package/dist/src/Model/errors.d.ts +10 -0
- package/dist/src/Model/errors.d.ts.map +1 -0
- package/dist/src/Model/service/actors/createModelProperties.d.ts.map +1 -1
- package/dist/src/Model/service/actors/loadOrCreateModel.d.ts.map +1 -1
- package/dist/src/Model/service/modelMachine.d.ts +0 -8
- package/dist/src/Model/service/modelMachine.d.ts.map +1 -1
- package/dist/src/ModelProperty/ModelProperty.d.ts +33 -1
- package/dist/src/ModelProperty/ModelProperty.d.ts.map +1 -1
- package/dist/src/ModelProperty/service/actors/compareAndMarkDraft.d.ts.map +1 -1
- package/dist/src/ModelProperty/service/modelPropertyMachine.d.ts +2 -9
- package/dist/src/ModelProperty/service/modelPropertyMachine.d.ts.map +1 -1
- package/dist/src/Schema/Schema.d.ts +1 -2
- package/dist/src/Schema/Schema.d.ts.map +1 -1
- package/dist/src/Schema/service/schemaMachine.d.ts +1 -217
- package/dist/src/Schema/service/schemaMachine.d.ts.map +1 -1
- package/dist/src/Schema/service/validation/SchemaValidationService.d.ts.map +1 -1
- package/dist/src/browser/db/Db.d.ts +3 -0
- package/dist/src/browser/db/Db.d.ts.map +1 -1
- package/dist/src/browser/db/drizzleFiles.d.ts +7 -2
- package/dist/src/browser/db/drizzleFiles.d.ts.map +1 -1
- package/dist/src/browser/db/embeddedMigrations.d.ts +11 -2
- package/dist/src/browser/db/embeddedMigrations.d.ts.map +1 -1
- package/dist/src/browser/db/sqliteBusyRetry.d.ts +14 -0
- package/dist/src/browser/db/sqliteBusyRetry.d.ts.map +1 -0
- package/dist/src/browser/helpers/FileManager.d.ts +1 -0
- package/dist/src/browser/helpers/FileManager.d.ts.map +1 -1
- package/dist/src/browser/helpers/QueryClient.d.ts +1 -0
- package/dist/src/browser/helpers/QueryClient.d.ts.map +1 -1
- package/dist/src/browser/helpers/opfsErrors.d.ts +2 -0
- package/dist/src/browser/helpers/opfsErrors.d.ts.map +1 -0
- package/dist/src/browser/helpers/tolerantWebAccess.d.ts +47 -0
- package/dist/src/browser/helpers/tolerantWebAccess.d.ts.map +1 -0
- package/dist/src/browser/workers/FileDownloader.d.ts.map +1 -1
- package/dist/src/browser/workers/ImageResizer.d.ts.map +1 -1
- package/dist/src/browser/workers/filesDownload.d.ts.map +1 -1
- package/dist/src/browser/workers/imageResize.d.ts.map +1 -1
- package/dist/src/client/ClientManager.d.ts.map +1 -1
- package/dist/src/client/actors/addModelsToDb.d.ts +14 -0
- package/dist/src/client/actors/addModelsToDb.d.ts.map +1 -1
- package/dist/src/client/actors/platformClassesInit.d.ts.map +1 -1
- package/dist/src/client/actors/processSchemaFiles.d.ts.map +1 -1
- package/dist/src/client/actors/saveConfig.d.ts +11 -0
- package/dist/src/client/actors/saveConfig.d.ts.map +1 -1
- package/dist/src/client/constants.d.ts +0 -8
- package/dist/src/client/constants.d.ts.map +1 -1
- package/dist/src/db/backfillMetadataPropertyIds.d.ts.map +1 -1
- package/dist/src/db/configs/{dev.schema.config.d.ts → migrations.config.d.ts} +1 -1
- package/dist/src/db/configs/migrations.config.d.ts.map +1 -0
- package/dist/src/db/read/batchLatestPublishedVersionBySeedLocalIds.d.ts +1 -1
- package/dist/src/db/read/batchLatestPublishedVersionBySeedLocalIds.d.ts.map +1 -1
- package/dist/src/db/read/getItemData.d.ts.map +1 -1
- package/dist/src/db/read/getItemProperties.d.ts.map +1 -1
- package/dist/src/db/read/getItems.d.ts +7 -2
- package/dist/src/db/read/getItems.d.ts.map +1 -1
- package/dist/src/db/read/getLatestPublishedVersionRow.d.ts +2 -1
- package/dist/src/db/read/getLatestPublishedVersionRow.d.ts.map +1 -1
- package/dist/src/db/read/getLatestVersionRow.d.ts +13 -0
- package/dist/src/db/read/getLatestVersionRow.d.ts.map +1 -0
- package/dist/src/db/read/getModelSchemas.d.ts.map +1 -1
- package/dist/src/db/read/getPropertyData.d.ts.map +1 -1
- package/dist/src/db/read/getPublishPayload.d.ts +9 -11
- package/dist/src/db/read/getPublishPayload.d.ts.map +1 -1
- package/dist/src/db/read/getPublishPendingDiff.d.ts +2 -1
- package/dist/src/db/read/getPublishPendingDiff.d.ts.map +1 -1
- package/dist/src/db/read/getPublishUploads.d.ts.map +1 -1
- package/dist/src/db/read/getSchemaUidForModel.d.ts.map +1 -1
- package/dist/src/db/read/getSeedPublishState.d.ts +8 -2
- package/dist/src/db/read/getSeedPublishState.d.ts.map +1 -1
- package/dist/src/db/read/isSeedRevoked.d.ts +7 -0
- package/dist/src/db/read/isSeedRevoked.d.ts.map +1 -0
- package/dist/src/db/read/publishErrors.d.ts +37 -0
- package/dist/src/db/read/publishErrors.d.ts.map +1 -0
- package/dist/src/db/read/resolveModelForSyncedSeed.d.ts +39 -0
- package/dist/src/db/read/resolveModelForSyncedSeed.d.ts.map +1 -0
- package/dist/src/db/read/resolveModelRecord.d.ts +69 -0
- package/dist/src/db/read/resolveModelRecord.d.ts.map +1 -0
- package/dist/src/db/read/resolveRelatedSeedRef.d.ts +34 -0
- package/dist/src/db/read/resolveRelatedSeedRef.d.ts.map +1 -0
- package/dist/src/db/read/subqueries/liveVersion.d.ts +12 -0
- package/dist/src/db/read/subqueries/liveVersion.d.ts.map +1 -0
- package/dist/src/db/read/subqueries/metadataLatest.d.ts +4 -0
- package/dist/src/db/read/subqueries/metadataLatest.d.ts.map +1 -1
- package/dist/src/db/read/subqueries/versionData.d.ts +7 -2
- package/dist/src/db/read/subqueries/versionData.d.ts.map +1 -1
- package/dist/src/db/read/summarizePublishWork.d.ts +10 -2
- package/dist/src/db/read/summarizePublishWork.d.ts.map +1 -1
- package/dist/src/db/resetAmbiguousLegacyItemData.d.ts +17 -0
- package/dist/src/db/resetAmbiguousLegacyItemData.d.ts.map +1 -0
- package/dist/src/db/sqlParamBatches.d.ts +27 -0
- package/dist/src/db/sqlParamBatches.d.ts.map +1 -0
- package/dist/src/db/write/addExcludedTransactions.d.ts +7 -0
- package/dist/src/db/write/addExcludedTransactions.d.ts.map +1 -0
- package/dist/src/db/write/applyPropertyAttestationUidsFromPublish.d.ts +6 -0
- package/dist/src/db/write/applyPropertyAttestationUidsFromPublish.d.ts.map +1 -1
- package/dist/src/db/write/createMetadata.d.ts +2 -0
- package/dist/src/db/write/createMetadata.d.ts.map +1 -1
- package/dist/src/db/write/createNewItem.d.ts +3 -1
- package/dist/src/db/write/createNewItem.d.ts.map +1 -1
- package/dist/src/db/write/createSeed.d.ts +2 -1
- package/dist/src/db/write/createSeed.d.ts.map +1 -1
- package/dist/src/db/write/createSeeds.d.ts +1 -1
- package/dist/src/db/write/createSeeds.d.ts.map +1 -1
- package/dist/src/db/write/linkModelToSchema.d.ts +12 -0
- package/dist/src/db/write/linkModelToSchema.d.ts.map +1 -0
- package/dist/src/db/write/updateItemPropertyValue.d.ts.map +1 -1
- package/dist/src/db/write/updateMetadata.d.ts.map +1 -1
- package/dist/src/db/write/updateSeedRevokedAt.d.ts +11 -1
- package/dist/src/db/write/updateSeedRevokedAt.d.ts.map +1 -1
- package/dist/src/db/write/updateSeedUid.d.ts.map +1 -1
- package/dist/src/db/write/updateVersionUid.d.ts +2 -1
- package/dist/src/db/write/updateVersionUid.d.ts.map +1 -1
- package/dist/src/events/files/download.d.ts.map +1 -1
- package/dist/src/events/item/easSyncManager.d.ts +2 -0
- package/dist/src/events/item/easSyncManager.d.ts.map +1 -1
- package/dist/src/events/item/index.d.ts.map +1 -1
- package/dist/src/events/item/syncDbWithEas.d.ts +16 -0
- package/dist/src/events/item/syncDbWithEas.d.ts.map +1 -1
- package/dist/src/helpers/FileManager/BaseFileManager.d.ts +1 -0
- package/dist/src/helpers/FileManager/BaseFileManager.d.ts.map +1 -1
- package/dist/src/helpers/FileManager/IFileManager.d.ts +5 -0
- package/dist/src/helpers/FileManager/IFileManager.d.ts.map +1 -1
- package/dist/src/helpers/FileManager/errors.d.ts +10 -0
- package/dist/src/helpers/FileManager/errors.d.ts.map +1 -0
- package/dist/src/helpers/compareMetadataRowsLatestFirst.d.ts +21 -3
- package/dist/src/helpers/compareMetadataRowsLatestFirst.d.ts.map +1 -1
- package/dist/src/helpers/constants.d.ts +9 -0
- package/dist/src/helpers/constants.d.ts.map +1 -1
- package/dist/src/helpers/crypto.d.ts +5 -0
- package/dist/src/helpers/crypto.d.ts.map +1 -1
- package/dist/src/helpers/db.d.ts +25 -5
- package/dist/src/helpers/db.d.ts.map +1 -1
- package/dist/src/helpers/easPropertyCanonical.d.ts +1 -1
- package/dist/src/helpers/easPropertyCanonical.d.ts.map +1 -1
- package/dist/src/helpers/entity/entityCommon.d.ts +10 -0
- package/dist/src/helpers/entity/entityCommon.d.ts.map +1 -1
- package/dist/src/helpers/entity/entityDestroy.d.ts +1 -1
- package/dist/src/helpers/entity/entityDestroy.d.ts.map +1 -1
- package/dist/src/helpers/entity/entityLiveQuery.d.ts +5 -0
- package/dist/src/helpers/entity/entityLiveQuery.d.ts.map +1 -1
- package/dist/src/helpers/file/fetchAll/actors.d.ts.map +1 -1
- package/dist/src/helpers/getSegmentedItemProperties.d.ts.map +1 -1
- package/dist/src/helpers/htmlEmbeddedDataUriPublish.d.ts +6 -0
- package/dist/src/helpers/htmlEmbeddedDataUriPublish.d.ts.map +1 -1
- package/dist/src/helpers/isPublishedMetadataRow.d.ts +10 -0
- package/dist/src/helpers/isPublishedMetadataRow.d.ts.map +1 -0
- package/dist/src/helpers/ownership.d.ts.map +1 -1
- package/dist/src/helpers/property.d.ts +6 -1
- package/dist/src/helpers/property.d.ts.map +1 -1
- package/dist/src/helpers/schema.d.ts +14 -4
- package/dist/src/helpers/schema.d.ts.map +1 -1
- package/dist/src/helpers/tabCoordinator.d.ts +45 -0
- package/dist/src/helpers/tabCoordinator.d.ts.map +1 -0
- package/dist/src/helpers/tabEvents.d.ts +27 -0
- package/dist/src/helpers/tabEvents.d.ts.map +1 -0
- package/dist/src/helpers/tabLocks.d.ts +28 -0
- package/dist/src/helpers/tabLocks.d.ts.map +1 -0
- package/dist/src/helpers/updateSchema.d.ts.map +1 -1
- package/dist/src/imports/json.d.ts.map +1 -1
- package/dist/src/imports/markdown.d.ts.map +1 -1
- package/dist/src/index.d.ts +11 -2
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/node/db/Db.d.ts.map +1 -1
- package/dist/src/node/helpers/FileManager.d.ts +2 -0
- package/dist/src/node/helpers/FileManager.d.ts.map +1 -1
- package/dist/src/query/createLocalQueryDataSource.d.ts +4 -0
- package/dist/src/query/createLocalQueryDataSource.d.ts.map +1 -1
- package/dist/src/seedSchema/MetadataSchema.d.ts +36 -0
- package/dist/src/seedSchema/MetadataSchema.d.ts.map +1 -1
- package/dist/src/seedSchema/ModelSchema.d.ts +57 -0
- package/dist/src/seedSchema/ModelSchema.d.ts.map +1 -1
- package/dist/src/seedSchema/SeedSchema.d.ts +19 -0
- package/dist/src/seedSchema/SeedSchema.d.ts.map +1 -1
- package/dist/src/seedSchema/VersionSchema.d.ts +17 -0
- package/dist/src/seedSchema/VersionSchema.d.ts.map +1 -1
- package/dist/src/services/write/actors/writeToDatabase.d.ts +5 -0
- package/dist/src/services/write/actors/writeToDatabase.d.ts.map +1 -1
- package/dist/src/services/write/writeProcessMachine.d.ts.map +1 -1
- package/dist/src/stores/eas.d.ts +1 -1
- package/dist/src/stores/eas.d.ts.map +1 -1
- package/dist/src/types/index.d.ts +7 -0
- package/dist/src/types/index.d.ts.map +1 -1
- package/dist/src/types/item.d.ts +12 -3
- package/dist/src/types/item.d.ts.map +1 -1
- package/dist/src/types/property.d.ts +3 -2
- package/dist/src/types/property.d.ts.map +1 -1
- package/dist/syncDbWithEas-LRKr_NZF.js +855 -0
- package/dist/syncDbWithEas-LRKr_NZF.js.map +1 -0
- package/dist/{index-280bL-n4.js → tabEvents-DYI2GU7i.js} +231 -68
- package/dist/tabEvents-DYI2GU7i.js.map +1 -0
- package/dist/tolerantWebAccess-CzOBz5M6.js +160 -0
- package/dist/tolerantWebAccess-CzOBz5M6.js.map +1 -0
- package/dist/updateSeedRevokedAt-B58ORbY3.js +32 -0
- package/dist/updateSeedRevokedAt-B58ORbY3.js.map +1 -0
- package/package.json +5 -5
- package/dist/BasePathResolver-B6CKqoKw.js.map +0 -1
- package/dist/ClientManager-ChcmUL47.js.map +0 -1
- package/dist/ModelProperty-D79uV42p.js.map +0 -1
- package/dist/Schema-a8uO-hIZ.js.map +0 -1
- package/dist/SchemaValidationService-Y49vqast.js.map +0 -1
- package/dist/backfillMetadataPropertyIds-CBsf7LnU.js.map +0 -1
- package/dist/cjs/ModelProperty-D9FGaGuE.js.map +0 -1
- package/dist/cjs/Schema-BiJIPLEL.js.map +0 -1
- package/dist/cjs/SchemaValidationService-DtYs_CNY.js.map +0 -1
- package/dist/cjs/backfillMetadataPropertyIds-2XaN3b9S.js.map +0 -1
- package/dist/cjs/getPublishPayload-D5DhLGvN.js.map +0 -1
- package/dist/cjs/getPublishUploads-DMhCCKYF.js.map +0 -1
- package/dist/cjs/getSegmentedItemProperties-CU8rtBAo.js.map +0 -1
- package/dist/cjs/index-CSNtEnbF.js.map +0 -1
- package/dist/cjs/index-DPp9rdRL.js.map +0 -1
- package/dist/cjs/property-DlKiAWt4.js.map +0 -1
- package/dist/cjs/syncDbWithEas-C6n34o_Q.js +0 -606
- package/dist/cjs/syncDbWithEas-C6n34o_Q.js.map +0 -1
- package/dist/db-WbrzEf7c.js.map +0 -1
- package/dist/eas-CfYCu4IX.js.map +0 -1
- package/dist/getPublishPayload-BIrTVUxb.js.map +0 -1
- package/dist/getSegmentedItemProperties-BmKE71vU.js.map +0 -1
- package/dist/index-280bL-n4.js.map +0 -1
- package/dist/index-ClSv5pTA.js.map +0 -1
- package/dist/index-Djd3667v.js.map +0 -1
- package/dist/index-HRHkbVQd.js.map +0 -1
- package/dist/index.node-DBtQkEfz.js.map +0 -1
- package/dist/property-CQjuZ4JW.js.map +0 -1
- package/dist/src/Item/service/actors/fetchDataFromEas.d.ts +0 -4
- package/dist/src/Item/service/actors/fetchDataFromEas.d.ts.map +0 -1
- package/dist/src/Item/service/actors/hydrateExistingItem.d.ts +0 -4
- package/dist/src/Item/service/actors/hydrateExistingItem.d.ts.map +0 -1
- package/dist/src/Item/service/actors/hydrateNewItem.d.ts +0 -4
- package/dist/src/Item/service/actors/hydrateNewItem.d.ts.map +0 -1
- package/dist/src/Item/service/actors/initialize.d.ts +0 -4
- package/dist/src/Item/service/actors/initialize.d.ts.map +0 -1
- package/dist/src/Item/service/actors/reload.d.ts +0 -5
- package/dist/src/Item/service/actors/reload.d.ts.map +0 -1
- package/dist/src/Item/service/actors/saveDataToDb.d.ts +0 -4
- package/dist/src/Item/service/actors/saveDataToDb.d.ts.map +0 -1
- package/dist/src/ItemProperty/service/actors/resolveRemoteStorage.d.ts +0 -5
- package/dist/src/ItemProperty/service/actors/resolveRemoteStorage.d.ts.map +0 -1
- package/dist/src/Schema/service/addModelsMachine.d.ts +0 -123
- package/dist/src/Schema/service/addModelsMachine.d.ts.map +0 -1
- package/dist/src/db/configs/dev.schema.config.d.ts.map +0 -1
- package/dist/src/helpers/file/download/actors.d.ts +0 -17
- package/dist/src/helpers/file/download/actors.d.ts.map +0 -1
- package/dist/src/helpers/file/download/index.d.ts +0 -70
- package/dist/src/helpers/file/download/index.d.ts.map +0 -1
- package/dist/src/services/publish/actors/createPublishAttempt.d.ts +0 -4
- package/dist/src/services/publish/actors/createPublishAttempt.d.ts.map +0 -1
- package/dist/src/services/publish/actors/preparePublishRequestData.d.ts +0 -4
- package/dist/src/services/publish/actors/preparePublishRequestData.d.ts.map +0 -1
- package/dist/src/services/publish/actors/upload.d.ts +0 -4
- package/dist/src/services/publish/actors/upload.d.ts.map +0 -1
- package/dist/src/services/publish/actors/validateItemData.d.ts +0 -4
- package/dist/src/services/publish/actors/validateItemData.d.ts.map +0 -1
- package/dist/src/services/publish/publishMachine.d.ts +0 -32
- package/dist/src/services/publish/publishMachine.d.ts.map +0 -1
- package/dist/syncDbWithEas-CuARXfyN.js +0 -598
- package/dist/syncDbWithEas-CuARXfyN.js.map +0 -1
- package/dist/updateSeedRevokedAt-CBcLfHWs.js +0 -22
- package/dist/updateSeedRevokedAt-CBcLfHWs.js.map +0 -1
|
@@ -0,0 +1,4139 @@
|
|
|
1
|
+
import { t as BasePathResolver, B as BaseDb, c as appState, a as BaseFileManager } from './BasePathResolver-ndE8XTpw.js';
|
|
2
|
+
import { eq, sql } from 'drizzle-orm';
|
|
3
|
+
import { o as withDbTabLock, q as notifyFilesWrittenOutsideCache, u as withSeedDbLock } from './tabEvents-DYI2GU7i.js';
|
|
4
|
+
import debug from 'debug';
|
|
5
|
+
import { F as FileSystemLockedError } from './errors-CrBxGWah.js';
|
|
6
|
+
import { drizzle } from 'drizzle-orm/sqlite-proxy';
|
|
7
|
+
import { sha256 } from '@noble/hashes/sha256';
|
|
8
|
+
import { bytesToHex, utf8ToBytes } from '@noble/hashes/utils';
|
|
9
|
+
import { s as schema } from './index-B0LgJblD.js';
|
|
10
|
+
import { SQLocalDrizzle } from 'sqlocal/drizzle';
|
|
11
|
+
import { Observable, distinctUntilChanged } from 'rxjs';
|
|
12
|
+
import { BaseArweaveClient, getPreferredArweaveReadBaseUrls, fetchArweaveRawFromBaseUrl, GET_TRANSACTION_TAGS } from '@seedprotocol/arweave';
|
|
13
|
+
import { GraphQLClient } from 'graphql-request';
|
|
14
|
+
import Arweave from 'arweave';
|
|
15
|
+
import { getEasEndpoint, BaseEasClient, BaseQueryClient } from '@seedprotocol/eas';
|
|
16
|
+
import { QueryClient } from '@tanstack/react-query';
|
|
17
|
+
|
|
18
|
+
class BrowserPathResolver {
|
|
19
|
+
/** @deprecated Prefer BasePathResolver static methods or configure(). */
|
|
20
|
+
static getInstance() {
|
|
21
|
+
return BasePathResolver.getInstance();
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Gets the root directory containing node_modules
|
|
25
|
+
* Note: In browser, this returns a virtual path based on OPFS
|
|
26
|
+
*/
|
|
27
|
+
getRootWithNodeModules() {
|
|
28
|
+
// In browser, we use OPFS which doesn't have traditional paths
|
|
29
|
+
// Return a virtual root path
|
|
30
|
+
return '/';
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Gets the SDK root directory
|
|
34
|
+
* Note: In browser, this returns a virtual path
|
|
35
|
+
*/
|
|
36
|
+
getSdkRootDir() {
|
|
37
|
+
// In browser, SDK is bundled, so we return a virtual path
|
|
38
|
+
return '/sdk';
|
|
39
|
+
}
|
|
40
|
+
getNodeModulesDir() {
|
|
41
|
+
// In browser, node_modules don't exist in the traditional sense
|
|
42
|
+
return '/node_modules';
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Gets the .seed directory path
|
|
46
|
+
* Note: In browser, this returns the OPFS path where .seed data is stored
|
|
47
|
+
*/
|
|
48
|
+
getDotSeedDir(schemaFileDir) {
|
|
49
|
+
// In browser, .seed directory is stored in OPFS
|
|
50
|
+
// The actual path is handled by the FileManager
|
|
51
|
+
return '/.seed';
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Finds the Seed Protocol config file
|
|
55
|
+
* Note: In browser, config files are not accessible via filesystem
|
|
56
|
+
*/
|
|
57
|
+
findConfigFile(searchDir) {
|
|
58
|
+
// In browser, config files are typically embedded in the bundle
|
|
59
|
+
// or loaded via fetch/import
|
|
60
|
+
return null;
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Gets paths for app-specific directories
|
|
64
|
+
* Note: In browser, these are virtual paths for OPFS
|
|
65
|
+
*/
|
|
66
|
+
getAppPaths(schemaFileDir) {
|
|
67
|
+
const dotSeedDir = this.getDotSeedDir(schemaFileDir);
|
|
68
|
+
return {
|
|
69
|
+
sdkRootDir: this.getSdkRootDir(),
|
|
70
|
+
dotSeedDir,
|
|
71
|
+
nodeModulesDir: this.getNodeModulesDir(),
|
|
72
|
+
appSchemaDir: `${dotSeedDir}/schema`,
|
|
73
|
+
appDbDir: `${dotSeedDir}/db`,
|
|
74
|
+
appMetaDir: `${dotSeedDir}/db/meta`,
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
BasePathResolver.configure(new BrowserPathResolver());
|
|
79
|
+
|
|
80
|
+
const KEY = 'excludedTransactions';
|
|
81
|
+
/**
|
|
82
|
+
* Adds transaction ids to the `excludedTransactions` app_state list (txs no gateway could serve).
|
|
83
|
+
* Reads, merges and writes under a cross-tab lock: writing a whole list read earlier lost the ids
|
|
84
|
+
* another tab or download had added in between.
|
|
85
|
+
*/
|
|
86
|
+
async function addExcludedTransactions(transactionIds) {
|
|
87
|
+
const additions = [...transactionIds];
|
|
88
|
+
if (additions.length === 0)
|
|
89
|
+
return;
|
|
90
|
+
await withDbTabLock('excluded-transactions', async () => {
|
|
91
|
+
const appDb = BaseDb.getAppDb();
|
|
92
|
+
const rows = await appDb.select().from(appState).where(eq(appState.key, KEY)).limit(1);
|
|
93
|
+
const merged = new Set();
|
|
94
|
+
try {
|
|
95
|
+
for (const id of JSON.parse(rows[0]?.value ?? '[]'))
|
|
96
|
+
merged.add(id);
|
|
97
|
+
}
|
|
98
|
+
catch {
|
|
99
|
+
// Unreadable list: start over with the new ids.
|
|
100
|
+
}
|
|
101
|
+
const sizeBefore = merged.size;
|
|
102
|
+
for (const id of additions)
|
|
103
|
+
merged.add(id);
|
|
104
|
+
if (merged.size === sizeBefore && rows.length > 0)
|
|
105
|
+
return;
|
|
106
|
+
const value = JSON.stringify([...merged]);
|
|
107
|
+
await appDb
|
|
108
|
+
.insert(appState)
|
|
109
|
+
.values({ key: KEY, value })
|
|
110
|
+
.onConflictDoUpdate({ target: appState.key, set: { value } });
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
var filesDownload = `(
|
|
115
|
+
${function () {
|
|
116
|
+
const identifyString = (str) => {
|
|
117
|
+
try {
|
|
118
|
+
JSON.parse(str);
|
|
119
|
+
return 'json';
|
|
120
|
+
}
|
|
121
|
+
catch (e) {
|
|
122
|
+
// Not JSON
|
|
123
|
+
}
|
|
124
|
+
if (!str) {
|
|
125
|
+
return;
|
|
126
|
+
}
|
|
127
|
+
if (str.trim().startsWith('<') && str.trim().endsWith('>')) {
|
|
128
|
+
return 'html';
|
|
129
|
+
}
|
|
130
|
+
// Simple markdown checks (very naive)
|
|
131
|
+
if (/^#{1,6}\s|^-{3,}|\*{3,}|^-{1,2}\s|\*\s/.test(str)) {
|
|
132
|
+
return 'markdown';
|
|
133
|
+
}
|
|
134
|
+
if (/^data:image\/[a-zA-Z]+;base64,[A-Za-z0-9+/]+={0,2}$/.test(str)) {
|
|
135
|
+
return 'base64';
|
|
136
|
+
}
|
|
137
|
+
// Default to plain text if unsure
|
|
138
|
+
return 'text';
|
|
139
|
+
};
|
|
140
|
+
const getMimeType = (base64) => {
|
|
141
|
+
if (!base64) {
|
|
142
|
+
return null;
|
|
143
|
+
}
|
|
144
|
+
const result = base64.match(/^data:([a-zA-Z0-9]+\/[a-zA-Z0-9-.+]+).*,/);
|
|
145
|
+
if (result && result.length > 1) {
|
|
146
|
+
return result[1];
|
|
147
|
+
}
|
|
148
|
+
else {
|
|
149
|
+
return null; // MIME type could not be determined
|
|
150
|
+
}
|
|
151
|
+
};
|
|
152
|
+
const getDataTypeFromString = (data) => {
|
|
153
|
+
const nonImageBase64Regex = /^(?!data:image\/(?:jpeg|png|gif|bmp|webp);base64,)[A-Za-z0-9+/=]+$/;
|
|
154
|
+
if (nonImageBase64Regex.test(data)) {
|
|
155
|
+
return 'base64';
|
|
156
|
+
}
|
|
157
|
+
// Regular expression for base64 (simple version, checking for base64 format)
|
|
158
|
+
const imageBase64Regex = /^data:image\/[a-zA-Z]+;base64,[A-Za-z0-9+/]+={0,2}$/;
|
|
159
|
+
if (imageBase64Regex.test(data)) {
|
|
160
|
+
return 'imageBase64';
|
|
161
|
+
}
|
|
162
|
+
// Regular expression for URL (simple version, checking for common URL format)
|
|
163
|
+
const urlRegex = /^(http:\/\/www\.|https:\/\/www\.|http:\/\/|https:\/\/)?[a-z0-9]+([\-\.]{1}[a-z0-9]+)*\.[a-z]{2,5}(:[0-9]{1,5})?(\/.*)?$/;
|
|
164
|
+
if (urlRegex.test(data)) {
|
|
165
|
+
return 'url';
|
|
166
|
+
}
|
|
167
|
+
return null;
|
|
168
|
+
};
|
|
169
|
+
const isBinary = (arrayBuffer) => {
|
|
170
|
+
const view = new Uint8Array(arrayBuffer);
|
|
171
|
+
let nonTextCount = 0;
|
|
172
|
+
const threshold = 0.2; // Adjust as needed (e.g., 20% non-text implies binary)
|
|
173
|
+
for (let i = 0; i < view.length; i++) {
|
|
174
|
+
const byte = view[i];
|
|
175
|
+
// ASCII printable characters (32-126) and common whitespace (9, 10, 13)
|
|
176
|
+
if ((byte >= 32 && byte <= 126) || // Printable ASCII
|
|
177
|
+
byte === 9 || byte === 10 || byte === 13 // Tab, LF, CR
|
|
178
|
+
) {
|
|
179
|
+
continue;
|
|
180
|
+
}
|
|
181
|
+
nonTextCount++;
|
|
182
|
+
if (nonTextCount / view.length > threshold) {
|
|
183
|
+
return true; // More than threshold are non-text bytes
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
return false; // Fewer than threshold are non-text bytes
|
|
187
|
+
};
|
|
188
|
+
const saveBufferToOPFS = async (filePath, buffer) => {
|
|
189
|
+
// Access the OPFS root directory
|
|
190
|
+
const rootHandle = await navigator.storage.getDirectory();
|
|
191
|
+
// Split the filePath into directory segments and file name
|
|
192
|
+
const segments = filePath.split('/').filter(Boolean);
|
|
193
|
+
const fileName = segments.pop(); // Extract the file name
|
|
194
|
+
if (!fileName) {
|
|
195
|
+
throw new Error('Invalid file path: No file name provided.');
|
|
196
|
+
}
|
|
197
|
+
// Traverse or create directories as needed
|
|
198
|
+
let currentDirHandle = rootHandle;
|
|
199
|
+
for (const segment of segments) {
|
|
200
|
+
currentDirHandle = await currentDirHandle.getDirectoryHandle(segment, { create: true });
|
|
201
|
+
}
|
|
202
|
+
// Create or open the file in OPFS
|
|
203
|
+
const fileHandleAsync = await currentDirHandle.getFileHandle(fileName, { create: true });
|
|
204
|
+
const write = async () => {
|
|
205
|
+
const fileHandle = await fileHandleAsync.createSyncAccessHandle();
|
|
206
|
+
try {
|
|
207
|
+
// Drop any previous, longer contents before writing from the start
|
|
208
|
+
fileHandle.truncate(0);
|
|
209
|
+
fileHandle.write(buffer, { at: 0 });
|
|
210
|
+
fileHandle.flush();
|
|
211
|
+
}
|
|
212
|
+
finally {
|
|
213
|
+
// A leaked handle keeps the file locked for the worker's lifetime
|
|
214
|
+
fileHandle.close();
|
|
215
|
+
}
|
|
216
|
+
};
|
|
217
|
+
// A sync access handle is exclusive: a download of the same file in another tab or worker would
|
|
218
|
+
// make createSyncAccessHandle throw, so writers of one path take turns.
|
|
219
|
+
if (navigator.locks) {
|
|
220
|
+
await navigator.locks.request(`seed:opfs-write:${filePath}`, write);
|
|
221
|
+
}
|
|
222
|
+
else {
|
|
223
|
+
await write();
|
|
224
|
+
}
|
|
225
|
+
// Written past ZenFS: the page refreshes its cache for this path and tells other tabs.
|
|
226
|
+
globalThis.postMessage({ message: 'fileSaved', filePath });
|
|
227
|
+
};
|
|
228
|
+
const getFilesPath = (filesRoot, ...parts) => {
|
|
229
|
+
const root = filesRoot.replace(/\/$/, '');
|
|
230
|
+
return [root, ...parts].filter(Boolean).join('/').replace(/\/+/g, '/');
|
|
231
|
+
};
|
|
232
|
+
const toBaseUrl = (hostOrUrl) => {
|
|
233
|
+
const h = (hostOrUrl || '').trim().replace(/\/$/, '');
|
|
234
|
+
if (!h)
|
|
235
|
+
return '';
|
|
236
|
+
if (h.startsWith('http://') || h.startsWith('https://'))
|
|
237
|
+
return h;
|
|
238
|
+
const protocol = h.startsWith('127.0.0.1') || h.startsWith('localhost') || h.includes(':1984')
|
|
239
|
+
? 'http'
|
|
240
|
+
: 'https';
|
|
241
|
+
return `${protocol}://${h}`;
|
|
242
|
+
};
|
|
243
|
+
/**
|
|
244
|
+
* GET /raw/{id} from each gateway in order. `networkFailedEverywhere` is true only when no gateway
|
|
245
|
+
* answered at all; a non-2xx (e.g. not yet propagated) is not a reason to exclude the transaction.
|
|
246
|
+
*/
|
|
247
|
+
const fetchRaw = async (baseUrls, transactionId) => {
|
|
248
|
+
let answered = false;
|
|
249
|
+
for (const base of baseUrls) {
|
|
250
|
+
try {
|
|
251
|
+
const response = await fetch(`${base}/raw/${transactionId}`);
|
|
252
|
+
answered = true;
|
|
253
|
+
if (!response.ok)
|
|
254
|
+
continue;
|
|
255
|
+
const arrayBuffer = await response.arrayBuffer();
|
|
256
|
+
if (arrayBuffer.byteLength > 0) {
|
|
257
|
+
return { arrayBuffer, networkFailedEverywhere: false };
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
catch (error) {
|
|
261
|
+
/* next gateway */
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
return { networkFailedEverywhere: !answered };
|
|
265
|
+
};
|
|
266
|
+
const downloadFiles = async ({ transactionIds, arweaveHost, arweaveBaseUrls, filesRoot = '/files', }) => {
|
|
267
|
+
// Preferred / resolved gateways first, then the configured host; deduped.
|
|
268
|
+
const baseUrls = [];
|
|
269
|
+
for (const candidate of (arweaveBaseUrls || []).concat([arweaveHost])) {
|
|
270
|
+
const base = toBaseUrl(candidate);
|
|
271
|
+
if (base && baseUrls.indexOf(base) === -1) {
|
|
272
|
+
baseUrls.push(base);
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
for (const transactionId of transactionIds) {
|
|
276
|
+
const { arrayBuffer, networkFailedEverywhere } = await fetchRaw(baseUrls, transactionId);
|
|
277
|
+
if (!arrayBuffer) {
|
|
278
|
+
if (networkFailedEverywhere) {
|
|
279
|
+
globalThis.postMessage({
|
|
280
|
+
message: 'excludeTransaction',
|
|
281
|
+
transactionId,
|
|
282
|
+
});
|
|
283
|
+
}
|
|
284
|
+
continue;
|
|
285
|
+
}
|
|
286
|
+
let dataString;
|
|
287
|
+
const isBinaryData = isBinary(arrayBuffer);
|
|
288
|
+
if (!isBinaryData) {
|
|
289
|
+
const decoder = new TextDecoder('utf-8');
|
|
290
|
+
const text = decoder.decode(arrayBuffer);
|
|
291
|
+
dataString = text;
|
|
292
|
+
}
|
|
293
|
+
if (dataString && dataString.startsWith('===FILE_SEPARATOR===')) {
|
|
294
|
+
const dataStringParts = dataString
|
|
295
|
+
.split('===FILE_SEPARATOR===')
|
|
296
|
+
.slice(1);
|
|
297
|
+
if (dataStringParts.length % 2 !== 0) {
|
|
298
|
+
throw new Error('Input array must have an even number of elements.');
|
|
299
|
+
}
|
|
300
|
+
for (let i = 0; i < dataStringParts.length; i += 2) {
|
|
301
|
+
const contentType = dataStringParts[i];
|
|
302
|
+
const content = dataStringParts[i + 1];
|
|
303
|
+
const encoder = new TextEncoder();
|
|
304
|
+
if (contentType === 'html') {
|
|
305
|
+
const fileName = `${transactionId}.html`;
|
|
306
|
+
const buffer = encoder.encode(content);
|
|
307
|
+
await saveBufferToOPFS(getFilesPath(filesRoot, 'html', fileName), buffer);
|
|
308
|
+
}
|
|
309
|
+
if (contentType === 'json') {
|
|
310
|
+
const fileName = `${transactionId}.json`;
|
|
311
|
+
const buffer = encoder.encode(content);
|
|
312
|
+
await saveBufferToOPFS(getFilesPath(filesRoot, 'json', fileName), buffer);
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
continue;
|
|
316
|
+
}
|
|
317
|
+
if (!dataString && arrayBuffer) {
|
|
318
|
+
await saveBufferToOPFS(getFilesPath(filesRoot, 'images', transactionId), new Uint8Array(arrayBuffer));
|
|
319
|
+
continue;
|
|
320
|
+
}
|
|
321
|
+
if (!dataString) {
|
|
322
|
+
continue;
|
|
323
|
+
}
|
|
324
|
+
let contentType = identifyString(dataString);
|
|
325
|
+
if (contentType !== 'json' &&
|
|
326
|
+
contentType !== 'base64' &&
|
|
327
|
+
contentType !== 'html') {
|
|
328
|
+
const possibleImageType = getDataTypeFromString(dataString);
|
|
329
|
+
if (!possibleImageType) {
|
|
330
|
+
continue;
|
|
331
|
+
}
|
|
332
|
+
contentType = possibleImageType;
|
|
333
|
+
}
|
|
334
|
+
if (contentType === 'url') {
|
|
335
|
+
const url = dataString;
|
|
336
|
+
let buffer;
|
|
337
|
+
try {
|
|
338
|
+
const response = await fetch(url);
|
|
339
|
+
if (!response.ok) {
|
|
340
|
+
continue;
|
|
341
|
+
}
|
|
342
|
+
buffer = await response.arrayBuffer();
|
|
343
|
+
}
|
|
344
|
+
catch (error) {
|
|
345
|
+
globalThis.postMessage({
|
|
346
|
+
message: 'excludeTransaction',
|
|
347
|
+
transactionId,
|
|
348
|
+
});
|
|
349
|
+
continue;
|
|
350
|
+
}
|
|
351
|
+
const bufferUint8Array = new Uint8Array(buffer);
|
|
352
|
+
// Extract the file extension from the URL
|
|
353
|
+
const extensionMatch = url.match(/\.(jpg|jpeg|png|gif|bmp|webp|svg)$/i);
|
|
354
|
+
if (!extensionMatch) {
|
|
355
|
+
throw new Error('Unable to determine the file extension from the URL.');
|
|
356
|
+
}
|
|
357
|
+
extensionMatch[0]; // e.g., ".jpg"
|
|
358
|
+
// Set the file name (you can customize this)
|
|
359
|
+
// const fileNameFromUrl = `${transactionId}${fileExtension}`
|
|
360
|
+
await saveBufferToOPFS(getFilesPath(filesRoot, 'images', transactionId), bufferUint8Array);
|
|
361
|
+
continue;
|
|
362
|
+
}
|
|
363
|
+
const mimeType = getMimeType(dataString);
|
|
364
|
+
let fileExtension = mimeType;
|
|
365
|
+
if (fileExtension && fileExtension?.startsWith('image')) {
|
|
366
|
+
fileExtension = fileExtension.replace('image/', '');
|
|
367
|
+
}
|
|
368
|
+
let fileName = transactionId;
|
|
369
|
+
if (contentType === 'base64') {
|
|
370
|
+
if (fileExtension) {
|
|
371
|
+
fileName += `.${fileExtension}`;
|
|
372
|
+
}
|
|
373
|
+
// Remove the Base64 header if it exists (e.g., "data:image/png;base64,")
|
|
374
|
+
const base64Data = dataString.split(',').pop() || '';
|
|
375
|
+
// Decode the Base64 string to binary
|
|
376
|
+
const binaryString = atob(base64Data);
|
|
377
|
+
const length = binaryString.length;
|
|
378
|
+
const binaryData = new Uint8Array(length);
|
|
379
|
+
for (let i = 0; i < length; i++) {
|
|
380
|
+
binaryData[i] = binaryString.charCodeAt(i);
|
|
381
|
+
}
|
|
382
|
+
await saveBufferToOPFS(getFilesPath(filesRoot, 'images', fileName), binaryData);
|
|
383
|
+
}
|
|
384
|
+
if (contentType === 'html') {
|
|
385
|
+
fileName += '.html';
|
|
386
|
+
const encoder = new TextEncoder();
|
|
387
|
+
const buffer = encoder.encode(dataString);
|
|
388
|
+
await saveBufferToOPFS(getFilesPath(filesRoot, 'html', fileName), buffer);
|
|
389
|
+
}
|
|
390
|
+
if (contentType === 'json') {
|
|
391
|
+
fileName += '.json';
|
|
392
|
+
const encoder = new TextEncoder();
|
|
393
|
+
const buffer = encoder.encode(dataString);
|
|
394
|
+
await saveBufferToOPFS(getFilesPath(filesRoot, 'json', fileName), buffer);
|
|
395
|
+
}
|
|
396
|
+
}
|
|
397
|
+
};
|
|
398
|
+
onmessage = async (e) => {
|
|
399
|
+
const { debug, filesRoot } = e.data;
|
|
400
|
+
if (!debug) {
|
|
401
|
+
console.log = () => { };
|
|
402
|
+
}
|
|
403
|
+
await downloadFiles({ ...e.data, filesRoot });
|
|
404
|
+
globalThis.postMessage({
|
|
405
|
+
message: 'filesDownload onmessage done',
|
|
406
|
+
done: true,
|
|
407
|
+
});
|
|
408
|
+
};
|
|
409
|
+
}.toString()}
|
|
410
|
+
)()`;
|
|
411
|
+
|
|
412
|
+
const logger$6 = debug('seedSdk:browser:workers:FileDownloader');
|
|
413
|
+
class FileDownloader {
|
|
414
|
+
constructor() {
|
|
415
|
+
this.workersArchive = [];
|
|
416
|
+
this.downloadAll = async ({ transactionIds, arweaveHost, arweaveBaseUrls, excludedTransactions }) => {
|
|
417
|
+
if (this.workersArchive.length > 0) {
|
|
418
|
+
for (let i = 0; i < this.workersArchive.length; i++) {
|
|
419
|
+
this.workersArchive[i].terminate();
|
|
420
|
+
delete this.workersArchive[i];
|
|
421
|
+
}
|
|
422
|
+
this.workersArchive = [];
|
|
423
|
+
}
|
|
424
|
+
const worker = new Worker(this.workerBlobUrl);
|
|
425
|
+
this.workersArchive.push(worker);
|
|
426
|
+
const localExcludedTransactions = new Set(excludedTransactions);
|
|
427
|
+
const savedPaths = [];
|
|
428
|
+
return new Promise((resolve, reject) => {
|
|
429
|
+
worker.onmessage = (e) => {
|
|
430
|
+
logger$6('filesDownload main thread onmessage', e.data);
|
|
431
|
+
if (e.data.message === 'excludeTransaction') {
|
|
432
|
+
localExcludedTransactions.add(e.data.transactionId);
|
|
433
|
+
}
|
|
434
|
+
if (e.data.message === 'fileSaved') {
|
|
435
|
+
savedPaths.push(e.data.filePath);
|
|
436
|
+
}
|
|
437
|
+
if (e.data.done) {
|
|
438
|
+
addExcludedTransactions(localExcludedTransactions)
|
|
439
|
+
// The worker wrote to OPFS directly; refresh caches here and in other tabs.
|
|
440
|
+
.then(() => notifyFilesWrittenOutsideCache(savedPaths))
|
|
441
|
+
.then(() => {
|
|
442
|
+
resolve(e.data);
|
|
443
|
+
})
|
|
444
|
+
.catch((error) => {
|
|
445
|
+
reject(error);
|
|
446
|
+
});
|
|
447
|
+
}
|
|
448
|
+
if (e.data.error) {
|
|
449
|
+
reject(e.data.error);
|
|
450
|
+
}
|
|
451
|
+
};
|
|
452
|
+
worker.postMessage({
|
|
453
|
+
transactionIds,
|
|
454
|
+
arweaveHost,
|
|
455
|
+
arweaveBaseUrls,
|
|
456
|
+
debug: logger$6.enabled,
|
|
457
|
+
filesRoot: BaseFileManager.getWorkingDir(),
|
|
458
|
+
});
|
|
459
|
+
});
|
|
460
|
+
};
|
|
461
|
+
this.cores = Math.min(navigator.hardwareConcurrency || 4, 4);
|
|
462
|
+
this.workerBlobUrl = globalThis.URL.createObjectURL(new Blob([filesDownload], { type: 'application/javascript' }));
|
|
463
|
+
}
|
|
464
|
+
}
|
|
465
|
+
|
|
466
|
+
var imageResize = `(
|
|
467
|
+
${function () {
|
|
468
|
+
const getFileHandle = async (path, rootHandle = null) => {
|
|
469
|
+
// Split the path into segments
|
|
470
|
+
const segments = path.split('/').filter(Boolean);
|
|
471
|
+
// Start from the root directory if not provided
|
|
472
|
+
if (!rootHandle) {
|
|
473
|
+
rootHandle = await navigator.storage.getDirectory();
|
|
474
|
+
}
|
|
475
|
+
let currentHandle = rootHandle;
|
|
476
|
+
// Traverse the path segments
|
|
477
|
+
for (let i = 0; i < segments.length; i++) {
|
|
478
|
+
const segment = segments[i];
|
|
479
|
+
const isLastSegment = i === segments.length - 1;
|
|
480
|
+
try {
|
|
481
|
+
for await (const [name, handle] of currentHandle.entries()) {
|
|
482
|
+
if (name !== segment) {
|
|
483
|
+
continue;
|
|
484
|
+
}
|
|
485
|
+
if (isLastSegment) {
|
|
486
|
+
if (handle.kind === 'file') {
|
|
487
|
+
return handle; // Return the file handle if found
|
|
488
|
+
}
|
|
489
|
+
else {
|
|
490
|
+
throw new Error(`Path '${path}' refers to a directory, not a file.`);
|
|
491
|
+
}
|
|
492
|
+
}
|
|
493
|
+
else if (handle.kind === 'directory') {
|
|
494
|
+
currentHandle = handle; // Traverse into the directory
|
|
495
|
+
}
|
|
496
|
+
else {
|
|
497
|
+
throw new Error(`Invalid path segment '${segment}'`);
|
|
498
|
+
}
|
|
499
|
+
}
|
|
500
|
+
}
|
|
501
|
+
catch (err) {
|
|
502
|
+
if (err instanceof Error && err.name === 'NotFoundError') {
|
|
503
|
+
throw new Error(`Path '${path}' does not exist.`);
|
|
504
|
+
}
|
|
505
|
+
else {
|
|
506
|
+
throw err;
|
|
507
|
+
}
|
|
508
|
+
}
|
|
509
|
+
}
|
|
510
|
+
throw new Error(`Path '${path}' could not be resolved.`);
|
|
511
|
+
};
|
|
512
|
+
async function getFileFromOPFS(path) {
|
|
513
|
+
const fileHandleAsync = await getFileHandle(path);
|
|
514
|
+
const file = await fileHandleAsync.getFile();
|
|
515
|
+
return file;
|
|
516
|
+
}
|
|
517
|
+
/** Infer MIME from magic bytes. OPFS File may have empty type, causing createImageBitmap to fail. */
|
|
518
|
+
async function getBlobWithInferredMime(file) {
|
|
519
|
+
const buf = await file.arrayBuffer();
|
|
520
|
+
const bytes = new Uint8Array(buf);
|
|
521
|
+
let mime = file.type;
|
|
522
|
+
if (!mime || mime === '') {
|
|
523
|
+
if (bytes[0] === 0xff && bytes[1] === 0xd8)
|
|
524
|
+
mime = 'image/jpeg';
|
|
525
|
+
else if (bytes[0] === 0x89 && bytes[1] === 0x50 && bytes[2] === 0x4e && bytes[3] === 0x47)
|
|
526
|
+
mime = 'image/png';
|
|
527
|
+
else if (bytes[0] === 0x52 && bytes[1] === 0x49 && bytes[2] === 0x46 && bytes[3] === 0x52 && bytes[8] === 0x57 && bytes[9] === 0x45 && bytes[10] === 0x42 && bytes[11] === 0x50)
|
|
528
|
+
mime = 'image/webp';
|
|
529
|
+
else if (bytes[0] === 0x47 && bytes[1] === 0x49 && bytes[2] === 0x46)
|
|
530
|
+
mime = 'image/gif';
|
|
531
|
+
else if (bytes[0] === 0x42 && bytes[1] === 0x4d)
|
|
532
|
+
mime = 'image/bmp';
|
|
533
|
+
else if (bytes[4] === 0x66 && bytes[5] === 0x74 && bytes[6] === 0x79 && bytes[7] === 0x70 && bytes[8] === 0x61 && bytes[9] === 0x76 && bytes[10] === 0x69 && bytes[11] === 0x66)
|
|
534
|
+
mime = 'image/avif';
|
|
535
|
+
else if (bytes[4] === 0x66 && bytes[5] === 0x74 && bytes[6] === 0x79 && bytes[7] === 0x70 && bytes[8] === 0x68 && bytes[9] === 0x65 && bytes[10] === 0x69 && bytes[11] === 0x63)
|
|
536
|
+
mime = 'image/heic';
|
|
537
|
+
else
|
|
538
|
+
mime = 'image/jpeg';
|
|
539
|
+
}
|
|
540
|
+
return new Blob([buf], { type: mime });
|
|
541
|
+
}
|
|
542
|
+
const DEFAULT_CONFIG = {
|
|
543
|
+
argorithm: 'null',
|
|
544
|
+
processByHalf: true,
|
|
545
|
+
quality: 0.5,
|
|
546
|
+
maxWidth: 800,
|
|
547
|
+
maxHeight: 600,
|
|
548
|
+
debug: false,
|
|
549
|
+
mimeType: 'image/jpeg',
|
|
550
|
+
};
|
|
551
|
+
function isIos() {
|
|
552
|
+
if (typeof navigator === 'undefined')
|
|
553
|
+
return false;
|
|
554
|
+
if (!navigator.userAgent)
|
|
555
|
+
return false;
|
|
556
|
+
return /iPad|iPhone|iPod/.test(navigator.userAgent);
|
|
557
|
+
}
|
|
558
|
+
const getTargetHeight = (srcHeight, scale, config) => {
|
|
559
|
+
return Math.min(Math.floor(srcHeight * scale), config.maxHeight);
|
|
560
|
+
};
|
|
561
|
+
const findMaxWidth = (config, canvas) => {
|
|
562
|
+
//Let's find the max available width for scaled image
|
|
563
|
+
const ratio = canvas.width / canvas.height;
|
|
564
|
+
let mWidth = Math.min(canvas.width, config.maxWidth, ratio * config.maxHeight);
|
|
565
|
+
if (config.maxSize &&
|
|
566
|
+
config.maxSize > 0 &&
|
|
567
|
+
config.maxSize < (canvas.width * canvas.height) / 1000)
|
|
568
|
+
mWidth = Math.min(mWidth, Math.floor((config.maxSize * 1000) / canvas.height));
|
|
569
|
+
if (!!config.scaleRatio)
|
|
570
|
+
mWidth = Math.min(mWidth, Math.floor(config.scaleRatio * canvas.width));
|
|
571
|
+
const rHeight = getTargetHeight(canvas.height, mWidth / canvas.width, config);
|
|
572
|
+
// console.log(
|
|
573
|
+
// 'browser-image-resizer: original image size = ' +
|
|
574
|
+
// canvas.width +
|
|
575
|
+
// ' px (width) X ' +
|
|
576
|
+
// canvas.height +
|
|
577
|
+
// ' px (height)'
|
|
578
|
+
// );
|
|
579
|
+
// console.log(
|
|
580
|
+
// 'browser-image-resizer: scaled image size = ' +
|
|
581
|
+
// mWidth +
|
|
582
|
+
// ' px (width) X ' +
|
|
583
|
+
// rHeight +
|
|
584
|
+
// ' px (height)'
|
|
585
|
+
// );
|
|
586
|
+
if (mWidth <= 0) {
|
|
587
|
+
mWidth = 1;
|
|
588
|
+
console.warn("browser-image-resizer: image size is too small");
|
|
589
|
+
}
|
|
590
|
+
if (isIos() && mWidth * rHeight > 167777216) {
|
|
591
|
+
console.error("browser-image-resizer: image size is too large for iOS WebKit.", mWidth, rHeight);
|
|
592
|
+
throw new Error("browser-image-resizer: image size is too large for iOS WebKit.");
|
|
593
|
+
}
|
|
594
|
+
return mWidth;
|
|
595
|
+
};
|
|
596
|
+
/**
|
|
597
|
+
* Hermite resize, multicore version - fast image resize/resample using Hermite filter.
|
|
598
|
+
*/
|
|
599
|
+
const resample = (srcCanvas, destCanvas, config) => {
|
|
600
|
+
return new Promise((resolve, reject) => {
|
|
601
|
+
const ratio_h = srcCanvas.height / destCanvas.height;
|
|
602
|
+
const cores = Math.min(navigator.hardwareConcurrency || 4, 4);
|
|
603
|
+
//prepare source and target data for workers
|
|
604
|
+
const ctx = srcCanvas.getContext('2d');
|
|
605
|
+
if (!ctx)
|
|
606
|
+
return reject('Canvas is empty (resample)');
|
|
607
|
+
const data_part = [];
|
|
608
|
+
const block_height = Math.ceil(srcCanvas.height / cores / 2) * 2;
|
|
609
|
+
let end_y = -1;
|
|
610
|
+
for (let c = 0; c < cores; c++) {
|
|
611
|
+
//source
|
|
612
|
+
const offset_y = end_y + 1;
|
|
613
|
+
if (offset_y >= srcCanvas.height) {
|
|
614
|
+
//size too small, nothing left for this core
|
|
615
|
+
continue;
|
|
616
|
+
}
|
|
617
|
+
end_y = Math.min(offset_y + block_height - 1, srcCanvas.height - 1);
|
|
618
|
+
const current_block_height = Math.min(block_height, srcCanvas.height - offset_y);
|
|
619
|
+
data_part.push({
|
|
620
|
+
source: ctx.getImageData(0, offset_y, srcCanvas.width, block_height),
|
|
621
|
+
startY: Math.ceil(offset_y / ratio_h),
|
|
622
|
+
height: current_block_height
|
|
623
|
+
});
|
|
624
|
+
}
|
|
625
|
+
//start
|
|
626
|
+
const destCtx = destCanvas.getContext('2d');
|
|
627
|
+
if (!destCtx)
|
|
628
|
+
return reject('Canvas is empty (resample dest)');
|
|
629
|
+
for (let c = 0; c < data_part.length; c++) {
|
|
630
|
+
//draw
|
|
631
|
+
const height_part = Math.ceil(data_part[c].height / ratio_h);
|
|
632
|
+
const target = destCtx.createImageData(destCanvas.width, height_part);
|
|
633
|
+
// target.data.set(event.data.target);
|
|
634
|
+
destCtx.putImageData(target, 0, data_part[c].startY);
|
|
635
|
+
}
|
|
636
|
+
});
|
|
637
|
+
};
|
|
638
|
+
/**
|
|
639
|
+
* Hermite resize - fast image resize/resample using Hermite filter. 1 cpu version!
|
|
640
|
+
*/
|
|
641
|
+
const resampleSingle = (srcCanvasData, destCanvasData) => {
|
|
642
|
+
const ratio_w = srcCanvasData.width / destCanvasData.width;
|
|
643
|
+
const ratio_h = srcCanvasData.height / destCanvasData.height;
|
|
644
|
+
const ratio_w_half = Math.ceil(ratio_w / 2);
|
|
645
|
+
const ratio_h_half = Math.ceil(ratio_h / 2);
|
|
646
|
+
const data = srcCanvasData.data;
|
|
647
|
+
const data2 = destCanvasData.data;
|
|
648
|
+
for (let j = 0; j < destCanvasData.height; j++) {
|
|
649
|
+
for (let i = 0; i < destCanvasData.width; i++) {
|
|
650
|
+
const x2 = (i + j * destCanvasData.width) * 4;
|
|
651
|
+
let weight = 0;
|
|
652
|
+
let weights = 0;
|
|
653
|
+
let weights_alpha = 0;
|
|
654
|
+
let gx_r = 0;
|
|
655
|
+
let gx_g = 0;
|
|
656
|
+
let gx_b = 0;
|
|
657
|
+
let gx_a = 0;
|
|
658
|
+
const center_y = j * ratio_h;
|
|
659
|
+
const xx_start = Math.floor(i * ratio_w);
|
|
660
|
+
const xx_stop = Math.min(Math.ceil((i + 1) * ratio_w), srcCanvasData.width);
|
|
661
|
+
const yy_start = Math.floor(j * ratio_h);
|
|
662
|
+
const yy_stop = Math.min(Math.ceil((j + 1) * ratio_h), srcCanvasData.height);
|
|
663
|
+
for (let yy = yy_start; yy < yy_stop; yy++) {
|
|
664
|
+
let dy = Math.abs(center_y - yy) / ratio_h_half;
|
|
665
|
+
let center_x = i * ratio_w;
|
|
666
|
+
let w0 = dy * dy; //pre-calc part of w
|
|
667
|
+
for (let xx = xx_start; xx < xx_stop; xx++) {
|
|
668
|
+
let dx = Math.abs(center_x - xx) / ratio_w_half;
|
|
669
|
+
let w = Math.sqrt(w0 + dx * dx);
|
|
670
|
+
if (w >= 1) {
|
|
671
|
+
//pixel too far
|
|
672
|
+
continue;
|
|
673
|
+
}
|
|
674
|
+
//hermite filter
|
|
675
|
+
weight = 2 * w * w * w - 3 * w * w + 1;
|
|
676
|
+
let pos_x = 4 * (xx + yy * srcCanvasData.width);
|
|
677
|
+
//alpha
|
|
678
|
+
gx_a += weight * data[pos_x + 3];
|
|
679
|
+
weights_alpha += weight;
|
|
680
|
+
//colors
|
|
681
|
+
if (data[pos_x + 3] < 255)
|
|
682
|
+
weight = weight * data[pos_x + 3] / 250;
|
|
683
|
+
gx_r += weight * data[pos_x];
|
|
684
|
+
gx_g += weight * data[pos_x + 1];
|
|
685
|
+
gx_b += weight * data[pos_x + 2];
|
|
686
|
+
weights += weight;
|
|
687
|
+
}
|
|
688
|
+
}
|
|
689
|
+
data2[x2] = gx_r / weights;
|
|
690
|
+
data2[x2 + 1] = gx_g / weights;
|
|
691
|
+
data2[x2 + 2] = gx_b / weights;
|
|
692
|
+
data2[x2 + 3] = gx_a / weights_alpha;
|
|
693
|
+
}
|
|
694
|
+
}
|
|
695
|
+
};
|
|
696
|
+
/**
|
|
697
|
+
* Hermite resize. Detect cpu count and use best option for user.
|
|
698
|
+
*/
|
|
699
|
+
const resampleAuto = (srcCanvas, destCanvas, config) => {
|
|
700
|
+
if (!!globalThis.Worker && navigator.hardwareConcurrency > 1 && config?.argorithm !== 'hermite_single') {
|
|
701
|
+
//workers supported and we have at least 2 cpu cores - using multithreading
|
|
702
|
+
return resample(srcCanvas, destCanvas);
|
|
703
|
+
}
|
|
704
|
+
else {
|
|
705
|
+
//1 cpu version
|
|
706
|
+
const { srcImgData, destImgData } = getImageData(srcCanvas, destCanvas);
|
|
707
|
+
resampleSingle(srcImgData, destImgData);
|
|
708
|
+
destCanvas.getContext('2d').putImageData(destImgData, 0, 0);
|
|
709
|
+
return;
|
|
710
|
+
}
|
|
711
|
+
};
|
|
712
|
+
async function scaleCanvasWithAlgorithm(canvas, config) {
|
|
713
|
+
const scale = config.outputWidth / canvas.width;
|
|
714
|
+
const scaled = new OffscreenCanvas(Math.floor(config.outputWidth), getTargetHeight(canvas.height, scale, config));
|
|
715
|
+
switch (config.algorithm) {
|
|
716
|
+
case 'hermite': {
|
|
717
|
+
await resampleAuto(canvas, scaled, config);
|
|
718
|
+
break;
|
|
719
|
+
}
|
|
720
|
+
case 'hermite_single': {
|
|
721
|
+
const { srcImgData, destImgData } = getImageData(canvas, scaled);
|
|
722
|
+
resampleSingle(srcImgData, destImgData);
|
|
723
|
+
scaled?.getContext('2d')?.putImageData(destImgData, 0, 0);
|
|
724
|
+
break;
|
|
725
|
+
}
|
|
726
|
+
case 'bilinear': {
|
|
727
|
+
// const { srcImgData, destImgData } = getImageData(canvas, scaled);
|
|
728
|
+
// bilinear(srcImgData, destImgData, scale);
|
|
729
|
+
// scaled?.getContext('2d')?.putImageData(destImgData, 0, 0);
|
|
730
|
+
break;
|
|
731
|
+
}
|
|
732
|
+
default: {
|
|
733
|
+
scaled.getContext('2d')?.drawImage(canvas, 0, 0, scaled.width, scaled.height);
|
|
734
|
+
break;
|
|
735
|
+
}
|
|
736
|
+
}
|
|
737
|
+
return scaled;
|
|
738
|
+
}
|
|
739
|
+
const getHalfScaleCanvas = (src) => {
|
|
740
|
+
const half = new OffscreenCanvas(src.width / 2, src.height / 2);
|
|
741
|
+
half
|
|
742
|
+
?.getContext('2d')
|
|
743
|
+
?.drawImage(src, 0, 0, half.width, half.height);
|
|
744
|
+
return half;
|
|
745
|
+
};
|
|
746
|
+
const getImageData = (canvas, scaled) => {
|
|
747
|
+
const srcImgData = canvas
|
|
748
|
+
?.getContext('2d')
|
|
749
|
+
?.getImageData(0, 0, canvas.width, canvas.height);
|
|
750
|
+
const destImgData = scaled
|
|
751
|
+
?.getContext('2d')
|
|
752
|
+
?.createImageData(scaled.width, scaled.height);
|
|
753
|
+
if (!srcImgData || !destImgData)
|
|
754
|
+
throw Error('Canvas is empty (scaleCanvasWithAlgorithm). You should run this script after the document is ready.');
|
|
755
|
+
return { srcImgData, destImgData };
|
|
756
|
+
};
|
|
757
|
+
async function saveBlobToOPFS(filePath, blob) {
|
|
758
|
+
// Access the OPFS root directory
|
|
759
|
+
const rootHandle = await navigator.storage.getDirectory();
|
|
760
|
+
// Split the filePath into directory segments and file name
|
|
761
|
+
const segments = filePath.split('/').filter(Boolean);
|
|
762
|
+
const fileName = segments.pop(); // Extract the file name
|
|
763
|
+
if (!fileName) {
|
|
764
|
+
throw new Error('Invalid file path: No file name provided.');
|
|
765
|
+
}
|
|
766
|
+
// Traverse or create directories as needed
|
|
767
|
+
let currentDirHandle = rootHandle;
|
|
768
|
+
for (const segment of segments) {
|
|
769
|
+
currentDirHandle = await currentDirHandle.getDirectoryHandle(segment, { create: true });
|
|
770
|
+
}
|
|
771
|
+
// Create or open the file in OPFS
|
|
772
|
+
const fileHandle = await currentDirHandle.getFileHandle(fileName, { create: true });
|
|
773
|
+
// Write the Blob to the file
|
|
774
|
+
const writableStream = await fileHandle.createWritable();
|
|
775
|
+
try {
|
|
776
|
+
await writableStream.write(blob);
|
|
777
|
+
}
|
|
778
|
+
catch (error) {
|
|
779
|
+
// Discard the partial write and release the file's lock
|
|
780
|
+
await writableStream.abort().catch(() => { });
|
|
781
|
+
throw error;
|
|
782
|
+
}
|
|
783
|
+
await writableStream.close();
|
|
784
|
+
}
|
|
785
|
+
const imageResize = async (filePath, width, height) => {
|
|
786
|
+
const config = {
|
|
787
|
+
...DEFAULT_CONFIG,
|
|
788
|
+
algorithm: 'hermite_single',
|
|
789
|
+
mimeType: 'image/webp',
|
|
790
|
+
maxWidth: width,
|
|
791
|
+
maxHeight: height,
|
|
792
|
+
};
|
|
793
|
+
const file = await getFileFromOPFS(filePath);
|
|
794
|
+
const blobWithMime = await getBlobWithInferredMime(file);
|
|
795
|
+
const imageBitmap = await createImageBitmap(blobWithMime);
|
|
796
|
+
let converting;
|
|
797
|
+
if (isIos() && imageBitmap.width * imageBitmap.height > 16777216) {
|
|
798
|
+
const scale = Math.sqrt(16777216 / (imageBitmap.width * imageBitmap.height));
|
|
799
|
+
converting = new OffscreenCanvas(Math.floor(imageBitmap.width * scale), Math.floor(imageBitmap.height * scale));
|
|
800
|
+
converting.getContext('2d')?.drawImage(imageBitmap, 0, 0, converting.width, converting.height);
|
|
801
|
+
}
|
|
802
|
+
else {
|
|
803
|
+
converting = new OffscreenCanvas(imageBitmap.width, imageBitmap.height);
|
|
804
|
+
converting.getContext('2d')?.drawImage(imageBitmap, 0, 0);
|
|
805
|
+
}
|
|
806
|
+
const maxWidth = findMaxWidth(config, converting);
|
|
807
|
+
if (!maxWidth) {
|
|
808
|
+
throw Error(`browser-image-resizer: maxWidth is ${maxWidth}!!`);
|
|
809
|
+
}
|
|
810
|
+
while (config.processByHalf && converting.width >= 2 * maxWidth) {
|
|
811
|
+
converting = getHalfScaleCanvas(converting);
|
|
812
|
+
}
|
|
813
|
+
if (converting.width > maxWidth) {
|
|
814
|
+
converting = await scaleCanvasWithAlgorithm(converting, Object.assign(config, { outputWidth: maxWidth }));
|
|
815
|
+
}
|
|
816
|
+
if (config.mimeType === null) {
|
|
817
|
+
return converting;
|
|
818
|
+
}
|
|
819
|
+
const resizedBlob = await converting.convertToBlob({ type: config.mimeType, quality: config.quality });
|
|
820
|
+
const pathSegments = filePath.split('/');
|
|
821
|
+
const fileName = pathSegments.pop();
|
|
822
|
+
if (!fileName) {
|
|
823
|
+
throw Error('Invalid file path: No file name provided.');
|
|
824
|
+
}
|
|
825
|
+
const newSegments = [
|
|
826
|
+
...pathSegments,
|
|
827
|
+
width,
|
|
828
|
+
];
|
|
829
|
+
const fileNameParts = fileName.split('.');
|
|
830
|
+
const newFileName = `${fileNameParts[0]}.webp`;
|
|
831
|
+
const newDirPath = newSegments.join('/');
|
|
832
|
+
const newFilePath = `${newDirPath}/${newFileName}`;
|
|
833
|
+
await saveBlobToOPFS(newFilePath, resizedBlob);
|
|
834
|
+
globalThis.postMessage({
|
|
835
|
+
done: true,
|
|
836
|
+
filePath: newFilePath,
|
|
837
|
+
});
|
|
838
|
+
};
|
|
839
|
+
onmessage = async (e) => {
|
|
840
|
+
const { filePath, width, height, debug } = e.data;
|
|
841
|
+
if (!debug) {
|
|
842
|
+
console.log = () => { };
|
|
843
|
+
}
|
|
844
|
+
try {
|
|
845
|
+
await imageResize(filePath, width, height);
|
|
846
|
+
}
|
|
847
|
+
catch (err) {
|
|
848
|
+
globalThis.postMessage({ error: err instanceof Error ? err.message : String(err) });
|
|
849
|
+
}
|
|
850
|
+
};
|
|
851
|
+
}.toString()}
|
|
852
|
+
)()`;
|
|
853
|
+
|
|
854
|
+
const logger$5 = debug('seedSdk:browser:workers:ImageResizer');
|
|
855
|
+
class ImageResizer {
|
|
856
|
+
constructor() {
|
|
857
|
+
this.workersArchive = new Map();
|
|
858
|
+
this.cores = Math.min(navigator.hardwareConcurrency || 4, 4);
|
|
859
|
+
this.workerBlobUrl = globalThis.URL.createObjectURL(new Blob([imageResize], { type: 'application/javascript' }));
|
|
860
|
+
}
|
|
861
|
+
async resize({ filePath, width, height }) {
|
|
862
|
+
if (this.workersArchive.has(filePath)) {
|
|
863
|
+
const savedWorker = this.workersArchive.get(filePath);
|
|
864
|
+
savedWorker?.terminate();
|
|
865
|
+
logger$5('[ImageResizer.resize] Terminated worker for filePath due to incoming request', filePath);
|
|
866
|
+
this.workersArchive.delete(filePath);
|
|
867
|
+
}
|
|
868
|
+
const worker = new Worker(this.workerBlobUrl);
|
|
869
|
+
this.workersArchive.set(filePath, worker);
|
|
870
|
+
return new Promise((resolve, reject) => {
|
|
871
|
+
worker.onmessage = (e) => {
|
|
872
|
+
logger$5('[ImageResizer.resize] main thread onmessage', e.data);
|
|
873
|
+
if (e.data.done) {
|
|
874
|
+
const savedWorker = this.workersArchive.get(filePath);
|
|
875
|
+
savedWorker?.terminate();
|
|
876
|
+
logger$5('[ImageResizer.resize] Terminated worker for filePath due to done', filePath);
|
|
877
|
+
this.workersArchive.delete(filePath);
|
|
878
|
+
// The worker wrote the variant to OPFS directly; refresh caches here and in other tabs.
|
|
879
|
+
notifyFilesWrittenOutsideCache([e.data.filePath]).then(() => resolve(e.data), () => resolve(e.data));
|
|
880
|
+
}
|
|
881
|
+
if (e.data.error) {
|
|
882
|
+
reject(e.data.error);
|
|
883
|
+
}
|
|
884
|
+
};
|
|
885
|
+
worker.onerror = (err) => {
|
|
886
|
+
reject(err);
|
|
887
|
+
};
|
|
888
|
+
worker.postMessage({
|
|
889
|
+
filePath,
|
|
890
|
+
width,
|
|
891
|
+
height,
|
|
892
|
+
debug: logger$5.enabled,
|
|
893
|
+
});
|
|
894
|
+
});
|
|
895
|
+
}
|
|
896
|
+
async resizeAll({ width, height }) {
|
|
897
|
+
const fs = await BaseFileManager.getFs();
|
|
898
|
+
const imageDir = BaseFileManager.getFilesPath('images');
|
|
899
|
+
let imageFilesStats = await fs.promises.readdir(imageDir, {
|
|
900
|
+
withFileTypes: true
|
|
901
|
+
});
|
|
902
|
+
imageFilesStats = imageFilesStats.filter((file) => file.isFile());
|
|
903
|
+
const imageFiles = imageFilesStats.map((file) => file.path);
|
|
904
|
+
const widthDir = `${imageDir}/${width}`;
|
|
905
|
+
await BaseFileManager.createDirIfNotExists(widthDir);
|
|
906
|
+
for (const imageFile of imageFiles) {
|
|
907
|
+
const resizedImageExists = await BaseFileManager.pathExists(`${widthDir}/${imageFile}`);
|
|
908
|
+
if (!resizedImageExists) {
|
|
909
|
+
await this.resize({ filePath: `${imageDir}/${imageFile}`, width, height });
|
|
910
|
+
}
|
|
911
|
+
}
|
|
912
|
+
}
|
|
913
|
+
}
|
|
914
|
+
|
|
915
|
+
/**
|
|
916
|
+
* Errors Chromium throws for a single OPFS entry that another context is using: the entry was
|
|
917
|
+
* removed between listing and reading (SQLite journals come and go per transaction), or it is
|
|
918
|
+
* held by a sync access handle in another tab or a not-yet-terminated worker.
|
|
919
|
+
*/
|
|
920
|
+
const SKIPPABLE_ENTRY_ERRORS = new Set([
|
|
921
|
+
'NotFoundError',
|
|
922
|
+
'InvalidStateError',
|
|
923
|
+
'NoModificationAllowedError',
|
|
924
|
+
'NotReadableError',
|
|
925
|
+
]);
|
|
926
|
+
function isSkippableOpfsEntryError(error) {
|
|
927
|
+
return error instanceof DOMException && SKIPPABLE_ENTRY_ERRORS.has(error.name);
|
|
928
|
+
}
|
|
929
|
+
|
|
930
|
+
const logger$4 = debug('seedSdk:browser:helpers:FileManager');
|
|
931
|
+
/**
|
|
932
|
+
* Browser-safe path helpers for SDK virtual file paths.
|
|
933
|
+
* We intentionally avoid Node/CJS path polyfills here to keep browser bundles ESM-safe.
|
|
934
|
+
* Provides the subset of Node path APIs used via BaseFileManager.getPathModule().
|
|
935
|
+
*/
|
|
936
|
+
const pathCompat = {
|
|
937
|
+
dirname(filePath) {
|
|
938
|
+
if (!filePath)
|
|
939
|
+
return '.';
|
|
940
|
+
const normalized = filePath.replace(/\\/g, '/');
|
|
941
|
+
if (normalized === '/')
|
|
942
|
+
return '/';
|
|
943
|
+
const trimmed = normalized.endsWith('/') && normalized.length > 1
|
|
944
|
+
? normalized.slice(0, -1)
|
|
945
|
+
: normalized;
|
|
946
|
+
const lastSlash = trimmed.lastIndexOf('/');
|
|
947
|
+
if (lastSlash === -1)
|
|
948
|
+
return '.';
|
|
949
|
+
if (lastSlash === 0)
|
|
950
|
+
return '/';
|
|
951
|
+
return trimmed.slice(0, lastSlash);
|
|
952
|
+
},
|
|
953
|
+
basename(filePath) {
|
|
954
|
+
if (!filePath)
|
|
955
|
+
return '';
|
|
956
|
+
const normalized = filePath.replace(/\\/g, '/');
|
|
957
|
+
if (normalized === '/')
|
|
958
|
+
return '/';
|
|
959
|
+
const trimmed = normalized.endsWith('/') && normalized.length > 1
|
|
960
|
+
? normalized.slice(0, -1)
|
|
961
|
+
: normalized;
|
|
962
|
+
const lastSlash = trimmed.lastIndexOf('/');
|
|
963
|
+
return lastSlash === -1 ? trimmed : trimmed.slice(lastSlash + 1);
|
|
964
|
+
},
|
|
965
|
+
isAbsolute(filePath) {
|
|
966
|
+
if (!filePath)
|
|
967
|
+
return false;
|
|
968
|
+
const normalized = filePath.replace(/\\/g, '/');
|
|
969
|
+
return normalized.startsWith('/');
|
|
970
|
+
},
|
|
971
|
+
join(...segments) {
|
|
972
|
+
if (segments.length === 0)
|
|
973
|
+
return '.';
|
|
974
|
+
const joined = segments
|
|
975
|
+
.filter((s) => s != null && s !== '')
|
|
976
|
+
.map((s) => String(s).replace(/\\/g, '/'))
|
|
977
|
+
.join('/');
|
|
978
|
+
return pathCompat.normalize(joined);
|
|
979
|
+
},
|
|
980
|
+
resolve(...segments) {
|
|
981
|
+
// POSIX-like resolve for virtual paths: walk right-to-left until absolute.
|
|
982
|
+
let resolved = '';
|
|
983
|
+
let absolute = false;
|
|
984
|
+
for (let i = segments.length - 1; i >= 0 && !absolute; i--) {
|
|
985
|
+
const segment = segments[i];
|
|
986
|
+
if (segment == null || segment === '')
|
|
987
|
+
continue;
|
|
988
|
+
const normalized = String(segment).replace(/\\/g, '/');
|
|
989
|
+
resolved = resolved ? `${normalized}/${resolved}` : normalized;
|
|
990
|
+
absolute = pathCompat.isAbsolute(normalized);
|
|
991
|
+
}
|
|
992
|
+
// Browser has no process.cwd(); treat unresolved relative paths as root-relative.
|
|
993
|
+
if (!absolute) {
|
|
994
|
+
resolved = `/${resolved}`;
|
|
995
|
+
}
|
|
996
|
+
return pathCompat.normalize(resolved);
|
|
997
|
+
},
|
|
998
|
+
normalize(filePath) {
|
|
999
|
+
if (!filePath)
|
|
1000
|
+
return '.';
|
|
1001
|
+
const normalized = filePath.replace(/\\/g, '/');
|
|
1002
|
+
const absolute = normalized.startsWith('/');
|
|
1003
|
+
const parts = normalized.split('/');
|
|
1004
|
+
const stack = [];
|
|
1005
|
+
for (const part of parts) {
|
|
1006
|
+
if (!part || part === '.')
|
|
1007
|
+
continue;
|
|
1008
|
+
if (part === '..') {
|
|
1009
|
+
if (stack.length > 0 && stack[stack.length - 1] !== '..') {
|
|
1010
|
+
stack.pop();
|
|
1011
|
+
}
|
|
1012
|
+
else if (!absolute) {
|
|
1013
|
+
stack.push('..');
|
|
1014
|
+
}
|
|
1015
|
+
continue;
|
|
1016
|
+
}
|
|
1017
|
+
stack.push(part);
|
|
1018
|
+
}
|
|
1019
|
+
const result = stack.join('/');
|
|
1020
|
+
if (absolute)
|
|
1021
|
+
return `/${result}`;
|
|
1022
|
+
return result || '.';
|
|
1023
|
+
},
|
|
1024
|
+
};
|
|
1025
|
+
/**
|
|
1026
|
+
* Chromium OPFS: the mount walk hit an entry another context is using (reload, other tab,
|
|
1027
|
+
* leftover sync access handle, a SQLite journal removed mid-walk).
|
|
1028
|
+
*/
|
|
1029
|
+
function isBusyOpfsMountError(error) {
|
|
1030
|
+
if (isSkippableOpfsEntryError(error)) {
|
|
1031
|
+
return true;
|
|
1032
|
+
}
|
|
1033
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
1034
|
+
return message.includes('state cached in an interface object');
|
|
1035
|
+
}
|
|
1036
|
+
/** Waits between mount attempts; about 2 s in total. */
|
|
1037
|
+
const MOUNT_RETRY_DELAYS_MS = [50, 150, 300, 600, 1000];
|
|
1038
|
+
/** OPFS / ZenFS can throw NotReadableError while a file is still settling after write. */
|
|
1039
|
+
function isTransientOpfsReadError(error) {
|
|
1040
|
+
if (error instanceof DOMException && error.name === 'NotReadableError') {
|
|
1041
|
+
return true;
|
|
1042
|
+
}
|
|
1043
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
1044
|
+
// Chromium wording when getFile/read races a writer or stale handle
|
|
1045
|
+
if (message.includes('permission problems') && message.includes('reference')) {
|
|
1046
|
+
return true;
|
|
1047
|
+
}
|
|
1048
|
+
return false;
|
|
1049
|
+
}
|
|
1050
|
+
function sleep(ms) {
|
|
1051
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
1052
|
+
}
|
|
1053
|
+
class BrowserFileManager {
|
|
1054
|
+
constructor() {
|
|
1055
|
+
this.zenfsCache = null;
|
|
1056
|
+
}
|
|
1057
|
+
async getFs() {
|
|
1058
|
+
if (!this.zenfsCache) {
|
|
1059
|
+
this.zenfsCache = await import('@zenfs/core');
|
|
1060
|
+
}
|
|
1061
|
+
return this.zenfsCache;
|
|
1062
|
+
}
|
|
1063
|
+
getFsSync() {
|
|
1064
|
+
if (!this.zenfsCache) {
|
|
1065
|
+
throw new Error('File system not initialized. Call getFs() or initializeFileSystem() first.');
|
|
1066
|
+
}
|
|
1067
|
+
return this.zenfsCache;
|
|
1068
|
+
}
|
|
1069
|
+
async getContentUrlFromPath(path) {
|
|
1070
|
+
const fileExists = await this.pathExists(path);
|
|
1071
|
+
if (fileExists) {
|
|
1072
|
+
const file = await this.readFile(path);
|
|
1073
|
+
return URL.createObjectURL(file);
|
|
1074
|
+
}
|
|
1075
|
+
}
|
|
1076
|
+
async initializeFileSystem(_workingDir) {
|
|
1077
|
+
const zenfs = await this.getFs();
|
|
1078
|
+
const { TolerantWebAccess } = await import('./tolerantWebAccess-CzOBz5M6.js');
|
|
1079
|
+
const { configureSingle } = zenfs;
|
|
1080
|
+
const configureRoot = async () => {
|
|
1081
|
+
const handle = await navigator.storage.getDirectory();
|
|
1082
|
+
await configureSingle({
|
|
1083
|
+
backend: TolerantWebAccess,
|
|
1084
|
+
handle,
|
|
1085
|
+
});
|
|
1086
|
+
};
|
|
1087
|
+
// TolerantWebAccess skips busy entries, so what reaches here is the walk failing above them
|
|
1088
|
+
// (e.g. a stale root handle). Retry without deleting OPFS data; BaseFileManager resets its
|
|
1089
|
+
// flags if every attempt fails.
|
|
1090
|
+
for (let attempt = 0;; attempt++) {
|
|
1091
|
+
try {
|
|
1092
|
+
await configureRoot();
|
|
1093
|
+
return;
|
|
1094
|
+
}
|
|
1095
|
+
catch (error) {
|
|
1096
|
+
if (!isBusyOpfsMountError(error)) {
|
|
1097
|
+
throw error;
|
|
1098
|
+
}
|
|
1099
|
+
if (attempt === MOUNT_RETRY_DELAYS_MS.length) {
|
|
1100
|
+
throw new FileSystemLockedError(error);
|
|
1101
|
+
}
|
|
1102
|
+
logger$4(`OPFS mount attempt ${attempt + 1} failed (${error?.name}); retrying`);
|
|
1103
|
+
await sleep(MOUNT_RETRY_DELAYS_MS[attempt]);
|
|
1104
|
+
}
|
|
1105
|
+
}
|
|
1106
|
+
}
|
|
1107
|
+
async downloadAllFiles({ transactionIds, arweaveHost, arweaveBaseUrls, excludedTransactions, }) {
|
|
1108
|
+
const fileDownloader = new FileDownloader();
|
|
1109
|
+
await fileDownloader.downloadAll({ transactionIds, arweaveHost, arweaveBaseUrls, excludedTransactions });
|
|
1110
|
+
}
|
|
1111
|
+
async resizeImage({ filePath, width, height }) {
|
|
1112
|
+
const imageResizer = new ImageResizer();
|
|
1113
|
+
await imageResizer.resize({ filePath, width, height });
|
|
1114
|
+
}
|
|
1115
|
+
async resizeAllImages({ width, height }) {
|
|
1116
|
+
const imageResizer = new ImageResizer();
|
|
1117
|
+
await imageResizer.resizeAll({ width, height });
|
|
1118
|
+
}
|
|
1119
|
+
async listImageFiles() {
|
|
1120
|
+
return this.listFiles('images');
|
|
1121
|
+
}
|
|
1122
|
+
async listFiles(dir) {
|
|
1123
|
+
const targetDir = BaseFileManager.getFilesPath(dir);
|
|
1124
|
+
const exists = await this.pathExists(targetDir);
|
|
1125
|
+
if (!exists) {
|
|
1126
|
+
return [];
|
|
1127
|
+
}
|
|
1128
|
+
const zenfs = await this.getFs();
|
|
1129
|
+
const entries = await zenfs.promises.readdir(targetDir, { withFileTypes: true });
|
|
1130
|
+
return entries.filter((entry) => entry.isFile()).map((entry) => entry.name);
|
|
1131
|
+
}
|
|
1132
|
+
async invalidateCachedPaths(filePaths) {
|
|
1133
|
+
const { mounts } = await this.getFs();
|
|
1134
|
+
const { TolerantWebAccessFS } = await import('./tolerantWebAccess-CzOBz5M6.js');
|
|
1135
|
+
const mounted = mounts.get('/');
|
|
1136
|
+
if (!(mounted instanceof TolerantWebAccessFS))
|
|
1137
|
+
return;
|
|
1138
|
+
for (const filePath of filePaths) {
|
|
1139
|
+
const absolute = filePath.startsWith('/') ? filePath : `/${filePath}`;
|
|
1140
|
+
try {
|
|
1141
|
+
await mounted.invalidate(absolute);
|
|
1142
|
+
}
|
|
1143
|
+
catch (error) {
|
|
1144
|
+
logger$4(`could not refresh cached ${absolute}`, error);
|
|
1145
|
+
}
|
|
1146
|
+
}
|
|
1147
|
+
}
|
|
1148
|
+
async pathExists(filePath) {
|
|
1149
|
+
try {
|
|
1150
|
+
const zenfs = await this.getFs();
|
|
1151
|
+
await zenfs.promises.access(filePath, zenfs.constants.F_OK);
|
|
1152
|
+
return true;
|
|
1153
|
+
}
|
|
1154
|
+
catch (error) {
|
|
1155
|
+
// ENOENT means the file doesn't exist, which is expected
|
|
1156
|
+
if (error?.code === 'ENOENT' || error?.errno === -2) {
|
|
1157
|
+
return false;
|
|
1158
|
+
}
|
|
1159
|
+
// For other errors, re-throw them
|
|
1160
|
+
throw error;
|
|
1161
|
+
}
|
|
1162
|
+
}
|
|
1163
|
+
async getFileSize(filePath) {
|
|
1164
|
+
try {
|
|
1165
|
+
const zenfs = await this.getFs();
|
|
1166
|
+
const stat = await zenfs.promises.stat(filePath);
|
|
1167
|
+
return typeof stat?.size === 'number' ? stat.size : null;
|
|
1168
|
+
}
|
|
1169
|
+
catch {
|
|
1170
|
+
return null;
|
|
1171
|
+
}
|
|
1172
|
+
}
|
|
1173
|
+
async createDirIfNotExists(filePath) {
|
|
1174
|
+
if (!(await this.pathExists(filePath))) {
|
|
1175
|
+
try {
|
|
1176
|
+
const zenfs = await this.getFs();
|
|
1177
|
+
await zenfs.promises.mkdir(filePath, { recursive: true });
|
|
1178
|
+
}
|
|
1179
|
+
catch (error) {
|
|
1180
|
+
// This is a no-op. We tried to create a directory that already exists.
|
|
1181
|
+
logger$4('Attempted to create a directory that already exists');
|
|
1182
|
+
}
|
|
1183
|
+
}
|
|
1184
|
+
}
|
|
1185
|
+
/**
|
|
1186
|
+
* Waits for a file to exist at the specified path.
|
|
1187
|
+
* @param {string} filePath - The path of the file to check.
|
|
1188
|
+
* @param {number} interval - The interval in milliseconds between checks (default: 500ms).
|
|
1189
|
+
* @param {number} timeout - The timeout in milliseconds to wait for the file to exist (default: 10s).
|
|
1190
|
+
* @returns {Promise<boolean>} - Resolves to true if the file exists within the timeout period, otherwise false.
|
|
1191
|
+
*/
|
|
1192
|
+
async waitForFile(filePath, interval = 1000, timeout = 60000) {
|
|
1193
|
+
// const fs = await this.getFs()
|
|
1194
|
+
// const fsNode = await import('node:fs')
|
|
1195
|
+
const pathExists = await this.pathExists(filePath);
|
|
1196
|
+
if (pathExists) {
|
|
1197
|
+
return true;
|
|
1198
|
+
}
|
|
1199
|
+
return new Promise((resolve, reject) => {
|
|
1200
|
+
const startTime = Date.now();
|
|
1201
|
+
let isBusy = false;
|
|
1202
|
+
const cancelableInterval = new CancelableInterval(async (stop) => {
|
|
1203
|
+
logger$4('waitForFile', filePath);
|
|
1204
|
+
if (isBusy) {
|
|
1205
|
+
return;
|
|
1206
|
+
}
|
|
1207
|
+
isBusy = true;
|
|
1208
|
+
// // TODO: Needs to read from OPFS
|
|
1209
|
+
// const exists = await BaseFileManager.pathExists(filePath)
|
|
1210
|
+
// if (exists) {
|
|
1211
|
+
// stop()
|
|
1212
|
+
// resolve(true)
|
|
1213
|
+
// }
|
|
1214
|
+
const pathExists = await this.pathExists(filePath);
|
|
1215
|
+
if (pathExists) {
|
|
1216
|
+
stop();
|
|
1217
|
+
resolve(true);
|
|
1218
|
+
}
|
|
1219
|
+
if (Date.now() - startTime >= timeout) {
|
|
1220
|
+
stop();
|
|
1221
|
+
reject(new Error('Timeout exceeded while waiting for file'));
|
|
1222
|
+
}
|
|
1223
|
+
isBusy = false;
|
|
1224
|
+
}, interval);
|
|
1225
|
+
cancelableInterval.start();
|
|
1226
|
+
// const _interval = setInterval(async () => {
|
|
1227
|
+
// logger('waitForFile', filePath)
|
|
1228
|
+
// if (isBusy) {
|
|
1229
|
+
// return
|
|
1230
|
+
// }
|
|
1231
|
+
// isBusy = true
|
|
1232
|
+
// // TODO: Needs to read from OPFS
|
|
1233
|
+
// if (fs.existsSync(filePath) && fsNode.existsSync(filePath)) {
|
|
1234
|
+
// clearInterval(_interval)
|
|
1235
|
+
// resolve(true)
|
|
1236
|
+
// }
|
|
1237
|
+
// const pathExists = await this.pathExists(filePath)
|
|
1238
|
+
// if (pathExists) {
|
|
1239
|
+
// clearInterval(_interval)
|
|
1240
|
+
// resolve(true)
|
|
1241
|
+
// }
|
|
1242
|
+
// if (Date.now() - startTime >= timeout) {
|
|
1243
|
+
// clearInterval(_interval)
|
|
1244
|
+
// reject(new Error('Timeout exceeded while waiting for file'))
|
|
1245
|
+
// }
|
|
1246
|
+
// isBusy = false
|
|
1247
|
+
// }, interval)
|
|
1248
|
+
// retry(
|
|
1249
|
+
// {
|
|
1250
|
+
// times: Math.ceil(timeout / interval),
|
|
1251
|
+
// interval: interval,
|
|
1252
|
+
// },
|
|
1253
|
+
// (callback: Function) => {
|
|
1254
|
+
// if (fs.existsSync(filePath) && fsNode.existsSync(filePath)) {
|
|
1255
|
+
// return callback(null, true) // File exists, finish with success
|
|
1256
|
+
// }
|
|
1257
|
+
// if (Date.now() - startTime >= timeout) {
|
|
1258
|
+
// return callback(new Error('Timeout exceeded while waiting for file'))
|
|
1259
|
+
// }
|
|
1260
|
+
// callback(new Error('File does not exist yet')) // Retry with this error
|
|
1261
|
+
// },
|
|
1262
|
+
// (err: Error, result: boolean) => {
|
|
1263
|
+
// if (err) {
|
|
1264
|
+
// return resolve(false) // Resolve as false if timeout or error occurs
|
|
1265
|
+
// }
|
|
1266
|
+
// resolve(result) // Resolve as true if file exists
|
|
1267
|
+
// },
|
|
1268
|
+
// )
|
|
1269
|
+
});
|
|
1270
|
+
}
|
|
1271
|
+
/**
|
|
1272
|
+
* Waits for a file to exist and have content (non-zero size).
|
|
1273
|
+
* This is important for browser/OPFS where writes may not be immediately readable.
|
|
1274
|
+
* @param {string} filePath - The path of the file to check.
|
|
1275
|
+
* @param {number} interval - The interval in milliseconds between checks (default: 100ms).
|
|
1276
|
+
* @param {number} timeout - The timeout in milliseconds to wait (default: 5s).
|
|
1277
|
+
* @returns {Promise<boolean>} - Resolves to true if the file exists with content within the timeout period.
|
|
1278
|
+
*/
|
|
1279
|
+
async waitForFileWithContent(filePath, interval = 100, timeout = 5000) {
|
|
1280
|
+
// First wait for file to exist
|
|
1281
|
+
await this.waitForFile(filePath, interval, timeout);
|
|
1282
|
+
// Usually readable at once: polling first cost every saveFile 100ms. Any read error falls
|
|
1283
|
+
// through to the polling below, which decides whether it is transient.
|
|
1284
|
+
try {
|
|
1285
|
+
if ((await this.readFile(filePath)).size > 0)
|
|
1286
|
+
return true;
|
|
1287
|
+
}
|
|
1288
|
+
catch {
|
|
1289
|
+
// handled by polling
|
|
1290
|
+
}
|
|
1291
|
+
// Now wait for file to have content
|
|
1292
|
+
return new Promise((resolve, reject) => {
|
|
1293
|
+
const startTime = Date.now();
|
|
1294
|
+
let isBusy = false;
|
|
1295
|
+
const cancelableInterval = new CancelableInterval(async (stop) => {
|
|
1296
|
+
logger$4('waitForFileWithContent', filePath);
|
|
1297
|
+
if (isBusy) {
|
|
1298
|
+
return;
|
|
1299
|
+
}
|
|
1300
|
+
isBusy = true;
|
|
1301
|
+
try {
|
|
1302
|
+
// Try to read the file to check if it has content
|
|
1303
|
+
const file = await this.readFile(filePath);
|
|
1304
|
+
if (file.size > 0) {
|
|
1305
|
+
stop();
|
|
1306
|
+
resolve(true);
|
|
1307
|
+
return;
|
|
1308
|
+
}
|
|
1309
|
+
// File exists but is 0 bytes, continue waiting
|
|
1310
|
+
}
|
|
1311
|
+
catch (error) {
|
|
1312
|
+
// If error is about file being 0 bytes, not readable, or I/O error, continue waiting
|
|
1313
|
+
const errorMessage = error?.message || String(error);
|
|
1314
|
+
if (errorMessage.includes('0 bytes') ||
|
|
1315
|
+
errorMessage.includes('ENOENT') ||
|
|
1316
|
+
errorMessage.includes('EIO') ||
|
|
1317
|
+
errorMessage.includes('Input/output error') ||
|
|
1318
|
+
isTransientOpfsReadError(error)) ;
|
|
1319
|
+
else {
|
|
1320
|
+
// Other errors should be thrown
|
|
1321
|
+
stop();
|
|
1322
|
+
reject(error);
|
|
1323
|
+
return;
|
|
1324
|
+
}
|
|
1325
|
+
}
|
|
1326
|
+
if (Date.now() - startTime >= timeout) {
|
|
1327
|
+
stop();
|
|
1328
|
+
reject(new Error(`Timeout exceeded while waiting for file ${filePath} to have content`));
|
|
1329
|
+
return;
|
|
1330
|
+
}
|
|
1331
|
+
isBusy = false;
|
|
1332
|
+
}, interval);
|
|
1333
|
+
cancelableInterval.start();
|
|
1334
|
+
});
|
|
1335
|
+
}
|
|
1336
|
+
async saveFile(filePath, content) {
|
|
1337
|
+
const zenfs = await this.getFs();
|
|
1338
|
+
// Convert content to a format that zenfs.writeFile accepts
|
|
1339
|
+
let writeContent;
|
|
1340
|
+
if (typeof content === 'string') {
|
|
1341
|
+
writeContent = content;
|
|
1342
|
+
}
|
|
1343
|
+
else if (content instanceof Blob) {
|
|
1344
|
+
const arrayBuffer = await content.arrayBuffer();
|
|
1345
|
+
writeContent = new Uint8Array(arrayBuffer);
|
|
1346
|
+
}
|
|
1347
|
+
else if (content instanceof ArrayBuffer) {
|
|
1348
|
+
writeContent = new Uint8Array(content);
|
|
1349
|
+
}
|
|
1350
|
+
else {
|
|
1351
|
+
throw new Error('Unsupported content type');
|
|
1352
|
+
}
|
|
1353
|
+
await zenfs.writeFile(filePath, writeContent);
|
|
1354
|
+
await this.waitForFileWithContent(filePath, 100, 5000);
|
|
1355
|
+
// try {
|
|
1356
|
+
// // Get a handle to the OPFS root directory
|
|
1357
|
+
// const root = await navigator.storage.getDirectory();
|
|
1358
|
+
// // Split the file path into directory and file name
|
|
1359
|
+
// const pathParts = filePath.split('/');
|
|
1360
|
+
// const fileName = pathParts.pop();
|
|
1361
|
+
// if (!fileName) throw new Error('Invalid file path');
|
|
1362
|
+
// // Traverse directories and create them if they don't exist
|
|
1363
|
+
// let currentDir = root;
|
|
1364
|
+
// for (const part of pathParts) {
|
|
1365
|
+
// if (part !== '') {
|
|
1366
|
+
// currentDir = await currentDir.getDirectoryHandle(part, { create: true });
|
|
1367
|
+
// }
|
|
1368
|
+
// }
|
|
1369
|
+
// // Get the file handle and create the file if it doesn't exist
|
|
1370
|
+
// const fileHandle = await currentDir.getFileHandle(fileName, { create: true });
|
|
1371
|
+
// // Create a writable stream and write the content
|
|
1372
|
+
// const writable = await fileHandle.createWritable();
|
|
1373
|
+
// if (typeof content === 'string' || content instanceof Uint8Array) {
|
|
1374
|
+
// await writable.write(content);
|
|
1375
|
+
// } else if (content instanceof Blob) {
|
|
1376
|
+
// await writable.write(content);
|
|
1377
|
+
// } else if (content instanceof ArrayBuffer) {
|
|
1378
|
+
// await writable.write(new Blob([content]));
|
|
1379
|
+
// } else {
|
|
1380
|
+
// throw new Error('Unsupported content type');
|
|
1381
|
+
// }
|
|
1382
|
+
// await writable.close();
|
|
1383
|
+
// logger(`File written successfully: ${filePath}`);
|
|
1384
|
+
// } catch (error) {
|
|
1385
|
+
// console.error(`Error writing to OPFS: ${error.message}`);
|
|
1386
|
+
// }
|
|
1387
|
+
}
|
|
1388
|
+
saveFileSync(filePath, content) {
|
|
1389
|
+
// Note: This is a synchronous wrapper, but zenfs operations may still be async under the hood
|
|
1390
|
+
// For true sync operations in browser, we'd need to use OPFS sync access handles
|
|
1391
|
+
// For now, we'll use zenfs.writeFileSync which should be available
|
|
1392
|
+
const zenfs = this.getFsSync();
|
|
1393
|
+
// Convert content to a format that zenfs.writeFileSync accepts
|
|
1394
|
+
let writeContent;
|
|
1395
|
+
if (typeof content === 'string') {
|
|
1396
|
+
writeContent = content;
|
|
1397
|
+
}
|
|
1398
|
+
else if (content instanceof Blob) {
|
|
1399
|
+
// Blob cannot be converted synchronously - throw error
|
|
1400
|
+
throw new Error('Blob content not supported in saveFileSync. Use saveFile() instead or convert to ArrayBuffer first.');
|
|
1401
|
+
}
|
|
1402
|
+
else if (content instanceof ArrayBuffer) {
|
|
1403
|
+
writeContent = new Uint8Array(content);
|
|
1404
|
+
}
|
|
1405
|
+
else {
|
|
1406
|
+
throw new Error('Unsupported content type');
|
|
1407
|
+
}
|
|
1408
|
+
zenfs.writeFileSync(filePath, writeContent);
|
|
1409
|
+
}
|
|
1410
|
+
async readFile(filePath) {
|
|
1411
|
+
const zenfs = await this.getFs();
|
|
1412
|
+
const maxAttempts = 3;
|
|
1413
|
+
const baseDelayMs = 50;
|
|
1414
|
+
for (let attempt = 0; attempt < maxAttempts; attempt++) {
|
|
1415
|
+
try {
|
|
1416
|
+
const data = await zenfs.promises.readFile(filePath);
|
|
1417
|
+
return new File([new Uint8Array(data)], filePath);
|
|
1418
|
+
}
|
|
1419
|
+
catch (error) {
|
|
1420
|
+
if (!isTransientOpfsReadError(error) || attempt === maxAttempts - 1) {
|
|
1421
|
+
throw error;
|
|
1422
|
+
}
|
|
1423
|
+
await sleep(baseDelayMs * (attempt + 1));
|
|
1424
|
+
}
|
|
1425
|
+
}
|
|
1426
|
+
throw new Error('readFile: exhausted retries');
|
|
1427
|
+
// try {
|
|
1428
|
+
// // Get a handle to the OPFS root directory
|
|
1429
|
+
// const root = await navigator.storage.getDirectory();
|
|
1430
|
+
// // Split the file path into directory and file name
|
|
1431
|
+
// const pathParts = filePath.split('/');
|
|
1432
|
+
// const fileName = pathParts.pop();
|
|
1433
|
+
// if (!fileName) throw new Error('Invalid file path');
|
|
1434
|
+
// // Traverse directories to reach the target file
|
|
1435
|
+
// let currentDir = root;
|
|
1436
|
+
// for (const part of pathParts) {
|
|
1437
|
+
// if (part !== '') {
|
|
1438
|
+
// currentDir = await currentDir.getDirectoryHandle(part, { create: false });
|
|
1439
|
+
// }
|
|
1440
|
+
// }
|
|
1441
|
+
// // Get the file handle
|
|
1442
|
+
// const fileHandle = await currentDir.getFileHandle(fileName, { create: false });
|
|
1443
|
+
// // Get the file and read it as an ArrayBuffer
|
|
1444
|
+
// return await fileHandle.getFile();
|
|
1445
|
+
// } catch (error) {
|
|
1446
|
+
// console.error(`Error reading from OPFS: ${error.message}`);
|
|
1447
|
+
// throw error;
|
|
1448
|
+
// }
|
|
1449
|
+
}
|
|
1450
|
+
readFileSync(filePath) {
|
|
1451
|
+
// Note: This is a synchronous wrapper, but zenfs operations may still be async under the hood
|
|
1452
|
+
// For true sync operations in browser, we'd need to use OPFS sync access handles
|
|
1453
|
+
// For now, we'll use zenfs.readFileSync which should be available
|
|
1454
|
+
const zenfs = this.getFsSync();
|
|
1455
|
+
const file = zenfs.readFileSync(filePath);
|
|
1456
|
+
return new File([new Uint8Array(file)], filePath);
|
|
1457
|
+
}
|
|
1458
|
+
async readFileAsBuffer(filePath) {
|
|
1459
|
+
try {
|
|
1460
|
+
// Get the file and read it as an ArrayBuffer
|
|
1461
|
+
const file = await this.readFile(filePath);
|
|
1462
|
+
const arrayBuffer = await file.arrayBuffer();
|
|
1463
|
+
// Convert ArrayBuffer to Blob
|
|
1464
|
+
return new Blob([arrayBuffer]);
|
|
1465
|
+
}
|
|
1466
|
+
catch (error) {
|
|
1467
|
+
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
1468
|
+
console.error(`Error reading from OPFS: ${errorMessage}`);
|
|
1469
|
+
throw error;
|
|
1470
|
+
}
|
|
1471
|
+
}
|
|
1472
|
+
async readFileAsString(filePath) {
|
|
1473
|
+
const blob = await this.readFileAsBuffer(filePath);
|
|
1474
|
+
return blob.text();
|
|
1475
|
+
}
|
|
1476
|
+
getParentDirPath(filePath) {
|
|
1477
|
+
return pathCompat.dirname(filePath);
|
|
1478
|
+
}
|
|
1479
|
+
getFilenameFromPath(filePath) {
|
|
1480
|
+
return pathCompat.basename(filePath);
|
|
1481
|
+
}
|
|
1482
|
+
getPathModule() {
|
|
1483
|
+
return pathCompat;
|
|
1484
|
+
}
|
|
1485
|
+
}
|
|
1486
|
+
class CancelableInterval {
|
|
1487
|
+
constructor(task, interval) {
|
|
1488
|
+
this.task = task;
|
|
1489
|
+
this.interval = interval;
|
|
1490
|
+
this.intervalId = null;
|
|
1491
|
+
this.currentTaskAbortController = null;
|
|
1492
|
+
}
|
|
1493
|
+
start() {
|
|
1494
|
+
this.intervalId = window.setInterval(async () => {
|
|
1495
|
+
if (this.currentTaskAbortController) {
|
|
1496
|
+
// Cancel the previous running task
|
|
1497
|
+
this.currentTaskAbortController.abort();
|
|
1498
|
+
}
|
|
1499
|
+
// Create a new abort controller for the current task
|
|
1500
|
+
this.currentTaskAbortController = new AbortController();
|
|
1501
|
+
const signal = this.currentTaskAbortController.signal;
|
|
1502
|
+
try {
|
|
1503
|
+
await this.taskWithCancellation(signal);
|
|
1504
|
+
}
|
|
1505
|
+
catch (error) {
|
|
1506
|
+
if (error instanceof DOMException && error.name === 'AbortError') {
|
|
1507
|
+
logger$4('Previous task was canceled.');
|
|
1508
|
+
}
|
|
1509
|
+
else {
|
|
1510
|
+
console.error('Task error:', error);
|
|
1511
|
+
}
|
|
1512
|
+
this.stop();
|
|
1513
|
+
}
|
|
1514
|
+
}, this.interval);
|
|
1515
|
+
}
|
|
1516
|
+
async taskWithCancellation(signal) {
|
|
1517
|
+
await this.task(() => this.stop());
|
|
1518
|
+
if (signal.aborted) {
|
|
1519
|
+
throw new DOMException('Task was aborted', 'AbortError');
|
|
1520
|
+
}
|
|
1521
|
+
}
|
|
1522
|
+
stop() {
|
|
1523
|
+
if (this.intervalId !== null) {
|
|
1524
|
+
clearInterval(this.intervalId);
|
|
1525
|
+
this.intervalId = null;
|
|
1526
|
+
}
|
|
1527
|
+
if (this.currentTaskAbortController) {
|
|
1528
|
+
this.currentTaskAbortController.abort();
|
|
1529
|
+
}
|
|
1530
|
+
}
|
|
1531
|
+
}
|
|
1532
|
+
BaseFileManager.configure(new BrowserFileManager());
|
|
1533
|
+
|
|
1534
|
+
// This file embeds the drizzle migration files as strings for browser runtime
|
|
1535
|
+
// These files are copied from packages/sdk/src/db/drizzle at build time
|
|
1536
|
+
// Individual migration SQL files
|
|
1537
|
+
const migrationSql_0000_married_malice = `CREATE TABLE \`appState\` (
|
|
1538
|
+
\`key\` text,
|
|
1539
|
+
\`value\` text,
|
|
1540
|
+
\`created_at\` integer,
|
|
1541
|
+
\`updated_at\` integer
|
|
1542
|
+
);
|
|
1543
|
+
--> statement-breakpoint
|
|
1544
|
+
CREATE UNIQUE INDEX \`appState_key_unique\` ON \`appState\` (\`key\`);--> statement-breakpoint
|
|
1545
|
+
CREATE TABLE \`config\` (
|
|
1546
|
+
\`id\` integer PRIMARY KEY AUTOINCREMENT NOT NULL,
|
|
1547
|
+
\`key\` text NOT NULL,
|
|
1548
|
+
\`text\` text,
|
|
1549
|
+
\`json\` text,
|
|
1550
|
+
\`blob\` blob
|
|
1551
|
+
);
|
|
1552
|
+
--> statement-breakpoint
|
|
1553
|
+
CREATE TABLE \`metadata\` (
|
|
1554
|
+
\`local_id\` text,
|
|
1555
|
+
\`uid\` text,
|
|
1556
|
+
\`property_name\` text,
|
|
1557
|
+
\`property_value\` text,
|
|
1558
|
+
\`schema_uid\` text,
|
|
1559
|
+
\`model_type\` text,
|
|
1560
|
+
\`seed_local_id\` text,
|
|
1561
|
+
\`seed_uid\` text,
|
|
1562
|
+
\`version_local_id\` text,
|
|
1563
|
+
\`version_uid\` text,
|
|
1564
|
+
\`eas_data_type\` text,
|
|
1565
|
+
\`ref_value_type\` text,
|
|
1566
|
+
\`ref_schema_uid\` text,
|
|
1567
|
+
\`ref_seed_type\` text,
|
|
1568
|
+
\`ref_resolved_value\` text,
|
|
1569
|
+
\`ref_resolved_display_value\` text,
|
|
1570
|
+
\`local_storage_dir\` text,
|
|
1571
|
+
\`attestation_raw\` text,
|
|
1572
|
+
\`attestation_created_at\` integer,
|
|
1573
|
+
\`content_hash\` text,
|
|
1574
|
+
\`created_at\` integer,
|
|
1575
|
+
\`updated_at\` integer
|
|
1576
|
+
);
|
|
1577
|
+
--> statement-breakpoint
|
|
1578
|
+
CREATE UNIQUE INDEX \`metadata_local_id_unique\` ON \`metadata\` (\`local_id\`);--> statement-breakpoint
|
|
1579
|
+
CREATE TABLE \`models\` (
|
|
1580
|
+
\`id\` integer PRIMARY KEY AUTOINCREMENT NOT NULL,
|
|
1581
|
+
\`name\` text NOT NULL,
|
|
1582
|
+
\`schema_file_id\` text
|
|
1583
|
+
);
|
|
1584
|
+
--> statement-breakpoint
|
|
1585
|
+
CREATE TABLE \`properties\` (
|
|
1586
|
+
\`id\` integer PRIMARY KEY AUTOINCREMENT NOT NULL,
|
|
1587
|
+
\`name\` text NOT NULL,
|
|
1588
|
+
\`data_type\` text NOT NULL,
|
|
1589
|
+
\`model_id\` integer NOT NULL,
|
|
1590
|
+
\`ref_model_id\` integer,
|
|
1591
|
+
\`ref_value_type\` text,
|
|
1592
|
+
\`schema_file_id\` text,
|
|
1593
|
+
FOREIGN KEY (\`model_id\`) REFERENCES \`models\`(\`id\`) ON UPDATE no action ON DELETE no action,
|
|
1594
|
+
FOREIGN KEY (\`ref_model_id\`) REFERENCES \`models\`(\`id\`) ON UPDATE no action ON DELETE no action
|
|
1595
|
+
);
|
|
1596
|
+
--> statement-breakpoint
|
|
1597
|
+
CREATE UNIQUE INDEX \`unique_name_model_id\` ON \`properties\` (\`name\`,\`model_id\`);--> statement-breakpoint
|
|
1598
|
+
CREATE TABLE \`model_schemas\` (
|
|
1599
|
+
\`id\` integer PRIMARY KEY AUTOINCREMENT NOT NULL,
|
|
1600
|
+
\`model_id\` integer,
|
|
1601
|
+
\`schema_id\` integer,
|
|
1602
|
+
FOREIGN KEY (\`model_id\`) REFERENCES \`models\`(\`id\`) ON UPDATE no action ON DELETE no action,
|
|
1603
|
+
FOREIGN KEY (\`schema_id\`) REFERENCES \`schemas\`(\`id\`) ON UPDATE no action ON DELETE no action
|
|
1604
|
+
);
|
|
1605
|
+
--> statement-breakpoint
|
|
1606
|
+
CREATE TABLE \`model_uids\` (
|
|
1607
|
+
\`id\` integer PRIMARY KEY AUTOINCREMENT NOT NULL,
|
|
1608
|
+
\`uid\` text NOT NULL,
|
|
1609
|
+
\`model_id\` integer NOT NULL,
|
|
1610
|
+
FOREIGN KEY (\`model_id\`) REFERENCES \`models\`(\`id\`) ON UPDATE no action ON DELETE no action
|
|
1611
|
+
);
|
|
1612
|
+
--> statement-breakpoint
|
|
1613
|
+
CREATE UNIQUE INDEX \`model_uids_model_id_unique\` ON \`model_uids\` (\`model_id\`);--> statement-breakpoint
|
|
1614
|
+
CREATE TABLE \`property_uids\` (
|
|
1615
|
+
\`id\` integer PRIMARY KEY AUTOINCREMENT NOT NULL,
|
|
1616
|
+
\`uid\` text NOT NULL,
|
|
1617
|
+
\`property_id\` integer NOT NULL,
|
|
1618
|
+
FOREIGN KEY (\`property_id\`) REFERENCES \`models\`(\`id\`) ON UPDATE no action ON DELETE no action
|
|
1619
|
+
);
|
|
1620
|
+
--> statement-breakpoint
|
|
1621
|
+
CREATE UNIQUE INDEX \`property_uids_property_id_unique\` ON \`property_uids\` (\`property_id\`);--> statement-breakpoint
|
|
1622
|
+
CREATE TABLE \`schemas\` (
|
|
1623
|
+
\`id\` integer PRIMARY KEY AUTOINCREMENT NOT NULL,
|
|
1624
|
+
\`name\` text NOT NULL,
|
|
1625
|
+
\`version\` integer NOT NULL,
|
|
1626
|
+
\`schema_file_id\` text,
|
|
1627
|
+
\`created_at\` integer,
|
|
1628
|
+
\`updated_at\` integer
|
|
1629
|
+
);
|
|
1630
|
+
--> statement-breakpoint
|
|
1631
|
+
CREATE TABLE \`seeds\` (
|
|
1632
|
+
\`local_id\` text,
|
|
1633
|
+
\`uid\` text,
|
|
1634
|
+
\`schema_uid\` text,
|
|
1635
|
+
\`type\` text,
|
|
1636
|
+
\`attestation_raw\` text,
|
|
1637
|
+
\`attestation_created_at\` integer,
|
|
1638
|
+
\`created_at\` integer,
|
|
1639
|
+
\`updated_at\` integer,
|
|
1640
|
+
\`_marked_for_deletion\` integer
|
|
1641
|
+
);
|
|
1642
|
+
--> statement-breakpoint
|
|
1643
|
+
CREATE UNIQUE INDEX \`seeds_local_id_unique\` ON \`seeds\` (\`local_id\`);--> statement-breakpoint
|
|
1644
|
+
CREATE TABLE \`versions\` (
|
|
1645
|
+
\`local_id\` text,
|
|
1646
|
+
\`uid\` text,
|
|
1647
|
+
\`seed_local_id\` text,
|
|
1648
|
+
\`seed_uid\` text,
|
|
1649
|
+
\`seed_type\` text,
|
|
1650
|
+
\`note\` text,
|
|
1651
|
+
\`created_at\` integer,
|
|
1652
|
+
\`updated_at\` integer,
|
|
1653
|
+
\`attestation_created_at\` integer,
|
|
1654
|
+
\`attestation_raw\` text
|
|
1655
|
+
);
|
|
1656
|
+
--> statement-breakpoint
|
|
1657
|
+
CREATE UNIQUE INDEX \`versions_local_id_unique\` ON \`versions\` (\`local_id\`);`;
|
|
1658
|
+
const migrationSql_0001_sweet_bruce_banner = `ALTER TABLE \`schemas\` ADD \`schema_data\` text;--> statement-breakpoint
|
|
1659
|
+
ALTER TABLE \`schemas\` ADD \`is_draft\` integer;`;
|
|
1660
|
+
const migrationSql_0002_bitter_proudstar = `CREATE UNIQUE INDEX \`unique_schema_file_id\` ON \`models\` (\`schema_file_id\`);--> statement-breakpoint
|
|
1661
|
+
CREATE UNIQUE INDEX \`unique_property_schema_file_id\` ON \`properties\` (\`schema_file_id\`);--> statement-breakpoint
|
|
1662
|
+
CREATE UNIQUE INDEX \`unique_schema_schema_file_id\` ON \`schemas\` (\`schema_file_id\`);`;
|
|
1663
|
+
const migrationSql_0003_cultured_senator_kelly = `ALTER TABLE \`models\` ADD \`is_edited\` integer;--> statement-breakpoint
|
|
1664
|
+
ALTER TABLE \`properties\` ADD \`is_edited\` integer;--> statement-breakpoint
|
|
1665
|
+
ALTER TABLE \`schemas\` ADD \`is_edited\` integer;`;
|
|
1666
|
+
const migrationSql_0004_add_publisher_to_seeds = `ALTER TABLE \`seeds\` ADD \`publisher\` text;`;
|
|
1667
|
+
const migrationSql_0005_bright_lily_hollister = `CREATE TABLE \`publish_processes\` (
|
|
1668
|
+
\`id\` integer PRIMARY KEY AUTOINCREMENT NOT NULL,
|
|
1669
|
+
\`seed_local_id\` text NOT NULL,
|
|
1670
|
+
\`model_name\` text NOT NULL,
|
|
1671
|
+
\`schema_id\` text,
|
|
1672
|
+
\`status\` text NOT NULL,
|
|
1673
|
+
\`started_at\` integer NOT NULL,
|
|
1674
|
+
\`completed_at\` integer,
|
|
1675
|
+
\`error_message\` text,
|
|
1676
|
+
\`error_step\` text,
|
|
1677
|
+
\`error_details\` text,
|
|
1678
|
+
\`persisted_snapshot\` text NOT NULL,
|
|
1679
|
+
\`seed_id\` text,
|
|
1680
|
+
\`existing_seed_uid\` text,
|
|
1681
|
+
\`created_at\` integer,
|
|
1682
|
+
\`updated_at\` integer
|
|
1683
|
+
);
|
|
1684
|
+
--> statement-breakpoint
|
|
1685
|
+
CREATE TABLE \`upload_processes\` (
|
|
1686
|
+
\`id\` integer PRIMARY KEY AUTOINCREMENT NOT NULL,
|
|
1687
|
+
\`reimbursement_confirmed\` integer NOT NULL,
|
|
1688
|
+
\`reimbursement_transaction_id\` text,
|
|
1689
|
+
\`transaction_keys\` text,
|
|
1690
|
+
\`persisted_snapshot\` text NOT NULL,
|
|
1691
|
+
\`created_at\` integer,
|
|
1692
|
+
\`updated_at\` integer
|
|
1693
|
+
);
|
|
1694
|
+
`;
|
|
1695
|
+
const migrationSql_0006_add_publisher_to_versions_and_metadata = `ALTER TABLE \`versions\` ADD \`publisher\` text;
|
|
1696
|
+
--> statement-breakpoint
|
|
1697
|
+
ALTER TABLE \`metadata\` ADD \`publisher\` text;
|
|
1698
|
+
`;
|
|
1699
|
+
const migrationSql_0007_add_required_to_properties = `ALTER TABLE \`properties\` ADD \`required\` integer DEFAULT 0;
|
|
1700
|
+
`;
|
|
1701
|
+
const migrationSql_0008_add_revoked_at_to_seeds = `ALTER TABLE \`seeds\` ADD \`revoked_at\` integer;
|
|
1702
|
+
`;
|
|
1703
|
+
const migrationSql_0009_happy_namor = `PRAGMA foreign_keys=OFF;--> statement-breakpoint
|
|
1704
|
+
CREATE TABLE \`__new_property_uids\` (
|
|
1705
|
+
\`id\` integer PRIMARY KEY AUTOINCREMENT NOT NULL,
|
|
1706
|
+
\`uid\` text NOT NULL,
|
|
1707
|
+
\`property_id\` integer NOT NULL,
|
|
1708
|
+
FOREIGN KEY (\`property_id\`) REFERENCES \`properties\`(\`id\`) ON UPDATE no action ON DELETE no action
|
|
1709
|
+
);
|
|
1710
|
+
--> statement-breakpoint
|
|
1711
|
+
INSERT INTO \`__new_property_uids\`("id", "uid", "property_id") SELECT "id", "uid", "property_id" FROM \`property_uids\`;--> statement-breakpoint
|
|
1712
|
+
DROP TABLE \`property_uids\`;--> statement-breakpoint
|
|
1713
|
+
ALTER TABLE \`__new_property_uids\` RENAME TO \`property_uids\`;--> statement-breakpoint
|
|
1714
|
+
PRAGMA foreign_keys=ON;--> statement-breakpoint
|
|
1715
|
+
CREATE UNIQUE INDEX \`property_uids_property_id_unique\` ON \`property_uids\` (\`property_id\`);--> statement-breakpoint
|
|
1716
|
+
ALTER TABLE \`metadata\` ADD \`property_id\` integer REFERENCES properties(id);`;
|
|
1717
|
+
const migrationSql_0010_add_arweave_l1_finalize_jobs = `CREATE TABLE \`arweave_l1_finalize_jobs\` (
|
|
1718
|
+
\`id\` integer PRIMARY KEY AUTOINCREMENT NOT NULL,
|
|
1719
|
+
\`seed_local_id\` text NOT NULL,
|
|
1720
|
+
\`data_item_id\` text NOT NULL,
|
|
1721
|
+
\`l1_transaction_id\` text,
|
|
1722
|
+
\`bundle_id\` text,
|
|
1723
|
+
\`version_local_id\` text,
|
|
1724
|
+
\`item_property_name\` text,
|
|
1725
|
+
\`phase\` text NOT NULL,
|
|
1726
|
+
\`status_json\` text,
|
|
1727
|
+
\`error_message\` text,
|
|
1728
|
+
\`created_at\` integer NOT NULL,
|
|
1729
|
+
\`updated_at\` integer NOT NULL
|
|
1730
|
+
);
|
|
1731
|
+
--> statement-breakpoint
|
|
1732
|
+
CREATE UNIQUE INDEX \`arweave_l1_finalize_jobs_data_item_id_unique\` ON \`arweave_l1_finalize_jobs\` (\`data_item_id\`);
|
|
1733
|
+
`;
|
|
1734
|
+
const migrationSql_0011_normalize_placeholder_uids = `UPDATE \`versions\` SET \`uid\` = NULL WHERE \`uid\` = 'NULL';
|
|
1735
|
+
--> statement-breakpoint
|
|
1736
|
+
UPDATE \`versions\` SET \`seed_uid\` = NULL WHERE \`seed_uid\` = 'NULL';
|
|
1737
|
+
--> statement-breakpoint
|
|
1738
|
+
UPDATE \`metadata\` SET \`uid\` = NULL WHERE \`uid\` = 'NULL';
|
|
1739
|
+
--> statement-breakpoint
|
|
1740
|
+
UPDATE \`metadata\` SET \`version_uid\` = NULL WHERE \`version_uid\` = 'NULL';
|
|
1741
|
+
--> statement-breakpoint
|
|
1742
|
+
UPDATE \`seeds\` SET \`uid\` = NULL WHERE \`uid\` = 'NULL';
|
|
1743
|
+
`;
|
|
1744
|
+
const migrationSql_0012_html_embedded_image_co_publish = `CREATE TABLE \`html_embedded_image_co_publish\` (
|
|
1745
|
+
\`id\` integer PRIMARY KEY AUTOINCREMENT NOT NULL,
|
|
1746
|
+
\`parent_seed_local_id\` text NOT NULL,
|
|
1747
|
+
\`html_seed_local_id\` text NOT NULL,
|
|
1748
|
+
\`image_seed_local_id\` text NOT NULL,
|
|
1749
|
+
\`stable_key\` text NOT NULL,
|
|
1750
|
+
\`created_at\` integer NOT NULL
|
|
1751
|
+
);
|
|
1752
|
+
--> statement-breakpoint
|
|
1753
|
+
CREATE UNIQUE INDEX \`html_embed_co_pub_parent_html_stable\` ON \`html_embedded_image_co_publish\` (\`parent_seed_local_id\`,\`html_seed_local_id\`,\`stable_key\`);
|
|
1754
|
+
`;
|
|
1755
|
+
const migrationSql_0013_eas_sync_processes = `CREATE TABLE \`eas_sync_processes\` (
|
|
1756
|
+
\`id\` integer PRIMARY KEY AUTOINCREMENT NOT NULL,
|
|
1757
|
+
\`status\` text NOT NULL,
|
|
1758
|
+
\`started_at\` integer NOT NULL,
|
|
1759
|
+
\`completed_at\` integer,
|
|
1760
|
+
\`request_payload\` text NOT NULL,
|
|
1761
|
+
\`error_message\` text,
|
|
1762
|
+
\`error_details\` text,
|
|
1763
|
+
\`persisted_snapshot\` text NOT NULL,
|
|
1764
|
+
\`created_at\` integer,
|
|
1765
|
+
\`updated_at\` integer
|
|
1766
|
+
);
|
|
1767
|
+
`;
|
|
1768
|
+
const migrationSql_0014_add_error_code_to_publish_processes = `ALTER TABLE \`publish_processes\` ADD \`error_code\` text;
|
|
1769
|
+
`;
|
|
1770
|
+
const migrationSql_0015_add_model_file_id_to_seeds = `ALTER TABLE \`seeds\` ADD \`model_file_id\` text;
|
|
1771
|
+
--> statement-breakpoint
|
|
1772
|
+
UPDATE \`seeds\` SET \`model_file_id\` = (
|
|
1773
|
+
SELECT \`models\`.\`schema_file_id\`
|
|
1774
|
+
FROM \`metadata\`
|
|
1775
|
+
INNER JOIN \`properties\` ON \`properties\`.\`id\` = \`metadata\`.\`property_id\`
|
|
1776
|
+
INNER JOIN \`models\` ON \`models\`.\`id\` = \`properties\`.\`model_id\`
|
|
1777
|
+
WHERE \`metadata\`.\`seed_local_id\` = \`seeds\`.\`local_id\`
|
|
1778
|
+
AND \`models\`.\`schema_file_id\` IS NOT NULL
|
|
1779
|
+
LIMIT 1
|
|
1780
|
+
) WHERE \`model_file_id\` IS NULL;
|
|
1781
|
+
`;
|
|
1782
|
+
const migrationSql_0016_add_revoked_at_to_metadata = `ALTER TABLE \`metadata\` ADD \`revoked_at\` integer;
|
|
1783
|
+
`;
|
|
1784
|
+
const migrationSql_0017_add_revoked_at_to_versions = `ALTER TABLE \`versions\` ADD \`revoked_at\` integer;`;
|
|
1785
|
+
const migrationSql_0018_add_storage_settings_to_properties = `ALTER TABLE \`properties\` ADD \`storage_type\` text;
|
|
1786
|
+
--> statement-breakpoint
|
|
1787
|
+
ALTER TABLE \`properties\` ADD \`local_storage_dir\` text;
|
|
1788
|
+
--> statement-breakpoint
|
|
1789
|
+
ALTER TABLE \`properties\` ADD \`filename_suffix\` text;
|
|
1790
|
+
--> statement-breakpoint
|
|
1791
|
+
UPDATE \`properties\` SET (\`storage_type\`, \`local_storage_dir\`, \`filename_suffix\`) = (
|
|
1792
|
+
SELECT
|
|
1793
|
+
CASE
|
|
1794
|
+
WHEN json_type(\`p\`.\`def\`, '$.storage') = 'object' THEN
|
|
1795
|
+
CASE WHEN json_extract(\`p\`.\`def\`, '$.storage.type') = 'ItemStorage' THEN 'ItemStorage' ELSE 'PropertyStorage' END
|
|
1796
|
+
ELSE json_extract(\`p\`.\`def\`, '$.storageType')
|
|
1797
|
+
END,
|
|
1798
|
+
CASE
|
|
1799
|
+
WHEN json_type(\`p\`.\`def\`, '$.storage') = 'object' THEN json_extract(\`p\`.\`def\`, '$.storage.path')
|
|
1800
|
+
ELSE json_extract(\`p\`.\`def\`, '$.localStorageDir')
|
|
1801
|
+
END,
|
|
1802
|
+
CASE
|
|
1803
|
+
WHEN json_type(\`p\`.\`def\`, '$.storage') = 'object' THEN json_extract(\`p\`.\`def\`, '$.storage.extension')
|
|
1804
|
+
ELSE json_extract(\`p\`.\`def\`, '$.filenameSuffix')
|
|
1805
|
+
END
|
|
1806
|
+
FROM (
|
|
1807
|
+
SELECT json_extract(
|
|
1808
|
+
\`schemas\`.\`schema_data\`,
|
|
1809
|
+
'$.models."' || \`models\`.\`name\` || '".properties."' || \`properties\`.\`name\` || '"'
|
|
1810
|
+
) AS \`def\`
|
|
1811
|
+
FROM \`models\`
|
|
1812
|
+
INNER JOIN \`model_schemas\` ON \`model_schemas\`.\`model_id\` = \`models\`.\`id\`
|
|
1813
|
+
INNER JOIN \`schemas\` ON \`schemas\`.\`id\` = \`model_schemas\`.\`schema_id\`
|
|
1814
|
+
WHERE \`models\`.\`id\` = \`properties\`.\`model_id\`
|
|
1815
|
+
AND \`models\`.\`name\` NOT LIKE '%"%'
|
|
1816
|
+
AND json_valid(\`schemas\`.\`schema_data\`)
|
|
1817
|
+
AND json_type(
|
|
1818
|
+
\`schemas\`.\`schema_data\`,
|
|
1819
|
+
'$.models."' || \`models\`.\`name\` || '".properties."' || \`properties\`.\`name\` || '"'
|
|
1820
|
+
) = 'object'
|
|
1821
|
+
ORDER BY \`schemas\`.\`id\` DESC
|
|
1822
|
+
LIMIT 1
|
|
1823
|
+
) AS \`p\`
|
|
1824
|
+
) WHERE \`storage_type\` IS NULL
|
|
1825
|
+
AND \`name\` NOT LIKE '%"%'
|
|
1826
|
+
AND EXISTS (
|
|
1827
|
+
SELECT 1 FROM \`models\`
|
|
1828
|
+
INNER JOIN \`model_schemas\` ON \`model_schemas\`.\`model_id\` = \`models\`.\`id\`
|
|
1829
|
+
INNER JOIN \`schemas\` ON \`schemas\`.\`id\` = \`model_schemas\`.\`schema_id\`
|
|
1830
|
+
WHERE \`models\`.\`id\` = \`properties\`.\`model_id\`
|
|
1831
|
+
AND \`models\`.\`name\` NOT LIKE '%"%'
|
|
1832
|
+
AND json_valid(\`schemas\`.\`schema_data\`)
|
|
1833
|
+
AND json_type(
|
|
1834
|
+
\`schemas\`.\`schema_data\`,
|
|
1835
|
+
'$.models."' || \`models\`.\`name\` || '".properties."' || \`properties\`.\`name\` || '"'
|
|
1836
|
+
) = 'object'
|
|
1837
|
+
);
|
|
1838
|
+
`;
|
|
1839
|
+
const migrationSql_0019_add_derived_from_uid_to_metadata = `ALTER TABLE \`metadata\` ADD \`derived_from_uid\` text;
|
|
1840
|
+
--> statement-breakpoint
|
|
1841
|
+
UPDATE \`metadata\` SET
|
|
1842
|
+
\`derived_from_uid\` = (
|
|
1843
|
+
SELECT \`source\`.\`uid\`
|
|
1844
|
+
FROM \`metadata\` AS \`source\`
|
|
1845
|
+
WHERE \`source\`.\`version_uid\` = \`metadata\`.\`version_uid\`
|
|
1846
|
+
AND \`source\`.\`property_name\` = 'storageTransactionId'
|
|
1847
|
+
AND \`source\`.\`uid\` IS NOT NULL
|
|
1848
|
+
AND \`source\`.\`property_value\` = \`metadata\`.\`property_value\`
|
|
1849
|
+
ORDER BY COALESCE(\`source\`.\`attestation_created_at\`, \`source\`.\`created_at\`) DESC
|
|
1850
|
+
LIMIT 1
|
|
1851
|
+
),
|
|
1852
|
+
\`attestation_created_at\` = COALESCE(\`attestation_created_at\`, (
|
|
1853
|
+
SELECT \`source\`.\`attestation_created_at\`
|
|
1854
|
+
FROM \`metadata\` AS \`source\`
|
|
1855
|
+
WHERE \`source\`.\`version_uid\` = \`metadata\`.\`version_uid\`
|
|
1856
|
+
AND \`source\`.\`property_name\` = 'storageTransactionId'
|
|
1857
|
+
AND \`source\`.\`uid\` IS NOT NULL
|
|
1858
|
+
AND \`source\`.\`property_value\` = \`metadata\`.\`property_value\`
|
|
1859
|
+
ORDER BY COALESCE(\`source\`.\`attestation_created_at\`, \`source\`.\`created_at\`) DESC
|
|
1860
|
+
LIMIT 1
|
|
1861
|
+
))
|
|
1862
|
+
WHERE \`uid\` IS NULL
|
|
1863
|
+
AND \`ref_value_type\` = 'file'
|
|
1864
|
+
AND \`version_uid\` IS NOT NULL
|
|
1865
|
+
AND \`derived_from_uid\` IS NULL
|
|
1866
|
+
AND EXISTS (
|
|
1867
|
+
SELECT 1
|
|
1868
|
+
FROM \`metadata\` AS \`source\`
|
|
1869
|
+
WHERE \`source\`.\`version_uid\` = \`metadata\`.\`version_uid\`
|
|
1870
|
+
AND \`source\`.\`property_name\` = 'storageTransactionId'
|
|
1871
|
+
AND \`source\`.\`uid\` IS NOT NULL
|
|
1872
|
+
AND \`source\`.\`property_value\` = \`metadata\`.\`property_value\`
|
|
1873
|
+
);
|
|
1874
|
+
`;
|
|
1875
|
+
// Journal JSON file
|
|
1876
|
+
const journalJson = `{
|
|
1877
|
+
"version": "7",
|
|
1878
|
+
"dialect": "sqlite",
|
|
1879
|
+
"entries": [
|
|
1880
|
+
{
|
|
1881
|
+
"idx": 0,
|
|
1882
|
+
"version": "6",
|
|
1883
|
+
"when": 1765976502903,
|
|
1884
|
+
"tag": "0000_married_malice",
|
|
1885
|
+
"breakpoints": true
|
|
1886
|
+
},
|
|
1887
|
+
{
|
|
1888
|
+
"idx": 1,
|
|
1889
|
+
"version": "6",
|
|
1890
|
+
"when": 1766010851770,
|
|
1891
|
+
"tag": "0001_sweet_bruce_banner",
|
|
1892
|
+
"breakpoints": true
|
|
1893
|
+
},
|
|
1894
|
+
{
|
|
1895
|
+
"idx": 2,
|
|
1896
|
+
"version": "6",
|
|
1897
|
+
"when": 1767621120087,
|
|
1898
|
+
"tag": "0002_bitter_proudstar",
|
|
1899
|
+
"breakpoints": true
|
|
1900
|
+
},
|
|
1901
|
+
{
|
|
1902
|
+
"idx": 3,
|
|
1903
|
+
"version": "6",
|
|
1904
|
+
"when": 1768415440282,
|
|
1905
|
+
"tag": "0003_cultured_senator_kelly",
|
|
1906
|
+
"breakpoints": true
|
|
1907
|
+
},
|
|
1908
|
+
{
|
|
1909
|
+
"idx": 4,
|
|
1910
|
+
"version": "6",
|
|
1911
|
+
"when": 1768500000000,
|
|
1912
|
+
"tag": "0004_add_publisher_to_seeds",
|
|
1913
|
+
"breakpoints": true
|
|
1914
|
+
},
|
|
1915
|
+
{
|
|
1916
|
+
"idx": 5,
|
|
1917
|
+
"version": "6",
|
|
1918
|
+
"when": 1772489937031,
|
|
1919
|
+
"tag": "0005_bright_lily_hollister",
|
|
1920
|
+
"breakpoints": true
|
|
1921
|
+
},
|
|
1922
|
+
{
|
|
1923
|
+
"idx": 6,
|
|
1924
|
+
"version": "6",
|
|
1925
|
+
"when": 1772600000000,
|
|
1926
|
+
"tag": "0006_add_publisher_to_versions_and_metadata",
|
|
1927
|
+
"breakpoints": true
|
|
1928
|
+
},
|
|
1929
|
+
{
|
|
1930
|
+
"idx": 7,
|
|
1931
|
+
"version": "6",
|
|
1932
|
+
"when": 1772700000000,
|
|
1933
|
+
"tag": "0007_add_required_to_properties",
|
|
1934
|
+
"breakpoints": true
|
|
1935
|
+
},
|
|
1936
|
+
{
|
|
1937
|
+
"idx": 8,
|
|
1938
|
+
"version": "6",
|
|
1939
|
+
"when": 1772800000000,
|
|
1940
|
+
"tag": "0008_add_revoked_at_to_seeds",
|
|
1941
|
+
"breakpoints": true
|
|
1942
|
+
},
|
|
1943
|
+
{
|
|
1944
|
+
"idx": 9,
|
|
1945
|
+
"version": "6",
|
|
1946
|
+
"when": 1773924021107,
|
|
1947
|
+
"tag": "0009_happy_namor",
|
|
1948
|
+
"breakpoints": true
|
|
1949
|
+
},
|
|
1950
|
+
{
|
|
1951
|
+
"idx": 10,
|
|
1952
|
+
"version": "6",
|
|
1953
|
+
"when": 1774000000000,
|
|
1954
|
+
"tag": "0010_add_arweave_l1_finalize_jobs",
|
|
1955
|
+
"breakpoints": true
|
|
1956
|
+
},
|
|
1957
|
+
{
|
|
1958
|
+
"idx": 11,
|
|
1959
|
+
"version": "6",
|
|
1960
|
+
"when": 1774100000000,
|
|
1961
|
+
"tag": "0011_normalize_placeholder_uids",
|
|
1962
|
+
"breakpoints": true
|
|
1963
|
+
},
|
|
1964
|
+
{
|
|
1965
|
+
"idx": 12,
|
|
1966
|
+
"version": "6",
|
|
1967
|
+
"when": 1774200000000,
|
|
1968
|
+
"tag": "0012_html_embedded_image_co_publish",
|
|
1969
|
+
"breakpoints": true
|
|
1970
|
+
},
|
|
1971
|
+
{
|
|
1972
|
+
"idx": 13,
|
|
1973
|
+
"version": "6",
|
|
1974
|
+
"when": 1774300000000,
|
|
1975
|
+
"tag": "0013_eas_sync_processes",
|
|
1976
|
+
"breakpoints": true
|
|
1977
|
+
},
|
|
1978
|
+
{
|
|
1979
|
+
"idx": 14,
|
|
1980
|
+
"version": "6",
|
|
1981
|
+
"when": 1774400000000,
|
|
1982
|
+
"tag": "0014_add_error_code_to_publish_processes",
|
|
1983
|
+
"breakpoints": true
|
|
1984
|
+
},
|
|
1985
|
+
{
|
|
1986
|
+
"idx": 15,
|
|
1987
|
+
"version": "6",
|
|
1988
|
+
"when": 1774500000000,
|
|
1989
|
+
"tag": "0015_add_model_file_id_to_seeds",
|
|
1990
|
+
"breakpoints": true
|
|
1991
|
+
},
|
|
1992
|
+
{
|
|
1993
|
+
"idx": 16,
|
|
1994
|
+
"version": "6",
|
|
1995
|
+
"when": 1774600000000,
|
|
1996
|
+
"tag": "0016_add_revoked_at_to_metadata",
|
|
1997
|
+
"breakpoints": true
|
|
1998
|
+
},
|
|
1999
|
+
{
|
|
2000
|
+
"idx": 17,
|
|
2001
|
+
"version": "6",
|
|
2002
|
+
"when": 1774700000000,
|
|
2003
|
+
"tag": "0017_add_revoked_at_to_versions",
|
|
2004
|
+
"breakpoints": true
|
|
2005
|
+
},
|
|
2006
|
+
{
|
|
2007
|
+
"idx": 18,
|
|
2008
|
+
"version": "6",
|
|
2009
|
+
"when": 1774800000000,
|
|
2010
|
+
"tag": "0018_add_storage_settings_to_properties",
|
|
2011
|
+
"breakpoints": true
|
|
2012
|
+
},
|
|
2013
|
+
{
|
|
2014
|
+
"idx": 19,
|
|
2015
|
+
"version": "6",
|
|
2016
|
+
"when": 1774900000000,
|
|
2017
|
+
"tag": "0019_add_derived_from_uid_to_metadata",
|
|
2018
|
+
"breakpoints": true
|
|
2019
|
+
}
|
|
2020
|
+
]
|
|
2021
|
+
}`;
|
|
2022
|
+
// Snapshot JSON file - this is large, so we'll import it dynamically if needed
|
|
2023
|
+
// For now, we'll read it from the actual file if ?raw works, otherwise we'll need to embed it
|
|
2024
|
+
const snapshotJson = `{
|
|
2025
|
+
"version": "6",
|
|
2026
|
+
"dialect": "sqlite",
|
|
2027
|
+
"id": "dd5a777b-e1a9-4b35-82c6-b0c2c7a8ef4d",
|
|
2028
|
+
"prevId": "ab739b16-741c-4ac4-b3bc-a894ef2582a1",
|
|
2029
|
+
"tables": {
|
|
2030
|
+
"appState": {
|
|
2031
|
+
"name": "appState",
|
|
2032
|
+
"columns": {
|
|
2033
|
+
"key": {
|
|
2034
|
+
"name": "key",
|
|
2035
|
+
"type": "text",
|
|
2036
|
+
"primaryKey": false,
|
|
2037
|
+
"notNull": false,
|
|
2038
|
+
"autoincrement": false
|
|
2039
|
+
},
|
|
2040
|
+
"value": {
|
|
2041
|
+
"name": "value",
|
|
2042
|
+
"type": "text",
|
|
2043
|
+
"primaryKey": false,
|
|
2044
|
+
"notNull": false,
|
|
2045
|
+
"autoincrement": false
|
|
2046
|
+
},
|
|
2047
|
+
"created_at": {
|
|
2048
|
+
"name": "created_at",
|
|
2049
|
+
"type": "integer",
|
|
2050
|
+
"primaryKey": false,
|
|
2051
|
+
"notNull": false,
|
|
2052
|
+
"autoincrement": false
|
|
2053
|
+
},
|
|
2054
|
+
"updated_at": {
|
|
2055
|
+
"name": "updated_at",
|
|
2056
|
+
"type": "integer",
|
|
2057
|
+
"primaryKey": false,
|
|
2058
|
+
"notNull": false,
|
|
2059
|
+
"autoincrement": false
|
|
2060
|
+
}
|
|
2061
|
+
},
|
|
2062
|
+
"indexes": {
|
|
2063
|
+
"appState_key_unique": {
|
|
2064
|
+
"name": "appState_key_unique",
|
|
2065
|
+
"columns": [
|
|
2066
|
+
"key"
|
|
2067
|
+
],
|
|
2068
|
+
"isUnique": true
|
|
2069
|
+
}
|
|
2070
|
+
},
|
|
2071
|
+
"foreignKeys": {},
|
|
2072
|
+
"compositePrimaryKeys": {},
|
|
2073
|
+
"uniqueConstraints": {},
|
|
2074
|
+
"checkConstraints": {}
|
|
2075
|
+
},
|
|
2076
|
+
"arweave_l1_finalize_jobs": {
|
|
2077
|
+
"name": "arweave_l1_finalize_jobs",
|
|
2078
|
+
"columns": {
|
|
2079
|
+
"id": {
|
|
2080
|
+
"name": "id",
|
|
2081
|
+
"type": "integer",
|
|
2082
|
+
"primaryKey": true,
|
|
2083
|
+
"notNull": true,
|
|
2084
|
+
"autoincrement": true
|
|
2085
|
+
},
|
|
2086
|
+
"seed_local_id": {
|
|
2087
|
+
"name": "seed_local_id",
|
|
2088
|
+
"type": "text",
|
|
2089
|
+
"primaryKey": false,
|
|
2090
|
+
"notNull": true,
|
|
2091
|
+
"autoincrement": false
|
|
2092
|
+
},
|
|
2093
|
+
"data_item_id": {
|
|
2094
|
+
"name": "data_item_id",
|
|
2095
|
+
"type": "text",
|
|
2096
|
+
"primaryKey": false,
|
|
2097
|
+
"notNull": true,
|
|
2098
|
+
"autoincrement": false
|
|
2099
|
+
},
|
|
2100
|
+
"l1_transaction_id": {
|
|
2101
|
+
"name": "l1_transaction_id",
|
|
2102
|
+
"type": "text",
|
|
2103
|
+
"primaryKey": false,
|
|
2104
|
+
"notNull": false,
|
|
2105
|
+
"autoincrement": false
|
|
2106
|
+
},
|
|
2107
|
+
"bundle_id": {
|
|
2108
|
+
"name": "bundle_id",
|
|
2109
|
+
"type": "text",
|
|
2110
|
+
"primaryKey": false,
|
|
2111
|
+
"notNull": false,
|
|
2112
|
+
"autoincrement": false
|
|
2113
|
+
},
|
|
2114
|
+
"version_local_id": {
|
|
2115
|
+
"name": "version_local_id",
|
|
2116
|
+
"type": "text",
|
|
2117
|
+
"primaryKey": false,
|
|
2118
|
+
"notNull": false,
|
|
2119
|
+
"autoincrement": false
|
|
2120
|
+
},
|
|
2121
|
+
"item_property_name": {
|
|
2122
|
+
"name": "item_property_name",
|
|
2123
|
+
"type": "text",
|
|
2124
|
+
"primaryKey": false,
|
|
2125
|
+
"notNull": false,
|
|
2126
|
+
"autoincrement": false
|
|
2127
|
+
},
|
|
2128
|
+
"phase": {
|
|
2129
|
+
"name": "phase",
|
|
2130
|
+
"type": "text",
|
|
2131
|
+
"primaryKey": false,
|
|
2132
|
+
"notNull": true,
|
|
2133
|
+
"autoincrement": false
|
|
2134
|
+
},
|
|
2135
|
+
"status_json": {
|
|
2136
|
+
"name": "status_json",
|
|
2137
|
+
"type": "text",
|
|
2138
|
+
"primaryKey": false,
|
|
2139
|
+
"notNull": false,
|
|
2140
|
+
"autoincrement": false
|
|
2141
|
+
},
|
|
2142
|
+
"error_message": {
|
|
2143
|
+
"name": "error_message",
|
|
2144
|
+
"type": "text",
|
|
2145
|
+
"primaryKey": false,
|
|
2146
|
+
"notNull": false,
|
|
2147
|
+
"autoincrement": false
|
|
2148
|
+
},
|
|
2149
|
+
"created_at": {
|
|
2150
|
+
"name": "created_at",
|
|
2151
|
+
"type": "integer",
|
|
2152
|
+
"primaryKey": false,
|
|
2153
|
+
"notNull": true,
|
|
2154
|
+
"autoincrement": false
|
|
2155
|
+
},
|
|
2156
|
+
"updated_at": {
|
|
2157
|
+
"name": "updated_at",
|
|
2158
|
+
"type": "integer",
|
|
2159
|
+
"primaryKey": false,
|
|
2160
|
+
"notNull": true,
|
|
2161
|
+
"autoincrement": false
|
|
2162
|
+
}
|
|
2163
|
+
},
|
|
2164
|
+
"indexes": {
|
|
2165
|
+
"arweave_l1_finalize_jobs_data_item_id_unique": {
|
|
2166
|
+
"name": "arweave_l1_finalize_jobs_data_item_id_unique",
|
|
2167
|
+
"columns": [
|
|
2168
|
+
"data_item_id"
|
|
2169
|
+
],
|
|
2170
|
+
"isUnique": true
|
|
2171
|
+
}
|
|
2172
|
+
},
|
|
2173
|
+
"foreignKeys": {},
|
|
2174
|
+
"compositePrimaryKeys": {},
|
|
2175
|
+
"uniqueConstraints": {},
|
|
2176
|
+
"checkConstraints": {}
|
|
2177
|
+
},
|
|
2178
|
+
"config": {
|
|
2179
|
+
"name": "config",
|
|
2180
|
+
"columns": {
|
|
2181
|
+
"id": {
|
|
2182
|
+
"name": "id",
|
|
2183
|
+
"type": "integer",
|
|
2184
|
+
"primaryKey": true,
|
|
2185
|
+
"notNull": true,
|
|
2186
|
+
"autoincrement": true
|
|
2187
|
+
},
|
|
2188
|
+
"key": {
|
|
2189
|
+
"name": "key",
|
|
2190
|
+
"type": "text",
|
|
2191
|
+
"primaryKey": false,
|
|
2192
|
+
"notNull": true,
|
|
2193
|
+
"autoincrement": false
|
|
2194
|
+
},
|
|
2195
|
+
"text": {
|
|
2196
|
+
"name": "text",
|
|
2197
|
+
"type": "text",
|
|
2198
|
+
"primaryKey": false,
|
|
2199
|
+
"notNull": false,
|
|
2200
|
+
"autoincrement": false
|
|
2201
|
+
},
|
|
2202
|
+
"json": {
|
|
2203
|
+
"name": "json",
|
|
2204
|
+
"type": "text",
|
|
2205
|
+
"primaryKey": false,
|
|
2206
|
+
"notNull": false,
|
|
2207
|
+
"autoincrement": false
|
|
2208
|
+
},
|
|
2209
|
+
"blob": {
|
|
2210
|
+
"name": "blob",
|
|
2211
|
+
"type": "blob",
|
|
2212
|
+
"primaryKey": false,
|
|
2213
|
+
"notNull": false,
|
|
2214
|
+
"autoincrement": false
|
|
2215
|
+
}
|
|
2216
|
+
},
|
|
2217
|
+
"indexes": {},
|
|
2218
|
+
"foreignKeys": {},
|
|
2219
|
+
"compositePrimaryKeys": {},
|
|
2220
|
+
"uniqueConstraints": {},
|
|
2221
|
+
"checkConstraints": {}
|
|
2222
|
+
},
|
|
2223
|
+
"eas_sync_processes": {
|
|
2224
|
+
"name": "eas_sync_processes",
|
|
2225
|
+
"columns": {
|
|
2226
|
+
"id": {
|
|
2227
|
+
"name": "id",
|
|
2228
|
+
"type": "integer",
|
|
2229
|
+
"primaryKey": true,
|
|
2230
|
+
"notNull": true,
|
|
2231
|
+
"autoincrement": true
|
|
2232
|
+
},
|
|
2233
|
+
"status": {
|
|
2234
|
+
"name": "status",
|
|
2235
|
+
"type": "text",
|
|
2236
|
+
"primaryKey": false,
|
|
2237
|
+
"notNull": true,
|
|
2238
|
+
"autoincrement": false
|
|
2239
|
+
},
|
|
2240
|
+
"started_at": {
|
|
2241
|
+
"name": "started_at",
|
|
2242
|
+
"type": "integer",
|
|
2243
|
+
"primaryKey": false,
|
|
2244
|
+
"notNull": true,
|
|
2245
|
+
"autoincrement": false
|
|
2246
|
+
},
|
|
2247
|
+
"completed_at": {
|
|
2248
|
+
"name": "completed_at",
|
|
2249
|
+
"type": "integer",
|
|
2250
|
+
"primaryKey": false,
|
|
2251
|
+
"notNull": false,
|
|
2252
|
+
"autoincrement": false
|
|
2253
|
+
},
|
|
2254
|
+
"request_payload": {
|
|
2255
|
+
"name": "request_payload",
|
|
2256
|
+
"type": "text",
|
|
2257
|
+
"primaryKey": false,
|
|
2258
|
+
"notNull": true,
|
|
2259
|
+
"autoincrement": false
|
|
2260
|
+
},
|
|
2261
|
+
"error_message": {
|
|
2262
|
+
"name": "error_message",
|
|
2263
|
+
"type": "text",
|
|
2264
|
+
"primaryKey": false,
|
|
2265
|
+
"notNull": false,
|
|
2266
|
+
"autoincrement": false
|
|
2267
|
+
},
|
|
2268
|
+
"error_details": {
|
|
2269
|
+
"name": "error_details",
|
|
2270
|
+
"type": "text",
|
|
2271
|
+
"primaryKey": false,
|
|
2272
|
+
"notNull": false,
|
|
2273
|
+
"autoincrement": false
|
|
2274
|
+
},
|
|
2275
|
+
"persisted_snapshot": {
|
|
2276
|
+
"name": "persisted_snapshot",
|
|
2277
|
+
"type": "text",
|
|
2278
|
+
"primaryKey": false,
|
|
2279
|
+
"notNull": true,
|
|
2280
|
+
"autoincrement": false
|
|
2281
|
+
},
|
|
2282
|
+
"created_at": {
|
|
2283
|
+
"name": "created_at",
|
|
2284
|
+
"type": "integer",
|
|
2285
|
+
"primaryKey": false,
|
|
2286
|
+
"notNull": false,
|
|
2287
|
+
"autoincrement": false
|
|
2288
|
+
},
|
|
2289
|
+
"updated_at": {
|
|
2290
|
+
"name": "updated_at",
|
|
2291
|
+
"type": "integer",
|
|
2292
|
+
"primaryKey": false,
|
|
2293
|
+
"notNull": false,
|
|
2294
|
+
"autoincrement": false
|
|
2295
|
+
}
|
|
2296
|
+
},
|
|
2297
|
+
"indexes": {},
|
|
2298
|
+
"foreignKeys": {},
|
|
2299
|
+
"compositePrimaryKeys": {},
|
|
2300
|
+
"uniqueConstraints": {},
|
|
2301
|
+
"checkConstraints": {}
|
|
2302
|
+
},
|
|
2303
|
+
"html_embedded_image_co_publish": {
|
|
2304
|
+
"name": "html_embedded_image_co_publish",
|
|
2305
|
+
"columns": {
|
|
2306
|
+
"id": {
|
|
2307
|
+
"name": "id",
|
|
2308
|
+
"type": "integer",
|
|
2309
|
+
"primaryKey": true,
|
|
2310
|
+
"notNull": true,
|
|
2311
|
+
"autoincrement": true
|
|
2312
|
+
},
|
|
2313
|
+
"parent_seed_local_id": {
|
|
2314
|
+
"name": "parent_seed_local_id",
|
|
2315
|
+
"type": "text",
|
|
2316
|
+
"primaryKey": false,
|
|
2317
|
+
"notNull": true,
|
|
2318
|
+
"autoincrement": false
|
|
2319
|
+
},
|
|
2320
|
+
"html_seed_local_id": {
|
|
2321
|
+
"name": "html_seed_local_id",
|
|
2322
|
+
"type": "text",
|
|
2323
|
+
"primaryKey": false,
|
|
2324
|
+
"notNull": true,
|
|
2325
|
+
"autoincrement": false
|
|
2326
|
+
},
|
|
2327
|
+
"image_seed_local_id": {
|
|
2328
|
+
"name": "image_seed_local_id",
|
|
2329
|
+
"type": "text",
|
|
2330
|
+
"primaryKey": false,
|
|
2331
|
+
"notNull": true,
|
|
2332
|
+
"autoincrement": false
|
|
2333
|
+
},
|
|
2334
|
+
"stable_key": {
|
|
2335
|
+
"name": "stable_key",
|
|
2336
|
+
"type": "text",
|
|
2337
|
+
"primaryKey": false,
|
|
2338
|
+
"notNull": true,
|
|
2339
|
+
"autoincrement": false
|
|
2340
|
+
},
|
|
2341
|
+
"created_at": {
|
|
2342
|
+
"name": "created_at",
|
|
2343
|
+
"type": "integer",
|
|
2344
|
+
"primaryKey": false,
|
|
2345
|
+
"notNull": true,
|
|
2346
|
+
"autoincrement": false
|
|
2347
|
+
}
|
|
2348
|
+
},
|
|
2349
|
+
"indexes": {
|
|
2350
|
+
"html_embed_co_pub_parent_html_stable": {
|
|
2351
|
+
"name": "html_embed_co_pub_parent_html_stable",
|
|
2352
|
+
"columns": [
|
|
2353
|
+
"parent_seed_local_id",
|
|
2354
|
+
"html_seed_local_id",
|
|
2355
|
+
"stable_key"
|
|
2356
|
+
],
|
|
2357
|
+
"isUnique": true
|
|
2358
|
+
}
|
|
2359
|
+
},
|
|
2360
|
+
"foreignKeys": {},
|
|
2361
|
+
"compositePrimaryKeys": {},
|
|
2362
|
+
"uniqueConstraints": {},
|
|
2363
|
+
"checkConstraints": {}
|
|
2364
|
+
},
|
|
2365
|
+
"metadata": {
|
|
2366
|
+
"name": "metadata",
|
|
2367
|
+
"columns": {
|
|
2368
|
+
"local_id": {
|
|
2369
|
+
"name": "local_id",
|
|
2370
|
+
"type": "text",
|
|
2371
|
+
"primaryKey": false,
|
|
2372
|
+
"notNull": false,
|
|
2373
|
+
"autoincrement": false
|
|
2374
|
+
},
|
|
2375
|
+
"uid": {
|
|
2376
|
+
"name": "uid",
|
|
2377
|
+
"type": "text",
|
|
2378
|
+
"primaryKey": false,
|
|
2379
|
+
"notNull": false,
|
|
2380
|
+
"autoincrement": false
|
|
2381
|
+
},
|
|
2382
|
+
"property_id": {
|
|
2383
|
+
"name": "property_id",
|
|
2384
|
+
"type": "integer",
|
|
2385
|
+
"primaryKey": false,
|
|
2386
|
+
"notNull": false,
|
|
2387
|
+
"autoincrement": false
|
|
2388
|
+
},
|
|
2389
|
+
"property_name": {
|
|
2390
|
+
"name": "property_name",
|
|
2391
|
+
"type": "text",
|
|
2392
|
+
"primaryKey": false,
|
|
2393
|
+
"notNull": false,
|
|
2394
|
+
"autoincrement": false
|
|
2395
|
+
},
|
|
2396
|
+
"property_value": {
|
|
2397
|
+
"name": "property_value",
|
|
2398
|
+
"type": "text",
|
|
2399
|
+
"primaryKey": false,
|
|
2400
|
+
"notNull": false,
|
|
2401
|
+
"autoincrement": false
|
|
2402
|
+
},
|
|
2403
|
+
"schema_uid": {
|
|
2404
|
+
"name": "schema_uid",
|
|
2405
|
+
"type": "text",
|
|
2406
|
+
"primaryKey": false,
|
|
2407
|
+
"notNull": false,
|
|
2408
|
+
"autoincrement": false
|
|
2409
|
+
},
|
|
2410
|
+
"model_type": {
|
|
2411
|
+
"name": "model_type",
|
|
2412
|
+
"type": "text",
|
|
2413
|
+
"primaryKey": false,
|
|
2414
|
+
"notNull": false,
|
|
2415
|
+
"autoincrement": false
|
|
2416
|
+
},
|
|
2417
|
+
"seed_local_id": {
|
|
2418
|
+
"name": "seed_local_id",
|
|
2419
|
+
"type": "text",
|
|
2420
|
+
"primaryKey": false,
|
|
2421
|
+
"notNull": false,
|
|
2422
|
+
"autoincrement": false
|
|
2423
|
+
},
|
|
2424
|
+
"seed_uid": {
|
|
2425
|
+
"name": "seed_uid",
|
|
2426
|
+
"type": "text",
|
|
2427
|
+
"primaryKey": false,
|
|
2428
|
+
"notNull": false,
|
|
2429
|
+
"autoincrement": false
|
|
2430
|
+
},
|
|
2431
|
+
"version_local_id": {
|
|
2432
|
+
"name": "version_local_id",
|
|
2433
|
+
"type": "text",
|
|
2434
|
+
"primaryKey": false,
|
|
2435
|
+
"notNull": false,
|
|
2436
|
+
"autoincrement": false
|
|
2437
|
+
},
|
|
2438
|
+
"version_uid": {
|
|
2439
|
+
"name": "version_uid",
|
|
2440
|
+
"type": "text",
|
|
2441
|
+
"primaryKey": false,
|
|
2442
|
+
"notNull": false,
|
|
2443
|
+
"autoincrement": false
|
|
2444
|
+
},
|
|
2445
|
+
"eas_data_type": {
|
|
2446
|
+
"name": "eas_data_type",
|
|
2447
|
+
"type": "text",
|
|
2448
|
+
"primaryKey": false,
|
|
2449
|
+
"notNull": false,
|
|
2450
|
+
"autoincrement": false
|
|
2451
|
+
},
|
|
2452
|
+
"ref_value_type": {
|
|
2453
|
+
"name": "ref_value_type",
|
|
2454
|
+
"type": "text",
|
|
2455
|
+
"primaryKey": false,
|
|
2456
|
+
"notNull": false,
|
|
2457
|
+
"autoincrement": false
|
|
2458
|
+
},
|
|
2459
|
+
"ref_schema_uid": {
|
|
2460
|
+
"name": "ref_schema_uid",
|
|
2461
|
+
"type": "text",
|
|
2462
|
+
"primaryKey": false,
|
|
2463
|
+
"notNull": false,
|
|
2464
|
+
"autoincrement": false
|
|
2465
|
+
},
|
|
2466
|
+
"ref_seed_type": {
|
|
2467
|
+
"name": "ref_seed_type",
|
|
2468
|
+
"type": "text",
|
|
2469
|
+
"primaryKey": false,
|
|
2470
|
+
"notNull": false,
|
|
2471
|
+
"autoincrement": false
|
|
2472
|
+
},
|
|
2473
|
+
"ref_resolved_value": {
|
|
2474
|
+
"name": "ref_resolved_value",
|
|
2475
|
+
"type": "text",
|
|
2476
|
+
"primaryKey": false,
|
|
2477
|
+
"notNull": false,
|
|
2478
|
+
"autoincrement": false
|
|
2479
|
+
},
|
|
2480
|
+
"ref_resolved_display_value": {
|
|
2481
|
+
"name": "ref_resolved_display_value",
|
|
2482
|
+
"type": "text",
|
|
2483
|
+
"primaryKey": false,
|
|
2484
|
+
"notNull": false,
|
|
2485
|
+
"autoincrement": false
|
|
2486
|
+
},
|
|
2487
|
+
"local_storage_dir": {
|
|
2488
|
+
"name": "local_storage_dir",
|
|
2489
|
+
"type": "text",
|
|
2490
|
+
"primaryKey": false,
|
|
2491
|
+
"notNull": false,
|
|
2492
|
+
"autoincrement": false
|
|
2493
|
+
},
|
|
2494
|
+
"attestation_raw": {
|
|
2495
|
+
"name": "attestation_raw",
|
|
2496
|
+
"type": "text",
|
|
2497
|
+
"primaryKey": false,
|
|
2498
|
+
"notNull": false,
|
|
2499
|
+
"autoincrement": false
|
|
2500
|
+
},
|
|
2501
|
+
"attestation_created_at": {
|
|
2502
|
+
"name": "attestation_created_at",
|
|
2503
|
+
"type": "integer",
|
|
2504
|
+
"primaryKey": false,
|
|
2505
|
+
"notNull": false,
|
|
2506
|
+
"autoincrement": false
|
|
2507
|
+
},
|
|
2508
|
+
"content_hash": {
|
|
2509
|
+
"name": "content_hash",
|
|
2510
|
+
"type": "text",
|
|
2511
|
+
"primaryKey": false,
|
|
2512
|
+
"notNull": false,
|
|
2513
|
+
"autoincrement": false
|
|
2514
|
+
},
|
|
2515
|
+
"created_at": {
|
|
2516
|
+
"name": "created_at",
|
|
2517
|
+
"type": "integer",
|
|
2518
|
+
"primaryKey": false,
|
|
2519
|
+
"notNull": false,
|
|
2520
|
+
"autoincrement": false
|
|
2521
|
+
},
|
|
2522
|
+
"updated_at": {
|
|
2523
|
+
"name": "updated_at",
|
|
2524
|
+
"type": "integer",
|
|
2525
|
+
"primaryKey": false,
|
|
2526
|
+
"notNull": false,
|
|
2527
|
+
"autoincrement": false
|
|
2528
|
+
},
|
|
2529
|
+
"publisher": {
|
|
2530
|
+
"name": "publisher",
|
|
2531
|
+
"type": "text",
|
|
2532
|
+
"primaryKey": false,
|
|
2533
|
+
"notNull": false,
|
|
2534
|
+
"autoincrement": false
|
|
2535
|
+
},
|
|
2536
|
+
"revoked_at": {
|
|
2537
|
+
"name": "revoked_at",
|
|
2538
|
+
"type": "integer",
|
|
2539
|
+
"primaryKey": false,
|
|
2540
|
+
"notNull": false,
|
|
2541
|
+
"autoincrement": false
|
|
2542
|
+
},
|
|
2543
|
+
"derived_from_uid": {
|
|
2544
|
+
"name": "derived_from_uid",
|
|
2545
|
+
"type": "text",
|
|
2546
|
+
"primaryKey": false,
|
|
2547
|
+
"notNull": false,
|
|
2548
|
+
"autoincrement": false
|
|
2549
|
+
}
|
|
2550
|
+
},
|
|
2551
|
+
"indexes": {
|
|
2552
|
+
"metadata_local_id_unique": {
|
|
2553
|
+
"name": "metadata_local_id_unique",
|
|
2554
|
+
"columns": [
|
|
2555
|
+
"local_id"
|
|
2556
|
+
],
|
|
2557
|
+
"isUnique": true
|
|
2558
|
+
}
|
|
2559
|
+
},
|
|
2560
|
+
"foreignKeys": {
|
|
2561
|
+
"metadata_property_id_properties_id_fk": {
|
|
2562
|
+
"name": "metadata_property_id_properties_id_fk",
|
|
2563
|
+
"tableFrom": "metadata",
|
|
2564
|
+
"tableTo": "properties",
|
|
2565
|
+
"columnsFrom": [
|
|
2566
|
+
"property_id"
|
|
2567
|
+
],
|
|
2568
|
+
"columnsTo": [
|
|
2569
|
+
"id"
|
|
2570
|
+
],
|
|
2571
|
+
"onDelete": "no action",
|
|
2572
|
+
"onUpdate": "no action"
|
|
2573
|
+
}
|
|
2574
|
+
},
|
|
2575
|
+
"compositePrimaryKeys": {},
|
|
2576
|
+
"uniqueConstraints": {},
|
|
2577
|
+
"checkConstraints": {}
|
|
2578
|
+
},
|
|
2579
|
+
"models": {
|
|
2580
|
+
"name": "models",
|
|
2581
|
+
"columns": {
|
|
2582
|
+
"id": {
|
|
2583
|
+
"name": "id",
|
|
2584
|
+
"type": "integer",
|
|
2585
|
+
"primaryKey": true,
|
|
2586
|
+
"notNull": true,
|
|
2587
|
+
"autoincrement": true
|
|
2588
|
+
},
|
|
2589
|
+
"name": {
|
|
2590
|
+
"name": "name",
|
|
2591
|
+
"type": "text",
|
|
2592
|
+
"primaryKey": false,
|
|
2593
|
+
"notNull": true,
|
|
2594
|
+
"autoincrement": false
|
|
2595
|
+
},
|
|
2596
|
+
"schema_file_id": {
|
|
2597
|
+
"name": "schema_file_id",
|
|
2598
|
+
"type": "text",
|
|
2599
|
+
"primaryKey": false,
|
|
2600
|
+
"notNull": false,
|
|
2601
|
+
"autoincrement": false
|
|
2602
|
+
},
|
|
2603
|
+
"is_edited": {
|
|
2604
|
+
"name": "is_edited",
|
|
2605
|
+
"type": "integer",
|
|
2606
|
+
"primaryKey": false,
|
|
2607
|
+
"notNull": false,
|
|
2608
|
+
"autoincrement": false
|
|
2609
|
+
}
|
|
2610
|
+
},
|
|
2611
|
+
"indexes": {
|
|
2612
|
+
"unique_schema_file_id": {
|
|
2613
|
+
"name": "unique_schema_file_id",
|
|
2614
|
+
"columns": [
|
|
2615
|
+
"schema_file_id"
|
|
2616
|
+
],
|
|
2617
|
+
"isUnique": true
|
|
2618
|
+
}
|
|
2619
|
+
},
|
|
2620
|
+
"foreignKeys": {},
|
|
2621
|
+
"compositePrimaryKeys": {},
|
|
2622
|
+
"uniqueConstraints": {},
|
|
2623
|
+
"checkConstraints": {}
|
|
2624
|
+
},
|
|
2625
|
+
"properties": {
|
|
2626
|
+
"name": "properties",
|
|
2627
|
+
"columns": {
|
|
2628
|
+
"id": {
|
|
2629
|
+
"name": "id",
|
|
2630
|
+
"type": "integer",
|
|
2631
|
+
"primaryKey": true,
|
|
2632
|
+
"notNull": true,
|
|
2633
|
+
"autoincrement": true
|
|
2634
|
+
},
|
|
2635
|
+
"name": {
|
|
2636
|
+
"name": "name",
|
|
2637
|
+
"type": "text",
|
|
2638
|
+
"primaryKey": false,
|
|
2639
|
+
"notNull": true,
|
|
2640
|
+
"autoincrement": false
|
|
2641
|
+
},
|
|
2642
|
+
"data_type": {
|
|
2643
|
+
"name": "data_type",
|
|
2644
|
+
"type": "text",
|
|
2645
|
+
"primaryKey": false,
|
|
2646
|
+
"notNull": true,
|
|
2647
|
+
"autoincrement": false
|
|
2648
|
+
},
|
|
2649
|
+
"model_id": {
|
|
2650
|
+
"name": "model_id",
|
|
2651
|
+
"type": "integer",
|
|
2652
|
+
"primaryKey": false,
|
|
2653
|
+
"notNull": true,
|
|
2654
|
+
"autoincrement": false
|
|
2655
|
+
},
|
|
2656
|
+
"ref_model_id": {
|
|
2657
|
+
"name": "ref_model_id",
|
|
2658
|
+
"type": "integer",
|
|
2659
|
+
"primaryKey": false,
|
|
2660
|
+
"notNull": false,
|
|
2661
|
+
"autoincrement": false
|
|
2662
|
+
},
|
|
2663
|
+
"ref_value_type": {
|
|
2664
|
+
"name": "ref_value_type",
|
|
2665
|
+
"type": "text",
|
|
2666
|
+
"primaryKey": false,
|
|
2667
|
+
"notNull": false,
|
|
2668
|
+
"autoincrement": false
|
|
2669
|
+
},
|
|
2670
|
+
"schema_file_id": {
|
|
2671
|
+
"name": "schema_file_id",
|
|
2672
|
+
"type": "text",
|
|
2673
|
+
"primaryKey": false,
|
|
2674
|
+
"notNull": false,
|
|
2675
|
+
"autoincrement": false
|
|
2676
|
+
},
|
|
2677
|
+
"is_edited": {
|
|
2678
|
+
"name": "is_edited",
|
|
2679
|
+
"type": "integer",
|
|
2680
|
+
"primaryKey": false,
|
|
2681
|
+
"notNull": false,
|
|
2682
|
+
"autoincrement": false
|
|
2683
|
+
},
|
|
2684
|
+
"required": {
|
|
2685
|
+
"name": "required",
|
|
2686
|
+
"type": "integer",
|
|
2687
|
+
"primaryKey": false,
|
|
2688
|
+
"notNull": false,
|
|
2689
|
+
"autoincrement": false
|
|
2690
|
+
},
|
|
2691
|
+
"storage_type": {
|
|
2692
|
+
"name": "storage_type",
|
|
2693
|
+
"type": "text",
|
|
2694
|
+
"primaryKey": false,
|
|
2695
|
+
"notNull": false,
|
|
2696
|
+
"autoincrement": false
|
|
2697
|
+
},
|
|
2698
|
+
"local_storage_dir": {
|
|
2699
|
+
"name": "local_storage_dir",
|
|
2700
|
+
"type": "text",
|
|
2701
|
+
"primaryKey": false,
|
|
2702
|
+
"notNull": false,
|
|
2703
|
+
"autoincrement": false
|
|
2704
|
+
},
|
|
2705
|
+
"filename_suffix": {
|
|
2706
|
+
"name": "filename_suffix",
|
|
2707
|
+
"type": "text",
|
|
2708
|
+
"primaryKey": false,
|
|
2709
|
+
"notNull": false,
|
|
2710
|
+
"autoincrement": false
|
|
2711
|
+
}
|
|
2712
|
+
},
|
|
2713
|
+
"indexes": {
|
|
2714
|
+
"unique_name_model_id": {
|
|
2715
|
+
"name": "unique_name_model_id",
|
|
2716
|
+
"columns": [
|
|
2717
|
+
"name",
|
|
2718
|
+
"model_id"
|
|
2719
|
+
],
|
|
2720
|
+
"isUnique": true
|
|
2721
|
+
},
|
|
2722
|
+
"unique_property_schema_file_id": {
|
|
2723
|
+
"name": "unique_property_schema_file_id",
|
|
2724
|
+
"columns": [
|
|
2725
|
+
"schema_file_id"
|
|
2726
|
+
],
|
|
2727
|
+
"isUnique": true
|
|
2728
|
+
}
|
|
2729
|
+
},
|
|
2730
|
+
"foreignKeys": {
|
|
2731
|
+
"properties_model_id_models_id_fk": {
|
|
2732
|
+
"name": "properties_model_id_models_id_fk",
|
|
2733
|
+
"tableFrom": "properties",
|
|
2734
|
+
"tableTo": "models",
|
|
2735
|
+
"columnsFrom": [
|
|
2736
|
+
"model_id"
|
|
2737
|
+
],
|
|
2738
|
+
"columnsTo": [
|
|
2739
|
+
"id"
|
|
2740
|
+
],
|
|
2741
|
+
"onDelete": "no action",
|
|
2742
|
+
"onUpdate": "no action"
|
|
2743
|
+
},
|
|
2744
|
+
"properties_ref_model_id_models_id_fk": {
|
|
2745
|
+
"name": "properties_ref_model_id_models_id_fk",
|
|
2746
|
+
"tableFrom": "properties",
|
|
2747
|
+
"tableTo": "models",
|
|
2748
|
+
"columnsFrom": [
|
|
2749
|
+
"ref_model_id"
|
|
2750
|
+
],
|
|
2751
|
+
"columnsTo": [
|
|
2752
|
+
"id"
|
|
2753
|
+
],
|
|
2754
|
+
"onDelete": "no action",
|
|
2755
|
+
"onUpdate": "no action"
|
|
2756
|
+
}
|
|
2757
|
+
},
|
|
2758
|
+
"compositePrimaryKeys": {},
|
|
2759
|
+
"uniqueConstraints": {},
|
|
2760
|
+
"checkConstraints": {}
|
|
2761
|
+
},
|
|
2762
|
+
"model_schemas": {
|
|
2763
|
+
"name": "model_schemas",
|
|
2764
|
+
"columns": {
|
|
2765
|
+
"id": {
|
|
2766
|
+
"name": "id",
|
|
2767
|
+
"type": "integer",
|
|
2768
|
+
"primaryKey": true,
|
|
2769
|
+
"notNull": true,
|
|
2770
|
+
"autoincrement": true
|
|
2771
|
+
},
|
|
2772
|
+
"model_id": {
|
|
2773
|
+
"name": "model_id",
|
|
2774
|
+
"type": "integer",
|
|
2775
|
+
"primaryKey": false,
|
|
2776
|
+
"notNull": false,
|
|
2777
|
+
"autoincrement": false
|
|
2778
|
+
},
|
|
2779
|
+
"schema_id": {
|
|
2780
|
+
"name": "schema_id",
|
|
2781
|
+
"type": "integer",
|
|
2782
|
+
"primaryKey": false,
|
|
2783
|
+
"notNull": false,
|
|
2784
|
+
"autoincrement": false
|
|
2785
|
+
}
|
|
2786
|
+
},
|
|
2787
|
+
"indexes": {},
|
|
2788
|
+
"foreignKeys": {
|
|
2789
|
+
"model_schemas_model_id_models_id_fk": {
|
|
2790
|
+
"name": "model_schemas_model_id_models_id_fk",
|
|
2791
|
+
"tableFrom": "model_schemas",
|
|
2792
|
+
"tableTo": "models",
|
|
2793
|
+
"columnsFrom": [
|
|
2794
|
+
"model_id"
|
|
2795
|
+
],
|
|
2796
|
+
"columnsTo": [
|
|
2797
|
+
"id"
|
|
2798
|
+
],
|
|
2799
|
+
"onDelete": "no action",
|
|
2800
|
+
"onUpdate": "no action"
|
|
2801
|
+
},
|
|
2802
|
+
"model_schemas_schema_id_schemas_id_fk": {
|
|
2803
|
+
"name": "model_schemas_schema_id_schemas_id_fk",
|
|
2804
|
+
"tableFrom": "model_schemas",
|
|
2805
|
+
"tableTo": "schemas",
|
|
2806
|
+
"columnsFrom": [
|
|
2807
|
+
"schema_id"
|
|
2808
|
+
],
|
|
2809
|
+
"columnsTo": [
|
|
2810
|
+
"id"
|
|
2811
|
+
],
|
|
2812
|
+
"onDelete": "no action",
|
|
2813
|
+
"onUpdate": "no action"
|
|
2814
|
+
}
|
|
2815
|
+
},
|
|
2816
|
+
"compositePrimaryKeys": {},
|
|
2817
|
+
"uniqueConstraints": {},
|
|
2818
|
+
"checkConstraints": {}
|
|
2819
|
+
},
|
|
2820
|
+
"model_uids": {
|
|
2821
|
+
"name": "model_uids",
|
|
2822
|
+
"columns": {
|
|
2823
|
+
"id": {
|
|
2824
|
+
"name": "id",
|
|
2825
|
+
"type": "integer",
|
|
2826
|
+
"primaryKey": true,
|
|
2827
|
+
"notNull": true,
|
|
2828
|
+
"autoincrement": true
|
|
2829
|
+
},
|
|
2830
|
+
"uid": {
|
|
2831
|
+
"name": "uid",
|
|
2832
|
+
"type": "text",
|
|
2833
|
+
"primaryKey": false,
|
|
2834
|
+
"notNull": true,
|
|
2835
|
+
"autoincrement": false
|
|
2836
|
+
},
|
|
2837
|
+
"model_id": {
|
|
2838
|
+
"name": "model_id",
|
|
2839
|
+
"type": "integer",
|
|
2840
|
+
"primaryKey": false,
|
|
2841
|
+
"notNull": true,
|
|
2842
|
+
"autoincrement": false
|
|
2843
|
+
}
|
|
2844
|
+
},
|
|
2845
|
+
"indexes": {
|
|
2846
|
+
"model_uids_model_id_unique": {
|
|
2847
|
+
"name": "model_uids_model_id_unique",
|
|
2848
|
+
"columns": [
|
|
2849
|
+
"model_id"
|
|
2850
|
+
],
|
|
2851
|
+
"isUnique": true
|
|
2852
|
+
}
|
|
2853
|
+
},
|
|
2854
|
+
"foreignKeys": {
|
|
2855
|
+
"model_uids_model_id_models_id_fk": {
|
|
2856
|
+
"name": "model_uids_model_id_models_id_fk",
|
|
2857
|
+
"tableFrom": "model_uids",
|
|
2858
|
+
"tableTo": "models",
|
|
2859
|
+
"columnsFrom": [
|
|
2860
|
+
"model_id"
|
|
2861
|
+
],
|
|
2862
|
+
"columnsTo": [
|
|
2863
|
+
"id"
|
|
2864
|
+
],
|
|
2865
|
+
"onDelete": "no action",
|
|
2866
|
+
"onUpdate": "no action"
|
|
2867
|
+
}
|
|
2868
|
+
},
|
|
2869
|
+
"compositePrimaryKeys": {},
|
|
2870
|
+
"uniqueConstraints": {},
|
|
2871
|
+
"checkConstraints": {}
|
|
2872
|
+
},
|
|
2873
|
+
"property_uids": {
|
|
2874
|
+
"name": "property_uids",
|
|
2875
|
+
"columns": {
|
|
2876
|
+
"id": {
|
|
2877
|
+
"name": "id",
|
|
2878
|
+
"type": "integer",
|
|
2879
|
+
"primaryKey": true,
|
|
2880
|
+
"notNull": true,
|
|
2881
|
+
"autoincrement": true
|
|
2882
|
+
},
|
|
2883
|
+
"uid": {
|
|
2884
|
+
"name": "uid",
|
|
2885
|
+
"type": "text",
|
|
2886
|
+
"primaryKey": false,
|
|
2887
|
+
"notNull": true,
|
|
2888
|
+
"autoincrement": false
|
|
2889
|
+
},
|
|
2890
|
+
"property_id": {
|
|
2891
|
+
"name": "property_id",
|
|
2892
|
+
"type": "integer",
|
|
2893
|
+
"primaryKey": false,
|
|
2894
|
+
"notNull": true,
|
|
2895
|
+
"autoincrement": false
|
|
2896
|
+
}
|
|
2897
|
+
},
|
|
2898
|
+
"indexes": {
|
|
2899
|
+
"property_uids_property_id_unique": {
|
|
2900
|
+
"name": "property_uids_property_id_unique",
|
|
2901
|
+
"columns": [
|
|
2902
|
+
"property_id"
|
|
2903
|
+
],
|
|
2904
|
+
"isUnique": true
|
|
2905
|
+
}
|
|
2906
|
+
},
|
|
2907
|
+
"foreignKeys": {
|
|
2908
|
+
"property_uids_property_id_properties_id_fk": {
|
|
2909
|
+
"name": "property_uids_property_id_properties_id_fk",
|
|
2910
|
+
"tableFrom": "property_uids",
|
|
2911
|
+
"tableTo": "properties",
|
|
2912
|
+
"columnsFrom": [
|
|
2913
|
+
"property_id"
|
|
2914
|
+
],
|
|
2915
|
+
"columnsTo": [
|
|
2916
|
+
"id"
|
|
2917
|
+
],
|
|
2918
|
+
"onDelete": "no action",
|
|
2919
|
+
"onUpdate": "no action"
|
|
2920
|
+
}
|
|
2921
|
+
},
|
|
2922
|
+
"compositePrimaryKeys": {},
|
|
2923
|
+
"uniqueConstraints": {},
|
|
2924
|
+
"checkConstraints": {}
|
|
2925
|
+
},
|
|
2926
|
+
"publish_processes": {
|
|
2927
|
+
"name": "publish_processes",
|
|
2928
|
+
"columns": {
|
|
2929
|
+
"id": {
|
|
2930
|
+
"name": "id",
|
|
2931
|
+
"type": "integer",
|
|
2932
|
+
"primaryKey": true,
|
|
2933
|
+
"notNull": true,
|
|
2934
|
+
"autoincrement": true
|
|
2935
|
+
},
|
|
2936
|
+
"seed_local_id": {
|
|
2937
|
+
"name": "seed_local_id",
|
|
2938
|
+
"type": "text",
|
|
2939
|
+
"primaryKey": false,
|
|
2940
|
+
"notNull": true,
|
|
2941
|
+
"autoincrement": false
|
|
2942
|
+
},
|
|
2943
|
+
"model_name": {
|
|
2944
|
+
"name": "model_name",
|
|
2945
|
+
"type": "text",
|
|
2946
|
+
"primaryKey": false,
|
|
2947
|
+
"notNull": true,
|
|
2948
|
+
"autoincrement": false
|
|
2949
|
+
},
|
|
2950
|
+
"schema_id": {
|
|
2951
|
+
"name": "schema_id",
|
|
2952
|
+
"type": "text",
|
|
2953
|
+
"primaryKey": false,
|
|
2954
|
+
"notNull": false,
|
|
2955
|
+
"autoincrement": false
|
|
2956
|
+
},
|
|
2957
|
+
"status": {
|
|
2958
|
+
"name": "status",
|
|
2959
|
+
"type": "text",
|
|
2960
|
+
"primaryKey": false,
|
|
2961
|
+
"notNull": true,
|
|
2962
|
+
"autoincrement": false
|
|
2963
|
+
},
|
|
2964
|
+
"started_at": {
|
|
2965
|
+
"name": "started_at",
|
|
2966
|
+
"type": "integer",
|
|
2967
|
+
"primaryKey": false,
|
|
2968
|
+
"notNull": true,
|
|
2969
|
+
"autoincrement": false
|
|
2970
|
+
},
|
|
2971
|
+
"completed_at": {
|
|
2972
|
+
"name": "completed_at",
|
|
2973
|
+
"type": "integer",
|
|
2974
|
+
"primaryKey": false,
|
|
2975
|
+
"notNull": false,
|
|
2976
|
+
"autoincrement": false
|
|
2977
|
+
},
|
|
2978
|
+
"error_message": {
|
|
2979
|
+
"name": "error_message",
|
|
2980
|
+
"type": "text",
|
|
2981
|
+
"primaryKey": false,
|
|
2982
|
+
"notNull": false,
|
|
2983
|
+
"autoincrement": false
|
|
2984
|
+
},
|
|
2985
|
+
"error_step": {
|
|
2986
|
+
"name": "error_step",
|
|
2987
|
+
"type": "text",
|
|
2988
|
+
"primaryKey": false,
|
|
2989
|
+
"notNull": false,
|
|
2990
|
+
"autoincrement": false
|
|
2991
|
+
},
|
|
2992
|
+
"error_details": {
|
|
2993
|
+
"name": "error_details",
|
|
2994
|
+
"type": "text",
|
|
2995
|
+
"primaryKey": false,
|
|
2996
|
+
"notNull": false,
|
|
2997
|
+
"autoincrement": false
|
|
2998
|
+
},
|
|
2999
|
+
"error_code": {
|
|
3000
|
+
"name": "error_code",
|
|
3001
|
+
"type": "text",
|
|
3002
|
+
"primaryKey": false,
|
|
3003
|
+
"notNull": false,
|
|
3004
|
+
"autoincrement": false
|
|
3005
|
+
},
|
|
3006
|
+
"persisted_snapshot": {
|
|
3007
|
+
"name": "persisted_snapshot",
|
|
3008
|
+
"type": "text",
|
|
3009
|
+
"primaryKey": false,
|
|
3010
|
+
"notNull": true,
|
|
3011
|
+
"autoincrement": false
|
|
3012
|
+
},
|
|
3013
|
+
"seed_id": {
|
|
3014
|
+
"name": "seed_id",
|
|
3015
|
+
"type": "text",
|
|
3016
|
+
"primaryKey": false,
|
|
3017
|
+
"notNull": false,
|
|
3018
|
+
"autoincrement": false
|
|
3019
|
+
},
|
|
3020
|
+
"existing_seed_uid": {
|
|
3021
|
+
"name": "existing_seed_uid",
|
|
3022
|
+
"type": "text",
|
|
3023
|
+
"primaryKey": false,
|
|
3024
|
+
"notNull": false,
|
|
3025
|
+
"autoincrement": false
|
|
3026
|
+
},
|
|
3027
|
+
"created_at": {
|
|
3028
|
+
"name": "created_at",
|
|
3029
|
+
"type": "integer",
|
|
3030
|
+
"primaryKey": false,
|
|
3031
|
+
"notNull": false,
|
|
3032
|
+
"autoincrement": false
|
|
3033
|
+
},
|
|
3034
|
+
"updated_at": {
|
|
3035
|
+
"name": "updated_at",
|
|
3036
|
+
"type": "integer",
|
|
3037
|
+
"primaryKey": false,
|
|
3038
|
+
"notNull": false,
|
|
3039
|
+
"autoincrement": false
|
|
3040
|
+
}
|
|
3041
|
+
},
|
|
3042
|
+
"indexes": {},
|
|
3043
|
+
"foreignKeys": {},
|
|
3044
|
+
"compositePrimaryKeys": {},
|
|
3045
|
+
"uniqueConstraints": {},
|
|
3046
|
+
"checkConstraints": {}
|
|
3047
|
+
},
|
|
3048
|
+
"schemas": {
|
|
3049
|
+
"name": "schemas",
|
|
3050
|
+
"columns": {
|
|
3051
|
+
"id": {
|
|
3052
|
+
"name": "id",
|
|
3053
|
+
"type": "integer",
|
|
3054
|
+
"primaryKey": true,
|
|
3055
|
+
"notNull": true,
|
|
3056
|
+
"autoincrement": true
|
|
3057
|
+
},
|
|
3058
|
+
"name": {
|
|
3059
|
+
"name": "name",
|
|
3060
|
+
"type": "text",
|
|
3061
|
+
"primaryKey": false,
|
|
3062
|
+
"notNull": true,
|
|
3063
|
+
"autoincrement": false
|
|
3064
|
+
},
|
|
3065
|
+
"version": {
|
|
3066
|
+
"name": "version",
|
|
3067
|
+
"type": "integer",
|
|
3068
|
+
"primaryKey": false,
|
|
3069
|
+
"notNull": true,
|
|
3070
|
+
"autoincrement": false
|
|
3071
|
+
},
|
|
3072
|
+
"schema_file_id": {
|
|
3073
|
+
"name": "schema_file_id",
|
|
3074
|
+
"type": "text",
|
|
3075
|
+
"primaryKey": false,
|
|
3076
|
+
"notNull": false,
|
|
3077
|
+
"autoincrement": false
|
|
3078
|
+
},
|
|
3079
|
+
"schema_data": {
|
|
3080
|
+
"name": "schema_data",
|
|
3081
|
+
"type": "text",
|
|
3082
|
+
"primaryKey": false,
|
|
3083
|
+
"notNull": false,
|
|
3084
|
+
"autoincrement": false
|
|
3085
|
+
},
|
|
3086
|
+
"is_draft": {
|
|
3087
|
+
"name": "is_draft",
|
|
3088
|
+
"type": "integer",
|
|
3089
|
+
"primaryKey": false,
|
|
3090
|
+
"notNull": false,
|
|
3091
|
+
"autoincrement": false
|
|
3092
|
+
},
|
|
3093
|
+
"is_edited": {
|
|
3094
|
+
"name": "is_edited",
|
|
3095
|
+
"type": "integer",
|
|
3096
|
+
"primaryKey": false,
|
|
3097
|
+
"notNull": false,
|
|
3098
|
+
"autoincrement": false
|
|
3099
|
+
},
|
|
3100
|
+
"created_at": {
|
|
3101
|
+
"name": "created_at",
|
|
3102
|
+
"type": "integer",
|
|
3103
|
+
"primaryKey": false,
|
|
3104
|
+
"notNull": false,
|
|
3105
|
+
"autoincrement": false
|
|
3106
|
+
},
|
|
3107
|
+
"updated_at": {
|
|
3108
|
+
"name": "updated_at",
|
|
3109
|
+
"type": "integer",
|
|
3110
|
+
"primaryKey": false,
|
|
3111
|
+
"notNull": false,
|
|
3112
|
+
"autoincrement": false
|
|
3113
|
+
}
|
|
3114
|
+
},
|
|
3115
|
+
"indexes": {
|
|
3116
|
+
"unique_schema_schema_file_id": {
|
|
3117
|
+
"name": "unique_schema_schema_file_id",
|
|
3118
|
+
"columns": [
|
|
3119
|
+
"schema_file_id"
|
|
3120
|
+
],
|
|
3121
|
+
"isUnique": true
|
|
3122
|
+
}
|
|
3123
|
+
},
|
|
3124
|
+
"foreignKeys": {},
|
|
3125
|
+
"compositePrimaryKeys": {},
|
|
3126
|
+
"uniqueConstraints": {},
|
|
3127
|
+
"checkConstraints": {}
|
|
3128
|
+
},
|
|
3129
|
+
"seeds": {
|
|
3130
|
+
"name": "seeds",
|
|
3131
|
+
"columns": {
|
|
3132
|
+
"local_id": {
|
|
3133
|
+
"name": "local_id",
|
|
3134
|
+
"type": "text",
|
|
3135
|
+
"primaryKey": false,
|
|
3136
|
+
"notNull": false,
|
|
3137
|
+
"autoincrement": false
|
|
3138
|
+
},
|
|
3139
|
+
"uid": {
|
|
3140
|
+
"name": "uid",
|
|
3141
|
+
"type": "text",
|
|
3142
|
+
"primaryKey": false,
|
|
3143
|
+
"notNull": false,
|
|
3144
|
+
"autoincrement": false
|
|
3145
|
+
},
|
|
3146
|
+
"schema_uid": {
|
|
3147
|
+
"name": "schema_uid",
|
|
3148
|
+
"type": "text",
|
|
3149
|
+
"primaryKey": false,
|
|
3150
|
+
"notNull": false,
|
|
3151
|
+
"autoincrement": false
|
|
3152
|
+
},
|
|
3153
|
+
"type": {
|
|
3154
|
+
"name": "type",
|
|
3155
|
+
"type": "text",
|
|
3156
|
+
"primaryKey": false,
|
|
3157
|
+
"notNull": false,
|
|
3158
|
+
"autoincrement": false
|
|
3159
|
+
},
|
|
3160
|
+
"model_file_id": {
|
|
3161
|
+
"name": "model_file_id",
|
|
3162
|
+
"type": "text",
|
|
3163
|
+
"primaryKey": false,
|
|
3164
|
+
"notNull": false,
|
|
3165
|
+
"autoincrement": false
|
|
3166
|
+
},
|
|
3167
|
+
"publisher": {
|
|
3168
|
+
"name": "publisher",
|
|
3169
|
+
"type": "text",
|
|
3170
|
+
"primaryKey": false,
|
|
3171
|
+
"notNull": false,
|
|
3172
|
+
"autoincrement": false
|
|
3173
|
+
},
|
|
3174
|
+
"attestation_raw": {
|
|
3175
|
+
"name": "attestation_raw",
|
|
3176
|
+
"type": "text",
|
|
3177
|
+
"primaryKey": false,
|
|
3178
|
+
"notNull": false,
|
|
3179
|
+
"autoincrement": false
|
|
3180
|
+
},
|
|
3181
|
+
"attestation_created_at": {
|
|
3182
|
+
"name": "attestation_created_at",
|
|
3183
|
+
"type": "integer",
|
|
3184
|
+
"primaryKey": false,
|
|
3185
|
+
"notNull": false,
|
|
3186
|
+
"autoincrement": false
|
|
3187
|
+
},
|
|
3188
|
+
"created_at": {
|
|
3189
|
+
"name": "created_at",
|
|
3190
|
+
"type": "integer",
|
|
3191
|
+
"primaryKey": false,
|
|
3192
|
+
"notNull": false,
|
|
3193
|
+
"autoincrement": false
|
|
3194
|
+
},
|
|
3195
|
+
"updated_at": {
|
|
3196
|
+
"name": "updated_at",
|
|
3197
|
+
"type": "integer",
|
|
3198
|
+
"primaryKey": false,
|
|
3199
|
+
"notNull": false,
|
|
3200
|
+
"autoincrement": false
|
|
3201
|
+
},
|
|
3202
|
+
"_marked_for_deletion": {
|
|
3203
|
+
"name": "_marked_for_deletion",
|
|
3204
|
+
"type": "integer",
|
|
3205
|
+
"primaryKey": false,
|
|
3206
|
+
"notNull": false,
|
|
3207
|
+
"autoincrement": false
|
|
3208
|
+
},
|
|
3209
|
+
"revoked_at": {
|
|
3210
|
+
"name": "revoked_at",
|
|
3211
|
+
"type": "integer",
|
|
3212
|
+
"primaryKey": false,
|
|
3213
|
+
"notNull": false,
|
|
3214
|
+
"autoincrement": false
|
|
3215
|
+
}
|
|
3216
|
+
},
|
|
3217
|
+
"indexes": {
|
|
3218
|
+
"seeds_local_id_unique": {
|
|
3219
|
+
"name": "seeds_local_id_unique",
|
|
3220
|
+
"columns": [
|
|
3221
|
+
"local_id"
|
|
3222
|
+
],
|
|
3223
|
+
"isUnique": true
|
|
3224
|
+
}
|
|
3225
|
+
},
|
|
3226
|
+
"foreignKeys": {},
|
|
3227
|
+
"compositePrimaryKeys": {},
|
|
3228
|
+
"uniqueConstraints": {},
|
|
3229
|
+
"checkConstraints": {}
|
|
3230
|
+
},
|
|
3231
|
+
"upload_processes": {
|
|
3232
|
+
"name": "upload_processes",
|
|
3233
|
+
"columns": {
|
|
3234
|
+
"id": {
|
|
3235
|
+
"name": "id",
|
|
3236
|
+
"type": "integer",
|
|
3237
|
+
"primaryKey": true,
|
|
3238
|
+
"notNull": true,
|
|
3239
|
+
"autoincrement": true
|
|
3240
|
+
},
|
|
3241
|
+
"reimbursement_confirmed": {
|
|
3242
|
+
"name": "reimbursement_confirmed",
|
|
3243
|
+
"type": "integer",
|
|
3244
|
+
"primaryKey": false,
|
|
3245
|
+
"notNull": true,
|
|
3246
|
+
"autoincrement": false
|
|
3247
|
+
},
|
|
3248
|
+
"reimbursement_transaction_id": {
|
|
3249
|
+
"name": "reimbursement_transaction_id",
|
|
3250
|
+
"type": "text",
|
|
3251
|
+
"primaryKey": false,
|
|
3252
|
+
"notNull": false,
|
|
3253
|
+
"autoincrement": false
|
|
3254
|
+
},
|
|
3255
|
+
"transaction_keys": {
|
|
3256
|
+
"name": "transaction_keys",
|
|
3257
|
+
"type": "text",
|
|
3258
|
+
"primaryKey": false,
|
|
3259
|
+
"notNull": false,
|
|
3260
|
+
"autoincrement": false
|
|
3261
|
+
},
|
|
3262
|
+
"persisted_snapshot": {
|
|
3263
|
+
"name": "persisted_snapshot",
|
|
3264
|
+
"type": "text",
|
|
3265
|
+
"primaryKey": false,
|
|
3266
|
+
"notNull": true,
|
|
3267
|
+
"autoincrement": false
|
|
3268
|
+
},
|
|
3269
|
+
"created_at": {
|
|
3270
|
+
"name": "created_at",
|
|
3271
|
+
"type": "integer",
|
|
3272
|
+
"primaryKey": false,
|
|
3273
|
+
"notNull": false,
|
|
3274
|
+
"autoincrement": false
|
|
3275
|
+
},
|
|
3276
|
+
"updated_at": {
|
|
3277
|
+
"name": "updated_at",
|
|
3278
|
+
"type": "integer",
|
|
3279
|
+
"primaryKey": false,
|
|
3280
|
+
"notNull": false,
|
|
3281
|
+
"autoincrement": false
|
|
3282
|
+
}
|
|
3283
|
+
},
|
|
3284
|
+
"indexes": {},
|
|
3285
|
+
"foreignKeys": {},
|
|
3286
|
+
"compositePrimaryKeys": {},
|
|
3287
|
+
"uniqueConstraints": {},
|
|
3288
|
+
"checkConstraints": {}
|
|
3289
|
+
},
|
|
3290
|
+
"versions": {
|
|
3291
|
+
"name": "versions",
|
|
3292
|
+
"columns": {
|
|
3293
|
+
"local_id": {
|
|
3294
|
+
"name": "local_id",
|
|
3295
|
+
"type": "text",
|
|
3296
|
+
"primaryKey": false,
|
|
3297
|
+
"notNull": false,
|
|
3298
|
+
"autoincrement": false
|
|
3299
|
+
},
|
|
3300
|
+
"uid": {
|
|
3301
|
+
"name": "uid",
|
|
3302
|
+
"type": "text",
|
|
3303
|
+
"primaryKey": false,
|
|
3304
|
+
"notNull": false,
|
|
3305
|
+
"autoincrement": false
|
|
3306
|
+
},
|
|
3307
|
+
"seed_local_id": {
|
|
3308
|
+
"name": "seed_local_id",
|
|
3309
|
+
"type": "text",
|
|
3310
|
+
"primaryKey": false,
|
|
3311
|
+
"notNull": false,
|
|
3312
|
+
"autoincrement": false
|
|
3313
|
+
},
|
|
3314
|
+
"seed_uid": {
|
|
3315
|
+
"name": "seed_uid",
|
|
3316
|
+
"type": "text",
|
|
3317
|
+
"primaryKey": false,
|
|
3318
|
+
"notNull": false,
|
|
3319
|
+
"autoincrement": false
|
|
3320
|
+
},
|
|
3321
|
+
"seed_type": {
|
|
3322
|
+
"name": "seed_type",
|
|
3323
|
+
"type": "text",
|
|
3324
|
+
"primaryKey": false,
|
|
3325
|
+
"notNull": false,
|
|
3326
|
+
"autoincrement": false
|
|
3327
|
+
},
|
|
3328
|
+
"note": {
|
|
3329
|
+
"name": "note",
|
|
3330
|
+
"type": "text",
|
|
3331
|
+
"primaryKey": false,
|
|
3332
|
+
"notNull": false,
|
|
3333
|
+
"autoincrement": false
|
|
3334
|
+
},
|
|
3335
|
+
"created_at": {
|
|
3336
|
+
"name": "created_at",
|
|
3337
|
+
"type": "integer",
|
|
3338
|
+
"primaryKey": false,
|
|
3339
|
+
"notNull": false,
|
|
3340
|
+
"autoincrement": false
|
|
3341
|
+
},
|
|
3342
|
+
"updated_at": {
|
|
3343
|
+
"name": "updated_at",
|
|
3344
|
+
"type": "integer",
|
|
3345
|
+
"primaryKey": false,
|
|
3346
|
+
"notNull": false,
|
|
3347
|
+
"autoincrement": false
|
|
3348
|
+
},
|
|
3349
|
+
"attestation_created_at": {
|
|
3350
|
+
"name": "attestation_created_at",
|
|
3351
|
+
"type": "integer",
|
|
3352
|
+
"primaryKey": false,
|
|
3353
|
+
"notNull": false,
|
|
3354
|
+
"autoincrement": false
|
|
3355
|
+
},
|
|
3356
|
+
"attestation_raw": {
|
|
3357
|
+
"name": "attestation_raw",
|
|
3358
|
+
"type": "text",
|
|
3359
|
+
"primaryKey": false,
|
|
3360
|
+
"notNull": false,
|
|
3361
|
+
"autoincrement": false
|
|
3362
|
+
},
|
|
3363
|
+
"publisher": {
|
|
3364
|
+
"name": "publisher",
|
|
3365
|
+
"type": "text",
|
|
3366
|
+
"primaryKey": false,
|
|
3367
|
+
"notNull": false,
|
|
3368
|
+
"autoincrement": false
|
|
3369
|
+
},
|
|
3370
|
+
"revoked_at": {
|
|
3371
|
+
"name": "revoked_at",
|
|
3372
|
+
"type": "integer",
|
|
3373
|
+
"primaryKey": false,
|
|
3374
|
+
"notNull": false,
|
|
3375
|
+
"autoincrement": false
|
|
3376
|
+
}
|
|
3377
|
+
},
|
|
3378
|
+
"indexes": {
|
|
3379
|
+
"versions_local_id_unique": {
|
|
3380
|
+
"name": "versions_local_id_unique",
|
|
3381
|
+
"columns": [
|
|
3382
|
+
"local_id"
|
|
3383
|
+
],
|
|
3384
|
+
"isUnique": true
|
|
3385
|
+
}
|
|
3386
|
+
},
|
|
3387
|
+
"foreignKeys": {},
|
|
3388
|
+
"compositePrimaryKeys": {},
|
|
3389
|
+
"uniqueConstraints": {},
|
|
3390
|
+
"checkConstraints": {}
|
|
3391
|
+
}
|
|
3392
|
+
},
|
|
3393
|
+
"views": {},
|
|
3394
|
+
"enums": {},
|
|
3395
|
+
"_meta": {
|
|
3396
|
+
"schemas": {},
|
|
3397
|
+
"tables": {},
|
|
3398
|
+
"columns": {}
|
|
3399
|
+
},
|
|
3400
|
+
"internal": {
|
|
3401
|
+
"indexes": {}
|
|
3402
|
+
}
|
|
3403
|
+
}`;
|
|
3404
|
+
|
|
3405
|
+
var drizzleFiles = /*#__PURE__*/Object.freeze({
|
|
3406
|
+
__proto__: null,
|
|
3407
|
+
journalJson: journalJson,
|
|
3408
|
+
migrationSql_0000_married_malice: migrationSql_0000_married_malice,
|
|
3409
|
+
migrationSql_0001_sweet_bruce_banner: migrationSql_0001_sweet_bruce_banner,
|
|
3410
|
+
migrationSql_0002_bitter_proudstar: migrationSql_0002_bitter_proudstar,
|
|
3411
|
+
migrationSql_0003_cultured_senator_kelly: migrationSql_0003_cultured_senator_kelly,
|
|
3412
|
+
migrationSql_0004_add_publisher_to_seeds: migrationSql_0004_add_publisher_to_seeds,
|
|
3413
|
+
migrationSql_0005_bright_lily_hollister: migrationSql_0005_bright_lily_hollister,
|
|
3414
|
+
migrationSql_0006_add_publisher_to_versions_and_metadata: migrationSql_0006_add_publisher_to_versions_and_metadata,
|
|
3415
|
+
migrationSql_0007_add_required_to_properties: migrationSql_0007_add_required_to_properties,
|
|
3416
|
+
migrationSql_0008_add_revoked_at_to_seeds: migrationSql_0008_add_revoked_at_to_seeds,
|
|
3417
|
+
migrationSql_0009_happy_namor: migrationSql_0009_happy_namor,
|
|
3418
|
+
migrationSql_0010_add_arweave_l1_finalize_jobs: migrationSql_0010_add_arweave_l1_finalize_jobs,
|
|
3419
|
+
migrationSql_0011_normalize_placeholder_uids: migrationSql_0011_normalize_placeholder_uids,
|
|
3420
|
+
migrationSql_0012_html_embedded_image_co_publish: migrationSql_0012_html_embedded_image_co_publish,
|
|
3421
|
+
migrationSql_0013_eas_sync_processes: migrationSql_0013_eas_sync_processes,
|
|
3422
|
+
migrationSql_0014_add_error_code_to_publish_processes: migrationSql_0014_add_error_code_to_publish_processes,
|
|
3423
|
+
migrationSql_0015_add_model_file_id_to_seeds: migrationSql_0015_add_model_file_id_to_seeds,
|
|
3424
|
+
migrationSql_0016_add_revoked_at_to_metadata: migrationSql_0016_add_revoked_at_to_metadata,
|
|
3425
|
+
migrationSql_0017_add_revoked_at_to_versions: migrationSql_0017_add_revoked_at_to_versions,
|
|
3426
|
+
migrationSql_0018_add_storage_settings_to_properties: migrationSql_0018_add_storage_settings_to_properties,
|
|
3427
|
+
migrationSql_0019_add_derived_from_uid_to_metadata: migrationSql_0019_add_derived_from_uid_to_metadata,
|
|
3428
|
+
snapshotJson: snapshotJson
|
|
3429
|
+
});
|
|
3430
|
+
|
|
3431
|
+
/**
|
|
3432
|
+
* Build drizzle migration metadata from embedded SQL strings.
|
|
3433
|
+
* Avoids `drizzle-orm/migrator` (Node fs / path / crypto) on the browser graph.
|
|
3434
|
+
*/
|
|
3435
|
+
function getEmbeddedMigrations() {
|
|
3436
|
+
const journal = JSON.parse(journalJson);
|
|
3437
|
+
const entries = journal.entries ?? [];
|
|
3438
|
+
return entries.map((entry) => {
|
|
3439
|
+
const varName = `migrationSql_${entry.tag}`;
|
|
3440
|
+
const query = drizzleFiles[varName];
|
|
3441
|
+
if (typeof query !== 'string') {
|
|
3442
|
+
throw new Error(`No embedded migration content for ${entry.tag}`);
|
|
3443
|
+
}
|
|
3444
|
+
const trimmed = query.trim();
|
|
3445
|
+
return {
|
|
3446
|
+
sql: trimmed.split('--> statement-breakpoint'),
|
|
3447
|
+
bps: Boolean(entry.breakpoints),
|
|
3448
|
+
folderMillis: entry.when,
|
|
3449
|
+
hash: bytesToHex(sha256(utf8ToBytes(trimmed))),
|
|
3450
|
+
};
|
|
3451
|
+
});
|
|
3452
|
+
}
|
|
3453
|
+
/** SQLite ignores `PRAGMA foreign_keys` inside a transaction, so such migrations must run outside one. */
|
|
3454
|
+
function canRunInTransaction(migration) {
|
|
3455
|
+
return !migration.sql.some((query) => /^\s*PRAGMA\s+foreign_keys\b/im.test(query));
|
|
3456
|
+
}
|
|
3457
|
+
/**
|
|
3458
|
+
* Same apply loop as drizzle-orm/sqlite-proxy/migrator, with in-memory migrations. Callers sharing
|
|
3459
|
+
* the database across tabs must hold a cross-tab lock: the read of the last applied migration and
|
|
3460
|
+
* the writes that follow aren't atomic.
|
|
3461
|
+
*/
|
|
3462
|
+
async function applyEmbeddedMigrations(db, migrations, migrationsTable = '__drizzle_migrations', runMigration) {
|
|
3463
|
+
await db.run(sql `
|
|
3464
|
+
CREATE TABLE IF NOT EXISTS ${sql.identifier(migrationsTable)} (
|
|
3465
|
+
id SERIAL PRIMARY KEY,
|
|
3466
|
+
hash text NOT NULL,
|
|
3467
|
+
created_at numeric
|
|
3468
|
+
)
|
|
3469
|
+
`);
|
|
3470
|
+
const dbMigrations = await db.values(sql `SELECT id, hash, created_at FROM ${sql.identifier(migrationsTable)} ORDER BY created_at DESC LIMIT 1`);
|
|
3471
|
+
const lastDbMigration = dbMigrations[0] ?? undefined;
|
|
3472
|
+
const runSequentially = async (queries) => {
|
|
3473
|
+
for (const query of queries) {
|
|
3474
|
+
await db.run(sql.raw(query));
|
|
3475
|
+
}
|
|
3476
|
+
};
|
|
3477
|
+
for (const migration of migrations) {
|
|
3478
|
+
if (!lastDbMigration || Number(lastDbMigration[2]) < migration.folderMillis) {
|
|
3479
|
+
const queries = [
|
|
3480
|
+
...migration.sql,
|
|
3481
|
+
`INSERT INTO \`${migrationsTable}\` ("hash", "created_at") VALUES('${migration.hash}', '${migration.folderMillis}')`,
|
|
3482
|
+
];
|
|
3483
|
+
await (runMigration ?? runSequentially)(queries, migration);
|
|
3484
|
+
}
|
|
3485
|
+
}
|
|
3486
|
+
}
|
|
3487
|
+
|
|
3488
|
+
const logger$3 = debug('seedSdk:browser:db:sqliteBusyRetry');
|
|
3489
|
+
/** Waits between attempts; about 1 s in total. */
|
|
3490
|
+
const SQLITE_BUSY_RETRY_DELAYS_MS = [25, 75, 150, 300, 450];
|
|
3491
|
+
/**
|
|
3492
|
+
* Another connection (usually another tab) holds the database lock. SQLite reports this as
|
|
3493
|
+
* SQLITE_BUSY ("database is locked") or SQLITE_LOCKED ("database table is locked").
|
|
3494
|
+
*/
|
|
3495
|
+
function isSqliteBusyError(error) {
|
|
3496
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
3497
|
+
return /SQLITE_BUSY|SQLITE_LOCKED|database (table )?is locked/i.test(message);
|
|
3498
|
+
}
|
|
3499
|
+
/**
|
|
3500
|
+
* Retries a statement another tab's lock rejected. Safe for the SDK's writes because each is a
|
|
3501
|
+
* single autocommit statement: one that failed with SQLITE_BUSY didn't apply. Don't use this for
|
|
3502
|
+
* statements inside a transaction, where a retry would replay part of it.
|
|
3503
|
+
*/
|
|
3504
|
+
function withSqliteBusyRetry(driver, delaysMs = SQLITE_BUSY_RETRY_DELAYS_MS) {
|
|
3505
|
+
return async (...args) => {
|
|
3506
|
+
for (let attempt = 0;; attempt++) {
|
|
3507
|
+
try {
|
|
3508
|
+
return await driver(...args);
|
|
3509
|
+
}
|
|
3510
|
+
catch (error) {
|
|
3511
|
+
if (!isSqliteBusyError(error) || attempt >= delaysMs.length)
|
|
3512
|
+
throw error;
|
|
3513
|
+
logger$3(`database busy (attempt ${attempt + 1}); retrying`);
|
|
3514
|
+
await new Promise((resolve) => setTimeout(resolve, delaysMs[attempt]));
|
|
3515
|
+
}
|
|
3516
|
+
}
|
|
3517
|
+
};
|
|
3518
|
+
}
|
|
3519
|
+
|
|
3520
|
+
const logger$2 = debug('seedSdk:browser:db:createSqlocalDrizzle');
|
|
3521
|
+
/** First sqlocal work can include sqlite-wasm fetch; keep this long to avoid false positives. */
|
|
3522
|
+
const SQLOCAL_FIRST_QUERY_TIMEOUT_MS = 90000;
|
|
3523
|
+
const HTTP_MODULE_WORKER_URL = /^https?:/i;
|
|
3524
|
+
function shouldBlobWrapModuleWorker(scriptURL, options) {
|
|
3525
|
+
const type = options?.type ?? 'classic';
|
|
3526
|
+
if (type !== 'module')
|
|
3527
|
+
return false;
|
|
3528
|
+
return HTTP_MODULE_WORKER_URL.test(String(scriptURL));
|
|
3529
|
+
}
|
|
3530
|
+
function createBlobModuleWorkerSource(scriptURL) {
|
|
3531
|
+
return `import ${JSON.stringify(String(scriptURL))};`;
|
|
3532
|
+
}
|
|
3533
|
+
/**
|
|
3534
|
+
* Construct SQLocal while starting its HTTPS module worker from a blob that
|
|
3535
|
+
* only imports the bundled worker URL. Some Chrome profiles kill
|
|
3536
|
+
* `new Worker(https://…/worker-HASH.js, { type: 'module' })` as an entry
|
|
3537
|
+
* script; importing the same URL from a blob worker reaches connect.
|
|
3538
|
+
*
|
|
3539
|
+
* The `Worker` patch is scoped to `factory()` so Vite still sees sqlocal's
|
|
3540
|
+
* own `new Worker(new URL('./worker', import.meta.url))` and emits a real
|
|
3541
|
+
* worker chunk.
|
|
3542
|
+
*/
|
|
3543
|
+
function createSqlocalDrizzle(factory) {
|
|
3544
|
+
let rejectFailed;
|
|
3545
|
+
const workerFailed = new Promise((_, reject) => {
|
|
3546
|
+
rejectFailed = reject;
|
|
3547
|
+
});
|
|
3548
|
+
// Avoid an unhandled rejection if the caller throws before racing this promise.
|
|
3549
|
+
workerFailed.catch(() => { });
|
|
3550
|
+
const restore = installModuleWorkerBlobWrap((error) => {
|
|
3551
|
+
rejectFailed?.(error);
|
|
3552
|
+
});
|
|
3553
|
+
try {
|
|
3554
|
+
return { instance: factory(), workerFailed };
|
|
3555
|
+
}
|
|
3556
|
+
finally {
|
|
3557
|
+
restore();
|
|
3558
|
+
}
|
|
3559
|
+
}
|
|
3560
|
+
async function raceSqlocalStartup(work, workerFailed, timeoutMs = SQLOCAL_FIRST_QUERY_TIMEOUT_MS) {
|
|
3561
|
+
let timeoutId;
|
|
3562
|
+
const timedOut = new Promise((_, reject) => {
|
|
3563
|
+
timeoutId = setTimeout(() => {
|
|
3564
|
+
reject(new Error(`sqlocal database failed to become ready within ${timeoutMs}ms`));
|
|
3565
|
+
}, timeoutMs);
|
|
3566
|
+
});
|
|
3567
|
+
try {
|
|
3568
|
+
return await Promise.race([work, workerFailed, timedOut]);
|
|
3569
|
+
}
|
|
3570
|
+
finally {
|
|
3571
|
+
if (timeoutId !== undefined) {
|
|
3572
|
+
clearTimeout(timeoutId);
|
|
3573
|
+
}
|
|
3574
|
+
}
|
|
3575
|
+
}
|
|
3576
|
+
function installModuleWorkerBlobWrap(onWorkerFailed) {
|
|
3577
|
+
const OriginalWorker = globalThis.Worker;
|
|
3578
|
+
if (typeof OriginalWorker === 'undefined') {
|
|
3579
|
+
return () => { };
|
|
3580
|
+
}
|
|
3581
|
+
function WrappedWorker(scriptURL, options) {
|
|
3582
|
+
const worker = shouldBlobWrapModuleWorker(scriptURL, options)
|
|
3583
|
+
? new OriginalWorker(URL.createObjectURL(new Blob([createBlobModuleWorkerSource(scriptURL)], {
|
|
3584
|
+
type: 'text/javascript',
|
|
3585
|
+
})), { ...options, type: 'module' })
|
|
3586
|
+
: new OriginalWorker(scriptURL, options);
|
|
3587
|
+
const fail = (event) => {
|
|
3588
|
+
const filename = 'filename' in event && typeof event.filename === 'string'
|
|
3589
|
+
? event.filename
|
|
3590
|
+
: '';
|
|
3591
|
+
const message = 'message' in event && typeof event.message === 'string'
|
|
3592
|
+
? event.message
|
|
3593
|
+
: event.type;
|
|
3594
|
+
const error = new Error(filename
|
|
3595
|
+
? `sqlocal worker failed to start (${event.type}): ${message} [${filename}]`
|
|
3596
|
+
: `sqlocal worker failed to start (${event.type}): ${message}`);
|
|
3597
|
+
logger$2('[createSqlocalDrizzle] worker failed', error.message);
|
|
3598
|
+
onWorkerFailed(error);
|
|
3599
|
+
};
|
|
3600
|
+
worker.addEventListener('error', fail);
|
|
3601
|
+
worker.addEventListener('messageerror', fail);
|
|
3602
|
+
return worker;
|
|
3603
|
+
}
|
|
3604
|
+
WrappedWorker.prototype = OriginalWorker.prototype;
|
|
3605
|
+
Object.setPrototypeOf(WrappedWorker, OriginalWorker);
|
|
3606
|
+
globalThis.Worker = WrappedWorker;
|
|
3607
|
+
return () => {
|
|
3608
|
+
globalThis.Worker = OriginalWorker;
|
|
3609
|
+
};
|
|
3610
|
+
}
|
|
3611
|
+
|
|
3612
|
+
const logger$1 = debug('seedSdk:browser:db:Db');
|
|
3613
|
+
class BrowserDb {
|
|
3614
|
+
getAppDb() {
|
|
3615
|
+
return this.appDb;
|
|
3616
|
+
}
|
|
3617
|
+
isAppDbReady() {
|
|
3618
|
+
return !!this.appDb;
|
|
3619
|
+
}
|
|
3620
|
+
async prepareDb(filesDir) {
|
|
3621
|
+
logger$1('[Db.prepareDb] preparing database');
|
|
3622
|
+
this.filesDir = filesDir;
|
|
3623
|
+
// Another tab may be preparing the same database: run file copies, migrations and the
|
|
3624
|
+
// one-time data fixes one tab at a time. See docs/MULTI_TAB.md.
|
|
3625
|
+
return withSeedDbLock('migrate', filesDir, () => this.prepareDbLocked(filesDir));
|
|
3626
|
+
}
|
|
3627
|
+
async prepareDbLocked(filesDir) {
|
|
3628
|
+
try {
|
|
3629
|
+
// Copy drizzle migration files from src/db/drizzle to filesDir/db
|
|
3630
|
+
await this.copyDrizzleFiles(filesDir);
|
|
3631
|
+
// Ensure meta directory exists
|
|
3632
|
+
const metaDirPath = `${filesDir}/db/meta`;
|
|
3633
|
+
await BaseFileManager.createDirIfNotExists(metaDirPath);
|
|
3634
|
+
// Ensure _journal.json file exists in meta directory
|
|
3635
|
+
const journalFilePath = `${metaDirPath}/_journal.json`;
|
|
3636
|
+
const journalExists = await BaseFileManager.pathExists(journalFilePath);
|
|
3637
|
+
if (!journalExists) {
|
|
3638
|
+
await BaseFileManager.saveFile(journalFilePath, JSON.stringify({
|
|
3639
|
+
version: 1,
|
|
3640
|
+
dialect: 'sqlite',
|
|
3641
|
+
entries: [],
|
|
3642
|
+
}, null, 2));
|
|
3643
|
+
}
|
|
3644
|
+
// Wait for journal file to be fully written before proceeding with migration
|
|
3645
|
+
// This is critical in browser/OPFS where writes may not be immediately readable
|
|
3646
|
+
logger$1('[Db.prepareDb] waiting for journal file to be fully written...');
|
|
3647
|
+
await BaseFileManager.waitForFileWithContent(journalFilePath, 100, 5000);
|
|
3648
|
+
logger$1('[Db.prepareDb] journal file is ready');
|
|
3649
|
+
// Initialize SQLocalDrizzle with reactive: true to enable reactive queries.
|
|
3650
|
+
// Blob-wrap sqlocal's HTTPS module worker so Chrome profiles that kill
|
|
3651
|
+
// `new Worker(https://…/worker-HASH.js, { type: 'module' })` as an entry
|
|
3652
|
+
// still reach connect via `import` of the same URL.
|
|
3653
|
+
const { instance: sqlocalDrizzle, workerFailed } = createSqlocalDrizzle(() => new SQLocalDrizzle({
|
|
3654
|
+
databasePath: `${this.filesDir}/db/seed.db`,
|
|
3655
|
+
reactive: true,
|
|
3656
|
+
}));
|
|
3657
|
+
const { batchDriver } = sqlocalDrizzle;
|
|
3658
|
+
const driver = withSqliteBusyRetry(sqlocalDrizzle.driver);
|
|
3659
|
+
// Store SQLocalDrizzle instance for reactive queries
|
|
3660
|
+
this.sqlocalInstance = sqlocalDrizzle;
|
|
3661
|
+
// Create db instance but do NOT set this.appDb yet. restoreFromDb (and other
|
|
3662
|
+
// callers of getAppDb()) must not see the db until migrations have completed,
|
|
3663
|
+
// otherwise they may query tables (e.g. publish_processes) that don't exist yet.
|
|
3664
|
+
const db = drizzle(driver, batchDriver, {
|
|
3665
|
+
schema,
|
|
3666
|
+
});
|
|
3667
|
+
logger$1('[Db.prepareDb] database prepared');
|
|
3668
|
+
await raceSqlocalStartup((async () => {
|
|
3669
|
+
await this.runMigrations(db);
|
|
3670
|
+
this.appDb = db;
|
|
3671
|
+
const { backfillMetadataPropertyIds } = await import('./backfillMetadataPropertyIds-fG3ujaSh.js');
|
|
3672
|
+
await backfillMetadataPropertyIds();
|
|
3673
|
+
// One-time: clear item data whose model can't be determined (seeds.model_file_id, migration 0015)
|
|
3674
|
+
const { resetAmbiguousLegacyItemData } = await import('./resetAmbiguousLegacyItemData-BqbHNUYk.js');
|
|
3675
|
+
await resetAmbiguousLegacyItemData();
|
|
3676
|
+
})(), workerFailed);
|
|
3677
|
+
return this.appDb;
|
|
3678
|
+
}
|
|
3679
|
+
catch (error) {
|
|
3680
|
+
logger$1('[Db.prepareDb] error', JSON.stringify(error));
|
|
3681
|
+
throw error;
|
|
3682
|
+
}
|
|
3683
|
+
}
|
|
3684
|
+
// static async prepareDb(filesDir: string) {
|
|
3685
|
+
// console.log('prepareDb', filesDir)
|
|
3686
|
+
// if (Db.sqliteWasmClient) {
|
|
3687
|
+
// return this.dbId
|
|
3688
|
+
// }
|
|
3689
|
+
// this.filesDir = filesDir
|
|
3690
|
+
// this.pathToDb = `${filesDir}/db/${DB_NAME_APP}.db`
|
|
3691
|
+
// if (typeof document === 'undefined') {
|
|
3692
|
+
// return
|
|
3693
|
+
// }
|
|
3694
|
+
// let promiser
|
|
3695
|
+
// try {
|
|
3696
|
+
// let sqlite3Worker1Promiser
|
|
3697
|
+
// const sqliteWasm = await import('@sqlite.org/sqlite-wasm')
|
|
3698
|
+
// if (sqliteWasm && sqliteWasm.sqlite3Worker1Promiser) {
|
|
3699
|
+
// sqlite3Worker1Promiser = sqliteWasm.sqlite3Worker1Promiser
|
|
3700
|
+
// }
|
|
3701
|
+
// if (!sqlite3Worker1Promiser && window.sqlite3Worker1Promiser) {
|
|
3702
|
+
// sqlite3Worker1Promiser = window.sqlite3Worker1Promiser
|
|
3703
|
+
// }
|
|
3704
|
+
// if (!sqlite3Worker1Promiser) {
|
|
3705
|
+
// throw new Error('Failed to load sqlite3Worker1Promiser')
|
|
3706
|
+
// }
|
|
3707
|
+
// promiser = await new Promise<(event: string, config: Record<string, unknown>) => Promise<any>>((resolve) => {
|
|
3708
|
+
// const _promiser = sqlite3Worker1Promiser({
|
|
3709
|
+
// onready: () => {
|
|
3710
|
+
// resolve(_promiser);
|
|
3711
|
+
// },
|
|
3712
|
+
// });
|
|
3713
|
+
// }).catch((error) => {
|
|
3714
|
+
// console.error('Error from sqlite proxy server: ', JSON.stringify(error))
|
|
3715
|
+
// });
|
|
3716
|
+
// } catch ( e ) {
|
|
3717
|
+
// console.error('Error from sqlite proxy server: ', JSON.stringify(e))
|
|
3718
|
+
// }
|
|
3719
|
+
// if (!promiser) {
|
|
3720
|
+
// throw new Error('Failed to create promiser')
|
|
3721
|
+
// }
|
|
3722
|
+
// this.sqliteWasmClient = promiser
|
|
3723
|
+
// const responseGet = await this.sqliteWasmClient('config-get', {});
|
|
3724
|
+
// logger('[Db.prepareDb] Running SQLite3 version', responseGet.result.version.libVersion);
|
|
3725
|
+
// const responseOpen = await this.sqliteWasmClient('open', {
|
|
3726
|
+
// filename: `file:${filesDir}/db/${DB_NAME_APP}.db?vfs=opfs`,
|
|
3727
|
+
// });
|
|
3728
|
+
// const { dbId } = responseOpen;
|
|
3729
|
+
// logger(
|
|
3730
|
+
// '[Db.prepareDb] OPFS is available, created persisted database at',
|
|
3731
|
+
// responseOpen.result.filename.replace(/^file:(.*?)\?vfs=opfs/, '$1'),
|
|
3732
|
+
// );
|
|
3733
|
+
// logger('[Db.prepareDb] dbId', dbId)
|
|
3734
|
+
// this.dbId = dbId
|
|
3735
|
+
// await this.migrate()
|
|
3736
|
+
// }
|
|
3737
|
+
async connectToDb(filesDir) {
|
|
3738
|
+
return this.dbId;
|
|
3739
|
+
}
|
|
3740
|
+
async copyDrizzleFiles(filesDir) {
|
|
3741
|
+
logger$1('[Db.copyDrizzleFiles] copying drizzle migration files');
|
|
3742
|
+
try {
|
|
3743
|
+
// Ensure db directory exists
|
|
3744
|
+
const dbDirPath = `${filesDir}/db`;
|
|
3745
|
+
await BaseFileManager.createDirIfNotExists(dbDirPath);
|
|
3746
|
+
// Ensure meta directory exists
|
|
3747
|
+
const metaDirPath = `${dbDirPath}/meta`;
|
|
3748
|
+
await BaseFileManager.createDirIfNotExists(metaDirPath);
|
|
3749
|
+
// Parse journal JSON to get all migration entries
|
|
3750
|
+
const journal = JSON.parse(journalJson);
|
|
3751
|
+
const entries = journal.entries || [];
|
|
3752
|
+
if (entries.length === 0) {
|
|
3753
|
+
logger$1('[Db.copyDrizzleFiles] no migration entries found in journal');
|
|
3754
|
+
return;
|
|
3755
|
+
}
|
|
3756
|
+
// Copy each migration SQL file (always overwrite to ensure they're up-to-date)
|
|
3757
|
+
// Each migration is exported as a separate variable (e.g., migrationSql_0000_married_malice)
|
|
3758
|
+
for (let i = 0; i < entries.length; i++) {
|
|
3759
|
+
const entry = entries[i];
|
|
3760
|
+
const tag = entry.tag; // e.g., "0000_married_malice"
|
|
3761
|
+
const migrationFileName = `${tag}.sql`;
|
|
3762
|
+
const migrationPath = `${dbDirPath}/${migrationFileName}`;
|
|
3763
|
+
// Get the SQL for this migration from the exported variable
|
|
3764
|
+
const migrationVarName = `migrationSql_${tag}`;
|
|
3765
|
+
const migrationContent = drizzleFiles[migrationVarName];
|
|
3766
|
+
if (!migrationContent) {
|
|
3767
|
+
logger$1(`[Db.copyDrizzleFiles] ERROR: No migration content found for ${migrationFileName} (variable: ${migrationVarName})`);
|
|
3768
|
+
throw new Error(`No migration content found for ${migrationFileName}. Expected variable: ${migrationVarName}`);
|
|
3769
|
+
}
|
|
3770
|
+
await BaseFileManager.saveFile(migrationPath, migrationContent.trim());
|
|
3771
|
+
logger$1(`[Db.copyDrizzleFiles] copied/updated migration SQL file: ${migrationFileName}`);
|
|
3772
|
+
}
|
|
3773
|
+
// Copy journal JSON file (always overwrite to ensure it's up-to-date with all migrations)
|
|
3774
|
+
const journalPath = `${metaDirPath}/_journal.json`;
|
|
3775
|
+
await BaseFileManager.saveFile(journalPath, journalJson);
|
|
3776
|
+
logger$1('[Db.copyDrizzleFiles] copied/updated journal JSON file');
|
|
3777
|
+
// Copy snapshot JSON file (use the latest snapshot based on the highest idx in journal)
|
|
3778
|
+
// Snapshot files are named like: 0000_snapshot.json, 0001_snapshot.json, etc.
|
|
3779
|
+
// The tag format is like "0000_married_malice", so we extract the numeric prefix
|
|
3780
|
+
const latestEntry = entries[entries.length - 1];
|
|
3781
|
+
const tagPrefixMatch = latestEntry.tag.match(/^(\d+_)/);
|
|
3782
|
+
const tagPrefix = tagPrefixMatch ? tagPrefixMatch[1] : '0000_';
|
|
3783
|
+
const snapshotFileName = `${tagPrefix}snapshot.json`;
|
|
3784
|
+
const snapshotPath = `${metaDirPath}/${snapshotFileName}`;
|
|
3785
|
+
// Always overwrite snapshot to ensure it's up-to-date
|
|
3786
|
+
await BaseFileManager.saveFile(snapshotPath, snapshotJson);
|
|
3787
|
+
logger$1(`[Db.copyDrizzleFiles] copied/updated snapshot JSON file: ${snapshotFileName}`);
|
|
3788
|
+
logger$1('[Db.copyDrizzleFiles] drizzle files copied successfully');
|
|
3789
|
+
}
|
|
3790
|
+
catch (error) {
|
|
3791
|
+
logger$1('[Db.copyDrizzleFiles] error copying drizzle files', error);
|
|
3792
|
+
// Don't throw - the files might already exist or migration might work without them
|
|
3793
|
+
// The migration will fail later if the files are truly needed
|
|
3794
|
+
}
|
|
3795
|
+
}
|
|
3796
|
+
/** Internal migration runner. Used by prepareDb before appDb is set. */
|
|
3797
|
+
async runMigrations(db, _pathToDbDir) {
|
|
3798
|
+
try {
|
|
3799
|
+
const migrations = getEmbeddedMigrations();
|
|
3800
|
+
logger$1('[Db.runMigrations] embedded migrations', migrations.length);
|
|
3801
|
+
await applyEmbeddedMigrations(db, migrations, undefined, (queries, migration) => this.runMigrationQueries(db, queries, canRunInTransaction(migration)));
|
|
3802
|
+
logger$1('[Db.runMigrations] migrations completed');
|
|
3803
|
+
}
|
|
3804
|
+
catch (error) {
|
|
3805
|
+
logger$1('[Db.runMigrations] error', JSON.stringify(error));
|
|
3806
|
+
throw error;
|
|
3807
|
+
}
|
|
3808
|
+
}
|
|
3809
|
+
/** Applies a migration atomically through SQLocal's transaction (exclusive across tabs) when SQLite allows. */
|
|
3810
|
+
async runMigrationQueries(db, queries, atomic) {
|
|
3811
|
+
const statements = queries.filter((query) => query.trim() !== '');
|
|
3812
|
+
if (!atomic || !this.sqlocalInstance) {
|
|
3813
|
+
for (const query of statements) {
|
|
3814
|
+
await db.run(sql.raw(query));
|
|
3815
|
+
}
|
|
3816
|
+
return;
|
|
3817
|
+
}
|
|
3818
|
+
await this.sqlocalInstance.transaction(async (tx) => {
|
|
3819
|
+
for (const query of statements) {
|
|
3820
|
+
await tx.query({ sql: query, params: [] });
|
|
3821
|
+
}
|
|
3822
|
+
});
|
|
3823
|
+
}
|
|
3824
|
+
async migrate(pathToDbDir, _dbName, _dbId) {
|
|
3825
|
+
const targetDb = this.appDb;
|
|
3826
|
+
if (!targetDb) {
|
|
3827
|
+
throw new Error('Database not prepared');
|
|
3828
|
+
}
|
|
3829
|
+
await this.runMigrations(targetDb, pathToDbDir);
|
|
3830
|
+
}
|
|
3831
|
+
// Legacy commented migrate/exec implementation archived at
|
|
3832
|
+
// docs/archive/commented/browser-Db-legacy-migrate.ts.txt
|
|
3833
|
+
/**
|
|
3834
|
+
* Execute a reactive query that emits new results whenever the underlying data changes.
|
|
3835
|
+
*
|
|
3836
|
+
* Supports two usage patterns:
|
|
3837
|
+
* 1. SQL tag function: liveQuery((sql) => sql`SELECT * FROM models`)
|
|
3838
|
+
* 2. Drizzle query builder: liveQuery(db.select().from(models))
|
|
3839
|
+
*
|
|
3840
|
+
* @param query - SQL query function or Drizzle query builder
|
|
3841
|
+
* @returns Observable that emits arrays of query results
|
|
3842
|
+
*
|
|
3843
|
+
* @example
|
|
3844
|
+
* ```typescript
|
|
3845
|
+
* // Using SQL tag function
|
|
3846
|
+
* const models$ = Db.liveQuery<ModelRow>(
|
|
3847
|
+
* (sql) => sql`SELECT * FROM models WHERE schema_file_id = ${schemaId}`
|
|
3848
|
+
* )
|
|
3849
|
+
*
|
|
3850
|
+
* // Using Drizzle query builder
|
|
3851
|
+
* const models$ = Db.liveQuery<ModelRow>(
|
|
3852
|
+
* appDb.select().from(models).where(eq(models.schemaFileId, schemaId))
|
|
3853
|
+
* )
|
|
3854
|
+
*
|
|
3855
|
+
* models$.subscribe(models => {
|
|
3856
|
+
* console.log('Models updated:', models)
|
|
3857
|
+
* })
|
|
3858
|
+
* ```
|
|
3859
|
+
*/
|
|
3860
|
+
liveQuery(query) {
|
|
3861
|
+
if (!this.sqlocalInstance) {
|
|
3862
|
+
throw new Error('Database not initialized. Call prepareDb first.');
|
|
3863
|
+
}
|
|
3864
|
+
if (!this.sqlocalInstance.reactiveQuery) {
|
|
3865
|
+
throw new Error('Reactive queries not enabled. Initialize SQLocalDrizzle with reactive: true.');
|
|
3866
|
+
}
|
|
3867
|
+
const baseObservable = new Observable((subscriber) => {
|
|
3868
|
+
const reactiveQueryResult = this.sqlocalInstance.reactiveQuery(query);
|
|
3869
|
+
const subscription = reactiveQueryResult.subscribe((data) => {
|
|
3870
|
+
subscriber.next(data);
|
|
3871
|
+
}, (err) => {
|
|
3872
|
+
console.error('[BaseDb.liveQuery] SQLocal reactiveQuery error:', err);
|
|
3873
|
+
subscriber.error(err);
|
|
3874
|
+
});
|
|
3875
|
+
return () => {
|
|
3876
|
+
subscription.unsubscribe();
|
|
3877
|
+
};
|
|
3878
|
+
});
|
|
3879
|
+
// Compare stable JSON snapshots via keySelector. SQLocal may reuse one array reference
|
|
3880
|
+
// and mutate rows in place; comparing (prev, curr) on the same reference makes
|
|
3881
|
+
// JSON.stringify(prev) === JSON.stringify(curr) after mutation and suppresses emissions.
|
|
3882
|
+
return baseObservable.pipe(distinctUntilChanged((a, b) => a === b, (x) => JSON.stringify(x)));
|
|
3883
|
+
}
|
|
3884
|
+
}
|
|
3885
|
+
BaseDb.configure(new BrowserDb());
|
|
3886
|
+
|
|
3887
|
+
const logger = debug("seedSdk:browser:ArweaveClient");
|
|
3888
|
+
// Cached Arweave instance (keyed by gateway so setHost / protocol changes apply)
|
|
3889
|
+
let _arweaveInstance = null;
|
|
3890
|
+
let _arweaveGatewayKey = null;
|
|
3891
|
+
/**
|
|
3892
|
+
* Get or create the Arweave instance for browser
|
|
3893
|
+
*/
|
|
3894
|
+
const getArweaveInstance = () => {
|
|
3895
|
+
const gatewayKey = `${BaseArweaveClient.getProtocol()}://${BaseArweaveClient.getHost()}`;
|
|
3896
|
+
if (_arweaveInstance && _arweaveGatewayKey === gatewayKey) {
|
|
3897
|
+
return _arweaveInstance;
|
|
3898
|
+
}
|
|
3899
|
+
_arweaveGatewayKey = gatewayKey;
|
|
3900
|
+
const apiConfig = BaseArweaveClient.getArweaveJsApiConfig();
|
|
3901
|
+
// Handle both ES modules and CommonJS exports from arweave package
|
|
3902
|
+
if ("default" in Arweave && typeof Arweave.default?.init === "function") {
|
|
3903
|
+
_arweaveInstance = Arweave.default.init(apiConfig);
|
|
3904
|
+
}
|
|
3905
|
+
else {
|
|
3906
|
+
_arweaveInstance = Arweave.init(apiConfig);
|
|
3907
|
+
}
|
|
3908
|
+
return _arweaveInstance;
|
|
3909
|
+
};
|
|
3910
|
+
class BrowserArweaveClient {
|
|
3911
|
+
getArweaveClient() {
|
|
3912
|
+
return new GraphQLClient(BaseArweaveClient.getEndpoint());
|
|
3913
|
+
}
|
|
3914
|
+
async getTransactionStatus(transactionId) {
|
|
3915
|
+
const url = BaseArweaveClient.getStatusUrl(transactionId);
|
|
3916
|
+
try {
|
|
3917
|
+
const response = await fetch(url);
|
|
3918
|
+
if (response.status === 404) {
|
|
3919
|
+
return {
|
|
3920
|
+
status: 404,
|
|
3921
|
+
confirmed: null,
|
|
3922
|
+
};
|
|
3923
|
+
}
|
|
3924
|
+
if (!response.ok) {
|
|
3925
|
+
return {
|
|
3926
|
+
status: response.status,
|
|
3927
|
+
confirmed: null,
|
|
3928
|
+
};
|
|
3929
|
+
}
|
|
3930
|
+
if (response.body) {
|
|
3931
|
+
await response.body.cancel();
|
|
3932
|
+
}
|
|
3933
|
+
return {
|
|
3934
|
+
status: 200,
|
|
3935
|
+
confirmed: null,
|
|
3936
|
+
};
|
|
3937
|
+
}
|
|
3938
|
+
catch (error) {
|
|
3939
|
+
logger("Error fetching transaction status:", error);
|
|
3940
|
+
return {
|
|
3941
|
+
status: 500,
|
|
3942
|
+
confirmed: null,
|
|
3943
|
+
};
|
|
3944
|
+
}
|
|
3945
|
+
}
|
|
3946
|
+
async getTransactionData(transactionId, options) {
|
|
3947
|
+
// Preferred gateways (usually the one the item was uploaded through) serve it before L1 does.
|
|
3948
|
+
// `/raw` is already decoded, so skip them when the caller asked for undecoded data.
|
|
3949
|
+
const preferred = options?.decode === false ? [] : getPreferredArweaveReadBaseUrls();
|
|
3950
|
+
for (const base of preferred) {
|
|
3951
|
+
const response = await fetchArweaveRawFromBaseUrl(base, transactionId);
|
|
3952
|
+
if (!response)
|
|
3953
|
+
continue;
|
|
3954
|
+
try {
|
|
3955
|
+
if (options?.string) {
|
|
3956
|
+
return await response.text();
|
|
3957
|
+
}
|
|
3958
|
+
return new Uint8Array(await response.arrayBuffer());
|
|
3959
|
+
}
|
|
3960
|
+
catch (error) {
|
|
3961
|
+
logger("Error reading preferred gateway response:", error);
|
|
3962
|
+
}
|
|
3963
|
+
}
|
|
3964
|
+
// Path-prefixed proxies (app-server Hyper proxy) are not supported by arweave.init host;
|
|
3965
|
+
// fetch via getRawUrl so /api/seed-gateway/... works.
|
|
3966
|
+
if (BaseArweaveClient.getGatewayPath()) {
|
|
3967
|
+
const response = await fetch(BaseArweaveClient.getRawUrl(transactionId));
|
|
3968
|
+
if (!response.ok) {
|
|
3969
|
+
throw new Error(`Failed to fetch transaction data: HTTP ${response.status}`);
|
|
3970
|
+
}
|
|
3971
|
+
if (options?.string) {
|
|
3972
|
+
return response.text();
|
|
3973
|
+
}
|
|
3974
|
+
return new Uint8Array(await response.arrayBuffer());
|
|
3975
|
+
}
|
|
3976
|
+
const arweave = getArweaveInstance();
|
|
3977
|
+
try {
|
|
3978
|
+
const data = await arweave.transactions.getData(transactionId, {
|
|
3979
|
+
decode: options?.decode ?? true,
|
|
3980
|
+
string: options?.string ?? false,
|
|
3981
|
+
});
|
|
3982
|
+
if (options?.string && typeof data === "string") {
|
|
3983
|
+
return data;
|
|
3984
|
+
}
|
|
3985
|
+
// Ensure we return Uint8Array
|
|
3986
|
+
if (data instanceof Uint8Array) {
|
|
3987
|
+
return data;
|
|
3988
|
+
}
|
|
3989
|
+
// Handle string data when not requesting string
|
|
3990
|
+
if (typeof data === "string") {
|
|
3991
|
+
return new TextEncoder().encode(data);
|
|
3992
|
+
}
|
|
3993
|
+
return data;
|
|
3994
|
+
}
|
|
3995
|
+
catch (error) {
|
|
3996
|
+
logger("Error fetching transaction data:", error);
|
|
3997
|
+
throw error;
|
|
3998
|
+
}
|
|
3999
|
+
}
|
|
4000
|
+
async getTransactionTags(transactionId) {
|
|
4001
|
+
const client = this.getArweaveClient();
|
|
4002
|
+
try {
|
|
4003
|
+
const result = await client.request(GET_TRANSACTION_TAGS, { transactionId });
|
|
4004
|
+
if (!result.tags?.tags) {
|
|
4005
|
+
return [];
|
|
4006
|
+
}
|
|
4007
|
+
return result.tags.tags.map((tag) => ({
|
|
4008
|
+
name: tag.name,
|
|
4009
|
+
value: tag.value,
|
|
4010
|
+
}));
|
|
4011
|
+
}
|
|
4012
|
+
catch (error) {
|
|
4013
|
+
logger("Error fetching transaction tags:", error);
|
|
4014
|
+
return [];
|
|
4015
|
+
}
|
|
4016
|
+
}
|
|
4017
|
+
async createTransaction(data, options) {
|
|
4018
|
+
const arweave = getArweaveInstance();
|
|
4019
|
+
const tx = await arweave.createTransaction({
|
|
4020
|
+
data,
|
|
4021
|
+
});
|
|
4022
|
+
// Add tags if provided
|
|
4023
|
+
if (options?.tags) {
|
|
4024
|
+
for (const tag of options.tags) {
|
|
4025
|
+
tx.addTag(tag.name, tag.value);
|
|
4026
|
+
}
|
|
4027
|
+
}
|
|
4028
|
+
return tx;
|
|
4029
|
+
}
|
|
4030
|
+
async downloadFiles(params) {
|
|
4031
|
+
const { transactionIds, excludedTransactions } = params;
|
|
4032
|
+
const results = [];
|
|
4033
|
+
const baseUrl = BaseArweaveClient.getBaseUrl();
|
|
4034
|
+
for (const transactionId of transactionIds) {
|
|
4035
|
+
// Skip excluded transactions
|
|
4036
|
+
if (excludedTransactions?.has(transactionId)) {
|
|
4037
|
+
continue;
|
|
4038
|
+
}
|
|
4039
|
+
try {
|
|
4040
|
+
const url = `${baseUrl}/raw/${transactionId}`;
|
|
4041
|
+
const response = await fetch(url);
|
|
4042
|
+
if (!response.ok) {
|
|
4043
|
+
results.push({
|
|
4044
|
+
transactionId,
|
|
4045
|
+
success: false,
|
|
4046
|
+
error: `HTTP ${response.status}: ${response.statusText}`,
|
|
4047
|
+
});
|
|
4048
|
+
continue;
|
|
4049
|
+
}
|
|
4050
|
+
const arrayBuffer = await response.arrayBuffer();
|
|
4051
|
+
const data = new Uint8Array(arrayBuffer);
|
|
4052
|
+
// Detect content type
|
|
4053
|
+
const contentType = response.headers.get("content-type") || undefined;
|
|
4054
|
+
results.push({
|
|
4055
|
+
transactionId,
|
|
4056
|
+
success: true,
|
|
4057
|
+
contentType,
|
|
4058
|
+
data,
|
|
4059
|
+
});
|
|
4060
|
+
}
|
|
4061
|
+
catch (error) {
|
|
4062
|
+
logger(`Error downloading transaction ${transactionId}:`, error);
|
|
4063
|
+
results.push({
|
|
4064
|
+
transactionId,
|
|
4065
|
+
success: false,
|
|
4066
|
+
error: error instanceof Error ? error.message : String(error),
|
|
4067
|
+
});
|
|
4068
|
+
}
|
|
4069
|
+
}
|
|
4070
|
+
return results;
|
|
4071
|
+
}
|
|
4072
|
+
}
|
|
4073
|
+
BaseArweaveClient.configure(new BrowserArweaveClient());
|
|
4074
|
+
|
|
4075
|
+
class BrowserEasClient {
|
|
4076
|
+
/** Reads the endpoint per call so SDK / publish chain config applied after import takes effect. */
|
|
4077
|
+
getEasClient() {
|
|
4078
|
+
const url = getEasEndpoint();
|
|
4079
|
+
if (this.easClient?.url !== url) {
|
|
4080
|
+
this.easClient = { url, client: new GraphQLClient(url) };
|
|
4081
|
+
}
|
|
4082
|
+
return this.easClient.client;
|
|
4083
|
+
}
|
|
4084
|
+
}
|
|
4085
|
+
BaseEasClient.configure(new BrowserEasClient());
|
|
4086
|
+
|
|
4087
|
+
/**
|
|
4088
|
+
* Cached results are only reused within a query's staleTime (0 unless the caller sets one), so
|
|
4089
|
+
* they don't need to outlive that by much. Nothing persists this cache.
|
|
4090
|
+
*/
|
|
4091
|
+
const QUERY_GC_TIME_MS = 1000 * 60 * 5;
|
|
4092
|
+
class BrowserQueryClient {
|
|
4093
|
+
getQueryClient() {
|
|
4094
|
+
if (this.queryClient)
|
|
4095
|
+
return this.queryClient;
|
|
4096
|
+
const reactQueryClient = new QueryClient({
|
|
4097
|
+
defaultOptions: {
|
|
4098
|
+
queries: {
|
|
4099
|
+
networkMode: 'offlineFirst',
|
|
4100
|
+
gcTime: QUERY_GC_TIME_MS,
|
|
4101
|
+
},
|
|
4102
|
+
},
|
|
4103
|
+
});
|
|
4104
|
+
const queryClient = {
|
|
4105
|
+
fetchQuery: async (options) => {
|
|
4106
|
+
const { queryKey, queryFn, networkMode, staleTime } = options;
|
|
4107
|
+
return reactQueryClient.fetchQuery({
|
|
4108
|
+
queryKey,
|
|
4109
|
+
queryFn,
|
|
4110
|
+
networkMode: networkMode,
|
|
4111
|
+
staleTime,
|
|
4112
|
+
});
|
|
4113
|
+
},
|
|
4114
|
+
getQueryData: (queryKey) => {
|
|
4115
|
+
return reactQueryClient.getQueryData(queryKey);
|
|
4116
|
+
},
|
|
4117
|
+
removeQueries: async (filters) => {
|
|
4118
|
+
await reactQueryClient.removeQueries(filters);
|
|
4119
|
+
},
|
|
4120
|
+
};
|
|
4121
|
+
this.queryClient = queryClient;
|
|
4122
|
+
return queryClient;
|
|
4123
|
+
}
|
|
4124
|
+
}
|
|
4125
|
+
BaseQueryClient.configure(new BrowserQueryClient());
|
|
4126
|
+
|
|
4127
|
+
function createPlatformServices() {
|
|
4128
|
+
return {
|
|
4129
|
+
pathResolver: new BrowserPathResolver(),
|
|
4130
|
+
fileManager: new BrowserFileManager(),
|
|
4131
|
+
db: new BrowserDb(),
|
|
4132
|
+
arweaveClient: new BrowserArweaveClient(),
|
|
4133
|
+
easClient: new BrowserEasClient(),
|
|
4134
|
+
queryClient: new BrowserQueryClient(),
|
|
4135
|
+
};
|
|
4136
|
+
}
|
|
4137
|
+
|
|
4138
|
+
export { createPlatformServices as c, isSkippableOpfsEntryError as i };
|
|
4139
|
+
//# sourceMappingURL=index.browser-CNrqhvEA.js.map
|