@travetto/model
Advanced tools
Comparing version 0.1.8 to 0.2.0
@@ -7,9 +7,12 @@ { | ||
"dependencies": { | ||
"@travetto/di": "^0.1.6", | ||
"@travetto/schema": "^0.1.8" | ||
"@travetto/di": "^0.2.0", | ||
"@travetto/schema": "^0.2.0" | ||
}, | ||
"description": "Datastore abstraction for CRUD operations with advanced query support.", | ||
"devDependencies": { | ||
"@travetto/test": "^0.1.6" | ||
"@travetto/test": "^0.2.0" | ||
}, | ||
"optionalExtensionDependencies": { | ||
"@travetto/express": "^0.1.11" | ||
}, | ||
"homepage": "https://travetto.io", | ||
@@ -33,3 +36,3 @@ "keywords": [ | ||
}, | ||
"version": "0.1.8" | ||
"version": "0.2.0" | ||
} |
@@ -106,2 +106,52 @@ travetto: Model | ||
This would find all users who are over 35 and that have the `contact` field specified. | ||
This would find all users who are over 35 and that have the `contact` field specified. | ||
## Extensions | ||
Integration with other modules can be supported by extensions. The dependencies are `optionalExtensionDependencies` and must be installed directly if you want to use them: | ||
### Express | ||
[`Express`](https://github.com/travetto/express) support with the `@ModelController` for exposing common RESTful patterns for routes. | ||
```typescript | ||
@ModelController('/user', User) | ||
class UserController { | ||
source: ModelService; | ||
} | ||
``` | ||
is a shorthand that is equal to: | ||
```typescript | ||
@Controller('/user') | ||
class UserController { | ||
source: ModelService; | ||
@Get('') | ||
async getAllUser(req:Request) { | ||
return await this.source.getAllByQuery(User, JSON.parse(req.params.q)); | ||
} | ||
@Get(':id') | ||
async getUser(req:Request) { | ||
return await this.source.getById(User, req.params.id); | ||
} | ||
@Delete(':id') | ||
async deleteUser(req:Request) { | ||
return await this.source.deleteById(User, req.params.id); | ||
} | ||
@Post('') | ||
@SchemaBody(User) | ||
async saveUser(req:TypedBody<User>) { | ||
return await this.source.save(User, req.body); | ||
} | ||
@Put('') | ||
@SchemaBody(User) | ||
async updateUser(req:TypedBody<User>) { | ||
return await this.source.update(User, req.body); | ||
} | ||
} | ||
``` |
import { Class } from '@travetto/registry'; | ||
import { ModelRegistry, IndexConfig } from '../service'; | ||
import { ModelRegistry } from '../service'; | ||
import { IndexConfig } from '../types'; | ||
@@ -4,0 +5,0 @@ function createIndex<T extends Class>(target: T, config: IndexConfig<T>) { |
import { Class } from '@travetto/registry'; | ||
import { ModelRegistry, ModelOptions } from '../service'; | ||
import { ModelRegistry } from '../service'; | ||
import { ModelOptions } from '../types'; | ||
@@ -4,0 +5,0 @@ export function Model(conf: Partial<ModelOptions<any>> = {}) { |
export * from './decorator'; | ||
export * from './model'; | ||
export * from './service'; | ||
export * from './service'; | ||
export * from './types'; |
@@ -0,5 +1,5 @@ | ||
import { Class } from '@travetto/registry'; | ||
import { Schema } from '@travetto/schema'; | ||
import { ModelCore } from './model'; | ||
import { ModelRegistry } from '../service'; | ||
import { Class } from '@travetto/registry'; | ||
@@ -6,0 +6,0 @@ @Schema() |
export * from './model'; | ||
export * from './types'; | ||
export * from './registry'; | ||
export * from './source'; | ||
export * from './class-model'; |
import { Class } from '@travetto/registry'; | ||
import { BindUtil, SchemaValidator, DEFAULT_VIEW } from '@travetto/schema'; | ||
import { Injectable } from '@travetto/di'; | ||
import { Env, Util } from '@travetto/base'; | ||
import { QueryVerifierService } from './query'; | ||
import { Injectable } from '@travetto/di'; | ||
import { ModelOptions } from './types'; | ||
import { ModelOptions } from '../types'; | ||
import { ModelCore, Query, BulkState, ModelQuery, PageableModelQuery } from '../model'; | ||
@@ -10,4 +12,2 @@ import { ModelSource } from './source'; | ||
import { Env, Util } from '@travetto/base'; | ||
function getClass<T>(o: T) { | ||
@@ -14,0 +14,0 @@ return o.constructor as Class<T>; |
@@ -1,7 +0,8 @@ | ||
import { ModelQuery, Query, PageableModelQuery } from '../../model'; | ||
import { Class } from '@travetto/registry'; | ||
import { SimpleType, ErrorCollector, OPERATORS, TypeUtil } from './types'; | ||
import { SchemaRegistry } from '@travetto/schema'; | ||
import { Injectable } from '@travetto/di'; | ||
import { Util } from '@travetto/base'; | ||
import { ModelQuery, Query, PageableModelQuery } from '../../model'; | ||
import { SimpleType, ErrorCollector, OPERATORS, TypeUtil } from './types'; | ||
import { ValidationErrors } from './error'; | ||
@@ -8,0 +9,0 @@ |
@@ -5,3 +5,3 @@ import { SchemaRegistry, SchemaChangeEvent } from '@travetto/schema'; | ||
import { ModelOptions } from './types'; | ||
import { ModelOptions } from '../types'; | ||
@@ -8,0 +8,0 @@ export class $ModelRegistry extends MetadataRegistry<ModelOptions<any>> { |
{ | ||
"compilerOptions": { | ||
"module": "commonjs", | ||
"target": "es2017", | ||
"target": "es2018", | ||
"strict": true, | ||
@@ -6,0 +6,0 @@ "noStrictGenericChecks": true, |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
50986
35
1246
156
8
294
+ Added@travetto/base@0.2.11(transitive)
+ Added@travetto/compiler@0.2.10(transitive)
+ Added@travetto/config@0.2.10(transitive)
+ Added@travetto/di@0.2.14(transitive)
+ Added@travetto/registry@0.2.10(transitive)
+ Added@travetto/schema@0.2.15(transitive)
+ Addedcommander@2.20.3(transitive)
+ Addedtypescript@3.9.10(transitive)
- Removed@travetto/base@0.1.4(transitive)
- Removed@travetto/compiler@0.1.5(transitive)
- Removed@travetto/config@0.1.4(transitive)
- Removed@travetto/di@0.1.6(transitive)
- Removed@travetto/registry@0.1.5(transitive)
- Removed@travetto/schema@0.1.8(transitive)
- Removed@types/faker@4.1.12(transitive)
- Removedfaker@4.1.0(transitive)
- Removedtypescript@2.9.2(transitive)
Updated@travetto/di@^0.2.0
Updated@travetto/schema@^0.2.0