@seedprotocol/sdk 0.6.4 → 0.6.6

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 (101) hide show
  1. package/dist/{BasePathResolver-0IHnXxtL.js → BasePathResolver-BGxb4Qod.js} +27 -4
  2. package/dist/BasePathResolver-BGxb4Qod.js.map +1 -0
  3. package/dist/{ModelProperty-BiDQu5rE.js → ModelProperty-Bvg9cJcd.js} +20 -20
  4. package/dist/{ModelProperty-BiDQu5rE.js.map → ModelProperty-Bvg9cJcd.js.map} +1 -1
  5. package/dist/{Schema-qciDB7Nu.js → Schema-BNJBY80k.js} +25 -25
  6. package/dist/{Schema-qciDB7Nu.js.map → Schema-BNJBY80k.js.map} +1 -1
  7. package/dist/{SchemaValidationService-BaOkRjsU.js → SchemaValidationService-aqXkwXTr.js} +5 -5
  8. package/dist/{SchemaValidationService-BaOkRjsU.js.map → SchemaValidationService-aqXkwXTr.js.map} +1 -1
  9. package/dist/{backfillMetadataPropertyIds-oypxoBXv.js → backfillMetadataPropertyIds-DYkvoOMz.js} +3 -3
  10. package/dist/{backfillMetadataPropertyIds-oypxoBXv.js.map → backfillMetadataPropertyIds-DYkvoOMz.js.map} +1 -1
  11. package/dist/cjs/{ModelProperty-DvIIhBnK.js → ModelProperty-alntkSnH.js} +17 -17
  12. package/dist/cjs/{ModelProperty-DvIIhBnK.js.map → ModelProperty-alntkSnH.js.map} +1 -1
  13. package/dist/cjs/{Schema-FdzNqyGo.js → Schema-ByFv6fcb.js} +20 -20
  14. package/dist/cjs/{Schema-FdzNqyGo.js.map → Schema-ByFv6fcb.js.map} +1 -1
  15. package/dist/cjs/{SchemaValidationService-pxRoOs79.js → SchemaValidationService-D55MWsxv.js} +2 -2
  16. package/dist/cjs/{SchemaValidationService-pxRoOs79.js.map → SchemaValidationService-D55MWsxv.js.map} +1 -1
  17. package/dist/cjs/{backfillMetadataPropertyIds-D0o5VwBh.js → backfillMetadataPropertyIds-DrrL5RqD.js} +2 -2
  18. package/dist/cjs/{backfillMetadataPropertyIds-D0o5VwBh.js.map → backfillMetadataPropertyIds-DrrL5RqD.js.map} +1 -1
  19. package/dist/cjs/{eas-DSZkoDUn.js → eas-D2E3_i_c.js} +3 -3
  20. package/dist/cjs/{eas-DSZkoDUn.js.map → eas-D2E3_i_c.js.map} +1 -1
  21. package/dist/cjs/{getItem-CPcdcFuS.js → getItem-B2zLVB_l.js} +2 -2
  22. package/dist/cjs/{getItem-CPcdcFuS.js.map → getItem-B2zLVB_l.js.map} +1 -1
  23. package/dist/cjs/{getPublishPayload-BvmVTKoc.js → getPublishPayload-Bv94k4ak.js} +11 -11
  24. package/dist/cjs/{getPublishPayload-BvmVTKoc.js.map → getPublishPayload-Bv94k4ak.js.map} +1 -1
  25. package/dist/cjs/{getPublishUploads-D2VZHZnu.js → getPublishUploads-CSbHUxYk.js} +4 -4
  26. package/dist/cjs/{getPublishUploads-D2VZHZnu.js.map → getPublishUploads-CSbHUxYk.js.map} +1 -1
  27. package/dist/cjs/{getSegmentedItemProperties-Bm1TEvBS.js → getSegmentedItemProperties-CMhXKQHz.js} +3 -3
  28. package/dist/cjs/{getSegmentedItemProperties-Bm1TEvBS.js.map → getSegmentedItemProperties-CMhXKQHz.js.map} +1 -1
  29. package/dist/cjs/{index-C-POwaLs.js → index-D-9WglxG.js} +190 -85
  30. package/dist/cjs/index-D-9WglxG.js.map +1 -0
  31. package/dist/cjs/{index-D_ph4zut.js → index-pSLjO-ch.js} +3 -3
  32. package/dist/cjs/index-pSLjO-ch.js.map +1 -0
  33. package/dist/cjs/{property-DkUtJxV2.js → property-gUK2PijH.js} +4 -4
  34. package/dist/cjs/{property-DkUtJxV2.js.map → property-gUK2PijH.js.map} +1 -1
  35. package/dist/cjs/{syncDbWithEas-DRoys7eo.js → syncDbWithEas-CYtl7VTD.js} +6 -6
  36. package/dist/cjs/{syncDbWithEas-DRoys7eo.js.map → syncDbWithEas-CYtl7VTD.js.map} +1 -1
  37. package/dist/{configurePlatform-Df4BlXwQ.js → configurePlatform-bGvKBBQy.js} +3 -3
  38. package/dist/{configurePlatform-Df4BlXwQ.js.map → configurePlatform-bGvKBBQy.js.map} +1 -1
  39. package/dist/{constants-CROrIRd-.js → constants-CTs2RUrM.js} +4 -2
  40. package/dist/{constants-CROrIRd-.js.map → constants-CTs2RUrM.js.map} +1 -1
  41. package/dist/{db-DVsy4QZe.js → db-YiH_kIpE.js} +13 -13
  42. package/dist/{db-DVsy4QZe.js.map → db-YiH_kIpE.js.map} +1 -1
  43. package/dist/{eas-z4W41ith.js → eas-1nUCcmeh.js} +4 -4
  44. package/dist/{eas-z4W41ith.js.map → eas-1nUCcmeh.js.map} +1 -1
  45. package/dist/{getItem-BiE_b7Fu.js → getItem-Bb8bTYzY.js} +5 -5
  46. package/dist/{getItem-BiE_b7Fu.js.map → getItem-Bb8bTYzY.js.map} +1 -1
  47. package/dist/{getPublishPayload-CuRGEZa5.js → getPublishPayload-BHw8mPSb.js} +14 -14
  48. package/dist/{getPublishPayload-CuRGEZa5.js.map → getPublishPayload-BHw8mPSb.js.map} +1 -1
  49. package/dist/{getPublishUploads-CMgzBCzZ.js → getPublishUploads-BYhckxFl.js} +7 -7
  50. package/dist/{getPublishUploads-CMgzBCzZ.js.map → getPublishUploads-BYhckxFl.js.map} +1 -1
  51. package/dist/{getSegmentedItemProperties-BCCSwTxr.js → getSegmentedItemProperties-B73nMPBv.js} +5 -5
  52. package/dist/{getSegmentedItemProperties-BCCSwTxr.js.map → getSegmentedItemProperties-B73nMPBv.js.map} +1 -1
  53. package/dist/{index-DjwIC6U3.js → index-CJNKYI37.js} +186 -106
  54. package/dist/index-CJNKYI37.js.map +1 -0
  55. package/dist/{index-xNWgPtlN.js → index-C_5xwOPQ.js} +2 -2
  56. package/dist/index-C_5xwOPQ.js.map +1 -0
  57. package/dist/{index-C41UZTmQ.js → index-DzgMt8ba.js} +7 -7
  58. package/dist/index-DzgMt8ba.js.map +1 -0
  59. package/dist/{index.node-DQZ3cPe-.js → index.node-ZLiBj9Cu.js} +4 -4
  60. package/dist/{index.node-DQZ3cPe-.js.map → index.node-ZLiBj9Cu.js.map} +1 -1
  61. package/dist/main.cjs +1 -1
  62. package/dist/main.js +21 -21
  63. package/dist/node.js +10 -10
  64. package/dist/platform.browser.js +149 -41
  65. package/dist/platform.browser.js.map +1 -1
  66. package/dist/platform.node.js +3 -3
  67. package/dist/{property-Bs3a4Dna.js → property-Dcb50seV.js} +7 -7
  68. package/dist/{property-Bs3a4Dna.js.map → property-Dcb50seV.js.map} +1 -1
  69. package/dist/src/browser/db/Db.d.ts +1 -1
  70. package/dist/src/browser/db/Db.d.ts.map +1 -1
  71. package/dist/src/browser/db/createSqlocalDrizzle.d.ts +21 -0
  72. package/dist/src/browser/db/createSqlocalDrizzle.d.ts.map +1 -0
  73. package/dist/src/browser/helpers/FileManager.d.ts +1 -1
  74. package/dist/src/browser/helpers/FileManager.d.ts.map +1 -1
  75. package/dist/src/client/ClientManager.d.ts +9 -5
  76. package/dist/src/client/ClientManager.d.ts.map +1 -1
  77. package/dist/src/client/actors/addModelsToDb.d.ts.map +1 -1
  78. package/dist/src/client/actors/addModelsToStore.d.ts.map +1 -1
  79. package/dist/src/client/actors/saveAppState.d.ts.map +1 -1
  80. package/dist/src/client/actors/saveConfig.d.ts.map +1 -1
  81. package/dist/src/client/clientManagerMachine.d.ts +1 -0
  82. package/dist/src/client/clientManagerMachine.d.ts.map +1 -1
  83. package/dist/src/client/coalesceInit.d.ts +7 -0
  84. package/dist/src/client/coalesceInit.d.ts.map +1 -0
  85. package/dist/src/client/constants.d.ts +3 -1
  86. package/dist/src/client/constants.d.ts.map +1 -1
  87. package/dist/src/helpers/FileManager/BaseFileManager.d.ts +7 -0
  88. package/dist/src/helpers/FileManager/BaseFileManager.d.ts.map +1 -1
  89. package/dist/src/types/machines.d.ts +1 -0
  90. package/dist/src/types/machines.d.ts.map +1 -1
  91. package/dist/{syncDbWithEas-DRpLRxwb.js → syncDbWithEas-B0RUeDuj.js} +10 -10
  92. package/dist/{syncDbWithEas-DRpLRxwb.js.map → syncDbWithEas-B0RUeDuj.js.map} +1 -1
  93. package/dist/{updateSeedRevokedAt-F0ZDvwOO.js → updateSeedRevokedAt-D5ZbBehZ.js} +2 -2
  94. package/dist/{updateSeedRevokedAt-F0ZDvwOO.js.map → updateSeedRevokedAt-D5ZbBehZ.js.map} +1 -1
  95. package/package.json +13 -5
  96. package/dist/BasePathResolver-0IHnXxtL.js.map +0 -1
  97. package/dist/cjs/index-C-POwaLs.js.map +0 -1
  98. package/dist/cjs/index-D_ph4zut.js.map +0 -1
  99. package/dist/index-C41UZTmQ.js.map +0 -1
  100. package/dist/index-DjwIC6U3.js.map +0 -1
  101. package/dist/index-xNWgPtlN.js.map +0 -1
@@ -152,14 +152,36 @@ class BaseFileManager {
152
152
  }
153
153
  return BaseFileManager._impl;
154
154
  }
155
- static async initializeFileSystem(workingDir) {
156
- if (this.initializing || this.fileSystemInitialized) {
155
+ /**
156
+ * Clears FS init flags so a later call can retry. Used after a failed init
157
+ * and by tests. Does not unmount or delete any files.
158
+ */
159
+ static resetInitializationState() {
160
+ this.fileSystemInitialized = false;
161
+ this.initializing = false;
162
+ this.initializePromise = null;
163
+ this.workingDir = undefined;
164
+ }
165
+ static initializeFileSystem(workingDir) {
166
+ if (this.fileSystemInitialized) {
157
167
  return Promise.resolve();
158
168
  }
169
+ if (this.initializePromise) {
170
+ return this.initializePromise;
171
+ }
159
172
  this.initializing = true;
173
+ const pending = this.runInitializeFileSystem(workingDir).finally(() => {
174
+ this.initializing = false;
175
+ if (this.initializePromise === pending) {
176
+ this.initializePromise = null;
177
+ }
178
+ });
179
+ this.initializePromise = pending;
180
+ return pending;
181
+ }
182
+ static async runInitializeFileSystem(workingDir) {
160
183
  await BaseFileManager.requireImpl().initializeFileSystem(workingDir);
161
184
  this.fileSystemInitialized = true;
162
- this.initializing = false;
163
185
  this.workingDir = workingDir;
164
186
  }
165
187
  static getWorkingDir() {
@@ -268,6 +290,7 @@ class BaseFileManager {
268
290
  BaseFileManager.fileSystemInitialized = false;
269
291
  BaseFileManager.initializing = false;
270
292
  BaseFileManager._impl = null;
293
+ BaseFileManager.initializePromise = null;
271
294
 
272
295
  var BaseFileManager$1 = /*#__PURE__*/Object.freeze({
273
296
  __proto__: null,
@@ -999,7 +1022,7 @@ const createPropertyInstances = async (propertyFileIds) => {
999
1022
  return;
1000
1023
  }
1001
1024
  try {
1002
- const mod = await Promise.resolve().then(function () { return require('./ModelProperty-DvIIhBnK.js'); });
1025
+ const mod = await Promise.resolve().then(function () { return require('./ModelProperty-alntkSnH.js'); });
1003
1026
  const ModelProperty = mod?.ModelProperty ?? mod?.default;
1004
1027
  if (!ModelProperty) {
1005
1028
  logger$v('createPropertyInstances: ModelProperty not available from dynamic import');
@@ -1183,7 +1206,7 @@ const loadOrCreateModel = xstate.fromCallback(({ sendBack, input: { context } })
1183
1206
  // Step 2: Fallback to Schema context (only if database doesn't have the model)
1184
1207
  // This handles the case where model exists in schema file but not yet in database
1185
1208
  try {
1186
- const schemaMod = await Promise.resolve().then(function () { return require('./Schema-FdzNqyGo.js'); });
1209
+ const schemaMod = await Promise.resolve().then(function () { return require('./Schema-ByFv6fcb.js'); });
1187
1210
  const { Schema } = schemaMod;
1188
1211
  const schema = Schema.create(schemaName, { waitForReady: false });
1189
1212
  const schemaSnapshot = schema.getService().getSnapshot();
@@ -1427,7 +1450,7 @@ const loadOrCreateModel = xstate.fromCallback(({ sendBack, input: { context } })
1427
1450
  }
1428
1451
  // Mark schema as draft when a new model is created so saveNewVersion() can persist it
1429
1452
  try {
1430
- const schemaMod = await Promise.resolve().then(function () { return require('./Schema-FdzNqyGo.js'); });
1453
+ const schemaMod = await Promise.resolve().then(function () { return require('./Schema-ByFv6fcb.js'); });
1431
1454
  const { Schema } = schemaMod;
1432
1455
  const schema = Schema.create(schemaName, { waitForReady: false });
1433
1456
  schema.getService().send({ type: 'markAsDraft', propertyKey: 'schema:models' });
@@ -1471,10 +1494,10 @@ const validateModel = xstate.fromCallback(({ sendBack, input: { context } }) =>
1471
1494
  const _validateModel = async () => {
1472
1495
  try {
1473
1496
  // Use dynamic imports to break circular dependencies
1474
- const validationServiceMod = await Promise.resolve().then(function () { return require('./SchemaValidationService-pxRoOs79.js'); });
1497
+ const validationServiceMod = await Promise.resolve().then(function () { return require('./SchemaValidationService-D55MWsxv.js'); });
1475
1498
  const { SchemaValidationService } = validationServiceMod;
1476
1499
  const validationService = new SchemaValidationService();
1477
- const schemaMod = await Promise.resolve().then(function () { return require('./Schema-FdzNqyGo.js'); });
1500
+ const schemaMod = await Promise.resolve().then(function () { return require('./Schema-ByFv6fcb.js'); });
1478
1501
  const { Schema } = schemaMod;
1479
1502
  // Validate model structure
1480
1503
  const structureResult = validationService.validateModelStructure(context);
@@ -1584,7 +1607,7 @@ const createModelProperties = xstate.fromCallback(({ sendBack, input }) => {
1584
1607
  return;
1585
1608
  }
1586
1609
  logger$t(`Creating ${Object.keys(propertyDefinitions).length} properties for model "${modelName}" (id: ${_dbId})`);
1587
- const mod = await Promise.resolve().then(function () { return require('./ModelProperty-DvIIhBnK.js'); });
1610
+ const mod = await Promise.resolve().then(function () { return require('./ModelProperty-alntkSnH.js'); });
1588
1611
  const ModelProperty = mod?.ModelProperty ?? mod?.default;
1589
1612
  if (!ModelProperty) {
1590
1613
  logger$t('ModelProperty not available from dynamic import');
@@ -1687,7 +1710,7 @@ const validateEntity = xstate.fromPromise(async ({ input }) => {
1687
1710
  const structureMsg = `[validateEntity] Validating model structure`;
1688
1711
  logger$s(structureMsg);
1689
1712
  // Use existing Model validation
1690
- const validationServiceMod = await Promise.resolve().then(function () { return require('./SchemaValidationService-pxRoOs79.js'); });
1713
+ const validationServiceMod = await Promise.resolve().then(function () { return require('./SchemaValidationService-D55MWsxv.js'); });
1691
1714
  const { SchemaValidationService } = validationServiceMod;
1692
1715
  const validationService = new SchemaValidationService();
1693
1716
  // Validate model structure
@@ -1705,7 +1728,7 @@ const validateEntity = xstate.fromPromise(async ({ input }) => {
1705
1728
  if (entityInput.entityData.schemaName) {
1706
1729
  try {
1707
1730
  logger$s(`[validateEntity] Validating model against schema "${entityInput.entityData.schemaName}"`);
1708
- const schemaMod = await Promise.resolve().then(function () { return require('./Schema-FdzNqyGo.js'); });
1731
+ const schemaMod = await Promise.resolve().then(function () { return require('./Schema-ByFv6fcb.js'); });
1709
1732
  const { Schema } = schemaMod;
1710
1733
  const schema = Schema.create(entityInput.entityData.schemaName, {
1711
1734
  waitForReady: false,
@@ -1741,7 +1764,7 @@ const validateEntity = xstate.fromPromise(async ({ input }) => {
1741
1764
  }
1742
1765
  else if (entityInput.entityType === 'modelProperty') {
1743
1766
  // Use existing ModelProperty validation
1744
- const validationServiceMod = await Promise.resolve().then(function () { return require('./SchemaValidationService-pxRoOs79.js'); });
1767
+ const validationServiceMod = await Promise.resolve().then(function () { return require('./SchemaValidationService-D55MWsxv.js'); });
1745
1768
  const { SchemaValidationService } = validationServiceMod;
1746
1769
  const validationService = new SchemaValidationService();
1747
1770
  // Validate property structure
@@ -1756,7 +1779,7 @@ const validateEntity = xstate.fromPromise(async ({ input }) => {
1756
1779
  // If schema name and model name provided, validate against schema
1757
1780
  if (entityInput.entityData._schemaName && entityInput.entityData.modelName) {
1758
1781
  try {
1759
- const schemaMod = await Promise.resolve().then(function () { return require('./Schema-FdzNqyGo.js'); });
1782
+ const schemaMod = await Promise.resolve().then(function () { return require('./Schema-ByFv6fcb.js'); });
1760
1783
  const { Schema } = schemaMod;
1761
1784
  const schema = Schema.create(entityInput.entityData._schemaName, {
1762
1785
  waitForReady: false,
@@ -1785,7 +1808,7 @@ const validateEntity = xstate.fromPromise(async ({ input }) => {
1785
1808
  }
1786
1809
  else if (entityInput.entityType === 'schema') {
1787
1810
  // Schema validation - use existing validation
1788
- const validationServiceMod = await Promise.resolve().then(function () { return require('./SchemaValidationService-pxRoOs79.js'); });
1811
+ const validationServiceMod = await Promise.resolve().then(function () { return require('./SchemaValidationService-D55MWsxv.js'); });
1789
1812
  const { SchemaValidationService } = validationServiceMod;
1790
1813
  const validationService = new SchemaValidationService();
1791
1814
  const schemaResult = validationService.validateSchema(entityInput.entityData);
@@ -3865,7 +3888,7 @@ const writeToDatabase = xstate.fromCallback(({ sendBack, input }) => {
3865
3888
  // initial write completes is not overwritten by the stale requestWrite payload.
3866
3889
  let dataToWrite = input.entityData;
3867
3890
  try {
3868
- const mod = await Promise.resolve().then(function () { return require('./ModelProperty-DvIIhBnK.js'); });
3891
+ const mod = await Promise.resolve().then(function () { return require('./ModelProperty-alntkSnH.js'); });
3869
3892
  const ModelProperty = mod?.ModelProperty ?? mod?.default;
3870
3893
  if (ModelProperty && typeof ModelProperty.getById === 'function') {
3871
3894
  const instance = ModelProperty.getById(input.entityId);
@@ -4245,7 +4268,7 @@ const modelMachine = xstate.setup({
4245
4268
  // Create ModelProperty instances for any new property IDs
4246
4269
  if (Array.isArray(newPropertyIds) && newPropertyIds.length > 0) {
4247
4270
  // Import and create instances asynchronously (fire-and-forget)
4248
- Promise.resolve().then(function () { return require('./ModelProperty-DvIIhBnK.js'); }).then(({ ModelProperty }) => {
4271
+ Promise.resolve().then(function () { return require('./ModelProperty-alntkSnH.js'); }).then(({ ModelProperty }) => {
4249
4272
  const createPromises = newPropertyIds.map(async (propertyFileId) => {
4250
4273
  try {
4251
4274
  const property = await ModelProperty.createById(propertyFileId);
@@ -4674,6 +4697,7 @@ exports.ClientManagerState = void 0;
4674
4697
  ClientManagerState["ADD_MODELS_TO_DB"] = "addModelsToDb";
4675
4698
  ClientManagerState["PROCESS_SCHEMA_FILES"] = "processSchemaFiles";
4676
4699
  ClientManagerState["IDLE"] = "idle";
4700
+ ClientManagerState["INIT_FAILED"] = "initFailed";
4677
4701
  })(exports.ClientManagerState || (exports.ClientManagerState = {}));
4678
4702
  var ClientManagerEvents;
4679
4703
  (function (ClientManagerEvents) {
@@ -4683,6 +4707,7 @@ var ClientManagerEvents;
4683
4707
  ClientManagerEvents["DB_READY"] = "dbReady";
4684
4708
  ClientManagerEvents["SAVE_CONFIG_SUCCESS"] = "saveConfigSuccess";
4685
4709
  ClientManagerEvents["SAVE_APP_STATE_SUCCESS"] = "saveAppStateSuccess";
4710
+ ClientManagerEvents["SAVE_APP_STATE_ERROR"] = "saveAppStateError";
4686
4711
  ClientManagerEvents["SET_ADDRESSES"] = "setAddresses";
4687
4712
  ClientManagerEvents["ADD_MODELS_TO_STORE_SUCCESS"] = "addModelsToStoreSuccess";
4688
4713
  ClientManagerEvents["ADD_MODELS_TO_DB_SUCCESS"] = "addModelsToDbSuccess";
@@ -5331,7 +5356,7 @@ const createItemPropertyInstances = async (metadataRows, seedLocalId, seedUid, m
5331
5356
  const schemaNameToTry = model$1?.schemaName;
5332
5357
  if (schemaNameToTry) {
5333
5358
  try {
5334
- const { Schema } = await Promise.resolve().then(function () { return require('./Schema-FdzNqyGo.js'); });
5359
+ const { Schema } = await Promise.resolve().then(function () { return require('./Schema-ByFv6fcb.js'); });
5335
5360
  const schemaInstance = Schema.create(schemaNameToTry, { waitForReady: false });
5336
5361
  const schemaContext = schemaInstance.getService().getSnapshot().context;
5337
5362
  if (schemaContext.models?.[modelName]?.properties) {
@@ -5380,7 +5405,7 @@ const createItemPropertyInstances = async (metadataRows, seedLocalId, seedUid, m
5380
5405
  }
5381
5406
  }
5382
5407
  if (Object.keys(propertySchemas).length === 0) {
5383
- const schemaMod = await Promise.resolve().then(function () { return require('./index-D_ph4zut.js'); });
5408
+ const schemaMod = await Promise.resolve().then(function () { return require('./index-pSLjO-ch.js'); });
5384
5409
  const { ModelPropertyDataTypes } = schemaMod;
5385
5410
  const KNOWN_MODEL_FALLBACKS = {
5386
5411
  Post: {
@@ -5427,7 +5452,7 @@ const createItemPropertyInstances = async (metadataRows, seedLocalId, seedUid, m
5427
5452
  // Infer propertyRecordSchema from metadata when schema is missing (enables persistence)
5428
5453
  let propSchema = propertySchemas[propertyName];
5429
5454
  if (!propSchema && isRefTypeFromMeta) {
5430
- const schemaMod = await Promise.resolve().then(function () { return require('./index-D_ph4zut.js'); });
5455
+ const schemaMod = await Promise.resolve().then(function () { return require('./index-pSLjO-ch.js'); });
5431
5456
  const { ModelPropertyDataTypes } = schemaMod;
5432
5457
  propSchema = {
5433
5458
  dataType: refSeedType === 'html' ? ModelPropertyDataTypes.Html
@@ -5684,9 +5709,9 @@ const runPublish = xstate.fromCallback(({ sendBack, input: { context } }) => {
5684
5709
  sendBack({ type: 'publishError', error: new Error(`Item not found for seedLocalId: ${seedLocalId}`) });
5685
5710
  return;
5686
5711
  }
5687
- const getPublishUploadsMod = await Promise.resolve().then(function () { return require('./getPublishUploads-D2VZHZnu.js'); });
5712
+ const getPublishUploadsMod = await Promise.resolve().then(function () { return require('./getPublishUploads-CSbHUxYk.js'); });
5688
5713
  const { getPublishUploads } = getPublishUploadsMod;
5689
- const getPublishPayloadMod = await Promise.resolve().then(function () { return require('./getPublishPayload-BvmVTKoc.js'); });
5714
+ const getPublishPayloadMod = await Promise.resolve().then(function () { return require('./getPublishPayload-Bv94k4ak.js'); });
5690
5715
  const { getPublishPayload } = getPublishPayloadMod;
5691
5716
  const uploads = await getPublishUploads(item);
5692
5717
  let uploadedTransactions = [];
@@ -6788,7 +6813,7 @@ const resolveRelatedValue = xstate.fromCallback(({ sendBack, input: { context }
6788
6813
  const { isRelation, propertyValue, propertyName, seedUid, propertyRecordSchema, populatedFromDb, schemaUid, } = context;
6789
6814
  const _resolveRelatedValue = async () => {
6790
6815
  // Use dynamic import to break circular dependency
6791
- const schemaMod = await Promise.resolve().then(function () { return require('./index-D_ph4zut.js'); });
6816
+ const schemaMod = await Promise.resolve().then(function () { return require('./index-pSLjO-ch.js'); });
6792
6817
  const { ModelPropertyDataTypes } = schemaMod;
6793
6818
  if (!propertyValue || !isRelation || populatedFromDb) {
6794
6819
  return;
@@ -7792,7 +7817,7 @@ const hydrateFromDb = xstate.fromCallback(({ sendBack, input: { context } }) =>
7792
7817
  // to use dynamically imported ModelPropertyDataTypes
7793
7818
  const _hydrateFromDb = async () => {
7794
7819
  // Use dynamic import to break circular dependency
7795
- const schemaMod = await Promise.resolve().then(function () { return require('./index-D_ph4zut.js'); });
7820
+ const schemaMod = await Promise.resolve().then(function () { return require('./index-pSLjO-ch.js'); });
7796
7821
  const { ModelPropertyDataTypes } = schemaMod;
7797
7822
  const appDb = BaseDb.getAppDb();
7798
7823
  const whereClauses = [];
@@ -8155,7 +8180,7 @@ const loadOrCreateProperty = xstate.fromCallback(({ sendBack, input: { context }
8155
8180
  };
8156
8181
  // Merge with schema from file/DB to get validation rules (enum, pattern, etc.) - properties table doesn't store these
8157
8182
  try {
8158
- const { getPropertySchema } = await Promise.resolve().then(function () { return require('./property-DkUtJxV2.js'); });
8183
+ const { getPropertySchema } = await Promise.resolve().then(function () { return require('./property-gUK2PijH.js'); });
8159
8184
  let schemaFromFile = await getPropertySchema(normalizedModelName, propertyName);
8160
8185
  if (!schemaFromFile?.validation) {
8161
8186
  // Fallback: get validation from schemaData in database (Schema context may not be loaded yet)
@@ -8620,9 +8645,9 @@ const analyzeInput = xstate.fromCallback(({ sendBack, input: { context, event }
8620
8645
  }
8621
8646
  const _analyzeInput = async () => {
8622
8647
  // Use dynamic import to break circular dependency
8623
- const schemaMod = await Promise.resolve().then(function () { return require('./index-D_ph4zut.js'); });
8648
+ const schemaMod = await Promise.resolve().then(function () { return require('./index-pSLjO-ch.js'); });
8624
8649
  const { ModelPropertyDataTypes } = schemaMod;
8625
- const { SchemaValidationService } = await Promise.resolve().then(function () { return require('./SchemaValidationService-pxRoOs79.js'); });
8650
+ const { SchemaValidationService } = await Promise.resolve().then(function () { return require('./SchemaValidationService-D55MWsxv.js'); });
8626
8651
  let propertyName = propertyNameRaw;
8627
8652
  if (!propertyName) {
8628
8653
  throw new Error('propertyName is required');
@@ -8820,7 +8845,7 @@ const createMetadata = async (metadataValues, propertyRecordSchema, options) =>
8820
8845
  propertyRecordSchema?.validation &&
8821
8846
  metadataValues.propertyValue != null &&
8822
8847
  metadataValues.propertyValue !== '') {
8823
- const { SchemaValidationService } = await Promise.resolve().then(function () { return require('./SchemaValidationService-pxRoOs79.js'); });
8848
+ const { SchemaValidationService } = await Promise.resolve().then(function () { return require('./SchemaValidationService-D55MWsxv.js'); });
8824
8849
  const validationService = new SchemaValidationService();
8825
8850
  const validationResult = validationService.validatePropertyValue(metadataValues.propertyValue, normalizeDataType(propertyRecordSchema.dataType), propertyRecordSchema.validation, propertyRecordSchema.refValueType
8826
8851
  ? normalizeDataType(String(propertyRecordSchema.refValueType))
@@ -9413,7 +9438,7 @@ const saveRelation = xstate.fromCallback(({ sendBack, input: { context, event }
9413
9438
  }
9414
9439
  const _saveRelation = async () => {
9415
9440
  // Use dynamic import to break circular dependency
9416
- const schemaMod = await Promise.resolve().then(function () { return require('./index-D_ph4zut.js'); });
9441
+ const schemaMod = await Promise.resolve().then(function () { return require('./index-pSLjO-ch.js'); });
9417
9442
  const { ModelPropertyDataTypes } = schemaMod;
9418
9443
  if (!propertyNameRaw) {
9419
9444
  throw new Error('propertyName is required');
@@ -10368,7 +10393,7 @@ class ItemProperty {
10368
10393
  return;
10369
10394
  }
10370
10395
  // Use dynamic import to break circular dependency
10371
- const schemaMod = await Promise.resolve().then(function () { return require('./index-D_ph4zut.js'); });
10396
+ const schemaMod = await Promise.resolve().then(function () { return require('./index-pSLjO-ch.js'); });
10372
10397
  const { ModelPropertyDataTypes } = schemaMod;
10373
10398
  const { context } = snapshot;
10374
10399
  const { propertyRecordSchema } = context;
@@ -11677,12 +11702,12 @@ class Item {
11677
11702
  };
11678
11703
  this.getPublishUploads = async (options) => {
11679
11704
  // Use dynamic import to break circular dependency
11680
- const getPublishUploadsMod = await Promise.resolve().then(function () { return require('./getPublishUploads-D2VZHZnu.js'); });
11705
+ const getPublishUploadsMod = await Promise.resolve().then(function () { return require('./getPublishUploads-CSbHUxYk.js'); });
11681
11706
  const { getPublishUploads } = getPublishUploadsMod;
11682
11707
  return await getPublishUploads(this, [], undefined, options);
11683
11708
  };
11684
11709
  this.getPublishPayload = async (uploadedTransactions, options) => {
11685
- const getPublishPayloadMod = await Promise.resolve().then(function () { return require('./getPublishPayload-BvmVTKoc.js'); });
11710
+ const getPublishPayloadMod = await Promise.resolve().then(function () { return require('./getPublishPayload-Bv94k4ak.js'); });
11686
11711
  const { getPublishPayload } = getPublishPayloadMod;
11687
11712
  return await getPublishPayload(this, uploadedTransactions, options);
11688
11713
  };
@@ -13339,7 +13364,7 @@ const runEasSync = xstate.fromPromise(async ({ input, }) => {
13339
13364
  requestPayload: input.requestPayload,
13340
13365
  persistedSnapshot: input.runningSnapshot,
13341
13366
  });
13342
- const { runSyncFromEas } = await Promise.resolve().then(function () { return require('./syncDbWithEas-DRoys7eo.js'); });
13367
+ const { runSyncFromEas } = await Promise.resolve().then(function () { return require('./syncDbWithEas-CYtl7VTD.js'); });
13343
13368
  try {
13344
13369
  await runSyncFromEas(toRunSyncArg(input.options));
13345
13370
  await finalizeEasSyncProcessRow(rowId, {
@@ -13860,7 +13885,12 @@ const saveAppState = xstate.fromCallback(({ sendBack, input: { key, value } }) =
13860
13885
  });
13861
13886
  }
13862
13887
  else {
13863
- throw error;
13888
+ sendBack({
13889
+ type: 'saveAppStateError',
13890
+ error: error instanceof Error ? error : new Error(String(error)),
13891
+ key,
13892
+ value,
13893
+ });
13864
13894
  }
13865
13895
  });
13866
13896
  });
@@ -13940,7 +13970,7 @@ const dbInit = xstate.fromCallback(({ sendBack, input: { context } }) => {
13940
13970
  .catch((error) => {
13941
13971
  logger$a('Error in dbInit:', error);
13942
13972
  sendBack({
13943
- type: 'ERROR',
13973
+ type: 'error',
13944
13974
  error: error instanceof Error ? error : new Error(String(error))
13945
13975
  });
13946
13976
  });
@@ -13963,8 +13993,16 @@ const addModelsToStore = xstate.fromCallback(({ sendBack, input: { context } })
13963
13993
  logger$9('model available:', key);
13964
13994
  }
13965
13995
  };
13966
- _addModelsToStore().then(() => {
13996
+ _addModelsToStore()
13997
+ .then(() => {
13967
13998
  sendBack({ type: ClientManagerEvents.ADD_MODELS_TO_STORE_SUCCESS });
13999
+ })
14000
+ .catch((error) => {
14001
+ logger$9('[client/actors] [addModelsToStore] Error:', error);
14002
+ sendBack({
14003
+ type: 'error',
14004
+ error: error instanceof Error ? error : new Error(String(error)),
14005
+ });
13968
14006
  });
13969
14007
  });
13970
14008
 
@@ -14094,7 +14132,10 @@ const addModelsToDb = xstate.fromCallback(({ sendBack, input: { context } }) =>
14094
14132
  sendBack({ type: ClientManagerEvents.ADD_MODELS_TO_DB_SUCCESS });
14095
14133
  }
14096
14134
  else {
14097
- throw error;
14135
+ sendBack({
14136
+ type: 'error',
14137
+ error: error instanceof Error ? error : new Error(String(error)),
14138
+ });
14098
14139
  }
14099
14140
  });
14100
14141
  return () => { };
@@ -14206,7 +14247,10 @@ const saveConfig = xstate.fromCallback(({ sendBack, input: { context } }) => {
14206
14247
  sendBack({ type: ClientManagerEvents.SAVE_CONFIG_SUCCESS });
14207
14248
  }
14208
14249
  else {
14209
- throw error;
14250
+ sendBack({
14251
+ type: 'error',
14252
+ error: error instanceof Error ? error : new Error(String(error)),
14253
+ });
14210
14254
  }
14211
14255
  });
14212
14256
  return () => { };
@@ -16684,8 +16728,8 @@ function parseAddressesPersistedPayload(value) {
16684
16728
  return { owned, watched };
16685
16729
  }
16686
16730
 
16687
- const { UNINITIALIZED, PLATFORM_CLASSES_INIT, FILE_SYSTEM_INIT, DB_INIT, SAVE_CONFIG, PROCESS_SCHEMA_FILES, ADD_MODELS_TO_STORE, ADD_MODELS_TO_DB, IDLE, } = exports.ClientManagerState;
16688
- const { UPDATE_CONTEXT, PLATFORM_CLASSES_READY, FILE_SYSTEM_READY, DB_READY, SAVE_CONFIG_SUCCESS, SAVE_APP_STATE_SUCCESS, SET_ADDRESSES, ADD_MODELS_TO_STORE_SUCCESS, ADD_MODELS_TO_DB_SUCCESS, PROCESS_SCHEMA_FILES_SUCCESS, } = ClientManagerEvents;
16731
+ const { UNINITIALIZED, PLATFORM_CLASSES_INIT, FILE_SYSTEM_INIT, DB_INIT, SAVE_CONFIG, PROCESS_SCHEMA_FILES, ADD_MODELS_TO_STORE, ADD_MODELS_TO_DB, IDLE, INIT_FAILED, } = exports.ClientManagerState;
16732
+ const { UPDATE_CONTEXT, PLATFORM_CLASSES_READY, FILE_SYSTEM_READY, DB_READY, SAVE_CONFIG_SUCCESS, SAVE_APP_STATE_SUCCESS, SAVE_APP_STATE_ERROR, SET_ADDRESSES, ADD_MODELS_TO_STORE_SUCCESS, ADD_MODELS_TO_DB_SUCCESS, PROCESS_SCHEMA_FILES_SUCCESS, } = ClientManagerEvents;
16689
16733
  const logSyncAfterAddressSave = debug("seedSdk:client:clientManagerMachine:syncAfterAddressSave");
16690
16734
  function addressesFromPersistedAddressValue(value) {
16691
16735
  if (!value || typeof value !== "object")
@@ -16729,7 +16773,14 @@ function emitAddressesPersistedIfAddressesKey(event) {
16729
16773
  const payload = parseAddressesPersistedPayload(event.value);
16730
16774
  eventEmitter.emit(ADDRESSES_PERSISTED_EVENT, payload);
16731
16775
  }
16732
- const clientManagerMachine = xstate.setup({
16776
+ function errorFromEvent(event, fallbackMessage) {
16777
+ const error = event?.error;
16778
+ if (error instanceof Error) {
16779
+ return error;
16780
+ }
16781
+ return new Error(String(error ?? fallbackMessage));
16782
+ }
16783
+ const clientManagerSetup = xstate.setup({
16733
16784
  types: {
16734
16785
  context: {},
16735
16786
  input: {},
@@ -16744,7 +16795,18 @@ const clientManagerMachine = xstate.setup({
16744
16795
  addModelsToDb,
16745
16796
  processSchemaFiles,
16746
16797
  },
16747
- }).createMachine({
16798
+ });
16799
+ function assignInitError(fallbackMessage) {
16800
+ return clientManagerSetup.assign(({ event }) => ({
16801
+ initError: errorFromEvent(event, fallbackMessage),
16802
+ isInitialized: false,
16803
+ }));
16804
+ }
16805
+ const failInit = (fallbackMessage) => ({
16806
+ target: INIT_FAILED,
16807
+ actions: assignInitError(fallbackMessage),
16808
+ });
16809
+ const clientManagerMachine = clientManagerSetup.createMachine({
16748
16810
  id: MachineIds.CLIENT_MANAGER,
16749
16811
  initial: UNINITIALIZED,
16750
16812
  context: ({ input }) => input,
@@ -16762,6 +16824,7 @@ const clientManagerMachine = xstate.setup({
16762
16824
  actions: xstate.assign({
16763
16825
  isInitialized: false,
16764
16826
  initError: undefined,
16827
+ saveError: undefined,
16765
16828
  }),
16766
16829
  },
16767
16830
  },
@@ -16778,16 +16841,7 @@ const clientManagerMachine = xstate.setup({
16778
16841
  [PLATFORM_CLASSES_READY]: {
16779
16842
  target: FILE_SYSTEM_INIT,
16780
16843
  },
16781
- error: {
16782
- actions: xstate.assign(({ event }) => {
16783
- const error = event.error instanceof Error
16784
- ? event.error
16785
- : new Error(String(event.error || 'Platform classes initialization failed'));
16786
- return {
16787
- initError: error,
16788
- };
16789
- }),
16790
- },
16844
+ error: failInit('Platform classes initialization failed'),
16791
16845
  },
16792
16846
  invoke: {
16793
16847
  src: 'platformClassesInit',
@@ -16795,6 +16849,7 @@ const clientManagerMachine = xstate.setup({
16795
16849
  event: event,
16796
16850
  context
16797
16851
  }),
16852
+ onError: failInit('Platform classes initialization failed'),
16798
16853
  },
16799
16854
  },
16800
16855
  [FILE_SYSTEM_INIT]: {
@@ -16802,19 +16857,12 @@ const clientManagerMachine = xstate.setup({
16802
16857
  [FILE_SYSTEM_READY]: {
16803
16858
  target: DB_INIT,
16804
16859
  },
16805
- error: {
16806
- target: IDLE,
16807
- actions: xstate.assign(({ event }) => {
16808
- const error = event.error instanceof Error
16809
- ? event.error
16810
- : new Error(String(event.error ?? 'File system initialization failed'));
16811
- return { initError: error };
16812
- }),
16813
- },
16860
+ error: failInit('File system initialization failed'),
16814
16861
  },
16815
16862
  invoke: {
16816
16863
  src: 'fileSystemInit',
16817
16864
  input: ({ context }) => ({ context }),
16865
+ onError: failInit('File system initialization failed'),
16818
16866
  },
16819
16867
  },
16820
16868
  [DB_INIT]: {
@@ -16822,10 +16870,12 @@ const clientManagerMachine = xstate.setup({
16822
16870
  [DB_READY]: {
16823
16871
  target: SAVE_CONFIG,
16824
16872
  },
16873
+ error: failInit('Database initialization failed'),
16825
16874
  },
16826
16875
  invoke: {
16827
16876
  src: 'dbInit',
16828
16877
  input: ({ context }) => ({ context }),
16878
+ onError: failInit('Database initialization failed'),
16829
16879
  },
16830
16880
  },
16831
16881
  [SAVE_CONFIG]: {
@@ -16833,10 +16883,12 @@ const clientManagerMachine = xstate.setup({
16833
16883
  [SAVE_CONFIG_SUCCESS]: {
16834
16884
  target: PROCESS_SCHEMA_FILES,
16835
16885
  },
16886
+ error: failInit('Saving config failed'),
16836
16887
  },
16837
16888
  invoke: {
16838
16889
  src: 'saveConfig',
16839
16890
  input: ({ context }) => ({ context }),
16891
+ onError: failInit('Saving config failed'),
16840
16892
  },
16841
16893
  },
16842
16894
  [PROCESS_SCHEMA_FILES]: {
@@ -16844,19 +16896,12 @@ const clientManagerMachine = xstate.setup({
16844
16896
  [PROCESS_SCHEMA_FILES_SUCCESS]: {
16845
16897
  target: ADD_MODELS_TO_STORE,
16846
16898
  },
16847
- error: {
16848
- target: IDLE,
16849
- actions: xstate.assign(({ event }) => {
16850
- const error = event.error instanceof Error
16851
- ? event.error
16852
- : new Error(String(event.error || 'Schema processing failed'));
16853
- return { initError: error };
16854
- }),
16855
- },
16899
+ error: failInit('Schema processing failed'),
16856
16900
  },
16857
16901
  invoke: {
16858
16902
  src: 'processSchemaFiles',
16859
16903
  input: ({ context }) => ({ context }),
16904
+ onError: failInit('Schema processing failed'),
16860
16905
  },
16861
16906
  },
16862
16907
  [ADD_MODELS_TO_STORE]: {
@@ -16864,10 +16909,12 @@ const clientManagerMachine = xstate.setup({
16864
16909
  [ADD_MODELS_TO_STORE_SUCCESS]: {
16865
16910
  target: ADD_MODELS_TO_DB,
16866
16911
  },
16912
+ error: failInit('Adding models to store failed'),
16867
16913
  },
16868
16914
  invoke: {
16869
16915
  src: 'addModelsToStore',
16870
16916
  input: ({ context }) => ({ context }),
16917
+ onError: failInit('Adding models to store failed'),
16871
16918
  },
16872
16919
  },
16873
16920
  [ADD_MODELS_TO_DB]: {
@@ -16875,10 +16922,27 @@ const clientManagerMachine = xstate.setup({
16875
16922
  [ADD_MODELS_TO_DB_SUCCESS]: {
16876
16923
  target: IDLE,
16877
16924
  },
16925
+ error: failInit('Adding models to database failed'),
16878
16926
  },
16879
16927
  invoke: {
16880
16928
  src: 'addModelsToDb',
16881
16929
  input: ({ context }) => ({ context }),
16930
+ onError: failInit('Adding models to database failed'),
16931
+ },
16932
+ },
16933
+ [INIT_FAILED]: {
16934
+ entry: xstate.assign({
16935
+ isInitialized: false,
16936
+ }),
16937
+ on: {
16938
+ init: {
16939
+ target: PLATFORM_CLASSES_INIT,
16940
+ actions: xstate.assign({
16941
+ isInitialized: false,
16942
+ initError: undefined,
16943
+ saveError: undefined,
16944
+ }),
16945
+ },
16882
16946
  },
16883
16947
  },
16884
16948
  [IDLE]: {
@@ -16888,9 +16952,10 @@ const clientManagerMachine = xstate.setup({
16888
16952
  on: {
16889
16953
  [SAVE_APP_STATE_SUCCESS]: {
16890
16954
  actions: [
16891
- xstate.assign(({ event }) => {
16955
+ xstate.assign(() => {
16892
16956
  return {
16893
16957
  isSaving: false,
16958
+ saveError: undefined,
16894
16959
  };
16895
16960
  }),
16896
16961
  ({ context, event }) => maybeRunSyncFromEasAfterAddressSave({
@@ -16900,6 +16965,12 @@ const clientManagerMachine = xstate.setup({
16900
16965
  ({ event }) => emitAddressesPersistedIfAddressesKey(event),
16901
16966
  ],
16902
16967
  },
16968
+ [SAVE_APP_STATE_ERROR]: {
16969
+ actions: xstate.assign(({ event }) => ({
16970
+ isSaving: false,
16971
+ saveError: errorFromEvent(event, 'Failed to save app state'),
16972
+ })),
16973
+ },
16903
16974
  [SET_ADDRESSES]: {
16904
16975
  actions: [
16905
16976
  xstate.assign(({ event, spawn }) => {
@@ -16916,6 +16987,7 @@ const clientManagerMachine = xstate.setup({
16916
16987
  ownedAddresses: normalized.owned,
16917
16988
  watchedAddresses: normalized.watched,
16918
16989
  isSaving: true,
16990
+ saveError: undefined,
16919
16991
  };
16920
16992
  })
16921
16993
  ],
@@ -16924,6 +16996,8 @@ const clientManagerMachine = xstate.setup({
16924
16996
  target: PLATFORM_CLASSES_INIT,
16925
16997
  actions: xstate.assign({
16926
16998
  isInitialized: false,
16999
+ initError: undefined,
17000
+ saveError: undefined,
16927
17001
  }),
16928
17002
  },
16929
17003
  },
@@ -16931,6 +17005,30 @@ const clientManagerMachine = xstate.setup({
16931
17005
  },
16932
17006
  });
16933
17007
 
17008
+ /**
17009
+ * Coalesce overlapping async init calls onto one in-flight promise.
17010
+ * Skip when already successfully ready. Always clear in-flight on settle
17011
+ * so a failed init can be retried.
17012
+ */
17013
+ function createCoalescedAsync(run, shouldSkip) {
17014
+ let inFlight = null;
17015
+ return (arg) => {
17016
+ if (inFlight) {
17017
+ return inFlight;
17018
+ }
17019
+ if (shouldSkip(arg)) {
17020
+ return Promise.resolve();
17021
+ }
17022
+ const pending = run(arg).finally(() => {
17023
+ if (inFlight === pending) {
17024
+ inFlight = null;
17025
+ }
17026
+ });
17027
+ inFlight = pending;
17028
+ return pending;
17029
+ };
17030
+ }
17031
+
16934
17032
  function msToUnixSeconds(ms) {
16935
17033
  if (ms == null || !Number.isFinite(ms))
16936
17034
  return 0;
@@ -17479,7 +17577,7 @@ const clientInstance = {
17479
17577
  // ensureInitialized();
17480
17578
  return clientManager;
17481
17579
  },
17482
- init: async (options) => {
17580
+ init: createCoalescedAsync(async (options) => {
17483
17581
  // If the actor is stopped (e.g., from a previous failed test), restart it
17484
17582
  const snapshot = clientManager.getSnapshot();
17485
17583
  const currentState = snapshot.value;
@@ -17515,6 +17613,7 @@ const clientInstance = {
17515
17613
  filesDir: undefined,
17516
17614
  dbConfig: undefined,
17517
17615
  initError: undefined,
17616
+ saveError: undefined,
17518
17617
  }
17519
17618
  });
17520
17619
  // Wait a moment for the context update to be processed
@@ -17537,15 +17636,12 @@ const clientInstance = {
17537
17636
  }
17538
17637
  try {
17539
17638
  await xstate.waitFor(clientManager, (snapshot) => {
17540
- // Check for errors in context (for cases where error is set but state hasn't transitioned yet)
17541
- if (snapshot.context.initError) {
17542
- const error = snapshot.context.initError instanceof Error
17543
- ? snapshot.context.initError
17544
- : new Error(String(snapshot.context.initError));
17545
- throw error;
17546
- }
17547
- return snapshot.context.isInitialized;
17639
+ return snapshot.context.isInitialized || snapshot.context.initError != null;
17548
17640
  }, { timeout: 120000 });
17641
+ const initError = clientManager.getSnapshot().context.initError;
17642
+ if (initError) {
17643
+ throw initError instanceof Error ? initError : new Error(String(initError));
17644
+ }
17549
17645
  }
17550
17646
  catch (error) {
17551
17647
  // Ensure we never throw undefined
@@ -17556,12 +17652,21 @@ const clientInstance = {
17556
17652
  }
17557
17653
  // Wire `@seedprotocol/query` local source once DB is ready
17558
17654
  registerSeedQueryLocalSource();
17559
- },
17655
+ }, () => {
17656
+ const snapshot = clientManager.getSnapshot();
17657
+ return (snapshot.value === exports.ClientManagerState.IDLE &&
17658
+ snapshot.context.isInitialized === true &&
17659
+ !snapshot.context.initError);
17660
+ }),
17560
17661
  setAddresses: async (addresses) => {
17561
17662
  ensureInitialized();
17562
17663
  logger$3('setAddresses', addresses);
17563
17664
  clientManager.send({ type: 'setAddresses', addresses });
17564
17665
  await xstate.waitFor(clientManager, (snapshot) => !snapshot.context.isSaving, { timeout: 10000 });
17666
+ const saveError = clientManager.getSnapshot().context.saveError;
17667
+ if (saveError) {
17668
+ throw saveError instanceof Error ? saveError : new Error(String(saveError));
17669
+ }
17565
17670
  logger$3('setAddresses success', addresses);
17566
17671
  },
17567
17672
  getAddresses: async () => {
@@ -17837,7 +17942,7 @@ const saveDraftLogger = debug('seedSdk:model:saveDraftToDb');
17837
17942
  // Lazy import cache for ModelProperty to avoid circular dependency
17838
17943
  // Eagerly start loading to minimize delay on first access
17839
17944
  let ModelPropertyClass = null;
17840
- const modelPropertyImportPromise = Promise.resolve().then(function () { return require('./ModelProperty-DvIIhBnK.js'); })
17945
+ const modelPropertyImportPromise = Promise.resolve().then(function () { return require('./ModelProperty-alntkSnH.js'); })
17841
17946
  .then(module => {
17842
17947
  ModelPropertyClass = module.ModelProperty;
17843
17948
  return ModelPropertyClass;
@@ -17854,7 +17959,7 @@ function getModelProperty() {
17854
17959
  }
17855
17960
  // Lazy import cache for Schema to avoid circular dependency
17856
17961
  let SchemaClass = null;
17857
- const schemaImportPromise = Promise.resolve().then(function () { return require('./Schema-FdzNqyGo.js'); })
17962
+ const schemaImportPromise = Promise.resolve().then(function () { return require('./Schema-ByFv6fcb.js'); })
17858
17963
  .then(module => {
17859
17964
  SchemaClass = module.Schema;
17860
17965
  return SchemaClass;
@@ -19756,7 +19861,7 @@ function resolveSdkDrizzleMigrationsDir(sdkRootDir) {
19756
19861
  })();
19757
19862
  // Also resolve relative to this module so temp-cwd tests / odd roots still find
19758
19863
  // packages/sdk/src/db/drizzle (or dist/db/drizzle after publish).
19759
- 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-C-POwaLs.js', document.baseURI).href))));
19864
+ 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-D-9WglxG.js', document.baseURI).href))));
19760
19865
  const candidates = [
19761
19866
  path.join(root, 'db', 'drizzle'), // production: sdkRoot is dist/
19762
19867
  path.join(root, 'dist', 'db', 'drizzle'), // sdk package root with built dist
@@ -19826,7 +19931,7 @@ class NodeDb {
19826
19931
  logger$1('[Db.prepareDb] running migrations from %s', outDir);
19827
19932
  await migrator.migrate(db, { migrationsFolder: outDir });
19828
19933
  this.db = db;
19829
- const { backfillMetadataPropertyIds } = await Promise.resolve().then(function () { return require('./backfillMetadataPropertyIds-D0o5VwBh.js'); });
19934
+ const { backfillMetadataPropertyIds } = await Promise.resolve().then(function () { return require('./backfillMetadataPropertyIds-DrrL5RqD.js'); });
19830
19935
  await backfillMetadataPropertyIds();
19831
19936
  return this.db;
19832
19937
  }
@@ -20417,4 +20522,4 @@ exports.versions = versions;
20417
20522
  exports.waitForEntityIdle = waitForEntityIdle;
20418
20523
  exports.withSeed = withSeed;
20419
20524
  exports.writeProcessMachine = writeProcessMachine;
20420
- //# sourceMappingURL=index-C-POwaLs.js.map
20525
+ //# sourceMappingURL=index-D-9WglxG.js.map