@aws-cdk/toolkit-lib 0.3.3 → 0.3.5

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 (146) hide show
  1. package/api-extractor.json +8 -2
  2. package/build-info.json +2 -2
  3. package/db.json.gz +0 -0
  4. package/lib/actions/bootstrap/private/helpers.js +3 -3
  5. package/lib/actions/diff/index.d.ts +2 -2
  6. package/lib/actions/diff/index.js +1 -1
  7. package/lib/actions/diff/private/helpers.js +8 -8
  8. package/lib/actions/refactor/index.d.ts +44 -0
  9. package/lib/actions/refactor/index.js +1 -1
  10. package/lib/api/aws-auth/awscli-compatible.d.ts +6 -5
  11. package/lib/api/aws-auth/awscli-compatible.js +2 -2
  12. package/lib/api/aws-auth/credential-plugins.d.ts +2 -2
  13. package/lib/api/aws-auth/credential-plugins.js +2 -2
  14. package/lib/api/aws-auth/provider-caching.d.ts +3 -3
  15. package/lib/api/aws-auth/provider-caching.js +1 -1
  16. package/lib/api/aws-auth/sdk-logger.d.ts +8 -2
  17. package/lib/api/aws-auth/sdk-logger.js +4 -4
  18. package/lib/api/aws-auth/sdk-provider.d.ts +4 -3
  19. package/lib/api/aws-auth/sdk-provider.js +2 -2
  20. package/lib/api/aws-auth/sdk.d.ts +7 -6
  21. package/lib/api/aws-auth/sdk.js +4 -4
  22. package/lib/api/aws-auth/tracing.d.ts +2 -2
  23. package/lib/api/aws-auth/tracing.js +1 -1
  24. package/lib/api/aws-auth/types.d.ts +3 -3
  25. package/lib/api/aws-auth/types.js +1 -1
  26. package/lib/api/bootstrap/bootstrap-environment.js +2 -2
  27. package/lib/api/bootstrap/bootstrap-template.yaml +12 -1
  28. package/lib/api/cloud-assembly/environment.js +1 -1
  29. package/lib/api/cloud-assembly/index.d.ts +2 -1
  30. package/lib/api/cloud-assembly/index.js +3 -2
  31. package/lib/api/cloud-assembly/private/context-aware-source.js +3 -3
  32. package/lib/api/cloud-assembly/private/exec.js +3 -3
  33. package/lib/api/cloud-assembly/private/prepare-source.js +4 -4
  34. package/lib/api/cloud-assembly/private/source-builder.d.ts +14 -12
  35. package/lib/api/cloud-assembly/private/source-builder.js +40 -23
  36. package/lib/api/cloud-assembly/private/stack-assembly.js +7 -7
  37. package/lib/api/cloud-assembly/source-builder.d.ts +19 -0
  38. package/lib/api/cloud-assembly/source-builder.js +1 -1
  39. package/lib/api/cloud-assembly/stack-collection.js +2 -2
  40. package/lib/api/cloudformation/evaluate-cloudformation-template.d.ts +1 -1
  41. package/lib/api/cloudformation/evaluate-cloudformation-template.js +2 -2
  42. package/lib/api/cloudformation/stack-helpers.js +2 -2
  43. package/lib/api/cloudformation/template-body-parameter.js +2 -2
  44. package/lib/api/context.js +2 -2
  45. package/lib/api/deployments/asset-publishing.js +2 -2
  46. package/lib/api/deployments/assets.js +5 -6
  47. package/lib/api/deployments/cfn-api.js +3 -3
  48. package/lib/api/deployments/checks.js +2 -2
  49. package/lib/api/deployments/deploy-stack.js +2 -2
  50. package/lib/api/deployments/deployment-result.js +2 -2
  51. package/lib/api/deployments/deployments.js +3 -3
  52. package/lib/api/diff/diff-formatter.js +2 -2
  53. package/lib/api/environment/environment-access.js +2 -2
  54. package/lib/api/environment/environment-resources.js +2 -2
  55. package/lib/api/environment/placeholders.js +1 -1
  56. package/lib/api/garbage-collection/garbage-collector.js +2 -2
  57. package/lib/api/garbage-collection/progress-printer.js +2 -2
  58. package/lib/api/garbage-collection/stack-refresh.js +2 -2
  59. package/lib/api/hotswap/appsync-mapping-templates.js +2 -2
  60. package/lib/api/hotswap/common.d.ts +2 -1
  61. package/lib/api/hotswap/common.js +9 -3
  62. package/lib/api/hotswap/ecs-services.js +3 -2
  63. package/lib/api/hotswap/hotswap-deployments.js +2 -2
  64. package/lib/api/hotswap/lambda-functions.js +2 -2
  65. package/lib/api/index.d.ts +0 -1
  66. package/lib/api/index.js +1 -2
  67. package/lib/api/io/private/index.d.ts +0 -1
  68. package/lib/api/io/private/index.js +1 -2
  69. package/lib/api/io/private/level-priority.js +1 -1
  70. package/lib/api/io/private/span.js +1 -1
  71. package/lib/api/logs-monitor/logs-monitor.js +2 -2
  72. package/lib/api/notices/cached-data-source.d.ts +13 -0
  73. package/lib/api/notices/cached-data-source.js +77 -0
  74. package/lib/api/notices/filter.d.ts +59 -0
  75. package/lib/api/notices/filter.js +189 -0
  76. package/lib/api/notices/index.d.ts +1 -0
  77. package/lib/api/{private.js → notices/index.js} +2 -2
  78. package/lib/api/notices/notices.d.ts +111 -0
  79. package/lib/api/notices/notices.js +131 -0
  80. package/lib/api/notices/types.d.ts +37 -0
  81. package/lib/api/notices/types.js +3 -0
  82. package/lib/api/notices/web-data-source.d.ts +9 -0
  83. package/lib/api/notices/web-data-source.js +70 -0
  84. package/lib/api/plugin/context-provider-plugin.js +1 -1
  85. package/lib/api/plugin/plugin.d.ts +4 -6
  86. package/lib/api/plugin/plugin.js +8 -13
  87. package/lib/api/refactoring/cloudformation.d.ts +23 -0
  88. package/lib/api/refactoring/cloudformation.js +54 -1
  89. package/lib/api/refactoring/exclude.d.ts +29 -0
  90. package/lib/api/refactoring/exclude.js +94 -0
  91. package/lib/api/refactoring/execution.d.ts +7 -0
  92. package/lib/api/refactoring/execution.js +43 -0
  93. package/lib/api/refactoring/index.d.ts +6 -23
  94. package/lib/api/refactoring/index.js +89 -60
  95. package/lib/api/resource-import/importer.js +2 -2
  96. package/lib/api/rwlock.js +2 -2
  97. package/lib/api/settings.js +2 -2
  98. package/lib/api/shared-private.js +31 -6186
  99. package/lib/api/toolkit-info.js +2 -2
  100. package/lib/api/work-graph/work-graph-builder.js +3 -3
  101. package/lib/api/work-graph/work-graph.js +2 -2
  102. package/lib/context-providers/ami.js +2 -2
  103. package/lib/context-providers/cc-api-provider.js +2 -2
  104. package/lib/context-providers/hosted-zones.js +2 -2
  105. package/lib/context-providers/index.js +4 -4
  106. package/lib/context-providers/keys.js +2 -2
  107. package/lib/context-providers/load-balancers.js +2 -2
  108. package/lib/context-providers/security-groups.js +2 -2
  109. package/lib/context-providers/ssm-parameters.js +2 -2
  110. package/lib/context-providers/vpcs.js +3 -3
  111. package/lib/index.d.ts +3 -1
  112. package/lib/index.js +4 -2
  113. package/lib/index_bg.wasm +0 -0
  114. package/lib/payloads/deploy.d.ts +8 -1
  115. package/lib/payloads/deploy.js +1 -1
  116. package/lib/payloads/hotswap.d.ts +1 -0
  117. package/lib/payloads/hotswap.js +1 -1
  118. package/lib/private/activity-printer/base.js +1 -1
  119. package/lib/toolkit/non-interactive-io-host.js +5 -4
  120. package/lib/toolkit/toolkit.d.ts +2 -2
  121. package/lib/toolkit/toolkit.js +82 -37
  122. package/lib/util/directories.js +2 -2
  123. package/lib/util/index.d.ts +1 -0
  124. package/lib/util/index.js +2 -1
  125. package/lib/util/json.js +1 -1
  126. package/lib/util/net.d.ts +9 -0
  127. package/lib/util/net.js +60 -0
  128. package/lib/util/objects.js +2 -2
  129. package/lib/util/types.js +1 -1
  130. package/lib/util/version-range.js +2 -2
  131. package/package.json +31 -31
  132. package/tsdoc.json +20 -0
  133. package/lib/api/io/private/sdk-logger.d.ts +0 -3
  134. package/lib/api/io/private/sdk-logger.js +0 -124
  135. package/lib/api/notices.d.ts +0 -210
  136. package/lib/api/notices.js +0 -430
  137. package/lib/api/private.d.ts +0 -1
  138. package/lib/api/shared-private.js.map +0 -7
  139. package/lib/api/shared-public.d.ts +0 -2139
  140. package/lib/api/shared-public.js +0 -3272
  141. package/lib/api/shared-public.js.map +0 -7
  142. package/lib/private/util.d.ts +0 -1
  143. package/lib/private/util.js +0 -787
  144. package/lib/private/util.js.map +0 -7
  145. /package/lib/{api → toolkit}/toolkit-error.d.ts +0 -0
  146. /package/lib/{api → toolkit}/toolkit-error.js +0 -0
@@ -1,787 +0,0 @@
1
- "use strict";
2
- var __create = Object.create;
3
- var __defProp = Object.defineProperty;
4
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
- var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __getProtoOf = Object.getPrototypeOf;
7
- var __hasOwnProp = Object.prototype.hasOwnProperty;
8
- var __export = (target, all) => {
9
- for (var name in all)
10
- __defProp(target, name, { get: all[name], enumerable: true });
11
- };
12
- var __copyProps = (to, from, except, desc) => {
13
- if (from && typeof from === "object" || typeof from === "function") {
14
- for (let key of __getOwnPropNames(from))
15
- if (!__hasOwnProp.call(to, key) && key !== except)
16
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
- }
18
- return to;
19
- };
20
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
- // If the importer is in node compatibility mode or this is not an ESM
22
- // file that has been converted to a CommonJS file using a Babel-
23
- // compatible transform (i.e. "__esModule" has not been set), then set
24
- // "default" to the CommonJS "module.exports" for node compatibility.
25
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
- mod
27
- ));
28
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
-
30
- // lib/private/util.ts
31
- var util_exports = {};
32
- __export(util_exports, {
33
- applyDefaults: () => applyDefaults,
34
- bundledPackageRootDir: () => bundledPackageRootDir,
35
- cdkCacheDir: () => cdkCacheDir,
36
- cdkHomeDir: () => cdkHomeDir,
37
- contentHash: () => contentHash,
38
- contentHashAny: () => contentHashAny,
39
- createBranded: () => createBranded,
40
- deepClone: () => deepClone,
41
- deepGet: () => deepGet,
42
- deepMerge: () => deepMerge,
43
- deepSet: () => deepSet,
44
- deserialize: () => deserialize,
45
- deserializeStructure: () => deserializeStructure,
46
- displayVersion: () => displayVersion,
47
- findJsonValue: () => findJsonValue,
48
- flatMap: () => flatMap,
49
- flatten: () => flatten,
50
- formatBytes: () => formatBytes,
51
- formatErrorMessage: () => formatErrorMessage,
52
- formatTime: () => formatTime,
53
- getResultObj: () => getResultObj,
54
- ifDefined: () => ifDefined,
55
- isArray: () => isArray,
56
- isDeveloperBuild: () => isDeveloperBuild,
57
- isEmpty: () => isEmpty,
58
- isObject: () => isObject,
59
- loadStructuredFile: () => loadStructuredFile,
60
- lowerCaseFirstCharacter: () => lowerCaseFirstCharacter,
61
- makeObject: () => makeObject,
62
- mapObject: () => mapObject,
63
- maxResourceTypeLength: () => maxResourceTypeLength,
64
- numberFromBool: () => numberFromBool,
65
- obscureTemplate: () => obscureTemplate,
66
- padLeft: () => padLeft,
67
- padRight: () => padRight,
68
- parallelPromises: () => parallelPromises,
69
- partition: () => partition,
70
- rangeFromSemver: () => rangeFromSemver,
71
- replacerBufferWithInfo: () => replacerBufferWithInfo,
72
- serialize: () => serialize,
73
- serializeStructure: () => serializeStructure,
74
- splitBySize: () => splitBySize,
75
- stackEventHasErrorMessage: () => stackEventHasErrorMessage,
76
- toYAML: () => toYAML,
77
- transformObjectKeys: () => transformObjectKeys,
78
- validateSnsTopicArn: () => validateSnsTopicArn,
79
- versionNumber: () => versionNumber,
80
- zipDirectory: () => zipDirectory
81
- });
82
- module.exports = __toCommonJS(util_exports);
83
-
84
- // lib/util/archive.ts
85
- var import_console = require("console");
86
- var import_fs = require("fs");
87
- var path = __toESM(require("path"));
88
- var glob = __toESM(require("glob"));
89
-
90
- // lib/util/format-error.ts
91
- function formatErrorMessage(error2) {
92
- if (error2 && Array.isArray(error2.errors)) {
93
- const innerMessages = error2.errors.map((innerError) => innerError?.message || innerError?.toString()).join("\n");
94
- return `AggregateError: ${innerMessages}`;
95
- }
96
- return error2?.message || error2?.toString() || "Unknown error";
97
- }
98
-
99
- // lib/util/archive.ts
100
- var archiver = require("archiver");
101
- async function zipDirectory(directory, outputFile) {
102
- const temporaryOutputFile = `${outputFile}.${randomString()}._tmp`;
103
- await writeZipFile(directory, temporaryOutputFile);
104
- await moveIntoPlace(temporaryOutputFile, outputFile);
105
- }
106
- function writeZipFile(directory, outputFile) {
107
- return new Promise(async (ok, fail) => {
108
- const globOptions = {
109
- dot: true,
110
- nodir: true,
111
- follow: true,
112
- cwd: directory
113
- };
114
- const files = glob.sync("**", globOptions);
115
- const output = (0, import_fs.createWriteStream)(outputFile);
116
- const archive = archiver("zip");
117
- archive.on("warning", fail);
118
- archive.on("error", fail);
119
- output.once("close", ok);
120
- archive.pipe(output);
121
- for (const file of files) {
122
- const fullPath = path.resolve(directory, file);
123
- const [data, stat] = await Promise.all([import_fs.promises.readFile(fullPath), import_fs.promises.stat(fullPath)]);
124
- archive.append(data, {
125
- name: file,
126
- mode: stat.mode
127
- });
128
- }
129
- await archive.finalize();
130
- });
131
- }
132
- async function moveIntoPlace(source, target) {
133
- let delay = 100;
134
- let attempts = 5;
135
- while (true) {
136
- try {
137
- await import_fs.promises.rename(source, target);
138
- return;
139
- } catch (e) {
140
- if (e.code !== "EPERM" || attempts-- <= 0) {
141
- throw e;
142
- }
143
- (0, import_console.error)(formatErrorMessage(e));
144
- await sleep(Math.floor(Math.random() * delay));
145
- delay *= 2;
146
- }
147
- }
148
- }
149
- function sleep(ms) {
150
- return new Promise((ok) => setTimeout(ok, ms));
151
- }
152
- function randomString() {
153
- return Math.random().toString(36).replace(/[^a-z0-9]+/g, "");
154
- }
155
-
156
- // lib/util/arrays.ts
157
- function flatMap(xs, fn) {
158
- return flatten(xs.map(fn));
159
- }
160
- function flatten(xs) {
161
- return Array.prototype.concat.apply([], xs);
162
- }
163
- function partition(collection, pred) {
164
- const ret = [];
165
- let i = 0;
166
- while (i < collection.length) {
167
- if (pred(collection[i])) {
168
- ret.push(collection.splice(i, 1)[0]);
169
- } else {
170
- i++;
171
- }
172
- }
173
- return ret;
174
- }
175
-
176
- // lib/util/bool.ts
177
- function numberFromBool(bool) {
178
- return +bool;
179
- }
180
-
181
- // lib/util/bytes.ts
182
- function formatBytes(bytes, decimals = 2) {
183
- decimals = decimals < 0 ? 0 : decimals;
184
- if (bytes === 0) {
185
- return "0 Bytes";
186
- }
187
- const k = 1024;
188
- const sizes = ["Bytes", "KiB", "MiB", "GiB", "TiB", "PiB", "EiB", "ZiB", "YiB"];
189
- const i = Math.floor(Math.log(bytes) / Math.log(k));
190
- return `${parseFloat((bytes / Math.pow(k, i)).toFixed(decimals))} ${sizes[i]}`;
191
- }
192
-
193
- // lib/util/cloudformation.ts
194
- function validateSnsTopicArn(arn) {
195
- return /^arn:aws:sns:[a-z0-9\-]+:[0-9]+:[a-z0-9\-\_]+$/i.test(arn);
196
- }
197
- function stackEventHasErrorMessage(status) {
198
- return status.endsWith("_FAILED") || status === "ROLLBACK_IN_PROGRESS" || status === "UPDATE_ROLLBACK_IN_PROGRESS";
199
- }
200
- function maxResourceTypeLength(template, startWidth = "AWS::CloudFormation::Stack".length) {
201
- const resources = template && template.Resources || {};
202
- let maxWidth = startWidth;
203
- for (const id of Object.keys(resources)) {
204
- const type = resources[id].Type || "";
205
- if (type.length > maxWidth) {
206
- maxWidth = type.length;
207
- }
208
- }
209
- return maxWidth;
210
- }
211
-
212
- // lib/util/content-hash.ts
213
- var crypto = __toESM(require("crypto"));
214
- function contentHash(data) {
215
- return crypto.createHash("sha256").update(data).digest("hex");
216
- }
217
- function contentHashAny(value) {
218
- const ret = crypto.createHash("sha256");
219
- recurse(value);
220
- return ret.digest("hex");
221
- function recurse(x) {
222
- if (typeof x === "string") {
223
- ret.update(x);
224
- return;
225
- }
226
- if (Array.isArray(x)) {
227
- ret.update("[");
228
- for (const e of x) {
229
- recurse(e);
230
- ret.update("||");
231
- }
232
- ret.update("]");
233
- return;
234
- }
235
- if (x && typeof x === "object") {
236
- ret.update("{");
237
- for (const key of Object.keys(x).sort()) {
238
- ret.update(key);
239
- ret.update(":");
240
- recurse(x[key]);
241
- }
242
- ret.update("}");
243
- return;
244
- }
245
- ret.update(`${x}${typeof x}`);
246
- }
247
- }
248
-
249
- // lib/util/directories.ts
250
- var fs2 = __toESM(require("fs"));
251
- var os = __toESM(require("os"));
252
- var path2 = __toESM(require("path"));
253
-
254
- // lib/api/toolkit-error.ts
255
- var TOOLKIT_ERROR_SYMBOL = Symbol.for("@aws-cdk/toolkit-lib.ToolkitError");
256
- var AUTHENTICATION_ERROR_SYMBOL = Symbol.for("@aws-cdk/toolkit-lib.AuthenticationError");
257
- var ASSEMBLY_ERROR_SYMBOL = Symbol.for("@aws-cdk/toolkit-lib.AssemblyError");
258
- var CONTEXT_PROVIDER_ERROR_SYMBOL = Symbol.for("@aws-cdk/toolkit-lib.ContextProviderError");
259
- var ToolkitError = class _ToolkitError extends Error {
260
- /**
261
- * Determines if a given error is an instance of ToolkitError.
262
- */
263
- static isToolkitError(x) {
264
- return x !== null && typeof x === "object" && TOOLKIT_ERROR_SYMBOL in x;
265
- }
266
- /**
267
- * Determines if a given error is an instance of AuthenticationError.
268
- */
269
- static isAuthenticationError(x) {
270
- return this.isToolkitError(x) && AUTHENTICATION_ERROR_SYMBOL in x;
271
- }
272
- /**
273
- * Determines if a given error is an instance of AssemblyError.
274
- */
275
- static isAssemblyError(x) {
276
- return this.isToolkitError(x) && ASSEMBLY_ERROR_SYMBOL in x;
277
- }
278
- /**
279
- * Determines if a given error is an instance of AssemblyError.
280
- */
281
- static isContextProviderError(x) {
282
- return this.isToolkitError(x) && CONTEXT_PROVIDER_ERROR_SYMBOL in x;
283
- }
284
- /**
285
- * An AssemblyError with an original error as cause
286
- */
287
- static withCause(message, error2) {
288
- return new _ToolkitError(message, "toolkit", error2);
289
- }
290
- /**
291
- * The type of the error, defaults to "toolkit".
292
- */
293
- type;
294
- /**
295
- * Denotes the source of the error as the toolkit.
296
- */
297
- source;
298
- /**
299
- * The specific original cause of the error, if available
300
- */
301
- cause;
302
- constructor(message, type = "toolkit", cause) {
303
- super(message);
304
- Object.setPrototypeOf(this, _ToolkitError.prototype);
305
- Object.defineProperty(this, TOOLKIT_ERROR_SYMBOL, { value: true });
306
- this.name = new.target.name;
307
- this.type = type;
308
- this.source = "toolkit";
309
- this.cause = cause;
310
- }
311
- };
312
-
313
- // lib/util/directories.ts
314
- function cdkHomeDir() {
315
- const tmpDir = fs2.realpathSync(os.tmpdir());
316
- let home;
317
- try {
318
- let userInfoHome = os.userInfo().homedir;
319
- if (userInfoHome == "/var/empty") {
320
- userInfoHome = void 0;
321
- }
322
- home = path2.join((userInfoHome ?? os.homedir()).trim(), ".cdk");
323
- } catch {
324
- }
325
- return process.env.CDK_HOME ? path2.resolve(process.env.CDK_HOME) : home || fs2.mkdtempSync(path2.join(tmpDir, ".cdk")).trim();
326
- }
327
- function cdkCacheDir() {
328
- return path2.join(cdkHomeDir(), "cache");
329
- }
330
- function bundledPackageRootDir(start, fail) {
331
- function _rootDir(dirname2) {
332
- const manifestPath = path2.join(dirname2, "package.json");
333
- if (fs2.existsSync(manifestPath)) {
334
- return dirname2;
335
- }
336
- if (path2.dirname(dirname2) === dirname2) {
337
- if (fail ?? true) {
338
- throw new ToolkitError("Unable to find package manifest");
339
- }
340
- return void 0;
341
- }
342
- return _rootDir(path2.dirname(dirname2));
343
- }
344
- return _rootDir(start);
345
- }
346
-
347
- // lib/util/json.ts
348
- function getResultObj(jsonObject, identifier, propertiesToReturn) {
349
- const propsObj = {};
350
- propertiesToReturn.forEach((propName) => {
351
- Object.assign(propsObj, { [propName]: findJsonValue(jsonObject, propName) });
352
- });
353
- Object.assign(propsObj, { ["Identifier"]: identifier });
354
- return propsObj;
355
- }
356
- function findJsonValue(jsonObject, path4) {
357
- const paths = path4.split(".");
358
- let obj = jsonObject;
359
- paths.forEach((p) => {
360
- obj = obj[p];
361
- if (obj === void 0) {
362
- throw new TypeError(`Cannot read field ${path4}. ${p} is not found.`);
363
- }
364
- });
365
- return obj;
366
- }
367
-
368
- // lib/util/types.ts
369
- function isObject(x) {
370
- return x !== null && typeof x === "object" && !isArray(x);
371
- }
372
- var isArray = Array.isArray;
373
- function ifDefined(x, def) {
374
- return typeof x !== "undefined" ? x : def;
375
- }
376
-
377
- // lib/util/objects.ts
378
- function applyDefaults(hash, defaults) {
379
- const result = {};
380
- Object.keys(hash).forEach((k) => result[k] = hash[k]);
381
- Object.keys(defaults).filter((k) => !(k in result)).forEach((k) => result[k] = defaults[k]);
382
- return result;
383
- }
384
- function isEmpty(x) {
385
- if (x == null) {
386
- return false;
387
- }
388
- if (isArray(x)) {
389
- return x.length === 0;
390
- }
391
- return Object.keys(x).length === 0;
392
- }
393
- function deepClone(x) {
394
- if (typeof x === "undefined") {
395
- return void 0;
396
- }
397
- if (x === null) {
398
- return null;
399
- }
400
- if (isArray(x)) {
401
- return x.map(deepClone);
402
- }
403
- if (isObject(x)) {
404
- return makeObject(mapObject(x, (k, v) => [k, deepClone(v)]));
405
- }
406
- return x;
407
- }
408
- function mapObject(x, fn) {
409
- const ret = [];
410
- Object.keys(x).forEach((key) => {
411
- ret.push(fn(key, x[key]));
412
- });
413
- return ret;
414
- }
415
- function makeObject(pairs) {
416
- const ret = {};
417
- for (const pair of pairs) {
418
- ret[pair[0]] = pair[1];
419
- }
420
- return ret;
421
- }
422
- function deepGet(x, path4) {
423
- path4 = path4.slice();
424
- while (path4.length > 0 && isObject(x)) {
425
- const key = path4.shift();
426
- x = x[key];
427
- }
428
- return path4.length === 0 ? x : void 0;
429
- }
430
- function deepSet(x, path4, value) {
431
- path4 = path4.slice();
432
- if (path4.length === 0) {
433
- throw new ToolkitError("Path may not be empty");
434
- }
435
- while (path4.length > 1 && isObject(x)) {
436
- const key = path4.shift();
437
- if (isPrototypePollutingKey(key)) {
438
- continue;
439
- }
440
- if (!(key in x)) {
441
- x[key] = {};
442
- }
443
- x = x[key];
444
- }
445
- if (!isObject(x)) {
446
- throw new ToolkitError(`Expected an object, got '${x}'`);
447
- }
448
- const finalKey = path4[0];
449
- if (isPrototypePollutingKey(finalKey)) {
450
- return;
451
- }
452
- if (value !== void 0) {
453
- x[finalKey] = value;
454
- } else {
455
- delete x[finalKey];
456
- }
457
- }
458
- function isPrototypePollutingKey(key) {
459
- return key === "__proto__" || key === "constructor" || key === "prototype";
460
- }
461
- function deepMerge(...objects) {
462
- function mergeOne(target, source) {
463
- for (const key of Object.keys(source)) {
464
- if (isPrototypePollutingKey(key)) {
465
- continue;
466
- }
467
- const value = source[key];
468
- if (isObject(value)) {
469
- if (!isObject(target[key])) {
470
- target[key] = {};
471
- }
472
- mergeOne(target[key], value);
473
- } else if (typeof value !== "undefined") {
474
- target[key] = value;
475
- }
476
- }
477
- }
478
- const others = objects.filter((x) => x != null);
479
- if (others.length === 0) {
480
- return {};
481
- }
482
- const into = others.splice(0, 1)[0];
483
- others.forEach((other) => mergeOne(into, other));
484
- return into;
485
- }
486
- function splitBySize(data, maxSizeBytes) {
487
- if (maxSizeBytes < 2) {
488
- return [void 0, data];
489
- }
490
- const entries = Object.entries(data);
491
- return recurse(0, 0);
492
- function recurse(index, runningTotalSize) {
493
- if (index >= entries.length) {
494
- return [data, void 0];
495
- }
496
- const size = runningTotalSize + entrySize(entries[index]);
497
- return size > maxSizeBytes ? cutAt(index) : recurse(index + 1, size);
498
- }
499
- function entrySize(entry) {
500
- return Buffer.byteLength(JSON.stringify(Object.fromEntries([entry])));
501
- }
502
- function cutAt(index) {
503
- return [
504
- Object.fromEntries(entries.slice(0, index)),
505
- Object.fromEntries(entries.slice(index))
506
- ];
507
- }
508
- }
509
- function transformObjectKeys(val, transform, exclude = {}) {
510
- if (val == null || typeof val !== "object") {
511
- return val;
512
- }
513
- if (Array.isArray(val)) {
514
- return val.map((input) => transformObjectKeys(input, transform, exclude));
515
- }
516
- const ret = {};
517
- for (const [k, v] of Object.entries(val)) {
518
- const childExclude = exclude[k];
519
- if (childExclude === true) {
520
- ret[transform(k)] = v;
521
- } else {
522
- ret[transform(k)] = transformObjectKeys(v, transform, childExclude);
523
- }
524
- }
525
- return ret;
526
- }
527
-
528
- // lib/util/parallel.ts
529
- async function parallelPromises(n, promises) {
530
- const ret = new Array();
531
- let count = 0;
532
- let error2;
533
- const queue = [...promises];
534
- return new Promise((ok, ko) => {
535
- tick();
536
- function tick() {
537
- if (count === 0 && error2) {
538
- ko(error2);
539
- return;
540
- }
541
- if (count === 0 && queue.length === 0) {
542
- ok(ret);
543
- return;
544
- }
545
- while (count < n && queue.length > 0 && !error2) {
546
- const next = queue.shift();
547
- if (next !== void 0) {
548
- start(next);
549
- }
550
- }
551
- }
552
- function start(fn) {
553
- count += 1;
554
- fn().then((result) => {
555
- ret.push(result);
556
- }).catch((e) => {
557
- error2 = e;
558
- }).finally(() => {
559
- count -= 1;
560
- tick();
561
- });
562
- }
563
- });
564
- }
565
-
566
- // lib/util/package-info.ts
567
- var path3 = __toESM(require("path"));
568
- function displayVersion() {
569
- return `${versionNumber()} (build ${commit()})`;
570
- }
571
- function isDeveloperBuild() {
572
- return versionNumber() === "0.0.0";
573
- }
574
- function versionNumber() {
575
- return require(path3.join(bundledPackageRootDir(__dirname), "package.json")).version.replace(/\+[0-9a-f]+$/, "");
576
- }
577
- function commit() {
578
- return require(path3.join(bundledPackageRootDir(__dirname), "build-info.json")).commit;
579
- }
580
-
581
- // lib/util/serialize.ts
582
- var fs3 = __toESM(require("fs/promises"));
583
-
584
- // lib/util/yaml-cfn.ts
585
- var yaml = __toESM(require("yaml"));
586
- var yaml_types = __toESM(require("yaml/types"));
587
- function serialize(obj) {
588
- const oldFold = yaml_types.strOptions.fold.lineWidth;
589
- try {
590
- yaml_types.strOptions.fold.lineWidth = 0;
591
- return yaml.stringify(obj, { schema: "yaml-1.1" });
592
- } finally {
593
- yaml_types.strOptions.fold.lineWidth = oldFold;
594
- }
595
- }
596
- function deserialize(str) {
597
- return parseYamlStrWithCfnTags(str);
598
- }
599
- function makeTagForCfnIntrinsic(intrinsicName, addFnPrefix) {
600
- return {
601
- identify(value) {
602
- return typeof value === "string";
603
- },
604
- tag: `!${intrinsicName}`,
605
- resolve: (_doc, cstNode) => {
606
- const ret = {};
607
- ret[addFnPrefix ? `Fn::${intrinsicName}` : intrinsicName] = // the +1 is to account for the ! the short form begins with
608
- parseYamlStrWithCfnTags(cstNode.toString().substring(intrinsicName.length + 1));
609
- return ret;
610
- }
611
- };
612
- }
613
- var shortForms = [
614
- "Base64",
615
- "Cidr",
616
- "FindInMap",
617
- "GetAZs",
618
- "ImportValue",
619
- "Join",
620
- "Sub",
621
- "Select",
622
- "Split",
623
- "Transform",
624
- "And",
625
- "Equals",
626
- "If",
627
- "Not",
628
- "Or",
629
- "GetAtt"
630
- ].map((name) => makeTagForCfnIntrinsic(name, true)).concat(
631
- makeTagForCfnIntrinsic("Ref", false),
632
- makeTagForCfnIntrinsic("Condition", false)
633
- );
634
- function parseYamlStrWithCfnTags(text) {
635
- return yaml.parse(text, {
636
- customTags: shortForms,
637
- schema: "core"
638
- });
639
- }
640
-
641
- // lib/util/serialize.ts
642
- function toYAML(obj) {
643
- return serialize(obj);
644
- }
645
- function deserializeStructure(str) {
646
- return deserialize(str);
647
- }
648
- function serializeStructure(object, json) {
649
- if (json) {
650
- return JSON.stringify(object, void 0, 2);
651
- } else {
652
- return toYAML(object);
653
- }
654
- }
655
- async function loadStructuredFile(fileName) {
656
- const contents = await fs3.readFile(fileName, { encoding: "utf-8" });
657
- return deserializeStructure(contents);
658
- }
659
- function obscureTemplate(template = {}) {
660
- if (template.Rules) {
661
- if (template.Rules.CheckBootstrapVersion) {
662
- if (Object.keys(template.Rules).length > 1) {
663
- delete template.Rules.CheckBootstrapVersion;
664
- } else {
665
- delete template.Rules;
666
- }
667
- }
668
- }
669
- return template;
670
- }
671
- function isJsonBuffer(value) {
672
- return typeof value === "object" && "type" in value && value.type === "Buffer" && "data" in value && Array.isArray(value.data);
673
- }
674
- function replacerBufferWithInfo(_key, value) {
675
- if (isJsonBuffer(value)) {
676
- return `<Buffer: ${formatBytes(value.data.length)}>`;
677
- }
678
- return value;
679
- }
680
-
681
- // lib/util/string-manipulation.ts
682
- function padLeft(n, x, char = " ") {
683
- return char.repeat(Math.max(0, n - x.length)) + x;
684
- }
685
- function padRight(n, x, char = " ") {
686
- return x + char.repeat(Math.max(0, n - x.length));
687
- }
688
- function formatTime(num) {
689
- return roundPercentage(millisecondsToSeconds(num));
690
- }
691
- function roundPercentage(num) {
692
- return Math.round(100 * num) / 100;
693
- }
694
- function millisecondsToSeconds(num) {
695
- return num / 1e3;
696
- }
697
- function lowerCaseFirstCharacter(str) {
698
- return str.length > 0 ? `${str[0].toLowerCase()}${str.slice(1)}` : str;
699
- }
700
-
701
- // lib/util/type-brands.ts
702
- function createBranded(value) {
703
- return value;
704
- }
705
-
706
- // lib/util/version-range.ts
707
- var semver = __toESM(require("semver"));
708
- function rangeFromSemver(ver, targetType) {
709
- const re = ver.match(/^([^\d]*)([\d.]*)$/);
710
- if (!re || !semver.valid(re[2])) {
711
- throw new ToolkitError("not a semver or unsupported range syntax");
712
- }
713
- const prefixPart = re[1];
714
- const verPart = re[2];
715
- switch (targetType) {
716
- case "bracket":
717
- switch (prefixPart) {
718
- case "":
719
- return ver;
720
- case "^":
721
- return `[${verPart},${semver.major(verPart) + 1}.0.0)`;
722
- default:
723
- throw new ToolkitError(`unsupported range syntax - ${prefixPart}`);
724
- }
725
- case "pep":
726
- switch (prefixPart) {
727
- case "":
728
- return `==${ver}`;
729
- case "^":
730
- return `>=${verPart},<${semver.major(verPart) + 1}.0.0`;
731
- default:
732
- throw new ToolkitError(`unsupported range syntax - ${prefixPart}`);
733
- }
734
- }
735
- }
736
- // Annotate the CommonJS export names for ESM import in node:
737
- 0 && (module.exports = {
738
- applyDefaults,
739
- bundledPackageRootDir,
740
- cdkCacheDir,
741
- cdkHomeDir,
742
- contentHash,
743
- contentHashAny,
744
- createBranded,
745
- deepClone,
746
- deepGet,
747
- deepMerge,
748
- deepSet,
749
- deserialize,
750
- deserializeStructure,
751
- displayVersion,
752
- findJsonValue,
753
- flatMap,
754
- flatten,
755
- formatBytes,
756
- formatErrorMessage,
757
- formatTime,
758
- getResultObj,
759
- ifDefined,
760
- isArray,
761
- isDeveloperBuild,
762
- isEmpty,
763
- isObject,
764
- loadStructuredFile,
765
- lowerCaseFirstCharacter,
766
- makeObject,
767
- mapObject,
768
- maxResourceTypeLength,
769
- numberFromBool,
770
- obscureTemplate,
771
- padLeft,
772
- padRight,
773
- parallelPromises,
774
- partition,
775
- rangeFromSemver,
776
- replacerBufferWithInfo,
777
- serialize,
778
- serializeStructure,
779
- splitBySize,
780
- stackEventHasErrorMessage,
781
- toYAML,
782
- transformObjectKeys,
783
- validateSnsTopicArn,
784
- versionNumber,
785
- zipDirectory
786
- });
787
- //# sourceMappingURL=util.js.map