@almadar/core 10.37.0 → 10.38.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.
@@ -0,0 +1,695 @@
1
+ import { z } from 'zod';
2
+
3
+ // src/mock/random.ts
4
+ var seedState = 42;
5
+ function seedRandom(value) {
6
+ seedState = (value ?? 42) >>> 0;
7
+ }
8
+ function nextFloat() {
9
+ seedState = seedState * 1664525 + 1013904223 >>> 0;
10
+ return seedState / 4294967296;
11
+ }
12
+ function randomInt({ min, max }) {
13
+ return Math.floor(nextFloat() * (max - min + 1)) + min;
14
+ }
15
+ function randomFloat({
16
+ min,
17
+ max,
18
+ fractionDigits = 2
19
+ }) {
20
+ const value = nextFloat() * (max - min) + min;
21
+ const factor = 10 ** fractionDigits;
22
+ return Math.round(value * factor) / factor;
23
+ }
24
+ function randomBoolean() {
25
+ return nextFloat() < 0.5;
26
+ }
27
+ function randomArrayElement(array) {
28
+ return array[randomInt({ min: 0, max: array.length - 1 })];
29
+ }
30
+ function shuffleArray(array) {
31
+ const copy = array.slice();
32
+ for (let i = copy.length - 1; i > 0; i--) {
33
+ const j = randomInt({ min: 0, max: i });
34
+ const tmp = copy[i];
35
+ copy[i] = copy[j];
36
+ copy[j] = tmp;
37
+ }
38
+ return copy;
39
+ }
40
+ function randomPastDate({ years = 1 } = {}) {
41
+ const now = Date.now();
42
+ const maxAge = years * 365 * 24 * 60 * 60 * 1e3;
43
+ const age = Math.floor(nextFloat() * maxAge);
44
+ return new Date(now - age);
45
+ }
46
+ function randomRecentDate({ days = 30 } = {}) {
47
+ const now = Date.now();
48
+ const maxAge = days * 24 * 60 * 60 * 1e3;
49
+ const age = Math.floor(nextFloat() * maxAge);
50
+ return new Date(now - age);
51
+ }
52
+ function randomAnytimeDate() {
53
+ const now = Date.now();
54
+ const maxAge = 100 * 365 * 24 * 60 * 60 * 1e3;
55
+ const age = Math.floor(nextFloat() * maxAge);
56
+ return new Date(now - age);
57
+ }
58
+ var LOREM_WORDS = [
59
+ "lorem",
60
+ "ipsum",
61
+ "dolor",
62
+ "sit",
63
+ "amet",
64
+ "consectetur",
65
+ "adipiscing",
66
+ "elit",
67
+ "sed",
68
+ "do",
69
+ "eiusmod",
70
+ "tempor",
71
+ "incididunt",
72
+ "ut",
73
+ "labore",
74
+ "et",
75
+ "dolore",
76
+ "magna",
77
+ "aliqua",
78
+ "enim",
79
+ "ad",
80
+ "minim",
81
+ "veniam",
82
+ "quis",
83
+ "nostrud",
84
+ "exercitation",
85
+ "ullamco",
86
+ "laboris",
87
+ "nisi",
88
+ "aliquip",
89
+ "ex",
90
+ "ea",
91
+ "commodo",
92
+ "consequat",
93
+ "duis",
94
+ "aute",
95
+ "irure",
96
+ "in",
97
+ "reprehenderit",
98
+ "voluptate",
99
+ "velit",
100
+ "esse",
101
+ "cillum",
102
+ "fugiat",
103
+ "nulla",
104
+ "pariatur",
105
+ "excepteur",
106
+ "sint",
107
+ "occaecat",
108
+ "cupidatat",
109
+ "non",
110
+ "proident",
111
+ "sunt",
112
+ "culpa",
113
+ "qui",
114
+ "officia",
115
+ "deserunt",
116
+ "mollit",
117
+ "anim",
118
+ "id",
119
+ "est",
120
+ "laborum"
121
+ ];
122
+ function randomWords(count) {
123
+ const words = [];
124
+ for (let i = 0; i < count; i++) {
125
+ words.push(randomArrayElement(LOREM_WORDS));
126
+ }
127
+ return words.join(" ");
128
+ }
129
+ function randomSentence() {
130
+ const words = randomWords(randomInt({ min: 4, max: 8 }));
131
+ return words.charAt(0).toUpperCase() + words.slice(1) + ".";
132
+ }
133
+ function randomUuid() {
134
+ const hex = () => randomInt({ min: 0, max: 15 }).toString(16);
135
+ return `${hex()}${hex()}${hex()}${hex()}${hex()}${hex()}${hex()}${hex()}-${hex()}${hex()}${hex()}${hex()}-4${hex()}${hex()}${hex()}-${hex()}${hex()}${hex()}${hex()}-${hex()}${hex()}${hex()}${hex()}${hex()}${hex()}${hex()}${hex()}${hex()}${hex()}${hex()}${hex()}`;
136
+ }
137
+ function randomColor() {
138
+ const channel = () => randomInt({ min: 0, max: 255 }).toString(16).padStart(2, "0");
139
+ return `#${channel()}${channel()}${channel()}`;
140
+ }
141
+ var PASSWORD_CHARS = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*";
142
+ function randomPassword(length = 12) {
143
+ let password = "";
144
+ for (let i = 0; i < length; i++) {
145
+ password += randomArrayElement(PASSWORD_CHARS.split(""));
146
+ }
147
+ return password;
148
+ }
149
+ function randomEmail() {
150
+ const user = randomWords(1).toLowerCase().replace(/\s+/g, ".");
151
+ const domain = randomWords(1).toLowerCase().replace(/\s+/g, "");
152
+ return `${user}@${domain}.com`;
153
+ }
154
+ function randomUrl() {
155
+ const slug2 = randomWords(2).toLowerCase().replace(/\s+/g, "-");
156
+ return `https://example.com/${slug2}`;
157
+ }
158
+ function randomPhone() {
159
+ const area = randomInt({ min: 200, max: 999 });
160
+ const prefix = randomInt({ min: 200, max: 999 });
161
+ const line = randomInt({ min: 0, max: 9999 }).toString().padStart(4, "0");
162
+ return `+1 (${area}) ${prefix}-${line}`;
163
+ }
164
+ var ID_PREFIXES = {
165
+ orbital: "orb_",
166
+ entity: "ent_",
167
+ trait: "trt_",
168
+ event: "evt_",
169
+ page: "pag_",
170
+ service: "svc_",
171
+ theme: "thm_",
172
+ palette: "pal_"
173
+ };
174
+ function brand(value) {
175
+ return value;
176
+ }
177
+ function makeIdKind(kind) {
178
+ const prefix = ID_PREFIXES[kind];
179
+ const is = (value) => value.startsWith(prefix) && value.length > prefix.length;
180
+ const as = (value) => {
181
+ if (!is(value)) {
182
+ throw new Error(
183
+ `Expected ${kind} id (prefix "${prefix}"), got: ${JSON.stringify(value)}`
184
+ );
185
+ }
186
+ return brand(value);
187
+ };
188
+ return { prefix, is, as };
189
+ }
190
+ var orbitalKind = makeIdKind("orbital");
191
+ var entityKind = makeIdKind("entity");
192
+ var traitKind = makeIdKind("trait");
193
+ var eventKind = makeIdKind("event");
194
+ var pageKind = makeIdKind("page");
195
+ var serviceKind = makeIdKind("service");
196
+ var themeKind = makeIdKind("theme");
197
+ var paletteKind = makeIdKind("palette");
198
+ var isOrbitalId = orbitalKind.is;
199
+ var isEntityId = entityKind.is;
200
+ var isTraitId = traitKind.is;
201
+ var isEventId = eventKind.is;
202
+ var isPageId = pageKind.is;
203
+ var isServiceId = serviceKind.is;
204
+ var isThemeId = themeKind.is;
205
+ var isPaletteEntryId = paletteKind.is;
206
+ z.string().refine(isOrbitalId, { message: `Expected an orbital id (prefix "${ID_PREFIXES.orbital}")` });
207
+ var EntityIdSchema = z.string().refine(isEntityId, { message: `Expected an entity id (prefix "${ID_PREFIXES.entity}")` });
208
+ var TraitIdSchema = z.string().refine(isTraitId, { message: `Expected a trait id (prefix "${ID_PREFIXES.trait}")` });
209
+ z.string().refine(isEventId, { message: `Expected an event id (prefix "${ID_PREFIXES.event}")` });
210
+ z.string().refine(isPageId, { message: `Expected a page id (prefix "${ID_PREFIXES.page}")` });
211
+ z.string().refine(isServiceId, { message: `Expected a service id (prefix "${ID_PREFIXES.service}")` });
212
+ z.string().refine(isThemeId, { message: `Expected a theme id (prefix "${ID_PREFIXES.theme}")` });
213
+ z.string().refine(isPaletteEntryId, { message: `Expected a palette-entry id (prefix "${ID_PREFIXES.palette}")` });
214
+ var LedgerKindSchema = z.enum([
215
+ "orbital",
216
+ "entity",
217
+ "trait",
218
+ "event",
219
+ "page",
220
+ "service",
221
+ "theme"
222
+ ]);
223
+ var LedgerEntrySchema = z.object({
224
+ id: z.string(),
225
+ kind: LedgerKindSchema,
226
+ bakedName: z.string(),
227
+ curName: z.string(),
228
+ renames: z.array(
229
+ z.object({ from: z.string(), to: z.string(), at: z.string() })
230
+ ),
231
+ owner: z.enum(["std", "io", "workspace"]),
232
+ parent: TraitIdSchema.optional()
233
+ });
234
+ z.object({
235
+ schemaVersion: z.literal(1),
236
+ entries: z.record(LedgerEntrySchema)
237
+ });
238
+ var JsonValueSchema = z.lazy(
239
+ () => z.union([z.string(), z.number(), z.boolean(), z.null(), z.array(JsonValueSchema), z.record(JsonValueSchema)])
240
+ );
241
+
242
+ // src/types/field.ts
243
+ var FIELD_TYPES = [
244
+ "string",
245
+ "number",
246
+ "boolean",
247
+ "date",
248
+ "timestamp",
249
+ "datetime",
250
+ "email",
251
+ "url",
252
+ "phone",
253
+ "uuid",
254
+ "image",
255
+ "array",
256
+ "object",
257
+ "enum",
258
+ "relation",
259
+ "trait",
260
+ "slot",
261
+ "pattern"
262
+ ];
263
+ z.enum(FIELD_TYPES);
264
+ var RelationCardinalitySchema = z.enum([
265
+ "one",
266
+ "many",
267
+ "one-to-many",
268
+ "many-to-one",
269
+ "many-to-many"
270
+ ]);
271
+ var RelationConfigSchema = z.object({
272
+ entity: z.string().min(1, "Target entity is required"),
273
+ entityId: EntityIdSchema.optional(),
274
+ field: z.string().optional(),
275
+ cardinality: RelationCardinalitySchema.optional(),
276
+ onDelete: z.enum(["cascade", "nullify", "restrict"]).optional(),
277
+ // Legacy compatibility fields
278
+ foreignKey: z.string().optional(),
279
+ target: z.string().optional(),
280
+ type: RelationCardinalitySchema.optional()
281
+ }).transform((data) => {
282
+ const normalized = {
283
+ entity: data.entity || data.target || "",
284
+ entityId: data.entityId,
285
+ cardinality: data.cardinality || data.type,
286
+ field: data.field,
287
+ onDelete: data.onDelete
288
+ };
289
+ return normalized;
290
+ });
291
+ var FIELD_TYPE_ALIASES = {
292
+ text: "string",
293
+ int: "number",
294
+ float: "number",
295
+ ts: "timestamp"
296
+ };
297
+ var EntityFieldSchema = z.lazy(() => {
298
+ const baseFieldShape = {
299
+ name: z.string().min(1, "Field name is required").optional(),
300
+ required: z.boolean().optional(),
301
+ default: JsonValueSchema.optional(),
302
+ min: z.number().optional(),
303
+ max: z.number().optional(),
304
+ properties: z.record(EntityFieldSchema).optional(),
305
+ intrinsic: z.boolean().optional(),
306
+ description: z.string().optional(),
307
+ synonyms: z.string().optional()
308
+ };
309
+ function scalarVariant(t) {
310
+ return z.object({
311
+ ...baseFieldShape,
312
+ type: z.literal(t),
313
+ values: z.array(z.string()).optional()
314
+ });
315
+ }
316
+ return z.preprocess(
317
+ (input) => {
318
+ if (input === null || typeof input !== "object" || !("type" in input) || typeof input.type !== "string") {
319
+ return input;
320
+ }
321
+ const obj = input;
322
+ const next = { ...obj };
323
+ const aliased = FIELD_TYPE_ALIASES[obj.type];
324
+ if (aliased !== void 0) next.type = aliased;
325
+ if (next.enum !== void 0 && next.values === void 0) {
326
+ next.values = next.enum;
327
+ }
328
+ delete next.enum;
329
+ return next;
330
+ },
331
+ z.discriminatedUnion("type", [
332
+ scalarVariant("string"),
333
+ scalarVariant("number"),
334
+ scalarVariant("boolean"),
335
+ scalarVariant("date"),
336
+ scalarVariant("timestamp"),
337
+ scalarVariant("datetime"),
338
+ scalarVariant("email"),
339
+ scalarVariant("url"),
340
+ scalarVariant("phone"),
341
+ scalarVariant("uuid"),
342
+ scalarVariant("image"),
343
+ scalarVariant("trait"),
344
+ scalarVariant("slot"),
345
+ scalarVariant("pattern"),
346
+ // Enum variant — REQUIRES non-empty values.
347
+ z.object({
348
+ ...baseFieldShape,
349
+ type: z.literal("enum"),
350
+ values: z.array(z.string()).min(1, "Enum field requires a non-empty `values` array")
351
+ }),
352
+ // Relation variant — REQUIRES relation config.
353
+ z.object({
354
+ ...baseFieldShape,
355
+ type: z.literal("relation"),
356
+ relation: RelationConfigSchema
357
+ }),
358
+ // Array variant — items optional to match relaxed TS shape.
359
+ z.object({
360
+ ...baseFieldShape,
361
+ type: z.literal("array"),
362
+ items: EntityFieldSchema.optional()
363
+ }),
364
+ // Object variant — fixed-key struct (`properties`) or dynamic-key
365
+ // map (`Map K V`, uniform value schema in `items`).
366
+ z.object({
367
+ ...baseFieldShape,
368
+ type: z.literal("object"),
369
+ items: EntityFieldSchema.optional(),
370
+ values: z.array(z.string()).optional()
371
+ })
372
+ ])
373
+ );
374
+ });
375
+ var ENTITY_ROLES = [
376
+ "player",
377
+ "enemy",
378
+ "npc",
379
+ "item",
380
+ "tile",
381
+ "projectile",
382
+ "effect",
383
+ "ui",
384
+ "decoration",
385
+ "vehicle"
386
+ ];
387
+ z.enum(ENTITY_ROLES);
388
+ var VISUAL_STYLES = ["pixel", "vector", "hd", "1-bit", "isometric"];
389
+ var VisualStyleSchema = z.enum(VISUAL_STYLES);
390
+ var ASSET_DIMENSIONS = ["2d", "3d"];
391
+ var AssetDimensionSchema = z.enum(ASSET_DIMENSIONS);
392
+ var ASSET_ASPECTS = ["1:1", "16:9", "5:7", "8:1"];
393
+ var AssetAspectSchema = z.enum(ASSET_ASPECTS);
394
+ var ANIMATION_NAMES = ["idle", "walk", "attack", "hit", "death"];
395
+ var AnimationNameSchema = z.enum(ANIMATION_NAMES);
396
+ var SPRITE_DIRECTIONS = ["se", "sw"];
397
+ var SpriteDirectionSchema = z.enum(SPRITE_DIRECTIONS);
398
+ var AnimationDefSchema = z.object({
399
+ row: z.number().int().nonnegative(),
400
+ frames: z.number().int().positive(),
401
+ frameRate: z.number().positive(),
402
+ loop: z.boolean()
403
+ });
404
+ z.object({
405
+ unit: z.string().optional(),
406
+ type: z.string().optional(),
407
+ frameWidth: z.number().positive(),
408
+ frameHeight: z.number().positive(),
409
+ columns: z.number().int().positive(),
410
+ rows: z.number().int().positive(),
411
+ directions: z.array(SpriteDirectionSchema),
412
+ sheets: z.record(SpriteDirectionSchema, z.string()),
413
+ animations: z.record(AnimationNameSchema, AnimationDefSchema)
414
+ });
415
+ var SubTextureSchema = z.object({
416
+ x: z.number().nonnegative(),
417
+ y: z.number().nonnegative(),
418
+ width: z.number().positive(),
419
+ height: z.number().positive(),
420
+ frameX: z.number().optional(),
421
+ frameY: z.number().optional(),
422
+ frameWidth: z.number().positive().optional(),
423
+ frameHeight: z.number().positive().optional()
424
+ });
425
+ z.object({
426
+ imagePath: z.string(),
427
+ subTextures: z.record(z.string(), SubTextureSchema)
428
+ });
429
+ z.object({
430
+ imagePath: z.string(),
431
+ tileWidth: z.number().positive(),
432
+ tileHeight: z.number().positive(),
433
+ columns: z.number().int().positive(),
434
+ rows: z.number().int().positive(),
435
+ margin: z.number().nonnegative().optional(),
436
+ spacing: z.number().nonnegative().optional(),
437
+ names: z.array(z.string()).optional()
438
+ });
439
+ var SemanticAssetRefSchema = z.object({
440
+ role: z.string().min(1),
441
+ category: z.string().min(1),
442
+ animations: z.array(z.string()).optional(),
443
+ style: VisualStyleSchema.optional(),
444
+ variant: z.string().optional(),
445
+ dimension: AssetDimensionSchema.optional(),
446
+ aspect: AssetAspectSchema.optional()
447
+ });
448
+ SemanticAssetRefSchema.extend({
449
+ url: z.string(),
450
+ atlas: z.string().optional(),
451
+ sprite: z.string().optional(),
452
+ name: z.string().optional(),
453
+ thumbnailUrl: z.string().optional()
454
+ });
455
+ var AssetCatalogEntrySchema = z.object({
456
+ url: z.string(),
457
+ name: z.string(),
458
+ category: z.string(),
459
+ kind: z.enum(["image", "spritesheet", "audio", "scene", "portrait", "model", "other"]),
460
+ thumbnailUrl: z.string().optional(),
461
+ dimension: AssetDimensionSchema.optional(),
462
+ aspect: AssetAspectSchema.optional()
463
+ });
464
+ z.array(AssetCatalogEntrySchema);
465
+ var ScenePosSchema = z.object({
466
+ x: z.number(),
467
+ y: z.number(),
468
+ z: z.number().optional()
469
+ });
470
+ var CAMERA_MODES = ["isometric", "perspective", "top-down", "follow", "chase"];
471
+ var CameraModeSchema = z.enum(CAMERA_MODES);
472
+ z.object({
473
+ pos: ScenePosSchema.optional(),
474
+ target: ScenePosSchema.optional(),
475
+ zoom: z.number().optional(),
476
+ fov: z.number().optional(),
477
+ mode: CameraModeSchema.optional()
478
+ });
479
+
480
+ // src/types/entity.ts
481
+ var EntityPersistenceSchema = z.enum([
482
+ "persistent",
483
+ "runtime"
484
+ ]);
485
+ z.object({
486
+ name: z.string().min(1, "Entity name is required"),
487
+ persistence: EntityPersistenceSchema.default("persistent"),
488
+ shared: z.boolean().optional(),
489
+ collection: z.string().optional(),
490
+ fields: z.array(EntityFieldSchema).min(1, "At least one field is required"),
491
+ instances: z.array(z.record(z.unknown())).optional(),
492
+ timestamps: z.boolean().optional(),
493
+ softDelete: z.boolean().optional(),
494
+ description: z.string().optional(),
495
+ visual_prompt: z.string().optional(),
496
+ assetRef: SemanticAssetRefSchema.optional()
497
+ });
498
+ function isFieldValue(value) {
499
+ if (value === null) return true;
500
+ const kind = typeof value;
501
+ if (kind === "string" || kind === "number" || kind === "boolean") return true;
502
+ if (value instanceof Date) return true;
503
+ if (Array.isArray(value)) return value.every((item) => isFieldValue(item));
504
+ if (kind === "object" && value !== null && typeof value === "object") {
505
+ return Object.values(value).every((item) => item === void 0 || isFieldValue(item));
506
+ }
507
+ return false;
508
+ }
509
+
510
+ // src/mock/sampleValue.ts
511
+ var MAX_NESTED_DEPTH = 3;
512
+ var RESERVED_FIELD_NAMES = /* @__PURE__ */ new Set(["id", "createdAt", "updatedAt"]);
513
+ var IMAGE_FIELD_NAMES = /* @__PURE__ */ new Set([
514
+ "image",
515
+ "imageurl",
516
+ "image_url",
517
+ "photo",
518
+ "photourl",
519
+ "photo_url",
520
+ "avatar",
521
+ "avatarurl",
522
+ "avatar_url",
523
+ "thumbnail",
524
+ "thumbnailurl",
525
+ "thumbnail_url",
526
+ "picture",
527
+ "pictureurl",
528
+ "cover",
529
+ "coverurl",
530
+ "banner",
531
+ "bannerurl"
532
+ ]);
533
+ function sampleImageUrl(entityName, fieldName, ctx, width = 400, height = 400) {
534
+ const salt = ctx.strategy === "seeded" ? randomInt({ min: 0, max: 1e3 }) : ctx.index;
535
+ const seed = `${entityName}-${fieldName}-${salt}`;
536
+ return `https://picsum.photos/seed/${encodeURIComponent(seed)}/${width}/${height}`;
537
+ }
538
+ function titleCase(name) {
539
+ const spaced = name.split("").flatMap((c) => c === "_" || c === "-" ? [" "] : c === c.toUpperCase() && c !== c.toLowerCase() ? [" ", c] : [c]).join("");
540
+ return spaced.split(/\s+/).filter((w) => w.length > 0).map((w) => w.charAt(0).toUpperCase() + w.slice(1)).join(" ");
541
+ }
542
+ function slug(name) {
543
+ return name.replace(/[^a-zA-Z0-9]/g, "").toLowerCase() || "value";
544
+ }
545
+ function indexUuid(index) {
546
+ return `00000000-0000-4000-8000-${index.toString(16).padStart(12, "0").slice(-12)}`;
547
+ }
548
+ function declaredValues(field) {
549
+ const values = "values" in field ? field.values : void 0;
550
+ return values && values.length > 0 ? values : void 0;
551
+ }
552
+ function isDeclaredDefaultHonored(field) {
553
+ const value = field.default;
554
+ if (value === void 0 || value === null) return false;
555
+ if (typeof value === "number" || typeof value === "boolean") return true;
556
+ if (Array.isArray(value)) return true;
557
+ if (typeof value === "object") return true;
558
+ if (typeof value !== "string") return false;
559
+ const values = declaredValues(field);
560
+ if (value === "") return values !== void 0 && values.includes("");
561
+ return values === void 0;
562
+ }
563
+ function sampleRowCount(entity, requested) {
564
+ return entity.persistence === "runtime" ? 1 : requested;
565
+ }
566
+ function sampleText(field, ctx) {
567
+ const fieldName = field.name ?? "field";
568
+ if (IMAGE_FIELD_NAMES.has(fieldName.toLowerCase())) {
569
+ return sampleImageUrl(ctx.entityName, fieldName, ctx);
570
+ }
571
+ return ctx.strategy === "seeded" ? randomWords(2) : `${titleCase(fieldName)} ${ctx.index}`;
572
+ }
573
+ function sampleDate(ctx, dateOnly) {
574
+ if (ctx.strategy === "index") {
575
+ const month = String(ctx.index % 12 + 1).padStart(2, "0");
576
+ return dateOnly ? `2026-${month}-15` : `2026-${month}-15T00:00:00.000Z`;
577
+ }
578
+ const iso = randomRecentDate({ days: 30 }).toISOString();
579
+ return dateOnly ? iso.split("T")[0] : iso;
580
+ }
581
+ function sampleRelation(field) {
582
+ return field.relation?.cardinality === "one" ? "" : [];
583
+ }
584
+ function sampleArray(field, ctx) {
585
+ const depth = ctx.depth ?? 0;
586
+ if (!field.items || depth >= MAX_NESTED_DEPTH) return [];
587
+ const count = ctx.strategy === "seeded" ? randomInt({ min: 3, max: 5 }) : 3;
588
+ const elementName = field.name ?? "item";
589
+ const out = [];
590
+ for (let i = 0; i < count; i++) {
591
+ const element = { ...field.items, name: `${elementName}[${i}]` };
592
+ out.push(
593
+ sampleFieldValue(element, {
594
+ ...ctx,
595
+ index: ctx.index * 10 + i,
596
+ depth: depth + 1
597
+ }) ?? null
598
+ );
599
+ }
600
+ return out;
601
+ }
602
+ function sampleObject(field, ctx) {
603
+ const depth = ctx.depth ?? 0;
604
+ if (!field.properties || depth >= MAX_NESTED_DEPTH) return null;
605
+ const out = {};
606
+ for (const [propName, propField] of Object.entries(field.properties)) {
607
+ const child = { ...propField, name: propName };
608
+ out[propName] = sampleFieldValue(child, { ...ctx, depth: depth + 1 }) ?? null;
609
+ }
610
+ return out;
611
+ }
612
+ function sampleFieldValue(field, ctx) {
613
+ const honoredDefault = field.default !== void 0 && isFieldValue(field.default) ? field.default : void 0;
614
+ if (field.intrinsic === true) return honoredDefault;
615
+ const isRuntime = ctx.persistence === "runtime";
616
+ if (isRuntime && honoredDefault !== void 0) return honoredDefault;
617
+ if (!isRuntime && isDeclaredDefaultHonored(field) && honoredDefault !== void 0) {
618
+ return honoredDefault;
619
+ }
620
+ const values = declaredValues(field);
621
+ if (values) {
622
+ const ordinal = isRuntime ? 1 : ctx.index;
623
+ return values[(ordinal - 1) % values.length];
624
+ }
625
+ switch (field.type) {
626
+ case "string":
627
+ return sampleText(field, ctx);
628
+ // Semantic domains synthesize a value that SATISFIES their own validator —
629
+ // the property that keeps the seeder and the validator from drifting.
630
+ case "email":
631
+ return ctx.strategy === "seeded" ? randomEmail() : `${slug(field.name ?? "user")}${ctx.index}@example.com`;
632
+ case "url":
633
+ return ctx.strategy === "seeded" ? randomUrl() : `https://example.com/${slug(field.name ?? "link")}/${ctx.index}`;
634
+ case "phone":
635
+ return ctx.strategy === "seeded" ? randomPhone() : `+1-555-${String(1e3 + ctx.index % 9e3).padStart(4, "0")}`;
636
+ case "uuid":
637
+ return ctx.strategy === "seeded" ? randomUuid() : indexUuid(ctx.index);
638
+ case "image":
639
+ return sampleImageUrl(ctx.entityName, field.name ?? "image", ctx);
640
+ case "number": {
641
+ if (ctx.strategy === "seeded") {
642
+ return randomInt({ min: field.min ?? 0, max: field.max ?? 100 });
643
+ }
644
+ const stepped = (field.min ?? 0) + ctx.index * 10;
645
+ return field.max !== void 0 && stepped > field.max ? field.max : stepped;
646
+ }
647
+ case "boolean":
648
+ return ctx.strategy === "seeded" ? randomBoolean() : ctx.index % 2 === 0;
649
+ case "date":
650
+ return sampleDate(ctx, true);
651
+ case "timestamp":
652
+ case "datetime":
653
+ return sampleDate(ctx, false);
654
+ case "enum":
655
+ return null;
656
+ case "relation":
657
+ return sampleRelation(field);
658
+ case "array":
659
+ return sampleArray(field, ctx);
660
+ case "object":
661
+ return sampleObject(field, ctx);
662
+ case "trait":
663
+ case "slot":
664
+ case "pattern":
665
+ return void 0;
666
+ default:
667
+ return sampleText(field, ctx);
668
+ }
669
+ }
670
+ function sampleRow(entity, ctx) {
671
+ const row = {};
672
+ for (const field of entity.fields) {
673
+ const name = field.name;
674
+ if (!name || RESERVED_FIELD_NAMES.has(name)) continue;
675
+ const value = sampleFieldValue(field, {
676
+ ...ctx,
677
+ entityName: entity.name,
678
+ persistence: ctx.persistence ?? entity.persistence
679
+ });
680
+ if (value !== void 0) row[name] = value;
681
+ }
682
+ return row;
683
+ }
684
+ function sampleRows(entity, count, strategy) {
685
+ const rowCount = sampleRowCount(entity, count);
686
+ const rows = [];
687
+ for (let i = 1; i <= rowCount; i++) {
688
+ rows.push(sampleRow(entity, { index: i, strategy, persistence: entity.persistence }));
689
+ }
690
+ return rows;
691
+ }
692
+
693
+ export { IMAGE_FIELD_NAMES, isDeclaredDefaultHonored, randomAnytimeDate, randomArrayElement, randomBoolean, randomColor, randomEmail, randomFloat, randomInt, randomPassword, randomPastDate, randomPhone, randomRecentDate, randomSentence, randomUrl, randomUuid, randomWords, sampleFieldValue, sampleImageUrl, sampleRow, sampleRowCount, sampleRows, seedRandom, shuffleArray };
694
+ //# sourceMappingURL=index.js.map
695
+ //# sourceMappingURL=index.js.map