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