@webda/gcp 4.0.0-beta.2 → 4.0.0-beta.3

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 (68) hide show
  1. package/README.md +54 -4
  2. package/lib/index.d.ts +4 -4
  3. package/lib/index.d.ts.map +1 -1
  4. package/lib/index.js +4 -4
  5. package/lib/index.js.map +1 -1
  6. package/lib/services/firestore.service.d.ts +236 -0
  7. package/lib/services/firestore.service.d.ts.map +1 -0
  8. package/lib/services/firestore.service.js +692 -0
  9. package/lib/services/firestore.service.js.map +1 -0
  10. package/lib/services/index.d.ts +1 -1
  11. package/lib/services/index.d.ts.map +1 -1
  12. package/lib/services/index.js +1 -1
  13. package/lib/services/index.js.map +1 -1
  14. package/lib/services/{kms.d.ts → kms.service.d.ts} +14 -15
  15. package/lib/services/kms.service.d.ts.map +1 -0
  16. package/lib/services/{kms.js → kms.service.js} +18 -16
  17. package/lib/services/kms.service.js.map +1 -0
  18. package/lib/services/{pubsub.d.ts → pubsub.service.d.ts} +23 -4
  19. package/lib/services/pubsub.service.d.ts.map +1 -0
  20. package/lib/services/{pubsub.js → pubsub.service.js} +36 -10
  21. package/lib/services/pubsub.service.js.map +1 -0
  22. package/lib/services/{queue.d.ts → queue.service.d.ts} +32 -16
  23. package/lib/services/queue.service.d.ts.map +1 -0
  24. package/lib/services/{queue.js → queue.service.js} +63 -32
  25. package/lib/services/queue.service.js.map +1 -0
  26. package/lib/services/storage.service.d.ts +268 -0
  27. package/lib/services/storage.service.d.ts.map +1 -0
  28. package/lib/services/{storage.js → storage.service.js} +116 -69
  29. package/lib/services/storage.service.js.map +1 -0
  30. package/package.json +33 -43
  31. package/webda.module.json +1122 -1440
  32. package/lib/index.spec.d.ts +0 -5
  33. package/lib/index.spec.d.ts.map +0 -1
  34. package/lib/index.spec.js +0 -7
  35. package/lib/index.spec.js.map +0 -1
  36. package/lib/services/firestore.d.ts +0 -135
  37. package/lib/services/firestore.d.ts.map +0 -1
  38. package/lib/services/firestore.js +0 -423
  39. package/lib/services/firestore.js.map +0 -1
  40. package/lib/services/firestore.spec.d.ts +0 -2
  41. package/lib/services/firestore.spec.d.ts.map +0 -1
  42. package/lib/services/firestore.spec.js +0 -187
  43. package/lib/services/firestore.spec.js.map +0 -1
  44. package/lib/services/kms.d.ts.map +0 -1
  45. package/lib/services/kms.js.map +0 -1
  46. package/lib/services/kms.spec.d.ts +0 -2
  47. package/lib/services/kms.spec.d.ts.map +0 -1
  48. package/lib/services/kms.spec.js +0 -53
  49. package/lib/services/kms.spec.js.map +0 -1
  50. package/lib/services/pubsub.d.ts.map +0 -1
  51. package/lib/services/pubsub.js.map +0 -1
  52. package/lib/services/pubsub.spec.d.ts +0 -2
  53. package/lib/services/pubsub.spec.d.ts.map +0 -1
  54. package/lib/services/pubsub.spec.js +0 -95
  55. package/lib/services/pubsub.spec.js.map +0 -1
  56. package/lib/services/queue.d.ts.map +0 -1
  57. package/lib/services/queue.js.map +0 -1
  58. package/lib/services/queue.spec.d.ts +0 -2
  59. package/lib/services/queue.spec.d.ts.map +0 -1
  60. package/lib/services/queue.spec.js +0 -117
  61. package/lib/services/queue.spec.js.map +0 -1
  62. package/lib/services/storage.d.ts +0 -215
  63. package/lib/services/storage.d.ts.map +0 -1
  64. package/lib/services/storage.js.map +0 -1
  65. package/lib/services/storage.spec.d.ts +0 -2
  66. package/lib/services/storage.spec.d.ts.map +0 -1
  67. package/lib/services/storage.spec.js +0 -224
  68. package/lib/services/storage.spec.js.map +0 -1
@@ -0,0 +1 @@
1
+ {"version":3,"file":"queue.service.js","sourceRoot":"","sources":["../../src/services/queue.service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAW,MAAM,EAAgB,MAAM,sBAAsB,CAAC;AACrE,OAAO,EAAkB,KAAK,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AACrE,OAAO,EAAE,iBAAiB,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAE5D;;GAEG;AACH,MAAM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AE,UAAU,CAAC,CAAC;QAC9C,CAAC,EACD,KAAK,IAAI,EAAE;YACT,IAAI,CAAC,YAAY,EAAE,cAAc,CAAC,SAAS,EAAE,UAAU,CAAC,CAAC;QAC3D,CAAC,CACF,CAAC;IACJ,CAAC;CACF;AAED,OAAO,EAAE,QAAQ,EAAE,CAAC"}
@@ -0,0 +1,268 @@
1
+ import { Bucket, StorageOptions } from "@google-cloud/storage";
2
+ import { BinaryFile, BinaryFileInfo, BinaryMap, CloudBinary, CloudBinaryParameters, CoreModel, OperationContext } from "@webda/core";
3
+ import { StorageFinder } from "@webda/utils";
4
+ import { Readable, Writable } from "node:stream";
5
+ export type StorageObject = {
6
+ key: string;
7
+ /**
8
+ * bucket is an option,
9
+ * if not provided: it will get the DEFAULT_BUCKET set from environment variable
10
+ */
11
+ bucket?: string;
12
+ };
13
+ export type DownloadParams = StorageObject & {
14
+ localPath: string;
15
+ };
16
+ export type PutObjectParams = StorageObject & {
17
+ localPath?: string;
18
+ content?: string | Buffer;
19
+ };
20
+ export type SignedUrlParams = StorageObject & {
21
+ expires?: number;
22
+ action: "read" | "write" | "delete";
23
+ contentMd5?: string;
24
+ contentType?: string;
25
+ extensionHeaders?: {
26
+ [key: string]: string;
27
+ };
28
+ responseDisposition?: string;
29
+ queryParams?: {
30
+ [key: string]: string;
31
+ };
32
+ };
33
+ export type StorageObjectMeta = {
34
+ size: number;
35
+ contentType: string;
36
+ };
37
+ /**
38
+ * Configuration for {@link Storage}
39
+ */
40
+ export declare class StorageParameters extends CloudBinaryParameters {
41
+ /**
42
+ * Bucket to store binaries in
43
+ */
44
+ bucket: string;
45
+ /**
46
+ * Specify endpoint for GCS
47
+ */
48
+ endpoint?: string;
49
+ }
50
+ /**
51
+ * Google Storage Finder implementation
52
+ */
53
+ export declare class GCSFinder implements StorageFinder {
54
+ private _storage;
55
+ /**
56
+ * @param options - GCS client options
57
+ */
58
+ constructor(options?: StorageOptions);
59
+ /**
60
+ * Get info from url
61
+ * @param path - the gs:// url
62
+ * @returns the bucket and key
63
+ */
64
+ getInfo(path: string): {
65
+ bucket: string;
66
+ key: string;
67
+ };
68
+ /**
69
+ * Depth or options is ignored
70
+ * @override
71
+ * @param path - the gs:// url to walk
72
+ * @param processor - called for each file found
73
+ * @param _options - ignored
74
+ * @param _depth - ignored
75
+ */
76
+ walk(path: string, processor: (filepath: string) => void, _options?: {
77
+ followSymlinks?: boolean;
78
+ resolveSymlink?: boolean;
79
+ includeDir?: boolean;
80
+ maxDepth?: number;
81
+ }, _depth?: number): Promise<void>;
82
+ /**
83
+ * Find files under a gs:// url
84
+ * @param currentPath - the gs:// url to search
85
+ * @param options - only `filterPattern` and `processor` are used
86
+ * @returns the files found
87
+ */
88
+ find(currentPath: string, options?: {
89
+ includeDir?: boolean;
90
+ maxDepth?: number;
91
+ } & {
92
+ filterPattern?: RegExp;
93
+ processor?: (filepath: string) => void;
94
+ }): Promise<string[]>;
95
+ /**
96
+ * Get a write stream
97
+ * @param path - the gs:// url
98
+ * @returns the write stream
99
+ */
100
+ getWriteStream(path: string): Promise<Writable>;
101
+ /**
102
+ * Get a read stream
103
+ * @param path - the gs:// url
104
+ * @returns the read stream
105
+ */
106
+ getReadStream(path: string): Promise<Readable>;
107
+ }
108
+ /**
109
+ * Storage handles the storage of binary on a Google Cloud Storage bucket
110
+ *
111
+ * See Binary the general interface
112
+ * @WebdaModda GoogleCloudStorage
113
+ */
114
+ export default class Storage<T extends StorageParameters = StorageParameters> extends CloudBinary<T> {
115
+ private _storage?;
116
+ /**
117
+ * GCS client, created on first use
118
+ * @returns the GCS client
119
+ */
120
+ private get storage();
121
+ /**
122
+ * @override
123
+ * @param info - the binary map
124
+ * @returns the content stream
125
+ */
126
+ _get(info: BinaryMap): Promise<Readable>;
127
+ /**
128
+ * @override
129
+ * @param map - the binary map
130
+ * @param expires - expiration in seconds
131
+ * @param _context - the operation context
132
+ * @returns the signed url
133
+ */
134
+ getSignedUrlFromMap(map: BinaryMap, expires: number, _context: OperationContext): Promise<string>;
135
+ /**
136
+ * Get object content as a stream
137
+ * @param params - the object to read
138
+ * @param params.bucket - the bucket, default to the one predefined
139
+ * @param params.key - the object key
140
+ * @returns the content stream
141
+ */
142
+ getContent({ bucket, key }: StorageObject): Promise<Readable>;
143
+ /**
144
+ * Upload a local file to GCS bucket destination
145
+ *
146
+ * @param key - key to add to
147
+ * @param body - content of the object, a string is a local file path
148
+ * @param metadata - to put along the object
149
+ * @param bucket - to use
150
+ */
151
+ putObject(key: string, body: Readable | Buffer | string, metadata?: {}, bucket?: string): Promise<void>;
152
+ /**
153
+ * Return the Google Bucket directly
154
+ *
155
+ * @param bucket - name of the bucket default to the one predefined
156
+ * @returns the bucket
157
+ */
158
+ getStorageBucket(bucket?: string): Bucket;
159
+ /**
160
+ * @inheritdoc
161
+ * @param hash - the binary hash
162
+ * @param uuid - the object uuid
163
+ * @param property - the object property
164
+ */
165
+ _cleanUsage(hash: string, uuid: string, property?: string): Promise<void>;
166
+ /**
167
+ * @inheritdoc
168
+ * @param hash - the binary hash
169
+ * @returns the number of objects using the binary
170
+ */
171
+ getUsageCount(hash: string): Promise<number>;
172
+ /**
173
+ * @inheritdoc
174
+ * @param object - the object to attach the binary to
175
+ * @param property - the object property
176
+ * @param file - the binary to store
177
+ */
178
+ store(object: CoreModel, property: string, file: BinaryFile): Promise<void>;
179
+ /**
180
+ * Delete a file inside an existing bucket
181
+ * @param params - the object to delete
182
+ * @param params.bucket - the bucket, default to the one predefined
183
+ * @param params.key - the object key
184
+ */
185
+ deleteObject({ bucket, key }: StorageObject): Promise<void>;
186
+ /**
187
+ * Move a file from one bucket to an other
188
+ * @param source - the object to move
189
+ * @param destination - the new location
190
+ */
191
+ moveObject(source: StorageObject, destination: StorageObject): Promise<void>;
192
+ /**
193
+ * Get a signed url for the client to upload the binary directly to GCS
194
+ * @param object - the object to attach the binary to
195
+ * @param property - the object property
196
+ * @param info - the binary information (hash, challenge), read from the context if not provided
197
+ * @param context - the operation context
198
+ * @returns the upload url, undefined if the binary is already uploaded
199
+ */
200
+ putRedirectUrl(object: CoreModel, property: string, info?: BinaryFileInfo & {
201
+ hash: string;
202
+ challenge: string;
203
+ }, context?: OperationContext<any>): Promise<{
204
+ url: string;
205
+ method: string;
206
+ headers: {
207
+ [key: string]: string;
208
+ };
209
+ }>;
210
+ /**
211
+ * Retrieve one signed URL to download the file in parameter
212
+ * @param params.bucket - the bucket, default to the one predefined
213
+ * @param params.key - the object key
214
+ * @param params.expires - expiration in seconds
215
+ * @param params.action - the action allowed by the url
216
+ * @param params - the object and signature options
217
+ * @returns URL in order to download the file
218
+ */
219
+ getSignedUrl({ bucket, key, expires, action, ...params }: SignedUrlParams): Promise<string>;
220
+ /**
221
+ * Retrieve mandatory headers if needed by the cloud provider (ie. Azure)
222
+ * Returns empty object if no headers are mandatory
223
+ * @returns mandatory headers
224
+ */
225
+ getSignedUrlHeaders(): {
226
+ [key: string]: string;
227
+ };
228
+ /**
229
+ * Retrieve public URL of this object
230
+ * @param params - the object
231
+ * @param params.bucket - the bucket, default to the one predefined
232
+ * @param params.key - the object key
233
+ * @returns Public URL in order to download the file
234
+ */
235
+ getPublicUrl({ bucket, key }: StorageObject): Promise<string>;
236
+ /**
237
+ * Fetch an object's metadata
238
+ * @param params - the object
239
+ * @param params.bucket - the bucket, default to the one predefined
240
+ * @param params.key - the object key
241
+ * @returns size and content type
242
+ */
243
+ getMeta({ bucket, key }: StorageObject): Promise<StorageObjectMeta>;
244
+ /**
245
+ * Get a bucket size with a prefix
246
+ * @param bucket - the bucket, default to the one predefined
247
+ * @param prefix - on the bucket
248
+ * @param regex - to filter files
249
+ * @returns the total size and count of files
250
+ */
251
+ getBucketSize(bucket?: string, prefix?: string, regex?: RegExp): Promise<{
252
+ size: number;
253
+ count: number;
254
+ }>;
255
+ /**
256
+ * Add a usage marker for a binary
257
+ * @param hash - the binary hash
258
+ * @param uuid - the marker name: `${property}_${uuid}`
259
+ * @param model - the model identifier of the object
260
+ */
261
+ putMarker(hash: string, uuid: string, model: string): Promise<void>;
262
+ /**
263
+ * Delete every object under the prefix, used by tests
264
+ */
265
+ __clean(): Promise<void>;
266
+ }
267
+ export { Storage };
268
+ //# sourceMappingURL=storage.service.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"storage.service.d.ts","sourceRoot":"","sources":["../../src/services/storage.service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAA4C,cAAc,EAAE,MAAM,uBAAuB,CAAC;AACzG,OAAO,EACL,UAAU,EACV,cAAc,EACd,SAAS,EACT,WAAW,EACX,qBAAqB,EACrB,SAAS,EACT,gBAAgB,EAEjB,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,aAAa,EAAa,MAAM,cAAc,CAAC;AAGxD,OAAO,EAAE,QAAQ,EAAU,QAAQ,EAAE,MAAM,aAAa,CAAC;AAGzD,MAAM,MAAM,aAAa,GAAG;IAC1B,GAAG,EAAE,MAAM,CAAC;IAEZ;;;OAGG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB,CAAC;AAEF,MAAM,MAAM,cAAc,GAAG,aAAa,GAAG;IAC3C,SAAS,EAAE,MAAM,CAAC;CACnB,CAAC;AAEF,MAAM,MAAM,eAAe,GAAG,aAAa,GAAG;IAC5C,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,OAAO,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;CAC3B,CAAC;AAEF,MAAM,MAAM,eAAe,GAAG,aAAa,GAAG;IAC5C,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,MAAM,EAAE,MAAM,GAAG,OAAO,GAAG,QAAQ,CAAC;IACpC,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,gBAAgB,CAAC,EAAE;QAAE,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAAA;KAAE,CAAC;IAC7C,mBAAmB,CAAC,EAAE,MAAM,CAAC;IAC7B,WAAW,CAAC,EAAE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G;IACG,aAAa,CAAC,MAAM,CAAC,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,MAAM;;;OA2BnE;IAED;;;;;OAKG;IACG,SAAS,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,iBAUxD;IAED;;OAEG;IACG,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC,CAG7B;CACF;AAED,OAAO,EAAE,OAAO,EAAE,CAAC"}
@@ -1,26 +1,29 @@
1
1
  import { Storage as GCS } from "@google-cloud/storage";
2
- import { BinaryParameters, CloudBinary, Throttler } from "@webda/core";
2
+ import { CloudBinary, CloudBinaryParameters, useModelId } from "@webda/core";
3
+ import { Throttler } from "@webda/utils";
3
4
  import { createReadStream } from "fs";
4
5
  import * as mime from "mime-types";
5
6
  import { Readable, Stream } from "node:stream";
6
7
  import { pipeline } from "node:stream/promises";
7
- export class StorageParameters extends BinaryParameters {
8
- constructor(params, service) {
9
- super(params, service);
10
- this.prefix = "";
11
- }
8
+ /**
9
+ * Configuration for {@link Storage}
10
+ */
11
+ export class StorageParameters extends CloudBinaryParameters {
12
12
  }
13
13
  /**
14
14
  * Google Storage Finder implementation
15
15
  */
16
16
  export class GCSFinder {
17
+ /**
18
+ * @param options - GCS client options
19
+ */
17
20
  constructor(options) {
18
21
  this._storage = new GCS(options);
19
22
  }
20
23
  /**
21
24
  * Get info from url
22
- * @param path
23
- * @returns
25
+ * @param path - the gs:// url
26
+ * @returns the bucket and key
24
27
  */
25
28
  getInfo(path) {
26
29
  const url = new URL(path);
@@ -39,8 +42,12 @@ export class GCSFinder {
39
42
  /**
40
43
  * Depth or options is ignored
41
44
  * @override
45
+ * @param path - the gs:// url to walk
46
+ * @param processor - called for each file found
47
+ * @param _options - ignored
48
+ * @param _depth - ignored
42
49
  */
43
- async walk(path, processor, options, depth) {
50
+ async walk(path, processor, _options, _depth) {
44
51
  const { bucket, key } = this.getInfo(path);
45
52
  let pageToken;
46
53
  do {
@@ -52,10 +59,10 @@ export class GCSFinder {
52
59
  } while (pageToken);
53
60
  }
54
61
  /**
55
- *
56
- * @param currentPath
57
- * @param options is ignored
58
- * @returns
62
+ * Find files under a gs:// url
63
+ * @param currentPath - the gs:// url to search
64
+ * @param options - only `filterPattern` and `processor` are used
65
+ * @returns the files found
59
66
  */
60
67
  async find(currentPath, options) {
61
68
  const res = [];
@@ -72,8 +79,8 @@ export class GCSFinder {
72
79
  }
73
80
  /**
74
81
  * Get a write stream
75
- * @param path
76
- * @returns
82
+ * @param path - the gs:// url
83
+ * @returns the write stream
77
84
  */
78
85
  async getWriteStream(path) {
79
86
  const { bucket, key } = this.getInfo(path);
@@ -81,8 +88,8 @@ export class GCSFinder {
81
88
  }
82
89
  /**
83
90
  * Get a read stream
84
- * @param path
85
- * @returns
91
+ * @param path - the gs:// url
92
+ * @returns the read stream
86
93
  */
87
94
  async getReadStream(path) {
88
95
  const { bucket, key } = this.getInfo(path);
@@ -96,22 +103,20 @@ export class GCSFinder {
96
103
  * @WebdaModda GoogleCloudStorage
97
104
  */
98
105
  export default class Storage extends CloudBinary {
106
+ /**
107
+ * GCS client, created on first use
108
+ * @returns the GCS client
109
+ */
99
110
  get storage() {
100
111
  if (!this._storage) {
101
112
  this._storage = new GCS({ apiEndpoint: this.parameters.endpoint });
102
113
  }
103
114
  return this._storage;
104
115
  }
105
- /**
106
- * Load the parameters
107
- *
108
- * @param params
109
- */
110
- loadParameters(params) {
111
- return new StorageParameters(params, this);
112
- }
113
116
  /**
114
117
  * @override
118
+ * @param info - the binary map
119
+ * @returns the content stream
115
120
  */
116
121
  async _get(info) {
117
122
  const key = this._getKey(info.hash);
@@ -119,6 +124,10 @@ export default class Storage extends CloudBinary {
119
124
  }
120
125
  /**
121
126
  * @override
127
+ * @param map - the binary map
128
+ * @param expires - expiration in seconds
129
+ * @param _context - the operation context
130
+ * @returns the signed url
122
131
  */
123
132
  getSignedUrlFromMap(map, expires, _context) {
124
133
  return this.getSignedUrl({
@@ -128,8 +137,11 @@ export default class Storage extends CloudBinary {
128
137
  });
129
138
  }
130
139
  /**
131
- * Get object content in Buffer
132
- * @param {StorageObject} params
140
+ * Get object content as a stream
141
+ * @param params - the object to read
142
+ * @param params.bucket - the bucket, default to the one predefined
143
+ * @param params.key - the object key
144
+ * @returns the content stream
133
145
  */
134
146
  async getContent({ bucket, key }) {
135
147
  return this.getStorageBucket(bucket).file(key).createReadStream();
@@ -137,14 +149,12 @@ export default class Storage extends CloudBinary {
137
149
  /**
138
150
  * Upload a local file to GCS bucket destination
139
151
  *
140
- * @param key to add to
141
- * @param body content of the object
142
- * @param metadatas to put along the object
143
- * @param bucket to use
152
+ * @param key - key to add to
153
+ * @param body - content of the object, a string is a local file path
154
+ * @param metadata - to put along the object
155
+ * @param bucket - to use
144
156
  */
145
- async putObject(key, body, metadata = {}, bucket = this.parameters.bucket
146
- //{ bucket, localPath, content, key }: PutObjectParams
147
- ) {
157
+ async putObject(key, body, metadata = {}, bucket = this.parameters.bucket) {
148
158
  const file = this.getStorageBucket(bucket).file(key);
149
159
  let contentType = "application/octet-stream";
150
160
  let stream;
@@ -166,14 +176,17 @@ export default class Storage extends CloudBinary {
166
176
  /**
167
177
  * Return the Google Bucket directly
168
178
  *
169
- * @param bucket name of the bucket default to the one predefined
170
- * @returns
179
+ * @param bucket - name of the bucket default to the one predefined
180
+ * @returns the bucket
171
181
  */
172
182
  getStorageBucket(bucket = this.parameters.bucket) {
173
183
  return this.storage.bucket(bucket);
174
184
  }
175
185
  /**
176
186
  * @inheritdoc
187
+ * @param hash - the binary hash
188
+ * @param uuid - the object uuid
189
+ * @param property - the object property
177
190
  */
178
191
  async _cleanUsage(hash, uuid, property) {
179
192
  const suffix = property ? `${property}_${uuid}` : `_${uuid}`;
@@ -187,6 +200,8 @@ export default class Storage extends CloudBinary {
187
200
  }
188
201
  /**
189
202
  * @inheritdoc
203
+ * @param hash - the binary hash
204
+ * @returns the number of objects using the binary
190
205
  */
191
206
  async getUsageCount(hash) {
192
207
  const [files] = await this.getStorageBucket().getFiles({
@@ -196,6 +211,9 @@ export default class Storage extends CloudBinary {
196
211
  }
197
212
  /**
198
213
  * @inheritdoc
214
+ * @param object - the object to attach the binary to
215
+ * @param property - the object property
216
+ * @param file - the binary to store
199
217
  */
200
218
  async store(object, property, file) {
201
219
  this.checkMap(object, property);
@@ -208,35 +226,41 @@ export default class Storage extends CloudBinary {
208
226
  challenge: file.challenge
209
227
  });
210
228
  }
211
- await this.putMarker(file.hash, `${property}_${object.getUuid()}`, object.getStore().getName());
212
- await this.uploadSuccess(object, property, file);
229
+ await this.putMarker(file.hash, `${property}_${object.getUUID()}`, useModelId(object.constructor));
230
+ await this.uploadSuccess(object, property, file.toBinaryFileInfo());
213
231
  }
214
232
  /**
215
233
  * Delete a file inside an existing bucket
216
- * @param {DeleteObjectParams} params
234
+ * @param params - the object to delete
235
+ * @param params.bucket - the bucket, default to the one predefined
236
+ * @param params.key - the object key
217
237
  */
218
238
  async deleteObject({ bucket, key }) {
219
239
  await this.getStorageBucket(bucket).file(key).delete();
220
- this._webda.log("DEBUG", `gs://${bucket}/${key} deleted`);
240
+ this.log("DEBUG", `gs://${bucket}/${key} deleted`);
221
241
  }
222
242
  /**
223
243
  * Move a file from one bucket to an other
224
- * @param {StorageObject} source
225
- * @param {StorageObject} destination
244
+ * @param source - the object to move
245
+ * @param destination - the new location
226
246
  */
227
247
  async moveObject(source, destination) {
228
248
  const newFile = this.getStorageBucket(destination.bucket).file(destination.key);
229
- this._webda.log("DEBUG", `moveObject gs://${source.bucket}/${source.key} => gs://${destination.bucket}/${destination.key}`);
249
+ this.log("DEBUG", `moveObject gs://${source.bucket}/${source.key} => gs://${destination.bucket}/${destination.key}`);
230
250
  await this.getStorageBucket(source.bucket).file(source.key).move(newFile);
231
251
  }
232
252
  /**
233
- * @inheritdoc
253
+ * Get a signed url for the client to upload the binary directly to GCS
254
+ * @param object - the object to attach the binary to
255
+ * @param property - the object property
256
+ * @param info - the binary information (hash, challenge), read from the context if not provided
257
+ * @param context - the operation context
258
+ * @returns the upload url, undefined if the binary is already uploaded
234
259
  */
235
- async putRedirectUrl(ctx) {
236
- const body = await ctx.getRequestBody();
237
- const { uuid, store, property } = ctx.getParameters();
238
- const targetStore = this.verifyMapAndStore(ctx);
239
- const object = await targetStore.get(uuid);
260
+ async putRedirectUrl(object, property, info, context) {
261
+ const body = info ?? (await context.getInput());
262
+ this.checkMap(object, property);
263
+ const uuid = object.getUUID();
240
264
  const base64String = Buffer.from(body.hash, "hex").toString("base64");
241
265
  const params = {
242
266
  bucket: this.parameters.bucket,
@@ -254,11 +278,11 @@ export default class Storage extends CloudBinary {
254
278
  const res = await this.getStorageBucket().file(params.key).getMetadata();
255
279
  challenge = res[0].metadata.challenge;
256
280
  }
257
- catch (err) {
258
- // Ignore error
281
+ catch {
282
+ // Ignore error: the data does not exist yet
259
283
  }
260
284
  await this.uploadSuccess(object, property, body);
261
- await this.putMarker(body.hash, `${property}_${uuid}`, store);
285
+ await this.putMarker(body.hash, `${property}_${uuid}`, useModelId(object.constructor));
262
286
  // If the challenge is the same, no need to upload
263
287
  if (challenge && challenge === body.challenge) {
264
288
  return;
@@ -278,8 +302,12 @@ export default class Storage extends CloudBinary {
278
302
  }
279
303
  /**
280
304
  * Retrieve one signed URL to download the file in parameter
281
- * @param {SignedUrlParams} params
282
- * @returns {string} URL in order to download the file
305
+ * @param params.bucket - the bucket, default to the one predefined
306
+ * @param params.key - the object key
307
+ * @param params.expires - expiration in seconds
308
+ * @param params.action - the action allowed by the url
309
+ * @param params - the object and signature options
310
+ * @returns URL in order to download the file
283
311
  */
284
312
  async getSignedUrl({ bucket, key, expires = 3600, action = "read", ...params }) {
285
313
  const options = {
@@ -289,29 +317,33 @@ export default class Storage extends CloudBinary {
289
317
  expires: Date.now() + expires * 1000
290
318
  };
291
319
  const [url] = await this.getStorageBucket(bucket).file(key).getSignedUrl(options);
292
- this._webda.log("TRACE", `The signed url for ${bucket}/${key} is ${url}.`);
320
+ this.log("TRACE", `The signed url for ${bucket}/${key} is ${url}.`);
293
321
  return url;
294
322
  }
295
323
  /**
296
324
  * Retrieve mandatory headers if needed by the cloud provider (ie. Azure)
297
325
  * Returns empty object if no headers are mandatory
298
- * @returns {[key:string]: string} mandatory headers
326
+ * @returns mandatory headers
299
327
  */
300
328
  getSignedUrlHeaders() {
301
329
  return {};
302
330
  }
303
331
  /**
304
332
  * Retrieve public URL of this object
305
- * @param {StorageModel} store
306
- * @returns {string} Public URL in order to download the file
333
+ * @param params - the object
334
+ * @param params.bucket - the bucket, default to the one predefined
335
+ * @param params.key - the object key
336
+ * @returns Public URL in order to download the file
307
337
  */
308
338
  async getPublicUrl({ bucket, key }) {
309
339
  return this.getStorageBucket(bucket).file(key).publicUrl();
310
340
  }
311
341
  /**
312
342
  * Fetch an object's metadata
313
- * @param {StorageModel} store
314
- * @returns {any} Metadata
343
+ * @param params - the object
344
+ * @param params.bucket - the bucket, default to the one predefined
345
+ * @param params.key - the object key
346
+ * @returns size and content type
315
347
  */
316
348
  async getMeta({ bucket, key }) {
317
349
  const [metadata] = await this.getStorageBucket(bucket).file(key).getMetadata();
@@ -322,9 +354,10 @@ export default class Storage extends CloudBinary {
322
354
  }
323
355
  /**
324
356
  * Get a bucket size with a prefix
325
- * @param bucket
326
- * @param prefix on the bucket
327
- * @param regex to filter files
357
+ * @param bucket - the bucket, default to the one predefined
358
+ * @param prefix - on the bucket
359
+ * @param regex - to filter files
360
+ * @returns the total size and count of files
328
361
  */
329
362
  async getBucketSize(bucket, prefix, regex) {
330
363
  let pageToken;
@@ -339,11 +372,13 @@ export default class Storage extends CloudBinary {
339
372
  size += Number.parseInt(metadata.size);
340
373
  count++;
341
374
  }
342
- catch (err) { }
375
+ catch {
376
+ // Ignore files removed while computing
377
+ }
343
378
  };
344
379
  };
345
380
  do {
346
- const [files, page, _] = await this.storage.bucket(bucket).getFiles({ maxResults: 1000, pageToken, prefix });
381
+ const [files, page] = await this.storage.bucket(bucket).getFiles({ maxResults: 1000, pageToken, prefix });
347
382
  files.filter(f => (regex ? f.name.match(regex) : true)).forEach(f => throttler.queue(dwl(f)));
348
383
  await throttler.wait();
349
384
  pageToken = page?.pageToken;
@@ -354,17 +389,29 @@ export default class Storage extends CloudBinary {
354
389
  };
355
390
  }
356
391
  /**
357
- * @inheritdoc
392
+ * Add a usage marker for a binary
393
+ * @param hash - the binary hash
394
+ * @param uuid - the marker name: `${property}_${uuid}`
395
+ * @param model - the model identifier of the object
358
396
  */
359
- async putMarker(hash, uuid, storeName) {
397
+ async putMarker(hash, uuid, model) {
360
398
  await this.getStorageBucket()
361
399
  .file(this._getKey(hash, uuid))
362
400
  .save("", {
363
401
  metadata: {
364
- webdaStore: storeName
402
+ metadata: {
403
+ webdaModel: model
404
+ }
365
405
  }
366
406
  });
367
407
  }
408
+ /**
409
+ * Delete every object under the prefix, used by tests
410
+ */
411
+ async __clean() {
412
+ const [files] = await this.getStorageBucket().getFiles({ prefix: this.parameters.prefix });
413
+ await Promise.all(files.map(f => f.delete()));
414
+ }
368
415
  }
369
416
  export { Storage };
370
- //# sourceMappingURL=storage.js.map
417
+ //# sourceMappingURL=storage.service.js.map