@terraforge/core 0.0.8 → 0.0.10

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 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, I extends State = State, O extends State = State, C extends Config = Config> = {
46
- readonly [nodeMetaSymbol]: Meta<T, I, O, C>;
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<I extends State = State, O extends State = State> = Meta<'resource', I, O, ResourceConfig>;
70
- type Resource<I extends State = State, O extends State = State> = O & {
71
- readonly [nodeMetaSymbol]: ResourceMeta<I, O>;
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<I, O>;
76
- get(parent: Group, id: string, physicalId: string): DataSource<I, O>;
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<any, any>[];
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, I extends State = State, O extends State = State, C extends Config = Config> = {
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: I;
101
+ readonly input: State;
102
102
  readonly config?: C;
103
103
  readonly dependencies: Set<URN>;
104
- readonly resolve: (data: O) => void;
105
- readonly output: <O>(cb: (data: State) => O) => Output<O>;
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, I extends State = State, O extends State = State, C extends Config = Config>(tag: T, provider: string, parent: Group, type: string, logicalId: string, input: I, config?: C) => Meta<T, I, O, C>;
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<I extends State = State, O extends State = State> = Meta<'data', I, O>;
110
- type DataSource<I extends State = State, O extends State = State> = {
111
- readonly [nodeMetaSymbol]: DataSourceMeta<I, O>;
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<I, O>;
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
  },
@@ -513,6 +479,89 @@ var dependentsOn = (resources, dependency) => {
513
479
  }
514
480
  return dependents;
515
481
  };
482
+ var findDependencyPaths = (value, dependencyUrn, path = []) => {
483
+ const paths = [];
484
+ const visit = (current, currentPath) => {
485
+ if (current instanceof Output) {
486
+ for (const dep of current.dependencies) {
487
+ if (dep.urn === dependencyUrn) {
488
+ paths.push(currentPath);
489
+ return;
490
+ }
491
+ }
492
+ return;
493
+ }
494
+ if (Array.isArray(current)) {
495
+ current.forEach((item, index) => {
496
+ visit(item, [...currentPath, index]);
497
+ });
498
+ return;
499
+ }
500
+ if (current && typeof current === "object") {
501
+ for (const [key, item] of Object.entries(current)) {
502
+ visit(item, [...currentPath, key]);
503
+ }
504
+ }
505
+ };
506
+ visit(value, path);
507
+ return paths;
508
+ };
509
+ var cloneState = (value) => JSON.parse(JSON.stringify(value));
510
+ var removeAtPath = (target, path) => {
511
+ if (path.length === 0) return;
512
+ let parent = target;
513
+ for (let i = 0; i < path.length - 1; i++) {
514
+ if (parent == null) return;
515
+ parent = parent[path[i]];
516
+ }
517
+ const last = path[path.length - 1];
518
+ if (Array.isArray(parent) && typeof last === "number") {
519
+ if (last >= 0 && last < parent.length) {
520
+ parent.splice(last, 1);
521
+ }
522
+ return;
523
+ }
524
+ if (parent && typeof parent === "object") {
525
+ delete parent[last];
526
+ }
527
+ };
528
+ var stripDependencyInputs = (input, metaInput, dependencyUrn) => {
529
+ const paths = findDependencyPaths(metaInput, dependencyUrn);
530
+ if (paths.length === 0) {
531
+ return input;
532
+ }
533
+ const detached = cloneState(input);
534
+ const sortedPaths = [...paths].sort((a, b) => {
535
+ if (a.length !== b.length) return b.length - a.length;
536
+ const aLast = a[a.length - 1];
537
+ const bLast = b[b.length - 1];
538
+ if (typeof aLast === "number" && typeof bLast === "number") {
539
+ return bLast - aLast;
540
+ }
541
+ return 0;
542
+ });
543
+ for (const path of sortedPaths) {
544
+ removeAtPath(detached, path);
545
+ }
546
+ return detached;
547
+ };
548
+ var allowsDependentReplace = (replaceOnChanges, dependencyPaths) => {
549
+ if (!replaceOnChanges || replaceOnChanges.length === 0) {
550
+ return false;
551
+ }
552
+ for (const path of dependencyPaths) {
553
+ const base = typeof path[0] === "string" ? path[0] : void 0;
554
+ if (!base) {
555
+ continue;
556
+ }
557
+ for (const replacePath of replaceOnChanges) {
558
+ if (replacePath === base || replacePath.startsWith(`${base}.`) || replacePath.startsWith(`${base}[`) || replacePath.startsWith(`${base}.*`)) {
559
+ return true;
560
+ }
561
+ }
562
+ }
563
+ return false;
564
+ };
516
565
 
517
566
  // src/workspace/error.ts
518
567
  var ResourceError = class _ResourceError extends Error {
@@ -946,89 +995,6 @@ var updateResource = async (resource, appToken, priorInputState, priorOutputStat
946
995
 
947
996
  // src/workspace/procedure/deploy-app.ts
948
997
  var debug7 = createDebugger("Deploy App");
949
- var findDependencyPaths = (value, dependencyUrn, path = []) => {
950
- const paths = [];
951
- const visit = (current, currentPath) => {
952
- if (current instanceof Output) {
953
- for (const dep of current.dependencies) {
954
- if (dep.urn === dependencyUrn) {
955
- paths.push(currentPath);
956
- return;
957
- }
958
- }
959
- return;
960
- }
961
- if (Array.isArray(current)) {
962
- current.forEach((item, index) => {
963
- visit(item, [...currentPath, index]);
964
- });
965
- return;
966
- }
967
- if (current && typeof current === "object") {
968
- for (const [key, item] of Object.entries(current)) {
969
- visit(item, [...currentPath, key]);
970
- }
971
- }
972
- };
973
- visit(value, path);
974
- return paths;
975
- };
976
- var cloneState = (value) => JSON.parse(JSON.stringify(value));
977
- var removeAtPath = (target, path) => {
978
- if (path.length === 0) return;
979
- let parent = target;
980
- for (let i = 0; i < path.length - 1; i++) {
981
- if (parent == null) return;
982
- parent = parent[path[i]];
983
- }
984
- const last = path[path.length - 1];
985
- if (Array.isArray(parent) && typeof last === "number") {
986
- if (last >= 0 && last < parent.length) {
987
- parent.splice(last, 1);
988
- }
989
- return;
990
- }
991
- if (parent && typeof parent === "object") {
992
- delete parent[last];
993
- }
994
- };
995
- var stripDependencyInputs = (input, metaInput, dependencyUrn) => {
996
- const paths = findDependencyPaths(metaInput, dependencyUrn);
997
- if (paths.length === 0) {
998
- return input;
999
- }
1000
- const detached = cloneState(input);
1001
- const sortedPaths = [...paths].sort((a, b) => {
1002
- if (a.length !== b.length) return b.length - a.length;
1003
- const aLast = a[a.length - 1];
1004
- const bLast = b[b.length - 1];
1005
- if (typeof aLast === "number" && typeof bLast === "number") {
1006
- return bLast - aLast;
1007
- }
1008
- return 0;
1009
- });
1010
- for (const path of sortedPaths) {
1011
- removeAtPath(detached, path);
1012
- }
1013
- return detached;
1014
- };
1015
- var allowsDependentReplace = (replaceOnChanges, dependencyPaths) => {
1016
- if (!replaceOnChanges || replaceOnChanges.length === 0) {
1017
- return false;
1018
- }
1019
- for (const path of dependencyPaths) {
1020
- const base = typeof path[0] === "string" ? path[0] : void 0;
1021
- if (!base) {
1022
- continue;
1023
- }
1024
- for (const replacePath of replaceOnChanges) {
1025
- if (replacePath === base || replacePath.startsWith(`${base}.`) || replacePath.startsWith(`${base}[`) || replacePath.startsWith(`${base}.*`)) {
1026
- return true;
1027
- }
1028
- }
1029
- }
1030
- return false;
1031
- };
1032
998
  var deployApp = async (app, opt) => {
1033
999
  debug7(app.name, "start");
1034
1000
  const latestState = await opt.backend.state.get(app.urn);
@@ -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) ? {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@terraforge/core",
3
- "version": "0.0.8",
3
+ "version": "0.0.10",
4
4
  "type": "module",
5
5
  "repository": {
6
6
  "type": "git",