@almadar/core 4.2.0 → 4.3.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.
@@ -1,5 +1,5 @@
1
1
  import { T as TraitEventContract, E as EntityField, a as EntityPersistence, b as EntityRow, O as OrbitalDefinition, c as OrbitalSchema, d as Trait, e as Entity, P as Page } from './schema-CDA_dJjH.js';
2
- export { C as ComposeBehaviorsInput, a as ComposeBehaviorsResult, E as EventWiringEntry, L as LayoutStrategy, b as applyEventWiring, c as composeBehaviors, d as detectLayoutStrategy } from './compose-behaviors-DQTTCmR2.js';
2
+ export { C as ComposeBehaviorsInput, a as ComposeBehaviorsResult, E as EventWiringEntry, L as LayoutStrategy, b as applyEventWiring, c as composeBehaviors, d as detectLayoutStrategy } from './compose-behaviors--NQpnVOA.js';
3
3
  import 'zod';
4
4
  import '@almadar/patterns';
5
5
 
@@ -52,6 +52,11 @@ declare function makePage(opts: MakePageOpts): Page;
52
52
  * Build an OrbitalDefinition from its three components.
53
53
  */
54
54
  declare function makeOrbital(name: string, entity: Entity, traits: Trait[], pages: Page[]): OrbitalDefinition;
55
+ /**
56
+ * Wrap one or more OrbitalDefinitions into an OrbitalSchema.
57
+ * Every .orb file should be a full OrbitalSchema — this is the builder for that.
58
+ */
59
+ declare function makeSchema(name: string, ...definitions: OrbitalDefinition[]): OrbitalSchema;
55
60
  /**
56
61
  * Merge multiple OrbitalDefinitions into one.
57
62
  * Collects all traits from all sources into a single orbital with a shared entity.
@@ -65,15 +70,16 @@ declare function mergeOrbitals(name: string, entity: Entity, sources: OrbitalDef
65
70
  */
66
71
  declare function wire(source: Trait, target: Trait, event: TraitEventContract, triggers: string): [Trait, Trait];
67
72
  /**
68
- * Extract the first trait from an OrbitalDefinition.
73
+ * Extract the first trait from an OrbitalDefinition or OrbitalSchema.
74
+ * If given an OrbitalSchema, unwraps to the first orbital inside it.
69
75
  */
70
- declare function extractTrait(orbital: OrbitalDefinition): Trait;
76
+ declare function extractTrait(input: OrbitalDefinition | OrbitalSchema): Trait;
71
77
  /**
72
78
  * Wire a cross-orbital event between two orbitals.
73
79
  * Adds emits to a's first trait, listens to b's first trait.
74
80
  * Pure: returns new orbitals, no mutation.
75
81
  */
76
- declare function connect(a: OrbitalDefinition, b: OrbitalDefinition, event: TraitEventContract, triggers?: string): [OrbitalDefinition, OrbitalDefinition];
82
+ declare function connect(a: OrbitalDefinition | OrbitalSchema, b: OrbitalDefinition | OrbitalSchema, event: TraitEventContract, triggers?: string): [OrbitalDefinition, OrbitalDefinition];
77
83
  interface ComposeConnection {
78
84
  from: string;
79
85
  to: string;
@@ -90,11 +96,11 @@ interface ComposePage {
90
96
  * Compose multiple orbitals into a single OrbitalSchema (application).
91
97
  * Applies connections (cross-orbital event wiring) and page assignments.
92
98
  */
93
- declare function compose(orbitals: OrbitalDefinition[], pages: ComposePage[], connections: ComposeConnection[], appName?: string): OrbitalSchema;
99
+ declare function compose(orbitals: (OrbitalDefinition | OrbitalSchema)[], pages: ComposePage[], connections: ComposeConnection[], appName?: string): OrbitalSchema;
94
100
  /**
95
101
  * Chain orbitals in sequence with automatic event wiring.
96
102
  * Sugar over connect + compose: wires events[0] from orbital[0] to orbital[1], etc.
97
103
  */
98
- declare function pipe(orbitals: OrbitalDefinition[], events: TraitEventContract[], appName?: string): OrbitalSchema;
104
+ declare function pipe(orbitals: (OrbitalDefinition | OrbitalSchema)[], events: TraitEventContract[], appName?: string): OrbitalSchema;
99
105
 
100
- export { type ComposeConnection, type ComposePage, type MakeEntityOpts, type MakePageOpts, compose, connect, ensureIdField, extractTrait, makeEntity, makeOrbital, makePage, mergeOrbitals, pipe, plural, wire };
106
+ export { type ComposeConnection, type ComposePage, type MakeEntityOpts, type MakePageOpts, compose, connect, ensureIdField, extractTrait, makeEntity, makeOrbital, makePage, makeSchema, mergeOrbitals, pipe, plural, wire };
package/dist/builders.js CHANGED
@@ -903,6 +903,14 @@ function applyEventWiring(orbitals, wiring) {
903
903
  }
904
904
 
905
905
  // src/builders/compose-behaviors.ts
906
+ function asDefinitions(inputs) {
907
+ return inputs.flatMap((input) => {
908
+ if ("orbitals" in input && Array.isArray(input.orbitals)) {
909
+ return input.orbitals;
910
+ }
911
+ return [input];
912
+ });
913
+ }
906
914
  function toKebabCase(name) {
907
915
  return name.replace(/([a-z])([A-Z])/g, "$1-$2").replace(/[\s_]+/g, "-").toLowerCase();
908
916
  }
@@ -953,10 +961,11 @@ function getEntityName(orbital) {
953
961
  function composeBehaviors(input) {
954
962
  const {
955
963
  appName,
956
- orbitals: rawOrbitals,
964
+ orbitals: rawInputs,
957
965
  layoutStrategy: strategyInput,
958
966
  eventWiring
959
967
  } = input;
968
+ const rawOrbitals = asDefinitions(rawInputs);
960
969
  const wiredOrbitals = eventWiring && eventWiring.length > 0 ? applyEventWiring(rawOrbitals, eventWiring) : rawOrbitals;
961
970
  const strategy = !strategyInput || strategyInput === "auto" ? detectLayoutStrategy(wiredOrbitals, eventWiring) : strategyInput;
962
971
  const pages = generatePages(wiredOrbitals, strategy);
@@ -1027,6 +1036,23 @@ function makePage(opts) {
1027
1036
  function makeOrbital(name, entity, traits, pages) {
1028
1037
  return { name, entity, traits, pages };
1029
1038
  }
1039
+ function makeSchema(name, ...definitions) {
1040
+ return { name, version: "1.0.0", orbitals: definitions };
1041
+ }
1042
+ function asDefinitions2(inputs) {
1043
+ return inputs.flatMap((input) => {
1044
+ if ("orbitals" in input && Array.isArray(input.orbitals)) {
1045
+ return input.orbitals;
1046
+ }
1047
+ return [input];
1048
+ });
1049
+ }
1050
+ function asDefinition(input) {
1051
+ if ("orbitals" in input && Array.isArray(input.orbitals)) {
1052
+ return input.orbitals[0];
1053
+ }
1054
+ return input;
1055
+ }
1030
1056
  function mergeOrbitals(name, entity, sources, pages) {
1031
1057
  const allTraits = sources.flatMap(
1032
1058
  (s) => s.traits.map((t) => structuredClone(t))
@@ -1044,12 +1070,13 @@ function wire(source, target, event, triggers) {
1044
1070
  }];
1045
1071
  return [s, t];
1046
1072
  }
1047
- function extractTrait(orbital) {
1073
+ function extractTrait(input) {
1074
+ const orbital = asDefinition(input);
1048
1075
  return structuredClone(orbital.traits[0]);
1049
1076
  }
1050
1077
  function connect(a, b, event, triggers) {
1051
- const aClone = structuredClone(a);
1052
- const bClone = structuredClone(b);
1078
+ const aClone = structuredClone(asDefinition(a));
1079
+ const bClone = structuredClone(asDefinition(b));
1053
1080
  const aTrait = aClone.traits[0];
1054
1081
  if (aTrait) {
1055
1082
  const emitContract = {
@@ -1070,7 +1097,7 @@ function connect(a, b, event, triggers) {
1070
1097
  return [aClone, bClone];
1071
1098
  }
1072
1099
  function compose(orbitals, pages, connections, appName) {
1073
- const cloned = structuredClone(orbitals);
1100
+ const cloned = structuredClone(asDefinitions2(orbitals));
1074
1101
  for (const conn of connections) {
1075
1102
  const emitter = cloned.find((o) => {
1076
1103
  const traits = o.traits;
@@ -1119,7 +1146,7 @@ function pipe(orbitals, events, appName) {
1119
1146
  if (events.length !== orbitals.length - 1) {
1120
1147
  throw new Error(`pipe requires exactly ${orbitals.length - 1} events for ${orbitals.length} orbitals`);
1121
1148
  }
1122
- const cloned = structuredClone(orbitals);
1149
+ const cloned = structuredClone(asDefinitions2(orbitals));
1123
1150
  for (let i = 0; i < events.length; i++) {
1124
1151
  const aTrait = cloned[i].traits[0];
1125
1152
  const bTrait = cloned[i + 1].traits[0];
@@ -1156,6 +1183,6 @@ function pipe(orbitals, events, appName) {
1156
1183
  };
1157
1184
  }
1158
1185
 
1159
- export { applyEventWiring, compose, composeBehaviors, connect, detectLayoutStrategy, ensureIdField, extractTrait, makeEntity, makeOrbital, makePage, mergeOrbitals, pipe, plural, wire };
1186
+ export { applyEventWiring, compose, composeBehaviors, connect, detectLayoutStrategy, ensureIdField, extractTrait, makeEntity, makeOrbital, makePage, makeSchema, mergeOrbitals, pipe, plural, wire };
1160
1187
  //# sourceMappingURL=builders.js.map
1161
1188
  //# sourceMappingURL=builders.js.map