@terraforge/core 0.0.8 → 0.0.9
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/index.d.ts +17 -17
- package/dist/index.js +1 -43
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -42,8 +42,8 @@ declare const interpolate: (literals: TemplateStringsArray, ...placeholders: Inp
|
|
|
42
42
|
type URN = `urn:${string}`;
|
|
43
43
|
|
|
44
44
|
declare const nodeMetaSymbol: unique symbol;
|
|
45
|
-
type Node<T extends Tag = Tag,
|
|
46
|
-
readonly [nodeMetaSymbol]: Meta<T
|
|
45
|
+
type Node<T extends Tag = Tag, O extends State = State> = {
|
|
46
|
+
readonly [nodeMetaSymbol]: Meta<T>;
|
|
47
47
|
readonly urn: URN;
|
|
48
48
|
} & O;
|
|
49
49
|
declare const isNode: (obj: object) => obj is {
|
|
@@ -66,14 +66,14 @@ type ResourceConfig = Config & {
|
|
|
66
66
|
/** If true, create the replacement before deleting the existing resource. */
|
|
67
67
|
createBeforeReplace?: boolean;
|
|
68
68
|
};
|
|
69
|
-
type ResourceMeta
|
|
70
|
-
type Resource<
|
|
71
|
-
readonly [nodeMetaSymbol]: ResourceMeta
|
|
69
|
+
type ResourceMeta = Meta<'resource', ResourceConfig>;
|
|
70
|
+
type Resource<O extends State = State> = O & {
|
|
71
|
+
readonly [nodeMetaSymbol]: ResourceMeta;
|
|
72
72
|
readonly urn: URN;
|
|
73
73
|
};
|
|
74
74
|
type ResourceClass<I extends State = State, O extends State = State> = {
|
|
75
|
-
new (parent: Group, id: string, props: I, config?: ResourceConfig): Resource<
|
|
76
|
-
get(parent: Group, id: string, physicalId: string): DataSource<
|
|
75
|
+
new (parent: Group, id: string, props: I, config?: ResourceConfig): Resource<O>;
|
|
76
|
+
get(parent: Group, id: string, physicalId: string): DataSource<O>;
|
|
77
77
|
};
|
|
78
78
|
|
|
79
79
|
declare class Stack extends Group {
|
|
@@ -87,31 +87,31 @@ type Tag = 'resource' | 'data';
|
|
|
87
87
|
type State = Record<string, unknown>;
|
|
88
88
|
type Config = {
|
|
89
89
|
/** Specify additional explicit dependencies in addition to the ones in the dependency graph. */
|
|
90
|
-
dependsOn?: Resource
|
|
90
|
+
dependsOn?: Resource[];
|
|
91
91
|
/** Pass an ID of an explicitly configured provider, instead of using the default provider. */
|
|
92
92
|
provider?: string;
|
|
93
93
|
};
|
|
94
|
-
type Meta<T extends Tag = Tag,
|
|
94
|
+
type Meta<T extends Tag = Tag, C extends Config = Config> = {
|
|
95
95
|
readonly tag: T;
|
|
96
96
|
readonly urn: URN;
|
|
97
97
|
readonly logicalId: string;
|
|
98
98
|
readonly type: string;
|
|
99
99
|
readonly stack: Stack;
|
|
100
100
|
readonly provider: string;
|
|
101
|
-
readonly input:
|
|
101
|
+
readonly input: State;
|
|
102
102
|
readonly config?: C;
|
|
103
103
|
readonly dependencies: Set<URN>;
|
|
104
|
-
readonly resolve: (data:
|
|
105
|
-
readonly output: <
|
|
104
|
+
readonly resolve: (data: State) => void;
|
|
105
|
+
readonly output: <V>(cb: (data: State) => V) => Output<V>;
|
|
106
106
|
};
|
|
107
|
-
declare const createMeta: <T extends Tag = Tag,
|
|
107
|
+
declare const createMeta: <T extends Tag = Tag, C extends Config = Config>(tag: T, provider: string, parent: Group, type: string, logicalId: string, input: State, config?: C) => Meta<T, C>;
|
|
108
108
|
|
|
109
|
-
type DataSourceMeta
|
|
110
|
-
type DataSource<
|
|
111
|
-
readonly [nodeMetaSymbol]: DataSourceMeta
|
|
109
|
+
type DataSourceMeta = Meta<'data'>;
|
|
110
|
+
type DataSource<O extends State = State> = {
|
|
111
|
+
readonly [nodeMetaSymbol]: DataSourceMeta;
|
|
112
112
|
readonly urn: URN;
|
|
113
113
|
} & O;
|
|
114
|
-
type DataSourceFunction<I extends State = State, O extends State = State> = (parent: Group, id: string, input: I, config?: Config) => DataSource<
|
|
114
|
+
type DataSourceFunction<I extends State = State, O extends State = State> = (parent: Group, id: string, input: I, config?: Config) => DataSource<O>;
|
|
115
115
|
|
|
116
116
|
declare class Group {
|
|
117
117
|
readonly parent: Group | undefined;
|
package/dist/index.js
CHANGED
|
@@ -186,40 +186,6 @@ var findInputDeps = (props) => {
|
|
|
186
186
|
find(props);
|
|
187
187
|
return deps;
|
|
188
188
|
};
|
|
189
|
-
var formatPath = (path) => {
|
|
190
|
-
if (path.length === 0) {
|
|
191
|
-
return "<root>";
|
|
192
|
-
}
|
|
193
|
-
return path.map((part) => {
|
|
194
|
-
if (typeof part === "number") {
|
|
195
|
-
return `[${part}]`;
|
|
196
|
-
}
|
|
197
|
-
return `.${part}`;
|
|
198
|
-
}).join("").replace(/^\./, "");
|
|
199
|
-
};
|
|
200
|
-
var findInputDepsWithPaths = (props) => {
|
|
201
|
-
const deps = [];
|
|
202
|
-
const find = (value, path) => {
|
|
203
|
-
if (value instanceof Output) {
|
|
204
|
-
for (const meta of value.dependencies) {
|
|
205
|
-
deps.push({
|
|
206
|
-
meta,
|
|
207
|
-
path: formatPath(path)
|
|
208
|
-
});
|
|
209
|
-
}
|
|
210
|
-
return;
|
|
211
|
-
}
|
|
212
|
-
if (Array.isArray(value)) {
|
|
213
|
-
value.map((item, index) => find(item, [...path, index]));
|
|
214
|
-
return;
|
|
215
|
-
}
|
|
216
|
-
if (value?.constructor === Object) {
|
|
217
|
-
Object.entries(value).map(([key, item]) => find(item, [...path, key]));
|
|
218
|
-
}
|
|
219
|
-
};
|
|
220
|
-
find(props, []);
|
|
221
|
-
return deps;
|
|
222
|
-
};
|
|
223
189
|
var resolveInputs = async (inputs) => {
|
|
224
190
|
const unresolved = [];
|
|
225
191
|
const find = (props, parent, key) => {
|
|
@@ -341,7 +307,7 @@ var createMeta = (tag, provider, parent, type, logicalId, input, config) => {
|
|
|
341
307
|
linkMetaDep(dep);
|
|
342
308
|
}
|
|
343
309
|
for (const dep of config?.dependsOn ?? []) {
|
|
344
|
-
linkMetaDep(dep
|
|
310
|
+
linkMetaDep(getMeta(dep));
|
|
345
311
|
}
|
|
346
312
|
return dependencies;
|
|
347
313
|
},
|
|
@@ -1137,14 +1103,6 @@ var deployApp = async (app, opt) => {
|
|
|
1137
1103
|
for (const node of stack.nodes) {
|
|
1138
1104
|
const meta = getMeta(node);
|
|
1139
1105
|
const dependencies = [...meta.dependencies];
|
|
1140
|
-
for (let i = 0; i < dependencies.length; i++) {
|
|
1141
|
-
if (!dependencies[i]) {
|
|
1142
|
-
const depPaths = findInputDepsWithPaths(meta.input).map((dep) => `${dep.path} -> ${dep.meta?.urn ?? "undefined"}`).join(", ");
|
|
1143
|
-
throw new Error(
|
|
1144
|
-
`Resource ${meta.urn} has an undefined dependency at index ${i}. Check inputs for missing/undefined Output references. ` + (depPaths ? `Dependency sources: ${depPaths}` : "")
|
|
1145
|
-
);
|
|
1146
|
-
}
|
|
1147
|
-
}
|
|
1148
1106
|
const partialNewResourceState = {
|
|
1149
1107
|
dependencies,
|
|
1150
1108
|
lifecycle: isResource(node) ? {
|