@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,14 +1,15 @@
1
1
  import { fromCallback, setup, assign, createActor } from 'xstate';
2
- import { i as getRefValueType, ai as createModelsFromJson, X as listCompleteSchemaFiles, aj as getLatestSchemaVersion, ak as createModelFromJson, k as loadSchemaFromFile, n as waitForEntityIdle, o as createReactiveProxy, q as findEntity, Y as loadAllSchemasFromDb, H as getClient, y as ClientManagerState, ag as unloadEntity, ah as clearDestroySubscriptions, u as forceRemoveFromCaches, v as runDestroyLifecycle } from './ClientManager-ChcmUL47.js';
3
- import './index-280bL-n4.js';
4
- import { A as addSchemaToDb, k as isDataType, M as ModelPropertyDataTypes, s as addModelsToDb, E as loadModelsFromDbForSchema } from './db-WbrzEf7c.js';
5
- import { D as SEED_PROTOCOL_SCHEMA_NAME, a as BaseDb, s as schemas, m as models, i as modelSchemas, p as properties, B as BaseFileManager, J as isInternalSchema } from './BasePathResolver-B6CKqoKw.js';
2
+ import { b as getRefValueType, D as createModelsFromJson, n as listCompleteSchemaFiles, F as getLatestSchemaVersion, l as loadSchemaFromFile, o as loadAllSchemasFromDb, h as getClient } from './ClientManager-DLleL_2e.js';
3
+ import './tabEvents-DYI2GU7i.js';
4
+ import { O as addSchemaToDb, k as isDataType, M as ModelPropertyDataTypes, w as addModelsToDb, S as loadModelsFromDbForSchema } from './db-BJZN0a0a.js';
5
+ import { F as SEED_PROTOCOL_SCHEMA_NAME, B as BaseDb, s as schemas, m as models, i as modelSchemas, p as properties, a as BaseFileManager, K as isInternalSchema } from './BasePathResolver-ndE8XTpw.js';
6
6
  import { eq, desc, and } from 'drizzle-orm';
7
7
  import debug from 'debug';
8
8
  import 'pluralize';
9
9
  import { generateId } from './generateId-BopUwD8F.js';
10
- import { SchemaValidationService } from './SchemaValidationService-Y49vqast.js';
11
- import { M as Model, w as writeProcessMachine, C as ConflictError, s as setupEntityLiveQuery } from './index-HRHkbVQd.js';
10
+ import { SchemaValidationService } from './SchemaValidationService-DDKr5piy.js';
11
+ import { w as writeProcessMachine, M as Model, C as ConflictError, s as setupEntityLiveQuery } from './index-DtfjeuxC.js';
12
+ import { j as waitForEntityIdle, k as createReactiveProxy, m as findEntity, C as ClientManagerState, V as unloadEntity, U as clearDestroySubscriptions, n as forceRemoveFromCaches, o as runDestroyLifecycle } from './Item-zBFWQDU9.js';
12
13
 
13
14
  const logger$d = debug('seedSdk:schema:actors:loadOrCreateSchema');
14
15
  /**
@@ -52,8 +53,8 @@ const createModelInstances$2 = async (modelIds) => {
52
53
  return;
53
54
  }
54
55
  try {
55
- const _mod_0 = await import('./index-HRHkbVQd.js');
56
- const _ns_0 = _mod_0.b;
56
+ const _mod_0 = await import('./index-DtfjeuxC.js');
57
+ const _ns_0 = _mod_0.c;
57
58
  const modelMod = _ns_0;
58
59
  const { Model } = modelMod;
59
60
  // Create instances for all model IDs in parallel
@@ -167,8 +168,8 @@ const loadOrCreateSchema = fromCallback(({ sendBack, input: { context } }) => {
167
168
  // For Seed Protocol, always load from internal file, never create new
168
169
  logger$d(`Loading internal Seed Protocol schema from SDK`);
169
170
  try {
170
- const _mod_1 = await import('./ClientManager-ChcmUL47.js');
171
- const _ns_1 = _mod_1.ao;
171
+ const _mod_1 = await import('./ClientManager-DLleL_2e.js');
172
+ const _ns_1 = _mod_1.S;
172
173
  const internalSchema = _ns_1;
173
174
  const schemaFile = internalSchema.default;
174
175
  // Check if it exists in database, if not, add it
@@ -662,8 +663,8 @@ const loadOrCreateSchema = fromCallback(({ sendBack, input: { context } }) => {
662
663
  // Ensure models are populated (fallback for seed-protocol if missing)
663
664
  if ((!mergedModels || Object.keys(mergedModels).length === 0) && schemaName === 'Seed Protocol') {
664
665
  try {
665
- const _mod_2 = await import('./ClientManager-ChcmUL47.js');
666
- const _ns_2 = _mod_2.ao;
666
+ const _mod_2 = await import('./ClientManager-DLleL_2e.js');
667
+ const _ns_2 = _mod_2.S;
667
668
  const internalSchema = _ns_2;
668
669
  const internalSchemaFile = internalSchema.default;
669
670
  mergedModels = { ...(internalSchemaFile.models || {}) };
@@ -891,8 +892,8 @@ const loadOrCreateSchema = fromCallback(({ sendBack, input: { context } }) => {
891
892
  // Ensure models are populated (fallback for seed-protocol if missing)
892
893
  if ((!mergedModels || Object.keys(mergedModels).length === 0) && schemaName === 'Seed Protocol') {
893
894
  try {
894
- const _mod_3 = await import('./ClientManager-ChcmUL47.js');
895
- const _ns_3 = _mod_3.ao;
895
+ const _mod_3 = await import('./ClientManager-DLleL_2e.js');
896
+ const _ns_3 = _mod_3.S;
896
897
  const internalSchema = _ns_3;
897
898
  const internalSchemaFile = internalSchema.default;
898
899
  mergedModels = { ...(internalSchemaFile.models || {}) };
@@ -982,8 +983,8 @@ const loadOrCreateSchema = fromCallback(({ sendBack, input: { context } }) => {
982
983
  // Ensure models are populated (fallback for seed-protocol if missing)
983
984
  if ((!mergedModels || Object.keys(mergedModels).length === 0) && schemaName === 'Seed Protocol') {
984
985
  try {
985
- const _mod_4 = await import('./ClientManager-ChcmUL47.js');
986
- const _ns_4 = _mod_4.ao;
986
+ const _mod_4 = await import('./ClientManager-DLleL_2e.js');
987
+ const _ns_4 = _mod_4.S;
987
988
  const internalSchema = _ns_4;
988
989
  const internalSchemaFile = internalSchema.default;
989
990
  mergedModels = { ...(internalSchemaFile.models || {}) };
@@ -1070,8 +1071,8 @@ const loadOrCreateSchema = fromCallback(({ sendBack, input: { context } }) => {
1070
1071
  // If schemaData is missing, try to load from internal schema file for seed-protocol
1071
1072
  if (!dbSchema.schemaData && schemaName === 'Seed Protocol') {
1072
1073
  try {
1073
- const _mod_5 = await import('./ClientManager-ChcmUL47.js');
1074
- const _ns_5 = _mod_5.ao;
1074
+ const _mod_5 = await import('./ClientManager-DLleL_2e.js');
1075
+ const _ns_5 = _mod_5.S;
1075
1076
  const internalSchema = _ns_5;
1076
1077
  const schemaFile = internalSchema.default;
1077
1078
  logger$d(`Found seed-protocol schema in internal file (schemaData missing, using internal schema)`);
@@ -1181,8 +1182,8 @@ const loadOrCreateSchema = fromCallback(({ sendBack, input: { context } }) => {
1181
1182
  // Ensure models are populated (fallback for seed-protocol if missing)
1182
1183
  if ((!mergedModels || Object.keys(mergedModels).length === 0) && schemaName === 'Seed Protocol') {
1183
1184
  try {
1184
- const _mod_6 = await import('./ClientManager-ChcmUL47.js');
1185
- const _ns_6 = _mod_6.ao;
1185
+ const _mod_6 = await import('./ClientManager-DLleL_2e.js');
1186
+ const _ns_6 = _mod_6.S;
1186
1187
  const internalSchema = _ns_6;
1187
1188
  const internalSchemaFile = internalSchema.default;
1188
1189
  mergedModels = { ...(internalSchemaFile.models || {}) };
@@ -1454,582 +1455,6 @@ const validateSchema = fromCallback(({ sendBack, input: { context } }) => {
1454
1455
  };
1455
1456
  });
1456
1457
 
1457
- const addModelsMachine = setup({
1458
- types: {
1459
- context: {},
1460
- input: {},
1461
- events: {},
1462
- },
1463
- actors: {
1464
- validateModels: fromCallback(({ sendBack, input }) => {
1465
- const _validate = async () => {
1466
- // Check for duplicate model names
1467
- const newModelNames = Object.keys(input.newModels);
1468
- const existingModelNames = Object.keys(input.existingModels || {});
1469
- for (const modelName of newModelNames) {
1470
- if (existingModelNames.includes(modelName)) {
1471
- throw new Error(`Model "${modelName}" already exists in schema`);
1472
- }
1473
- }
1474
- // Check for duplicates within new models
1475
- const seenNames = new Set();
1476
- for (const modelName of newModelNames) {
1477
- if (seenNames.has(modelName)) {
1478
- throw new Error(`Duplicate model name detected: "${modelName}". Each model must have a unique name.`);
1479
- }
1480
- seenNames.add(modelName);
1481
- }
1482
- // Basic validation - ensure models have required structure
1483
- for (const [modelName, modelDef] of Object.entries(input.newModels)) {
1484
- if (!modelDef || typeof modelDef !== 'object') {
1485
- throw new Error(`Invalid model definition for "${modelName}": must be an object`);
1486
- }
1487
- if (!modelDef.properties || typeof modelDef.properties !== 'object') {
1488
- throw new Error(`Model "${modelName}" must have a "properties" object`);
1489
- }
1490
- }
1491
- sendBack({ type: 'done', output: { valid: true } });
1492
- };
1493
- _validate().catch((error) => {
1494
- sendBack({ type: 'error', error: error instanceof Error ? error : new Error(String(error)) });
1495
- });
1496
- return () => {
1497
- // Cleanup
1498
- };
1499
- }),
1500
- createModelInstances: fromCallback(({ sendBack, input }) => {
1501
- const _createInstances = async () => {
1502
- const debug = (await import('debug')).default;
1503
- const logger = debug('seedSdk:schema:addModels:createInstances');
1504
- const schemaMod = await Promise.resolve().then(function () { return Schema$1; });
1505
- const { Schema: SchemaClass, schemaInstanceState } = schemaMod;
1506
- const schemaName = input.schemaContext.metadata?.name || input.schemaContext.schemaName;
1507
- const schemaInstance = SchemaClass.create(schemaName, {
1508
- waitForReady: false,
1509
- });
1510
- const modelInstances = new Map();
1511
- // Get instance state to store model instances
1512
- const instanceState = schemaInstanceState.get(schemaInstance);
1513
- if (!instanceState) {
1514
- throw new Error('Schema instance state not found');
1515
- }
1516
- for (const [modelName, modelData] of Object.entries(input.models)) {
1517
- try {
1518
- logger(`Creating model instance for "${modelName}"`);
1519
- // Look up modelFileId from database BEFORE creating the Model instance
1520
- let modelFileId = undefined;
1521
- try {
1522
- const db = BaseDb.getAppDb();
1523
- if (db) {
1524
- const dbModels = await db
1525
- .select()
1526
- .from(models)
1527
- .where(eq(models.name, modelName))
1528
- .limit(1);
1529
- if (dbModels.length > 0 && dbModels[0].schemaFileId) {
1530
- modelFileId = dbModels[0].schemaFileId;
1531
- logger(`Found modelFileId "${modelFileId}" for model "${modelName}" from database`);
1532
- }
1533
- }
1534
- }
1535
- catch (error) {
1536
- logger(`Error looking up modelFileId from database: ${error}`);
1537
- }
1538
- // If not found in database, generate a new modelFileId for new models
1539
- if (!modelFileId) {
1540
- modelFileId = generateId();
1541
- logger(`Generated new modelFileId "${modelFileId}" for new model "${modelName}"`);
1542
- }
1543
- // Create new Model instance with modelFileId
1544
- // Model.create() will set _modelFileId in the context automatically
1545
- const modelInstance = Model.create(modelName, schemaName, {
1546
- modelFileId,
1547
- waitForReady: false,
1548
- });
1549
- const service = modelInstance.getService();
1550
- logger(`Created Model instance for "${modelName}" with modelFileId "${modelFileId}"`);
1551
- // Wait for the Model service to finish loading (loadOrCreateModel completes)
1552
- await new Promise((resolve) => {
1553
- let resolved = false;
1554
- let subscription = null;
1555
- // Check if already idle
1556
- const snapshot = service.getSnapshot();
1557
- if (snapshot.value === 'idle') {
1558
- const currentModelFileId = snapshot.context._modelFileId;
1559
- if (currentModelFileId === modelFileId) {
1560
- logger(`ModelFileId "${modelFileId}" correctly set for model "${modelName}"`);
1561
- }
1562
- else {
1563
- logger(`WARNING: ModelFileId not set for model "${modelName}" (expected: "${modelFileId}", got: "${currentModelFileId || 'undefined'}")`);
1564
- // Try to set it again
1565
- service.send({
1566
- type: 'updateContext',
1567
- _modelFileId: modelFileId,
1568
- });
1569
- }
1570
- resolved = true;
1571
- resolve();
1572
- return;
1573
- }
1574
- // Wait for service to become idle
1575
- subscription = service.subscribe((snapshot) => {
1576
- if (snapshot.value === 'idle') {
1577
- if (subscription) {
1578
- subscription.unsubscribe();
1579
- subscription = null;
1580
- }
1581
- const currentModelFileId = snapshot.context._modelFileId;
1582
- if (currentModelFileId === modelFileId) {
1583
- logger(`ModelFileId "${modelFileId}" correctly set for model "${modelName}"`);
1584
- }
1585
- else {
1586
- logger(`WARNING: ModelFileId not set for model "${modelName}" (expected: "${modelFileId}", got: "${currentModelFileId || 'undefined'}")`);
1587
- // Try to set it again - but only once to avoid infinite loop
1588
- if (!resolved) {
1589
- service.send({
1590
- type: 'updateContext',
1591
- _modelFileId: modelFileId,
1592
- });
1593
- }
1594
- }
1595
- if (!resolved) {
1596
- resolved = true;
1597
- resolve();
1598
- }
1599
- }
1600
- else if (snapshot.value === 'error') {
1601
- if (subscription) {
1602
- subscription.unsubscribe();
1603
- subscription = null;
1604
- }
1605
- if (!resolved) {
1606
- resolved = true;
1607
- resolve();
1608
- }
1609
- }
1610
- });
1611
- // Timeout after 2 seconds
1612
- setTimeout(() => {
1613
- if (subscription) {
1614
- subscription.unsubscribe();
1615
- subscription = null;
1616
- }
1617
- if (!resolved) {
1618
- resolved = true;
1619
- resolve();
1620
- }
1621
- }, 2000);
1622
- });
1623
- // Update the model instance with current data
1624
- modelInstance.getService().send({
1625
- type: 'updateContext',
1626
- properties: modelData.properties || {},
1627
- });
1628
- // Initialize original values
1629
- modelInstance.getService().send({
1630
- type: 'initializeOriginalValues',
1631
- originalValues: {
1632
- _originalValues: {
1633
- properties: modelData.properties ? JSON.parse(JSON.stringify(modelData.properties)) : {},
1634
- },
1635
- },
1636
- isEdited: false,
1637
- });
1638
- // Store in instance state
1639
- if (!instanceState.modelInstances) {
1640
- instanceState.modelInstances = new Map();
1641
- }
1642
- instanceState.modelInstances.set(modelName, modelInstance);
1643
- modelInstances.set(modelName, modelInstance);
1644
- logger(`Successfully created model instance for "${modelName}"`);
1645
- }
1646
- catch (error) {
1647
- logger(`Error creating model instance for "${modelName}": ${error}`);
1648
- throw error;
1649
- }
1650
- }
1651
- sendBack({
1652
- type: 'done',
1653
- output: { modelInstances }
1654
- });
1655
- };
1656
- _createInstances().catch((error) => {
1657
- sendBack({ type: 'error', error: error instanceof Error ? error : new Error(String(error)) });
1658
- });
1659
- return () => {
1660
- // Cleanup
1661
- };
1662
- }),
1663
- collectModelFileIds: fromCallback(({ sendBack, input }) => {
1664
- const _collectIds = async () => {
1665
- const debug = (await import('debug')).default;
1666
- const logger = debug('seedSdk:schema:addModels:collectIds');
1667
- const modelFileIds = new Map();
1668
- for (const [modelName, modelInstance] of input.modelInstances.entries()) {
1669
- try {
1670
- const service = modelInstance.getService();
1671
- let modelFileId = undefined;
1672
- // Check current snapshot first
1673
- const snapshot = service.getSnapshot();
1674
- if (snapshot.value === 'idle' && snapshot.context._modelFileId) {
1675
- modelFileId = snapshot.context._modelFileId;
1676
- }
1677
- else {
1678
- // If not ready, wait for it to become idle
1679
- await new Promise((resolve) => {
1680
- const subscription = service.subscribe((snapshot) => {
1681
- if (snapshot.value === 'idle') {
1682
- subscription.unsubscribe();
1683
- if (snapshot.context._modelFileId) {
1684
- modelFileId = snapshot.context._modelFileId;
1685
- }
1686
- resolve();
1687
- }
1688
- else if (snapshot.value === 'error') {
1689
- subscription.unsubscribe();
1690
- resolve();
1691
- }
1692
- });
1693
- // Timeout after 1 second
1694
- setTimeout(() => {
1695
- subscription.unsubscribe();
1696
- resolve();
1697
- }, 1000);
1698
- });
1699
- }
1700
- if (modelFileId) {
1701
- modelFileIds.set(modelName, modelFileId);
1702
- logger(`Collected modelFileId "${modelFileId}" for model "${modelName}"`);
1703
- }
1704
- else {
1705
- logger(`WARNING: modelFileId not found for model "${modelName}" after waiting`);
1706
- }
1707
- }
1708
- catch (error) {
1709
- logger(`Error collecting modelFileId for "${modelName}": ${error}`);
1710
- // Continue with other models even if one fails
1711
- }
1712
- }
1713
- sendBack({
1714
- type: 'done',
1715
- output: { modelFileIds }
1716
- });
1717
- };
1718
- _collectIds().catch((error) => {
1719
- sendBack({ type: 'error', error: error instanceof Error ? error : new Error(String(error)) });
1720
- });
1721
- return () => {
1722
- // Cleanup
1723
- };
1724
- }),
1725
- persistModelsToDb: fromCallback(({ sendBack, input }) => {
1726
- const _persist = async () => {
1727
- const debug = (await import('debug')).default;
1728
- const logger = debug('seedSdk:schema:addModels:persist');
1729
- // Only process in browser environment where store is available
1730
- if (typeof window === 'undefined') {
1731
- logger('Not in browser environment, skipping store update');
1732
- sendBack({
1733
- type: 'done',
1734
- output: { addedModels: input.models }
1735
- });
1736
- return;
1737
- }
1738
- const schemaName = input.schemaContext.metadata?.name || input.schemaContext.schemaName;
1739
- const schemaFileId = input.schemaContext.id; // id is the schemaFileId (string) in SchemaMachineContext
1740
- const db = BaseDb.getAppDb();
1741
- if (!db) {
1742
- logger('Database not found, skipping model store update');
1743
- sendBack({
1744
- type: 'done',
1745
- output: { addedModels: input.models }
1746
- });
1747
- return;
1748
- }
1749
- // Find schema record - prefer schemaFileId lookup (more reliable), then fall back to name
1750
- // Retry up to 3 times with a short delay in case schema is still being saved
1751
- let schemaRecord;
1752
- const maxRetries = 3;
1753
- const retryDelay = 100; // ms
1754
- for (let attempt = 0; attempt < maxRetries && !schemaRecord; attempt++) {
1755
- if (attempt > 0) {
1756
- logger(`Retry ${attempt}/${maxRetries - 1} to find schema, waiting ${retryDelay}ms...`);
1757
- await new Promise(resolve => setTimeout(resolve, retryDelay));
1758
- }
1759
- // PRIMARY: Look up by schemaFileId if available (most reliable, independent of name changes)
1760
- if (schemaFileId) {
1761
- logger(`Looking up schema by schemaFileId: ${schemaFileId} (attempt ${attempt + 1})`);
1762
- const schemasById = await db
1763
- .select()
1764
- .from(schemas)
1765
- .where(eq(schemas.schemaFileId, schemaFileId))
1766
- .limit(1);
1767
- if (schemasById.length > 0) {
1768
- schemaRecord = schemasById[0];
1769
- if (schemaRecord) {
1770
- logger(`Found schema by schemaFileId: ${schemaFileId} (id: ${schemaRecord.id}, name: ${schemaRecord.name}, isDraft: ${schemaRecord.isDraft})`);
1771
- }
1772
- break;
1773
- }
1774
- else {
1775
- logger(`No schema found by schemaFileId: ${schemaFileId}, will try by name`);
1776
- }
1777
- }
1778
- // FALLBACK: If not found by schemaFileId, try by name (prefer draft records)
1779
- if (!schemaRecord) {
1780
- logger(`Looking up schema by name: "${schemaName}" (attempt ${attempt + 1})`);
1781
- const schemasByName = await db
1782
- .select()
1783
- .from(schemas)
1784
- .where(eq(schemas.name, schemaName))
1785
- .orderBy(desc(schemas.isDraft), desc(schemas.version))
1786
- .limit(10); // Get multiple to find drafts
1787
- if (schemasByName.length > 0) {
1788
- // Prefer draft records
1789
- const draftRecord = schemasByName.find((s) => s.isDraft === true);
1790
- schemaRecord = draftRecord || schemasByName[0];
1791
- if (schemaRecord) {
1792
- logger(`Found schema by name "${schemaName}": selected ${draftRecord ? 'draft' : 'first'} record (id: ${schemaRecord.id}, isDraft: ${schemaRecord.isDraft})`);
1793
- }
1794
- break;
1795
- }
1796
- }
1797
- }
1798
- if (!schemaRecord) {
1799
- logger(`Schema "${schemaName}" (schemaFileId: ${schemaFileId || 'none'}) not found in database after ${maxRetries} attempts, skipping model store update`);
1800
- sendBack({
1801
- type: 'done',
1802
- output: { addedModels: input.models }
1803
- });
1804
- return;
1805
- }
1806
- // Convert schema model format to JSON import format for createModelFromJson
1807
- const modelDefinitions = {};
1808
- for (const [modelName, modelDef] of Object.entries(input.models)) {
1809
- // Convert properties from schema format to JSON import format
1810
- const convertedProperties = {};
1811
- if (modelDef.properties) {
1812
- for (const [propName, propDef] of Object.entries(modelDef.properties)) {
1813
- // Schema format: { dataType, ref, refValueType, storageType, localStorageDir, filenameSuffix }
1814
- // JSON import format: { type, model, items, storage: { type, path, extension } }
1815
- const schemaProp = propDef;
1816
- const jsonProp = {
1817
- type: schemaProp.dataType || schemaProp.type,
1818
- };
1819
- // Handle Relation type
1820
- if (schemaProp.ref || schemaProp.refModelName) {
1821
- jsonProp.model = schemaProp.refModelName || schemaProp.ref;
1822
- }
1823
- // Handle List type
1824
- if (isDataType(schemaProp.dataType, ModelPropertyDataTypes.List) && schemaProp.refValueType) {
1825
- jsonProp.refValueType = schemaProp.refValueType;
1826
- if (schemaProp.ref || schemaProp.refModelName) {
1827
- jsonProp.ref = schemaProp.refModelName || schemaProp.ref;
1828
- }
1829
- }
1830
- // Handle storage configuration
1831
- if (schemaProp.storageType || schemaProp.localStorageDir || schemaProp.filenameSuffix) {
1832
- jsonProp.storage = {
1833
- type: schemaProp.storageType === 'ItemStorage' ? 'ItemStorage' : 'PropertyStorage',
1834
- path: schemaProp.localStorageDir,
1835
- extension: schemaProp.filenameSuffix,
1836
- };
1837
- }
1838
- if (schemaProp.required !== undefined) {
1839
- jsonProp.required = schemaProp.required;
1840
- }
1841
- convertedProperties[propName] = jsonProp;
1842
- }
1843
- }
1844
- // Create model definition in JSON import format
1845
- // Note: description is not passed - JSON files can have it but we ignore it at runtime
1846
- const jsonModelDef = {
1847
- properties: convertedProperties,
1848
- };
1849
- // Create Model instance
1850
- const ModelClass = await createModelFromJson(modelName, jsonModelDef, schemaName);
1851
- modelDefinitions[modelName] = ModelClass;
1852
- // Model is now accessible via Model static methods, no registration needed
1853
- logger(`Created model "${modelName}"`);
1854
- }
1855
- // Add models to database with modelFileIds
1856
- if (Object.keys(modelDefinitions).length > 0) {
1857
- await addModelsToDb(modelDefinitions, schemaRecord, undefined, {
1858
- schemaFileId: input.schemaContext.id, // id is the schemaFileId (string) in SchemaMachineContext
1859
- modelFileIds: input.modelFileIds.size > 0 ? input.modelFileIds : undefined,
1860
- });
1861
- logger(`Added ${Object.keys(modelDefinitions).length} new models to database`);
1862
- }
1863
- sendBack({
1864
- type: 'done',
1865
- output: { addedModels: input.models }
1866
- });
1867
- };
1868
- _persist().catch((error) => {
1869
- sendBack({ type: 'error', error: error instanceof Error ? error : new Error(String(error)) });
1870
- });
1871
- return () => {
1872
- // Cleanup
1873
- };
1874
- }),
1875
- },
1876
- }).createMachine({
1877
- id: 'addModels',
1878
- initial: 'preparing',
1879
- context: ({ input }) => ({
1880
- schemaContext: input.schemaContext,
1881
- models: input.models,
1882
- existingModels: input.existingModels,
1883
- progress: {
1884
- stage: 'preparing',
1885
- totalModels: Object.keys(input.models).length,
1886
- completedModels: 0,
1887
- },
1888
- }),
1889
- states: {
1890
- preparing: {
1891
- invoke: {
1892
- src: 'validateModels',
1893
- input: ({ context }) => ({
1894
- newModels: context.models,
1895
- existingModels: context.existingModels,
1896
- }),
1897
- onDone: {
1898
- target: 'creatingInstances',
1899
- actions: assign({
1900
- progress: ({ context }) => ({
1901
- ...context.progress,
1902
- stage: 'creatingInstances',
1903
- }),
1904
- }),
1905
- },
1906
- onError: {
1907
- target: 'error',
1908
- actions: assign({
1909
- errors: ({ context, event }) => [
1910
- ...(context.errors || []),
1911
- {
1912
- modelName: 'validation',
1913
- error: event.error instanceof Error ? event.error : new Error(String(event.error))
1914
- },
1915
- ],
1916
- }),
1917
- },
1918
- },
1919
- },
1920
- creatingInstances: {
1921
- invoke: {
1922
- src: 'createModelInstances',
1923
- input: ({ context }) => ({
1924
- schemaContext: context.schemaContext,
1925
- models: context.models,
1926
- }),
1927
- onDone: {
1928
- target: 'collectingIds',
1929
- actions: assign({
1930
- modelInstances: ({ event }) => {
1931
- // Type assertion needed due to XState v5 type inference limitation
1932
- const doneEvent = event;
1933
- return doneEvent.output?.modelInstances;
1934
- },
1935
- progress: ({ context }) => ({
1936
- ...context.progress,
1937
- stage: 'collectingIds',
1938
- }),
1939
- }),
1940
- },
1941
- onError: {
1942
- target: 'error',
1943
- actions: assign({
1944
- errors: ({ context, event }) => [
1945
- ...(context.errors || []),
1946
- {
1947
- modelName: 'createInstances',
1948
- error: event.error instanceof Error ? event.error : new Error(String(event.error))
1949
- },
1950
- ],
1951
- }),
1952
- },
1953
- },
1954
- },
1955
- collectingIds: {
1956
- invoke: {
1957
- src: 'collectModelFileIds',
1958
- input: ({ context }) => ({
1959
- modelInstances: context.modelInstances,
1960
- }),
1961
- onDone: {
1962
- target: 'persisting',
1963
- actions: assign({
1964
- modelFileIds: ({ event }) => {
1965
- // Type assertion needed due to XState v5 type inference limitation
1966
- const doneEvent = event;
1967
- return doneEvent.output?.modelFileIds;
1968
- },
1969
- progress: ({ context }) => ({
1970
- ...context.progress,
1971
- stage: 'persisting',
1972
- }),
1973
- }),
1974
- },
1975
- onError: {
1976
- target: 'error',
1977
- actions: assign({
1978
- errors: ({ context, event }) => [
1979
- ...(context.errors || []),
1980
- {
1981
- modelName: 'collectIds',
1982
- error: event.error instanceof Error ? event.error : new Error(String(event.error))
1983
- },
1984
- ],
1985
- }),
1986
- },
1987
- },
1988
- },
1989
- persisting: {
1990
- invoke: {
1991
- src: 'persistModelsToDb',
1992
- input: ({ context }) => ({
1993
- schemaContext: context.schemaContext,
1994
- models: context.models,
1995
- modelFileIds: context.modelFileIds,
1996
- }),
1997
- onDone: {
1998
- target: '#addModels.success',
1999
- actions: assign({
2000
- addedModels: ({ event }) => {
2001
- // Type assertion needed due to XState v5 type inference limitation
2002
- // Convert through unknown first to avoid type overlap error
2003
- const doneEvent = event;
2004
- return { addedModels: doneEvent.output?.addedModels };
2005
- },
2006
- }),
2007
- },
2008
- onError: {
2009
- target: 'error',
2010
- actions: assign({
2011
- errors: ({ context, event }) => [
2012
- ...(context.errors || []),
2013
- { modelName: 'persist', error: event.error instanceof Error ? event.error : new Error(String(event.error)) },
2014
- ],
2015
- }),
2016
- },
2017
- },
2018
- },
2019
- success: {
2020
- id: 'success',
2021
- type: 'final',
2022
- output: ({ context }) => ({ addedModels: context.addedModels?.addedModels || [] }),
2023
- },
2024
- error: {
2025
- type: 'final',
2026
- output: ({ context }) => ({
2027
- errors: context.errors || [],
2028
- }),
2029
- },
2030
- },
2031
- });
2032
-
2033
1458
  const logger$c = debug('seedSdk:schema:actors:checkExistingSchema');
2034
1459
  /**
2035
1460
  * Query model IDs (schemaFileId) from database for a given schema
@@ -2084,8 +1509,8 @@ const createModelInstances$1 = async (modelIds) => {
2084
1509
  return;
2085
1510
  }
2086
1511
  try {
2087
- const _mod_7 = await import('./index-HRHkbVQd.js');
2088
- const _ns_7 = _mod_7.b;
1512
+ const _mod_7 = await import('./index-DtfjeuxC.js');
1513
+ const _ns_7 = _mod_7.c;
2089
1514
  const mod = _ns_7;
2090
1515
  const Model = mod?.Model ?? mod?.default;
2091
1516
  if (!Model) {
@@ -2131,8 +1556,8 @@ const checkExistingSchema = fromCallback(({ sendBack, input: { context } }) => {
2131
1556
  if (isInternal && schemaName === SEED_PROTOCOL_SCHEMA_NAME) {
2132
1557
  // For Seed Protocol, check if it exists in database
2133
1558
  try {
2134
- const _mod_8 = await import('./ClientManager-ChcmUL47.js');
2135
- const _ns_8 = _mod_8.ao;
1559
+ const _mod_8 = await import('./ClientManager-DLleL_2e.js');
1560
+ const _ns_8 = _mod_8.S;
2136
1561
  const internalSchema = _ns_8;
2137
1562
  const schemaFile = internalSchema.default;
2138
1563
  if (db && schemaFile.id) {
@@ -2491,8 +1916,8 @@ const writeSchemaToDb = fromCallback(({ sendBack, input }) => {
2491
1916
  if (isInternal && schemaName === SEED_PROTOCOL_SCHEMA_NAME) {
2492
1917
  // For Seed Protocol, load from internal file
2493
1918
  logger$b(`Loading internal Seed Protocol schema from SDK`);
2494
- const _mod_9 = await import('./ClientManager-ChcmUL47.js');
2495
- const _ns_9 = _mod_9.ao;
1919
+ const _mod_9 = await import('./ClientManager-DLleL_2e.js');
1920
+ const _ns_9 = _mod_9.S;
2496
1921
  const internalSchema = _ns_9;
2497
1922
  finalSchema = internalSchema.default;
2498
1923
  const db = BaseDb.getAppDb();
@@ -2961,8 +2386,8 @@ const createModelInstances = fromCallback(({ sendBack, input }) => {
2961
2386
  return;
2962
2387
  }
2963
2388
  try {
2964
- const _mod_10 = await import('./index-HRHkbVQd.js');
2965
- const _ns_10 = _mod_10.b;
2389
+ const _mod_10 = await import('./index-DtfjeuxC.js');
2390
+ const _ns_10 = _mod_10.c;
2966
2391
  const modelMod = _ns_10;
2967
2392
  const { Model } = modelMod;
2968
2393
  // Create instances for all model IDs in parallel
@@ -3049,8 +2474,8 @@ const verifyModelInstancesInCache = fromCallback(({ sendBack, input }) => {
3049
2474
  }
3050
2475
  try {
3051
2476
  const result = await verifyWithRetry$2(async () => {
3052
- const _mod_11 = await import('./index-HRHkbVQd.js');
3053
- const _ns_11 = _mod_11.b;
2477
+ const _mod_11 = await import('./index-DtfjeuxC.js');
2478
+ const _ns_11 = _mod_11.c;
3054
2479
  const modelMod = _ns_11;
3055
2480
  const { Model } = modelMod;
3056
2481
  // Check each model ID in the cache
@@ -3108,8 +2533,8 @@ const writePropertiesToDb = fromCallback(({ sendBack, input }) => {
3108
2533
  const _write = async () => {
3109
2534
  const { modelIds } = input;
3110
2535
  try {
3111
- const _mod_12 = await import('./BasePathResolver-B6CKqoKw.js');
3112
- const _ns_12 = _mod_12.M;
2536
+ const _mod_12 = await import('./BasePathResolver-ndE8XTpw.js');
2537
+ const _ns_12 = _mod_12.N;
3113
2538
  const modelSchemaMod = _ns_12;
3114
2539
  const { models: modelsTable, properties: propertiesTable } = modelSchemaMod;
3115
2540
  const drizzleMod = await import('drizzle-orm');
@@ -3298,10 +2723,10 @@ const createPropertyInstances = fromCallback(({ sendBack, input }) => {
3298
2723
  return;
3299
2724
  }
3300
2725
  try {
3301
- const modProp = await import('./ModelProperty-D79uV42p.js');
2726
+ const modProp = await import('./ModelProperty-lth9L37R.js');
3302
2727
  const ModelProperty = modProp?.ModelProperty ?? modProp?.default;
3303
- const _mod_13 = await import('./index-HRHkbVQd.js');
3304
- const _ns_13 = _mod_13.b;
2728
+ const _mod_13 = await import('./index-DtfjeuxC.js');
2729
+ const _ns_13 = _mod_13.c;
3305
2730
  const modModel = _ns_13;
3306
2731
  const Model = modModel?.Model ?? modModel?.default;
3307
2732
  if (!ModelProperty || !Model) {
@@ -3407,7 +2832,7 @@ const verifyPropertyInstancesInCache = fromCallback(({ sendBack, input }) => {
3407
2832
  }
3408
2833
  try {
3409
2834
  const result = await verifyWithRetry(async () => {
3410
- const mod = await import('./ModelProperty-D79uV42p.js');
2835
+ const mod = await import('./ModelProperty-lth9L37R.js');
3411
2836
  const ModelProperty = mod?.ModelProperty ?? mod?.default;
3412
2837
  if (!ModelProperty) {
3413
2838
  throw new Error('ModelProperty not available from dynamic import');
@@ -3467,7 +2892,6 @@ const schemaMachine = setup({
3467
2892
  actors: {
3468
2893
  loadOrCreateSchema,
3469
2894
  validateSchema,
3470
- addModelsMachine,
3471
2895
  writeProcessMachine,
3472
2896
  // Staged loading actors
3473
2897
  checkExistingSchema,
@@ -3486,9 +2910,6 @@ const schemaMachine = setup({
3486
2910
  isSchemaValid: ({ context }) => {
3487
2911
  return !context._validationErrors || context._validationErrors.length === 0;
3488
2912
  },
3489
- hasValidationErrors: ({ context }) => {
3490
- return !!context._validationErrors && context._validationErrors.length > 0;
3491
- },
3492
2913
  },
3493
2914
  }).createMachine({
3494
2915
  id: 'schema',
@@ -3572,22 +2993,15 @@ const schemaMachine = setup({
3572
2993
  }),
3573
2994
  },
3574
2995
  destroyStarted: {
3575
- actions: assign({ _destroyInProgress: true, _destroyError: null }),
3576
- },
3577
- destroyDone: {
3578
- actions: assign({ _destroyInProgress: false }),
2996
+ actions: assign({ _destroyError: null }),
3579
2997
  },
3580
2998
  destroyError: {
3581
2999
  actions: assign(({ event }) => ({
3582
- _destroyInProgress: false,
3583
3000
  _destroyError: event.error instanceof Error
3584
3001
  ? { message: event.error.message, name: event.error.name }
3585
3002
  : { message: String(event.error) },
3586
3003
  })),
3587
3004
  },
3588
- clearDestroyError: {
3589
- actions: assign({ _destroyError: null }),
3590
- },
3591
3005
  },
3592
3006
  states: {
3593
3007
  loading: {
@@ -3976,9 +3390,6 @@ const schemaMachine = setup({
3976
3390
  },
3977
3391
  }),
3978
3392
  on: {
3979
- addModels: {
3980
- target: 'addingModels',
3981
- },
3982
3393
  validateSchema: {
3983
3394
  target: 'validating',
3984
3395
  },
@@ -3996,122 +3407,27 @@ const schemaMachine = setup({
3996
3407
  },
3997
3408
  },
3998
3409
  },
3999
- always: {
4000
- guard: 'hasValidationErrors',
4001
- target: 'validating',
4002
- },
4003
- },
4004
- addingModels: {
4005
- entry: assign({
4006
- // Move first pending item to current if not already set
4007
- _pendingModelAdditions: ({ context, event }) => {
4008
- const pending = context._pendingModelAdditions || [];
4009
- // If event has models, it's a new request - add to queue if we're already processing
4010
- if (event.models) {
4011
- return [
4012
- ...pending,
4013
- {
4014
- models: event.models,
4015
- timestamp: Date.now(),
4016
- },
4017
- ];
4018
- }
4019
- return pending;
4020
- },
4021
- }),
4022
- invoke: {
4023
- src: 'addModelsMachine',
4024
- input: ({ context }) => {
4025
- // Get models from first item in pending queue, or from context if queue is empty
4026
- const pending = context._pendingModelAdditions || [];
4027
- const models = pending.length > 0 ? pending[0].models : {};
4028
- return {
4029
- schemaContext: context,
4030
- models,
4031
- existingModels: context.models || {},
4032
- };
4033
- },
4034
- onDone: {
4035
- actions: [
4036
- assign({
4037
- models: ({ context, event }) => {
4038
- const addedModels = event.output?.addedModels || {};
4039
- return {
4040
- ...(context.models || {}),
4041
- ...addedModels,
4042
- };
4043
- },
4044
- _pendingModelAdditions: ({ context }) => {
4045
- // Remove first item from queue (the one we just processed)
4046
- const pending = context._pendingModelAdditions || [];
4047
- return pending.length > 1 ? pending.slice(1) : undefined;
4048
- },
4049
- }),
4050
- // Trigger validation after models are added
4051
- ({ self }) => {
4052
- self.send({ type: 'validateSchema' });
4053
- },
4054
- ],
4055
- },
4056
- onError: {
4057
- actions: assign({
4058
- _modelAdditionErrors: ({ context, event }) => {
4059
- const existing = context._modelAdditionErrors || [];
4060
- return [
4061
- ...existing,
4062
- {
4063
- error: event.error instanceof Error ? event.error : new Error(String(event.error)),
4064
- timestamp: Date.now(),
4065
- },
4066
- ];
4067
- },
4068
- _pendingModelAdditions: ({ context }) => {
4069
- // Remove first item from queue even on error, so we can process next
4070
- const pending = context._pendingModelAdditions || [];
4071
- return pending.length > 1 ? pending.slice(1) : undefined;
4072
- },
4073
- }),
4074
- },
4075
- },
4076
- on: {
4077
- // Queue additional requests while processing
4078
- addModels: {
4079
- actions: assign({
4080
- _pendingModelAdditions: ({ context, event }) => {
4081
- const existing = context._pendingModelAdditions || [];
4082
- return [
4083
- ...existing,
4084
- {
4085
- models: event.models,
4086
- timestamp: Date.now(),
4087
- },
4088
- ];
4089
- },
4090
- }),
4091
- },
4092
- },
4093
- always: [
4094
- {
4095
- // If there are pending additions after processing, process next one
4096
- guard: ({ context }) => {
4097
- const pending = context._pendingModelAdditions || [];
4098
- return pending.length > 0;
4099
- },
4100
- target: 'addingModels',
4101
- },
4102
- {
4103
- // No more pending, return to idle
4104
- target: 'idle',
4105
- },
4106
- ],
3410
+ // No `always: hasValidationErrors -> validating` here: validation is re-run when the context changes
3411
+ // (updateContext) or on request (validateSchema). Re-entering while errors exist would loop
3412
+ // forever on a schema that is still invalid.
4107
3413
  },
4108
3414
  validating: {
4109
3415
  on: {
3416
+ // These state-level handlers take precedence over the root ones, so they must store the result
3417
+ // themselves.
4110
3418
  validationSuccess: {
4111
3419
  target: 'idle',
3420
+ actions: assign(({ context }) => ({
3421
+ ...context,
3422
+ _validationErrors: [],
3423
+ })),
4112
3424
  },
4113
3425
  validationError: {
4114
3426
  target: 'idle',
3427
+ actions: assign(({ context, event }) => ({
3428
+ ...context,
3429
+ _validationErrors: event.errors,
3430
+ })),
4115
3431
  },
4116
3432
  },
4117
3433
  invoke: {
@@ -4429,8 +3745,8 @@ async function loadSchemaWithRenames(schemaFilePath, modelRenames) {
4429
3745
  updatedAt: new Date(schemaFile.metadata.updatedAt).getTime(),
4430
3746
  };
4431
3747
  // Use dynamic import to break circular dependency
4432
- const _mod_14 = await import('./db-WbrzEf7c.js');
4433
- const _ns_14 = _mod_14.Q;
3748
+ const _mod_14 = await import('./db-BJZN0a0a.js');
3749
+ const _ns_14 = _mod_14.Z;
4434
3750
  const dbMod = _ns_14;
4435
3751
  const { addSchemaToDb, addModelsToDb } = dbMod;
4436
3752
  // Add schema to database with schemaFileId
@@ -4542,10 +3858,10 @@ async function renameModelProperty(schemaName, modelName, oldPropertyName, newPr
4542
3858
  await BaseFileManager.waitForFileWithContent(newFilePath);
4543
3859
  logger$1(`Renamed property ${oldPropertyName} to ${newPropertyName} in schema ${schemaName} v${newVersion}`);
4544
3860
  // Migrate metadata rows so ItemProperty values follow the new name (prevents duplicate ItemProperties)
4545
- const _mod_15 = await import('./db-WbrzEf7c.js');
4546
- const _ns_15 = _mod_15.Q;
3861
+ const _mod_15 = await import('./db-BJZN0a0a.js');
3862
+ const _ns_15 = _mod_15.Z;
4547
3863
  const { migrateMetadataForPropertyRename } = _ns_15;
4548
- const migratedCount = await migrateMetadataForPropertyRename(modelName, oldPropertyName, newPropertyName, oldProperty.id);
3864
+ const migratedCount = await migrateMetadataForPropertyRename(modelName, oldPropertyName, newPropertyName, oldProperty.id, { schemaName });
4549
3865
  if (migratedCount > 0) {
4550
3866
  logger$1(`Migrated ${migratedCount} metadata rows for property rename`);
4551
3867
  }
@@ -4820,7 +4136,6 @@ class Schema {
4820
4136
  // Initialize instance state in WeakMap (only non-serializable resources)
4821
4137
  schemaInstanceState.set(this, {
4822
4138
  liveQuerySubscription: null,
4823
- modelInstances: new Map(),
4824
4139
  });
4825
4140
  // Set up liveQuery subscription for cross-instance model updates
4826
4141
  // This will be initialized once we have the schemaId
@@ -5030,118 +4345,10 @@ class Schema {
5030
4345
  }
5031
4346
  }
5032
4347
  else if (prop === 'models') {
5033
- // Models are read-only computed values from Model instances
5034
- // Cannot be set directly - models are managed via Model instances
5035
- throw new Error('Cannot set schema.models directly. Models are computed from Model instances.');
5036
- /* DISABLED CODE - See comment above
5037
- // Convert array of Model instances or plain objects back to object format
5038
- let modelsObject: { [key: string]: any }
5039
- if (Array.isArray(value)) {
5040
- modelsObject = {}
5041
- const seenNames = new Set<string>()
5042
-
5043
- // Check for duplicate model names
5044
- for (const model of value) {
5045
- // Handle Model instances
5046
- if (model instanceof Model) {
5047
- const modelName = model.modelName!
5048
- if (seenNames.has(modelName)) {
5049
- throw new Error(
5050
- `Duplicate model name detected: "${modelName}". Each model must have a unique name.`
5051
- )
5052
- }
5053
- seenNames.add(modelName)
5054
- modelsObject[modelName] = {
5055
- properties: model.properties || {},
5056
- }
5057
- } else if (model && typeof model === 'object' && 'name' in model) {
5058
- // Handle plain objects
5059
- const modelName = model.name as string
5060
- if (seenNames.has(modelName)) {
5061
- throw new Error(
5062
- `Duplicate model name detected: "${modelName}". Each model must have a unique name.`
5063
- )
5064
- }
5065
- seenNames.add(modelName)
5066
- const { name, ...modelData } = model
5067
- modelsObject[name] = modelData
5068
- }
5069
- }
5070
- } else {
5071
- modelsObject = value || {}
5072
- // Check for duplicates in object format too
5073
- const modelNames = Object.keys(modelsObject)
5074
- const seenNames = new Set<string>()
5075
- for (const modelName of modelNames) {
5076
- if (seenNames.has(modelName)) {
5077
- throw new Error(
5078
- `Duplicate model name detected: "${modelName}". Each model must have a unique name.`
5079
- )
5080
- }
5081
- seenNames.add(modelName)
5082
- }
5083
- }
5084
-
5085
- const context = newInstance._getSnapshotContext()
5086
-
5087
- // Check if service is still running before sending events
5088
- let snapshot = newInstance._service.getSnapshot()
5089
- const wasServiceStopped = snapshot.status === 'stopped'
5090
-
5091
- if (wasServiceStopped) {
5092
- logger(`Service is stopped, will restart before adding models`)
5093
- newInstance._service.start()
5094
- snapshot = newInstance._service.getSnapshot()
5095
- }
5096
-
5097
- // Check current state after potential restart
5098
- const currentState = snapshot.value
5099
- // Check if state is a loading state object (XState v5 nested states)
5100
- const isServiceLoading = typeof currentState === 'object' && 'loading' in currentState
5101
-
5102
- // If service is loading, wait for it to finish before adding models
5103
- if (isServiceLoading || wasServiceStopped) {
5104
- logger(`Service is ${isServiceLoading ? 'loading' : 'was stopped'}, will add models after loading completes`)
5105
-
5106
- const loadingSubscription = newInstance._service.subscribe((snapshot) => {
5107
- if (snapshot.value === 'idle') {
5108
- loadingSubscription.unsubscribe()
5109
- logger(`Service finished loading, sending addModels event`)
5110
- newInstance._service.send({
5111
- type: 'addModels',
5112
- models: modelsObject,
5113
- })
5114
- } else if (snapshot.value === 'error') {
5115
- loadingSubscription.unsubscribe()
5116
- logger(`Service failed to load, cannot add models`)
5117
- }
5118
- })
5119
- } else {
5120
- // Service is ready, send addModels event immediately
5121
- // The state machine will handle all the complexity (validation, instance creation, ID collection, persistence)
5122
- logger(`Service is ready, sending addModels event`)
5123
- newInstance._service.send({
5124
- type: 'addModels',
5125
- models: modelsObject,
5126
- })
5127
- }
5128
-
5129
- // Mark schema as draft when models change
5130
- newInstance._service.send({
5131
- type: 'markAsDraft',
5132
- propertyKey: 'schema:models',
5133
- })
5134
-
5135
- // Save draft to database immediately so changes persist
5136
- newInstance._saveDraftToDb().catch((error) => {
5137
- logger(`Failed to save draft to database: ${error instanceof Error ? error.message : String(error)}`)
5138
- })
5139
-
5140
- // Update client context so useSchema and useSchemas hooks reflect the change
5141
- newInstance._updateClientContext().catch(() => {
5142
- // Silently fail if not in browser environment
5143
- })
5144
- */
4348
+ // Models are read-only, computed from Model instances. Array assignment was removed because
4349
+ // the draft save could run before the new Model instances existed, losing them.
4350
+ throw new Error('Cannot set schema.models directly. Models are computed from Model instances; ' +
4351
+ 'use Model.create(modelName, schema, { properties }) to add one.');
5145
4352
  }
5146
4353
  else if (prop === 'createdAt' || prop === 'updatedAt') {
5147
4354
  // Update metadata object
@@ -5192,7 +4399,12 @@ class Schema {
5192
4399
  return schema;
5193
4400
  const readyPromise = waitForEntityIdle(schema, { timeout: readyTimeout }).then(() => schema);
5194
4401
  this.pendingSchemaByName.set(schemaName, readyPromise);
5195
- readyPromise.finally(() => this.pendingSchemaByName.delete(schemaName));
4402
+ // Clear on both outcomes without a .finally() chain: that derived promise would reject unhandled
4403
+ // whenever readyPromise does, even when the caller handles the rejection.
4404
+ const clearPending = () => {
4405
+ this.pendingSchemaByName.delete(schemaName);
4406
+ };
4407
+ readyPromise.then(clearPending, clearPending);
5196
4408
  return readyPromise;
5197
4409
  }
5198
4410
  /**
@@ -5753,13 +4965,19 @@ class Schema {
5753
4965
  _dbVersion: publishedSchema.version,
5754
4966
  });
5755
4967
  // Clear edited flags on all ModelProperty instances and in database
5756
- const modelPropertyMod = await import('./ModelProperty-D79uV42p.js');
4968
+ const modelPropertyMod = await import('./ModelProperty-lth9L37R.js');
5757
4969
  const { ModelProperty } = modelPropertyMod;
5758
4970
  for (const propertyKey of context._editedProperties) {
5759
4971
  const [modelName, propertyName] = propertyKey.split(':');
5760
- const cacheKey = `${modelName}:${propertyName}`;
5761
4972
  const ModelPropertyClass = ModelProperty;
5762
- const cachedInstance = ModelPropertyClass.instanceCache.get(cacheKey);
4973
+ // Model names are only unique per schema: pick this schema's instance, which may be keyed by id.
4974
+ const thisSchemaName = this.schemaName;
4975
+ const cachedInstance = [...ModelPropertyClass.instanceCache.values()].find(({ instance }) => {
4976
+ const ctx = instance.getService().getSnapshot().context;
4977
+ return (ctx.modelName === modelName &&
4978
+ ctx.name === propertyName &&
4979
+ (!ctx._schemaName || ctx._schemaName === thisSchemaName));
4980
+ });
5763
4981
  if (cachedInstance) {
5764
4982
  const modelProperty = cachedInstance.instance;
5765
4983
  modelProperty.getService().getSnapshot().context;
@@ -5770,12 +4988,12 @@ class Schema {
5770
4988
  // Clear isEdited flag in database
5771
4989
  try {
5772
4990
  if (db && modelName && propertyName) {
5773
- // Find model by name
5774
- const modelRecords = await db
5775
- .select({ id: models.id })
5776
- .from(models)
5777
- .where(eq(models.name, modelName))
5778
- .limit(1);
4991
+ // Find this schema's model by name
4992
+ const _mod_16 = await import('./db-BJZN0a0a.js');
4993
+ const _ns_16 = _mod_16.Y;
4994
+ const { resolveModelRecord } = _ns_16;
4995
+ const modelRecord = await resolveModelRecord(modelName, { schemaName: thisSchemaName }, db);
4996
+ const modelRecords = modelRecord ? [modelRecord] : [];
5779
4997
  if (modelRecords.length > 0) {
5780
4998
  // Find property by name and modelId
5781
4999
  const propertyRecords = await db
@@ -6337,6 +5555,18 @@ class Schema {
6337
5555
  Schema.instanceCacheByName,
6338
5556
  ],
6339
5557
  });
5558
+ // The rows for this schema's models and properties are deleted below; evict their cached
5559
+ // instances too, or a re-import would get them back with dangling _dbIds.
5560
+ if (schemaName) {
5561
+ const evictedModelNames = Model.evictForSchema(schemaName);
5562
+ const { ModelProperty } = await import('./ModelProperty-lth9L37R.js');
5563
+ ModelProperty.evictForModels(evictedModelNames, schemaName);
5564
+ // Evicting stops new writes but not ones already running; let those land before deleting their rows
5565
+ const _mod_17 = await import('./index-DtfjeuxC.js');
5566
+ const _ns_17 = _mod_17.b;
5567
+ const { waitForInFlightWrites } = _ns_17;
5568
+ await waitForInFlightWrites();
5569
+ }
6340
5570
  await runDestroyLifecycle(this, {
6341
5571
  getService: (instance) => instance._service,
6342
5572
  doDestroy: async () => {
@@ -6556,4 +5786,4 @@ var Schema$1 = /*#__PURE__*/Object.freeze({
6556
5786
  });
6557
5787
 
6558
5788
  export { Schema as S, deletePropertyFromModel as a, Schema$1 as b, deleteModelFromSchema as d, renameModelProperty as r, schemaMachine as s, updateModelProperties as u };
6559
- //# sourceMappingURL=Schema-a8uO-hIZ.js.map
5789
+ //# sourceMappingURL=Schema-DOhlrQ-N.js.map