sst 2.23.14 → 2.24.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.
@@ -1,194 +0,0 @@
1
- import { DockerFactory } from "./private/docker.js";
2
- import { makeAssetHandler } from "./private/handlers/index.js";
3
- import { EventType, } from "cdk-assets/lib/progress.js";
4
- export class AssetPublishing {
5
- manifest;
6
- options;
7
- /**
8
- * The message for the IPublishProgress interface
9
- */
10
- message = "Starting";
11
- /**
12
- * The current asset for the IPublishProgress interface
13
- */
14
- currentAsset;
15
- failures = new Array();
16
- assets;
17
- totalOperations;
18
- completedOperations = 0;
19
- aborted = false;
20
- handlerHost;
21
- publishInParallel;
22
- buildAssets;
23
- publishAssets;
24
- handlerCache = new Map();
25
- constructor(manifest, options) {
26
- this.manifest = manifest;
27
- this.options = options;
28
- this.assets = manifest.entries;
29
- this.totalOperations = this.assets.length;
30
- this.publishInParallel = options.publishInParallel ?? false;
31
- this.buildAssets = options.buildAssets ?? true;
32
- this.publishAssets = options.publishAssets ?? true;
33
- const self = this;
34
- this.handlerHost = {
35
- aws: this.options.aws,
36
- get aborted() {
37
- return self.aborted;
38
- },
39
- emitMessage(t, m) {
40
- self.progressEvent(t, m);
41
- },
42
- dockerFactory: new DockerFactory(),
43
- };
44
- }
45
- /**
46
- * Publish all assets from the manifest
47
- */
48
- async publish() {
49
- if (this.publishInParallel) {
50
- await Promise.all(this.assets.map(async (asset) => this.publishAsset(asset)));
51
- }
52
- else {
53
- for (const asset of this.assets) {
54
- if (!(await this.publishAsset(asset))) {
55
- break;
56
- }
57
- }
58
- }
59
- if ((this.options.throwOnError ?? true) && this.failures.length > 0) {
60
- throw new Error(`Error publishing: ${this.failures.map((e) => e.error.message)}`);
61
- }
62
- }
63
- /**
64
- * Build a single asset from the manifest
65
- */
66
- async buildEntry(asset) {
67
- try {
68
- if (this.progressEvent(EventType.START, `Building ${asset.id}`)) {
69
- return false;
70
- }
71
- const handler = this.assetHandler(asset);
72
- await handler.build();
73
- if (this.aborted) {
74
- throw new Error("Aborted");
75
- }
76
- this.completedOperations++;
77
- if (this.progressEvent(EventType.SUCCESS, `Built ${asset.id}`)) {
78
- return false;
79
- }
80
- }
81
- catch (e) {
82
- this.failures.push({ asset, error: e });
83
- this.completedOperations++;
84
- if (this.progressEvent(EventType.FAIL, e.message)) {
85
- return false;
86
- }
87
- }
88
- return true;
89
- }
90
- /**
91
- * Publish a single asset from the manifest
92
- */
93
- async publishEntry(asset) {
94
- try {
95
- if (this.progressEvent(EventType.START, `Publishing ${asset.id}`)) {
96
- return false;
97
- }
98
- const handler = this.assetHandler(asset);
99
- await handler.publish();
100
- if (this.aborted) {
101
- throw new Error("Aborted");
102
- }
103
- this.completedOperations++;
104
- if (this.progressEvent(EventType.SUCCESS, `Published ${asset.id}`)) {
105
- return false;
106
- }
107
- }
108
- catch (e) {
109
- this.failures.push({ asset, error: e });
110
- this.completedOperations++;
111
- if (this.progressEvent(EventType.FAIL, e.message)) {
112
- return false;
113
- }
114
- }
115
- return true;
116
- }
117
- /**
118
- * Return whether a single asset is published
119
- */
120
- isEntryPublished(asset) {
121
- const handler = this.assetHandler(asset);
122
- return handler.isPublished();
123
- }
124
- /**
125
- * publish an asset (used by 'publish()')
126
- * @param asset The asset to publish
127
- * @returns false when publishing should stop
128
- */
129
- async publishAsset(asset) {
130
- try {
131
- if (this.progressEvent(EventType.START, `Publishing ${asset.id}`)) {
132
- return false;
133
- }
134
- const handler = this.assetHandler(asset);
135
- if (this.buildAssets) {
136
- await handler.build();
137
- }
138
- if (this.publishAssets) {
139
- await handler.publish();
140
- }
141
- if (this.aborted) {
142
- throw new Error("Aborted");
143
- }
144
- this.completedOperations++;
145
- if (this.progressEvent(EventType.SUCCESS, `Published ${asset.id}`)) {
146
- return false;
147
- }
148
- }
149
- catch (e) {
150
- this.failures.push({ asset, error: e });
151
- this.completedOperations++;
152
- if (this.progressEvent(EventType.FAIL, e.message)) {
153
- return false;
154
- }
155
- }
156
- return true;
157
- }
158
- get percentComplete() {
159
- if (this.totalOperations === 0) {
160
- return 100;
161
- }
162
- return Math.floor((this.completedOperations / this.totalOperations) * 100);
163
- }
164
- abort() {
165
- this.aborted = true;
166
- }
167
- get hasFailures() {
168
- return this.failures.length > 0;
169
- }
170
- /**
171
- * Publish a progress event to the listener, if present.
172
- *
173
- * Returns whether an abort is requested. Helper to get rid of repetitive code in publish().
174
- */
175
- progressEvent(event, message) {
176
- this.message = message;
177
- if (this.options.progressListener) {
178
- this.options.progressListener.onPublishEvent(event, this);
179
- }
180
- return this.aborted;
181
- }
182
- assetHandler(asset) {
183
- const existing = this.handlerCache.get(asset);
184
- if (existing) {
185
- return existing;
186
- }
187
- const ret = makeAssetHandler(this.manifest, asset, this.handlerHost, {
188
- // TODO: remove after PR is merged
189
- quiet: this.options.quiet,
190
- });
191
- this.handlerCache.set(asset, ret);
192
- return ret;
193
- }
194
- }