@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
@@ -1,368 +0,0 @@
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
- var resolveReferences_1 = require("../resolveReferences");
144
- var unpackBashExpressions = function (obj) {
145
- return Object.fromEntries(Object.entries(obj).map(function (_a) {
146
- var _b = __read(_a, 2),
147
- key = _b[0],
148
- value = _b[1];
149
- return [key, value.toString()];
150
- }));
151
- };
152
- describe("resolveReferences", function () {
153
- it("replaces occurences of ${componentName:VARIABLE_NAME}", function () {
154
- return __awaiter(void 0, void 0, void 0, function () {
155
- var variables, otherVariables, result;
156
- return __generator(this, function (_a) {
157
- switch (_a.label) {
158
- case 0:
159
- variables = {
160
- a: "hello world",
161
- b: "a replaced value looks like this: '${api:FOO}', nice!"
162
- };
163
- otherVariables = {
164
- api: {
165
- FOO: "foo from api"
166
- },
167
- frontend: {
168
- FOO: "foo from frontend"
169
- }
170
- };
171
- return [4 /*yield*/, (0, resolveReferences_1.resolveReferences)(variables, function (componentName) {
172
- return __awaiter(void 0, void 0, void 0, function () {
173
- return __generator(this, function (_a) {
174
- return [2 /*return*/, otherVariables[componentName]];
175
- });
176
- });
177
- })];
178
- case 1:
179
- result = _a.sent();
180
- expect(unpackBashExpressions(result)).toEqual({
181
- a: "hello world",
182
- b: "a replaced value looks like this: 'foo from api', nice!"
183
- });
184
- return [2 /*return*/];
185
- }
186
- });
187
- });
188
- });
189
-
190
- it("replaces self references with structure ${VARIABLE_NAME}", function () {
191
- return __awaiter(void 0, void 0, void 0, function () {
192
- var variables, result;
193
- return __generator(this, function (_a) {
194
- switch (_a.label) {
195
- case 0:
196
- variables = {
197
- FOO: "hello world",
198
- BAR: "this: ${FOO}!"
199
- };
200
- return [4 /*yield*/, (0, resolveReferences_1.resolveReferences)(variables)];
201
- case 1:
202
- result = _a.sent();
203
- expect(unpackBashExpressions(result)).toEqual({
204
- FOO: "hello world",
205
- BAR: "this: hello world!"
206
- });
207
- return [2 /*return*/];
208
- }
209
- });
210
- });
211
- });
212
-
213
- it("replaces self references mixed with other vars", function () {
214
- return __awaiter(void 0, void 0, void 0, function () {
215
- var variables, otherVariables, result;
216
- return __generator(this, function (_a) {
217
- switch (_a.label) {
218
- case 0:
219
- variables = {
220
- FOO: "hello from ${api:FOO}",
221
- BAR: "this: ${FOO}!"
222
- };
223
- otherVariables = {
224
- api: {
225
- FOO: "foo from api"
226
- }
227
- };
228
- return [4 /*yield*/, (0, resolveReferences_1.resolveReferences)(variables, function (componentName) {
229
- return __awaiter(void 0, void 0, void 0, function () {
230
- return __generator(this, function (_a) {
231
- return [2 /*return*/, otherVariables[componentName]];
232
- });
233
- });
234
- })];
235
- case 1:
236
- result = _a.sent();
237
- expect(unpackBashExpressions(result)).toEqual({
238
- FOO: "hello from foo from api",
239
- BAR: "this: hello from foo from api!"
240
- });
241
- return [2 /*return*/];
242
- }
243
- });
244
- });
245
- });
246
-
247
- it("keeps variables as is if not found (when null is returned)", function () {
248
- return __awaiter(void 0, void 0, void 0, function () {
249
- var variables, otherVariables, result;
250
- return __generator(this, function (_a) {
251
- switch (_a.label) {
252
- case 0:
253
- variables = {
254
- a: "hello world",
255
- b: "a not found value looks like this: '${api:FOO}'"
256
- };
257
- otherVariables = {};
258
- return [4 /*yield*/, (0, resolveReferences_1.resolveReferences)(variables, function (componentName) {
259
- return __awaiter(void 0, void 0, void 0, function () {
260
- return __generator(this, function (_a) {
261
- return [2 /*return*/, otherVariables[componentName]];
262
- });
263
- });
264
- })];
265
- case 1:
266
- result = _a.sent();
267
- expect(unpackBashExpressions(result)).toEqual({
268
- a: "hello world",
269
- b: "a not found value looks like this: '${api:FOO}'"
270
- });
271
- return [2 /*return*/];
272
- }
273
- });
274
- });
275
- });
276
-
277
- it("replaces mulitple levels deep", function () {
278
- return __awaiter(void 0, void 0, void 0, function () {
279
- var variables, otherVariables, result;
280
- return __generator(this, function (_a) {
281
- switch (_a.label) {
282
- case 0:
283
- variables = {
284
- a: "value is ${frontend:FOO}!"
285
- };
286
- otherVariables = {
287
- api: {
288
- FOO: "foo from api"
289
- },
290
- frontend: {
291
- FOO: "hi, ${api:FOO}"
292
- }
293
- };
294
- return [4 /*yield*/, (0, resolveReferences_1.resolveReferences)(variables, function (componentName) {
295
- return __awaiter(void 0, void 0, void 0, function () {
296
- return __generator(this, function (_a) {
297
- return [2 /*return*/, otherVariables[componentName]];
298
- });
299
- });
300
- })];
301
- case 1:
302
- result = _a.sent();
303
- expect(unpackBashExpressions(result)).toEqual({
304
- a: "value is hi, foo from api!"
305
- });
306
- return [2 /*return*/];
307
- }
308
- });
309
- });
310
- });
311
-
312
- it("prevents endless loops", function () {
313
- return __awaiter(void 0, void 0, void 0, function () {
314
- var variables, otherVariables, result;
315
- return __generator(this, function (_a) {
316
- switch (_a.label) {
317
- case 0:
318
- variables = {
319
- a: "value is ${frontend:FOO}!"
320
- };
321
- otherVariables = {
322
- api: {
323
- FOO: "api ${frontend:FOO}"
324
- },
325
- frontend: {
326
- FOO: "frontend ${api:FOO}"
327
- }
328
- };
329
- return [4 /*yield*/, (0, resolveReferences_1.resolveReferences)(variables, function (componentName) {
330
- return __awaiter(void 0, void 0, void 0, function () {
331
- return __generator(this, function (_a) {
332
- return [2 /*return*/, otherVariables[componentName]];
333
- });
334
- });
335
- })];
336
- case 1:
337
- result = _a.sent();
338
- expect(unpackBashExpressions(result)).toEqual({
339
- a: "value is frontend api ${frontend:FOO}!"
340
- });
341
- return [2 /*return*/];
342
- }
343
- });
344
- });
345
- });
346
- });
347
-
348
- describe("translateLegacyFromComponents", function () {
349
- it("translatetes the old `fromComponents` approach to ${componentName:variableName}", function () {
350
- var fromComponents = {
351
- api: {
352
- API_FOO: "FOO",
353
- API_BAR: "BAR"
354
- },
355
- www: {
356
- WWW_X: "X",
357
- WWW_Y: "Y"
358
- }
359
- };
360
- var result = (0, resolveReferences_1.translateLegacyFromComponents)(fromComponents);
361
- expect(result).toEqual({
362
- API_FOO: "${api:FOO}",
363
- API_BAR: "${api:BAR}",
364
- WWW_X: "${www:X}",
365
- WWW_Y: "${www:Y}"
366
- });
367
- });
368
- });
@@ -1,6 +0,0 @@
1
- import type { BashExpression } from "../bash/BashExpression";
2
- import type { UnspecifiedEnvVars } from "..";
3
- export declare const resolveReferences: (vars: Record<string, string | BashExpression | undefined | null>, getOtherVariables?: (componentName: string, alreadyVisited: Record<string, Record<string, boolean>>) => Promise<UnspecifiedEnvVars>, alreadyVisitedBase?: Record<string, Record<string, boolean>>) => Promise<Record<string, BashExpression>>;
4
- export declare const translateLegacyFromComponents: (fromComponents: Record<string, Record<string, string>>) => {
5
- [k: string]: string;
6
- };
@@ -1,286 +0,0 @@
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
- var __spreadArray = this && this.__spreadArray || function (to, from, pack) {
141
- if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
142
- if (ar || !(i in from)) {
143
- if (!ar) ar = Array.prototype.slice.call(from, 0, i);
144
- ar[i] = from[i];
145
- }
146
- }
147
- return to.concat(ar || Array.prototype.slice.call(from));
148
- };
149
- var __importDefault = this && this.__importDefault || function (mod) {
150
- return mod && mod.__esModule ? mod : {
151
- "default": mod
152
- };
153
- };
154
- Object.defineProperty(exports, "__esModule", {
155
- value: true
156
- });
157
- exports.translateLegacyFromComponents = exports.resolveReferences = void 0;
158
- var lodash_1 = require("lodash");
159
- var replaceAsync_1 = __importDefault(require("../bash/replaceAsync"));
160
- // regex to resolve references in catladder variables
161
- // those expressions have the pattern ${componentName:variableName}
162
- var REGEX = /\$\{(([^:}]+):)?([^}]+)}/gm;
163
- var resolveReferences = function (vars_1, getOtherVariables_1) {
164
- var args_1 = [];
165
- for (var _i = 2; _i < arguments.length; _i++) {
166
- args_1[_i - 2] = arguments[_i];
167
- }
168
- return __awaiter(void 0, __spreadArray([vars_1, getOtherVariables_1], __read(args_1), false), void 0, function (vars, getOtherVariables, alreadyVisitedBase) {
169
- var replaceSingleValue, _a, _b;
170
- if (alreadyVisitedBase === void 0) {
171
- alreadyVisitedBase = {};
172
- }
173
- return __generator(this, function (_c) {
174
- switch (_c.label) {
175
- case 0:
176
- replaceSingleValue = function (value_1) {
177
- var args_1 = [];
178
- for (var _i = 1; _i < arguments.length; _i++) {
179
- args_1[_i - 1] = arguments[_i];
180
- }
181
- return __awaiter(void 0, __spreadArray([value_1], __read(args_1), false), void 0, function (value, alreadyVisited) {
182
- if (alreadyVisited === void 0) {
183
- alreadyVisited = alreadyVisitedBase;
184
- }
185
- return __generator(this, function (_a) {
186
- switch (_a.label) {
187
- case 0:
188
- if (!REGEX.test(value.toString())) return [3 /*break*/, 2];
189
- return [4 /*yield*/, (0, replaceAsync_1.default)(value, REGEX, function (match, _, componentName, variableName) {
190
- return __awaiter(void 0, void 0, void 0, function () {
191
- var newAlreadyVisited, result, _a, replaced, _b;
192
- var _c, _d;
193
- var _e, _f;
194
- return __generator(this, function (_g) {
195
- switch (_g.label) {
196
- case 0:
197
- if ((_e = alreadyVisited[componentName]) === null || _e === void 0 ? void 0 : _e[variableName]) {
198
- return [2 /*return*/, match]; // prevent endless loop
199
- }
200
-
201
- newAlreadyVisited = (0, lodash_1.merge)({}, alreadyVisited, (_c = {}, _c[componentName] = (_d = {}, _d[variableName] = true, _d), _c));
202
- if (!componentName) return [3 /*break*/, 2];
203
- return [4 /*yield*/, getOtherVariables === null || getOtherVariables === void 0 ? void 0 : getOtherVariables(componentName, newAlreadyVisited).then(function (r) {
204
- return r === null || r === void 0 ? void 0 : r[variableName];
205
- })];
206
- case 1:
207
- _a = (_f = _g.sent()) !== null && _f !== void 0 ? _f : null;
208
- return [3 /*break*/, 3];
209
- case 2:
210
- _a = vars[variableName];
211
- _g.label = 3;
212
- case 3:
213
- result = _a;
214
- if (!(result !== null && result !== undefined)) return [3 /*break*/, 5];
215
- return [4 /*yield*/, replaceSingleValue(result, newAlreadyVisited)];
216
- case 4:
217
- _b = _g.sent();
218
- return [3 /*break*/, 6];
219
- case 5:
220
- _b = match;
221
- _g.label = 6;
222
- case 6:
223
- replaced = _b;
224
- return [2 /*return*/, replaced];
225
- }
226
- });
227
- });
228
- })];
229
- case 1:
230
- // we consider variables that got references in it BashExpressions, because the replacement may be one
231
- return [2 /*return*/, _a.sent()];
232
- case 2:
233
- return [2 /*return*/, value];
234
- }
235
- });
236
- });
237
- };
238
- _b = (_a = Object).fromEntries;
239
- return [4 /*yield*/, Promise.all(Object.entries(vars).map(function (_a) {
240
- return __awaiter(void 0, [_a], void 0, function (_b) {
241
- var _c, _d;
242
- var _e = __read(_b, 2),
243
- key = _e[0],
244
- value = _e[1];
245
- return __generator(this, function (_f) {
246
- switch (_f.label) {
247
- case 0:
248
- if (value === null || value === undefined) {
249
- return [2 /*return*/, [key, null]];
250
- }
251
- _c = [key];
252
- if (!(value !== null && value !== undefined)) return [3 /*break*/, 2];
253
- return [4 /*yield*/, replaceSingleValue(value)];
254
- case 1:
255
- _d = _f.sent();
256
- return [3 /*break*/, 3];
257
- case 2:
258
- _d = null;
259
- _f.label = 3;
260
- case 3:
261
- return [2 /*return*/, _c.concat([_d])];
262
- }
263
- });
264
- });
265
- }))];
266
- case 1:
267
- return [2 /*return*/, _b.apply(_a, [_c.sent()])];
268
- }
269
- });
270
- });
271
- };
272
- exports.resolveReferences = resolveReferences;
273
- var translateLegacyFromComponents = function (fromComponents) {
274
- return Object.fromEntries(Object.entries(fromComponents).flatMap(function (_a) {
275
- var _b = __read(_a, 2),
276
- componentName = _b[0],
277
- variables = _b[1];
278
- return Object.entries(variables).map(function (_a) {
279
- var _b = __read(_a, 2),
280
- ourName = _b[0],
281
- otherName = _b[1];
282
- return [ourName, "${" + componentName + ":" + otherName + "}"];
283
- });
284
- }));
285
- };
286
- exports.translateLegacyFromComponents = translateLegacyFromComponents;