@travetto/model-file 5.0.6 → 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.
- package/package.json +7 -7
- 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.
|
|
3
|
+
"version": "5.0.8",
|
|
4
4
|
"description": "File system backing for the travetto model module.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"datastore",
|
|
@@ -25,14 +25,14 @@
|
|
|
25
25
|
"directory": "module/model-file"
|
|
26
26
|
},
|
|
27
27
|
"dependencies": {
|
|
28
|
-
"@travetto/config": "^5.0.
|
|
29
|
-
"@travetto/di": "^5.0.
|
|
30
|
-
"@travetto/model": "^5.0.
|
|
31
|
-
"@travetto/schema": "^5.0.
|
|
28
|
+
"@travetto/config": "^5.0.7",
|
|
29
|
+
"@travetto/di": "^5.0.7",
|
|
30
|
+
"@travetto/model": "^5.0.8",
|
|
31
|
+
"@travetto/schema": "^5.0.7"
|
|
32
32
|
},
|
|
33
33
|
"peerDependencies": {
|
|
34
|
-
"@travetto/cli": "^5.0.
|
|
35
|
-
"@travetto/test": "^5.0.
|
|
34
|
+
"@travetto/cli": "^5.0.7",
|
|
35
|
+
"@travetto/test": "^5.0.7"
|
|
36
36
|
},
|
|
37
37
|
"peerDependenciesMeta": {
|
|
38
38
|
"@travetto/cli": {
|
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.
|
|
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.
|
|
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
|
|
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);
|