@almadar/runtime 6.7.0 → 6.8.1

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.
@@ -1,4 +1,4 @@
1
- export { InMemoryPersistence, OrbitalServerRuntime, collectDeclaredConfigDefaults, createOrbitalServerRuntime } from './chunk-QE4EUBYW.js';
1
+ export { InMemoryPersistence, OrbitalServerRuntime, collectDeclaredConfigDefaults, createOrbitalServerRuntime } from './chunk-L3FDWEQL.js';
2
2
  import './chunk-PZ5AY32C.js';
3
3
  //# sourceMappingURL=OrbitalServerRuntime.js.map
4
4
  //# sourceMappingURL=OrbitalServerRuntime.js.map
@@ -1703,7 +1703,7 @@ function picsumUrl(entityName, fieldName, width = 400, height = 400) {
1703
1703
  return `https://picsum.photos/seed/${encodeURIComponent(seed)}/${width}/${height}`;
1704
1704
  }
1705
1705
  var SEED_REFERENCE_TIMESTAMP = "2024-01-01T00:00:00.000Z";
1706
- var MockPersistenceAdapter = class {
1706
+ var MockPersistenceAdapter = class _MockPersistenceAdapter {
1707
1707
  stores = /* @__PURE__ */ new Map();
1708
1708
  schemas = /* @__PURE__ */ new Map();
1709
1709
  idCounters = /* @__PURE__ */ new Map();
@@ -1822,10 +1822,17 @@ var MockPersistenceAdapter = class {
1822
1822
  }
1823
1823
  return item;
1824
1824
  }
1825
+ /** Max nesting depth for recursive array/object schemas (e.g. a Comment
1826
+ * entity whose `replies: [Comment]` field references itself). Without
1827
+ * this guard, generateArrayValue → generateObjectValue → generateArray…
1828
+ * recurses until stack overflow on every recursive type. Three levels
1829
+ * is enough to render a useful thread depth (parent → reply → sub-reply)
1830
+ * in catalog/preview without blowing the fixture. */
1831
+ static MAX_NESTED_DEPTH = 3;
1825
1832
  /**
1826
1833
  * Generate a mock value for a field based on its schema.
1827
1834
  */
1828
- generateFieldValue(entityName, field, index) {
1835
+ generateFieldValue(entityName, field, index, depth = 0) {
1829
1836
  const fieldTypeLc = field.type.toLowerCase();
1830
1837
  mockLog.debug("field:generate", {
1831
1838
  entityName,
@@ -1861,13 +1868,52 @@ var MockPersistenceAdapter = class {
1861
1868
  return null;
1862
1869
  // Relations need special handling
1863
1870
  case "array":
1864
- return [];
1871
+ return this.generateArrayValue(entityName, field, index, depth);
1865
1872
  case "object":
1866
- return null;
1873
+ return this.generateObjectValue(entityName, field, index, depth);
1867
1874
  default:
1868
1875
  return this.generateStringValue(entityName, field, index);
1869
1876
  }
1870
1877
  }
1878
+ /**
1879
+ * Generate 3–5 elements for an array field. When `items` describes an
1880
+ * object shape (the common case for `tiles: [KpiTile]`-style declarations),
1881
+ * each element is recursively mock-generated against `items.properties`.
1882
+ * When `items` describes a scalar, each element uses the scalar generator
1883
+ * for that type. When `items` is missing (legacy `[object] = []` declarations
1884
+ * with no element schema), falls back to an empty array — the historical
1885
+ * behavior.
1886
+ */
1887
+ generateArrayValue(entityName, field, index, depth = 0) {
1888
+ if (!field.items) return [];
1889
+ if (depth >= _MockPersistenceAdapter.MAX_NESTED_DEPTH) return [];
1890
+ const count = faker.number.int({ min: 3, max: 5 });
1891
+ const out = [];
1892
+ for (let i = 0; i < count; i++) {
1893
+ const elementField = {
1894
+ ...field.items,
1895
+ name: `${field.name}[${i}]`
1896
+ };
1897
+ out.push(this.generateFieldValue(entityName, elementField, index * 10 + i, depth + 1));
1898
+ }
1899
+ return out;
1900
+ }
1901
+ /**
1902
+ * Generate a single object value with each declared property populated
1903
+ * by faker. Walks `properties` and recursively delegates to
1904
+ * `generateFieldValue` per property so nested objects-of-arrays-of-objects
1905
+ * compose correctly.
1906
+ */
1907
+ generateObjectValue(entityName, field, index, depth = 0) {
1908
+ if (!field.properties) return null;
1909
+ if (depth >= _MockPersistenceAdapter.MAX_NESTED_DEPTH) return null;
1910
+ const out = {};
1911
+ for (const [propName, propField] of Object.entries(field.properties)) {
1912
+ const childField = { ...propField, name: propName };
1913
+ out[propName] = this.generateFieldValue(entityName, childField, index, depth + 1);
1914
+ }
1915
+ return out;
1916
+ }
1871
1917
  /**
1872
1918
  * Generate a string value based on the field's declared schema metadata.
1873
1919
  * Reads `values` (enum) first, then `format` (email/url/phone/uuid/date/
@@ -3589,6 +3635,32 @@ function needsPreprocessing(schema) {
3589
3635
  }
3590
3636
  return false;
3591
3637
  }
3638
+ function mapFieldForMock(f) {
3639
+ const rec = f;
3640
+ const out = {
3641
+ name: f.name,
3642
+ type: rec["type"]
3643
+ };
3644
+ if (typeof rec["required"] === "boolean") out.required = rec["required"];
3645
+ if (Array.isArray(rec["values"])) out.values = rec["values"];
3646
+ if (rec["default"] !== void 0) out.default = rec["default"];
3647
+ if (typeof rec["format"] === "string") out.format = rec["format"];
3648
+ const items = rec["items"];
3649
+ if (items && typeof items === "object" && "type" in items) {
3650
+ out.items = mapFieldForMock({ name: "", ...items });
3651
+ }
3652
+ const properties = rec["properties"];
3653
+ if (properties && typeof properties === "object" && !Array.isArray(properties)) {
3654
+ const propsOut = {};
3655
+ for (const [k, v] of Object.entries(properties)) {
3656
+ if (v && typeof v === "object" && "type" in v) {
3657
+ propsOut[k] = mapFieldForMock({ name: k, ...v });
3658
+ }
3659
+ }
3660
+ if (Object.keys(propsOut).length > 0) out.properties = propsOut;
3661
+ }
3662
+ return out;
3663
+ }
3592
3664
  var OrbitalServerRuntime = class {
3593
3665
  orbitals = /* @__PURE__ */ new Map();
3594
3666
  eventBus;
@@ -4005,13 +4077,7 @@ var OrbitalServerRuntime = class {
4005
4077
  if (entity?.name && entity.fields) {
4006
4078
  const fields = entity.fields.filter(
4007
4079
  (f) => typeof f.name === "string" && f.name.length > 0
4008
- ).map((f) => ({
4009
- name: f.name,
4010
- type: f.type,
4011
- required: f.required,
4012
- values: f.values,
4013
- default: f.default
4014
- }));
4080
+ ).map((f) => mapFieldForMock(f));
4015
4081
  this.persistence.registerEntity({ name: entity.name, fields });
4016
4082
  if (this.config.debug) {
4017
4083
  persistLog.debug("mock:seeded", { entity: entity.name, count: this.persistence.count(entity.name) });
@@ -4026,13 +4092,7 @@ var OrbitalServerRuntime = class {
4026
4092
  if (!auxEntity.name || !auxEntity.fields) continue;
4027
4093
  const auxFields = auxEntity.fields.filter(
4028
4094
  (f) => typeof f.name === "string" && f.name.length > 0
4029
- ).map((f) => ({
4030
- name: f.name,
4031
- type: f.type,
4032
- required: f.required,
4033
- values: f.values,
4034
- default: f.default
4035
- }));
4095
+ ).map((f) => mapFieldForMock(f));
4036
4096
  this.persistence.registerEntity({ name: auxEntity.name, fields: auxFields });
4037
4097
  if (this.config.debug) {
4038
4098
  persistLog.debug("mock:seeded-auxiliary", {
@@ -4314,13 +4374,7 @@ var OrbitalServerRuntime = class {
4314
4374
  if (entity?.name && entity.fields) {
4315
4375
  const fields = entity.fields.filter(
4316
4376
  (f) => typeof f.name === "string" && f.name.length > 0
4317
- ).map((f) => ({
4318
- name: f.name,
4319
- type: f.type,
4320
- required: f.required,
4321
- values: f.values,
4322
- default: f.default
4323
- }));
4377
+ ).map((f) => mapFieldForMock(f));
4324
4378
  this.persistence.registerEntity({ name: entity.name, fields });
4325
4379
  }
4326
4380
  }
@@ -5398,5 +5452,5 @@ function buildMatcher(src, listenerOrbital) {
5398
5452
  }
5399
5453
 
5400
5454
  export { EffectExecutor, EventBus, HANDLER_MANIFEST, InMemoryPersistence, MockPersistenceAdapter, OrbitalServerRuntime, StateMachineManager, buildEmitsFromTraits, collectDeclaredConfigDefaults, containsBindings, createContextFromBindings, createInitialTraitState, createMockPersistence, createOrbitalServerRuntime, createTestExecutor, createUnifiedLoader, extractBindings, findInitialState, findTransition, formatPayloadValidationError, getIsolatedCollectionName, getNamespacedEvent, interpolateProps, interpolateValue, isBrowser, isElectron, isNamespacedEvent, isNode, normalizeEventKey, parseNamespacedEvent, preprocessSchema, processEvent, validateEventPayload, validatePayloadShapes };
5401
- //# sourceMappingURL=chunk-QE4EUBYW.js.map
5402
- //# sourceMappingURL=chunk-QE4EUBYW.js.map
5455
+ //# sourceMappingURL=chunk-L3FDWEQL.js.map
5456
+ //# sourceMappingURL=chunk-L3FDWEQL.js.map