@almadar/runtime 1.2.3 → 2.0.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/LICENSE CHANGED
@@ -1,72 +1,21 @@
1
- Business Source License 1.1
2
-
3
- Parameters
4
-
5
- Licensor: Almadar FZE
6
- Licensed Work: KFlow Builder / Almadar
7
- The Licensed Work is (c) 2025-2026 Almadar FZE.
8
- Additional Use Grant: You may make production use of the Licensed Work for
9
- non-commercial purposes and for internal evaluation.
10
- Production use for commercial purposes requires a
11
- commercial license from the Licensor.
12
- Change Date: 2030-02-01
13
- Change License: Apache License, Version 2.0
14
-
15
- Terms
16
-
17
- The Licensor hereby grants you the right to copy, modify, create derivative
18
- works, redistribute, and make non-production use of the Licensed Work. The
19
- Licensor may make an Additional Use Grant, above, permitting limited
20
- production use.
21
-
22
- Effective on the Change Date, or the fourth anniversary of the first publicly
23
- available distribution of a specific version of the Licensed Work under this
24
- License, whichever comes first, the Licensor hereby grants you rights under
25
- the terms of the Change License, and the rights granted in the paragraph
26
- above terminate.
27
-
28
- If your use of the Licensed Work does not comply with the requirements
29
- currently in effect as described in this License, you must purchase a
30
- commercial license from the Licensor, its affiliated entities, or authorized
31
- resellers, or you must refrain from using the Licensed Work.
32
-
33
- All copies of the original and modified Licensed Work, and derivative works
34
- of the Licensed Work, are subject to this License. This License applies
35
- separately for each version of the Licensed Work and the Change Date may vary
36
- for each version of the Licensed Work released by Licensor.
37
-
38
- You must conspicuously display this License on each original or modified copy
39
- of the Licensed Work. If you receive the Licensed Work in original or
40
- modified form from a third party, the terms and conditions set forth in this
41
- License apply to your use of that work.
42
-
43
- Any use of the Licensed Work in violation of this License will automatically
44
- terminate your rights under this License for the current and all other
45
- versions of the Licensed Work.
46
-
47
- This License does not grant you any right in any trademark or logo of
48
- Licensor or its affiliates (provided that you may use a trademark or logo of
49
- Licensor as expressly required by this License).
50
-
51
- TO THE EXTENT PERMITTED BY APPLICABLE LAW, THE LICENSED WORK IS PROVIDED ON
52
- AN "AS IS" BASIS. LICENSOR HEREBY DISCLAIMS ALL WARRANTIES AND CONDITIONS,
53
- EXPRESS OR IMPLIED, INCLUDING (WITHOUT LIMITATION) WARRANTIES OF
54
- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, NON-INFRINGEMENT, AND
55
- TITLE.
56
-
57
- ---
58
-
59
- License text copyright (c) 2017 MariaDB Corporation Ab, All Rights Reserved.
60
- "Business Source License" is a trademark of MariaDB Corporation Ab.
61
-
62
- ADDITIONAL TERMS:
63
-
64
- Documentation (builder/packages/website/docs/) is licensed under CC BY 4.0.
65
-
66
- TRADEMARKS:
67
-
68
- "Orbital", "KFlow", "Almadar", and the Almadar logo are trademarks of
69
- Almadar FZE. You may not use these trademarks without prior written
70
- permission from Almadar FZE.
71
-
72
- For licensing inquiries: licensing@almadar.io
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Almadar Team
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,25 @@
1
+ # @almadar/runtime
2
+
3
+ > Interpreted runtime for Almadar orbital applications (OrbitalServerRuntime)
4
+
5
+ Part of the [Almadar](https://github.com/almadar-io/almadar) platform.
6
+
7
+ ## Installation
8
+
9
+ ```bash
10
+ npm install @almadar/runtime
11
+ ```
12
+
13
+ ## Usage
14
+
15
+ ```typescript
16
+ import { /* ... */ } from '@almadar/runtime';
17
+ ```
18
+
19
+ ## API
20
+
21
+ <!-- Document public exports here -->
22
+
23
+ ## License
24
+
25
+ MIT
@@ -1,5 +1,5 @@
1
1
  import { Router } from 'express';
2
- import { I as IEventBus, R as RuntimeEvent, e as EventListener, U as Unsubscribe, E as EffectHandlers, d as Effect, T as TraitState } from './types-LiBPiu-u.js';
2
+ import { I as IEventBus, i as RuntimeEvent, h as EventListener, U as Unsubscribe, E as EffectHandlers, g as Effect, T as TraitState } from './types-9hbY6RWC.js';
3
3
  import { OrbitalSchema, Orbital, Trait } from '@almadar/core';
4
4
 
5
5
  /**
@@ -33,11 +33,20 @@ import { OrbitalSchema, Orbital, Trait } from '@almadar/core';
33
33
  declare class EventBus implements IEventBus {
34
34
  private listeners;
35
35
  private debug;
36
+ /** Maximum recursion depth before circuit breaker activates (RCG-05) */
37
+ private maxDepth;
38
+ /** Current emission depth for circular loop detection */
39
+ private depth;
36
40
  constructor(options?: {
37
41
  debug?: boolean;
42
+ maxDepth?: number;
38
43
  });
39
44
  /**
40
- * Emit an event to all registered listeners
45
+ * Emit an event to all registered listeners.
46
+ *
47
+ * Includes circuit breaker (RCG-05): if emit is called recursively
48
+ * beyond `maxDepth`, the event is dropped and an error is logged.
49
+ * This prevents infinite loops from circular emit/listen chains.
41
50
  */
42
51
  emit(type: string, payload?: Record<string, unknown>, source?: RuntimeEvent['source']): void;
43
52
  /**
@@ -421,6 +430,8 @@ interface RuntimeOrbital {
421
430
  name: string;
422
431
  type: string;
423
432
  }>;
433
+ /** Pre-defined entity instances to seed on registration */
434
+ instances?: Array<Record<string, unknown>>;
424
435
  };
425
436
  traits: RuntimeTrait[];
426
437
  }
@@ -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-Bp1YgmI1.js';
3
- import './types-LiBPiu-u.js';
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-CNyOL8XD.js';
3
+ import './types-9hbY6RWC.js';
4
4
  import '@almadar/core';
@@ -1,4 +1,4 @@
1
- import { EventBus, createUnifiedLoader, preprocessSchema, StateMachineManager, createContextFromBindings, EffectExecutor } from './chunk-QBQSJJF6.js';
1
+ import { EventBus, createUnifiedLoader, preprocessSchema, StateMachineManager, createContextFromBindings, EffectExecutor } from './chunk-EOMQVFFE.js';
2
2
  import { Router } from 'express';
3
3
  import { evaluateGuard } from '@almadar/evaluator';
4
4
  import { faker } from '@faker-js/faker';
@@ -877,6 +877,78 @@ var OrbitalServerRuntime = class {
877
877
  }
878
878
  },
879
879
  persist: async (action, targetEntityType, data) => {
880
+ if (action === "batch") {
881
+ const operations = data?.operations;
882
+ if (!Array.isArray(operations) || operations.length === 0) {
883
+ effectResults.push({
884
+ effect: "persist",
885
+ action: "batch",
886
+ success: false,
887
+ error: "Batch requires a non-empty operations array"
888
+ });
889
+ return;
890
+ }
891
+ const batchResults = [];
892
+ const completed = [];
893
+ let batchFailed = false;
894
+ let batchError = "";
895
+ for (const op of operations) {
896
+ if (!Array.isArray(op) || op.length < 2) {
897
+ batchFailed = true;
898
+ batchError = `Invalid batch operation format: ${JSON.stringify(op)}`;
899
+ break;
900
+ }
901
+ const [opAction, opEntityType, ...opRest] = op;
902
+ try {
903
+ switch (opAction) {
904
+ case "create": {
905
+ const createData = opRest[0] || {};
906
+ const { id: newId } = await this.persistence.create(opEntityType, createData);
907
+ batchResults.push({ action: "create", entityType: opEntityType, id: newId, ...createData });
908
+ completed.push({ action: "create", entityType: opEntityType, id: newId });
909
+ break;
910
+ }
911
+ case "update": {
912
+ const updateId = opRest[0];
913
+ const updateData = opRest[1] || {};
914
+ await this.persistence.update(opEntityType, updateId, updateData);
915
+ const updated = await this.persistence.getById(opEntityType, updateId);
916
+ batchResults.push({ action: "update", entityType: opEntityType, id: updateId, ...updated || updateData });
917
+ completed.push({ action: "update", entityType: opEntityType, id: updateId });
918
+ break;
919
+ }
920
+ case "delete": {
921
+ const deleteId = opRest[0];
922
+ await this.persistence.delete(opEntityType, deleteId);
923
+ batchResults.push({ action: "delete", entityType: opEntityType, id: deleteId, deleted: true });
924
+ completed.push({ action: "delete", entityType: opEntityType, id: deleteId });
925
+ break;
926
+ }
927
+ default:
928
+ batchFailed = true;
929
+ batchError = `Unknown batch operation action: ${opAction}`;
930
+ break;
931
+ }
932
+ } catch (err) {
933
+ batchFailed = true;
934
+ batchError = `Batch operation [${opAction}, ${opEntityType}] failed: ${err instanceof Error ? err.message : String(err)}`;
935
+ break;
936
+ }
937
+ if (batchFailed) break;
938
+ }
939
+ effectResults.push({
940
+ effect: "persist",
941
+ action: "batch",
942
+ data: {
943
+ operations: batchResults,
944
+ completedCount: completed.length,
945
+ totalCount: operations.length
946
+ },
947
+ success: !batchFailed,
948
+ ...batchFailed ? { error: batchError } : {}
949
+ });
950
+ return;
951
+ }
880
952
  const type = targetEntityType || entityType;
881
953
  let resultData;
882
954
  try {