@travetto/model-file 5.0.7 → 5.0.8

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 (2) hide show
  1. package/package.json +2 -2
  2. package/src/service.ts +8 -3
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@travetto/model-file",
3
- "version": "5.0.7",
3
+ "version": "5.0.8",
4
4
  "description": "File system backing for the travetto model module.",
5
5
  "keywords": [
6
6
  "datastore",
@@ -27,7 +27,7 @@
27
27
  "dependencies": {
28
28
  "@travetto/config": "^5.0.7",
29
29
  "@travetto/di": "^5.0.7",
30
- "@travetto/model": "^5.0.7",
30
+ "@travetto/model": "^5.0.8",
31
31
  "@travetto/schema": "^5.0.7"
32
32
  },
33
33
  "peerDependencies": {
package/src/service.ts CHANGED
@@ -170,7 +170,7 @@ export class FileModelService implements ModelCrudSupport, ModelBlobSupport, Mod
170
170
 
171
171
  // Blob
172
172
  async upsertBlob(location: string, input: BinaryInput, meta?: BlobMeta, overwrite = true): Promise<void> {
173
- if (!overwrite && await this.describeBlob(location).then(() => true, () => false)) {
173
+ if (!overwrite && await this.getBlobMeta(location).then(() => true, () => false)) {
174
174
  return;
175
175
  }
176
176
 
@@ -184,12 +184,12 @@ export class FileModelService implements ModelCrudSupport, ModelBlobSupport, Mod
184
184
 
185
185
  async getBlob(location: string, range?: ByteRange): Promise<Blob> {
186
186
  const file = await this.#find(ModelBlobNamespace, BIN, location);
187
- const meta = await this.describeBlob(location);
187
+ const meta = await this.getBlobMeta(location);
188
188
  const final = range ? ModelBlobUtil.enforceRange(range, meta.size!) : undefined;
189
189
  return BinaryUtil.readableBlob(() => createReadStream(file, { ...range }), { ...meta, range: final });
190
190
  }
191
191
 
192
- async describeBlob(location: string): Promise<BlobMeta> {
192
+ async getBlobMeta(location: string): Promise<BlobMeta> {
193
193
  const file = await this.#find(ModelBlobNamespace, META, location);
194
194
  const content = await fs.readFile(file);
195
195
  const text: BlobMeta = JSON.parse(content.toString('utf8'));
@@ -208,6 +208,11 @@ export class FileModelService implements ModelCrudSupport, ModelBlobSupport, Mod
208
208
  }
209
209
  }
210
210
 
211
+ async updateBlobMeta(location: string, meta: BlobMeta): Promise<void> {
212
+ const file = await this.#find(ModelBlobNamespace, META, location);
213
+ await fs.writeFile(file, JSON.stringify(meta));
214
+ }
215
+
211
216
  // Expiry
212
217
  async deleteExpired<T extends ModelType>(cls: Class<T>): Promise<number> {
213
218
  return ModelExpiryUtil.naiveDeleteExpired(this, cls);