@seedprotocol/sdk 0.4.14 → 0.4.15
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/{ArweaveClient-D6E8xe3J.js → ArweaveClient-DPeCeRMF.js} +21 -18
- package/dist/ArweaveClient-DPeCeRMF.js.map +1 -0
- package/dist/{ArweaveClient-DElJwN08.js → ArweaveClient-Zz6VwCkj.js} +21 -18
- package/dist/ArweaveClient-Zz6VwCkj.js.map +1 -0
- package/dist/{Db-De4o7jww.js → Db-Cvoi9q3N.js} +8 -5
- package/dist/Db-Cvoi9q3N.js.map +1 -0
- package/dist/{Db-DW1Un2jz.js → Db-DsFElL33.js} +356 -52
- package/dist/Db-DsFElL33.js.map +1 -0
- package/dist/{EasClient-BpGDIkmb.js → EasClient-B2N8bc3C.js} +6 -5
- package/dist/{EasClient-DGY_mkrd.js.map → EasClient-B2N8bc3C.js.map} +1 -1
- package/dist/{EasClient-DGY_mkrd.js → EasClient-D5Nn1WBF.js} +6 -5
- package/dist/{EasClient-BpGDIkmb.js.map → EasClient-D5Nn1WBF.js.map} +1 -1
- package/dist/{FileManager-DrHQbmYj.js → FileManager-Bk-JeMoA.js} +48 -11
- package/dist/FileManager-Bk-JeMoA.js.map +1 -0
- package/dist/{FileManager-Cw8mOIqZ.js → FileManager-Cqy_Lq46.js} +12 -8
- package/dist/FileManager-Cqy_Lq46.js.map +1 -0
- package/dist/{ModelProperty-D8d25NtC.js → ModelProperty-CkQaEsBu.js} +30 -28
- package/dist/ModelProperty-CkQaEsBu.js.map +1 -0
- package/dist/{PathResolver-D1k3dZg5.js → PathResolver-C3sdR5LL.js} +6 -5
- package/dist/{PathResolver-D1k3dZg5.js.map → PathResolver-C3sdR5LL.js.map} +1 -1
- package/dist/{PathResolver-BHj0UZTj.js → PathResolver-DF1QFI1d.js} +6 -5
- package/dist/{PathResolver-BHj0UZTj.js.map → PathResolver-DF1QFI1d.js.map} +1 -1
- package/dist/{QueryClient-BCVom0BA.js → QueryClient-CnONLIkA.js} +6 -5
- package/dist/{QueryClient-BCVom0BA.js.map → QueryClient-CnONLIkA.js.map} +1 -1
- package/dist/{QueryClient-D4974vvo.js → QueryClient-Ctgd0tDn.js} +6 -5
- package/dist/{QueryClient-D4974vvo.js.map → QueryClient-Ctgd0tDn.js.map} +1 -1
- package/dist/{Schema-CLlE7onI.js → Schema-Bnim4hAF.js} +90 -57
- package/dist/Schema-Bnim4hAF.js.map +1 -0
- package/dist/{SchemaValidationService-CwKY3QlY.js → SchemaValidationService-DXxRk-9Q.js} +138 -38
- package/dist/SchemaValidationService-DXxRk-9Q.js.map +1 -0
- package/dist/backfillMetadataPropertyIds-dzwzz4dA.js +67 -0
- package/dist/backfillMetadataPropertyIds-dzwzz4dA.js.map +1 -0
- package/dist/cjs/{ModelProperty-CgQ3zR-u.js → ModelProperty-C80601ai.js} +23 -21
- package/dist/cjs/ModelProperty-C80601ai.js.map +1 -0
- package/dist/cjs/{Schema-B0D7LgYb.js → Schema-6BQKp7hO.js} +60 -39
- package/dist/cjs/Schema-6BQKp7hO.js.map +1 -0
- package/dist/cjs/{SchemaValidationService-DUIOUvC_.js → SchemaValidationService-BySF1P0v.js} +138 -38
- package/dist/cjs/SchemaValidationService-BySF1P0v.js.map +1 -0
- package/dist/cjs/backfillMetadataPropertyIds-D9uzW5bW.js +84 -0
- package/dist/cjs/backfillMetadataPropertyIds-D9uzW5bW.js.map +1 -0
- package/dist/cjs/{getItem-BP4BYB4Z.js → getItem-Dj49AjWB.js} +5 -4
- package/dist/cjs/{getItem-BP4BYB4Z.js.map → getItem-Dj49AjWB.js.map} +1 -1
- package/dist/cjs/getPublishPayload-dR9co4rH.js +888 -0
- package/dist/cjs/getPublishPayload-dR9co4rH.js.map +1 -0
- package/dist/cjs/{getPublishUploads-D4DMfuOm.js → getPublishUploads-g61mgXaA.js} +111 -35
- package/dist/cjs/getPublishUploads-g61mgXaA.js.map +1 -0
- package/dist/cjs/getSegmentedItemProperties-NFvOHlAi.js +146 -0
- package/dist/cjs/getSegmentedItemProperties-NFvOHlAi.js.map +1 -0
- package/dist/cjs/{index-CUd7xS2i.js → index-9O_Ji1kY.js} +3332 -1367
- package/dist/cjs/index-9O_Ji1kY.js.map +1 -0
- package/dist/cjs/{index-BM8CSlnN.js → index-ud9i9fpp.js} +15 -7
- package/dist/cjs/index-ud9i9fpp.js.map +1 -0
- package/dist/cjs/{ownership-D3npAPnx.js → ownership-CyLRNReQ.js} +24 -7
- package/dist/cjs/ownership-CyLRNReQ.js.map +1 -0
- package/dist/cjs/property-Hj-RhQVX.js +318 -0
- package/dist/cjs/property-Hj-RhQVX.js.map +1 -0
- package/dist/db/drizzle/drizzle/0005_bright_lily_hollister.sql +27 -0
- package/dist/db/drizzle/drizzle/0006_add_publisher_to_versions_and_metadata.sql +3 -0
- package/dist/db/drizzle/drizzle/0007_add_required_to_properties.sql +1 -0
- package/dist/db/drizzle/drizzle/0008_add_revoked_at_to_seeds.sql +1 -0
- package/dist/db/drizzle/drizzle/0009_happy_namor.sql +14 -0
- package/dist/db/drizzle/drizzle/meta/0005_snapshot.json +1031 -0
- package/dist/db/drizzle/drizzle/meta/0006_snapshot.json +1045 -0
- package/dist/db/drizzle/drizzle/meta/0007_snapshot.json +1052 -0
- package/dist/db/drizzle/drizzle/meta/0008_snapshot.json +1059 -0
- package/dist/db/drizzle/drizzle/meta/0009_snapshot.json +1080 -0
- package/dist/db/drizzle/drizzle/meta/_journal.json +35 -0
- package/dist/{getItem-B_IP-uNX.js → getItem-ClK0UZqi.js} +5 -4
- package/dist/{getItem-B_IP-uNX.js.map → getItem-ClK0UZqi.js.map} +1 -1
- package/dist/getPublishPayload-CdfPTl8l.js +875 -0
- package/dist/getPublishPayload-CdfPTl8l.js.map +1 -0
- package/dist/{getPublishUploads-DPk5RcAG.js → getPublishUploads-CGBky9q9.js} +109 -15
- package/dist/getPublishUploads-CGBky9q9.js.map +1 -0
- package/dist/getSegmentedItemProperties-CJWdYH9W.js +144 -0
- package/dist/getSegmentedItemProperties-CJWdYH9W.js.map +1 -0
- package/dist/{index-DbmqfO-Q.js → index-C74KrwXN.js} +4 -2
- package/dist/index-C74KrwXN.js.map +1 -0
- package/dist/index-CgmWq1sF.js +19 -0
- package/dist/index-CgmWq1sF.js.map +1 -0
- package/dist/{index-Dh_gxItx.js → index-uPXtq2cf.js} +3321 -1376
- package/dist/index-uPXtq2cf.js.map +1 -0
- package/dist/main.cjs +7 -4
- package/dist/main.cjs.map +1 -1
- package/dist/main.js +138 -2218
- package/dist/main.js.map +1 -1
- package/dist/node.js +13 -12
- package/dist/node.js.map +1 -1
- package/dist/{ownership-CEv7BhIh.js → ownership-QK5haR3-.js} +24 -7
- package/dist/ownership-QK5haR3-.js.map +1 -0
- package/dist/{property-CppuVi-i.js → property-Dt0U3UXJ.js} +26 -6
- package/dist/property-Dt0U3UXJ.js.map +1 -0
- package/dist/{queries-B1vaglQW.js → queries-BUB-vUBm.js} +2 -2
- package/dist/{queries-B1vaglQW.js.map → queries-BUB-vUBm.js.map} +1 -1
- package/dist/seedSchema/AppStateSchema.d.ts +82 -0
- package/dist/seedSchema/AppStateSchema.d.ts.map +1 -0
- package/dist/seedSchema/ConfigSchema.d.ts +101 -0
- package/dist/seedSchema/ConfigSchema.d.ts.map +1 -0
- package/dist/seedSchema/MetadataSchema.d.ts +422 -0
- package/dist/seedSchema/MetadataSchema.d.ts.map +1 -0
- package/dist/seedSchema/MetadataSchema.ts +4 -1
- package/dist/seedSchema/ModelSchema.d.ts +243 -0
- package/dist/seedSchema/ModelSchema.d.ts.map +1 -0
- package/dist/seedSchema/ModelSchema.ts +1 -0
- package/dist/seedSchema/ModelSchemaSchema.d.ts +61 -0
- package/dist/seedSchema/ModelSchemaSchema.d.ts.map +1 -0
- package/dist/seedSchema/ModelUidSchema.d.ts +64 -0
- package/dist/seedSchema/ModelUidSchema.d.ts.map +1 -0
- package/dist/seedSchema/PropertyUidSchema.d.ts +64 -0
- package/dist/seedSchema/PropertyUidSchema.d.ts.map +1 -0
- package/dist/seedSchema/PropertyUidSchema.ts +2 -2
- package/dist/seedSchema/PublishProcessSchema.ts +22 -0
- package/dist/seedSchema/SchemaSchema.d.ts +169 -0
- package/dist/seedSchema/SchemaSchema.d.ts.map +1 -0
- package/dist/seedSchema/SeedSchema.d.ts +192 -0
- package/dist/seedSchema/SeedSchema.d.ts.map +1 -0
- package/dist/seedSchema/SeedSchema.ts +1 -0
- package/dist/seedSchema/UploadProcessSchema.ts +14 -0
- package/dist/seedSchema/VersionSchema.d.ts +194 -0
- package/dist/seedSchema/VersionSchema.d.ts.map +1 -0
- package/dist/seedSchema/VersionSchema.ts +1 -0
- package/dist/seedSchema/index.d.ts +11 -0
- package/dist/seedSchema/index.d.ts.map +1 -0
- package/dist/seedSchema/index.ts +2 -0
- package/dist/src/Item/Item.d.ts +5 -1
- package/dist/src/Item/Item.d.ts.map +1 -1
- package/dist/src/Item/queries.d.ts.map +1 -1
- package/dist/src/Item/service/actors/loadOrCreateItem.d.ts.map +1 -1
- package/dist/src/Item/service/actors/saveDataToDb.d.ts.map +1 -1
- package/dist/src/Item/service/itemMachineSingle.d.ts.map +1 -1
- package/dist/src/ItemProperty/ItemProperty.d.ts +4 -0
- 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/resolveRelatedValue.d.ts.map +1 -1
- package/dist/src/ItemProperty/service/actors/saveValueToDb/analyzeInput.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.map +1 -1
- package/dist/src/Model/index.d.ts +1 -0
- package/dist/src/Model/index.d.ts.map +1 -1
- package/dist/src/Model/service/actors/createModelProperties.d.ts.map +1 -1
- package/dist/src/Model/service/modelMachine.d.ts +2 -2
- package/dist/src/ModelProperty/ModelProperty.d.ts +1 -1
- package/dist/src/ModelProperty/ModelProperty.d.ts.map +1 -1
- package/dist/src/ModelProperty/service/modelPropertyMachine.d.ts +17 -17
- package/dist/src/Schema/Schema.d.ts +1 -0
- package/dist/src/Schema/Schema.d.ts.map +1 -1
- package/dist/src/Schema/service/actors/loadOrCreateSchema.d.ts.map +1 -1
- package/dist/src/Schema/service/addModelsMachine.d.ts +14 -14
- package/dist/src/Schema/service/addModelsMachine.d.ts.map +1 -1
- package/dist/src/Schema/service/schemaMachine.d.ts +87 -87
- package/dist/src/Schema/service/validation/SchemaValidationService.d.ts +5 -1
- package/dist/src/Schema/service/validation/SchemaValidationService.d.ts.map +1 -1
- package/dist/src/Schema/validation.d.ts +2 -0
- package/dist/src/Schema/validation.d.ts.map +1 -1
- package/dist/src/browser/db/Db.d.ts +3 -1
- 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/helpers/ArweaveClient.d.ts.map +1 -1
- 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/index.d.ts +0 -1
- package/dist/src/browser/index.d.ts.map +1 -1
- package/dist/src/browser/workers/ImageResizer.d.ts.map +1 -1
- package/dist/src/browser/workers/imageResize.d.ts.map +1 -1
- package/dist/src/client/ClientManager.d.ts +11 -0
- package/dist/src/client/ClientManager.d.ts.map +1 -1
- package/dist/src/client/actors/addModelsToDb.d.ts.map +1 -1
- package/dist/src/client/actors/dbInit.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/clientManagerMachine.d.ts.map +1 -1
- package/dist/src/db/Db/BaseDb.d.ts.map +1 -1
- package/dist/src/db/backfillMetadataPropertyIds.d.ts +7 -0
- package/dist/src/db/backfillMetadataPropertyIds.d.ts.map +1 -0
- package/dist/src/db/configs/dev.schema.config.d.ts.map +1 -1
- package/dist/src/db/read/getAttesterForSeed.d.ts +13 -0
- package/dist/src/db/read/getAttesterForSeed.d.ts.map +1 -0
- package/dist/src/db/read/getItemData.d.ts.map +1 -1
- package/dist/src/db/read/getItems.d.ts.map +1 -1
- package/dist/src/db/read/getMetadataAttestationUidsForSeedUid.d.ts +9 -0
- package/dist/src/db/read/getMetadataAttestationUidsForSeedUid.d.ts.map +1 -0
- package/dist/src/db/read/getPropertyData.d.ts +1 -1
- package/dist/src/db/read/getPropertyData.d.ts.map +1 -1
- package/dist/src/db/read/getPublishPayload.d.ts +26 -2
- package/dist/src/db/read/getPublishPayload.d.ts.map +1 -1
- package/dist/src/db/read/getPublishUploads.d.ts +1 -0
- package/dist/src/db/read/getPublishUploads.d.ts.map +1 -1
- package/dist/src/db/read/getRelatedItemsForPublish.d.ts.map +1 -1
- package/dist/src/db/read/getVersionsForSeedUid.d.ts +4 -0
- package/dist/src/db/read/getVersionsForSeedUid.d.ts.map +1 -0
- package/dist/src/db/read/subqueries/metadataLatest.d.ts.map +1 -1
- package/dist/src/db/write/createMetadata.d.ts +15 -1
- package/dist/src/db/write/createMetadata.d.ts.map +1 -1
- package/dist/src/db/write/createNewItem.d.ts.map +1 -1
- package/dist/src/db/write/createSeed.d.ts.map +1 -1
- package/dist/src/db/write/createVersion.d.ts.map +1 -1
- package/dist/src/db/write/updateItemPropertyValue.d.ts +2 -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 +10 -0
- package/dist/src/db/write/updateSeedRevokedAt.d.ts.map +1 -0
- package/dist/src/db/write/updateSeedUid.d.ts +6 -1
- package/dist/src/db/write/updateSeedUid.d.ts.map +1 -1
- package/dist/src/db/write/updateVersionUid.d.ts +13 -0
- package/dist/src/db/write/updateVersionUid.d.ts.map +1 -0
- package/dist/src/eas.d.ts +5 -2
- package/dist/src/eas.d.ts.map +1 -1
- package/dist/src/events/item/syncDbWithEas.d.ts +10 -0
- package/dist/src/events/item/syncDbWithEas.d.ts.map +1 -1
- package/dist/src/graphql/gql/gql.d.ts +2 -7
- package/dist/src/graphql/gql/gql.d.ts.map +1 -1
- package/dist/src/graphql/gql/graphql.d.ts +2 -16
- package/dist/src/graphql/gql/graphql.d.ts.map +1 -1
- package/dist/src/helpers/ArweaveClient/BaseArweaveClient.d.ts +22 -8
- package/dist/src/helpers/ArweaveClient/BaseArweaveClient.d.ts.map +1 -1
- package/dist/src/helpers/ArweaveClient/index.d.ts.map +1 -1
- package/dist/src/helpers/ArweaveClient/uploadApiVerification.d.ts +19 -0
- package/dist/src/helpers/ArweaveClient/uploadApiVerification.d.ts.map +1 -0
- package/dist/src/helpers/FileManager/BaseFileManager.d.ts +4 -0
- package/dist/src/helpers/FileManager/BaseFileManager.d.ts.map +1 -1
- package/dist/src/helpers/constants.d.ts.map +1 -1
- package/dist/src/helpers/crypto.d.ts +6 -0
- package/dist/src/helpers/crypto.d.ts.map +1 -1
- package/dist/src/helpers/db.d.ts +25 -0
- package/dist/src/helpers/db.d.ts.map +1 -1
- package/dist/src/helpers/easRevokedFilter.d.ts +10 -0
- package/dist/src/helpers/easRevokedFilter.d.ts.map +1 -0
- package/dist/src/helpers/file/queries.d.ts.map +1 -1
- package/dist/src/helpers/getSegmentedItemProperties.d.ts +2 -2
- package/dist/src/helpers/getSegmentedItemProperties.d.ts.map +1 -1
- package/dist/src/helpers/index.d.ts +3 -0
- package/dist/src/helpers/index.d.ts.map +1 -1
- package/dist/src/helpers/listPropertyValueFromStorage.d.ts +5 -0
- package/dist/src/helpers/listPropertyValueFromStorage.d.ts.map +1 -0
- package/dist/src/helpers/metadataPropertyNames.d.ts +50 -0
- package/dist/src/helpers/metadataPropertyNames.d.ts.map +1 -0
- package/dist/src/helpers/model.d.ts.map +1 -1
- package/dist/src/helpers/ownership.d.ts +2 -0
- package/dist/src/helpers/ownership.d.ts.map +1 -1
- package/dist/src/helpers/property/index.d.ts +24 -12
- package/dist/src/helpers/property/index.d.ts.map +1 -1
- package/dist/src/helpers/property.d.ts.map +1 -1
- package/dist/src/helpers/publishConfig.d.ts +36 -0
- package/dist/src/helpers/publishConfig.d.ts.map +1 -1
- package/dist/src/helpers/schema.d.ts.map +1 -1
- package/dist/src/helpers/updateSchema.d.ts +2 -5
- package/dist/src/helpers/updateSchema.d.ts.map +1 -1
- package/dist/src/imports/index.d.ts +1 -1
- package/dist/src/imports/index.d.ts.map +1 -1
- package/dist/src/imports/json.d.ts +16 -1
- package/dist/src/imports/json.d.ts.map +1 -1
- package/dist/src/index.d.ts +33 -8
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/interfaces/IItem.d.ts +5 -1
- package/dist/src/interfaces/IItem.d.ts.map +1 -1
- package/dist/src/interfaces/IItemProperty.d.ts +3 -0
- package/dist/src/interfaces/IItemProperty.d.ts.map +1 -1
- package/dist/src/node/db/Db.d.ts.map +1 -1
- package/dist/src/node/helpers/ArweaveClient.d.ts.map +1 -1
- package/dist/src/node/helpers/FileManager.d.ts +1 -0
- package/dist/src/node/helpers/FileManager.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 +17 -0
- package/dist/src/seedSchema/ModelSchema.d.ts.map +1 -1
- package/dist/src/seedSchema/PublishProcessSchema.d.ts +285 -0
- package/dist/src/seedSchema/PublishProcessSchema.d.ts.map +1 -0
- package/dist/src/seedSchema/SeedSchema.d.ts +17 -0
- package/dist/src/seedSchema/SeedSchema.d.ts.map +1 -1
- package/dist/src/seedSchema/UploadProcessSchema.d.ts +135 -0
- package/dist/src/seedSchema/UploadProcessSchema.d.ts.map +1 -0
- package/dist/src/seedSchema/VersionSchema.d.ts +19 -0
- package/dist/src/seedSchema/VersionSchema.d.ts.map +1 -1
- package/dist/src/seedSchema/index.d.ts +2 -0
- package/dist/src/seedSchema/index.d.ts.map +1 -1
- package/dist/src/services/write/writeProcessMachine.d.ts +1 -1
- package/dist/src/types/arweave.d.ts +2 -1
- package/dist/src/types/arweave.d.ts.map +1 -1
- package/dist/src/types/db.d.ts +2 -0
- package/dist/src/types/db.d.ts.map +1 -1
- package/dist/src/types/import.d.ts +3 -0
- package/dist/src/types/import.d.ts.map +1 -1
- package/dist/src/types/index.d.ts +9 -0
- package/dist/src/types/index.d.ts.map +1 -1
- package/dist/src/types/item.d.ts +13 -0
- package/dist/src/types/item.d.ts.map +1 -1
- package/dist/src/types/machines.d.ts +1 -0
- package/dist/src/types/machines.d.ts.map +1 -1
- package/dist/src/types/property.d.ts +11 -2
- package/dist/src/types/property.d.ts.map +1 -1
- package/dist/src/vite/index.d.ts.map +1 -1
- package/dist/vite.cjs +2 -127
- package/dist/vite.cjs.map +1 -1
- package/dist/vite.js +2 -127
- package/dist/vite.js.map +1 -1
- package/package.json +4 -11
- package/dist/ArweaveClient-D6E8xe3J.js.map +0 -1
- package/dist/ArweaveClient-DElJwN08.js.map +0 -1
- package/dist/Db-DW1Un2jz.js.map +0 -1
- package/dist/Db-De4o7jww.js.map +0 -1
- package/dist/FileManager-Cw8mOIqZ.js.map +0 -1
- package/dist/FileManager-DrHQbmYj.js.map +0 -1
- package/dist/ModelProperty-D8d25NtC.js.map +0 -1
- package/dist/Schema-CLlE7onI.js.map +0 -1
- package/dist/SchemaValidationService-CwKY3QlY.js.map +0 -1
- package/dist/cjs/ModelProperty-CgQ3zR-u.js.map +0 -1
- package/dist/cjs/Schema-B0D7LgYb.js.map +0 -1
- package/dist/cjs/SchemaValidationService-DUIOUvC_.js.map +0 -1
- package/dist/cjs/getPublishPayload-B90BFd8m.js +0 -520
- package/dist/cjs/getPublishPayload-B90BFd8m.js.map +0 -1
- package/dist/cjs/getPublishUploads-D4DMfuOm.js.map +0 -1
- package/dist/cjs/getSegmentedItemProperties-KdudlzXm.js +0 -71
- package/dist/cjs/getSegmentedItemProperties-KdudlzXm.js.map +0 -1
- package/dist/cjs/index-BM8CSlnN.js.map +0 -1
- package/dist/cjs/index-CUd7xS2i.js.map +0 -1
- package/dist/cjs/ownership-D3npAPnx.js.map +0 -1
- package/dist/getPublishPayload-BekDN5Ti.js +0 -503
- package/dist/getPublishPayload-BekDN5Ti.js.map +0 -1
- package/dist/getPublishUploads-DPk5RcAG.js.map +0 -1
- package/dist/getSegmentedItemProperties-DfQNbOpb.js +0 -69
- package/dist/getSegmentedItemProperties-DfQNbOpb.js.map +0 -1
- package/dist/index-DbmqfO-Q.js.map +0 -1
- package/dist/index-Dh_gxItx.js.map +0 -1
- package/dist/index-XBnjc_SF.js +0 -18
- package/dist/index-XBnjc_SF.js.map +0 -1
- package/dist/ownership-CEv7BhIh.js.map +0 -1
- package/dist/property-CppuVi-i.js.map +0 -1
- package/dist/src/browser/react/OPFSImage.d.ts +0 -7
- package/dist/src/browser/react/OPFSImage.d.ts.map +0 -1
- package/dist/src/browser/react/SeedImage.d.ts +0 -11
- package/dist/src/browser/react/SeedImage.d.ts.map +0 -1
- package/dist/src/browser/react/SeedProvider.d.ts +0 -30
- package/dist/src/browser/react/SeedProvider.d.ts.map +0 -1
- package/dist/src/browser/react/client.d.ts +0 -2
- package/dist/src/browser/react/client.d.ts.map +0 -1
- package/dist/src/browser/react/db.d.ts +0 -4
- package/dist/src/browser/react/db.d.ts.map +0 -1
- package/dist/src/browser/react/index.d.ts +0 -14
- package/dist/src/browser/react/index.d.ts.map +0 -1
- package/dist/src/browser/react/item.d.ts +0 -44
- package/dist/src/browser/react/item.d.ts.map +0 -1
- package/dist/src/browser/react/itemProperty.d.ts +0 -93
- package/dist/src/browser/react/itemProperty.d.ts.map +0 -1
- package/dist/src/browser/react/liveQuery.d.ts +0 -29
- package/dist/src/browser/react/liveQuery.d.ts.map +0 -1
- package/dist/src/browser/react/model.d.ts +0 -48
- package/dist/src/browser/react/model.d.ts.map +0 -1
- package/dist/src/browser/react/modelProperty.d.ts +0 -82
- package/dist/src/browser/react/modelProperty.d.ts.map +0 -1
- package/dist/src/browser/react/queryClient.d.ts +0 -28
- package/dist/src/browser/react/queryClient.d.ts.map +0 -1
- package/dist/src/browser/react/schema.d.ts +0 -45
- package/dist/src/browser/react/schema.d.ts.map +0 -1
- package/dist/src/browser/react/services.d.ts +0 -24
- package/dist/src/browser/react/services.d.ts.map +0 -1
- package/dist/src/browser/react/trash.d.ts +0 -9
- package/dist/src/browser/react/trash.d.ts.map +0 -1
- package/dist/src/browser/react/useImageFiles.d.ts +0 -19
- package/dist/src/browser/react/useImageFiles.d.ts.map +0 -1
package/dist/main.js
CHANGED
|
@@ -1,2242 +1,143 @@
|
|
|
1
1
|
import 'reflect-metadata';
|
|
2
|
-
import {
|
|
3
|
-
export {
|
|
4
|
-
|
|
5
|
-
import {
|
|
6
|
-
|
|
7
|
-
export {
|
|
8
|
-
|
|
9
|
-
import {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
import { useSelector } from '@xstate/react';
|
|
13
|
-
import { or, isNull, eq, isNotNull, and, gt, desc } from 'drizzle-orm';
|
|
14
|
-
import { useQueryClient, useQuery, QueryClient as QueryClient$1, QueryClientProvider } from '@tanstack/react-query';
|
|
15
|
-
import 'pluralize';
|
|
16
|
-
import { g as getSegmentedItemProperties } from './getSegmentedItemProperties-DfQNbOpb.js';
|
|
17
|
-
export { resolvePublishPayloadValues } from './getPublishPayload-BekDN5Ti.js';
|
|
2
|
+
import { o as BaseDb, z as versions, a3 as metadata, s as seeds, C as parseListPropertyValueFromStorage, q as getCorrectId } from './index-uPXtq2cf.js';
|
|
3
|
+
export { v as BaseArweaveClient, t as BaseFileManager, ai as ClientManagerState, aE as DEFAULT_ARWEAVE_GATEWAYS, aD as DEFAULT_ARWEAVE_HOST, $ as EasClient, t as FileManager, H as INTERNAL_DATA_TYPES, aq as ImageSize, r as Item, ar as ItemProperty, aj as MachineIds, M as Model, b as ModelPropertyDataTypes, ap as SEED_PROTOCOL_SCHEMA_NAME, aC as SeedModels, V as VERSION_SCHEMA_UID_OPTIMISM_SEPOLIA, W as appState, a$ as client, ak as createNewItem, aT as createSchema, ag as eventEmitter, aA as generateId, aG as getAddressesForItemsFilter, aH as getArweaveUrlForTransaction, ah as getClient, Q as getEasSchemaForItemProperty, ax as getEasSchemaUidBySchemaName, p as getGetAdditionalSyncAddresses, aP as getGetPublisherForNewSeeds, aw as getItemPropertiesFromEas, av as getItemVersionsFromEas, am as getMetadataLatest, au as getModelSchemasFromEas, aR as getRevokeExecutor, aW as getSchemaNameFromId, az as getSeedsBySchemaName, ay as getSeedsFromSchemaUids, aJ as getUploadApiArweaveDataUrl, aN as getUploadExecutor, aK as getUploadPipelineTransactionStatus, al as getVersionData, aX as importJsonSchema, aV as listSchemas, an as loadAllSchemasFromDb, a5 as modelSchemas, a6 as modelUids, x as models, aI as normalizeUploadApiBaseUrl, y as properties, ao as propertyMachine, aa as propertyUids, ab as publishProcesses, aY as readJsonImportFile, aU as readSchema, ac as schemas, aS as setAdditionalSyncAddresses, aO as setGetPublisherForNewSeeds, aQ as setRevokeExecutor, at as setSchemaUidForModel, as as setSchemaUidForSchemaDefinition, aM as setUploadExecutor, aZ as syncSchemaFromSource, a_ as transformImportToSchemaFile, aF as updateSeedRevokedAt, ad as uploadProcesses, aL as waitForEntityIdle, aB as withExcludeRevokedFilter } from './index-uPXtq2cf.js';
|
|
4
|
+
export { getPropertySchema } from './property-Dt0U3UXJ.js';
|
|
5
|
+
import { eq, desc, and, isNotNull, ne, or } from 'drizzle-orm';
|
|
6
|
+
export { S as Schema, a as deleteModelFromSchema, d as deletePropertyFromModel, r as renameModelProperty, s as schemaMachine, u as updateModelProperties } from './Schema-Bnim4hAF.js';
|
|
7
|
+
export { ModelProperty } from './ModelProperty-CkQaEsBu.js';
|
|
8
|
+
export { isItemOwned } from './ownership-QK5haR3-.js';
|
|
9
|
+
import { g as getSegmentedItemProperties } from './getSegmentedItemProperties-CJWdYH9W.js';
|
|
10
|
+
export { PublishValidationFailedError, resolvePublishPayloadValues, validateItemForPublish } from './getPublishPayload-CdfPTl8l.js';
|
|
11
|
+
export { itemHasPublishUploadCandidates } from './getPublishUploads-CGBky9q9.js';
|
|
18
12
|
import 'js-yaml';
|
|
19
13
|
import 'fs';
|
|
20
14
|
import 'xstate';
|
|
21
15
|
import 'drizzle-orm/sqlite-core';
|
|
22
16
|
import 'nanoid';
|
|
23
17
|
import 'nanoid-dictionary';
|
|
18
|
+
import 'debug';
|
|
24
19
|
import 'ethers';
|
|
25
|
-
import '
|
|
20
|
+
import 'pluralize';
|
|
21
|
+
import '@sinclair/typebox';
|
|
26
22
|
import 'drizzle-orm/casing';
|
|
23
|
+
import 'lodash-es';
|
|
24
|
+
import 'rxjs';
|
|
27
25
|
import 'eventemitter3';
|
|
28
26
|
import 'arweave';
|
|
29
|
-
import '
|
|
30
|
-
import './SchemaValidationService-
|
|
27
|
+
import 'js-sha3';
|
|
28
|
+
import './SchemaValidationService-DXxRk-9Q.js';
|
|
31
29
|
import '@sinclair/typebox/value';
|
|
32
30
|
|
|
33
|
-
const
|
|
34
|
-
const client = getClient();
|
|
35
|
-
const clientService = client.getService();
|
|
36
|
-
const isClientReady = useSelector(clientService, (snapshot) => {
|
|
37
|
-
return snapshot.value === ClientManagerState.IDLE;
|
|
38
|
-
});
|
|
39
|
-
// GlobalState removed - check ClientManager state directly
|
|
40
|
-
return isClientReady;
|
|
41
|
-
};
|
|
42
|
-
|
|
31
|
+
const isEmptyUid = (uid) => uid == null || uid === '' || uid === 'NULL';
|
|
43
32
|
/**
|
|
44
|
-
*
|
|
45
|
-
*
|
|
46
|
-
*
|
|
47
|
-
* 1. SQL tag function: useLiveQuery((sql) => sql`SELECT * FROM models`)
|
|
48
|
-
* 2. Drizzle query builder: useLiveQuery(db.select().from(models))
|
|
49
|
-
*
|
|
50
|
-
* @param query - SQL query function or Drizzle query builder, or null/undefined to disable the query
|
|
51
|
-
* @returns Array of query results, or undefined if not yet loaded
|
|
52
|
-
*
|
|
53
|
-
* @example
|
|
54
|
-
* ```typescript
|
|
55
|
-
* // Using SQL tag function
|
|
56
|
-
* const models = useLiveQuery<ModelRow>(
|
|
57
|
-
* (sql) => sql`SELECT * FROM models WHERE schema_file_id = ${schemaId}`
|
|
58
|
-
* )
|
|
59
|
-
*
|
|
60
|
-
* // Using Drizzle query builder
|
|
61
|
-
* import { models } from '@/seedSchema'
|
|
62
|
-
* import { eq } from 'drizzle-orm'
|
|
63
|
-
*
|
|
64
|
-
* const appDb = BaseDb.getAppDb()
|
|
65
|
-
* const models = useLiveQuery<ModelRow>(
|
|
66
|
-
* appDb.select().from(models).where(eq(models.schemaFileId, schemaId))
|
|
67
|
-
* )
|
|
68
|
-
* ```
|
|
33
|
+
* Updates the version record with the attestation UID after a Version attestation is created.
|
|
34
|
+
* Targets the version without a uid yet (the one being published).
|
|
35
|
+
* Publisher is immutable once set: we never overwrite an existing publisher.
|
|
69
36
|
*/
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
const
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
const
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
return;
|
|
98
|
-
}
|
|
99
|
-
const subscription = observable.subscribe({
|
|
100
|
-
next: (results) => {
|
|
101
|
-
const prev = previousDataRef.current;
|
|
102
|
-
const prevJson = prev ? JSON.stringify(prev) : 'undefined';
|
|
103
|
-
const currJson = results ? JSON.stringify(results) : 'undefined';
|
|
104
|
-
const isSameValue = prevJson === currJson;
|
|
105
|
-
// Defensive check: don't update state if values are the same
|
|
106
|
-
// This should be handled by distinctUntilChanged, but adding as safety
|
|
107
|
-
// (especially important for Drizzle query builders which may not work with distinctUntilChanged)
|
|
108
|
-
if (isSameValue && prev !== undefined) {
|
|
109
|
-
return;
|
|
110
|
-
}
|
|
111
|
-
previousDataRef.current = results;
|
|
112
|
-
setData(results);
|
|
113
|
-
},
|
|
114
|
-
error: (err) => {
|
|
115
|
-
console.error('[useLiveQuery] Error:', err);
|
|
116
|
-
// Don't set data to undefined on error - keep last known good state
|
|
117
|
-
// This prevents UI flickering on transient errors
|
|
118
|
-
},
|
|
119
|
-
});
|
|
120
|
-
subscriptionRef.current = subscription;
|
|
121
|
-
// Cleanup on unmount or observable change
|
|
122
|
-
return () => {
|
|
123
|
-
if (subscriptionRef.current) {
|
|
124
|
-
subscriptionRef.current.unsubscribe();
|
|
125
|
-
subscriptionRef.current = null;
|
|
126
|
-
}
|
|
127
|
-
};
|
|
128
|
-
}, [observable]); // Only re-subscribe when observable changes
|
|
129
|
-
return data;
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
const logger$2 = debug('seedSdk:react:item');
|
|
133
|
-
const useItem = ({ modelName, seedLocalId, seedUid }) => {
|
|
134
|
-
const [item, setItem] = useState();
|
|
135
|
-
const [isLoading, setIsLoading] = useState(!!(seedLocalId || seedUid));
|
|
136
|
-
const [error, setError] = useState(null);
|
|
137
|
-
const subscriptionRef = useRef(undefined);
|
|
138
|
-
const hasSeenIdleRef = useRef(false);
|
|
139
|
-
const isClientReady = useIsClientReady();
|
|
140
|
-
const modelNameRef = useRef(modelName);
|
|
141
|
-
const seedLocalIdRef = useRef(seedLocalId);
|
|
142
|
-
const seedUidRef = useRef(seedUid);
|
|
143
|
-
// Determine if we should be loading based on parameters - use useMemo to stabilize
|
|
144
|
-
// Use refs to check current values to avoid dependency issues
|
|
145
|
-
const shouldLoad = useMemo(() => {
|
|
146
|
-
if (!isClientReady)
|
|
147
|
-
return false;
|
|
148
|
-
return !!(seedLocalIdRef.current || seedUidRef.current);
|
|
149
|
-
}, [isClientReady, seedLocalId, seedUid]);
|
|
150
|
-
const loadItem = useCallback(async () => {
|
|
151
|
-
// Check shouldLoad inside the function to avoid recreating the callback
|
|
152
|
-
const currentShouldLoad = !!(isClientReady && (seedLocalIdRef.current || seedUidRef.current));
|
|
153
|
-
if (!currentShouldLoad) {
|
|
154
|
-
setItem(undefined);
|
|
155
|
-
setIsLoading(false);
|
|
156
|
-
setError(null);
|
|
157
|
-
return;
|
|
158
|
-
}
|
|
159
|
-
try {
|
|
160
|
-
// Don't set isLoading here - let the subscription effect handle it
|
|
161
|
-
// This avoids race conditions where isLoading is set to true but then
|
|
162
|
-
// the subscription effect hasn't run yet to set it to false
|
|
163
|
-
setError(null);
|
|
164
|
-
const foundItem = await Item.find({
|
|
165
|
-
modelName: modelNameRef.current,
|
|
166
|
-
seedLocalId: seedLocalIdRef.current,
|
|
167
|
-
seedUid: seedUidRef.current,
|
|
168
|
-
});
|
|
169
|
-
if (!foundItem) {
|
|
170
|
-
logger$2('[useItem] [loadItem] no item found', modelNameRef.current, seedLocalIdRef.current);
|
|
171
|
-
// Don't clear item if we already have one for the same request (e.g. duplicate loadItem from effect re-run)
|
|
172
|
-
setItem((prev) => {
|
|
173
|
-
if (!prev)
|
|
174
|
-
return undefined;
|
|
175
|
-
const match = (prev.seedLocalId && prev.seedLocalId === seedLocalIdRef.current) ||
|
|
176
|
-
(prev.seedUid && prev.seedUid === seedUidRef.current);
|
|
177
|
-
return match ? prev : undefined;
|
|
178
|
-
});
|
|
179
|
-
setIsLoading(false);
|
|
180
|
-
setError(null);
|
|
181
|
-
return;
|
|
182
|
-
}
|
|
183
|
-
// Item.find() now waits for idle by default, so the item should be ready
|
|
184
|
-
setItem(foundItem);
|
|
185
|
-
setIsLoading(false); // Item is ready since find() waited for idle
|
|
186
|
-
setError(null);
|
|
187
|
-
}
|
|
188
|
-
catch (error) {
|
|
189
|
-
logger$2('[useItem] Error loading item:', error);
|
|
190
|
-
setItem(undefined);
|
|
191
|
-
setIsLoading(false);
|
|
192
|
-
setError(error);
|
|
193
|
-
}
|
|
194
|
-
}, [isClientReady]);
|
|
195
|
-
useEffect(() => {
|
|
196
|
-
modelNameRef.current = modelName;
|
|
197
|
-
seedLocalIdRef.current = seedLocalId;
|
|
198
|
-
seedUidRef.current = seedUid;
|
|
199
|
-
}, [modelName, seedLocalId, seedUid]);
|
|
200
|
-
// Fetch/refetch when parameters change or client becomes ready
|
|
201
|
-
useEffect(() => {
|
|
202
|
-
// Only clear item if we don't have parameters to load
|
|
203
|
-
// Don't clear if shouldLoad is false but we have an item - it might just be a timing issue
|
|
204
|
-
if (!shouldLoad) {
|
|
205
|
-
// Only clear if we actually don't have parameters (not just client not ready)
|
|
206
|
-
if (!seedLocalId && !seedUid) {
|
|
207
|
-
setItem(undefined);
|
|
208
|
-
setIsLoading(false);
|
|
209
|
-
setError(null);
|
|
210
|
-
}
|
|
211
|
-
return;
|
|
212
|
-
}
|
|
213
|
-
loadItem();
|
|
214
|
-
}, [shouldLoad, loadItem, seedLocalId, seedUid]);
|
|
215
|
-
// Subscribe to service changes when item is available
|
|
216
|
-
useEffect(() => {
|
|
217
|
-
if (!item) {
|
|
218
|
-
// Clean up subscription if item is not available
|
|
219
|
-
subscriptionRef.current?.unsubscribe();
|
|
220
|
-
subscriptionRef.current = undefined;
|
|
221
|
-
hasSeenIdleRef.current = false;
|
|
222
|
-
return;
|
|
223
|
-
}
|
|
224
|
-
// Clean up previous subscription
|
|
225
|
-
subscriptionRef.current?.unsubscribe();
|
|
226
|
-
hasSeenIdleRef.current = false;
|
|
227
|
-
// Subscribe to service changes. Only set isLoading to true after we've seen idle at least
|
|
228
|
-
// once, so we don't overwrite the ready state that loadItem() just set (find() waits for idle).
|
|
229
|
-
const service = item.getService();
|
|
230
|
-
const subscription = service.subscribe((snapshot) => {
|
|
231
|
-
// Update loading state based on service state changes
|
|
232
|
-
if (snapshot && typeof snapshot === 'object' && 'value' in snapshot) {
|
|
233
|
-
const isIdle = snapshot.value === 'idle';
|
|
234
|
-
if (isIdle) {
|
|
235
|
-
hasSeenIdleRef.current = true;
|
|
236
|
-
setIsLoading(false);
|
|
237
|
-
setError(null);
|
|
238
|
-
}
|
|
239
|
-
else if (snapshot.value === 'error') {
|
|
240
|
-
setError(new Error('Item service error'));
|
|
241
|
-
setIsLoading(false);
|
|
242
|
-
}
|
|
243
|
-
else {
|
|
244
|
-
// Only show loading if we've already seen idle (real transition to loading)
|
|
245
|
-
if (hasSeenIdleRef.current) {
|
|
246
|
-
setIsLoading(true);
|
|
247
|
-
}
|
|
248
|
-
}
|
|
249
|
-
}
|
|
250
|
-
});
|
|
251
|
-
subscriptionRef.current = subscription;
|
|
252
|
-
return () => {
|
|
253
|
-
subscriptionRef.current?.unsubscribe();
|
|
254
|
-
subscriptionRef.current = undefined;
|
|
255
|
-
};
|
|
256
|
-
}, [item]);
|
|
257
|
-
return {
|
|
258
|
-
item,
|
|
259
|
-
isLoading,
|
|
260
|
-
error,
|
|
261
|
-
};
|
|
262
|
-
};
|
|
263
|
-
const getItemsQueryKey = (modelName, deleted, includeEas, addressFilter) => ['seed', 'items', modelName ?? null, deleted ?? false, includeEas ?? false, addressFilter ?? null];
|
|
264
|
-
const useItems = ({ modelName, deleted = false, includeEas = false, addressFilter, }) => {
|
|
265
|
-
const isClientReady = useIsClientReady();
|
|
266
|
-
const queryClient = useQueryClient();
|
|
267
|
-
const previousSeedsTableDataRef = useRef(undefined);
|
|
268
|
-
const itemsRef = useRef([]);
|
|
269
|
-
const lastFetchedIdsRef = useRef(new Set());
|
|
270
|
-
const queryKey = useMemo(() => getItemsQueryKey(modelName, deleted, includeEas, addressFilter), [modelName, deleted, includeEas, addressFilter]);
|
|
271
|
-
const { data: items = [], isLoading, error: queryError, } = useQuery({
|
|
272
|
-
queryKey,
|
|
273
|
-
queryFn: () => Item.all(modelName, deleted, { waitForReady: true, includeEas, addressFilter }),
|
|
274
|
-
enabled: isClientReady,
|
|
275
|
-
});
|
|
276
|
-
itemsRef.current = items;
|
|
277
|
-
// Watch the seeds table for changes
|
|
278
|
-
const db = isClientReady ? BaseDb.getAppDb() : null;
|
|
279
|
-
const seedsQuery = useMemo(() => {
|
|
280
|
-
if (!db)
|
|
281
|
-
return null;
|
|
282
|
-
const conditions = [];
|
|
283
|
-
if (!includeEas) {
|
|
284
|
-
conditions.push(or(isNull(seeds.uid), eq(seeds.uid, '')));
|
|
285
|
-
}
|
|
286
|
-
if (modelName) {
|
|
287
|
-
conditions.push(eq(seeds.type, modelName.toLowerCase()));
|
|
288
|
-
}
|
|
289
|
-
if (deleted) {
|
|
290
|
-
conditions.push(or(isNotNull(seeds._markedForDeletion), eq(seeds._markedForDeletion, 1)));
|
|
291
|
-
}
|
|
292
|
-
else {
|
|
293
|
-
conditions.push(or(isNull(seeds._markedForDeletion), eq(seeds._markedForDeletion, 0)));
|
|
294
|
-
}
|
|
295
|
-
const versionData = getVersionData();
|
|
296
|
-
return db
|
|
297
|
-
.with(versionData)
|
|
298
|
-
.select({
|
|
299
|
-
localId: seeds.localId,
|
|
300
|
-
uid: seeds.uid,
|
|
301
|
-
type: seeds.type,
|
|
302
|
-
schemaUid: seeds.schemaUid,
|
|
303
|
-
createdAt: seeds.createdAt,
|
|
304
|
-
attestationCreatedAt: seeds.attestationCreatedAt,
|
|
305
|
-
_markedForDeletion: seeds._markedForDeletion,
|
|
306
|
-
})
|
|
307
|
-
.from(seeds)
|
|
308
|
-
.leftJoin(versionData, eq(seeds.localId, versionData.seedLocalId))
|
|
309
|
-
.where(and(gt(versionData.versionsCount, 0), ...conditions))
|
|
310
|
-
.groupBy(seeds.localId);
|
|
311
|
-
}, [db, isClientReady, modelName, deleted, includeEas]);
|
|
312
|
-
const seedsTableData = useLiveQuery(seedsQuery);
|
|
313
|
-
// Invalidate when table data actually changes so useQuery refetches
|
|
314
|
-
useEffect(() => {
|
|
315
|
-
if (!isClientReady || !seedsTableData)
|
|
316
|
-
return;
|
|
317
|
-
const tableDataItemsSet = new Set();
|
|
318
|
-
for (const dbSeed of seedsTableData) {
|
|
319
|
-
const key = dbSeed.localId || dbSeed.uid;
|
|
320
|
-
if (key)
|
|
321
|
-
tableDataItemsSet.add(key);
|
|
322
|
-
}
|
|
323
|
-
const currentItemsSet = new Set();
|
|
324
|
-
for (const item of itemsRef.current) {
|
|
325
|
-
const key = item.seedLocalId || item.seedUid;
|
|
326
|
-
if (key)
|
|
327
|
-
currentItemsSet.add(key);
|
|
328
|
-
}
|
|
329
|
-
if (tableDataItemsSet.size === 0 && currentItemsSet.size > 0)
|
|
330
|
-
return;
|
|
331
|
-
const lastFetched = lastFetchedIdsRef.current;
|
|
332
|
-
if (lastFetched.size === tableDataItemsSet.size &&
|
|
333
|
-
[...lastFetched].every((id) => tableDataItemsSet.has(id))) {
|
|
334
|
-
return;
|
|
335
|
-
}
|
|
336
|
-
previousSeedsTableDataRef.current = seedsTableData;
|
|
337
|
-
const setsAreEqual = currentItemsSet.size === tableDataItemsSet.size &&
|
|
338
|
-
[...currentItemsSet].every((id) => tableDataItemsSet.has(id));
|
|
339
|
-
if (setsAreEqual) {
|
|
340
|
-
lastFetchedIdsRef.current = new Set(tableDataItemsSet);
|
|
341
|
-
return;
|
|
342
|
-
}
|
|
343
|
-
lastFetchedIdsRef.current = new Set(tableDataItemsSet);
|
|
344
|
-
queryClient.invalidateQueries({ queryKey });
|
|
345
|
-
}, [isClientReady, seedsTableData, queryClient, queryKey]);
|
|
346
|
-
return {
|
|
347
|
-
items: orderBy(items, [
|
|
348
|
-
(item) => item.lastVersionPublishedAt ||
|
|
349
|
-
item.attestationCreatedAt ||
|
|
350
|
-
item.createdAt,
|
|
351
|
-
], ['desc']),
|
|
352
|
-
isLoading,
|
|
353
|
-
error: queryError,
|
|
354
|
-
};
|
|
355
|
-
};
|
|
356
|
-
const useCreateItem = () => {
|
|
357
|
-
const [isLoading, setIsLoading] = useState(false);
|
|
358
|
-
const [error, setError] = useState(null);
|
|
359
|
-
const resetError = useCallback(() => setError(null), []);
|
|
360
|
-
const createItem = useCallback(async (modelName, itemData) => {
|
|
361
|
-
if (isLoading) {
|
|
362
|
-
logger$2('[useCreateItem] [createItem] already creating item, skipping');
|
|
363
|
-
return undefined;
|
|
364
|
-
}
|
|
365
|
-
setError(null);
|
|
366
|
-
// Flush loading=true synchronously so the UI (and tests) can observe it before async work runs.
|
|
367
|
-
flushSync(() => setIsLoading(true));
|
|
368
|
-
try {
|
|
369
|
-
const data = itemData ?? {};
|
|
370
|
-
const { seedLocalId } = await createNewItem({ modelName, ...data });
|
|
371
|
-
const newItem = await Item.find({ modelName, seedLocalId });
|
|
372
|
-
return (newItem ?? undefined);
|
|
373
|
-
}
|
|
374
|
-
catch (err) {
|
|
375
|
-
logger$2('[useCreateItem] Error creating item:', err);
|
|
376
|
-
setError(err instanceof Error ? err : new Error(String(err)));
|
|
377
|
-
return undefined;
|
|
378
|
-
}
|
|
379
|
-
finally {
|
|
380
|
-
// Defer clearing loading so React can commit the loading=true render first.
|
|
381
|
-
// Otherwise the test (or UI) may never observe isLoading true (same continuation batching).
|
|
382
|
-
queueMicrotask(() => setIsLoading(false));
|
|
383
|
-
}
|
|
384
|
-
}, [isLoading]);
|
|
385
|
-
return {
|
|
386
|
-
createItem,
|
|
387
|
-
isLoading,
|
|
388
|
-
error,
|
|
389
|
-
resetError,
|
|
390
|
-
};
|
|
391
|
-
};
|
|
392
|
-
const usePublishItem = () => {
|
|
393
|
-
const [publishingItem, setPublishingItem] = useState(null);
|
|
394
|
-
const [isLoading, setIsLoading] = useState(false);
|
|
395
|
-
const [error, setError] = useState(null);
|
|
396
|
-
const subscriptionRef = useRef(undefined);
|
|
397
|
-
const resetError = useCallback(() => setError(null), []);
|
|
398
|
-
const publishItem = useCallback((item) => {
|
|
399
|
-
if (!item)
|
|
400
|
-
return;
|
|
401
|
-
setPublishingItem(item);
|
|
402
|
-
setError(null);
|
|
403
|
-
item.publish().catch(() => {
|
|
404
|
-
// Error is surfaced via service state subscription; avoid unhandled rejection
|
|
405
|
-
});
|
|
406
|
-
}, []);
|
|
407
|
-
useEffect(() => {
|
|
408
|
-
if (!publishingItem) {
|
|
409
|
-
subscriptionRef.current?.unsubscribe();
|
|
410
|
-
subscriptionRef.current = undefined;
|
|
411
|
-
setIsLoading(false);
|
|
412
|
-
return;
|
|
413
|
-
}
|
|
414
|
-
subscriptionRef.current?.unsubscribe();
|
|
415
|
-
const service = publishingItem.getService();
|
|
416
|
-
const subscription = service.subscribe((snapshot) => {
|
|
417
|
-
const value = snapshot?.value;
|
|
418
|
-
const ctx = snapshot?.context;
|
|
419
|
-
setIsLoading(value === 'publishing');
|
|
420
|
-
const publishError = ctx?._publishError;
|
|
421
|
-
setError(publishError ? new Error(publishError.message) : null);
|
|
422
|
-
});
|
|
423
|
-
subscriptionRef.current = subscription;
|
|
424
|
-
const snap = service.getSnapshot();
|
|
425
|
-
setIsLoading(snap?.value === 'publishing');
|
|
426
|
-
const ctx = snap?.context;
|
|
427
|
-
const publishError = ctx?._publishError;
|
|
428
|
-
setError(publishError ? new Error(publishError.message) : null);
|
|
429
|
-
return () => {
|
|
430
|
-
subscriptionRef.current?.unsubscribe();
|
|
431
|
-
subscriptionRef.current = undefined;
|
|
432
|
-
};
|
|
433
|
-
}, [publishingItem]);
|
|
434
|
-
return {
|
|
435
|
-
publishItem,
|
|
436
|
-
isLoading,
|
|
437
|
-
error,
|
|
438
|
-
resetError,
|
|
439
|
-
};
|
|
37
|
+
const updateVersionUid = async ({ seedLocalId, versionUid, publisher, }) => {
|
|
38
|
+
if (!seedLocalId || !versionUid) {
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
const appDb = BaseDb.getAppDb();
|
|
42
|
+
if (!appDb)
|
|
43
|
+
return;
|
|
44
|
+
const rows = await appDb
|
|
45
|
+
.select({ localId: versions.localId, uid: versions.uid, publisher: versions.publisher })
|
|
46
|
+
.from(versions)
|
|
47
|
+
.where(eq(versions.seedLocalId, seedLocalId))
|
|
48
|
+
.orderBy(desc(versions.createdAt));
|
|
49
|
+
const toUpdate = rows.find((r) => r.localId && isEmptyUid(r.uid));
|
|
50
|
+
if (!toUpdate?.localId)
|
|
51
|
+
return;
|
|
52
|
+
let shouldSetPublisher = publisher != null && publisher !== '';
|
|
53
|
+
if (shouldSetPublisher && toUpdate.publisher != null && toUpdate.publisher !== '') {
|
|
54
|
+
shouldSetPublisher = false;
|
|
55
|
+
}
|
|
56
|
+
await appDb
|
|
57
|
+
.update(versions)
|
|
58
|
+
.set({
|
|
59
|
+
uid: versionUid,
|
|
60
|
+
...(shouldSetPublisher && { publisher }),
|
|
61
|
+
updatedAt: Date.now(),
|
|
62
|
+
})
|
|
63
|
+
.where(eq(versions.localId, toUpdate.localId));
|
|
440
64
|
};
|
|
441
65
|
|
|
442
|
-
const
|
|
443
|
-
|
|
444
|
-
function useItemProperty(arg1, arg2) {
|
|
445
|
-
const isClientReady = useIsClientReady();
|
|
446
|
-
const [property, setProperty] = useState(undefined);
|
|
447
|
-
const [isLoading, setIsLoading] = useState(false);
|
|
448
|
-
const [error, setError] = useState(null);
|
|
449
|
-
const subscriptionRef = useRef(undefined);
|
|
450
|
-
const [, setVersion] = useState(0); // Version counter to force re-renders
|
|
451
|
-
// Extract primitives so useMemo/useCallback deps are stable when caller passes inline objects
|
|
452
|
-
// Support object form with itemId: useItemProperty({ itemId, propertyName })
|
|
453
|
-
const arg1IsObject = typeof arg1 === 'object' && arg1 != null;
|
|
454
|
-
const obj = arg1IsObject ? arg1 : null;
|
|
455
|
-
const itemIdFromObj = obj != null ? obj.itemId : undefined;
|
|
456
|
-
const seedLocalId = obj != null ? obj.seedLocalId : undefined;
|
|
457
|
-
const seedUid = obj != null ? obj.seedUid : undefined;
|
|
458
|
-
const propertyNameFromObj = obj != null ? obj.propertyName : undefined;
|
|
459
|
-
const itemId = typeof arg1 === 'string' ? arg1 : (itemIdFromObj !== undefined && itemIdFromObj !== '' ? itemIdFromObj : undefined);
|
|
460
|
-
const propertyNameFromArgs = typeof arg1 === 'string' ? arg2 : undefined;
|
|
461
|
-
const propertyName = propertyNameFromObj ?? propertyNameFromArgs;
|
|
462
|
-
// Determine which lookup mode we're in based on arguments (deps are primitives to avoid infinite loop)
|
|
463
|
-
// Unify itemId and identifiers: when itemId is provided (string or object form), use it as seedLocalId so we hit the same code path
|
|
464
|
-
const lookupMode = useMemo(() => {
|
|
465
|
-
const resolvedSeedLocalId = (itemId !== undefined && itemId !== '') ? itemId : seedLocalId;
|
|
466
|
-
const resolvedSeedUid = (itemId !== undefined && itemId !== '') ? undefined : seedUid;
|
|
467
|
-
if ((resolvedSeedLocalId != null || resolvedSeedUid != null) && propertyName != null && propertyName !== '') {
|
|
468
|
-
return {
|
|
469
|
-
type: 'identifiers',
|
|
470
|
-
seedLocalId: resolvedSeedLocalId ?? undefined,
|
|
471
|
-
seedUid: resolvedSeedUid,
|
|
472
|
-
propertyName,
|
|
473
|
-
};
|
|
474
|
-
}
|
|
475
|
-
return null;
|
|
476
|
-
}, [itemId, propertyName, seedLocalId, seedUid]);
|
|
477
|
-
// Determine initial loading state
|
|
478
|
-
useMemo(() => {
|
|
479
|
-
if (!lookupMode)
|
|
480
|
-
return false;
|
|
481
|
-
return !!((lookupMode.seedLocalId || lookupMode.seedUid) &&
|
|
482
|
-
lookupMode.propertyName);
|
|
483
|
-
}, [lookupMode]);
|
|
484
|
-
// Determine if we should be loading based on parameters
|
|
485
|
-
const shouldLoad = useMemo(() => {
|
|
486
|
-
if (!isClientReady)
|
|
487
|
-
return false;
|
|
488
|
-
if (!lookupMode)
|
|
489
|
-
return false;
|
|
490
|
-
return !!((lookupMode.seedLocalId || lookupMode.seedUid) &&
|
|
491
|
-
lookupMode.propertyName);
|
|
492
|
-
}, [isClientReady, lookupMode]);
|
|
493
|
-
const updateItemProperty = useCallback(async () => {
|
|
494
|
-
if (!isClientReady || !lookupMode) {
|
|
495
|
-
setProperty(undefined);
|
|
496
|
-
setIsLoading(false);
|
|
497
|
-
setError(null);
|
|
498
|
-
return;
|
|
499
|
-
}
|
|
500
|
-
try {
|
|
501
|
-
setIsLoading(true);
|
|
502
|
-
setError(null);
|
|
503
|
-
const seedLocalId = lookupMode.seedLocalId;
|
|
504
|
-
const seedUid = lookupMode.seedUid;
|
|
505
|
-
if (!seedLocalId && !seedUid) {
|
|
506
|
-
setProperty(undefined);
|
|
507
|
-
setIsLoading(false);
|
|
508
|
-
setError(null);
|
|
509
|
-
return;
|
|
510
|
-
}
|
|
511
|
-
const foundProperty = await ItemProperty.find({
|
|
512
|
-
propertyName: lookupMode.propertyName,
|
|
513
|
-
seedLocalId,
|
|
514
|
-
seedUid,
|
|
515
|
-
});
|
|
516
|
-
if (!foundProperty) {
|
|
517
|
-
logger$1(`[useItemProperty] [updateItemProperty] no property found for Item.${seedLocalId || seedUid}.${lookupMode.propertyName}`);
|
|
518
|
-
setProperty(undefined);
|
|
519
|
-
setIsLoading(false);
|
|
520
|
-
setError(null);
|
|
521
|
-
return;
|
|
522
|
-
}
|
|
523
|
-
// ItemProperty.find() now waits for idle by default, so the property should be ready
|
|
524
|
-
setProperty(foundProperty);
|
|
525
|
-
setIsLoading(false); // Property is ready since find() waited for idle
|
|
526
|
-
setError(null);
|
|
527
|
-
}
|
|
528
|
-
catch (error) {
|
|
529
|
-
logger$1('[useItemProperty] Error updating item property:', error);
|
|
530
|
-
setProperty(undefined);
|
|
531
|
-
setIsLoading(false);
|
|
532
|
-
setError(error);
|
|
533
|
-
}
|
|
534
|
-
}, [isClientReady, lookupMode]);
|
|
535
|
-
// Fetch/refetch when lookup parameters change or client becomes ready.
|
|
536
|
-
// Skip refetch when we already have the property for this lookup (avoids setting loading true
|
|
537
|
-
// again when effect re-runs e.g. from Strict Mode or updateItemProperty identity change).
|
|
538
|
-
// Match by the active identifier only: when looking up by seedLocalId both must match;
|
|
539
|
-
// when looking up by seedUid both must match. Do not use (seedUid === undefined) as a match
|
|
540
|
-
// when seedLocalIds differ, which would incorrectly skip refetch after seedLocalId change.
|
|
541
|
-
useEffect(() => {
|
|
542
|
-
if (!shouldLoad) {
|
|
543
|
-
setProperty(undefined);
|
|
544
|
-
setIsLoading(false);
|
|
545
|
-
setError(null);
|
|
546
|
-
return;
|
|
547
|
-
}
|
|
548
|
-
const alreadyHavePropertyGuard = property &&
|
|
549
|
-
lookupMode &&
|
|
550
|
-
property.propertyName === lookupMode.propertyName &&
|
|
551
|
-
((lookupMode.seedLocalId != null && property.seedLocalId === lookupMode.seedLocalId) ||
|
|
552
|
-
(lookupMode.seedUid != null && property.seedUid === lookupMode.seedUid));
|
|
553
|
-
if (alreadyHavePropertyGuard)
|
|
554
|
-
return;
|
|
555
|
-
updateItemProperty();
|
|
556
|
-
}, [shouldLoad, updateItemProperty, property, lookupMode]);
|
|
557
|
-
// Subscribe to service changes when property is available
|
|
558
|
-
useEffect(() => {
|
|
559
|
-
if (!property) {
|
|
560
|
-
// Clean up subscription if property is not available
|
|
561
|
-
subscriptionRef.current?.unsubscribe();
|
|
562
|
-
subscriptionRef.current = undefined;
|
|
563
|
-
return;
|
|
564
|
-
}
|
|
565
|
-
// Clean up previous subscription
|
|
566
|
-
subscriptionRef.current?.unsubscribe();
|
|
567
|
-
// Subscribe to service changes. Only set isLoading to false when idle; never set to true
|
|
568
|
-
// here so we never overwrite the loaded state when the machine emits any non-idle state
|
|
569
|
-
// (e.g. loading, initializing, resolvingRelatedValue) after the initial fetch.
|
|
570
|
-
const subscription = property.getService().subscribe((snapshot) => {
|
|
571
|
-
if (snapshot && typeof snapshot === 'object' && 'value' in snapshot && snapshot.value === 'idle') {
|
|
572
|
-
setIsLoading(false);
|
|
573
|
-
setError(null);
|
|
574
|
-
}
|
|
575
|
-
// Force re-render by incrementing version counter
|
|
576
|
-
setVersion(prev => prev + 1);
|
|
577
|
-
});
|
|
578
|
-
subscriptionRef.current = subscription;
|
|
579
|
-
return () => {
|
|
580
|
-
subscriptionRef.current?.unsubscribe();
|
|
581
|
-
subscriptionRef.current = undefined;
|
|
582
|
-
};
|
|
583
|
-
}, [property]);
|
|
584
|
-
return {
|
|
585
|
-
property,
|
|
586
|
-
isLoading,
|
|
587
|
-
error,
|
|
588
|
-
};
|
|
589
|
-
}
|
|
590
|
-
/** Fetches item properties list for useQuery (shared with useItemProperties). */
|
|
591
|
-
async function fetchItemPropertiesList(seedLocalId, seedUid) {
|
|
592
|
-
if (!seedLocalId && !seedUid)
|
|
593
|
-
return [];
|
|
594
|
-
const db = BaseDb.getAppDb();
|
|
595
|
-
if (!db)
|
|
66
|
+
const getVersionsForSeedUid = async (seedUid) => {
|
|
67
|
+
if (!seedUid)
|
|
596
68
|
return [];
|
|
597
|
-
const
|
|
598
|
-
const
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
if (baseList.length > 0) {
|
|
606
|
-
const first = baseList[0];
|
|
607
|
-
modelName = first.modelName ?? first.modelType;
|
|
608
|
-
if (modelName && typeof modelName === 'string')
|
|
609
|
-
modelName = startCase(modelName);
|
|
610
|
-
}
|
|
611
|
-
if (!modelName) {
|
|
612
|
-
const seedRecords = await db
|
|
613
|
-
.select({ type: seeds.type })
|
|
614
|
-
.from(seeds)
|
|
615
|
-
.where(seedUid ? eq(seeds.uid, seedUid) : eq(seeds.localId, seedLocalId))
|
|
616
|
-
.limit(1);
|
|
617
|
-
if (seedRecords.length > 0 && seedRecords[0].type) {
|
|
618
|
-
modelName = startCase(seedRecords[0].type);
|
|
619
|
-
}
|
|
620
|
-
}
|
|
621
|
-
const modelProperties = [];
|
|
622
|
-
if (modelName) {
|
|
623
|
-
try {
|
|
624
|
-
const _mod_0 = await import('./index-Dh_gxItx.js');
|
|
625
|
-
const _ns_0 = _mod_0.a$;
|
|
626
|
-
const modelMod = _ns_0;
|
|
627
|
-
const { Model } = modelMod;
|
|
628
|
-
const model = await Model.getByNameAsync(modelName);
|
|
629
|
-
if (model?.properties) {
|
|
630
|
-
for (const modelProperty of model.properties) {
|
|
631
|
-
if (modelProperty.name)
|
|
632
|
-
modelProperties.push(modelProperty.name);
|
|
633
|
-
}
|
|
634
|
-
}
|
|
635
|
-
}
|
|
636
|
-
catch (error) {
|
|
637
|
-
propertiesLogger(`[useItemProperties] Error getting ModelProperties for ${modelName}:`, error);
|
|
638
|
-
}
|
|
639
|
-
}
|
|
640
|
-
if (modelName && modelProperties.length > 0) {
|
|
641
|
-
const resolvedSeedLocalId = baseList.length > 0 ? (baseList[0].seedLocalId ?? seedLocalId) : seedLocalId;
|
|
642
|
-
const resolvedSeedUid = baseList.length > 0 ? (baseList[0].seedUid ?? seedUid) : seedUid;
|
|
643
|
-
for (const propertyName of modelProperties) {
|
|
644
|
-
if (propertiesWithMetadata.has(propertyName))
|
|
645
|
-
continue;
|
|
646
|
-
try {
|
|
647
|
-
const itemProperty = ItemProperty.create({
|
|
648
|
-
propertyName,
|
|
649
|
-
modelName,
|
|
650
|
-
seedLocalId: resolvedSeedLocalId || undefined,
|
|
651
|
-
seedUid: resolvedSeedUid || undefined,
|
|
652
|
-
propertyValue: null,
|
|
653
|
-
}, { waitForReady: false });
|
|
654
|
-
if (itemProperty)
|
|
655
|
-
_itemProperties.push(itemProperty);
|
|
656
|
-
}
|
|
657
|
-
catch (error) {
|
|
658
|
-
logger$1(`[useItemProperties] Error creating ItemProperty for missing property ${propertyName}:`, error);
|
|
659
|
-
}
|
|
660
|
-
}
|
|
661
|
-
}
|
|
662
|
-
if (seedLocalId || seedUid) {
|
|
663
|
-
const seedRecords = await db
|
|
664
|
-
.select({ createdAt: seeds.createdAt })
|
|
665
|
-
.from(seeds)
|
|
666
|
-
.where(seedUid ? eq(seeds.uid, seedUid) : eq(seeds.localId, seedLocalId))
|
|
667
|
-
.limit(1);
|
|
668
|
-
if (seedRecords.length > 0 && seedRecords[0].createdAt) {
|
|
669
|
-
const createdAtPropertyName = 'createdAt';
|
|
670
|
-
const hasCreatedAtProperty = _itemProperties.some((p) => p.propertyName === createdAtPropertyName);
|
|
671
|
-
if (!hasCreatedAtProperty && modelName) {
|
|
672
|
-
try {
|
|
673
|
-
const resolvedSeedLocalId = baseList.length > 0 ? (baseList[0].seedLocalId ?? seedLocalId) : seedLocalId;
|
|
674
|
-
const resolvedSeedUid = baseList.length > 0 ? (baseList[0].seedUid ?? seedUid) : seedUid;
|
|
675
|
-
const createdAtProperty = ItemProperty.create({
|
|
676
|
-
propertyName: createdAtPropertyName,
|
|
677
|
-
modelName,
|
|
678
|
-
seedLocalId: resolvedSeedLocalId || undefined,
|
|
679
|
-
seedUid: resolvedSeedUid || undefined,
|
|
680
|
-
propertyValue: seedRecords[0].createdAt.toString(),
|
|
681
|
-
}, { waitForReady: false });
|
|
682
|
-
if (createdAtProperty)
|
|
683
|
-
_itemProperties.push(createdAtProperty);
|
|
684
|
-
}
|
|
685
|
-
catch (error) {
|
|
686
|
-
logger$1(`[useItemProperties] Error creating createdAt ItemProperty:`, error);
|
|
687
|
-
}
|
|
688
|
-
}
|
|
689
|
-
}
|
|
690
|
-
}
|
|
691
|
-
return _itemProperties;
|
|
692
|
-
}
|
|
693
|
-
function useItemProperties(arg1) {
|
|
694
|
-
const isClientReady = useIsClientReady();
|
|
695
|
-
const queryClient = useQueryClient();
|
|
696
|
-
const previousTableDataRef = useRef(undefined);
|
|
697
|
-
// Determine which lookup mode we're in based on arguments
|
|
698
|
-
const lookupMode = useMemo(() => {
|
|
699
|
-
if (typeof arg1 === 'string') {
|
|
700
|
-
// String argument: itemId (assumed to be seedLocalId)
|
|
701
|
-
return { type: 'itemId', itemId: arg1 };
|
|
702
|
-
}
|
|
703
|
-
else if (typeof arg1 === 'object') {
|
|
704
|
-
// Object argument: { seedLocalId/seedUid }
|
|
705
|
-
return {
|
|
706
|
-
type: 'identifiers',
|
|
707
|
-
seedLocalId: arg1.seedLocalId,
|
|
708
|
-
seedUid: arg1.seedUid,
|
|
709
|
-
};
|
|
710
|
-
}
|
|
711
|
-
else {
|
|
712
|
-
return null;
|
|
713
|
-
}
|
|
714
|
-
}, [arg1]);
|
|
715
|
-
// Determine seedLocalId and seedUid for query
|
|
716
|
-
const seedLocalId = useMemo(() => {
|
|
717
|
-
if (!lookupMode)
|
|
718
|
-
return undefined;
|
|
719
|
-
if (lookupMode.type === 'itemId') {
|
|
720
|
-
return lookupMode.itemId;
|
|
721
|
-
}
|
|
722
|
-
else {
|
|
723
|
-
return lookupMode.seedLocalId;
|
|
724
|
-
}
|
|
725
|
-
}, [lookupMode]);
|
|
726
|
-
const seedUid = useMemo(() => {
|
|
727
|
-
if (!lookupMode || lookupMode.type === 'itemId')
|
|
728
|
-
return undefined;
|
|
729
|
-
return lookupMode.seedUid;
|
|
730
|
-
}, [lookupMode]);
|
|
731
|
-
const canonicalItemKey = seedLocalId ?? seedUid ?? '';
|
|
732
|
-
const itemPropertiesQueryKey = useMemo(() => ['seed', 'itemProperties', canonicalItemKey], [canonicalItemKey]);
|
|
733
|
-
const { data: properties = [], isLoading, error: queryError, } = useQuery({
|
|
734
|
-
queryKey: itemPropertiesQueryKey,
|
|
735
|
-
queryFn: () => fetchItemPropertiesList(seedLocalId, seedUid),
|
|
736
|
-
enabled: isClientReady && !!canonicalItemKey,
|
|
737
|
-
});
|
|
738
|
-
// Watch the metadata table for changes
|
|
739
|
-
// Query metadata table directly and filter for latest records in JavaScript
|
|
740
|
-
// This is simpler and works better with useLiveQuery than CTEs
|
|
741
|
-
// Get db inside useMemo to avoid recreating query on each render
|
|
742
|
-
// Drizzle query builders are new objects each time, but useMemo will only recreate
|
|
743
|
-
// when dependencies change, which is what we want for reactive queries
|
|
744
|
-
const propertiesQuery = useMemo(() => {
|
|
745
|
-
if (!isClientReady || (!seedLocalId && !seedUid)) {
|
|
746
|
-
propertiesLogger('[useItemProperties] Query: returning null (not ready or no identifiers)');
|
|
747
|
-
return null;
|
|
748
|
-
}
|
|
749
|
-
const db = BaseDb.getAppDb();
|
|
750
|
-
if (!db) {
|
|
751
|
-
propertiesLogger('[useItemProperties] Query: returning null (no db)');
|
|
752
|
-
return null;
|
|
753
|
-
}
|
|
754
|
-
propertiesLogger(`[useItemProperties] Query: creating query for seedLocalId=${seedLocalId}, seedUid=${seedUid}`);
|
|
755
|
-
// Query metadata table directly - we'll filter for latest records in JavaScript
|
|
756
|
-
const query = seedUid
|
|
757
|
-
? db
|
|
758
|
-
.select({
|
|
759
|
-
propertyName: metadata.propertyName,
|
|
760
|
-
propertyValue: metadata.propertyValue,
|
|
761
|
-
seedLocalId: metadata.seedLocalId,
|
|
762
|
-
seedUid: metadata.seedUid,
|
|
763
|
-
modelType: metadata.modelType,
|
|
764
|
-
schemaUid: metadata.schemaUid,
|
|
765
|
-
createdAt: metadata.createdAt,
|
|
766
|
-
attestationCreatedAt: metadata.attestationCreatedAt,
|
|
767
|
-
})
|
|
768
|
-
.from(metadata)
|
|
769
|
-
.where(and(eq(metadata.seedUid, seedUid), isNotNull(metadata.propertyName)))
|
|
770
|
-
: seedLocalId
|
|
771
|
-
? db
|
|
772
|
-
.select({
|
|
773
|
-
propertyName: metadata.propertyName,
|
|
774
|
-
propertyValue: metadata.propertyValue,
|
|
775
|
-
seedLocalId: metadata.seedLocalId,
|
|
776
|
-
seedUid: metadata.seedUid,
|
|
777
|
-
modelType: metadata.modelType,
|
|
778
|
-
schemaUid: metadata.schemaUid,
|
|
779
|
-
createdAt: metadata.createdAt,
|
|
780
|
-
attestationCreatedAt: metadata.attestationCreatedAt,
|
|
781
|
-
})
|
|
782
|
-
.from(metadata)
|
|
783
|
-
.where(and(eq(metadata.seedLocalId, seedLocalId), isNotNull(metadata.propertyName)))
|
|
784
|
-
: null;
|
|
785
|
-
propertiesLogger(`[useItemProperties] Query: created query object`, { queryType: seedUid ? 'seedUid' : 'seedLocalId' });
|
|
786
|
-
return query;
|
|
787
|
-
}, [isClientReady, seedLocalId, seedUid]);
|
|
788
|
-
const rawPropertiesTableData = useLiveQuery(propertiesQuery);
|
|
789
|
-
// Filter for latest records (one per propertyName) in JavaScript
|
|
790
|
-
const propertiesTableData = useMemo(() => {
|
|
791
|
-
if (!rawPropertiesTableData || rawPropertiesTableData.length === 0) {
|
|
792
|
-
return [];
|
|
793
|
-
}
|
|
794
|
-
// Group by propertyName and keep only the latest record for each
|
|
795
|
-
const latestByProperty = new Map();
|
|
796
|
-
for (const record of rawPropertiesTableData) {
|
|
797
|
-
if (!record.propertyName)
|
|
798
|
-
continue;
|
|
799
|
-
const existing = latestByProperty.get(record.propertyName);
|
|
800
|
-
if (!existing) {
|
|
801
|
-
latestByProperty.set(record.propertyName, record);
|
|
802
|
-
}
|
|
803
|
-
else {
|
|
804
|
-
// Compare timestamps to find the latest
|
|
805
|
-
const existingTime = existing.attestationCreatedAt || existing.createdAt || 0;
|
|
806
|
-
const currentTime = record.attestationCreatedAt || record.createdAt || 0;
|
|
807
|
-
if (currentTime > existingTime) {
|
|
808
|
-
latestByProperty.set(record.propertyName, record);
|
|
809
|
-
}
|
|
810
|
-
}
|
|
811
|
-
}
|
|
812
|
-
return Array.from(latestByProperty.values());
|
|
813
|
-
}, [rawPropertiesTableData]);
|
|
814
|
-
// Invalidate when metadata table data actually changes so useQuery refetches
|
|
815
|
-
useEffect(() => {
|
|
816
|
-
if (!isClientReady || (!seedLocalId && !seedUid) || propertiesTableData === undefined)
|
|
817
|
-
return;
|
|
818
|
-
// Include propertyValue so value-only changes produce a different string and trigger invalidation
|
|
819
|
-
const tableDataString = JSON.stringify(propertiesTableData
|
|
820
|
-
.map((p) => ({
|
|
821
|
-
propertyName: p.propertyName,
|
|
822
|
-
propertyValue: p.propertyValue,
|
|
823
|
-
seedLocalId: p.seedLocalId,
|
|
824
|
-
seedUid: p.seedUid,
|
|
825
|
-
}))
|
|
826
|
-
.sort((a, b) => (a.propertyName || '').localeCompare(b.propertyName || '')));
|
|
827
|
-
if (previousTableDataRef.current === tableDataString)
|
|
828
|
-
return;
|
|
829
|
-
previousTableDataRef.current = tableDataString;
|
|
830
|
-
// Invalidate when metadata table data changed (new/updated/removed props or value changes)
|
|
831
|
-
// so useQuery refetches and UI shows latest values.
|
|
832
|
-
if (propertiesTableData.length > 0) {
|
|
833
|
-
queryClient.invalidateQueries({ queryKey: itemPropertiesQueryKey });
|
|
834
|
-
}
|
|
835
|
-
}, [isClientReady, propertiesTableData, properties, seedLocalId, seedUid, queryClient, itemPropertiesQueryKey]);
|
|
836
|
-
useEffect(() => {
|
|
837
|
-
previousTableDataRef.current = undefined;
|
|
838
|
-
}, [seedLocalId, seedUid]);
|
|
839
|
-
return {
|
|
840
|
-
properties,
|
|
841
|
-
isLoading,
|
|
842
|
-
error: queryError,
|
|
843
|
-
};
|
|
844
|
-
}
|
|
845
|
-
/**
|
|
846
|
-
* Hook to create an ItemProperty with loading and error state.
|
|
847
|
-
* create(props) creates a new property instance for an item; provide seedLocalId or seedUid, propertyName, and modelName.
|
|
848
|
-
*/
|
|
849
|
-
const useCreateItemProperty = () => {
|
|
850
|
-
const subscriptionRef = useRef(undefined);
|
|
851
|
-
const [isLoading, setIsLoading] = useState(false);
|
|
852
|
-
const [error, setError] = useState(null);
|
|
853
|
-
const resetError = useCallback(() => setError(null), []);
|
|
854
|
-
const create = useCallback((props) => {
|
|
855
|
-
if (!props.propertyName || (!props.seedLocalId && !props.seedUid) || !props.modelName) {
|
|
856
|
-
const err = new Error('seedLocalId or seedUid, propertyName, and modelName are required');
|
|
857
|
-
setError(err);
|
|
858
|
-
return undefined;
|
|
859
|
-
}
|
|
860
|
-
setError(null);
|
|
861
|
-
setIsLoading(true);
|
|
862
|
-
subscriptionRef.current?.unsubscribe();
|
|
863
|
-
subscriptionRef.current = undefined;
|
|
864
|
-
const instance = ItemProperty.create(props, { waitForReady: false });
|
|
865
|
-
if (!instance) {
|
|
866
|
-
setError(new Error('Failed to create item property'));
|
|
867
|
-
setIsLoading(false);
|
|
868
|
-
return undefined;
|
|
869
|
-
}
|
|
870
|
-
const subscription = instance.getService().subscribe((snapshot) => {
|
|
871
|
-
if (snapshot?.value === 'error') {
|
|
872
|
-
const err = snapshot.context?._loadingError?.error ?? new Error('Failed to create item property');
|
|
873
|
-
setError(err instanceof Error ? err : new Error(String(err)));
|
|
874
|
-
setIsLoading(false);
|
|
875
|
-
}
|
|
876
|
-
if (snapshot?.value === 'idle') {
|
|
877
|
-
setError(null);
|
|
878
|
-
setIsLoading(false);
|
|
879
|
-
}
|
|
880
|
-
});
|
|
881
|
-
subscriptionRef.current = subscription;
|
|
882
|
-
return instance;
|
|
883
|
-
}, []);
|
|
884
|
-
useEffect(() => {
|
|
885
|
-
return () => {
|
|
886
|
-
subscriptionRef.current?.unsubscribe();
|
|
887
|
-
subscriptionRef.current = undefined;
|
|
888
|
-
};
|
|
889
|
-
}, []);
|
|
890
|
-
return {
|
|
891
|
-
create,
|
|
892
|
-
isLoading,
|
|
893
|
-
error,
|
|
894
|
-
resetError,
|
|
895
|
-
};
|
|
896
|
-
};
|
|
897
|
-
const useDestroyItemProperty = () => {
|
|
898
|
-
const [currentInstance, setCurrentInstance] = useState(null);
|
|
899
|
-
const [destroyState, setDestroyState] = useState({
|
|
900
|
-
isLoading: false,
|
|
901
|
-
error: null,
|
|
902
|
-
});
|
|
903
|
-
useEffect(() => {
|
|
904
|
-
if (!currentInstance) {
|
|
905
|
-
setDestroyState({ isLoading: false, error: null });
|
|
906
|
-
return;
|
|
907
|
-
}
|
|
908
|
-
const service = currentInstance.getService();
|
|
909
|
-
const update = () => {
|
|
910
|
-
const snap = service.getSnapshot();
|
|
911
|
-
const ctx = snap.context;
|
|
912
|
-
setDestroyState({
|
|
913
|
-
isLoading: !!ctx._destroyInProgress,
|
|
914
|
-
error: ctx._destroyError ? new Error(ctx._destroyError.message) : null,
|
|
915
|
-
});
|
|
916
|
-
};
|
|
917
|
-
update();
|
|
918
|
-
const sub = service.subscribe(update);
|
|
919
|
-
return () => sub.unsubscribe();
|
|
920
|
-
}, [currentInstance]);
|
|
921
|
-
const destroy = useCallback(async (itemProperty) => {
|
|
922
|
-
if (!itemProperty)
|
|
923
|
-
return;
|
|
924
|
-
setCurrentInstance(itemProperty);
|
|
925
|
-
await itemProperty.destroy();
|
|
926
|
-
}, []);
|
|
927
|
-
const resetError = useCallback(() => {
|
|
928
|
-
if (currentInstance) {
|
|
929
|
-
currentInstance.getService().send({ type: 'clearDestroyError' });
|
|
930
|
-
}
|
|
931
|
-
}, [currentInstance]);
|
|
932
|
-
return {
|
|
933
|
-
destroy,
|
|
934
|
-
isLoading: destroyState.isLoading,
|
|
935
|
-
error: destroyState.error,
|
|
936
|
-
resetError,
|
|
937
|
-
};
|
|
938
|
-
};
|
|
939
|
-
|
|
940
|
-
debug('seedSdk:react:services');
|
|
941
|
-
|
|
942
|
-
debug('seedSdk:react:db');
|
|
943
|
-
|
|
944
|
-
const logger = debug('seedSdk:react:schema');
|
|
945
|
-
/**
|
|
946
|
-
* Hook to get a Schema class instance (with setters) that is reactive
|
|
947
|
-
* This allows you to edit schema properties directly like: schema.name = 'New name'
|
|
948
|
-
* The schema instance uses a Proxy to ensure React re-renders when properties change
|
|
949
|
-
* @param schemaIdentifier - The name of the schema or the schema file ID
|
|
950
|
-
* - If a name is provided, retrieves the latest version with that name
|
|
951
|
-
* - If an ID is provided, retrieves the specific schema by ID
|
|
952
|
-
* @returns Object with schema instance
|
|
953
|
-
*/
|
|
954
|
-
const useSchema = (schemaIdentifier) => {
|
|
955
|
-
const [schema, setSchema] = useState(null);
|
|
956
|
-
const [isLoading, setIsLoading] = useState(schemaIdentifier ? true : false);
|
|
957
|
-
const [error, setError] = useState(null);
|
|
958
|
-
const subscriptionRef = useRef(null);
|
|
959
|
-
const isClientReady = useIsClientReady();
|
|
960
|
-
const loadSchema = useCallback((identifier) => {
|
|
961
|
-
setIsLoading(true);
|
|
962
|
-
setError(null);
|
|
963
|
-
try {
|
|
964
|
-
const schemaInstance = Schema.create(identifier, {
|
|
965
|
-
waitForReady: false,
|
|
966
|
-
});
|
|
967
|
-
setSchema(schemaInstance);
|
|
968
|
-
const service = schemaInstance.getService();
|
|
969
|
-
const initialSnapshot = service.getSnapshot();
|
|
970
|
-
// Set initial loading state based on whether status is 'idle'
|
|
971
|
-
const isIdle = initialSnapshot.value === 'idle';
|
|
972
|
-
if (isIdle) {
|
|
973
|
-
flushSync(() => setIsLoading(false));
|
|
974
|
-
setError(null);
|
|
975
|
-
}
|
|
976
|
-
else {
|
|
977
|
-
setIsLoading(true);
|
|
978
|
-
}
|
|
979
|
-
// Subscribe to all status changes and update isLoading based on whether status is 'idle'
|
|
980
|
-
subscriptionRef.current = service.subscribe((snapshot) => {
|
|
981
|
-
const isIdle = snapshot.value === 'idle';
|
|
982
|
-
if (isIdle) {
|
|
983
|
-
flushSync(() => setIsLoading(false));
|
|
984
|
-
setError(null);
|
|
985
|
-
}
|
|
986
|
-
else {
|
|
987
|
-
setIsLoading(true);
|
|
988
|
-
}
|
|
989
|
-
});
|
|
990
|
-
}
|
|
991
|
-
catch (error) {
|
|
992
|
-
logger('[useSchema] Error creating schema:', error);
|
|
993
|
-
setError(error);
|
|
994
|
-
setSchema(null);
|
|
995
|
-
setIsLoading(false);
|
|
996
|
-
return null;
|
|
997
|
-
}
|
|
998
|
-
}, []);
|
|
999
|
-
useEffect(() => {
|
|
1000
|
-
// Clean up previous subscription before starting a new load
|
|
1001
|
-
if (subscriptionRef.current) {
|
|
1002
|
-
subscriptionRef.current.unsubscribe();
|
|
1003
|
-
subscriptionRef.current = null;
|
|
1004
|
-
}
|
|
1005
|
-
if (!isClientReady) {
|
|
1006
|
-
setSchema(null);
|
|
1007
|
-
setError(null);
|
|
1008
|
-
setIsLoading(false);
|
|
1009
|
-
return;
|
|
1010
|
-
}
|
|
1011
|
-
if (!schemaIdentifier) {
|
|
1012
|
-
setSchema(null);
|
|
1013
|
-
setError(null);
|
|
1014
|
-
setIsLoading(false);
|
|
1015
|
-
return;
|
|
1016
|
-
}
|
|
1017
|
-
loadSchema(schemaIdentifier);
|
|
1018
|
-
// Cleanup function to unsubscribe when effect re-runs or component unmounts
|
|
1019
|
-
return () => {
|
|
1020
|
-
if (subscriptionRef.current) {
|
|
1021
|
-
subscriptionRef.current.unsubscribe();
|
|
1022
|
-
subscriptionRef.current = null;
|
|
1023
|
-
}
|
|
1024
|
-
};
|
|
1025
|
-
}, [schemaIdentifier, isClientReady, loadSchema]);
|
|
1026
|
-
return {
|
|
1027
|
-
schema,
|
|
1028
|
-
isLoading,
|
|
1029
|
-
error,
|
|
1030
|
-
};
|
|
1031
|
-
};
|
|
1032
|
-
const SEED_SCHEMAS_QUERY_KEY = ['seed', 'schemas'];
|
|
1033
|
-
const useSchemas = () => {
|
|
1034
|
-
const isClientReady = useIsClientReady();
|
|
1035
|
-
const queryClient = useQueryClient();
|
|
1036
|
-
const previousSchemasTableDataRef = useRef(undefined);
|
|
1037
|
-
const schemasRef = useRef([]);
|
|
1038
|
-
const { data: schemas$1 = [], isLoading, error: queryError, } = useQuery({
|
|
1039
|
-
queryKey: SEED_SCHEMAS_QUERY_KEY,
|
|
1040
|
-
queryFn: () => Schema.all({ waitForReady: true }),
|
|
1041
|
-
enabled: isClientReady,
|
|
1042
|
-
});
|
|
1043
|
-
schemasRef.current = schemas$1;
|
|
1044
|
-
// Watch the schemas table for changes and invalidate so useQuery refetches
|
|
1045
|
-
const db = isClientReady ? BaseDb.getAppDb() : null;
|
|
1046
|
-
const schemasQuery = useMemo(() => {
|
|
1047
|
-
if (!db)
|
|
1048
|
-
return null;
|
|
1049
|
-
return db.select().from(schemas).orderBy(schemas.name, desc(schemas.version));
|
|
1050
|
-
}, [db, isClientReady]);
|
|
1051
|
-
const schemasTableData = useLiveQuery(schemasQuery);
|
|
1052
|
-
// When a schema is created, addSchemaToDb posts to this channel; live query often doesn't re-run when schemas table is inserted.
|
|
1053
|
-
useEffect(() => {
|
|
1054
|
-
if (typeof BroadcastChannel === 'undefined')
|
|
1055
|
-
return;
|
|
1056
|
-
const ch = new BroadcastChannel('seed-schemas-invalidate');
|
|
1057
|
-
const onMessage = () => {
|
|
1058
|
-
queryClient.invalidateQueries({ queryKey: SEED_SCHEMAS_QUERY_KEY });
|
|
1059
|
-
};
|
|
1060
|
-
ch.addEventListener('message', onMessage);
|
|
1061
|
-
return () => {
|
|
1062
|
-
ch.removeEventListener('message', onMessage);
|
|
1063
|
-
ch.close();
|
|
1064
|
-
};
|
|
1065
|
-
}, [queryClient]);
|
|
1066
|
-
useEffect(() => {
|
|
1067
|
-
if (!isClientReady || !schemasTableData) {
|
|
1068
|
-
return;
|
|
1069
|
-
}
|
|
1070
|
-
const prevData = previousSchemasTableDataRef.current;
|
|
1071
|
-
const prevDataJson = prevData ? JSON.stringify(prevData) : 'undefined';
|
|
1072
|
-
const currDataJson = schemasTableData ? JSON.stringify(schemasTableData) : 'undefined';
|
|
1073
|
-
if (prevDataJson === currDataJson && prevData !== undefined) {
|
|
1074
|
-
return;
|
|
1075
|
-
}
|
|
1076
|
-
previousSchemasTableDataRef.current = schemasTableData;
|
|
1077
|
-
const currentSchemasSet = new Set();
|
|
1078
|
-
for (const schema of schemasRef.current) {
|
|
1079
|
-
const schemaFileId = schema.id || schema.schemaFileId;
|
|
1080
|
-
if (schemaFileId) {
|
|
1081
|
-
currentSchemasSet.add(schemaFileId);
|
|
1082
|
-
}
|
|
1083
|
-
else {
|
|
1084
|
-
const name = schema.metadata?.name;
|
|
1085
|
-
const version = schema.version;
|
|
1086
|
-
if (name && version !== undefined) {
|
|
1087
|
-
currentSchemasSet.add(`${name}:${version}`);
|
|
1088
|
-
}
|
|
1089
|
-
}
|
|
1090
|
-
}
|
|
1091
|
-
const tableDataSchemasSet = new Set();
|
|
1092
|
-
for (const dbSchema of schemasTableData) {
|
|
1093
|
-
if (dbSchema.name === 'Seed Protocol')
|
|
1094
|
-
continue;
|
|
1095
|
-
if (dbSchema.schemaFileId) {
|
|
1096
|
-
tableDataSchemasSet.add(dbSchema.schemaFileId);
|
|
1097
|
-
}
|
|
1098
|
-
else if (dbSchema.name != null && dbSchema.version !== undefined) {
|
|
1099
|
-
tableDataSchemasSet.add(`${dbSchema.name}:${dbSchema.version}`);
|
|
1100
|
-
}
|
|
1101
|
-
}
|
|
1102
|
-
const setsAreEqual = currentSchemasSet.size === tableDataSchemasSet.size &&
|
|
1103
|
-
[...currentSchemasSet].every((id) => tableDataSchemasSet.has(id));
|
|
1104
|
-
// Only invalidate when we have data and the table has rows we might be missing (live query saw new data).
|
|
1105
|
-
// Skip during initial load (currentSchemasSet empty) to avoid disrupting loading state.
|
|
1106
|
-
// Do NOT invalidate when we have more than the table: the live query may not have updated
|
|
1107
|
-
// yet, and refetching could overwrite cache with stale/empty data.
|
|
1108
|
-
const tableHasNewRows = currentSchemasSet.size > 0 &&
|
|
1109
|
-
tableDataSchemasSet.size > 0 &&
|
|
1110
|
-
[...tableDataSchemasSet].some((id) => !currentSchemasSet.has(id));
|
|
1111
|
-
if (!setsAreEqual && tableHasNewRows) {
|
|
1112
|
-
queryClient.invalidateQueries({ queryKey: SEED_SCHEMAS_QUERY_KEY });
|
|
1113
|
-
}
|
|
1114
|
-
}, [isClientReady, schemasTableData, queryClient]);
|
|
1115
|
-
return {
|
|
1116
|
-
schemas: schemas$1,
|
|
1117
|
-
isLoading,
|
|
1118
|
-
error: queryError,
|
|
1119
|
-
};
|
|
1120
|
-
};
|
|
1121
|
-
const useCreateSchema = () => {
|
|
1122
|
-
const subscriptionRef = useRef(null);
|
|
1123
|
-
const [isLoading, setIsLoading] = useState(false);
|
|
1124
|
-
const [error, setError] = useState(null);
|
|
1125
|
-
const resetError = useCallback(() => setError(null), []);
|
|
1126
|
-
const createSchema = useCallback((schemaName) => {
|
|
1127
|
-
setError(null);
|
|
1128
|
-
setIsLoading(true);
|
|
1129
|
-
subscriptionRef.current?.unsubscribe();
|
|
1130
|
-
subscriptionRef.current = null;
|
|
1131
|
-
const schema = Schema.create(schemaName, {
|
|
1132
|
-
waitForReady: false,
|
|
1133
|
-
});
|
|
1134
|
-
const subscription = schema.getService().subscribe((snapshot) => {
|
|
1135
|
-
if (snapshot.value === 'error') {
|
|
1136
|
-
const err = snapshot.context._loadingError?.error;
|
|
1137
|
-
setError(err instanceof Error ? err : new Error('Failed to create schema'));
|
|
1138
|
-
setIsLoading(false);
|
|
1139
|
-
}
|
|
1140
|
-
if (snapshot.value === 'idle') {
|
|
1141
|
-
setError(null);
|
|
1142
|
-
setIsLoading(false);
|
|
1143
|
-
}
|
|
1144
|
-
});
|
|
1145
|
-
subscriptionRef.current = subscription;
|
|
1146
|
-
return schema;
|
|
1147
|
-
}, []);
|
|
1148
|
-
useEffect(() => {
|
|
1149
|
-
return () => {
|
|
1150
|
-
subscriptionRef.current?.unsubscribe();
|
|
1151
|
-
subscriptionRef.current = null;
|
|
1152
|
-
};
|
|
1153
|
-
}, []);
|
|
1154
|
-
return {
|
|
1155
|
-
createSchema,
|
|
1156
|
-
isLoading,
|
|
1157
|
-
error,
|
|
1158
|
-
resetError,
|
|
1159
|
-
};
|
|
1160
|
-
};
|
|
1161
|
-
const useDestroySchema = () => {
|
|
1162
|
-
const [currentInstance, setCurrentInstance] = useState(null);
|
|
1163
|
-
const [destroyState, setDestroyState] = useState({
|
|
1164
|
-
isLoading: false,
|
|
1165
|
-
error: null,
|
|
1166
|
-
});
|
|
1167
|
-
useEffect(() => {
|
|
1168
|
-
if (!currentInstance) {
|
|
1169
|
-
setDestroyState({ isLoading: false, error: null });
|
|
1170
|
-
return;
|
|
1171
|
-
}
|
|
1172
|
-
const service = currentInstance.getService();
|
|
1173
|
-
const update = () => {
|
|
1174
|
-
const snap = service.getSnapshot();
|
|
1175
|
-
const ctx = snap.context;
|
|
1176
|
-
setDestroyState({
|
|
1177
|
-
isLoading: !!ctx._destroyInProgress,
|
|
1178
|
-
error: ctx._destroyError ? new Error(ctx._destroyError.message) : null,
|
|
1179
|
-
});
|
|
1180
|
-
};
|
|
1181
|
-
update();
|
|
1182
|
-
const sub = service.subscribe(update);
|
|
1183
|
-
return () => sub.unsubscribe();
|
|
1184
|
-
}, [currentInstance]);
|
|
1185
|
-
const destroy = useCallback(async (schema) => {
|
|
1186
|
-
if (!schema)
|
|
1187
|
-
return;
|
|
1188
|
-
setCurrentInstance(schema);
|
|
1189
|
-
await schema.destroy();
|
|
1190
|
-
}, []);
|
|
1191
|
-
const resetError = useCallback(() => {
|
|
1192
|
-
if (currentInstance) {
|
|
1193
|
-
currentInstance.getService().send({ type: 'clearDestroyError' });
|
|
1194
|
-
}
|
|
1195
|
-
}, [currentInstance]);
|
|
1196
|
-
return {
|
|
1197
|
-
destroy,
|
|
1198
|
-
isLoading: destroyState.isLoading,
|
|
1199
|
-
error: destroyState.error,
|
|
1200
|
-
resetError,
|
|
1201
|
-
};
|
|
1202
|
-
};
|
|
1203
|
-
const useAllSchemaVersions = () => {
|
|
1204
|
-
const [schemaInstances, setSchemaInstances] = useState();
|
|
1205
|
-
const schemaInstancesRef = useRef(new Map());
|
|
1206
|
-
const isClientReady = useIsClientReady();
|
|
1207
|
-
const fetchSchemas = useCallback(async () => {
|
|
1208
|
-
if (!isClientReady) {
|
|
1209
|
-
return;
|
|
1210
|
-
}
|
|
1211
|
-
try {
|
|
1212
|
-
// Use DB-first approach: load all schemas from database
|
|
1213
|
-
// This will also import any missing schemas from files
|
|
1214
|
-
const allSchemasData = await loadAllSchemasFromDb();
|
|
1215
|
-
// Extract unique schema names
|
|
1216
|
-
const schemaNames = new Set();
|
|
1217
|
-
for (const schemaData of allSchemasData) {
|
|
1218
|
-
const schemaName = schemaData.schema.metadata?.name;
|
|
1219
|
-
if (schemaName) {
|
|
1220
|
-
schemaNames.add(schemaName);
|
|
1221
|
-
}
|
|
1222
|
-
}
|
|
1223
|
-
// Create/update Schema instances
|
|
1224
|
-
const currentInstances = new Map();
|
|
1225
|
-
for (const schemaName of schemaNames) {
|
|
1226
|
-
// Reuse existing instance if it exists
|
|
1227
|
-
if (schemaInstancesRef.current.has(schemaName)) {
|
|
1228
|
-
const existingInstance = schemaInstancesRef.current.get(schemaName);
|
|
1229
|
-
currentInstances.set(schemaName, existingInstance);
|
|
1230
|
-
}
|
|
1231
|
-
else {
|
|
1232
|
-
// Create new instance
|
|
1233
|
-
const schema = Schema.create(schemaName, {
|
|
1234
|
-
waitForReady: false,
|
|
1235
|
-
});
|
|
1236
|
-
currentInstances.set(schemaName, schema);
|
|
1237
|
-
}
|
|
1238
|
-
}
|
|
1239
|
-
// Cleanup instances that are no longer needed
|
|
1240
|
-
for (const [name, instance] of schemaInstancesRef.current.entries()) {
|
|
1241
|
-
if (!schemaNames.has(name)) {
|
|
1242
|
-
instance.unload();
|
|
1243
|
-
}
|
|
1244
|
-
}
|
|
1245
|
-
// Update ref and state
|
|
1246
|
-
schemaInstancesRef.current = currentInstances;
|
|
1247
|
-
setSchemaInstances(Array.from(currentInstances.values()));
|
|
1248
|
-
}
|
|
1249
|
-
catch (error) {
|
|
1250
|
-
logger('Error fetching all schema versions from database:', error);
|
|
1251
|
-
setSchemaInstances(null);
|
|
1252
|
-
}
|
|
1253
|
-
}, [isClientReady]);
|
|
1254
|
-
useEffect(() => {
|
|
1255
|
-
if (!isClientReady) {
|
|
1256
|
-
return;
|
|
1257
|
-
}
|
|
1258
|
-
fetchSchemas();
|
|
1259
|
-
}, [isClientReady, fetchSchemas]);
|
|
1260
|
-
// Cleanup on unmount
|
|
1261
|
-
useEffect(() => {
|
|
1262
|
-
return () => {
|
|
1263
|
-
schemaInstancesRef.current.forEach((instance) => {
|
|
1264
|
-
instance.unload();
|
|
1265
|
-
});
|
|
1266
|
-
schemaInstancesRef.current.clear();
|
|
1267
|
-
};
|
|
1268
|
-
}, []);
|
|
1269
|
-
return schemaInstances;
|
|
69
|
+
const appDb = BaseDb.getAppDb();
|
|
70
|
+
const rows = (await appDb
|
|
71
|
+
.select({ uid: versions.uid, seedUid: versions.seedUid })
|
|
72
|
+
.from(versions)
|
|
73
|
+
.where(eq(versions.seedUid, seedUid)));
|
|
74
|
+
return rows
|
|
75
|
+
.filter((r) => r.uid && r.uid !== '0x' + '0'.repeat(64))
|
|
76
|
+
.map((r) => ({ uid: r.uid }));
|
|
1270
77
|
};
|
|
1271
78
|
|
|
1272
79
|
/**
|
|
1273
|
-
*
|
|
1274
|
-
*
|
|
1275
|
-
* updates the returned Model instances when changes occur.
|
|
1276
|
-
* @param schemaId - The schema ID (schema file ID) or schema name to get models from
|
|
1277
|
-
* @returns Array of Model instances belonging to the schema
|
|
80
|
+
* Returns attestation UIDs (metadata.uid) for all metadata records belonging to a seed.
|
|
81
|
+
* Used when revoking attestations - metadata attestations must be revoked.
|
|
1278
82
|
*/
|
|
1279
|
-
const
|
|
1280
|
-
|
|
1281
|
-
|
|
1282
|
-
const
|
|
1283
|
-
const
|
|
1284
|
-
|
|
1285
|
-
|
|
1286
|
-
|
|
1287
|
-
|
|
1288
|
-
|
|
1289
|
-
|
|
1290
|
-
// Capture previous data before any async work so we don't overwrite good cache with [].
|
|
1291
|
-
const prev = queryClient.getQueryData(queryKey);
|
|
1292
|
-
// Use waitForReady: false so we return models as soon as they exist; waitForReady: true
|
|
1293
|
-
// filters to only idle models and can return [] while a model is in creatingProperties.
|
|
1294
|
-
const next = await Model.all(schemaId, { waitForReady: false });
|
|
1295
|
-
// getModelsData can intermittently return [] after returning data; keep prev to avoid overwrite.
|
|
1296
|
-
if (Array.isArray(prev) && prev.length > 0 && Array.isArray(next) && next.length === 0) {
|
|
1297
|
-
return [...prev];
|
|
1298
|
-
}
|
|
1299
|
-
// If this refetch returned [], avoid overwriting non-empty cache (e.g. race where another refetch already wrote data).
|
|
1300
|
-
if (Array.isArray(next) && next.length === 0) {
|
|
1301
|
-
const current = queryClient.getQueryData(queryKey);
|
|
1302
|
-
if (Array.isArray(current) && current.length > 0) {
|
|
1303
|
-
return [...current];
|
|
1304
|
-
}
|
|
1305
|
-
}
|
|
1306
|
-
return next;
|
|
1307
|
-
},
|
|
1308
|
-
enabled: isClientReady && !!schemaId,
|
|
1309
|
-
});
|
|
1310
|
-
// Never expose [] when we previously had models (avoids flash from refetch races, remounts, or intermittent getModelsData returning []).
|
|
1311
|
-
// When schemaId is null/undefined, always show [] — do not use fallback from a previous schema.
|
|
1312
|
-
const schemaIdKey = schemaId && typeof schemaId === 'string' ? schemaId : '';
|
|
1313
|
-
if (models$1.length > 0) {
|
|
1314
|
-
lastModelsBySchemaId.set(schemaIdKey, models$1);
|
|
1315
|
-
}
|
|
1316
|
-
const fallback = modelsRef.current.length > 0 ? modelsRef.current : lastModelsBySchemaId.get(schemaIdKey);
|
|
1317
|
-
const displayModels = !schemaId
|
|
1318
|
-
? models$1
|
|
1319
|
-
: models$1.length > 0
|
|
1320
|
-
? models$1
|
|
1321
|
-
: fallback?.length
|
|
1322
|
-
? fallback
|
|
1323
|
-
: models$1;
|
|
1324
|
-
modelsRef.current = displayModels;
|
|
1325
|
-
// When a model is created, writeModelToDb posts to this channel; live query over join often doesn't re-run
|
|
1326
|
-
useEffect(() => {
|
|
1327
|
-
if (!schemaId || typeof BroadcastChannel === 'undefined')
|
|
1328
|
-
return;
|
|
1329
|
-
const ch = new BroadcastChannel('seed-models-invalidate');
|
|
1330
|
-
const onMessage = (event) => {
|
|
1331
|
-
const { schemaName, schemaFileId } = event.data || {};
|
|
1332
|
-
if (schemaId === schemaName || schemaId === schemaFileId) {
|
|
1333
|
-
queryClient.invalidateQueries({ queryKey });
|
|
1334
|
-
queryClient.refetchQueries({ queryKey });
|
|
1335
|
-
}
|
|
1336
|
-
};
|
|
1337
|
-
ch.addEventListener('message', onMessage);
|
|
1338
|
-
return () => {
|
|
1339
|
-
ch.removeEventListener('message', onMessage);
|
|
1340
|
-
ch.close();
|
|
1341
|
-
};
|
|
1342
|
-
}, [schemaId, queryClient, queryKey]);
|
|
1343
|
-
// Stabilize query reference: only recreate when (schemaId, isClientReady) change, not when db reference changes.
|
|
1344
|
-
// This keeps the same liveQuery observable/subscription alive so effects can deliver updates when a new model is added.
|
|
1345
|
-
const stableModelsQueryKeyRef = useRef(null);
|
|
1346
|
-
const stableModelsQueryRef = useRef(null);
|
|
1347
|
-
function buildModelsQuery() {
|
|
1348
|
-
const currentDb = BaseDb.getAppDb();
|
|
1349
|
-
if (!currentDb || !schemaId)
|
|
1350
|
-
return null;
|
|
1351
|
-
return currentDb
|
|
1352
|
-
.select({
|
|
1353
|
-
modelFileId: models.schemaFileId,
|
|
1354
|
-
modelName: models.name,
|
|
1355
|
-
})
|
|
1356
|
-
.from(schemas)
|
|
1357
|
-
.innerJoin(modelSchemas, eq(schemas.id, modelSchemas.schemaId))
|
|
1358
|
-
.innerJoin(models, eq(modelSchemas.modelId, models.id))
|
|
1359
|
-
.where(or(eq(schemas.schemaFileId, schemaId), eq(schemas.name, schemaId)));
|
|
1360
|
-
}
|
|
1361
|
-
const modelsQuery = useMemo(() => {
|
|
1362
|
-
if (!schemaId || !isClientReady)
|
|
1363
|
-
return null;
|
|
1364
|
-
const key = { schemaId, ready: isClientReady };
|
|
1365
|
-
const prevKey = stableModelsQueryKeyRef.current;
|
|
1366
|
-
if (prevKey &&
|
|
1367
|
-
prevKey.schemaId === key.schemaId &&
|
|
1368
|
-
prevKey.ready === key.ready &&
|
|
1369
|
-
stableModelsQueryRef.current !== null) {
|
|
1370
|
-
return stableModelsQueryRef.current;
|
|
1371
|
-
}
|
|
1372
|
-
const q = buildModelsQuery();
|
|
1373
|
-
if (!q)
|
|
1374
|
-
return null;
|
|
1375
|
-
stableModelsQueryKeyRef.current = key;
|
|
1376
|
-
stableModelsQueryRef.current = q;
|
|
1377
|
-
return q;
|
|
1378
|
-
}, [schemaId, isClientReady]);
|
|
1379
|
-
const modelsTableData = useLiveQuery(modelsQuery);
|
|
1380
|
-
useEffect(() => {
|
|
1381
|
-
if (!isClientReady || !modelsTableData || !schemaId)
|
|
1382
|
-
return;
|
|
1383
|
-
const currentModelsSet = new Set();
|
|
1384
|
-
for (const model of modelsRef.current) {
|
|
1385
|
-
const modelFileId = model.id || model.modelFileId;
|
|
1386
|
-
if (modelFileId)
|
|
1387
|
-
currentModelsSet.add(modelFileId);
|
|
1388
|
-
else if (model.modelName)
|
|
1389
|
-
currentModelsSet.add(model.modelName);
|
|
1390
|
-
}
|
|
1391
|
-
const tableDataModelsSet = new Set();
|
|
1392
|
-
for (const dbModel of modelsTableData) {
|
|
1393
|
-
if (dbModel.modelFileId)
|
|
1394
|
-
tableDataModelsSet.add(dbModel.modelFileId);
|
|
1395
|
-
else if (dbModel.modelName)
|
|
1396
|
-
tableDataModelsSet.add(dbModel.modelName);
|
|
1397
|
-
}
|
|
1398
|
-
const setsAreEqual = currentModelsSet.size === tableDataModelsSet.size &&
|
|
1399
|
-
[...currentModelsSet].every((id) => tableDataModelsSet.has(id));
|
|
1400
|
-
// Only invalidate when the table has rows we might be missing (live query saw new data).
|
|
1401
|
-
// Do NOT invalidate when we have more than the table: the live query may not have updated
|
|
1402
|
-
// yet (e.g. join over model_schemas), and refetching would overwrite cache with [].
|
|
1403
|
-
const tableHasNewRows = tableDataModelsSet.size > 0 &&
|
|
1404
|
-
[...tableDataModelsSet].some((id) => !currentModelsSet.has(id));
|
|
1405
|
-
if (!setsAreEqual && tableHasNewRows) {
|
|
1406
|
-
queryClient.invalidateQueries({ queryKey });
|
|
1407
|
-
}
|
|
1408
|
-
}, [isClientReady, modelsTableData, schemaId, queryClient, queryKey]);
|
|
1409
|
-
return {
|
|
1410
|
-
models: displayModels,
|
|
1411
|
-
isLoading,
|
|
1412
|
-
error: queryError,
|
|
1413
|
-
};
|
|
1414
|
-
};
|
|
1415
|
-
/**
|
|
1416
|
-
* Hook to get a specific Model instance
|
|
1417
|
-
* Can be called in two ways:
|
|
1418
|
-
* 1. With schemaId and modelName: useModel(schemaId, modelName)
|
|
1419
|
-
* 2. With modelId: useModel(modelId)
|
|
1420
|
-
*
|
|
1421
|
-
* @param schemaIdOrModelId - The schema ID (schema file ID) OR the model ID (modelFileId)
|
|
1422
|
-
* @param modelName - The name of the model to retrieve (required if first param is schemaId)
|
|
1423
|
-
* @returns Object with model, isLoading, and error
|
|
1424
|
-
*/
|
|
1425
|
-
const useModel = (schemaIdOrModelId, modelName) => {
|
|
1426
|
-
const isClientReady = useIsClientReady();
|
|
1427
|
-
const [model, setModel] = useState(undefined);
|
|
1428
|
-
const [isLoading, setIsLoading] = useState(false);
|
|
1429
|
-
const [error, setError] = useState(null);
|
|
1430
|
-
const subscriptionRef = useRef(undefined);
|
|
1431
|
-
const [, setVersion] = useState(0); // Version counter to force re-renders
|
|
1432
|
-
// If modelName is provided, treat first param as schemaId
|
|
1433
|
-
// Otherwise, treat first param as modelId
|
|
1434
|
-
const isModelIdLookup = modelName === undefined || modelName === null;
|
|
1435
|
-
// Determine initial loading state
|
|
1436
|
-
useMemo(() => {
|
|
1437
|
-
if (!isClientReady)
|
|
1438
|
-
return false;
|
|
1439
|
-
if (isModelIdLookup) {
|
|
1440
|
-
return !!schemaIdOrModelId;
|
|
1441
|
-
}
|
|
1442
|
-
else {
|
|
1443
|
-
return !!(schemaIdOrModelId && modelName);
|
|
1444
|
-
}
|
|
1445
|
-
}, [isClientReady, isModelIdLookup, schemaIdOrModelId, modelName]);
|
|
1446
|
-
// Lookup model by ID if needed
|
|
1447
|
-
useEffect(() => {
|
|
1448
|
-
if (!isClientReady || !isModelIdLookup || !schemaIdOrModelId) {
|
|
1449
|
-
setModel(undefined);
|
|
1450
|
-
setIsLoading(false);
|
|
1451
|
-
setError(null);
|
|
1452
|
-
return;
|
|
1453
|
-
}
|
|
1454
|
-
const lookupModelById = async () => {
|
|
1455
|
-
try {
|
|
1456
|
-
setIsLoading(true);
|
|
1457
|
-
setError(null);
|
|
1458
|
-
// Use Model.createById which handles cache + DB lookup
|
|
1459
|
-
const foundModel = await Model.createById(schemaIdOrModelId);
|
|
1460
|
-
setModel(foundModel || undefined);
|
|
1461
|
-
setIsLoading(false);
|
|
1462
|
-
setError(null);
|
|
1463
|
-
}
|
|
1464
|
-
catch (error) {
|
|
1465
|
-
console.error('[useModel] Error looking up model by ID:', error);
|
|
1466
|
-
setModel(undefined);
|
|
1467
|
-
setIsLoading(false);
|
|
1468
|
-
setError(error);
|
|
1469
|
-
}
|
|
1470
|
-
};
|
|
1471
|
-
lookupModelById();
|
|
1472
|
-
}, [isClientReady, isModelIdLookup, schemaIdOrModelId]);
|
|
1473
|
-
// Subscribe to service changes when model is available (for modelId lookup)
|
|
1474
|
-
useEffect(() => {
|
|
1475
|
-
if (!isModelIdLookup || !model) {
|
|
1476
|
-
// Clean up subscription if model is not available
|
|
1477
|
-
subscriptionRef.current?.unsubscribe();
|
|
1478
|
-
subscriptionRef.current = undefined;
|
|
1479
|
-
return;
|
|
1480
|
-
}
|
|
1481
|
-
// Clean up previous subscription
|
|
1482
|
-
subscriptionRef.current?.unsubscribe();
|
|
1483
|
-
// Subscribe to service changes
|
|
1484
|
-
const subscription = model.getService().subscribe((snapshot) => {
|
|
1485
|
-
// Force re-render by incrementing version counter
|
|
1486
|
-
setVersion(prev => prev + 1);
|
|
1487
|
-
});
|
|
1488
|
-
subscriptionRef.current = subscription;
|
|
1489
|
-
return () => {
|
|
1490
|
-
subscriptionRef.current?.unsubscribe();
|
|
1491
|
-
subscriptionRef.current = undefined;
|
|
1492
|
-
};
|
|
1493
|
-
}, [isModelIdLookup, model]);
|
|
1494
|
-
// If doing modelId lookup, return the model directly
|
|
1495
|
-
if (isModelIdLookup) {
|
|
1496
|
-
return {
|
|
1497
|
-
model,
|
|
1498
|
-
isLoading,
|
|
1499
|
-
error,
|
|
1500
|
-
};
|
|
1501
|
-
}
|
|
1502
|
-
// Otherwise, use schemaId + modelName lookup via useModels
|
|
1503
|
-
const { models: modelsList, isLoading: modelsLoading, error: modelsError } = useModels(schemaIdOrModelId);
|
|
1504
|
-
const foundModel = useMemo(() => {
|
|
1505
|
-
if (!modelName) {
|
|
1506
|
-
return undefined;
|
|
1507
|
-
}
|
|
1508
|
-
// Try both modelName property and name getter for compatibility
|
|
1509
|
-
return modelsList.find((m) => {
|
|
1510
|
-
const mName = m.modelName ?? m.name;
|
|
1511
|
-
return mName === modelName;
|
|
1512
|
-
});
|
|
1513
|
-
}, [modelsList, modelName]);
|
|
1514
|
-
// Subscribe to service changes when model is available (for schemaId + modelName lookup)
|
|
1515
|
-
useEffect(() => {
|
|
1516
|
-
if (isModelIdLookup || !foundModel) {
|
|
1517
|
-
// Clean up subscription if model is not available
|
|
1518
|
-
subscriptionRef.current?.unsubscribe();
|
|
1519
|
-
subscriptionRef.current = undefined;
|
|
1520
|
-
return;
|
|
1521
|
-
}
|
|
1522
|
-
// Clean up previous subscription
|
|
1523
|
-
subscriptionRef.current?.unsubscribe();
|
|
1524
|
-
// Subscribe to service changes
|
|
1525
|
-
const subscription = foundModel.getService().subscribe((snapshot) => {
|
|
1526
|
-
// Force re-render by incrementing version counter
|
|
1527
|
-
setVersion(prev => prev + 1);
|
|
1528
|
-
});
|
|
1529
|
-
subscriptionRef.current = subscription;
|
|
1530
|
-
return () => {
|
|
1531
|
-
subscriptionRef.current?.unsubscribe();
|
|
1532
|
-
subscriptionRef.current = undefined;
|
|
1533
|
-
};
|
|
1534
|
-
}, [isModelIdLookup, foundModel]);
|
|
1535
|
-
// For schemaId + modelName lookup, derive loading/error from useModels
|
|
1536
|
-
return {
|
|
1537
|
-
model: foundModel,
|
|
1538
|
-
isLoading: modelsLoading,
|
|
1539
|
-
error: modelsError,
|
|
1540
|
-
};
|
|
1541
|
-
};
|
|
1542
|
-
const useCreateModel = () => {
|
|
1543
|
-
const subscriptionRef = useRef(undefined);
|
|
1544
|
-
const [isLoading, setIsLoading] = useState(false);
|
|
1545
|
-
const [error, setError] = useState(null);
|
|
1546
|
-
const resetError = useCallback(() => setError(null), []);
|
|
1547
|
-
const create = useCallback((schemaName, modelName, options) => {
|
|
1548
|
-
setError(null);
|
|
1549
|
-
setIsLoading(true);
|
|
1550
|
-
subscriptionRef.current?.unsubscribe();
|
|
1551
|
-
subscriptionRef.current = undefined;
|
|
1552
|
-
const model = Model.create(modelName, schemaName, {
|
|
1553
|
-
...options,
|
|
1554
|
-
waitForReady: false,
|
|
1555
|
-
});
|
|
1556
|
-
const subscription = model.getService().subscribe((snapshot) => {
|
|
1557
|
-
if (snapshot.value === 'error') {
|
|
1558
|
-
setError(snapshot.context._loadingError?.error ??
|
|
1559
|
-
new Error('Failed to create model'));
|
|
1560
|
-
setIsLoading(false);
|
|
1561
|
-
}
|
|
1562
|
-
if (snapshot.value === 'idle') {
|
|
1563
|
-
setError(null);
|
|
1564
|
-
setIsLoading(false);
|
|
1565
|
-
}
|
|
1566
|
-
});
|
|
1567
|
-
subscriptionRef.current = subscription;
|
|
1568
|
-
return model;
|
|
1569
|
-
}, []);
|
|
1570
|
-
useEffect(() => {
|
|
1571
|
-
return () => {
|
|
1572
|
-
subscriptionRef.current?.unsubscribe();
|
|
1573
|
-
subscriptionRef.current = undefined;
|
|
1574
|
-
};
|
|
1575
|
-
}, []);
|
|
1576
|
-
return {
|
|
1577
|
-
create,
|
|
1578
|
-
isLoading,
|
|
1579
|
-
error,
|
|
1580
|
-
resetError,
|
|
1581
|
-
};
|
|
1582
|
-
};
|
|
1583
|
-
const useDestroyModel = () => {
|
|
1584
|
-
const [currentInstance, setCurrentInstance] = useState(null);
|
|
1585
|
-
const [destroyState, setDestroyState] = useState({
|
|
1586
|
-
isLoading: false,
|
|
1587
|
-
error: null,
|
|
1588
|
-
});
|
|
1589
|
-
useEffect(() => {
|
|
1590
|
-
if (!currentInstance) {
|
|
1591
|
-
setDestroyState({ isLoading: false, error: null });
|
|
1592
|
-
return;
|
|
1593
|
-
}
|
|
1594
|
-
const service = currentInstance.getService();
|
|
1595
|
-
const update = () => {
|
|
1596
|
-
const snap = service.getSnapshot();
|
|
1597
|
-
const ctx = snap.context;
|
|
1598
|
-
setDestroyState({
|
|
1599
|
-
isLoading: !!ctx._destroyInProgress,
|
|
1600
|
-
error: ctx._destroyError ? new Error(ctx._destroyError.message) : null,
|
|
1601
|
-
});
|
|
1602
|
-
};
|
|
1603
|
-
update();
|
|
1604
|
-
const sub = service.subscribe(update);
|
|
1605
|
-
return () => sub.unsubscribe();
|
|
1606
|
-
}, [currentInstance]);
|
|
1607
|
-
const destroy = useCallback(async (model) => {
|
|
1608
|
-
if (!model)
|
|
1609
|
-
return;
|
|
1610
|
-
setCurrentInstance(model);
|
|
1611
|
-
await model.destroy();
|
|
1612
|
-
}, []);
|
|
1613
|
-
const resetError = useCallback(() => {
|
|
1614
|
-
if (currentInstance) {
|
|
1615
|
-
currentInstance.getService().send({ type: 'clearDestroyError' });
|
|
1616
|
-
}
|
|
1617
|
-
}, [currentInstance]);
|
|
1618
|
-
return {
|
|
1619
|
-
destroy,
|
|
1620
|
-
isLoading: destroyState.isLoading,
|
|
1621
|
-
error: destroyState.error,
|
|
1622
|
-
resetError,
|
|
1623
|
-
};
|
|
83
|
+
const getMetadataAttestationUidsForSeedUid = async (seedUid) => {
|
|
84
|
+
if (!seedUid)
|
|
85
|
+
return [];
|
|
86
|
+
const appDb = BaseDb.getAppDb();
|
|
87
|
+
const rows = await appDb
|
|
88
|
+
.select({ uid: metadata.uid, schemaUid: metadata.schemaUid })
|
|
89
|
+
.from(metadata)
|
|
90
|
+
.where(and(eq(metadata.seedUid, seedUid), isNotNull(metadata.uid), ne(metadata.uid, ''), ne(metadata.uid, '0x' + '0'.repeat(64))));
|
|
91
|
+
return rows
|
|
92
|
+
.filter((r) => r.uid != null && r.schemaUid != null)
|
|
93
|
+
.map((r) => ({ uid: r.uid, schemaUid: r.schemaUid }));
|
|
1624
94
|
};
|
|
1625
95
|
|
|
1626
|
-
|
|
1627
|
-
|
|
1628
|
-
|
|
1629
|
-
|
|
1630
|
-
* 1. With schemaId and modelName: useModelProperties(schemaId, modelName)
|
|
1631
|
-
* 2. With modelId: useModelProperties(modelId)
|
|
1632
|
-
*
|
|
1633
|
-
* Uses useLiveQuery to watch for changes in the properties table and automatically
|
|
1634
|
-
* updates the returned ModelProperty instances when changes occur.
|
|
1635
|
-
*
|
|
1636
|
-
* @param schemaIdOrModelId - The schema ID (schema file ID) OR the model ID (modelFileId)
|
|
1637
|
-
* @param modelName - The name of the model to get properties from (required if first param is schemaId)
|
|
1638
|
-
* @returns Object with modelProperties array, isLoading, and error
|
|
1639
|
-
*/
|
|
1640
|
-
const useModelProperties = (schemaIdOrModelId, modelName) => {
|
|
1641
|
-
// Use useModel to handle both lookup patterns (by ID or by schemaId + modelName)
|
|
1642
|
-
const { model } = useModel(schemaIdOrModelId, modelName);
|
|
1643
|
-
// Determine the modelName for use in getPropertySchema
|
|
1644
|
-
useMemo(() => {
|
|
1645
|
-
if (!model)
|
|
1646
|
-
return undefined;
|
|
1647
|
-
try {
|
|
1648
|
-
return model.modelName ?? model.name;
|
|
1649
|
-
}
|
|
1650
|
-
catch {
|
|
1651
|
-
return undefined;
|
|
1652
|
-
}
|
|
1653
|
-
}, [model]);
|
|
1654
|
-
const isClientReady = useIsClientReady();
|
|
1655
|
-
const queryClient = useQueryClient();
|
|
1656
|
-
// Get _dbId (database ID) from model context
|
|
1657
|
-
const dbModelId = useMemo(() => {
|
|
1658
|
-
if (!model)
|
|
1659
|
-
return null;
|
|
96
|
+
function getAttesterFromRow(row) {
|
|
97
|
+
if (row.publisher)
|
|
98
|
+
return row.publisher;
|
|
99
|
+
if (row.attestationRaw) {
|
|
1660
100
|
try {
|
|
1661
|
-
const
|
|
1662
|
-
return
|
|
101
|
+
const parsed = JSON.parse(row.attestationRaw);
|
|
102
|
+
return parsed.attester ?? null;
|
|
1663
103
|
}
|
|
1664
104
|
catch {
|
|
1665
105
|
return null;
|
|
1666
106
|
}
|
|
1667
|
-
}, [model]);
|
|
1668
|
-
const modelId = model?.id;
|
|
1669
|
-
const modelPropertiesQueryKey = useMemo(() => ['seed', 'modelProperties', modelId ?? ''], [modelId]);
|
|
1670
|
-
const { data: modelProperties = [], isLoading, error: queryError, } = useQuery({
|
|
1671
|
-
queryKey: modelPropertiesQueryKey,
|
|
1672
|
-
queryFn: () => ModelProperty.all(modelId, { waitForReady: true }),
|
|
1673
|
-
enabled: isClientReady && !!modelId,
|
|
1674
|
-
});
|
|
1675
|
-
const db = isClientReady ? BaseDb.getAppDb() : null;
|
|
1676
|
-
const propertiesQuery = useMemo(() => {
|
|
1677
|
-
if (!db || !dbModelId)
|
|
1678
|
-
return null;
|
|
1679
|
-
return db
|
|
1680
|
-
.select({
|
|
1681
|
-
id: properties.id,
|
|
1682
|
-
name: properties.name,
|
|
1683
|
-
dataType: properties.dataType,
|
|
1684
|
-
schemaFileId: properties.schemaFileId,
|
|
1685
|
-
})
|
|
1686
|
-
.from(properties)
|
|
1687
|
-
.where(eq(properties.modelId, dbModelId));
|
|
1688
|
-
}, [db, isClientReady, dbModelId]);
|
|
1689
|
-
const propertiesTableData = useLiveQuery(propertiesQuery);
|
|
1690
|
-
const modelPropertiesRef = useRef([]);
|
|
1691
|
-
modelPropertiesRef.current = modelProperties;
|
|
1692
|
-
// Fallback: when we have modelId but query returned [] (e.g. properties not in DB yet or
|
|
1693
|
-
// propertiesTableData is undefined because model._dbId isn't set yet), schedule refetches
|
|
1694
|
-
// so we pick up properties after they're written.
|
|
1695
|
-
useEffect(() => {
|
|
1696
|
-
if (!modelId || modelProperties.length > 0 || !queryClient || !modelPropertiesQueryKey)
|
|
1697
|
-
return;
|
|
1698
|
-
const delays = [400, 1200, 2500];
|
|
1699
|
-
const timers = delays.map((ms) => setTimeout(() => {
|
|
1700
|
-
queryClient.invalidateQueries({ queryKey: modelPropertiesQueryKey });
|
|
1701
|
-
}, ms));
|
|
1702
|
-
return () => timers.forEach((t) => clearTimeout(t));
|
|
1703
|
-
}, [modelId, modelProperties.length, queryClient, modelPropertiesQueryKey]);
|
|
1704
|
-
useEffect(() => {
|
|
1705
|
-
if (!isClientReady || !model?.id || !propertiesTableData || !modelPropertiesQueryKey)
|
|
1706
|
-
return;
|
|
1707
|
-
const currentPropertiesSet = new Set();
|
|
1708
|
-
for (const prop of modelPropertiesRef.current) {
|
|
1709
|
-
const context = prop._getSnapshotContext();
|
|
1710
|
-
const propertyFileId = context?.id;
|
|
1711
|
-
if (propertyFileId)
|
|
1712
|
-
currentPropertiesSet.add(propertyFileId);
|
|
1713
|
-
else if (prop.name)
|
|
1714
|
-
currentPropertiesSet.add(prop.name);
|
|
1715
|
-
}
|
|
1716
|
-
const tableDataPropertiesSet = new Set();
|
|
1717
|
-
for (const dbProperty of propertiesTableData) {
|
|
1718
|
-
if (dbProperty.schemaFileId)
|
|
1719
|
-
tableDataPropertiesSet.add(dbProperty.schemaFileId);
|
|
1720
|
-
else if (dbProperty.name)
|
|
1721
|
-
tableDataPropertiesSet.add(dbProperty.name);
|
|
1722
|
-
}
|
|
1723
|
-
const setsAreEqual = currentPropertiesSet.size === tableDataPropertiesSet.size &&
|
|
1724
|
-
(currentPropertiesSet.size === 0 ||
|
|
1725
|
-
[...currentPropertiesSet].every((id) => tableDataPropertiesSet.has(id)));
|
|
1726
|
-
// Invalidate when cached list is out of sync with the table: either we have stale cached data
|
|
1727
|
-
// (currentPropertiesSet.size > 0) or the table has new rows we don't have yet (tableDataPropertiesSet.size > 0).
|
|
1728
|
-
// The latter handles the case where the initial query returned [] before properties were written.
|
|
1729
|
-
const shouldInvalidate = !setsAreEqual && (currentPropertiesSet.size > 0 || tableDataPropertiesSet.size > 0);
|
|
1730
|
-
if (shouldInvalidate) {
|
|
1731
|
-
queryClient.invalidateQueries({ queryKey: modelPropertiesQueryKey });
|
|
1732
|
-
}
|
|
1733
|
-
}, [isClientReady, propertiesTableData, model?.id, queryClient, modelPropertiesQueryKey]);
|
|
1734
|
-
// When we have cached modelProperties, do not report isLoading: true even if the query
|
|
1735
|
-
// is refetching (e.g. after useModels refetch causes modelId to change briefly). UX expects
|
|
1736
|
-
// isLoading false once we have shown data.
|
|
1737
|
-
const effectiveIsLoading = isLoading && modelProperties.length === 0;
|
|
1738
|
-
return {
|
|
1739
|
-
modelProperties,
|
|
1740
|
-
isLoading: effectiveIsLoading,
|
|
1741
|
-
error: queryError,
|
|
1742
|
-
};
|
|
1743
|
-
};
|
|
1744
|
-
/**
|
|
1745
|
-
* Helper function to get property schema by modelFileId and propertyName
|
|
1746
|
-
*/
|
|
1747
|
-
const getPropertySchemaByModelFileId = async (modelFileId, propertyName) => {
|
|
1748
|
-
// Get model by modelFileId
|
|
1749
|
-
const model = await Model.createById(modelFileId);
|
|
1750
|
-
if (!model) {
|
|
1751
|
-
return undefined;
|
|
1752
|
-
}
|
|
1753
|
-
// Get modelName from model
|
|
1754
|
-
const modelName = model.modelName ?? model.name;
|
|
1755
|
-
if (!modelName) {
|
|
1756
|
-
return undefined;
|
|
1757
|
-
}
|
|
1758
|
-
// Use existing getPropertySchema function
|
|
1759
|
-
return getPropertySchema(modelName, propertyName);
|
|
1760
|
-
};
|
|
1761
|
-
function useModelProperty(arg1, arg2, arg3) {
|
|
1762
|
-
// Determine initial loading state - start loading if we have valid parameters
|
|
1763
|
-
const initialLoadingState = useMemo(() => {
|
|
1764
|
-
if (arg3 !== undefined && arg3 !== null) {
|
|
1765
|
-
// Three arguments: schemaId, modelName, propertyName
|
|
1766
|
-
return !!(arg1 && arg2 && arg3);
|
|
1767
|
-
}
|
|
1768
|
-
else if (arg2 !== undefined && arg2 !== null) {
|
|
1769
|
-
// Two arguments: modelFileId, propertyName
|
|
1770
|
-
return !!(arg1 && arg2);
|
|
1771
|
-
}
|
|
1772
|
-
else {
|
|
1773
|
-
// One argument: propertyFileId
|
|
1774
|
-
return !!arg1;
|
|
1775
|
-
}
|
|
1776
|
-
}, [arg1, arg2, arg3]);
|
|
1777
|
-
const [modelProperty, setModelProperty] = useState(undefined);
|
|
1778
|
-
const [isLoading, setIsLoading] = useState(initialLoadingState);
|
|
1779
|
-
const [error, setError] = useState(null);
|
|
1780
|
-
const subscriptionRef = useRef(undefined);
|
|
1781
|
-
const isClientReady = useIsClientReady();
|
|
1782
|
-
// Determine which lookup mode we're in based on arguments
|
|
1783
|
-
const lookupMode = useMemo(() => {
|
|
1784
|
-
if (arg3 !== undefined && arg3 !== null) {
|
|
1785
|
-
// Three arguments: schemaId, modelName, propertyName
|
|
1786
|
-
return { type: 'schemaId', schemaId: arg1, modelName: arg2, propertyName: arg3 };
|
|
1787
|
-
}
|
|
1788
|
-
else if (arg2 !== undefined && arg2 !== null) {
|
|
1789
|
-
// Two arguments: modelFileId, propertyName
|
|
1790
|
-
return { type: 'modelFileId', modelFileId: arg1, propertyName: arg2 };
|
|
1791
|
-
}
|
|
1792
|
-
else {
|
|
1793
|
-
// One argument: propertyFileId
|
|
1794
|
-
return { type: 'propertyFileId', propertyFileId: arg1 };
|
|
1795
|
-
}
|
|
1796
|
-
}, [arg1, arg2, arg3]);
|
|
1797
|
-
// Determine if we should be loading based on parameters
|
|
1798
|
-
const shouldLoad = useMemo(() => {
|
|
1799
|
-
if (!isClientReady)
|
|
1800
|
-
return false;
|
|
1801
|
-
if (lookupMode.type === 'propertyFileId') {
|
|
1802
|
-
return !!lookupMode.propertyFileId;
|
|
1803
|
-
}
|
|
1804
|
-
else if (lookupMode.type === 'modelFileId') {
|
|
1805
|
-
return !!(lookupMode.modelFileId && lookupMode.propertyName);
|
|
1806
|
-
}
|
|
1807
|
-
else {
|
|
1808
|
-
return !!(lookupMode.schemaId && lookupMode.modelName && lookupMode.propertyName);
|
|
1809
|
-
}
|
|
1810
|
-
}, [isClientReady, lookupMode]);
|
|
1811
|
-
const updateModelProperty = useCallback(async () => {
|
|
1812
|
-
if (!isClientReady) {
|
|
1813
|
-
setModelProperty(undefined);
|
|
1814
|
-
setIsLoading(false);
|
|
1815
|
-
setError(null);
|
|
1816
|
-
return;
|
|
1817
|
-
}
|
|
1818
|
-
let propertyData;
|
|
1819
|
-
let resolvedModelName;
|
|
1820
|
-
try {
|
|
1821
|
-
setIsLoading(true);
|
|
1822
|
-
setError(null);
|
|
1823
|
-
if (lookupMode.type === 'propertyFileId') {
|
|
1824
|
-
if (!lookupMode.propertyFileId) {
|
|
1825
|
-
setModelProperty(undefined);
|
|
1826
|
-
setIsLoading(false);
|
|
1827
|
-
setError(null);
|
|
1828
|
-
return;
|
|
1829
|
-
}
|
|
1830
|
-
// Use ModelProperty.createById for propertyFileId lookup
|
|
1831
|
-
const foundProperty = await ModelProperty.createById(lookupMode.propertyFileId);
|
|
1832
|
-
if (foundProperty) {
|
|
1833
|
-
setModelProperty(foundProperty);
|
|
1834
|
-
setIsLoading(false);
|
|
1835
|
-
setError(null);
|
|
1836
|
-
}
|
|
1837
|
-
else {
|
|
1838
|
-
setModelProperty(undefined);
|
|
1839
|
-
setIsLoading(false);
|
|
1840
|
-
setError(null);
|
|
1841
|
-
}
|
|
1842
|
-
return;
|
|
1843
|
-
}
|
|
1844
|
-
else if (lookupMode.type === 'modelFileId') {
|
|
1845
|
-
if (!lookupMode.modelFileId || !lookupMode.propertyName) {
|
|
1846
|
-
setModelProperty(undefined);
|
|
1847
|
-
setIsLoading(false);
|
|
1848
|
-
setError(null);
|
|
1849
|
-
return;
|
|
1850
|
-
}
|
|
1851
|
-
// Get property schema by modelFileId and propertyName
|
|
1852
|
-
// This function already gets the model and resolves modelName
|
|
1853
|
-
propertyData = await getPropertySchemaByModelFileId(lookupMode.modelFileId, lookupMode.propertyName);
|
|
1854
|
-
// Get modelName from model (needed for ModelProperty.create)
|
|
1855
|
-
const model = await Model.createById(lookupMode.modelFileId);
|
|
1856
|
-
resolvedModelName = model?.modelName ?? model?.name;
|
|
1857
|
-
}
|
|
1858
|
-
else {
|
|
1859
|
-
// lookupMode.type === 'schemaId'
|
|
1860
|
-
if (!lookupMode.schemaId || !lookupMode.modelName || !lookupMode.propertyName) {
|
|
1861
|
-
setModelProperty(undefined);
|
|
1862
|
-
setIsLoading(false);
|
|
1863
|
-
setError(null);
|
|
1864
|
-
return;
|
|
1865
|
-
}
|
|
1866
|
-
// Use existing getPropertySchema for schemaId + modelName + propertyName
|
|
1867
|
-
propertyData = await getPropertySchema(lookupMode.modelName, lookupMode.propertyName);
|
|
1868
|
-
resolvedModelName = lookupMode.modelName;
|
|
1869
|
-
}
|
|
1870
|
-
if (propertyData && resolvedModelName) {
|
|
1871
|
-
const createdProperty = ModelProperty.create({ ...propertyData, modelName: resolvedModelName }, { waitForReady: false });
|
|
1872
|
-
const resolvedProperty = createdProperty instanceof Promise ? await createdProperty : createdProperty;
|
|
1873
|
-
flushSync(() => {
|
|
1874
|
-
setModelProperty(resolvedProperty);
|
|
1875
|
-
setIsLoading(false);
|
|
1876
|
-
setError(null);
|
|
1877
|
-
});
|
|
1878
|
-
}
|
|
1879
|
-
else {
|
|
1880
|
-
setModelProperty(undefined);
|
|
1881
|
-
setIsLoading(false);
|
|
1882
|
-
setError(null);
|
|
1883
|
-
}
|
|
1884
|
-
}
|
|
1885
|
-
catch (error) {
|
|
1886
|
-
console.error('[useModelProperty] Error updating model property:', error);
|
|
1887
|
-
setModelProperty(undefined);
|
|
1888
|
-
setIsLoading(false);
|
|
1889
|
-
setError(error);
|
|
1890
|
-
}
|
|
1891
|
-
}, [isClientReady, lookupMode.type, lookupMode.propertyFileId, lookupMode.modelFileId, lookupMode.propertyName, lookupMode.schemaId, lookupMode.modelName]);
|
|
1892
|
-
// Fetch/refetch when lookup parameters change or client becomes ready
|
|
1893
|
-
useEffect(() => {
|
|
1894
|
-
if (!shouldLoad) {
|
|
1895
|
-
setModelProperty(undefined);
|
|
1896
|
-
setIsLoading(false);
|
|
1897
|
-
setError(null);
|
|
1898
|
-
return;
|
|
1899
|
-
}
|
|
1900
|
-
updateModelProperty();
|
|
1901
|
-
}, [shouldLoad, updateModelProperty]);
|
|
1902
|
-
// Subscribe to service changes when modelProperty is available.
|
|
1903
|
-
// Skip subscription for schemaId/modelFileId lookups where we created the instance locally—
|
|
1904
|
-
// refetching on every snapshot would set loading and can race with the initial render.
|
|
1905
|
-
// Debounce to reduce refetch frequency and avoid updateContext/refetch loops.
|
|
1906
|
-
const shouldSubscribe = lookupMode.type === 'propertyFileId';
|
|
1907
|
-
useEffect(() => {
|
|
1908
|
-
if (!modelProperty || !shouldSubscribe) {
|
|
1909
|
-
return;
|
|
1910
|
-
}
|
|
1911
|
-
// Clean up previous subscription
|
|
1912
|
-
subscriptionRef.current?.unsubscribe();
|
|
1913
|
-
const debouncedUpdate = debounce(updateModelProperty, 100);
|
|
1914
|
-
// Subscribe to service changes
|
|
1915
|
-
const subscription = modelProperty.getService().subscribe(() => {
|
|
1916
|
-
debouncedUpdate();
|
|
1917
|
-
});
|
|
1918
|
-
subscriptionRef.current = subscription;
|
|
1919
|
-
return () => {
|
|
1920
|
-
debouncedUpdate.cancel();
|
|
1921
|
-
subscriptionRef.current?.unsubscribe();
|
|
1922
|
-
subscriptionRef.current = undefined;
|
|
1923
|
-
};
|
|
1924
|
-
}, [modelProperty, updateModelProperty, shouldSubscribe]);
|
|
1925
|
-
return {
|
|
1926
|
-
modelProperty,
|
|
1927
|
-
isLoading,
|
|
1928
|
-
error,
|
|
1929
|
-
};
|
|
1930
|
-
}
|
|
1931
|
-
/**
|
|
1932
|
-
* Hook to create a ModelProperty with loading and error state.
|
|
1933
|
-
* create(schemaId, modelName, property) creates a new property on the model.
|
|
1934
|
-
*/
|
|
1935
|
-
const useCreateModelProperty = () => {
|
|
1936
|
-
const subscriptionRef = useRef(undefined);
|
|
1937
|
-
const [isLoading, setIsLoading] = useState(false);
|
|
1938
|
-
const [error, setError] = useState(null);
|
|
1939
|
-
const resetError = useCallback(() => setError(null), []);
|
|
1940
|
-
const create = useCallback((schemaId, modelName, property) => {
|
|
1941
|
-
setError(null);
|
|
1942
|
-
setIsLoading(true);
|
|
1943
|
-
subscriptionRef.current?.unsubscribe();
|
|
1944
|
-
subscriptionRef.current = undefined;
|
|
1945
|
-
if (!modelName || !property.name || !property.dataType) {
|
|
1946
|
-
const err = new Error('modelName, property name and dataType are required');
|
|
1947
|
-
setError(err);
|
|
1948
|
-
setIsLoading(false);
|
|
1949
|
-
throw err;
|
|
1950
|
-
}
|
|
1951
|
-
// Resolve schema name: schemaId may be "Blog-1" (schemaName-version) or just "Blog"
|
|
1952
|
-
const schemaName = getSchemaNameFromId(schemaId) ?? schemaId;
|
|
1953
|
-
const created = ModelProperty.create({ ...property, modelName }, { waitForReady: false, schemaName });
|
|
1954
|
-
const subscription = created.getService().subscribe((snapshot) => {
|
|
1955
|
-
if (snapshot.value === 'error') {
|
|
1956
|
-
const err = snapshot.context._loadingError?.error ?? new Error('Failed to create model property');
|
|
1957
|
-
setError(err instanceof Error ? err : new Error(String(err)));
|
|
1958
|
-
setIsLoading(false);
|
|
1959
|
-
}
|
|
1960
|
-
if (snapshot.value === 'idle') {
|
|
1961
|
-
setError(null);
|
|
1962
|
-
setIsLoading(false);
|
|
1963
|
-
}
|
|
1964
|
-
});
|
|
1965
|
-
subscriptionRef.current = subscription;
|
|
1966
|
-
return created;
|
|
1967
|
-
}, []);
|
|
1968
|
-
useEffect(() => {
|
|
1969
|
-
return () => {
|
|
1970
|
-
subscriptionRef.current?.unsubscribe();
|
|
1971
|
-
subscriptionRef.current = undefined;
|
|
1972
|
-
};
|
|
1973
|
-
}, []);
|
|
1974
|
-
return {
|
|
1975
|
-
create,
|
|
1976
|
-
isLoading,
|
|
1977
|
-
error,
|
|
1978
|
-
resetError,
|
|
1979
|
-
};
|
|
1980
|
-
};
|
|
1981
|
-
const useDestroyModelProperty = () => {
|
|
1982
|
-
const [currentInstance, setCurrentInstance] = useState(null);
|
|
1983
|
-
const [destroyState, setDestroyState] = useState({
|
|
1984
|
-
isLoading: false,
|
|
1985
|
-
error: null,
|
|
1986
|
-
});
|
|
1987
|
-
useEffect(() => {
|
|
1988
|
-
if (!currentInstance) {
|
|
1989
|
-
setDestroyState({ isLoading: false, error: null });
|
|
1990
|
-
return;
|
|
1991
|
-
}
|
|
1992
|
-
const service = currentInstance.getService();
|
|
1993
|
-
const update = () => {
|
|
1994
|
-
const snap = service.getSnapshot();
|
|
1995
|
-
const ctx = snap.context;
|
|
1996
|
-
setDestroyState({
|
|
1997
|
-
isLoading: !!ctx._destroyInProgress,
|
|
1998
|
-
error: ctx._destroyError ? new Error(ctx._destroyError.message) : null,
|
|
1999
|
-
});
|
|
2000
|
-
};
|
|
2001
|
-
update();
|
|
2002
|
-
const sub = service.subscribe(update);
|
|
2003
|
-
return () => sub.unsubscribe();
|
|
2004
|
-
}, [currentInstance]);
|
|
2005
|
-
const destroy = useCallback(async (modelProperty) => {
|
|
2006
|
-
if (!modelProperty)
|
|
2007
|
-
return;
|
|
2008
|
-
setCurrentInstance(modelProperty);
|
|
2009
|
-
await modelProperty.destroy();
|
|
2010
|
-
}, []);
|
|
2011
|
-
const resetError = useCallback(() => {
|
|
2012
|
-
if (currentInstance) {
|
|
2013
|
-
currentInstance.getService().send({ type: 'clearDestroyError' });
|
|
2014
|
-
}
|
|
2015
|
-
}, [currentInstance]);
|
|
2016
|
-
return {
|
|
2017
|
-
destroy,
|
|
2018
|
-
isLoading: destroyState.isLoading,
|
|
2019
|
-
error: destroyState.error,
|
|
2020
|
-
resetError,
|
|
2021
|
-
};
|
|
2022
|
-
};
|
|
2023
|
-
|
|
2024
|
-
const useDeleteItem = () => {
|
|
2025
|
-
const [currentInstance, setCurrentInstance] = useState(null);
|
|
2026
|
-
const [destroyState, setDestroyState] = useState({
|
|
2027
|
-
isLoading: false,
|
|
2028
|
-
error: null,
|
|
2029
|
-
});
|
|
2030
|
-
useEffect(() => {
|
|
2031
|
-
if (!currentInstance) {
|
|
2032
|
-
setDestroyState({ isLoading: false, error: null });
|
|
2033
|
-
return;
|
|
2034
|
-
}
|
|
2035
|
-
const service = currentInstance.getService();
|
|
2036
|
-
const update = () => {
|
|
2037
|
-
const snap = service.getSnapshot();
|
|
2038
|
-
const ctx = snap.context;
|
|
2039
|
-
setDestroyState({
|
|
2040
|
-
isLoading: !!ctx._destroyInProgress,
|
|
2041
|
-
error: ctx._destroyError ? new Error(ctx._destroyError.message) : null,
|
|
2042
|
-
});
|
|
2043
|
-
};
|
|
2044
|
-
update();
|
|
2045
|
-
const sub = service.subscribe(update);
|
|
2046
|
-
return () => sub.unsubscribe();
|
|
2047
|
-
}, [currentInstance]);
|
|
2048
|
-
const destroy = useCallback(async (item) => {
|
|
2049
|
-
if (!item)
|
|
2050
|
-
return;
|
|
2051
|
-
setCurrentInstance(item);
|
|
2052
|
-
await item.destroy();
|
|
2053
|
-
}, []);
|
|
2054
|
-
const resetError = useCallback(() => {
|
|
2055
|
-
if (currentInstance) {
|
|
2056
|
-
currentInstance.getService().send({ type: 'clearDestroyError' });
|
|
2057
|
-
}
|
|
2058
|
-
}, [currentInstance]);
|
|
2059
|
-
return {
|
|
2060
|
-
deleteItem: destroy,
|
|
2061
|
-
isLoading: destroyState.isLoading,
|
|
2062
|
-
error: destroyState.error,
|
|
2063
|
-
resetError,
|
|
2064
|
-
};
|
|
2065
|
-
};
|
|
2066
|
-
|
|
2067
|
-
const IMAGE_FILES_QUERY_KEY = ['seed', 'imageFiles'];
|
|
2068
|
-
/**
|
|
2069
|
-
* Returns an up-to-date list of image filenames stored in the file system (OPFS in browser).
|
|
2070
|
-
* Automatically refetches when images are saved (file-saved) or after bulk downloads (fs.downloadAll.success).
|
|
2071
|
-
*
|
|
2072
|
-
* Must be used within SeedProvider and after client.init().
|
|
2073
|
-
*
|
|
2074
|
-
* @example
|
|
2075
|
-
* ```tsx
|
|
2076
|
-
* const { imageFiles, isLoading, error, refetch } = useImageFiles()
|
|
2077
|
-
* // imageFiles: ['photo.jpg', 'cover.png']
|
|
2078
|
-
* ```
|
|
2079
|
-
*/
|
|
2080
|
-
function useImageFiles() {
|
|
2081
|
-
const isClientReady = useIsClientReady();
|
|
2082
|
-
const queryClient = useQueryClient();
|
|
2083
|
-
const { data: imageFiles = [], isLoading, error, refetch, } = useQuery({
|
|
2084
|
-
queryKey: IMAGE_FILES_QUERY_KEY,
|
|
2085
|
-
queryFn: () => BaseFileManager.listImageFiles(),
|
|
2086
|
-
enabled: isClientReady,
|
|
2087
|
-
});
|
|
2088
|
-
useEffect(() => {
|
|
2089
|
-
const fileSavedHandler = (filePath) => {
|
|
2090
|
-
if (filePath.includes('/images/')) {
|
|
2091
|
-
queryClient.invalidateQueries({ queryKey: IMAGE_FILES_QUERY_KEY });
|
|
2092
|
-
}
|
|
2093
|
-
};
|
|
2094
|
-
const downloadSuccessHandler = () => {
|
|
2095
|
-
queryClient.invalidateQueries({ queryKey: IMAGE_FILES_QUERY_KEY });
|
|
2096
|
-
};
|
|
2097
|
-
eventEmitter.on('file-saved', fileSavedHandler);
|
|
2098
|
-
eventEmitter.on('fs.downloadAll.success', downloadSuccessHandler);
|
|
2099
|
-
return () => {
|
|
2100
|
-
eventEmitter.off('file-saved', fileSavedHandler);
|
|
2101
|
-
eventEmitter.off('fs.downloadAll.success', downloadSuccessHandler);
|
|
2102
|
-
};
|
|
2103
|
-
}, [queryClient]);
|
|
2104
|
-
return {
|
|
2105
|
-
imageFiles,
|
|
2106
|
-
isLoading,
|
|
2107
|
-
error: error instanceof Error ? error : null,
|
|
2108
|
-
refetch,
|
|
2109
|
-
};
|
|
2110
|
-
}
|
|
2111
|
-
|
|
2112
|
-
const SEED_QUERY_DEFAULT_OPTIONS = {
|
|
2113
|
-
queries: {
|
|
2114
|
-
networkMode: 'offlineFirst',
|
|
2115
|
-
gcTime: 1000 * 60 * 60 * 24, // 24 hours
|
|
2116
|
-
staleTime: 1000 * 60, // 1 minute - list data can be slightly stale
|
|
2117
|
-
},
|
|
2118
|
-
};
|
|
2119
|
-
/**
|
|
2120
|
-
* Returns the default options used by Seed for list-query caching.
|
|
2121
|
-
* Use this when building your own QueryClient so Seed hooks get consistent behavior.
|
|
2122
|
-
*/
|
|
2123
|
-
function getSeedQueryDefaultOptions() {
|
|
2124
|
-
return { ...SEED_QUERY_DEFAULT_OPTIONS };
|
|
2125
|
-
}
|
|
2126
|
-
/**
|
|
2127
|
-
* Merges Seed's default query options with your existing default options.
|
|
2128
|
-
* Your options take precedence over Seed's. Use when constructing your own QueryClient:
|
|
2129
|
-
*
|
|
2130
|
-
* @example
|
|
2131
|
-
* ```ts
|
|
2132
|
-
* const client = new QueryClient({
|
|
2133
|
-
* defaultOptions: mergeSeedQueryDefaults({
|
|
2134
|
-
* queries: { gcTime: 1000 * 60 * 60 },
|
|
2135
|
-
* }),
|
|
2136
|
-
* })
|
|
2137
|
-
* ```
|
|
2138
|
-
*/
|
|
2139
|
-
function mergeSeedQueryDefaults(userOptions) {
|
|
2140
|
-
const seed = getSeedQueryDefaultOptions();
|
|
2141
|
-
if (!userOptions)
|
|
2142
|
-
return seed;
|
|
2143
|
-
return {
|
|
2144
|
-
queries: {
|
|
2145
|
-
...seed.queries,
|
|
2146
|
-
...(userOptions.queries ?? {}),
|
|
2147
|
-
},
|
|
2148
|
-
mutations: {
|
|
2149
|
-
...(seed.mutations ?? {}),
|
|
2150
|
-
...(userOptions.mutations ?? {}),
|
|
2151
|
-
},
|
|
2152
|
-
};
|
|
2153
|
-
}
|
|
2154
|
-
/**
|
|
2155
|
-
* Creates a QueryClient configured with Seed's default options.
|
|
2156
|
-
* Use this when you want to provide your own QueryClientProvider but still use Seed's defaults.
|
|
2157
|
-
*
|
|
2158
|
-
* @param overrides - Optional config to merge with Seed defaults (e.g. defaultOptions, logger).
|
|
2159
|
-
*/
|
|
2160
|
-
function createSeedQueryClient(overrides) {
|
|
2161
|
-
const defaults = getSeedQueryDefaultOptions();
|
|
2162
|
-
const { defaultOptions: userDefaultOptions, ...restOverrides } = overrides ?? {};
|
|
2163
|
-
return new QueryClient$1({
|
|
2164
|
-
...restOverrides,
|
|
2165
|
-
defaultOptions: userDefaultOptions
|
|
2166
|
-
? mergeSeedQueryDefaults(userDefaultOptions)
|
|
2167
|
-
: defaults,
|
|
2168
|
-
});
|
|
2169
|
-
}
|
|
2170
|
-
|
|
2171
|
-
/** Module-level ref so invalidateItemPropertiesForItem works when test and app share the same bundle but not the same window (e.g. iframe). */
|
|
2172
|
-
let invalidateItemPropertiesRef = null;
|
|
2173
|
-
/**
|
|
2174
|
-
* Invalidates and refetches the item-properties query for an item.
|
|
2175
|
-
* Call this after updating an ItemProperty (e.g. after save()) so useItemProperties
|
|
2176
|
-
* refetches and the UI updates. Returns a Promise that resolves when the refetch has completed (if available).
|
|
2177
|
-
*/
|
|
2178
|
-
function invalidateItemPropertiesForItem(canonicalId) {
|
|
2179
|
-
const p1 = invalidateItemPropertiesRef?.(canonicalId);
|
|
2180
|
-
if (typeof window !== 'undefined' && window.__SEED_INVALIDATE_ITEM_PROPERTIES__) {
|
|
2181
|
-
window.__SEED_INVALIDATE_ITEM_PROPERTIES__(canonicalId);
|
|
2182
107
|
}
|
|
2183
|
-
return Promise.resolve(p1).then(() => { });
|
|
2184
|
-
}
|
|
2185
|
-
function SeedProviderEventSubscriber({ queryClient }) {
|
|
2186
|
-
useEffect(() => {
|
|
2187
|
-
const invalidate = (canonicalId) => {
|
|
2188
|
-
const key = ['seed', 'itemProperties', canonicalId];
|
|
2189
|
-
queryClient.invalidateQueries({ queryKey: key });
|
|
2190
|
-
return queryClient.refetchQueries({ queryKey: key });
|
|
2191
|
-
};
|
|
2192
|
-
invalidateItemPropertiesRef = invalidate;
|
|
2193
|
-
if (typeof window !== 'undefined') {
|
|
2194
|
-
window.__SEED_INVALIDATE_ITEM_PROPERTIES__ = invalidate;
|
|
2195
|
-
}
|
|
2196
|
-
const handler = (payload) => {
|
|
2197
|
-
const canonicalId = payload?.seedLocalId ?? payload?.seedUid;
|
|
2198
|
-
if (canonicalId) {
|
|
2199
|
-
invalidate(canonicalId);
|
|
2200
|
-
}
|
|
2201
|
-
};
|
|
2202
|
-
eventEmitter.on('itemProperty.saved', handler);
|
|
2203
|
-
return () => {
|
|
2204
|
-
eventEmitter.off('itemProperty.saved', handler);
|
|
2205
|
-
invalidateItemPropertiesRef = null;
|
|
2206
|
-
if (typeof window !== 'undefined') {
|
|
2207
|
-
window.__SEED_INVALIDATE_ITEM_PROPERTIES__ = null;
|
|
2208
|
-
}
|
|
2209
|
-
};
|
|
2210
|
-
}, [queryClient]);
|
|
2211
108
|
return null;
|
|
2212
109
|
}
|
|
2213
110
|
/**
|
|
2214
|
-
*
|
|
2215
|
-
*
|
|
2216
|
-
* after calling client.init().
|
|
111
|
+
* Returns the attester address for a seed (from seeds.publisher or attestationRaw.attester).
|
|
112
|
+
* Used when revoking attestations to determine which account must perform the revoke.
|
|
2217
113
|
*
|
|
2218
|
-
*
|
|
2219
|
-
*
|
|
114
|
+
* @param seedLocalId - Optional seed local ID
|
|
115
|
+
* @param seedUid - Optional seed UID (attestation ID)
|
|
116
|
+
* @returns The attester address, or null if not found or no attester
|
|
2220
117
|
*/
|
|
2221
|
-
function
|
|
2222
|
-
const
|
|
2223
|
-
|
|
2224
|
-
|
|
2225
|
-
|
|
2226
|
-
|
|
2227
|
-
|
|
2228
|
-
|
|
2229
|
-
|
|
2230
|
-
|
|
2231
|
-
|
|
2232
|
-
|
|
2233
|
-
|
|
2234
|
-
|
|
2235
|
-
|
|
2236
|
-
|
|
2237
|
-
|
|
2238
|
-
|
|
2239
|
-
|
|
118
|
+
async function getAttesterForSeed(params) {
|
|
119
|
+
const { seedLocalId, seedUid } = params;
|
|
120
|
+
const appDb = BaseDb.getAppDb();
|
|
121
|
+
if (!appDb)
|
|
122
|
+
return null;
|
|
123
|
+
const conditions = [];
|
|
124
|
+
if (seedLocalId)
|
|
125
|
+
conditions.push(eq(seeds.localId, seedLocalId));
|
|
126
|
+
if (seedUid)
|
|
127
|
+
conditions.push(eq(seeds.uid, seedUid));
|
|
128
|
+
if (conditions.length === 0)
|
|
129
|
+
return null;
|
|
130
|
+
const seedRows = await appDb
|
|
131
|
+
.select({
|
|
132
|
+
publisher: seeds.publisher,
|
|
133
|
+
attestationRaw: seeds.attestationRaw,
|
|
134
|
+
})
|
|
135
|
+
.from(seeds)
|
|
136
|
+
.where(conditions.length === 1 ? conditions[0] : or(...conditions))
|
|
137
|
+
.limit(1);
|
|
138
|
+
if (!seedRows || seedRows.length === 0)
|
|
139
|
+
return null;
|
|
140
|
+
return getAttesterFromRow(seedRows[0]);
|
|
2240
141
|
}
|
|
2241
142
|
|
|
2242
143
|
/**
|
|
@@ -2251,15 +152,39 @@ async function getRelatedItemsForPublish(item, visited = new Set()) {
|
|
|
2251
152
|
}
|
|
2252
153
|
visited.add(seedLocalId);
|
|
2253
154
|
const result = [];
|
|
2254
|
-
const { itemRelationProperties, itemImageProperties, itemListProperties } = getSegmentedItemProperties(item);
|
|
2255
|
-
const getItemMod = await import('./getItem-
|
|
155
|
+
const { itemRelationProperties, itemImageProperties, itemListProperties } = await getSegmentedItemProperties(item);
|
|
156
|
+
const getItemMod = await import('./getItem-ClK0UZqi.js');
|
|
2256
157
|
const { getItem } = getItemMod;
|
|
2257
158
|
const processRelationOrImage = async (prop) => {
|
|
2258
159
|
const snapshot = prop.getService().getSnapshot();
|
|
2259
160
|
const context = snapshot.context ?? null;
|
|
2260
161
|
if (!context)
|
|
2261
162
|
return;
|
|
2262
|
-
|
|
163
|
+
let value = context.propertyValue;
|
|
164
|
+
// File/Image/Html/Json: fallback to metadata when propertyValue is empty (e.g. schema-loaded before metadata)
|
|
165
|
+
const isStorageSeed = prop.propertyDef?.dataType === 'File' ||
|
|
166
|
+
prop.propertyDef?.dataType === 'Image' ||
|
|
167
|
+
prop.propertyDef?.dataType === 'Html' ||
|
|
168
|
+
prop.propertyDef?.dataType === 'Json' ||
|
|
169
|
+
(prop.propertyDef?.dataType === 'Relation' &&
|
|
170
|
+
(prop.propertyDef?.refValueType === 'File' ||
|
|
171
|
+
prop.propertyDef?.refValueType === 'Image' ||
|
|
172
|
+
prop.propertyDef?.refValueType === 'Html' ||
|
|
173
|
+
prop.propertyDef?.refValueType === 'Json'));
|
|
174
|
+
if (!value && prop.propertyName && isStorageSeed) {
|
|
175
|
+
const ctx = context;
|
|
176
|
+
if (ctx.seedLocalId || ctx.seedUid) {
|
|
177
|
+
const _mod_0 = await import('./index-uPXtq2cf.js');
|
|
178
|
+
const _ns_0 = _mod_0.bs;
|
|
179
|
+
const { getPropertyData } = _ns_0;
|
|
180
|
+
const meta = await getPropertyData({
|
|
181
|
+
propertyName: prop.propertyName,
|
|
182
|
+
seedLocalId: ctx.seedLocalId,
|
|
183
|
+
seedUid: ctx.seedUid,
|
|
184
|
+
});
|
|
185
|
+
value = meta?.propertyValue;
|
|
186
|
+
}
|
|
187
|
+
}
|
|
2263
188
|
if (!value)
|
|
2264
189
|
return;
|
|
2265
190
|
const { localId: seedLocalId, uid: seedUid } = getCorrectId(value);
|
|
@@ -2273,7 +198,9 @@ async function getRelatedItemsForPublish(item, visited = new Set()) {
|
|
|
2273
198
|
await processRelationOrImage(prop);
|
|
2274
199
|
}
|
|
2275
200
|
for (const listProperty of itemListProperties) {
|
|
2276
|
-
|
|
201
|
+
const listRef = listProperty.propertyDef?.ref ||
|
|
202
|
+
listProperty.propertyDef?.refModelName;
|
|
203
|
+
if (!listRef)
|
|
2277
204
|
continue;
|
|
2278
205
|
const snapshot = listProperty.getService().getSnapshot();
|
|
2279
206
|
const context = snapshot.context ?? null;
|
|
@@ -2282,15 +209,8 @@ async function getRelatedItemsForPublish(item, visited = new Set()) {
|
|
|
2282
209
|
let value = context.propertyValue;
|
|
2283
210
|
if (!value || listProperty.uid)
|
|
2284
211
|
continue;
|
|
2285
|
-
if (typeof value === 'string'
|
|
2286
|
-
value =
|
|
2287
|
-
if (typeof value === 'string' && value.length > 66) {
|
|
2288
|
-
try {
|
|
2289
|
-
value = JSON.parse(value);
|
|
2290
|
-
}
|
|
2291
|
-
catch {
|
|
2292
|
-
value = value.split(',');
|
|
2293
|
-
}
|
|
212
|
+
if (typeof value === 'string') {
|
|
213
|
+
value = parseListPropertyValueFromStorage(value);
|
|
2294
214
|
}
|
|
2295
215
|
const arr = Array.isArray(value) ? value : [];
|
|
2296
216
|
for (const seedId of arr) {
|
|
@@ -2305,5 +225,5 @@ async function getRelatedItemsForPublish(item, visited = new Set()) {
|
|
|
2305
225
|
return result;
|
|
2306
226
|
}
|
|
2307
227
|
|
|
2308
|
-
export {
|
|
228
|
+
export { BaseDb, getAttesterForSeed, getCorrectId, getMetadataAttestationUidsForSeedUid, getRelatedItemsForPublish, getSegmentedItemProperties, getVersionsForSeedUid, metadata, seeds, updateVersionUid, versions };
|
|
2309
229
|
//# sourceMappingURL=main.js.map
|