@almadar/runtime 6.22.0 → 6.24.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.
- package/dist/{OrbitalServerRuntime-CO0rEx3p.d.ts → OrbitalServerRuntime-h0NCwFuc.d.ts} +65 -10
- package/dist/OrbitalServerRuntime.d.ts +1 -2
- package/dist/OrbitalServerRuntime.js +2 -8
- package/dist/OrbitalServerRuntime.js.map +1 -1
- package/dist/{chunk-M7HMVDYF.js → chunk-4SX6WJKY.js} +2 -2
- package/dist/{chunk-M7HMVDYF.js.map → chunk-4SX6WJKY.js.map} +1 -1
- package/dist/index.d.ts +2 -4
- package/dist/index.js +2 -2
- package/package.json +4 -4
- package/dist/LocalPersistenceAdapter.d.ts +0 -46
- package/dist/LocalPersistenceAdapter.js +0 -79
- package/dist/LocalPersistenceAdapter.js.map +0 -1
- package/dist/PersistenceAdapter-B6dQCbbU.d.ts +0 -67
package/dist/index.d.ts
CHANGED
|
@@ -1,13 +1,11 @@
|
|
|
1
1
|
import { B as BindingContext, E as EvaluationContextExtensions, P as PatternProps, a as EffectHandlers, b as EffectContext, c as ExecutionEnvironment, d as EffectResult, T as TraitDefinition } from './types-BA7GoDni.js';
|
|
2
2
|
export { e as Effect, f as EventListener, H as HANDLER_MANIFEST, I as IEventBus, R as RuntimeConfig, g as RuntimeEvent, h as TraitState, i as TransitionObserver, j as TransitionResult, U as Unsubscribe } from './types-BA7GoDni.js';
|
|
3
|
-
import { U as UnifiedLoaderOptions, S as SchemaLoader, I as ImportChainLike, L as LoadResult, a as LoadedSchema, b as LoadedOrbital } from './OrbitalServerRuntime-
|
|
4
|
-
export { E as EntitySharingMap, c as EventBus, d as EventNamespaceMap, O as OrbitalEventRequest,
|
|
3
|
+
import { U as UnifiedLoaderOptions, S as SchemaLoader, I as ImportChainLike, L as LoadResult, a as LoadedSchema, b as LoadedOrbital, P as PersistenceAdapter } from './OrbitalServerRuntime-h0NCwFuc.js';
|
|
4
|
+
export { E as EntitySharingMap, c as EventBus, d as EventNamespaceMap, e as InMemoryPersistence, O as OrbitalEventRequest, f as OrbitalEventResponse, g as OrbitalServerRuntimeConfig, h as PreprocessOptions, i as PreprocessResult, j as PreprocessedSchema, k as ProcessEventOptions, R as RegisteredOrbital, l as RuntimeOrbital, m as RuntimeOrbitalSchema, n as RuntimeTrait, o as StateMachineManager, p as collectDeclaredConfigDefaults, q as collectDeclaredEntityDefaults, r as createInitialTraitState, s as findInitialState, t as findTransition, u as getIsolatedCollectionName, v as getNamespacedEvent, w as isBrowser, x as isElectron, y as isNamespacedEvent, z as isNode, A as normalizeEventKey, B as parseNamespacedEvent, C as preprocessSchema, D as processEvent } from './OrbitalServerRuntime-h0NCwFuc.js';
|
|
5
5
|
import { EvaluationContext } from '@almadar/evaluator';
|
|
6
6
|
export { EvaluationContext, createMinimalContext } from '@almadar/evaluator';
|
|
7
7
|
import { EventPayload, EntityField, EntityRow, ServiceParams, PayloadField, OrbitalDefinition, OrbitalSchema } from '@almadar/core';
|
|
8
8
|
export { EntityField } from '@almadar/core';
|
|
9
|
-
import { P as PersistenceAdapter } from './PersistenceAdapter-B6dQCbbU.js';
|
|
10
|
-
export { I as InMemoryPersistence } from './PersistenceAdapter-B6dQCbbU.js';
|
|
11
9
|
export { ServerBridgeConfig, ServerBridgeState } from './ServerBridge.js';
|
|
12
10
|
export { OsHandlerContext, OsHandlerResult } from './createOsHandlers.js';
|
|
13
11
|
import 'express';
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { EffectExecutor, createContextFromBindings } from './chunk-
|
|
2
|
-
export { EffectExecutor, EventBus, HANDLER_MANIFEST, InMemoryPersistence, MockPersistenceAdapter, StateMachineManager, TickScheduler, buildEmitsFromTraits, collectDeclaredConfigDefaults, collectDeclaredEntityDefaults, containsBindings, createContextFromBindings, createInitialTraitState, createMinimalContext, createMockPersistence, createTestExecutor, createTickScheduler, createUnifiedLoader, extractBindings, findInitialState, findTransition, formatPayloadValidationError, getIsolatedCollectionName, getNamespacedEvent, interpolateProps, interpolateValue, isBrowser, isElectron, isNamespacedEvent, isNode, isValidDurationString, normalizeEventKey, parseDurationString, parseNamespacedEvent, preprocessSchema, processEvent, validateEventPayload, validatePayloadShapes } from './chunk-
|
|
1
|
+
import { EffectExecutor, createContextFromBindings } from './chunk-4SX6WJKY.js';
|
|
2
|
+
export { EffectExecutor, EventBus, HANDLER_MANIFEST, InMemoryPersistence, MockPersistenceAdapter, StateMachineManager, TickScheduler, buildEmitsFromTraits, collectDeclaredConfigDefaults, collectDeclaredEntityDefaults, containsBindings, createContextFromBindings, createInitialTraitState, createMinimalContext, createMockPersistence, createTestExecutor, createTickScheduler, createUnifiedLoader, extractBindings, findInitialState, findTransition, formatPayloadValidationError, getIsolatedCollectionName, getNamespacedEvent, interpolateProps, interpolateValue, isBrowser, isElectron, isNamespacedEvent, isNode, isValidDurationString, normalizeEventKey, parseDurationString, parseNamespacedEvent, preprocessSchema, processEvent, validateEventPayload, validatePayloadShapes } from './chunk-4SX6WJKY.js';
|
|
3
3
|
export { cronMatches, cronMinuteKey, isValidCronExpression, parseCron, parseCronField } from './chunk-U4PL237A.js';
|
|
4
4
|
import { __export } from './chunk-PZ5AY32C.js';
|
|
5
5
|
import { createLogger } from '@almadar/logger';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@almadar/runtime",
|
|
3
|
-
"version": "6.
|
|
3
|
+
"version": "6.24.0",
|
|
4
4
|
"description": "Interpreted runtime for Almadar orbital applications (OrbitalServerRuntime)",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -10,8 +10,7 @@
|
|
|
10
10
|
"express": false,
|
|
11
11
|
"module": false,
|
|
12
12
|
"@almadar/server": false,
|
|
13
|
-
"./dist/createOsHandlers.js": false
|
|
14
|
-
"./dist/LocalPersistenceAdapter.js": false
|
|
13
|
+
"./dist/createOsHandlers.js": false
|
|
15
14
|
},
|
|
16
15
|
"exports": {
|
|
17
16
|
".": {
|
|
@@ -67,7 +66,8 @@
|
|
|
67
66
|
"express": "^5.0.0",
|
|
68
67
|
"tsup": "^8.0.0",
|
|
69
68
|
"typescript": "^5.7.0",
|
|
70
|
-
"vitest": "^2.1.0"
|
|
69
|
+
"vitest": "^2.1.0",
|
|
70
|
+
"turbo": "^2.8.17"
|
|
71
71
|
},
|
|
72
72
|
"repository": {
|
|
73
73
|
"type": "git",
|
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
import { EntityRow } from '@almadar/core';
|
|
2
|
-
import { P as PersistenceAdapter } from './PersistenceAdapter-B6dQCbbU.js';
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* LocalPersistenceAdapter - Filesystem CRUD for `persistence: "local"` entities.
|
|
6
|
-
*
|
|
7
|
-
* One directory per entity type, one JSON file per instance.
|
|
8
|
-
* Language-level feature: benefits all .orb programs, not just the agent.
|
|
9
|
-
* Offline-first apps, CLI tools, config managers, local databases all use it.
|
|
10
|
-
*
|
|
11
|
-
* @packageDocumentation
|
|
12
|
-
*/
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* Filesystem-backed persistence adapter.
|
|
16
|
-
*
|
|
17
|
-
* Storage layout:
|
|
18
|
-
* ```
|
|
19
|
-
* {root}/
|
|
20
|
-
* {entityType}/
|
|
21
|
-
* {id}.json
|
|
22
|
-
* ```
|
|
23
|
-
*/
|
|
24
|
-
declare class LocalPersistenceAdapter implements PersistenceAdapter {
|
|
25
|
-
private readonly root;
|
|
26
|
-
constructor(root: string);
|
|
27
|
-
private entityDir;
|
|
28
|
-
private filePath;
|
|
29
|
-
create(entityType: string, data: EntityRow): Promise<{
|
|
30
|
-
id: string;
|
|
31
|
-
}>;
|
|
32
|
-
update(entityType: string, id: string, data: EntityRow): Promise<void>;
|
|
33
|
-
delete(entityType: string, id: string): Promise<void>;
|
|
34
|
-
getById(entityType: string, id: string): Promise<EntityRow | null>;
|
|
35
|
-
list(entityType: string): Promise<EntityRow[]>;
|
|
36
|
-
/**
|
|
37
|
-
* Remove all data for an entity type.
|
|
38
|
-
*/
|
|
39
|
-
clear(entityType: string): Promise<void>;
|
|
40
|
-
/**
|
|
41
|
-
* Remove all local data.
|
|
42
|
-
*/
|
|
43
|
-
clearAll(): Promise<void>;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
export { LocalPersistenceAdapter };
|
|
@@ -1,79 +0,0 @@
|
|
|
1
|
-
import './chunk-PZ5AY32C.js';
|
|
2
|
-
import fs from 'fs';
|
|
3
|
-
import path from 'path';
|
|
4
|
-
|
|
5
|
-
var LocalPersistenceAdapter = class {
|
|
6
|
-
root;
|
|
7
|
-
constructor(root) {
|
|
8
|
-
this.root = root;
|
|
9
|
-
fs.mkdirSync(root, { recursive: true });
|
|
10
|
-
}
|
|
11
|
-
entityDir(entityType) {
|
|
12
|
-
const dir = path.join(this.root, entityType.toLowerCase());
|
|
13
|
-
fs.mkdirSync(dir, { recursive: true });
|
|
14
|
-
return dir;
|
|
15
|
-
}
|
|
16
|
-
filePath(entityType, id) {
|
|
17
|
-
return path.join(this.entityDir(entityType), `${id}.json`);
|
|
18
|
-
}
|
|
19
|
-
async create(entityType, data) {
|
|
20
|
-
const id = data.id || `${entityType.toLowerCase()}_${Date.now()}_${Math.random().toString(36).slice(2, 8)}`;
|
|
21
|
-
const record = { ...data, id };
|
|
22
|
-
const filePath = this.filePath(entityType, id);
|
|
23
|
-
fs.writeFileSync(filePath, JSON.stringify(record, null, 2), "utf-8");
|
|
24
|
-
return { id };
|
|
25
|
-
}
|
|
26
|
-
async update(entityType, id, data) {
|
|
27
|
-
const filePath = this.filePath(entityType, id);
|
|
28
|
-
let existing = { id };
|
|
29
|
-
if (fs.existsSync(filePath)) {
|
|
30
|
-
existing = JSON.parse(fs.readFileSync(filePath, "utf-8"));
|
|
31
|
-
}
|
|
32
|
-
const merged = { ...existing, ...data, id };
|
|
33
|
-
fs.writeFileSync(filePath, JSON.stringify(merged, null, 2), "utf-8");
|
|
34
|
-
}
|
|
35
|
-
async delete(entityType, id) {
|
|
36
|
-
const filePath = this.filePath(entityType, id);
|
|
37
|
-
if (fs.existsSync(filePath)) {
|
|
38
|
-
fs.unlinkSync(filePath);
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
async getById(entityType, id) {
|
|
42
|
-
const filePath = this.filePath(entityType, id);
|
|
43
|
-
if (!fs.existsSync(filePath)) return null;
|
|
44
|
-
return JSON.parse(fs.readFileSync(filePath, "utf-8"));
|
|
45
|
-
}
|
|
46
|
-
async list(entityType) {
|
|
47
|
-
const dir = this.entityDir(entityType);
|
|
48
|
-
if (!fs.existsSync(dir)) return [];
|
|
49
|
-
const files = fs.readdirSync(dir).filter((f) => f.endsWith(".json"));
|
|
50
|
-
const results = [];
|
|
51
|
-
for (const file of files) {
|
|
52
|
-
const content = fs.readFileSync(path.join(dir, file), "utf-8");
|
|
53
|
-
results.push(JSON.parse(content));
|
|
54
|
-
}
|
|
55
|
-
return results;
|
|
56
|
-
}
|
|
57
|
-
/**
|
|
58
|
-
* Remove all data for an entity type.
|
|
59
|
-
*/
|
|
60
|
-
async clear(entityType) {
|
|
61
|
-
const dir = path.join(this.root, entityType.toLowerCase());
|
|
62
|
-
if (fs.existsSync(dir)) {
|
|
63
|
-
fs.rmSync(dir, { recursive: true, force: true });
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
/**
|
|
67
|
-
* Remove all local data.
|
|
68
|
-
*/
|
|
69
|
-
async clearAll() {
|
|
70
|
-
if (fs.existsSync(this.root)) {
|
|
71
|
-
fs.rmSync(this.root, { recursive: true, force: true });
|
|
72
|
-
fs.mkdirSync(this.root, { recursive: true });
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
};
|
|
76
|
-
|
|
77
|
-
export { LocalPersistenceAdapter };
|
|
78
|
-
//# sourceMappingURL=LocalPersistenceAdapter.js.map
|
|
79
|
-
//# sourceMappingUR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AE,SAAA,EAAW,MAAM,CAAA;AAAA,IAC7C;AAAA,EACF;AACF","file":"LocalPersistenceAdapter.js","sourcesContent":["/**\n * LocalPersistenceAdapter - Filesystem CRUD for `persistence: \"local\"` entities.\n *\n * One directory per entity type, one JSON file per instance.\n * Language-level feature: benefits all .orb programs, not just the agent.\n * Offline-first apps, CLI tools, config managers, local databases all use it.\n *\n * @packageDocumentation\n */\n\nimport fs from 'fs';\nimport path from 'path';\nimport type { PersistenceAdapter } from './OrbitalServerRuntime.js';\nimport type { EntityRow } from './types.js';\n\n/**\n * Filesystem-backed persistence adapter.\n *\n * Storage layout:\n * ```\n * {root}/\n * {entityType}/\n * {id}.json\n * ```\n */\nexport class LocalPersistenceAdapter implements PersistenceAdapter {\n private readonly root: string;\n\n constructor(root: string) {\n this.root = root;\n fs.mkdirSync(root, { recursive: true });\n }\n\n private entityDir(entityType: string): string {\n const dir = path.join(this.root, entityType.toLowerCase());\n fs.mkdirSync(dir, { recursive: true });\n return dir;\n }\n\n private filePath(entityType: string, id: string): string {\n return path.join(this.entityDir(entityType), `${id}.json`);\n }\n\n async create(entityType: string, data: EntityRow): Promise<{ id: string }> {\n const id = (data.id as string) || `${entityType.toLowerCase()}_${Date.now()}_${Math.random().toString(36).slice(2, 8)}`;\n const record: EntityRow = { ...data, id };\n const filePath = this.filePath(entityType, id);\n fs.writeFileSync(filePath, JSON.stringify(record, null, 2), 'utf-8');\n return { id };\n }\n\n async update(entityType: string, id: string, data: EntityRow): Promise<void> {\n const filePath = this.filePath(entityType, id);\n let existing: EntityRow = { id };\n if (fs.existsSync(filePath)) {\n existing = JSON.parse(fs.readFileSync(filePath, 'utf-8')) as EntityRow;\n }\n const merged: EntityRow = { ...existing, ...data, id };\n fs.writeFileSync(filePath, JSON.stringify(merged, null, 2), 'utf-8');\n }\n\n async delete(entityType: string, id: string): Promise<void> {\n const filePath = this.filePath(entityType, id);\n if (fs.existsSync(filePath)) {\n fs.unlinkSync(filePath);\n }\n }\n\n async getById(entityType: string, id: string): Promise<EntityRow | null> {\n const filePath = this.filePath(entityType, id);\n if (!fs.existsSync(filePath)) return null;\n return JSON.parse(fs.readFileSync(filePath, 'utf-8')) as EntityRow;\n }\n\n async list(entityType: string): Promise<EntityRow[]> {\n const dir = this.entityDir(entityType);\n if (!fs.existsSync(dir)) return [];\n const files = fs.readdirSync(dir).filter(f => f.endsWith('.json'));\n const results: EntityRow[] = [];\n for (const file of files) {\n const content = fs.readFileSync(path.join(dir, file), 'utf-8');\n results.push(JSON.parse(content) as EntityRow);\n }\n return results;\n }\n\n /**\n * Remove all data for an entity type.\n */\n async clear(entityType: string): Promise<void> {\n const dir = path.join(this.root, entityType.toLowerCase());\n if (fs.existsSync(dir)) {\n fs.rmSync(dir, { recursive: true, force: true });\n }\n }\n\n /**\n * Remove all local data.\n */\n async clearAll(): Promise<void> {\n if (fs.existsSync(this.root)) {\n fs.rmSync(this.root, { recursive: true, force: true });\n fs.mkdirSync(this.root, { recursive: true });\n }\n }\n}\n"]}
|
|
@@ -1,67 +0,0 @@
|
|
|
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 };
|