@almadar/runtime 5.3.0 → 5.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1684,6 +1684,9 @@ function buildEmitsFromTraits(traits, explicitEmits) {
1684
1684
  }
1685
1685
  return result;
1686
1686
  }
1687
+ var mockLog = createLogger("almadar:runtime:mock");
1688
+ var DEFAULT_MOCK_SEED = 42;
1689
+ var SEED_REFERENCE_TIMESTAMP = "2024-01-01T00:00:00.000Z";
1687
1690
  var MockPersistenceAdapter = class {
1688
1691
  stores = /* @__PURE__ */ new Map();
1689
1692
  schemas = /* @__PURE__ */ new Map();
@@ -1693,13 +1696,20 @@ var MockPersistenceAdapter = class {
1693
1696
  this.config = {
1694
1697
  defaultSeedCount: 6,
1695
1698
  debug: false,
1699
+ seed: DEFAULT_MOCK_SEED,
1696
1700
  ...config
1697
1701
  };
1698
- if (config.seed !== void 0) {
1699
- faker.seed(config.seed);
1700
- if (this.config.debug) {
1701
- console.log(`[MockPersistence] Using seed: ${config.seed}`);
1702
- }
1702
+ faker.seed(this.config.seed);
1703
+ mockLog.debug("mock:adapter:init", { seed: this.config.seed });
1704
+ }
1705
+ /** Re-anchor faker's PRNG to the configured seed. Called before every
1706
+ * re-seed loop so identical reseed sequences produce identical rows
1707
+ * (timestamps + faker-generated fields). Without this, the first
1708
+ * reseed produces row set A, the second produces row set B, and
1709
+ * diff observers see all rows as "changed" between frames. */
1710
+ resetFakerSeed() {
1711
+ if (this.config.seed !== void 0) {
1712
+ faker.seed(this.config.seed);
1703
1713
  }
1704
1714
  }
1705
1715
  // ============================================================================
@@ -1747,12 +1757,11 @@ var MockPersistenceAdapter = class {
1747
1757
  }
1748
1758
  for (const instance of instances) {
1749
1759
  const id = instance.id || this.nextId(entityName);
1750
- const now = (/* @__PURE__ */ new Date()).toISOString();
1751
1760
  const item = {
1752
1761
  ...instance,
1753
1762
  id,
1754
- createdAt: instance.createdAt || now,
1755
- updatedAt: now
1763
+ createdAt: instance.createdAt || SEED_REFERENCE_TIMESTAMP,
1764
+ updatedAt: SEED_REFERENCE_TIMESTAMP
1756
1765
  };
1757
1766
  store.set(id, item);
1758
1767
  }
@@ -1766,21 +1775,26 @@ var MockPersistenceAdapter = class {
1766
1775
  if (this.config.debug) {
1767
1776
  console.log(`[MockPersistence] Seeding ${count} ${entityName}...`);
1768
1777
  }
1778
+ const generated = [];
1769
1779
  for (let i = 0; i < count; i++) {
1770
1780
  const item = this.generateMockItem(normalized, entityName, fields, i + 1);
1771
1781
  store.set(item.id, item);
1782
+ generated.push({
1783
+ id: item.id,
1784
+ updatedAt: typeof item.updatedAt === "string" ? item.updatedAt : ""
1785
+ });
1772
1786
  }
1787
+ mockLog.debug("mock:seed", { entityName, count, idsAndTimestamps: JSON.stringify(generated) });
1773
1788
  }
1774
1789
  /**
1775
1790
  * Generate a single mock item based on field schemas.
1776
1791
  */
1777
1792
  generateMockItem(normalizedName, entityName, fields, index) {
1778
1793
  const id = this.nextId(entityName);
1779
- const now = (/* @__PURE__ */ new Date()).toISOString();
1780
1794
  const item = {
1781
1795
  id,
1782
1796
  createdAt: faker.date.past({ years: 1 }).toISOString(),
1783
- updatedAt: now
1797
+ updatedAt: SEED_REFERENCE_TIMESTAMP
1784
1798
  };
1785
1799
  for (const field of fields) {
1786
1800
  if (field.name === "id" || field.name === "createdAt" || field.name === "updatedAt") {
@@ -1946,12 +1960,14 @@ var MockPersistenceAdapter = class {
1946
1960
  this.stores.delete(normalized);
1947
1961
  this.idCounters.delete(normalized);
1948
1962
  }
1949
- /**
1950
- * Clear all data.
1951
- */
1963
+ /** Clear all data + re-anchor faker so the next seed loop reproduces
1964
+ * identical rows. Hermetic-frame mode calls this between every step
1965
+ * via OrbitalServerRuntime.resetMockPersistence. */
1952
1966
  clearAll() {
1953
1967
  this.stores.clear();
1954
1968
  this.idCounters.clear();
1969
+ this.resetFakerSeed();
1970
+ mockLog.debug("mock:adapter:clearAll", { reanchored: this.config.seed });
1955
1971
  }
1956
1972
  /**
1957
1973
  * Get count of items for an entity.
@@ -3396,5 +3412,5 @@ var InMemoryPersistence = class {
3396
3412
  };
3397
3413
 
3398
3414
  export { EffectExecutor, EventBus, HANDLER_MANIFEST, InMemoryPersistence, MockPersistenceAdapter, StateMachineManager, buildEmitsFromTraits, containsBindings, createContextFromBindings, createInitialTraitState, createLogger, createMockPersistence, createTestExecutor, createUnifiedLoader, extractBindings, findInitialState, findTransition, formatPayloadValidationError, getIsolatedCollectionName, getNamespacedEvent, interpolateProps, interpolateValue, isBrowser, isElectron, isNamespacedEvent, isNode, normalizeEventKey, parseNamespacedEvent, preprocessSchema, processEvent, validateEventPayload, validatePayloadShapes };
3399
- //# sourceMappingURL=chunk-FAWWBERN.js.map
3400
- //# sourceMappingURL=chunk-FAWWBERN.js.map
3415
+ //# sourceMappingURL=chunk-62BIUDUH.js.map
3416
+ //# sourceMappingURL=chunk-62BIUDUH.js.map