@catladder/pipeline 1.170.0 → 2.0.0

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.
Files changed (194) hide show
  1. package/dist/bash/BashExpression.d.ts +2 -6
  2. package/dist/bash/BashExpression.js +5 -15
  3. package/dist/bash/bashEscape.d.ts +34 -0
  4. package/dist/bash/bashEscape.js +114 -0
  5. package/dist/bash/bashYaml.js +25 -2
  6. package/dist/bash/getInjectVarsScript.js +4 -2
  7. package/dist/bash/index.d.ts +2 -0
  8. package/dist/bash/index.js +26 -0
  9. package/dist/build/base/createAppBuildJob.js +3 -3
  10. package/dist/build/base/writeDotEnv.js +6 -4
  11. package/dist/build/custom/testJob.js +12 -12
  12. package/dist/build/docker.d.ts +3 -3
  13. package/dist/build/node/buildJob.js +1 -1
  14. package/dist/build/node/cache.d.ts +2 -4
  15. package/dist/build/node/cache.js +3 -24
  16. package/dist/build/node/testJob.js +11 -11
  17. package/dist/build/rails/build.js +1 -1
  18. package/dist/build/rails/test.js +8 -8
  19. package/dist/build/types.d.ts +0 -10
  20. package/dist/constants.js +1 -1
  21. package/dist/context/createComponentContext.js +0 -1
  22. package/dist/context/getEnvConfig.js +2 -1
  23. package/dist/context/getEnvironment.js +1 -2
  24. package/dist/context/getEnvironmentVariables.d.ts +5 -6
  25. package/dist/context/getEnvironmentVariables.js +50 -38
  26. package/dist/deploy/base/deploy.js +3 -3
  27. package/dist/deploy/cloudRun/createJobs/getCloudRunDeployScripts.js +2 -2
  28. package/dist/deploy/cloudRun/index.js +2 -2
  29. package/dist/deploy/cloudRun/utils/getServiceName.d.ts +1 -1
  30. package/dist/deploy/kubernetes/cloudSql/index.d.ts +2 -2
  31. package/dist/deploy/kubernetes/cloudSql/index.js +3 -14
  32. package/dist/deploy/kubernetes/deployJob.js +1 -3
  33. package/dist/deploy/kubernetes/index.js +2 -2
  34. package/dist/deploy/kubernetes/kubeEnv.d.ts +3 -3
  35. package/dist/deploy/kubernetes/kubeValues.d.ts +3 -4
  36. package/dist/deploy/kubernetes/kubeValues.js +2 -3
  37. package/dist/deploy/types/base.d.ts +0 -6
  38. package/dist/deploy/types/kubernetes.d.ts +1 -34
  39. package/dist/globalScriptFunctions/index.d.ts +14 -0
  40. package/dist/globalScriptFunctions/index.js +37 -0
  41. package/dist/index.d.ts +3 -1
  42. package/dist/index.js +3 -1
  43. package/dist/pipeline/gitlab/createGitlabJobs.js +3 -5
  44. package/dist/pipeline/gitlab/createGitlabPipeline.d.ts +1 -0
  45. package/dist/pipeline/gitlab/createGitlabPipeline.js +38 -2
  46. package/dist/pipeline/packageManager.js +1 -1
  47. package/dist/runner/index.d.ts +1 -1
  48. package/dist/tsconfig.tsbuildinfo +1 -1
  49. package/dist/types/config.d.ts +6 -9
  50. package/dist/types/context.d.ts +2 -9
  51. package/dist/types/gitlab-types.d.ts +1 -0
  52. package/dist/types/jobs.d.ts +0 -8
  53. package/dist/utils/gitlab.js +4 -1
  54. package/dist/utils/writeFiles.js +1 -7
  55. package/dist/variables/VariableValue.d.ts +3 -0
  56. package/dist/variables/VariableValue.js +5 -0
  57. package/dist/variables/VariableValueContainingReferences.d.ts +24 -0
  58. package/dist/variables/VariableValueContainingReferences.js +97 -0
  59. package/dist/variables/__tests__/resolveAllReferences.test.js +219 -0
  60. package/dist/variables/__tests__/resolveAllReferencesOnce.test.d.ts +1 -0
  61. package/dist/variables/__tests__/resolveAllReferencesOnce.test.js +171 -0
  62. package/dist/variables/__tests__/resolveReferencesOnce.test.d.ts +1 -0
  63. package/dist/variables/__tests__/resolveReferencesOnce.test.js +202 -0
  64. package/dist/variables/__tests__/variableValue.test.d.ts +1 -0
  65. package/dist/variables/__tests__/variableValue.test.js +36 -0
  66. package/dist/variables/resolveAllReferences.d.ts +3 -0
  67. package/dist/{bash/replaceAsync.js → variables/resolveAllReferences.js} +60 -41
  68. package/dist/variables/resolveAllReferencesOnce.d.ts +5 -0
  69. package/dist/variables/resolveAllReferencesOnce.js +191 -0
  70. package/dist/variables/resolveReferencesOnce.d.ts +8 -0
  71. package/dist/variables/resolveReferencesOnce.js +22 -0
  72. package/examples/__snapshots__/cloud-run-http2.test.ts.snap +312 -238
  73. package/examples/__snapshots__/cloud-run-memory-limit.test.ts.snap +312 -238
  74. package/examples/__snapshots__/cloud-run-meteor-with-worker.test.ts.snap +312 -222
  75. package/examples/__snapshots__/cloud-run-nextjs.test.ts.snap +1436 -0
  76. package/examples/__snapshots__/cloud-run-no-cpu-throttling.test.ts.snap +312 -238
  77. package/examples/__snapshots__/cloud-run-no-service.test.ts.snap +316 -238
  78. package/examples/__snapshots__/cloud-run-non-public.test.ts.snap +312 -238
  79. package/examples/__snapshots__/cloud-run-post-stop-job.test.ts.snap +313 -238
  80. package/examples/__snapshots__/cloud-run-service-custom-vpc-connector.test.ts.snap +312 -238
  81. package/examples/__snapshots__/cloud-run-service-custom-vpc.test.ts.snap +312 -238
  82. package/examples/__snapshots__/cloud-run-service-gen2.test.ts.snap +312 -238
  83. package/examples/__snapshots__/cloud-run-service-increase-timout.test.ts.snap +312 -238
  84. package/examples/__snapshots__/cloud-run-service-with-volumes.test.ts.snap +316 -238
  85. package/examples/__snapshots__/cloud-run-storybook.test.ts.snap +294 -220
  86. package/examples/__snapshots__/cloud-run-with-ngnix.test.ts.snap +312 -238
  87. package/examples/__snapshots__/cloud-run-with-sql-reuse-db.test.ts.snap +652 -486
  88. package/examples/__snapshots__/cloud-run-with-sql.test.ts.snap +282 -288
  89. package/examples/__snapshots__/cloud-run-with-worker.test.ts.snap +312 -238
  90. package/examples/__snapshots__/custom-build-job-with-tests.test.ts.snap +284 -194
  91. package/examples/__snapshots__/custom-build-job.test.ts.snap +278 -188
  92. package/examples/__snapshots__/custom-deploy.test.ts.snap +220 -154
  93. package/examples/__snapshots__/custom-envs.test.ts.snap +216 -126
  94. package/examples/__snapshots__/custom-sbom-java.test.ts.snap +278 -188
  95. package/examples/__snapshots__/git-submodule.test.ts.snap +312 -238
  96. package/examples/__snapshots__/kubernetes-application-customization.test.ts.snap +231 -253
  97. package/examples/__snapshots__/kubernetes-with-cloud-sql.test.ts.snap +240 -262
  98. package/examples/__snapshots__/kubernetes-with-jobs.test.ts.snap +504 -506
  99. package/examples/__snapshots__/kubernetes-with-mongodb.test.ts.snap +239 -261
  100. package/examples/__snapshots__/local-dot-env.test.ts.snap +236 -238
  101. package/examples/__snapshots__/meteor-kubernetes.test.ts.snap +236 -242
  102. package/examples/__snapshots__/multiline-var.test.ts.snap +1355 -973
  103. package/examples/__snapshots__/native-app.test.ts.snap +438 -392
  104. package/examples/__snapshots__/node-build-with-custom-image.test.ts.snap +312 -238
  105. package/examples/__snapshots__/node-build-with-docker-additions.test.ts.snap +312 -238
  106. package/examples/__snapshots__/rails-k8s-with-worker-dockerfile.test.ts.snap +186 -188
  107. package/examples/__snapshots__/rails-k8s-with-worker.test.ts.snap +162 -164
  108. package/examples/__snapshots__/referencing-other-vars.test.ts.snap +4741 -0
  109. package/examples/__snapshots__/wait-for-other-deploy.test.ts.snap +330 -228
  110. package/examples/__snapshots__/{workspace-api-www-custom-cache.test.ts.snap → workspace-api-www-turbo-cache.test.ts.snap} +457 -499
  111. package/examples/__snapshots__/workspace-api-www.test.ts.snap +452 -482
  112. package/examples/{workspace-api-www-custom-cache.test.ts → cloud-run-nextjs.test.ts} +2 -2
  113. package/examples/cloud-run-nextjs.ts +28 -0
  114. package/examples/cloud-run-with-sql.ts +0 -1
  115. package/examples/kubernetes-application-customization.ts +1 -0
  116. package/examples/kubernetes-with-cloud-sql.ts +1 -0
  117. package/examples/kubernetes-with-jobs.ts +1 -0
  118. package/examples/kubernetes-with-mongodb.ts +1 -0
  119. package/examples/meteor-kubernetes.ts +1 -1
  120. package/examples/native-app.ts +10 -7
  121. package/examples/rails-k8s-with-worker.ts +7 -1
  122. package/examples/{kubernetes-with-cloud-sql-legacy.test.ts → referencing-other-vars.test.ts} +2 -2
  123. package/examples/referencing-other-vars.ts +83 -0
  124. package/examples/workspace-api-www-turbo-cache.test.ts +11 -0
  125. package/examples/{workspace-api-www-custom-cache.ts → workspace-api-www-turbo-cache.ts} +4 -3
  126. package/examples/workspace-api-www.ts +3 -2
  127. package/package.json +2 -6
  128. package/src/bash/BashExpression.ts +10 -13
  129. package/src/bash/bashEscape.ts +158 -0
  130. package/src/bash/bashYaml.ts +36 -2
  131. package/src/bash/getInjectVarsScript.ts +11 -2
  132. package/src/bash/index.ts +2 -0
  133. package/src/build/base/createAppBuildJob.ts +0 -1
  134. package/src/build/base/writeDotEnv.ts +6 -6
  135. package/src/build/custom/testJob.ts +0 -1
  136. package/src/build/node/buildJob.ts +2 -2
  137. package/src/build/node/cache.ts +0 -29
  138. package/src/build/node/testJob.ts +0 -1
  139. package/src/build/rails/build.ts +0 -1
  140. package/src/build/rails/test.ts +0 -1
  141. package/src/build/types.ts +0 -13
  142. package/src/context/createComponentContext.ts +0 -1
  143. package/src/context/getEnvConfig.ts +2 -2
  144. package/src/context/getEnvironment.ts +1 -1
  145. package/src/context/getEnvironmentContext.ts +1 -1
  146. package/src/context/getEnvironmentVariables.ts +44 -51
  147. package/src/deploy/base/deploy.ts +1 -1
  148. package/src/deploy/cloudRun/createJobs/getCloudRunDeployScripts.ts +4 -12
  149. package/src/deploy/cloudRun/index.ts +2 -2
  150. package/src/deploy/kubernetes/cloudSql/index.ts +3 -16
  151. package/src/deploy/kubernetes/deployJob.ts +0 -2
  152. package/src/deploy/kubernetes/index.ts +2 -2
  153. package/src/deploy/kubernetes/kubeEnv.ts +3 -3
  154. package/src/deploy/kubernetes/kubeValues.ts +5 -8
  155. package/src/deploy/types/base.ts +0 -6
  156. package/src/deploy/types/kubernetes.ts +1 -36
  157. package/src/globalScriptFunctions/index.ts +30 -0
  158. package/src/index.ts +2 -0
  159. package/src/pipeline/gitlab/createGitlabJobs.ts +1 -4
  160. package/src/pipeline/gitlab/createGitlabPipeline.ts +8 -1
  161. package/src/pipeline/packageManager.ts +7 -5
  162. package/src/runner/index.ts +0 -1
  163. package/src/types/config.ts +6 -9
  164. package/src/types/context.ts +3 -9
  165. package/src/types/gitlab-types.ts +1 -0
  166. package/src/types/jobs.ts +0 -8
  167. package/src/utils/gitlab.ts +19 -2
  168. package/src/utils/writeFiles.ts +1 -2
  169. package/src/variables/VariableValue.ts +6 -0
  170. package/src/variables/VariableValueContainingReferences.ts +89 -0
  171. package/src/variables/__tests__/resolveAllReferences.test.ts +110 -0
  172. package/src/variables/__tests__/resolveAllReferencesOnce.test.ts +64 -0
  173. package/src/variables/__tests__/resolveReferencesOnce.test.ts +117 -0
  174. package/src/variables/__tests__/variableValue.test.ts +73 -0
  175. package/src/variables/resolveAllReferences.ts +46 -0
  176. package/src/variables/resolveAllReferencesOnce.ts +44 -0
  177. package/src/variables/resolveReferencesOnce.ts +29 -0
  178. package/bin/catladder-gitlab-dev.js +0 -3
  179. package/bin/catladder-gitlab.js +0 -3
  180. package/dist/bash/replaceAsync.d.ts +0 -2
  181. package/dist/bundles/catladder-gitlab/index.js +0 -15
  182. package/dist/context/__tests__/resolveReferences.test.js +0 -368
  183. package/dist/context/resolveReferences.d.ts +0 -6
  184. package/dist/context/resolveReferences.js +0 -286
  185. package/dist/deploy/kubernetes/processSecretsAsFiles.d.ts +0 -85
  186. package/dist/deploy/kubernetes/processSecretsAsFiles.js +0 -33
  187. package/examples/__snapshots__/kubernetes-with-cloud-sql-legacy.test.ts.snap +0 -1795
  188. package/examples/kubernetes-with-cloud-sql-legacy.ts +0 -35
  189. package/scripts/bundle +0 -2
  190. package/src/bash/replaceAsync.ts +0 -54
  191. package/src/context/__tests__/resolveReferences.test.ts +0 -148
  192. package/src/context/resolveReferences.ts +0 -93
  193. package/src/deploy/kubernetes/processSecretsAsFiles.ts +0 -35
  194. /package/dist/{context/__tests__/resolveReferences.test.d.ts → variables/__tests__/resolveAllReferences.test.d.ts} +0 -0
@@ -0,0 +1,202 @@
1
+ "use strict";
2
+
3
+ var __awaiter = this && this.__awaiter || function (thisArg, _arguments, P, generator) {
4
+ function adopt(value) {
5
+ return value instanceof P ? value : new P(function (resolve) {
6
+ resolve(value);
7
+ });
8
+ }
9
+ return new (P || (P = Promise))(function (resolve, reject) {
10
+ function fulfilled(value) {
11
+ try {
12
+ step(generator.next(value));
13
+ } catch (e) {
14
+ reject(e);
15
+ }
16
+ }
17
+ function rejected(value) {
18
+ try {
19
+ step(generator["throw"](value));
20
+ } catch (e) {
21
+ reject(e);
22
+ }
23
+ }
24
+ function step(result) {
25
+ result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected);
26
+ }
27
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
28
+ });
29
+ };
30
+ var __generator = this && this.__generator || function (thisArg, body) {
31
+ var _ = {
32
+ label: 0,
33
+ sent: function () {
34
+ if (t[0] & 1) throw t[1];
35
+ return t[1];
36
+ },
37
+ trys: [],
38
+ ops: []
39
+ },
40
+ f,
41
+ y,
42
+ t,
43
+ g;
44
+ return g = {
45
+ next: verb(0),
46
+ "throw": verb(1),
47
+ "return": verb(2)
48
+ }, typeof Symbol === "function" && (g[Symbol.iterator] = function () {
49
+ return this;
50
+ }), g;
51
+ function verb(n) {
52
+ return function (v) {
53
+ return step([n, v]);
54
+ };
55
+ }
56
+ function step(op) {
57
+ if (f) throw new TypeError("Generator is already executing.");
58
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
59
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
60
+ if (y = 0, t) op = [op[0] & 2, t.value];
61
+ switch (op[0]) {
62
+ case 0:
63
+ case 1:
64
+ t = op;
65
+ break;
66
+ case 4:
67
+ _.label++;
68
+ return {
69
+ value: op[1],
70
+ done: false
71
+ };
72
+ case 5:
73
+ _.label++;
74
+ y = op[1];
75
+ op = [0];
76
+ continue;
77
+ case 7:
78
+ op = _.ops.pop();
79
+ _.trys.pop();
80
+ continue;
81
+ default:
82
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
83
+ _ = 0;
84
+ continue;
85
+ }
86
+ if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
87
+ _.label = op[1];
88
+ break;
89
+ }
90
+ if (op[0] === 6 && _.label < t[1]) {
91
+ _.label = t[1];
92
+ t = op;
93
+ break;
94
+ }
95
+ if (t && _.label < t[2]) {
96
+ _.label = t[2];
97
+ _.ops.push(op);
98
+ break;
99
+ }
100
+ if (t[2]) _.ops.pop();
101
+ _.trys.pop();
102
+ continue;
103
+ }
104
+ op = body.call(thisArg, _);
105
+ } catch (e) {
106
+ op = [6, e];
107
+ y = 0;
108
+ } finally {
109
+ f = t = 0;
110
+ }
111
+ if (op[0] & 5) throw op[1];
112
+ return {
113
+ value: op[0] ? op[1] : void 0,
114
+ done: true
115
+ };
116
+ }
117
+ };
118
+ Object.defineProperty(exports, "__esModule", {
119
+ value: true
120
+ });
121
+ var VariableValueContainingReferences_1 = require("../VariableValueContainingReferences");
122
+ var resolveReferencesOnce_1 = require("../resolveReferencesOnce");
123
+ describe("resolveReferencesOnce", function () {
124
+ it("should replace a reference to another component", function () {
125
+ return __awaiter(void 0, void 0, void 0, function () {
126
+ var value, result;
127
+ return __generator(this, function (_a) {
128
+ value = (0, VariableValueContainingReferences_1.createVariableValueContainingReferencesFromString)("the other component has ${otherComponent:variableName}, isn't that cool?", {
129
+ componentName: "myComponent"
130
+ });
131
+ result = (0, resolveReferencesOnce_1.resolveReferencesOnce)(value, function (_a) {
132
+ var componentName = _a.componentName,
133
+ variableName = _a.variableName;
134
+ return (0, VariableValueContainingReferences_1.createVariableValueContainingReferencesFromString)("replaced ".concat(componentName, ":").concat(variableName), {
135
+ componentName: componentName
136
+ });
137
+ });
138
+ expect(result.parts).toEqual(["the other component has ", "replaced otherComponent:variableName", ", isn't that cool?"]);
139
+ return [2 /*return*/];
140
+ });
141
+ });
142
+ });
143
+
144
+ it("should keep references in replacement", function () {
145
+ return __awaiter(void 0, void 0, void 0, function () {
146
+ var value, result;
147
+ return __generator(this, function (_a) {
148
+ value = (0, VariableValueContainingReferences_1.createVariableValueContainingReferencesFromString)("the other component has ${otherComponent:variableName}, isn't that cool?", {
149
+ componentName: "myComponent"
150
+ });
151
+ result = (0, resolveReferencesOnce_1.resolveReferencesOnce)(value, function (_a) {
152
+ var componentName = _a.componentName,
153
+ variableName = _a.variableName;
154
+ return (0, VariableValueContainingReferences_1.createVariableValueContainingReferencesFromString)("replaced ".concat(componentName, ":").concat(variableName, ", contains reference to ${thirdComponent:x}"), {
155
+ componentName: componentName
156
+ });
157
+ });
158
+ expect(result.parts).toEqual(["the other component has ", "replaced otherComponent:variableName, contains reference to ", new VariableValueContainingReferences_1.VariableReference("thirdComponent", "x"), ", isn't that cool?"]);
159
+ return [2 /*return*/];
160
+ });
161
+ });
162
+ });
163
+
164
+ it("can be run multiple times", function () {
165
+ return __awaiter(void 0, void 0, void 0, function () {
166
+ var value, replacer, result;
167
+ return __generator(this, function (_a) {
168
+ value = (0, VariableValueContainingReferences_1.createVariableValueContainingReferencesFromString)("the other component has ${otherComponent:variableName}, isn't that cool?", {
169
+ componentName: "myComponent"
170
+ });
171
+ replacer = function (_a) {
172
+ var componentName = _a.componentName,
173
+ variableName = _a.variableName;
174
+ return (0, VariableValueContainingReferences_1.createVariableValueContainingReferencesFromString)(componentName === "thirdComponent" ? "value from third component" : "replaced ".concat(componentName, ":").concat(variableName, ", contains reference to ${thirdComponent:x}"), {
175
+ componentName: componentName
176
+ });
177
+ };
178
+ result = (0, resolveReferencesOnce_1.resolveReferencesOnce)((0, resolveReferencesOnce_1.resolveReferencesOnce)(value, replacer), replacer);
179
+ expect(result.parts).toEqual(["the other component has ", "replaced otherComponent:variableName, contains reference to ", "value from third component", ", isn't that cool?"]);
180
+ return [2 /*return*/];
181
+ });
182
+ });
183
+ });
184
+
185
+ it("flags unresolveable", function () {
186
+ return __awaiter(void 0, void 0, void 0, function () {
187
+ var value, result;
188
+ return __generator(this, function (_a) {
189
+ value = (0, VariableValueContainingReferences_1.createVariableValueContainingReferencesFromString)("the other component has ${otherComponent:variableName}, isn't that cool?", {
190
+ componentName: "myComponent"
191
+ });
192
+ result = (0, resolveReferencesOnce_1.resolveReferencesOnce)(value, function (_a) {
193
+ var componentName = _a.componentName,
194
+ variableName = _a.variableName;
195
+ return null;
196
+ });
197
+ expect(result.parts).toEqual(["the other component has ", new VariableValueContainingReferences_1.UnresolvableReference(new VariableValueContainingReferences_1.VariableReference("otherComponent", "variableName")), ", isn't that cool?"]);
198
+ return [2 /*return*/];
199
+ });
200
+ });
201
+ });
202
+ });
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,36 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ var VariableValueContainingReferences_1 = require("../VariableValueContainingReferences");
7
+ describe("createVarialeValueFromString", function () {
8
+ it("should create a VariableValue from a simple string", function () {
9
+ var stringValue = "hello world";
10
+ var result = (0, VariableValueContainingReferences_1.createVariableValueContainingReferencesFromString)(stringValue, {
11
+ componentName: "myComponent"
12
+ });
13
+ expect(result.parts).toEqual([stringValue]);
14
+ });
15
+ it("extracts references to other components", function () {
16
+ var stringValue = "the other component has ${otherComponent:variableName}, isn't that cool?";
17
+ var result = (0, VariableValueContainingReferences_1.createVariableValueContainingReferencesFromString)(stringValue, {
18
+ componentName: "myComponent"
19
+ });
20
+ expect(result.parts).toEqual(["the other component has ", new VariableValueContainingReferences_1.VariableReference("otherComponent", "variableName"), ", isn't that cool?"]);
21
+ });
22
+ it("extracts self references", function () {
23
+ var stringValue = "my component has ${variableName}!";
24
+ var result = (0, VariableValueContainingReferences_1.createVariableValueContainingReferencesFromString)(stringValue, {
25
+ componentName: "myComponent"
26
+ });
27
+ expect(result.parts).toEqual(["my component has ", new VariableValueContainingReferences_1.VariableReference("myComponent", "variableName"), "!"]);
28
+ });
29
+ it("extracts multiple references", function () {
30
+ var stringValue = "my component has ${variableName} and the other component has ${otherComponent:variableName}!";
31
+ var result = (0, VariableValueContainingReferences_1.createVariableValueContainingReferencesFromString)(stringValue, {
32
+ componentName: "myComponent"
33
+ });
34
+ expect(result.parts).toEqual(["my component has ", new VariableValueContainingReferences_1.VariableReference("myComponent", "variableName"), " and the other component has ", new VariableValueContainingReferences_1.VariableReference("otherComponent", "variableName"), "!"]);
35
+ });
36
+ });
@@ -0,0 +1,3 @@
1
+ import type { VariableValue } from "./VariableValue";
2
+ import type { VariableValueContainingReferences } from "./VariableValueContainingReferences";
3
+ export declare const resolveAllReferences: (values: Record<string, VariableValueContainingReferences>, getEnvVars: (componentName: string) => Promise<Record<string, VariableValue | null | undefined>>) => Promise<Record<string, VariableValueContainingReferences>>;
@@ -115,58 +115,77 @@ var __generator = this && this.__generator || function (thisArg, body) {
115
115
  };
116
116
  }
117
117
  };
118
+ var __read = this && this.__read || function (o, n) {
119
+ var m = typeof Symbol === "function" && o[Symbol.iterator];
120
+ if (!m) return o;
121
+ var i = m.call(o),
122
+ r,
123
+ ar = [],
124
+ e;
125
+ try {
126
+ while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
127
+ } catch (error) {
128
+ e = {
129
+ error: error
130
+ };
131
+ } finally {
132
+ try {
133
+ if (r && !r.done && (m = i["return"])) m.call(i);
134
+ } finally {
135
+ if (e) throw e.error;
136
+ }
137
+ }
138
+ return ar;
139
+ };
118
140
  Object.defineProperty(exports, "__esModule", {
119
141
  value: true
120
142
  });
121
- var BashExpression_1 = require("./BashExpression");
122
- // from https://github.com/dsblv/string-replace-async/blob/main/index.js
123
- // and adjusted a bit
124
- function replaceAsync(string, searchValue, replacer) {
125
- return __awaiter(this, void 0, void 0, function () {
126
- var wasBashExpression, stringRepresentation, values_1, resolvedValues_1, containsBashExpression, result, error_1;
143
+ exports.resolveAllReferences = void 0;
144
+ var VariableValueContainingReferences_1 = require("./VariableValueContainingReferences");
145
+ var resolveAllReferencesOnce_1 = require("./resolveAllReferencesOnce");
146
+ var resolveAllReferences = function (values, getEnvVars) {
147
+ return __awaiter(void 0, void 0, void 0, function () {
148
+ var result, i, replaced, unresolved;
127
149
  return __generator(this, function (_a) {
128
150
  switch (_a.label) {
129
151
  case 0:
130
- wasBashExpression = string instanceof BashExpression_1.BashExpression;
131
- stringRepresentation = wasBashExpression ? string.toString() : (0, BashExpression_1.bashEscape)(string);
152
+ result = values;
153
+ i = 0;
132
154
  _a.label = 1;
133
155
  case 1:
134
- _a.trys.push([1, 3,, 4]);
135
- values_1 = [];
136
- String.prototype.replace.call(stringRepresentation, searchValue, function () {
137
- var args = [];
138
- for (var _i = 0; _i < arguments.length; _i++) {
139
- args[_i] = arguments[_i];
140
- }
141
- // eslint-disable-next-line prefer-spread
142
- var result = replacer.apply(undefined, args);
143
- values_1.push(result);
144
- return "";
145
- });
146
- return [4 /*yield*/, Promise.all(values_1)];
156
+ if (!Object.values(result).some(function (value) {
157
+ return value.parts.some(function (part) {
158
+ return part instanceof VariableValueContainingReferences_1.VariableReference;
159
+ });
160
+ })) return [3 /*break*/, 3];
161
+ return [4 /*yield*/, (0, resolveAllReferencesOnce_1.resolveAllReferencesOnce)(result, getEnvVars)];
147
162
  case 2:
148
- resolvedValues_1 = _a.sent();
149
- containsBashExpression = resolvedValues_1.some(function (value) {
150
- return value instanceof BashExpression_1.BashExpression;
151
- });
152
- result = String.prototype.replace.call(stringRepresentation, searchValue, function () {
153
- var _a, _b;
154
- return (_b = (_a = resolvedValues_1.shift()) === null || _a === void 0 ? void 0 : _a.toString()) !== null && _b !== void 0 ? _b : "";
155
- });
156
- if (wasBashExpression || containsBashExpression) {
157
- return [2 /*return*/, new BashExpression_1.BashExpression(result)];
158
- } else {
159
- return [2 /*return*/, result];
163
+ replaced = _a.sent();
164
+ result = replaced;
165
+ i++;
166
+ if (i > 1000) {
167
+ unresolved = Object.entries(result).filter(function (_a) {
168
+ var _b = __read(_a, 2),
169
+ key = _b[0],
170
+ value = _b[1];
171
+ return value.parts.some(function (part) {
172
+ return part instanceof VariableValueContainingReferences_1.VariableReference;
173
+ });
174
+ });
175
+ throw new Error("Infinite loop detected in these variables: " + unresolved.map(function (_a) {
176
+ var _b = __read(_a, 2),
177
+ key = _b[0],
178
+ value = _b[1];
179
+ return "".concat(key, " (last reference: ").concat(value.parts.find(function (part) {
180
+ return part instanceof VariableValueContainingReferences_1.VariableReference;
181
+ }), ")");
182
+ }).join(", "));
160
183
  }
161
- return [3 /*break*/, 4];
184
+ return [3 /*break*/, 1];
162
185
  case 3:
163
- error_1 = _a.sent();
164
- return [2 /*return*/, Promise.reject(error_1)];
165
- case 4:
166
- return [2 /*return*/];
186
+ return [2 /*return*/, result];
167
187
  }
168
188
  });
169
189
  });
170
- }
171
-
172
- exports.default = replaceAsync;
190
+ };
191
+ exports.resolveAllReferences = resolveAllReferences;
@@ -0,0 +1,5 @@
1
+ import type { VariableValue } from "./VariableValue";
2
+ import type { VariableValueContainingReferences } from "./VariableValueContainingReferences";
3
+ export declare const resolveAllReferencesOnce: (values: Record<string, VariableValueContainingReferences>, getEnvVars: (componentName: string) => Promise<Record<string, VariableValue | undefined | null>>) => Promise<{
4
+ [k: string]: VariableValueContainingReferences;
5
+ }>;
@@ -0,0 +1,191 @@
1
+ "use strict";
2
+
3
+ var __awaiter = this && this.__awaiter || function (thisArg, _arguments, P, generator) {
4
+ function adopt(value) {
5
+ return value instanceof P ? value : new P(function (resolve) {
6
+ resolve(value);
7
+ });
8
+ }
9
+ return new (P || (P = Promise))(function (resolve, reject) {
10
+ function fulfilled(value) {
11
+ try {
12
+ step(generator.next(value));
13
+ } catch (e) {
14
+ reject(e);
15
+ }
16
+ }
17
+ function rejected(value) {
18
+ try {
19
+ step(generator["throw"](value));
20
+ } catch (e) {
21
+ reject(e);
22
+ }
23
+ }
24
+ function step(result) {
25
+ result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected);
26
+ }
27
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
28
+ });
29
+ };
30
+ var __generator = this && this.__generator || function (thisArg, body) {
31
+ var _ = {
32
+ label: 0,
33
+ sent: function () {
34
+ if (t[0] & 1) throw t[1];
35
+ return t[1];
36
+ },
37
+ trys: [],
38
+ ops: []
39
+ },
40
+ f,
41
+ y,
42
+ t,
43
+ g;
44
+ return g = {
45
+ next: verb(0),
46
+ "throw": verb(1),
47
+ "return": verb(2)
48
+ }, typeof Symbol === "function" && (g[Symbol.iterator] = function () {
49
+ return this;
50
+ }), g;
51
+ function verb(n) {
52
+ return function (v) {
53
+ return step([n, v]);
54
+ };
55
+ }
56
+ function step(op) {
57
+ if (f) throw new TypeError("Generator is already executing.");
58
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
59
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
60
+ if (y = 0, t) op = [op[0] & 2, t.value];
61
+ switch (op[0]) {
62
+ case 0:
63
+ case 1:
64
+ t = op;
65
+ break;
66
+ case 4:
67
+ _.label++;
68
+ return {
69
+ value: op[1],
70
+ done: false
71
+ };
72
+ case 5:
73
+ _.label++;
74
+ y = op[1];
75
+ op = [0];
76
+ continue;
77
+ case 7:
78
+ op = _.ops.pop();
79
+ _.trys.pop();
80
+ continue;
81
+ default:
82
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
83
+ _ = 0;
84
+ continue;
85
+ }
86
+ if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
87
+ _.label = op[1];
88
+ break;
89
+ }
90
+ if (op[0] === 6 && _.label < t[1]) {
91
+ _.label = t[1];
92
+ t = op;
93
+ break;
94
+ }
95
+ if (t && _.label < t[2]) {
96
+ _.label = t[2];
97
+ _.ops.push(op);
98
+ break;
99
+ }
100
+ if (t[2]) _.ops.pop();
101
+ _.trys.pop();
102
+ continue;
103
+ }
104
+ op = body.call(thisArg, _);
105
+ } catch (e) {
106
+ op = [6, e];
107
+ y = 0;
108
+ } finally {
109
+ f = t = 0;
110
+ }
111
+ if (op[0] & 5) throw op[1];
112
+ return {
113
+ value: op[0] ? op[1] : void 0,
114
+ done: true
115
+ };
116
+ }
117
+ };
118
+ var __read = this && this.__read || function (o, n) {
119
+ var m = typeof Symbol === "function" && o[Symbol.iterator];
120
+ if (!m) return o;
121
+ var i = m.call(o),
122
+ r,
123
+ ar = [],
124
+ e;
125
+ try {
126
+ while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
127
+ } catch (error) {
128
+ e = {
129
+ error: error
130
+ };
131
+ } finally {
132
+ try {
133
+ if (r && !r.done && (m = i["return"])) m.call(i);
134
+ } finally {
135
+ if (e) throw e.error;
136
+ }
137
+ }
138
+ return ar;
139
+ };
140
+ Object.defineProperty(exports, "__esModule", {
141
+ value: true
142
+ });
143
+ exports.resolveAllReferencesOnce = void 0;
144
+ var VariableValueContainingReferences_1 = require("./VariableValueContainingReferences");
145
+ var resolveReferencesOnce_1 = require("./resolveReferencesOnce");
146
+ var resolveAllReferencesOnce = function (values, getEnvVars) {
147
+ return __awaiter(void 0, void 0, void 0, function () {
148
+ var allReferences, allComponentsUnique, allEnvVarsInComponents, _a, _b;
149
+ return __generator(this, function (_c) {
150
+ switch (_c.label) {
151
+ case 0:
152
+ allReferences = Object.values(values).flatMap(function (value) {
153
+ return value === null || value === void 0 ? void 0 : value.parts.filter(function (part) {
154
+ return part instanceof VariableValueContainingReferences_1.VariableReference;
155
+ });
156
+ });
157
+ allComponentsUnique = Array.from(new Set(allReferences.map(function (reference) {
158
+ return reference.componentName;
159
+ })));
160
+ _b = (_a = Object).fromEntries;
161
+ return [4 /*yield*/, Promise.all(allComponentsUnique.map(function (componentName) {
162
+ return __awaiter(void 0, void 0, void 0, function () {
163
+ var _a;
164
+ return __generator(this, function (_b) {
165
+ switch (_b.label) {
166
+ case 0:
167
+ _a = [componentName];
168
+ return [4 /*yield*/, getEnvVars(componentName)];
169
+ case 1:
170
+ return [2 /*return*/, _a.concat([_b.sent()])];
171
+ }
172
+ });
173
+ });
174
+ }))];
175
+ case 1:
176
+ allEnvVarsInComponents = _b.apply(_a, [_c.sent()]);
177
+ return [2 /*return*/, Object.fromEntries(Object.entries(values).map(function (_a) {
178
+ var _b = __read(_a, 2),
179
+ key = _b[0],
180
+ value = _b[1];
181
+ return [key, value !== null && value !== undefined ? (0, resolveReferencesOnce_1.resolveReferencesOnce)(value, function (_a) {
182
+ var componentName = _a.componentName,
183
+ variableName = _a.variableName;
184
+ return allEnvVarsInComponents[componentName][variableName];
185
+ }) : value];
186
+ }))];
187
+ }
188
+ });
189
+ });
190
+ };
191
+ exports.resolveAllReferencesOnce = resolveAllReferencesOnce;
@@ -0,0 +1,8 @@
1
+ import type { VariableValue } from "./VariableValue";
2
+ import { VariableValueContainingReferences } from "./VariableValueContainingReferences";
3
+ type Resolver = (args: {
4
+ componentName: string;
5
+ variableName: string;
6
+ }) => VariableValue | null | undefined;
7
+ export declare const resolveReferencesOnce: (value: VariableValueContainingReferences, resolver: Resolver) => VariableValueContainingReferences;
8
+ export {};
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.resolveReferencesOnce = void 0;
7
+ var VariableValueContainingReferences_1 = require("./VariableValueContainingReferences");
8
+ var resolveReferencesOnce = function (value, resolver) {
9
+ var replacedParts = value.parts.map(function (part) {
10
+ if (part instanceof VariableValueContainingReferences_1.VariableReference) {
11
+ var result = resolver({
12
+ componentName: part.componentName,
13
+ variableName: part.variableName
14
+ });
15
+ return result !== null && result !== void 0 ? result : new VariableValueContainingReferences_1.UnresolvableReference(part);
16
+ } else {
17
+ return part;
18
+ }
19
+ });
20
+ return new VariableValueContainingReferences_1.VariableValueContainingReferences(replacedParts);
21
+ };
22
+ exports.resolveReferencesOnce = resolveReferencesOnce;