@travetto/model 3.1.8 → 3.1.10

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
@@ -205,7 +205,7 @@ export interface ModelBulkSupport extends ModelCrudSupport {
205
205
  ```
206
206
 
207
207
  ## Declaration
208
- Models are declared via the [@Model](https://github.com/travetto/travetto/tree/main/module/model/src/registry/decorator.ts#L12) decorator, which allows the system to know that this is a class that is compatible with the module. The only requirement for a model is the [ModelType](https://github.com/travetto/travetto/tree/main/module/model/src/types/model.ts#L9)
208
+ Models are declared via the [@Model](https://github.com/travetto/travetto/tree/main/module/model/src/registry/decorator.ts#L13) decorator, which allows the system to know that this is a class that is compatible with the module. The only requirement for a model is the [ModelType](https://github.com/travetto/travetto/tree/main/module/model/src/types/model.ts#L9)
209
209
 
210
210
  **Code: ModelType**
211
211
  ```typescript
@@ -216,10 +216,6 @@ export interface ModelType {
216
216
  * If not provided, will be computed on create
217
217
  */
218
218
  id: string;
219
- /**
220
- * Type of model to save
221
- */
222
- type?: string;
223
219
  /**
224
220
  * Run before saving
225
221
  */
@@ -384,7 +380,7 @@ export class MemoryPolymorphicSuite extends ModelPolymorphismSuite {
384
380
  ```
385
381
 
386
382
  ## CLI - model:export
387
- The module provides the ability to generate an export of the model structure from all the various [@Model](https://github.com/travetto/travetto/tree/main/module/model/src/registry/decorator.ts#L12)s within the application. This is useful for being able to generate the appropriate files to manually create the data schemas in production.
383
+ The module provides the ability to generate an export of the model structure from all the various [@Model](https://github.com/travetto/travetto/tree/main/module/model/src/registry/decorator.ts#L13)s within the application. This is useful for being able to generate the appropriate files to manually create the data schemas in production.
388
384
 
389
385
  **Terminal: Running model export**
390
386
  ```bash
@@ -407,7 +403,7 @@ Models
407
403
  ```
408
404
 
409
405
  ## CLI - model:install
410
- The module provides the ability to install all the various [@Model](https://github.com/travetto/travetto/tree/main/module/model/src/registry/decorator.ts#L12)s within the application given the current configuration being targeted. This is useful for being able to prepare the datastore manually.
406
+ The module provides the ability to install all the various [@Model](https://github.com/travetto/travetto/tree/main/module/model/src/registry/decorator.ts#L13)s within the application given the current configuration being targeted. This is useful for being able to prepare the datastore manually.
411
407
 
412
408
  **Terminal: Running model install**
413
409
  ```bash
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@travetto/model",
3
- "version": "3.1.8",
3
+ "version": "3.1.10",
4
4
  "description": "Datastore abstraction for core operations.",
5
5
  "keywords": [
6
6
  "datastore",
@@ -26,13 +26,13 @@
26
26
  "directory": "module/model"
27
27
  },
28
28
  "dependencies": {
29
- "@travetto/config": "^3.1.2",
29
+ "@travetto/config": "^3.1.4",
30
30
  "@travetto/di": "^3.1.1",
31
31
  "@travetto/registry": "^3.1.1",
32
- "@travetto/schema": "^3.1.2"
32
+ "@travetto/schema": "^3.1.4"
33
33
  },
34
34
  "peerDependencies": {
35
- "@travetto/cli": "^3.1.2",
35
+ "@travetto/cli": "^3.1.4",
36
36
  "@travetto/test": "^3.1.1"
37
37
  },
38
38
  "peerDependenciesMeta": {
@@ -1,4 +1,5 @@
1
1
  import { Class } from '@travetto/base';
2
+ import { SchemaRegistry } from '@travetto/schema';
2
3
 
3
4
  import { ModelType } from '../types/model';
4
5
  import { ModelRegistry } from './model';
@@ -15,6 +16,7 @@ export function Model(conf: Partial<ModelOptions<ModelType>> | string = {}) {
15
16
  conf = { store: conf };
16
17
  }
17
18
  ModelRegistry.register(target, conf);
19
+ SchemaRegistry.register(target, { baseType: conf.baseType });
18
20
  return target;
19
21
  };
20
22
  }
@@ -63,9 +63,9 @@ class $ModelRegistry extends MetadataRegistry<ModelOptions<ModelType>> {
63
63
  const view = schema.views[AllViewⲐ].schema;
64
64
  delete view.id.required; // Allow ids to be optional
65
65
 
66
- if ('type' in view && this.getBaseModel(cls) !== cls) {
67
- config.subType = schema.subType; // Copy from schema
68
- delete view.type.required; // Allow type to be optional
66
+ if (schema.subTypeField in view && this.getBaseModel(cls) !== cls) {
67
+ config.subType = !!schema.subTypeName; // Copy from schema
68
+ delete view[schema.subTypeField].required; // Allow type to be optional
69
69
  }
70
70
  return config;
71
71
  }
@@ -134,8 +134,9 @@ class $ModelRegistry extends MetadataRegistry<ModelOptions<ModelType>> {
134
134
  getStore(cls: Class): string {
135
135
  if (!this.stores.has(cls)) {
136
136
  const config = this.get(cls) ?? this.getOrCreatePending(cls);
137
- if (config.subType) {
138
- return this.getStore(this.getBaseModel(cls));
137
+ const base = this.getBaseModel(cls);
138
+ if (base !== cls) {
139
+ return this.getStore(base);
139
140
  }
140
141
 
141
142
  const name = config.store ?? cls.name.toLowerCase();
@@ -13,10 +13,6 @@ export interface ModelType {
13
13
  * If not provided, will be computed on create
14
14
  */
15
15
  id: string;
16
- /**
17
- * Type of model to save
18
- */
19
- type?: string;
20
16
  /**
21
17
  * Run before saving
22
18
  */