@telorun/kernel 0.2.4
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 +17 -0
- package/dist/boot-context-registry.d.ts +47 -0
- package/dist/boot-context-registry.d.ts.map +1 -0
- package/dist/boot-context-registry.js +131 -0
- package/dist/boot-context-registry.js.map +1 -0
- package/dist/capabilities/capabilities/component.yaml +3 -0
- package/dist/capabilities/capabilities/executable.yaml +7 -0
- package/dist/capabilities/capabilities/handler.yaml +3 -0
- package/dist/capabilities/capabilities/listener.yaml +3 -0
- package/dist/capabilities/capabilities/provider.yaml +3 -0
- package/dist/capabilities/capabilities/template.yaml +3 -0
- package/dist/capabilities/capabilities/type.yaml +3 -0
- package/dist/capabilities/component.yaml +3 -0
- package/dist/capabilities/executable.yaml +7 -0
- package/dist/capabilities/handler.yaml +3 -0
- package/dist/capabilities/listener.yaml +3 -0
- package/dist/capabilities/provider.yaml +3 -0
- package/dist/capabilities/template.yaml +3 -0
- package/dist/capabilities/type.yaml +3 -0
- package/dist/cli.d.ts +3 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +109 -0
- package/dist/cli.js.map +1 -0
- package/dist/controller-loader.d.ts +24 -0
- package/dist/controller-loader.d.ts.map +1 -0
- package/dist/controller-loader.js +265 -0
- package/dist/controller-loader.js.map +1 -0
- package/dist/controller-registry.d.ts +56 -0
- package/dist/controller-registry.d.ts.map +1 -0
- package/dist/controller-registry.js +169 -0
- package/dist/controller-registry.js.map +1 -0
- package/dist/controllers/capability/capability-controller.d.ts +37 -0
- package/dist/controllers/capability/capability-controller.d.ts.map +1 -0
- package/dist/controllers/capability/capability-controller.js +30 -0
- package/dist/controllers/capability/capability-controller.js.map +1 -0
- package/dist/controllers/module/module-controller.d.ts +16 -0
- package/dist/controllers/module/module-controller.d.ts.map +1 -0
- package/dist/controllers/module/module-controller.js +95 -0
- package/dist/controllers/module/module-controller.js.map +1 -0
- package/dist/controllers/module/module.json +48 -0
- package/dist/controllers/resource-definition/resource-definition-controller.d.ts +33 -0
- package/dist/controllers/resource-definition/resource-definition-controller.d.ts.map +1 -0
- package/dist/controllers/resource-definition/resource-definition-controller.js +44 -0
- package/dist/controllers/resource-definition/resource-definition-controller.js.map +1 -0
- package/dist/event-stream.d.ts +45 -0
- package/dist/event-stream.d.ts.map +1 -0
- package/dist/event-stream.js +98 -0
- package/dist/event-stream.js.map +1 -0
- package/dist/events.d.ts +13 -0
- package/dist/events.d.ts.map +1 -0
- package/dist/events.js +89 -0
- package/dist/events.js.map +1 -0
- package/dist/expressions.d.ts +20 -0
- package/dist/expressions.d.ts.map +1 -0
- package/dist/expressions.js +253 -0
- package/dist/expressions.js.map +1 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +9 -0
- package/dist/index.js.map +1 -0
- package/dist/kernel.d.ts +113 -0
- package/dist/kernel.d.ts.map +1 -0
- package/dist/kernel.js +558 -0
- package/dist/kernel.js.map +1 -0
- package/dist/loader.d.ts +17 -0
- package/dist/loader.d.ts.map +1 -0
- package/dist/loader.js +189 -0
- package/dist/loader.js.map +1 -0
- package/dist/manifest-adapters/http-adapter.d.ts +8 -0
- package/dist/manifest-adapters/http-adapter.d.ts.map +1 -0
- package/dist/manifest-adapters/http-adapter.js +29 -0
- package/dist/manifest-adapters/http-adapter.js.map +1 -0
- package/dist/manifest-adapters/local-file-adapter.d.ts +11 -0
- package/dist/manifest-adapters/local-file-adapter.d.ts.map +1 -0
- package/dist/manifest-adapters/local-file-adapter.js +51 -0
- package/dist/manifest-adapters/local-file-adapter.js.map +1 -0
- package/dist/manifest-adapters/manifest-adapter.d.ts +33 -0
- package/dist/manifest-adapters/manifest-adapter.d.ts.map +1 -0
- package/dist/manifest-adapters/manifest-adapter.js +2 -0
- package/dist/manifest-adapters/manifest-adapter.js.map +1 -0
- package/dist/manifest-adapters/registry-adapter.d.ts +9 -0
- package/dist/manifest-adapters/registry-adapter.d.ts.map +1 -0
- package/dist/manifest-adapters/registry-adapter.js +46 -0
- package/dist/manifest-adapters/registry-adapter.js.map +1 -0
- package/dist/manifest-schemas.d.ts +66 -0
- package/dist/manifest-schemas.d.ts.map +1 -0
- package/dist/manifest-schemas.js +55 -0
- package/dist/manifest-schemas.js.map +1 -0
- package/dist/registry.d.ts +41 -0
- package/dist/registry.d.ts.map +1 -0
- package/dist/registry.js +122 -0
- package/dist/registry.js.map +1 -0
- package/dist/resource-context.d.ts +48 -0
- package/dist/resource-context.d.ts.map +1 -0
- package/dist/resource-context.js +146 -0
- package/dist/resource-context.js.map +1 -0
- package/dist/resource-uri.d.ts +80 -0
- package/dist/resource-uri.d.ts.map +1 -0
- package/dist/resource-uri.js +160 -0
- package/dist/resource-uri.js.map +1 -0
- package/dist/schema-valiator.d.ts +9 -0
- package/dist/schema-valiator.d.ts.map +1 -0
- package/dist/schema-valiator.js +43 -0
- package/dist/schema-valiator.js.map +1 -0
- package/dist/snapshot-serializer.d.ts +63 -0
- package/dist/snapshot-serializer.d.ts.map +1 -0
- package/dist/snapshot-serializer.js +164 -0
- package/dist/snapshot-serializer.js.map +1 -0
- package/dist/src/controllers/module/module.yaml +32 -0
- package/dist/template-definition.d.ts +38 -0
- package/dist/template-definition.d.ts.map +1 -0
- package/dist/template-definition.js +26 -0
- package/dist/template-definition.js.map +1 -0
- package/dist/template-expander.d.ts +19 -0
- package/dist/template-expander.d.ts.map +1 -0
- package/dist/template-expander.js +425 -0
- package/dist/template-expander.js.map +1 -0
- package/dist/types.d.ts +62 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +8 -0
- package/dist/types.js.map +1 -0
- package/package.json +42 -0
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { RuntimeResource } from "@telorun/sdk";
|
|
2
|
+
import { ResourceInstance } from "./types.js";
|
|
3
|
+
export interface SnapshotData {
|
|
4
|
+
timestamp: string;
|
|
5
|
+
resources: Array<{
|
|
6
|
+
kind: string;
|
|
7
|
+
name: string;
|
|
8
|
+
metadata: Record<string, any>;
|
|
9
|
+
data: Record<string, any>;
|
|
10
|
+
snapshot?: Record<string, any>;
|
|
11
|
+
}>;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Serializes runtime state into YAML snapshots
|
|
15
|
+
* Captures resource definitions, instances, and custom state
|
|
16
|
+
* Recursively includes nested resources based on generationDepth
|
|
17
|
+
*/
|
|
18
|
+
export declare class SnapshotSerializer {
|
|
19
|
+
/**
|
|
20
|
+
* Take a snapshot of runtime state
|
|
21
|
+
* @param resources Map of resources organized by kind
|
|
22
|
+
* @param resourceInstances Map of resource instances to include custom snapshots
|
|
23
|
+
* @param filePath Optional file path to write snapshot to
|
|
24
|
+
* @returns Snapshot data object
|
|
25
|
+
*/
|
|
26
|
+
takeSnapshot(resources: Map<string, Map<string, RuntimeResource>>, resourceInstances?: Map<string, {
|
|
27
|
+
resource: RuntimeResource;
|
|
28
|
+
instance: ResourceInstance;
|
|
29
|
+
}>, filePath?: string): Promise<SnapshotData>;
|
|
30
|
+
/**
|
|
31
|
+
* Serialize a single resource
|
|
32
|
+
*/
|
|
33
|
+
private serializeResource;
|
|
34
|
+
/**
|
|
35
|
+
* Get snapshot from resource instance if it implements snapshot() method
|
|
36
|
+
*/
|
|
37
|
+
private getInstanceSnapshot;
|
|
38
|
+
/**
|
|
39
|
+
* Serialize metadata, filtering out circular references and functions
|
|
40
|
+
*/
|
|
41
|
+
private serializeMetadata;
|
|
42
|
+
/**
|
|
43
|
+
* Serialize resource data, filtering out circular references and functions
|
|
44
|
+
*/
|
|
45
|
+
private serializeData;
|
|
46
|
+
/**
|
|
47
|
+
* Group resources by generation depth for hierarchical ordering
|
|
48
|
+
*/
|
|
49
|
+
private groupByGenerationDepth;
|
|
50
|
+
/**
|
|
51
|
+
* Write snapshot to YAML file
|
|
52
|
+
*/
|
|
53
|
+
private writeSnapshotToFile;
|
|
54
|
+
/**
|
|
55
|
+
* Generate resource key for instance lookup
|
|
56
|
+
*/
|
|
57
|
+
private getResourceKey;
|
|
58
|
+
/**
|
|
59
|
+
* Load snapshot from YAML file
|
|
60
|
+
*/
|
|
61
|
+
loadSnapshotFromFile(filePath: string): Promise<SnapshotData>;
|
|
62
|
+
}
|
|
63
|
+
//# sourceMappingURL=snapshot-serializer.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"snapshot-serializer.d.ts","sourceRoot":"","sources":["../src/snapshot-serializer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAI/C,OAAO,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAE9C,MAAM,WAAW,YAAY;IAC3B,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,KAAK,CAAC;QACf,IAAI,EAAE,MAAM,CAAC;QACb,IAAI,EAAE,MAAM,CAAC;QACb,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;QAC9B,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;QAC1B,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;KAChC,CAAC,CAAC;CACJ;AAED;;;;GAIG;AACH,qBAAa,kBAAkB;IAC7B;;;;;;OAMG;IACG,YAAY,CAChB,SAAS,EAAE,GAAG,CAAC,MAAM,EAAE,GAAG,CAAC,MAAM,EAAE,eAAe,CAAC,CAAC,EACpD,iBAAiB,CAAC,EAAE,GAAG,CAAC,MAAM,EAAE;QAAE,QAAQ,EAAE,eAAe,CAAC;QAAC,QAAQ,EAAE,gBAAgB,CAAA;KAAE,CAAC,EAC1F,QAAQ,CAAC,EAAE,MAAM,GAChB,OAAO,CAAC,YAAY,CAAC;IA4BxB;;OAEG;YACW,iBAAiB;IAoC/B;;OAEG;YACW,mBAAmB;IAmBjC;;OAEG;IACH,OAAO,CAAC,iBAAiB;IAiBzB;;OAEG;IACH,OAAO,CAAC,aAAa;IAiBrB;;OAEG;IACH,OAAO,CAAC,sBAAsB;IAoB9B;;OAEG;YACW,mBAAmB;IAgBjC;;OAEG;IACH,OAAO,CAAC,cAAc;IAItB;;OAEG;IACG,oBAAoB,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,YAAY,CAAC;CAIpE"}
|
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
import * as fs from "fs/promises";
|
|
2
|
+
import * as YAML from "js-yaml";
|
|
3
|
+
import * as path from "path";
|
|
4
|
+
/**
|
|
5
|
+
* Serializes runtime state into YAML snapshots
|
|
6
|
+
* Captures resource definitions, instances, and custom state
|
|
7
|
+
* Recursively includes nested resources based on generationDepth
|
|
8
|
+
*/
|
|
9
|
+
export class SnapshotSerializer {
|
|
10
|
+
/**
|
|
11
|
+
* Take a snapshot of runtime state
|
|
12
|
+
* @param resources Map of resources organized by kind
|
|
13
|
+
* @param resourceInstances Map of resource instances to include custom snapshots
|
|
14
|
+
* @param filePath Optional file path to write snapshot to
|
|
15
|
+
* @returns Snapshot data object
|
|
16
|
+
*/
|
|
17
|
+
async takeSnapshot(resources, resourceInstances, filePath) {
|
|
18
|
+
const snapshot = {
|
|
19
|
+
timestamp: new Date().toISOString(),
|
|
20
|
+
resources: [],
|
|
21
|
+
};
|
|
22
|
+
// Get all resources organized by generation depth (0 = first level)
|
|
23
|
+
// Start with depth 0 (directly loaded resources) and recursively include nested ones
|
|
24
|
+
const resourcesByDepth = this.groupByGenerationDepth(resources);
|
|
25
|
+
// Process resources starting from depth 0
|
|
26
|
+
for (const depth of Array.from(resourcesByDepth.keys()).sort((a, b) => a - b)) {
|
|
27
|
+
const resourcesAtDepth = resourcesByDepth.get(depth) || [];
|
|
28
|
+
for (const resource of resourcesAtDepth) {
|
|
29
|
+
const resourceEntry = await this.serializeResource(resource, resourceInstances);
|
|
30
|
+
snapshot.resources.push(resourceEntry);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
// Write to file if path provided
|
|
34
|
+
if (filePath) {
|
|
35
|
+
await this.writeSnapshotToFile(snapshot, filePath);
|
|
36
|
+
}
|
|
37
|
+
return snapshot;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Serialize a single resource
|
|
41
|
+
*/
|
|
42
|
+
async serializeResource(resource, resourceInstances) {
|
|
43
|
+
const { kind, metadata, ...data } = resource;
|
|
44
|
+
const { name } = metadata;
|
|
45
|
+
const resourceEntry = {
|
|
46
|
+
kind,
|
|
47
|
+
name,
|
|
48
|
+
metadata: this.serializeMetadata(metadata),
|
|
49
|
+
data: this.serializeData(data),
|
|
50
|
+
};
|
|
51
|
+
// Include custom snapshot if resource instance has snapshot() method
|
|
52
|
+
if (resourceInstances) {
|
|
53
|
+
const key = this.getResourceKey(kind, name);
|
|
54
|
+
const instanceData = resourceInstances.get(key);
|
|
55
|
+
if (instanceData && instanceData.instance) {
|
|
56
|
+
const snapshotData = await this.getInstanceSnapshot(instanceData.instance);
|
|
57
|
+
if (snapshotData) {
|
|
58
|
+
resourceEntry.snapshot = snapshotData;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
return resourceEntry;
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Get snapshot from resource instance if it implements snapshot() method
|
|
66
|
+
*/
|
|
67
|
+
async getInstanceSnapshot(instance) {
|
|
68
|
+
const instanceAny = instance;
|
|
69
|
+
// Check if snapshot method exists
|
|
70
|
+
if (typeof instanceAny.snapshot === "function") {
|
|
71
|
+
try {
|
|
72
|
+
const result = await Promise.resolve(instanceAny.snapshot(instance));
|
|
73
|
+
return result;
|
|
74
|
+
}
|
|
75
|
+
catch (error) {
|
|
76
|
+
console.error("Error calling snapshot() on resource instance:", error);
|
|
77
|
+
return null;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
return null;
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Serialize metadata, filtering out circular references and functions
|
|
84
|
+
*/
|
|
85
|
+
serializeMetadata(metadata) {
|
|
86
|
+
const serialized = {};
|
|
87
|
+
for (const [key, value] of Object.entries(metadata)) {
|
|
88
|
+
if (typeof value === "function") {
|
|
89
|
+
continue;
|
|
90
|
+
}
|
|
91
|
+
try {
|
|
92
|
+
serialized[key] = JSON.parse(JSON.stringify(value));
|
|
93
|
+
}
|
|
94
|
+
catch {
|
|
95
|
+
// Skip non-serializable values
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
return serialized;
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Serialize resource data, filtering out circular references and functions
|
|
102
|
+
*/
|
|
103
|
+
serializeData(data) {
|
|
104
|
+
const serialized = {};
|
|
105
|
+
for (const [key, value] of Object.entries(data)) {
|
|
106
|
+
if (typeof value === "function") {
|
|
107
|
+
continue;
|
|
108
|
+
}
|
|
109
|
+
try {
|
|
110
|
+
serialized[key] = JSON.parse(JSON.stringify(value));
|
|
111
|
+
}
|
|
112
|
+
catch {
|
|
113
|
+
// Skip non-serializable values
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
return serialized;
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* Group resources by generation depth for hierarchical ordering
|
|
120
|
+
*/
|
|
121
|
+
groupByGenerationDepth(resources) {
|
|
122
|
+
const grouped = new Map();
|
|
123
|
+
for (const kindMap of resources.values()) {
|
|
124
|
+
for (const resource of kindMap.values()) {
|
|
125
|
+
const depth = resource.metadata.generationDepth ?? 0;
|
|
126
|
+
if (!grouped.has(depth)) {
|
|
127
|
+
grouped.set(depth, []);
|
|
128
|
+
}
|
|
129
|
+
grouped.get(depth).push(resource);
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
return grouped;
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* Write snapshot to YAML file
|
|
136
|
+
*/
|
|
137
|
+
async writeSnapshotToFile(snapshot, filePath) {
|
|
138
|
+
// Ensure directory exists
|
|
139
|
+
const dir = path.dirname(filePath);
|
|
140
|
+
if (dir !== "." && dir !== "") {
|
|
141
|
+
await fs.mkdir(dir, { recursive: true });
|
|
142
|
+
}
|
|
143
|
+
// Convert to YAML
|
|
144
|
+
const yaml = YAML.dump(snapshot, {
|
|
145
|
+
indent: 2,
|
|
146
|
+
lineWidth: 0,
|
|
147
|
+
});
|
|
148
|
+
await fs.writeFile(filePath, yaml, "utf-8");
|
|
149
|
+
}
|
|
150
|
+
/**
|
|
151
|
+
* Generate resource key for instance lookup
|
|
152
|
+
*/
|
|
153
|
+
getResourceKey(kind, name) {
|
|
154
|
+
return `${kind}:${name}`;
|
|
155
|
+
}
|
|
156
|
+
/**
|
|
157
|
+
* Load snapshot from YAML file
|
|
158
|
+
*/
|
|
159
|
+
async loadSnapshotFromFile(filePath) {
|
|
160
|
+
const content = await fs.readFile(filePath, "utf-8");
|
|
161
|
+
return YAML.load(content);
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
//# sourceMappingURL=snapshot-serializer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"snapshot-serializer.js","sourceRoot":"","sources":["../src/snapshot-serializer.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,MAAM,aAAa,CAAC;AAClC,OAAO,KAAK,IAAI,MAAM,SAAS,CAAC;AAChC,OAAO,KAAK,IAAI,MAAM,MAAM,CAAC;AAc7B;;;;GAIG;AACH,MAAM,OAAO,kBAAkB;IAC7B;;;;;;OAMG;IACH,KAAK,CAAC,YAAY,CAChB,SAAoD,EACpD,iBAA0F,EAC1F,QAAiB;QAEjB,MAAM,QAAQ,GAAiB;YAC7B,SAAS,EAAE,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE;YACnC,SAAS,EAAE,EAAE;SACd,CAAC;QAEF,oEAAoE;QACpE,qFAAqF;QACrF,MAAM,gBAAgB,GAAG,IAAI,CAAC,sBAAsB,CAAC,SAAS,CAAC,CAAC;QAEhE,0CAA0C;QAC1C,KAAK,M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QACnC,IAAI,GAAG,KAAK,GAAG,IAAI,GAAG,KAAK,EAAE,EAAE,CAAC;YAC9B,MAAM,EAAE,CAAC,KAAK,CAAC,GAAG,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;QAC3C,CAAC;QAED,kBAAkB;QAClB,MAAM,IAAI,GAAG,IAAI,CAAC,IAAI,CAAC,QAAQ,EAAE;YAC/B,MAAM,EAAE,CAAC;YACT,SAAS,EAAE,CAAC;SACb,CAAC,CAAC;QAEH,MAAM,EAAE,CAAC,SAAS,CAAC,QAAQ,EAAE,IAAI,EAAE,OAAO,CAAC,CAAC;IAC9C,CAAC;IAED;;OAEG;IACK,cAAc,CAAC,IAAY,EAAE,IAAY;QAC/C,OAAO,GAAG,IAAI,IAAI,IAAI,EAAE,CAAC;IAC3B,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,oBAAoB,CAAC,QAAgB;QACzC,MAAM,OAAO,GAAG,MAAM,EAAE,CAAC,QAAQ,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;QACrD,OAAO,IAAI,CAAC,IAAI,CAAC,OAAO,CAAiB,CAAC;IAC5C,CAAC;CACF"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
type: 'object'
|
|
2
|
+
properties:
|
|
3
|
+
metadata:
|
|
4
|
+
type: 'object'
|
|
5
|
+
properties:
|
|
6
|
+
name:
|
|
7
|
+
type: 'string'
|
|
8
|
+
required: ['name']
|
|
9
|
+
source:
|
|
10
|
+
type: 'string'
|
|
11
|
+
description: 'Path to module directory (relative to runtime root)'
|
|
12
|
+
imports:
|
|
13
|
+
type: 'array'
|
|
14
|
+
items:
|
|
15
|
+
type: 'string'
|
|
16
|
+
description: 'Paths to other modules to import'
|
|
17
|
+
definitions:
|
|
18
|
+
type: 'array'
|
|
19
|
+
items:
|
|
20
|
+
type: 'string'
|
|
21
|
+
description: 'Paths to ResourceDefinition files'
|
|
22
|
+
resources:
|
|
23
|
+
type: 'array'
|
|
24
|
+
items:
|
|
25
|
+
oneOf:
|
|
26
|
+
- type: 'string'
|
|
27
|
+
- type: 'object'
|
|
28
|
+
properties:
|
|
29
|
+
path:
|
|
30
|
+
type: 'string'
|
|
31
|
+
description: 'Paths to resource instance files to load'
|
|
32
|
+
required: ['metadata', 'source']
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { RuntimeResource } from "@telorun/sdk";
|
|
2
|
+
/**
|
|
3
|
+
* Built-in TemplateDefinition resource type
|
|
4
|
+
*/
|
|
5
|
+
export interface TemplateDefinition extends RuntimeResource {
|
|
6
|
+
kind: "TemplateDefinition";
|
|
7
|
+
schema: Record<string, any>;
|
|
8
|
+
resources: TemplateResourceBlueprint[];
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* A resource blueprint that can include control flow directives
|
|
12
|
+
*/
|
|
13
|
+
export interface TemplateResourceBlueprint {
|
|
14
|
+
for?: string | string[];
|
|
15
|
+
if?: string;
|
|
16
|
+
kind?: string;
|
|
17
|
+
metadata?: {
|
|
18
|
+
name: string;
|
|
19
|
+
[key: string]: any;
|
|
20
|
+
};
|
|
21
|
+
resource?: RuntimeResource;
|
|
22
|
+
[key: string]: any;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Template expansion context containing variables from schema
|
|
26
|
+
*/
|
|
27
|
+
export interface TemplateContext {
|
|
28
|
+
[varName: string]: any;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Validates if a resource is a TemplateDefinition
|
|
32
|
+
*/
|
|
33
|
+
export declare function isTemplateDefinition(resource: RuntimeResource): resource is TemplateDefinition;
|
|
34
|
+
/**
|
|
35
|
+
* Extracts default values from JSONSchema to build initial template context
|
|
36
|
+
*/
|
|
37
|
+
export declare function extractDefaultsFromSchema(schema: Record<string, any>): TemplateContext;
|
|
38
|
+
//# sourceMappingURL=template-definition.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"template-definition.d.ts","sourceRoot":"","sources":["../src/template-definition.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAE/C;;GAEG;AACH,MAAM,WAAW,kBAAmB,SAAQ,eAAe;IACzD,IAAI,EAAE,oBAAoB,CAAC;IAC3B,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IAC5B,SAAS,EAAE,yBAAyB,EAAE,CAAC;CACxC;AAED;;GAEG;AACH,MAAM,WAAW,yBAAyB;IAExC,GAAG,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC;IACxB,EAAE,CAAC,EAAE,MAAM,CAAC;IAGZ,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,QAAQ,CAAC,EAAE;QACT,IAAI,EAAE,MAAM,CAAC;QACb,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAC;KACpB,CAAC;IAGF,QAAQ,CAAC,EAAE,eAAe,CAAC;IAG3B,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAC;CACpB;AAED;;GAEG;AACH,MAAM,WAAW,eAAe;IAC9B,CAAC,OAAO,EAAE,MAAM,GAAG,GAAG,CAAC;CACxB;AAED;;GAEG;AACH,wBAAgB,oBAAoB,CAAC,QAAQ,EAAE,eAAe,GAAG,QAAQ,IAAI,kBAAkB,CAE9F;AAED;;GAEG;AACH,wBAAgB,yBAAyB,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,eAAe,CAmBtF"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Validates if a resource is a TemplateDefinition
|
|
3
|
+
*/
|
|
4
|
+
export function isTemplateDefinition(resource) {
|
|
5
|
+
return resource.kind === "TemplateDefinition";
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* Extracts default values from JSONSchema to build initial template context
|
|
9
|
+
*/
|
|
10
|
+
export function extractDefaultsFromSchema(schema) {
|
|
11
|
+
const context = {};
|
|
12
|
+
if (!schema || typeof schema !== "object") {
|
|
13
|
+
return context;
|
|
14
|
+
}
|
|
15
|
+
const properties = schema.properties;
|
|
16
|
+
if (!properties || typeof properties !== "object") {
|
|
17
|
+
return context;
|
|
18
|
+
}
|
|
19
|
+
for (const [key, propSchema] of Object.entries(properties)) {
|
|
20
|
+
if (propSchema && typeof propSchema === "object" && "default" in propSchema) {
|
|
21
|
+
context[key] = propSchema.default;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
return context;
|
|
25
|
+
}
|
|
26
|
+
//# sourceMappingURL=template-definition.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"template-definition.js","sourceRoot":"","sources":["../src/template-definition.ts"],"names":[],"mappings":"AAwCA;;GAEG;AACH,MAAM,UAAU,oBAAoB,CAAC,QAAyB;IAC5D,OAAO,QAAQ,CAAC,IAAI,KAAK,oBAAoB,CAAC;AAChD,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,yBAAyB,CAAC,MAA2B;IACnE,MAAM,OAAO,GAAoB,EAAE,CAAC;IAEpC,IAAI,CAAC,MAAM,IAAI,OAAO,MAAM,KAAK,QAAQ,EAAE,CAAC;QAC1C,OAAO,OAAO,CAAC;IACjB,CAAC;IAED,MAAM,UAAU,GAAG,MAAM,CAAC,UAAU,CAAC;IACrC,IAAI,CAAC,UAAU,IAAI,OAAO,UAAU,KAAK,QAAQ,EAAE,CAAC;QAClD,OAAO,OAAO,CAAC;IACjB,CAAC;IAED,KAAK,MAAM,CAAC,GAAG,EAAE,UAAU,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,UAAU,CAAC,EAAE,CAAC;QAC3D,IAAI,UAAU,IAAI,OAAO,UAAU,KAAK,QAAQ,IAAI,SAAS,IAAI,UAAU,EAAE,CAAC;YAC5E,OAAO,CAAC,GAAG,CAAC,GAAG,UAAU,CAAC,OAAO,CAAC;QACpC,CAAC;IACH,CAAC;IAED,OAAO,OAAO,CAAC;AACjB,CAAC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { RuntimeResource } from "@telorun/sdk";
|
|
2
|
+
import type { TemplateContext, TemplateDefinition } from "./template-definition.js";
|
|
3
|
+
/**
|
|
4
|
+
* Expands all TemplateDefinition resources into concrete resources
|
|
5
|
+
* Supports recursive expansion (templates can generate templates)
|
|
6
|
+
*/
|
|
7
|
+
export declare function expandTemplates(resources: RuntimeResource[]): RuntimeResource[];
|
|
8
|
+
/**
|
|
9
|
+
* Instantiates a template with provided parameters
|
|
10
|
+
* This is called when a resource of kind "Template.<Name>" is encountered
|
|
11
|
+
*/
|
|
12
|
+
export declare function instantiateTemplate(template: TemplateDefinition, parameters: Record<string, any>, instanceName: string, depth?: number, parentUri?: string): RuntimeResource[];
|
|
13
|
+
/**
|
|
14
|
+
* Expands array/object properties that contain 'for' directives
|
|
15
|
+
* Example: routes: [{ for: "r in routes", resource: { path: "${{ r }}" } }]
|
|
16
|
+
* Also supports nested loops with array syntax: { for: ["e in endpoints", "m in e.methods"], ... }
|
|
17
|
+
*/
|
|
18
|
+
export declare function expandPropertyWithControlFlow(value: any, context: TemplateContext): any;
|
|
19
|
+
//# sourceMappingURL=template-expander.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"template-expander.d.ts","sourceRoot":"","sources":["../src/template-expander.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAG/C,OAAO,KAAK,EACR,eAAe,EACf,kBAAkB,EAErB,MAAM,0BAA0B,CAAC;AAOlC;;;GAGG;AACH,wBAAgB,eAAe,CAAC,SAAS,EAAE,eAAe,EAAE,GAAG,eAAe,EAAE,CAsB/E;AAED;;;GAGG;AACH,wBAAgB,mBAAmB,CACjC,QAAQ,EAAE,kBAAkB,EAC5B,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EAC/B,YAAY,EAAE,MAAM,EACpB,KAAK,SAAI,EACT,SAAS,CAAC,EAAE,MAAM,GACjB,eAAe,EAAE,CAoBnB;AAucD;;;;GAIG;AACH,wBAAgB,6BAA6B,CAAC,KAAK,EAAE,GAAG,EAAE,OAAO,EAAE,eAAe,GAAG,GAAG,CA4BvF"}
|