@seedprotocol/sdk 0.6.10 → 0.7.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (399) hide show
  1. package/dist/{BasePathResolver-B6CKqoKw.js → BasePathResolver-DRT09oVv.js} +36 -2
  2. package/dist/BasePathResolver-DRT09oVv.js.map +1 -0
  3. package/dist/ClientManager-DngaZdw6.js +4763 -0
  4. package/dist/ClientManager-DngaZdw6.js.map +1 -0
  5. package/dist/{ClientManager-ChcmUL47.js → Item-ZUAmf943.js} +1175 -5903
  6. package/dist/Item-ZUAmf943.js.map +1 -0
  7. package/dist/{ModelProperty-D79uV42p.js → ModelProperty-6llK4MTH.js} +326 -109
  8. package/dist/ModelProperty-6llK4MTH.js.map +1 -0
  9. package/dist/{Schema-a8uO-hIZ.js → Schema-D-Ud-XYw.js} +164 -885
  10. package/dist/Schema-D-Ud-XYw.js.map +1 -0
  11. package/dist/{SchemaValidationService-Y49vqast.js → SchemaValidationService-IoS7JquP.js} +26 -18
  12. package/dist/SchemaValidationService-IoS7JquP.js.map +1 -0
  13. package/dist/{backfillMetadataPropertyIds-CBsf7LnU.js → backfillMetadataPropertyIds-BlVeE7w7.js} +11 -6
  14. package/dist/backfillMetadataPropertyIds-BlVeE7w7.js.map +1 -0
  15. package/dist/cjs/{ModelProperty-D9FGaGuE.js → ModelProperty-Dv7AQfmQ.js} +297 -89
  16. package/dist/cjs/ModelProperty-Dv7AQfmQ.js.map +1 -0
  17. package/dist/cjs/{Schema-BiJIPLEL.js → Schema-BHVp1g-M.js} +136 -868
  18. package/dist/cjs/Schema-BHVp1g-M.js.map +1 -0
  19. package/dist/cjs/{SchemaValidationService-DtYs_CNY.js → SchemaValidationService-BSU9knjf.js} +18 -11
  20. package/dist/cjs/SchemaValidationService-BSU9knjf.js.map +1 -0
  21. package/dist/cjs/{backfillMetadataPropertyIds-2XaN3b9S.js → backfillMetadataPropertyIds-WIovQ_d8.js} +8 -3
  22. package/dist/cjs/backfillMetadataPropertyIds-WIovQ_d8.js.map +1 -0
  23. package/dist/cjs/{eas-CMNppmGE.js → eas-CUYXdr2t.js} +4 -4
  24. package/dist/cjs/{eas-CMNppmGE.js.map → eas-CUYXdr2t.js.map} +1 -1
  25. package/dist/cjs/{getItem-B6jEINjW.js → getItem-z1tHu0hu.js} +2 -2
  26. package/dist/cjs/{getItem-B6jEINjW.js.map → getItem-z1tHu0hu.js.map} +1 -1
  27. package/dist/cjs/getLatestVersionRow-CcaabxIW.js +59 -0
  28. package/dist/cjs/getLatestVersionRow-CcaabxIW.js.map +1 -0
  29. package/dist/cjs/{getPublishPayload-D5DhLGvN.js → getPublishPayload-CEP_e-Kv.js} +283 -138
  30. package/dist/cjs/getPublishPayload-CEP_e-Kv.js.map +1 -0
  31. package/dist/cjs/{getPublishUploads-DMhCCKYF.js → getPublishUploads-Ctn5k1k6.js} +65 -19
  32. package/dist/cjs/getPublishUploads-Ctn5k1k6.js.map +1 -0
  33. package/dist/cjs/{index-CSNtEnbF.js → index-Cvvt0-5B.js} +2698 -1725
  34. package/dist/cjs/index-Cvvt0-5B.js.map +1 -0
  35. package/dist/cjs/{index-DPp9rdRL.js → index-DfGhF1dc.js} +3 -3
  36. package/dist/cjs/index-DfGhF1dc.js.map +1 -0
  37. package/dist/cjs/{property-DlKiAWt4.js → property-DbEPQ1m9.js} +40 -35
  38. package/dist/cjs/property-DbEPQ1m9.js.map +1 -0
  39. package/dist/cjs/publishDraftGraph-C38gf302.js +403 -0
  40. package/dist/cjs/publishDraftGraph-C38gf302.js.map +1 -0
  41. package/dist/cjs/resetAmbiguousLegacyItemData-CfMhRHwK.js +116 -0
  42. package/dist/cjs/resetAmbiguousLegacyItemData-CfMhRHwK.js.map +1 -0
  43. package/dist/cjs/resolveModelForSyncedSeed-CNYaLOir.js +49 -0
  44. package/dist/cjs/resolveModelForSyncedSeed-CNYaLOir.js.map +1 -0
  45. package/dist/cjs/syncDbWithEas-d1iOdTTI.js +886 -0
  46. package/dist/cjs/syncDbWithEas-d1iOdTTI.js.map +1 -0
  47. package/dist/{configurePlatform-CE0Vew17.js → configurePlatform-CZpjyuCo.js} +4 -4
  48. package/dist/{configurePlatform-CE0Vew17.js.map → configurePlatform-CZpjyuCo.js.map} +1 -1
  49. package/dist/db/drizzle/0015_add_model_file_id_to_seeds.sql +11 -0
  50. package/dist/db/drizzle/0016_add_revoked_at_to_metadata.sql +1 -0
  51. package/dist/db/drizzle/0017_add_revoked_at_to_versions.sql +1 -0
  52. package/dist/db/drizzle/0018_add_storage_settings_to_properties.sql +53 -0
  53. package/dist/db/drizzle/0019_add_derived_from_uid_to_metadata.sql +35 -0
  54. package/dist/db/drizzle/meta/0011_snapshot.json +1182 -0
  55. package/dist/db/drizzle/meta/0012_snapshot.json +1244 -0
  56. package/dist/db/drizzle/meta/0013_snapshot.json +63 -1
  57. package/dist/db/drizzle/meta/0014_snapshot.json +62 -0
  58. package/dist/db/drizzle/meta/0015_snapshot.json +1338 -0
  59. package/dist/db/drizzle/meta/0016_snapshot.json +1345 -0
  60. package/dist/db/drizzle/meta/0017_snapshot.json +1352 -0
  61. package/dist/db/drizzle/meta/0018_snapshot.json +1373 -0
  62. package/dist/db/drizzle/meta/0019_snapshot.json +1380 -0
  63. package/dist/db/drizzle/meta/_journal.json +35 -0
  64. package/dist/{db-WbrzEf7c.js → db-Lw0KVZmc.js} +546 -106
  65. package/dist/db-Lw0KVZmc.js.map +1 -0
  66. package/dist/{eas-CfYCu4IX.js → eas-CQ-Smzk2.js} +7 -7
  67. package/dist/eas-CQ-Smzk2.js.map +1 -0
  68. package/dist/errors-CrBxGWah.js +17 -0
  69. package/dist/errors-CrBxGWah.js.map +1 -0
  70. package/dist/{getItem-Br-bGNFO.js → getItem-CSfSok9f.js} +8 -10
  71. package/dist/{getItem-Br-bGNFO.js.map → getItem-CSfSok9f.js.map} +1 -1
  72. package/dist/getLatestVersionRow-72Atl9vB.js +46 -0
  73. package/dist/getLatestVersionRow-72Atl9vB.js.map +1 -0
  74. package/dist/{getPublishPayload-BIrTVUxb.js → getPublishPayload-76_KfB5Y.js} +297 -154
  75. package/dist/getPublishPayload-76_KfB5Y.js.map +1 -0
  76. package/dist/{getPublishUploads-C6cDeZdz.js → getPublishUploads-CqgMBD8f.js} +68 -21
  77. package/dist/getPublishUploads-CqgMBD8f.js.map +1 -0
  78. package/dist/{index-Djd3667v.js → index-5b3JsS55.js} +2 -2
  79. package/dist/index-5b3JsS55.js.map +1 -0
  80. package/dist/{index-ClSv5pTA.js → index-BpgD305l.js} +12 -11
  81. package/dist/index-BpgD305l.js.map +1 -0
  82. package/dist/{index-HRHkbVQd.js → index-Y-yYyRBf.js} +530 -196
  83. package/dist/index-Y-yYyRBf.js.map +1 -0
  84. package/dist/index.browser-DaTzn79x.js +4139 -0
  85. package/dist/index.browser-DaTzn79x.js.map +1 -0
  86. package/dist/{index.node-DBtQkEfz.js → index.node-NYKqFOoe.js} +9 -4
  87. package/dist/index.node-NYKqFOoe.js.map +1 -0
  88. package/dist/main.cjs +1 -1
  89. package/dist/main.js +886 -560
  90. package/dist/main.js.map +1 -1
  91. package/dist/node.js +19 -15
  92. package/dist/node.js.map +1 -1
  93. package/dist/platform.browser.js +18 -3719
  94. package/dist/platform.browser.js.map +1 -1
  95. package/dist/platform.node.js +3 -3
  96. package/dist/{property-CQjuZ4JW.js → property-ByaiSyUK.js} +53 -48
  97. package/dist/property-ByaiSyUK.js.map +1 -0
  98. package/dist/publishDraftGraph-BRm6Pq3Q.js +405 -0
  99. package/dist/publishDraftGraph-BRm6Pq3Q.js.map +1 -0
  100. package/dist/resetAmbiguousLegacyItemData-B4dX6ZA1.js +88 -0
  101. package/dist/resetAmbiguousLegacyItemData-B4dX6ZA1.js.map +1 -0
  102. package/dist/resolveModelForSyncedSeed-B0tco3zG.js +46 -0
  103. package/dist/resolveModelForSyncedSeed-B0tco3zG.js.map +1 -0
  104. package/dist/seedSchema/MetadataSchema.ts +9 -0
  105. package/dist/seedSchema/ModelSchema.ts +5 -0
  106. package/dist/seedSchema/SeedSchema.ts +3 -0
  107. package/dist/seedSchema/VersionSchema.ts +5 -0
  108. package/dist/src/Item/Item.d.ts +21 -0
  109. package/dist/src/Item/Item.d.ts.map +1 -1
  110. package/dist/src/Item/service/actors/loadOrCreateItem.d.ts.map +1 -1
  111. package/dist/src/Item/service/actors/waitForDb.d.ts.map +1 -1
  112. package/dist/src/Item/service/itemMachineSingle.d.ts +3 -29
  113. package/dist/src/Item/service/itemMachineSingle.d.ts.map +1 -1
  114. package/dist/src/ItemProperty/ItemProperty.d.ts +13 -4
  115. package/dist/src/ItemProperty/ItemProperty.d.ts.map +1 -1
  116. package/dist/src/ItemProperty/service/actors/hydrateFromDb.d.ts.map +1 -1
  117. package/dist/src/ItemProperty/service/actors/loadOrCreateProperty.d.ts.map +1 -1
  118. package/dist/src/ItemProperty/service/actors/saveValueToDb/saveFile.d.ts.map +1 -1
  119. package/dist/src/ItemProperty/service/actors/saveValueToDb/saveHtml.d.ts.map +1 -1
  120. package/dist/src/ItemProperty/service/actors/saveValueToDb/saveImage.d.ts.map +1 -1
  121. package/dist/src/ItemProperty/service/actors/saveValueToDb/saveItemStorage.d.ts.map +1 -1
  122. package/dist/src/ItemProperty/service/propertyMachine.d.ts +4 -9
  123. package/dist/src/ItemProperty/service/propertyMachine.d.ts.map +1 -1
  124. package/dist/src/Model/Model.d.ts +52 -2
  125. package/dist/src/Model/Model.d.ts.map +1 -1
  126. package/dist/src/Model/errors.d.ts +10 -0
  127. package/dist/src/Model/errors.d.ts.map +1 -0
  128. package/dist/src/Model/service/actors/createModelProperties.d.ts.map +1 -1
  129. package/dist/src/Model/service/actors/loadOrCreateModel.d.ts.map +1 -1
  130. package/dist/src/Model/service/actors/validateModel.d.ts.map +1 -1
  131. package/dist/src/Model/service/modelMachine.d.ts +0 -8
  132. package/dist/src/Model/service/modelMachine.d.ts.map +1 -1
  133. package/dist/src/ModelProperty/ModelProperty.d.ts +42 -2
  134. package/dist/src/ModelProperty/ModelProperty.d.ts.map +1 -1
  135. package/dist/src/ModelProperty/service/actors/compareAndMarkDraft.d.ts.map +1 -1
  136. package/dist/src/ModelProperty/service/actors/saveToSchema.d.ts.map +1 -1
  137. package/dist/src/ModelProperty/service/actors/validateProperty.d.ts.map +1 -1
  138. package/dist/src/ModelProperty/service/modelPropertyMachine.d.ts +2 -9
  139. package/dist/src/ModelProperty/service/modelPropertyMachine.d.ts.map +1 -1
  140. package/dist/src/Schema/Schema.d.ts +8 -2
  141. package/dist/src/Schema/Schema.d.ts.map +1 -1
  142. package/dist/src/Schema/service/actors/checkExistingSchema.d.ts.map +1 -1
  143. package/dist/src/Schema/service/actors/createModelInstances.d.ts.map +1 -1
  144. package/dist/src/Schema/service/actors/loadOrCreateSchema.d.ts.map +1 -1
  145. package/dist/src/Schema/service/schemaMachine.d.ts +1 -217
  146. package/dist/src/Schema/service/schemaMachine.d.ts.map +1 -1
  147. package/dist/src/Schema/service/validation/SchemaValidationService.d.ts.map +1 -1
  148. package/dist/src/browser/db/Db.d.ts +3 -0
  149. package/dist/src/browser/db/Db.d.ts.map +1 -1
  150. package/dist/src/browser/db/drizzleFiles.d.ts +7 -2
  151. package/dist/src/browser/db/drizzleFiles.d.ts.map +1 -1
  152. package/dist/src/browser/db/embeddedMigrations.d.ts +11 -2
  153. package/dist/src/browser/db/embeddedMigrations.d.ts.map +1 -1
  154. package/dist/src/browser/db/sqliteBusyRetry.d.ts +14 -0
  155. package/dist/src/browser/db/sqliteBusyRetry.d.ts.map +1 -0
  156. package/dist/src/browser/helpers/FileManager.d.ts +1 -0
  157. package/dist/src/browser/helpers/FileManager.d.ts.map +1 -1
  158. package/dist/src/browser/helpers/QueryClient.d.ts +1 -0
  159. package/dist/src/browser/helpers/QueryClient.d.ts.map +1 -1
  160. package/dist/src/browser/helpers/opfsErrors.d.ts +2 -0
  161. package/dist/src/browser/helpers/opfsErrors.d.ts.map +1 -0
  162. package/dist/src/browser/helpers/tolerantWebAccess.d.ts +47 -0
  163. package/dist/src/browser/helpers/tolerantWebAccess.d.ts.map +1 -0
  164. package/dist/src/browser/workers/FileDownloader.d.ts.map +1 -1
  165. package/dist/src/browser/workers/ImageResizer.d.ts.map +1 -1
  166. package/dist/src/browser/workers/filesDownload.d.ts.map +1 -1
  167. package/dist/src/browser/workers/imageResize.d.ts.map +1 -1
  168. package/dist/src/client/ClientManager.d.ts.map +1 -1
  169. package/dist/src/client/actors/addModelsToDb.d.ts +14 -0
  170. package/dist/src/client/actors/addModelsToDb.d.ts.map +1 -1
  171. package/dist/src/client/actors/platformClassesInit.d.ts.map +1 -1
  172. package/dist/src/client/actors/processSchemaFiles.d.ts.map +1 -1
  173. package/dist/src/client/actors/saveConfig.d.ts +11 -0
  174. package/dist/src/client/actors/saveConfig.d.ts.map +1 -1
  175. package/dist/src/client/constants.d.ts +0 -8
  176. package/dist/src/client/constants.d.ts.map +1 -1
  177. package/dist/src/db/backfillMetadataPropertyIds.d.ts.map +1 -1
  178. package/dist/src/db/configs/{dev.schema.config.d.ts → migrations.config.d.ts} +1 -1
  179. package/dist/src/db/configs/migrations.config.d.ts.map +1 -0
  180. package/dist/src/db/read/batchLatestPublishedVersionBySeedLocalIds.d.ts +1 -1
  181. package/dist/src/db/read/batchLatestPublishedVersionBySeedLocalIds.d.ts.map +1 -1
  182. package/dist/src/db/read/getItemData.d.ts.map +1 -1
  183. package/dist/src/db/read/getItemProperties.d.ts.map +1 -1
  184. package/dist/src/db/read/getItems.d.ts +7 -2
  185. package/dist/src/db/read/getItems.d.ts.map +1 -1
  186. package/dist/src/db/read/getLatestPublishedVersionRow.d.ts +2 -1
  187. package/dist/src/db/read/getLatestPublishedVersionRow.d.ts.map +1 -1
  188. package/dist/src/db/read/getLatestVersionRow.d.ts +13 -0
  189. package/dist/src/db/read/getLatestVersionRow.d.ts.map +1 -0
  190. package/dist/src/db/read/getModelSchemas.d.ts.map +1 -1
  191. package/dist/src/db/read/getPropertyData.d.ts.map +1 -1
  192. package/dist/src/db/read/getPublishPayload.d.ts +18 -11
  193. package/dist/src/db/read/getPublishPayload.d.ts.map +1 -1
  194. package/dist/src/db/read/getPublishPendingDiff.d.ts +2 -1
  195. package/dist/src/db/read/getPublishPendingDiff.d.ts.map +1 -1
  196. package/dist/src/db/read/getPublishUploads.d.ts +5 -0
  197. package/dist/src/db/read/getPublishUploads.d.ts.map +1 -1
  198. package/dist/src/db/read/getSchemaUidForModel.d.ts.map +1 -1
  199. package/dist/src/db/read/getSeedPublishState.d.ts +8 -2
  200. package/dist/src/db/read/getSeedPublishState.d.ts.map +1 -1
  201. package/dist/src/db/read/isSeedRevoked.d.ts +7 -0
  202. package/dist/src/db/read/isSeedRevoked.d.ts.map +1 -0
  203. package/dist/src/db/read/publishDraftGraph.d.ts +57 -0
  204. package/dist/src/db/read/publishDraftGraph.d.ts.map +1 -0
  205. package/dist/src/db/read/publishErrors.d.ts +37 -0
  206. package/dist/src/db/read/publishErrors.d.ts.map +1 -0
  207. package/dist/src/db/read/resolveModelForSyncedSeed.d.ts +39 -0
  208. package/dist/src/db/read/resolveModelForSyncedSeed.d.ts.map +1 -0
  209. package/dist/src/db/read/resolveModelRecord.d.ts +69 -0
  210. package/dist/src/db/read/resolveModelRecord.d.ts.map +1 -0
  211. package/dist/src/db/read/resolveRelatedSeedRef.d.ts +34 -0
  212. package/dist/src/db/read/resolveRelatedSeedRef.d.ts.map +1 -0
  213. package/dist/src/db/read/subqueries/liveVersion.d.ts +12 -0
  214. package/dist/src/db/read/subqueries/liveVersion.d.ts.map +1 -0
  215. package/dist/src/db/read/subqueries/metadataLatest.d.ts +4 -0
  216. package/dist/src/db/read/subqueries/metadataLatest.d.ts.map +1 -1
  217. package/dist/src/db/read/subqueries/versionData.d.ts +7 -2
  218. package/dist/src/db/read/subqueries/versionData.d.ts.map +1 -1
  219. package/dist/src/db/read/summarizePublishWork.d.ts +10 -2
  220. package/dist/src/db/read/summarizePublishWork.d.ts.map +1 -1
  221. package/dist/src/db/resetAmbiguousLegacyItemData.d.ts +17 -0
  222. package/dist/src/db/resetAmbiguousLegacyItemData.d.ts.map +1 -0
  223. package/dist/src/db/sqlParamBatches.d.ts +27 -0
  224. package/dist/src/db/sqlParamBatches.d.ts.map +1 -0
  225. package/dist/src/db/write/addExcludedTransactions.d.ts +7 -0
  226. package/dist/src/db/write/addExcludedTransactions.d.ts.map +1 -0
  227. package/dist/src/db/write/applyPropertyAttestationUidsFromPublish.d.ts +6 -0
  228. package/dist/src/db/write/applyPropertyAttestationUidsFromPublish.d.ts.map +1 -1
  229. package/dist/src/db/write/createMetadata.d.ts +2 -0
  230. package/dist/src/db/write/createMetadata.d.ts.map +1 -1
  231. package/dist/src/db/write/createNewItem.d.ts +3 -1
  232. package/dist/src/db/write/createNewItem.d.ts.map +1 -1
  233. package/dist/src/db/write/createSeed.d.ts +2 -1
  234. package/dist/src/db/write/createSeed.d.ts.map +1 -1
  235. package/dist/src/db/write/createSeeds.d.ts +1 -1
  236. package/dist/src/db/write/createSeeds.d.ts.map +1 -1
  237. package/dist/src/db/write/linkModelToSchema.d.ts +12 -0
  238. package/dist/src/db/write/linkModelToSchema.d.ts.map +1 -0
  239. package/dist/src/db/write/updateItemPropertyValue.d.ts.map +1 -1
  240. package/dist/src/db/write/updateMetadata.d.ts.map +1 -1
  241. package/dist/src/db/write/updateSeedRevokedAt.d.ts +11 -1
  242. package/dist/src/db/write/updateSeedRevokedAt.d.ts.map +1 -1
  243. package/dist/src/db/write/updateSeedUid.d.ts.map +1 -1
  244. package/dist/src/db/write/updateVersionUid.d.ts +2 -1
  245. package/dist/src/db/write/updateVersionUid.d.ts.map +1 -1
  246. package/dist/src/events/files/download.d.ts.map +1 -1
  247. package/dist/src/events/item/easSyncManager.d.ts +2 -0
  248. package/dist/src/events/item/easSyncManager.d.ts.map +1 -1
  249. package/dist/src/events/item/index.d.ts.map +1 -1
  250. package/dist/src/events/item/syncDbWithEas.d.ts +16 -0
  251. package/dist/src/events/item/syncDbWithEas.d.ts.map +1 -1
  252. package/dist/src/helpers/FileManager/BaseFileManager.d.ts +1 -0
  253. package/dist/src/helpers/FileManager/BaseFileManager.d.ts.map +1 -1
  254. package/dist/src/helpers/FileManager/IFileManager.d.ts +5 -0
  255. package/dist/src/helpers/FileManager/IFileManager.d.ts.map +1 -1
  256. package/dist/src/helpers/FileManager/errors.d.ts +10 -0
  257. package/dist/src/helpers/FileManager/errors.d.ts.map +1 -0
  258. package/dist/src/helpers/compareMetadataRowsLatestFirst.d.ts +21 -3
  259. package/dist/src/helpers/compareMetadataRowsLatestFirst.d.ts.map +1 -1
  260. package/dist/src/helpers/constants.d.ts +9 -0
  261. package/dist/src/helpers/constants.d.ts.map +1 -1
  262. package/dist/src/helpers/crypto.d.ts +5 -0
  263. package/dist/src/helpers/crypto.d.ts.map +1 -1
  264. package/dist/src/helpers/db.d.ts +25 -5
  265. package/dist/src/helpers/db.d.ts.map +1 -1
  266. package/dist/src/helpers/easPropertyCanonical.d.ts +1 -1
  267. package/dist/src/helpers/easPropertyCanonical.d.ts.map +1 -1
  268. package/dist/src/helpers/entity/entityCommon.d.ts +10 -0
  269. package/dist/src/helpers/entity/entityCommon.d.ts.map +1 -1
  270. package/dist/src/helpers/entity/entityDestroy.d.ts +1 -1
  271. package/dist/src/helpers/entity/entityDestroy.d.ts.map +1 -1
  272. package/dist/src/helpers/entity/entityLiveQuery.d.ts +5 -0
  273. package/dist/src/helpers/entity/entityLiveQuery.d.ts.map +1 -1
  274. package/dist/src/helpers/entity/evictionEpoch.d.ts +18 -0
  275. package/dist/src/helpers/entity/evictionEpoch.d.ts.map +1 -0
  276. package/dist/src/helpers/file/fetchAll/actors.d.ts.map +1 -1
  277. package/dist/src/helpers/getSegmentedItemProperties.d.ts.map +1 -1
  278. package/dist/src/helpers/htmlEmbeddedDataUriPublish.d.ts +31 -3
  279. package/dist/src/helpers/htmlEmbeddedDataUriPublish.d.ts.map +1 -1
  280. package/dist/src/helpers/isPublishedMetadataRow.d.ts +10 -0
  281. package/dist/src/helpers/isPublishedMetadataRow.d.ts.map +1 -0
  282. package/dist/src/helpers/ownership.d.ts.map +1 -1
  283. package/dist/src/helpers/property.d.ts +6 -1
  284. package/dist/src/helpers/property.d.ts.map +1 -1
  285. package/dist/src/helpers/schema.d.ts +14 -4
  286. package/dist/src/helpers/schema.d.ts.map +1 -1
  287. package/dist/src/helpers/tabCoordinator.d.ts +45 -0
  288. package/dist/src/helpers/tabCoordinator.d.ts.map +1 -0
  289. package/dist/src/helpers/tabEvents.d.ts +27 -0
  290. package/dist/src/helpers/tabEvents.d.ts.map +1 -0
  291. package/dist/src/helpers/tabLocks.d.ts +28 -0
  292. package/dist/src/helpers/tabLocks.d.ts.map +1 -0
  293. package/dist/src/helpers/updateSchema.d.ts.map +1 -1
  294. package/dist/src/imports/json.d.ts.map +1 -1
  295. package/dist/src/imports/markdown.d.ts.map +1 -1
  296. package/dist/src/index.d.ts +13 -3
  297. package/dist/src/index.d.ts.map +1 -1
  298. package/dist/src/node/db/Db.d.ts.map +1 -1
  299. package/dist/src/node/helpers/FileManager.d.ts +2 -0
  300. package/dist/src/node/helpers/FileManager.d.ts.map +1 -1
  301. package/dist/src/query/createLocalQueryDataSource.d.ts +4 -0
  302. package/dist/src/query/createLocalQueryDataSource.d.ts.map +1 -1
  303. package/dist/src/seedSchema/MetadataSchema.d.ts +36 -0
  304. package/dist/src/seedSchema/MetadataSchema.d.ts.map +1 -1
  305. package/dist/src/seedSchema/ModelSchema.d.ts +57 -0
  306. package/dist/src/seedSchema/ModelSchema.d.ts.map +1 -1
  307. package/dist/src/seedSchema/SeedSchema.d.ts +19 -0
  308. package/dist/src/seedSchema/SeedSchema.d.ts.map +1 -1
  309. package/dist/src/seedSchema/VersionSchema.d.ts +17 -0
  310. package/dist/src/seedSchema/VersionSchema.d.ts.map +1 -1
  311. package/dist/src/services/write/actors/validateEntity.d.ts.map +1 -1
  312. package/dist/src/services/write/actors/writeToDatabase.d.ts +5 -0
  313. package/dist/src/services/write/actors/writeToDatabase.d.ts.map +1 -1
  314. package/dist/src/services/write/writeProcessMachine.d.ts.map +1 -1
  315. package/dist/src/stores/eas.d.ts +1 -1
  316. package/dist/src/stores/eas.d.ts.map +1 -1
  317. package/dist/src/types/index.d.ts +7 -0
  318. package/dist/src/types/index.d.ts.map +1 -1
  319. package/dist/src/types/item.d.ts +19 -11
  320. package/dist/src/types/item.d.ts.map +1 -1
  321. package/dist/src/types/property.d.ts +3 -2
  322. package/dist/src/types/property.d.ts.map +1 -1
  323. package/dist/syncDbWithEas-BPap9Sru.js +855 -0
  324. package/dist/syncDbWithEas-BPap9Sru.js.map +1 -0
  325. package/dist/{index-280bL-n4.js → tabEvents-C6NXS6Jl.js} +231 -68
  326. package/dist/tabEvents-C6NXS6Jl.js.map +1 -0
  327. package/dist/tolerantWebAccess-NBQ1NB4i.js +160 -0
  328. package/dist/tolerantWebAccess-NBQ1NB4i.js.map +1 -0
  329. package/dist/updateSeedRevokedAt-CYwgVNlM.js +32 -0
  330. package/dist/updateSeedRevokedAt-CYwgVNlM.js.map +1 -0
  331. package/package.json +8 -10
  332. package/dist/BasePathResolver-B6CKqoKw.js.map +0 -1
  333. package/dist/ClientManager-ChcmUL47.js.map +0 -1
  334. package/dist/ModelProperty-D79uV42p.js.map +0 -1
  335. package/dist/Schema-a8uO-hIZ.js.map +0 -1
  336. package/dist/SchemaValidationService-Y49vqast.js.map +0 -1
  337. package/dist/backfillMetadataPropertyIds-CBsf7LnU.js.map +0 -1
  338. package/dist/cjs/ModelProperty-D9FGaGuE.js.map +0 -1
  339. package/dist/cjs/Schema-BiJIPLEL.js.map +0 -1
  340. package/dist/cjs/SchemaValidationService-DtYs_CNY.js.map +0 -1
  341. package/dist/cjs/backfillMetadataPropertyIds-2XaN3b9S.js.map +0 -1
  342. package/dist/cjs/getPublishPayload-D5DhLGvN.js.map +0 -1
  343. package/dist/cjs/getPublishUploads-DMhCCKYF.js.map +0 -1
  344. package/dist/cjs/getSegmentedItemProperties-CU8rtBAo.js +0 -148
  345. package/dist/cjs/getSegmentedItemProperties-CU8rtBAo.js.map +0 -1
  346. package/dist/cjs/index-CSNtEnbF.js.map +0 -1
  347. package/dist/cjs/index-DPp9rdRL.js.map +0 -1
  348. package/dist/cjs/property-DlKiAWt4.js.map +0 -1
  349. package/dist/cjs/syncDbWithEas-C6n34o_Q.js +0 -606
  350. package/dist/cjs/syncDbWithEas-C6n34o_Q.js.map +0 -1
  351. package/dist/db-WbrzEf7c.js.map +0 -1
  352. package/dist/eas-CfYCu4IX.js.map +0 -1
  353. package/dist/getPublishPayload-BIrTVUxb.js.map +0 -1
  354. package/dist/getPublishUploads-C6cDeZdz.js.map +0 -1
  355. package/dist/getSegmentedItemProperties-BmKE71vU.js +0 -148
  356. package/dist/getSegmentedItemProperties-BmKE71vU.js.map +0 -1
  357. package/dist/index-280bL-n4.js.map +0 -1
  358. package/dist/index-ClSv5pTA.js.map +0 -1
  359. package/dist/index-Djd3667v.js.map +0 -1
  360. package/dist/index-HRHkbVQd.js.map +0 -1
  361. package/dist/index.node-DBtQkEfz.js.map +0 -1
  362. package/dist/property-CQjuZ4JW.js.map +0 -1
  363. package/dist/src/Item/service/actors/fetchDataFromEas.d.ts +0 -4
  364. package/dist/src/Item/service/actors/fetchDataFromEas.d.ts.map +0 -1
  365. package/dist/src/Item/service/actors/hydrateExistingItem.d.ts +0 -4
  366. package/dist/src/Item/service/actors/hydrateExistingItem.d.ts.map +0 -1
  367. package/dist/src/Item/service/actors/hydrateNewItem.d.ts +0 -4
  368. package/dist/src/Item/service/actors/hydrateNewItem.d.ts.map +0 -1
  369. package/dist/src/Item/service/actors/initialize.d.ts +0 -4
  370. package/dist/src/Item/service/actors/initialize.d.ts.map +0 -1
  371. package/dist/src/Item/service/actors/reload.d.ts +0 -5
  372. package/dist/src/Item/service/actors/reload.d.ts.map +0 -1
  373. package/dist/src/Item/service/actors/saveDataToDb.d.ts +0 -4
  374. package/dist/src/Item/service/actors/saveDataToDb.d.ts.map +0 -1
  375. package/dist/src/ItemProperty/service/actors/resolveRemoteStorage.d.ts +0 -5
  376. package/dist/src/ItemProperty/service/actors/resolveRemoteStorage.d.ts.map +0 -1
  377. package/dist/src/Schema/service/addModelsMachine.d.ts +0 -123
  378. package/dist/src/Schema/service/addModelsMachine.d.ts.map +0 -1
  379. package/dist/src/browser/helpers/index.d.ts +0 -4
  380. package/dist/src/browser/helpers/index.d.ts.map +0 -1
  381. package/dist/src/db/configs/dev.schema.config.d.ts.map +0 -1
  382. package/dist/src/helpers/file/download/actors.d.ts +0 -17
  383. package/dist/src/helpers/file/download/actors.d.ts.map +0 -1
  384. package/dist/src/helpers/file/download/index.d.ts +0 -70
  385. package/dist/src/helpers/file/download/index.d.ts.map +0 -1
  386. package/dist/src/services/publish/actors/createPublishAttempt.d.ts +0 -4
  387. package/dist/src/services/publish/actors/createPublishAttempt.d.ts.map +0 -1
  388. package/dist/src/services/publish/actors/preparePublishRequestData.d.ts +0 -4
  389. package/dist/src/services/publish/actors/preparePublishRequestData.d.ts.map +0 -1
  390. package/dist/src/services/publish/actors/upload.d.ts +0 -4
  391. package/dist/src/services/publish/actors/upload.d.ts.map +0 -1
  392. package/dist/src/services/publish/actors/validateItemData.d.ts +0 -4
  393. package/dist/src/services/publish/actors/validateItemData.d.ts.map +0 -1
  394. package/dist/src/services/publish/publishMachine.d.ts +0 -32
  395. package/dist/src/services/publish/publishMachine.d.ts.map +0 -1
  396. package/dist/syncDbWithEas-CuARXfyN.js +0 -598
  397. package/dist/syncDbWithEas-CuARXfyN.js.map +0 -1
  398. package/dist/updateSeedRevokedAt-CBcLfHWs.js +0 -22
  399. package/dist/updateSeedRevokedAt-CBcLfHWs.js.map +0 -1
@@ -2,11 +2,11 @@
2
2
 
3
3
  var xstate = require('xstate');
4
4
  require('reflect-metadata');
5
- var main_cjs = require('./index-CSNtEnbF.js');
5
+ var main_cjs = require('./index-Cvvt0-5B.js');
6
6
  require('pluralize');
7
7
  var drizzleOrm = require('drizzle-orm');
8
8
  var debug = require('debug');
9
- var Schema = require('./Schema-BiJIPLEL.js');
9
+ var Schema = require('./Schema-BHVp1g-M.js');
10
10
  require('immer');
11
11
  require('drizzle-orm/sqlite-core');
12
12
  require('@seedprotocol/arweave');
@@ -32,7 +32,7 @@ require('js-yaml');
32
32
  require('child_process');
33
33
  require('@seedprotocol/arweave/node');
34
34
  require('@seedprotocol/eas/node');
35
- require('./SchemaValidationService-DtYs_CNY.js');
35
+ require('./SchemaValidationService-BSU9knjf.js');
36
36
  require('@sinclair/typebox/value');
37
37
 
38
38
  const logger$3 = debug('seedSdk:modelProperty:actors:saveToSchema');
@@ -43,12 +43,12 @@ const logger$3 = debug('seedSdk:modelProperty:actors:saveToSchema');
43
43
  */
44
44
  async function getSchemaNameFromModel(modelName) {
45
45
  // Get the latest schema files and find which one contains this model
46
- const schemaHelpersMod = await Promise.resolve().then(function () { return require('./index-CSNtEnbF.js'); }).then(function (n) { return n.schema$1; });
46
+ const schemaHelpersMod = await Promise.resolve().then(function () { return require('./index-Cvvt0-5B.js'); }).then(function (n) { return n.schema$1; });
47
47
  const { listLatestSchemaFiles } = schemaHelpersMod;
48
48
  const latestSchemas = await listLatestSchemaFiles();
49
49
  for (const schema of latestSchemas) {
50
50
  try {
51
- const fileManagerMod = await Promise.resolve().then(function () { return require('./index-CSNtEnbF.js'); }).then(function (n) { return n.BaseFileManager$1; });
51
+ const fileManagerMod = await Promise.resolve().then(function () { return require('./index-Cvvt0-5B.js'); }).then(function (n) { return n.BaseFileManager$1; });
52
52
  const { BaseFileManager } = fileManagerMod;
53
53
  const content = await BaseFileManager.readFileAsString(schema.filePath);
54
54
  const schemaFile = JSON.parse(content);
@@ -63,10 +63,10 @@ async function getSchemaNameFromModel(modelName) {
63
63
  }
64
64
  return undefined;
65
65
  }
66
- const saveToSchema = xstate.fromCallback(({ sendBack, input: { context } }) => {
66
+ const saveToSchema = xstate.fromCallback(({ sendBack, input: { context }, self }) => {
67
67
  const _saveToSchema = async () => {
68
68
  // Use dynamic import to break circular dependency
69
- const validationServiceMod = await Promise.resolve().then(function () { return require('./SchemaValidationService-DtYs_CNY.js'); });
69
+ const validationServiceMod = await Promise.resolve().then(function () { return require('./SchemaValidationService-BSU9knjf.js'); });
70
70
  const { SchemaValidationService } = validationServiceMod;
71
71
  const validationService = new SchemaValidationService();
72
72
  // Validate property structure before saving
@@ -85,14 +85,17 @@ const saveToSchema = xstate.fromCallback(({ sendBack, input: { context } }) => {
85
85
  throw new Error(`Model not found for modelId: ${context.modelId}`);
86
86
  }
87
87
  // Persist to database only - schema file is updated only when user calls Schema.saveNewVersion()
88
- const dbMod = await Promise.resolve().then(function () { return require('./index-CSNtEnbF.js'); }).then(function (n) { return n.db; });
88
+ const dbMod = await Promise.resolve().then(function () { return require('./index-Cvvt0-5B.js'); }).then(function (n) { return n.db; });
89
89
  const { savePropertyToDb } = dbMod;
90
90
  await savePropertyToDb(context);
91
91
  // Mark schema as draft so user knows to save
92
92
  const schemaName = context._schemaName ?? (await getSchemaNameFromModel(context.modelName));
93
93
  if (schemaName) {
94
- const schemaMod = await Promise.resolve().then(function () { return require('./Schema-BiJIPLEL.js'); });
94
+ const schemaMod = await Promise.resolve().then(function () { return require('./Schema-BHVp1g-M.js'); });
95
95
  const { Schema } = schemaMod;
96
+ // Stopped meanwhile (unloaded, or evicted with its schema): don't load the schema again
97
+ if (main_cjs.isActorStopped(self))
98
+ return;
96
99
  const schema = Schema.create(schemaName, { waitForReady: false });
97
100
  schema.getService().send({
98
101
  type: 'markAsDraft',
@@ -113,7 +116,7 @@ const saveToSchema = xstate.fromCallback(({ sendBack, input: { context } }) => {
113
116
  });
114
117
 
115
118
  const logger$2 = debug('seedSdk:modelProperty:actors:compareAndMarkDraft');
116
- const compareAndMarkDraft = xstate.fromCallback(({ sendBack, input: { context } }) => {
119
+ const compareAndMarkDraft = xstate.fromCallback(({ sendBack, input: { context }, self }) => {
117
120
  const _compareAndMarkDraft = async () => {
118
121
  // Fill modelName/dataType from _originalValues when missing, then from DB by schemaFileId
119
122
  let fullContext = {
@@ -124,7 +127,7 @@ const compareAndMarkDraft = xstate.fromCallback(({ sendBack, input: { context }
124
127
  const schemaFileIdForResolve = fullContext._propertyFileId || (typeof fullContext.id === 'string' ? fullContext.id : undefined);
125
128
  if (schemaFileIdForResolve && (fullContext.modelName === undefined || fullContext.dataType === undefined)) {
126
129
  try {
127
- const dbMod = await Promise.resolve().then(function () { return require('./index-CSNtEnbF.js'); }).then(function (n) { return n.db; });
130
+ const dbMod = await Promise.resolve().then(function () { return require('./index-Cvvt0-5B.js'); }).then(function (n) { return n.db; });
128
131
  const { getPropertyModelNameAndDataType, getModelNameByModelId } = dbMod;
129
132
  let fromDb;
130
133
  for (let attempt = 0; attempt < 6; attempt++) {
@@ -169,7 +172,7 @@ const compareAndMarkDraft = xstate.fromCallback(({ sendBack, input: { context }
169
172
  if (fullContext.modelName && fullContext.name && schemaFileId) {
170
173
  logger$2(`[compareAndMarkDraft] _originalValues not set, but saving to database anyway for property ${context.modelName}:${context.name} (schemaFileId: ${schemaFileId})`);
171
174
  try {
172
- const dbMod = await Promise.resolve().then(function () { return require('./index-CSNtEnbF.js'); }).then(function (n) { return n.db; });
175
+ const dbMod = await Promise.resolve().then(function () { return require('./index-Cvvt0-5B.js'); }).then(function (n) { return n.db; });
173
176
  const { savePropertyToDb } = dbMod;
174
177
  // Ensure _propertyFileId is set for savePropertyToDb to find the property
175
178
  const contextWithFileId = {
@@ -229,7 +232,7 @@ const compareAndMarkDraft = xstate.fromCallback(({ sendBack, input: { context }
229
232
  logger$2(`Property ${fullContext.modelName}:${fullContext.name} has changes, marking as edited`);
230
233
  logger$2(`[compareAndMarkDraft] Context when saving: id=${fullContext.id}, _propertyFileId=${fullContext._propertyFileId}, name=${fullContext.name}, _originalValues.name=${fullContext._originalValues?.name}`);
231
234
  // Use dynamic import to break circular dependency
232
- const dbMod = await Promise.resolve().then(function () { return require('./index-CSNtEnbF.js'); }).then(function (n) { return n.db; });
235
+ const dbMod = await Promise.resolve().then(function () { return require('./index-Cvvt0-5B.js'); }).then(function (n) { return n.db; });
233
236
  const { savePropertyToDb } = dbMod;
234
237
  // Save to database (but not JSON file) - always save to DB when there are changes
235
238
  try {
@@ -243,8 +246,11 @@ const compareAndMarkDraft = xstate.fromCallback(({ sendBack, input: { context }
243
246
  // Mark schema as draft if schema name is available
244
247
  if (fullContext._schemaName) {
245
248
  // Get the Schema instance and mark it as draft
246
- const schemaMod = await Promise.resolve().then(function () { return require('./Schema-BiJIPLEL.js'); });
249
+ const schemaMod = await Promise.resolve().then(function () { return require('./Schema-BHVp1g-M.js'); });
247
250
  const { Schema } = schemaMod;
251
+ // Stopped meanwhile (unloaded, or evicted with its schema): don't load the schema again
252
+ if (main_cjs.isActorStopped(self))
253
+ return;
248
254
  const schema = Schema.create(fullContext._schemaName, {
249
255
  waitForReady: false,
250
256
  });
@@ -260,18 +266,19 @@ const compareAndMarkDraft = xstate.fromCallback(({ sendBack, input: { context }
260
266
  logger$2(`Property ${fullContext.modelName}:${fullContext.name} has no changes`);
261
267
  // Clear isEdited flag in database
262
268
  try {
263
- const seedSchemaMod = await Promise.resolve().then(function () { return require('./index-CSNtEnbF.js'); }).then(function (n) { return n.schema; });
269
+ const seedSchemaMod = await Promise.resolve().then(function () { return require('./index-Cvvt0-5B.js'); }).then(function (n) { return n.schema; });
264
270
  const { properties: propertiesTable, models: modelsTable } = seedSchemaMod;
265
271
  const drizzleMod = await import('drizzle-orm');
266
272
  const { eq, and } = drizzleMod;
267
273
  const db = main_cjs.BaseDb.getAppDb();
268
274
  if (db && fullContext.modelName && fullContext.name) {
269
- // Find model by name
270
- const modelRecords = await db
271
- .select({ id: modelsTable.id })
272
- .from(modelsTable)
273
- .where(eq(modelsTable.name, fullContext.modelName))
274
- .limit(1);
275
+ // Find this property's model (model names are only unique per schema)
276
+ const { resolveModelRecord } = await Promise.resolve().then(function () { return require('./index-Cvvt0-5B.js'); }).then(function (n) { return n.resolveModelRecord$1; });
277
+ const modelRecord = await resolveModelRecord(fullContext.modelName, {
278
+ modelId: typeof fullContext.modelId === 'number' ? fullContext.modelId : undefined,
279
+ schemaName: fullContext._schemaName,
280
+ }, db);
281
+ const modelRecords = modelRecord ? [modelRecord] : [];
275
282
  if (modelRecords.length > 0) {
276
283
  // Find property by name and modelId
277
284
  const propertyRecords = await db
@@ -310,7 +317,7 @@ const compareAndMarkDraft = xstate.fromCallback(({ sendBack, input: { context }
310
317
  });
311
318
 
312
319
  const logger$1 = debug('seedSdk:modelProperty:actors:validateProperty');
313
- const validateProperty = xstate.fromCallback(({ sendBack, input: { context } }) => {
320
+ const validateProperty = xstate.fromCallback(({ sendBack, input: { context }, self }) => {
314
321
  const _validateProperty = async () => {
315
322
  // Use full context for validation: fill modelName/dataType from _originalValues when missing, then
316
323
  // from DB by schemaFileId (context.id) so just-created renames don't fail structure validation.
@@ -324,7 +331,7 @@ const validateProperty = xstate.fromCallback(({ sendBack, input: { context } })
324
331
  // Brief wait so trackPendingWrite from ModelProperty.create() has time to run (it's in setTimeout(0))
325
332
  await new Promise((r) => setTimeout(r, 60));
326
333
  try {
327
- const dbMod = await Promise.resolve().then(function () { return require('./index-CSNtEnbF.js'); }).then(function (n) { return n.db; });
334
+ const dbMod = await Promise.resolve().then(function () { return require('./index-Cvvt0-5B.js'); }).then(function (n) { return n.db; });
328
335
  const { getPropertyModelNameAndDataType, getModelNameByModelId } = dbMod;
329
336
  // Try pending write first (property row may not exist yet)
330
337
  if (fullContext.modelName === undefined && schemaFileId) {
@@ -376,10 +383,10 @@ const validateProperty = xstate.fromCallback(({ sendBack, input: { context } })
376
383
  fullContext = { ...fullContext, dataType: (fullContext.dataType ?? context._originalValues?.dataType) || 'Text' };
377
384
  }
378
385
  // Use dynamic imports to break circular dependencies
379
- const validationServiceMod = await Promise.resolve().then(function () { return require('./SchemaValidationService-DtYs_CNY.js'); });
386
+ const validationServiceMod = await Promise.resolve().then(function () { return require('./SchemaValidationService-BSU9knjf.js'); });
380
387
  const { SchemaValidationService } = validationServiceMod;
381
388
  const validationService = new SchemaValidationService();
382
- const schemaMod = await Promise.resolve().then(function () { return require('./Schema-BiJIPLEL.js'); });
389
+ const schemaMod = await Promise.resolve().then(function () { return require('./Schema-BHVp1g-M.js'); });
383
390
  const { Schema } = schemaMod;
384
391
  // Validate property structure
385
392
  const structureResult = validationService.validatePropertyStructure(fullContext);
@@ -388,6 +395,9 @@ const validateProperty = xstate.fromCallback(({ sendBack, input: { context } })
388
395
  return;
389
396
  }
390
397
  // If we have schema name and model name, validate against schema
398
+ // Stopped meanwhile (unloaded, or evicted with its schema): don't load the schema again
399
+ if (main_cjs.isActorStopped(self))
400
+ return;
391
401
  if (fullContext._schemaName && fullContext.modelName) {
392
402
  try {
393
403
  const schema = Schema.create(fullContext._schemaName, {
@@ -481,9 +491,6 @@ const modelPropertyMachine = xstate.setup({
481
491
  const valid = !context._validationErrors || context._validationErrors.length === 0;
482
492
  return valid;
483
493
  },
484
- hasValidationErrors: ({ context }) => {
485
- return !!context._validationErrors && context._validationErrors.length > 0;
486
- },
487
494
  },
488
495
  actions: {
489
496
  assignValidationErrors: xstate.assign(({ context, event }) => {
@@ -582,7 +589,8 @@ const modelPropertyMachine = xstate.setup({
582
589
  actions: xstate.assign(({ context, event }) => ({
583
590
  ...context,
584
591
  _originalValues: event.originalValues,
585
- _schemaName: event.schemaName,
592
+ // Senders don't know the schema name; keep one setSchemaName already stored.
593
+ _schemaName: event.schemaName ?? context._schemaName,
586
594
  _isEdited: event.isEdited ?? false,
587
595
  _validationErrors: undefined,
588
596
  })),
@@ -601,22 +609,15 @@ const modelPropertyMachine = xstate.setup({
601
609
  })),
602
610
  },
603
611
  destroyStarted: {
604
- actions: xstate.assign({ _destroyInProgress: true, _destroyError: null }),
605
- },
606
- destroyDone: {
607
- actions: xstate.assign({ _destroyInProgress: false }),
612
+ actions: xstate.assign({ _destroyError: null }),
608
613
  },
609
614
  destroyError: {
610
615
  actions: xstate.assign(({ event }) => ({
611
- _destroyInProgress: false,
612
616
  _destroyError: event.error instanceof Error
613
617
  ? { message: event.error.message, name: event.error.name }
614
618
  : { message: String(event.error) },
615
619
  })),
616
620
  },
617
- clearDestroyError: {
618
- actions: xstate.assign({ _destroyError: null }),
619
- },
620
621
  },
621
622
  states: {
622
623
  idle: {
@@ -691,11 +692,9 @@ const modelPropertyMachine = xstate.setup({
691
692
  },
692
693
  },
693
694
  saveToSchema: {
694
- always: {
695
- guard: 'isPropertyValid',
696
- target: '.saving',
697
- },
698
- initial: 'saving',
695
+ // Gate the save in a transient child. An `always` on this parent targeting `.saving` re-enters
696
+ // the invoking child on every microstep and never settles (save() ran the process out of memory).
697
+ initial: 'checking',
699
698
  on: {
700
699
  // Apply updateContext but do not re-invoke saveToSchema actor (avoids infinite loop).
701
700
  // Context is updated; in-flight save completes with original context.
@@ -772,6 +771,12 @@ const modelPropertyMachine = xstate.setup({
772
771
  },
773
772
  },
774
773
  states: {
774
+ checking: {
775
+ always: [
776
+ { guard: 'isPropertyValid', target: 'saving' },
777
+ { target: '#modelProperty.idle' },
778
+ ],
779
+ },
775
780
  saving: {
776
781
  on: {
777
782
  saveToSchemaSuccess: {
@@ -835,6 +840,8 @@ const TPropertyKeys = [
835
840
  ];
836
841
  class ModelProperty {
837
842
  constructor(property) {
843
+ /** currentEvictionEpoch() at construction: lookups started for this instance don't outlive an eviction. */
844
+ this._evictionEpoch = main_cjs.currentEvictionEpoch();
838
845
  // id is now the schemaFileId (string), _dbId is the database integer ID
839
846
  // Preserve _propertyFileId if it exists in the property object (from getPropertySchema)
840
847
  // Convert null to undefined for optional fields (TypeBox validation expects undefined, not null)
@@ -854,6 +861,15 @@ class ModelProperty {
854
861
  this._initializeOriginalValues(property);
855
862
  // Note: Property getters/setters are now handled by the Proxy in create()
856
863
  }
864
+ /**
865
+ * Send from fire-and-forget async work (DB lookups started in the constructor), which can finish
866
+ * after the instance was unloaded or evicted with its schema.
867
+ */
868
+ _sendIfRunning(event) {
869
+ if (main_cjs.isActorStopped(this._service))
870
+ return;
871
+ this._service.send(event);
872
+ }
857
873
  /**
858
874
  * Initialize original values and schema name for tracking changes
859
875
  * This is called asynchronously after construction
@@ -865,10 +881,10 @@ class ModelProperty {
865
881
  const refModelName = property.refModelName || property.ref;
866
882
  if (refModelName && !property.refModelId) {
867
883
  // Resolve refModelId asynchronously and update context
868
- this._resolveRefModelId(refModelName).then((refModelId) => {
884
+ this._resolveRefModelId(refModelName, property).then((refModelId) => {
869
885
  if (refModelId) {
870
886
  // Update the context with the resolved refModelId
871
- this._service.send({
887
+ this._sendIfRunning({
872
888
  type: 'updateContext',
873
889
  refModelId,
874
890
  });
@@ -936,7 +952,7 @@ class ModelProperty {
936
952
  // Initialize with original values, including isEdited flag
937
953
  // Load isEdited from database if property exists in DB (async, fire-and-forget)
938
954
  this._loadIsEditedFromDb(property, isEdited).then((isEditedFromDb) => {
939
- this._service.send({
955
+ this._sendIfRunning({
940
956
  type: 'initializeOriginalValues',
941
957
  originalValues,
942
958
  schemaName: undefined, // Will be set later if needed
@@ -944,7 +960,7 @@ class ModelProperty {
944
960
  });
945
961
  }).catch(() => {
946
962
  // If we can't load from DB, use computed isEdited value
947
- this._service.send({
963
+ this._sendIfRunning({
948
964
  type: 'initializeOriginalValues',
949
965
  originalValues,
950
966
  schemaName: undefined, // Will be set later if needed
@@ -959,7 +975,7 @@ class ModelProperty {
959
975
  originalValues[key] = property[key];
960
976
  }
961
977
  });
962
- this._service.send({
978
+ this._sendIfRunning({
963
979
  type: 'initializeOriginalValues',
964
980
  originalValues,
965
981
  schemaName: undefined,
@@ -967,7 +983,7 @@ class ModelProperty {
967
983
  });
968
984
  // Get schema name from model asynchronously (fire-and-forget)
969
985
  if (property.modelName) {
970
- this._setSchemaName(property.modelName).catch(() => {
986
+ this._setSchemaName(property).catch(() => {
971
987
  // If we can't get schema name, that's okay - it will be set later if needed
972
988
  });
973
989
  }
@@ -987,12 +1003,10 @@ class ModelProperty {
987
1003
  if (!db) {
988
1004
  return fallbackIsEdited;
989
1005
  }
990
- // Find model by name
991
- const modelRecords = await db
992
- .select({ id: main_cjs.models.id })
993
- .from(main_cjs.models)
994
- .where(drizzleOrm.eq(main_cjs.models.name, property.modelName))
995
- .limit(1);
1006
+ // Find this property's model (by modelId when known; model names are only unique per schema)
1007
+ const { resolveModelRecord } = await Promise.resolve().then(function () { return require('./index-Cvvt0-5B.js'); }).then(function (n) { return n.resolveModelRecord$1; });
1008
+ const modelRecord = await resolveModelRecord(property.modelName, this._ownerModelScope(property), db);
1009
+ const modelRecords = modelRecord ? [modelRecord] : [];
996
1010
  if (modelRecords.length === 0) {
997
1011
  return fallbackIsEdited;
998
1012
  }
@@ -1016,7 +1030,7 @@ class ModelProperty {
1016
1030
  * @param refModelName - The name of the referenced model
1017
1031
  * @returns The database ID of the referenced model, or undefined if not found
1018
1032
  */
1019
- async _resolveRefModelId(refModelName) {
1033
+ async _resolveRefModelId(refModelName, property) {
1020
1034
  if (!refModelName) {
1021
1035
  return undefined;
1022
1036
  }
@@ -1025,13 +1039,11 @@ class ModelProperty {
1025
1039
  if (!db) {
1026
1040
  return undefined;
1027
1041
  }
1028
- const refModelRecords = await db
1029
- .select()
1030
- .from(main_cjs.models)
1031
- .where(drizzleOrm.eq(main_cjs.models.name, refModelName))
1032
- .limit(1);
1033
- if (refModelRecords.length > 0 && refModelRecords[0].id) {
1034
- return refModelRecords[0].id;
1042
+ // Resolve the ref within the owning model's schema
1043
+ const { resolveRefModelRecord } = await Promise.resolve().then(function () { return require('./index-Cvvt0-5B.js'); }).then(function (n) { return n.resolveModelRecord$1; });
1044
+ const refModelRecord = await resolveRefModelRecord(refModelName, property ? this._ownerModelScope(property) : { schemaName: this._getSnapshotContext()._schemaName }, db);
1045
+ if (refModelRecord?.id) {
1046
+ return refModelRecord.id;
1035
1047
  }
1036
1048
  }
1037
1049
  catch (error) {
@@ -1040,6 +1052,15 @@ class ModelProperty {
1040
1052
  }
1041
1053
  return undefined;
1042
1054
  }
1055
+ /** Which model this property belongs to: its models row id and/or schema. */
1056
+ _ownerModelScope(property) {
1057
+ const context = this._getSnapshotContext();
1058
+ const modelId = property.modelId ?? context.modelId;
1059
+ return {
1060
+ modelId: typeof modelId === 'number' ? modelId : undefined,
1061
+ schemaName: context._schemaName,
1062
+ };
1063
+ }
1043
1064
  /**
1044
1065
  * Get schema file values for this property to use as "original" values
1045
1066
  * This allows comparison with database values to detect edits
@@ -1049,7 +1070,40 @@ class ModelProperty {
1049
1070
  return undefined;
1050
1071
  }
1051
1072
  try {
1052
- const model = await main_cjs.Model.getByNameAsync(property.modelName);
1073
+ const { modelId, schemaName } = this._ownerModelScope(property);
1074
+ // Synchronous cache hits first: callers compare against these values right after construction,
1075
+ // so an extra await here lets every property look "edited" (a draft save each). Only then the
1076
+ // DB (by modelId), and never instantiate a Model while its own properties are initializing.
1077
+ let model = schemaName ? main_cjs.Model.getByName(property.modelName, schemaName) : undefined;
1078
+ if (!model) {
1079
+ try {
1080
+ model = main_cjs.Model.getByName(property.modelName);
1081
+ }
1082
+ catch {
1083
+ model = undefined; // ambiguous name; resolve by modelId below
1084
+ }
1085
+ }
1086
+ if (!model && modelId) {
1087
+ const { resolveModelRecord } = await Promise.resolve().then(function () { return require('./index-Cvvt0-5B.js'); }).then(function (n) { return n.resolveModelRecord$1; });
1088
+ const modelFileId = (await resolveModelRecord(property.modelName, { modelId }))?.schemaFileId;
1089
+ model = modelFileId ? main_cjs.Model.getById(modelFileId) : undefined;
1090
+ }
1091
+ // Evicted (with its schema) or unloaded while the lookups above ran: don't instantiate its model
1092
+ // again from rows that are being deleted.
1093
+ if (!model && main_cjs.isActorStopped(this._service))
1094
+ return undefined;
1095
+ if (!model) {
1096
+ try {
1097
+ // The epoch from when this instance was built: an eviction of the model's schema since
1098
+ // then (this instance may already be stopped) must not re-create the model.
1099
+ model = await main_cjs.Model.getByNameAsync(property.modelName, undefined, {
1100
+ evictionEpoch: this._evictionEpoch,
1101
+ });
1102
+ }
1103
+ catch {
1104
+ model = undefined;
1105
+ }
1106
+ }
1053
1107
  if (!model || !model.properties || model.properties.length === 0) {
1054
1108
  return undefined;
1055
1109
  }
@@ -1073,7 +1127,7 @@ class ModelProperty {
1073
1127
  originalValues.ref = schemaFileValue.ref;
1074
1128
  originalValues.refModelName = schemaFileValue.ref;
1075
1129
  // Try to get refModelId from database
1076
- const refModelId = await this._resolveRefModelId(schemaFileValue.ref);
1130
+ const refModelId = await this._resolveRefModelId(schemaFileValue.ref, property);
1077
1131
  if (refModelId) {
1078
1132
  originalValues.refModelId = refModelId;
1079
1133
  }
@@ -1091,11 +1145,19 @@ class ModelProperty {
1091
1145
  * Set the schema name for this property by looking it up from the model
1092
1146
  * Tries database first (more reliable), then falls back to schema files
1093
1147
  */
1094
- async _setSchemaName(modelName) {
1148
+ async _setSchemaName(property) {
1095
1149
  try {
1150
+ // create() sets the schema name right after construction when its caller knows it. Don't look it
1151
+ // up then: the file fallback below reads and parses every schema file, per property.
1152
+ await Promise.resolve();
1153
+ if (this._getSnapshotContext()._schemaName)
1154
+ return;
1096
1155
  let schemaName;
1156
+ // From the property data: the instance's own modelId field is never assigned (the reactive proxy
1157
+ // serves values from the machine context), so reading this.modelId skipped the DB lookup.
1158
+ const { modelId } = this._ownerModelScope(property);
1097
1159
  // Try to get schema name from database first (more reliable)
1098
- if (this.modelId) {
1160
+ if (modelId) {
1099
1161
  try {
1100
1162
  const db = main_cjs.BaseDb.getAppDb();
1101
1163
  if (db) {
@@ -1106,7 +1168,7 @@ class ModelProperty {
1106
1168
  .from(main_cjs.modelSchemas)
1107
1169
  .innerJoin(main_cjs.schemas, drizzleOrm.eq(main_cjs.modelSchemas.schemaId, main_cjs.schemas.id))
1108
1170
  .innerJoin(main_cjs.models, drizzleOrm.eq(main_cjs.modelSchemas.modelId, main_cjs.models.id))
1109
- .where(drizzleOrm.eq(main_cjs.models.id, this.modelId))
1171
+ .where(drizzleOrm.eq(main_cjs.models.id, modelId))
1110
1172
  .limit(1);
1111
1173
  if (modelSchemaRecords.length > 0) {
1112
1174
  schemaName = modelSchemaRecords[0].schemaName;
@@ -1119,11 +1181,11 @@ class ModelProperty {
1119
1181
  }
1120
1182
  // Fall back to schema file lookup if database didn't work
1121
1183
  if (!schemaName) {
1122
- schemaName = await getSchemaNameFromModel(modelName);
1184
+ schemaName = await getSchemaNameFromModel(property.modelName);
1123
1185
  }
1124
1186
  if (schemaName) {
1125
1187
  // Update the context with the schema name using dedicated event
1126
- this._service.send({
1188
+ this._sendIfRunning({
1127
1189
  type: 'setSchemaName',
1128
1190
  schemaName,
1129
1191
  });
@@ -1220,11 +1282,32 @@ class ModelProperty {
1220
1282
  logger(`ModelProperty.create: Generated new id (schemaFileId) "${propertyWithId.id}" for property "${property.name}"`);
1221
1283
  }
1222
1284
  // Create cache key from modelName and name, or use id
1223
- const cacheKey = propertyWithId.modelName && propertyWithId.name
1285
+ let cacheKey = propertyWithId.modelName && propertyWithId.name
1224
1286
  ? `${propertyWithId.modelName}:${propertyWithId.name}`
1225
1287
  : propertyWithId.id
1226
1288
  ? `id:${propertyWithId.id}`
1227
1289
  : propertyWithId.name || 'unnamed';
1290
+ // Model names are only unique per schema: a cached "Post:title" may be another schema's
1291
+ // property. If the ids say it's a different property, key this one by its own id instead.
1292
+ // (Not by file id: the same property is often created first with a generated id, then its real one.)
1293
+ const isOtherProperty = (cachedContext) => (typeof propertyWithId.modelId === 'number' &&
1294
+ typeof cachedContext.modelId === 'number' &&
1295
+ cachedContext.modelId !== propertyWithId.modelId) ||
1296
+ (!!schemaName && !!cachedContext._schemaName && cachedContext._schemaName !== schemaName);
1297
+ const cachedByName = this.instanceCache.get(cacheKey);
1298
+ if (cachedByName && propertyWithId.id && isOtherProperty(cachedByName.instance._getSnapshotContext())) {
1299
+ // Reuse this property's own id-keyed entry if it already has one.
1300
+ cacheKey = `id:${propertyWithId.id}`;
1301
+ for (const [key, { instance }] of this.instanceCache.entries()) {
1302
+ if (!key.startsWith('id:'))
1303
+ continue;
1304
+ const ctx = instance._getSnapshotContext();
1305
+ if (ctx.modelName === propertyWithId.modelName && ctx.name === propertyWithId.name && !isOtherProperty(ctx)) {
1306
+ cacheKey = key;
1307
+ break;
1308
+ }
1309
+ }
1310
+ }
1228
1311
  // Check if instance exists in cache
1229
1312
  if (this.instanceCache.has(cacheKey)) {
1230
1313
  const { instance, refCount } = this.instanceCache.get(cacheKey);
@@ -1286,11 +1369,15 @@ class ModelProperty {
1286
1369
  instance: proxiedInstance,
1287
1370
  refCount: 1,
1288
1371
  });
1372
+ this.indexCachedInstance(cacheKey, proxiedInstance);
1289
1373
  // Trigger write process if property has modelId (or modelName) and id (schemaFileId)
1290
1374
  // Wait for service to be ready (idle state) and have writeProcess spawned
1291
1375
  const propertyFileId = propertyWithId.id; // id is now the schemaFileId (string)
1292
1376
  const hasModelId = propertyWithId.modelId || propertyWithId.modelName;
1293
- if (hasModelId && propertyFileId) {
1377
+ // A _dbId means the data was loaded from an existing row (createById, getPropertySchema), so
1378
+ // there's nothing to write. Writing it back anyway raced deletes of that row's model (FK error).
1379
+ const isPersisted = typeof propertyWithId._dbId === 'number';
1380
+ if (hasModelId && propertyFileId && !isPersisted) {
1294
1381
  // Wait for writeProcess to be spawned (it's spawned in idle state entry action)
1295
1382
  // Retry a few times if writeProcess isn't available yet
1296
1383
  let retries = 0;
@@ -1298,6 +1385,9 @@ class ModelProperty {
1298
1385
  const checkAndSend = async () => {
1299
1386
  const service = proxiedInstance.getService();
1300
1387
  const snapshot = service.getSnapshot();
1388
+ // Unloaded or evicted (e.g. Schema.destroy) before the write started: nothing to write to
1389
+ if (main_cjs.isActorStopped(service))
1390
+ return;
1301
1391
  if (snapshot.value === 'idle' && snapshot.context.writeProcess) {
1302
1392
  const writeProcess = snapshot.context.writeProcess;
1303
1393
  // Resolve dbModelId - convert from string (modelFileId) to number (database ID) if needed
@@ -1337,14 +1427,17 @@ class ModelProperty {
1337
1427
  // Don't clear pending write here - it might resolve later
1338
1428
  return;
1339
1429
  }
1430
+ // Resolving the modelId awaited the DB; the instance may have been stopped meanwhile
1431
+ if (main_cjs.isActorStopped(service))
1432
+ return;
1340
1433
  // Track pending write now that we have the resolved modelId
1341
1434
  this.trackPendingWrite(propertyFileId, resolvedModelId);
1342
1435
  logger(`Triggering write process for property "${property.name}" (modelId: ${resolvedModelId}, propertyFileId: ${propertyFileId})`);
1343
1436
  // Check current write state
1344
1437
  const currentWriteState = writeProcess.getSnapshot();
1345
1438
  if (currentWriteState.value === 'success') {
1346
- // Write already succeeded, clear pending write immediately
1347
- this.clearPendingWrite(propertyFileId, 'success');
1439
+ // Write already succeeded
1440
+ void this.completePendingWrite(propertyFileId, resolvedModelId);
1348
1441
  }
1349
1442
  else {
1350
1443
  // Set up subscription to catch future state changes
@@ -1352,8 +1445,7 @@ class ModelProperty {
1352
1445
  if (writeSnapshot.value === 'success') {
1353
1446
  writeSubscription.unsubscribe();
1354
1447
  logger(`[writeProcess subscription] Write succeeded for property "${property.name}" (propertyFileId: ${propertyFileId})`);
1355
- // Clear pending write on success
1356
- this.clearPendingWrite(propertyFileId, 'success');
1448
+ void this.completePendingWrite(propertyFileId, resolvedModelId);
1357
1449
  }
1358
1450
  else if (writeSnapshot.value === 'error') {
1359
1451
  writeSubscription.unsubscribe();
@@ -1371,6 +1463,7 @@ class ModelProperty {
1371
1463
  dataType: property.dataType,
1372
1464
  refModelId: property.refModelId,
1373
1465
  refValueType: property.refValueType,
1466
+ required: property.required,
1374
1467
  storageType: property.storageType,
1375
1468
  localStorageDir: property.localStorageDir,
1376
1469
  filenameSuffix: property.filenameSuffix,
@@ -1398,18 +1491,56 @@ class ModelProperty {
1398
1491
  return proxiedInstance;
1399
1492
  return main_cjs.waitForEntityIdle(proxiedInstance, { timeout: readyTimeout }).then(() => proxiedInstance);
1400
1493
  }
1494
+ /** Whether an idIndex entry still points at a cached instance with that id. */
1495
+ static isIndexEntryCurrent(propertyFileId, entry) {
1496
+ if (this.instanceCache.get(entry.cacheKey)?.instance !== entry.instance)
1497
+ return false;
1498
+ try {
1499
+ return entry.instance._getSnapshotContext().id === propertyFileId;
1500
+ }
1501
+ catch {
1502
+ return false;
1503
+ }
1504
+ }
1505
+ /** Add a newly cached instance to idIndex, and keep its entry current when its id changes. */
1506
+ static indexCachedInstance(cacheKey, instance) {
1507
+ const index = (id) => {
1508
+ if (!id)
1509
+ return;
1510
+ const existing = this.idIndex.get(id);
1511
+ // Keep the instance cached first, as the old scan in insertion order returned
1512
+ if (existing && existing.instance !== instance && this.isIndexEntryCurrent(id, existing))
1513
+ return;
1514
+ this.idIndex.set(id, { cacheKey, instance });
1515
+ };
1516
+ let indexedId = instance._getSnapshotContext().id;
1517
+ index(indexedId);
1518
+ instance._service.subscribe((snapshot) => {
1519
+ const id = snapshot.context.id;
1520
+ if (id === indexedId)
1521
+ return;
1522
+ indexedId = id;
1523
+ index(id);
1524
+ });
1525
+ }
1401
1526
  /**
1402
1527
  * Get ModelProperty instance by propertyFileId from static cache
1403
1528
  */
1404
1529
  static getById(propertyFileId) {
1405
1530
  if (!propertyFileId)
1406
1531
  return undefined;
1407
- // Search through cache to find by propertyFileId
1532
+ const indexed = this.idIndex.get(propertyFileId);
1533
+ if (!indexed)
1534
+ return undefined;
1535
+ if (this.isIndexEntryCurrent(propertyFileId, indexed))
1536
+ return indexed.instance;
1537
+ // The indexed instance left the cache or changed id; another cached instance may still have it.
1408
1538
  // Cache key might be "modelName:propertyName" or "id:propertyId"
1539
+ this.idIndex.delete(propertyFileId);
1409
1540
  for (const [cacheKey, { instance }] of this.instanceCache.entries()) {
1410
- const context = instance._getSnapshotContext();
1411
1541
  // id is now the schemaFileId (string)
1412
- if (context.id === propertyFileId) {
1542
+ if (instance._getSnapshotContext().id === propertyFileId) {
1543
+ this.idIndex.set(propertyFileId, { cacheKey, instance });
1413
1544
  return instance;
1414
1545
  }
1415
1546
  }
@@ -1419,7 +1550,7 @@ class ModelProperty {
1419
1550
  * Create or get ModelProperty instance by propertyFileId
1420
1551
  * Queries the database to find the property if not cached
1421
1552
  */
1422
- static async createById(propertyFileId) {
1553
+ static async createById(propertyFileId, options) {
1423
1554
  if (!propertyFileId) {
1424
1555
  return undefined;
1425
1556
  }
@@ -1433,10 +1564,7 @@ class ModelProperty {
1433
1564
  if (!db) {
1434
1565
  return undefined;
1435
1566
  }
1436
- await db
1437
- .select()
1438
- .from(main_cjs.properties)
1439
- .limit(100);
1567
+ const evictionEpoch = options?.evictionEpoch ?? main_cjs.currentEvictionEpoch();
1440
1568
  const propertyRecords = await db
1441
1569
  .select()
1442
1570
  .from(main_cjs.properties)
@@ -1468,6 +1596,9 @@ class ModelProperty {
1468
1596
  refModelId: propertyRecord.refModelId || undefined,
1469
1597
  refValueType: propertyRecord.refValueType ? propertyRecord.refValueType : undefined,
1470
1598
  required: propertyRecord.required ?? false,
1599
+ storageType: propertyRecord.storageType ?? undefined,
1600
+ localStorageDir: propertyRecord.localStorageDir ?? undefined,
1601
+ filenameSuffix: propertyRecord.filenameSuffix ?? undefined,
1471
1602
  };
1472
1603
  // Load isEdited from database
1473
1604
  const isEditedFromDb = propertyRecord.isEdited ?? false;
@@ -1483,6 +1614,19 @@ class ModelProperty {
1483
1614
  propertyData.ref = refModelRecords[0].name;
1484
1615
  }
1485
1616
  }
1617
+ // Its model's schema was evicted while we read the rows (e.g. a model's property lookup in flight
1618
+ // during Schema.destroy or test cleanup): don't bring the property back.
1619
+ if (main_cjs.anyEvictionSince(evictionEpoch)) {
1620
+ const schemaRows = await db
1621
+ .select({ name: main_cjs.schemas.name })
1622
+ .from(main_cjs.modelSchemas)
1623
+ .innerJoin(main_cjs.schemas, drizzleOrm.eq(main_cjs.schemas.id, main_cjs.modelSchemas.schemaId))
1624
+ .where(drizzleOrm.eq(main_cjs.modelSchemas.modelId, propertyRecord.modelId));
1625
+ if (schemaRows.length === 0 ||
1626
+ schemaRows.some((row) => main_cjs.schemaEvictedSince(row.name, evictionEpoch))) {
1627
+ return undefined;
1628
+ }
1629
+ }
1486
1630
  // Create ModelProperty instance (sync for createById so we can send updateContext)
1487
1631
  const instance = this.create(propertyData, { waitForReady: false });
1488
1632
  // Set isEdited from database after creation
@@ -1549,6 +1693,20 @@ class ModelProperty {
1549
1693
  timestamp: Date.now(),
1550
1694
  });
1551
1695
  }
1696
+ /**
1697
+ * A property write succeeded: add the property to its model's property ids, then drop the pending
1698
+ * write. In that order, `Model.properties` (property ids + pending writes) never misses it; in Node,
1699
+ * where the Model has no reactive liveQuery, nothing else would add it.
1700
+ */
1701
+ static async completePendingWrite(propertyFileId, modelId) {
1702
+ try {
1703
+ await main_cjs.Model.refreshPropertiesForDbId(modelId);
1704
+ }
1705
+ catch (error) {
1706
+ logger(`Refreshing properties of model ${modelId} after writing "${propertyFileId}" failed: ${error}`);
1707
+ }
1708
+ this.clearPendingWrite(propertyFileId, 'success');
1709
+ }
1552
1710
  /**
1553
1711
  * Clear or update pending write status
1554
1712
  */
@@ -1687,6 +1845,36 @@ class ModelProperty {
1687
1845
  logger('ModelProperty.reload() called - ModelProperty is loaded as part of Model/Schema. Reload the parent Model or Schema instead.');
1688
1846
  // No-op for now, but could be enhanced to reload from DB if needed
1689
1847
  }
1848
+ /**
1849
+ * Force-evict cached ModelProperty instances for the given models, ignoring refCounts, and stop
1850
+ * their services. Used by Schema.destroy() so a re-imported schema gets fresh instances instead of
1851
+ * ones holding a deleted row's _dbId.
1852
+ */
1853
+ static evictForModels(modelNames, schemaName) {
1854
+ if (modelNames.length === 0)
1855
+ return;
1856
+ const names = new Set(modelNames);
1857
+ for (const [cacheKey, { instance }] of this.instanceCache.entries()) {
1858
+ let context;
1859
+ try {
1860
+ context = instance._getSnapshotContext();
1861
+ }
1862
+ catch {
1863
+ continue;
1864
+ }
1865
+ if (!context.modelName || !names.has(context.modelName))
1866
+ continue;
1867
+ if (schemaName && context._schemaName && context._schemaName !== schemaName)
1868
+ continue;
1869
+ this.instanceCache.delete(cacheKey);
1870
+ try {
1871
+ instance._service.stop();
1872
+ }
1873
+ catch {
1874
+ // Service might already be stopped
1875
+ }
1876
+ }
1877
+ }
1690
1878
  unload() {
1691
1879
  // ModelProperty doesn't have liveQuery subscriptions or complex cache management
1692
1880
  // Just stop the service
@@ -1702,13 +1890,24 @@ class ModelProperty {
1702
1890
  */
1703
1891
  async destroy() {
1704
1892
  const context = this._getSnapshotContext();
1705
- const cacheKey = context.modelName && context.name
1706
- ? `${context.modelName}:${context.name}`
1707
- : (context.id ?? '');
1708
- if (!cacheKey)
1893
+ // Stored under "modelName:name", or "id:<id>" when another schema's same-name property holds that key
1894
+ const cacheKeys = [...ModelProperty.instanceCache.entries()]
1895
+ .filter(([, entry]) => {
1896
+ try {
1897
+ return entry.instance._getSnapshotContext().id === context.id;
1898
+ }
1899
+ catch {
1900
+ return false;
1901
+ }
1902
+ })
1903
+ .map(([key]) => key);
1904
+ if (cacheKeys.length === 0 && context.modelName && context.name) {
1905
+ cacheKeys.push(`${context.modelName}:${context.name}`);
1906
+ }
1907
+ if (cacheKeys.length === 0)
1709
1908
  return;
1710
1909
  main_cjs.forceRemoveFromCaches(this, {
1711
- getCacheKeys: () => [cacheKey],
1910
+ getCacheKeys: () => cacheKeys,
1712
1911
  caches: [ModelProperty.instanceCache],
1713
1912
  });
1714
1913
  await main_cjs.runDestroyLifecycle(this, {
@@ -1757,6 +1956,15 @@ class ModelProperty {
1757
1956
  }
1758
1957
  }
1759
1958
  ModelProperty.instanceCache = new Map();
1959
+ /**
1960
+ * propertyFileId -> where the instance with that id is cached, so getById doesn't scan the cache
1961
+ * (a model's properties are looked up one by one, which made loading one model O(n²)).
1962
+ * Every cached instance's current id has an entry: it's added when the instance is cached and
1963
+ * again whenever its context id changes (a property is often created with a generated id and
1964
+ * then gets its real one). Entries aren't removed when an instance leaves the cache or changes
1965
+ * id; getById checks an entry before using it.
1966
+ */
1967
+ ModelProperty.idIndex = new Map();
1760
1968
  // Pending writes tracking
1761
1969
  ModelProperty.pendingWrites = new Map();
1762
1970
 
@@ -1766,4 +1974,4 @@ var ModelProperty$1 = /*#__PURE__*/Object.freeze({
1766
1974
  });
1767
1975
 
1768
1976
  exports.ModelProperty = ModelProperty;
1769
- //# sourceMappingURL=ModelProperty-D9FGaGuE.js.map
1977
+ //# sourceMappingURL=ModelProperty-Dv7AQfmQ.js.map