@seedprotocol/sdk 0.6.10 → 0.7.1
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-DRT09oVv.js} +36 -2
- package/dist/BasePathResolver-DRT09oVv.js.map +1 -0
- package/dist/ClientManager-DngaZdw6.js +4763 -0
- package/dist/ClientManager-DngaZdw6.js.map +1 -0
- package/dist/{ClientManager-ChcmUL47.js → Item-ZUAmf943.js} +1175 -5903
- package/dist/Item-ZUAmf943.js.map +1 -0
- package/dist/{ModelProperty-D79uV42p.js → ModelProperty-6llK4MTH.js} +326 -109
- package/dist/ModelProperty-6llK4MTH.js.map +1 -0
- package/dist/{Schema-a8uO-hIZ.js → Schema-D-Ud-XYw.js} +164 -885
- package/dist/Schema-D-Ud-XYw.js.map +1 -0
- package/dist/{SchemaValidationService-Y49vqast.js → SchemaValidationService-IoS7JquP.js} +26 -18
- package/dist/SchemaValidationService-IoS7JquP.js.map +1 -0
- package/dist/{backfillMetadataPropertyIds-CBsf7LnU.js → backfillMetadataPropertyIds-BlVeE7w7.js} +11 -6
- package/dist/backfillMetadataPropertyIds-BlVeE7w7.js.map +1 -0
- package/dist/cjs/{ModelProperty-D9FGaGuE.js → ModelProperty-Dv7AQfmQ.js} +297 -89
- package/dist/cjs/ModelProperty-Dv7AQfmQ.js.map +1 -0
- package/dist/cjs/{Schema-BiJIPLEL.js → Schema-BHVp1g-M.js} +136 -868
- package/dist/cjs/Schema-BHVp1g-M.js.map +1 -0
- package/dist/cjs/{SchemaValidationService-DtYs_CNY.js → SchemaValidationService-BSU9knjf.js} +18 -11
- package/dist/cjs/SchemaValidationService-BSU9knjf.js.map +1 -0
- package/dist/cjs/{backfillMetadataPropertyIds-2XaN3b9S.js → backfillMetadataPropertyIds-WIovQ_d8.js} +8 -3
- package/dist/cjs/backfillMetadataPropertyIds-WIovQ_d8.js.map +1 -0
- package/dist/cjs/{eas-CMNppmGE.js → eas-CUYXdr2t.js} +4 -4
- package/dist/cjs/{eas-CMNppmGE.js.map → eas-CUYXdr2t.js.map} +1 -1
- package/dist/cjs/{getItem-B6jEINjW.js → getItem-z1tHu0hu.js} +2 -2
- package/dist/cjs/{getItem-B6jEINjW.js.map → getItem-z1tHu0hu.js.map} +1 -1
- package/dist/cjs/getLatestVersionRow-CcaabxIW.js +59 -0
- package/dist/cjs/getLatestVersionRow-CcaabxIW.js.map +1 -0
- package/dist/cjs/{getPublishPayload-D5DhLGvN.js → getPublishPayload-CEP_e-Kv.js} +283 -138
- package/dist/cjs/getPublishPayload-CEP_e-Kv.js.map +1 -0
- package/dist/cjs/{getPublishUploads-DMhCCKYF.js → getPublishUploads-Ctn5k1k6.js} +65 -19
- package/dist/cjs/getPublishUploads-Ctn5k1k6.js.map +1 -0
- package/dist/cjs/{index-CSNtEnbF.js → index-Cvvt0-5B.js} +2698 -1725
- package/dist/cjs/index-Cvvt0-5B.js.map +1 -0
- package/dist/cjs/{index-DPp9rdRL.js → index-DfGhF1dc.js} +3 -3
- package/dist/cjs/index-DfGhF1dc.js.map +1 -0
- package/dist/cjs/{property-DlKiAWt4.js → property-DbEPQ1m9.js} +40 -35
- package/dist/cjs/property-DbEPQ1m9.js.map +1 -0
- package/dist/cjs/publishDraftGraph-C38gf302.js +403 -0
- package/dist/cjs/publishDraftGraph-C38gf302.js.map +1 -0
- package/dist/cjs/resetAmbiguousLegacyItemData-CfMhRHwK.js +116 -0
- package/dist/cjs/resetAmbiguousLegacyItemData-CfMhRHwK.js.map +1 -0
- package/dist/cjs/resolveModelForSyncedSeed-CNYaLOir.js +49 -0
- package/dist/cjs/resolveModelForSyncedSeed-CNYaLOir.js.map +1 -0
- package/dist/cjs/syncDbWithEas-d1iOdTTI.js +886 -0
- package/dist/cjs/syncDbWithEas-d1iOdTTI.js.map +1 -0
- package/dist/{configurePlatform-CE0Vew17.js → configurePlatform-CZpjyuCo.js} +4 -4
- package/dist/{configurePlatform-CE0Vew17.js.map → configurePlatform-CZpjyuCo.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-Lw0KVZmc.js} +546 -106
- package/dist/db-Lw0KVZmc.js.map +1 -0
- package/dist/{eas-CfYCu4IX.js → eas-CQ-Smzk2.js} +7 -7
- package/dist/eas-CQ-Smzk2.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-CSfSok9f.js} +8 -10
- package/dist/{getItem-Br-bGNFO.js.map → getItem-CSfSok9f.js.map} +1 -1
- package/dist/getLatestVersionRow-72Atl9vB.js +46 -0
- package/dist/getLatestVersionRow-72Atl9vB.js.map +1 -0
- package/dist/{getPublishPayload-BIrTVUxb.js → getPublishPayload-76_KfB5Y.js} +297 -154
- package/dist/getPublishPayload-76_KfB5Y.js.map +1 -0
- package/dist/{getPublishUploads-C6cDeZdz.js → getPublishUploads-CqgMBD8f.js} +68 -21
- package/dist/getPublishUploads-CqgMBD8f.js.map +1 -0
- package/dist/{index-Djd3667v.js → index-5b3JsS55.js} +2 -2
- package/dist/index-5b3JsS55.js.map +1 -0
- package/dist/{index-ClSv5pTA.js → index-BpgD305l.js} +12 -11
- package/dist/index-BpgD305l.js.map +1 -0
- package/dist/{index-HRHkbVQd.js → index-Y-yYyRBf.js} +530 -196
- package/dist/index-Y-yYyRBf.js.map +1 -0
- package/dist/index.browser-DaTzn79x.js +4139 -0
- package/dist/index.browser-DaTzn79x.js.map +1 -0
- package/dist/{index.node-DBtQkEfz.js → index.node-NYKqFOoe.js} +9 -4
- package/dist/index.node-NYKqFOoe.js.map +1 -0
- package/dist/main.cjs +1 -1
- package/dist/main.js +886 -560
- 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-ByaiSyUK.js} +53 -48
- package/dist/property-ByaiSyUK.js.map +1 -0
- package/dist/publishDraftGraph-BRm6Pq3Q.js +405 -0
- package/dist/publishDraftGraph-BRm6Pq3Q.js.map +1 -0
- package/dist/resetAmbiguousLegacyItemData-B4dX6ZA1.js +88 -0
- package/dist/resetAmbiguousLegacyItemData-B4dX6ZA1.js.map +1 -0
- package/dist/resolveModelForSyncedSeed-B0tco3zG.js +46 -0
- package/dist/resolveModelForSyncedSeed-B0tco3zG.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 +21 -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 +13 -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 +52 -2
- 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/actors/validateModel.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 +42 -2
- 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/actors/saveToSchema.d.ts.map +1 -1
- package/dist/src/ModelProperty/service/actors/validateProperty.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 +8 -2
- package/dist/src/Schema/Schema.d.ts.map +1 -1
- package/dist/src/Schema/service/actors/checkExistingSchema.d.ts.map +1 -1
- package/dist/src/Schema/service/actors/createModelInstances.d.ts.map +1 -1
- package/dist/src/Schema/service/actors/loadOrCreateSchema.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 +18 -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 +5 -0
- 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/publishDraftGraph.d.ts +57 -0
- package/dist/src/db/read/publishDraftGraph.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/entity/evictionEpoch.d.ts +18 -0
- package/dist/src/helpers/entity/evictionEpoch.d.ts.map +1 -0
- 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 +31 -3
- 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 +13 -3
- 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/validateEntity.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 +19 -11
- 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-BPap9Sru.js +855 -0
- package/dist/syncDbWithEas-BPap9Sru.js.map +1 -0
- package/dist/{index-280bL-n4.js → tabEvents-C6NXS6Jl.js} +231 -68
- package/dist/tabEvents-C6NXS6Jl.js.map +1 -0
- package/dist/tolerantWebAccess-NBQ1NB4i.js +160 -0
- package/dist/tolerantWebAccess-NBQ1NB4i.js.map +1 -0
- package/dist/updateSeedRevokedAt-CYwgVNlM.js +32 -0
- package/dist/updateSeedRevokedAt-CYwgVNlM.js.map +1 -0
- package/package.json +8 -10
- 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 +0 -148
- 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/getPublishUploads-C6cDeZdz.js.map +0 -1
- package/dist/getSegmentedItemProperties-BmKE71vU.js +0 -148
- 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/browser/helpers/index.d.ts +0 -4
- package/dist/src/browser/helpers/index.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
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
import { fromCallback, setup, assign, createActor } from 'xstate';
|
|
2
|
-
import {
|
|
3
|
-
import './
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
2
|
+
import { b as getRefValueType, D as createModelsFromJson, n as listCompleteSchemaFiles, F as getLatestSchemaVersion, l as loadSchemaFromFile, o as loadAllSchemasFromDb, h as getClient } from './ClientManager-DngaZdw6.js';
|
|
3
|
+
import './tabEvents-C6NXS6Jl.js';
|
|
4
|
+
import { O as addSchemaToDb, k as isDataType, M as ModelPropertyDataTypes, w as addModelsToDb, S as loadModelsFromDbForSchema } from './db-Lw0KVZmc.js';
|
|
5
|
+
import { F as SEED_PROTOCOL_SCHEMA_NAME, B as BaseDb, s as schemas, j as models, g as modelSchemas, p as properties, a as BaseFileManager, K as isInternalSchema } from './BasePathResolver-DRT09oVv.js';
|
|
6
6
|
import { eq, desc, and } from 'drizzle-orm';
|
|
7
7
|
import debug from 'debug';
|
|
8
|
+
import { c as currentEvictionEpoch, w as writeProcessMachine, M as Model, C as ConflictError, d as setupEntityLiveQuery } from './index-Y-yYyRBf.js';
|
|
8
9
|
import 'pluralize';
|
|
9
10
|
import { generateId } from './generateId-BopUwD8F.js';
|
|
10
|
-
import { SchemaValidationService } from './SchemaValidationService-
|
|
11
|
-
import {
|
|
11
|
+
import { SchemaValidationService } from './SchemaValidationService-IoS7JquP.js';
|
|
12
|
+
import { j as waitForEntityIdle, k as createReactiveProxy, m as findEntity, C as ClientManagerState, U as clearDestroySubscriptions, n as forceRemoveFromCaches, V as unloadEntity, o as runDestroyLifecycle } from './Item-ZUAmf943.js';
|
|
12
13
|
|
|
13
14
|
const logger$d = debug('seedSdk:schema:actors:loadOrCreateSchema');
|
|
14
15
|
/**
|
|
@@ -47,20 +48,21 @@ const getModelIdsForSchema$1 = async (schemaId) => {
|
|
|
47
48
|
* This ensures that Model.getById() in Schema.getContext() will find the instances
|
|
48
49
|
* @param modelIds - Array of model file IDs to create instances for
|
|
49
50
|
*/
|
|
50
|
-
const createModelInstances$2 = async (modelIds) => {
|
|
51
|
+
const createModelInstances$2 = async (modelIds, evictionEpoch) => {
|
|
51
52
|
if (modelIds.length === 0) {
|
|
52
53
|
return;
|
|
53
54
|
}
|
|
54
55
|
try {
|
|
55
|
-
const _mod_0 = await import('./index-
|
|
56
|
-
const _ns_0 = _mod_0.
|
|
56
|
+
const _mod_0 = await import('./index-Y-yYyRBf.js');
|
|
57
|
+
const _ns_0 = _mod_0.f;
|
|
57
58
|
const modelMod = _ns_0;
|
|
58
59
|
const { Model } = modelMod;
|
|
59
60
|
// Create instances for all model IDs in parallel
|
|
60
61
|
// Model.createById() will check cache first, then query DB and create if needed
|
|
61
62
|
const createPromises = modelIds.map(async (modelFileId) => {
|
|
62
63
|
try {
|
|
63
|
-
|
|
64
|
+
// Not if the schema was evicted (Schema.destroy, test cleanup) since this load started
|
|
65
|
+
const model = await Model.createById(modelFileId, { evictionEpoch });
|
|
64
66
|
if (model) {
|
|
65
67
|
logger$d(`Created/cached Model instance for modelFileId "${modelFileId}"`);
|
|
66
68
|
}
|
|
@@ -159,6 +161,7 @@ const getSchemaFilePath$2 = (name, version, schemaFileId) => {
|
|
|
159
161
|
return path.join(workingDir, filename);
|
|
160
162
|
};
|
|
161
163
|
const loadOrCreateSchema = fromCallback(({ sendBack, input: { context } }) => {
|
|
164
|
+
const evictionEpoch = currentEvictionEpoch();
|
|
162
165
|
const _loadOrCreateSchema = async () => {
|
|
163
166
|
const { schemaName } = context;
|
|
164
167
|
// Check if this is an internal SDK schema (should not create files in app directory) — use static import so consumer bundles resolve correctly
|
|
@@ -167,8 +170,8 @@ const loadOrCreateSchema = fromCallback(({ sendBack, input: { context } }) => {
|
|
|
167
170
|
// For Seed Protocol, always load from internal file, never create new
|
|
168
171
|
logger$d(`Loading internal Seed Protocol schema from SDK`);
|
|
169
172
|
try {
|
|
170
|
-
const _mod_1 = await import('./ClientManager-
|
|
171
|
-
const _ns_1 = _mod_1.
|
|
173
|
+
const _mod_1 = await import('./ClientManager-DngaZdw6.js');
|
|
174
|
+
const _ns_1 = _mod_1.S;
|
|
172
175
|
const internalSchema = _ns_1;
|
|
173
176
|
const schemaFile = internalSchema.default;
|
|
174
177
|
// Check if it exists in database, if not, add it
|
|
@@ -477,7 +480,7 @@ const loadOrCreateSchema = fromCallback(({ sendBack, input: { context } }) => {
|
|
|
477
480
|
if (schemaRecord && schemaRecord.id) {
|
|
478
481
|
modelIds = await getModelIdsForSchema$1(schemaRecord.id);
|
|
479
482
|
// Create Model instances so they're cached before getContext runs
|
|
480
|
-
await createModelInstances$2(modelIds);
|
|
483
|
+
await createModelInstances$2(modelIds, evictionEpoch);
|
|
481
484
|
}
|
|
482
485
|
sendBack({
|
|
483
486
|
type: 'loadOrCreateSchemaSuccess',
|
|
@@ -662,8 +665,8 @@ const loadOrCreateSchema = fromCallback(({ sendBack, input: { context } }) => {
|
|
|
662
665
|
// Ensure models are populated (fallback for seed-protocol if missing)
|
|
663
666
|
if ((!mergedModels || Object.keys(mergedModels).length === 0) && schemaName === 'Seed Protocol') {
|
|
664
667
|
try {
|
|
665
|
-
const _mod_2 = await import('./ClientManager-
|
|
666
|
-
const _ns_2 = _mod_2.
|
|
668
|
+
const _mod_2 = await import('./ClientManager-DngaZdw6.js');
|
|
669
|
+
const _ns_2 = _mod_2.S;
|
|
667
670
|
const internalSchema = _ns_2;
|
|
668
671
|
const internalSchemaFile = internalSchema.default;
|
|
669
672
|
mergedModels = { ...(internalSchemaFile.models || {}) };
|
|
@@ -726,7 +729,7 @@ const loadOrCreateSchema = fromCallback(({ sendBack, input: { context } }) => {
|
|
|
726
729
|
if (dbSchema.id) {
|
|
727
730
|
modelIds = await getModelIdsForSchema$1(dbSchema.id);
|
|
728
731
|
// Create Model instances so they're cached before getContext runs
|
|
729
|
-
await createModelInstances$2(modelIds);
|
|
732
|
+
await createModelInstances$2(modelIds, evictionEpoch);
|
|
730
733
|
}
|
|
731
734
|
// Track conflict detection metadata
|
|
732
735
|
const loadedAt = Date.now();
|
|
@@ -823,7 +826,7 @@ const loadOrCreateSchema = fromCallback(({ sendBack, input: { context } }) => {
|
|
|
823
826
|
if (draftsByFileId[0].id) {
|
|
824
827
|
modelIds = await getModelIdsForSchema$1(draftsByFileId[0].id);
|
|
825
828
|
// Create Model instances so they're cached before getContext runs
|
|
826
|
-
await createModelInstances$2(modelIds);
|
|
829
|
+
await createModelInstances$2(modelIds, evictionEpoch);
|
|
827
830
|
}
|
|
828
831
|
// Track conflict detection metadata
|
|
829
832
|
const loadedAt = Date.now();
|
|
@@ -891,8 +894,8 @@ const loadOrCreateSchema = fromCallback(({ sendBack, input: { context } }) => {
|
|
|
891
894
|
// Ensure models are populated (fallback for seed-protocol if missing)
|
|
892
895
|
if ((!mergedModels || Object.keys(mergedModels).length === 0) && schemaName === 'Seed Protocol') {
|
|
893
896
|
try {
|
|
894
|
-
const _mod_3 = await import('./ClientManager-
|
|
895
|
-
const _ns_3 = _mod_3.
|
|
897
|
+
const _mod_3 = await import('./ClientManager-DngaZdw6.js');
|
|
898
|
+
const _ns_3 = _mod_3.S;
|
|
896
899
|
const internalSchema = _ns_3;
|
|
897
900
|
const internalSchemaFile = internalSchema.default;
|
|
898
901
|
mergedModels = { ...(internalSchemaFile.models || {}) };
|
|
@@ -956,7 +959,7 @@ const loadOrCreateSchema = fromCallback(({ sendBack, input: { context } }) => {
|
|
|
956
959
|
if (dbSchema.id) {
|
|
957
960
|
modelIds = await getModelIdsForSchema$1(dbSchema.id);
|
|
958
961
|
// Create Model instances so they're cached before getContext runs
|
|
959
|
-
await createModelInstances$2(modelIds);
|
|
962
|
+
await createModelInstances$2(modelIds, evictionEpoch);
|
|
960
963
|
}
|
|
961
964
|
// Track conflict detection metadata from DB record
|
|
962
965
|
const loadedAt = Date.now();
|
|
@@ -982,8 +985,8 @@ const loadOrCreateSchema = fromCallback(({ sendBack, input: { context } }) => {
|
|
|
982
985
|
// Ensure models are populated (fallback for seed-protocol if missing)
|
|
983
986
|
if ((!mergedModels || Object.keys(mergedModels).length === 0) && schemaName === 'Seed Protocol') {
|
|
984
987
|
try {
|
|
985
|
-
const _mod_4 = await import('./ClientManager-
|
|
986
|
-
const _ns_4 = _mod_4.
|
|
988
|
+
const _mod_4 = await import('./ClientManager-DngaZdw6.js');
|
|
989
|
+
const _ns_4 = _mod_4.S;
|
|
987
990
|
const internalSchema = _ns_4;
|
|
988
991
|
const internalSchemaFile = internalSchema.default;
|
|
989
992
|
mergedModels = { ...(internalSchemaFile.models || {}) };
|
|
@@ -1046,7 +1049,7 @@ const loadOrCreateSchema = fromCallback(({ sendBack, input: { context } }) => {
|
|
|
1046
1049
|
if (dbSchema.id) {
|
|
1047
1050
|
modelIds = await getModelIdsForSchema$1(dbSchema.id);
|
|
1048
1051
|
// Create Model instances so they're cached before getContext runs
|
|
1049
|
-
await createModelInstances$2(modelIds);
|
|
1052
|
+
await createModelInstances$2(modelIds, evictionEpoch);
|
|
1050
1053
|
}
|
|
1051
1054
|
// Track conflict detection metadata
|
|
1052
1055
|
const loadedAt = Date.now();
|
|
@@ -1070,8 +1073,8 @@ const loadOrCreateSchema = fromCallback(({ sendBack, input: { context } }) => {
|
|
|
1070
1073
|
// If schemaData is missing, try to load from internal schema file for seed-protocol
|
|
1071
1074
|
if (!dbSchema.schemaData && schemaName === 'Seed Protocol') {
|
|
1072
1075
|
try {
|
|
1073
|
-
const _mod_5 = await import('./ClientManager-
|
|
1074
|
-
const _ns_5 = _mod_5.
|
|
1076
|
+
const _mod_5 = await import('./ClientManager-DngaZdw6.js');
|
|
1077
|
+
const _ns_5 = _mod_5.S;
|
|
1075
1078
|
const internalSchema = _ns_5;
|
|
1076
1079
|
const schemaFile = internalSchema.default;
|
|
1077
1080
|
logger$d(`Found seed-protocol schema in internal file (schemaData missing, using internal schema)`);
|
|
@@ -1088,7 +1091,7 @@ const loadOrCreateSchema = fromCallback(({ sendBack, input: { context } }) => {
|
|
|
1088
1091
|
if (dbSchema.id) {
|
|
1089
1092
|
modelIds = await getModelIdsForSchema$1(dbSchema.id);
|
|
1090
1093
|
// Create Model instances so they're cached before getContext runs
|
|
1091
|
-
await createModelInstances$2(modelIds);
|
|
1094
|
+
await createModelInstances$2(modelIds, evictionEpoch);
|
|
1092
1095
|
}
|
|
1093
1096
|
sendBack({
|
|
1094
1097
|
type: 'loadOrCreateSchemaSuccess',
|
|
@@ -1150,7 +1153,7 @@ const loadOrCreateSchema = fromCallback(({ sendBack, input: { context } }) => {
|
|
|
1150
1153
|
if (matchingDraft.id) {
|
|
1151
1154
|
modelIds = await getModelIdsForSchema$1(matchingDraft.id);
|
|
1152
1155
|
// Create Model instances so they're cached before getContext runs
|
|
1153
|
-
await createModelInstances$2(modelIds);
|
|
1156
|
+
await createModelInstances$2(modelIds, evictionEpoch);
|
|
1154
1157
|
}
|
|
1155
1158
|
// Track conflict detection metadata
|
|
1156
1159
|
const loadedAt = Date.now();
|
|
@@ -1181,8 +1184,8 @@ const loadOrCreateSchema = fromCallback(({ sendBack, input: { context } }) => {
|
|
|
1181
1184
|
// Ensure models are populated (fallback for seed-protocol if missing)
|
|
1182
1185
|
if ((!mergedModels || Object.keys(mergedModels).length === 0) && schemaName === 'Seed Protocol') {
|
|
1183
1186
|
try {
|
|
1184
|
-
const _mod_6 = await import('./ClientManager-
|
|
1185
|
-
const _ns_6 = _mod_6.
|
|
1187
|
+
const _mod_6 = await import('./ClientManager-DngaZdw6.js');
|
|
1188
|
+
const _ns_6 = _mod_6.S;
|
|
1186
1189
|
const internalSchema = _ns_6;
|
|
1187
1190
|
const internalSchemaFile = internalSchema.default;
|
|
1188
1191
|
mergedModels = { ...(internalSchemaFile.models || {}) };
|
|
@@ -1206,7 +1209,7 @@ const loadOrCreateSchema = fromCallback(({ sendBack, input: { context } }) => {
|
|
|
1206
1209
|
if (schemaRecords.length > 0 && schemaRecords[0].id) {
|
|
1207
1210
|
modelIds = await getModelIdsForSchema$1(schemaRecords[0].id);
|
|
1208
1211
|
// Create Model instances so they're cached before getContext runs
|
|
1209
|
-
await createModelInstances$2(modelIds);
|
|
1212
|
+
await createModelInstances$2(modelIds, evictionEpoch);
|
|
1210
1213
|
}
|
|
1211
1214
|
}
|
|
1212
1215
|
}
|
|
@@ -1260,7 +1263,7 @@ const loadOrCreateSchema = fromCallback(({ sendBack, input: { context } }) => {
|
|
|
1260
1263
|
if (foundSchema.id) {
|
|
1261
1264
|
modelIds = await getModelIdsForSchema$1(foundSchema.id);
|
|
1262
1265
|
// Create Model instances so they're cached before getContext runs
|
|
1263
|
-
await createModelInstances$2(modelIds);
|
|
1266
|
+
await createModelInstances$2(modelIds, evictionEpoch);
|
|
1264
1267
|
}
|
|
1265
1268
|
// Track conflict detection metadata
|
|
1266
1269
|
const loadedAt = Date.now();
|
|
@@ -1292,7 +1295,7 @@ const loadOrCreateSchema = fromCallback(({ sendBack, input: { context } }) => {
|
|
|
1292
1295
|
if (foundSchema.id) {
|
|
1293
1296
|
modelIds = await getModelIdsForSchema$1(foundSchema.id);
|
|
1294
1297
|
// Create Model instances so they're cached before getContext runs
|
|
1295
|
-
await createModelInstances$2(modelIds);
|
|
1298
|
+
await createModelInstances$2(modelIds, evictionEpoch);
|
|
1296
1299
|
}
|
|
1297
1300
|
// Track conflict detection metadata
|
|
1298
1301
|
const loadedAt = Date.now();
|
|
@@ -1365,7 +1368,7 @@ const loadOrCreateSchema = fromCallback(({ sendBack, input: { context } }) => {
|
|
|
1365
1368
|
if (schemaRecords.length > 0 && schemaRecords[0].id) {
|
|
1366
1369
|
modelIds = await getModelIdsForSchema$1(schemaRecords[0].id);
|
|
1367
1370
|
// Create Model instances so they're cached before getContext runs
|
|
1368
|
-
await createModelInstances$2(modelIds);
|
|
1371
|
+
await createModelInstances$2(modelIds, evictionEpoch);
|
|
1369
1372
|
}
|
|
1370
1373
|
}
|
|
1371
1374
|
}
|
|
@@ -1454,582 +1457,6 @@ const validateSchema = fromCallback(({ sendBack, input: { context } }) => {
|
|
|
1454
1457
|
};
|
|
1455
1458
|
});
|
|
1456
1459
|
|
|
1457
|
-
const addModelsMachine = setup({
|
|
1458
|
-
types: {
|
|
1459
|
-
context: {},
|
|
1460
|
-
input: {},
|
|
1461
|
-
events: {},
|
|
1462
|
-
},
|
|
1463
|
-
actors: {
|
|
1464
|
-
validateModels: fromCallback(({ sendBack, input }) => {
|
|
1465
|
-
const _validate = async () => {
|
|
1466
|
-
// Check for duplicate model names
|
|
1467
|
-
const newModelNames = Object.keys(input.newModels);
|
|
1468
|
-
const existingModelNames = Object.keys(input.existingModels || {});
|
|
1469
|
-
for (const modelName of newModelNames) {
|
|
1470
|
-
if (existingModelNames.includes(modelName)) {
|
|
1471
|
-
throw new Error(`Model "${modelName}" already exists in schema`);
|
|
1472
|
-
}
|
|
1473
|
-
}
|
|
1474
|
-
// Check for duplicates within new models
|
|
1475
|
-
const seenNames = new Set();
|
|
1476
|
-
for (const modelName of newModelNames) {
|
|
1477
|
-
if (seenNames.has(modelName)) {
|
|
1478
|
-
throw new Error(`Duplicate model name detected: "${modelName}". Each model must have a unique name.`);
|
|
1479
|
-
}
|
|
1480
|
-
seenNames.add(modelName);
|
|
1481
|
-
}
|
|
1482
|
-
// Basic validation - ensure models have required structure
|
|
1483
|
-
for (const [modelName, modelDef] of Object.entries(input.newModels)) {
|
|
1484
|
-
if (!modelDef || typeof modelDef !== 'object') {
|
|
1485
|
-
throw new Error(`Invalid model definition for "${modelName}": must be an object`);
|
|
1486
|
-
}
|
|
1487
|
-
if (!modelDef.properties || typeof modelDef.properties !== 'object') {
|
|
1488
|
-
throw new Error(`Model "${modelName}" must have a "properties" object`);
|
|
1489
|
-
}
|
|
1490
|
-
}
|
|
1491
|
-
sendBack({ type: 'done', output: { valid: true } });
|
|
1492
|
-
};
|
|
1493
|
-
_validate().catch((error) => {
|
|
1494
|
-
sendBack({ type: 'error', error: error instanceof Error ? error : new Error(String(error)) });
|
|
1495
|
-
});
|
|
1496
|
-
return () => {
|
|
1497
|
-
// Cleanup
|
|
1498
|
-
};
|
|
1499
|
-
}),
|
|
1500
|
-
createModelInstances: fromCallback(({ sendBack, input }) => {
|
|
1501
|
-
const _createInstances = async () => {
|
|
1502
|
-
const debug = (await import('debug')).default;
|
|
1503
|
-
const logger = debug('seedSdk:schema:addModels:createInstances');
|
|
1504
|
-
const schemaMod = await Promise.resolve().then(function () { return Schema$1; });
|
|
1505
|
-
const { Schema: SchemaClass, schemaInstanceState } = schemaMod;
|
|
1506
|
-
const schemaName = input.schemaContext.metadata?.name || input.schemaContext.schemaName;
|
|
1507
|
-
const schemaInstance = SchemaClass.create(schemaName, {
|
|
1508
|
-
waitForReady: false,
|
|
1509
|
-
});
|
|
1510
|
-
const modelInstances = new Map();
|
|
1511
|
-
// Get instance state to store model instances
|
|
1512
|
-
const instanceState = schemaInstanceState.get(schemaInstance);
|
|
1513
|
-
if (!instanceState) {
|
|
1514
|
-
throw new Error('Schema instance state not found');
|
|
1515
|
-
}
|
|
1516
|
-
for (const [modelName, modelData] of Object.entries(input.models)) {
|
|
1517
|
-
try {
|
|
1518
|
-
logger(`Creating model instance for "${modelName}"`);
|
|
1519
|
-
// Look up modelFileId from database BEFORE creating the Model instance
|
|
1520
|
-
let modelFileId = undefined;
|
|
1521
|
-
try {
|
|
1522
|
-
const db = BaseDb.getAppDb();
|
|
1523
|
-
if (db) {
|
|
1524
|
-
const dbModels = await db
|
|
1525
|
-
.select()
|
|
1526
|
-
.from(models)
|
|
1527
|
-
.where(eq(models.name, modelName))
|
|
1528
|
-
.limit(1);
|
|
1529
|
-
if (dbModels.length > 0 && dbModels[0].schemaFileId) {
|
|
1530
|
-
modelFileId = dbModels[0].schemaFileId;
|
|
1531
|
-
logger(`Found modelFileId "${modelFileId}" for model "${modelName}" from database`);
|
|
1532
|
-
}
|
|
1533
|
-
}
|
|
1534
|
-
}
|
|
1535
|
-
catch (error) {
|
|
1536
|
-
logger(`Error looking up modelFileId from database: ${error}`);
|
|
1537
|
-
}
|
|
1538
|
-
// If not found in database, generate a new modelFileId for new models
|
|
1539
|
-
if (!modelFileId) {
|
|
1540
|
-
modelFileId = generateId();
|
|
1541
|
-
logger(`Generated new modelFileId "${modelFileId}" for new model "${modelName}"`);
|
|
1542
|
-
}
|
|
1543
|
-
// Create new Model instance with modelFileId
|
|
1544
|
-
// Model.create() will set _modelFileId in the context automatically
|
|
1545
|
-
const modelInstance = Model.create(modelName, schemaName, {
|
|
1546
|
-
modelFileId,
|
|
1547
|
-
waitForReady: false,
|
|
1548
|
-
});
|
|
1549
|
-
const service = modelInstance.getService();
|
|
1550
|
-
logger(`Created Model instance for "${modelName}" with modelFileId "${modelFileId}"`);
|
|
1551
|
-
// Wait for the Model service to finish loading (loadOrCreateModel completes)
|
|
1552
|
-
await new Promise((resolve) => {
|
|
1553
|
-
let resolved = false;
|
|
1554
|
-
let subscription = null;
|
|
1555
|
-
// Check if already idle
|
|
1556
|
-
const snapshot = service.getSnapshot();
|
|
1557
|
-
if (snapshot.value === 'idle') {
|
|
1558
|
-
const currentModelFileId = snapshot.context._modelFileId;
|
|
1559
|
-
if (currentModelFileId === modelFileId) {
|
|
1560
|
-
logger(`ModelFileId "${modelFileId}" correctly set for model "${modelName}"`);
|
|
1561
|
-
}
|
|
1562
|
-
else {
|
|
1563
|
-
logger(`WARNING: ModelFileId not set for model "${modelName}" (expected: "${modelFileId}", got: "${currentModelFileId || 'undefined'}")`);
|
|
1564
|
-
// Try to set it again
|
|
1565
|
-
service.send({
|
|
1566
|
-
type: 'updateContext',
|
|
1567
|
-
_modelFileId: modelFileId,
|
|
1568
|
-
});
|
|
1569
|
-
}
|
|
1570
|
-
resolved = true;
|
|
1571
|
-
resolve();
|
|
1572
|
-
return;
|
|
1573
|
-
}
|
|
1574
|
-
// Wait for service to become idle
|
|
1575
|
-
subscription = service.subscribe((snapshot) => {
|
|
1576
|
-
if (snapshot.value === 'idle') {
|
|
1577
|
-
if (subscription) {
|
|
1578
|
-
subscription.unsubscribe();
|
|
1579
|
-
subscription = null;
|
|
1580
|
-
}
|
|
1581
|
-
const currentModelFileId = snapshot.context._modelFileId;
|
|
1582
|
-
if (currentModelFileId === modelFileId) {
|
|
1583
|
-
logger(`ModelFileId "${modelFileId}" correctly set for model "${modelName}"`);
|
|
1584
|
-
}
|
|
1585
|
-
else {
|
|
1586
|
-
logger(`WARNING: ModelFileId not set for model "${modelName}" (expected: "${modelFileId}", got: "${currentModelFileId || 'undefined'}")`);
|
|
1587
|
-
// Try to set it again - but only once to avoid infinite loop
|
|
1588
|
-
if (!resolved) {
|
|
1589
|
-
service.send({
|
|
1590
|
-
type: 'updateContext',
|
|
1591
|
-
_modelFileId: modelFileId,
|
|
1592
|
-
});
|
|
1593
|
-
}
|
|
1594
|
-
}
|
|
1595
|
-
if (!resolved) {
|
|
1596
|
-
resolved = true;
|
|
1597
|
-
resolve();
|
|
1598
|
-
}
|
|
1599
|
-
}
|
|
1600
|
-
else if (snapshot.value === 'error') {
|
|
1601
|
-
if (subscription) {
|
|
1602
|
-
subscription.unsubscribe();
|
|
1603
|
-
subscription = null;
|
|
1604
|
-
}
|
|
1605
|
-
if (!resolved) {
|
|
1606
|
-
resolved = true;
|
|
1607
|
-
resolve();
|
|
1608
|
-
}
|
|
1609
|
-
}
|
|
1610
|
-
});
|
|
1611
|
-
// Timeout after 2 seconds
|
|
1612
|
-
setTimeout(() => {
|
|
1613
|
-
if (subscription) {
|
|
1614
|
-
subscription.unsubscribe();
|
|
1615
|
-
subscription = null;
|
|
1616
|
-
}
|
|
1617
|
-
if (!resolved) {
|
|
1618
|
-
resolved = true;
|
|
1619
|
-
resolve();
|
|
1620
|
-
}
|
|
1621
|
-
}, 2000);
|
|
1622
|
-
});
|
|
1623
|
-
// Update the model instance with current data
|
|
1624
|
-
modelInstance.getService().send({
|
|
1625
|
-
type: 'updateContext',
|
|
1626
|
-
properties: modelData.properties || {},
|
|
1627
|
-
});
|
|
1628
|
-
// Initialize original values
|
|
1629
|
-
modelInstance.getService().send({
|
|
1630
|
-
type: 'initializeOriginalValues',
|
|
1631
|
-
originalValues: {
|
|
1632
|
-
_originalValues: {
|
|
1633
|
-
properties: modelData.properties ? JSON.parse(JSON.stringify(modelData.properties)) : {},
|
|
1634
|
-
},
|
|
1635
|
-
},
|
|
1636
|
-
isEdited: false,
|
|
1637
|
-
});
|
|
1638
|
-
// Store in instance state
|
|
1639
|
-
if (!instanceState.modelInstances) {
|
|
1640
|
-
instanceState.modelInstances = new Map();
|
|
1641
|
-
}
|
|
1642
|
-
instanceState.modelInstances.set(modelName, modelInstance);
|
|
1643
|
-
modelInstances.set(modelName, modelInstance);
|
|
1644
|
-
logger(`Successfully created model instance for "${modelName}"`);
|
|
1645
|
-
}
|
|
1646
|
-
catch (error) {
|
|
1647
|
-
logger(`Error creating model instance for "${modelName}": ${error}`);
|
|
1648
|
-
throw error;
|
|
1649
|
-
}
|
|
1650
|
-
}
|
|
1651
|
-
sendBack({
|
|
1652
|
-
type: 'done',
|
|
1653
|
-
output: { modelInstances }
|
|
1654
|
-
});
|
|
1655
|
-
};
|
|
1656
|
-
_createInstances().catch((error) => {
|
|
1657
|
-
sendBack({ type: 'error', error: error instanceof Error ? error : new Error(String(error)) });
|
|
1658
|
-
});
|
|
1659
|
-
return () => {
|
|
1660
|
-
// Cleanup
|
|
1661
|
-
};
|
|
1662
|
-
}),
|
|
1663
|
-
collectModelFileIds: fromCallback(({ sendBack, input }) => {
|
|
1664
|
-
const _collectIds = async () => {
|
|
1665
|
-
const debug = (await import('debug')).default;
|
|
1666
|
-
const logger = debug('seedSdk:schema:addModels:collectIds');
|
|
1667
|
-
const modelFileIds = new Map();
|
|
1668
|
-
for (const [modelName, modelInstance] of input.modelInstances.entries()) {
|
|
1669
|
-
try {
|
|
1670
|
-
const service = modelInstance.getService();
|
|
1671
|
-
let modelFileId = undefined;
|
|
1672
|
-
// Check current snapshot first
|
|
1673
|
-
const snapshot = service.getSnapshot();
|
|
1674
|
-
if (snapshot.value === 'idle' && snapshot.context._modelFileId) {
|
|
1675
|
-
modelFileId = snapshot.context._modelFileId;
|
|
1676
|
-
}
|
|
1677
|
-
else {
|
|
1678
|
-
// If not ready, wait for it to become idle
|
|
1679
|
-
await new Promise((resolve) => {
|
|
1680
|
-
const subscription = service.subscribe((snapshot) => {
|
|
1681
|
-
if (snapshot.value === 'idle') {
|
|
1682
|
-
subscription.unsubscribe();
|
|
1683
|
-
if (snapshot.context._modelFileId) {
|
|
1684
|
-
modelFileId = snapshot.context._modelFileId;
|
|
1685
|
-
}
|
|
1686
|
-
resolve();
|
|
1687
|
-
}
|
|
1688
|
-
else if (snapshot.value === 'error') {
|
|
1689
|
-
subscription.unsubscribe();
|
|
1690
|
-
resolve();
|
|
1691
|
-
}
|
|
1692
|
-
});
|
|
1693
|
-
// Timeout after 1 second
|
|
1694
|
-
setTimeout(() => {
|
|
1695
|
-
subscription.unsubscribe();
|
|
1696
|
-
resolve();
|
|
1697
|
-
}, 1000);
|
|
1698
|
-
});
|
|
1699
|
-
}
|
|
1700
|
-
if (modelFileId) {
|
|
1701
|
-
modelFileIds.set(modelName, modelFileId);
|
|
1702
|
-
logger(`Collected modelFileId "${modelFileId}" for model "${modelName}"`);
|
|
1703
|
-
}
|
|
1704
|
-
else {
|
|
1705
|
-
logger(`WARNING: modelFileId not found for model "${modelName}" after waiting`);
|
|
1706
|
-
}
|
|
1707
|
-
}
|
|
1708
|
-
catch (error) {
|
|
1709
|
-
logger(`Error collecting modelFileId for "${modelName}": ${error}`);
|
|
1710
|
-
// Continue with other models even if one fails
|
|
1711
|
-
}
|
|
1712
|
-
}
|
|
1713
|
-
sendBack({
|
|
1714
|
-
type: 'done',
|
|
1715
|
-
output: { modelFileIds }
|
|
1716
|
-
});
|
|
1717
|
-
};
|
|
1718
|
-
_collectIds().catch((error) => {
|
|
1719
|
-
sendBack({ type: 'error', error: error instanceof Error ? error : new Error(String(error)) });
|
|
1720
|
-
});
|
|
1721
|
-
return () => {
|
|
1722
|
-
// Cleanup
|
|
1723
|
-
};
|
|
1724
|
-
}),
|
|
1725
|
-
persistModelsToDb: fromCallback(({ sendBack, input }) => {
|
|
1726
|
-
const _persist = async () => {
|
|
1727
|
-
const debug = (await import('debug')).default;
|
|
1728
|
-
const logger = debug('seedSdk:schema:addModels:persist');
|
|
1729
|
-
// Only process in browser environment where store is available
|
|
1730
|
-
if (typeof window === 'undefined') {
|
|
1731
|
-
logger('Not in browser environment, skipping store update');
|
|
1732
|
-
sendBack({
|
|
1733
|
-
type: 'done',
|
|
1734
|
-
output: { addedModels: input.models }
|
|
1735
|
-
});
|
|
1736
|
-
return;
|
|
1737
|
-
}
|
|
1738
|
-
const schemaName = input.schemaContext.metadata?.name || input.schemaContext.schemaName;
|
|
1739
|
-
const schemaFileId = input.schemaContext.id; // id is the schemaFileId (string) in SchemaMachineContext
|
|
1740
|
-
const db = BaseDb.getAppDb();
|
|
1741
|
-
if (!db) {
|
|
1742
|
-
logger('Database not found, skipping model store update');
|
|
1743
|
-
sendBack({
|
|
1744
|
-
type: 'done',
|
|
1745
|
-
output: { addedModels: input.models }
|
|
1746
|
-
});
|
|
1747
|
-
return;
|
|
1748
|
-
}
|
|
1749
|
-
// Find schema record - prefer schemaFileId lookup (more reliable), then fall back to name
|
|
1750
|
-
// Retry up to 3 times with a short delay in case schema is still being saved
|
|
1751
|
-
let schemaRecord;
|
|
1752
|
-
const maxRetries = 3;
|
|
1753
|
-
const retryDelay = 100; // ms
|
|
1754
|
-
for (let attempt = 0; attempt < maxRetries && !schemaRecord; attempt++) {
|
|
1755
|
-
if (attempt > 0) {
|
|
1756
|
-
logger(`Retry ${attempt}/${maxRetries - 1} to find schema, waiting ${retryDelay}ms...`);
|
|
1757
|
-
await new Promise(resolve => setTimeout(resolve, retryDelay));
|
|
1758
|
-
}
|
|
1759
|
-
// PRIMARY: Look up by schemaFileId if available (most reliable, independent of name changes)
|
|
1760
|
-
if (schemaFileId) {
|
|
1761
|
-
logger(`Looking up schema by schemaFileId: ${schemaFileId} (attempt ${attempt + 1})`);
|
|
1762
|
-
const schemasById = await db
|
|
1763
|
-
.select()
|
|
1764
|
-
.from(schemas)
|
|
1765
|
-
.where(eq(schemas.schemaFileId, schemaFileId))
|
|
1766
|
-
.limit(1);
|
|
1767
|
-
if (schemasById.length > 0) {
|
|
1768
|
-
schemaRecord = schemasById[0];
|
|
1769
|
-
if (schemaRecord) {
|
|
1770
|
-
logger(`Found schema by schemaFileId: ${schemaFileId} (id: ${schemaRecord.id}, name: ${schemaRecord.name}, isDraft: ${schemaRecord.isDraft})`);
|
|
1771
|
-
}
|
|
1772
|
-
break;
|
|
1773
|
-
}
|
|
1774
|
-
else {
|
|
1775
|
-
logger(`No schema found by schemaFileId: ${schemaFileId}, will try by name`);
|
|
1776
|
-
}
|
|
1777
|
-
}
|
|
1778
|
-
// FALLBACK: If not found by schemaFileId, try by name (prefer draft records)
|
|
1779
|
-
if (!schemaRecord) {
|
|
1780
|
-
logger(`Looking up schema by name: "${schemaName}" (attempt ${attempt + 1})`);
|
|
1781
|
-
const schemasByName = await db
|
|
1782
|
-
.select()
|
|
1783
|
-
.from(schemas)
|
|
1784
|
-
.where(eq(schemas.name, schemaName))
|
|
1785
|
-
.orderBy(desc(schemas.isDraft), desc(schemas.version))
|
|
1786
|
-
.limit(10); // Get multiple to find drafts
|
|
1787
|
-
if (schemasByName.length > 0) {
|
|
1788
|
-
// Prefer draft records
|
|
1789
|
-
const draftRecord = schemasByName.find((s) => s.isDraft === true);
|
|
1790
|
-
schemaRecord = draftRecord || schemasByName[0];
|
|
1791
|
-
if (schemaRecord) {
|
|
1792
|
-
logger(`Found schema by name "${schemaName}": selected ${draftRecord ? 'draft' : 'first'} record (id: ${schemaRecord.id}, isDraft: ${schemaRecord.isDraft})`);
|
|
1793
|
-
}
|
|
1794
|
-
break;
|
|
1795
|
-
}
|
|
1796
|
-
}
|
|
1797
|
-
}
|
|
1798
|
-
if (!schemaRecord) {
|
|
1799
|
-
logger(`Schema "${schemaName}" (schemaFileId: ${schemaFileId || 'none'}) not found in database after ${maxRetries} attempts, skipping model store update`);
|
|
1800
|
-
sendBack({
|
|
1801
|
-
type: 'done',
|
|
1802
|
-
output: { addedModels: input.models }
|
|
1803
|
-
});
|
|
1804
|
-
return;
|
|
1805
|
-
}
|
|
1806
|
-
// Convert schema model format to JSON import format for createModelFromJson
|
|
1807
|
-
const modelDefinitions = {};
|
|
1808
|
-
for (const [modelName, modelDef] of Object.entries(input.models)) {
|
|
1809
|
-
// Convert properties from schema format to JSON import format
|
|
1810
|
-
const convertedProperties = {};
|
|
1811
|
-
if (modelDef.properties) {
|
|
1812
|
-
for (const [propName, propDef] of Object.entries(modelDef.properties)) {
|
|
1813
|
-
// Schema format: { dataType, ref, refValueType, storageType, localStorageDir, filenameSuffix }
|
|
1814
|
-
// JSON import format: { type, model, items, storage: { type, path, extension } }
|
|
1815
|
-
const schemaProp = propDef;
|
|
1816
|
-
const jsonProp = {
|
|
1817
|
-
type: schemaProp.dataType || schemaProp.type,
|
|
1818
|
-
};
|
|
1819
|
-
// Handle Relation type
|
|
1820
|
-
if (schemaProp.ref || schemaProp.refModelName) {
|
|
1821
|
-
jsonProp.model = schemaProp.refModelName || schemaProp.ref;
|
|
1822
|
-
}
|
|
1823
|
-
// Handle List type
|
|
1824
|
-
if (isDataType(schemaProp.dataType, ModelPropertyDataTypes.List) && schemaProp.refValueType) {
|
|
1825
|
-
jsonProp.refValueType = schemaProp.refValueType;
|
|
1826
|
-
if (schemaProp.ref || schemaProp.refModelName) {
|
|
1827
|
-
jsonProp.ref = schemaProp.refModelName || schemaProp.ref;
|
|
1828
|
-
}
|
|
1829
|
-
}
|
|
1830
|
-
// Handle storage configuration
|
|
1831
|
-
if (schemaProp.storageType || schemaProp.localStorageDir || schemaProp.filenameSuffix) {
|
|
1832
|
-
jsonProp.storage = {
|
|
1833
|
-
type: schemaProp.storageType === 'ItemStorage' ? 'ItemStorage' : 'PropertyStorage',
|
|
1834
|
-
path: schemaProp.localStorageDir,
|
|
1835
|
-
extension: schemaProp.filenameSuffix,
|
|
1836
|
-
};
|
|
1837
|
-
}
|
|
1838
|
-
if (schemaProp.required !== undefined) {
|
|
1839
|
-
jsonProp.required = schemaProp.required;
|
|
1840
|
-
}
|
|
1841
|
-
convertedProperties[propName] = jsonProp;
|
|
1842
|
-
}
|
|
1843
|
-
}
|
|
1844
|
-
// Create model definition in JSON import format
|
|
1845
|
-
// Note: description is not passed - JSON files can have it but we ignore it at runtime
|
|
1846
|
-
const jsonModelDef = {
|
|
1847
|
-
properties: convertedProperties,
|
|
1848
|
-
};
|
|
1849
|
-
// Create Model instance
|
|
1850
|
-
const ModelClass = await createModelFromJson(modelName, jsonModelDef, schemaName);
|
|
1851
|
-
modelDefinitions[modelName] = ModelClass;
|
|
1852
|
-
// Model is now accessible via Model static methods, no registration needed
|
|
1853
|
-
logger(`Created model "${modelName}"`);
|
|
1854
|
-
}
|
|
1855
|
-
// Add models to database with modelFileIds
|
|
1856
|
-
if (Object.keys(modelDefinitions).length > 0) {
|
|
1857
|
-
await addModelsToDb(modelDefinitions, schemaRecord, undefined, {
|
|
1858
|
-
schemaFileId: input.schemaContext.id, // id is the schemaFileId (string) in SchemaMachineContext
|
|
1859
|
-
modelFileIds: input.modelFileIds.size > 0 ? input.modelFileIds : undefined,
|
|
1860
|
-
});
|
|
1861
|
-
logger(`Added ${Object.keys(modelDefinitions).length} new models to database`);
|
|
1862
|
-
}
|
|
1863
|
-
sendBack({
|
|
1864
|
-
type: 'done',
|
|
1865
|
-
output: { addedModels: input.models }
|
|
1866
|
-
});
|
|
1867
|
-
};
|
|
1868
|
-
_persist().catch((error) => {
|
|
1869
|
-
sendBack({ type: 'error', error: error instanceof Error ? error : new Error(String(error)) });
|
|
1870
|
-
});
|
|
1871
|
-
return () => {
|
|
1872
|
-
// Cleanup
|
|
1873
|
-
};
|
|
1874
|
-
}),
|
|
1875
|
-
},
|
|
1876
|
-
}).createMachine({
|
|
1877
|
-
id: 'addModels',
|
|
1878
|
-
initial: 'preparing',
|
|
1879
|
-
context: ({ input }) => ({
|
|
1880
|
-
schemaContext: input.schemaContext,
|
|
1881
|
-
models: input.models,
|
|
1882
|
-
existingModels: input.existingModels,
|
|
1883
|
-
progress: {
|
|
1884
|
-
stage: 'preparing',
|
|
1885
|
-
totalModels: Object.keys(input.models).length,
|
|
1886
|
-
completedModels: 0,
|
|
1887
|
-
},
|
|
1888
|
-
}),
|
|
1889
|
-
states: {
|
|
1890
|
-
preparing: {
|
|
1891
|
-
invoke: {
|
|
1892
|
-
src: 'validateModels',
|
|
1893
|
-
input: ({ context }) => ({
|
|
1894
|
-
newModels: context.models,
|
|
1895
|
-
existingModels: context.existingModels,
|
|
1896
|
-
}),
|
|
1897
|
-
onDone: {
|
|
1898
|
-
target: 'creatingInstances',
|
|
1899
|
-
actions: assign({
|
|
1900
|
-
progress: ({ context }) => ({
|
|
1901
|
-
...context.progress,
|
|
1902
|
-
stage: 'creatingInstances',
|
|
1903
|
-
}),
|
|
1904
|
-
}),
|
|
1905
|
-
},
|
|
1906
|
-
onError: {
|
|
1907
|
-
target: 'error',
|
|
1908
|
-
actions: assign({
|
|
1909
|
-
errors: ({ context, event }) => [
|
|
1910
|
-
...(context.errors || []),
|
|
1911
|
-
{
|
|
1912
|
-
modelName: 'validation',
|
|
1913
|
-
error: event.error instanceof Error ? event.error : new Error(String(event.error))
|
|
1914
|
-
},
|
|
1915
|
-
],
|
|
1916
|
-
}),
|
|
1917
|
-
},
|
|
1918
|
-
},
|
|
1919
|
-
},
|
|
1920
|
-
creatingInstances: {
|
|
1921
|
-
invoke: {
|
|
1922
|
-
src: 'createModelInstances',
|
|
1923
|
-
input: ({ context }) => ({
|
|
1924
|
-
schemaContext: context.schemaContext,
|
|
1925
|
-
models: context.models,
|
|
1926
|
-
}),
|
|
1927
|
-
onDone: {
|
|
1928
|
-
target: 'collectingIds',
|
|
1929
|
-
actions: assign({
|
|
1930
|
-
modelInstances: ({ event }) => {
|
|
1931
|
-
// Type assertion needed due to XState v5 type inference limitation
|
|
1932
|
-
const doneEvent = event;
|
|
1933
|
-
return doneEvent.output?.modelInstances;
|
|
1934
|
-
},
|
|
1935
|
-
progress: ({ context }) => ({
|
|
1936
|
-
...context.progress,
|
|
1937
|
-
stage: 'collectingIds',
|
|
1938
|
-
}),
|
|
1939
|
-
}),
|
|
1940
|
-
},
|
|
1941
|
-
onError: {
|
|
1942
|
-
target: 'error',
|
|
1943
|
-
actions: assign({
|
|
1944
|
-
errors: ({ context, event }) => [
|
|
1945
|
-
...(context.errors || []),
|
|
1946
|
-
{
|
|
1947
|
-
modelName: 'createInstances',
|
|
1948
|
-
error: event.error instanceof Error ? event.error : new Error(String(event.error))
|
|
1949
|
-
},
|
|
1950
|
-
],
|
|
1951
|
-
}),
|
|
1952
|
-
},
|
|
1953
|
-
},
|
|
1954
|
-
},
|
|
1955
|
-
collectingIds: {
|
|
1956
|
-
invoke: {
|
|
1957
|
-
src: 'collectModelFileIds',
|
|
1958
|
-
input: ({ context }) => ({
|
|
1959
|
-
modelInstances: context.modelInstances,
|
|
1960
|
-
}),
|
|
1961
|
-
onDone: {
|
|
1962
|
-
target: 'persisting',
|
|
1963
|
-
actions: assign({
|
|
1964
|
-
modelFileIds: ({ event }) => {
|
|
1965
|
-
// Type assertion needed due to XState v5 type inference limitation
|
|
1966
|
-
const doneEvent = event;
|
|
1967
|
-
return doneEvent.output?.modelFileIds;
|
|
1968
|
-
},
|
|
1969
|
-
progress: ({ context }) => ({
|
|
1970
|
-
...context.progress,
|
|
1971
|
-
stage: 'persisting',
|
|
1972
|
-
}),
|
|
1973
|
-
}),
|
|
1974
|
-
},
|
|
1975
|
-
onError: {
|
|
1976
|
-
target: 'error',
|
|
1977
|
-
actions: assign({
|
|
1978
|
-
errors: ({ context, event }) => [
|
|
1979
|
-
...(context.errors || []),
|
|
1980
|
-
{
|
|
1981
|
-
modelName: 'collectIds',
|
|
1982
|
-
error: event.error instanceof Error ? event.error : new Error(String(event.error))
|
|
1983
|
-
},
|
|
1984
|
-
],
|
|
1985
|
-
}),
|
|
1986
|
-
},
|
|
1987
|
-
},
|
|
1988
|
-
},
|
|
1989
|
-
persisting: {
|
|
1990
|
-
invoke: {
|
|
1991
|
-
src: 'persistModelsToDb',
|
|
1992
|
-
input: ({ context }) => ({
|
|
1993
|
-
schemaContext: context.schemaContext,
|
|
1994
|
-
models: context.models,
|
|
1995
|
-
modelFileIds: context.modelFileIds,
|
|
1996
|
-
}),
|
|
1997
|
-
onDone: {
|
|
1998
|
-
target: '#addModels.success',
|
|
1999
|
-
actions: assign({
|
|
2000
|
-
addedModels: ({ event }) => {
|
|
2001
|
-
// Type assertion needed due to XState v5 type inference limitation
|
|
2002
|
-
// Convert through unknown first to avoid type overlap error
|
|
2003
|
-
const doneEvent = event;
|
|
2004
|
-
return { addedModels: doneEvent.output?.addedModels };
|
|
2005
|
-
},
|
|
2006
|
-
}),
|
|
2007
|
-
},
|
|
2008
|
-
onError: {
|
|
2009
|
-
target: 'error',
|
|
2010
|
-
actions: assign({
|
|
2011
|
-
errors: ({ context, event }) => [
|
|
2012
|
-
...(context.errors || []),
|
|
2013
|
-
{ modelName: 'persist', error: event.error instanceof Error ? event.error : new Error(String(event.error)) },
|
|
2014
|
-
],
|
|
2015
|
-
}),
|
|
2016
|
-
},
|
|
2017
|
-
},
|
|
2018
|
-
},
|
|
2019
|
-
success: {
|
|
2020
|
-
id: 'success',
|
|
2021
|
-
type: 'final',
|
|
2022
|
-
output: ({ context }) => ({ addedModels: context.addedModels?.addedModels || [] }),
|
|
2023
|
-
},
|
|
2024
|
-
error: {
|
|
2025
|
-
type: 'final',
|
|
2026
|
-
output: ({ context }) => ({
|
|
2027
|
-
errors: context.errors || [],
|
|
2028
|
-
}),
|
|
2029
|
-
},
|
|
2030
|
-
},
|
|
2031
|
-
});
|
|
2032
|
-
|
|
2033
1460
|
const logger$c = debug('seedSdk:schema:actors:checkExistingSchema');
|
|
2034
1461
|
/**
|
|
2035
1462
|
* Query model IDs (schemaFileId) from database for a given schema
|
|
@@ -2079,13 +1506,13 @@ const getSchemaFilePath$1 = (name, version, schemaFileId) => {
|
|
|
2079
1506
|
/**
|
|
2080
1507
|
* Create Model instances for all model IDs to ensure they're cached
|
|
2081
1508
|
*/
|
|
2082
|
-
const createModelInstances$1 = async (modelIds) => {
|
|
1509
|
+
const createModelInstances$1 = async (modelIds, evictionEpoch) => {
|
|
2083
1510
|
if (modelIds.length === 0) {
|
|
2084
1511
|
return;
|
|
2085
1512
|
}
|
|
2086
1513
|
try {
|
|
2087
|
-
const _mod_7 = await import('./index-
|
|
2088
|
-
const _ns_7 = _mod_7.
|
|
1514
|
+
const _mod_7 = await import('./index-Y-yYyRBf.js');
|
|
1515
|
+
const _ns_7 = _mod_7.f;
|
|
2089
1516
|
const mod = _ns_7;
|
|
2090
1517
|
const Model = mod?.Model ?? mod?.default;
|
|
2091
1518
|
if (!Model) {
|
|
@@ -2094,7 +1521,8 @@ const createModelInstances$1 = async (modelIds) => {
|
|
|
2094
1521
|
}
|
|
2095
1522
|
const createPromises = modelIds.map(async (modelFileId) => {
|
|
2096
1523
|
try {
|
|
2097
|
-
|
|
1524
|
+
// Not if the schema was evicted (Schema.destroy, test cleanup) since this check started
|
|
1525
|
+
const model = await Model.createById(modelFileId, { evictionEpoch });
|
|
2098
1526
|
if (model) {
|
|
2099
1527
|
logger$c(`Created/cached Model instance for modelFileId "${modelFileId}"`);
|
|
2100
1528
|
}
|
|
@@ -2111,6 +1539,7 @@ const createModelInstances$1 = async (modelIds) => {
|
|
|
2111
1539
|
}
|
|
2112
1540
|
};
|
|
2113
1541
|
const checkExistingSchema = fromCallback(({ sendBack, input: { context } }) => {
|
|
1542
|
+
const evictionEpoch = currentEvictionEpoch();
|
|
2114
1543
|
const _check = async () => {
|
|
2115
1544
|
const { schemaName } = context;
|
|
2116
1545
|
if (!schemaName) {
|
|
@@ -2131,8 +1560,8 @@ const checkExistingSchema = fromCallback(({ sendBack, input: { context } }) => {
|
|
|
2131
1560
|
if (isInternal && schemaName === SEED_PROTOCOL_SCHEMA_NAME) {
|
|
2132
1561
|
// For Seed Protocol, check if it exists in database
|
|
2133
1562
|
try {
|
|
2134
|
-
const _mod_8 = await import('./ClientManager-
|
|
2135
|
-
const _ns_8 = _mod_8.
|
|
1563
|
+
const _mod_8 = await import('./ClientManager-DngaZdw6.js');
|
|
1564
|
+
const _ns_8 = _mod_8.S;
|
|
2136
1565
|
const internalSchema = _ns_8;
|
|
2137
1566
|
const schemaFile = internalSchema.default;
|
|
2138
1567
|
if (db && schemaFile.id) {
|
|
@@ -2146,7 +1575,7 @@ const checkExistingSchema = fromCallback(({ sendBack, input: { context } }) => {
|
|
|
2146
1575
|
let modelIds = [];
|
|
2147
1576
|
if (schemaRecord.id) {
|
|
2148
1577
|
modelIds = await getModelIdsForSchema(schemaRecord.id);
|
|
2149
|
-
await createModelInstances$1(modelIds);
|
|
1578
|
+
await createModelInstances$1(modelIds, evictionEpoch);
|
|
2150
1579
|
}
|
|
2151
1580
|
sendBack({
|
|
2152
1581
|
type: 'schemaFound',
|
|
@@ -2353,7 +1782,7 @@ const checkExistingSchema = fromCallback(({ sendBack, input: { context } }) => {
|
|
|
2353
1782
|
let modelIds = [];
|
|
2354
1783
|
if (dbSchema.id) {
|
|
2355
1784
|
modelIds = await getModelIdsForSchema(dbSchema.id);
|
|
2356
|
-
await createModelInstances$1(modelIds);
|
|
1785
|
+
await createModelInstances$1(modelIds, evictionEpoch);
|
|
2357
1786
|
}
|
|
2358
1787
|
const loadedAt = Date.now();
|
|
2359
1788
|
const dbVersion = dbSchema.version || schemaFile.version;
|
|
@@ -2407,7 +1836,7 @@ const checkExistingSchema = fromCallback(({ sendBack, input: { context } }) => {
|
|
|
2407
1836
|
let modelIds = [];
|
|
2408
1837
|
if (matchingDraft.id) {
|
|
2409
1838
|
modelIds = await getModelIdsForSchema(matchingDraft.id);
|
|
2410
|
-
await createModelInstances$1(modelIds);
|
|
1839
|
+
await createModelInstances$1(modelIds, evictionEpoch);
|
|
2411
1840
|
}
|
|
2412
1841
|
const loadedAt = Date.now();
|
|
2413
1842
|
const dbVersion = matchingDraft.version || schemaFile.version;
|
|
@@ -2442,7 +1871,7 @@ const checkExistingSchema = fromCallback(({ sendBack, input: { context } }) => {
|
|
|
2442
1871
|
.limit(1);
|
|
2443
1872
|
if (schemaRecords.length > 0 && schemaRecords[0].id) {
|
|
2444
1873
|
modelIds = await getModelIdsForSchema(schemaRecords[0].id);
|
|
2445
|
-
await createModelInstances$1(modelIds);
|
|
1874
|
+
await createModelInstances$1(modelIds, evictionEpoch);
|
|
2446
1875
|
}
|
|
2447
1876
|
}
|
|
2448
1877
|
}
|
|
@@ -2491,8 +1920,8 @@ const writeSchemaToDb = fromCallback(({ sendBack, input }) => {
|
|
|
2491
1920
|
if (isInternal && schemaName === SEED_PROTOCOL_SCHEMA_NAME) {
|
|
2492
1921
|
// For Seed Protocol, load from internal file
|
|
2493
1922
|
logger$b(`Loading internal Seed Protocol schema from SDK`);
|
|
2494
|
-
const _mod_9 = await import('./ClientManager-
|
|
2495
|
-
const _ns_9 = _mod_9.
|
|
1923
|
+
const _mod_9 = await import('./ClientManager-DngaZdw6.js');
|
|
1924
|
+
const _ns_9 = _mod_9.S;
|
|
2496
1925
|
const internalSchema = _ns_9;
|
|
2497
1926
|
finalSchema = internalSchema.default;
|
|
2498
1927
|
const db = BaseDb.getAppDb();
|
|
@@ -2950,6 +2379,7 @@ const logger$7 = debug('seedSdk:schema:actors:createModelInstances');
|
|
|
2950
2379
|
* This ensures that Model.getById() in Schema.getContext() will find the instances
|
|
2951
2380
|
*/
|
|
2952
2381
|
const createModelInstances = fromCallback(({ sendBack, input }) => {
|
|
2382
|
+
const evictionEpoch = currentEvictionEpoch();
|
|
2953
2383
|
const _create = async () => {
|
|
2954
2384
|
const { modelIds, schemaName } = input;
|
|
2955
2385
|
if (modelIds.length === 0) {
|
|
@@ -2961,15 +2391,16 @@ const createModelInstances = fromCallback(({ sendBack, input }) => {
|
|
|
2961
2391
|
return;
|
|
2962
2392
|
}
|
|
2963
2393
|
try {
|
|
2964
|
-
const _mod_10 = await import('./index-
|
|
2965
|
-
const _ns_10 = _mod_10.
|
|
2394
|
+
const _mod_10 = await import('./index-Y-yYyRBf.js');
|
|
2395
|
+
const _ns_10 = _mod_10.f;
|
|
2966
2396
|
const modelMod = _ns_10;
|
|
2967
2397
|
const { Model } = modelMod;
|
|
2968
2398
|
// Create instances for all model IDs in parallel
|
|
2969
2399
|
// Model.createById() will check cache first, then query DB and create if needed
|
|
2970
2400
|
const createPromises = modelIds.map(async (modelFileId) => {
|
|
2971
2401
|
try {
|
|
2972
|
-
|
|
2402
|
+
// Not if the schema was evicted (Schema.destroy, test cleanup) since this started
|
|
2403
|
+
const model = await Model.createById(modelFileId, { evictionEpoch });
|
|
2973
2404
|
if (model) {
|
|
2974
2405
|
logger$7(`Created/cached Model instance for modelFileId "${modelFileId}"`);
|
|
2975
2406
|
return true;
|
|
@@ -3049,8 +2480,8 @@ const verifyModelInstancesInCache = fromCallback(({ sendBack, input }) => {
|
|
|
3049
2480
|
}
|
|
3050
2481
|
try {
|
|
3051
2482
|
const result = await verifyWithRetry$2(async () => {
|
|
3052
|
-
const _mod_11 = await import('./index-
|
|
3053
|
-
const _ns_11 = _mod_11.
|
|
2483
|
+
const _mod_11 = await import('./index-Y-yYyRBf.js');
|
|
2484
|
+
const _ns_11 = _mod_11.f;
|
|
3054
2485
|
const modelMod = _ns_11;
|
|
3055
2486
|
const { Model } = modelMod;
|
|
3056
2487
|
// Check each model ID in the cache
|
|
@@ -3108,8 +2539,8 @@ const writePropertiesToDb = fromCallback(({ sendBack, input }) => {
|
|
|
3108
2539
|
const _write = async () => {
|
|
3109
2540
|
const { modelIds } = input;
|
|
3110
2541
|
try {
|
|
3111
|
-
const _mod_12 = await import('./BasePathResolver-
|
|
3112
|
-
const _ns_12 = _mod_12.
|
|
2542
|
+
const _mod_12 = await import('./BasePathResolver-DRT09oVv.js');
|
|
2543
|
+
const _ns_12 = _mod_12.N;
|
|
3113
2544
|
const modelSchemaMod = _ns_12;
|
|
3114
2545
|
const { models: modelsTable, properties: propertiesTable } = modelSchemaMod;
|
|
3115
2546
|
const drizzleMod = await import('drizzle-orm');
|
|
@@ -3298,10 +2729,10 @@ const createPropertyInstances = fromCallback(({ sendBack, input }) => {
|
|
|
3298
2729
|
return;
|
|
3299
2730
|
}
|
|
3300
2731
|
try {
|
|
3301
|
-
const modProp = await import('./ModelProperty-
|
|
2732
|
+
const modProp = await import('./ModelProperty-6llK4MTH.js');
|
|
3302
2733
|
const ModelProperty = modProp?.ModelProperty ?? modProp?.default;
|
|
3303
|
-
const _mod_13 = await import('./index-
|
|
3304
|
-
const _ns_13 = _mod_13.
|
|
2734
|
+
const _mod_13 = await import('./index-Y-yYyRBf.js');
|
|
2735
|
+
const _ns_13 = _mod_13.f;
|
|
3305
2736
|
const modModel = _ns_13;
|
|
3306
2737
|
const Model = modModel?.Model ?? modModel?.default;
|
|
3307
2738
|
if (!ModelProperty || !Model) {
|
|
@@ -3407,7 +2838,7 @@ const verifyPropertyInstancesInCache = fromCallback(({ sendBack, input }) => {
|
|
|
3407
2838
|
}
|
|
3408
2839
|
try {
|
|
3409
2840
|
const result = await verifyWithRetry(async () => {
|
|
3410
|
-
const mod = await import('./ModelProperty-
|
|
2841
|
+
const mod = await import('./ModelProperty-6llK4MTH.js');
|
|
3411
2842
|
const ModelProperty = mod?.ModelProperty ?? mod?.default;
|
|
3412
2843
|
if (!ModelProperty) {
|
|
3413
2844
|
throw new Error('ModelProperty not available from dynamic import');
|
|
@@ -3467,7 +2898,6 @@ const schemaMachine = setup({
|
|
|
3467
2898
|
actors: {
|
|
3468
2899
|
loadOrCreateSchema,
|
|
3469
2900
|
validateSchema,
|
|
3470
|
-
addModelsMachine,
|
|
3471
2901
|
writeProcessMachine,
|
|
3472
2902
|
// Staged loading actors
|
|
3473
2903
|
checkExistingSchema,
|
|
@@ -3486,9 +2916,6 @@ const schemaMachine = setup({
|
|
|
3486
2916
|
isSchemaValid: ({ context }) => {
|
|
3487
2917
|
return !context._validationErrors || context._validationErrors.length === 0;
|
|
3488
2918
|
},
|
|
3489
|
-
hasValidationErrors: ({ context }) => {
|
|
3490
|
-
return !!context._validationErrors && context._validationErrors.length > 0;
|
|
3491
|
-
},
|
|
3492
2919
|
},
|
|
3493
2920
|
}).createMachine({
|
|
3494
2921
|
id: 'schema',
|
|
@@ -3572,22 +2999,15 @@ const schemaMachine = setup({
|
|
|
3572
2999
|
}),
|
|
3573
3000
|
},
|
|
3574
3001
|
destroyStarted: {
|
|
3575
|
-
actions: assign({
|
|
3576
|
-
},
|
|
3577
|
-
destroyDone: {
|
|
3578
|
-
actions: assign({ _destroyInProgress: false }),
|
|
3002
|
+
actions: assign({ _destroyError: null }),
|
|
3579
3003
|
},
|
|
3580
3004
|
destroyError: {
|
|
3581
3005
|
actions: assign(({ event }) => ({
|
|
3582
|
-
_destroyInProgress: false,
|
|
3583
3006
|
_destroyError: event.error instanceof Error
|
|
3584
3007
|
? { message: event.error.message, name: event.error.name }
|
|
3585
3008
|
: { message: String(event.error) },
|
|
3586
3009
|
})),
|
|
3587
3010
|
},
|
|
3588
|
-
clearDestroyError: {
|
|
3589
|
-
actions: assign({ _destroyError: null }),
|
|
3590
|
-
},
|
|
3591
3011
|
},
|
|
3592
3012
|
states: {
|
|
3593
3013
|
loading: {
|
|
@@ -3976,9 +3396,6 @@ const schemaMachine = setup({
|
|
|
3976
3396
|
},
|
|
3977
3397
|
}),
|
|
3978
3398
|
on: {
|
|
3979
|
-
addModels: {
|
|
3980
|
-
target: 'addingModels',
|
|
3981
|
-
},
|
|
3982
3399
|
validateSchema: {
|
|
3983
3400
|
target: 'validating',
|
|
3984
3401
|
},
|
|
@@ -3996,122 +3413,27 @@ const schemaMachine = setup({
|
|
|
3996
3413
|
},
|
|
3997
3414
|
},
|
|
3998
3415
|
},
|
|
3999
|
-
always:
|
|
4000
|
-
|
|
4001
|
-
|
|
4002
|
-
},
|
|
4003
|
-
},
|
|
4004
|
-
addingModels: {
|
|
4005
|
-
entry: assign({
|
|
4006
|
-
// Move first pending item to current if not already set
|
|
4007
|
-
_pendingModelAdditions: ({ context, event }) => {
|
|
4008
|
-
const pending = context._pendingModelAdditions || [];
|
|
4009
|
-
// If event has models, it's a new request - add to queue if we're already processing
|
|
4010
|
-
if (event.models) {
|
|
4011
|
-
return [
|
|
4012
|
-
...pending,
|
|
4013
|
-
{
|
|
4014
|
-
models: event.models,
|
|
4015
|
-
timestamp: Date.now(),
|
|
4016
|
-
},
|
|
4017
|
-
];
|
|
4018
|
-
}
|
|
4019
|
-
return pending;
|
|
4020
|
-
},
|
|
4021
|
-
}),
|
|
4022
|
-
invoke: {
|
|
4023
|
-
src: 'addModelsMachine',
|
|
4024
|
-
input: ({ context }) => {
|
|
4025
|
-
// Get models from first item in pending queue, or from context if queue is empty
|
|
4026
|
-
const pending = context._pendingModelAdditions || [];
|
|
4027
|
-
const models = pending.length > 0 ? pending[0].models : {};
|
|
4028
|
-
return {
|
|
4029
|
-
schemaContext: context,
|
|
4030
|
-
models,
|
|
4031
|
-
existingModels: context.models || {},
|
|
4032
|
-
};
|
|
4033
|
-
},
|
|
4034
|
-
onDone: {
|
|
4035
|
-
actions: [
|
|
4036
|
-
assign({
|
|
4037
|
-
models: ({ context, event }) => {
|
|
4038
|
-
const addedModels = event.output?.addedModels || {};
|
|
4039
|
-
return {
|
|
4040
|
-
...(context.models || {}),
|
|
4041
|
-
...addedModels,
|
|
4042
|
-
};
|
|
4043
|
-
},
|
|
4044
|
-
_pendingModelAdditions: ({ context }) => {
|
|
4045
|
-
// Remove first item from queue (the one we just processed)
|
|
4046
|
-
const pending = context._pendingModelAdditions || [];
|
|
4047
|
-
return pending.length > 1 ? pending.slice(1) : undefined;
|
|
4048
|
-
},
|
|
4049
|
-
}),
|
|
4050
|
-
// Trigger validation after models are added
|
|
4051
|
-
({ self }) => {
|
|
4052
|
-
self.send({ type: 'validateSchema' });
|
|
4053
|
-
},
|
|
4054
|
-
],
|
|
4055
|
-
},
|
|
4056
|
-
onError: {
|
|
4057
|
-
actions: assign({
|
|
4058
|
-
_modelAdditionErrors: ({ context, event }) => {
|
|
4059
|
-
const existing = context._modelAdditionErrors || [];
|
|
4060
|
-
return [
|
|
4061
|
-
...existing,
|
|
4062
|
-
{
|
|
4063
|
-
error: event.error instanceof Error ? event.error : new Error(String(event.error)),
|
|
4064
|
-
timestamp: Date.now(),
|
|
4065
|
-
},
|
|
4066
|
-
];
|
|
4067
|
-
},
|
|
4068
|
-
_pendingModelAdditions: ({ context }) => {
|
|
4069
|
-
// Remove first item from queue even on error, so we can process next
|
|
4070
|
-
const pending = context._pendingModelAdditions || [];
|
|
4071
|
-
return pending.length > 1 ? pending.slice(1) : undefined;
|
|
4072
|
-
},
|
|
4073
|
-
}),
|
|
4074
|
-
},
|
|
4075
|
-
},
|
|
4076
|
-
on: {
|
|
4077
|
-
// Queue additional requests while processing
|
|
4078
|
-
addModels: {
|
|
4079
|
-
actions: assign({
|
|
4080
|
-
_pendingModelAdditions: ({ context, event }) => {
|
|
4081
|
-
const existing = context._pendingModelAdditions || [];
|
|
4082
|
-
return [
|
|
4083
|
-
...existing,
|
|
4084
|
-
{
|
|
4085
|
-
models: event.models,
|
|
4086
|
-
timestamp: Date.now(),
|
|
4087
|
-
},
|
|
4088
|
-
];
|
|
4089
|
-
},
|
|
4090
|
-
}),
|
|
4091
|
-
},
|
|
4092
|
-
},
|
|
4093
|
-
always: [
|
|
4094
|
-
{
|
|
4095
|
-
// If there are pending additions after processing, process next one
|
|
4096
|
-
guard: ({ context }) => {
|
|
4097
|
-
const pending = context._pendingModelAdditions || [];
|
|
4098
|
-
return pending.length > 0;
|
|
4099
|
-
},
|
|
4100
|
-
target: 'addingModels',
|
|
4101
|
-
},
|
|
4102
|
-
{
|
|
4103
|
-
// No more pending, return to idle
|
|
4104
|
-
target: 'idle',
|
|
4105
|
-
},
|
|
4106
|
-
],
|
|
3416
|
+
// No `always: hasValidationErrors -> validating` here: validation is re-run when the context changes
|
|
3417
|
+
// (updateContext) or on request (validateSchema). Re-entering while errors exist would loop
|
|
3418
|
+
// forever on a schema that is still invalid.
|
|
4107
3419
|
},
|
|
4108
3420
|
validating: {
|
|
4109
3421
|
on: {
|
|
3422
|
+
// These state-level handlers take precedence over the root ones, so they must store the result
|
|
3423
|
+
// themselves.
|
|
4110
3424
|
validationSuccess: {
|
|
4111
3425
|
target: 'idle',
|
|
3426
|
+
actions: assign(({ context }) => ({
|
|
3427
|
+
...context,
|
|
3428
|
+
_validationErrors: [],
|
|
3429
|
+
})),
|
|
4112
3430
|
},
|
|
4113
3431
|
validationError: {
|
|
4114
3432
|
target: 'idle',
|
|
3433
|
+
actions: assign(({ context, event }) => ({
|
|
3434
|
+
...context,
|
|
3435
|
+
_validationErrors: event.errors,
|
|
3436
|
+
})),
|
|
4115
3437
|
},
|
|
4116
3438
|
},
|
|
4117
3439
|
invoke: {
|
|
@@ -4429,8 +3751,8 @@ async function loadSchemaWithRenames(schemaFilePath, modelRenames) {
|
|
|
4429
3751
|
updatedAt: new Date(schemaFile.metadata.updatedAt).getTime(),
|
|
4430
3752
|
};
|
|
4431
3753
|
// Use dynamic import to break circular dependency
|
|
4432
|
-
const _mod_14 = await import('./db-
|
|
4433
|
-
const _ns_14 = _mod_14.
|
|
3754
|
+
const _mod_14 = await import('./db-Lw0KVZmc.js');
|
|
3755
|
+
const _ns_14 = _mod_14.Z;
|
|
4434
3756
|
const dbMod = _ns_14;
|
|
4435
3757
|
const { addSchemaToDb, addModelsToDb } = dbMod;
|
|
4436
3758
|
// Add schema to database with schemaFileId
|
|
@@ -4542,10 +3864,10 @@ async function renameModelProperty(schemaName, modelName, oldPropertyName, newPr
|
|
|
4542
3864
|
await BaseFileManager.waitForFileWithContent(newFilePath);
|
|
4543
3865
|
logger$1(`Renamed property ${oldPropertyName} to ${newPropertyName} in schema ${schemaName} v${newVersion}`);
|
|
4544
3866
|
// Migrate metadata rows so ItemProperty values follow the new name (prevents duplicate ItemProperties)
|
|
4545
|
-
const _mod_15 = await import('./db-
|
|
4546
|
-
const _ns_15 = _mod_15.
|
|
3867
|
+
const _mod_15 = await import('./db-Lw0KVZmc.js');
|
|
3868
|
+
const _ns_15 = _mod_15.Z;
|
|
4547
3869
|
const { migrateMetadataForPropertyRename } = _ns_15;
|
|
4548
|
-
const migratedCount = await migrateMetadataForPropertyRename(modelName, oldPropertyName, newPropertyName, oldProperty.id);
|
|
3870
|
+
const migratedCount = await migrateMetadataForPropertyRename(modelName, oldPropertyName, newPropertyName, oldProperty.id, { schemaName });
|
|
4549
3871
|
if (migratedCount > 0) {
|
|
4550
3872
|
logger$1(`Migrated ${migratedCount} metadata rows for property rename`);
|
|
4551
3873
|
}
|
|
@@ -4820,7 +4142,6 @@ class Schema {
|
|
|
4820
4142
|
// Initialize instance state in WeakMap (only non-serializable resources)
|
|
4821
4143
|
schemaInstanceState.set(this, {
|
|
4822
4144
|
liveQuerySubscription: null,
|
|
4823
|
-
modelInstances: new Map(),
|
|
4824
4145
|
});
|
|
4825
4146
|
// Set up liveQuery subscription for cross-instance model updates
|
|
4826
4147
|
// This will be initialized once we have the schemaId
|
|
@@ -5030,118 +4351,10 @@ class Schema {
|
|
|
5030
4351
|
}
|
|
5031
4352
|
}
|
|
5032
4353
|
else if (prop === 'models') {
|
|
5033
|
-
// Models are read-only computed
|
|
5034
|
-
//
|
|
5035
|
-
throw new Error('Cannot set schema.models directly. Models are computed from Model instances
|
|
5036
|
-
|
|
5037
|
-
// Convert array of Model instances or plain objects back to object format
|
|
5038
|
-
let modelsObject: { [key: string]: any }
|
|
5039
|
-
if (Array.isArray(value)) {
|
|
5040
|
-
modelsObject = {}
|
|
5041
|
-
const seenNames = new Set<string>()
|
|
5042
|
-
|
|
5043
|
-
// Check for duplicate model names
|
|
5044
|
-
for (const model of value) {
|
|
5045
|
-
// Handle Model instances
|
|
5046
|
-
if (model instanceof Model) {
|
|
5047
|
-
const modelName = model.modelName!
|
|
5048
|
-
if (seenNames.has(modelName)) {
|
|
5049
|
-
throw new Error(
|
|
5050
|
-
`Duplicate model name detected: "${modelName}". Each model must have a unique name.`
|
|
5051
|
-
)
|
|
5052
|
-
}
|
|
5053
|
-
seenNames.add(modelName)
|
|
5054
|
-
modelsObject[modelName] = {
|
|
5055
|
-
properties: model.properties || {},
|
|
5056
|
-
}
|
|
5057
|
-
} else if (model && typeof model === 'object' && 'name' in model) {
|
|
5058
|
-
// Handle plain objects
|
|
5059
|
-
const modelName = model.name as string
|
|
5060
|
-
if (seenNames.has(modelName)) {
|
|
5061
|
-
throw new Error(
|
|
5062
|
-
`Duplicate model name detected: "${modelName}". Each model must have a unique name.`
|
|
5063
|
-
)
|
|
5064
|
-
}
|
|
5065
|
-
seenNames.add(modelName)
|
|
5066
|
-
const { name, ...modelData } = model
|
|
5067
|
-
modelsObject[name] = modelData
|
|
5068
|
-
}
|
|
5069
|
-
}
|
|
5070
|
-
} else {
|
|
5071
|
-
modelsObject = value || {}
|
|
5072
|
-
// Check for duplicates in object format too
|
|
5073
|
-
const modelNames = Object.keys(modelsObject)
|
|
5074
|
-
const seenNames = new Set<string>()
|
|
5075
|
-
for (const modelName of modelNames) {
|
|
5076
|
-
if (seenNames.has(modelName)) {
|
|
5077
|
-
throw new Error(
|
|
5078
|
-
`Duplicate model name detected: "${modelName}". Each model must have a unique name.`
|
|
5079
|
-
)
|
|
5080
|
-
}
|
|
5081
|
-
seenNames.add(modelName)
|
|
5082
|
-
}
|
|
5083
|
-
}
|
|
5084
|
-
|
|
5085
|
-
const context = newInstance._getSnapshotContext()
|
|
5086
|
-
|
|
5087
|
-
// Check if service is still running before sending events
|
|
5088
|
-
let snapshot = newInstance._service.getSnapshot()
|
|
5089
|
-
const wasServiceStopped = snapshot.status === 'stopped'
|
|
5090
|
-
|
|
5091
|
-
if (wasServiceStopped) {
|
|
5092
|
-
logger(`Service is stopped, will restart before adding models`)
|
|
5093
|
-
newInstance._service.start()
|
|
5094
|
-
snapshot = newInstance._service.getSnapshot()
|
|
5095
|
-
}
|
|
5096
|
-
|
|
5097
|
-
// Check current state after potential restart
|
|
5098
|
-
const currentState = snapshot.value
|
|
5099
|
-
// Check if state is a loading state object (XState v5 nested states)
|
|
5100
|
-
const isServiceLoading = typeof currentState === 'object' && 'loading' in currentState
|
|
5101
|
-
|
|
5102
|
-
// If service is loading, wait for it to finish before adding models
|
|
5103
|
-
if (isServiceLoading || wasServiceStopped) {
|
|
5104
|
-
logger(`Service is ${isServiceLoading ? 'loading' : 'was stopped'}, will add models after loading completes`)
|
|
5105
|
-
|
|
5106
|
-
const loadingSubscription = newInstance._service.subscribe((snapshot) => {
|
|
5107
|
-
if (snapshot.value === 'idle') {
|
|
5108
|
-
loadingSubscription.unsubscribe()
|
|
5109
|
-
logger(`Service finished loading, sending addModels event`)
|
|
5110
|
-
newInstance._service.send({
|
|
5111
|
-
type: 'addModels',
|
|
5112
|
-
models: modelsObject,
|
|
5113
|
-
})
|
|
5114
|
-
} else if (snapshot.value === 'error') {
|
|
5115
|
-
loadingSubscription.unsubscribe()
|
|
5116
|
-
logger(`Service failed to load, cannot add models`)
|
|
5117
|
-
}
|
|
5118
|
-
})
|
|
5119
|
-
} else {
|
|
5120
|
-
// Service is ready, send addModels event immediately
|
|
5121
|
-
// The state machine will handle all the complexity (validation, instance creation, ID collection, persistence)
|
|
5122
|
-
logger(`Service is ready, sending addModels event`)
|
|
5123
|
-
newInstance._service.send({
|
|
5124
|
-
type: 'addModels',
|
|
5125
|
-
models: modelsObject,
|
|
5126
|
-
})
|
|
5127
|
-
}
|
|
5128
|
-
|
|
5129
|
-
// Mark schema as draft when models change
|
|
5130
|
-
newInstance._service.send({
|
|
5131
|
-
type: 'markAsDraft',
|
|
5132
|
-
propertyKey: 'schema:models',
|
|
5133
|
-
})
|
|
5134
|
-
|
|
5135
|
-
// Save draft to database immediately so changes persist
|
|
5136
|
-
newInstance._saveDraftToDb().catch((error) => {
|
|
5137
|
-
logger(`Failed to save draft to database: ${error instanceof Error ? error.message : String(error)}`)
|
|
5138
|
-
})
|
|
5139
|
-
|
|
5140
|
-
// Update client context so useSchema and useSchemas hooks reflect the change
|
|
5141
|
-
newInstance._updateClientContext().catch(() => {
|
|
5142
|
-
// Silently fail if not in browser environment
|
|
5143
|
-
})
|
|
5144
|
-
*/
|
|
4354
|
+
// Models are read-only, computed from Model instances. Array assignment was removed because
|
|
4355
|
+
// the draft save could run before the new Model instances existed, losing them.
|
|
4356
|
+
throw new Error('Cannot set schema.models directly. Models are computed from Model instances; ' +
|
|
4357
|
+
'use Model.create(modelName, schema, { properties }) to add one.');
|
|
5145
4358
|
}
|
|
5146
4359
|
else if (prop === 'createdAt' || prop === 'updatedAt') {
|
|
5147
4360
|
// Update metadata object
|
|
@@ -5192,7 +4405,12 @@ class Schema {
|
|
|
5192
4405
|
return schema;
|
|
5193
4406
|
const readyPromise = waitForEntityIdle(schema, { timeout: readyTimeout }).then(() => schema);
|
|
5194
4407
|
this.pendingSchemaByName.set(schemaName, readyPromise);
|
|
5195
|
-
|
|
4408
|
+
// Clear on both outcomes without a .finally() chain: that derived promise would reject unhandled
|
|
4409
|
+
// whenever readyPromise does, even when the caller handles the rejection.
|
|
4410
|
+
const clearPending = () => {
|
|
4411
|
+
this.pendingSchemaByName.delete(schemaName);
|
|
4412
|
+
};
|
|
4413
|
+
readyPromise.then(clearPending, clearPending);
|
|
5196
4414
|
return readyPromise;
|
|
5197
4415
|
}
|
|
5198
4416
|
/**
|
|
@@ -5753,13 +4971,19 @@ class Schema {
|
|
|
5753
4971
|
_dbVersion: publishedSchema.version,
|
|
5754
4972
|
});
|
|
5755
4973
|
// Clear edited flags on all ModelProperty instances and in database
|
|
5756
|
-
const modelPropertyMod = await import('./ModelProperty-
|
|
4974
|
+
const modelPropertyMod = await import('./ModelProperty-6llK4MTH.js');
|
|
5757
4975
|
const { ModelProperty } = modelPropertyMod;
|
|
5758
4976
|
for (const propertyKey of context._editedProperties) {
|
|
5759
4977
|
const [modelName, propertyName] = propertyKey.split(':');
|
|
5760
|
-
const cacheKey = `${modelName}:${propertyName}`;
|
|
5761
4978
|
const ModelPropertyClass = ModelProperty;
|
|
5762
|
-
|
|
4979
|
+
// Model names are only unique per schema: pick this schema's instance, which may be keyed by id.
|
|
4980
|
+
const thisSchemaName = this.schemaName;
|
|
4981
|
+
const cachedInstance = [...ModelPropertyClass.instanceCache.values()].find(({ instance }) => {
|
|
4982
|
+
const ctx = instance.getService().getSnapshot().context;
|
|
4983
|
+
return (ctx.modelName === modelName &&
|
|
4984
|
+
ctx.name === propertyName &&
|
|
4985
|
+
(!ctx._schemaName || ctx._schemaName === thisSchemaName));
|
|
4986
|
+
});
|
|
5763
4987
|
if (cachedInstance) {
|
|
5764
4988
|
const modelProperty = cachedInstance.instance;
|
|
5765
4989
|
modelProperty.getService().getSnapshot().context;
|
|
@@ -5770,12 +4994,12 @@ class Schema {
|
|
|
5770
4994
|
// Clear isEdited flag in database
|
|
5771
4995
|
try {
|
|
5772
4996
|
if (db && modelName && propertyName) {
|
|
5773
|
-
// Find model by name
|
|
5774
|
-
const
|
|
5775
|
-
|
|
5776
|
-
|
|
5777
|
-
|
|
5778
|
-
|
|
4997
|
+
// Find this schema's model by name
|
|
4998
|
+
const _mod_16 = await import('./db-Lw0KVZmc.js');
|
|
4999
|
+
const _ns_16 = _mod_16.Y;
|
|
5000
|
+
const { resolveModelRecord } = _ns_16;
|
|
5001
|
+
const modelRecord = await resolveModelRecord(modelName, { schemaName: thisSchemaName }, db);
|
|
5002
|
+
const modelRecords = modelRecord ? [modelRecord] : [];
|
|
5779
5003
|
if (modelRecords.length > 0) {
|
|
5780
5004
|
// Find property by name and modelId
|
|
5781
5005
|
const propertyRecords = await db
|
|
@@ -6274,6 +5498,47 @@ class Schema {
|
|
|
6274
5498
|
saveDraftLogger(`Removed schema from saving set (key: ${saveKey})`);
|
|
6275
5499
|
}
|
|
6276
5500
|
}
|
|
5501
|
+
/**
|
|
5502
|
+
* Force-evict the cached Schema instance(s) named `schemaName`, ignoring refCounts: stop their live
|
|
5503
|
+
* query and service. Schema.destroy does the same for itself. For code that deletes a schema's rows
|
|
5504
|
+
* without destroying it (test cleanup): a live Schema keeps re-creating its models from its live
|
|
5505
|
+
* query while their rows are being deleted.
|
|
5506
|
+
*/
|
|
5507
|
+
static evict(schemaName) {
|
|
5508
|
+
const instances = new Set();
|
|
5509
|
+
for (const { instance } of Schema.instanceCacheById.values())
|
|
5510
|
+
instances.add(instance);
|
|
5511
|
+
for (const { instance } of Schema.instanceCacheByName.values())
|
|
5512
|
+
instances.add(instance);
|
|
5513
|
+
for (const instance of instances) {
|
|
5514
|
+
let context;
|
|
5515
|
+
try {
|
|
5516
|
+
context = instance._getSnapshotContext();
|
|
5517
|
+
}
|
|
5518
|
+
catch {
|
|
5519
|
+
continue;
|
|
5520
|
+
}
|
|
5521
|
+
if (context.schemaName !== schemaName)
|
|
5522
|
+
continue;
|
|
5523
|
+
clearDestroySubscriptions(instance, {
|
|
5524
|
+
instanceState: schemaInstanceState,
|
|
5525
|
+
onUnload: () => schemaInstanceState.delete(instance),
|
|
5526
|
+
});
|
|
5527
|
+
forceRemoveFromCaches(instance, {
|
|
5528
|
+
getCacheKeys: () => [context.id, context.schemaName].filter((k) => !!k),
|
|
5529
|
+
caches: [
|
|
5530
|
+
Schema.instanceCacheById,
|
|
5531
|
+
Schema.instanceCacheByName,
|
|
5532
|
+
],
|
|
5533
|
+
});
|
|
5534
|
+
try {
|
|
5535
|
+
instance._service.stop();
|
|
5536
|
+
}
|
|
5537
|
+
catch {
|
|
5538
|
+
// Service might already be stopped
|
|
5539
|
+
}
|
|
5540
|
+
}
|
|
5541
|
+
}
|
|
6277
5542
|
unload() {
|
|
6278
5543
|
try {
|
|
6279
5544
|
const context = this._getSnapshotContext();
|
|
@@ -6337,6 +5602,18 @@ class Schema {
|
|
|
6337
5602
|
Schema.instanceCacheByName,
|
|
6338
5603
|
],
|
|
6339
5604
|
});
|
|
5605
|
+
// The rows for this schema's models and properties are deleted below; evict their cached
|
|
5606
|
+
// instances too, or a re-import would get them back with dangling _dbIds.
|
|
5607
|
+
if (schemaName) {
|
|
5608
|
+
const evictedModelNames = Model.evictForSchema(schemaName);
|
|
5609
|
+
const { ModelProperty } = await import('./ModelProperty-6llK4MTH.js');
|
|
5610
|
+
ModelProperty.evictForModels(evictedModelNames, schemaName);
|
|
5611
|
+
// Evicting stops new writes but not ones already running; let those land before deleting their rows
|
|
5612
|
+
const _mod_17 = await import('./index-Y-yYyRBf.js');
|
|
5613
|
+
const _ns_17 = _mod_17.e;
|
|
5614
|
+
const { waitForInFlightWrites } = _ns_17;
|
|
5615
|
+
await waitForInFlightWrites();
|
|
5616
|
+
}
|
|
6340
5617
|
await runDestroyLifecycle(this, {
|
|
6341
5618
|
getService: (instance) => instance._service,
|
|
6342
5619
|
doDestroy: async () => {
|
|
@@ -6478,8 +5755,10 @@ class Schema {
|
|
|
6478
5755
|
}
|
|
6479
5756
|
},
|
|
6480
5757
|
createChildInstances: async (ids) => {
|
|
5758
|
+
// One at a time: an eviction of this schema part way through stops the rest
|
|
5759
|
+
const evictionEpoch = currentEvictionEpoch();
|
|
6481
5760
|
for (const id of ids) {
|
|
6482
|
-
await Model.createById(id);
|
|
5761
|
+
await Model.createById(id, { evictionEpoch });
|
|
6483
5762
|
}
|
|
6484
5763
|
},
|
|
6485
5764
|
queryInitialData: async (schemaId) => {
|
|
@@ -6556,4 +5835,4 @@ var Schema$1 = /*#__PURE__*/Object.freeze({
|
|
|
6556
5835
|
});
|
|
6557
5836
|
|
|
6558
5837
|
export { Schema as S, deletePropertyFromModel as a, Schema$1 as b, deleteModelFromSchema as d, renameModelProperty as r, schemaMachine as s, updateModelProperties as u };
|
|
6559
|
-
//# sourceMappingURL=Schema-
|
|
5838
|
+
//# sourceMappingURL=Schema-D-Ud-XYw.js.map
|