@almadar/core 4.2.0 → 4.3.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/builders.d.ts +14 -8
- package/dist/builders.js +35 -7
- package/dist/builders.js.map +1 -1
- package/dist/{compose-behaviors-DQTTCmR2.d.ts → compose-behaviors--NQpnVOA.d.ts} +2 -2
- package/dist/index.d.ts +1 -1
- package/dist/index.js +10 -1
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/builders.d.ts
CHANGED
|
@@ -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
|
|
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
|
|
|
@@ -21,7 +21,7 @@ import '@almadar/patterns';
|
|
|
21
21
|
/**
|
|
22
22
|
* Ensure the fields array has an `id` field. Prepends one if missing.
|
|
23
23
|
*/
|
|
24
|
-
declare function ensureIdField(fields
|
|
24
|
+
declare function ensureIdField(fields?: EntityField[]): EntityField[];
|
|
25
25
|
/**
|
|
26
26
|
* Simple pluralization: append 's'.
|
|
27
27
|
*/
|
|
@@ -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(
|
|
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:
|
|
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);
|
|
@@ -989,6 +998,7 @@ function composeBehaviors(input) {
|
|
|
989
998
|
|
|
990
999
|
// src/builders.ts
|
|
991
1000
|
function ensureIdField(fields) {
|
|
1001
|
+
if (!fields || fields.length === 0) return [{ name: "id", type: "string", required: true }];
|
|
992
1002
|
if (fields.some((f) => f.name === "id")) return fields;
|
|
993
1003
|
return [{ name: "id", type: "string", required: true }, ...fields];
|
|
994
1004
|
}
|
|
@@ -1027,6 +1037,23 @@ function makePage(opts) {
|
|
|
1027
1037
|
function makeOrbital(name, entity, traits, pages) {
|
|
1028
1038
|
return { name, entity, traits, pages };
|
|
1029
1039
|
}
|
|
1040
|
+
function makeSchema(name, ...definitions) {
|
|
1041
|
+
return { name, version: "1.0.0", orbitals: definitions };
|
|
1042
|
+
}
|
|
1043
|
+
function asDefinitions2(inputs) {
|
|
1044
|
+
return inputs.flatMap((input) => {
|
|
1045
|
+
if ("orbitals" in input && Array.isArray(input.orbitals)) {
|
|
1046
|
+
return input.orbitals;
|
|
1047
|
+
}
|
|
1048
|
+
return [input];
|
|
1049
|
+
});
|
|
1050
|
+
}
|
|
1051
|
+
function asDefinition(input) {
|
|
1052
|
+
if ("orbitals" in input && Array.isArray(input.orbitals)) {
|
|
1053
|
+
return input.orbitals[0];
|
|
1054
|
+
}
|
|
1055
|
+
return input;
|
|
1056
|
+
}
|
|
1030
1057
|
function mergeOrbitals(name, entity, sources, pages) {
|
|
1031
1058
|
const allTraits = sources.flatMap(
|
|
1032
1059
|
(s) => s.traits.map((t) => structuredClone(t))
|
|
@@ -1044,12 +1071,13 @@ function wire(source, target, event, triggers) {
|
|
|
1044
1071
|
}];
|
|
1045
1072
|
return [s, t];
|
|
1046
1073
|
}
|
|
1047
|
-
function extractTrait(
|
|
1074
|
+
function extractTrait(input) {
|
|
1075
|
+
const orbital = asDefinition(input);
|
|
1048
1076
|
return structuredClone(orbital.traits[0]);
|
|
1049
1077
|
}
|
|
1050
1078
|
function connect(a, b, event, triggers) {
|
|
1051
|
-
const aClone = structuredClone(a);
|
|
1052
|
-
const bClone = structuredClone(b);
|
|
1079
|
+
const aClone = structuredClone(asDefinition(a));
|
|
1080
|
+
const bClone = structuredClone(asDefinition(b));
|
|
1053
1081
|
const aTrait = aClone.traits[0];
|
|
1054
1082
|
if (aTrait) {
|
|
1055
1083
|
const emitContract = {
|
|
@@ -1070,7 +1098,7 @@ function connect(a, b, event, triggers) {
|
|
|
1070
1098
|
return [aClone, bClone];
|
|
1071
1099
|
}
|
|
1072
1100
|
function compose(orbitals, pages, connections, appName) {
|
|
1073
|
-
const cloned = structuredClone(orbitals);
|
|
1101
|
+
const cloned = structuredClone(asDefinitions2(orbitals));
|
|
1074
1102
|
for (const conn of connections) {
|
|
1075
1103
|
const emitter = cloned.find((o) => {
|
|
1076
1104
|
const traits = o.traits;
|
|
@@ -1119,7 +1147,7 @@ function pipe(orbitals, events, appName) {
|
|
|
1119
1147
|
if (events.length !== orbitals.length - 1) {
|
|
1120
1148
|
throw new Error(`pipe requires exactly ${orbitals.length - 1} events for ${orbitals.length} orbitals`);
|
|
1121
1149
|
}
|
|
1122
|
-
const cloned = structuredClone(orbitals);
|
|
1150
|
+
const cloned = structuredClone(asDefinitions2(orbitals));
|
|
1123
1151
|
for (let i = 0; i < events.length; i++) {
|
|
1124
1152
|
const aTrait = cloned[i].traits[0];
|
|
1125
1153
|
const bTrait = cloned[i + 1].traits[0];
|
|
@@ -1156,6 +1184,6 @@ function pipe(orbitals, events, appName) {
|
|
|
1156
1184
|
};
|
|
1157
1185
|
}
|
|
1158
1186
|
|
|
1159
|
-
export { applyEventWiring, compose, composeBehaviors, connect, detectLayoutStrategy, ensureIdField, extractTrait, makeEntity, makeOrbital, makePage, mergeOrbitals, pipe, plural, wire };
|
|
1187
|
+
export { applyEventWiring, compose, composeBehaviors, connect, detectLayoutStrategy, ensureIdField, extractTrait, makeEntity, makeOrbital, makePage, makeSchema, mergeOrbitals, pipe, plural, wire };
|
|
1160
1188
|
//# sourceMappingURL=builders.js.map
|
|
1161
1189
|
//# sourceMappingURL=builders.js.map
|