@seedprotocol/sdk 0.7.7 → 0.7.8-next.1066.gac32194

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 (302) hide show
  1. package/dist/{ClientManager-2GtDWHq6.js → ClientManager-Dcju5x4k.js} +835 -80
  2. package/dist/ClientManager-Dcju5x4k.js.map +1 -0
  3. package/dist/{Item-D6j0IvBP.js → Item-DZfNz7xl.js} +2145 -1354
  4. package/dist/Item-DZfNz7xl.js.map +1 -0
  5. package/dist/{ModelProperty-B52C3CQ2.js → ModelProperty-sMGL-_LK.js} +51 -52
  6. package/dist/ModelProperty-sMGL-_LK.js.map +1 -0
  7. package/dist/{Schema-O1QLoXv6.js → Schema-D-TczaIj.js} +106 -91
  8. package/dist/Schema-D-TczaIj.js.map +1 -0
  9. package/dist/{SchemaValidationService-BxCbfDaI.js → SchemaValidationService-NYTtSCxd.js} +6 -6
  10. package/dist/{SchemaValidationService-BxCbfDaI.js.map → SchemaValidationService-NYTtSCxd.js.map} +1 -1
  11. package/dist/{backfillMetadataPropertyIds-CzSbuucw.js → backfillMetadataPropertyIds-DEvD0OAT.js} +3 -3
  12. package/dist/{backfillMetadataPropertyIds-CzSbuucw.js.map → backfillMetadataPropertyIds-DEvD0OAT.js.map} +1 -1
  13. package/dist/{configurePlatform-Bbpw_R4y.js → configurePlatform-CtA7fydC.js} +2 -2
  14. package/dist/{configurePlatform-Bbpw_R4y.js.map → configurePlatform-CtA7fydC.js.map} +1 -1
  15. package/dist/db/drizzle/0020_add_pending_writes.sql +24 -0
  16. package/dist/db/drizzle/0021_add_pending_write_error_name.sql +1 -0
  17. package/dist/db/drizzle/meta/0020_snapshot.json +1542 -0
  18. package/dist/db/drizzle/meta/0021_snapshot.json +1549 -0
  19. package/dist/db/drizzle/meta/_journal.json +14 -0
  20. package/dist/{detachRowsBeforeDelete-D1TyEMco.js → detachRowsBeforeDelete-CLbBbpX4.js} +2 -2
  21. package/dist/{detachRowsBeforeDelete-D1TyEMco.js.map → detachRowsBeforeDelete-CLbBbpX4.js.map} +1 -1
  22. package/dist/dist/{ClientManager-2GtDWHq6.d.ts → ClientManager-Dcju5x4k.d.ts} +393 -292
  23. package/dist/dist/ClientManager-Dcju5x4k.d.ts.map +1 -0
  24. package/dist/dist/{Item-D6j0IvBP.d.ts → Item-DZfNz7xl.d.ts} +456 -266
  25. package/dist/dist/Item-DZfNz7xl.d.ts.map +1 -0
  26. package/dist/dist/{ModelProperty-B52C3CQ2.d.ts → ModelProperty-sMGL-_LK.d.ts} +1 -1
  27. package/dist/dist/{ModelProperty-B52C3CQ2.d.ts.map → ModelProperty-sMGL-_LK.d.ts.map} +1 -1
  28. package/dist/dist/{Schema-O1QLoXv6.d.ts → Schema-D-TczaIj.d.ts} +11 -4
  29. package/dist/dist/Schema-D-TczaIj.d.ts.map +1 -0
  30. package/dist/dist/{SchemaValidationService-BxCbfDaI.d.ts → SchemaValidationService-NYTtSCxd.d.ts} +1 -1
  31. package/dist/dist/{SchemaValidationService-BxCbfDaI.d.ts.map → SchemaValidationService-NYTtSCxd.d.ts.map} +1 -1
  32. package/dist/dist/{backfillMetadataPropertyIds-CzSbuucw.d.ts → backfillMetadataPropertyIds-DEvD0OAT.d.ts} +1 -1
  33. package/dist/dist/backfillMetadataPropertyIds-DEvD0OAT.d.ts.map +1 -0
  34. package/dist/dist/{configurePlatform-Bbpw_R4y.d.ts → configurePlatform-CtA7fydC.d.ts} +1 -1
  35. package/dist/dist/configurePlatform-CtA7fydC.d.ts.map +1 -0
  36. package/dist/dist/{detachRowsBeforeDelete-D1TyEMco.d.ts → detachRowsBeforeDelete-CLbBbpX4.d.ts} +1 -1
  37. package/dist/dist/detachRowsBeforeDelete-CLbBbpX4.d.ts.map +1 -0
  38. package/dist/dist/{eas-DOdj-EMK.d.ts → eas-CcpQiXum.d.ts} +1 -1
  39. package/dist/dist/eas-CcpQiXum.d.ts.map +1 -0
  40. package/dist/dist/{errors-KM-yq2MD.d.ts → errors-BGk_IJO5.d.ts} +39 -24
  41. package/dist/dist/errors-BGk_IJO5.d.ts.map +1 -0
  42. package/dist/dist/{getItem-Bh0zv-o1.d.ts → getItem-CHSX3aMm.d.ts} +1 -1
  43. package/dist/dist/getItem-CHSX3aMm.d.ts.map +1 -0
  44. package/dist/dist/{getPublishPayload-oH8wJhnH.d.ts → getPublishPayload-DMd4oLir.d.ts} +1 -1
  45. package/dist/dist/getPublishPayload-DMd4oLir.d.ts.map +1 -0
  46. package/dist/dist/{getPublishUploads-Cex-NBe6.d.ts → getPublishUploads-C9FnRG9c.d.ts} +1 -1
  47. package/dist/dist/{getPublishUploads-Cex-NBe6.d.ts.map → getPublishUploads-C9FnRG9c.d.ts.map} +1 -1
  48. package/dist/dist/{index-BbFwftAv.d.ts → index-C--KAWoe.d.ts} +378 -1
  49. package/dist/dist/{index-BbFwftAv.d.ts.map → index-C--KAWoe.d.ts.map} +1 -1
  50. package/dist/dist/{index-DpgQMIRq.d.ts → index-CI0NFf4B.d.ts} +836 -426
  51. package/dist/dist/index-CI0NFf4B.d.ts.map +1 -0
  52. package/dist/dist/{index-BAao3_Po.d.ts → index-Ccmd9_KY.d.ts} +5 -5
  53. package/dist/dist/index-Ccmd9_KY.d.ts.map +1 -0
  54. package/dist/dist/index-l3b6p1Ih.d.ts +14 -0
  55. package/dist/dist/index-l3b6p1Ih.d.ts.map +1 -0
  56. package/dist/dist/{index.browser-nndbVM7z.d.ts → index.browser-kY8M-xUA.d.ts} +2892 -1754
  57. package/dist/dist/{index.browser-nndbVM7z.d.ts.map → index.browser-kY8M-xUA.d.ts.map} +1 -1
  58. package/dist/dist/{index.node-BUfx-JaP.d.ts → index.node-Ba2KbmOq.d.ts} +4125 -2613
  59. package/dist/dist/{index.node-BUfx-JaP.d.ts.map → index.node-Ba2KbmOq.d.ts.map} +1 -1
  60. package/dist/dist/platform.browser.d.ts +2 -2
  61. package/dist/dist/platform.node.d.ts +2 -2
  62. package/dist/dist/{property-BDBvImLs.d.ts → property-CO7pKTWK.d.ts} +3 -3
  63. package/dist/dist/property-CO7pKTWK.d.ts.map +1 -0
  64. package/dist/dist/{propertyValidationRules-BlfLn4rP.d.ts → propertyValidationRules-D5HZy0Bq.d.ts} +1 -1
  65. package/dist/dist/propertyValidationRules-D5HZy0Bq.d.ts.map +1 -0
  66. package/dist/dist/{publishDraftGraph-CLO85LLz.d.ts → publishDraftGraph-B5KPqtbg.d.ts} +1 -1
  67. package/dist/dist/{publishDraftGraph-CLO85LLz.d.ts.map → publishDraftGraph-B5KPqtbg.d.ts.map} +1 -1
  68. package/dist/dist/{resetAmbiguousLegacyItemData-Cy8ik7xk.d.ts → resetAmbiguousLegacyItemData-77CZ8HT7.d.ts} +1 -1
  69. package/dist/dist/resetAmbiguousLegacyItemData-77CZ8HT7.d.ts.map +1 -0
  70. package/dist/dist/{resolveModelForSyncedSeed-DFr4COc4.d.ts → resolveModelForSyncedSeed-DHOq_FGs.d.ts} +1 -1
  71. package/dist/dist/resolveModelForSyncedSeed-DHOq_FGs.d.ts.map +1 -0
  72. package/dist/dist/{syncDbWithEas-CAOlw3i-.d.ts → syncDbWithEas-BZ6AI-IC.d.ts} +1 -1
  73. package/dist/dist/syncDbWithEas-BZ6AI-IC.d.ts.map +1 -0
  74. package/dist/dist/{tabEvents-DksXwk3X.d.ts → tabEvents-CIlzHSKZ.d.ts} +35 -18
  75. package/dist/dist/tabEvents-CIlzHSKZ.d.ts.map +1 -0
  76. package/dist/dist/{tolerantWebAccess-CEIjFGf0.d.ts → tolerantWebAccess-BwJ8bElF.d.ts} +1 -1
  77. package/dist/dist/{tolerantWebAccess-CEIjFGf0.d.ts.map → tolerantWebAccess-BwJ8bElF.d.ts.map} +1 -1
  78. package/dist/dist/{updateSeedRevokedAt-Cjr35YjE.d.ts → updateSeedRevokedAt-ClxMSXcB.d.ts} +1 -1
  79. package/dist/dist/updateSeedRevokedAt-ClxMSXcB.d.ts.map +1 -0
  80. package/dist/{eas-DOdj-EMK.js → eas-CcpQiXum.js} +4 -4
  81. package/dist/{eas-DOdj-EMK.js.map → eas-CcpQiXum.js.map} +1 -1
  82. package/dist/{errors-KM-yq2MD.js → errors-BGk_IJO5.js} +222 -275
  83. package/dist/errors-BGk_IJO5.js.map +1 -0
  84. package/dist/{getItem-Bh0zv-o1.js → getItem-CHSX3aMm.js} +5 -5
  85. package/dist/{getItem-Bh0zv-o1.js.map → getItem-CHSX3aMm.js.map} +1 -1
  86. package/dist/{getPublishPayload-oH8wJhnH.js → getPublishPayload-DMd4oLir.js} +18 -15
  87. package/dist/getPublishPayload-DMd4oLir.js.map +1 -0
  88. package/dist/{getPublishUploads-Cex-NBe6.js → getPublishUploads-C9FnRG9c.js} +9 -6
  89. package/dist/getPublishUploads-C9FnRG9c.js.map +1 -0
  90. package/dist/{index-BbFwftAv.js → index-C--KAWoe.js} +3 -2
  91. package/dist/index-C--KAWoe.js.map +1 -0
  92. package/dist/{index-DpgQMIRq.js → index-CI0NFf4B.js} +132 -9
  93. package/dist/index-CI0NFf4B.js.map +1 -0
  94. package/dist/{index-BAao3_Po.js → index-Ccmd9_KY.js} +8 -8
  95. package/dist/index-Ccmd9_KY.js.map +1 -0
  96. package/dist/index-l3b6p1Ih.js +28 -0
  97. package/dist/index-l3b6p1Ih.js.map +1 -0
  98. package/dist/{index.browser-nndbVM7z.js → index.browser-kY8M-xUA.js} +284 -73
  99. package/dist/index.browser-kY8M-xUA.js.map +1 -0
  100. package/dist/{index.node-BUfx-JaP.js → index.node-Ba2KbmOq.js} +93 -6
  101. package/dist/index.node-Ba2KbmOq.js.map +1 -0
  102. package/dist/main.js +84 -26
  103. package/dist/main.js.map +1 -1
  104. package/dist/node.js +11 -11
  105. package/dist/platform.browser.js +5 -5
  106. package/dist/platform.node.js +4 -4
  107. package/dist/{property-BDBvImLs.js → property-CO7pKTWK.js} +9 -11
  108. package/dist/property-CO7pKTWK.js.map +1 -0
  109. package/dist/{propertyValidationRules-BlfLn4rP.js → propertyValidationRules-D5HZy0Bq.js} +10 -10
  110. package/dist/{propertyValidationRules-BlfLn4rP.js.map → propertyValidationRules-D5HZy0Bq.js.map} +1 -1
  111. package/dist/{publishDraftGraph-CLO85LLz.js → publishDraftGraph-B5KPqtbg.js} +6 -6
  112. package/dist/{publishDraftGraph-CLO85LLz.js.map → publishDraftGraph-B5KPqtbg.js.map} +1 -1
  113. package/dist/{resetAmbiguousLegacyItemData-Cy8ik7xk.js → resetAmbiguousLegacyItemData-77CZ8HT7.js} +2 -2
  114. package/dist/{resetAmbiguousLegacyItemData-Cy8ik7xk.js.map → resetAmbiguousLegacyItemData-77CZ8HT7.js.map} +1 -1
  115. package/dist/{resolveModelForSyncedSeed-DFr4COc4.js → resolveModelForSyncedSeed-DHOq_FGs.js} +2 -2
  116. package/dist/{resolveModelForSyncedSeed-DFr4COc4.js.map → resolveModelForSyncedSeed-DHOq_FGs.js.map} +1 -1
  117. package/dist/seedSchema/PendingWriteSchema.ts +57 -0
  118. package/dist/seedSchema/index.ts +1 -0
  119. package/dist/src/Item/Item.d.ts +38 -7
  120. package/dist/src/Item/Item.d.ts.map +1 -1
  121. package/dist/src/Item/service/itemMachineSingle.d.ts.map +1 -1
  122. package/dist/src/ItemProperty/ItemProperty.d.ts +66 -9
  123. package/dist/src/ItemProperty/ItemProperty.d.ts.map +1 -1
  124. package/dist/src/ItemProperty/service/actors/hydrateFromDb.d.ts.map +1 -1
  125. package/dist/src/ItemProperty/service/actors/loadOrCreateProperty.d.ts.map +1 -1
  126. package/dist/src/ItemProperty/service/actors/saveValueToDb/analyzeInput.d.ts.map +1 -1
  127. package/dist/src/ItemProperty/service/actors/saveValueToDb/saveFile.d.ts.map +1 -1
  128. package/dist/src/ItemProperty/service/actors/saveValueToDb/saveHtml.d.ts.map +1 -1
  129. package/dist/src/ItemProperty/service/actors/saveValueToDb/saveImage.d.ts.map +1 -1
  130. package/dist/src/ItemProperty/service/actors/saveValueToDb/saveItemStorage.d.ts +5 -0
  131. package/dist/src/ItemProperty/service/actors/saveValueToDb/saveItemStorage.d.ts.map +1 -1
  132. package/dist/src/ItemProperty/service/actors/saveValueToDb/storageValue.d.ts +22 -0
  133. package/dist/src/ItemProperty/service/actors/saveValueToDb/storageValue.d.ts.map +1 -0
  134. package/dist/src/ItemProperty/service/propertyMachine.d.ts.map +1 -1
  135. package/dist/src/Model/Model.d.ts +50 -9
  136. package/dist/src/Model/Model.d.ts.map +1 -1
  137. package/dist/src/Model/service/actors/validateModel.d.ts.map +1 -1
  138. package/dist/src/ModelProperty/ModelProperty.d.ts.map +1 -1
  139. package/dist/src/ModelProperty/service/actors/compareAndMarkDraft.d.ts.map +1 -1
  140. package/dist/src/ModelProperty/service/actors/validateProperty.d.ts.map +1 -1
  141. package/dist/src/Schema/Schema.d.ts +22 -3
  142. package/dist/src/Schema/Schema.d.ts.map +1 -1
  143. package/dist/src/Schema/service/actors/checkExistingSchema.d.ts.map +1 -1
  144. package/dist/src/Schema/service/actors/createModelInstances.d.ts.map +1 -1
  145. package/dist/src/Schema/service/actors/loadOrCreateSchema.d.ts.map +1 -1
  146. package/dist/src/browser/db/Db.d.ts +7 -0
  147. package/dist/src/browser/db/Db.d.ts.map +1 -1
  148. package/dist/src/browser/db/drizzleFiles.d.ts +4 -2
  149. package/dist/src/browser/db/drizzleFiles.d.ts.map +1 -1
  150. package/dist/src/browser/db/sqliteBusyRetry.d.ts.map +1 -1
  151. package/dist/src/browser/helpers/EasClient.d.ts +1 -1
  152. package/dist/src/browser/helpers/EasClient.d.ts.map +1 -1
  153. package/dist/src/browser/helpers/FileManager.d.ts.map +1 -1
  154. package/dist/src/client/ClientManager.d.ts +13 -0
  155. package/dist/src/client/ClientManager.d.ts.map +1 -1
  156. package/dist/src/client/actors/saveConfig.d.ts.map +1 -1
  157. package/dist/src/client/addressesPersisted.d.ts +10 -0
  158. package/dist/src/client/addressesPersisted.d.ts.map +1 -0
  159. package/dist/src/client/clientManagerMachine.d.ts.map +1 -1
  160. package/dist/src/db/Db/BaseDb.d.ts +10 -0
  161. package/dist/src/db/Db/BaseDb.d.ts.map +1 -1
  162. package/dist/src/db/read/getItemProperties.d.ts.map +1 -1
  163. package/dist/src/db/read/getPublishPayload.d.ts.map +1 -1
  164. package/dist/src/db/read/getPublishUploads.d.ts.map +1 -1
  165. package/dist/src/db/read/getSeedData.d.ts +4 -1
  166. package/dist/src/db/read/getSeedData.d.ts.map +1 -1
  167. package/dist/src/db/read/getSeedPublisher.d.ts +4 -1
  168. package/dist/src/db/read/getSeedPublisher.d.ts.map +1 -1
  169. package/dist/src/db/read/getVersionData.d.ts +4 -1
  170. package/dist/src/db/read/getVersionData.d.ts.map +1 -1
  171. package/dist/src/db/write/claimUnpublishedDrafts.d.ts +6 -0
  172. package/dist/src/db/write/claimUnpublishedDrafts.d.ts.map +1 -1
  173. package/dist/src/db/write/createMetadata.d.ts +13 -0
  174. package/dist/src/db/write/createMetadata.d.ts.map +1 -1
  175. package/dist/src/db/write/createNewItem.d.ts +5 -0
  176. package/dist/src/db/write/createNewItem.d.ts.map +1 -1
  177. package/dist/src/db/write/createSeed.d.ts +20 -1
  178. package/dist/src/db/write/createSeed.d.ts.map +1 -1
  179. package/dist/src/db/write/createVersion.d.ts +5 -1
  180. package/dist/src/db/write/createVersion.d.ts.map +1 -1
  181. package/dist/src/db/write/removeLocalCopiesForAddresses.d.ts +9 -2
  182. package/dist/src/db/write/removeLocalCopiesForAddresses.d.ts.map +1 -1
  183. package/dist/src/db/write/updateItemPropertyValue.d.ts +9 -1
  184. package/dist/src/db/write/updateItemPropertyValue.d.ts.map +1 -1
  185. package/dist/src/db/write/updateMetadata.d.ts +8 -1
  186. package/dist/src/db/write/updateMetadata.d.ts.map +1 -1
  187. package/dist/src/events/item/syncDbWithEas.d.ts.map +1 -1
  188. package/dist/src/helpers/db.d.ts +4 -2
  189. package/dist/src/helpers/db.d.ts.map +1 -1
  190. package/dist/src/helpers/entity/entityCache.d.ts +2 -42
  191. package/dist/src/helpers/entity/entityCache.d.ts.map +1 -1
  192. package/dist/src/helpers/entity/entityCommon.d.ts +9 -0
  193. package/dist/src/helpers/entity/entityCommon.d.ts.map +1 -1
  194. package/dist/src/helpers/entity/entityDestroy.d.ts +13 -7
  195. package/dist/src/helpers/entity/entityDestroy.d.ts.map +1 -1
  196. package/dist/src/helpers/entity/entityLiveQuery.d.ts +3 -2
  197. package/dist/src/helpers/entity/entityLiveQuery.d.ts.map +1 -1
  198. package/dist/src/helpers/entity/entityState.d.ts +28 -0
  199. package/dist/src/helpers/entity/entityState.d.ts.map +1 -0
  200. package/dist/src/helpers/entity/entityUnload.d.ts +3 -2
  201. package/dist/src/helpers/entity/entityUnload.d.ts.map +1 -1
  202. package/dist/src/helpers/entity/index.d.ts +1 -0
  203. package/dist/src/helpers/entity/index.d.ts.map +1 -1
  204. package/dist/src/helpers/itemStorageFile.d.ts +7 -0
  205. package/dist/src/helpers/itemStorageFile.d.ts.map +1 -1
  206. package/dist/src/helpers/metadataPropertyNames.d.ts +6 -0
  207. package/dist/src/helpers/metadataPropertyNames.d.ts.map +1 -1
  208. package/dist/src/helpers/property.d.ts.map +1 -1
  209. package/dist/src/helpers/propertySchemaUid.d.ts +13 -0
  210. package/dist/src/helpers/propertySchemaUid.d.ts.map +1 -0
  211. package/dist/src/helpers/propertyWriteTickets.d.ts +11 -0
  212. package/dist/src/helpers/propertyWriteTickets.d.ts.map +1 -0
  213. package/dist/src/helpers/reactiveProxy.d.ts +18 -0
  214. package/dist/src/helpers/reactiveProxy.d.ts.map +1 -1
  215. package/dist/src/helpers/sessionObjectUrls.d.ts +4 -0
  216. package/dist/src/helpers/sessionObjectUrls.d.ts.map +1 -0
  217. package/dist/src/helpers/tabCoordinator.d.ts +9 -0
  218. package/dist/src/helpers/tabCoordinator.d.ts.map +1 -1
  219. package/dist/src/helpers/tabLocks.d.ts +11 -0
  220. package/dist/src/helpers/tabLocks.d.ts.map +1 -1
  221. package/dist/src/helpers/timing.d.ts +10 -0
  222. package/dist/src/helpers/timing.d.ts.map +1 -0
  223. package/dist/src/imports/json.d.ts.map +1 -1
  224. package/dist/src/index.d.ts +1 -0
  225. package/dist/src/index.d.ts.map +1 -1
  226. package/dist/src/interfaces/IDb.d.ts +2 -0
  227. package/dist/src/interfaces/IDb.d.ts.map +1 -1
  228. package/dist/src/interfaces/IItem.d.ts +1 -0
  229. package/dist/src/interfaces/IItem.d.ts.map +1 -1
  230. package/dist/src/interfaces/IItemProperty.d.ts +5 -0
  231. package/dist/src/interfaces/IItemProperty.d.ts.map +1 -1
  232. package/dist/src/node/db/Db.d.ts +3 -0
  233. package/dist/src/node/db/Db.d.ts.map +1 -1
  234. package/dist/src/node/db/singleConnectionTransactions.d.ts +22 -0
  235. package/dist/src/node/db/singleConnectionTransactions.d.ts.map +1 -0
  236. package/dist/src/outbox/conflicts.d.ts +60 -0
  237. package/dist/src/outbox/conflicts.d.ts.map +1 -0
  238. package/dist/src/outbox/index.d.ts +9 -0
  239. package/dist/src/outbox/index.d.ts.map +1 -0
  240. package/dist/src/outbox/itemAppliers.d.ts +153 -0
  241. package/dist/src/outbox/itemAppliers.d.ts.map +1 -0
  242. package/dist/src/outbox/outbox.d.ts +143 -0
  243. package/dist/src/outbox/outbox.d.ts.map +1 -0
  244. package/dist/src/outbox/pendingValues.d.ts +27 -0
  245. package/dist/src/outbox/pendingValues.d.ts.map +1 -0
  246. package/dist/src/seedSchema/PendingWriteSchema.d.ts +385 -0
  247. package/dist/src/seedSchema/PendingWriteSchema.d.ts.map +1 -0
  248. package/dist/src/seedSchema/index.d.ts +1 -0
  249. package/dist/src/seedSchema/index.d.ts.map +1 -1
  250. package/dist/src/types/property.d.ts +5 -0
  251. package/dist/src/types/property.d.ts.map +1 -1
  252. package/dist/{syncDbWithEas-CAOlw3i-.js → syncDbWithEas-BZ6AI-IC.js} +25 -20
  253. package/dist/syncDbWithEas-BZ6AI-IC.js.map +1 -0
  254. package/dist/{tabEvents-DksXwk3X.js → tabEvents-CIlzHSKZ.js} +56 -25
  255. package/dist/tabEvents-CIlzHSKZ.js.map +1 -0
  256. package/dist/{tolerantWebAccess-CEIjFGf0.js → tolerantWebAccess-BwJ8bElF.js} +6 -6
  257. package/dist/{tolerantWebAccess-CEIjFGf0.js.map → tolerantWebAccess-BwJ8bElF.js.map} +1 -1
  258. package/dist/{updateSeedRevokedAt-Cjr35YjE.js → updateSeedRevokedAt-ClxMSXcB.js} +3 -3
  259. package/dist/{updateSeedRevokedAt-Cjr35YjE.js.map → updateSeedRevokedAt-ClxMSXcB.js.map} +1 -1
  260. package/package.json +7 -7
  261. package/dist/ClientManager-2GtDWHq6.js.map +0 -1
  262. package/dist/Item-D6j0IvBP.js.map +0 -1
  263. package/dist/ModelProperty-B52C3CQ2.js.map +0 -1
  264. package/dist/Schema-O1QLoXv6.js.map +0 -1
  265. package/dist/discardNewDraft-hiVaUVjV.js +0 -78
  266. package/dist/discardNewDraft-hiVaUVjV.js.map +0 -1
  267. package/dist/dist/ClientManager-2GtDWHq6.d.ts.map +0 -1
  268. package/dist/dist/Item-D6j0IvBP.d.ts.map +0 -1
  269. package/dist/dist/Schema-O1QLoXv6.d.ts.map +0 -1
  270. package/dist/dist/backfillMetadataPropertyIds-CzSbuucw.d.ts.map +0 -1
  271. package/dist/dist/configurePlatform-Bbpw_R4y.d.ts.map +0 -1
  272. package/dist/dist/detachRowsBeforeDelete-D1TyEMco.d.ts.map +0 -1
  273. package/dist/dist/discardNewDraft-hiVaUVjV.d.ts +0 -8
  274. package/dist/dist/discardNewDraft-hiVaUVjV.d.ts.map +0 -1
  275. package/dist/dist/eas-DOdj-EMK.d.ts.map +0 -1
  276. package/dist/dist/errors-KM-yq2MD.d.ts.map +0 -1
  277. package/dist/dist/getItem-Bh0zv-o1.d.ts.map +0 -1
  278. package/dist/dist/getPublishPayload-oH8wJhnH.d.ts.map +0 -1
  279. package/dist/dist/index-BAao3_Po.d.ts.map +0 -1
  280. package/dist/dist/index-DpgQMIRq.d.ts.map +0 -1
  281. package/dist/dist/property-BDBvImLs.d.ts.map +0 -1
  282. package/dist/dist/propertyValidationRules-BlfLn4rP.d.ts.map +0 -1
  283. package/dist/dist/resetAmbiguousLegacyItemData-Cy8ik7xk.d.ts.map +0 -1
  284. package/dist/dist/resolveModelForSyncedSeed-DFr4COc4.d.ts.map +0 -1
  285. package/dist/dist/syncDbWithEas-CAOlw3i-.d.ts.map +0 -1
  286. package/dist/dist/tabEvents-DksXwk3X.d.ts.map +0 -1
  287. package/dist/dist/updateSeedRevokedAt-Cjr35YjE.d.ts.map +0 -1
  288. package/dist/errors-KM-yq2MD.js.map +0 -1
  289. package/dist/getPublishPayload-oH8wJhnH.js.map +0 -1
  290. package/dist/getPublishUploads-Cex-NBe6.js.map +0 -1
  291. package/dist/index-BAao3_Po.js.map +0 -1
  292. package/dist/index-BbFwftAv.js.map +0 -1
  293. package/dist/index-DpgQMIRq.js.map +0 -1
  294. package/dist/index.browser-nndbVM7z.js.map +0 -1
  295. package/dist/index.node-BUfx-JaP.js.map +0 -1
  296. package/dist/property-BDBvImLs.js.map +0 -1
  297. package/dist/src/db/write/discardNewDraft.d.ts +0 -8
  298. package/dist/src/db/write/discardNewDraft.d.ts.map +0 -1
  299. package/dist/src/helpers/propertyWriteQueue.d.ts +0 -15
  300. package/dist/src/helpers/propertyWriteQueue.d.ts.map +0 -1
  301. package/dist/syncDbWithEas-CAOlw3i-.js.map +0 -1
  302. package/dist/tabEvents-DksXwk3X.js.map +0 -1
@@ -1,29 +1,13 @@
1
1
  import { fromCallback, fromPromise, setup, assign, createActor } from 'xstate';
2
- import { B as BaseDb, t as models, v as properties, ai as generateId, aJ as isInternalSchema, aK as writeModelToDb, aL as writePropertyToDb, aM as addSchemaToDb, r as modelSchemas, A as schemas, H as AmbiguousModelError, aN as renameModelInDb, aO as currentNameMatchLevels, a as TProperty } from './index-DpgQMIRq.js';
2
+ import { F as BaseDb, s as models, v as properties, ai as generateId, aL as isInternalSchema, aM as writeModelToDb, aN as writePropertyToDb, aO as addSchemaToDb, q as modelSchemas, A as schemas, H as AmbiguousModelError, aP as renameModelInDb, aQ as currentNameMatchLevels, a as TProperty } from './index-CI0NFf4B.js';
3
3
  import { eq, and, isNull, or } from 'drizzle-orm';
4
4
  import debug from 'debug';
5
- import { d as waitForEntityIdle, D as DEFAULT_READY_TIMEOUT_MS, Z as getInvariantSafePropertyDescriptor, n as findEntity, C as ClientManagerState, I as Item, _ as clearDestroySubscriptions, o as forceRemoveFromCaches, $ as unloadEntity, q as runDestroyLifecycle } from './Item-D6j0IvBP.js';
6
- import { m as getClient } from './ClientManager-2GtDWHq6.js';
5
+ import { P as isActorStopped, ak as ActorKeyedState, C as waitForEntityIdle, Q as DEFAULT_READY_TIMEOUT_MS, R as createReactiveProxy, T as findEntity, X as ClientManagerState, I as Item, al as clearDestroySubscriptions, U as forceRemoveFromCaches, am as unloadEntity, V as runDestroyLifecycle } from './Item-DZfNz7xl.js';
6
+ import { z as getClient } from './ClientManager-Dcju5x4k.js';
7
7
  import { modelPropertiesToObject } from './model-oHA3YhOd.js';
8
8
  import { localNamesInBestMatchTier } from '@seedprotocol/eas';
9
9
  import { Type } from '@sinclair/typebox';
10
10
 
11
- /**
12
- * Common getters and utilities for entity classes
13
- * These work with any entity that has a getService() method returning an XState actor
14
- */
15
- /**
16
- * Get the current state value from an entity's service
17
- */
18
- /**
19
- * Whether an actor has been stopped (unload, destroy, or Schema eviction). Async work started by an
20
- * entity (DB lookups, retry timers) must check this before sending, since a stopped actor ignores
21
- * events and XState warns about every one of them.
22
- */
23
- function isActorStopped(actor) {
24
- return actor.getSnapshot().status === 'stopped';
25
- }
26
-
27
11
  const logger$7 = debug('seedSdk:model:actors:loadOrCreateModel');
28
12
  /**
29
13
  * Create ModelProperty instances for all property IDs to ensure they're cached
@@ -35,7 +19,7 @@ const createPropertyInstances = async (propertyFileIds) => {
35
19
  return;
36
20
  }
37
21
  try {
38
- const mod = await import('./ModelProperty-B52C3CQ2.js');
22
+ const mod = await import('./ModelProperty-sMGL-_LK.js');
39
23
  const ModelProperty = mod?.ModelProperty ?? mod?.default;
40
24
  if (!ModelProperty) {
41
25
  logger$7('createPropertyInstances: ModelProperty not available from dynamic import');
@@ -101,11 +85,11 @@ const loadOrCreateModel = fromCallback(({ sendBack, input: { context }, self })
101
85
  if (!modelRecord) {
102
86
  // Model names are only unique per schema: prefer this schema's row, and otherwise only
103
87
  // consider same-name rows that no schema claims yet (never another schema's model).
104
- const _mod_0 = await import('./index-DpgQMIRq.js');
105
- const _ns_0 = _mod_0.bg;
88
+ const _mod_0 = await import('./index-CI0NFf4B.js');
89
+ const _ns_0 = _mod_0.bk;
106
90
  const { modelSchemas } = _ns_0;
107
- const _mod_1 = await import('./index-DpgQMIRq.js');
108
- const _ns_1 = _mod_1.bf;
91
+ const _mod_1 = await import('./index-CI0NFf4B.js');
92
+ const _ns_1 = _mod_1.bj;
109
93
  const { schemas: schemasTable } = _ns_1;
110
94
  let dbModels = await db
111
95
  .select({
@@ -252,14 +236,14 @@ const loadOrCreateModel = fromCallback(({ sendBack, input: { context }, self })
252
236
  // Step 2: Fallback to Schema context (only if database doesn't have the model)
253
237
  // This handles the case where model exists in schema file but not yet in database
254
238
  try {
255
- const _mod_2 = await import('./Schema-O1QLoXv6.js');
239
+ const _mod_2 = await import('./Schema-D-TczaIj.js');
256
240
  const _ns_2 = _mod_2.b;
257
241
  const schemaMod = _ns_2;
258
242
  const { Schema } = schemaMod;
259
243
  // Stopped meanwhile (unloaded, or evicted with its schema): don't load the schema again
260
244
  if (isActorStopped(self))
261
245
  return;
262
- const schema = Schema.create(schemaName, { waitForReady: false });
246
+ const schema = Schema.create(schemaName, { waitForReady: false, hold: false });
263
247
  const schemaSnapshot = schema.getService().getSnapshot();
264
248
  // Wait for schema to load if it's still loading
265
249
  // Check if state is a loading state object (XState v5 nested states)
@@ -403,12 +387,12 @@ const loadOrCreateModel = fromCallback(({ sendBack, input: { context }, self })
403
387
  }
404
388
  // Also check database for models (in case they're persisted but not in Schema context)
405
389
  if (db) {
406
- const _mod_3 = await import('./index-DpgQMIRq.js');
407
- const _ns_3 = _mod_3.bg;
390
+ const _mod_3 = await import('./index-CI0NFf4B.js');
391
+ const _ns_3 = _mod_3.bk;
408
392
  const modelSchemaSchemaMod = _ns_3;
409
393
  const { modelSchemas } = modelSchemaSchemaMod;
410
- const _mod_4 = await import('./index-DpgQMIRq.js');
411
- const _ns_4 = _mod_4.bf;
394
+ const _mod_4 = await import('./index-CI0NFf4B.js');
395
+ const _ns_4 = _mod_4.bj;
412
396
  const schemaSchemaMod = _ns_4;
413
397
  const { schemas: schemasTable } = schemaSchemaMod;
414
398
  // Query all models for this schema to check for duplicates (case-insensitive)
@@ -503,12 +487,12 @@ const loadOrCreateModel = fromCallback(({ sendBack, input: { context }, self })
503
487
  }
504
488
  // Mark schema as draft when a new model is created so saveNewVersion() can persist it
505
489
  try {
506
- const _mod_5 = await import('./Schema-O1QLoXv6.js');
490
+ const _mod_5 = await import('./Schema-D-TczaIj.js');
507
491
  const _ns_5 = _mod_5.b;
508
492
  const schemaMod = _ns_5;
509
493
  const { Schema } = schemaMod;
510
494
  if (!isActorStopped(self)) {
511
- const schema = Schema.create(schemaName, { waitForReady: false });
495
+ const schema = Schema.create(schemaName, { waitForReady: false, hold: false });
512
496
  schema.getService().send({ type: 'markAsDraft', propertyKey: 'schema:models' });
513
497
  }
514
498
  }
@@ -551,10 +535,10 @@ const validateModel = fromCallback(({ sendBack, input: { context }, self }) => {
551
535
  const _validateModel = async () => {
552
536
  try {
553
537
  // Use dynamic imports to break circular dependencies
554
- const validationServiceMod = await import('./SchemaValidationService-BxCbfDaI.js');
538
+ const validationServiceMod = await import('./SchemaValidationService-NYTtSCxd.js');
555
539
  const { SchemaValidationService } = validationServiceMod;
556
540
  const validationService = new SchemaValidationService();
557
- const _mod_6 = await import('./Schema-O1QLoXv6.js');
541
+ const _mod_6 = await import('./Schema-D-TczaIj.js');
558
542
  const _ns_6 = _mod_6.b;
559
543
  const schemaMod = _ns_6;
560
544
  const { Schema } = schemaMod;
@@ -576,9 +560,7 @@ const validateModel = fromCallback(({ sendBack, input: { context }, self }) => {
576
560
  return;
577
561
  if (context.schemaName) {
578
562
  try {
579
- const schema = Schema.create(context.schemaName, {
580
- waitForReady: false,
581
- });
563
+ const schema = Schema.create(context.schemaName, { waitForReady: false, hold: false });
582
564
  const schemaSnapshot = schema.getService().getSnapshot();
583
565
  const schemaStatus = schemaSnapshot.value;
584
566
  // Only validate against schema if it's loaded (in idle state)
@@ -673,7 +655,7 @@ const createModelProperties = fromCallback(({ sendBack, input, self }) => {
673
655
  return;
674
656
  }
675
657
  logger$5(`Creating ${Object.keys(propertyDefinitions).length} properties for model "${modelName}" (id: ${_dbId})`);
676
- const mod = await import('./ModelProperty-B52C3CQ2.js');
658
+ const mod = await import('./ModelProperty-sMGL-_LK.js');
677
659
  const ModelProperty = mod?.ModelProperty ?? mod?.default;
678
660
  if (!ModelProperty) {
679
661
  logger$5('ModelProperty not available from dynamic import');
@@ -698,8 +680,8 @@ const createModelProperties = fromCallback(({ sendBack, input, self }) => {
698
680
  : undefined;
699
681
  // Otherwise use provided ID or generate a random one
700
682
  // IDs should be generated in the import process before creating properties
701
- const _mod_7 = await import('./index-DpgQMIRq.js');
702
- const _ns_7 = _mod_7.bk;
683
+ const _mod_7 = await import('./index-CI0NFf4B.js');
684
+ const _ns_7 = _mod_7.bo;
703
685
  const { generateId } = _ns_7;
704
686
  const propertyFileId = propData.id || propertyRecord?.schemaFileId || generateId();
705
687
  logger$5(`Creating property "${propName}" with fileId "${propertyFileId}"`);
@@ -716,8 +698,8 @@ const createModelProperties = fromCallback(({ sendBack, input, self }) => {
716
698
  }
717
699
  else if (refModelName) {
718
700
  // Fallback: resolve the ref by name within this model's schema
719
- const _mod_8 = await import('./index-DpgQMIRq.js');
720
- const _ns_8 = _mod_8.bh;
701
+ const _mod_8 = await import('./index-CI0NFf4B.js');
702
+ const _ns_8 = _mod_8.bl;
721
703
  const { resolveModelRecord } = _ns_8;
722
704
  const refModelRecord = await resolveModelRecord(refModelName, { schemaName }, db);
723
705
  if (refModelRecord?.id) {
@@ -887,13 +869,13 @@ const validateEntity = fromPromise(async ({ input }) => {
887
869
  const evictionEpoch = currentEvictionEpoch();
888
870
  /** The schema to validate against; throws (validation then skips the schema check) once it was evicted. */
889
871
  const schemaForValidation = async (schemaName) => {
890
- const _mod_9 = await import('./Schema-O1QLoXv6.js');
872
+ const _mod_9 = await import('./Schema-D-TczaIj.js');
891
873
  const _ns_9 = _mod_9.b;
892
874
  const { Schema } = _ns_9;
893
875
  if (schemaEvictedSince(schemaName, evictionEpoch)) {
894
876
  throw new Error(`Schema "${schemaName}" was evicted during validation`);
895
877
  }
896
- return Schema.create(schemaName, { waitForReady: false });
878
+ return Schema.create(schemaName, { waitForReady: false, hold: false });
897
879
  };
898
880
  const _validate = async () => {
899
881
  try {
@@ -905,7 +887,7 @@ const validateEntity = fromPromise(async ({ input }) => {
905
887
  const structureMsg = `[validateEntity] Validating model structure`;
906
888
  logger$4(structureMsg);
907
889
  // Use existing Model validation
908
- const validationServiceMod = await import('./SchemaValidationService-BxCbfDaI.js');
890
+ const validationServiceMod = await import('./SchemaValidationService-NYTtSCxd.js');
909
891
  const { SchemaValidationService } = validationServiceMod;
910
892
  const validationService = new SchemaValidationService();
911
893
  // Validate model structure
@@ -955,7 +937,7 @@ const validateEntity = fromPromise(async ({ input }) => {
955
937
  }
956
938
  else if (entityInput.entityType === 'modelProperty') {
957
939
  // Use existing ModelProperty validation
958
- const validationServiceMod = await import('./SchemaValidationService-BxCbfDaI.js');
940
+ const validationServiceMod = await import('./SchemaValidationService-NYTtSCxd.js');
959
941
  const { SchemaValidationService } = validationServiceMod;
960
942
  const validationService = new SchemaValidationService();
961
943
  // Validate property structure
@@ -995,7 +977,7 @@ const validateEntity = fromPromise(async ({ input }) => {
995
977
  }
996
978
  else if (entityInput.entityType === 'schema') {
997
979
  // Schema validation - use existing validation
998
- const validationServiceMod = await import('./SchemaValidationService-BxCbfDaI.js');
980
+ const validationServiceMod = await import('./SchemaValidationService-NYTtSCxd.js');
999
981
  const { SchemaValidationService } = validationServiceMod;
1000
982
  const validationService = new SchemaValidationService();
1001
983
  const schemaResult = validationService.validateSchema(entityInput.entityData);
@@ -1083,7 +1065,7 @@ const writeToDatabase = fromCallback(({ sendBack, input }) => {
1083
1065
  // initial write completes is not overwritten by the stale requestWrite payload.
1084
1066
  let dataToWrite = input.entityData;
1085
1067
  try {
1086
- const mod = await import('./ModelProperty-B52C3CQ2.js');
1068
+ const mod = await import('./ModelProperty-sMGL-_LK.js');
1087
1069
  const ModelProperty = mod?.ModelProperty ?? mod?.default;
1088
1070
  if (ModelProperty && typeof ModelProperty.getById === 'function') {
1089
1071
  const instance = ModelProperty.getById(input.entityId);
@@ -1477,7 +1459,7 @@ const modelMachine = setup({
1477
1459
  // Create ModelProperty instances for any new property IDs
1478
1460
  if (Array.isArray(newPropertyIds) && newPropertyIds.length > 0) {
1479
1461
  // Import and create instances asynchronously (fire-and-forget)
1480
- import('./ModelProperty-B52C3CQ2.js').then(({ ModelProperty }) => {
1462
+ import('./ModelProperty-sMGL-_LK.js').then(({ ModelProperty }) => {
1481
1463
  if (self.getSnapshot().status === 'stopped')
1482
1464
  return;
1483
1465
  const createPromises = newPropertyIds.map(async (propertyFileId) => {
@@ -1828,6 +1810,9 @@ function setupEntityLiveQuery(instance, config) {
1828
1810
  logger('Instance state not found');
1829
1811
  return;
1830
1812
  }
1813
+ // Unloaded or destroyed while setup awaited: subscribing now would leak the query.
1814
+ if (isActorStopped(instance.getService()))
1815
+ return;
1831
1816
  // Subscribe to liveQuery updates
1832
1817
  const subscription = query$.subscribe({
1833
1818
  next: async (rows) => {
@@ -2011,7 +1996,7 @@ const saveDraftLogger = debug('seedSdk:model:saveDraftToDb');
2011
1996
  // Lazy import cache for ModelProperty to avoid circular dependency
2012
1997
  // Eagerly start loading to minimize delay on first access
2013
1998
  let ModelPropertyClass = null;
2014
- const modelPropertyImportPromise = import('./ModelProperty-B52C3CQ2.js')
1999
+ const modelPropertyImportPromise = import('./ModelProperty-sMGL-_LK.js')
2015
2000
  .then(module => {
2016
2001
  ModelPropertyClass = module.ModelProperty;
2017
2002
  return ModelPropertyClass;
@@ -2026,9 +2011,8 @@ function getModelProperty() {
2026
2011
  // and the getter will return empty array, which matches the original behavior
2027
2012
  return ModelPropertyClass;
2028
2013
  }
2029
- // WeakMap to store mutable state per Model instance
2030
- // This avoids issues with read-only properties when instances are frozen by Immer
2031
- const modelInstanceState = new WeakMap();
2014
+ // Mutable state per Model instance
2015
+ const modelInstanceState = new ActorKeyedState();
2032
2016
  // Settles once the properties passed to Model.create exist, or rejects when they can't be created.
2033
2017
  // The model reaches idle before its write, so idle alone doesn't mean they exist yet. Keyed by the
2034
2018
  // actor because callers hold the proxy, not the instance.
@@ -2228,6 +2212,7 @@ class Model {
2228
2212
  }
2229
2213
  const waitForReady = options?.waitForReady !== false;
2230
2214
  const readyTimeout = options?.readyTimeout ?? DEFAULT_READY_TIMEOUT_MS;
2215
+ const holds = options?.hold === false ? 0 : 1;
2231
2216
  // Extract schema name and instance
2232
2217
  let schemaName;
2233
2218
  let schemaInstance; // Using any to avoid circular dependency with Schema
@@ -2245,12 +2230,10 @@ class Model {
2245
2230
  const id = options?.modelFileId || options?.id; // schemaFileId (string) - public ID
2246
2231
  const registerWithSchema = options?.registerWithSchema !== false && schemaInstance !== undefined;
2247
2232
  // Step 1: Check ID-based cache first (if ID provided)
2248
- if (id && this.instanceCacheById.has(id)) {
2249
- const { instance, refCount } = this.instanceCacheById.get(id);
2250
- this.instanceCacheById.set(id, {
2251
- instance,
2252
- refCount: refCount + 1,
2253
- });
2233
+ const cachedById = id ? this.instanceCacheById.get(id) : undefined;
2234
+ if (cachedById) {
2235
+ cachedById.refCount += holds;
2236
+ const { instance } = cachedById;
2254
2237
  logger(`Model.create: Found instance in ID cache for "${modelName}" (ID: ${id})`);
2255
2238
  if (!waitForReady)
2256
2239
  return instance;
@@ -2284,18 +2267,16 @@ class Model {
2284
2267
  // create('My Model') calls get new instances with incremented names.
2285
2268
  if (id && uniqueModelName === modelName) {
2286
2269
  const legacyKey = `${schemaName}:${modelName}`;
2287
- if (this.instanceCache.has(legacyKey)) {
2288
- const { instance, refCount } = this.instanceCache.get(legacyKey);
2270
+ const legacyEntry = this.instanceCache.get(legacyKey);
2271
+ if (legacyEntry) {
2272
+ const { instance } = legacyEntry;
2289
2273
  const ctx = instance._getSnapshotContext();
2290
2274
  if (!ctx._idFromSchema && !this.isOtherModelId(ctx.id, id)) {
2291
- this.instanceCache.set(legacyKey, {
2292
- instance,
2293
- refCount: refCount + 1,
2294
- });
2275
+ legacyEntry.refCount += holds;
2295
2276
  logger(`Model.create: Found instance in legacy cache for "${modelName}"`);
2296
2277
  const existingId = instance._getSnapshotContext().id;
2297
2278
  if (existingId) {
2298
- this.instanceCacheById.set(existingId, { instance, refCount: refCount + 1 });
2279
+ this.instanceCacheById.set(existingId, legacyEntry);
2299
2280
  this.instanceCacheByName.set(legacyKey, existingId);
2300
2281
  }
2301
2282
  if (!waitForReady)
@@ -2325,17 +2306,15 @@ class Model {
2325
2306
  // This is a fallback in case an instance was cached with a unique name
2326
2307
  if (this.instanceCache.has(nameKey) &&
2327
2308
  !this.isOtherModelId(this.instanceCache.get(nameKey).instance._getSnapshotContext().id, id)) {
2328
- const { instance, refCount } = this.instanceCache.get(nameKey);
2329
- this.instanceCache.set(nameKey, {
2330
- instance,
2331
- refCount: refCount + 1,
2332
- });
2309
+ const legacyEntry = this.instanceCache.get(nameKey);
2310
+ legacyEntry.refCount += holds;
2311
+ const { instance } = legacyEntry;
2333
2312
  logger(`Model.create: Found instance in legacy cache for "${modelName}"`);
2334
2313
  // Migrate to new cache structure
2335
2314
  const context = instance._getSnapshotContext();
2336
2315
  const existingId = context.id; // id is now the schemaFileId (string)
2337
2316
  if (existingId) {
2338
- this.instanceCacheById.set(existingId, { instance, refCount: refCount + 1 });
2317
+ this.instanceCacheById.set(existingId, legacyEntry);
2339
2318
  this.instanceCacheByName.set(nameKey, existingId);
2340
2319
  }
2341
2320
  if (!waitForReady)
@@ -2398,168 +2377,88 @@ class Model {
2398
2377
  });
2399
2378
  }
2400
2379
  }
2401
- // Wrap instance in Proxy for reactive property access
2402
- // Create a custom proxy that handles 'name' as an alias for 'modelName'
2403
- const proxiedInstance = new Proxy(newInstance, {
2404
- get(target, prop) {
2405
- // Handle special properties
2406
- if (prop === '_service') {
2407
- return Reflect.get(target, prop);
2408
- }
2409
- // Handle 'name' as an alias for 'modelName'
2410
- if (prop === 'name') {
2411
- const context = target._getSnapshotContext();
2412
- return context.modelName;
2413
- }
2414
- // Handle 'id' property - returns the schemaFileId (string)
2415
- if (prop === 'id') {
2416
- const context = target._getSnapshotContext();
2417
- return context.id; // id is now the schemaFileId (string)
2418
- }
2419
- // Handle tracked properties
2420
- if (typeof prop === 'string' && TRACKED_PROPERTIES.includes(prop)) {
2421
- const context = target._getSnapshotContext();
2422
- return context[prop];
2423
- }
2424
- // Handle 'properties' getter - not tracked, but accessible via getter
2425
- if (typeof prop === 'string' && prop === 'properties') {
2426
- // Delegate to the getter method on the instance
2427
- return target.properties;
2428
- }
2429
- // For methods and other properties, use Reflect
2430
- return Reflect.get(target, prop);
2431
- },
2432
- set(target, prop, value) {
2433
- // Handle special properties
2434
- if (prop === '_service') {
2435
- return Reflect.set(target, prop, value);
2380
+ // Wrap instance in Proxy for reactive property access. `name` is an alias for `modelName`.
2381
+ const sendUpdate = (target, prop, value) => {
2382
+ if (prop === 'modelName') {
2383
+ // Model name change - need to update Schema and database
2384
+ const context = target._getSnapshotContext();
2385
+ const oldName = context.modelName;
2386
+ const newName = value;
2387
+ if (oldName === newName) {
2388
+ logger(`Model name unchanged: "${oldName}"`);
2389
+ return;
2436
2390
  }
2437
- // Handle 'name' as an alias for 'modelName'
2438
- if (prop === 'name') {
2439
- prop = 'modelName';
2391
+ logger(`Updating model name from "${oldName}" to "${newName}"`);
2392
+ // Update Model instance cache using new ID-based structure
2393
+ const modelFileId = context.id; // id is now the schemaFileId (string)
2394
+ if (modelFileId) {
2395
+ Model.updateNameIndex(oldName, newName, context.schemaName, modelFileId);
2440
2396
  }
2441
- // Handle tracked properties
2442
- if (typeof prop === 'string' && TRACKED_PROPERTIES.includes(prop)) {
2443
- // Use the sendUpdate logic
2444
- if (prop === 'modelName') {
2445
- // Model name change - need to update Schema and database
2446
- const context = target._getSnapshotContext();
2447
- const oldName = context.modelName;
2448
- const newName = value;
2449
- if (oldName === newName) {
2450
- logger(`Model name unchanged: "${oldName}"`);
2451
- return true;
2452
- }
2453
- logger(`Updating model name from "${oldName}" to "${newName}"`);
2454
- // Update Model instance cache using new ID-based structure
2455
- const modelFileId = context.id; // id is now the schemaFileId (string)
2456
- if (modelFileId) {
2457
- Model.updateNameIndex(oldName, newName, context.schemaName, modelFileId);
2458
- }
2459
- else {
2460
- // Fallback to legacy cache if no ID (shouldn't happen, but safety)
2461
- const oldCacheKey = `${context.schemaName}:${oldName}`;
2462
- const newCacheKey = `${context.schemaName}:${newName}`;
2463
- if (Model.instanceCache.has(oldCacheKey)) {
2464
- const entry = Model.instanceCache.get(oldCacheKey);
2465
- Model.instanceCache.delete(oldCacheKey);
2466
- Model.instanceCache.set(newCacheKey, entry);
2467
- }
2468
- }
2469
- // Update Model context
2470
- target._service.send({
2471
- type: 'updateContext',
2472
- modelName: newName,
2473
- });
2474
- // Mark model as draft
2475
- target._service.send({
2476
- type: 'markAsDraft',
2477
- propertyKey: 'modelName',
2478
- });
2479
- // Save draft to database immediately so changes persist
2480
- trackDraftSave(target._service, target._saveDraftToDb(oldName, newName), `Model "${newName}"`);
2481
- // NOTE: Schema is not notified of model name changes during edits.
2482
- // Schema will read from Model instances when persisting/saving.
2483
- }
2484
- else if (prop === 'properties') {
2485
- // Properties are read-only computed values from ModelProperty instances
2486
- // Cannot be set directly - properties are managed via ModelProperty instances
2487
- throw new Error('Cannot set model.properties directly. Properties are computed from ModelProperty instances.');
2488
- }
2489
- else if (prop === 'description') {
2490
- // Description is not supported - JSON files can have it but we ignore it at runtime
2491
- throw new Error('Cannot set model.description. Description is not supported in runtime Model instances.');
2492
- }
2493
- else {
2494
- // Standard property update
2495
- target._service.send({
2496
- type: 'updateContext',
2497
- [prop]: value,
2498
- });
2397
+ else {
2398
+ // Fallback to legacy cache if no ID (shouldn't happen, but safety)
2399
+ const oldCacheKey = `${context.schemaName}:${oldName}`;
2400
+ const newCacheKey = `${context.schemaName}:${newName}`;
2401
+ if (Model.instanceCache.has(oldCacheKey)) {
2402
+ const entry = Model.instanceCache.get(oldCacheKey);
2403
+ Model.instanceCache.delete(oldCacheKey);
2404
+ Model.instanceCache.set(newCacheKey, entry);
2499
2405
  }
2500
- return true;
2501
2406
  }
2502
- // For non-tracked properties, use Reflect
2503
- return Reflect.set(target, prop, value);
2504
- },
2505
- has(target, prop) {
2506
- // Handle 'name' as an alias for 'modelName'
2407
+ // Update Model context
2408
+ target._service.send({
2409
+ type: 'updateContext',
2410
+ modelName: newName,
2411
+ });
2412
+ // Mark model as draft
2413
+ target._service.send({
2414
+ type: 'markAsDraft',
2415
+ propertyKey: 'modelName',
2416
+ });
2417
+ // Save draft to database immediately so changes persist
2418
+ trackDraftSave(target._service, target._saveDraftToDb(oldName, newName), `Model "${newName}"`);
2419
+ // NOTE: Schema is not notified of model name changes during edits.
2420
+ // Schema will read from Model instances when persisting/saving.
2421
+ }
2422
+ else {
2423
+ // Standard property update
2424
+ target._service.send({
2425
+ type: 'updateContext',
2426
+ [prop]: value,
2427
+ });
2428
+ }
2429
+ };
2430
+ const proxiedInstance = createReactiveProxy({
2431
+ instance: newInstance,
2432
+ service: newInstance._service,
2433
+ trackedProperties: TRACKED_PROPERTIES,
2434
+ getContext: (target) => target._getSnapshotContext(),
2435
+ sendUpdate,
2436
+ resolve: (target, prop) => {
2507
2437
  if (prop === 'name') {
2508
- return true;
2509
- }
2510
- // Handle 'id' property
2511
- if (prop === 'id') {
2512
- return true;
2513
- }
2514
- // Check tracked properties
2515
- if (typeof prop === 'string' && TRACKED_PROPERTIES.includes(prop)) {
2516
- const context = target._getSnapshotContext();
2517
- return prop in context;
2438
+ return {
2439
+ get: () => target._getSnapshotContext().modelName,
2440
+ set: (value) => sendUpdate(target, 'modelName', value),
2441
+ };
2518
2442
  }
2519
- return Reflect.has(target, prop);
2443
+ return undefined;
2520
2444
  },
2521
- ownKeys(target) {
2522
- // Include 'name' and 'id' in ownKeys
2523
- const keys = Reflect.ownKeys(target);
2524
- const additionalKeys = [];
2525
- if (!keys.includes('name')) {
2526
- additionalKeys.push('name');
2445
+ virtualKeys: () => ['name'],
2446
+ onSet: (_target, prop) => {
2447
+ if (prop === 'properties') {
2448
+ // Properties are read-only computed values from ModelProperty instances
2449
+ throw new Error('Cannot set model.properties directly. Properties are computed from ModelProperty instances.');
2527
2450
  }
2528
- if (!keys.includes('id')) {
2529
- additionalKeys.push('id');
2451
+ if (prop === 'description') {
2452
+ // Description is not supported - JSON files can have it but we ignore it at runtime
2453
+ throw new Error('Cannot set model.description. Description is not supported in runtime Model instances.');
2530
2454
  }
2531
- return additionalKeys.length > 0 ? [...keys, ...additionalKeys] : keys;
2532
- },
2533
- getOwnPropertyDescriptor(target, prop) {
2534
- // Handle 'name' as an alias for 'modelName'
2535
- if (prop === 'name') {
2536
- return getInvariantSafePropertyDescriptor(target, prop, {
2537
- value: target._getSnapshotContext().modelName,
2538
- });
2539
- }
2540
- // Handle 'id' property - returns the modelFileId
2541
- if (prop === 'id') {
2542
- return getInvariantSafePropertyDescriptor(target, prop, {
2543
- value: target._getSnapshotContext().id, // id is now the schemaFileId (string)
2544
- writable: false, // id is read-only
2545
- });
2546
- }
2547
- let invent;
2548
- if (typeof prop === 'string' && TRACKED_PROPERTIES.includes(prop)) {
2549
- const context = target._getSnapshotContext();
2550
- if (prop in context) {
2551
- invent = { value: context[prop] };
2552
- }
2553
- }
2554
- return getInvariantSafePropertyDescriptor(target, prop, invent);
2555
2455
  },
2556
2456
  });
2557
2457
  // Step 8: Store in new ID-based cache
2558
- // resolvedId is guaranteed to be defined at this point (generated if not provided)
2559
- this.instanceCacheById.set(resolvedId, {
2560
- instance: proxiedInstance,
2561
- refCount: 1,
2562
- });
2458
+ // resolvedId is guaranteed to be defined at this point (generated if not provided).
2459
+ // The ID and legacy caches share one entry: one hold count for the instance.
2460
+ const entry = { instance: proxiedInstance, refCount: holds };
2461
+ this.instanceCacheById.set(resolvedId, entry);
2563
2462
  // Step 9: Store in name-based index (placeholder key when !id; loadOrCreateModel will replace with final name)
2564
2463
  this.instanceCacheByName.set(nameKey, resolvedId);
2565
2464
  // Step 9b: When created with id (schema model) and unique name, also register original name so create(modelName) returns same instance
@@ -2567,10 +2466,7 @@ class Model {
2567
2466
  this.instanceCacheByName.set(originalNameKey, resolvedId);
2568
2467
  }
2569
2468
  // Step 10: Also store in legacy cache (for backward compatibility during migration)
2570
- this.instanceCache.set(nameKey, {
2571
- instance: proxiedInstance,
2572
- refCount: 1,
2573
- });
2469
+ this.instanceCache.set(nameKey, entry);
2574
2470
  logger(`Model.create: Created new instance for "${uniqueModelName}" (ID: ${id})`);
2575
2471
  // Model instance is now cached and accessible via Model.getById() and Model.getByName()
2576
2472
  // No wrapper or store registration needed
@@ -2851,42 +2747,80 @@ class Model {
2851
2747
  return this.waitUntilReady(proxiedInstance, readyTimeout);
2852
2748
  }
2853
2749
  /**
2854
- * Get Model instance by modelFileId (O(1) lookup)
2750
+ * Get Model instance by modelFileId (O(1) lookup). Takes a hold on the instance; release it with
2751
+ * `unload()`.
2855
2752
  */
2856
2753
  static getById(modelFileId) {
2857
2754
  const entry = this.instanceCacheById.get(modelFileId);
2858
- if (entry) {
2859
- // Increment ref count
2860
- this.instanceCacheById.set(modelFileId, {
2861
- instance: entry.instance,
2862
- refCount: entry.refCount + 1,
2863
- });
2864
- return entry.instance;
2755
+ if (!entry)
2756
+ return undefined;
2757
+ entry.refCount += 1;
2758
+ return entry.instance;
2759
+ }
2760
+ /**
2761
+ * @internal For a Schema loading its models: true when this load should take the schema's hold
2762
+ * on the model (pass no `hold` option), false when the schema already holds it (pass
2763
+ * `hold: false`). After a true, call `dropSchemaHold` if the load returns no model.
2764
+ */
2765
+ static takeSchemaHold(modelFileId) {
2766
+ if (!modelFileId || this.schemaHeldModelIds.has(modelFileId))
2767
+ return false;
2768
+ this.schemaHeldModelIds.add(modelFileId);
2769
+ return true;
2770
+ }
2771
+ /** @internal The load `takeSchemaHold` approved found no model: there is no hold to release. */
2772
+ static dropSchemaHold(modelFileId) {
2773
+ this.schemaHeldModelIds.delete(modelFileId);
2774
+ }
2775
+ /** @internal A Schema's last unload: releases its hold on each of its models. */
2776
+ static releaseSchemaHolds(schemaName) {
2777
+ for (const modelFileId of [...this.schemaHeldModelIds]) {
2778
+ const model = this.peek(modelFileId);
2779
+ if (!model) {
2780
+ this.schemaHeldModelIds.delete(modelFileId);
2781
+ continue;
2782
+ }
2783
+ if (model._getSnapshotContext().schemaName !== schemaName)
2784
+ continue;
2785
+ this.schemaHeldModelIds.delete(modelFileId);
2786
+ model.unload();
2865
2787
  }
2866
- return undefined;
2867
2788
  }
2868
2789
  /**
2869
- * Get Model instance by name (O(1) lookup via name→ID mapping)
2790
+ * The cached Model with this modelFileId, without taking a hold. For SDK code that reads the
2791
+ * model and doesn't hand it to a caller; callers that keep it use `getById`, `find` or `create`.
2792
+ */
2793
+ static peek(modelFileId) {
2794
+ return this.instanceCacheById.get(modelFileId)?.instance;
2795
+ }
2796
+ /**
2797
+ * Get Model instance by name (O(1) lookup via name→ID mapping). Takes a hold on the instance;
2798
+ * release it with `unload()`.
2870
2799
  *
2871
2800
  * @param modelName - The name of the model
2872
2801
  * @param schemaName - The schema name (optional, will query DB if not provided)
2873
2802
  * @returns The Model instance if found, undefined otherwise
2874
2803
  */
2875
2804
  static getByName(modelName, schemaName) {
2805
+ const model = this.peekByName(modelName, schemaName);
2806
+ return model?.id ? this.getById(model.id) : undefined;
2807
+ }
2808
+ /**
2809
+ * `getByName` without taking a hold. Without `schemaName` it searches every cached schema and
2810
+ * throws AmbiguousModelError when models from several schemas share the name; callers that know
2811
+ * the schema or model id should use Model.resolve() instead.
2812
+ */
2813
+ static peekByName(modelName, schemaName) {
2876
2814
  if (schemaName) {
2877
- const nameKey = `${schemaName}:${modelName}`;
2878
- const id = this.instanceCacheByName.get(nameKey);
2879
- if (!id) {
2880
- return undefined;
2881
- }
2882
- return this.getById(id);
2815
+ const id = this.instanceCacheByName.get(`${schemaName}:${modelName}`);
2816
+ return id ? this.peek(id) : undefined;
2883
2817
  }
2884
- // If schemaName not provided, search all name keys. Model names are only unique per schema, so
2885
- // this throws AmbiguousModelError when cached models from several schemas share the name.
2886
- // Callers that know the schema or model id should use Model.resolve() instead.
2887
2818
  return this._getUniqueCachedModel(modelName, (cachedModelName) => cachedModelName === modelName);
2888
2819
  }
2889
- /** The one cached Model whose name matches, or AmbiguousModelError if models from several schemas do. */
2820
+ /**
2821
+ * The one cached Model whose name matches (no hold taken), or AmbiguousModelError if models from
2822
+ * several schemas do.
2823
+ */
2890
2824
  static _getUniqueCachedModel(label, matches) {
2891
2825
  const matchesById = new Map(); // modelFileId -> schemaName
2892
2826
  for (const [nameKey, id] of this.instanceCacheByName.entries()) {
@@ -2900,32 +2834,32 @@ class Model {
2900
2834
  throw new AmbiguousModelError(label, [...matchesById.values()]);
2901
2835
  }
2902
2836
  const [matchId] = matchesById.keys();
2903
- return matchId ? this.getById(matchId) : undefined;
2837
+ return matchId ? this.peek(matchId) : undefined;
2904
2838
  }
2905
2839
  /**
2906
2840
  * Resolve a cached Model from the most specific scope available: modelFileId (Model.id), then
2907
- * schemaName + modelName, then modelName alone.
2841
+ * schemaName + modelName, then modelName alone. Takes no hold.
2908
2842
  */
2909
2843
  static resolve(modelName, scope = {}) {
2910
2844
  if (scope.modelFileId) {
2911
- const byId = this.getById(scope.modelFileId);
2845
+ const byId = this.peek(scope.modelFileId);
2912
2846
  if (byId)
2913
2847
  return byId;
2914
2848
  }
2915
2849
  if (!modelName)
2916
2850
  return undefined;
2917
2851
  if (scope.schemaName) {
2918
- const bySchema = this.getByName(modelName, scope.schemaName);
2852
+ const bySchema = this.peekByName(modelName, scope.schemaName);
2919
2853
  if (bySchema)
2920
2854
  return bySchema;
2921
2855
  }
2922
- return this.getByName(modelName);
2856
+ return this.peekByName(modelName);
2923
2857
  }
2924
2858
  /**
2925
2859
  * Find Model by modelType (an EAS model name, as seeds.type stores it). Matched as ADR 0008
2926
2860
  * matches EAS names: `new_model` finds "New model", and `htmlpage` (an older SDK's name) finds
2927
2861
  * "HTMLPage", unless HTMLPage's nameMatch (ADR 0009) is `exact`. Only the tightest matching tier
2928
- * counts; matches in several schemas are ambiguous.
2862
+ * counts; matches in several schemas are ambiguous. Takes no hold.
2929
2863
  */
2930
2864
  static findByModelType(modelType) {
2931
2865
  if (!modelType)
@@ -2937,7 +2871,7 @@ class Model {
2937
2871
  return this._getUniqueCachedModel(modelType, (cachedModelName) => best.has(cachedModelName));
2938
2872
  }
2939
2873
  /**
2940
- * Get all Model instances for a schema from cache only (synchronous).
2874
+ * Get all Model instances for a schema from cache only (synchronous). Takes no holds.
2941
2875
  * Includes models created at runtime via Model.create() that may not yet be in schema context.
2942
2876
  */
2943
2877
  static getCachedInstancesForSchema(schemaName) {
@@ -2946,7 +2880,7 @@ class Model {
2946
2880
  for (const [nameKey, id] of this.instanceCacheByName.entries()) {
2947
2881
  const [cachedSchemaName] = nameKey.split(':');
2948
2882
  if (cachedSchemaName === schemaName && id && !seen.has(id)) {
2949
- const instance = this.getById(id);
2883
+ const instance = this.peek(id);
2950
2884
  if (instance) {
2951
2885
  instances.push(instance);
2952
2886
  seen.add(id);
@@ -2968,16 +2902,16 @@ class Model {
2968
2902
  }
2969
2903
  /**
2970
2904
  * Async Model.resolve(): exact cache hit by modelFileId or schemaName+modelName, else the DB row for
2971
- * that scope (instantiating the Model), and only then the name-only fallback.
2905
+ * that scope (instantiating the Model), and only then the name-only fallback. Takes no hold.
2972
2906
  */
2973
2907
  static async resolveAsync(modelName, scope = {}) {
2974
2908
  if (scope.modelFileId) {
2975
- const byId = this.getById(scope.modelFileId);
2909
+ const byId = this.peek(scope.modelFileId);
2976
2910
  if (byId)
2977
2911
  return byId;
2978
2912
  }
2979
2913
  if (modelName && scope.schemaName) {
2980
- const bySchema = this.getByName(modelName, scope.schemaName);
2914
+ const bySchema = this.peekByName(modelName, scope.schemaName);
2981
2915
  if (bySchema)
2982
2916
  return bySchema;
2983
2917
  }
@@ -3006,7 +2940,7 @@ class Model {
3006
2940
  return undefined;
3007
2941
  if (modelDestroyedSince(record.modelFileId, evictionEpoch))
3008
2942
  return undefined;
3009
- return this.create(record.modelName, record.schemaName, { id: record.modelFileId });
2943
+ return this.create(record.modelName, record.schemaName, { id: record.modelFileId, hold: false });
3010
2944
  }
3011
2945
  }
3012
2946
  catch (error) {
@@ -3014,7 +2948,7 @@ class Model {
3014
2948
  }
3015
2949
  }
3016
2950
  }
3017
- return modelName ? this.getByNameAsync(modelName) : undefined;
2951
+ return modelName ? this.getByNameAsync(modelName, undefined, { hold: false }) : undefined;
3018
2952
  }
3019
2953
  /**
3020
2954
  * Get Model instance by name, querying database if not in cache
@@ -3022,11 +2956,11 @@ class Model {
3022
2956
  *
3023
2957
  * @param modelName - The name of the model
3024
2958
  * @param schemaName - Optional schema name (will query DB if not provided)
3025
- * @returns The Model instance if found, undefined otherwise
2959
+ * @returns The Model instance if found, undefined otherwise. Takes a hold unless `hold: false`.
3026
2960
  */
3027
2961
  static async getByNameAsync(modelName, schemaName, options) {
3028
2962
  // First try cache
3029
- const cached = this.getByName(modelName, schemaName);
2963
+ const cached = options?.hold === false ? this.peekByName(modelName, schemaName) : this.getByName(modelName, schemaName);
3030
2964
  if (cached) {
3031
2965
  return cached;
3032
2966
  }
@@ -3039,8 +2973,8 @@ class Model {
3039
2973
  const evictionEpoch = options?.evictionEpoch ?? currentEvictionEpoch();
3040
2974
  try {
3041
2975
  // Query model by name (throws AmbiguousModelError when several schemas define it)
3042
- const _mod_10 = await import('./index-DpgQMIRq.js');
3043
- const _ns_10 = _mod_10.bh;
2976
+ const _mod_10 = await import('./index-CI0NFf4B.js');
2977
+ const _ns_10 = _mod_10.bl;
3044
2978
  const { resolveModelRecord } = _ns_10;
3045
2979
  const resolved = await resolveModelRecord(modelName, {}, db);
3046
2980
  if (!resolved?.schemaFileId) {
@@ -3074,6 +3008,7 @@ class Model {
3074
3008
  // Create model instance (will be cached)
3075
3009
  return this.create(record.modelName, record.schemaName, {
3076
3010
  id: record.modelFileId, // id is now the schemaFileId (string)
3011
+ ...(options?.hold === false && { hold: false }),
3077
3012
  });
3078
3013
  }
3079
3014
  catch (error) {
@@ -3097,7 +3032,7 @@ class Model {
3097
3032
  return undefined;
3098
3033
  }
3099
3034
  // Step 1: Check cache first (fast path)
3100
- const cached = this.getById(modelFileId);
3035
+ const cached = options?.hold === false ? this.peek(modelFileId) : this.getById(modelFileId);
3101
3036
  if (cached) {
3102
3037
  logger(`Model.createById: Found instance in cache for ID "${modelFileId}"`);
3103
3038
  return cached;
@@ -3146,6 +3081,7 @@ class Model {
3146
3081
  logger(`Model.createById: Creating model "${modelName}" in schema "${schemaName}" from ID "${modelFileId}"`);
3147
3082
  return this.create(modelName, schemaName, {
3148
3083
  id: modelFileId, // id is now the schemaFileId (string)
3084
+ ...(options?.hold === false && { hold: false }),
3149
3085
  });
3150
3086
  }
3151
3087
  catch (error) {
@@ -3252,7 +3188,8 @@ class Model {
3252
3188
  * Get all Model instances, optionally filtered by schema.
3253
3189
  * When DB is available, loads from DB via getModelsData; otherwise returns from cache.
3254
3190
  * With waitForReady, waits for each model to be ready (idle, with any properties from Model.create
3255
- * created) and leaves out models that error or time out.
3191
+ * created) and leaves out models that error or time out. Takes no holds: a caller that keeps a
3192
+ * model uses `Model.find` or `Model.create`.
3256
3193
  */
3257
3194
  static async all(schemaName, options) {
3258
3195
  const { waitForReady = false, readyTimeout = DEFAULT_READY_TIMEOUT_MS } = options ?? {};
@@ -3264,7 +3201,7 @@ class Model {
3264
3201
  for (const [nameKey, id] of this.instanceCacheByName.entries()) {
3265
3202
  const [cachedSchemaName] = nameKey.split(':');
3266
3203
  if (cachedSchemaName === schemaName) {
3267
- const instance = this.getById(id);
3204
+ const instance = this.peek(id);
3268
3205
  if (instance && !seen.has(id)) {
3269
3206
  instances.push(instance);
3270
3207
  seen.add(id);
@@ -3307,7 +3244,7 @@ class Model {
3307
3244
  for (const row of rows) {
3308
3245
  // A model can appear more than once (e.g. duplicate model_schemas links); return it once.
3309
3246
  if (row.schemaFileId && !seen.has(row.schemaFileId)) {
3310
- const instance = await this.createById(row.schemaFileId);
3247
+ const instance = await this.createById(row.schemaFileId, { hold: false });
3311
3248
  if (instance && !seen.has(instance.id ?? row.schemaFileId)) {
3312
3249
  instances.push(instance);
3313
3250
  seen.add(instance.id ?? row.schemaFileId);
@@ -3319,7 +3256,7 @@ class Model {
3319
3256
  for (const [nameKey, id] of this.instanceCacheByName.entries()) {
3320
3257
  const [cachedSchemaName] = nameKey.split(':');
3321
3258
  if (cachedSchemaName === schemaName && id && !seen.has(id)) {
3322
- const instance = this.getById(id);
3259
+ const instance = this.peek(id);
3323
3260
  if (instance) {
3324
3261
  instances.push(instance);
3325
3262
  seen.add(id);
@@ -3699,6 +3636,8 @@ class Model {
3699
3636
  if (context.schemaName !== schemaName)
3700
3637
  continue;
3701
3638
  const nameKey = `${context.schemaName}:${context.modelName}`;
3639
+ if (context.id)
3640
+ this.schemaHeldModelIds.delete(context.id);
3702
3641
  clearDestroySubscriptions(instance, { instanceState: modelInstanceState });
3703
3642
  forceRemoveFromCaches(instance, {
3704
3643
  getCacheKeys: () => (context.id ? [context.id, nameKey] : [nameKey]),
@@ -3765,6 +3704,8 @@ class Model {
3765
3704
  // Before the caches are cleared, so a lookup by id already reading the row doesn't re-cache it
3766
3705
  if (modelFileId)
3767
3706
  recordModelDestroy(modelFileId);
3707
+ if (modelFileId)
3708
+ Model.schemaHeldModelIds.delete(modelFileId);
3768
3709
  const cacheKeys = [];
3769
3710
  if (modelFileId)
3770
3711
  cacheKeys.push(modelFileId);
@@ -3792,7 +3733,7 @@ class Model {
3792
3733
  .limit(1);
3793
3734
  if (modelRecords.length > 0) {
3794
3735
  const modelId = modelRecords[0].id;
3795
- const { detachModelRows } = await import('./detachRowsBeforeDelete-D1TyEMco.js');
3736
+ const { detachModelRows } = await import('./detachRowsBeforeDelete-CLbBbpX4.js');
3796
3737
  await detachModelRows(db, [typeof modelId === 'string' ? parseInt(modelId, 10) : modelId]);
3797
3738
  await db.delete(modelSchemas).where(eq(modelSchemas.modelId, modelId));
3798
3739
  await db
@@ -3803,10 +3744,10 @@ class Model {
3803
3744
  }
3804
3745
  if (schemaName && modelName) {
3805
3746
  // Imported here, not at module load: Model and Schema import each other.
3806
- const _mod_11 = await import('./Schema-O1QLoXv6.js');
3747
+ const _mod_11 = await import('./Schema-D-TczaIj.js');
3807
3748
  const _ns_11 = _mod_11.b;
3808
3749
  const { Schema } = _ns_11;
3809
- const schema = Schema.create(schemaName, { waitForReady: false });
3750
+ const schema = Schema.create(schemaName, { waitForReady: false, hold: false });
3810
3751
  const schemaContext = schema.getService().getSnapshot().context;
3811
3752
  if (schemaContext.models?.[modelName]) {
3812
3753
  const updatedModels = { ...schemaContext.models };
@@ -3847,8 +3788,8 @@ class Model {
3847
3788
  return undefined;
3848
3789
  }
3849
3790
  // Model names are only unique per schema: find this model's row by its id (schemaFileId).
3850
- const _mod_12 = await import('./index-DpgQMIRq.js');
3851
- const _ns_12 = _mod_12.bh;
3791
+ const _mod_12 = await import('./index-CI0NFf4B.js');
3792
+ const _ns_12 = _mod_12.bl;
3852
3793
  const { resolveModelRecord } = _ns_12;
3853
3794
  const modelRecord = await resolveModelRecord(modelName, { modelFileId: context.id, schemaName: context.schemaName }, db);
3854
3795
  if (!modelRecord?.id) {
@@ -4048,6 +3989,12 @@ Model.savingModels = new Set();
4048
3989
  Model.cachedClientInitialized = null;
4049
3990
  Model.clientCheckTime = 0;
4050
3991
  Model.CLIENT_CHECK_CACHE_MS = 50; // Cache for 50ms to avoid excessive checks
3992
+ /**
3993
+ * Models their schema holds, by modelFileId. A schema's first load of a model takes one hold for
3994
+ * the schema, and the schema's last unload releases it (releaseSchemaHolds), so a user's unload
3995
+ * can't drop a model out of `schema.models` while the schema is loaded.
3996
+ */
3997
+ Model.schemaHeldModelIds = new Set();
4051
3998
 
4052
3999
  var Model$1 = /*#__PURE__*/Object.freeze({
4053
4000
  __proto__: null,
@@ -4107,5 +4054,5 @@ var errors = /*#__PURE__*/Object.freeze({
4107
4054
  UnknownModelError: UnknownModelError
4108
4055
  });
4109
4056
 
4110
- export { ConflictError as C, ItemCreateValidationError as I, Model as M, TModelSchema as T, UnknownModelError as U, TModelValues as a, anyEvictionSince as b, currentEvictionEpoch as c, ItemCreateError as d, setupEntityLiveQuery as e, finishSchemaDestroy as f, getDraftSaveError as g, writeToDatabase$1 as h, isActorStopped as i, Model$1 as j, errors as k, recordSchemaDestroy as r, schemaEvictedSince as s, trackDraftSave as t, writeProcessMachine as w };
4111
- //# sourceMappingURL=errors-KM-yq2MD.js.map
4057
+ export { ConflictError as C, ItemCreateValidationError as I, Model as M, TModelSchema as T, UnknownModelError as U, TModelValues as a, anyEvictionSince as b, currentEvictionEpoch as c, ItemCreateError as d, setupEntityLiveQuery as e, finishSchemaDestroy as f, getDraftSaveError as g, writeToDatabase$1 as h, Model$1 as i, errors as j, recordSchemaDestroy as r, schemaEvictedSince as s, trackDraftSave as t, writeProcessMachine as w };
4058
+ //# sourceMappingURL=errors-BGk_IJO5.js.map