@terraforge/core 0.0.3 → 0.0.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/dist/index.d.ts +17 -2
- package/dist/index.js +50 -3
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -21,6 +21,7 @@ declare class Output<T = unknown> extends Future<T> {
|
|
|
21
21
|
}
|
|
22
22
|
declare const deferredOutput: unknown;
|
|
23
23
|
declare const output: unknown;
|
|
24
|
+
type URN = `urn:${string}`;
|
|
24
25
|
declare const nodeMetaSymbol: unknown;
|
|
25
26
|
type Node<
|
|
26
27
|
T extends Tag = Tag,
|
|
@@ -28,7 +29,8 @@ type Node<
|
|
|
28
29
|
O extends State = any,
|
|
29
30
|
C extends Config = Config
|
|
30
31
|
> = {
|
|
31
|
-
[nodeMetaSymbol]: Meta<T, I, O, C>;
|
|
32
|
+
readonly [nodeMetaSymbol]: Meta<T, I, O, C>;
|
|
33
|
+
readonly urn: URN;
|
|
32
34
|
} & O;
|
|
33
35
|
declare const isNode: (obj: object) => obj is {
|
|
34
36
|
[nodeMetaSymbol]: Meta;
|
|
@@ -57,6 +59,7 @@ type Resource<
|
|
|
57
59
|
O extends State = State
|
|
58
60
|
> = O & {
|
|
59
61
|
readonly [nodeMetaSymbol]: ResourceMeta<I, O>;
|
|
62
|
+
readonly urn: URN;
|
|
60
63
|
};
|
|
61
64
|
type ResourceClass<
|
|
62
65
|
I extends State = State,
|
|
@@ -71,7 +74,6 @@ declare class Stack extends Group {
|
|
|
71
74
|
constructor(app: App, name: string);
|
|
72
75
|
dependsOn(...stacks: Stack[]);
|
|
73
76
|
}
|
|
74
|
-
type URN = `urn:${string}`;
|
|
75
77
|
type Tag = "resource" | "data";
|
|
76
78
|
type State = Record<string, unknown>;
|
|
77
79
|
type Config = {
|
|
@@ -232,9 +234,22 @@ type WorkSpaceOptions = {
|
|
|
232
234
|
declare class WorkSpace {
|
|
233
235
|
protected props: WorkSpaceOptions;
|
|
234
236
|
constructor(props: WorkSpaceOptions);
|
|
237
|
+
/**
|
|
238
|
+
* Deploy the entire app or use the filter option to deploy specific stacks inside your app.
|
|
239
|
+
*/
|
|
235
240
|
deploy(app: App, options?: ProcedureOptions);
|
|
241
|
+
/**
|
|
242
|
+
* Delete the entire app or use the filter option to delete specific stacks inside your app.
|
|
243
|
+
*/
|
|
236
244
|
delete(app: App, options?: ProcedureOptions);
|
|
245
|
+
/**
|
|
246
|
+
* Hydrate the outputs of the resources & data-sources inside your app.
|
|
247
|
+
*/
|
|
237
248
|
hydrate(app: App);
|
|
249
|
+
/**
|
|
250
|
+
* Refresh the state of the resources & data-sources inside your app.
|
|
251
|
+
*/
|
|
252
|
+
refresh(app: App);
|
|
238
253
|
protected destroyProviders();
|
|
239
254
|
}
|
|
240
255
|
type ResourceOperation = "create" | "update" | "delete" | "replace" | "import" | "resolve" | "get";
|
package/dist/index.js
CHANGED
|
@@ -382,7 +382,7 @@ var lockApp = async (lockBackend, app, fn) => {
|
|
|
382
382
|
|
|
383
383
|
// src/workspace/concurrency.ts
|
|
384
384
|
import promiseLimit from "p-limit";
|
|
385
|
-
var
|
|
385
|
+
var createConcurrencyQueue = (concurrency) => {
|
|
386
386
|
const queue = promiseLimit(concurrency);
|
|
387
387
|
return (cb) => {
|
|
388
388
|
return queue(cb);
|
|
@@ -631,7 +631,7 @@ var deleteApp = async (app, opt) => {
|
|
|
631
631
|
if (opt.filters && opt.filters.length > 0) {
|
|
632
632
|
stackStates = stackStates.filter((stackState) => opt.filters.includes(stackState.name));
|
|
633
633
|
}
|
|
634
|
-
const queue =
|
|
634
|
+
const queue = createConcurrencyQueue(opt.concurrency ?? 10);
|
|
635
635
|
const graph = new DependencyGraph;
|
|
636
636
|
const allNodes = {};
|
|
637
637
|
for (const stackState of Object.values(appState.stacks)) {
|
|
@@ -854,7 +854,7 @@ var deployApp = async (app, opt) => {
|
|
|
854
854
|
stacks = app.stacks.filter((stack) => opt.filters.includes(stack.name));
|
|
855
855
|
filteredOutStacks = app.stacks.filter((stack) => !opt.filters.includes(stack.name));
|
|
856
856
|
}
|
|
857
|
-
const queue =
|
|
857
|
+
const queue = createConcurrencyQueue(opt.concurrency ?? 10);
|
|
858
858
|
const graph = new DependencyGraph;
|
|
859
859
|
const allNodes = {};
|
|
860
860
|
for (const stackState of Object.values(appState.stacks)) {
|
|
@@ -1020,6 +1020,41 @@ var hydrate = async (app, opt) => {
|
|
|
1020
1020
|
}
|
|
1021
1021
|
};
|
|
1022
1022
|
|
|
1023
|
+
// src/workspace/procedure/refresh.ts
|
|
1024
|
+
var refresh = async (app, opt) => {
|
|
1025
|
+
const appState = await opt.backend.state.get(app.urn);
|
|
1026
|
+
const queue = createConcurrencyQueue(opt.concurrency ?? 10);
|
|
1027
|
+
if (appState) {
|
|
1028
|
+
await Promise.all(Object.values(appState.stacks).map((stackState) => {
|
|
1029
|
+
return Promise.all(Object.values(stackState.nodes).map((nodeState) => {
|
|
1030
|
+
return queue(async () => {
|
|
1031
|
+
const provider = findProvider(opt.providers, nodeState.provider);
|
|
1032
|
+
if (nodeState.tag === "data") {
|
|
1033
|
+
const result = await provider.getData?.({
|
|
1034
|
+
type: nodeState.type,
|
|
1035
|
+
state: nodeState.output
|
|
1036
|
+
});
|
|
1037
|
+
if (result && !compareState(result.state, nodeState.output)) {
|
|
1038
|
+
nodeState.output = result.state;
|
|
1039
|
+
nodeState.input = result.state;
|
|
1040
|
+
}
|
|
1041
|
+
} else if (nodeState.tag === "resource") {
|
|
1042
|
+
const result = await provider.getResource({
|
|
1043
|
+
type: nodeState.type,
|
|
1044
|
+
state: nodeState.output
|
|
1045
|
+
});
|
|
1046
|
+
if (result && !compareState(result.state, nodeState.output)) {
|
|
1047
|
+
nodeState.output = result.state;
|
|
1048
|
+
nodeState.input = result.state;
|
|
1049
|
+
}
|
|
1050
|
+
}
|
|
1051
|
+
});
|
|
1052
|
+
}));
|
|
1053
|
+
}));
|
|
1054
|
+
await opt.backend.state.update(app.urn, appState);
|
|
1055
|
+
}
|
|
1056
|
+
};
|
|
1057
|
+
|
|
1023
1058
|
// src/workspace/workspace.ts
|
|
1024
1059
|
class WorkSpace {
|
|
1025
1060
|
props;
|
|
@@ -1047,6 +1082,15 @@ class WorkSpace {
|
|
|
1047
1082
|
hydrate(app) {
|
|
1048
1083
|
return hydrate(app, this.props);
|
|
1049
1084
|
}
|
|
1085
|
+
refresh(app) {
|
|
1086
|
+
return lockApp(this.props.backend.lock, app, async () => {
|
|
1087
|
+
try {
|
|
1088
|
+
await refresh(app, this.props);
|
|
1089
|
+
} finally {
|
|
1090
|
+
await this.destroyProviders();
|
|
1091
|
+
}
|
|
1092
|
+
});
|
|
1093
|
+
}
|
|
1050
1094
|
async destroyProviders() {
|
|
1051
1095
|
await Promise.all(this.props.providers.map((p) => {
|
|
1052
1096
|
return p.destroy?.();
|
|
@@ -1306,6 +1350,9 @@ var createCustomResourceClass = (providerId, resourceType) => {
|
|
|
1306
1350
|
if (key === nodeMetaSymbol) {
|
|
1307
1351
|
return meta;
|
|
1308
1352
|
}
|
|
1353
|
+
if (key === "urn") {
|
|
1354
|
+
return meta.urn;
|
|
1355
|
+
}
|
|
1309
1356
|
if (typeof key === "symbol") {
|
|
1310
1357
|
return;
|
|
1311
1358
|
}
|