@seedprotocol/sdk 0.6.10 → 0.7.0

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 (382) hide show
  1. package/dist/{BasePathResolver-B6CKqoKw.js → BasePathResolver-ndE8XTpw.js} +36 -2
  2. package/dist/BasePathResolver-ndE8XTpw.js.map +1 -0
  3. package/dist/ClientManager-DLleL_2e.js +4763 -0
  4. package/dist/ClientManager-DLleL_2e.js.map +1 -0
  5. package/dist/{ClientManager-ChcmUL47.js → Item-zBFWQDU9.js} +1119 -5893
  6. package/dist/Item-zBFWQDU9.js.map +1 -0
  7. package/dist/{ModelProperty-D79uV42p.js → ModelProperty-lth9L37R.js} +289 -101
  8. package/dist/ModelProperty-lth9L37R.js.map +1 -0
  9. package/dist/{Schema-a8uO-hIZ.js → Schema-DOhlrQ-N.js} +94 -864
  10. package/dist/Schema-DOhlrQ-N.js.map +1 -0
  11. package/dist/{SchemaValidationService-Y49vqast.js → SchemaValidationService-DDKr5piy.js} +26 -18
  12. package/dist/SchemaValidationService-DDKr5piy.js.map +1 -0
  13. package/dist/{backfillMetadataPropertyIds-CBsf7LnU.js → backfillMetadataPropertyIds-fG3ujaSh.js} +11 -6
  14. package/dist/backfillMetadataPropertyIds-fG3ujaSh.js.map +1 -0
  15. package/dist/cjs/{ModelProperty-D9FGaGuE.js → ModelProperty-BEsIHAjk.js} +260 -81
  16. package/dist/cjs/ModelProperty-BEsIHAjk.js.map +1 -0
  17. package/dist/cjs/{Schema-BiJIPLEL.js → Schema-qEp5mH1N.js} +66 -847
  18. package/dist/cjs/Schema-qEp5mH1N.js.map +1 -0
  19. package/dist/cjs/{SchemaValidationService-DtYs_CNY.js → SchemaValidationService-CWEnZmOH.js} +18 -11
  20. package/dist/cjs/SchemaValidationService-CWEnZmOH.js.map +1 -0
  21. package/dist/cjs/{backfillMetadataPropertyIds-2XaN3b9S.js → backfillMetadataPropertyIds-tw8JGMT0.js} +8 -3
  22. package/dist/cjs/backfillMetadataPropertyIds-tw8JGMT0.js.map +1 -0
  23. package/dist/cjs/{eas-CMNppmGE.js → eas-CLiV2Hmn.js} +4 -4
  24. package/dist/cjs/{eas-CMNppmGE.js.map → eas-CLiV2Hmn.js.map} +1 -1
  25. package/dist/cjs/{getItem-B6jEINjW.js → getItem-DSRtx_68.js} +2 -2
  26. package/dist/cjs/{getItem-B6jEINjW.js.map → getItem-DSRtx_68.js.map} +1 -1
  27. package/dist/cjs/getLatestVersionRow-DVizNNoI.js +59 -0
  28. package/dist/cjs/getLatestVersionRow-DVizNNoI.js.map +1 -0
  29. package/dist/cjs/{getPublishPayload-D5DhLGvN.js → getPublishPayload-D5-dYtNq.js} +249 -60
  30. package/dist/cjs/getPublishPayload-D5-dYtNq.js.map +1 -0
  31. package/dist/cjs/{getPublishUploads-DMhCCKYF.js → getPublishUploads-B5Lq6q-_.js} +20 -13
  32. package/dist/cjs/getPublishUploads-B5Lq6q-_.js.map +1 -0
  33. package/dist/cjs/{getSegmentedItemProperties-CU8rtBAo.js → getSegmentedItemProperties-giHO7R3d.js} +10 -11
  34. package/dist/cjs/getSegmentedItemProperties-giHO7R3d.js.map +1 -0
  35. package/dist/cjs/{index-DPp9rdRL.js → index-B3UDbm1C.js} +3 -3
  36. package/dist/cjs/index-B3UDbm1C.js.map +1 -0
  37. package/dist/cjs/{index-CSNtEnbF.js → index-C66AfYDG.js} +2510 -1694
  38. package/dist/cjs/index-C66AfYDG.js.map +1 -0
  39. package/dist/cjs/{property-DlKiAWt4.js → property-BVJIP7SX.js} +40 -35
  40. package/dist/cjs/property-BVJIP7SX.js.map +1 -0
  41. package/dist/cjs/resetAmbiguousLegacyItemData-BaZqUui9.js +116 -0
  42. package/dist/cjs/resetAmbiguousLegacyItemData-BaZqUui9.js.map +1 -0
  43. package/dist/cjs/resolveModelForSyncedSeed-CC6dQctx.js +49 -0
  44. package/dist/cjs/resolveModelForSyncedSeed-CC6dQctx.js.map +1 -0
  45. package/dist/cjs/syncDbWithEas-Dk96sAG-.js +873 -0
  46. package/dist/cjs/syncDbWithEas-Dk96sAG-.js.map +1 -0
  47. package/dist/{configurePlatform-CE0Vew17.js → configurePlatform-BMoPG9vY.js} +4 -4
  48. package/dist/{configurePlatform-CE0Vew17.js.map → configurePlatform-BMoPG9vY.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-BJZN0a0a.js} +546 -106
  65. package/dist/db-BJZN0a0a.js.map +1 -0
  66. package/dist/{eas-CfYCu4IX.js → eas-B0hsMLqt.js} +7 -7
  67. package/dist/eas-B0hsMLqt.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-DEh4WfHG.js} +8 -10
  71. package/dist/{getItem-Br-bGNFO.js.map → getItem-DEh4WfHG.js.map} +1 -1
  72. package/dist/getLatestVersionRow-Brrl1AnW.js +46 -0
  73. package/dist/getLatestVersionRow-Brrl1AnW.js.map +1 -0
  74. package/dist/{getPublishPayload-BIrTVUxb.js → getPublishPayload-H032DHC7.js} +263 -75
  75. package/dist/getPublishPayload-H032DHC7.js.map +1 -0
  76. package/dist/{getPublishUploads-C6cDeZdz.js → getPublishUploads-CR66RlGJ.js} +25 -17
  77. package/dist/{getPublishUploads-C6cDeZdz.js.map → getPublishUploads-CR66RlGJ.js.map} +1 -1
  78. package/dist/{getSegmentedItemProperties-BmKE71vU.js → getSegmentedItemProperties-C2EJ2G0N.js} +13 -14
  79. package/dist/getSegmentedItemProperties-C2EJ2G0N.js.map +1 -0
  80. package/dist/{index-ClSv5pTA.js → index-6bJuv5Tt.js} +12 -11
  81. package/dist/index-6bJuv5Tt.js.map +1 -0
  82. package/dist/{index-Djd3667v.js → index-B0LgJblD.js} +2 -2
  83. package/dist/index-B0LgJblD.js.map +1 -0
  84. package/dist/{index-HRHkbVQd.js → index-DtfjeuxC.js} +417 -174
  85. package/dist/index-DtfjeuxC.js.map +1 -0
  86. package/dist/index.browser-CNrqhvEA.js +4139 -0
  87. package/dist/index.browser-CNrqhvEA.js.map +1 -0
  88. package/dist/{index.node-DBtQkEfz.js → index.node-DrHiTuOr.js} +9 -4
  89. package/dist/index.node-DrHiTuOr.js.map +1 -0
  90. package/dist/main.cjs +1 -1
  91. package/dist/main.js +771 -521
  92. package/dist/main.js.map +1 -1
  93. package/dist/node.js +19 -15
  94. package/dist/node.js.map +1 -1
  95. package/dist/platform.browser.js +18 -3719
  96. package/dist/platform.browser.js.map +1 -1
  97. package/dist/platform.node.js +3 -3
  98. package/dist/{property-CQjuZ4JW.js → property-D2Nnsmm1.js} +53 -48
  99. package/dist/property-D2Nnsmm1.js.map +1 -0
  100. package/dist/resetAmbiguousLegacyItemData-BqbHNUYk.js +88 -0
  101. package/dist/resetAmbiguousLegacyItemData-BqbHNUYk.js.map +1 -0
  102. package/dist/resolveModelForSyncedSeed-DQK6JfXS.js +46 -0
  103. package/dist/resolveModelForSyncedSeed-DQK6JfXS.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 +10 -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 +3 -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 +37 -0
  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/modelMachine.d.ts +0 -8
  131. package/dist/src/Model/service/modelMachine.d.ts.map +1 -1
  132. package/dist/src/ModelProperty/ModelProperty.d.ts +33 -1
  133. package/dist/src/ModelProperty/ModelProperty.d.ts.map +1 -1
  134. package/dist/src/ModelProperty/service/actors/compareAndMarkDraft.d.ts.map +1 -1
  135. package/dist/src/ModelProperty/service/modelPropertyMachine.d.ts +2 -9
  136. package/dist/src/ModelProperty/service/modelPropertyMachine.d.ts.map +1 -1
  137. package/dist/src/Schema/Schema.d.ts +1 -2
  138. package/dist/src/Schema/Schema.d.ts.map +1 -1
  139. package/dist/src/Schema/service/schemaMachine.d.ts +1 -217
  140. package/dist/src/Schema/service/schemaMachine.d.ts.map +1 -1
  141. package/dist/src/Schema/service/validation/SchemaValidationService.d.ts.map +1 -1
  142. package/dist/src/browser/db/Db.d.ts +3 -0
  143. package/dist/src/browser/db/Db.d.ts.map +1 -1
  144. package/dist/src/browser/db/drizzleFiles.d.ts +7 -2
  145. package/dist/src/browser/db/drizzleFiles.d.ts.map +1 -1
  146. package/dist/src/browser/db/embeddedMigrations.d.ts +11 -2
  147. package/dist/src/browser/db/embeddedMigrations.d.ts.map +1 -1
  148. package/dist/src/browser/db/sqliteBusyRetry.d.ts +14 -0
  149. package/dist/src/browser/db/sqliteBusyRetry.d.ts.map +1 -0
  150. package/dist/src/browser/helpers/FileManager.d.ts +1 -0
  151. package/dist/src/browser/helpers/FileManager.d.ts.map +1 -1
  152. package/dist/src/browser/helpers/QueryClient.d.ts +1 -0
  153. package/dist/src/browser/helpers/QueryClient.d.ts.map +1 -1
  154. package/dist/src/browser/helpers/opfsErrors.d.ts +2 -0
  155. package/dist/src/browser/helpers/opfsErrors.d.ts.map +1 -0
  156. package/dist/src/browser/helpers/tolerantWebAccess.d.ts +47 -0
  157. package/dist/src/browser/helpers/tolerantWebAccess.d.ts.map +1 -0
  158. package/dist/src/browser/workers/FileDownloader.d.ts.map +1 -1
  159. package/dist/src/browser/workers/ImageResizer.d.ts.map +1 -1
  160. package/dist/src/browser/workers/filesDownload.d.ts.map +1 -1
  161. package/dist/src/browser/workers/imageResize.d.ts.map +1 -1
  162. package/dist/src/client/ClientManager.d.ts.map +1 -1
  163. package/dist/src/client/actors/addModelsToDb.d.ts +14 -0
  164. package/dist/src/client/actors/addModelsToDb.d.ts.map +1 -1
  165. package/dist/src/client/actors/platformClassesInit.d.ts.map +1 -1
  166. package/dist/src/client/actors/processSchemaFiles.d.ts.map +1 -1
  167. package/dist/src/client/actors/saveConfig.d.ts +11 -0
  168. package/dist/src/client/actors/saveConfig.d.ts.map +1 -1
  169. package/dist/src/client/constants.d.ts +0 -8
  170. package/dist/src/client/constants.d.ts.map +1 -1
  171. package/dist/src/db/backfillMetadataPropertyIds.d.ts.map +1 -1
  172. package/dist/src/db/configs/{dev.schema.config.d.ts → migrations.config.d.ts} +1 -1
  173. package/dist/src/db/configs/migrations.config.d.ts.map +1 -0
  174. package/dist/src/db/read/batchLatestPublishedVersionBySeedLocalIds.d.ts +1 -1
  175. package/dist/src/db/read/batchLatestPublishedVersionBySeedLocalIds.d.ts.map +1 -1
  176. package/dist/src/db/read/getItemData.d.ts.map +1 -1
  177. package/dist/src/db/read/getItemProperties.d.ts.map +1 -1
  178. package/dist/src/db/read/getItems.d.ts +7 -2
  179. package/dist/src/db/read/getItems.d.ts.map +1 -1
  180. package/dist/src/db/read/getLatestPublishedVersionRow.d.ts +2 -1
  181. package/dist/src/db/read/getLatestPublishedVersionRow.d.ts.map +1 -1
  182. package/dist/src/db/read/getLatestVersionRow.d.ts +13 -0
  183. package/dist/src/db/read/getLatestVersionRow.d.ts.map +1 -0
  184. package/dist/src/db/read/getModelSchemas.d.ts.map +1 -1
  185. package/dist/src/db/read/getPropertyData.d.ts.map +1 -1
  186. package/dist/src/db/read/getPublishPayload.d.ts +9 -11
  187. package/dist/src/db/read/getPublishPayload.d.ts.map +1 -1
  188. package/dist/src/db/read/getPublishPendingDiff.d.ts +2 -1
  189. package/dist/src/db/read/getPublishPendingDiff.d.ts.map +1 -1
  190. package/dist/src/db/read/getPublishUploads.d.ts.map +1 -1
  191. package/dist/src/db/read/getSchemaUidForModel.d.ts.map +1 -1
  192. package/dist/src/db/read/getSeedPublishState.d.ts +8 -2
  193. package/dist/src/db/read/getSeedPublishState.d.ts.map +1 -1
  194. package/dist/src/db/read/isSeedRevoked.d.ts +7 -0
  195. package/dist/src/db/read/isSeedRevoked.d.ts.map +1 -0
  196. package/dist/src/db/read/publishErrors.d.ts +37 -0
  197. package/dist/src/db/read/publishErrors.d.ts.map +1 -0
  198. package/dist/src/db/read/resolveModelForSyncedSeed.d.ts +39 -0
  199. package/dist/src/db/read/resolveModelForSyncedSeed.d.ts.map +1 -0
  200. package/dist/src/db/read/resolveModelRecord.d.ts +69 -0
  201. package/dist/src/db/read/resolveModelRecord.d.ts.map +1 -0
  202. package/dist/src/db/read/resolveRelatedSeedRef.d.ts +34 -0
  203. package/dist/src/db/read/resolveRelatedSeedRef.d.ts.map +1 -0
  204. package/dist/src/db/read/subqueries/liveVersion.d.ts +12 -0
  205. package/dist/src/db/read/subqueries/liveVersion.d.ts.map +1 -0
  206. package/dist/src/db/read/subqueries/metadataLatest.d.ts +4 -0
  207. package/dist/src/db/read/subqueries/metadataLatest.d.ts.map +1 -1
  208. package/dist/src/db/read/subqueries/versionData.d.ts +7 -2
  209. package/dist/src/db/read/subqueries/versionData.d.ts.map +1 -1
  210. package/dist/src/db/read/summarizePublishWork.d.ts +10 -2
  211. package/dist/src/db/read/summarizePublishWork.d.ts.map +1 -1
  212. package/dist/src/db/resetAmbiguousLegacyItemData.d.ts +17 -0
  213. package/dist/src/db/resetAmbiguousLegacyItemData.d.ts.map +1 -0
  214. package/dist/src/db/sqlParamBatches.d.ts +27 -0
  215. package/dist/src/db/sqlParamBatches.d.ts.map +1 -0
  216. package/dist/src/db/write/addExcludedTransactions.d.ts +7 -0
  217. package/dist/src/db/write/addExcludedTransactions.d.ts.map +1 -0
  218. package/dist/src/db/write/applyPropertyAttestationUidsFromPublish.d.ts +6 -0
  219. package/dist/src/db/write/applyPropertyAttestationUidsFromPublish.d.ts.map +1 -1
  220. package/dist/src/db/write/createMetadata.d.ts +2 -0
  221. package/dist/src/db/write/createMetadata.d.ts.map +1 -1
  222. package/dist/src/db/write/createNewItem.d.ts +3 -1
  223. package/dist/src/db/write/createNewItem.d.ts.map +1 -1
  224. package/dist/src/db/write/createSeed.d.ts +2 -1
  225. package/dist/src/db/write/createSeed.d.ts.map +1 -1
  226. package/dist/src/db/write/createSeeds.d.ts +1 -1
  227. package/dist/src/db/write/createSeeds.d.ts.map +1 -1
  228. package/dist/src/db/write/linkModelToSchema.d.ts +12 -0
  229. package/dist/src/db/write/linkModelToSchema.d.ts.map +1 -0
  230. package/dist/src/db/write/updateItemPropertyValue.d.ts.map +1 -1
  231. package/dist/src/db/write/updateMetadata.d.ts.map +1 -1
  232. package/dist/src/db/write/updateSeedRevokedAt.d.ts +11 -1
  233. package/dist/src/db/write/updateSeedRevokedAt.d.ts.map +1 -1
  234. package/dist/src/db/write/updateSeedUid.d.ts.map +1 -1
  235. package/dist/src/db/write/updateVersionUid.d.ts +2 -1
  236. package/dist/src/db/write/updateVersionUid.d.ts.map +1 -1
  237. package/dist/src/events/files/download.d.ts.map +1 -1
  238. package/dist/src/events/item/easSyncManager.d.ts +2 -0
  239. package/dist/src/events/item/easSyncManager.d.ts.map +1 -1
  240. package/dist/src/events/item/index.d.ts.map +1 -1
  241. package/dist/src/events/item/syncDbWithEas.d.ts +16 -0
  242. package/dist/src/events/item/syncDbWithEas.d.ts.map +1 -1
  243. package/dist/src/helpers/FileManager/BaseFileManager.d.ts +1 -0
  244. package/dist/src/helpers/FileManager/BaseFileManager.d.ts.map +1 -1
  245. package/dist/src/helpers/FileManager/IFileManager.d.ts +5 -0
  246. package/dist/src/helpers/FileManager/IFileManager.d.ts.map +1 -1
  247. package/dist/src/helpers/FileManager/errors.d.ts +10 -0
  248. package/dist/src/helpers/FileManager/errors.d.ts.map +1 -0
  249. package/dist/src/helpers/compareMetadataRowsLatestFirst.d.ts +21 -3
  250. package/dist/src/helpers/compareMetadataRowsLatestFirst.d.ts.map +1 -1
  251. package/dist/src/helpers/constants.d.ts +9 -0
  252. package/dist/src/helpers/constants.d.ts.map +1 -1
  253. package/dist/src/helpers/crypto.d.ts +5 -0
  254. package/dist/src/helpers/crypto.d.ts.map +1 -1
  255. package/dist/src/helpers/db.d.ts +25 -5
  256. package/dist/src/helpers/db.d.ts.map +1 -1
  257. package/dist/src/helpers/easPropertyCanonical.d.ts +1 -1
  258. package/dist/src/helpers/easPropertyCanonical.d.ts.map +1 -1
  259. package/dist/src/helpers/entity/entityCommon.d.ts +10 -0
  260. package/dist/src/helpers/entity/entityCommon.d.ts.map +1 -1
  261. package/dist/src/helpers/entity/entityDestroy.d.ts +1 -1
  262. package/dist/src/helpers/entity/entityDestroy.d.ts.map +1 -1
  263. package/dist/src/helpers/entity/entityLiveQuery.d.ts +5 -0
  264. package/dist/src/helpers/entity/entityLiveQuery.d.ts.map +1 -1
  265. package/dist/src/helpers/file/fetchAll/actors.d.ts.map +1 -1
  266. package/dist/src/helpers/getSegmentedItemProperties.d.ts.map +1 -1
  267. package/dist/src/helpers/htmlEmbeddedDataUriPublish.d.ts +6 -0
  268. package/dist/src/helpers/htmlEmbeddedDataUriPublish.d.ts.map +1 -1
  269. package/dist/src/helpers/isPublishedMetadataRow.d.ts +10 -0
  270. package/dist/src/helpers/isPublishedMetadataRow.d.ts.map +1 -0
  271. package/dist/src/helpers/ownership.d.ts.map +1 -1
  272. package/dist/src/helpers/property.d.ts +6 -1
  273. package/dist/src/helpers/property.d.ts.map +1 -1
  274. package/dist/src/helpers/schema.d.ts +14 -4
  275. package/dist/src/helpers/schema.d.ts.map +1 -1
  276. package/dist/src/helpers/tabCoordinator.d.ts +45 -0
  277. package/dist/src/helpers/tabCoordinator.d.ts.map +1 -0
  278. package/dist/src/helpers/tabEvents.d.ts +27 -0
  279. package/dist/src/helpers/tabEvents.d.ts.map +1 -0
  280. package/dist/src/helpers/tabLocks.d.ts +28 -0
  281. package/dist/src/helpers/tabLocks.d.ts.map +1 -0
  282. package/dist/src/helpers/updateSchema.d.ts.map +1 -1
  283. package/dist/src/imports/json.d.ts.map +1 -1
  284. package/dist/src/imports/markdown.d.ts.map +1 -1
  285. package/dist/src/index.d.ts +11 -2
  286. package/dist/src/index.d.ts.map +1 -1
  287. package/dist/src/node/db/Db.d.ts.map +1 -1
  288. package/dist/src/node/helpers/FileManager.d.ts +2 -0
  289. package/dist/src/node/helpers/FileManager.d.ts.map +1 -1
  290. package/dist/src/query/createLocalQueryDataSource.d.ts +4 -0
  291. package/dist/src/query/createLocalQueryDataSource.d.ts.map +1 -1
  292. package/dist/src/seedSchema/MetadataSchema.d.ts +36 -0
  293. package/dist/src/seedSchema/MetadataSchema.d.ts.map +1 -1
  294. package/dist/src/seedSchema/ModelSchema.d.ts +57 -0
  295. package/dist/src/seedSchema/ModelSchema.d.ts.map +1 -1
  296. package/dist/src/seedSchema/SeedSchema.d.ts +19 -0
  297. package/dist/src/seedSchema/SeedSchema.d.ts.map +1 -1
  298. package/dist/src/seedSchema/VersionSchema.d.ts +17 -0
  299. package/dist/src/seedSchema/VersionSchema.d.ts.map +1 -1
  300. package/dist/src/services/write/actors/writeToDatabase.d.ts +5 -0
  301. package/dist/src/services/write/actors/writeToDatabase.d.ts.map +1 -1
  302. package/dist/src/services/write/writeProcessMachine.d.ts.map +1 -1
  303. package/dist/src/stores/eas.d.ts +1 -1
  304. package/dist/src/stores/eas.d.ts.map +1 -1
  305. package/dist/src/types/index.d.ts +7 -0
  306. package/dist/src/types/index.d.ts.map +1 -1
  307. package/dist/src/types/item.d.ts +12 -3
  308. package/dist/src/types/item.d.ts.map +1 -1
  309. package/dist/src/types/property.d.ts +3 -2
  310. package/dist/src/types/property.d.ts.map +1 -1
  311. package/dist/syncDbWithEas-LRKr_NZF.js +855 -0
  312. package/dist/syncDbWithEas-LRKr_NZF.js.map +1 -0
  313. package/dist/{index-280bL-n4.js → tabEvents-DYI2GU7i.js} +231 -68
  314. package/dist/tabEvents-DYI2GU7i.js.map +1 -0
  315. package/dist/tolerantWebAccess-CzOBz5M6.js +160 -0
  316. package/dist/tolerantWebAccess-CzOBz5M6.js.map +1 -0
  317. package/dist/updateSeedRevokedAt-B58ORbY3.js +32 -0
  318. package/dist/updateSeedRevokedAt-B58ORbY3.js.map +1 -0
  319. package/package.json +5 -5
  320. package/dist/BasePathResolver-B6CKqoKw.js.map +0 -1
  321. package/dist/ClientManager-ChcmUL47.js.map +0 -1
  322. package/dist/ModelProperty-D79uV42p.js.map +0 -1
  323. package/dist/Schema-a8uO-hIZ.js.map +0 -1
  324. package/dist/SchemaValidationService-Y49vqast.js.map +0 -1
  325. package/dist/backfillMetadataPropertyIds-CBsf7LnU.js.map +0 -1
  326. package/dist/cjs/ModelProperty-D9FGaGuE.js.map +0 -1
  327. package/dist/cjs/Schema-BiJIPLEL.js.map +0 -1
  328. package/dist/cjs/SchemaValidationService-DtYs_CNY.js.map +0 -1
  329. package/dist/cjs/backfillMetadataPropertyIds-2XaN3b9S.js.map +0 -1
  330. package/dist/cjs/getPublishPayload-D5DhLGvN.js.map +0 -1
  331. package/dist/cjs/getPublishUploads-DMhCCKYF.js.map +0 -1
  332. package/dist/cjs/getSegmentedItemProperties-CU8rtBAo.js.map +0 -1
  333. package/dist/cjs/index-CSNtEnbF.js.map +0 -1
  334. package/dist/cjs/index-DPp9rdRL.js.map +0 -1
  335. package/dist/cjs/property-DlKiAWt4.js.map +0 -1
  336. package/dist/cjs/syncDbWithEas-C6n34o_Q.js +0 -606
  337. package/dist/cjs/syncDbWithEas-C6n34o_Q.js.map +0 -1
  338. package/dist/db-WbrzEf7c.js.map +0 -1
  339. package/dist/eas-CfYCu4IX.js.map +0 -1
  340. package/dist/getPublishPayload-BIrTVUxb.js.map +0 -1
  341. package/dist/getSegmentedItemProperties-BmKE71vU.js.map +0 -1
  342. package/dist/index-280bL-n4.js.map +0 -1
  343. package/dist/index-ClSv5pTA.js.map +0 -1
  344. package/dist/index-Djd3667v.js.map +0 -1
  345. package/dist/index-HRHkbVQd.js.map +0 -1
  346. package/dist/index.node-DBtQkEfz.js.map +0 -1
  347. package/dist/property-CQjuZ4JW.js.map +0 -1
  348. package/dist/src/Item/service/actors/fetchDataFromEas.d.ts +0 -4
  349. package/dist/src/Item/service/actors/fetchDataFromEas.d.ts.map +0 -1
  350. package/dist/src/Item/service/actors/hydrateExistingItem.d.ts +0 -4
  351. package/dist/src/Item/service/actors/hydrateExistingItem.d.ts.map +0 -1
  352. package/dist/src/Item/service/actors/hydrateNewItem.d.ts +0 -4
  353. package/dist/src/Item/service/actors/hydrateNewItem.d.ts.map +0 -1
  354. package/dist/src/Item/service/actors/initialize.d.ts +0 -4
  355. package/dist/src/Item/service/actors/initialize.d.ts.map +0 -1
  356. package/dist/src/Item/service/actors/reload.d.ts +0 -5
  357. package/dist/src/Item/service/actors/reload.d.ts.map +0 -1
  358. package/dist/src/Item/service/actors/saveDataToDb.d.ts +0 -4
  359. package/dist/src/Item/service/actors/saveDataToDb.d.ts.map +0 -1
  360. package/dist/src/ItemProperty/service/actors/resolveRemoteStorage.d.ts +0 -5
  361. package/dist/src/ItemProperty/service/actors/resolveRemoteStorage.d.ts.map +0 -1
  362. package/dist/src/Schema/service/addModelsMachine.d.ts +0 -123
  363. package/dist/src/Schema/service/addModelsMachine.d.ts.map +0 -1
  364. package/dist/src/db/configs/dev.schema.config.d.ts.map +0 -1
  365. package/dist/src/helpers/file/download/actors.d.ts +0 -17
  366. package/dist/src/helpers/file/download/actors.d.ts.map +0 -1
  367. package/dist/src/helpers/file/download/index.d.ts +0 -70
  368. package/dist/src/helpers/file/download/index.d.ts.map +0 -1
  369. package/dist/src/services/publish/actors/createPublishAttempt.d.ts +0 -4
  370. package/dist/src/services/publish/actors/createPublishAttempt.d.ts.map +0 -1
  371. package/dist/src/services/publish/actors/preparePublishRequestData.d.ts +0 -4
  372. package/dist/src/services/publish/actors/preparePublishRequestData.d.ts.map +0 -1
  373. package/dist/src/services/publish/actors/upload.d.ts +0 -4
  374. package/dist/src/services/publish/actors/upload.d.ts.map +0 -1
  375. package/dist/src/services/publish/actors/validateItemData.d.ts +0 -4
  376. package/dist/src/services/publish/actors/validateItemData.d.ts.map +0 -1
  377. package/dist/src/services/publish/publishMachine.d.ts +0 -32
  378. package/dist/src/services/publish/publishMachine.d.ts.map +0 -1
  379. package/dist/syncDbWithEas-CuARXfyN.js +0 -598
  380. package/dist/syncDbWithEas-CuARXfyN.js.map +0 -1
  381. package/dist/updateSeedRevokedAt-CBcLfHWs.js +0 -22
  382. package/dist/updateSeedRevokedAt-CBcLfHWs.js.map +0 -1
@@ -1,29 +1,30 @@
1
1
  import { fromCallback, setup, assign, createActor } from 'xstate';
2
2
  import 'reflect-metadata';
3
- import { w as writeProcessMachine, M as Model } from './index-HRHkbVQd.js';
4
- import { t as getModelIdByFileId, n as normalizeDataType, u as getModelId } from './db-WbrzEf7c.js';
3
+ import { w as writeProcessMachine, i as isActorStopped, M as Model } from './index-DtfjeuxC.js';
4
+ import { x as getModelIdByFileId, n as normalizeDataType, y as getModelId } from './db-BJZN0a0a.js';
5
5
  import 'pluralize';
6
- import { a as BaseDb, m as models, p as properties, s as schemas, i as modelSchemas, B as BaseFileManager } from './BasePathResolver-B6CKqoKw.js';
6
+ import { B as BaseDb, m as models, p as properties, s as schemas, i as modelSchemas, a as BaseFileManager } from './BasePathResolver-ndE8XTpw.js';
7
7
  import { eq, and } from 'drizzle-orm';
8
8
  import { modelPropertiesToObject } from './model-DGMe-TTm.js';
9
9
  import debug from 'debug';
10
- import './index-280bL-n4.js';
11
- import { S as Schema } from './Schema-a8uO-hIZ.js';
12
- import { n as waitForEntityIdle, o as createReactiveProxy, q as findEntity, u as forceRemoveFromCaches, v as runDestroyLifecycle } from './ClientManager-ChcmUL47.js';
10
+ import './tabEvents-DYI2GU7i.js';
11
+ import { S as Schema } from './Schema-DOhlrQ-N.js';
12
+ import { j as waitForEntityIdle, k as createReactiveProxy, m as findEntity, n as forceRemoveFromCaches, o as runDestroyLifecycle } from './Item-zBFWQDU9.js';
13
13
  import { generateId } from './generateId-BopUwD8F.js';
14
+ import './ClientManager-DLleL_2e.js';
15
+ import '@seedprotocol/arweave';
16
+ import '@seedprotocol/eas';
17
+ import '@noble/hashes/sha3';
18
+ import '@noble/hashes/utils';
19
+ import '@seedprotocol/query';
20
+ import 'lodash-es';
14
21
  import 'drizzle-orm/casing';
15
22
  import '@sinclair/typebox';
16
- import 'lodash-es';
17
23
  import 'drizzle-orm/sqlite-core';
18
- import '@seedprotocol/arweave';
19
- import '@seedprotocol/eas';
20
24
  import 'nanoid';
21
25
  import 'nanoid-dictionary';
22
- import '@seedprotocol/query';
23
- import './SchemaValidationService-Y49vqast.js';
26
+ import './SchemaValidationService-DDKr5piy.js';
24
27
  import '@sinclair/typebox/value';
25
- import '@noble/hashes/sha3';
26
- import '@noble/hashes/utils';
27
28
  import 'rxjs';
28
29
 
29
30
  const logger$3 = debug('seedSdk:modelProperty:actors:saveToSchema');
@@ -34,15 +35,15 @@ const logger$3 = debug('seedSdk:modelProperty:actors:saveToSchema');
34
35
  */
35
36
  async function getSchemaNameFromModel(modelName) {
36
37
  // Get the latest schema files and find which one contains this model
37
- const _mod_0 = await import('./ClientManager-ChcmUL47.js');
38
- const _ns_0 = _mod_0.an;
38
+ const _mod_0 = await import('./ClientManager-DLleL_2e.js');
39
+ const _ns_0 = _mod_0.G;
39
40
  const schemaHelpersMod = _ns_0;
40
41
  const { listLatestSchemaFiles } = schemaHelpersMod;
41
42
  const latestSchemas = await listLatestSchemaFiles();
42
43
  for (const schema of latestSchemas) {
43
44
  try {
44
- const _mod_1 = await import('./BasePathResolver-B6CKqoKw.js');
45
- const _ns_1 = _mod_1.N;
45
+ const _mod_1 = await import('./BasePathResolver-ndE8XTpw.js');
46
+ const _ns_1 = _mod_1.O;
46
47
  const fileManagerMod = _ns_1;
47
48
  const { BaseFileManager } = fileManagerMod;
48
49
  const content = await BaseFileManager.readFileAsString(schema.filePath);
@@ -61,7 +62,7 @@ async function getSchemaNameFromModel(modelName) {
61
62
  const saveToSchema = fromCallback(({ sendBack, input: { context } }) => {
62
63
  const _saveToSchema = async () => {
63
64
  // Use dynamic import to break circular dependency
64
- const validationServiceMod = await import('./SchemaValidationService-Y49vqast.js');
65
+ const validationServiceMod = await import('./SchemaValidationService-DDKr5piy.js');
65
66
  const { SchemaValidationService } = validationServiceMod;
66
67
  const validationService = new SchemaValidationService();
67
68
  // Validate property structure before saving
@@ -80,15 +81,15 @@ const saveToSchema = fromCallback(({ sendBack, input: { context } }) => {
80
81
  throw new Error(`Model not found for modelId: ${context.modelId}`);
81
82
  }
82
83
  // Persist to database only - schema file is updated only when user calls Schema.saveNewVersion()
83
- const _mod_2 = await import('./db-WbrzEf7c.js');
84
- const _ns_2 = _mod_2.Q;
84
+ const _mod_2 = await import('./db-BJZN0a0a.js');
85
+ const _ns_2 = _mod_2.Z;
85
86
  const dbMod = _ns_2;
86
87
  const { savePropertyToDb } = dbMod;
87
88
  await savePropertyToDb(context);
88
89
  // Mark schema as draft so user knows to save
89
90
  const schemaName = context._schemaName ?? (await getSchemaNameFromModel(context.modelName));
90
91
  if (schemaName) {
91
- const _mod_3 = await import('./Schema-a8uO-hIZ.js');
92
+ const _mod_3 = await import('./Schema-DOhlrQ-N.js');
92
93
  const _ns_3 = _mod_3.b;
93
94
  const schemaMod = _ns_3;
94
95
  const { Schema } = schemaMod;
@@ -123,8 +124,8 @@ const compareAndMarkDraft = fromCallback(({ sendBack, input: { context } }) => {
123
124
  const schemaFileIdForResolve = fullContext._propertyFileId || (typeof fullContext.id === 'string' ? fullContext.id : undefined);
124
125
  if (schemaFileIdForResolve && (fullContext.modelName === undefined || fullContext.dataType === undefined)) {
125
126
  try {
126
- const _mod_4 = await import('./db-WbrzEf7c.js');
127
- const _ns_4 = _mod_4.Q;
127
+ const _mod_4 = await import('./db-BJZN0a0a.js');
128
+ const _ns_4 = _mod_4.Z;
128
129
  const dbMod = _ns_4;
129
130
  const { getPropertyModelNameAndDataType, getModelNameByModelId } = dbMod;
130
131
  let fromDb;
@@ -170,8 +171,8 @@ const compareAndMarkDraft = fromCallback(({ sendBack, input: { context } }) => {
170
171
  if (fullContext.modelName && fullContext.name && schemaFileId) {
171
172
  logger$2(`[compareAndMarkDraft] _originalValues not set, but saving to database anyway for property ${context.modelName}:${context.name} (schemaFileId: ${schemaFileId})`);
172
173
  try {
173
- const _mod_5 = await import('./db-WbrzEf7c.js');
174
- const _ns_5 = _mod_5.Q;
174
+ const _mod_5 = await import('./db-BJZN0a0a.js');
175
+ const _ns_5 = _mod_5.Z;
175
176
  const dbMod = _ns_5;
176
177
  const { savePropertyToDb } = dbMod;
177
178
  // Ensure _propertyFileId is set for savePropertyToDb to find the property
@@ -232,8 +233,8 @@ const compareAndMarkDraft = fromCallback(({ sendBack, input: { context } }) => {
232
233
  logger$2(`Property ${fullContext.modelName}:${fullContext.name} has changes, marking as edited`);
233
234
  logger$2(`[compareAndMarkDraft] Context when saving: id=${fullContext.id}, _propertyFileId=${fullContext._propertyFileId}, name=${fullContext.name}, _originalValues.name=${fullContext._originalValues?.name}`);
234
235
  // Use dynamic import to break circular dependency
235
- const _mod_6 = await import('./db-WbrzEf7c.js');
236
- const _ns_6 = _mod_6.Q;
236
+ const _mod_6 = await import('./db-BJZN0a0a.js');
237
+ const _ns_6 = _mod_6.Z;
237
238
  const dbMod = _ns_6;
238
239
  const { savePropertyToDb } = dbMod;
239
240
  // Save to database (but not JSON file) - always save to DB when there are changes
@@ -248,7 +249,7 @@ const compareAndMarkDraft = fromCallback(({ sendBack, input: { context } }) => {
248
249
  // Mark schema as draft if schema name is available
249
250
  if (fullContext._schemaName) {
250
251
  // Get the Schema instance and mark it as draft
251
- const _mod_7 = await import('./Schema-a8uO-hIZ.js');
252
+ const _mod_7 = await import('./Schema-DOhlrQ-N.js');
252
253
  const _ns_7 = _mod_7.b;
253
254
  const schemaMod = _ns_7;
254
255
  const { Schema } = schemaMod;
@@ -267,7 +268,7 @@ const compareAndMarkDraft = fromCallback(({ sendBack, input: { context } }) => {
267
268
  logger$2(`Property ${fullContext.modelName}:${fullContext.name} has no changes`);
268
269
  // Clear isEdited flag in database
269
270
  try {
270
- const _mod_8 = await import('./index-Djd3667v.js');
271
+ const _mod_8 = await import('./index-B0LgJblD.js');
271
272
  const _ns_8 = _mod_8.s;
272
273
  const seedSchemaMod = _ns_8;
273
274
  const { properties: propertiesTable, models: modelsTable } = seedSchemaMod;
@@ -275,12 +276,15 @@ const compareAndMarkDraft = fromCallback(({ sendBack, input: { context } }) => {
275
276
  const { eq, and } = drizzleMod;
276
277
  const db = BaseDb.getAppDb();
277
278
  if (db && fullContext.modelName && fullContext.name) {
278
- // Find model by name
279
- const modelRecords = await db
280
- .select({ id: modelsTable.id })
281
- .from(modelsTable)
282
- .where(eq(modelsTable.name, fullContext.modelName))
283
- .limit(1);
279
+ // Find this property's model (model names are only unique per schema)
280
+ const _mod_9 = await import('./db-BJZN0a0a.js');
281
+ const _ns_9 = _mod_9.Y;
282
+ const { resolveModelRecord } = _ns_9;
283
+ const modelRecord = await resolveModelRecord(fullContext.modelName, {
284
+ modelId: typeof fullContext.modelId === 'number' ? fullContext.modelId : undefined,
285
+ schemaName: fullContext._schemaName,
286
+ }, db);
287
+ const modelRecords = modelRecord ? [modelRecord] : [];
284
288
  if (modelRecords.length > 0) {
285
289
  // Find property by name and modelId
286
290
  const propertyRecords = await db
@@ -333,9 +337,9 @@ const validateProperty = fromCallback(({ sendBack, input: { context } }) => {
333
337
  // Brief wait so trackPendingWrite from ModelProperty.create() has time to run (it's in setTimeout(0))
334
338
  await new Promise((r) => setTimeout(r, 60));
335
339
  try {
336
- const _mod_9 = await import('./db-WbrzEf7c.js');
337
- const _ns_9 = _mod_9.Q;
338
- const dbMod = _ns_9;
340
+ const _mod_10 = await import('./db-BJZN0a0a.js');
341
+ const _ns_10 = _mod_10.Z;
342
+ const dbMod = _ns_10;
339
343
  const { getPropertyModelNameAndDataType, getModelNameByModelId } = dbMod;
340
344
  // Try pending write first (property row may not exist yet)
341
345
  if (fullContext.modelName === undefined && schemaFileId) {
@@ -387,12 +391,12 @@ const validateProperty = fromCallback(({ sendBack, input: { context } }) => {
387
391
  fullContext = { ...fullContext, dataType: (fullContext.dataType ?? context._originalValues?.dataType) || 'Text' };
388
392
  }
389
393
  // Use dynamic imports to break circular dependencies
390
- const validationServiceMod = await import('./SchemaValidationService-Y49vqast.js');
394
+ const validationServiceMod = await import('./SchemaValidationService-DDKr5piy.js');
391
395
  const { SchemaValidationService } = validationServiceMod;
392
396
  const validationService = new SchemaValidationService();
393
- const _mod_10 = await import('./Schema-a8uO-hIZ.js');
394
- const _ns_10 = _mod_10.b;
395
- const schemaMod = _ns_10;
397
+ const _mod_11 = await import('./Schema-DOhlrQ-N.js');
398
+ const _ns_11 = _mod_11.b;
399
+ const schemaMod = _ns_11;
396
400
  const { Schema } = schemaMod;
397
401
  // Validate property structure
398
402
  const structureResult = validationService.validatePropertyStructure(fullContext);
@@ -494,9 +498,6 @@ const modelPropertyMachine = setup({
494
498
  const valid = !context._validationErrors || context._validationErrors.length === 0;
495
499
  return valid;
496
500
  },
497
- hasValidationErrors: ({ context }) => {
498
- return !!context._validationErrors && context._validationErrors.length > 0;
499
- },
500
501
  },
501
502
  actions: {
502
503
  assignValidationErrors: assign(({ context, event }) => {
@@ -595,7 +596,8 @@ const modelPropertyMachine = setup({
595
596
  actions: assign(({ context, event }) => ({
596
597
  ...context,
597
598
  _originalValues: event.originalValues,
598
- _schemaName: event.schemaName,
599
+ // Senders don't know the schema name; keep one setSchemaName already stored.
600
+ _schemaName: event.schemaName ?? context._schemaName,
599
601
  _isEdited: event.isEdited ?? false,
600
602
  _validationErrors: undefined,
601
603
  })),
@@ -614,22 +616,15 @@ const modelPropertyMachine = setup({
614
616
  })),
615
617
  },
616
618
  destroyStarted: {
617
- actions: assign({ _destroyInProgress: true, _destroyError: null }),
618
- },
619
- destroyDone: {
620
- actions: assign({ _destroyInProgress: false }),
619
+ actions: assign({ _destroyError: null }),
621
620
  },
622
621
  destroyError: {
623
622
  actions: assign(({ event }) => ({
624
- _destroyInProgress: false,
625
623
  _destroyError: event.error instanceof Error
626
624
  ? { message: event.error.message, name: event.error.name }
627
625
  : { message: String(event.error) },
628
626
  })),
629
627
  },
630
- clearDestroyError: {
631
- actions: assign({ _destroyError: null }),
632
- },
633
628
  },
634
629
  states: {
635
630
  idle: {
@@ -704,11 +699,9 @@ const modelPropertyMachine = setup({
704
699
  },
705
700
  },
706
701
  saveToSchema: {
707
- always: {
708
- guard: 'isPropertyValid',
709
- target: '.saving',
710
- },
711
- initial: 'saving',
702
+ // Gate the save in a transient child. An `always` on this parent targeting `.saving` re-enters
703
+ // the invoking child on every microstep and never settles (save() ran the process out of memory).
704
+ initial: 'checking',
712
705
  on: {
713
706
  // Apply updateContext but do not re-invoke saveToSchema actor (avoids infinite loop).
714
707
  // Context is updated; in-flight save completes with original context.
@@ -785,6 +778,12 @@ const modelPropertyMachine = setup({
785
778
  },
786
779
  },
787
780
  states: {
781
+ checking: {
782
+ always: [
783
+ { guard: 'isPropertyValid', target: 'saving' },
784
+ { target: '#modelProperty.idle' },
785
+ ],
786
+ },
788
787
  saving: {
789
788
  on: {
790
789
  saveToSchemaSuccess: {
@@ -867,6 +866,15 @@ class ModelProperty {
867
866
  this._initializeOriginalValues(property);
868
867
  // Note: Property getters/setters are now handled by the Proxy in create()
869
868
  }
869
+ /**
870
+ * Send from fire-and-forget async work (DB lookups started in the constructor), which can finish
871
+ * after the instance was unloaded or evicted with its schema.
872
+ */
873
+ _sendIfRunning(event) {
874
+ if (isActorStopped(this._service))
875
+ return;
876
+ this._service.send(event);
877
+ }
870
878
  /**
871
879
  * Initialize original values and schema name for tracking changes
872
880
  * This is called asynchronously after construction
@@ -878,10 +886,10 @@ class ModelProperty {
878
886
  const refModelName = property.refModelName || property.ref;
879
887
  if (refModelName && !property.refModelId) {
880
888
  // Resolve refModelId asynchronously and update context
881
- this._resolveRefModelId(refModelName).then((refModelId) => {
889
+ this._resolveRefModelId(refModelName, property).then((refModelId) => {
882
890
  if (refModelId) {
883
891
  // Update the context with the resolved refModelId
884
- this._service.send({
892
+ this._sendIfRunning({
885
893
  type: 'updateContext',
886
894
  refModelId,
887
895
  });
@@ -949,7 +957,7 @@ class ModelProperty {
949
957
  // Initialize with original values, including isEdited flag
950
958
  // Load isEdited from database if property exists in DB (async, fire-and-forget)
951
959
  this._loadIsEditedFromDb(property, isEdited).then((isEditedFromDb) => {
952
- this._service.send({
960
+ this._sendIfRunning({
953
961
  type: 'initializeOriginalValues',
954
962
  originalValues,
955
963
  schemaName: undefined, // Will be set later if needed
@@ -957,7 +965,7 @@ class ModelProperty {
957
965
  });
958
966
  }).catch(() => {
959
967
  // If we can't load from DB, use computed isEdited value
960
- this._service.send({
968
+ this._sendIfRunning({
961
969
  type: 'initializeOriginalValues',
962
970
  originalValues,
963
971
  schemaName: undefined, // Will be set later if needed
@@ -972,7 +980,7 @@ class ModelProperty {
972
980
  originalValues[key] = property[key];
973
981
  }
974
982
  });
975
- this._service.send({
983
+ this._sendIfRunning({
976
984
  type: 'initializeOriginalValues',
977
985
  originalValues,
978
986
  schemaName: undefined,
@@ -980,7 +988,7 @@ class ModelProperty {
980
988
  });
981
989
  // Get schema name from model asynchronously (fire-and-forget)
982
990
  if (property.modelName) {
983
- this._setSchemaName(property.modelName).catch(() => {
991
+ this._setSchemaName(property).catch(() => {
984
992
  // If we can't get schema name, that's okay - it will be set later if needed
985
993
  });
986
994
  }
@@ -1000,12 +1008,12 @@ class ModelProperty {
1000
1008
  if (!db) {
1001
1009
  return fallbackIsEdited;
1002
1010
  }
1003
- // Find model by name
1004
- const modelRecords = await db
1005
- .select({ id: models.id })
1006
- .from(models)
1007
- .where(eq(models.name, property.modelName))
1008
- .limit(1);
1011
+ // Find this property's model (by modelId when known; model names are only unique per schema)
1012
+ const _mod_12 = await import('./db-BJZN0a0a.js');
1013
+ const _ns_12 = _mod_12.Y;
1014
+ const { resolveModelRecord } = _ns_12;
1015
+ const modelRecord = await resolveModelRecord(property.modelName, this._ownerModelScope(property), db);
1016
+ const modelRecords = modelRecord ? [modelRecord] : [];
1009
1017
  if (modelRecords.length === 0) {
1010
1018
  return fallbackIsEdited;
1011
1019
  }
@@ -1029,7 +1037,7 @@ class ModelProperty {
1029
1037
  * @param refModelName - The name of the referenced model
1030
1038
  * @returns The database ID of the referenced model, or undefined if not found
1031
1039
  */
1032
- async _resolveRefModelId(refModelName) {
1040
+ async _resolveRefModelId(refModelName, property) {
1033
1041
  if (!refModelName) {
1034
1042
  return undefined;
1035
1043
  }
@@ -1038,13 +1046,13 @@ class ModelProperty {
1038
1046
  if (!db) {
1039
1047
  return undefined;
1040
1048
  }
1041
- const refModelRecords = await db
1042
- .select()
1043
- .from(models)
1044
- .where(eq(models.name, refModelName))
1045
- .limit(1);
1046
- if (refModelRecords.length > 0 && refModelRecords[0].id) {
1047
- return refModelRecords[0].id;
1049
+ // Resolve the ref within the owning model's schema
1050
+ const _mod_13 = await import('./db-BJZN0a0a.js');
1051
+ const _ns_13 = _mod_13.Y;
1052
+ const { resolveRefModelRecord } = _ns_13;
1053
+ const refModelRecord = await resolveRefModelRecord(refModelName, property ? this._ownerModelScope(property) : { schemaName: this._getSnapshotContext()._schemaName }, db);
1054
+ if (refModelRecord?.id) {
1055
+ return refModelRecord.id;
1048
1056
  }
1049
1057
  }
1050
1058
  catch (error) {
@@ -1053,6 +1061,15 @@ class ModelProperty {
1053
1061
  }
1054
1062
  return undefined;
1055
1063
  }
1064
+ /** Which model this property belongs to: its models row id and/or schema. */
1065
+ _ownerModelScope(property) {
1066
+ const context = this._getSnapshotContext();
1067
+ const modelId = property.modelId ?? context.modelId;
1068
+ return {
1069
+ modelId: typeof modelId === 'number' ? modelId : undefined,
1070
+ schemaName: context._schemaName,
1071
+ };
1072
+ }
1056
1073
  /**
1057
1074
  * Get schema file values for this property to use as "original" values
1058
1075
  * This allows comparison with database values to detect edits
@@ -1062,7 +1079,34 @@ class ModelProperty {
1062
1079
  return undefined;
1063
1080
  }
1064
1081
  try {
1065
- const model = await Model.getByNameAsync(property.modelName);
1082
+ const { modelId, schemaName } = this._ownerModelScope(property);
1083
+ // Synchronous cache hits first: callers compare against these values right after construction,
1084
+ // so an extra await here lets every property look "edited" (a draft save each). Only then the
1085
+ // DB (by modelId), and never instantiate a Model while its own properties are initializing.
1086
+ let model = schemaName ? Model.getByName(property.modelName, schemaName) : undefined;
1087
+ if (!model) {
1088
+ try {
1089
+ model = Model.getByName(property.modelName);
1090
+ }
1091
+ catch {
1092
+ model = undefined; // ambiguous name; resolve by modelId below
1093
+ }
1094
+ }
1095
+ if (!model && modelId) {
1096
+ const _mod_14 = await import('./db-BJZN0a0a.js');
1097
+ const _ns_14 = _mod_14.Y;
1098
+ const { resolveModelRecord } = _ns_14;
1099
+ const modelFileId = (await resolveModelRecord(property.modelName, { modelId }))?.schemaFileId;
1100
+ model = modelFileId ? Model.getById(modelFileId) : undefined;
1101
+ }
1102
+ if (!model) {
1103
+ try {
1104
+ model = await Model.getByNameAsync(property.modelName);
1105
+ }
1106
+ catch {
1107
+ model = undefined;
1108
+ }
1109
+ }
1066
1110
  if (!model || !model.properties || model.properties.length === 0) {
1067
1111
  return undefined;
1068
1112
  }
@@ -1086,7 +1130,7 @@ class ModelProperty {
1086
1130
  originalValues.ref = schemaFileValue.ref;
1087
1131
  originalValues.refModelName = schemaFileValue.ref;
1088
1132
  // Try to get refModelId from database
1089
- const refModelId = await this._resolveRefModelId(schemaFileValue.ref);
1133
+ const refModelId = await this._resolveRefModelId(schemaFileValue.ref, property);
1090
1134
  if (refModelId) {
1091
1135
  originalValues.refModelId = refModelId;
1092
1136
  }
@@ -1104,11 +1148,19 @@ class ModelProperty {
1104
1148
  * Set the schema name for this property by looking it up from the model
1105
1149
  * Tries database first (more reliable), then falls back to schema files
1106
1150
  */
1107
- async _setSchemaName(modelName) {
1151
+ async _setSchemaName(property) {
1108
1152
  try {
1153
+ // create() sets the schema name right after construction when its caller knows it. Don't look it
1154
+ // up then: the file fallback below reads and parses every schema file, per property.
1155
+ await Promise.resolve();
1156
+ if (this._getSnapshotContext()._schemaName)
1157
+ return;
1109
1158
  let schemaName;
1159
+ // From the property data: the instance's own modelId field is never assigned (the reactive proxy
1160
+ // serves values from the machine context), so reading this.modelId skipped the DB lookup.
1161
+ const { modelId } = this._ownerModelScope(property);
1110
1162
  // Try to get schema name from database first (more reliable)
1111
- if (this.modelId) {
1163
+ if (modelId) {
1112
1164
  try {
1113
1165
  const db = BaseDb.getAppDb();
1114
1166
  if (db) {
@@ -1119,7 +1171,7 @@ class ModelProperty {
1119
1171
  .from(modelSchemas)
1120
1172
  .innerJoin(schemas, eq(modelSchemas.schemaId, schemas.id))
1121
1173
  .innerJoin(models, eq(modelSchemas.modelId, models.id))
1122
- .where(eq(models.id, this.modelId))
1174
+ .where(eq(models.id, modelId))
1123
1175
  .limit(1);
1124
1176
  if (modelSchemaRecords.length > 0) {
1125
1177
  schemaName = modelSchemaRecords[0].schemaName;
@@ -1132,11 +1184,11 @@ class ModelProperty {
1132
1184
  }
1133
1185
  // Fall back to schema file lookup if database didn't work
1134
1186
  if (!schemaName) {
1135
- schemaName = await getSchemaNameFromModel(modelName);
1187
+ schemaName = await getSchemaNameFromModel(property.modelName);
1136
1188
  }
1137
1189
  if (schemaName) {
1138
1190
  // Update the context with the schema name using dedicated event
1139
- this._service.send({
1191
+ this._sendIfRunning({
1140
1192
  type: 'setSchemaName',
1141
1193
  schemaName,
1142
1194
  });
@@ -1233,11 +1285,32 @@ class ModelProperty {
1233
1285
  logger(`ModelProperty.create: Generated new id (schemaFileId) "${propertyWithId.id}" for property "${property.name}"`);
1234
1286
  }
1235
1287
  // Create cache key from modelName and name, or use id
1236
- const cacheKey = propertyWithId.modelName && propertyWithId.name
1288
+ let cacheKey = propertyWithId.modelName && propertyWithId.name
1237
1289
  ? `${propertyWithId.modelName}:${propertyWithId.name}`
1238
1290
  : propertyWithId.id
1239
1291
  ? `id:${propertyWithId.id}`
1240
1292
  : propertyWithId.name || 'unnamed';
1293
+ // Model names are only unique per schema: a cached "Post:title" may be another schema's
1294
+ // property. If the ids say it's a different property, key this one by its own id instead.
1295
+ // (Not by file id: the same property is often created first with a generated id, then its real one.)
1296
+ const isOtherProperty = (cachedContext) => (typeof propertyWithId.modelId === 'number' &&
1297
+ typeof cachedContext.modelId === 'number' &&
1298
+ cachedContext.modelId !== propertyWithId.modelId) ||
1299
+ (!!schemaName && !!cachedContext._schemaName && cachedContext._schemaName !== schemaName);
1300
+ const cachedByName = this.instanceCache.get(cacheKey);
1301
+ if (cachedByName && propertyWithId.id && isOtherProperty(cachedByName.instance._getSnapshotContext())) {
1302
+ // Reuse this property's own id-keyed entry if it already has one.
1303
+ cacheKey = `id:${propertyWithId.id}`;
1304
+ for (const [key, { instance }] of this.instanceCache.entries()) {
1305
+ if (!key.startsWith('id:'))
1306
+ continue;
1307
+ const ctx = instance._getSnapshotContext();
1308
+ if (ctx.modelName === propertyWithId.modelName && ctx.name === propertyWithId.name && !isOtherProperty(ctx)) {
1309
+ cacheKey = key;
1310
+ break;
1311
+ }
1312
+ }
1313
+ }
1241
1314
  // Check if instance exists in cache
1242
1315
  if (this.instanceCache.has(cacheKey)) {
1243
1316
  const { instance, refCount } = this.instanceCache.get(cacheKey);
@@ -1299,11 +1372,15 @@ class ModelProperty {
1299
1372
  instance: proxiedInstance,
1300
1373
  refCount: 1,
1301
1374
  });
1375
+ this.indexCachedInstance(cacheKey, proxiedInstance);
1302
1376
  // Trigger write process if property has modelId (or modelName) and id (schemaFileId)
1303
1377
  // Wait for service to be ready (idle state) and have writeProcess spawned
1304
1378
  const propertyFileId = propertyWithId.id; // id is now the schemaFileId (string)
1305
1379
  const hasModelId = propertyWithId.modelId || propertyWithId.modelName;
1306
- if (hasModelId && propertyFileId) {
1380
+ // A _dbId means the data was loaded from an existing row (createById, getPropertySchema), so
1381
+ // there's nothing to write. Writing it back anyway raced deletes of that row's model (FK error).
1382
+ const isPersisted = typeof propertyWithId._dbId === 'number';
1383
+ if (hasModelId && propertyFileId && !isPersisted) {
1307
1384
  // Wait for writeProcess to be spawned (it's spawned in idle state entry action)
1308
1385
  // Retry a few times if writeProcess isn't available yet
1309
1386
  let retries = 0;
@@ -1311,6 +1388,9 @@ class ModelProperty {
1311
1388
  const checkAndSend = async () => {
1312
1389
  const service = proxiedInstance.getService();
1313
1390
  const snapshot = service.getSnapshot();
1391
+ // Unloaded or evicted (e.g. Schema.destroy) before the write started: nothing to write to
1392
+ if (isActorStopped(service))
1393
+ return;
1314
1394
  if (snapshot.value === 'idle' && snapshot.context.writeProcess) {
1315
1395
  const writeProcess = snapshot.context.writeProcess;
1316
1396
  // Resolve dbModelId - convert from string (modelFileId) to number (database ID) if needed
@@ -1350,14 +1430,17 @@ class ModelProperty {
1350
1430
  // Don't clear pending write here - it might resolve later
1351
1431
  return;
1352
1432
  }
1433
+ // Resolving the modelId awaited the DB; the instance may have been stopped meanwhile
1434
+ if (isActorStopped(service))
1435
+ return;
1353
1436
  // Track pending write now that we have the resolved modelId
1354
1437
  this.trackPendingWrite(propertyFileId, resolvedModelId);
1355
1438
  logger(`Triggering write process for property "${property.name}" (modelId: ${resolvedModelId}, propertyFileId: ${propertyFileId})`);
1356
1439
  // Check current write state
1357
1440
  const currentWriteState = writeProcess.getSnapshot();
1358
1441
  if (currentWriteState.value === 'success') {
1359
- // Write already succeeded, clear pending write immediately
1360
- this.clearPendingWrite(propertyFileId, 'success');
1442
+ // Write already succeeded
1443
+ void this.completePendingWrite(propertyFileId, resolvedModelId);
1361
1444
  }
1362
1445
  else {
1363
1446
  // Set up subscription to catch future state changes
@@ -1365,8 +1448,7 @@ class ModelProperty {
1365
1448
  if (writeSnapshot.value === 'success') {
1366
1449
  writeSubscription.unsubscribe();
1367
1450
  logger(`[writeProcess subscription] Write succeeded for property "${property.name}" (propertyFileId: ${propertyFileId})`);
1368
- // Clear pending write on success
1369
- this.clearPendingWrite(propertyFileId, 'success');
1451
+ void this.completePendingWrite(propertyFileId, resolvedModelId);
1370
1452
  }
1371
1453
  else if (writeSnapshot.value === 'error') {
1372
1454
  writeSubscription.unsubscribe();
@@ -1384,6 +1466,7 @@ class ModelProperty {
1384
1466
  dataType: property.dataType,
1385
1467
  refModelId: property.refModelId,
1386
1468
  refValueType: property.refValueType,
1469
+ required: property.required,
1387
1470
  storageType: property.storageType,
1388
1471
  localStorageDir: property.localStorageDir,
1389
1472
  filenameSuffix: property.filenameSuffix,
@@ -1411,18 +1494,56 @@ class ModelProperty {
1411
1494
  return proxiedInstance;
1412
1495
  return waitForEntityIdle(proxiedInstance, { timeout: readyTimeout }).then(() => proxiedInstance);
1413
1496
  }
1497
+ /** Whether an idIndex entry still points at a cached instance with that id. */
1498
+ static isIndexEntryCurrent(propertyFileId, entry) {
1499
+ if (this.instanceCache.get(entry.cacheKey)?.instance !== entry.instance)
1500
+ return false;
1501
+ try {
1502
+ return entry.instance._getSnapshotContext().id === propertyFileId;
1503
+ }
1504
+ catch {
1505
+ return false;
1506
+ }
1507
+ }
1508
+ /** Add a newly cached instance to idIndex, and keep its entry current when its id changes. */
1509
+ static indexCachedInstance(cacheKey, instance) {
1510
+ const index = (id) => {
1511
+ if (!id)
1512
+ return;
1513
+ const existing = this.idIndex.get(id);
1514
+ // Keep the instance cached first, as the old scan in insertion order returned
1515
+ if (existing && existing.instance !== instance && this.isIndexEntryCurrent(id, existing))
1516
+ return;
1517
+ this.idIndex.set(id, { cacheKey, instance });
1518
+ };
1519
+ let indexedId = instance._getSnapshotContext().id;
1520
+ index(indexedId);
1521
+ instance._service.subscribe((snapshot) => {
1522
+ const id = snapshot.context.id;
1523
+ if (id === indexedId)
1524
+ return;
1525
+ indexedId = id;
1526
+ index(id);
1527
+ });
1528
+ }
1414
1529
  /**
1415
1530
  * Get ModelProperty instance by propertyFileId from static cache
1416
1531
  */
1417
1532
  static getById(propertyFileId) {
1418
1533
  if (!propertyFileId)
1419
1534
  return undefined;
1420
- // Search through cache to find by propertyFileId
1535
+ const indexed = this.idIndex.get(propertyFileId);
1536
+ if (!indexed)
1537
+ return undefined;
1538
+ if (this.isIndexEntryCurrent(propertyFileId, indexed))
1539
+ return indexed.instance;
1540
+ // The indexed instance left the cache or changed id; another cached instance may still have it.
1421
1541
  // Cache key might be "modelName:propertyName" or "id:propertyId"
1542
+ this.idIndex.delete(propertyFileId);
1422
1543
  for (const [cacheKey, { instance }] of this.instanceCache.entries()) {
1423
- const context = instance._getSnapshotContext();
1424
1544
  // id is now the schemaFileId (string)
1425
- if (context.id === propertyFileId) {
1545
+ if (instance._getSnapshotContext().id === propertyFileId) {
1546
+ this.idIndex.set(propertyFileId, { cacheKey, instance });
1426
1547
  return instance;
1427
1548
  }
1428
1549
  }
@@ -1481,6 +1602,9 @@ class ModelProperty {
1481
1602
  refModelId: propertyRecord.refModelId || undefined,
1482
1603
  refValueType: propertyRecord.refValueType ? propertyRecord.refValueType : undefined,
1483
1604
  required: propertyRecord.required ?? false,
1605
+ storageType: propertyRecord.storageType ?? undefined,
1606
+ localStorageDir: propertyRecord.localStorageDir ?? undefined,
1607
+ filenameSuffix: propertyRecord.filenameSuffix ?? undefined,
1484
1608
  };
1485
1609
  // Load isEdited from database
1486
1610
  const isEditedFromDb = propertyRecord.isEdited ?? false;
@@ -1562,6 +1686,20 @@ class ModelProperty {
1562
1686
  timestamp: Date.now(),
1563
1687
  });
1564
1688
  }
1689
+ /**
1690
+ * A property write succeeded: add the property to its model's property ids, then drop the pending
1691
+ * write. In that order, `Model.properties` (property ids + pending writes) never misses it; in Node,
1692
+ * where the Model has no reactive liveQuery, nothing else would add it.
1693
+ */
1694
+ static async completePendingWrite(propertyFileId, modelId) {
1695
+ try {
1696
+ await Model.refreshPropertiesForDbId(modelId);
1697
+ }
1698
+ catch (error) {
1699
+ logger(`Refreshing properties of model ${modelId} after writing "${propertyFileId}" failed: ${error}`);
1700
+ }
1701
+ this.clearPendingWrite(propertyFileId, 'success');
1702
+ }
1565
1703
  /**
1566
1704
  * Clear or update pending write status
1567
1705
  */
@@ -1700,6 +1838,36 @@ class ModelProperty {
1700
1838
  logger('ModelProperty.reload() called - ModelProperty is loaded as part of Model/Schema. Reload the parent Model or Schema instead.');
1701
1839
  // No-op for now, but could be enhanced to reload from DB if needed
1702
1840
  }
1841
+ /**
1842
+ * Force-evict cached ModelProperty instances for the given models, ignoring refCounts, and stop
1843
+ * their services. Used by Schema.destroy() so a re-imported schema gets fresh instances instead of
1844
+ * ones holding a deleted row's _dbId.
1845
+ */
1846
+ static evictForModels(modelNames, schemaName) {
1847
+ if (modelNames.length === 0)
1848
+ return;
1849
+ const names = new Set(modelNames);
1850
+ for (const [cacheKey, { instance }] of this.instanceCache.entries()) {
1851
+ let context;
1852
+ try {
1853
+ context = instance._getSnapshotContext();
1854
+ }
1855
+ catch {
1856
+ continue;
1857
+ }
1858
+ if (!context.modelName || !names.has(context.modelName))
1859
+ continue;
1860
+ if (schemaName && context._schemaName && context._schemaName !== schemaName)
1861
+ continue;
1862
+ this.instanceCache.delete(cacheKey);
1863
+ try {
1864
+ instance._service.stop();
1865
+ }
1866
+ catch {
1867
+ // Service might already be stopped
1868
+ }
1869
+ }
1870
+ }
1703
1871
  unload() {
1704
1872
  // ModelProperty doesn't have liveQuery subscriptions or complex cache management
1705
1873
  // Just stop the service
@@ -1715,13 +1883,24 @@ class ModelProperty {
1715
1883
  */
1716
1884
  async destroy() {
1717
1885
  const context = this._getSnapshotContext();
1718
- const cacheKey = context.modelName && context.name
1719
- ? `${context.modelName}:${context.name}`
1720
- : (context.id ?? '');
1721
- if (!cacheKey)
1886
+ // Stored under "modelName:name", or "id:<id>" when another schema's same-name property holds that key
1887
+ const cacheKeys = [...ModelProperty.instanceCache.entries()]
1888
+ .filter(([, entry]) => {
1889
+ try {
1890
+ return entry.instance._getSnapshotContext().id === context.id;
1891
+ }
1892
+ catch {
1893
+ return false;
1894
+ }
1895
+ })
1896
+ .map(([key]) => key);
1897
+ if (cacheKeys.length === 0 && context.modelName && context.name) {
1898
+ cacheKeys.push(`${context.modelName}:${context.name}`);
1899
+ }
1900
+ if (cacheKeys.length === 0)
1722
1901
  return;
1723
1902
  forceRemoveFromCaches(this, {
1724
- getCacheKeys: () => [cacheKey],
1903
+ getCacheKeys: () => cacheKeys,
1725
1904
  caches: [ModelProperty.instanceCache],
1726
1905
  });
1727
1906
  await runDestroyLifecycle(this, {
@@ -1770,6 +1949,15 @@ class ModelProperty {
1770
1949
  }
1771
1950
  }
1772
1951
  ModelProperty.instanceCache = new Map();
1952
+ /**
1953
+ * propertyFileId -> where the instance with that id is cached, so getById doesn't scan the cache
1954
+ * (a model's properties are looked up one by one, which made loading one model O(n²)).
1955
+ * Every cached instance's current id has an entry: it's added when the instance is cached and
1956
+ * again whenever its context id changes (a property is often created with a generated id and
1957
+ * then gets its real one). Entries aren't removed when an instance leaves the cache or changes
1958
+ * id; getById checks an entry before using it.
1959
+ */
1960
+ ModelProperty.idIndex = new Map();
1773
1961
  // Pending writes tracking
1774
1962
  ModelProperty.pendingWrites = new Map();
1775
1963
 
@@ -1779,4 +1967,4 @@ var ModelProperty$1 = /*#__PURE__*/Object.freeze({
1779
1967
  });
1780
1968
 
1781
1969
  export { ModelProperty };
1782
- //# sourceMappingURL=ModelProperty-D79uV42p.js.map
1970
+ //# sourceMappingURL=ModelProperty-lth9L37R.js.map