@travetto/model 3.4.5 → 4.0.0-rc.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.
package/README.md CHANGED
@@ -239,7 +239,7 @@ In addition to the provided contracts, the module also provides common utilities
239
239
 
240
240
  **Code: Memory Service**
241
241
  ```typescript
242
- import { Readable } from 'stream';
242
+ import { Readable } from 'node:stream';
243
243
  import { StreamUtil, Class, TimeSpan } from '@travetto/base';
244
244
  import { DeepPartial } from '@travetto/schema';
245
245
  import { Injectable } from '@travetto/di';
@@ -382,7 +382,7 @@ Usage: model:export [options] <provider:string> <models...:string>
382
382
 
383
383
  Options:
384
384
  -e, --env <string> Application environment
385
- -m, --module <string> Module to run for
385
+ -m, --module <module> Module to run for
386
386
  -h, --help display help for command
387
387
 
388
388
  Providers
@@ -405,7 +405,7 @@ Usage: model:install [options] <provider:string> <models...:string>
405
405
 
406
406
  Options:
407
407
  -e, --env <string> Application environment
408
- -m, --module <string> Module to run for
408
+ -m, --module <module> Module to run for
409
409
  -h, --help display help for command
410
410
 
411
411
  Providers
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@travetto/model",
3
- "version": "3.4.5",
3
+ "version": "4.0.0-rc.1",
4
4
  "description": "Datastore abstraction for core operations.",
5
5
  "keywords": [
6
6
  "datastore",
@@ -26,14 +26,14 @@
26
26
  "directory": "module/model"
27
27
  },
28
28
  "dependencies": {
29
- "@travetto/config": "^3.4.4",
30
- "@travetto/di": "^3.4.2",
31
- "@travetto/registry": "^3.4.2",
32
- "@travetto/schema": "^3.4.4"
29
+ "@travetto/config": "^4.0.0-rc.1",
30
+ "@travetto/di": "^4.0.0-rc.1",
31
+ "@travetto/registry": "^4.0.0-rc.1",
32
+ "@travetto/schema": "^4.0.0-rc.1"
33
33
  },
34
34
  "peerDependencies": {
35
- "@travetto/cli": "^3.4.7",
36
- "@travetto/test": "^3.4.3"
35
+ "@travetto/cli": "^4.0.0-rc.1",
36
+ "@travetto/test": "^4.0.0-rc.1"
37
37
  },
38
38
  "peerDependenciesMeta": {
39
39
  "@travetto/cli": {
@@ -1,4 +1,4 @@
1
- import crypto from 'crypto';
1
+ import crypto from 'node:crypto';
2
2
 
3
3
  import { Class, ObjectUtil, Util } from '@travetto/base';
4
4
  import { SchemaRegistry, SchemaValidator, ValidationError, ValidationResultError } from '@travetto/schema';
@@ -1,3 +1,5 @@
1
+ import timers from 'node:timers/promises';
2
+
1
3
  import { ShutdownManager, Class, TimeSpan, TimeUtil } from '@travetto/base';
2
4
 
3
5
  import { ModelRegistry } from '../../registry/model';
@@ -36,16 +38,12 @@ export class ModelExpiryUtil {
36
38
  let running = true;
37
39
  const cullInterval = TimeUtil.timeToMs(svc.config?.cullRate ?? '10m');
38
40
 
39
- ShutdownManager.onShutdown(this, {
40
- close(cb) {
41
- running = false;
42
- cb?.();
43
- }
44
- });
41
+ ShutdownManager.onGracefulShutdown(async () => { running = false; }, this);
42
+
45
43
  (async (): Promise<void> => {
46
- await TimeUtil.wait('1s'); // Wait a second to start culling
44
+ await timers.setTimeout(1000); // Wait a second to start culling
47
45
  while (running) {
48
- await TimeUtil.wait(cullInterval);
46
+ await timers.setTimeout(cullInterval);
49
47
  await Promise.all(cullable.map(cls => svc.deleteExpired(cls)));
50
48
  }
51
49
  })();
@@ -1,4 +1,4 @@
1
- import { Class, GlobalEnv } from '@travetto/base';
1
+ import { Class, Env } from '@travetto/base';
2
2
  import { SchemaChangeListener } from '@travetto/schema';
3
3
 
4
4
  import { ModelRegistry } from '../../registry/model';
@@ -13,7 +13,7 @@ export class ModelStorageUtil {
13
13
  * Register change listener on startup
14
14
  */
15
15
  static async registerModelChangeListener(storage: ModelStorageSupport, target?: Class): Promise<void> {
16
- if (!GlobalEnv.dynamic || !(storage?.config?.autoCreate ?? GlobalEnv.devMode)) {
16
+ if (!Env.dynamic || !(storage?.config?.autoCreate ?? !Env.production)) {
17
17
  return;
18
18
  }
19
19
 
@@ -1,11 +1,11 @@
1
- import fs from 'fs/promises';
2
- import { createReadStream } from 'fs';
1
+ import fs from 'node:fs/promises';
2
+ import { createReadStream } from 'node:fs';
3
3
 
4
- import os from 'os';
4
+ import os from 'node:os';
5
5
 
6
- import { Readable } from 'stream';
6
+ import { Readable } from 'node:stream';
7
7
 
8
- import { path, RootIndex } from '@travetto/manifest';
8
+ import { path, RuntimeContext } from '@travetto/manifest';
9
9
  import { StreamUtil, Class, TimeSpan } from '@travetto/base';
10
10
  import { Injectable } from '@travetto/di';
11
11
  import { Config } from '@travetto/config';
@@ -37,7 +37,7 @@ export class FileModelConfig {
37
37
  cullRate?: number | TimeSpan;
38
38
 
39
39
  async postConstruct(): Promise<void> {
40
- this.folder ??= path.resolve(os.tmpdir(), `trv_file_${RootIndex.mainModuleName.replace(/[^a-z]/ig, '_')}`);
40
+ this.folder ??= path.resolve(os.tmpdir(), `trv_file_${RuntimeContext.main.name.replace(/[^a-z]/ig, '_')}`);
41
41
  }
42
42
  }
43
43
 
@@ -1,4 +1,4 @@
1
- import { Readable } from 'stream';
1
+ import { Readable } from 'node:stream';
2
2
 
3
3
  import { StreamUtil, Class, TimeSpan } from '@travetto/base';
4
4
  import { DeepPartial } from '@travetto/schema';
@@ -1,4 +1,4 @@
1
- import { RootIndex } from '@travetto/manifest';
1
+ import { RuntimeIndex } from '@travetto/manifest';
2
2
  import { SchemaRegistry } from '@travetto/schema';
3
3
  import { MetadataRegistry } from '@travetto/registry';
4
4
  import { DependencyRegistry } from '@travetto/di';
@@ -52,7 +52,7 @@ class $ModelRegistry extends MetadataRegistry<ModelOptions<ModelType>> {
52
52
  }
53
53
 
54
54
  createPending(cls: Class): Partial<ModelOptions<ModelType>> {
55
- return { class: cls, indices: [], autoCreate: true, baseType: RootIndex.getFunctionMetadata(cls)?.abstract, postLoad: [], prePersist: [] };
55
+ return { class: cls, indices: [], autoCreate: true, baseType: RuntimeIndex.getFunctionMetadata(cls)?.abstract, postLoad: [], prePersist: [] };
56
56
  }
57
57
 
58
58
  registerDataHandlers(cls: Class, pConfig?: Partial<ModelOptions<ModelType>>): void {
@@ -4,7 +4,7 @@ import { ModelType, OptionalId } from '../types/model';
4
4
  /**
5
5
  * Interface for basic data interface
6
6
  *
7
- * @concrete ../internal/service/common:ModelBasicSupportTarget
7
+ * @concrete ../internal/service/common#ModelBasicSupportTarget
8
8
  */
9
9
  export interface ModelBasicSupport<C = unknown> {
10
10
  /**
@@ -65,7 +65,7 @@ export class BulkProcessError extends AppError {
65
65
  /**
66
66
  * Determines if model allows for bulk operations
67
67
  *
68
- * @concrete ../internal/service/common:ModelBulkSupportTarget
68
+ * @concrete ../internal/service/common#ModelBulkSupportTarget
69
69
  */
70
70
  export interface ModelBulkSupport extends ModelCrudSupport {
71
71
  processBulk<T extends ModelType>(cls: Class<T>, operations: BulkOp<T>[]): Promise<BulkResponse>;
@@ -6,7 +6,7 @@ import { ModelBasicSupport } from './basic';
6
6
 
7
7
  /**
8
8
  * Interface for simple CRUD
9
- * @concrete ../internal/service/common:ModelCrudSupportTarget
9
+ * @concrete ../internal/service/common#ModelCrudSupportTarget
10
10
  */
11
11
  export interface ModelCrudSupport extends ModelBasicSupport {
12
12
 
@@ -6,7 +6,7 @@ import { ModelCrudSupport } from './crud';
6
6
  /**
7
7
  * Support for managing expiration of data
8
8
  *
9
- * @concrete ../internal/service/common:ModelExpirySupportTarget
9
+ * @concrete ../internal/service/common#ModelExpirySupportTarget
10
10
  */
11
11
  export interface ModelExpirySupport extends ModelCrudSupport {
12
12
  /**
@@ -7,7 +7,7 @@ import { ModelBasicSupport } from './basic';
7
7
  /**
8
8
  * Support for simple indexed activity
9
9
  *
10
- * @concrete ../internal/service/common:ModelIndexedSupportTarget
10
+ * @concrete ../internal/service/common#ModelIndexedSupportTarget
11
11
  */
12
12
  export interface ModelIndexedSupport extends ModelBasicSupport {
13
13
  /**
@@ -10,7 +10,7 @@ import { ModelType } from '../types/model';
10
10
  *
11
11
  * This is intended to be used during development only for rapid prototyping.
12
12
  *
13
- * @concrete ../internal/service/common:ModelStorageSupportTarget
13
+ * @concrete ../internal/service/common#ModelStorageSupportTarget
14
14
  */
15
15
  export interface ModelStorageSupport {
16
16
 
@@ -1,4 +1,4 @@
1
- import { Readable } from 'stream';
1
+ import { Readable } from 'node:stream';
2
2
 
3
3
  export interface StreamMeta {
4
4
  /**
@@ -43,7 +43,7 @@ export interface PartialStream {
43
43
  /**
44
44
  * Support for Streams CRD. Stream update is not supported.
45
45
  *
46
- * @concrete ../internal/service/common:ModelStreamSupportTarget
46
+ * @concrete ../internal/service/common#ModelStreamSupportTarget
47
47
  */
48
48
  export interface ModelStreamSupport {
49
49
 
@@ -1,4 +1,4 @@
1
- import { ConsoleManager, defineEnv } from '@travetto/base';
1
+ import { Env } from '@travetto/base';
2
2
  import { CliValidationError, CliCommandShape, cliTpl } from '@travetto/cli';
3
3
  import { RootRegistry } from '@travetto/registry';
4
4
 
@@ -17,7 +17,7 @@ export abstract class BaseModelCommand implements CliCommandShape {
17
17
  abstract getOp(): keyof ModelStorageSupport;
18
18
 
19
19
  preMain(): void {
20
- defineEnv({ debug: false });
20
+ Env.DEBUG.set(false);
21
21
  }
22
22
 
23
23
  async help(): Promise<string[]> {
@@ -36,7 +36,6 @@ export abstract class BaseModelCommand implements CliCommandShape {
36
36
  }
37
37
 
38
38
  async validate(provider: string, models: string[]): Promise<CliValidationError | undefined> {
39
- ConsoleManager.setDebug(false);
40
39
  await RootRegistry.init();
41
40
 
42
41
  const candidates = await ModelCandidateUtil.export(this.getOp());
@@ -1,4 +1,4 @@
1
- import { ShutdownManager, type Class } from '@travetto/base';
1
+ import type { Class } from '@travetto/base';
2
2
  import type { ModelStorageSupport } from '@travetto/model/src/service/storage';
3
3
  import type { ModelType } from '@travetto/model/src/types/model';
4
4
 
@@ -11,6 +11,5 @@ export class ModelInstallUtil {
11
11
  console.log('Installing', { name: m.Ⲑid });
12
12
  await provider.createModel(m);
13
13
  }
14
- ShutdownManager.execute(-1); // Release database
15
14
  }
16
15
  }
@@ -1,7 +1,7 @@
1
1
  /** @jsxImportSource @travetto/doc */
2
- import { readFileSync } from 'fs';
2
+ import { readFileSync } from 'node:fs';
3
3
 
4
- import { RootIndex } from '@travetto/manifest';
4
+ import { RuntimeIndex } from '@travetto/manifest';
5
5
  import { d, c, DocJSXElementByFn, DocJSXElement } from '@travetto/doc';
6
6
  import { Config } from '@travetto/config';
7
7
 
@@ -16,7 +16,7 @@ export const Links = {
16
16
 
17
17
  export const ModelTypes = (file: string | Function): DocJSXElement[] => {
18
18
  if (typeof file !== 'string') {
19
- file = RootIndex.getFunctionMetadata(file)!.source;
19
+ file = RuntimeIndex.getFunctionMetadata(file)!.source;
20
20
  }
21
21
  const contents = readFileSync(file, 'utf8');
22
22
  const found: DocJSXElementByFn<'CodeLink'>[] = [];
@@ -1,4 +1,4 @@
1
- import assert from 'assert';
1
+ import assert from 'node:assert';
2
2
 
3
3
  import { Suite, Test } from '@travetto/test';
4
4
  import { ModelCrudSupport, Model, NotFoundError } from '@travetto/model';
@@ -1,4 +1,4 @@
1
- import assert from 'assert';
1
+ import assert from 'node:assert';
2
2
 
3
3
  import { Suite, Test } from '@travetto/test';
4
4
 
@@ -1,4 +1,4 @@
1
- import assert from 'assert';
1
+ import assert from 'node:assert';
2
2
 
3
3
  import { Suite, Test } from '@travetto/test';
4
4
  import { Schema, Text, Precision, } from '@travetto/schema';
@@ -1,4 +1,5 @@
1
- import assert from 'assert';
1
+ import assert from 'node:assert';
2
+ import timers from 'node:timers/promises';
2
3
 
3
4
  import { Suite, Test } from '@travetto/test';
4
5
  import { TimeSpan, TimeUnit, TimeUtil } from '@travetto/base';
@@ -22,7 +23,7 @@ export abstract class ModelExpirySuite extends BaseModelSuite<ModelExpirySupport
22
23
  delayFactor: number = 1;
23
24
 
24
25
  async wait(n: number | TimeSpan) {
25
- await TimeUtil.wait(TimeUtil.timeToMs(n) * this.delayFactor);
26
+ await timers.setTimeout(TimeUtil.timeToMs(n) * this.delayFactor);
26
27
  }
27
28
 
28
29
  timeFromNow(v: number | TimeSpan, unit?: TimeUnit) {
@@ -1,4 +1,4 @@
1
- import assert from 'assert';
1
+ import assert from 'node:assert';
2
2
 
3
3
  import { Suite, Test } from '@travetto/test';
4
4
  import { Schema } from '@travetto/schema';
@@ -1,5 +1,5 @@
1
- import assert from 'assert';
2
- import timers from 'timers/promises';
1
+ import assert from 'node:assert';
2
+ import timers from 'node:timers/promises';
3
3
 
4
4
  import { Suite, Test } from '@travetto/test';
5
5
  import { SubTypeField, Text, TypeMismatchError } from '@travetto/schema';
@@ -1,7 +1,8 @@
1
- import fs from 'fs/promises';
2
- import assert from 'assert';
3
- import crypto from 'crypto';
4
- import { Readable } from 'stream';
1
+ import fs from 'node:fs/promises';
2
+ import assert from 'node:assert';
3
+ import crypto from 'node:crypto';
4
+ import { Readable } from 'node:stream';
5
+ import { pipeline } from 'node:stream/promises';
5
6
 
6
7
  import { Suite, Test, TestFixtures } from '@travetto/test';
7
8
  import { StreamUtil } from '@travetto/base';
@@ -15,14 +16,9 @@ export abstract class ModelStreamSuite extends BaseModelSuite<ModelStreamSupport
15
16
  fixture = new TestFixtures(['@travetto/model']);
16
17
 
17
18
  async getHash(stream: Readable): Promise<string> {
18
- const hash = crypto.createHash('sha1');
19
- hash.setEncoding('hex');
20
- await new Promise((res, rej) => {
21
- stream.on('end', res);
22
- stream.on('error', rej);
23
- stream.pipe(hash);
24
- });
25
- return hash.read() as string;
19
+ const hasher = crypto.createHash('sha1').setEncoding('hex');
20
+ await pipeline(stream, hasher);
21
+ return hasher.read().toString();
26
22
  }
27
23
 
28
24
  async getStream(resource: string): Promise<readonly [{ size: number, contentType: string, hash: string, filename: string }, Readable]> {