@almadar/runtime 5.7.0 → 5.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.
- package/dist/LocalPersistenceAdapter.d.ts +46 -0
- package/dist/LocalPersistenceAdapter.js +79 -0
- package/dist/LocalPersistenceAdapter.js.map +1 -0
- package/dist/{OrbitalServerRuntime-BMOr7miw.d.ts → OrbitalServerRuntime-BP5sz5Bn.d.ts} +2 -107
- package/dist/OrbitalServerRuntime.d.ts +2 -1
- package/dist/OrbitalServerRuntime.js +39 -367
- package/dist/OrbitalServerRuntime.js.map +1 -1
- package/dist/PersistenceAdapter-B6dQCbbU.d.ts +67 -0
- package/dist/{chunk-54YR5TKO.js → chunk-GW5OOIRO.js} +55 -11
- package/dist/chunk-GW5OOIRO.js.map +1 -0
- package/dist/createOsHandlers.d.ts +28 -0
- package/dist/createOsHandlers.js +285 -0
- package/dist/createOsHandlers.js.map +1 -0
- package/dist/index.d.ts +6 -26
- package/dist/index.js +2 -2
- package/package.json +1 -1
- package/dist/chunk-54YR5TKO.js.map +0 -1
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { EntityRow } from '@almadar/core';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* PersistenceAdapter — the storage contract for runtime effect handlers.
|
|
5
|
+
*
|
|
6
|
+
* The server-side runtime and the in-browser mock runtime both invoke
|
|
7
|
+
* `fetch` / `persist` / `ref` / `deref` / `swap!` effects against an
|
|
8
|
+
* implementation of this interface. Extracted from
|
|
9
|
+
* `OrbitalServerRuntime.ts` so it can be imported by browser code that
|
|
10
|
+
* cannot depend on the server module (which pulls in express).
|
|
11
|
+
*
|
|
12
|
+
* @packageDocumentation
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Storage contract for CRUD operations on runtime entity rows.
|
|
17
|
+
*
|
|
18
|
+
* Implementations:
|
|
19
|
+
* - `InMemoryPersistence` (this file) — simple Map-backed store, used by
|
|
20
|
+
* the browser mock runtime and as the default when an adapter is not
|
|
21
|
+
* supplied to `OrbitalServerRuntime`.
|
|
22
|
+
* - `MockPersistenceAdapter` — in-memory with faker-generated seed data
|
|
23
|
+
* for realistic preview content.
|
|
24
|
+
* - `LocalPersistenceAdapter` — localStorage-backed, browser-safe.
|
|
25
|
+
* - Consumer-provided (e.g. Firestore, Postgres) for production servers.
|
|
26
|
+
*/
|
|
27
|
+
interface PersistenceAdapter {
|
|
28
|
+
create(entityType: string, data: EntityRow): Promise<{
|
|
29
|
+
id: string;
|
|
30
|
+
}>;
|
|
31
|
+
update(entityType: string, id: string, data: EntityRow): Promise<void>;
|
|
32
|
+
delete(entityType: string, id: string): Promise<void>;
|
|
33
|
+
getById(entityType: string, id: string): Promise<EntityRow | null>;
|
|
34
|
+
list(entityType: string): Promise<EntityRow[]>;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Simple in-memory persistence for dev/testing and offline previews.
|
|
38
|
+
* Keys each entity collection by type, rows by generated string id.
|
|
39
|
+
*/
|
|
40
|
+
declare class InMemoryPersistence implements PersistenceAdapter {
|
|
41
|
+
private data;
|
|
42
|
+
private idCounter;
|
|
43
|
+
/**
|
|
44
|
+
* Seed the store with pre-existing rows.
|
|
45
|
+
*
|
|
46
|
+
* Accepts either a plain `Record<entityType, EntityRow[]>` or an iterable
|
|
47
|
+
* of `[entityType, EntityRow[]]` entries. Rows without an `id` get one
|
|
48
|
+
* generated at insert time; rows with an `id` keep it (so re-seeding
|
|
49
|
+
* after a schema rebuild preserves identities used in render bindings).
|
|
50
|
+
*/
|
|
51
|
+
seed(seedData: Record<string, EntityRow[]> | Iterable<[string, EntityRow[]]>): void;
|
|
52
|
+
create(entityType: string, data: EntityRow): Promise<{
|
|
53
|
+
id: string;
|
|
54
|
+
}>;
|
|
55
|
+
update(entityType: string, id: string, data: EntityRow): Promise<void>;
|
|
56
|
+
delete(entityType: string, id: string): Promise<void>;
|
|
57
|
+
getById(entityType: string, id: string): Promise<EntityRow | null>;
|
|
58
|
+
list(entityType: string): Promise<EntityRow[]>;
|
|
59
|
+
/**
|
|
60
|
+
* Snapshot the entire store as a plain object (entityType → rows).
|
|
61
|
+
* Useful for feeding a fresh render-time binding layer with the
|
|
62
|
+
* current persistence view.
|
|
63
|
+
*/
|
|
64
|
+
snapshot(): Record<string, EntityRow[]>;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
export { InMemoryPersistence as I, type PersistenceAdapter as P };
|
|
@@ -2656,15 +2656,53 @@ function renameEntityInRenderUiConfig(node, oldName, newName) {
|
|
|
2656
2656
|
return next;
|
|
2657
2657
|
}
|
|
2658
2658
|
function renameEntityInEffects(effects, oldName, newName) {
|
|
2659
|
-
return effects.map((effect) =>
|
|
2660
|
-
|
|
2661
|
-
|
|
2662
|
-
|
|
2663
|
-
|
|
2664
|
-
|
|
2665
|
-
|
|
2666
|
-
|
|
2667
|
-
|
|
2659
|
+
return effects.map((effect) => renameEntityInEffect(effect, oldName, newName));
|
|
2660
|
+
}
|
|
2661
|
+
var ENTITY_AT_POS_1 = /* @__PURE__ */ new Set(["fetch", "ref", "deref", "spawn"]);
|
|
2662
|
+
var ALL_ARGS_ARE_EFFECTS = /* @__PURE__ */ new Set([
|
|
2663
|
+
"do",
|
|
2664
|
+
"atomic",
|
|
2665
|
+
"async/race",
|
|
2666
|
+
"async/all",
|
|
2667
|
+
"async/sequence"
|
|
2668
|
+
]);
|
|
2669
|
+
var ARGS_FROM_POS_2_ARE_EFFECTS = /* @__PURE__ */ new Set([
|
|
2670
|
+
"if",
|
|
2671
|
+
"when",
|
|
2672
|
+
"let",
|
|
2673
|
+
"async/delay",
|
|
2674
|
+
"async/debounce",
|
|
2675
|
+
"async/throttle",
|
|
2676
|
+
"async/interval"
|
|
2677
|
+
]);
|
|
2678
|
+
function renameEntityInEffect(effect, oldName, newName) {
|
|
2679
|
+
if (!Array.isArray(effect) || effect.length === 0) return effect;
|
|
2680
|
+
const op = effect[0];
|
|
2681
|
+
if (typeof op !== "string") return effect;
|
|
2682
|
+
if (op === "render-ui" && effect.length >= 3) {
|
|
2683
|
+
const [, slot, config, ...rest] = effect;
|
|
2684
|
+
const nextConfig = renameEntityInRenderUiConfig(config, oldName, newName);
|
|
2685
|
+
return [op, slot, nextConfig, ...rest];
|
|
2686
|
+
}
|
|
2687
|
+
if (op === "persist" && effect.length >= 3 && effect[2] === oldName) {
|
|
2688
|
+
return [op, effect[1], newName, ...effect.slice(3)];
|
|
2689
|
+
}
|
|
2690
|
+
if (ENTITY_AT_POS_1.has(op) && effect[1] === oldName) {
|
|
2691
|
+
return [op, newName, ...effect.slice(2)];
|
|
2692
|
+
}
|
|
2693
|
+
const skipFirstNonEffectArg = ARGS_FROM_POS_2_ARE_EFFECTS.has(op);
|
|
2694
|
+
const recurseAll = ALL_ARGS_ARE_EFFECTS.has(op);
|
|
2695
|
+
if (recurseAll || skipFirstNonEffectArg) {
|
|
2696
|
+
const startIndex = skipFirstNonEffectArg ? 2 : 1;
|
|
2697
|
+
return effect.map((arg, i) => {
|
|
2698
|
+
if (i < startIndex) return arg;
|
|
2699
|
+
if (Array.isArray(arg)) {
|
|
2700
|
+
return renameEntityInEffect(arg, oldName, newName);
|
|
2701
|
+
}
|
|
2702
|
+
return arg;
|
|
2703
|
+
});
|
|
2704
|
+
}
|
|
2705
|
+
return effect;
|
|
2668
2706
|
}
|
|
2669
2707
|
function applyLinkedEntityRename(trait, linkedEntity) {
|
|
2670
2708
|
const atomLinked = trait.linkedEntity;
|
|
@@ -2679,6 +2717,12 @@ function applyLinkedEntityRename(trait, linkedEntity) {
|
|
|
2679
2717
|
) : t.effects;
|
|
2680
2718
|
return { ...t, effects: nextEffects };
|
|
2681
2719
|
});
|
|
2720
|
+
refResolverLog.info("linkedEntity:rename", {
|
|
2721
|
+
trait: trait.name,
|
|
2722
|
+
from: atomLinked,
|
|
2723
|
+
to: linkedEntity,
|
|
2724
|
+
transitionCount: nextTransitions.length
|
|
2725
|
+
});
|
|
2682
2726
|
return {
|
|
2683
2727
|
...trait,
|
|
2684
2728
|
linkedEntity,
|
|
@@ -3433,5 +3477,5 @@ var InMemoryPersistence = class {
|
|
|
3433
3477
|
};
|
|
3434
3478
|
|
|
3435
3479
|
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 };
|
|
3436
|
-
//# sourceMappingURL=chunk-
|
|
3437
|
-
//# sourceMappingURL=chunk-
|
|
3480
|
+
//# sourceMappingURL=chunk-GW5OOIRO.js.map
|
|
3481
|
+
//# sourceMappingURL=chunk-GW5OOIRO.js.map
|