@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,29 +1,30 @@
|
|
|
1
1
|
import { fromCallback, setup, assign, createActor } from 'xstate';
|
|
2
2
|
import 'reflect-metadata';
|
|
3
|
-
import { w as writeProcessMachine, M as Model } from './index-
|
|
4
|
-
import {
|
|
3
|
+
import { i as isActorStopped, w as writeProcessMachine, c as currentEvictionEpoch, M as Model, b as anyEvictionSince, s as schemaEvictedSince } from './index-Y-yYyRBf.js';
|
|
4
|
+
import { x as getModelIdByFileId, n as normalizeDataType, y as getModelId } from './db-Lw0KVZmc.js';
|
|
5
5
|
import 'pluralize';
|
|
6
|
-
import {
|
|
6
|
+
import { B as BaseDb, j as models, p as properties, s as schemas, g as modelSchemas, a as BaseFileManager } from './BasePathResolver-DRT09oVv.js';
|
|
7
7
|
import { eq, and } from 'drizzle-orm';
|
|
8
8
|
import { modelPropertiesToObject } from './model-DGMe-TTm.js';
|
|
9
9
|
import debug from 'debug';
|
|
10
|
-
import './
|
|
11
|
-
import { S as Schema } from './Schema-
|
|
12
|
-
import {
|
|
10
|
+
import './tabEvents-C6NXS6Jl.js';
|
|
11
|
+
import { S as Schema } from './Schema-D-Ud-XYw.js';
|
|
12
|
+
import { j as waitForEntityIdle, k as createReactiveProxy, m as findEntity, n as forceRemoveFromCaches, o as runDestroyLifecycle } from './Item-ZUAmf943.js';
|
|
13
13
|
import { generateId } from './generateId-BopUwD8F.js';
|
|
14
|
+
import './ClientManager-DngaZdw6.js';
|
|
15
|
+
import '@seedprotocol/arweave';
|
|
16
|
+
import '@seedprotocol/eas';
|
|
17
|
+
import '@noble/hashes/sha3';
|
|
18
|
+
import '@noble/hashes/utils';
|
|
19
|
+
import '@seedprotocol/query';
|
|
20
|
+
import 'lodash-es';
|
|
14
21
|
import 'drizzle-orm/casing';
|
|
15
22
|
import '@sinclair/typebox';
|
|
16
|
-
import 'lodash-es';
|
|
17
23
|
import 'drizzle-orm/sqlite-core';
|
|
18
|
-
import '@seedprotocol/arweave';
|
|
19
|
-
import '@seedprotocol/eas';
|
|
20
24
|
import 'nanoid';
|
|
21
25
|
import 'nanoid-dictionary';
|
|
22
|
-
import '
|
|
23
|
-
import './SchemaValidationService-Y49vqast.js';
|
|
26
|
+
import './SchemaValidationService-IoS7JquP.js';
|
|
24
27
|
import '@sinclair/typebox/value';
|
|
25
|
-
import '@noble/hashes/sha3';
|
|
26
|
-
import '@noble/hashes/utils';
|
|
27
28
|
import 'rxjs';
|
|
28
29
|
|
|
29
30
|
const logger$3 = debug('seedSdk:modelProperty:actors:saveToSchema');
|
|
@@ -34,15 +35,15 @@ const logger$3 = debug('seedSdk:modelProperty:actors:saveToSchema');
|
|
|
34
35
|
*/
|
|
35
36
|
async function getSchemaNameFromModel(modelName) {
|
|
36
37
|
// Get the latest schema files and find which one contains this model
|
|
37
|
-
const _mod_0 = await import('./ClientManager-
|
|
38
|
-
const _ns_0 = _mod_0.
|
|
38
|
+
const _mod_0 = await import('./ClientManager-DngaZdw6.js');
|
|
39
|
+
const _ns_0 = _mod_0.G;
|
|
39
40
|
const schemaHelpersMod = _ns_0;
|
|
40
41
|
const { listLatestSchemaFiles } = schemaHelpersMod;
|
|
41
42
|
const latestSchemas = await listLatestSchemaFiles();
|
|
42
43
|
for (const schema of latestSchemas) {
|
|
43
44
|
try {
|
|
44
|
-
const _mod_1 = await import('./BasePathResolver-
|
|
45
|
-
const _ns_1 = _mod_1.
|
|
45
|
+
const _mod_1 = await import('./BasePathResolver-DRT09oVv.js');
|
|
46
|
+
const _ns_1 = _mod_1.O;
|
|
46
47
|
const fileManagerMod = _ns_1;
|
|
47
48
|
const { BaseFileManager } = fileManagerMod;
|
|
48
49
|
const content = await BaseFileManager.readFileAsString(schema.filePath);
|
|
@@ -58,10 +59,10 @@ async function getSchemaNameFromModel(modelName) {
|
|
|
58
59
|
}
|
|
59
60
|
return undefined;
|
|
60
61
|
}
|
|
61
|
-
const saveToSchema = fromCallback(({ sendBack, input: { context } }) => {
|
|
62
|
+
const saveToSchema = fromCallback(({ sendBack, input: { context }, self }) => {
|
|
62
63
|
const _saveToSchema = async () => {
|
|
63
64
|
// Use dynamic import to break circular dependency
|
|
64
|
-
const validationServiceMod = await import('./SchemaValidationService-
|
|
65
|
+
const validationServiceMod = await import('./SchemaValidationService-IoS7JquP.js');
|
|
65
66
|
const { SchemaValidationService } = validationServiceMod;
|
|
66
67
|
const validationService = new SchemaValidationService();
|
|
67
68
|
// Validate property structure before saving
|
|
@@ -80,18 +81,21 @@ const saveToSchema = fromCallback(({ sendBack, input: { context } }) => {
|
|
|
80
81
|
throw new Error(`Model not found for modelId: ${context.modelId}`);
|
|
81
82
|
}
|
|
82
83
|
// Persist to database only - schema file is updated only when user calls Schema.saveNewVersion()
|
|
83
|
-
const _mod_2 = await import('./db-
|
|
84
|
-
const _ns_2 = _mod_2.
|
|
84
|
+
const _mod_2 = await import('./db-Lw0KVZmc.js');
|
|
85
|
+
const _ns_2 = _mod_2.Z;
|
|
85
86
|
const dbMod = _ns_2;
|
|
86
87
|
const { savePropertyToDb } = dbMod;
|
|
87
88
|
await savePropertyToDb(context);
|
|
88
89
|
// Mark schema as draft so user knows to save
|
|
89
90
|
const schemaName = context._schemaName ?? (await getSchemaNameFromModel(context.modelName));
|
|
90
91
|
if (schemaName) {
|
|
91
|
-
const _mod_3 = await import('./Schema-
|
|
92
|
+
const _mod_3 = await import('./Schema-D-Ud-XYw.js');
|
|
92
93
|
const _ns_3 = _mod_3.b;
|
|
93
94
|
const schemaMod = _ns_3;
|
|
94
95
|
const { Schema } = schemaMod;
|
|
96
|
+
// Stopped meanwhile (unloaded, or evicted with its schema): don't load the schema again
|
|
97
|
+
if (isActorStopped(self))
|
|
98
|
+
return;
|
|
95
99
|
const schema = Schema.create(schemaName, { waitForReady: false });
|
|
96
100
|
schema.getService().send({
|
|
97
101
|
type: 'markAsDraft',
|
|
@@ -112,7 +116,7 @@ const saveToSchema = fromCallback(({ sendBack, input: { context } }) => {
|
|
|
112
116
|
});
|
|
113
117
|
|
|
114
118
|
const logger$2 = debug('seedSdk:modelProperty:actors:compareAndMarkDraft');
|
|
115
|
-
const compareAndMarkDraft = fromCallback(({ sendBack, input: { context } }) => {
|
|
119
|
+
const compareAndMarkDraft = fromCallback(({ sendBack, input: { context }, self }) => {
|
|
116
120
|
const _compareAndMarkDraft = async () => {
|
|
117
121
|
// Fill modelName/dataType from _originalValues when missing, then from DB by schemaFileId
|
|
118
122
|
let fullContext = {
|
|
@@ -123,8 +127,8 @@ const compareAndMarkDraft = fromCallback(({ sendBack, input: { context } }) => {
|
|
|
123
127
|
const schemaFileIdForResolve = fullContext._propertyFileId || (typeof fullContext.id === 'string' ? fullContext.id : undefined);
|
|
124
128
|
if (schemaFileIdForResolve && (fullContext.modelName === undefined || fullContext.dataType === undefined)) {
|
|
125
129
|
try {
|
|
126
|
-
const _mod_4 = await import('./db-
|
|
127
|
-
const _ns_4 = _mod_4.
|
|
130
|
+
const _mod_4 = await import('./db-Lw0KVZmc.js');
|
|
131
|
+
const _ns_4 = _mod_4.Z;
|
|
128
132
|
const dbMod = _ns_4;
|
|
129
133
|
const { getPropertyModelNameAndDataType, getModelNameByModelId } = dbMod;
|
|
130
134
|
let fromDb;
|
|
@@ -170,8 +174,8 @@ const compareAndMarkDraft = fromCallback(({ sendBack, input: { context } }) => {
|
|
|
170
174
|
if (fullContext.modelName && fullContext.name && schemaFileId) {
|
|
171
175
|
logger$2(`[compareAndMarkDraft] _originalValues not set, but saving to database anyway for property ${context.modelName}:${context.name} (schemaFileId: ${schemaFileId})`);
|
|
172
176
|
try {
|
|
173
|
-
const _mod_5 = await import('./db-
|
|
174
|
-
const _ns_5 = _mod_5.
|
|
177
|
+
const _mod_5 = await import('./db-Lw0KVZmc.js');
|
|
178
|
+
const _ns_5 = _mod_5.Z;
|
|
175
179
|
const dbMod = _ns_5;
|
|
176
180
|
const { savePropertyToDb } = dbMod;
|
|
177
181
|
// Ensure _propertyFileId is set for savePropertyToDb to find the property
|
|
@@ -232,8 +236,8 @@ const compareAndMarkDraft = fromCallback(({ sendBack, input: { context } }) => {
|
|
|
232
236
|
logger$2(`Property ${fullContext.modelName}:${fullContext.name} has changes, marking as edited`);
|
|
233
237
|
logger$2(`[compareAndMarkDraft] Context when saving: id=${fullContext.id}, _propertyFileId=${fullContext._propertyFileId}, name=${fullContext.name}, _originalValues.name=${fullContext._originalValues?.name}`);
|
|
234
238
|
// Use dynamic import to break circular dependency
|
|
235
|
-
const _mod_6 = await import('./db-
|
|
236
|
-
const _ns_6 = _mod_6.
|
|
239
|
+
const _mod_6 = await import('./db-Lw0KVZmc.js');
|
|
240
|
+
const _ns_6 = _mod_6.Z;
|
|
237
241
|
const dbMod = _ns_6;
|
|
238
242
|
const { savePropertyToDb } = dbMod;
|
|
239
243
|
// Save to database (but not JSON file) - always save to DB when there are changes
|
|
@@ -248,10 +252,13 @@ const compareAndMarkDraft = fromCallback(({ sendBack, input: { context } }) => {
|
|
|
248
252
|
// Mark schema as draft if schema name is available
|
|
249
253
|
if (fullContext._schemaName) {
|
|
250
254
|
// Get the Schema instance and mark it as draft
|
|
251
|
-
const _mod_7 = await import('./Schema-
|
|
255
|
+
const _mod_7 = await import('./Schema-D-Ud-XYw.js');
|
|
252
256
|
const _ns_7 = _mod_7.b;
|
|
253
257
|
const schemaMod = _ns_7;
|
|
254
258
|
const { Schema } = schemaMod;
|
|
259
|
+
// Stopped meanwhile (unloaded, or evicted with its schema): don't load the schema again
|
|
260
|
+
if (isActorStopped(self))
|
|
261
|
+
return;
|
|
255
262
|
const schema = Schema.create(fullContext._schemaName, {
|
|
256
263
|
waitForReady: false,
|
|
257
264
|
});
|
|
@@ -267,7 +274,7 @@ const compareAndMarkDraft = fromCallback(({ sendBack, input: { context } }) => {
|
|
|
267
274
|
logger$2(`Property ${fullContext.modelName}:${fullContext.name} has no changes`);
|
|
268
275
|
// Clear isEdited flag in database
|
|
269
276
|
try {
|
|
270
|
-
const _mod_8 = await import('./index-
|
|
277
|
+
const _mod_8 = await import('./index-5b3JsS55.js');
|
|
271
278
|
const _ns_8 = _mod_8.s;
|
|
272
279
|
const seedSchemaMod = _ns_8;
|
|
273
280
|
const { properties: propertiesTable, models: modelsTable } = seedSchemaMod;
|
|
@@ -275,12 +282,15 @@ const compareAndMarkDraft = fromCallback(({ sendBack, input: { context } }) => {
|
|
|
275
282
|
const { eq, and } = drizzleMod;
|
|
276
283
|
const db = BaseDb.getAppDb();
|
|
277
284
|
if (db && fullContext.modelName && fullContext.name) {
|
|
278
|
-
// Find model
|
|
279
|
-
const
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
.
|
|
285
|
+
// Find this property's model (model names are only unique per schema)
|
|
286
|
+
const _mod_9 = await import('./db-Lw0KVZmc.js');
|
|
287
|
+
const _ns_9 = _mod_9.Y;
|
|
288
|
+
const { resolveModelRecord } = _ns_9;
|
|
289
|
+
const modelRecord = await resolveModelRecord(fullContext.modelName, {
|
|
290
|
+
modelId: typeof fullContext.modelId === 'number' ? fullContext.modelId : undefined,
|
|
291
|
+
schemaName: fullContext._schemaName,
|
|
292
|
+
}, db);
|
|
293
|
+
const modelRecords = modelRecord ? [modelRecord] : [];
|
|
284
294
|
if (modelRecords.length > 0) {
|
|
285
295
|
// Find property by name and modelId
|
|
286
296
|
const propertyRecords = await db
|
|
@@ -319,7 +329,7 @@ const compareAndMarkDraft = fromCallback(({ sendBack, input: { context } }) => {
|
|
|
319
329
|
});
|
|
320
330
|
|
|
321
331
|
const logger$1 = debug('seedSdk:modelProperty:actors:validateProperty');
|
|
322
|
-
const validateProperty = fromCallback(({ sendBack, input: { context } }) => {
|
|
332
|
+
const validateProperty = fromCallback(({ sendBack, input: { context }, self }) => {
|
|
323
333
|
const _validateProperty = async () => {
|
|
324
334
|
// Use full context for validation: fill modelName/dataType from _originalValues when missing, then
|
|
325
335
|
// from DB by schemaFileId (context.id) so just-created renames don't fail structure validation.
|
|
@@ -333,9 +343,9 @@ const validateProperty = fromCallback(({ sendBack, input: { context } }) => {
|
|
|
333
343
|
// Brief wait so trackPendingWrite from ModelProperty.create() has time to run (it's in setTimeout(0))
|
|
334
344
|
await new Promise((r) => setTimeout(r, 60));
|
|
335
345
|
try {
|
|
336
|
-
const
|
|
337
|
-
const
|
|
338
|
-
const dbMod =
|
|
346
|
+
const _mod_10 = await import('./db-Lw0KVZmc.js');
|
|
347
|
+
const _ns_10 = _mod_10.Z;
|
|
348
|
+
const dbMod = _ns_10;
|
|
339
349
|
const { getPropertyModelNameAndDataType, getModelNameByModelId } = dbMod;
|
|
340
350
|
// Try pending write first (property row may not exist yet)
|
|
341
351
|
if (fullContext.modelName === undefined && schemaFileId) {
|
|
@@ -387,12 +397,12 @@ const validateProperty = fromCallback(({ sendBack, input: { context } }) => {
|
|
|
387
397
|
fullContext = { ...fullContext, dataType: (fullContext.dataType ?? context._originalValues?.dataType) || 'Text' };
|
|
388
398
|
}
|
|
389
399
|
// Use dynamic imports to break circular dependencies
|
|
390
|
-
const validationServiceMod = await import('./SchemaValidationService-
|
|
400
|
+
const validationServiceMod = await import('./SchemaValidationService-IoS7JquP.js');
|
|
391
401
|
const { SchemaValidationService } = validationServiceMod;
|
|
392
402
|
const validationService = new SchemaValidationService();
|
|
393
|
-
const
|
|
394
|
-
const
|
|
395
|
-
const schemaMod =
|
|
403
|
+
const _mod_11 = await import('./Schema-D-Ud-XYw.js');
|
|
404
|
+
const _ns_11 = _mod_11.b;
|
|
405
|
+
const schemaMod = _ns_11;
|
|
396
406
|
const { Schema } = schemaMod;
|
|
397
407
|
// Validate property structure
|
|
398
408
|
const structureResult = validationService.validatePropertyStructure(fullContext);
|
|
@@ -401,6 +411,9 @@ const validateProperty = fromCallback(({ sendBack, input: { context } }) => {
|
|
|
401
411
|
return;
|
|
402
412
|
}
|
|
403
413
|
// If we have schema name and model name, validate against schema
|
|
414
|
+
// Stopped meanwhile (unloaded, or evicted with its schema): don't load the schema again
|
|
415
|
+
if (isActorStopped(self))
|
|
416
|
+
return;
|
|
404
417
|
if (fullContext._schemaName && fullContext.modelName) {
|
|
405
418
|
try {
|
|
406
419
|
const schema = Schema.create(fullContext._schemaName, {
|
|
@@ -494,9 +507,6 @@ const modelPropertyMachine = setup({
|
|
|
494
507
|
const valid = !context._validationErrors || context._validationErrors.length === 0;
|
|
495
508
|
return valid;
|
|
496
509
|
},
|
|
497
|
-
hasValidationErrors: ({ context }) => {
|
|
498
|
-
return !!context._validationErrors && context._validationErrors.length > 0;
|
|
499
|
-
},
|
|
500
510
|
},
|
|
501
511
|
actions: {
|
|
502
512
|
assignValidationErrors: assign(({ context, event }) => {
|
|
@@ -595,7 +605,8 @@ const modelPropertyMachine = setup({
|
|
|
595
605
|
actions: assign(({ context, event }) => ({
|
|
596
606
|
...context,
|
|
597
607
|
_originalValues: event.originalValues,
|
|
598
|
-
|
|
608
|
+
// Senders don't know the schema name; keep one setSchemaName already stored.
|
|
609
|
+
_schemaName: event.schemaName ?? context._schemaName,
|
|
599
610
|
_isEdited: event.isEdited ?? false,
|
|
600
611
|
_validationErrors: undefined,
|
|
601
612
|
})),
|
|
@@ -614,22 +625,15 @@ const modelPropertyMachine = setup({
|
|
|
614
625
|
})),
|
|
615
626
|
},
|
|
616
627
|
destroyStarted: {
|
|
617
|
-
actions: assign({
|
|
618
|
-
},
|
|
619
|
-
destroyDone: {
|
|
620
|
-
actions: assign({ _destroyInProgress: false }),
|
|
628
|
+
actions: assign({ _destroyError: null }),
|
|
621
629
|
},
|
|
622
630
|
destroyError: {
|
|
623
631
|
actions: assign(({ event }) => ({
|
|
624
|
-
_destroyInProgress: false,
|
|
625
632
|
_destroyError: event.error instanceof Error
|
|
626
633
|
? { message: event.error.message, name: event.error.name }
|
|
627
634
|
: { message: String(event.error) },
|
|
628
635
|
})),
|
|
629
636
|
},
|
|
630
|
-
clearDestroyError: {
|
|
631
|
-
actions: assign({ _destroyError: null }),
|
|
632
|
-
},
|
|
633
637
|
},
|
|
634
638
|
states: {
|
|
635
639
|
idle: {
|
|
@@ -704,11 +708,9 @@ const modelPropertyMachine = setup({
|
|
|
704
708
|
},
|
|
705
709
|
},
|
|
706
710
|
saveToSchema: {
|
|
707
|
-
always
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
},
|
|
711
|
-
initial: 'saving',
|
|
711
|
+
// Gate the save in a transient child. An `always` on this parent targeting `.saving` re-enters
|
|
712
|
+
// the invoking child on every microstep and never settles (save() ran the process out of memory).
|
|
713
|
+
initial: 'checking',
|
|
712
714
|
on: {
|
|
713
715
|
// Apply updateContext but do not re-invoke saveToSchema actor (avoids infinite loop).
|
|
714
716
|
// Context is updated; in-flight save completes with original context.
|
|
@@ -785,6 +787,12 @@ const modelPropertyMachine = setup({
|
|
|
785
787
|
},
|
|
786
788
|
},
|
|
787
789
|
states: {
|
|
790
|
+
checking: {
|
|
791
|
+
always: [
|
|
792
|
+
{ guard: 'isPropertyValid', target: 'saving' },
|
|
793
|
+
{ target: '#modelProperty.idle' },
|
|
794
|
+
],
|
|
795
|
+
},
|
|
788
796
|
saving: {
|
|
789
797
|
on: {
|
|
790
798
|
saveToSchemaSuccess: {
|
|
@@ -848,6 +856,8 @@ const TPropertyKeys = [
|
|
|
848
856
|
];
|
|
849
857
|
class ModelProperty {
|
|
850
858
|
constructor(property) {
|
|
859
|
+
/** currentEvictionEpoch() at construction: lookups started for this instance don't outlive an eviction. */
|
|
860
|
+
this._evictionEpoch = currentEvictionEpoch();
|
|
851
861
|
// id is now the schemaFileId (string), _dbId is the database integer ID
|
|
852
862
|
// Preserve _propertyFileId if it exists in the property object (from getPropertySchema)
|
|
853
863
|
// Convert null to undefined for optional fields (TypeBox validation expects undefined, not null)
|
|
@@ -867,6 +877,15 @@ class ModelProperty {
|
|
|
867
877
|
this._initializeOriginalValues(property);
|
|
868
878
|
// Note: Property getters/setters are now handled by the Proxy in create()
|
|
869
879
|
}
|
|
880
|
+
/**
|
|
881
|
+
* Send from fire-and-forget async work (DB lookups started in the constructor), which can finish
|
|
882
|
+
* after the instance was unloaded or evicted with its schema.
|
|
883
|
+
*/
|
|
884
|
+
_sendIfRunning(event) {
|
|
885
|
+
if (isActorStopped(this._service))
|
|
886
|
+
return;
|
|
887
|
+
this._service.send(event);
|
|
888
|
+
}
|
|
870
889
|
/**
|
|
871
890
|
* Initialize original values and schema name for tracking changes
|
|
872
891
|
* This is called asynchronously after construction
|
|
@@ -878,10 +897,10 @@ class ModelProperty {
|
|
|
878
897
|
const refModelName = property.refModelName || property.ref;
|
|
879
898
|
if (refModelName && !property.refModelId) {
|
|
880
899
|
// Resolve refModelId asynchronously and update context
|
|
881
|
-
this._resolveRefModelId(refModelName).then((refModelId) => {
|
|
900
|
+
this._resolveRefModelId(refModelName, property).then((refModelId) => {
|
|
882
901
|
if (refModelId) {
|
|
883
902
|
// Update the context with the resolved refModelId
|
|
884
|
-
this.
|
|
903
|
+
this._sendIfRunning({
|
|
885
904
|
type: 'updateContext',
|
|
886
905
|
refModelId,
|
|
887
906
|
});
|
|
@@ -949,7 +968,7 @@ class ModelProperty {
|
|
|
949
968
|
// Initialize with original values, including isEdited flag
|
|
950
969
|
// Load isEdited from database if property exists in DB (async, fire-and-forget)
|
|
951
970
|
this._loadIsEditedFromDb(property, isEdited).then((isEditedFromDb) => {
|
|
952
|
-
this.
|
|
971
|
+
this._sendIfRunning({
|
|
953
972
|
type: 'initializeOriginalValues',
|
|
954
973
|
originalValues,
|
|
955
974
|
schemaName: undefined, // Will be set later if needed
|
|
@@ -957,7 +976,7 @@ class ModelProperty {
|
|
|
957
976
|
});
|
|
958
977
|
}).catch(() => {
|
|
959
978
|
// If we can't load from DB, use computed isEdited value
|
|
960
|
-
this.
|
|
979
|
+
this._sendIfRunning({
|
|
961
980
|
type: 'initializeOriginalValues',
|
|
962
981
|
originalValues,
|
|
963
982
|
schemaName: undefined, // Will be set later if needed
|
|
@@ -972,7 +991,7 @@ class ModelProperty {
|
|
|
972
991
|
originalValues[key] = property[key];
|
|
973
992
|
}
|
|
974
993
|
});
|
|
975
|
-
this.
|
|
994
|
+
this._sendIfRunning({
|
|
976
995
|
type: 'initializeOriginalValues',
|
|
977
996
|
originalValues,
|
|
978
997
|
schemaName: undefined,
|
|
@@ -980,7 +999,7 @@ class ModelProperty {
|
|
|
980
999
|
});
|
|
981
1000
|
// Get schema name from model asynchronously (fire-and-forget)
|
|
982
1001
|
if (property.modelName) {
|
|
983
|
-
this._setSchemaName(property
|
|
1002
|
+
this._setSchemaName(property).catch(() => {
|
|
984
1003
|
// If we can't get schema name, that's okay - it will be set later if needed
|
|
985
1004
|
});
|
|
986
1005
|
}
|
|
@@ -1000,12 +1019,12 @@ class ModelProperty {
|
|
|
1000
1019
|
if (!db) {
|
|
1001
1020
|
return fallbackIsEdited;
|
|
1002
1021
|
}
|
|
1003
|
-
// Find model by
|
|
1004
|
-
const
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
1022
|
+
// Find this property's model (by modelId when known; model names are only unique per schema)
|
|
1023
|
+
const _mod_12 = await import('./db-Lw0KVZmc.js');
|
|
1024
|
+
const _ns_12 = _mod_12.Y;
|
|
1025
|
+
const { resolveModelRecord } = _ns_12;
|
|
1026
|
+
const modelRecord = await resolveModelRecord(property.modelName, this._ownerModelScope(property), db);
|
|
1027
|
+
const modelRecords = modelRecord ? [modelRecord] : [];
|
|
1009
1028
|
if (modelRecords.length === 0) {
|
|
1010
1029
|
return fallbackIsEdited;
|
|
1011
1030
|
}
|
|
@@ -1029,7 +1048,7 @@ class ModelProperty {
|
|
|
1029
1048
|
* @param refModelName - The name of the referenced model
|
|
1030
1049
|
* @returns The database ID of the referenced model, or undefined if not found
|
|
1031
1050
|
*/
|
|
1032
|
-
async _resolveRefModelId(refModelName) {
|
|
1051
|
+
async _resolveRefModelId(refModelName, property) {
|
|
1033
1052
|
if (!refModelName) {
|
|
1034
1053
|
return undefined;
|
|
1035
1054
|
}
|
|
@@ -1038,13 +1057,13 @@ class ModelProperty {
|
|
|
1038
1057
|
if (!db) {
|
|
1039
1058
|
return undefined;
|
|
1040
1059
|
}
|
|
1041
|
-
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
|
|
1046
|
-
if (
|
|
1047
|
-
return
|
|
1060
|
+
// Resolve the ref within the owning model's schema
|
|
1061
|
+
const _mod_13 = await import('./db-Lw0KVZmc.js');
|
|
1062
|
+
const _ns_13 = _mod_13.Y;
|
|
1063
|
+
const { resolveRefModelRecord } = _ns_13;
|
|
1064
|
+
const refModelRecord = await resolveRefModelRecord(refModelName, property ? this._ownerModelScope(property) : { schemaName: this._getSnapshotContext()._schemaName }, db);
|
|
1065
|
+
if (refModelRecord?.id) {
|
|
1066
|
+
return refModelRecord.id;
|
|
1048
1067
|
}
|
|
1049
1068
|
}
|
|
1050
1069
|
catch (error) {
|
|
@@ -1053,6 +1072,15 @@ class ModelProperty {
|
|
|
1053
1072
|
}
|
|
1054
1073
|
return undefined;
|
|
1055
1074
|
}
|
|
1075
|
+
/** Which model this property belongs to: its models row id and/or schema. */
|
|
1076
|
+
_ownerModelScope(property) {
|
|
1077
|
+
const context = this._getSnapshotContext();
|
|
1078
|
+
const modelId = property.modelId ?? context.modelId;
|
|
1079
|
+
return {
|
|
1080
|
+
modelId: typeof modelId === 'number' ? modelId : undefined,
|
|
1081
|
+
schemaName: context._schemaName,
|
|
1082
|
+
};
|
|
1083
|
+
}
|
|
1056
1084
|
/**
|
|
1057
1085
|
* Get schema file values for this property to use as "original" values
|
|
1058
1086
|
* This allows comparison with database values to detect edits
|
|
@@ -1062,7 +1090,42 @@ class ModelProperty {
|
|
|
1062
1090
|
return undefined;
|
|
1063
1091
|
}
|
|
1064
1092
|
try {
|
|
1065
|
-
const
|
|
1093
|
+
const { modelId, schemaName } = this._ownerModelScope(property);
|
|
1094
|
+
// Synchronous cache hits first: callers compare against these values right after construction,
|
|
1095
|
+
// so an extra await here lets every property look "edited" (a draft save each). Only then the
|
|
1096
|
+
// DB (by modelId), and never instantiate a Model while its own properties are initializing.
|
|
1097
|
+
let model = schemaName ? Model.getByName(property.modelName, schemaName) : undefined;
|
|
1098
|
+
if (!model) {
|
|
1099
|
+
try {
|
|
1100
|
+
model = Model.getByName(property.modelName);
|
|
1101
|
+
}
|
|
1102
|
+
catch {
|
|
1103
|
+
model = undefined; // ambiguous name; resolve by modelId below
|
|
1104
|
+
}
|
|
1105
|
+
}
|
|
1106
|
+
if (!model && modelId) {
|
|
1107
|
+
const _mod_14 = await import('./db-Lw0KVZmc.js');
|
|
1108
|
+
const _ns_14 = _mod_14.Y;
|
|
1109
|
+
const { resolveModelRecord } = _ns_14;
|
|
1110
|
+
const modelFileId = (await resolveModelRecord(property.modelName, { modelId }))?.schemaFileId;
|
|
1111
|
+
model = modelFileId ? Model.getById(modelFileId) : undefined;
|
|
1112
|
+
}
|
|
1113
|
+
// Evicted (with its schema) or unloaded while the lookups above ran: don't instantiate its model
|
|
1114
|
+
// again from rows that are being deleted.
|
|
1115
|
+
if (!model && isActorStopped(this._service))
|
|
1116
|
+
return undefined;
|
|
1117
|
+
if (!model) {
|
|
1118
|
+
try {
|
|
1119
|
+
// The epoch from when this instance was built: an eviction of the model's schema since
|
|
1120
|
+
// then (this instance may already be stopped) must not re-create the model.
|
|
1121
|
+
model = await Model.getByNameAsync(property.modelName, undefined, {
|
|
1122
|
+
evictionEpoch: this._evictionEpoch,
|
|
1123
|
+
});
|
|
1124
|
+
}
|
|
1125
|
+
catch {
|
|
1126
|
+
model = undefined;
|
|
1127
|
+
}
|
|
1128
|
+
}
|
|
1066
1129
|
if (!model || !model.properties || model.properties.length === 0) {
|
|
1067
1130
|
return undefined;
|
|
1068
1131
|
}
|
|
@@ -1086,7 +1149,7 @@ class ModelProperty {
|
|
|
1086
1149
|
originalValues.ref = schemaFileValue.ref;
|
|
1087
1150
|
originalValues.refModelName = schemaFileValue.ref;
|
|
1088
1151
|
// Try to get refModelId from database
|
|
1089
|
-
const refModelId = await this._resolveRefModelId(schemaFileValue.ref);
|
|
1152
|
+
const refModelId = await this._resolveRefModelId(schemaFileValue.ref, property);
|
|
1090
1153
|
if (refModelId) {
|
|
1091
1154
|
originalValues.refModelId = refModelId;
|
|
1092
1155
|
}
|
|
@@ -1104,11 +1167,19 @@ class ModelProperty {
|
|
|
1104
1167
|
* Set the schema name for this property by looking it up from the model
|
|
1105
1168
|
* Tries database first (more reliable), then falls back to schema files
|
|
1106
1169
|
*/
|
|
1107
|
-
async _setSchemaName(
|
|
1170
|
+
async _setSchemaName(property) {
|
|
1108
1171
|
try {
|
|
1172
|
+
// create() sets the schema name right after construction when its caller knows it. Don't look it
|
|
1173
|
+
// up then: the file fallback below reads and parses every schema file, per property.
|
|
1174
|
+
await Promise.resolve();
|
|
1175
|
+
if (this._getSnapshotContext()._schemaName)
|
|
1176
|
+
return;
|
|
1109
1177
|
let schemaName;
|
|
1178
|
+
// From the property data: the instance's own modelId field is never assigned (the reactive proxy
|
|
1179
|
+
// serves values from the machine context), so reading this.modelId skipped the DB lookup.
|
|
1180
|
+
const { modelId } = this._ownerModelScope(property);
|
|
1110
1181
|
// Try to get schema name from database first (more reliable)
|
|
1111
|
-
if (
|
|
1182
|
+
if (modelId) {
|
|
1112
1183
|
try {
|
|
1113
1184
|
const db = BaseDb.getAppDb();
|
|
1114
1185
|
if (db) {
|
|
@@ -1119,7 +1190,7 @@ class ModelProperty {
|
|
|
1119
1190
|
.from(modelSchemas)
|
|
1120
1191
|
.innerJoin(schemas, eq(modelSchemas.schemaId, schemas.id))
|
|
1121
1192
|
.innerJoin(models, eq(modelSchemas.modelId, models.id))
|
|
1122
|
-
.where(eq(models.id,
|
|
1193
|
+
.where(eq(models.id, modelId))
|
|
1123
1194
|
.limit(1);
|
|
1124
1195
|
if (modelSchemaRecords.length > 0) {
|
|
1125
1196
|
schemaName = modelSchemaRecords[0].schemaName;
|
|
@@ -1132,11 +1203,11 @@ class ModelProperty {
|
|
|
1132
1203
|
}
|
|
1133
1204
|
// Fall back to schema file lookup if database didn't work
|
|
1134
1205
|
if (!schemaName) {
|
|
1135
|
-
schemaName = await getSchemaNameFromModel(modelName);
|
|
1206
|
+
schemaName = await getSchemaNameFromModel(property.modelName);
|
|
1136
1207
|
}
|
|
1137
1208
|
if (schemaName) {
|
|
1138
1209
|
// Update the context with the schema name using dedicated event
|
|
1139
|
-
this.
|
|
1210
|
+
this._sendIfRunning({
|
|
1140
1211
|
type: 'setSchemaName',
|
|
1141
1212
|
schemaName,
|
|
1142
1213
|
});
|
|
@@ -1233,11 +1304,32 @@ class ModelProperty {
|
|
|
1233
1304
|
logger(`ModelProperty.create: Generated new id (schemaFileId) "${propertyWithId.id}" for property "${property.name}"`);
|
|
1234
1305
|
}
|
|
1235
1306
|
// Create cache key from modelName and name, or use id
|
|
1236
|
-
|
|
1307
|
+
let cacheKey = propertyWithId.modelName && propertyWithId.name
|
|
1237
1308
|
? `${propertyWithId.modelName}:${propertyWithId.name}`
|
|
1238
1309
|
: propertyWithId.id
|
|
1239
1310
|
? `id:${propertyWithId.id}`
|
|
1240
1311
|
: propertyWithId.name || 'unnamed';
|
|
1312
|
+
// Model names are only unique per schema: a cached "Post:title" may be another schema's
|
|
1313
|
+
// property. If the ids say it's a different property, key this one by its own id instead.
|
|
1314
|
+
// (Not by file id: the same property is often created first with a generated id, then its real one.)
|
|
1315
|
+
const isOtherProperty = (cachedContext) => (typeof propertyWithId.modelId === 'number' &&
|
|
1316
|
+
typeof cachedContext.modelId === 'number' &&
|
|
1317
|
+
cachedContext.modelId !== propertyWithId.modelId) ||
|
|
1318
|
+
(!!schemaName && !!cachedContext._schemaName && cachedContext._schemaName !== schemaName);
|
|
1319
|
+
const cachedByName = this.instanceCache.get(cacheKey);
|
|
1320
|
+
if (cachedByName && propertyWithId.id && isOtherProperty(cachedByName.instance._getSnapshotContext())) {
|
|
1321
|
+
// Reuse this property's own id-keyed entry if it already has one.
|
|
1322
|
+
cacheKey = `id:${propertyWithId.id}`;
|
|
1323
|
+
for (const [key, { instance }] of this.instanceCache.entries()) {
|
|
1324
|
+
if (!key.startsWith('id:'))
|
|
1325
|
+
continue;
|
|
1326
|
+
const ctx = instance._getSnapshotContext();
|
|
1327
|
+
if (ctx.modelName === propertyWithId.modelName && ctx.name === propertyWithId.name && !isOtherProperty(ctx)) {
|
|
1328
|
+
cacheKey = key;
|
|
1329
|
+
break;
|
|
1330
|
+
}
|
|
1331
|
+
}
|
|
1332
|
+
}
|
|
1241
1333
|
// Check if instance exists in cache
|
|
1242
1334
|
if (this.instanceCache.has(cacheKey)) {
|
|
1243
1335
|
const { instance, refCount } = this.instanceCache.get(cacheKey);
|
|
@@ -1299,11 +1391,15 @@ class ModelProperty {
|
|
|
1299
1391
|
instance: proxiedInstance,
|
|
1300
1392
|
refCount: 1,
|
|
1301
1393
|
});
|
|
1394
|
+
this.indexCachedInstance(cacheKey, proxiedInstance);
|
|
1302
1395
|
// Trigger write process if property has modelId (or modelName) and id (schemaFileId)
|
|
1303
1396
|
// Wait for service to be ready (idle state) and have writeProcess spawned
|
|
1304
1397
|
const propertyFileId = propertyWithId.id; // id is now the schemaFileId (string)
|
|
1305
1398
|
const hasModelId = propertyWithId.modelId || propertyWithId.modelName;
|
|
1306
|
-
|
|
1399
|
+
// A _dbId means the data was loaded from an existing row (createById, getPropertySchema), so
|
|
1400
|
+
// there's nothing to write. Writing it back anyway raced deletes of that row's model (FK error).
|
|
1401
|
+
const isPersisted = typeof propertyWithId._dbId === 'number';
|
|
1402
|
+
if (hasModelId && propertyFileId && !isPersisted) {
|
|
1307
1403
|
// Wait for writeProcess to be spawned (it's spawned in idle state entry action)
|
|
1308
1404
|
// Retry a few times if writeProcess isn't available yet
|
|
1309
1405
|
let retries = 0;
|
|
@@ -1311,6 +1407,9 @@ class ModelProperty {
|
|
|
1311
1407
|
const checkAndSend = async () => {
|
|
1312
1408
|
const service = proxiedInstance.getService();
|
|
1313
1409
|
const snapshot = service.getSnapshot();
|
|
1410
|
+
// Unloaded or evicted (e.g. Schema.destroy) before the write started: nothing to write to
|
|
1411
|
+
if (isActorStopped(service))
|
|
1412
|
+
return;
|
|
1314
1413
|
if (snapshot.value === 'idle' && snapshot.context.writeProcess) {
|
|
1315
1414
|
const writeProcess = snapshot.context.writeProcess;
|
|
1316
1415
|
// Resolve dbModelId - convert from string (modelFileId) to number (database ID) if needed
|
|
@@ -1350,14 +1449,17 @@ class ModelProperty {
|
|
|
1350
1449
|
// Don't clear pending write here - it might resolve later
|
|
1351
1450
|
return;
|
|
1352
1451
|
}
|
|
1452
|
+
// Resolving the modelId awaited the DB; the instance may have been stopped meanwhile
|
|
1453
|
+
if (isActorStopped(service))
|
|
1454
|
+
return;
|
|
1353
1455
|
// Track pending write now that we have the resolved modelId
|
|
1354
1456
|
this.trackPendingWrite(propertyFileId, resolvedModelId);
|
|
1355
1457
|
logger(`Triggering write process for property "${property.name}" (modelId: ${resolvedModelId}, propertyFileId: ${propertyFileId})`);
|
|
1356
1458
|
// Check current write state
|
|
1357
1459
|
const currentWriteState = writeProcess.getSnapshot();
|
|
1358
1460
|
if (currentWriteState.value === 'success') {
|
|
1359
|
-
// Write already succeeded
|
|
1360
|
-
this.
|
|
1461
|
+
// Write already succeeded
|
|
1462
|
+
void this.completePendingWrite(propertyFileId, resolvedModelId);
|
|
1361
1463
|
}
|
|
1362
1464
|
else {
|
|
1363
1465
|
// Set up subscription to catch future state changes
|
|
@@ -1365,8 +1467,7 @@ class ModelProperty {
|
|
|
1365
1467
|
if (writeSnapshot.value === 'success') {
|
|
1366
1468
|
writeSubscription.unsubscribe();
|
|
1367
1469
|
logger(`[writeProcess subscription] Write succeeded for property "${property.name}" (propertyFileId: ${propertyFileId})`);
|
|
1368
|
-
|
|
1369
|
-
this.clearPendingWrite(propertyFileId, 'success');
|
|
1470
|
+
void this.completePendingWrite(propertyFileId, resolvedModelId);
|
|
1370
1471
|
}
|
|
1371
1472
|
else if (writeSnapshot.value === 'error') {
|
|
1372
1473
|
writeSubscription.unsubscribe();
|
|
@@ -1384,6 +1485,7 @@ class ModelProperty {
|
|
|
1384
1485
|
dataType: property.dataType,
|
|
1385
1486
|
refModelId: property.refModelId,
|
|
1386
1487
|
refValueType: property.refValueType,
|
|
1488
|
+
required: property.required,
|
|
1387
1489
|
storageType: property.storageType,
|
|
1388
1490
|
localStorageDir: property.localStorageDir,
|
|
1389
1491
|
filenameSuffix: property.filenameSuffix,
|
|
@@ -1411,18 +1513,56 @@ class ModelProperty {
|
|
|
1411
1513
|
return proxiedInstance;
|
|
1412
1514
|
return waitForEntityIdle(proxiedInstance, { timeout: readyTimeout }).then(() => proxiedInstance);
|
|
1413
1515
|
}
|
|
1516
|
+
/** Whether an idIndex entry still points at a cached instance with that id. */
|
|
1517
|
+
static isIndexEntryCurrent(propertyFileId, entry) {
|
|
1518
|
+
if (this.instanceCache.get(entry.cacheKey)?.instance !== entry.instance)
|
|
1519
|
+
return false;
|
|
1520
|
+
try {
|
|
1521
|
+
return entry.instance._getSnapshotContext().id === propertyFileId;
|
|
1522
|
+
}
|
|
1523
|
+
catch {
|
|
1524
|
+
return false;
|
|
1525
|
+
}
|
|
1526
|
+
}
|
|
1527
|
+
/** Add a newly cached instance to idIndex, and keep its entry current when its id changes. */
|
|
1528
|
+
static indexCachedInstance(cacheKey, instance) {
|
|
1529
|
+
const index = (id) => {
|
|
1530
|
+
if (!id)
|
|
1531
|
+
return;
|
|
1532
|
+
const existing = this.idIndex.get(id);
|
|
1533
|
+
// Keep the instance cached first, as the old scan in insertion order returned
|
|
1534
|
+
if (existing && existing.instance !== instance && this.isIndexEntryCurrent(id, existing))
|
|
1535
|
+
return;
|
|
1536
|
+
this.idIndex.set(id, { cacheKey, instance });
|
|
1537
|
+
};
|
|
1538
|
+
let indexedId = instance._getSnapshotContext().id;
|
|
1539
|
+
index(indexedId);
|
|
1540
|
+
instance._service.subscribe((snapshot) => {
|
|
1541
|
+
const id = snapshot.context.id;
|
|
1542
|
+
if (id === indexedId)
|
|
1543
|
+
return;
|
|
1544
|
+
indexedId = id;
|
|
1545
|
+
index(id);
|
|
1546
|
+
});
|
|
1547
|
+
}
|
|
1414
1548
|
/**
|
|
1415
1549
|
* Get ModelProperty instance by propertyFileId from static cache
|
|
1416
1550
|
*/
|
|
1417
1551
|
static getById(propertyFileId) {
|
|
1418
1552
|
if (!propertyFileId)
|
|
1419
1553
|
return undefined;
|
|
1420
|
-
|
|
1554
|
+
const indexed = this.idIndex.get(propertyFileId);
|
|
1555
|
+
if (!indexed)
|
|
1556
|
+
return undefined;
|
|
1557
|
+
if (this.isIndexEntryCurrent(propertyFileId, indexed))
|
|
1558
|
+
return indexed.instance;
|
|
1559
|
+
// The indexed instance left the cache or changed id; another cached instance may still have it.
|
|
1421
1560
|
// Cache key might be "modelName:propertyName" or "id:propertyId"
|
|
1561
|
+
this.idIndex.delete(propertyFileId);
|
|
1422
1562
|
for (const [cacheKey, { instance }] of this.instanceCache.entries()) {
|
|
1423
|
-
const context = instance._getSnapshotContext();
|
|
1424
1563
|
// id is now the schemaFileId (string)
|
|
1425
|
-
if (
|
|
1564
|
+
if (instance._getSnapshotContext().id === propertyFileId) {
|
|
1565
|
+
this.idIndex.set(propertyFileId, { cacheKey, instance });
|
|
1426
1566
|
return instance;
|
|
1427
1567
|
}
|
|
1428
1568
|
}
|
|
@@ -1432,7 +1572,7 @@ class ModelProperty {
|
|
|
1432
1572
|
* Create or get ModelProperty instance by propertyFileId
|
|
1433
1573
|
* Queries the database to find the property if not cached
|
|
1434
1574
|
*/
|
|
1435
|
-
static async createById(propertyFileId) {
|
|
1575
|
+
static async createById(propertyFileId, options) {
|
|
1436
1576
|
if (!propertyFileId) {
|
|
1437
1577
|
return undefined;
|
|
1438
1578
|
}
|
|
@@ -1446,10 +1586,7 @@ class ModelProperty {
|
|
|
1446
1586
|
if (!db) {
|
|
1447
1587
|
return undefined;
|
|
1448
1588
|
}
|
|
1449
|
-
|
|
1450
|
-
.select()
|
|
1451
|
-
.from(properties)
|
|
1452
|
-
.limit(100);
|
|
1589
|
+
const evictionEpoch = options?.evictionEpoch ?? currentEvictionEpoch();
|
|
1453
1590
|
const propertyRecords = await db
|
|
1454
1591
|
.select()
|
|
1455
1592
|
.from(properties)
|
|
@@ -1481,6 +1618,9 @@ class ModelProperty {
|
|
|
1481
1618
|
refModelId: propertyRecord.refModelId || undefined,
|
|
1482
1619
|
refValueType: propertyRecord.refValueType ? propertyRecord.refValueType : undefined,
|
|
1483
1620
|
required: propertyRecord.required ?? false,
|
|
1621
|
+
storageType: propertyRecord.storageType ?? undefined,
|
|
1622
|
+
localStorageDir: propertyRecord.localStorageDir ?? undefined,
|
|
1623
|
+
filenameSuffix: propertyRecord.filenameSuffix ?? undefined,
|
|
1484
1624
|
};
|
|
1485
1625
|
// Load isEdited from database
|
|
1486
1626
|
const isEditedFromDb = propertyRecord.isEdited ?? false;
|
|
@@ -1496,6 +1636,19 @@ class ModelProperty {
|
|
|
1496
1636
|
propertyData.ref = refModelRecords[0].name;
|
|
1497
1637
|
}
|
|
1498
1638
|
}
|
|
1639
|
+
// Its model's schema was evicted while we read the rows (e.g. a model's property lookup in flight
|
|
1640
|
+
// during Schema.destroy or test cleanup): don't bring the property back.
|
|
1641
|
+
if (anyEvictionSince(evictionEpoch)) {
|
|
1642
|
+
const schemaRows = await db
|
|
1643
|
+
.select({ name: schemas.name })
|
|
1644
|
+
.from(modelSchemas)
|
|
1645
|
+
.innerJoin(schemas, eq(schemas.id, modelSchemas.schemaId))
|
|
1646
|
+
.where(eq(modelSchemas.modelId, propertyRecord.modelId));
|
|
1647
|
+
if (schemaRows.length === 0 ||
|
|
1648
|
+
schemaRows.some((row) => schemaEvictedSince(row.name, evictionEpoch))) {
|
|
1649
|
+
return undefined;
|
|
1650
|
+
}
|
|
1651
|
+
}
|
|
1499
1652
|
// Create ModelProperty instance (sync for createById so we can send updateContext)
|
|
1500
1653
|
const instance = this.create(propertyData, { waitForReady: false });
|
|
1501
1654
|
// Set isEdited from database after creation
|
|
@@ -1562,6 +1715,20 @@ class ModelProperty {
|
|
|
1562
1715
|
timestamp: Date.now(),
|
|
1563
1716
|
});
|
|
1564
1717
|
}
|
|
1718
|
+
/**
|
|
1719
|
+
* A property write succeeded: add the property to its model's property ids, then drop the pending
|
|
1720
|
+
* write. In that order, `Model.properties` (property ids + pending writes) never misses it; in Node,
|
|
1721
|
+
* where the Model has no reactive liveQuery, nothing else would add it.
|
|
1722
|
+
*/
|
|
1723
|
+
static async completePendingWrite(propertyFileId, modelId) {
|
|
1724
|
+
try {
|
|
1725
|
+
await Model.refreshPropertiesForDbId(modelId);
|
|
1726
|
+
}
|
|
1727
|
+
catch (error) {
|
|
1728
|
+
logger(`Refreshing properties of model ${modelId} after writing "${propertyFileId}" failed: ${error}`);
|
|
1729
|
+
}
|
|
1730
|
+
this.clearPendingWrite(propertyFileId, 'success');
|
|
1731
|
+
}
|
|
1565
1732
|
/**
|
|
1566
1733
|
* Clear or update pending write status
|
|
1567
1734
|
*/
|
|
@@ -1700,6 +1867,36 @@ class ModelProperty {
|
|
|
1700
1867
|
logger('ModelProperty.reload() called - ModelProperty is loaded as part of Model/Schema. Reload the parent Model or Schema instead.');
|
|
1701
1868
|
// No-op for now, but could be enhanced to reload from DB if needed
|
|
1702
1869
|
}
|
|
1870
|
+
/**
|
|
1871
|
+
* Force-evict cached ModelProperty instances for the given models, ignoring refCounts, and stop
|
|
1872
|
+
* their services. Used by Schema.destroy() so a re-imported schema gets fresh instances instead of
|
|
1873
|
+
* ones holding a deleted row's _dbId.
|
|
1874
|
+
*/
|
|
1875
|
+
static evictForModels(modelNames, schemaName) {
|
|
1876
|
+
if (modelNames.length === 0)
|
|
1877
|
+
return;
|
|
1878
|
+
const names = new Set(modelNames);
|
|
1879
|
+
for (const [cacheKey, { instance }] of this.instanceCache.entries()) {
|
|
1880
|
+
let context;
|
|
1881
|
+
try {
|
|
1882
|
+
context = instance._getSnapshotContext();
|
|
1883
|
+
}
|
|
1884
|
+
catch {
|
|
1885
|
+
continue;
|
|
1886
|
+
}
|
|
1887
|
+
if (!context.modelName || !names.has(context.modelName))
|
|
1888
|
+
continue;
|
|
1889
|
+
if (schemaName && context._schemaName && context._schemaName !== schemaName)
|
|
1890
|
+
continue;
|
|
1891
|
+
this.instanceCache.delete(cacheKey);
|
|
1892
|
+
try {
|
|
1893
|
+
instance._service.stop();
|
|
1894
|
+
}
|
|
1895
|
+
catch {
|
|
1896
|
+
// Service might already be stopped
|
|
1897
|
+
}
|
|
1898
|
+
}
|
|
1899
|
+
}
|
|
1703
1900
|
unload() {
|
|
1704
1901
|
// ModelProperty doesn't have liveQuery subscriptions or complex cache management
|
|
1705
1902
|
// Just stop the service
|
|
@@ -1715,13 +1912,24 @@ class ModelProperty {
|
|
|
1715
1912
|
*/
|
|
1716
1913
|
async destroy() {
|
|
1717
1914
|
const context = this._getSnapshotContext();
|
|
1718
|
-
|
|
1719
|
-
|
|
1720
|
-
|
|
1721
|
-
|
|
1915
|
+
// Stored under "modelName:name", or "id:<id>" when another schema's same-name property holds that key
|
|
1916
|
+
const cacheKeys = [...ModelProperty.instanceCache.entries()]
|
|
1917
|
+
.filter(([, entry]) => {
|
|
1918
|
+
try {
|
|
1919
|
+
return entry.instance._getSnapshotContext().id === context.id;
|
|
1920
|
+
}
|
|
1921
|
+
catch {
|
|
1922
|
+
return false;
|
|
1923
|
+
}
|
|
1924
|
+
})
|
|
1925
|
+
.map(([key]) => key);
|
|
1926
|
+
if (cacheKeys.length === 0 && context.modelName && context.name) {
|
|
1927
|
+
cacheKeys.push(`${context.modelName}:${context.name}`);
|
|
1928
|
+
}
|
|
1929
|
+
if (cacheKeys.length === 0)
|
|
1722
1930
|
return;
|
|
1723
1931
|
forceRemoveFromCaches(this, {
|
|
1724
|
-
getCacheKeys: () =>
|
|
1932
|
+
getCacheKeys: () => cacheKeys,
|
|
1725
1933
|
caches: [ModelProperty.instanceCache],
|
|
1726
1934
|
});
|
|
1727
1935
|
await runDestroyLifecycle(this, {
|
|
@@ -1770,6 +1978,15 @@ class ModelProperty {
|
|
|
1770
1978
|
}
|
|
1771
1979
|
}
|
|
1772
1980
|
ModelProperty.instanceCache = new Map();
|
|
1981
|
+
/**
|
|
1982
|
+
* propertyFileId -> where the instance with that id is cached, so getById doesn't scan the cache
|
|
1983
|
+
* (a model's properties are looked up one by one, which made loading one model O(n²)).
|
|
1984
|
+
* Every cached instance's current id has an entry: it's added when the instance is cached and
|
|
1985
|
+
* again whenever its context id changes (a property is often created with a generated id and
|
|
1986
|
+
* then gets its real one). Entries aren't removed when an instance leaves the cache or changes
|
|
1987
|
+
* id; getById checks an entry before using it.
|
|
1988
|
+
*/
|
|
1989
|
+
ModelProperty.idIndex = new Map();
|
|
1773
1990
|
// Pending writes tracking
|
|
1774
1991
|
ModelProperty.pendingWrites = new Map();
|
|
1775
1992
|
|
|
@@ -1779,4 +1996,4 @@ var ModelProperty$1 = /*#__PURE__*/Object.freeze({
|
|
|
1779
1996
|
});
|
|
1780
1997
|
|
|
1781
1998
|
export { ModelProperty };
|
|
1782
|
-
//# sourceMappingURL=ModelProperty-
|
|
1999
|
+
//# sourceMappingURL=ModelProperty-6llK4MTH.js.map
|