@_linked/s3 1.0.3 → 1.1.1

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.
@@ -0,0 +1,18 @@
1
+ name: PR
2
+
3
+ on:
4
+ pull_request:
5
+ branches:
6
+ - main
7
+
8
+ jobs:
9
+ checks:
10
+ uses: linked-fw/.github/.github/workflows/pr.yml@v1
11
+ # The changeset reminder posts a PR comment. A reusable workflow only holds what its
12
+ # caller granted, and the org default is read-only.
13
+ permissions:
14
+ contents: read
15
+ pull-requests: write
16
+ with:
17
+ require-tests: false
18
+ run-e2e: false
@@ -1,3 +1,8 @@
1
+ # Calls the shared workflow in linked-fw/.github.
2
+ #
3
+ # This FILENAME is what npm's trusted-publisher check validates — not the shared workflow's.
4
+ # Renaming this file invalidates this package's trusted publisher, and the only symptom is
5
+ # that releases quietly start needing manual approval again.
1
6
  name: Publish
2
7
 
3
8
  on:
@@ -9,46 +14,17 @@ concurrency: ${{ github.workflow }}-${{ github.ref }}
9
14
 
10
15
  jobs:
11
16
  release:
12
- name: Publish Release
13
- runs-on: ubuntu-latest
17
+ uses: linked-fw/.github/.github/workflows/publish.yml@v1
14
18
  permissions:
15
19
  contents: write
16
20
  pull-requests: write
17
- steps:
18
- # Author the changesets "Version Packages" PR as the org release App (not the default
19
- # GITHUB_TOKEN) so its CI runs without a manual "Approve and run" gate. Requires the org
20
- # App installed on this repo + org secrets RELEASE_APP_ID / RELEASE_APP_PRIVATE_KEY.
21
- - name: Generate GitHub App token
22
- id: app-token
23
- uses: actions/create-github-app-token@v2
24
- with:
25
- app-id: ${{ secrets.RELEASE_APP_ID }}
26
- private-key: ${{ secrets.RELEASE_APP_PRIVATE_KEY }}
27
-
28
- - name: Checkout
29
- uses: actions/checkout@v4
30
- with:
31
- token: ${{ steps.app-token.outputs.token }}
32
-
33
- - name: Setup Node.js
34
- uses: actions/setup-node@v4
35
- with:
36
- node-version: 22.16.0
37
- registry-url: 'https://registry.npmjs.org'
38
-
39
- - name: Install dependencies
40
- run: npm ci --legacy-peer-deps
41
-
42
- - name: Build
43
- run: npm run build
44
-
45
- - name: Create release Pull Request or Publish
46
- uses: changesets/action@v1
47
- with:
48
- publish: npx changeset publish
49
- title: 'chore: release'
50
- commit: 'chore: release'
51
- env:
52
- GITHUB_TOKEN: ${{ steps.app-token.outputs.token }}
53
- NODE_AUTH_TOKEN: ${{ secrets.NPM_AUTH_TOKEN }}
54
- NPM_TOKEN: ${{ secrets.NPM_AUTH_TOKEN }}
21
+ # Needed HERE as well as in the shared workflow: a reusable workflow cannot widen the
22
+ # permissions its caller was granted, and without this npm never gets an id-token and
23
+ # every release silently falls back to the approval queue.
24
+ id-token: write
25
+ # Named rather than `inherit`: `inherit` forwards everything this repo can see, which is
26
+ # how a community repo would end up forwarding a first-party token.
27
+ secrets:
28
+ NPM_TOKEN: ${{ secrets.NPM_AUTH_TOKEN }}
29
+ RELEASE_APP_ID: ${{ secrets.RELEASE_APP_ID }}
30
+ RELEASE_APP_PRIVATE_KEY: ${{ secrets.RELEASE_APP_PRIVATE_KEY }}
package/CHANGELOG.md CHANGED
@@ -1,5 +1,17 @@
1
1
  # @\_linked/s3
2
2
 
3
+ ## 1.1.1
4
+
5
+ ### Patch Changes
6
+
7
+ - [#12](https://github.com/linked-fw/s3/pull/12) [`9b5150c`](https://github.com/linked-fw/s3/commit/9b5150c57b87609ed6f456fd9fa80b60dbb76d66) Thanks [@flyon](https://github.com/flyon)! - Point `repository.url` at the linked-fw organisation, so npm provenance verification matches the repository that builds the package.
8
+
9
+ ## 1.1.0
10
+
11
+ ### Minor Changes
12
+
13
+ - [`cb74e4c`](https://github.com/linked-cm/s3/commit/cb74e4c8e7bd4055b58e568b57aa74886a02b6cd) - ESM-only. Dropped the CommonJS build; ships ES modules only (`type: module`, no `require` export condition, no `lib/cjs`). Fixed the root `types` field. CJS consumers on Node 22+ can `require()` it (sync ESM) or use dynamic `import()`.
14
+
3
15
  ## 1.0.3
4
16
 
5
17
  ### Patch Changes
@@ -0,0 +1,2 @@
1
+ //import your providers here (providers only run in the backend)
2
+ //# sourceMappingURL=backend.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"backend.js","sourceRoot":"","sources":["../../src/backend.ts"],"names":[],"mappings":"AAAA,gEAAgE"}
@@ -0,0 +1,12 @@
1
+ import './types.js';
2
+ import './ontologies/s3.js';
3
+ //SHAPES FIRST
4
+ import './shapes/S3Bucket.js';
5
+ import './shapes/S3FileStore.js';
6
+ // Old quad-store patterns — depend on N3FileStore/BackendStore (in modules_old)
7
+ // import './shapes/S3FrontendStore.js';
8
+ // import './shapes/S3FrontendStoreProvider.js';
9
+ // import './shapes/S3QuadStore.js';
10
+ //THEN COMPONENTS
11
+ import './utils/accessUrl.js';
12
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,YAAY,CAAC;AACpB,OAAO,oBAAoB,CAAC;AAE5B,cAAc;AACd,OAAO,sBAAsB,CAAC;AAC9B,OAAO,yBAAyB,CAAC;AACjC,gFAAgF;AAChF,wCAAwC;AACxC,gDAAgD;AAChD,oCAAoC;AAEpC,iBAAiB;AACjB,OAAO,sBAAsB,CAAC"}
@@ -16,23 +16,23 @@ export declare var loadData: () => Promise<{
16
16
  "rdfs:label": string;
17
17
  }[];
18
18
  }>;
19
- export declare var ns: (term: string) => import("@_linked/core/utils/NodeReference.js").NodeReferenceValue;
20
- export declare var _self: import("@_linked/core/utils/NodeReference.js").NodeReferenceValue;
21
- export declare var Bucket: import("@_linked/core/utils/NodeReference.js").NodeReferenceValue;
22
- export declare var FileStore: import("@_linked/core/utils/NodeReference.js").NodeReferenceValue;
23
- export declare var FrontendStore: import("@_linked/core/utils/NodeReference.js").NodeReferenceValue;
24
- export declare var QuadStore: import("@_linked/core/utils/NodeReference.js").NodeReferenceValue;
25
- export declare var bucket: import("@_linked/core/utils/NodeReference.js").NodeReferenceValue;
26
- export declare var endpoint: import("@_linked/core/utils/NodeReference.js").NodeReferenceValue;
27
- export declare var key: import("@_linked/core/utils/NodeReference.js").NodeReferenceValue;
28
- export declare var secret: import("@_linked/core/utils/NodeReference.js").NodeReferenceValue;
19
+ export declare var ns: (term: string) => import("@_linked/core/utils/NodeReference").NodeReferenceValue;
20
+ export declare var _self: import("@_linked/core/utils/NodeReference").NodeReferenceValue;
21
+ export declare var Bucket: import("@_linked/core/utils/NodeReference").NodeReferenceValue;
22
+ export declare var FileStore: import("@_linked/core/utils/NodeReference").NodeReferenceValue;
23
+ export declare var FrontendStore: import("@_linked/core/utils/NodeReference").NodeReferenceValue;
24
+ export declare var QuadStore: import("@_linked/core/utils/NodeReference").NodeReferenceValue;
25
+ export declare var bucket: import("@_linked/core/utils/NodeReference").NodeReferenceValue;
26
+ export declare var endpoint: import("@_linked/core/utils/NodeReference").NodeReferenceValue;
27
+ export declare var key: import("@_linked/core/utils/NodeReference").NodeReferenceValue;
28
+ export declare var secret: import("@_linked/core/utils/NodeReference").NodeReferenceValue;
29
29
  export declare const s3: {
30
- Bucket: import("@_linked/core/utils/NodeReference.js").NodeReferenceValue;
31
- FileStore: import("@_linked/core/utils/NodeReference.js").NodeReferenceValue;
32
- FrontendStore: import("@_linked/core/utils/NodeReference.js").NodeReferenceValue;
33
- QuadStore: import("@_linked/core/utils/NodeReference.js").NodeReferenceValue;
34
- bucket: import("@_linked/core/utils/NodeReference.js").NodeReferenceValue;
35
- endpoint: import("@_linked/core/utils/NodeReference.js").NodeReferenceValue;
36
- key: import("@_linked/core/utils/NodeReference.js").NodeReferenceValue;
37
- secret: import("@_linked/core/utils/NodeReference.js").NodeReferenceValue;
30
+ Bucket: import("@_linked/core/utils/NodeReference").NodeReferenceValue;
31
+ FileStore: import("@_linked/core/utils/NodeReference").NodeReferenceValue;
32
+ FrontendStore: import("@_linked/core/utils/NodeReference").NodeReferenceValue;
33
+ QuadStore: import("@_linked/core/utils/NodeReference").NodeReferenceValue;
34
+ bucket: import("@_linked/core/utils/NodeReference").NodeReferenceValue;
35
+ endpoint: import("@_linked/core/utils/NodeReference").NodeReferenceValue;
36
+ key: import("@_linked/core/utils/NodeReference").NodeReferenceValue;
37
+ secret: import("@_linked/core/utils/NodeReference").NodeReferenceValue;
38
38
  };
@@ -0,0 +1,35 @@
1
+ import { createNameSpace } from '@_linked/core/utils/NameSpace';
2
+ import { linkedOntology } from '../package.js';
3
+ import * as _this from './s3.js';
4
+ export var loadData = () => {
5
+ //@ts-ignore
6
+ return import('../data/s3.json', { with: { type: 'json' } }).then((data) => data.default);
7
+ };
8
+ export var ns = createNameSpace('http://lincd.org/ont/s3/');
9
+ export var _self = ns('');
10
+ // Classes
11
+ export var Bucket = ns('Bucket');
12
+ export var FileStore = ns('FileStore');
13
+ export var FrontendStore = ns('FrontendStore');
14
+ export var QuadStore = ns('QuadStore');
15
+ // Properties
16
+ export var bucket = ns('bucket');
17
+ export var endpoint = ns('endpoint');
18
+ export var key = ns('key');
19
+ export var secret = ns('secret');
20
+ //An extra grouping object so all the entities can be accessed from the prefix/name
21
+ export const s3 = {
22
+ // Classes
23
+ Bucket,
24
+ FileStore,
25
+ FrontendStore,
26
+ QuadStore,
27
+ // Properties
28
+ bucket,
29
+ endpoint,
30
+ key,
31
+ secret,
32
+ };
33
+ //Registers this ontology to LINCD.JS, so that data loading can be automated amongst other things
34
+ linkedOntology(_this, ns, 's3', loadData, '../data/s3.json');
35
+ //# sourceMappingURL=s3.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"s3.js","sourceRoot":"","sources":["../../../src/ontologies/s3.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,+BAA+B,CAAC;AAChE,OAAO,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAC/C,OAAO,KAAK,KAAK,MAAM,SAAS,CAAC;AAEjC,MAAM,CAAC,IAAI,QAAQ,GAAG,GAAG,EAAE;IACzB,YAAY;IACZ,OAAO,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Util, linkedOntology, registerPackageExport, packageExports, packageName, } = linkedPackage('@_linked/s3');
3
+ //# sourceMappingURL=package.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"package.js","sourceRoot":"","sources":["../../src/package.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,6BAA6B,CAAC;AAE5D,MAAM,CAAC,MAAM,EACX,WAAW,EACX,UAAU,EACV,cAAc,EACd,qBAAqB,EACrB,cAAc,EACd,WAAW,GACZ,GAAG,aAAa,CAAC,aAAa,CAAC,CAAC"}
@@ -20,7 +20,7 @@ export declare const createS3Client: (config?: S3ClientConfigInput) => S3Client;
20
20
  */
21
21
  export declare const s3Client: S3Client;
22
22
  export declare class S3Bucket extends Shape {
23
- static targetClass: import("@_linked/core/utils/NodeReference.js").NodeReferenceValue;
23
+ static targetClass: import("@_linked/core/utils/NodeReference").NodeReferenceValue;
24
24
  protected _client: S3Client;
25
25
  label: string;
26
26
  private ensureKeyPromise;
@@ -0,0 +1,277 @@
1
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
2
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
5
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
6
+ };
7
+ var __metadata = (this && this.__metadata) || function (k, v) {
8
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
9
+ };
10
+ import { CopyObjectCommand, CreateBucketCommand, DeleteObjectCommand, GetObjectCommand, HeadObjectCommand, ListObjectsCommand, PutObjectCommand, S3Client, } from '@aws-sdk/client-s3';
11
+ import { Shape } from '@_linked/core/shapes/Shape';
12
+ import { s3 } from '../ontologies/s3.js';
13
+ import { linkedShape } from '../package.js';
14
+ export const endpoint = process.env.S3_BUCKET_ENDPOINT;
15
+ /**
16
+ * Builds an S3 client from explicit config, falling back to legacy env vars.
17
+ * This enables multiple S3 stores in one process with independent credentials/endpoints.
18
+ */
19
+ export const createS3Client = (config = {}) => {
20
+ var _a, _b, _c, _d, _e;
21
+ return new S3Client({
22
+ endpoint: (_a = config.endpoint) !== null && _a !== void 0 ? _a : process.env.S3_BUCKET_ENDPOINT,
23
+ // https://github.com/aws/aws-sdk-js-v3/issues/3392#issuecomment-1120027821
24
+ credentials: {
25
+ accessKeyId: (_b = config.accessKeyId) !== null && _b !== void 0 ? _b : process.env.AWS_ACCESS_KEY_ID,
26
+ secretAccessKey: (_c = config.secretAccessKey) !== null && _c !== void 0 ? _c : process.env.AWS_SECRET_ACCESS_KEY,
27
+ },
28
+ region: (_e = (_d = config.region) !== null && _d !== void 0 ? _d : process.env.AWS_REGION) !== null && _e !== void 0 ? _e : 'us-east-1',
29
+ });
30
+ };
31
+ /**
32
+ * Legacy singleton exported for backward compatibility. New code should prefer
33
+ * per-instance clients by passing config into S3Bucket/S3FileStore.
34
+ */
35
+ export const s3Client = createS3Client();
36
+ let S3Bucket = class S3Bucket extends Shape {
37
+ constructor(n, clientConfig) {
38
+ super(typeof n === 'string' ? null : n);
39
+ this.ensureKeyPromise = new Map();
40
+ if (typeof n === 'string') {
41
+ this.label = n;
42
+ }
43
+ this._client = createS3Client(clientConfig);
44
+ }
45
+ get endpoint() {
46
+ return this._client.config.endpoint.toString();
47
+ }
48
+ /**
49
+ * Delete an object from the bucket.
50
+ * @param key The key of the object to delete
51
+ * @param options Additional options to pass to the DeleteObjectCommand
52
+ * @returns The response from the DeleteObjectCommand
53
+ * @todo Batch delete, see https://docs.aws.amazon.com/AmazonS3/latest/API/API_DeleteObjects.html
54
+ */
55
+ async deleteObject(key, options) {
56
+ let bucketParams = {
57
+ Bucket: this.label,
58
+ Key: key,
59
+ ...options,
60
+ };
61
+ try {
62
+ const data = await this._client.send(new DeleteObjectCommand(bucketParams));
63
+ // console.log('Successfully deleted object ' + key);
64
+ return data;
65
+ }
66
+ catch (err) {
67
+ console.log('Could not delete object: ', err);
68
+ }
69
+ }
70
+ async copyObject(sourceKey, destinationKey, options) {
71
+ let bucketParams = {
72
+ Bucket: this.label,
73
+ Key: destinationKey,
74
+ CopySource: `${this.label}/${sourceKey}`,
75
+ ...options,
76
+ };
77
+ try {
78
+ const data = await this._client.send(new CopyObjectCommand(bucketParams));
79
+ // console.log('Successfully copied object ' + sourceKey + ' to ' + destinationKey);
80
+ return data.$metadata.httpStatusCode === 200;
81
+ }
82
+ catch (err) {
83
+ console.log('Could not copy object: ', err);
84
+ }
85
+ }
86
+ /**
87
+ * Put an object into the bucket.
88
+ *
89
+ * @param key The key of the object to PUT (i.e. file name)
90
+ * @param value The value of the object to PUT (i.e. file contents)
91
+ * @param options Additional options to pass to the PutObjectCommand
92
+ * @returns The response from the PutObjectCommand
93
+ */
94
+ async putObject(key, value, options) {
95
+ let bucketParams = {
96
+ Bucket: this.label,
97
+ Key: key,
98
+ Body: value,
99
+ ACL: 'public-read',
100
+ ...options,
101
+ };
102
+ try {
103
+ const data = await this._client.send(new PutObjectCommand(bucketParams));
104
+ // console.log(
105
+ // 'Successfully uploaded object: ' +
106
+ // bucketParams.Bucket +
107
+ // '/' +
108
+ // bucketParams.Key,
109
+ // );
110
+ return data;
111
+ }
112
+ catch (err) {
113
+ console.log('Error', err);
114
+ }
115
+ return null;
116
+ }
117
+ /**
118
+ * Get a list of all object keys in the bucket.
119
+ * Important to note that only a maximum 1000 keys will be returned.
120
+ *
121
+ * @param prefix The prefix to search for in the bucket. This can be a folder or the beginning of a file name.
122
+ * @returns A list of all object keys in the bucket
123
+ * @todo Recursive search within directories
124
+ * @todo Implement pagination
125
+ */
126
+ async getAllObjectKeys(prefix = '') {
127
+ var _a;
128
+ let bucketParams = {
129
+ Bucket: this.label,
130
+ Prefix: prefix,
131
+ };
132
+ try {
133
+ const data = await this._client.send(new ListObjectsCommand(bucketParams));
134
+ return ((_a = data.Contents) === null || _a === void 0 ? void 0 : _a.map((object) => object.Key)) || [];
135
+ }
136
+ catch (err) {
137
+ console.log('Could not list bucket contents: ', err);
138
+ return Promise.reject(err);
139
+ }
140
+ }
141
+ /**
142
+ * Get the contents of an object in the bucket.
143
+ * @param key The key of the object to get
144
+ * @returns The contents of the object as a string
145
+ */
146
+ async getObject(key) {
147
+ let bucketParams = {
148
+ Bucket: this.label,
149
+ Key: key,
150
+ };
151
+ return new Promise(async (resolve, reject) => {
152
+ const getObjectCommand = new GetObjectCommand(bucketParams);
153
+ try {
154
+ const response = await this._client.send(getObjectCommand);
155
+ // let objectData = response.Body.toString();
156
+ // resolve(objectData);
157
+ //for future usecases: use this to stream data or use binary data,
158
+ // see https://stackoverflow.com/questions/36942442/how-to-get-response-from-s3-getobject-in-node-js
159
+ // // Store all of data chunks returned from the response data stream
160
+ // // into an array then use Array#join() to use the returned contents as a String
161
+ let responseDataChunks = [];
162
+ // let body:ReadableStream = response.Body as ReadableStream;
163
+ let body = response.Body;
164
+ // Handle an error while streaming the response body
165
+ body.once('error', (err) => reject(err));
166
+ // Attach a 'data' listener to add the chunks of data to our array
167
+ // Each chunk is a Buffer instance
168
+ body.on('data', (chunk) => responseDataChunks.push(chunk));
169
+ // Once the stream has no more data, join the chunks into a string and return the string
170
+ body.once('end', () => resolve(responseDataChunks.join('')));
171
+ }
172
+ catch (err) {
173
+ // Handle the error or throw
174
+ return reject(err);
175
+ }
176
+ });
177
+ }
178
+ /**
179
+ * Ensure that the given key exists in the bucket, the file contents
180
+ * will be an empty json object.
181
+ *
182
+ * @param key The key to insert if it does not exist
183
+ * @returns The promise that will resolve when the key exists
184
+ */
185
+ async ensureKeyExists(key) {
186
+ if (!this.ensureKeyPromise.has(key)) {
187
+ let promise = this._ensureKeyExists(key);
188
+ this.ensureKeyPromise.set(key, promise);
189
+ }
190
+ return this.ensureKeyPromise.get(key);
191
+ }
192
+ async _ensureKeyExists(key) {
193
+ let bucketParams = {
194
+ Bucket: this.label,
195
+ Key: key,
196
+ };
197
+ return new Promise(async (resolve, reject) => {
198
+ //see if the object already exists
199
+ try {
200
+ await this._client.send(new HeadObjectCommand(bucketParams));
201
+ resolve();
202
+ }
203
+ catch (error) {
204
+ if (error.name === 'NotFound') {
205
+ // Note with v3 AWS-SDK use error.code
206
+ //If the object does not exist, create it,
207
+ // with the content being an empty json object
208
+ try {
209
+ await this._client.send(new PutObjectCommand({
210
+ ...bucketParams,
211
+ Body: JSON.stringify({}),
212
+ }));
213
+ // console.log(
214
+ // `Successfully created object "${bucketParams.Key}" in bucket ${bucketParams.Bucket}`,
215
+ // );
216
+ resolve();
217
+ }
218
+ catch (err) {
219
+ if (err.name === 'NoSuchBucket') {
220
+ await this.createBucket();
221
+ await this._ensureKeyExists(key);
222
+ resolve();
223
+ }
224
+ reject('Error putting object: ' + err);
225
+ }
226
+ }
227
+ else {
228
+ reject('Error checking existence of object: ' + error);
229
+ }
230
+ }
231
+ });
232
+ }
233
+ async keyExists(key) {
234
+ let bucketParams = {
235
+ Bucket: this.label,
236
+ Key: key,
237
+ };
238
+ return new Promise(async (resolve, reject) => {
239
+ //see if the object already exists
240
+ try {
241
+ await this._client.send(new HeadObjectCommand(bucketParams));
242
+ resolve(true);
243
+ }
244
+ catch (error) {
245
+ if (error.name === 'NotFound') {
246
+ return false;
247
+ }
248
+ else {
249
+ console.warn('Error checking existence of object: ' + error);
250
+ return false;
251
+ }
252
+ }
253
+ });
254
+ }
255
+ /**
256
+ * Create the bucket if it does not exist.
257
+ * @returns The promise that will resolve when the bucket exists
258
+ */
259
+ async createBucket() {
260
+ let bucketParams = { Bucket: this.label };
261
+ try {
262
+ const data = await this._client.send(new CreateBucketCommand(bucketParams));
263
+ console.log('Successfully created bucket ' + this.label);
264
+ return data; // For unit tests.
265
+ }
266
+ catch (err) {
267
+ console.log('Could not create bucket: ', err);
268
+ }
269
+ }
270
+ };
271
+ S3Bucket.targetClass = s3.Bucket;
272
+ S3Bucket = __decorate([
273
+ linkedShape,
274
+ __metadata("design:paramtypes", [Object, Object])
275
+ ], S3Bucket);
276
+ export { S3Bucket };
277
+ //# sourceMappingURL=S3Bucket.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"S3Bucket.js","sourceRoot":"","sources":["../../../src/shapes/S3Bucket.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,EACL,iBAAiB,EAEjB,mBAAmB,EACnB,mBAAmB,EAEnB,gBAAgB,EAEhB,iBAAiB,EAEjB,kBAAkB,EAClB,gBAAgB,EAChB,QAAQ,GACT,MAAM,oBAAoB,CAAC;AAM5B,OAAO,EAAE,KAAK,EAAE,MAAM,4BAA4B,CAAC;AACnD,OAAO,EAAE,EAAE,EAAE,MAAM,qBAAqB,CAAC;AACzC,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAU5C,MAAM,CAAC,MAAM,QAAQ,GAAW,OAAO,CAAC,GAAG,CAAC,kBAAkB,CAAC;AAE/D;;;GAGG;AACH,MAAM,CAAC,MAAM,cAAc,GAAG,CAAC,SAA8B,EAAE,EAAE,EAAE;;IACjE,OAAA,IAAI,QAAQ,CAAC;QACX,QAAQ,EAAE,MAAA,MAAM,CAAC,QAAQ,mCAAI,OAAO,CAAC,GAAG,CAAC,kBAAkB;QAC3D,2EAA2E;QAC3E,WAAW,EAAE;YACX,WAAW,EAAE,MAAA,MAAM,CAAC,WAAW,mCAAI,OAAO,CAAC,GAAG,CAAC,iBAAiB;YAChE,eAAe,EACb,MAAA,MAAM,CAAC,eAAe,mCAAI,OAAO,CAAC,GAAG,CAAC,qBAAqB;SAC9D;QACD,MAAM,EAAE,MAAA,MAAA,MAAM,CAAC,MAAM,mCAAI,OAAO,CAAC,GAAG,CAAC,UAAU,mCAAI,WAAW;KAC/D,CAAC,CAAA;CAAA,CAAC;AAEL;;;GAGG;AACH,MAAM,CAAC,MAAM,QAAQ,GAAG,cAAc,EAAE,CA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AC,CAAC,CAAC;IACL,CAAC;IAED;;;OAGG;IACH,KAAK,CAAC,YAAY;QAChB,IAAI,YAAY,GAAG,EAAE,MAAM,EAAE,IAAI,CAAC,KAAK,EAAE,CAAC;QAC1C,IAAI,CAAC;YACH,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC,OAAO,CAAC,IAAI,CAClC,IAAI,mBAAmB,CAAC,YAAY,CAAC,CACtC,CAAC;YACF,OAAO,CAAC,GAAG,CAAC,8BAA8B,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC;YACzD,OAAO,IAAI,CAAC,CAAC,kBAAkB;QACjC,CAAC;QAAC,OAAO,GAAG,EAAE,CAAC;YACb,OAAO,CAAC,GAAG,CAAC,2BAA2B,EAAE,GAAG,CAAC,CAAC;QAChD,CAAC;IACH,CAAC;;AAvQM,oBAAW,GAAG,EAAE,CAAC,MAAM,AAAZ,CAAa;AADpB,QAAQ;IADpB,WAAW;;GACC,QAAQ,CAyQpB"}
@@ -9,7 +9,7 @@ export interface S3FileStoreConfig {
9
9
  clientConfig?: S3ClientConfigInput;
10
10
  }
11
11
  export declare class S3FileStore extends Shape implements IFileStore {
12
- static targetClass: import("@_linked/core/utils/NodeReference.js").NodeReferenceValue;
12
+ static targetClass: import("@_linked/core/utils/NodeReference").NodeReferenceValue;
13
13
  label: string;
14
14
  private _bucket;
15
15
  private readonly config;