@seedprotocol/sdk 0.7.5 → 0.7.6-next.957.g6bb7768

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 (220) hide show
  1. package/README.md +2 -2
  2. package/dist/{ClientManager-DRf4uuei.js → ClientManager-D6YA20jP.js} +207 -149
  3. package/dist/ClientManager-D6YA20jP.js.map +1 -0
  4. package/dist/{Item-DTJPMjFk.js → Item-B1MH0tXx.js} +126 -86
  5. package/dist/Item-B1MH0tXx.js.map +1 -0
  6. package/dist/{ModelProperty-Dto5C0om.js → ModelProperty-Dw6dHdu_.js} +37 -37
  7. package/dist/{ModelProperty-Dto5C0om.js.map → ModelProperty-Dw6dHdu_.js.map} +1 -1
  8. package/dist/{Schema-8DxGcORY.js → Schema-DppObO6h.js} +62 -212
  9. package/dist/Schema-DppObO6h.js.map +1 -0
  10. package/dist/{SchemaValidationService-CE92y1TT.js → SchemaValidationService-DXQ-D531.js} +6 -6
  11. package/dist/{SchemaValidationService-CE92y1TT.js.map → SchemaValidationService-DXQ-D531.js.map} +1 -1
  12. package/dist/{backfillMetadataPropertyIds-CRqp-BqX.js → backfillMetadataPropertyIds-Uhzlwg9X.js} +3 -3
  13. package/dist/{backfillMetadataPropertyIds-CRqp-BqX.js.map → backfillMetadataPropertyIds-Uhzlwg9X.js.map} +1 -1
  14. package/dist/configurePlatform-CVoh3JeR.js +81 -0
  15. package/dist/configurePlatform-CVoh3JeR.js.map +1 -0
  16. package/dist/{detachRowsBeforeDelete-BVetHtn2.js → detachRowsBeforeDelete-CtmIFpgV.js} +2 -2
  17. package/dist/{detachRowsBeforeDelete-BVetHtn2.js.map → detachRowsBeforeDelete-CtmIFpgV.js.map} +1 -1
  18. package/dist/{discardNewDraft-CEOouygG.js → discardNewDraft-oGYdB5vS.js} +5 -5
  19. package/dist/{discardNewDraft-CEOouygG.js.map → discardNewDraft-oGYdB5vS.js.map} +1 -1
  20. package/dist/dist/ClientManager-D6YA20jP.d.ts +933 -0
  21. package/dist/dist/ClientManager-D6YA20jP.d.ts.map +1 -0
  22. package/dist/dist/Item-B1MH0tXx.d.ts +898 -0
  23. package/dist/dist/Item-B1MH0tXx.d.ts.map +1 -0
  24. package/dist/dist/ModelProperty-Dw6dHdu_.d.ts +315 -0
  25. package/dist/dist/ModelProperty-Dw6dHdu_.d.ts.map +1 -0
  26. package/dist/dist/Schema-DppObO6h.d.ts +601 -0
  27. package/dist/dist/Schema-DppObO6h.d.ts.map +1 -0
  28. package/dist/dist/SchemaValidationService-DXQ-D531.d.ts +118 -0
  29. package/dist/dist/SchemaValidationService-DXQ-D531.d.ts.map +1 -0
  30. package/dist/dist/backfillMetadataPropertyIds-Uhzlwg9X.d.ts +7 -0
  31. package/dist/dist/backfillMetadataPropertyIds-Uhzlwg9X.d.ts.map +1 -0
  32. package/dist/dist/configurePlatform-CVoh3JeR.d.ts +30 -0
  33. package/dist/dist/configurePlatform-CVoh3JeR.d.ts.map +1 -0
  34. package/dist/dist/detachRowsBeforeDelete-CtmIFpgV.d.ts +13 -0
  35. package/dist/dist/detachRowsBeforeDelete-CtmIFpgV.d.ts.map +1 -0
  36. package/dist/dist/discardNewDraft-oGYdB5vS.d.ts +8 -0
  37. package/dist/dist/discardNewDraft-oGYdB5vS.d.ts.map +1 -0
  38. package/dist/dist/eas-CSm5wmry.d.ts +12 -0
  39. package/dist/dist/eas-CSm5wmry.d.ts.map +1 -0
  40. package/dist/dist/errors-3tc6XkCB.d.ts +487 -0
  41. package/dist/dist/errors-3tc6XkCB.d.ts.map +1 -0
  42. package/dist/dist/errors-Do7v6RKu.d.ts +22 -0
  43. package/dist/dist/errors-Do7v6RKu.d.ts.map +1 -0
  44. package/dist/dist/getItem-DM3a-7XE.d.ts +6 -0
  45. package/dist/dist/getItem-DM3a-7XE.d.ts.map +1 -0
  46. package/dist/dist/getPublishPayload-CJF0k5d8.d.ts +47 -0
  47. package/dist/dist/getPublishPayload-CJF0k5d8.d.ts.map +1 -0
  48. package/dist/dist/getPublishUploads-C7-fYIgX.d.ts +89 -0
  49. package/dist/dist/getPublishUploads-C7-fYIgX.d.ts.map +1 -0
  50. package/dist/dist/index--mmQ3LQu.d.ts +6 -0
  51. package/dist/dist/index--mmQ3LQu.d.ts.map +1 -0
  52. package/dist/dist/index-B7yAoYli.d.ts +2752 -0
  53. package/dist/dist/index-B7yAoYli.d.ts.map +1 -0
  54. package/dist/dist/index-CrvIcVFJ.d.ts +4475 -0
  55. package/dist/dist/index-CrvIcVFJ.d.ts.map +1 -0
  56. package/dist/dist/index.browser-BmVS-c2C.d.ts +8445 -0
  57. package/dist/dist/index.browser-BmVS-c2C.d.ts.map +1 -0
  58. package/dist/dist/index.node-BKpbCAWt.d.ts +11123 -0
  59. package/dist/dist/index.node-BKpbCAWt.d.ts.map +1 -0
  60. package/dist/dist/mimeTypes-C9r76DCH.d.ts +30 -0
  61. package/dist/dist/mimeTypes-C9r76DCH.d.ts.map +1 -0
  62. package/dist/dist/model-oHA3YhOd.d.ts +6 -0
  63. package/dist/dist/model-oHA3YhOd.d.ts.map +1 -0
  64. package/dist/dist/platform.browser.d.ts +3 -0
  65. package/dist/dist/platform.browser.d.ts.map +1 -0
  66. package/dist/dist/platform.node.d.ts +3 -0
  67. package/dist/dist/platform.node.d.ts.map +1 -0
  68. package/dist/dist/property-DQ-Owzki.d.ts +37 -0
  69. package/dist/dist/property-DQ-Owzki.d.ts.map +1 -0
  70. package/dist/dist/propertyValidationRules-BDhFjlwP.d.ts +8 -0
  71. package/dist/dist/propertyValidationRules-BDhFjlwP.d.ts.map +1 -0
  72. package/dist/dist/publishDraftGraph-CzPd9oe9.d.ts +76 -0
  73. package/dist/dist/publishDraftGraph-CzPd9oe9.d.ts.map +1 -0
  74. package/dist/dist/resetAmbiguousLegacyItemData-cXZm4NuG.d.ts +17 -0
  75. package/dist/dist/resetAmbiguousLegacyItemData-cXZm4NuG.d.ts.map +1 -0
  76. package/dist/dist/resolveModelForSyncedSeed-BgxtVCHI.d.ts +21 -0
  77. package/dist/dist/resolveModelForSyncedSeed-BgxtVCHI.d.ts.map +1 -0
  78. package/dist/dist/syncDbWithEas-Y5GysSCm.d.ts +22 -0
  79. package/dist/dist/syncDbWithEas-Y5GysSCm.d.ts.map +1 -0
  80. package/dist/dist/tabEvents-D9x26vf2.d.ts +81 -0
  81. package/dist/dist/tabEvents-D9x26vf2.d.ts.map +1 -0
  82. package/dist/dist/tolerantWebAccess-BFU2t-SC.d.ts +113 -0
  83. package/dist/dist/tolerantWebAccess-BFU2t-SC.d.ts.map +1 -0
  84. package/dist/dist/updateSeedRevokedAt-CCF8WWYS.d.ts +11 -0
  85. package/dist/dist/updateSeedRevokedAt-CCF8WWYS.d.ts.map +1 -0
  86. package/dist/drizzle.js +2 -0
  87. package/dist/drizzle.js.map +1 -0
  88. package/dist/{eas-D7jvWMnI.js → eas-CSm5wmry.js} +3 -3
  89. package/dist/{eas-D7jvWMnI.js.map → eas-CSm5wmry.js.map} +1 -1
  90. package/dist/{errors-CIrbsN_i.js → errors-3tc6XkCB.js} +81 -36
  91. package/dist/errors-3tc6XkCB.js.map +1 -0
  92. package/dist/errors-Do7v6RKu.js +34 -0
  93. package/dist/errors-Do7v6RKu.js.map +1 -0
  94. package/dist/{getItem-CxU_kT5W.js → getItem-DM3a-7XE.js} +4 -4
  95. package/dist/{getItem-CxU_kT5W.js.map → getItem-DM3a-7XE.js.map} +1 -1
  96. package/dist/{getPublishPayload-DTjOKd3y.js → getPublishPayload-CJF0k5d8.js} +31 -25
  97. package/dist/getPublishPayload-CJF0k5d8.js.map +1 -0
  98. package/dist/{getPublishUploads-CVTBo_OV.js → getPublishUploads-C7-fYIgX.js} +6 -6
  99. package/dist/{getPublishUploads-CVTBo_OV.js.map → getPublishUploads-C7-fYIgX.js.map} +1 -1
  100. package/dist/{index-CMxEil8T.js → index--mmQ3LQu.js} +8 -8
  101. package/dist/index--mmQ3LQu.js.map +1 -0
  102. package/dist/{index-DWK-LOUY.js → index-B7yAoYli.js} +2 -2
  103. package/dist/index-B7yAoYli.js.map +1 -0
  104. package/dist/{BasePathResolver-CBTXCMFL.js → index-CrvIcVFJ.js} +304 -285
  105. package/dist/index-CrvIcVFJ.js.map +1 -0
  106. package/dist/{index.browser-shRXMeB3.js → index.browser-BmVS-c2C.js} +34 -44
  107. package/dist/index.browser-BmVS-c2C.js.map +1 -0
  108. package/dist/{index.node-DAKJNYp5.js → index.node-BKpbCAWt.js} +43 -7
  109. package/dist/index.node-BKpbCAWt.js.map +1 -0
  110. package/dist/main.js +23 -24
  111. package/dist/main.js.map +1 -1
  112. package/dist/node.js +13 -10
  113. package/dist/node.js.map +1 -1
  114. package/dist/platform.browser.js +7 -7
  115. package/dist/platform.node.js +4 -4
  116. package/dist/{property-lz9yIpyA.js → property-DQ-Owzki.js} +7 -7
  117. package/dist/{property-lz9yIpyA.js.map → property-DQ-Owzki.js.map} +1 -1
  118. package/dist/{propertyValidationRules-LuIwoQoJ.js → propertyValidationRules-BDhFjlwP.js} +10 -10
  119. package/dist/{propertyValidationRules-LuIwoQoJ.js.map → propertyValidationRules-BDhFjlwP.js.map} +1 -1
  120. package/dist/{publishDraftGraph-CgSLPKvQ.js → publishDraftGraph-CzPd9oe9.js} +41 -8
  121. package/dist/publishDraftGraph-CzPd9oe9.js.map +1 -0
  122. package/dist/{resetAmbiguousLegacyItemData-CuamkAAh.js → resetAmbiguousLegacyItemData-cXZm4NuG.js} +2 -2
  123. package/dist/{resetAmbiguousLegacyItemData-CuamkAAh.js.map → resetAmbiguousLegacyItemData-cXZm4NuG.js.map} +1 -1
  124. package/dist/{resolveModelForSyncedSeed-BbSctSvz.js → resolveModelForSyncedSeed-BgxtVCHI.js} +2 -2
  125. package/dist/{resolveModelForSyncedSeed-BbSctSvz.js.map → resolveModelForSyncedSeed-BgxtVCHI.js.map} +1 -1
  126. package/dist/src/Item/Item.d.ts.map +1 -1
  127. package/dist/src/ItemProperty/service/actors/initialize.d.ts.map +1 -1
  128. package/dist/src/ItemProperty/service/actors/saveValueToDb/analyzeInput.d.ts.map +1 -1
  129. package/dist/src/ItemProperty/service/actors/saveValueToDb/rowContext.d.ts +10 -0
  130. package/dist/src/ItemProperty/service/actors/saveValueToDb/rowContext.d.ts.map +1 -0
  131. package/dist/src/ItemProperty/service/actors/saveValueToDb/saveFile.d.ts.map +1 -1
  132. package/dist/src/ItemProperty/service/actors/saveValueToDb/saveHtml.d.ts.map +1 -1
  133. package/dist/src/ItemProperty/service/actors/saveValueToDb/saveImage.d.ts.map +1 -1
  134. package/dist/src/ItemProperty/service/actors/saveValueToDb/saveItemStorage.d.ts.map +1 -1
  135. package/dist/src/ItemProperty/service/propertyMachine.d.ts +20 -20
  136. package/dist/src/Model/Model.d.ts +8 -0
  137. package/dist/src/Model/Model.d.ts.map +1 -1
  138. package/dist/src/ModelProperty/ModelProperty.d.ts +1 -1
  139. package/dist/src/ModelProperty/service/modelPropertyMachine.d.ts +3 -3
  140. package/dist/src/Schema/service/actors/checkExistingSchema.d.ts.map +1 -1
  141. package/dist/src/Schema/service/actors/loadOrCreateSchema.d.ts.map +1 -1
  142. package/dist/src/Schema/service/actors/writeModelsToDb.d.ts.map +1 -1
  143. package/dist/src/browser/db/Db.d.ts.map +1 -1
  144. package/dist/src/browser/helpers/ArweaveClient.d.ts.map +1 -1
  145. package/dist/src/client/actors/addModelsToDb.d.ts.map +1 -1
  146. package/dist/src/client/actors/platformClassesInit.d.ts +1 -7
  147. package/dist/src/client/actors/platformClassesInit.d.ts.map +1 -1
  148. package/dist/src/client/actors/saveAppState.d.ts.map +1 -1
  149. package/dist/src/client/actors/saveConfig.d.ts.map +1 -1
  150. package/dist/src/client/seedConfigDefaults.d.ts +10 -0
  151. package/dist/src/client/seedConfigDefaults.d.ts.map +1 -0
  152. package/dist/src/db/read/getPublishPayload.d.ts.map +1 -1
  153. package/dist/src/db/write/updateItemPropertyValue.d.ts +6 -0
  154. package/dist/src/db/write/updateItemPropertyValue.d.ts.map +1 -1
  155. package/dist/src/drizzle/index.d.ts +7 -0
  156. package/dist/src/drizzle/index.d.ts.map +1 -0
  157. package/dist/src/events/files/download.d.ts.map +1 -1
  158. package/dist/src/events/item/syncDbWithEas.d.ts.map +1 -1
  159. package/dist/src/helpers/FileManager/errors.d.ts +11 -0
  160. package/dist/src/helpers/FileManager/errors.d.ts.map +1 -1
  161. package/dist/src/helpers/db.d.ts +14 -0
  162. package/dist/src/helpers/db.d.ts.map +1 -1
  163. package/dist/src/helpers/dotSeedPath.d.ts +7 -0
  164. package/dist/src/helpers/dotSeedPath.d.ts.map +1 -0
  165. package/dist/src/helpers/entity/entityLiveQuery.d.ts.map +1 -1
  166. package/dist/src/helpers/environment.d.ts +5 -0
  167. package/dist/src/helpers/environment.d.ts.map +1 -1
  168. package/dist/src/helpers/getSegmentedItemProperties.d.ts.map +1 -1
  169. package/dist/src/helpers/metadataPropertyNames.d.ts +10 -0
  170. package/dist/src/helpers/metadataPropertyNames.d.ts.map +1 -1
  171. package/dist/src/helpers/reconcilePropertyDraftRows.d.ts +9 -0
  172. package/dist/src/helpers/reconcilePropertyDraftRows.d.ts.map +1 -0
  173. package/dist/src/helpers/updateSchema.d.ts.map +1 -1
  174. package/dist/src/imports/index.d.ts +1 -1
  175. package/dist/src/imports/index.d.ts.map +1 -1
  176. package/dist/src/imports/json.d.ts +18 -5
  177. package/dist/src/imports/json.d.ts.map +1 -1
  178. package/dist/src/index.d.ts +2 -2
  179. package/dist/src/index.d.ts.map +1 -1
  180. package/dist/src/node/helpers/resolveFilesDir.d.ts +8 -0
  181. package/dist/src/node/helpers/resolveFilesDir.d.ts.map +1 -0
  182. package/dist/src/node/webpack/index.d.ts +2 -0
  183. package/dist/src/node/webpack/index.d.ts.map +1 -1
  184. package/dist/src/platform/index.browser.d.ts +5 -0
  185. package/dist/src/platform/index.browser.d.ts.map +1 -1
  186. package/dist/src/platform/index.node.d.ts +1 -0
  187. package/dist/src/platform/index.node.d.ts.map +1 -1
  188. package/dist/src/stores/eas.d.ts +1 -1
  189. package/dist/src/stores/eas.d.ts.map +1 -1
  190. package/dist/src/types/import.d.ts +15 -0
  191. package/dist/src/types/import.d.ts.map +1 -1
  192. package/dist/src/types/index.d.ts +8 -4
  193. package/dist/src/types/index.d.ts.map +1 -1
  194. package/dist/{syncDbWithEas-CrAY9Rl2.js → syncDbWithEas-Y5GysSCm.js} +17 -13
  195. package/dist/syncDbWithEas-Y5GysSCm.js.map +1 -0
  196. package/dist/{tabEvents-BGBYV65P.js → tabEvents-D9x26vf2.js} +4 -4
  197. package/dist/{tabEvents-BGBYV65P.js.map → tabEvents-D9x26vf2.js.map} +1 -1
  198. package/dist/{tolerantWebAccess-DVHCEulL.js → tolerantWebAccess-BFU2t-SC.js} +8 -8
  199. package/dist/{tolerantWebAccess-DVHCEulL.js.map → tolerantWebAccess-BFU2t-SC.js.map} +1 -1
  200. package/dist/{updateSeedRevokedAt-Dy5J8CfQ.js → updateSeedRevokedAt-CCF8WWYS.js} +3 -3
  201. package/dist/{updateSeedRevokedAt-Dy5J8CfQ.js.map → updateSeedRevokedAt-CCF8WWYS.js.map} +1 -1
  202. package/package.json +31 -31
  203. package/dist/BasePathResolver-CBTXCMFL.js.map +0 -1
  204. package/dist/ClientManager-DRf4uuei.js.map +0 -1
  205. package/dist/Item-DTJPMjFk.js.map +0 -1
  206. package/dist/Schema-8DxGcORY.js.map +0 -1
  207. package/dist/configurePlatform-D4aGjKNk.js +0 -31
  208. package/dist/configurePlatform-D4aGjKNk.js.map +0 -1
  209. package/dist/errors-CIrbsN_i.js.map +0 -1
  210. package/dist/errors-CrBxGWah.js +0 -17
  211. package/dist/errors-CrBxGWah.js.map +0 -1
  212. package/dist/getPublishPayload-DTjOKd3y.js.map +0 -1
  213. package/dist/index-CMxEil8T.js.map +0 -1
  214. package/dist/index-DWK-LOUY.js.map +0 -1
  215. package/dist/index.browser-shRXMeB3.js.map +0 -1
  216. package/dist/index.node-DAKJNYp5.js.map +0 -1
  217. package/dist/publishDraftGraph-CgSLPKvQ.js.map +0 -1
  218. package/dist/src/client/nodeEndpointDefaults.d.ts +0 -8
  219. package/dist/src/client/nodeEndpointDefaults.d.ts.map +0 -1
  220. package/dist/syncDbWithEas-CrAY9Rl2.js.map +0 -1
@@ -1,10 +1,10 @@
1
1
  import { startCase, isEqual } from 'lodash-es';
2
- import { B as BaseDb, o as easSyncProcesses, I as eventEmitter, a4 as isNode, af as isBrowser, K as BasePathResolver, aF as normalizeAddressConfig, j as appState, aS as downloadAllFilesRequestHandler, aT as downloadAllFilesBinaryRequestHandler, h as BaseFileManager, t as models$1, s as modelUids, C as seeds, aG as normalizeAddressList, A as schemas, aQ as loadModelsFromDbForSchema, aN as addSchemaToDb, aK as isInternalSchema, aU as warnOnInvalidNameMatch, aV as INTERNAL_SCHEMA_IDS, al as generateId, aW as linkModelToSchema, aR as clearNameMatchLevels, n as normalizeDataType, ae as easPropertyNameForPublish, av as SEED_PROTOCOL_SCHEMA_NAME, r as modelSchemas, m as metadata$1, v as properties, N as resolveItemModelFileId, F as versions, ah as normalizePublisher, aj as loadNameMatchLevels, p as htmlEmbeddedImageCoPublish, k as arweaveL1FinalizeJobs, z as publishProcesses, aX as getWatchedAddressesFromDb, aY as getOwnedAddressesFromDb, aZ as CLIENT_NOT_INITIALIZED } from './BasePathResolver-CBTXCMFL.js';
2
+ import { B as BaseDb, o as easSyncProcesses, I as eventEmitter, ac as isBrowser, a1 as isNode, aE as normalizeAddressConfig, aS as isTestOrSeedDev, j as appState, aT as downloadAllFilesRequestHandler, aU as downloadAllFilesBinaryRequestHandler, h as BaseFileManager, t as models$1, s as modelUids, C as seeds, aF as normalizeAddressList, A as schemas, aP as loadModelsFromDbForSchema, aM as addSchemaToDb, aJ as isInternalSchema, ai as generateId, aR as clearNameMatchLevels, aV as warnOnInvalidNameMatch, aW as INTERNAL_SCHEMA_IDS, aX as linkModelToSchema, n as normalizeDataType, ab as easPropertyNameForPublish, au as SEED_PROTOCOL_SCHEMA_NAME, r as modelSchemas, m as metadata$1, v as properties, L as resolveItemModelFileId, F as versions, ae as normalizePublisher, ag as loadNameMatchLevels, p as htmlEmbeddedImageCoPublish, k as arweaveL1FinalizeJobs, z as publishProcesses, aY as getWatchedAddressesFromDb, aZ as getOwnedAddressesFromDb, a_ as CLIENT_NOT_INITIALIZED } from './index-CrvIcVFJ.js';
3
3
  import debug from 'debug';
4
4
  import { createActor, setup, assign, fromPromise, fromCallback, waitFor } from 'xstate';
5
- import { u as MachineIds, a0 as ClientManagerEvents, a1 as withLockedItemStorageRow, a2 as getItemStorageFilePath, a3 as writeItemStorageFile, e as compareMetadataRowsLatestFirst, w as writeInBatches, a4 as resolvePublisherFromSeedRow, C as ClientManagerState, G as isLocalUnsealedDraft, s as selectInBatches, I as Item } from './Item-DTJPMjFk.js';
5
+ import { u as MachineIds, a0 as ClientManagerEvents, a1 as withLockedItemStorageRow, a2 as getItemStorageFilePath, a3 as writeItemStorageFile, e as compareMetadataRowsLatestFirst, w as writeInBatches, a4 as resolvePublisherFromSeedRow, C as ClientManagerState, G as isLocalUnsealedDraft, s as selectInBatches, I as Item } from './Item-B1MH0tXx.js';
6
6
  import { eq, inArray, and, isNotNull, ne, desc, countDistinct, isNull, or, sql, like } from 'drizzle-orm';
7
- import { a as withDbTabLock, i as isLeaderTab, c as postTabMessage, o as onTabMessage, w as whenLeaderTab, l as listenForOtherTabsEvents, s as startTabCoordination, b as withSeedDbLock, e as emitAcrossTabs, A as ADDRESSES_PERSISTED_EVENT, p as parseAddressesPersistedPayload, L as LOCAL_COPIES_REMOVED_EVENT } from './tabEvents-BGBYV65P.js';
7
+ import { a as withDbTabLock, i as isLeaderTab, c as postTabMessage, o as onTabMessage, w as whenLeaderTab, l as listenForOtherTabsEvents, s as startTabCoordination, b as withSeedDbLock, e as emitAcrossTabs, A as ADDRESSES_PERSISTED_EVENT, p as parseAddressesPersistedPayload, L as LOCAL_COPIES_REMOVED_EVENT } from './tabEvents-D9x26vf2.js';
8
8
  import { seedGatewayConfigFromSeedConfig, setPreferredArweaveReadBaseUrls, resolveSeedGatewayEndpoints, setResolvedSeedGatewayEndpoints, BaseArweaveClient, ensureReadGatewaySelected, DEFAULT_ARWEAVE_HOST } from '@seedprotocol/arweave';
9
9
  import { configureEasReadChain, easName, BaseQueryClient, BaseEasClient, GET_SCHEMAS, whenEasReadChainSettled, getEasReadChainId, DEFAULT_EAS_CHAIN_ID, isEasReadChainConfigured, isPlaceholderUid, localNamesInBestMatchTier, isValidEasAttestationUid } from '@seedprotocol/eas';
10
10
  import 'pluralize';
@@ -212,7 +212,7 @@ function toRunSyncArg(options) {
212
212
  return undefined;
213
213
  }
214
214
  const runEasSync = fromPromise(async ({ input, }) => {
215
- const { runSyncFromEas } = await import('./syncDbWithEas-CrAY9Rl2.js');
215
+ const { runSyncFromEas } = await import('./syncDbWithEas-Y5GysSCm.js');
216
216
  // Sync checks for rows and then inserts the rest (no unique index on uids), so syncs in
217
217
  // different tabs take turns. A sync can run for minutes, so wait without a timeout.
218
218
  await withDbTabLock('eas-sync', async () => {
@@ -542,39 +542,28 @@ const setupServiceHandlers = () => {
542
542
  eventEmitter.addListener('service.save', saveServiceHandler);
543
543
  };
544
544
 
545
+ /** `filesDir` when the config sets neither it nor `endpoints.files`. */
546
+ const DEFAULT_FILES_DIR = '.seed';
545
547
  /**
546
- * On Node, storage uses `filesDir`. `endpoints.filePaths` and `endpoints.files` are
547
- * required by init but have no separate Node consumer, so fill them from `filesDir`.
548
- * Browser configs are left unchanged.
548
+ * Fills `filesDir` and `endpoints` so `client.init` can be called with neither. `filesDir` falls
549
+ * back to `endpoints.files`, then to {@link DEFAULT_FILES_DIR}. The endpoint labels have no consumer
550
+ * besides that fallback and the copy saved in `app_state`, so missing ones take `filesDir`.
549
551
  */
550
- function normalizeSeedConfigEndpoints(config) {
552
+ function applySeedConfigDefaults(config) {
551
553
  if (!config)
552
554
  return config;
553
555
  const endpoints = config.endpoints;
554
556
  if (endpoints?.filePaths && endpoints?.files)
555
557
  return config;
556
- if (!(isNode() && !isBrowser()))
557
- return config;
558
- const filesDir = config.filesDir;
559
- if (!filesDir)
560
- return config;
558
+ const filesDir = config.filesDir || endpoints?.files || DEFAULT_FILES_DIR;
561
559
  const next = {
562
560
  filePaths: endpoints?.filePaths || filesDir,
563
561
  files: endpoints?.files || filesDir,
564
562
  };
565
- return { ...config, endpoints: next };
563
+ return { ...config, filesDir, endpoints: next };
566
564
  }
567
565
 
568
566
  const logger$e = debug('seedSdk:ClientManager:initialize');
569
- /**
570
- * Whether a relative filesDir already names the .seed directory or a path inside
571
- * it ('.seed', '.seed/files', './.seed/files'). '.seed-alt/x' is not: it is
572
- * resolved under .seed like any other relative path.
573
- */
574
- function isUnderDotSeed(relativePath) {
575
- const firstSegment = relativePath.split(/[\\/]+/).find((segment) => segment !== '' && segment !== '.');
576
- return firstSegment === '.seed';
577
- }
578
567
  const platformClassesInit = fromCallback(({ sendBack, input: { context, event } }) => {
579
568
  logger$e('initialize from ClientManager');
580
569
  const { isInitialized } = context;
@@ -586,10 +575,6 @@ const platformClassesInit = fromCallback(({ sendBack, input: { context, event }
586
575
  sendBack({ type: 'initialized' });
587
576
  return;
588
577
  }
589
- // Validate synchronously before starting async operations
590
- // This ensures errors are handled immediately, preventing unhandled rejections
591
- const { config } = options;
592
- const { endpoints } = config || {};
593
578
  // Track if the operation is cancelled
594
579
  let cancelled = false;
595
580
  // Create a promise that will handle validation errors immediately
@@ -601,21 +586,22 @@ const platformClassesInit = fromCallback(({ sendBack, input: { context, event }
601
586
  return;
602
587
  }
603
588
  const { addresses } = options;
604
- const config = normalizeSeedConfigEndpoints(options.config);
605
- // Validate required endpoints - this should happen early in the initialization process.
606
- // Node fills these from filesDir; browser callers still pass them.
607
- if (!config?.endpoints || !config.endpoints.filePaths || !config.endpoints.files) {
608
- throw new Error('Config must include endpoints with filePaths and files');
609
- }
610
- // Prefer the condition-resolved factory when available; fall back to explicit
611
- // platform imports so source/vitest resolution stays reliable.
612
- const { configurePlatform } = await import('./configurePlatform-D4aGjKNk.js');
589
+ const config = applySeedConfigDefaults(options.config);
590
+ if (!config) {
591
+ throw new Error('client.init requires a config');
592
+ }
593
+ const _mod_0 = await import('./configurePlatform-CVoh3JeR.js');
594
+ const _ns_0 = _mod_0.a;
595
+ const { configurePlatform } = _ns_0;
613
596
  if (isBrowser()) {
614
597
  const { createPlatformServices } = await import('./platform.browser.js');
615
598
  configurePlatform(createPlatformServices());
616
599
  }
617
600
  else if (isNode()) {
618
- const { createPlatformServices } = await import('./platform.node.js');
601
+ // `#seed-node-platform` (package.json `imports`) maps to the browser platform under
602
+ // the `browser` condition, so browser bundles never contain the Node platform
603
+ // (libsql, node:fs). A relative import here would ship it to every browser app.
604
+ const { createPlatformServices } = await import('#seed-node-platform');
619
605
  configurePlatform(createPlatformServices());
620
606
  }
621
607
  else {
@@ -642,45 +628,15 @@ const platformClassesInit = fromCallback(({ sendBack, input: { context, event }
642
628
  const resolvedGateway = await resolveSeedGatewayEndpoints(gatewayConfig);
643
629
  setResolvedSeedGatewayEndpoints(resolvedGateway);
644
630
  BaseArweaveClient.setHost(`${resolvedGateway.arweaveProtocol}://${resolvedGateway.arweaveHost}`);
645
- // Note: Validation already happened above, but we have endpoints here for path normalization
646
- // Normalize filesDir for Node.js environment
647
- // In Node.js, filesDir should be resolved relative to .seed directory at project root
631
+ // filesDir falls back to endpoints.files (applySeedConfigDefaults fills both)
648
632
  let normalizedFilesDir = filesDir || endpoints?.files;
649
633
  // jsdom (and any env with both Node + window) is "browser" for SDK: PathResolver is OPFS/virtual.
650
634
  // Do not run real fs against those paths (e.g. mkdir '/.seed').
651
635
  if (isNode() && !isBrowser() && normalizedFilesDir) {
652
- const path = (await import('node:path')).default;
653
- const fs = (await import('node:fs')).default;
654
- // Not created here: prepareDb creates filesDir (under .seed when it's relative), so an absolute
655
- // filesDir works from a read-only working directory (e.g. a packaged Electron app's cwd `/`).
656
- const dotSeedDir = BasePathResolver.getDotSeedDir();
657
- // Check if filesDir is a browser OPFS-style path (absolute path starting with '/'
658
- // that is a simple single-level path like '/app-files', not a real filesystem path)
659
- // Browser OPFS paths are typically simple like '/app-files', '/files', etc.
660
- const pathWithoutLeadingSlash = normalizedFilesDir.slice(1);
661
- const isBrowserOpfsPath = path.isAbsolute(normalizedFilesDir) &&
662
- normalizedFilesDir.startsWith('/') &&
663
- pathWithoutLeadingSlash.length > 0 &&
664
- !pathWithoutLeadingSlash.includes('/') && // Single directory name, no subdirectories
665
- !fs.existsSync(normalizedFilesDir); // Doesn't exist on filesystem
666
- if (isBrowserOpfsPath) {
667
- // Convert browser OPFS path to .seed subdirectory
668
- // e.g., '/app-files' -> '.seed/app-files'
669
- const dirName = normalizedFilesDir.slice(1) || 'app-files';
670
- normalizedFilesDir = path.join(dotSeedDir, dirName);
671
- }
672
- else if (!path.isAbsolute(normalizedFilesDir)) {
673
- // If it's a relative path, check if it is already under .seed
674
- if (isUnderDotSeed(normalizedFilesDir)) {
675
- // Already relative to project root, resolve it
676
- normalizedFilesDir = path.resolve(normalizedFilesDir);
677
- }
678
- else {
679
- // Resolve relative to .seed directory
680
- normalizedFilesDir = path.join(dotSeedDir, normalizedFilesDir);
681
- }
682
- }
683
- // If it's an absolute path that exists or is a valid filesystem path, use it as-is
636
+ // Lives in the Node platform so browser bundles (and Next.js server builds, which
637
+ // alias it to the browser platform) carry no fs code with computed paths.
638
+ const { resolveFilesDir } = await import('#seed-node-platform');
639
+ normalizedFilesDir = resolveFilesDir(normalizedFilesDir);
684
640
  }
685
641
  const normalizedAddresses = normalizeAddressConfig(addresses);
686
642
  sendBack({ type: 'updateContext', context: {
@@ -754,7 +710,7 @@ const saveAppState = fromCallback(({ sendBack, input: { key, value } }) => {
754
710
  const appDb = BaseDb.getAppDb();
755
711
  if (!appDb) {
756
712
  // In test environments, continue anyway
757
- if (process.env.NODE_ENV === 'test' || process.env.IS_SEED_DEV) {
713
+ if (isTestOrSeedDev()) {
758
714
  logger$d('[client/actors] [saveAppState] App DB not found, but continuing in test environment');
759
715
  return;
760
716
  }
@@ -776,7 +732,7 @@ const saveAppState = fromCallback(({ sendBack, input: { key, value } }) => {
776
732
  catch (error) {
777
733
  logger$d('[client/actors] [saveAppState] Error saving app state:', error);
778
734
  // In test environments, continue anyway
779
- if (process.env.NODE_ENV === 'test' || process.env.IS_SEED_DEV) {
735
+ if (isTestOrSeedDev()) {
780
736
  logger$d('[client/actors] [saveAppState] Continuing despite error in test environment');
781
737
  return;
782
738
  }
@@ -794,7 +750,7 @@ const saveAppState = fromCallback(({ sendBack, input: { key, value } }) => {
794
750
  .catch((error) => {
795
751
  logger$d('[client/actors] [saveAppState] Error in promise chain:', error);
796
752
  // In test environments, still send success to allow state machine to progress
797
- if (process.env.NODE_ENV === 'test' || process.env.IS_SEED_DEV) {
753
+ if (isTestOrSeedDev()) {
798
754
  logger$d('[client/actors] [saveAppState] Sending success despite error in test environment');
799
755
  sendBack({
800
756
  type: 'saveAppStateSuccess',
@@ -1051,7 +1007,7 @@ const addModelsToDb = fromCallback(({ sendBack, input: { context } }) => {
1051
1007
  }
1052
1008
  }
1053
1009
  catch (error) {
1054
- if (process.env.NODE_ENV === 'test' || process.env.IS_SEED_DEV) {
1010
+ if (isTestOrSeedDev()) {
1055
1011
  logger$a('[client/actors] [addModelsToDb] Warning: Could not fetch schemas from EAS (background):', error.message);
1056
1012
  }
1057
1013
  else {
@@ -1073,7 +1029,7 @@ const addModelsToDb = fromCallback(({ sendBack, input: { context } }) => {
1073
1029
  .catch((error) => {
1074
1030
  logger$a('[client/actors] [addModelsToDb] Error:', error);
1075
1031
  // In test environments, still send success to allow initialization to complete
1076
- if (process.env.NODE_ENV === 'test' || process.env.IS_SEED_DEV) {
1032
+ if (isTestOrSeedDev()) {
1077
1033
  logger$a('[client/actors] [addModelsToDb] Continuing despite error in test environment');
1078
1034
  sendBack({ type: ClientManagerEvents.ADD_MODELS_TO_DB_SUCCESS });
1079
1035
  }
@@ -1238,7 +1194,7 @@ const saveConfig = fromCallback(({ sendBack, input: { context } }) => {
1238
1194
  const appDb = BaseDb.getAppDb();
1239
1195
  if (!appDb) {
1240
1196
  // In test environments, continue anyway
1241
- if (process.env.NODE_ENV === 'test' || process.env.IS_SEED_DEV) {
1197
+ if (isTestOrSeedDev()) {
1242
1198
  logger$8('[internal/actors] [saveConfig] App DB not found, but continuing in test environment');
1243
1199
  return;
1244
1200
  }
@@ -1296,7 +1252,7 @@ const saveConfig = fromCallback(({ sendBack, input: { context } }) => {
1296
1252
  catch (error) {
1297
1253
  logger$8('[internal/actors] [saveConfig] Error saving config:', error);
1298
1254
  // In test environments, continue anyway
1299
- if (process.env.NODE_ENV === 'test' || process.env.IS_SEED_DEV) {
1255
+ if (isTestOrSeedDev()) {
1300
1256
  logger$8('[internal/actors] [saveConfig] Continuing despite error in test environment');
1301
1257
  return;
1302
1258
  }
@@ -1312,7 +1268,7 @@ const saveConfig = fromCallback(({ sendBack, input: { context } }) => {
1312
1268
  .catch((error) => {
1313
1269
  logger$8('[internal/actors] [saveConfig] Error in saveConfig promise chain:', error);
1314
1270
  // In test environments, still send success to allow state machine to progress
1315
- if (process.env.NODE_ENV === 'test' || process.env.IS_SEED_DEV) {
1271
+ if (isTestOrSeedDev()) {
1316
1272
  logger$8('[internal/actors] [saveConfig] Sending success despite error in test environment');
1317
1273
  sendBack({ type: ClientManagerEvents.SAVE_CONFIG_SUCCESS });
1318
1274
  }
@@ -2023,9 +1979,9 @@ function getRefValueType(prop) {
2023
1979
  * @returns Promise that resolves when properties are found, or rejects if not found after max retries
2024
1980
  */
2025
1981
  const verifyPropertiesPersisted = async (db, modelId, modelName, maxRetries = 10, retryDelay = 100) => {
2026
- const _mod_0 = await import('./BasePathResolver-CBTXCMFL.js');
2027
- const _ns_0 = _mod_0.bb;
2028
- const modelSchemaMod = _ns_0;
1982
+ const _mod_1 = await import('./index-CrvIcVFJ.js');
1983
+ const _ns_1 = _mod_1.bd;
1984
+ const modelSchemaMod = _ns_1;
2029
1985
  const { properties: propertiesTable } = modelSchemaMod;
2030
1986
  const drizzleMod = await import('drizzle-orm');
2031
1987
  const { eq } = drizzleMod;
@@ -2246,17 +2202,11 @@ const transformImportToSchemaFile = (importData, version = 1) => {
2246
2202
  const parseJsonImportContent = (content) => {
2247
2203
  try {
2248
2204
  const data = JSON.parse(content);
2249
- // Determine the format and extract name
2250
- let schemaName;
2251
- // Check if it's a complete schema format (has $schema field)
2252
- if (data.$schema) {
2253
- // Complete schema format: name is in metadata.name
2254
- schemaName = data.metadata?.name;
2255
- }
2256
- else {
2257
- // Minimal format: name is at top level
2258
- schemaName = data.name;
2259
- }
2205
+ // Complete schema format keeps the name in metadata.name, minimal format at the top level.
2206
+ // A schema file without $schema (SchemaFileInput) still has metadata.name.
2207
+ const schemaName = data.$schema
2208
+ ? data.metadata?.name
2209
+ : (data.name ?? data.metadata?.name);
2260
2210
  if (!schemaName) {
2261
2211
  throw new Error('Schema name is required (either at top level or in metadata.name)');
2262
2212
  }
@@ -2334,6 +2284,21 @@ const getSchemaFilePath = (workingDir, name, version, schemaFileId) => {
2334
2284
  const filename = `${schemaFileId}_${sanitizedName}_v${version}.json`;
2335
2285
  return path.join(workingDir, filename);
2336
2286
  };
2287
+ /** The complete schema stored at filePath, or undefined when it can't be read or isn't complete. */
2288
+ const readCompleteSchemaFile = async (filePath) => {
2289
+ try {
2290
+ const schema = JSON.parse(await BaseFileManager.readFileAsString(filePath));
2291
+ if (!schema.$schema)
2292
+ return undefined;
2293
+ if (schema.models)
2294
+ schema.models = normalizeSchemaModels(schema.models);
2295
+ return schema;
2296
+ }
2297
+ catch (error) {
2298
+ logger$6(`Could not read schema file ${filePath}:`, error);
2299
+ return undefined;
2300
+ }
2301
+ };
2337
2302
  /**
2338
2303
  * Import a JSON schema file and save it in the full schema file format
2339
2304
  * Also converts the JSON models to Model classes and adds them to the database
@@ -2375,6 +2340,9 @@ function warnOnEasNameCollisions(schemaFile) {
2375
2340
  return warnings;
2376
2341
  }
2377
2342
  async function importJsonSchema(importFilePathOrContents, version = 1) {
2343
+ return importSchema(importFilePathOrContents, version, { replaceStoredFile: false });
2344
+ }
2345
+ async function importSchema(importFilePathOrContents, version, options) {
2378
2346
  // Determine if we have a file path or file contents
2379
2347
  let importData;
2380
2348
  let importFilePath;
@@ -2403,6 +2371,7 @@ async function importJsonSchema(importFilePathOrContents, version = 1) {
2403
2371
  }
2404
2372
  // Use original schema file if available, otherwise transform from import format
2405
2373
  let schemaFile;
2374
+ let replacingStoredFile = false;
2406
2375
  if (originalSchemaFile) {
2407
2376
  schemaFile = originalSchemaFile;
2408
2377
  // Normalize models if provided as array (some tools output array format)
@@ -2416,9 +2385,9 @@ async function importJsonSchema(importFilePathOrContents, version = 1) {
2416
2385
  // Check DB for existing schema by name+version (same as minimal path)
2417
2386
  const db = BaseDb.getAppDb();
2418
2387
  if (db) {
2419
- const _mod_1 = await import('./BasePathResolver-CBTXCMFL.js');
2420
- const _ns_1 = _mod_1.bd;
2421
- const schemaSchemaMod = _ns_1;
2388
+ const _mod_2 = await import('./index-CrvIcVFJ.js');
2389
+ const _ns_2 = _mod_2.bf;
2390
+ const schemaSchemaMod = _ns_2;
2422
2391
  const { schemas: schemasTable } = schemaSchemaMod;
2423
2392
  const drizzleMod = await import('drizzle-orm');
2424
2393
  const { eq, and, desc } = drizzleMod;
@@ -2465,16 +2434,23 @@ async function importJsonSchema(importFilePathOrContents, version = 1) {
2465
2434
  schemaFile.id = await getDeterministicSchemaFileId(schemaFile);
2466
2435
  logger$6(`Generated deterministic schema ID for ${schemaFile.metadata.name}:`, schemaFile.id);
2467
2436
  }
2468
- // Before generating IDs, check if a file already exists with this schemaFileId
2469
- // This handles the case where the schema was already loaded via loadSchemaFromFile
2437
+ // A file with this schemaFileId and version is reused only when its content matches. A pinned id
2438
+ // (one the schema file sets) keeps the same path when the content changes.
2470
2439
  const workingDir = BaseFileManager.getWorkingDir();
2471
- BaseFileManager.getPathModule();
2472
2440
  const existingFilePath = getSchemaFilePath(workingDir, schemaFile.metadata.name, schemaFile.version, schemaFile.id);
2473
- const existingFileExists = await BaseFileManager.pathExists(existingFilePath);
2474
- if (existingFileExists) {
2475
- // File already exists with this schemaFileId - just load it instead of creating a new one
2476
- logger$6(`Schema file already exists with schemaFileId ${schemaFile.id}, loading it instead of creating new file`);
2477
- return await loadSchemaFromFile(existingFilePath);
2441
+ if (await BaseFileManager.pathExists(existingFilePath)) {
2442
+ const storedSchema = await readCompleteSchemaFile(existingFilePath);
2443
+ if (storedSchema && compareSchemaContent(schemaFile, storedSchema)) {
2444
+ logger$6(`Schema file already exists with schemaFileId ${schemaFile.id} and the same content, loading it`);
2445
+ return await loadSchemaFromFile(existingFilePath);
2446
+ }
2447
+ if (!options.replaceStoredFile) {
2448
+ throw new Error(`Schema ${schemaFile.metadata.name} v${schemaFile.version} already exists with different content ` +
2449
+ `(schema id ${schemaFile.id}). Bump the schema's version, or delete the existing file first.`);
2450
+ }
2451
+ console.warn(`[seed] schema ${schemaFile.metadata.name} v${schemaFile.version}: content changed but id ` +
2452
+ `${schemaFile.id} and version did not; replacing the stored schema file. Bump "version" when the schema changes.`);
2453
+ replacingStoredFile = true;
2478
2454
  }
2479
2455
  // Generate missing model and property IDs.
2480
2456
  // Use deterministic IDs (from schema content hash) so addModelsToDb finds existing
@@ -2501,9 +2477,9 @@ async function importJsonSchema(importFilePathOrContents, version = 1) {
2501
2477
  // For minimal imports: check DB for existing schema before creating new file
2502
2478
  const db = BaseDb.getAppDb();
2503
2479
  if (db) {
2504
- const _mod_2 = await import('./BasePathResolver-CBTXCMFL.js');
2505
- const _ns_2 = _mod_2.bd;
2506
- const schemaSchemaMod = _ns_2;
2480
+ const _mod_3 = await import('./index-CrvIcVFJ.js');
2481
+ const _ns_3 = _mod_3.bf;
2482
+ const schemaSchemaMod = _ns_3;
2507
2483
  const { schemas: schemasTable } = schemaSchemaMod;
2508
2484
  const drizzleMod = await import('drizzle-orm');
2509
2485
  const { eq, and, desc } = drizzleMod;
@@ -2670,8 +2646,10 @@ async function importJsonSchema(importFilePathOrContents, version = 1) {
2670
2646
  propertyFileIds.set(modelName, propIds);
2671
2647
  }
2672
2648
  }
2673
- // Convert JSON models to Model classes, passing modelFileIds and propertyFileIds so Model instances use correct IDs
2674
- const modelDefinitions = await createModelsFromJson(importDataForInternal, modelFileIds, propertyFileIds);
2649
+ // Convert JSON models to Model classes, passing modelFileIds and propertyFileIds so Model instances use correct IDs.
2650
+ // addModelsToDb below writes their rows; the models adopt them once it has run.
2651
+ const rowsWritten = createRowsWrittenSignal();
2652
+ const modelDefinitions = await createModelsFromJson(importDataForInternal, modelFileIds, propertyFileIds, rowsWritten.promise);
2675
2653
  logger$6('loadSchemaFromFile (internal) - modelDefinitions length:', Object.keys(modelDefinitions).length);
2676
2654
  // Convert schema file metadata to schema input for database
2677
2655
  const schemaInput = {
@@ -2682,9 +2660,9 @@ async function importJsonSchema(importFilePathOrContents, version = 1) {
2682
2660
  updatedAt: new Date(schemaFile.metadata.updatedAt).getTime(),
2683
2661
  };
2684
2662
  // Use dynamic import to break circular dependency
2685
- const _mod_3 = await import('./BasePathResolver-CBTXCMFL.js');
2686
- const _ns_3 = _mod_3.bg;
2687
- const dbMod = _ns_3;
2663
+ const _mod_4 = await import('./index-CrvIcVFJ.js');
2664
+ const _ns_4 = _mod_4.bi;
2665
+ const dbMod = _ns_4;
2688
2666
  const { addSchemaToDb, addModelsToDb } = dbMod;
2689
2667
  // Try to add schema and models to database if database is available
2690
2668
  try {
@@ -2704,13 +2682,13 @@ async function importJsonSchema(importFilePathOrContents, version = 1) {
2704
2682
  });
2705
2683
  // Verify expected models are linked (single attempt - addModelsToDb already confirmed)
2706
2684
  const expectedModelNames = Object.keys(schemaFile.models || {});
2707
- const _mod_4 = await import('./BasePathResolver-CBTXCMFL.js');
2708
- const _ns_4 = _mod_4.be;
2709
- const modelSchemaSchemaMod = _ns_4;
2685
+ const _mod_5 = await import('./index-CrvIcVFJ.js');
2686
+ const _ns_5 = _mod_5.bg;
2687
+ const modelSchemaSchemaMod = _ns_5;
2710
2688
  const { modelSchemas } = modelSchemaSchemaMod;
2711
- const _mod_5 = await import('./BasePathResolver-CBTXCMFL.js');
2712
- const _ns_5 = _mod_5.bb;
2713
- const modelSchemaMod = _ns_5;
2689
+ const _mod_6 = await import('./index-CrvIcVFJ.js');
2690
+ const _ns_6 = _mod_6.bd;
2691
+ const modelSchemaMod = _ns_6;
2714
2692
  const { models: modelsTable } = modelSchemaMod;
2715
2693
  const drizzleMod = await import('drizzle-orm');
2716
2694
  const { eq, and, isNull } = drizzleMod;
@@ -2800,6 +2778,9 @@ async function importJsonSchema(importFilePathOrContents, version = 1) {
2800
2778
  // Database not available - log warning but continue
2801
2779
  logger$6('Database not available, skipping database operations:', dbError instanceof Error ? dbError.message : String(dbError));
2802
2780
  }
2781
+ finally {
2782
+ rowsWritten.settle();
2783
+ }
2803
2784
  // Models are now Model instances, no registration needed
2804
2785
  // They should be created via Model.create() and are accessible via Model static methods
2805
2786
  for (const [modelName] of Object.entries(modelDefinitions)) {
@@ -2819,7 +2800,7 @@ async function importJsonSchema(importFilePathOrContents, version = 1) {
2819
2800
  // Get the target file path using ID-based naming (preferred)
2820
2801
  const filePath = getSchemaFilePath(workingDir, schemaFile.metadata.name, version, schemaFile.id);
2821
2802
  // Check if schema already exists
2822
- const exists = await BaseFileManager.pathExists(filePath);
2803
+ const exists = !replacingStoredFile && (await BaseFileManager.pathExists(filePath));
2823
2804
  if (exists) {
2824
2805
  // If we have a file path and the import file is the same as the target file,
2825
2806
  // and it's already a complete schema, just load it without writing
@@ -2907,15 +2888,16 @@ async function applySchemaToDb(schemaFile, modelDefinitions, modelFileIds, prope
2907
2888
  createdAt: new Date(schemaFile.metadata.createdAt).getTime(),
2908
2889
  updatedAt: new Date(schemaFile.metadata.updatedAt).getTime(),
2909
2890
  };
2910
- const _mod_6 = await import('./BasePathResolver-CBTXCMFL.js');
2911
- const _ns_6 = _mod_6.bg;
2912
- const dbMod = _ns_6;
2891
+ const _mod_7 = await import('./index-CrvIcVFJ.js');
2892
+ const _ns_7 = _mod_7.bi;
2893
+ const dbMod = _ns_7;
2913
2894
  const { addSchemaToDb, addModelsToDb } = dbMod;
2914
2895
  const db = BaseDb.getAppDb();
2915
2896
  if (!db) {
2916
2897
  throw new Error('Database not found');
2917
2898
  }
2918
2899
  warnOnInvalidNameMatch(schemaFile);
2900
+ const droppedModelNames = await getModelsDroppedFromStoredSchema(db, schemaFile);
2919
2901
  const schemaData = JSON.stringify(schemaFile, null, 2);
2920
2902
  const schemaRecord = await addSchemaToDb(schemaInput, schemaFile.id, schemaData, false);
2921
2903
  if (Object.keys(modelDefinitions).length > 0) {
@@ -2927,11 +2909,66 @@ async function applySchemaToDb(schemaFile, modelDefinitions, modelFileIds, prope
2927
2909
  });
2928
2910
  await new Promise(resolve => setTimeout(resolve, 200));
2929
2911
  }
2912
+ if (droppedModelNames.length > 0 && schemaRecord.id) {
2913
+ await unlinkModelsFromSchema(db, schemaRecord.id, droppedModelNames);
2914
+ }
2930
2915
  return { schemaRecord };
2931
2916
  }
2917
+ /**
2918
+ * Names of the models the stored published schema of this name has and schemaFile drops. A model
2919
+ * whose id is still in schemaFile was renamed, not dropped. Returns none when the stored row is a
2920
+ * draft (its edits aren't the app's to undo) or a newer version than schemaFile.
2921
+ */
2922
+ async function getModelsDroppedFromStoredSchema(db, schemaFile) {
2923
+ const _mod_8 = await import('./index-CrvIcVFJ.js');
2924
+ const _ns_8 = _mod_8.bf;
2925
+ const { schemas: schemasTable } = _ns_8;
2926
+ const { eq } = await import('drizzle-orm');
2927
+ const rows = await db
2928
+ .select({ version: schemasTable.version, isDraft: schemasTable.isDraft, schemaData: schemasTable.schemaData })
2929
+ .from(schemasTable)
2930
+ .where(eq(schemasTable.name, schemaFile.metadata.name));
2931
+ if (rows.length === 0 || rows.some((row) => row.isDraft))
2932
+ return [];
2933
+ const stored = rows.reduce((a, b) => (b.version > a.version ? b : a));
2934
+ if (!stored.schemaData || stored.version > schemaFile.version)
2935
+ return [];
2936
+ let storedModels;
2937
+ try {
2938
+ storedModels = normalizeSchemaModels(JSON.parse(stored.schemaData).models ?? {});
2939
+ }
2940
+ catch {
2941
+ return [];
2942
+ }
2943
+ const models = schemaFile.models ?? {};
2944
+ const modelIds = new Set(Object.values(models).map((model) => model.id).filter(Boolean));
2945
+ return Object.entries(storedModels)
2946
+ .filter(([name, model]) => !(name in models) && !(model.id && modelIds.has(model.id)))
2947
+ .map(([name]) => name);
2948
+ }
2949
+ /** Delete the model_schemas rows linking the named models to the schema. The models and their items stay. */
2950
+ async function unlinkModelsFromSchema(db, schemaId, modelNames) {
2951
+ const _mod_9 = await import('./index-CrvIcVFJ.js');
2952
+ const _ns_9 = _mod_9.bg;
2953
+ const { modelSchemas } = _ns_9;
2954
+ const _mod_10 = await import('./index-CrvIcVFJ.js');
2955
+ const _ns_10 = _mod_10.bd;
2956
+ const { models: modelsTable } = _ns_10;
2957
+ const { and, eq, inArray } = await import('drizzle-orm');
2958
+ const links = await db
2959
+ .select({ id: modelSchemas.id })
2960
+ .from(modelSchemas)
2961
+ .innerJoin(modelsTable, eq(modelSchemas.modelId, modelsTable.id))
2962
+ .where(and(eq(modelSchemas.schemaId, schemaId), inArray(modelsTable.name, modelNames)));
2963
+ if (links.length === 0)
2964
+ return;
2965
+ await db.delete(modelSchemas).where(inArray(modelSchemas.id, links.map((link) => link.id)));
2966
+ logger$6(`Unlinked models dropped from the schema (schema id ${schemaId}): ${modelNames.join(', ')}`);
2967
+ }
2932
2968
  /**
2933
2969
  * Sync a canonical schema from a file path or inlined object to the database.
2934
- * Uses add/update semantics: no "already exists with different content" errors, no ID-based file copy.
2970
+ * A stored schema file with the same id and version but different content is overwritten (with a
2971
+ * warning) instead of reused, and models dropped from the schema are unlinked from it.
2935
2972
  * Called automatically at init when config.schema is provided.
2936
2973
  *
2937
2974
  * @param source - File path (string) or complete SchemaFileFormat object
@@ -2947,11 +2984,11 @@ async function syncSchemaFromSource(source) {
2947
2984
  const content = await BaseFileManager.readFileAsString(resolvedPath);
2948
2985
  const parsed = JSON.parse(content);
2949
2986
  const version = parsed?.version ?? 1;
2950
- await importJsonSchema({ contents: content }, version);
2987
+ await importSchema({ contents: content }, version, { replaceStoredFile: true });
2951
2988
  }
2952
2989
  else {
2953
2990
  const version = source.version ?? 1;
2954
- await importJsonSchema({ contents: JSON.stringify(source) }, version);
2991
+ await importSchema({ contents: JSON.stringify(source) }, version, { replaceStoredFile: true });
2955
2992
  }
2956
2993
  }
2957
2994
  /**
@@ -3060,8 +3097,10 @@ const loadSchemaFromFile = async (schemaFilePath) => {
3060
3097
  propertyFileIds.set(modelName, propIds);
3061
3098
  }
3062
3099
  }
3063
- // Convert JSON models to Model classes, passing modelFileIds and propertyFileIds so Model instances use correct IDs
3064
- const modelDefinitions = await createModelsFromJson(importData, modelFileIds, propertyFileIds);
3100
+ // Convert JSON models to Model classes, passing modelFileIds and propertyFileIds so Model instances use correct IDs.
3101
+ // applySchemaToDb below writes their rows; the models adopt them once it has run.
3102
+ const rowsWritten = createRowsWrittenSignal();
3103
+ const modelDefinitions = await createModelsFromJson(importData, modelFileIds, propertyFileIds, rowsWritten.promise);
3065
3104
  logger$6('loadSchemaFromFile - modelDefinitions length:', Object.keys(modelDefinitions).length);
3066
3105
  // Try to add schema and models to database if database is available
3067
3106
  try {
@@ -3074,15 +3113,15 @@ const loadSchemaFromFile = async (schemaFilePath) => {
3074
3113
  modelName,
3075
3114
  jsonPropertiesToSchemaProperties(modelName, modelDef, propertyFileIds.get(modelName)),
3076
3115
  ]));
3077
- const { schemaRecord } = await applySchemaToDb(schemaFile, modelDefinitions, modelFileIds, propertyFileIds, propertyDefinitions);
3116
+ const { schemaRecord } = await applySchemaToDb(schemaFile, modelDefinitions, modelFileIds, propertyFileIds, propertyDefinitions).finally(rowsWritten.settle);
3078
3117
  // Query the database to get model IDs that were just created
3079
- const _mod_7 = await import('./BasePathResolver-CBTXCMFL.js');
3080
- const _ns_7 = _mod_7.be;
3081
- const modelSchemaSchemaMod = _ns_7;
3118
+ const _mod_11 = await import('./index-CrvIcVFJ.js');
3119
+ const _ns_11 = _mod_11.bg;
3120
+ const modelSchemaSchemaMod = _ns_11;
3082
3121
  const { modelSchemas } = modelSchemaSchemaMod;
3083
- const _mod_8 = await import('./BasePathResolver-CBTXCMFL.js');
3084
- const _ns_8 = _mod_8.bb;
3085
- const modelSchemaMod = _ns_8;
3122
+ const _mod_12 = await import('./index-CrvIcVFJ.js');
3123
+ const _ns_12 = _mod_12.bd;
3124
+ const modelSchemaMod = _ns_12;
3086
3125
  const { models: modelsTable } = modelSchemaMod;
3087
3126
  const drizzleMod = await import('drizzle-orm');
3088
3127
  const { eq } = drizzleMod;
@@ -3146,9 +3185,9 @@ const loadSchemaFromFile = async (schemaFilePath) => {
3146
3185
  // After properties are created (file path), ensure schemaFile has the correct IDs from database
3147
3186
  // Query the database to get the actual schemaFileId values that were used
3148
3187
  // This ensures schemaData matches what's actually in the database
3149
- const _mod_9 = await import('./BasePathResolver-CBTXCMFL.js');
3150
- const _ns_9 = _mod_9.bb;
3151
- const modelSchemaMod2 = _ns_9;
3188
+ const _mod_13 = await import('./index-CrvIcVFJ.js');
3189
+ const _ns_13 = _mod_13.bd;
3190
+ const modelSchemaMod2 = _ns_13;
3152
3191
  const { properties: propertiesTable } = modelSchemaMod2;
3153
3192
  let schemaFileUpdated = false;
3154
3193
  for (const [modelName, modelFileId] of modelFileIds.entries()) {
@@ -3182,9 +3221,9 @@ const loadSchemaFromFile = async (schemaFilePath) => {
3182
3221
  // This is important even if nothing changed, to ensure consistency
3183
3222
  const updatedSchemaData = JSON.stringify(schemaFile, null, 2);
3184
3223
  // Update the schema record in the database with current schemaData
3185
- const _mod_10 = await import('./BasePathResolver-CBTXCMFL.js');
3186
- const _ns_10 = _mod_10.bd;
3187
- const schemaSchemaMod = _ns_10;
3224
+ const _mod_14 = await import('./index-CrvIcVFJ.js');
3225
+ const _ns_14 = _mod_14.bf;
3226
+ const schemaSchemaMod = _ns_14;
3188
3227
  const { schemas: schemasTable } = schemaSchemaMod;
3189
3228
  await db
3190
3229
  .update(schemasTable)
@@ -3203,6 +3242,9 @@ const loadSchemaFromFile = async (schemaFilePath) => {
3203
3242
  // Database not available - log warning but continue
3204
3243
  logger$6('Database not available, skipping database operations:', dbError instanceof Error ? dbError.message : String(dbError));
3205
3244
  }
3245
+ finally {
3246
+ rowsWritten.settle();
3247
+ }
3206
3248
  // Models are now Model instances, no registration needed
3207
3249
  // They should be created via Model.create() and are accessible via Model static methods
3208
3250
  for (const [modelName] of Object.entries(modelDefinitions)) {
@@ -3284,6 +3326,18 @@ const jsonPropertiesToSchemaProperties = (modelName, modelDef, propertyFileIds)
3284
3326
  }
3285
3327
  return convertedProperties;
3286
3328
  };
3329
+ /**
3330
+ * For callers of createModelsFromJson that write the models with addModelsToDb: pass `promise` as its
3331
+ * persistedBy and call `settle` once addModelsToDb has run or failed (in a finally). The new models wait
3332
+ * for it, then adopt the rows addModelsToDb wrote; any model it didn't write writes itself.
3333
+ */
3334
+ const createRowsWrittenSignal = () => {
3335
+ let settle;
3336
+ const promise = new Promise((resolve) => {
3337
+ settle = resolve;
3338
+ });
3339
+ return { promise, settle };
3340
+ };
3287
3341
  /**
3288
3342
  * Create a Model class from a JSON model definition
3289
3343
  * @param modelName - The name of the model
@@ -3292,10 +3346,11 @@ const jsonPropertiesToSchemaProperties = (modelName, modelDef, propertyFileIds)
3292
3346
  * @returns A Model class that can be used with the SDK
3293
3347
  */
3294
3348
  const createModelFromJson = async (modelName, modelDef, schemaName, modelFileId, // Optional modelFileId from JSON file
3295
- propertyFileIds) => {
3296
- const _mod_11 = await import('./errors-CIrbsN_i.js');
3297
- const _ns_11 = _mod_11.h;
3298
- const modelMod = _ns_11;
3349
+ propertyFileIds, // Optional map of property names to their file IDs from the JSON file
3350
+ persistedBy) => {
3351
+ const _mod_15 = await import('./errors-3tc6XkCB.js');
3352
+ const _ns_15 = _mod_15.h;
3353
+ const modelMod = _ns_15;
3299
3354
  const { Model } = modelMod;
3300
3355
  const convertedProperties = jsonPropertiesToSchemaProperties(modelName, modelDef, propertyFileIds);
3301
3356
  // Create Model instance with the definition
@@ -3312,6 +3367,7 @@ propertyFileIds) => {
3312
3367
  id: modelFileId, // Also pass as id for backward compatibility
3313
3368
  properties: convertedProperties,
3314
3369
  waitForReady: false,
3370
+ persistedBy,
3315
3371
  });
3316
3372
  return modelInstance;
3317
3373
  };
@@ -3320,9 +3376,11 @@ propertyFileIds) => {
3320
3376
  * @param importData - The JSON import data
3321
3377
  * @param modelFileIds - Optional map of model names to their file IDs from the JSON file
3322
3378
  * @param propertyFileIds - Optional map of model names to maps of property names to their file IDs from the JSON file
3379
+ * @param persistedBy - When the caller writes the models with addModelsToDb: a promise that settles once
3380
+ * that has run (see createRowsWrittenSignal). New models then adopt those rows instead of writing them too.
3323
3381
  * @returns ModelDefinitions object with Model classes
3324
3382
  */
3325
- const createModelsFromJson = async (importData, modelFileIds, propertyFileIds) => {
3383
+ const createModelsFromJson = async (importData, modelFileIds, propertyFileIds, persistedBy) => {
3326
3384
  const modelDefinitions = {};
3327
3385
  const schemaName = importData.name;
3328
3386
  for (const [modelName, modelDef] of Object.entries(importData.models)) {
@@ -3335,7 +3393,7 @@ const createModelsFromJson = async (importData, modelFileIds, propertyFileIds) =
3335
3393
  }
3336
3394
  // Get propertyFileIds for this model if available
3337
3395
  const modelPropertyFileIds = propertyFileIds?.get(modelName);
3338
- const ModelClass = await createModelFromJson(modelName, modelDef, schemaName, finalModelFileId, modelPropertyFileIds);
3396
+ const ModelClass = await createModelFromJson(modelName, modelDef, schemaName, finalModelFileId, modelPropertyFileIds, persistedBy);
3339
3397
  modelDefinitions[modelName] = ModelClass;
3340
3398
  }
3341
3399
  return modelDefinitions;
@@ -5650,5 +5708,5 @@ var ClientManager$1 = /*#__PURE__*/Object.freeze({
5650
5708
  getClient: getClient
5651
5709
  });
5652
5710
 
5653
- export { requestEasSyncFromEventBus as A, requestEasSyncFromModelsInit as B, ClientManager as C, sendEasSyncClientRequest as D, EAS_CHAIN_ID_APP_STATE_KEY as E, setRetriesWhenOnlineEnabled as F, startEasSyncActor as G, unregisterSeedQueryLocalSource as H, INIT_CONFIG_CONFLICT_MESSAGE as I, createModelsFromJson as J, getLatestSchemaVersion as K, jsonPropertiesToSchemaProperties as L, schema as M, ClientManager$1 as N, SEEDPROTOCOL_Seed_Protocol_v1 as S, getContentHash as a, isVerbatimItemStorageDraftRow as b, convertVerbatimItemStorageRow as c, assertLocalDbChain as d, claimUnpublishedDrafts as e, createLocalQueryDataSource as f, getRefValueType as g, hardDeleteLocalSeedsByLocalIds as h, importJsonSchema as i, createSchema as j, easSyncActor as k, loadSchemaFromFile as l, getClient as m, getPublishedSeedRecord as n, getSchemaNameFromId as o, isSeedQueryLocalSourceRegistered as p, listCompleteSchemaFiles as q, readJsonImportFile as r, syncSchemaFromSource as s, transformImportToSchemaFile as t, loadAllSchemasFromDb as u, mergeEasSyncRequestIntents as v, waitForEasReadChain as w, readSchema as x, registerSeedQueryLocalSource as y, requestEasSyncFromAddressChange as z };
5654
- //# sourceMappingURL=ClientManager-DRf4uuei.js.map
5711
+ export { requestEasSyncFromEventBus as A, requestEasSyncFromModelsInit as B, ClientManager as C, sendEasSyncClientRequest as D, EAS_CHAIN_ID_APP_STATE_KEY as E, setRetriesWhenOnlineEnabled as F, startEasSyncActor as G, unregisterSeedQueryLocalSource as H, INIT_CONFIG_CONFLICT_MESSAGE as I, createRowsWrittenSignal as J, createModelsFromJson as K, getLatestSchemaVersion as L, jsonPropertiesToSchemaProperties as M, schema as N, ClientManager$1 as O, SEEDPROTOCOL_Seed_Protocol_v1 as S, getContentHash as a, isVerbatimItemStorageDraftRow as b, convertVerbatimItemStorageRow as c, assertLocalDbChain as d, claimUnpublishedDrafts as e, createLocalQueryDataSource as f, getRefValueType as g, hardDeleteLocalSeedsByLocalIds as h, importJsonSchema as i, createSchema as j, easSyncActor as k, loadSchemaFromFile as l, getClient as m, getPublishedSeedRecord as n, getSchemaNameFromId as o, isSeedQueryLocalSourceRegistered as p, listCompleteSchemaFiles as q, readJsonImportFile as r, syncSchemaFromSource as s, transformImportToSchemaFile as t, loadAllSchemasFromDb as u, mergeEasSyncRequestIntents as v, waitForEasReadChain as w, readSchema as x, registerSeedQueryLocalSource as y, requestEasSyncFromAddressChange as z };
5712
+ //# sourceMappingURL=ClientManager-D6YA20jP.js.map