@almadar/runtime 1.0.1 → 1.0.10
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.
|
@@ -595,7 +595,13 @@ declare class OrbitalServerRuntime {
|
|
|
595
595
|
*
|
|
596
596
|
* For explicit preprocessing control, use `registerWithPreprocess()`.
|
|
597
597
|
*/
|
|
598
|
-
register(schema: RuntimeOrbitalSchema): void
|
|
598
|
+
register(schema: RuntimeOrbitalSchema): Promise<void>;
|
|
599
|
+
/**
|
|
600
|
+
* Register an OrbitalSchema synchronously (for backward compatibility).
|
|
601
|
+
* Note: This version doesn't wait for instance seeding to complete.
|
|
602
|
+
* Use async register() for guaranteed instance seeding.
|
|
603
|
+
*/
|
|
604
|
+
registerSync(schema: RuntimeOrbitalSchema): void;
|
|
599
605
|
/**
|
|
600
606
|
* Register an OrbitalSchema with preprocessing to resolve `uses` imports.
|
|
601
607
|
*
|
|
@@ -651,6 +657,10 @@ declare class OrbitalServerRuntime {
|
|
|
651
657
|
/**
|
|
652
658
|
* Register a single orbital
|
|
653
659
|
*/
|
|
660
|
+
private registerOrbitalAsync;
|
|
661
|
+
/**
|
|
662
|
+
* Register a single orbital (sync wrapper for backward compatibility)
|
|
663
|
+
*/
|
|
654
664
|
private registerOrbital;
|
|
655
665
|
/**
|
|
656
666
|
* Set up event listeners for cross-orbital communication
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import 'express';
|
|
2
|
-
export { n as EffectResult, L as LoaderConfig, O as OrbitalEventRequest, c as OrbitalEventResponse, o as OrbitalServerRuntime, d as OrbitalServerRuntimeConfig, P as PersistenceAdapter, R as RuntimeOrbital, h as RuntimeOrbitalSchema, i as RuntimeTrait, q as RuntimeTraitTick, r as createOrbitalServerRuntime } from './OrbitalServerRuntime-
|
|
2
|
+
export { n as EffectResult, L as LoaderConfig, O as OrbitalEventRequest, c as OrbitalEventResponse, o as OrbitalServerRuntime, d as OrbitalServerRuntimeConfig, P as PersistenceAdapter, R as RuntimeOrbital, h as RuntimeOrbitalSchema, i as RuntimeTrait, q as RuntimeTraitTick, r as createOrbitalServerRuntime } from './OrbitalServerRuntime-Bp1YgmI1.js';
|
|
3
3
|
import './types-LiBPiu-u.js';
|
|
4
4
|
import '@almadar/core';
|
|
@@ -987,12 +987,38 @@ var MockPersistenceAdapter = class {
|
|
|
987
987
|
// ============================================================================
|
|
988
988
|
/**
|
|
989
989
|
* Register an entity schema and seed mock data.
|
|
990
|
+
* If the schema has seedData, those instances are used directly.
|
|
991
|
+
* Otherwise, random mock data is generated with faker.
|
|
990
992
|
*/
|
|
991
993
|
registerEntity(schema, seedCount) {
|
|
992
994
|
const normalized = schema.name.toLowerCase();
|
|
993
995
|
this.schemas.set(normalized, schema);
|
|
994
|
-
|
|
995
|
-
|
|
996
|
+
if (schema.seedData && schema.seedData.length > 0) {
|
|
997
|
+
this.seedFromInstances(schema.name, schema.seedData);
|
|
998
|
+
} else {
|
|
999
|
+
const count = seedCount ?? this.config.defaultSeedCount ?? 6;
|
|
1000
|
+
this.seed(schema.name, schema.fields, count);
|
|
1001
|
+
}
|
|
1002
|
+
}
|
|
1003
|
+
/**
|
|
1004
|
+
* Seed an entity with pre-authored instance data.
|
|
1005
|
+
*/
|
|
1006
|
+
seedFromInstances(entityName, instances) {
|
|
1007
|
+
const store = this.getStore(entityName);
|
|
1008
|
+
if (this.config.debug) {
|
|
1009
|
+
console.log(`[MockPersistence] Seeding ${instances.length} ${entityName} from schema instances...`);
|
|
1010
|
+
}
|
|
1011
|
+
for (const instance of instances) {
|
|
1012
|
+
const id = instance.id || this.nextId(entityName);
|
|
1013
|
+
const now = (/* @__PURE__ */ new Date()).toISOString();
|
|
1014
|
+
const item = {
|
|
1015
|
+
...instance,
|
|
1016
|
+
id,
|
|
1017
|
+
createdAt: instance.createdAt || now,
|
|
1018
|
+
updatedAt: now
|
|
1019
|
+
};
|
|
1020
|
+
store.set(id, item);
|
|
1021
|
+
}
|
|
996
1022
|
}
|
|
997
1023
|
/**
|
|
998
1024
|
* Seed an entity with mock data.
|
|
@@ -2348,7 +2374,7 @@ var InMemoryPersistence = class {
|
|
|
2348
2374
|
data = /* @__PURE__ */ new Map();
|
|
2349
2375
|
idCounter = 0;
|
|
2350
2376
|
async create(entityType, data) {
|
|
2351
|
-
const id = `${entityType}-${++this.idCounter}`;
|
|
2377
|
+
const id = data.id || `${entityType}-${++this.idCounter}`;
|
|
2352
2378
|
if (!this.data.has(entityType)) {
|
|
2353
2379
|
this.data.set(entityType, /* @__PURE__ */ new Map());
|
|
2354
2380
|
}
|
|
@@ -2424,10 +2450,25 @@ var OrbitalServerRuntime = class {
|
|
|
2424
2450
|
*
|
|
2425
2451
|
* For explicit preprocessing control, use `registerWithPreprocess()`.
|
|
2426
2452
|
*/
|
|
2427
|
-
register(schema) {
|
|
2453
|
+
async register(schema) {
|
|
2428
2454
|
if (this.config.debug) {
|
|
2429
2455
|
console.log(`[OrbitalRuntime] Registering schema: ${schema.name}`);
|
|
2430
2456
|
}
|
|
2457
|
+
for (const orbital of schema.orbitals) {
|
|
2458
|
+
await this.registerOrbitalAsync(orbital);
|
|
2459
|
+
}
|
|
2460
|
+
this.setupEventListeners();
|
|
2461
|
+
this.setupTicks();
|
|
2462
|
+
}
|
|
2463
|
+
/**
|
|
2464
|
+
* Register an OrbitalSchema synchronously (for backward compatibility).
|
|
2465
|
+
* Note: This version doesn't wait for instance seeding to complete.
|
|
2466
|
+
* Use async register() for guaranteed instance seeding.
|
|
2467
|
+
*/
|
|
2468
|
+
registerSync(schema) {
|
|
2469
|
+
if (this.config.debug) {
|
|
2470
|
+
console.log(`[OrbitalRuntime] Registering schema (sync): ${schema.name}`);
|
|
2471
|
+
}
|
|
2431
2472
|
for (const orbital of schema.orbitals) {
|
|
2432
2473
|
this.registerOrbital(orbital);
|
|
2433
2474
|
}
|
|
@@ -2543,7 +2584,7 @@ var OrbitalServerRuntime = class {
|
|
|
2543
2584
|
/**
|
|
2544
2585
|
* Register a single orbital
|
|
2545
2586
|
*/
|
|
2546
|
-
|
|
2587
|
+
async registerOrbitalAsync(orbital) {
|
|
2547
2588
|
const traitDefs = orbital.traits.map((t) => {
|
|
2548
2589
|
const stateMachine = t.stateMachine;
|
|
2549
2590
|
const states = t.states || stateMachine?.states || [];
|
|
@@ -2561,10 +2602,30 @@ var OrbitalServerRuntime = class {
|
|
|
2561
2602
|
manager,
|
|
2562
2603
|
entityData: /* @__PURE__ */ new Map()
|
|
2563
2604
|
});
|
|
2564
|
-
|
|
2565
|
-
if (
|
|
2566
|
-
const
|
|
2567
|
-
|
|
2605
|
+
const entity = orbital.entity;
|
|
2606
|
+
if (entity?.name && entity.instances && Array.isArray(entity.instances)) {
|
|
2607
|
+
const instances = entity.instances;
|
|
2608
|
+
if (instances.length > 0) {
|
|
2609
|
+
console.log(`[OrbitalRuntime] Seeding ${instances.length} instances for ${entity.name} from schema`);
|
|
2610
|
+
const results = await Promise.all(
|
|
2611
|
+
instances.map(async (instance) => {
|
|
2612
|
+
try {
|
|
2613
|
+
const result = await this.persistence.create(entity.name, instance);
|
|
2614
|
+
console.log(`[OrbitalRuntime] Seeded instance: ${instance.id || "no-id"}`);
|
|
2615
|
+
return result;
|
|
2616
|
+
} catch (err) {
|
|
2617
|
+
console.error(`[OrbitalRuntime] Failed to seed instance ${instance.id}:`, err);
|
|
2618
|
+
return null;
|
|
2619
|
+
}
|
|
2620
|
+
})
|
|
2621
|
+
);
|
|
2622
|
+
const successCount = results.filter((r) => r !== null).length;
|
|
2623
|
+
console.log(`[OrbitalRuntime] Seeded ${successCount}/${instances.length} ${entity.name} instances from schema`);
|
|
2624
|
+
}
|
|
2625
|
+
} else if (this.config.mode === "mock" && this.persistence instanceof MockPersistenceAdapter) {
|
|
2626
|
+
if (this.config.debug) {
|
|
2627
|
+
console.log(`[OrbitalRuntime] No instances in schema, generating mock data for ${entity?.name}`);
|
|
2628
|
+
}
|
|
2568
2629
|
if (entity?.name && entity.fields) {
|
|
2569
2630
|
const fields = entity.fields.map((f) => ({
|
|
2570
2631
|
name: f.name,
|
|
@@ -2574,10 +2635,10 @@ var OrbitalServerRuntime = class {
|
|
|
2574
2635
|
default: f.default
|
|
2575
2636
|
}));
|
|
2576
2637
|
this.persistence.registerEntity({ name: entity.name, fields });
|
|
2577
|
-
|
|
2638
|
+
if (this.config.debug) {
|
|
2639
|
+
console.log(`[OrbitalRuntime] Seeded mock data for entity: ${entity.name}, count: ${this.persistence.count(entity.name)}`);
|
|
2640
|
+
}
|
|
2578
2641
|
}
|
|
2579
|
-
} else {
|
|
2580
|
-
console.log(`[OrbitalRuntime] Mock seeding SKIPPED`);
|
|
2581
2642
|
}
|
|
2582
2643
|
if (this.config.debug) {
|
|
2583
2644
|
console.log(
|
|
@@ -2585,6 +2646,14 @@ var OrbitalServerRuntime = class {
|
|
|
2585
2646
|
);
|
|
2586
2647
|
}
|
|
2587
2648
|
}
|
|
2649
|
+
/**
|
|
2650
|
+
* Register a single orbital (sync wrapper for backward compatibility)
|
|
2651
|
+
*/
|
|
2652
|
+
registerOrbital(orbital) {
|
|
2653
|
+
this.registerOrbitalAsync(orbital).catch((err) => {
|
|
2654
|
+
console.error(`[OrbitalRuntime] Failed to register orbital:`, err);
|
|
2655
|
+
});
|
|
2656
|
+
}
|
|
2588
2657
|
/**
|
|
2589
2658
|
* Set up event listeners for cross-orbital communication
|
|
2590
2659
|
*/
|