@travetto/model
Advanced tools
Comparing version 0.0.41 to 0.1.1
@@ -7,8 +7,8 @@ { | ||
"dependencies": { | ||
"@travetto/di": "^0.0.33", | ||
"@travetto/schema": "^0.0.36" | ||
"@travetto/di": "^0.1.1", | ||
"@travetto/schema": "^0.1.1" | ||
}, | ||
"description": "Datastore abstraction for CRUD operations with advanced query support.", | ||
"devDependencies": { | ||
"@travetto/test": "^0.0.83" | ||
"@travetto/test": "^0.1.1" | ||
}, | ||
@@ -33,3 +33,3 @@ "homepage": "https://travetto.io", | ||
}, | ||
"version": "0.0.41" | ||
"version": "0.1.1" | ||
} |
@@ -10,3 +10,3 @@ import { Class } from '@travetto/registry'; | ||
import { AppEnv, deepAssign } from '@travetto/base'; | ||
import { Env, Util } from '@travetto/base'; | ||
@@ -32,3 +32,3 @@ function getClass<T>(o: T) { | ||
await ModelRegistry.init(); | ||
if (AppEnv.watch) { | ||
if (Env.watch) { | ||
if (this.source.onSchemaChange) { | ||
@@ -43,2 +43,3 @@ ModelRegistry.onSchemaChange(this.source.onSchemaChange.bind(this.source)); | ||
/** Handles subtyping on polymorphic endpoints */ | ||
convert<T extends ModelCore>(cls: Class<T>, o: T) { | ||
@@ -60,2 +61,3 @@ const config = ModelRegistry.get(cls); | ||
/** Handles any pre-persistance activities needed */ | ||
async prePersist<T extends ModelCore>(cls: Class<T>, o: T): Promise<T>; | ||
@@ -72,2 +74,3 @@ async prePersist<T extends ModelCore>(cls: Class<T>, o: Partial<T>, view: string): Promise<Partial<T>>; | ||
/** Handles any pre-retrieval activities needed */ | ||
postLoad<T extends ModelCore>(cls: Class<T>, o: T): T; | ||
@@ -85,2 +88,3 @@ postLoad<T extends ModelCore>(cls: Class<T>, o: Partial<T>, view: string): Partial<T>; | ||
/** Executes a raw query against the model space */ | ||
async query<T extends ModelCore, U = T>(cls: Class<T>, query: Query<T>) { | ||
@@ -93,2 +97,3 @@ this.queryService.verify(cls, query); | ||
/** Retrieves all instances of cls that match query */ | ||
async getAllByQuery<T extends ModelCore>(cls: Class<T>, query: PageableModelQuery<T> = {}) { | ||
@@ -105,2 +110,3 @@ this.queryService.verify(cls, query); | ||
/** Find the count of matching documetns by query */ | ||
getCountByQuery<T extends ModelCore>(cls: Class<T>, query: ModelQuery<T> = {}) { | ||
@@ -112,2 +118,3 @@ this.queryService.verify(cls, query); | ||
/** Find one by query, fail if not found */ | ||
async getByQuery<T extends ModelCore>(cls: Class<T>, query: PageableModelQuery<T> = {}, failOnMany: boolean = true) { | ||
@@ -120,2 +127,3 @@ this.queryService.verify(cls, query); | ||
/** Save or update, upsert, for a document */ | ||
async saveOrUpdate<T extends ModelCore>(cls: Class<T>, o: T, query: ModelQuery<T>) { | ||
@@ -126,3 +134,3 @@ this.queryService.verify(cls, query); | ||
if (res.length === 1) { | ||
o = deepAssign(res[0], o); | ||
o = Util.deepAssign(res[0], o); | ||
return await this.update(cls, o); | ||
@@ -135,2 +143,3 @@ } else if (res.length === 0) { | ||
/** Find one by id */ | ||
async getById<T extends ModelCore>(cls: Class<T>, id: string) { | ||
@@ -141,2 +150,3 @@ const res = await this.source.getById(cls, id); | ||
/** Delete one by id */ | ||
deleteById<T extends ModelCore>(cls: Class<T>, id: string) { | ||
@@ -146,2 +156,3 @@ return this.source.deleteById(cls, id); | ||
/** Delete all by query */ | ||
deleteByQuery<T extends ModelCore>(cls: Class<T>, query: ModelQuery<T> = {}) { | ||
@@ -153,2 +164,3 @@ this.queryService.verify(cls, query); | ||
/** Save a new instance */ | ||
async save<T extends ModelCore>(cls: Class<T>, o: T) { | ||
@@ -160,2 +172,3 @@ o = await this.prePersist(cls, o); | ||
/** Save all as new instances */ | ||
async saveAll<T extends ModelCore>(cls: Class<T>, objs: T[]) { | ||
@@ -167,2 +180,3 @@ objs = await Promise.all(objs.map(o => this.prePersist(cls, o))); | ||
/** Update/replace an existing record */ | ||
async update<T extends ModelCore>(cls: Class<T>, o: T) { | ||
@@ -174,2 +188,3 @@ o = await this.prePersist(cls, o); | ||
/** Update/replace all with partial data, by query */ | ||
updateAllByQuery<T extends ModelCore>(cls: Class<T>, query: ModelQuery<T>, data: Partial<T>) { | ||
@@ -181,6 +196,9 @@ this.queryService.verify(cls, query); | ||
updatePartial<T extends ModelCore>(cls: Class<T>, model: Partial<T>) { | ||
return this.source.updatePartial(cls, model); | ||
/** Partial update single record, by id */ | ||
async updatePartial<T extends ModelCore>(cls: Class<T>, model: Partial<T>) { | ||
const res = await this.source.updatePartial(cls, model); | ||
return this.postLoad(cls, res); | ||
} | ||
/** Partial update, by query*/ | ||
async updatePartialByQuery<T extends ModelCore>(cls: Class<T>, query: ModelQuery<T>, body: Partial<T>) { | ||
@@ -196,2 +214,3 @@ this.queryService.verify(cls, query); | ||
/** Partial update single record, by view and by id */ | ||
async updatePartialView<T extends ModelCore>(cls: Class<T>, o: Partial<T>, view: string) { | ||
@@ -204,2 +223,3 @@ o = await this.prePersist(cls, o, view); | ||
/** Partial update by view and by query */ | ||
async updatePartialViewByQuery<T extends ModelCore>(cls: Class<T>, o: Partial<T>, view: string, query: ModelQuery<T>) { | ||
@@ -214,2 +234,3 @@ this.queryService.verify(cls, query); | ||
/** Bulk create/update/delete */ | ||
bulkProcess<T extends ModelCore>(cls: Class<T>, state: BulkState<T>) { | ||
@@ -216,0 +237,0 @@ return this.source.bulkProcess(cls, state); |
@@ -6,3 +6,3 @@ import { ModelQuery, Query, PageableModelQuery } from '../../model'; | ||
import { Injectable } from '@travetto/di'; | ||
import { isPlainObject } from '@travetto/base'; | ||
import { Util } from '@travetto/base'; | ||
import { ValidationErrors } from './error'; | ||
@@ -108,3 +108,3 @@ | ||
if (!isPlainObject(value)) { | ||
if (!Util.isPlainObject(value)) { | ||
// Ha ndle literal | ||
@@ -174,3 +174,3 @@ const actualType = TypeUtil.getActualType(value); | ||
} else if (firstKey === $NOT) { | ||
if (isPlainObject(sub)) { | ||
if (Util.isPlainObject(sub)) { | ||
this.processWhereClause(state, cls, sub); | ||
@@ -177,0 +177,0 @@ return true; |
@@ -1,12 +0,11 @@ | ||
import { View } from '@travetto/schema'; | ||
import { Model, ModelService, WhereClause, PageableModelQuery, Query } from '../index'; | ||
import * as assert from 'assert'; | ||
import { DependencyRegistry } from '@travetto/di'; | ||
import { RootRegistry } from '@travetto/registry'; | ||
import { Test, Suite, BeforeAll } from '@travetto/test'; | ||
import { ModelService } from '../index'; | ||
import { TestSource } from './registry'; | ||
import { Person, Address } from './models'; | ||
import { Test, Suite, BeforeAll } from '@travetto/test'; | ||
import * as assert from 'assert'; | ||
import { DependencyRegistry } from '@travetto/di'; | ||
import { RootRegistry, Class } from '@travetto/registry'; | ||
import { RetainFields } from '../src/model/query/common'; | ||
const street1 = '1234 Fun'; | ||
@@ -13,0 +12,0 @@ |
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
42470
973
8
294
+ Added@travetto/base@0.1.4(transitive)
+ Added@travetto/compiler@0.1.5(transitive)
+ Added@travetto/config@0.1.4(transitive)
+ Added@travetto/di@0.1.6(transitive)
+ Added@travetto/registry@0.1.5(transitive)
+ Added@travetto/schema@0.1.8(transitive)
- Removed@travetto/base@0.0.162(transitive)
- Removed@travetto/compiler@0.0.48(transitive)
- Removed@travetto/config@0.0.40(transitive)
- Removed@travetto/di@0.0.33(transitive)
- Removed@travetto/registry@0.0.50(transitive)
- Removed@travetto/schema@0.0.36(transitive)
Updated@travetto/di@^0.1.1
Updated@travetto/schema@^0.1.1