@travetto/model-file 7.0.0-rc.1 → 7.0.0-rc.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 (2) hide show
  1. package/package.json +7 -7
  2. package/src/service.ts +14 -14
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@travetto/model-file",
3
- "version": "7.0.0-rc.1",
3
+ "version": "7.0.0-rc.3",
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": "^7.0.0-rc.1",
29
- "@travetto/di": "^7.0.0-rc.1",
30
- "@travetto/model": "^7.0.0-rc.1",
31
- "@travetto/schema": "^7.0.0-rc.1"
28
+ "@travetto/config": "^7.0.0-rc.3",
29
+ "@travetto/di": "^7.0.0-rc.3",
30
+ "@travetto/model": "^7.0.0-rc.3",
31
+ "@travetto/schema": "^7.0.0-rc.3"
32
32
  },
33
33
  "peerDependencies": {
34
- "@travetto/cli": "^7.0.0-rc.1",
35
- "@travetto/test": "^7.0.0-rc.1"
34
+ "@travetto/cli": "^7.0.0-rc.3",
35
+ "@travetto/test": "^7.0.0-rc.3"
36
36
  },
37
37
  "peerDependenciesMeta": {
38
38
  "@travetto/cli": {
package/src/service.ts CHANGED
@@ -4,7 +4,7 @@ import os from 'node:os';
4
4
  import { pipeline } from 'node:stream/promises';
5
5
  import path from 'node:path';
6
6
 
7
- import { Class, TimeSpan, Runtime, BlobMeta, ByteRange, BinaryInput, BinaryUtil } from '@travetto/runtime';
7
+ import { Class, TimeSpan, Runtime, BlobMeta, ByteRange, BinaryInput, BinaryUtil, JSONUtil } from '@travetto/runtime';
8
8
  import { Injectable } from '@travetto/di';
9
9
  import { Config } from '@travetto/config';
10
10
  import { Required } from '@travetto/schema';
@@ -26,7 +26,7 @@ export class FileModelConfig {
26
26
  @Required(false)
27
27
  folder: string;
28
28
  namespace: string = '.';
29
- autoCreate?: boolean;
29
+ modifyStorage?: boolean;
30
30
  cullRate?: number | TimeSpan;
31
31
 
32
32
  async postConstruct(): Promise<void> {
@@ -34,7 +34,7 @@ export class FileModelConfig {
34
34
  }
35
35
  }
36
36
 
37
- const exists = (f: string): Promise<boolean> => fs.stat(f).then(() => true, () => false);
37
+ const exists = (file: string): Promise<boolean> => fs.stat(file).then(() => true, () => false);
38
38
 
39
39
  /**
40
40
  * Standard file support
@@ -71,13 +71,13 @@ export class FileModelService implements ModelCrudSupport, ModelBlobSupport, Mod
71
71
  if (id) {
72
72
  resolved = path.resolve(resolved, id.replace(/^[/]/, '').substring(0, 3));
73
73
  }
74
- let dir = resolved;
74
+ let folder = resolved;
75
75
  if (id) {
76
76
  resolved = path.resolve(resolved, `${id}${suffix}`);
77
- dir = path.dirname(resolved);
77
+ folder = path.dirname(resolved);
78
78
  }
79
79
 
80
- await fs.mkdir(dir, { recursive: true });
80
+ await fs.mkdir(folder, { recursive: true });
81
81
  return resolved;
82
82
  }
83
83
 
@@ -161,9 +161,9 @@ export class FileModelService implements ModelCrudSupport, ModelBlobSupport, Mod
161
161
  for await (const [id] of FileModelService.scanFolder(await this.#resolveName(cls, '.json'), '.json')) {
162
162
  try {
163
163
  yield await this.get(cls, id);
164
- } catch (err) {
165
- if (!(err instanceof NotFoundError)) {
166
- throw err;
164
+ } catch (error) {
165
+ if (!(error instanceof NotFoundError)) {
166
+ throw error;
167
167
  }
168
168
  }
169
169
  }
@@ -193,7 +193,7 @@ export class FileModelService implements ModelCrudSupport, ModelBlobSupport, Mod
193
193
  async getBlobMeta(location: string): Promise<BlobMeta> {
194
194
  const file = await this.#find(ModelBlobNamespace, META, location);
195
195
  const content = await fs.readFile(file);
196
- const text: BlobMeta = JSON.parse(content.toString('utf8'));
196
+ const text: BlobMeta = JSONUtil.parseSafe(content.toString('utf8'));
197
197
  return text;
198
198
  }
199
199
 
@@ -219,8 +219,8 @@ export class FileModelService implements ModelCrudSupport, ModelBlobSupport, Mod
219
219
  let deleted = 0;
220
220
  for await (const [_id, file] of FileModelService.scanFolder(await this.#resolveName(cls, '.json'), '.json')) {
221
221
  try {
222
- const res = await ModelCrudUtil.load(cls, await fs.readFile(file));
223
- if (ModelExpiryUtil.getExpiryState(cls, res).expired) {
222
+ const item = await ModelCrudUtil.load(cls, await fs.readFile(file));
223
+ if (ModelExpiryUtil.getExpiryState(cls, item).expired) {
224
224
  await fs.rm(file, { force: true });
225
225
  deleted += 1;
226
226
  }
@@ -231,8 +231,8 @@ export class FileModelService implements ModelCrudSupport, ModelBlobSupport, Mod
231
231
 
232
232
  // Storage management
233
233
  async createStorage(): Promise<void> {
234
- const dir = path.resolve(this.config.folder, this.config.namespace);
235
- await fs.mkdir(dir, { recursive: true });
234
+ const folder = path.resolve(this.config.folder, this.config.namespace);
235
+ await fs.mkdir(folder, { recursive: true });
236
236
  }
237
237
 
238
238
  async deleteStorage(): Promise<void> {