@seedprotocol/sdk 0.6.3 → 0.6.5

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 (97) 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-BKvUJGud.js} +20 -20
  4. package/dist/{ModelProperty-BiDQu5rE.js.map → ModelProperty-BKvUJGud.js.map} +1 -1
  5. package/dist/{Schema-qciDB7Nu.js → Schema-BBh7ZhRk.js} +25 -25
  6. package/dist/{Schema-qciDB7Nu.js.map → Schema-BBh7ZhRk.js.map} +1 -1
  7. package/dist/{SchemaValidationService-BaOkRjsU.js → SchemaValidationService-BnJ43zov.js} +5 -5
  8. package/dist/{SchemaValidationService-BaOkRjsU.js.map → SchemaValidationService-BnJ43zov.js.map} +1 -1
  9. package/dist/{backfillMetadataPropertyIds-oypxoBXv.js → backfillMetadataPropertyIds-BEryy6Mu.js} +3 -3
  10. package/dist/{backfillMetadataPropertyIds-oypxoBXv.js.map → backfillMetadataPropertyIds-BEryy6Mu.js.map} +1 -1
  11. package/dist/cjs/{ModelProperty-DvIIhBnK.js → ModelProperty-CGjXNHFW.js} +17 -17
  12. package/dist/cjs/{ModelProperty-DvIIhBnK.js.map → ModelProperty-CGjXNHFW.js.map} +1 -1
  13. package/dist/cjs/{Schema-FdzNqyGo.js → Schema-CLMqGTHn.js} +20 -20
  14. package/dist/cjs/{Schema-FdzNqyGo.js.map → Schema-CLMqGTHn.js.map} +1 -1
  15. package/dist/cjs/{SchemaValidationService-pxRoOs79.js → SchemaValidationService-BnS8o5FK.js} +2 -2
  16. package/dist/cjs/{SchemaValidationService-pxRoOs79.js.map → SchemaValidationService-BnS8o5FK.js.map} +1 -1
  17. package/dist/cjs/{backfillMetadataPropertyIds-D0o5VwBh.js → backfillMetadataPropertyIds-B3xNIFjQ.js} +2 -2
  18. package/dist/cjs/{backfillMetadataPropertyIds-D0o5VwBh.js.map → backfillMetadataPropertyIds-B3xNIFjQ.js.map} +1 -1
  19. package/dist/cjs/{eas-DSZkoDUn.js → eas-wqfFyiti.js} +3 -3
  20. package/dist/cjs/{eas-DSZkoDUn.js.map → eas-wqfFyiti.js.map} +1 -1
  21. package/dist/cjs/{getItem-CPcdcFuS.js → getItem-BbEWSf4-.js} +2 -2
  22. package/dist/cjs/{getItem-CPcdcFuS.js.map → getItem-BbEWSf4-.js.map} +1 -1
  23. package/dist/cjs/{getPublishPayload-BvmVTKoc.js → getPublishPayload-i3UrBhza.js} +11 -11
  24. package/dist/cjs/{getPublishPayload-BvmVTKoc.js.map → getPublishPayload-i3UrBhza.js.map} +1 -1
  25. package/dist/cjs/{getPublishUploads-D2VZHZnu.js → getPublishUploads-CHhrLQmE.js} +4 -4
  26. package/dist/cjs/{getPublishUploads-D2VZHZnu.js.map → getPublishUploads-CHhrLQmE.js.map} +1 -1
  27. package/dist/cjs/{getSegmentedItemProperties-Bm1TEvBS.js → getSegmentedItemProperties-ZlOTqI0r.js} +3 -3
  28. package/dist/cjs/{getSegmentedItemProperties-Bm1TEvBS.js.map → getSegmentedItemProperties-ZlOTqI0r.js.map} +1 -1
  29. package/dist/cjs/{index-C-POwaLs.js → index-Bx8ReSFI.js} +192 -83
  30. package/dist/cjs/index-Bx8ReSFI.js.map +1 -0
  31. package/dist/cjs/{index-D_ph4zut.js → index-DBGNShZR.js} +3 -3
  32. package/dist/cjs/index-DBGNShZR.js.map +1 -0
  33. package/dist/cjs/{property-DkUtJxV2.js → property-CWZoijFu.js} +4 -4
  34. package/dist/cjs/{property-DkUtJxV2.js.map → property-CWZoijFu.js.map} +1 -1
  35. package/dist/cjs/{syncDbWithEas-DRoys7eo.js → syncDbWithEas-DRbf_wzk.js} +6 -6
  36. package/dist/cjs/{syncDbWithEas-DRoys7eo.js.map → syncDbWithEas-DRbf_wzk.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-CbeA8ykN.js} +13 -13
  42. package/dist/{db-DVsy4QZe.js.map → db-CbeA8ykN.js.map} +1 -1
  43. package/dist/{eas-z4W41ith.js → eas-CDANhqoz.js} +4 -4
  44. package/dist/{eas-z4W41ith.js.map → eas-CDANhqoz.js.map} +1 -1
  45. package/dist/{getItem-BiE_b7Fu.js → getItem-CUOCDTe8.js} +5 -5
  46. package/dist/{getItem-BiE_b7Fu.js.map → getItem-CUOCDTe8.js.map} +1 -1
  47. package/dist/{getPublishPayload-CuRGEZa5.js → getPublishPayload-0ntIkzv8.js} +14 -14
  48. package/dist/{getPublishPayload-CuRGEZa5.js.map → getPublishPayload-0ntIkzv8.js.map} +1 -1
  49. package/dist/{getPublishUploads-CMgzBCzZ.js → getPublishUploads-DLeAkS2m.js} +7 -7
  50. package/dist/{getPublishUploads-CMgzBCzZ.js.map → getPublishUploads-DLeAkS2m.js.map} +1 -1
  51. package/dist/{getSegmentedItemProperties-BCCSwTxr.js → getSegmentedItemProperties-C0rMewcl.js} +5 -5
  52. package/dist/{getSegmentedItemProperties-BCCSwTxr.js.map → getSegmentedItemProperties-C0rMewcl.js.map} +1 -1
  53. package/dist/{index-DjwIC6U3.js → index-BMeU7u_g.js} +188 -104
  54. package/dist/index-BMeU7u_g.js.map +1 -0
  55. package/dist/{index-C41UZTmQ.js → index-CQIlolE1.js} +7 -7
  56. package/dist/index-CQIlolE1.js.map +1 -0
  57. package/dist/{index-xNWgPtlN.js → index-C_5xwOPQ.js} +2 -2
  58. package/dist/index-C_5xwOPQ.js.map +1 -0
  59. package/dist/{index.node-DQZ3cPe-.js → index.node-DkpiPLbZ.js} +4 -4
  60. package/dist/{index.node-DQZ3cPe-.js.map → index.node-DkpiPLbZ.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 +32 -21
  65. package/dist/platform.browser.js.map +1 -1
  66. package/dist/platform.node.js +3 -3
  67. package/dist/{property-Bs3a4Dna.js → property-B-9szEcZ.js} +7 -7
  68. package/dist/{property-Bs3a4Dna.js.map → property-B-9szEcZ.js.map} +1 -1
  69. package/dist/src/browser/helpers/FileManager.d.ts +1 -1
  70. package/dist/src/browser/helpers/FileManager.d.ts.map +1 -1
  71. package/dist/src/client/ClientManager.d.ts +24 -5
  72. package/dist/src/client/ClientManager.d.ts.map +1 -1
  73. package/dist/src/client/actors/addModelsToDb.d.ts.map +1 -1
  74. package/dist/src/client/actors/addModelsToStore.d.ts.map +1 -1
  75. package/dist/src/client/actors/saveAppState.d.ts.map +1 -1
  76. package/dist/src/client/actors/saveConfig.d.ts.map +1 -1
  77. package/dist/src/client/clientManagerMachine.d.ts +7 -1
  78. package/dist/src/client/clientManagerMachine.d.ts.map +1 -1
  79. package/dist/src/client/coalesceInit.d.ts +7 -0
  80. package/dist/src/client/coalesceInit.d.ts.map +1 -0
  81. package/dist/src/client/constants.d.ts +3 -1
  82. package/dist/src/client/constants.d.ts.map +1 -1
  83. package/dist/src/helpers/FileManager/BaseFileManager.d.ts +7 -0
  84. package/dist/src/helpers/FileManager/BaseFileManager.d.ts.map +1 -1
  85. package/dist/src/types/machines.d.ts +1 -0
  86. package/dist/src/types/machines.d.ts.map +1 -1
  87. package/dist/{syncDbWithEas-DRpLRxwb.js → syncDbWithEas-CNBuYKo_.js} +10 -10
  88. package/dist/{syncDbWithEas-DRpLRxwb.js.map → syncDbWithEas-CNBuYKo_.js.map} +1 -1
  89. package/dist/{updateSeedRevokedAt-F0ZDvwOO.js → updateSeedRevokedAt-D5ZbBehZ.js} +2 -2
  90. package/dist/{updateSeedRevokedAt-F0ZDvwOO.js.map → updateSeedRevokedAt-D5ZbBehZ.js.map} +1 -1
  91. package/package.json +13 -5
  92. package/dist/BasePathResolver-0IHnXxtL.js.map +0 -1
  93. package/dist/cjs/index-C-POwaLs.js.map +0 -1
  94. package/dist/cjs/index-D_ph4zut.js.map +0 -1
  95. package/dist/index-C41UZTmQ.js.map +0 -1
  96. package/dist/index-DjwIC6U3.js.map +0 -1
  97. 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-CGjXNHFW.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-CLMqGTHn.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-CLMqGTHn.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-BnS8o5FK.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-CLMqGTHn.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-CGjXNHFW.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-BnS8o5FK.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-CLMqGTHn.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-BnS8o5FK.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-CLMqGTHn.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-BnS8o5FK.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-CGjXNHFW.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-CGjXNHFW.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-CLMqGTHn.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-DBGNShZR.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-DBGNShZR.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-CHhrLQmE.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-i3UrBhza.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-DBGNShZR.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-DBGNShZR.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-CWZoijFu.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-DBGNShZR.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-BnS8o5FK.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-BnS8o5FK.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-DBGNShZR.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-DBGNShZR.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-CHhrLQmE.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-i3UrBhza.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-DRbf_wzk.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,6 +16773,22 @@ function emitAddressesPersistedIfAddressesKey(event) {
16729
16773
  const payload = parseAddressesPersistedPayload(event.value);
16730
16774
  eventEmitter.emit(ADDRESSES_PERSISTED_EVENT, payload);
16731
16775
  }
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
+ function failInit(fallbackMessage) {
16784
+ return {
16785
+ target: INIT_FAILED,
16786
+ actions: {
16787
+ type: 'assignInitError',
16788
+ params: { fallbackMessage },
16789
+ },
16790
+ };
16791
+ }
16732
16792
  const clientManagerMachine = xstate.setup({
16733
16793
  types: {
16734
16794
  context: {},
@@ -16744,6 +16804,12 @@ const clientManagerMachine = xstate.setup({
16744
16804
  addModelsToDb,
16745
16805
  processSchemaFiles,
16746
16806
  },
16807
+ actions: {
16808
+ assignInitError: xstate.assign(({ event }, params) => ({
16809
+ initError: errorFromEvent(event, params.fallbackMessage),
16810
+ isInitialized: false,
16811
+ })),
16812
+ },
16747
16813
  }).createMachine({
16748
16814
  id: MachineIds.CLIENT_MANAGER,
16749
16815
  initial: UNINITIALIZED,
@@ -16762,6 +16828,7 @@ const clientManagerMachine = xstate.setup({
16762
16828
  actions: xstate.assign({
16763
16829
  isInitialized: false,
16764
16830
  initError: undefined,
16831
+ saveError: undefined,
16765
16832
  }),
16766
16833
  },
16767
16834
  },
@@ -16778,16 +16845,7 @@ const clientManagerMachine = xstate.setup({
16778
16845
  [PLATFORM_CLASSES_READY]: {
16779
16846
  target: FILE_SYSTEM_INIT,
16780
16847
  },
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
- },
16848
+ error: failInit('Platform classes initialization failed'),
16791
16849
  },
16792
16850
  invoke: {
16793
16851
  src: 'platformClassesInit',
@@ -16795,6 +16853,7 @@ const clientManagerMachine = xstate.setup({
16795
16853
  event: event,
16796
16854
  context
16797
16855
  }),
16856
+ onError: failInit('Platform classes initialization failed'),
16798
16857
  },
16799
16858
  },
16800
16859
  [FILE_SYSTEM_INIT]: {
@@ -16802,19 +16861,12 @@ const clientManagerMachine = xstate.setup({
16802
16861
  [FILE_SYSTEM_READY]: {
16803
16862
  target: DB_INIT,
16804
16863
  },
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
- },
16864
+ error: failInit('File system initialization failed'),
16814
16865
  },
16815
16866
  invoke: {
16816
16867
  src: 'fileSystemInit',
16817
16868
  input: ({ context }) => ({ context }),
16869
+ onError: failInit('File system initialization failed'),
16818
16870
  },
16819
16871
  },
16820
16872
  [DB_INIT]: {
@@ -16822,10 +16874,12 @@ const clientManagerMachine = xstate.setup({
16822
16874
  [DB_READY]: {
16823
16875
  target: SAVE_CONFIG,
16824
16876
  },
16877
+ error: failInit('Database initialization failed'),
16825
16878
  },
16826
16879
  invoke: {
16827
16880
  src: 'dbInit',
16828
16881
  input: ({ context }) => ({ context }),
16882
+ onError: failInit('Database initialization failed'),
16829
16883
  },
16830
16884
  },
16831
16885
  [SAVE_CONFIG]: {
@@ -16833,10 +16887,12 @@ const clientManagerMachine = xstate.setup({
16833
16887
  [SAVE_CONFIG_SUCCESS]: {
16834
16888
  target: PROCESS_SCHEMA_FILES,
16835
16889
  },
16890
+ error: failInit('Saving config failed'),
16836
16891
  },
16837
16892
  invoke: {
16838
16893
  src: 'saveConfig',
16839
16894
  input: ({ context }) => ({ context }),
16895
+ onError: failInit('Saving config failed'),
16840
16896
  },
16841
16897
  },
16842
16898
  [PROCESS_SCHEMA_FILES]: {
@@ -16844,19 +16900,12 @@ const clientManagerMachine = xstate.setup({
16844
16900
  [PROCESS_SCHEMA_FILES_SUCCESS]: {
16845
16901
  target: ADD_MODELS_TO_STORE,
16846
16902
  },
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
- },
16903
+ error: failInit('Schema processing failed'),
16856
16904
  },
16857
16905
  invoke: {
16858
16906
  src: 'processSchemaFiles',
16859
16907
  input: ({ context }) => ({ context }),
16908
+ onError: failInit('Schema processing failed'),
16860
16909
  },
16861
16910
  },
16862
16911
  [ADD_MODELS_TO_STORE]: {
@@ -16864,10 +16913,12 @@ const clientManagerMachine = xstate.setup({
16864
16913
  [ADD_MODELS_TO_STORE_SUCCESS]: {
16865
16914
  target: ADD_MODELS_TO_DB,
16866
16915
  },
16916
+ error: failInit('Adding models to store failed'),
16867
16917
  },
16868
16918
  invoke: {
16869
16919
  src: 'addModelsToStore',
16870
16920
  input: ({ context }) => ({ context }),
16921
+ onError: failInit('Adding models to store failed'),
16871
16922
  },
16872
16923
  },
16873
16924
  [ADD_MODELS_TO_DB]: {
@@ -16875,10 +16926,27 @@ const clientManagerMachine = xstate.setup({
16875
16926
  [ADD_MODELS_TO_DB_SUCCESS]: {
16876
16927
  target: IDLE,
16877
16928
  },
16929
+ error: failInit('Adding models to database failed'),
16878
16930
  },
16879
16931
  invoke: {
16880
16932
  src: 'addModelsToDb',
16881
16933
  input: ({ context }) => ({ context }),
16934
+ onError: failInit('Adding models to database failed'),
16935
+ },
16936
+ },
16937
+ [INIT_FAILED]: {
16938
+ entry: xstate.assign({
16939
+ isInitialized: false,
16940
+ }),
16941
+ on: {
16942
+ init: {
16943
+ target: PLATFORM_CLASSES_INIT,
16944
+ actions: xstate.assign({
16945
+ isInitialized: false,
16946
+ initError: undefined,
16947
+ saveError: undefined,
16948
+ }),
16949
+ },
16882
16950
  },
16883
16951
  },
16884
16952
  [IDLE]: {
@@ -16888,9 +16956,10 @@ const clientManagerMachine = xstate.setup({
16888
16956
  on: {
16889
16957
  [SAVE_APP_STATE_SUCCESS]: {
16890
16958
  actions: [
16891
- xstate.assign(({ event }) => {
16959
+ xstate.assign(() => {
16892
16960
  return {
16893
16961
  isSaving: false,
16962
+ saveError: undefined,
16894
16963
  };
16895
16964
  }),
16896
16965
  ({ context, event }) => maybeRunSyncFromEasAfterAddressSave({
@@ -16900,6 +16969,12 @@ const clientManagerMachine = xstate.setup({
16900
16969
  ({ event }) => emitAddressesPersistedIfAddressesKey(event),
16901
16970
  ],
16902
16971
  },
16972
+ [SAVE_APP_STATE_ERROR]: {
16973
+ actions: xstate.assign(({ event }) => ({
16974
+ isSaving: false,
16975
+ saveError: errorFromEvent(event, 'Failed to save app state'),
16976
+ })),
16977
+ },
16903
16978
  [SET_ADDRESSES]: {
16904
16979
  actions: [
16905
16980
  xstate.assign(({ event, spawn }) => {
@@ -16916,6 +16991,7 @@ const clientManagerMachine = xstate.setup({
16916
16991
  ownedAddresses: normalized.owned,
16917
16992
  watchedAddresses: normalized.watched,
16918
16993
  isSaving: true,
16994
+ saveError: undefined,
16919
16995
  };
16920
16996
  })
16921
16997
  ],
@@ -16924,6 +17000,8 @@ const clientManagerMachine = xstate.setup({
16924
17000
  target: PLATFORM_CLASSES_INIT,
16925
17001
  actions: xstate.assign({
16926
17002
  isInitialized: false,
17003
+ initError: undefined,
17004
+ saveError: undefined,
16927
17005
  }),
16928
17006
  },
16929
17007
  },
@@ -16931,6 +17009,30 @@ const clientManagerMachine = xstate.setup({
16931
17009
  },
16932
17010
  });
16933
17011
 
17012
+ /**
17013
+ * Coalesce overlapping async init calls onto one in-flight promise.
17014
+ * Skip when already successfully ready. Always clear in-flight on settle
17015
+ * so a failed init can be retried.
17016
+ */
17017
+ function createCoalescedAsync(run, shouldSkip) {
17018
+ let inFlight = null;
17019
+ return (arg) => {
17020
+ if (inFlight) {
17021
+ return inFlight;
17022
+ }
17023
+ if (shouldSkip(arg)) {
17024
+ return Promise.resolve();
17025
+ }
17026
+ const pending = run(arg).finally(() => {
17027
+ if (inFlight === pending) {
17028
+ inFlight = null;
17029
+ }
17030
+ });
17031
+ inFlight = pending;
17032
+ return pending;
17033
+ };
17034
+ }
17035
+
16934
17036
  function msToUnixSeconds(ms) {
16935
17037
  if (ms == null || !Number.isFinite(ms))
16936
17038
  return 0;
@@ -17479,7 +17581,7 @@ const clientInstance = {
17479
17581
  // ensureInitialized();
17480
17582
  return clientManager;
17481
17583
  },
17482
- init: async (options) => {
17584
+ init: createCoalescedAsync(async (options) => {
17483
17585
  // If the actor is stopped (e.g., from a previous failed test), restart it
17484
17586
  const snapshot = clientManager.getSnapshot();
17485
17587
  const currentState = snapshot.value;
@@ -17515,6 +17617,7 @@ const clientInstance = {
17515
17617
  filesDir: undefined,
17516
17618
  dbConfig: undefined,
17517
17619
  initError: undefined,
17620
+ saveError: undefined,
17518
17621
  }
17519
17622
  });
17520
17623
  // Wait a moment for the context update to be processed
@@ -17537,15 +17640,12 @@ const clientInstance = {
17537
17640
  }
17538
17641
  try {
17539
17642
  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;
17643
+ return snapshot.context.isInitialized || snapshot.context.initError != null;
17548
17644
  }, { timeout: 120000 });
17645
+ const initError = clientManager.getSnapshot().context.initError;
17646
+ if (initError) {
17647
+ throw initError instanceof Error ? initError : new Error(String(initError));
17648
+ }
17549
17649
  }
17550
17650
  catch (error) {
17551
17651
  // Ensure we never throw undefined
@@ -17556,12 +17656,21 @@ const clientInstance = {
17556
17656
  }
17557
17657
  // Wire `@seedprotocol/query` local source once DB is ready
17558
17658
  registerSeedQueryLocalSource();
17559
- },
17659
+ }, () => {
17660
+ const snapshot = clientManager.getSnapshot();
17661
+ return (snapshot.value === exports.ClientManagerState.IDLE &&
17662
+ snapshot.context.isInitialized === true &&
17663
+ !snapshot.context.initError);
17664
+ }),
17560
17665
  setAddresses: async (addresses) => {
17561
17666
  ensureInitialized();
17562
17667
  logger$3('setAddresses', addresses);
17563
17668
  clientManager.send({ type: 'setAddresses', addresses });
17564
17669
  await xstate.waitFor(clientManager, (snapshot) => !snapshot.context.isSaving, { timeout: 10000 });
17670
+ const saveError = clientManager.getSnapshot().context.saveError;
17671
+ if (saveError) {
17672
+ throw saveError instanceof Error ? saveError : new Error(String(saveError));
17673
+ }
17565
17674
  logger$3('setAddresses success', addresses);
17566
17675
  },
17567
17676
  getAddresses: async () => {
@@ -17837,7 +17946,7 @@ const saveDraftLogger = debug('seedSdk:model:saveDraftToDb');
17837
17946
  // Lazy import cache for ModelProperty to avoid circular dependency
17838
17947
  // Eagerly start loading to minimize delay on first access
17839
17948
  let ModelPropertyClass = null;
17840
- const modelPropertyImportPromise = Promise.resolve().then(function () { return require('./ModelProperty-DvIIhBnK.js'); })
17949
+ const modelPropertyImportPromise = Promise.resolve().then(function () { return require('./ModelProperty-CGjXNHFW.js'); })
17841
17950
  .then(module => {
17842
17951
  ModelPropertyClass = module.ModelProperty;
17843
17952
  return ModelPropertyClass;
@@ -17854,7 +17963,7 @@ function getModelProperty() {
17854
17963
  }
17855
17964
  // Lazy import cache for Schema to avoid circular dependency
17856
17965
  let SchemaClass = null;
17857
- const schemaImportPromise = Promise.resolve().then(function () { return require('./Schema-FdzNqyGo.js'); })
17966
+ const schemaImportPromise = Promise.resolve().then(function () { return require('./Schema-CLMqGTHn.js'); })
17858
17967
  .then(module => {
17859
17968
  SchemaClass = module.Schema;
17860
17969
  return SchemaClass;
@@ -19756,7 +19865,7 @@ function resolveSdkDrizzleMigrationsDir(sdkRootDir) {
19756
19865
  })();
19757
19866
  // Also resolve relative to this module so temp-cwd tests / odd roots still find
19758
19867
  // 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))));
19868
+ 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-Bx8ReSFI.js', document.baseURI).href))));
19760
19869
  const candidates = [
19761
19870
  path.join(root, 'db', 'drizzle'), // production: sdkRoot is dist/
19762
19871
  path.join(root, 'dist', 'db', 'drizzle'), // sdk package root with built dist
@@ -19826,7 +19935,7 @@ class NodeDb {
19826
19935
  logger$1('[Db.prepareDb] running migrations from %s', outDir);
19827
19936
  await migrator.migrate(db, { migrationsFolder: outDir });
19828
19937
  this.db = db;
19829
- const { backfillMetadataPropertyIds } = await Promise.resolve().then(function () { return require('./backfillMetadataPropertyIds-D0o5VwBh.js'); });
19938
+ const { backfillMetadataPropertyIds } = await Promise.resolve().then(function () { return require('./backfillMetadataPropertyIds-B3xNIFjQ.js'); });
19830
19939
  await backfillMetadataPropertyIds();
19831
19940
  return this.db;
19832
19941
  }
@@ -20417,4 +20526,4 @@ exports.versions = versions;
20417
20526
  exports.waitForEntityIdle = waitForEntityIdle;
20418
20527
  exports.withSeed = withSeed;
20419
20528
  exports.writeProcessMachine = writeProcessMachine;
20420
- //# sourceMappingURL=index-C-POwaLs.js.map
20529
+ //# sourceMappingURL=index-Bx8ReSFI.js.map