@seedprotocol/sdk 0.5.2 → 0.6.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 (127) hide show
  1. package/dist/{BasePathResolver-BDgc7c4T.js → BasePathResolver-DWY_hb8w.js} +2 -2
  2. package/dist/{BasePathResolver-BDgc7c4T.js.map → BasePathResolver-DWY_hb8w.js.map} +1 -1
  3. package/dist/{ModelProperty-BBXBvgvy.js → ModelProperty-DGJf78CS.js} +21 -21
  4. package/dist/{ModelProperty-BBXBvgvy.js.map → ModelProperty-DGJf78CS.js.map} +1 -1
  5. package/dist/{Schema-xAt7jWlW.js → Schema-Drmce3q-.js} +39 -39
  6. package/dist/{Schema-xAt7jWlW.js.map → Schema-Drmce3q-.js.map} +1 -1
  7. package/dist/{SchemaValidationService-CLzAdBm-.js → SchemaValidationService-a_sfnpDV.js} +5 -5
  8. package/dist/{SchemaValidationService-CLzAdBm-.js.map → SchemaValidationService-a_sfnpDV.js.map} +1 -1
  9. package/dist/{backfillMetadataPropertyIds-DBVaIs7O.js → backfillMetadataPropertyIds-CZcOi-cK.js} +3 -3
  10. package/dist/{backfillMetadataPropertyIds-DBVaIs7O.js.map → backfillMetadataPropertyIds-CZcOi-cK.js.map} +1 -1
  11. package/dist/cjs/{ModelProperty-Dgd4tGrB.js → ModelProperty-BA26rMV8.js} +17 -17
  12. package/dist/cjs/{ModelProperty-Dgd4tGrB.js.map → ModelProperty-BA26rMV8.js.map} +1 -1
  13. package/dist/cjs/{Schema-dkd-eo3B.js → Schema-Hgwq3L34.js} +20 -20
  14. package/dist/cjs/{Schema-dkd-eo3B.js.map → Schema-Hgwq3L34.js.map} +1 -1
  15. package/dist/cjs/{SchemaValidationService-BMnjcVWV.js → SchemaValidationService-DVmOGZao.js} +2 -2
  16. package/dist/cjs/{SchemaValidationService-BMnjcVWV.js.map → SchemaValidationService-DVmOGZao.js.map} +1 -1
  17. package/dist/cjs/{backfillMetadataPropertyIds-ClLuj3s6.js → backfillMetadataPropertyIds-BWJI4eCj.js} +2 -2
  18. package/dist/cjs/{backfillMetadataPropertyIds-ClLuj3s6.js.map → backfillMetadataPropertyIds-BWJI4eCj.js.map} +1 -1
  19. package/dist/cjs/{eas-nWAzbl_F.js → eas-BJ8FtbU9.js} +3 -3
  20. package/dist/cjs/{eas-nWAzbl_F.js.map → eas-BJ8FtbU9.js.map} +1 -1
  21. package/dist/cjs/{getItem-B08FgglK.js → getItem-DdBKeEEU.js} +2 -2
  22. package/dist/cjs/{getItem-B08FgglK.js.map → getItem-DdBKeEEU.js.map} +1 -1
  23. package/dist/cjs/{getPublishPayload-B_G_6qkE.js → getPublishPayload-DSBLjMKl.js} +11 -11
  24. package/dist/cjs/{getPublishPayload-B_G_6qkE.js.map → getPublishPayload-DSBLjMKl.js.map} +1 -1
  25. package/dist/cjs/{getPublishUploads-Dt-DS-lo.js → getPublishUploads-DMKnK2_R.js} +4 -4
  26. package/dist/cjs/{getPublishUploads-Dt-DS-lo.js.map → getPublishUploads-DMKnK2_R.js.map} +1 -1
  27. package/dist/cjs/{getSegmentedItemProperties-BDGbeDW7.js → getSegmentedItemProperties-D0ZzTmvi.js} +3 -3
  28. package/dist/cjs/{getSegmentedItemProperties-BDGbeDW7.js.map → getSegmentedItemProperties-D0ZzTmvi.js.map} +1 -1
  29. package/dist/cjs/{index-CRBI6dSD.js → index-BD1b6zAi.js} +498 -40
  30. package/dist/cjs/index-BD1b6zAi.js.map +1 -0
  31. package/dist/cjs/{index-Dx19j60c.js → index-DQggpLqI.js} +3 -3
  32. package/dist/cjs/index-DQggpLqI.js.map +1 -0
  33. package/dist/cjs/index.browser-BSf8HpnU.js.map +1 -1
  34. package/dist/cjs/{property-628qAHpN.js → property-D4IB0zBz.js} +4 -4
  35. package/dist/cjs/{property-628qAHpN.js.map → property-D4IB0zBz.js.map} +1 -1
  36. package/dist/cjs/{syncDbWithEas-DOBtMPw-.js → syncDbWithEas-BYvFJc7N.js} +6 -6
  37. package/dist/cjs/{syncDbWithEas-DOBtMPw-.js.map → syncDbWithEas-BYvFJc7N.js.map} +1 -1
  38. package/dist/{configurePlatform-Ce6NIKRP.js → configurePlatform-CXQCT7N8.js} +3 -3
  39. package/dist/{configurePlatform-Ce6NIKRP.js.map → configurePlatform-CXQCT7N8.js.map} +1 -1
  40. package/dist/{constants-slkc9uq0.js → constants-B7aNfB_1.js} +3 -3
  41. package/dist/constants-B7aNfB_1.js.map +1 -0
  42. package/dist/constants-DMHTYMgJ.js.map +1 -1
  43. package/dist/{db-CSmK0c3e.js → db-Bad8QKfZ.js} +18 -18
  44. package/dist/{db-CSmK0c3e.js.map → db-Bad8QKfZ.js.map} +1 -1
  45. package/dist/{eas-rx1grht5.js → eas-BB9hVW68.js} +6 -6
  46. package/dist/{eas-rx1grht5.js.map → eas-BB9hVW68.js.map} +1 -1
  47. package/dist/{getItem-hPBJU5JF.js → getItem-Cina46nb.js} +5 -5
  48. package/dist/{getItem-hPBJU5JF.js.map → getItem-Cina46nb.js.map} +1 -1
  49. package/dist/{getPublishPayload-5ugovGK5.js → getPublishPayload-BEO52UOv.js} +16 -16
  50. package/dist/{getPublishPayload-5ugovGK5.js.map → getPublishPayload-BEO52UOv.js.map} +1 -1
  51. package/dist/{getPublishUploads-CdWeci-s.js → getPublishUploads-CJjfqJi9.js} +7 -7
  52. package/dist/{getPublishUploads-CdWeci-s.js.map → getPublishUploads-CJjfqJi9.js.map} +1 -1
  53. package/dist/{getSegmentedItemProperties-DV2LHElJ.js → getSegmentedItemProperties-CbzFDgFr.js} +5 -5
  54. package/dist/{getSegmentedItemProperties-DV2LHElJ.js.map → getSegmentedItemProperties-CbzFDgFr.js.map} +1 -1
  55. package/dist/{index-ClwdGWfr.js → index-B4In0GEO.js} +428 -64
  56. package/dist/index-B4In0GEO.js.map +1 -0
  57. package/dist/index-DNOCl06b.js +28 -0
  58. package/dist/index-DNOCl06b.js.map +1 -0
  59. package/dist/{index-QMrBK-L3.js → index-DrEkRiuK.js} +2 -2
  60. package/dist/index-DrEkRiuK.js.map +1 -0
  61. package/dist/{index.node-CrXwRoiB.js → index.node-CnP9s4cV.js} +4 -4
  62. package/dist/{index.node-CrXwRoiB.js.map → index.node-CnP9s4cV.js.map} +1 -1
  63. package/dist/main.cjs +1 -1
  64. package/dist/main.js +19 -20
  65. package/dist/main.js.map +1 -1
  66. package/dist/node.js +10 -10
  67. package/dist/node.js.map +1 -1
  68. package/dist/platform.browser.js +4 -4
  69. package/dist/platform.browser.js.map +1 -1
  70. package/dist/platform.node.js +3 -3
  71. package/dist/{property-CKhOxRNt.js → property-DIN1zQ_c.js} +8 -8
  72. package/dist/{property-CKhOxRNt.js.map → property-DIN1zQ_c.js.map} +1 -1
  73. package/dist/src/Item/Item.d.ts +5 -0
  74. package/dist/src/Item/Item.d.ts.map +1 -1
  75. package/dist/src/Item/service/itemMachineSingle.d.ts +2 -2
  76. package/dist/src/Item/service/itemMachineSingle.d.ts.map +1 -1
  77. package/dist/src/ItemProperty/ItemProperty.d.ts +1 -1
  78. package/dist/src/ItemProperty/service/propertyMachine.d.ts +2 -2
  79. package/dist/src/ItemProperty/service/propertyMachine.d.ts.map +1 -1
  80. package/dist/src/Model/service/modelMachine.d.ts +10 -18
  81. package/dist/src/Model/service/modelMachine.d.ts.map +1 -1
  82. package/dist/src/ModelProperty/service/modelPropertyMachine.d.ts +5 -13
  83. package/dist/src/ModelProperty/service/modelPropertyMachine.d.ts.map +1 -1
  84. package/dist/src/Schema/service/addModelsMachine.d.ts +8 -8
  85. package/dist/src/Schema/service/addModelsMachine.d.ts.map +1 -1
  86. package/dist/src/Schema/service/schemaMachine.d.ts +22 -30
  87. package/dist/src/Schema/service/schemaMachine.d.ts.map +1 -1
  88. package/dist/src/client/ClientManager.d.ts +16 -6
  89. package/dist/src/client/ClientManager.d.ts.map +1 -1
  90. package/dist/src/client/clientManagerMachine.d.ts +2 -2
  91. package/dist/src/client/clientManagerMachine.d.ts.map +1 -1
  92. package/dist/src/client/events.d.ts +7 -0
  93. package/dist/src/client/events.d.ts.map +1 -1
  94. package/dist/src/db/write/removeLocalCopiesForAddresses.d.ts +20 -0
  95. package/dist/src/db/write/removeLocalCopiesForAddresses.d.ts.map +1 -0
  96. package/dist/src/events/item/easSyncManager.d.ts +2 -2
  97. package/dist/src/events/item/easSyncManager.d.ts.map +1 -1
  98. package/dist/src/helpers/file/download/index.d.ts +2 -2
  99. package/dist/src/helpers/file/download/index.d.ts.map +1 -1
  100. package/dist/src/helpers/file/fetchAll/index.d.ts +2 -2
  101. package/dist/src/helpers/file/fetchAll/index.d.ts.map +1 -1
  102. package/dist/src/helpers/mediaRef.d.ts +2 -2
  103. package/dist/src/helpers/mediaRef.d.ts.map +1 -1
  104. package/dist/src/helpers/ownership.d.ts +7 -0
  105. package/dist/src/helpers/ownership.d.ts.map +1 -1
  106. package/dist/src/index.d.ts +2 -2
  107. package/dist/src/index.d.ts.map +1 -1
  108. package/dist/src/services/publish/publishMachine.d.ts +1 -1
  109. package/dist/src/services/publish/publishMachine.d.ts.map +1 -1
  110. package/dist/src/services/write/writeProcessMachine.d.ts +2 -6
  111. package/dist/src/services/write/writeProcessMachine.d.ts.map +1 -1
  112. package/dist/{syncDbWithEas-GsaXzTIY.js → syncDbWithEas-ceVUuWSZ.js} +13 -13
  113. package/dist/{syncDbWithEas-GsaXzTIY.js.map → syncDbWithEas-ceVUuWSZ.js.map} +1 -1
  114. package/dist/{updateSeedRevokedAt-Ba0OhDQj.js → updateSeedRevokedAt-CtRjZiyh.js} +2 -2
  115. package/dist/{updateSeedRevokedAt-Ba0OhDQj.js.map → updateSeedRevokedAt-CtRjZiyh.js.map} +1 -1
  116. package/package.json +23 -6
  117. package/dist/cjs/index-CRBI6dSD.js.map +0 -1
  118. package/dist/cjs/index-Dx19j60c.js.map +0 -1
  119. package/dist/cjs/ownership-3Tc1-Yrc.js +0 -105
  120. package/dist/cjs/ownership-3Tc1-Yrc.js.map +0 -1
  121. package/dist/constants-slkc9uq0.js.map +0 -1
  122. package/dist/index-CcH2e0Zr.js +0 -23
  123. package/dist/index-CcH2e0Zr.js.map +0 -1
  124. package/dist/index-ClwdGWfr.js.map +0 -1
  125. package/dist/index-QMrBK-L3.js.map +0 -1
  126. package/dist/ownership-58i0iyD9.js +0 -106
  127. package/dist/ownership-58i0iyD9.js.map +0 -1
@@ -1000,7 +1000,7 @@ const createPropertyInstances = async (propertyFileIds) => {
1000
1000
  return;
1001
1001
  }
1002
1002
  try {
1003
- const mod = await Promise.resolve().then(function () { return require('./ModelProperty-Dgd4tGrB.js'); });
1003
+ const mod = await Promise.resolve().then(function () { return require('./ModelProperty-BA26rMV8.js'); });
1004
1004
  const ModelProperty = mod?.ModelProperty ?? mod?.default;
1005
1005
  if (!ModelProperty) {
1006
1006
  logger$v('createPropertyInstances: ModelProperty not available from dynamic import');
@@ -1184,7 +1184,7 @@ const loadOrCreateModel = xstate.fromCallback(({ sendBack, input: { context } })
1184
1184
  // Step 2: Fallback to Schema context (only if database doesn't have the model)
1185
1185
  // This handles the case where model exists in schema file but not yet in database
1186
1186
  try {
1187
- const schemaMod = await Promise.resolve().then(function () { return require('./Schema-dkd-eo3B.js'); });
1187
+ const schemaMod = await Promise.resolve().then(function () { return require('./Schema-Hgwq3L34.js'); });
1188
1188
  const { Schema } = schemaMod;
1189
1189
  const schema = Schema.create(schemaName, { waitForReady: false });
1190
1190
  const schemaSnapshot = schema.getService().getSnapshot();
@@ -1428,7 +1428,7 @@ const loadOrCreateModel = xstate.fromCallback(({ sendBack, input: { context } })
1428
1428
  }
1429
1429
  // Mark schema as draft when a new model is created so saveNewVersion() can persist it
1430
1430
  try {
1431
- const schemaMod = await Promise.resolve().then(function () { return require('./Schema-dkd-eo3B.js'); });
1431
+ const schemaMod = await Promise.resolve().then(function () { return require('./Schema-Hgwq3L34.js'); });
1432
1432
  const { Schema } = schemaMod;
1433
1433
  const schema = Schema.create(schemaName, { waitForReady: false });
1434
1434
  schema.getService().send({ type: 'markAsDraft', propertyKey: 'schema:models' });
@@ -1472,10 +1472,10 @@ const validateModel = xstate.fromCallback(({ sendBack, input: { context } }) =>
1472
1472
  const _validateModel = async () => {
1473
1473
  try {
1474
1474
  // Use dynamic imports to break circular dependencies
1475
- const validationServiceMod = await Promise.resolve().then(function () { return require('./SchemaValidationService-BMnjcVWV.js'); });
1475
+ const validationServiceMod = await Promise.resolve().then(function () { return require('./SchemaValidationService-DVmOGZao.js'); });
1476
1476
  const { SchemaValidationService } = validationServiceMod;
1477
1477
  const validationService = new SchemaValidationService();
1478
- const schemaMod = await Promise.resolve().then(function () { return require('./Schema-dkd-eo3B.js'); });
1478
+ const schemaMod = await Promise.resolve().then(function () { return require('./Schema-Hgwq3L34.js'); });
1479
1479
  const { Schema } = schemaMod;
1480
1480
  // Validate model structure
1481
1481
  const structureResult = validationService.validateModelStructure(context);
@@ -1585,7 +1585,7 @@ const createModelProperties = xstate.fromCallback(({ sendBack, input }) => {
1585
1585
  return;
1586
1586
  }
1587
1587
  logger$t(`Creating ${Object.keys(propertyDefinitions).length} properties for model "${modelName}" (id: ${_dbId})`);
1588
- const mod = await Promise.resolve().then(function () { return require('./ModelProperty-Dgd4tGrB.js'); });
1588
+ const mod = await Promise.resolve().then(function () { return require('./ModelProperty-BA26rMV8.js'); });
1589
1589
  const ModelProperty = mod?.ModelProperty ?? mod?.default;
1590
1590
  if (!ModelProperty) {
1591
1591
  logger$t('ModelProperty not available from dynamic import');
@@ -1688,7 +1688,7 @@ const validateEntity = xstate.fromPromise(async ({ input }) => {
1688
1688
  const structureMsg = `[validateEntity] Validating model structure`;
1689
1689
  logger$s(structureMsg);
1690
1690
  // Use existing Model validation
1691
- const validationServiceMod = await Promise.resolve().then(function () { return require('./SchemaValidationService-BMnjcVWV.js'); });
1691
+ const validationServiceMod = await Promise.resolve().then(function () { return require('./SchemaValidationService-DVmOGZao.js'); });
1692
1692
  const { SchemaValidationService } = validationServiceMod;
1693
1693
  const validationService = new SchemaValidationService();
1694
1694
  // Validate model structure
@@ -1706,7 +1706,7 @@ const validateEntity = xstate.fromPromise(async ({ input }) => {
1706
1706
  if (entityInput.entityData.schemaName) {
1707
1707
  try {
1708
1708
  logger$s(`[validateEntity] Validating model against schema "${entityInput.entityData.schemaName}"`);
1709
- const schemaMod = await Promise.resolve().then(function () { return require('./Schema-dkd-eo3B.js'); });
1709
+ const schemaMod = await Promise.resolve().then(function () { return require('./Schema-Hgwq3L34.js'); });
1710
1710
  const { Schema } = schemaMod;
1711
1711
  const schema = Schema.create(entityInput.entityData.schemaName, {
1712
1712
  waitForReady: false,
@@ -1742,7 +1742,7 @@ const validateEntity = xstate.fromPromise(async ({ input }) => {
1742
1742
  }
1743
1743
  else if (entityInput.entityType === 'modelProperty') {
1744
1744
  // Use existing ModelProperty validation
1745
- const validationServiceMod = await Promise.resolve().then(function () { return require('./SchemaValidationService-BMnjcVWV.js'); });
1745
+ const validationServiceMod = await Promise.resolve().then(function () { return require('./SchemaValidationService-DVmOGZao.js'); });
1746
1746
  const { SchemaValidationService } = validationServiceMod;
1747
1747
  const validationService = new SchemaValidationService();
1748
1748
  // Validate property structure
@@ -1757,7 +1757,7 @@ const validateEntity = xstate.fromPromise(async ({ input }) => {
1757
1757
  // If schema name and model name provided, validate against schema
1758
1758
  if (entityInput.entityData._schemaName && entityInput.entityData.modelName) {
1759
1759
  try {
1760
- const schemaMod = await Promise.resolve().then(function () { return require('./Schema-dkd-eo3B.js'); });
1760
+ const schemaMod = await Promise.resolve().then(function () { return require('./Schema-Hgwq3L34.js'); });
1761
1761
  const { Schema } = schemaMod;
1762
1762
  const schema = Schema.create(entityInput.entityData._schemaName, {
1763
1763
  waitForReady: false,
@@ -1786,7 +1786,7 @@ const validateEntity = xstate.fromPromise(async ({ input }) => {
1786
1786
  }
1787
1787
  else if (entityInput.entityType === 'schema') {
1788
1788
  // Schema validation - use existing validation
1789
- const validationServiceMod = await Promise.resolve().then(function () { return require('./SchemaValidationService-BMnjcVWV.js'); });
1789
+ const validationServiceMod = await Promise.resolve().then(function () { return require('./SchemaValidationService-DVmOGZao.js'); });
1790
1790
  const { SchemaValidationService } = validationServiceMod;
1791
1791
  const validationService = new SchemaValidationService();
1792
1792
  const schemaResult = validationService.validateSchema(entityInput.entityData);
@@ -3827,7 +3827,7 @@ const writeToDatabase = xstate.fromCallback(({ sendBack, input }) => {
3827
3827
  // initial write completes is not overwritten by the stale requestWrite payload.
3828
3828
  let dataToWrite = input.entityData;
3829
3829
  try {
3830
- const mod = await Promise.resolve().then(function () { return require('./ModelProperty-Dgd4tGrB.js'); });
3830
+ const mod = await Promise.resolve().then(function () { return require('./ModelProperty-BA26rMV8.js'); });
3831
3831
  const ModelProperty = mod?.ModelProperty ?? mod?.default;
3832
3832
  if (ModelProperty && typeof ModelProperty.getById === 'function') {
3833
3833
  const instance = ModelProperty.getById(input.entityId);
@@ -4207,7 +4207,7 @@ const modelMachine = xstate.setup({
4207
4207
  // Create ModelProperty instances for any new property IDs
4208
4208
  if (Array.isArray(newPropertyIds) && newPropertyIds.length > 0) {
4209
4209
  // Import and create instances asynchronously (fire-and-forget)
4210
- Promise.resolve().then(function () { return require('./ModelProperty-Dgd4tGrB.js'); }).then(({ ModelProperty }) => {
4210
+ Promise.resolve().then(function () { return require('./ModelProperty-BA26rMV8.js'); }).then(({ ModelProperty }) => {
4211
4211
  const createPromises = newPropertyIds.map(async (propertyFileId) => {
4212
4212
  try {
4213
4213
  const property = await ModelProperty.createById(propertyFileId);
@@ -5188,7 +5188,7 @@ const createItemPropertyInstances = async (metadataRows, seedLocalId, seedUid, m
5188
5188
  const schemaNameToTry = model$1?.schemaName;
5189
5189
  if (schemaNameToTry) {
5190
5190
  try {
5191
- const { Schema } = await Promise.resolve().then(function () { return require('./Schema-dkd-eo3B.js'); });
5191
+ const { Schema } = await Promise.resolve().then(function () { return require('./Schema-Hgwq3L34.js'); });
5192
5192
  const schemaInstance = Schema.create(schemaNameToTry, { waitForReady: false });
5193
5193
  const schemaContext = schemaInstance.getService().getSnapshot().context;
5194
5194
  if (schemaContext.models?.[modelName]?.properties) {
@@ -5237,7 +5237,7 @@ const createItemPropertyInstances = async (metadataRows, seedLocalId, seedUid, m
5237
5237
  }
5238
5238
  }
5239
5239
  if (Object.keys(propertySchemas).length === 0) {
5240
- const schemaMod = await Promise.resolve().then(function () { return require('./index-Dx19j60c.js'); });
5240
+ const schemaMod = await Promise.resolve().then(function () { return require('./index-DQggpLqI.js'); });
5241
5241
  const { ModelPropertyDataTypes } = schemaMod;
5242
5242
  const KNOWN_MODEL_FALLBACKS = {
5243
5243
  Post: {
@@ -5284,7 +5284,7 @@ const createItemPropertyInstances = async (metadataRows, seedLocalId, seedUid, m
5284
5284
  // Infer propertyRecordSchema from metadata when schema is missing (enables persistence)
5285
5285
  let propSchema = propertySchemas[propertyName];
5286
5286
  if (!propSchema && isRefTypeFromMeta) {
5287
- const schemaMod = await Promise.resolve().then(function () { return require('./index-Dx19j60c.js'); });
5287
+ const schemaMod = await Promise.resolve().then(function () { return require('./index-DQggpLqI.js'); });
5288
5288
  const { ModelPropertyDataTypes } = schemaMod;
5289
5289
  propSchema = {
5290
5290
  dataType: refSeedType === 'html' ? ModelPropertyDataTypes.Html
@@ -5541,9 +5541,9 @@ const runPublish = xstate.fromCallback(({ sendBack, input: { context } }) => {
5541
5541
  sendBack({ type: 'publishError', error: new Error(`Item not found for seedLocalId: ${seedLocalId}`) });
5542
5542
  return;
5543
5543
  }
5544
- const getPublishUploadsMod = await Promise.resolve().then(function () { return require('./getPublishUploads-Dt-DS-lo.js'); });
5544
+ const getPublishUploadsMod = await Promise.resolve().then(function () { return require('./getPublishUploads-DMKnK2_R.js'); });
5545
5545
  const { getPublishUploads } = getPublishUploadsMod;
5546
- const getPublishPayloadMod = await Promise.resolve().then(function () { return require('./getPublishPayload-B_G_6qkE.js'); });
5546
+ const getPublishPayloadMod = await Promise.resolve().then(function () { return require('./getPublishPayload-DSBLjMKl.js'); });
5547
5547
  const { getPublishPayload } = getPublishPayloadMod;
5548
5548
  const uploads = await getPublishUploads(item);
5549
5549
  let uploadedTransactions = [];
@@ -6524,7 +6524,7 @@ const resolveRelatedValue = xstate.fromCallback(({ sendBack, input: { context }
6524
6524
  const { isRelation, propertyValue, propertyName, seedUid, propertyRecordSchema, populatedFromDb, schemaUid, } = context;
6525
6525
  const _resolveRelatedValue = async () => {
6526
6526
  // Use dynamic import to break circular dependency
6527
- const schemaMod = await Promise.resolve().then(function () { return require('./index-Dx19j60c.js'); });
6527
+ const schemaMod = await Promise.resolve().then(function () { return require('./index-DQggpLqI.js'); });
6528
6528
  const { ModelPropertyDataTypes } = schemaMod;
6529
6529
  if (!propertyValue || !isRelation || populatedFromDb) {
6530
6530
  return;
@@ -7527,7 +7527,7 @@ const hydrateFromDb = xstate.fromCallback(({ sendBack, input: { context } }) =>
7527
7527
  // to use dynamically imported ModelPropertyDataTypes
7528
7528
  const _hydrateFromDb = async () => {
7529
7529
  // Use dynamic import to break circular dependency
7530
- const schemaMod = await Promise.resolve().then(function () { return require('./index-Dx19j60c.js'); });
7530
+ const schemaMod = await Promise.resolve().then(function () { return require('./index-DQggpLqI.js'); });
7531
7531
  const { ModelPropertyDataTypes } = schemaMod;
7532
7532
  const appDb = BaseDb.getAppDb();
7533
7533
  const whereClauses = [];
@@ -7890,7 +7890,7 @@ const loadOrCreateProperty = xstate.fromCallback(({ sendBack, input: { context }
7890
7890
  };
7891
7891
  // Merge with schema from file/DB to get validation rules (enum, pattern, etc.) - properties table doesn't store these
7892
7892
  try {
7893
- const { getPropertySchema } = await Promise.resolve().then(function () { return require('./property-628qAHpN.js'); });
7893
+ const { getPropertySchema } = await Promise.resolve().then(function () { return require('./property-D4IB0zBz.js'); });
7894
7894
  let schemaFromFile = await getPropertySchema(normalizedModelName, propertyName);
7895
7895
  if (!schemaFromFile?.validation) {
7896
7896
  // Fallback: get validation from schemaData in database (Schema context may not be loaded yet)
@@ -8355,9 +8355,9 @@ const analyzeInput = xstate.fromCallback(({ sendBack, input: { context, event }
8355
8355
  }
8356
8356
  const _analyzeInput = async () => {
8357
8357
  // Use dynamic import to break circular dependency
8358
- const schemaMod = await Promise.resolve().then(function () { return require('./index-Dx19j60c.js'); });
8358
+ const schemaMod = await Promise.resolve().then(function () { return require('./index-DQggpLqI.js'); });
8359
8359
  const { ModelPropertyDataTypes } = schemaMod;
8360
- const { SchemaValidationService } = await Promise.resolve().then(function () { return require('./SchemaValidationService-BMnjcVWV.js'); });
8360
+ const { SchemaValidationService } = await Promise.resolve().then(function () { return require('./SchemaValidationService-DVmOGZao.js'); });
8361
8361
  let propertyName = propertyNameRaw;
8362
8362
  if (!propertyName) {
8363
8363
  throw new Error('propertyName is required');
@@ -8555,7 +8555,7 @@ const createMetadata = async (metadataValues, propertyRecordSchema, options) =>
8555
8555
  propertyRecordSchema?.validation &&
8556
8556
  metadataValues.propertyValue != null &&
8557
8557
  metadataValues.propertyValue !== '') {
8558
- const { SchemaValidationService } = await Promise.resolve().then(function () { return require('./SchemaValidationService-BMnjcVWV.js'); });
8558
+ const { SchemaValidationService } = await Promise.resolve().then(function () { return require('./SchemaValidationService-DVmOGZao.js'); });
8559
8559
  const validationService = new SchemaValidationService();
8560
8560
  const validationResult = validationService.validatePropertyValue(metadataValues.propertyValue, normalizeDataType(propertyRecordSchema.dataType), propertyRecordSchema.validation, propertyRecordSchema.refValueType
8561
8561
  ? normalizeDataType(String(propertyRecordSchema.refValueType))
@@ -9148,7 +9148,7 @@ const saveRelation = xstate.fromCallback(({ sendBack, input: { context, event }
9148
9148
  }
9149
9149
  const _saveRelation = async () => {
9150
9150
  // Use dynamic import to break circular dependency
9151
- const schemaMod = await Promise.resolve().then(function () { return require('./index-Dx19j60c.js'); });
9151
+ const schemaMod = await Promise.resolve().then(function () { return require('./index-DQggpLqI.js'); });
9152
9152
  const { ModelPropertyDataTypes } = schemaMod;
9153
9153
  if (!propertyNameRaw) {
9154
9154
  throw new Error('propertyName is required');
@@ -10192,7 +10192,7 @@ class ItemProperty {
10192
10192
  return;
10193
10193
  }
10194
10194
  // Use dynamic import to break circular dependency
10195
- const schemaMod = await Promise.resolve().then(function () { return require('./index-Dx19j60c.js'); });
10195
+ const schemaMod = await Promise.resolve().then(function () { return require('./index-DQggpLqI.js'); });
10196
10196
  const { ModelPropertyDataTypes } = schemaMod;
10197
10197
  const { context } = snapshot;
10198
10198
  const { propertyRecordSchema } = context;
@@ -11101,7 +11101,7 @@ class ItemProperty {
11101
11101
  }
11102
11102
  async save() {
11103
11103
  const ctx = this._getSnapshotContext();
11104
- const { assertItemOwned } = await Promise.resolve().then(function () { return require('./ownership-3Tc1-Yrc.js'); });
11104
+ const { assertItemOwned } = await Promise.resolve().then(function () { return ownership; });
11105
11105
  await assertItemOwned({
11106
11106
  seedLocalId: ctx?.seedLocalId ?? undefined,
11107
11107
  seedUid: ctx?.seedUid ?? undefined,
@@ -11440,7 +11440,7 @@ class Item {
11440
11440
  });
11441
11441
  };
11442
11442
  this.unpublish = async () => {
11443
- const { assertItemOwned } = await Promise.resolve().then(function () { return require('./ownership-3Tc1-Yrc.js'); });
11443
+ const { assertItemOwned } = await Promise.resolve().then(function () { return ownership; });
11444
11444
  const { getRevokeExecutor } = await Promise.resolve().then(function () { return publishConfig; });
11445
11445
  await assertItemOwned(this);
11446
11446
  const seedUid = this.seedUid;
@@ -11464,7 +11464,7 @@ class Item {
11464
11464
  this._service.send({ type: 'updateContext', revokedAt });
11465
11465
  };
11466
11466
  this.publish = async () => {
11467
- const { assertItemOwned } = await Promise.resolve().then(function () { return require('./ownership-3Tc1-Yrc.js'); });
11467
+ const { assertItemOwned } = await Promise.resolve().then(function () { return ownership; });
11468
11468
  await assertItemOwned(this);
11469
11469
  this._service.send({ type: 'startPublish' });
11470
11470
  return new Promise((resolve, reject) => {
@@ -11500,12 +11500,12 @@ class Item {
11500
11500
  };
11501
11501
  this.getPublishUploads = async (options) => {
11502
11502
  // Use dynamic import to break circular dependency
11503
- const getPublishUploadsMod = await Promise.resolve().then(function () { return require('./getPublishUploads-Dt-DS-lo.js'); });
11503
+ const getPublishUploadsMod = await Promise.resolve().then(function () { return require('./getPublishUploads-DMKnK2_R.js'); });
11504
11504
  const { getPublishUploads } = getPublishUploadsMod;
11505
11505
  return await getPublishUploads(this, [], undefined, options);
11506
11506
  };
11507
11507
  this.getPublishPayload = async (uploadedTransactions, options) => {
11508
- const getPublishPayloadMod = await Promise.resolve().then(function () { return require('./getPublishPayload-B_G_6qkE.js'); });
11508
+ const getPublishPayloadMod = await Promise.resolve().then(function () { return require('./getPublishPayload-DSBLjMKl.js'); });
11509
11509
  const { getPublishPayload } = getPublishPayloadMod;
11510
11510
  return await getPublishPayload(this, uploadedTransactions, options);
11511
11511
  };
@@ -12158,6 +12158,39 @@ class Item {
12158
12158
  }
12159
12159
  return null;
12160
12160
  }
12161
+ /**
12162
+ * Drop cached Item instances for the given seed local ids / uids without soft-deleting DB rows.
12163
+ * Used by local purge (`removeLocalCopiesForAddresses`) before hard-deleting rows.
12164
+ */
12165
+ static dropCachedInstancesForSeedIds(ids) {
12166
+ const uniqueIds = [
12167
+ ...new Set(ids.filter((id) => typeof id === 'string' && id.length > 0)),
12168
+ ];
12169
+ const seenInstances = new Set();
12170
+ for (const id of uniqueIds) {
12171
+ const entry = this.findItemInstanceCacheEntryById(id);
12172
+ if (entry && !seenInstances.has(entry.instance)) {
12173
+ seenInstances.add(entry.instance);
12174
+ const instance = entry.instance;
12175
+ const cacheKeys = this.collectInstanceCacheKeysForInstance(instance);
12176
+ clearDestroySubscriptions(instance, {
12177
+ instanceState: itemInstanceState,
12178
+ onUnload: (inst) => inst._subscription?.unsubscribe(),
12179
+ });
12180
+ forceRemoveFromCaches(instance, {
12181
+ getCacheKeys: () => cacheKeys,
12182
+ caches: [Item.instanceCache],
12183
+ });
12184
+ try {
12185
+ instance._service.stop();
12186
+ }
12187
+ catch {
12188
+ // Service may already be stopped
12189
+ }
12190
+ }
12191
+ ItemProperty.clearInstanceCacheForItem(id);
12192
+ }
12193
+ }
12161
12194
  /**
12162
12195
  * Create Item instance by ID (queries database if not in cache)
12163
12196
  * The ID can be either seedUid or seedLocalId
@@ -12999,7 +13032,7 @@ class Item {
12999
13032
  * Destroy the item: soft delete in DB, remove from caches, clean up subscriptions, stop service.
13000
13033
  */
13001
13034
  async destroy() {
13002
- const { assertItemOwned } = await Promise.resolve().then(function () { return require('./ownership-3Tc1-Yrc.js'); });
13035
+ const { assertItemOwned } = await Promise.resolve().then(function () { return ownership; });
13003
13036
  await assertItemOwned(this);
13004
13037
  const context = this._getSnapshotContext();
13005
13038
  const cacheKeys = Item.collectInstanceCacheKeysForInstance(this);
@@ -13155,7 +13188,7 @@ const runEasSync = xstate.fromPromise(async ({ input, }) => {
13155
13188
  requestPayload: input.requestPayload,
13156
13189
  persistedSnapshot: input.runningSnapshot,
13157
13190
  });
13158
- const { runSyncFromEas } = await Promise.resolve().then(function () { return require('./syncDbWithEas-DOBtMPw-.js'); });
13191
+ const { runSyncFromEas } = await Promise.resolve().then(function () { return require('./syncDbWithEas-BYvFJc7N.js'); });
13159
13192
  try {
13160
13193
  await runSyncFromEas(toRunSyncArg(input.options));
13161
13194
  await finalizeEasSyncProcessRow(rowId, {
@@ -14031,6 +14064,140 @@ const saveConfig = xstate.fromCallback(({ sendBack, input: { context } }) => {
14031
14064
  });
14032
14065
 
14033
14066
  const logger$6 = debug('seedSdk:helpers:schema');
14067
+ /**
14068
+ * Sanitize a schema name to be filesystem-safe
14069
+ * Replaces all special characters (except alphanumeric, hyphens, underscores) with underscores
14070
+ * Converts spaces to underscores
14071
+ * Removes leading/trailing underscores
14072
+ *
14073
+ * @param name - Schema name to sanitize
14074
+ * @returns Sanitized name safe for use in filenames
14075
+ */
14076
+ const sanitizeSchemaName$1 = (name) => {
14077
+ return name
14078
+ .replace(/[^a-zA-Z0-9\s_-]/g, '_') // Replace special chars (except spaces, hyphens, underscores) with underscore
14079
+ .replace(/\s+/g, '_') // Convert spaces to underscores
14080
+ .replace(/^_+|_+$/g, '') // Remove leading/trailing underscores
14081
+ .replace(/_+/g, '_'); // Collapse multiple underscores to single
14082
+ };
14083
+ /**
14084
+ * Generate filename for a schema
14085
+ * Format: {schemaFileId}_{schemaName}_v{version}.json
14086
+ *
14087
+ * The ID-first format ensures all files for a schema group together when sorted alphabetically.
14088
+ *
14089
+ * @param name - Schema name
14090
+ * @param version - Schema version
14091
+ * @param schemaFileId - Schema file ID (required)
14092
+ */
14093
+ const getSchemaFilename = (name, version, schemaFileId) => {
14094
+ const sanitizedName = sanitizeSchemaName$1(name);
14095
+ return `${schemaFileId}_${sanitizedName}_v${version}.json`;
14096
+ };
14097
+ /**
14098
+ * Get the full file path for a schema
14099
+ * Format: {schemaFileId}_{schemaName}_v{version}.json
14100
+ *
14101
+ * The ID-first format ensures all files for a schema group together when sorted alphabetically.
14102
+ *
14103
+ * @param name - Schema name
14104
+ * @param version - Schema version
14105
+ * @param schemaFileId - Schema file ID (required)
14106
+ */
14107
+ const getSchemaFilePath$1 = (name, version, schemaFileId) => {
14108
+ const path = BaseFileManager.getPathModule();
14109
+ const filename = getSchemaFilename(name, version, schemaFileId);
14110
+ const workingDir = BaseFileManager.getWorkingDir();
14111
+ return path.join(workingDir, filename);
14112
+ };
14113
+ /**
14114
+ * Create a new schema file
14115
+ * @param schema - The schema object to save
14116
+ * @param schemaFileId - Schema file ID (required)
14117
+ * @throws Error if schema already exists or if workingDir is invalid
14118
+ */
14119
+ const createSchema = async (schema, schemaFileId) => {
14120
+ if (!schema.name || !schema.version) {
14121
+ throw new Error('Schema must have a name and version');
14122
+ }
14123
+ const filePath = getSchemaFilePath$1(schema.name, schema.version, schemaFileId);
14124
+ // Check if schema already exists
14125
+ const exists = await BaseFileManager.pathExists(filePath);
14126
+ if (exists) {
14127
+ throw new Error(`Schema ${schema.name} v${schema.version} already exists`);
14128
+ }
14129
+ // Ensure working directory exists
14130
+ const workingDir = BaseFileManager.getWorkingDir();
14131
+ await BaseFileManager.createDirIfNotExists(workingDir);
14132
+ // Write schema to file
14133
+ const content = JSON.stringify(schema, null, 2);
14134
+ await BaseFileManager.saveFile(filePath, content);
14135
+ };
14136
+ /**
14137
+ * Read a schema file by name and version
14138
+ * @param name - The name of the schema
14139
+ * @param version - The version of the schema
14140
+ * @param schemaFileId - Schema file ID (required)
14141
+ * @returns The schema object, or null if not found
14142
+ */
14143
+ const readSchema = async (name, version, schemaFileId) => {
14144
+ const filePath = getSchemaFilePath$1(name, version, schemaFileId);
14145
+ const exists = await BaseFileManager.pathExists(filePath);
14146
+ if (!exists) {
14147
+ return null;
14148
+ }
14149
+ try {
14150
+ const content = await BaseFileManager.readFileAsString(filePath);
14151
+ return JSON.parse(content);
14152
+ }
14153
+ catch (error) {
14154
+ throw new Error(`Failed to read schema ${name} v${version}: ${error instanceof Error ? error.message : String(error)}`);
14155
+ }
14156
+ };
14157
+ /**
14158
+ * Update an existing schema file
14159
+ * @param schema - The updated schema object (must have same name and version as existing)
14160
+ * @param schemaFileId - Schema file ID (required)
14161
+ * @throws Error if schema doesn't exist
14162
+ */
14163
+ async function updateSchema(schema, schemaFileId) {
14164
+ if (!schema.name || !schema.version) {
14165
+ throw new Error('Schema must have a name and version');
14166
+ }
14167
+ const filePath = getSchemaFilePath$1(schema.name, schema.version, schemaFileId);
14168
+ // Check if schema exists
14169
+ const exists = await BaseFileManager.pathExists(filePath);
14170
+ if (!exists) {
14171
+ throw new Error(`Schema ${schema.name} v${schema.version} does not exist`);
14172
+ }
14173
+ // Write updated schema to file
14174
+ const content = JSON.stringify(schema, null, 2);
14175
+ await BaseFileManager.saveFile(filePath, content);
14176
+ }
14177
+ /**
14178
+ * Delete a schema file
14179
+ * @param name - The name of the schema
14180
+ * @param version - The version of the schema
14181
+ * @param schemaFileId - Schema file ID (required)
14182
+ * @throws Error if schema doesn't exist
14183
+ */
14184
+ async function deleteSchema(name, version, schemaFileId) {
14185
+ const filePath = getSchemaFilePath$1(name, version, schemaFileId);
14186
+ // Check if schema exists
14187
+ const exists = await BaseFileManager.pathExists(filePath);
14188
+ if (!exists) {
14189
+ throw new Error(`Schema ${name} v${version} does not exist`);
14190
+ }
14191
+ // Delete the file
14192
+ const fs = await BaseFileManager.getFs();
14193
+ BaseFileManager.getPathModule();
14194
+ try {
14195
+ await fs.promises.unlink(filePath);
14196
+ }
14197
+ catch (error) {
14198
+ throw new Error(`Failed to delete schema ${name} v${version}: ${error instanceof Error ? error.message : String(error)}`);
14199
+ }
14200
+ }
14034
14201
  /**
14035
14202
  * List all schema files in the working directory
14036
14203
  * Only returns files that are NOT already complete schema files (i.e., files without $schema field)
@@ -14141,6 +14308,24 @@ async function listCompleteSchemaFiles() {
14141
14308
  throw new Error(`Failed to list complete schemas: ${error instanceof Error ? error.message : String(error)}`);
14142
14309
  }
14143
14310
  }
14311
+ /**
14312
+ * Find a schema by name (returns the latest version if multiple versions exist)
14313
+ * @param name - The name of the schema
14314
+ * @returns The schema with the highest version, or null if not found
14315
+ */
14316
+ async function findSchemaByName(name) {
14317
+ const schemas = await listCompleteSchemaFiles();
14318
+ const matchingSchemas = schemas.filter((s) => s.name === name);
14319
+ if (matchingSchemas.length === 0) {
14320
+ return null;
14321
+ }
14322
+ // Find the schema with the highest version
14323
+ const latest = matchingSchemas.reduce((prev, current) => current.version > prev.version ? current : prev);
14324
+ if (!latest.schemaFileId) {
14325
+ throw new Error(`Schema ${latest.name} v${latest.version} is missing schemaFileId`);
14326
+ }
14327
+ return readSchema(latest.name, latest.version, latest.schemaFileId);
14328
+ }
14144
14329
  /**
14145
14330
  * Get the latest version number for a schema by name
14146
14331
  * Only considers complete schema files (with $schema field)
@@ -14173,6 +14358,27 @@ async function listLatestSchemaFiles() {
14173
14358
  }
14174
14359
  return Array.from(schemaMap.values());
14175
14360
  }
14361
+ /**
14362
+ * Filter an array of schemas to only include the latest version for each schema name
14363
+ * Works with any object that has a name (via metadata.name or name property) and a version property
14364
+ * @param schemas - Array of schema objects
14365
+ * @returns Array containing only the latest version of each schema
14366
+ */
14367
+ function filterLatestSchemas(schemas) {
14368
+ // Group by schema name and keep only the latest version of each
14369
+ const schemaMap = new Map();
14370
+ for (const schema of schemas) {
14371
+ const schemaName = schema.metadata?.name || schema.name;
14372
+ if (!schemaName) {
14373
+ continue; // Skip schemas without a name
14374
+ }
14375
+ const existing = schemaMap.get(schemaName);
14376
+ if (!existing || schema.version > existing.version) {
14377
+ schemaMap.set(schemaName, schema);
14378
+ }
14379
+ }
14380
+ return Array.from(schemaMap.values());
14381
+ }
14176
14382
  /**
14177
14383
  * Unified schema loading function that queries database first, then merges with files
14178
14384
  * Returns all schemas with their draft status and source information
@@ -14366,14 +14572,93 @@ async function loadAllSchemasFromDb() {
14366
14572
  }
14367
14573
  return result;
14368
14574
  }
14575
+ /**
14576
+ * Migration helper: Migrate existing file-based schemas to the database
14577
+ * This function should be called once to migrate existing schema files to the new database-first approach
14578
+ * All existing schemas will be marked as published (isDraft = false) since they already exist in files
14579
+ * @returns Number of schemas migrated
14580
+ */
14581
+ async function migrateFileSchemasToDb() {
14582
+ const db = BaseDb.getAppDb();
14583
+ if (!db) {
14584
+ throw new Error('Database not found');
14585
+ }
14586
+ logger$6('Starting migration of file-based schemas to database');
14587
+ // Get all complete schema files
14588
+ const completeSchemas = await listCompleteSchemaFiles();
14589
+ let migratedCount = 0;
14590
+ for (const schemaFileInfo of completeSchemas) {
14591
+ try {
14592
+ // Read the schema file
14593
+ const content = await BaseFileManager.readFileAsString(schemaFileInfo.filePath);
14594
+ const schemaFile = JSON.parse(content);
14595
+ if (!schemaFile.$schema || !schemaFile.metadata?.name) {
14596
+ logger$6(`Skipping invalid schema file: ${schemaFileInfo.filePath}`);
14597
+ continue;
14598
+ }
14599
+ const schemaName = schemaFile.metadata.name;
14600
+ // Check if schema already exists in database
14601
+ const existingSchemas = await db
14602
+ .select()
14603
+ .from(schemas)
14604
+ .where(drizzleOrm.eq(schemas.name, schemaName))
14605
+ .limit(1);
14606
+ // Only migrate if it doesn't exist or if existing record doesn't have schemaFileId
14607
+ if (existingSchemas.length === 0 || !existingSchemas[0].schemaFileId) {
14608
+ // Add schema to database as published (isDraft = false)
14609
+ await addSchemaToDb({
14610
+ name: schemaName,
14611
+ version: schemaFile.version,
14612
+ createdAt: new Date(schemaFile.metadata.createdAt).getTime(),
14613
+ updatedAt: new Date(schemaFile.metadata.updatedAt).getTime(),
14614
+ }, schemaFile.id, // schemaFileId
14615
+ JSON.stringify(schemaFile, null, 2), // schemaData
14616
+ false);
14617
+ migratedCount++;
14618
+ logger$6(`Migrated schema: ${schemaName} v${schemaFile.version}`);
14619
+ }
14620
+ else {
14621
+ logger$6(`Schema ${schemaName} already exists in database, skipping`);
14622
+ }
14623
+ }
14624
+ catch (error) {
14625
+ logger$6(`Error migrating schema file ${schemaFileInfo.filePath}:`, error);
14626
+ }
14627
+ }
14628
+ logger$6(`Migration complete: ${migratedCount} schemas migrated`);
14629
+ return migratedCount;
14630
+ }
14631
+ /**
14632
+ * Extract the schema name from a schemaId string
14633
+ * @param schemaId - Schema ID in the format `${schemaName}-${schemaVersion}`
14634
+ * @returns The schema name, or null if the format is invalid
14635
+ */
14636
+ function getSchemaNameFromId(schemaId) {
14637
+ if (!schemaId) {
14638
+ return null;
14639
+ }
14640
+ const lastDashIndex = schemaId.lastIndexOf('-');
14641
+ if (lastDashIndex === -1 || lastDashIndex === 0 || lastDashIndex === schemaId.length - 1) {
14642
+ return null;
14643
+ }
14644
+ return schemaId.substring(0, lastDashIndex);
14645
+ }
14369
14646
 
14370
14647
  var schema = /*#__PURE__*/Object.freeze({
14371
14648
  __proto__: null,
14649
+ createSchema: createSchema,
14650
+ deleteSchema: deleteSchema,
14651
+ filterLatestSchemas: filterLatestSchemas,
14652
+ findSchemaByName: findSchemaByName,
14372
14653
  getLatestSchemaVersion: getLatestSchemaVersion,
14654
+ getSchemaNameFromId: getSchemaNameFromId,
14373
14655
  listCompleteSchemaFiles: listCompleteSchemaFiles,
14374
14656
  listLatestSchemaFiles: listLatestSchemaFiles,
14375
14657
  listSchemaFiles: listSchemaFiles,
14376
- loadAllSchemasFromDb: loadAllSchemasFromDb
14658
+ loadAllSchemasFromDb: loadAllSchemasFromDb,
14659
+ migrateFileSchemasToDb: migrateFileSchemasToDb,
14660
+ readSchema: readSchema,
14661
+ updateSchema: updateSchema
14377
14662
  });
14378
14663
 
14379
14664
  const { sha3_256 } = sha3__namespace;
@@ -16234,6 +16519,8 @@ const processSchemaFiles = xstate.fromCallback(({ sendBack, input: { context } }
16234
16519
 
16235
16520
  /** Emitted by the client manager after `app_state.addresses` is written (post-`setAddresses`). */
16236
16521
  const ADDRESSES_PERSISTED_EVENT = 'addresses.persisted';
16522
+ /** Emitted after hard-deleting local on-chain seed copies for publisher addresses. */
16523
+ const LOCAL_COPIES_REMOVED_EVENT = 'localCopies.removed';
16237
16524
  function parseAddressesPersistedPayload(value) {
16238
16525
  if (!value || typeof value !== 'object') {
16239
16526
  return { owned: [], watched: [] };
@@ -16892,6 +17179,155 @@ function unregisterSeedQueryLocalSource() {
16892
17179
  registered = false;
16893
17180
  }
16894
17181
 
17182
+ const READ_ONLY_ERROR = 'Item is read-only: you do not own this item';
17183
+ async function getSeedRowForItem(item) {
17184
+ const appDb = BaseDb.getAppDb();
17185
+ if (!appDb)
17186
+ return null;
17187
+ const conditions = [];
17188
+ if (item.seedLocalId)
17189
+ conditions.push(drizzleOrm.eq(seeds.localId, item.seedLocalId));
17190
+ if (item.seedUid)
17191
+ conditions.push(drizzleOrm.eq(seeds.uid, item.seedUid));
17192
+ if (conditions.length === 0)
17193
+ return null;
17194
+ const seedRows = await appDb
17195
+ .select({
17196
+ publisher: seeds.publisher,
17197
+ attestationRaw: seeds.attestationRaw,
17198
+ uid: seeds.uid,
17199
+ })
17200
+ .from(seeds)
17201
+ .where(conditions.length === 1 ? conditions[0] : drizzleOrm.or(...conditions))
17202
+ .limit(1);
17203
+ if (!seedRows || seedRows.length === 0)
17204
+ return null;
17205
+ return seedRows[0];
17206
+ }
17207
+ /** Resolve publisher from seed row: `publisher` column, else `attestationRaw.attester`. */
17208
+ function resolvePublisherFromSeedRow(row) {
17209
+ if (row.publisher)
17210
+ return row.publisher;
17211
+ if (row.attestationRaw) {
17212
+ try {
17213
+ const parsed = JSON.parse(row.attestationRaw);
17214
+ return parsed.attester ?? null;
17215
+ }
17216
+ catch {
17217
+ return null;
17218
+ }
17219
+ }
17220
+ return null;
17221
+ }
17222
+ /**
17223
+ * Checks if the current user owns the item (publisher is in owned addresses).
17224
+ * Locally created items (no publisher, no attestationRaw) are considered owned.
17225
+ * Includes getAdditionalSyncAddresses (e.g. `modularAccountModuleContract` when configured)
17226
+ * so ownership aligns with EAS sync when the publisher/attester matches those addresses.
17227
+ */
17228
+ async function isItemOwned(item) {
17229
+ const row = await getSeedRowForItem(item);
17230
+ if (!row)
17231
+ return false;
17232
+ const publisher = resolvePublisherFromSeedRow(row);
17233
+ if (!publisher) {
17234
+ if (!row.uid && !row.attestationRaw) {
17235
+ return true;
17236
+ }
17237
+ return false;
17238
+ }
17239
+ let addressesToCheck = await getOwnedAddressesFromDb();
17240
+ const ownedSet = new Set(addressesToCheck.map((a) => a.toLowerCase()));
17241
+ return ownedSet.has(publisher.toLowerCase());
17242
+ }
17243
+ /**
17244
+ * Throws if the item is not owned. Use before write operations (publish, save, destroy).
17245
+ */
17246
+ async function assertItemOwned(item) {
17247
+ const owned = await isItemOwned(item);
17248
+ if (!owned) {
17249
+ throw new Error(READ_ONLY_ERROR);
17250
+ }
17251
+ }
17252
+
17253
+ var ownership = /*#__PURE__*/Object.freeze({
17254
+ __proto__: null,
17255
+ assertItemOwned: assertItemOwned,
17256
+ isItemOwned: isItemOwned,
17257
+ resolvePublisherFromSeedRow: resolvePublisherFromSeedRow
17258
+ });
17259
+
17260
+ const emptyResult = () => ({
17261
+ removedSeedLocalIds: [],
17262
+ removedSeedUids: [],
17263
+ });
17264
+ function normalizeAddresses(addresses) {
17265
+ return [
17266
+ ...new Set(addresses
17267
+ .filter((a) => typeof a === 'string' && a.length > 0)
17268
+ .map((a) => a.toLowerCase())),
17269
+ ];
17270
+ }
17271
+ /**
17272
+ * Find local on-chain seed copies for the given publisher addresses (no delete).
17273
+ * Drafts (no uid and no attestationRaw) are excluded.
17274
+ */
17275
+ async function findLocalOnchainCopiesForAddresses(addresses) {
17276
+ const normalized = normalizeAddresses(addresses);
17277
+ if (normalized.length === 0) {
17278
+ return emptyResult();
17279
+ }
17280
+ const appDb = BaseDb.getAppDb();
17281
+ if (!appDb) {
17282
+ return emptyResult();
17283
+ }
17284
+ const addressSet = new Set(normalized);
17285
+ const candidateRows = (await appDb
17286
+ .select({
17287
+ localId: seeds.localId,
17288
+ uid: seeds.uid,
17289
+ publisher: seeds.publisher,
17290
+ attestationRaw: seeds.attestationRaw,
17291
+ })
17292
+ .from(seeds)
17293
+ .where(drizzleOrm.or(drizzleOrm.isNotNull(seeds.uid), drizzleOrm.isNotNull(seeds.attestationRaw))));
17294
+ const matched = candidateRows.filter((row) => {
17295
+ if (!row.localId)
17296
+ return false;
17297
+ const publisher = resolvePublisherFromSeedRow(row);
17298
+ return publisher != null && addressSet.has(publisher.toLowerCase());
17299
+ });
17300
+ return {
17301
+ removedSeedLocalIds: matched.map((r) => r.localId).filter(Boolean),
17302
+ removedSeedUids: matched
17303
+ .map((r) => r.uid)
17304
+ .filter((u) => typeof u === 'string' && u.length > 0),
17305
+ };
17306
+ }
17307
+ /**
17308
+ * Hard-delete the given seed local ids and related local rows (cascade).
17309
+ * Does not touch schemas, app_state, or chain.
17310
+ */
17311
+ async function hardDeleteLocalSeedsByLocalIds(seedLocalIds) {
17312
+ if (seedLocalIds.length === 0)
17313
+ return;
17314
+ const appDb = BaseDb.getAppDb();
17315
+ if (!appDb)
17316
+ return;
17317
+ await appDb
17318
+ .delete(htmlEmbeddedImageCoPublish)
17319
+ .where(drizzleOrm.or(drizzleOrm.inArray(htmlEmbeddedImageCoPublish.parentSeedLocalId, seedLocalIds), drizzleOrm.inArray(htmlEmbeddedImageCoPublish.htmlSeedLocalId, seedLocalIds), drizzleOrm.inArray(htmlEmbeddedImageCoPublish.imageSeedLocalId, seedLocalIds)));
17320
+ await appDb
17321
+ .delete(arweaveL1FinalizeJobs)
17322
+ .where(drizzleOrm.inArray(arweaveL1FinalizeJobs.seedLocalId, seedLocalIds));
17323
+ await appDb
17324
+ .delete(publishProcesses)
17325
+ .where(drizzleOrm.inArray(publishProcesses.seedLocalId, seedLocalIds));
17326
+ await appDb.delete(metadata$1).where(drizzleOrm.inArray(metadata$1.seedLocalId, seedLocalIds));
17327
+ await appDb.delete(versions).where(drizzleOrm.inArray(versions.seedLocalId, seedLocalIds));
17328
+ await appDb.delete(seeds).where(drizzleOrm.inArray(seeds.localId, seedLocalIds));
17329
+ }
17330
+
16895
17331
  const logger$3 = debug('seedSdk:client');
16896
17332
  const clientManager = xstate.createActor(clientManagerMachine, {
16897
17333
  input: {
@@ -17020,6 +17456,29 @@ const clientInstance = {
17020
17456
  ensureInitialized();
17021
17457
  return getWatchedAddressesFromDb();
17022
17458
  },
17459
+ /**
17460
+ * Hard-delete local on-chain seed copies for the given publisher addresses.
17461
+ * Drafts (no uid / attestationRaw) are kept. Chain is untouched; reconnect can rehydrate via syncFromEas.
17462
+ */
17463
+ removeLocalCopiesForAddresses: async (addresses) => {
17464
+ ensureInitialized();
17465
+ const list = Array.isArray(addresses) ? addresses : [];
17466
+ const matched = await findLocalOnchainCopiesForAddresses(list);
17467
+ const cacheIds = [
17468
+ ...matched.removedSeedLocalIds,
17469
+ ...matched.removedSeedUids,
17470
+ ];
17471
+ if (cacheIds.length > 0) {
17472
+ Item.dropCachedInstancesForSeedIds(cacheIds);
17473
+ }
17474
+ await hardDeleteLocalSeedsByLocalIds(matched.removedSeedLocalIds);
17475
+ eventEmitter.emit(LOCAL_COPIES_REMOVED_EVENT, {
17476
+ addresses: list,
17477
+ removedSeedLocalIds: matched.removedSeedLocalIds,
17478
+ removedSeedUids: matched.removedSeedUids,
17479
+ });
17480
+ return matched;
17481
+ },
17023
17482
  /**
17024
17483
  * Syncs item attestations from EAS for the configured models and given addresses.
17025
17484
  * Uses owned + watched addresses from DB when addresses are not provided.
@@ -17247,7 +17706,7 @@ const saveDraftLogger = debug('seedSdk:model:saveDraftToDb');
17247
17706
  // Lazy import cache for ModelProperty to avoid circular dependency
17248
17707
  // Eagerly start loading to minimize delay on first access
17249
17708
  let ModelPropertyClass = null;
17250
- const modelPropertyImportPromise = Promise.resolve().then(function () { return require('./ModelProperty-Dgd4tGrB.js'); })
17709
+ const modelPropertyImportPromise = Promise.resolve().then(function () { return require('./ModelProperty-BA26rMV8.js'); })
17251
17710
  .then(module => {
17252
17711
  ModelPropertyClass = module.ModelProperty;
17253
17712
  return ModelPropertyClass;
@@ -17264,7 +17723,7 @@ function getModelProperty() {
17264
17723
  }
17265
17724
  // Lazy import cache for Schema to avoid circular dependency
17266
17725
  let SchemaClass = null;
17267
- const schemaImportPromise = Promise.resolve().then(function () { return require('./Schema-dkd-eo3B.js'); })
17726
+ const schemaImportPromise = Promise.resolve().then(function () { return require('./Schema-Hgwq3L34.js'); })
17268
17727
  .then(module => {
17269
17728
  SchemaClass = module.Schema;
17270
17729
  return SchemaClass;
@@ -19169,7 +19628,7 @@ function resolveSdkDrizzleMigrationsDir(sdkRootDir) {
19169
19628
  })();
19170
19629
  // Also resolve relative to this module so temp-cwd tests / odd roots still find
19171
19630
  // packages/sdk/src/db/drizzle (or dist/db/drizzle after publish).
19172
- const moduleDir = path.dirname(node_url.fileURLToPath((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('cjs/index-CRBI6dSD.js', document.baseURI).href))));
19631
+ const moduleDir = path.dirname(node_url.fileURLToPath((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('cjs/index-BD1b6zAi.js', document.baseURI).href))));
19173
19632
  const candidates = [
19174
19633
  path.join(root, 'db', 'drizzle'), // production: sdkRoot is dist/
19175
19634
  path.join(root, 'dist', 'db', 'drizzle'), // sdk package root with built dist
@@ -19239,7 +19698,7 @@ class NodeDb {
19239
19698
  logger$1('[Db.prepareDb] running migrations from %s', outDir);
19240
19699
  await migrator.migrate(db, { migrationsFolder: outDir });
19241
19700
  this.db = db;
19242
- const { backfillMetadataPropertyIds } = await Promise.resolve().then(function () { return require('./backfillMetadataPropertyIds-ClLuj3s6.js'); });
19701
+ const { backfillMetadataPropertyIds } = await Promise.resolve().then(function () { return require('./backfillMetadataPropertyIds-BWJI4eCj.js'); });
19243
19702
  await backfillMetadataPropertyIds();
19244
19703
  return this.db;
19245
19704
  }
@@ -19788,7 +20247,6 @@ exports.getLatestPublishedVersionRow = getLatestPublishedVersionRow;
19788
20247
  exports.getLatestSchemaVersion = getLatestSchemaVersion;
19789
20248
  exports.getModelId = getModelId;
19790
20249
  exports.getModelIdByFileId = getModelIdByFileId;
19791
- exports.getOwnedAddressesFromDb = getOwnedAddressesFromDb;
19792
20250
  exports.getPropertyData = getPropertyData$1;
19793
20251
  exports.getPropertyIdForModelAndName = getPropertyIdForModelAndName;
19794
20252
  exports.getRefValueType = getRefValueType;
@@ -19829,4 +20287,4 @@ exports.versions = versions;
19829
20287
  exports.waitForEntityIdle = waitForEntityIdle;
19830
20288
  exports.withSeed = withSeed;
19831
20289
  exports.writeProcessMachine = writeProcessMachine;
19832
- //# sourceMappingURL=index-CRBI6dSD.js.map
20290
+ //# sourceMappingURL=index-BD1b6zAi.js.map