@travetto/model 3.0.2 → 3.0.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.
package/README.md CHANGED
@@ -1,6 +1,7 @@
1
1
  <!-- This file was generated by @travetto/doc and should not be modified directly -->
2
- <!-- Please modify https://github.com/travetto/travetto/tree/main/module/model/DOC.ts and execute "npx trv doc" to rebuild -->
2
+ <!-- Please modify https://github.com/travetto/travetto/tree/main/module/model/DOC.tsx and execute "npx trv doc" to rebuild -->
3
3
  # Data Modeling Support
4
+
4
5
  ## Datastore abstraction for core operations.
5
6
 
6
7
  **Install: @travetto/model**
@@ -15,11 +16,10 @@ yarn add @travetto/model
15
16
  This module provides a set of contracts/interfaces to data model persistence, modification and retrieval. This module builds heavily upon the [Schema](https://github.com/travetto/travetto/tree/main/module/schema#readme "Data type registry for runtime validation, reflection and binding."), which is used for data model validation.
16
17
 
17
18
  ## Contracts
18
-
19
19
  The module is mainly composed of contracts. The contracts define the expected interface for various model patterns. The primary contracts are [Basic](https://github.com/travetto/travetto/tree/main/module/model/src/service/basic.ts#L9), [CRUD](https://github.com/travetto/travetto/tree/main/module/model/src/service/crud.ts#L11), [Indexed](https://github.com/travetto/travetto/tree/main/module/model/src/service/indexed.ts#L12), [Expiry](https://github.com/travetto/travetto/tree/main/module/model/src/service/expiry.ts#L11), [Streaming](https://github.com/travetto/travetto/tree/main/module/model/src/service/stream.ts#L3) and [Bulk](https://github.com/travetto/travetto/tree/main/module/model/src/service/bulk.ts#L19).
20
20
 
21
- ### [Basic](https://github.com/travetto/travetto/tree/main/module/model/src/service/basic.ts#L9)
22
- All [Data Modeling Support](https://github.com/travetto/travetto/tree/main/module/model#readme "Datastore abstraction for core operations.") implementations, must honor the BasicCrud contract to be able to participate in the model ecosystem. This contract represents the bare minimum for a model service.
21
+ ### Basic
22
+ All [Data Modeling Support](https://github.com/travetto/travetto/tree/main/module/model#readme "Datastore abstraction for core operations.") implementations, must honor the [Basic](https://github.com/travetto/travetto/tree/main/module/model/src/service/basic.ts#L9) contract to be able to participate in the model ecosystem. This contract represents the bare minimum for a model service.
23
23
 
24
24
  **Code: Basic Contract**
25
25
  ```typescript
@@ -52,8 +52,8 @@ export interface ModelBasicSupport<C = unknown> {
52
52
  }
53
53
  ```
54
54
 
55
- ### [CRUD](https://github.com/travetto/travetto/tree/main/module/model/src/service/crud.ts#L11)
56
- The crud contract, builds upon the basic contract, and is built around the idea of simple data retrieval and storage, to create a foundation for other services that need only basic support. The model extension in [Authentication](https://github.com/travetto/travetto/tree/main/module/auth#readme "Authentication scaffolding for the Travetto framework"), is an example of a module that only needs create, read and delete, and so any implementation of [Data Modeling Support](https://github.com/travetto/travetto/tree/main/module/model#readme "Datastore abstraction for core operations.") that honors this contract, can be used with the [Authentication](https://github.com/travetto/travetto/tree/main/module/auth#readme "Authentication scaffolding for the Travetto framework") model extension.
55
+ ### CRUD
56
+ The [CRUD](https://github.com/travetto/travetto/tree/main/module/model/src/service/crud.ts#L11) contract, builds upon the basic contract, and is built around the idea of simple data retrieval and storage, to create a foundation for other services that need only basic support. The model extension in [Authentication](https://github.com/travetto/travetto/tree/main/module/auth#readme "Authentication scaffolding for the Travetto framework"), is an example of a module that only needs create, read and delete, and so any implementation of [Data Modeling Support](https://github.com/travetto/travetto/tree/main/module/model#readme "Datastore abstraction for core operations.") that honors this contract, can be used with the [Authentication](https://github.com/travetto/travetto/tree/main/module/auth#readme "Authentication scaffolding for the Travetto framework") model extension.
57
57
 
58
58
  **Code: Crud Contract**
59
59
  ```typescript
@@ -95,9 +95,8 @@ export interface ModelCrudSupport extends ModelBasicSupport {
95
95
  }
96
96
  ```
97
97
 
98
- ### [Indexed](https://github.com/travetto/travetto/tree/main/module/model/src/service/indexed.ts#L12)
99
- Additionally, an implementation may support the ability for basic indexed queries. This is not the full featured query support of [Data Model Querying](https://github.com/travetto/travetto/tree/main/module/model-query#readme "Datastore abstraction for advanced query support."), but
100
- allowing for indexed lookups. This does not support listing by index, but may be added at a later date.
98
+ ### Indexed
99
+ Additionally, an implementation may support the ability for basic [Indexed](https://github.com/travetto/travetto/tree/main/module/model/src/service/indexed.ts#L12) queries. This is not the full featured query support of [Data Model Querying](https://github.com/travetto/travetto/tree/main/module/model-query#readme "Datastore abstraction for advanced query support."), but allowing for indexed lookups. This does not support listing by index, but may be added at a later date.
101
100
 
102
101
  **Code: Indexed Contract**
103
102
  ```typescript
@@ -136,9 +135,8 @@ export interface ModelIndexedSupport extends ModelBasicSupport {
136
135
  }
137
136
  ```
138
137
 
139
- ### [Expiry](https://github.com/travetto/travetto/tree/main/module/model/src/service/expiry.ts#L11)
140
-
141
- Certain implementations will also provide support for automatic expiry of data at runtime. This is extremely useful for temporary data as, and is used in the [Caching](https://github.com/travetto/travetto/tree/main/module/cache#readme "Caching functionality with decorators for declarative use.") module for expiring data accordingly.
138
+ ### Expiry
139
+ Certain implementations will also provide support for automatic [Expiry](https://github.com/travetto/travetto/tree/main/module/model/src/service/expiry.ts#L11) of data at runtime. This is extremely useful for temporary data as, and is used in the [Caching](https://github.com/travetto/travetto/tree/main/module/cache#readme "Caching functionality with decorators for declarative use.") module for expiring data accordingly.
142
140
 
143
141
  **Code: Expiry Contract**
144
142
  ```typescript
@@ -152,9 +150,8 @@ export interface ModelExpirySupport extends ModelCrudSupport {
152
150
  }
153
151
  ```
154
152
 
155
- ### [Streaming](https://github.com/travetto/travetto/tree/main/module/model/src/service/stream.ts#L3)
156
-
157
- Some implementations also allow for the ability to read/write binary data as a stream. Given that all implementations can store [Base64](https://en.wikipedia.org/wiki/Base64) encoded data, the key differentiator here, is native support for streaming data, as well as being able to store binary data of significant sizes. This pattern is currently used by [Asset](https://github.com/travetto/travetto/tree/main/module/asset#readme "Modular library for storing and retrieving binary assets") for reading and writing asset data.
153
+ ### Stream
154
+ Some implementations also allow for the ability to read/write binary data as a [Streaming](https://github.com/travetto/travetto/tree/main/module/model/src/service/stream.ts#L3). Given that all implementations can store [Base64](https://en.wikipedia.org/wiki/Base64) encoded data, the key differentiator here, is native support for streaming data, as well as being able to store binary data of significant sizes. This pattern is currently used by [Asset](https://github.com/travetto/travetto/tree/main/module/asset#readme "Modular library for storing and retrieving binary assets") for reading and writing asset data.
158
155
 
159
156
  **Code: Stream Contract**
160
157
  ```typescript
@@ -188,9 +185,8 @@ export interface ModelStreamSupport {
188
185
  }
189
186
  ```
190
187
 
191
- ### [Bulk](https://github.com/travetto/travetto/tree/main/module/model/src/service/bulk.ts#L19)
192
-
193
- Finally, there is support for bulk operations. This is not to simply imply issuing many commands at in parallel, but implementation support for an atomic/bulk operation. This should allow for higher throughput on data ingest, and potentially for atomic support on transactions.
188
+ ### Bulk
189
+ Finally, there is support for [Bulk](https://github.com/travetto/travetto/tree/main/module/model/src/service/bulk.ts#L19) operations. This is not to simply imply issuing many commands at in parallel, but implementation support for an atomic/bulk operation. This should allow for higher throughput on data ingest, and potentially for atomic support on transactions.
194
190
 
195
191
  **Code: Bulk Contract**
196
192
  ```typescript
@@ -229,7 +225,6 @@ export interface ModelType {
229
225
  All fields are optional, but the `id` and `type` are important as those field types are unable to be changed. This may make using existing data models impossible if types other than strings are required. Additionally, the type field, is intended to record the base model type and cannot be remapped. This is important to support polymorphism, not only in [Data Modeling Support](https://github.com/travetto/travetto/tree/main/module/model#readme "Datastore abstraction for core operations."), but also in [Schema](https://github.com/travetto/travetto/tree/main/module/schema#readme "Data type registry for runtime validation, reflection and binding.").
230
226
 
231
227
  ## Implementations
232
-
233
228
  |Service|Basic|CRUD|Indexed|Expiry|Stream|Bulk|
234
229
  |-------|-----|----|-------|------|------|----|
235
230
  |[DynamoDB Model Support](https://github.com/travetto/travetto/tree/main/module/model-dynamodb#readme "DynamoDB backing for the travetto model module.")|X|X|X|X| | |
@@ -243,8 +238,7 @@ All fields are optional, but the `id` and `type` are important as those field ty
243
238
  |[FileModelService](https://github.com/travetto/travetto/tree/main/module/model/src/provider/file.ts#L51)|X|X| |X|X|X|
244
239
 
245
240
  ## Custom Model Service
246
- In addition to the provided contracts, the module also provides common utilities and shared test suites. The common utilities are useful for
247
- repetitive functionality, that is unable to be shared due to not relying upon inheritance (this was an intentional design decision). This allows for all the [Data Modeling Support](https://github.com/travetto/travetto/tree/main/module/model#readme "Datastore abstraction for core operations.") implementations to completely own the functionality and also to be able to provide additional/unique functionality that goes beyond the interface.
241
+ In addition to the provided contracts, the module also provides common utilities and shared test suites. The common utilities are useful for repetitive functionality, that is unable to be shared due to not relying upon inheritance (this was an intentional design decision). This allows for all the [Data Modeling Support](https://github.com/travetto/travetto/tree/main/module/model#readme "Datastore abstraction for core operations.") implementations to completely own the functionality and also to be able to provide additional/unique functionality that goes beyond the interface.
248
242
 
249
243
  **Code: Memory Service**
250
244
  ```typescript
@@ -381,7 +375,6 @@ export class MemoryPolymorphicSuite extends ModelPolymorphismSuite {
381
375
  ```
382
376
 
383
377
  ## CLI - model:export
384
-
385
378
  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.
386
379
 
387
380
  **Terminal: Running model export**
@@ -396,7 +389,6 @@ Options:
396
389
  ```
397
390
 
398
391
  ## CLI - model:install
399
-
400
392
  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.
401
393
 
402
394
  **Terminal: Running model install**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@travetto/model",
3
- "version": "3.0.2",
3
+ "version": "3.0.3",
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.0.2",
30
- "@travetto/di": "^3.0.2",
31
- "@travetto/registry": "^3.0.2",
32
- "@travetto/schema": "^3.0.2"
29
+ "@travetto/config": "^3.0.3",
30
+ "@travetto/di": "^3.0.3",
31
+ "@travetto/registry": "^3.0.3",
32
+ "@travetto/schema": "^3.0.3"
33
33
  },
34
34
  "peerDependencies": {
35
- "@travetto/cli": "^3.0.2",
36
- "@travetto/test": "^3.0.2"
35
+ "@travetto/cli": "^3.0.3",
36
+ "@travetto/test": "^3.0.3"
37
37
  },
38
38
  "peerDependenciesMeta": {
39
39
  "@travetto/cli": {
@@ -0,0 +1,46 @@
1
+ /** @jsxImportSource @travetto/doc */
2
+ import { readFileSync } from 'fs';
3
+
4
+ import { RootIndex } from '@travetto/manifest';
5
+ import { d, c, DocJSXElementByFn, DocJSXElement } from '@travetto/doc';
6
+ import { Config } from '@travetto/config';
7
+
8
+ export const Links = {
9
+ Basic: d.codeLink('Basic', '@travetto/model/src/service/basic.ts', /export interface/),
10
+ Crud: d.codeLink('CRUD', '@travetto/model/src/service/crud.ts', /export interface/),
11
+ Expiry: d.codeLink('Expiry', '@travetto/model/src/service/expiry.ts', /export interface/),
12
+ Indexed: d.codeLink('Indexed', '@travetto/model/src/service/indexed.ts', /export interface/),
13
+ Bulk: d.codeLink('Bulk', '@travetto/model/src/service/bulk.ts', /export interface/),
14
+ Stream: d.codeLink('Streaming', '@travetto/model/src/service/stream.ts', /export interface/),
15
+ };
16
+
17
+ export const ModelTypes = (file: string | Function): DocJSXElement[] => {
18
+ if (typeof file !== 'string') {
19
+ file = RootIndex.getFunctionMetadata(file)!.source;
20
+ }
21
+ const contents = readFileSync(file, 'utf8');
22
+ const found: DocJSXElementByFn<'CodeLink'>[] = [];
23
+ const seen = new Set();
24
+ for (const [, key] of contents.matchAll(/Model(Crud|Expiry|Indexed|Bulk|Stream)Support/g)) {
25
+ if (!seen.has(key)) {
26
+ seen.add(key);
27
+ // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
28
+ found.push(Links[key as keyof typeof Links]);
29
+ }
30
+ }
31
+ return found.map(v => <li>{v}</li>);
32
+ };
33
+
34
+ export const ModelCustomConfig = ({ cfg }: { cfg: Function }): JSXElement => <>
35
+ Out of the box, by installing the module, everything should be wired up by default.If you need to customize any aspect of the source
36
+ or config, you can override and register it with the {d.mod('Di')} module.
37
+
38
+ <c.Code title='Wiring up a custom Model Source' src='doc/custom-service.ts' />
39
+
40
+ where the {cfg} is defined by:
41
+
42
+ <c.Code title={`Structure of ${cfg.name}`} src={cfg} />
43
+
44
+ Additionally, you can see that the class is registered with the {Config} annotation, and so these values can be overridden using the
45
+ standard {d.mod('Config')}resolution paths.
46
+ </>;
@@ -1,46 +0,0 @@
1
- import { readFileSync } from 'fs';
2
-
3
- import { RootIndex } from '@travetto/manifest';
4
- import { d, mod } from '@travetto/doc';
5
- import { Config } from '@travetto/config';
6
- import { AllType, AllTypeMap } from '@travetto/doc/src/nodes';
7
-
8
- export const Links = {
9
- Basic: d.SnippetLink('Basic', '@travetto/model/src/service/basic.ts', /export interface/),
10
- Crud: d.SnippetLink('CRUD', '@travetto/model/src/service/crud.ts', /export interface/),
11
- Expiry: d.SnippetLink('Expiry', '@travetto/model/src/service/expiry.ts', /export interface/),
12
- Indexed: d.SnippetLink('Indexed', '@travetto/model/src/service/indexed.ts', /export interface/),
13
- Bulk: d.SnippetLink('Bulk', '@travetto/model/src/service/bulk.ts', /export interface/),
14
- Stream: d.SnippetLink('Streaming', '@travetto/model/src/service/stream.ts', /export interface/),
15
- };
16
-
17
- export const ModelTypes = (file: string | Function): AllTypeMap['SnippetLink'][] => {
18
- if (typeof file !== 'string') {
19
- file = RootIndex.getFunctionMetadata(file)!.source;
20
- }
21
- const contents = readFileSync(file, 'utf8');
22
- const found: AllTypeMap['SnippetLink'][] = [];
23
- const seen = new Set();
24
- for (const [, key] of contents.matchAll(/Model(Crud|Expiry|Indexed|Bulk|Stream)Support/g)) {
25
- if (!seen.has(key)) {
26
- seen.add(key);
27
- // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
28
- found.push(Links[key as keyof typeof Links]);
29
- }
30
- }
31
- return found;
32
- };
33
-
34
- export const ModelCustomConfig = (cfg: Function): AllType => d`
35
- Out of the box, by installing the module, everything should be wired up by default.If you need to customize any aspect of the source
36
- or config, you can override and register it with the ${mod.Di} module.
37
-
38
- ${d.Code('Wiring up a custom Model Source', 'doc/custom-service.ts')}
39
-
40
- where the ${cfg} is defined by:
41
-
42
- ${d.Code(`Structure of ${cfg.name}`, cfg)}
43
-
44
- Additionally, you can see that the class is registered with the ${Config} annotation, and so these values can be overridden using the
45
- standard ${mod.Config}resolution paths.
46
- `;