reactivedb
Advanced tools
Comparing version 0.10.3 to 0.10.4-alpha.1
@@ -1,14 +0,13 @@ | ||
import { ReactiveDBException } from './Exception'; | ||
export declare const NonExistentTable: (tableName: string) => ReactiveDBException; | ||
export declare const UnmodifiableTable: () => ReactiveDBException; | ||
export declare const InvalidQuery: () => ReactiveDBException; | ||
export declare const AliasConflict: (column: string, tableName: string) => ReactiveDBException; | ||
export declare const GraphFailed: (err: Error) => ReactiveDBException; | ||
export declare const NotImplemented: () => ReactiveDBException; | ||
export declare const UnexpectedRelationship: () => ReactiveDBException; | ||
export declare const InvalidType: (expect?: [string, string] | undefined) => ReactiveDBException; | ||
export declare const UnexpectedTransactionUse: () => ReactiveDBException; | ||
export declare const PrimaryKeyNotProvided: () => ReactiveDBException; | ||
export declare const PrimaryKeyConflict: () => ReactiveDBException; | ||
export declare const DatabaseIsNotEmpty: () => ReactiveDBException; | ||
export declare const NotConnected: () => ReactiveDBException; | ||
export declare const NonExistentTable: (tableName: string) => string; | ||
export declare const UnmodifiableTable: () => string; | ||
export declare const InvalidQuery: () => string; | ||
export declare const AliasConflict: (column: string, tableName: string) => string; | ||
export declare const GraphFailed: (err: Error) => string; | ||
export declare const NotImplemented: () => string; | ||
export declare const UnexpectedRelationship: () => string; | ||
export declare const InvalidType: (expect?: [string, string] | undefined) => string; | ||
export declare const UnexpectedTransactionUse: () => string; | ||
export declare const PrimaryKeyNotProvided: () => string; | ||
export declare const PrimaryKeyConflict: () => string; | ||
export declare const DatabaseIsNotEmpty: () => string; | ||
export declare const NotConnected: () => string; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var Exception_1 = require("./Exception"); | ||
exports.NonExistentTable = function (tableName) { return new Exception_1.ReactiveDBException("Table: `" + tableName + "` cannot be found."); }; | ||
exports.UnmodifiableTable = function () { return new Exception_1.ReactiveDBException("Method: defineSchema cannot be invoked since schema is existed or database is connected"); }; | ||
exports.InvalidQuery = function () { return new Exception_1.ReactiveDBException('Only navigation properties were included in query.'); }; | ||
exports.AliasConflict = function (column, tableName) { return new Exception_1.ReactiveDBException("Definition conflict, Column: `" + column + "` on table: " + tableName + "."); }; | ||
exports.GraphFailed = function (err) { return new Exception_1.ReactiveDBException("Graphify query result failed, due to: " + err.message + "."); }; | ||
exports.NotImplemented = function () { return new Exception_1.ReactiveDBException('Not implemented yet.'); }; | ||
exports.UnexpectedRelationship = function () { return new Exception_1.ReactiveDBException('Unexpected relationship was specified.'); }; | ||
exports.NonExistentTable = function (tableName) { return "Table: `" + tableName + "` cannot be found."; }; | ||
exports.UnmodifiableTable = function () { return "Method: defineSchema cannot be invoked since schema is existed or database is connected"; }; | ||
exports.InvalidQuery = function () { return 'Only navigation properties were included in query.'; }; | ||
exports.AliasConflict = function (column, tableName) { return "Definition conflict, Column: `" + column + "` on table: " + tableName + "."; }; | ||
exports.GraphFailed = function (err) { return "Graphify query result failed, due to: " + err.message + "."; }; | ||
exports.NotImplemented = function () { return 'Not implemented yet.'; }; | ||
exports.UnexpectedRelationship = function () { return 'Unexpected relationship was specified.'; }; | ||
exports.InvalidType = function (expect) { | ||
@@ -16,9 +15,9 @@ var message = 'Unexpected data type'; | ||
} | ||
return new Exception_1.ReactiveDBException(message + '.'); | ||
return message + '.'; | ||
}; | ||
exports.UnexpectedTransactionUse = function () { return new Exception_1.ReactiveDBException('Please use Database#transaction to get a transaction scope first.'); }; | ||
exports.PrimaryKeyNotProvided = function () { return new Exception_1.ReactiveDBException("Primary key was not provided."); }; | ||
exports.PrimaryKeyConflict = function () { return new Exception_1.ReactiveDBException("Primary key was already provided."); }; | ||
exports.DatabaseIsNotEmpty = function () { return new Exception_1.ReactiveDBException('Method: load cannnot be invoked since database is not empty.'); }; | ||
exports.NotConnected = function () { return new Exception_1.ReactiveDBException('Method: dispose cannnot be invoked before database is connected.'); }; | ||
exports.UnexpectedTransactionUse = function () { return 'Please use Database#transaction to get a transaction scope first.'; }; | ||
exports.PrimaryKeyNotProvided = function () { return "Primary key was not provided."; }; | ||
exports.PrimaryKeyConflict = function () { return "Primary key was already provided."; }; | ||
exports.DatabaseIsNotEmpty = function () { return 'Method: load cannnot be invoked since database is not empty.'; }; | ||
exports.NotConnected = function () { return 'Method: dispose cannnot be invoked before database is connected.'; }; | ||
//# sourceMappingURL=database.js.map |
@@ -1,7 +0,3 @@ | ||
export interface ReactiveDBException extends Error { | ||
export declare class ReactiveDBException extends Error { | ||
constructor(message: string); | ||
} | ||
export interface ReactiveDBExceptionCtor { | ||
new (message: string): ReactiveDBException; | ||
readonly prototype: ReactiveDBException; | ||
} | ||
export declare const ReactiveDBException: ReactiveDBExceptionCtor; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
function ReactiveDBExceptionCtor(message) { | ||
var err = Error.call(this, message); | ||
this.name = err.name; | ||
this.message = message; | ||
this.stack = err.stack; | ||
return this; | ||
} | ||
ReactiveDBExceptionCtor.prototype = Object.create(Error.prototype, { | ||
constructor: { | ||
value: ReactiveDBExceptionCtor, | ||
enumerable: false, | ||
writable: true, | ||
configurable: true | ||
var tslib_1 = require("tslib"); | ||
var ReactiveDBException = /** @class */ (function (_super) { | ||
tslib_1.__extends(ReactiveDBException, _super); | ||
function ReactiveDBException(message) { | ||
var _this = _super.call(this, message) || this; | ||
_this.name = 'ReactiveDBError'; | ||
Object.setPrototypeOf(_this, ReactiveDBException.prototype); | ||
return _this; | ||
} | ||
}); | ||
exports.ReactiveDBException = ReactiveDBExceptionCtor; | ||
return ReactiveDBException; | ||
}(Error)); | ||
exports.ReactiveDBException = ReactiveDBException; | ||
//# sourceMappingURL=Exception.js.map |
@@ -1,2 +0,5 @@ | ||
export * from './database'; | ||
export * from './token'; | ||
import * as dbErrMsg from './database'; | ||
import * as tokenErrMsg from './token'; | ||
export { dbErrMsg }; | ||
export { tokenErrMsg }; | ||
export { ReactiveDBException as Exception } from './Exception'; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var tslib_1 = require("tslib"); | ||
tslib_1.__exportStar(require("./database"), exports); | ||
tslib_1.__exportStar(require("./token"), exports); | ||
var dbErrMsg = require("./database"); | ||
exports.dbErrMsg = dbErrMsg; | ||
var tokenErrMsg = require("./token"); | ||
exports.tokenErrMsg = tokenErrMsg; | ||
var Exception_1 = require("./Exception"); | ||
exports.Exception = Exception_1.ReactiveDBException; | ||
//# sourceMappingURL=index.js.map |
@@ -1,3 +0,2 @@ | ||
import { ReactiveDBException } from './Exception'; | ||
export declare const TokenConsumed: () => ReactiveDBException; | ||
export declare const TokenConcatFailed: (msg?: string | undefined) => ReactiveDBException; | ||
export declare const TokenConsumed: () => string; | ||
export declare const TokenConcatFailed: (msg?: string | undefined) => string; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var Exception_1 = require("./Exception"); | ||
exports.TokenConsumed = function () { return new Exception_1.ReactiveDBException('QueryToken was already consumed.'); }; | ||
exports.TokenConsumed = function () { return 'QueryToken was already consumed.'; }; | ||
exports.TokenConcatFailed = function (msg) { | ||
var errMsg = 'Token cannot be concated' + ((msg ? ' due to: ' + msg : '') + "."); | ||
return new Exception_1.ReactiveDBException(errMsg); | ||
return errMsg; | ||
}; | ||
//# sourceMappingURL=token.js.map |
@@ -5,3 +5,5 @@ "use strict"; | ||
if (typeof global !== 'undefined') { | ||
global['self'] = global; | ||
if (!global['self']) { | ||
global['self'] = global; | ||
} | ||
// shim for SinonJS | ||
@@ -8,0 +10,0 @@ if (!global['location']) { |
@@ -0,1 +1,2 @@ | ||
import './operators'; | ||
import './global'; | ||
@@ -2,0 +3,0 @@ import 'tslib'; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var tslib_1 = require("tslib"); | ||
require("./operators"); | ||
require("./global"); | ||
@@ -5,0 +6,0 @@ require("tslib"); |
{ | ||
"name": "reactivedb", | ||
"version": "0.10.3", | ||
"version": "0.10.4-alpha.1", | ||
"description": "Reactive ORM for Lovefield", | ||
@@ -20,3 +20,3 @@ "main": "./index.js", | ||
"lint": "tslint -c tslint.json src/*.ts --project ./tsconfig.json \"src/**/*.ts\" \"./test/**/*.ts\" -e \"./test/e2e/*.ts\"", | ||
"publish_all": "ts-node ./tools/publish.ts", | ||
"publish_all": "node ./tools/publish.js", | ||
"start": "webpack-dev-server --inline --colors --progress --port 3000", | ||
@@ -26,3 +26,3 @@ "start-demo": "webpack-dev-server --config ./example/webpack.config.js --inline --colors --progress --port 3001 --open", | ||
"test_O1": "npm run lint && NODE_ENV=test optimize=true tman --mocha spec-js/test/run.js", | ||
"version": "ts-node tools/version.ts && git add .", | ||
"version": "node tools/version.js && git add .", | ||
"watch": "NODE_ENV=test ts-node ./tools/watch.ts & npm run watch_test", | ||
@@ -32,2 +32,5 @@ "watch_cjs": "tsc src/index.ts -m commonjs --outDir dist --sourcemap --target ES5 -d --diagnostics --pretty --strict --noImplicitReturns --suppressImplicitAnyIndexErrors --moduleResolution node --noEmitHelpers --lib es5,es2015.iterable,es2015.collection,es2015.promise,dom -w", | ||
}, | ||
"resolutions": { | ||
"yeoman-generator": "^2.0.3" | ||
}, | ||
"keywords": [ | ||
@@ -34,0 +37,0 @@ "lovefield", |
@@ -1,23 +0,21 @@ | ||
import { ReactiveDBException } from './Exception' | ||
export const NonExistentTable = | ||
(tableName: string) => new ReactiveDBException(`Table: \`${tableName}\` cannot be found.`) | ||
(tableName: string) => `Table: \`${tableName}\` cannot be found.` | ||
export const UnmodifiableTable = | ||
() => new ReactiveDBException(`Method: defineSchema cannot be invoked since schema is existed or database is connected`) | ||
() => `Method: defineSchema cannot be invoked since schema is existed or database is connected` | ||
export const InvalidQuery = | ||
() => new ReactiveDBException('Only navigation properties were included in query.') | ||
() => 'Only navigation properties were included in query.' | ||
export const AliasConflict = | ||
(column: string, tableName: string) => new ReactiveDBException(`Definition conflict, Column: \`${column}\` on table: ${tableName}.`) | ||
(column: string, tableName: string) => `Definition conflict, Column: \`${column}\` on table: ${tableName}.` | ||
export const GraphFailed = | ||
(err: Error) => new ReactiveDBException(`Graphify query result failed, due to: ${err.message}.`) | ||
(err: Error) => `Graphify query result failed, due to: ${err.message}.` | ||
export const NotImplemented = | ||
() => new ReactiveDBException('Not implemented yet.') | ||
() => 'Not implemented yet.' | ||
export const UnexpectedRelationship = | ||
() => new ReactiveDBException('Unexpected relationship was specified.') | ||
() => 'Unexpected relationship was specified.' | ||
@@ -30,18 +28,18 @@ export const InvalidType = | ||
} | ||
return new ReactiveDBException(message + '.') | ||
return message + '.' | ||
} | ||
export const UnexpectedTransactionUse = | ||
() => new ReactiveDBException('Please use Database#transaction to get a transaction scope first.') | ||
() => 'Please use Database#transaction to get a transaction scope first.' | ||
export const PrimaryKeyNotProvided = | ||
() => new ReactiveDBException(`Primary key was not provided.`) | ||
() => `Primary key was not provided.` | ||
export const PrimaryKeyConflict = | ||
() => new ReactiveDBException(`Primary key was already provided.`) | ||
() => `Primary key was already provided.` | ||
export const DatabaseIsNotEmpty = | ||
() => new ReactiveDBException('Method: load cannnot be invoked since database is not empty.') | ||
() => 'Method: load cannnot be invoked since database is not empty.' | ||
export const NotConnected = | ||
() => new ReactiveDBException('Method: dispose cannnot be invoked before database is connected.') | ||
() => 'Method: dispose cannnot be invoked before database is connected.' |
@@ -1,25 +0,9 @@ | ||
export interface ReactiveDBException extends Error { } | ||
export class ReactiveDBException extends Error { | ||
export interface ReactiveDBExceptionCtor { | ||
new(message: string): ReactiveDBException | ||
readonly prototype: ReactiveDBException | ||
} | ||
constructor(message: string) { | ||
super(message) | ||
this.name = 'ReactiveDBError'; | ||
(Object as any).setPrototypeOf(this, ReactiveDBException.prototype) | ||
} | ||
function ReactiveDBExceptionCtor(this: ReactiveDBException, message: string): ReactiveDBException { | ||
const err = Error.call(this, message) | ||
this.name = err.name | ||
this.message = message | ||
this.stack = err.stack | ||
return this | ||
} | ||
ReactiveDBExceptionCtor.prototype = Object.create(Error.prototype, { | ||
constructor: { | ||
value: ReactiveDBExceptionCtor, | ||
enumerable: false, | ||
writable: true, | ||
configurable: true | ||
} | ||
}) | ||
export const ReactiveDBException = ReactiveDBExceptionCtor as any as ReactiveDBExceptionCtor |
@@ -1,2 +0,7 @@ | ||
export * from './database' | ||
export * from './token' | ||
import * as dbErrMsg from './database' | ||
import * as tokenErrMsg from './token' | ||
export { dbErrMsg } | ||
export { tokenErrMsg } | ||
export { ReactiveDBException as Exception } from './Exception' |
@@ -1,5 +0,3 @@ | ||
import { ReactiveDBException } from './Exception' | ||
export const TokenConsumed = | ||
() => new ReactiveDBException('QueryToken was already consumed.') | ||
() => 'QueryToken was already consumed.' | ||
@@ -9,3 +7,3 @@ export const TokenConcatFailed = | ||
const errMsg = 'Token cannot be concated' + `${ msg ? ' due to: ' + msg : '' }.` | ||
return new ReactiveDBException(errMsg) | ||
return errMsg | ||
} |
// lovefield nodejs polyfill | ||
if (typeof global !== 'undefined') { | ||
global['self'] = global | ||
if (!global['self']) { | ||
global['self'] = global | ||
} | ||
// shim for SinonJS | ||
@@ -5,0 +7,0 @@ if (!global['location']) { |
@@ -0,1 +1,2 @@ | ||
import './operators' | ||
import './global' | ||
@@ -2,0 +3,0 @@ import 'tslib' |
import { Observable } from 'rxjs/Observable' | ||
import { ErrorObservable } from 'rxjs/observable/ErrorObservable' | ||
import { Subscription } from 'rxjs/Subscription' | ||
import { from } from 'rxjs/observable/from' | ||
import { fromPromise } from 'rxjs/observable/fromPromise' | ||
import { of as just } from 'rxjs/observable/of' | ||
import { ConnectableObservable } from 'rxjs/observable/ConnectableObservable' | ||
@@ -12,3 +9,3 @@ import { concatMap } from 'rxjs/operators/concatMap' | ||
import * as lf from 'lovefield' | ||
import * as Exception from '../exception' | ||
import { dbErrMsg, Exception } from '../exception' | ||
import * as typeDefinition from './helper/definition' | ||
@@ -19,3 +16,3 @@ import Version from '../version' | ||
import { dispose, contextTableName, fieldIdentifier, hiddenColName } from './symbols' | ||
import { forEach, clone, contains, tryCatch, hasOwn, getType, assert, assertValue, warn, isNonNullable } from '../utils' | ||
import { forEach, clone, contains, tryCatch, hasOwn, getType, assert, identity, warn } from '../utils' | ||
import { createPredicate, createPkClause, mergeTransactionResult, predicatableQuery, lfFactory } from './helper' | ||
@@ -48,3 +45,3 @@ import { Relationship, RDBType, DataStoreType, LeafType, StatementType, JoinMode } from '../interface/enum' | ||
private storedIds = new Set<string>() | ||
private subscription: Subscription | null = null | ||
private subscription: Subscription | ||
@@ -57,3 +54,4 @@ private findPrimaryKey = (name: string) => { | ||
const schema = this.schemas.get(name) | ||
return assertValue(schema, Exception.NonExistentTable(name)) | ||
assert(schema, dbErrMsg.NonExistentTable(name)) | ||
return schema! | ||
} | ||
@@ -67,7 +65,7 @@ | ||
const advanced = !this.schemaDefs.has(tableName) && !this.connected | ||
assert(advanced, Exception.UnmodifiableTable()) | ||
assert(advanced, dbErrMsg.UnmodifiableTable()) | ||
const hasPK = Object.keys(schema) | ||
.some((key: string) => schema[key].primaryKey === true) | ||
assert(hasPK, Exception.PrimaryKeyNotProvided()) | ||
assert(hasPK, dbErrMsg.PrimaryKeyNotProvided()) | ||
@@ -109,3 +107,3 @@ this.schemaDefs.set(tableName, schema) | ||
load(data: any) { | ||
assert(!this.connected, Exception.DatabaseIsNotEmpty()) | ||
assert(!this.connected, dbErrMsg.DatabaseIsNotEmpty()) | ||
@@ -190,3 +188,3 @@ const load = (db: lf.Database) => { | ||
if (type !== 'Object') { | ||
return Observable.throw(Exception.InvalidType(['Object', type])) | ||
return Observable.throw(new Exception(dbErrMsg.InvalidType(['Object', type]))) | ||
} | ||
@@ -269,3 +267,3 @@ | ||
return fromPromise(prefetch.exec()) | ||
return Observable.fromPromise(prefetch.exec()) | ||
.pipe(concatMap(deleteByScopedIds)) | ||
@@ -302,3 +300,3 @@ } | ||
} else { | ||
return just({ result: false, insert: 0, update: 0, delete: 0, select: 0 }) | ||
return Observable.of({ result: false, insert: 0, update: 0, delete: 0, select: 0 }) | ||
} | ||
@@ -356,3 +354,3 @@ } | ||
const prefetch = predicatableQuery(db, table, predicate!, StatementType.Select) | ||
return fromPromise(prefetch.exec()).pipe( | ||
return Observable.fromPromise(prefetch.exec()).pipe( | ||
concatMap(removeByRootEntities) | ||
@@ -367,3 +365,3 @@ ) | ||
if (!this.connected) { | ||
return Observable.throw(Exception.NotConnected()) | ||
return Observable.throw(new Exception(dbErrMsg.NotConnected())) | ||
} | ||
@@ -379,3 +377,3 @@ | ||
this.schemaBuilder = null | ||
this.subscription!.unsubscribe() | ||
this.subscription.unsubscribe() | ||
}) | ||
@@ -389,3 +387,3 @@ ) | ||
attachTx(_: TransactionEffects) { | ||
throw Exception.UnexpectedTransactionUse() | ||
throw new Exception(dbErrMsg.UnexpectedTransactionUse()) | ||
} | ||
@@ -396,3 +394,3 @@ | ||
return fromPromise(tx.exec(queries)).pipe( | ||
return Observable.fromPromise(tx.exec(queries)).pipe( | ||
tap(transactionErrorHandler), | ||
@@ -428,3 +426,3 @@ map((ret) => { | ||
transactionQueries.push(...queries) | ||
return just(null) | ||
return Observable.of(null) | ||
} | ||
@@ -444,3 +442,3 @@ } | ||
return acc.pipe(tap(curr)) | ||
}, from(tx.exec(transactionQueries))).pipe( | ||
}, Observable.from(tx.exec(transactionQueries))).pipe( | ||
map((r) => { | ||
@@ -506,3 +504,3 @@ return { | ||
if (def.primaryKey) { | ||
assert(!primaryKey[0], Exception.PrimaryKeyConflict()) | ||
assert(!primaryKey[0], dbErrMsg.PrimaryKeyConflict()) | ||
primaryKey.push(key) | ||
@@ -519,3 +517,3 @@ } | ||
const isNullable = ![def.primaryKey, def.index, def.unique].some(isNonNullable) | ||
const isNullable = ![def.primaryKey, def.index, def.unique].some(identity) | ||
if (isNullable) { | ||
@@ -632,3 +630,3 @@ nullable.push(key) | ||
default: | ||
throw Exception.InvalidType() | ||
throw new Exception(dbErrMsg.InvalidType()) | ||
} | ||
@@ -671,3 +669,3 @@ } | ||
.every(key => contains(key, navigators)) | ||
assert(!onlyNavigator, Exception.InvalidQuery()) | ||
assert(!onlyNavigator, dbErrMsg.InvalidQuery()) | ||
@@ -692,3 +690,3 @@ if (!hasKey) { | ||
columns.push(...ret.columns) | ||
assert(!rootDefinition[key], Exception.AliasConflict(key, tableName)) | ||
assert(!rootDefinition[key], dbErrMsg.AliasConflict(key, tableName)) | ||
@@ -785,3 +783,3 @@ if ((defs as ColumnDef).column) { | ||
const pkVal = compoundEntites[pk] | ||
assert(pkVal !== undefined, Exception.PrimaryKeyNotProvided()) | ||
assert(pkVal !== undefined, dbErrMsg.PrimaryKeyNotProvided()) | ||
@@ -893,3 +891,3 @@ const [ table ] = Database.getTables(db, tableName) | ||
return fromPromise<T[]>(query.exec() as any) | ||
return Observable.fromPromise<T[]>(query.exec() as any) | ||
} | ||
@@ -896,0 +894,0 @@ |
@@ -5,3 +5,3 @@ import { forEach } from '../../utils' | ||
import { Relationship } from '../../interface' | ||
import * as Exception from '../../exception' | ||
import { Exception, dbErrMsg } from '../../exception' | ||
@@ -21,5 +21,5 @@ export function revise(relation: Relationship, def: Object) { | ||
case Relationship.manyToMany: | ||
throw Exception.NotImplemented() | ||
throw new Exception(dbErrMsg.NotImplemented()) | ||
default: | ||
throw Exception.UnexpectedRelationship() | ||
throw new Exception(dbErrMsg.UnexpectedRelationship()) | ||
} | ||
@@ -26,0 +26,0 @@ |
import { identity } from '../../utils' | ||
import * as Exception from '../../exception' | ||
import { Exception, dbErrMsg } from '../../exception' | ||
@@ -15,4 +15,4 @@ const nestJS = require('nesthydrationjs')() | ||
} catch (e) { | ||
throw Exception.GraphFailed(e) | ||
throw new Exception(dbErrMsg.GraphFailed(e)) | ||
} | ||
} |
import * as lf from 'lovefield' | ||
import { forEach, assertValue, warn } from '../../utils' | ||
import { forEach, assert, warn } from '../../utils' | ||
import { fieldIdentifier } from '../symbols' | ||
import * as Exception from '../../exception' | ||
import { dbErrMsg } from '../../exception' | ||
@@ -13,3 +13,3 @@ export class Mutation { | ||
val: any | ||
} | undefined | ||
} | ||
@@ -71,5 +71,6 @@ constructor( | ||
private toUpdater() { | ||
const meta = assertValue(this.meta, Exception.PrimaryKeyNotProvided()) | ||
assert(this.meta, dbErrMsg.PrimaryKeyNotProvided()) | ||
const query = this.db.update(this.table) | ||
query.where(this.table[meta.key].eq(meta.val)) | ||
query.where(this.table[this.meta.key].eq(this.meta.val)) | ||
@@ -89,7 +90,8 @@ forEach(this.params, (val, key) => { | ||
private toRow() { | ||
const meta = assertValue(this.meta, Exception.PrimaryKeyNotProvided()) | ||
assert(this.meta, dbErrMsg.PrimaryKeyNotProvided()) | ||
return { | ||
table: this.table, | ||
row: this.table.createRow({ | ||
[meta.key]: meta.val, | ||
[this.meta.key]: this.meta.val, | ||
...this.params | ||
@@ -101,3 +103,5 @@ }) | ||
patch(patch: Object) { | ||
this.params = { ...this.params, ...patch } | ||
forEach(patch, (val, key) => { | ||
this.params[key] = val | ||
}) | ||
return this | ||
@@ -104,0 +108,0 @@ } |
import { Observable } from 'rxjs/Observable' | ||
import { OperatorFunction } from 'rxjs/interfaces' | ||
import { from } from 'rxjs/observable/from' | ||
import { combineAll } from 'rxjs/operators/combineAll' | ||
@@ -12,2 +11,3 @@ import { map } from 'rxjs/operators/map' | ||
import { tap } from 'rxjs/operators/tap' | ||
import { filter } from 'rxjs/operators/filter' | ||
import { Selector } from './Selector' | ||
@@ -17,3 +17,8 @@ import { ProxySelector } from './ProxySelector' | ||
import { TokenConsumed } from '../../exception/token' | ||
import { diff, Ops, OpsType } from '../../utils/diff' | ||
export type TraceResult<T> = Ops & { | ||
result: T[] | ||
} | ||
export type SelectorMeta<T> = Selector<T> | ProxySelector<T> | ||
@@ -28,4 +33,5 @@ | ||
private consumed = false | ||
private lastEmit: T[] = [] | ||
constructor(selector$: Observable<SelectorMeta<T>>) { | ||
constructor(selector$: Observable<SelectorMeta<T>>, lastEmit?: T[]) { | ||
this.selector$ = selector$.pipe( | ||
@@ -35,4 +41,9 @@ publishReplay(1), | ||
) | ||
this.lastEmit = lastEmit || [] | ||
} | ||
setLastEmit(data: T[]) { | ||
this.lastEmit = data | ||
} | ||
map<K>(fn: OperatorFunction<T[], K[]>) { | ||
@@ -64,5 +75,16 @@ this.selector$ = this.selector$.pipe( | ||
traces(pk?: string): Observable<TraceResult<T>> { | ||
return this.changes().pipe( | ||
map((result: T[]) => { | ||
const ops = diff(this.lastEmit, result, pk) | ||
return { result, ...ops } | ||
}), | ||
filter((xs) => xs.type !== OpsType.ShouldSkip), | ||
tap(({ result }) => (this.lastEmit = result)), | ||
) | ||
} | ||
concat(...tokens: QueryToken<T>[]) { | ||
tokens.unshift(this) | ||
const newSelector$ = from(tokens).pipe( | ||
const newSelector$ = Observable.from(tokens).pipe( | ||
map(token => token.selector$.pipe(skipWhileProxySelector)), | ||
@@ -75,3 +97,3 @@ combineAll<Observable<Selector<T>>, Selector<T>[]>(), | ||
) | ||
return new QueryToken<T>(newSelector$) | ||
return new QueryToken<T>(newSelector$, this.lastEmit) | ||
} | ||
@@ -81,3 +103,3 @@ | ||
tokens.unshift(this) | ||
const newSelector$ = from(tokens).pipe( | ||
const newSelector$ = Observable.from(tokens).pipe( | ||
map(token => token.selector$.pipe(skipWhileProxySelector)), | ||
@@ -90,3 +112,3 @@ combineAll<Observable<Selector<T>>, Selector<T>[]>(), | ||
) | ||
return new QueryToken<T>(newSelector$) | ||
return new QueryToken<T>(newSelector$, this.lastEmit) | ||
} | ||
@@ -93,0 +115,0 @@ |
import { Observer } from 'rxjs/Observer' | ||
import { Observable } from 'rxjs/Observable' | ||
import { OperatorFunction } from 'rxjs/interfaces' | ||
import { filter } from 'rxjs/operators/filter' | ||
import { from } from 'rxjs/observable/from' | ||
import { fromPromise } from 'rxjs/observable/fromPromise' | ||
import { combineAll } from 'rxjs/operators/combineAll' | ||
@@ -14,9 +11,8 @@ import { debounceTime } from 'rxjs/operators/debounceTime' | ||
import { refCount } from 'rxjs/operators/refCount' | ||
import { scan } from 'rxjs/operators/scan' | ||
import { switchMap } from 'rxjs/operators/switchMap' | ||
import { async } from 'rxjs/scheduler/async' | ||
import * as lf from 'lovefield' | ||
import * as Exception from '../../exception' | ||
import { tokenErrMsg } from '../../exception' | ||
import { predicatableQuery, graph } from '../helper' | ||
import { identity, forEach, assert, warn, isNonNullable } from '../../utils' | ||
import { identity, forEach, assert, warn } from '../../utils' | ||
import { PredicateProvider } from './PredicateProvider' | ||
@@ -36,3 +32,3 @@ import { ShapeMatcher, OrderInfo, StatementType } from '../../interface' | ||
const nextSkip = acc.skip! + acc.limit! | ||
assert(current.skip === nextSkip, Exception.TokenConcatFailed(` | ||
assert(current.skip === nextSkip, tokenErrMsg.TokenConcatFailed(` | ||
skip should be serial, | ||
@@ -56,3 +52,3 @@ expect: ${JSON.stringify(acc, null, 2)} | ||
const dist = new Selector<U>(originalToken.db, fakeQuery as any, { } as any) | ||
dist.change$ = from(metaDatas).pipe( | ||
dist.change$ = Observable.from(metaDatas).pipe( | ||
map(metas => metas.mapFn(metas.change$)), | ||
@@ -66,5 +62,5 @@ combineAll<Observable<U[]>, U[][]>(), | ||
dist.values = () => { | ||
assert(!dist.consumed, Exception.TokenConsumed()) | ||
assert(!dist.consumed, tokenErrMsg.TokenConsumed()) | ||
dist.consumed = true | ||
return from(metaDatas).pipe( | ||
return Observable.from(metaDatas).pipe( | ||
mergeMap(metaData => metaData.values()), | ||
@@ -129,6 +125,5 @@ reduce((acc, val) => acc.concat(val)) | ||
return lfIssueFix(changesOnQuery).pipe( | ||
publishReplay(1), | ||
refCount() | ||
) | ||
return lfIssueFix(changesOnQuery) | ||
.publishReplay(1) | ||
.refCount() | ||
} | ||
@@ -214,5 +209,5 @@ | ||
.then(pks => this.getValue(this.getQuery(this.inPKs(pks)))) | ||
return this.mapFn(fromPromise(p)) | ||
return this.mapFn(Observable.fromPromise(p)) | ||
} else { | ||
return this.mapFn(fromPromise(this.getValue(this.getQuery()) as Promise<T[]>)) | ||
return this.mapFn(Observable.fromPromise(this.getValue(this.getQuery()) as Promise<T[]>)) | ||
} | ||
@@ -239,3 +234,3 @@ } | ||
) | ||
assert(equal, Exception.TokenConcatFailed()) | ||
assert(equal, tokenErrMsg.TokenConcatFailed()) | ||
@@ -328,6 +323,3 @@ return Selector.concatFactory(this, ...selectors) | ||
return changes.pipe( | ||
scan(doKeep, null), | ||
filter(isNonNullable) | ||
) | ||
return (changes as any).scan(doKeep, null).filter(Boolean) | ||
} |
@@ -1,24 +0,7 @@ | ||
import { Truthy } from './truthy' | ||
import { ReactiveDBException } from '../exception/Exception' | ||
export function assert(condition: boolean, error: Error | string): void { | ||
truthyOrThrow(condition, error) | ||
} | ||
export function assertValue<T>( | ||
value: T, | ||
error: Error | string | ||
): Truthy<T> | never { | ||
return truthyOrThrow(value, error) | ||
} | ||
function truthyOrThrow<T>(x: T, error: Error | string): Truthy<T> | never { | ||
if (x) { | ||
return x as Truthy<T> | ||
export function assert(condition: any, message: string) { | ||
if (!condition) { | ||
throw new ReactiveDBException(message) | ||
} | ||
if (error instanceof Error) { | ||
throw error | ||
} else { | ||
throw new Error(error) | ||
} | ||
} |
@@ -11,4 +11,4 @@ export * from './hash' | ||
export * from './get-type' | ||
export * from './truthy' | ||
export * from './try-catch' | ||
export * from './diff' | ||
export { warn } from './warn' |
import { Observable } from 'rxjs/Observable' | ||
import { empty } from 'rxjs/observable/empty' | ||
import { skip } from 'rxjs/operators/skip' | ||
@@ -12,3 +11,3 @@ import { ErrorObservable } from 'rxjs/observable/ErrorObservable' | ||
return empty<T>().pipe(skip(1)) | ||
return Observable.empty<T>().pipe(skip(1)) | ||
} |
@@ -1,1 +0,1 @@ | ||
export default '0.10.3' | ||
export default '0.10.4-alpha.10-diff-alpha0.10.4-alpha.10-diff-diff' |
@@ -5,5 +5,2 @@ "use strict"; | ||
var Observable_1 = require("rxjs/Observable"); | ||
var from_1 = require("rxjs/observable/from"); | ||
var fromPromise_1 = require("rxjs/observable/fromPromise"); | ||
var of_1 = require("rxjs/observable/of"); | ||
var concatMap_1 = require("rxjs/operators/concatMap"); | ||
@@ -13,3 +10,3 @@ var map_1 = require("rxjs/operators/map"); | ||
var lf = require("lovefield"); | ||
var Exception = require("../exception"); | ||
var exception_1 = require("../exception"); | ||
var typeDefinition = require("./helper/definition"); | ||
@@ -46,3 +43,2 @@ var version_1 = require("../version"); | ||
this.storedIds = new Set(); | ||
this.subscription = null; | ||
this.findPrimaryKey = function (name) { | ||
@@ -53,3 +49,4 @@ return _this.findSchema(name).pk; | ||
var schema = _this.schemas.get(name); | ||
return utils_1.assertValue(schema, Exception.NonExistentTable(name)); | ||
utils_1.assert(schema, exception_1.dbErrMsg.NonExistentTable(name)); | ||
return schema; | ||
}; | ||
@@ -72,6 +69,6 @@ this.schemaBuilder = lf.schema.create(name, version); | ||
var advanced = !this.schemaDefs.has(tableName) && !this.connected; | ||
utils_1.assert(advanced, Exception.UnmodifiableTable()); | ||
utils_1.assert(advanced, exception_1.dbErrMsg.UnmodifiableTable()); | ||
var hasPK = Object.keys(schema) | ||
.some(function (key) { return schema[key].primaryKey === true; }); | ||
utils_1.assert(hasPK, Exception.PrimaryKeyNotProvided()); | ||
utils_1.assert(hasPK, exception_1.dbErrMsg.PrimaryKeyNotProvided()); | ||
this.schemaDefs.set(tableName, schema); | ||
@@ -93,3 +90,3 @@ return this; | ||
var _this = this; | ||
utils_1.assert(!this.connected, Exception.DatabaseIsNotEmpty()); | ||
utils_1.assert(!this.connected, exception_1.dbErrMsg.DatabaseIsNotEmpty()); | ||
var load = function (db) { | ||
@@ -161,3 +158,3 @@ utils_1.forEach(data.tables, function (entities, name) { | ||
if (type !== 'Object') { | ||
return Observable_1.Observable.throw(Exception.InvalidType(['Object', type])); | ||
return Observable_1.Observable.throw(new exception_1.Exception(exception_1.dbErrMsg.InvalidType(['Object', type]))); | ||
} | ||
@@ -231,3 +228,3 @@ var _a = utils_1.tryCatch(this.findSchema)(tableName), schema = _a[0], err = _a[1]; | ||
}; | ||
return fromPromise_1.fromPromise(prefetch.exec()) | ||
return Observable_1.Observable.fromPromise(prefetch.exec()) | ||
.pipe(concatMap_1.concatMap(deleteByScopedIds)); | ||
@@ -255,3 +252,3 @@ }; | ||
else { | ||
return of_1.of({ result: false, insert: 0, update: 0, delete: 0, select: 0 }); | ||
return Observable_1.Observable.of({ result: false, insert: 0, update: 0, delete: 0, select: 0 }); | ||
} | ||
@@ -302,3 +299,3 @@ }; | ||
var prefetch = helper_1.predicatableQuery(db, table, predicate, enum_1.StatementType.Select); | ||
return fromPromise_1.fromPromise(prefetch.exec()).pipe(concatMap_1.concatMap(removeByRootEntities)); | ||
return Observable_1.Observable.fromPromise(prefetch.exec()).pipe(concatMap_1.concatMap(removeByRootEntities)); | ||
}; | ||
@@ -310,3 +307,3 @@ return this.database$.pipe(concatMap_1.concatMap(remove)); | ||
if (!this.connected) { | ||
return Observable_1.Observable.throw(Exception.NotConnected()); | ||
return Observable_1.Observable.throw(new exception_1.Exception(exception_1.dbErrMsg.NotConnected())); | ||
} | ||
@@ -326,7 +323,7 @@ var cleanUp = function (db) { | ||
Database.prototype.attachTx = function (_) { | ||
throw Exception.UnexpectedTransactionUse(); | ||
throw new exception_1.Exception(exception_1.dbErrMsg.UnexpectedTransactionUse()); | ||
}; | ||
Database.prototype.executor = function (db, queries) { | ||
var tx = db.createTransaction(); | ||
return fromPromise_1.fromPromise(tx.exec(queries)).pipe(tap_1.tap(transactionErrorHandler), map_1.map(function (ret) { | ||
return Observable_1.Observable.fromPromise(tx.exec(queries)).pipe(tap_1.tap(transactionErrorHandler), map_1.map(function (ret) { | ||
return tslib_1.__assign({ result: true }, helper_1.mergeTransactionResult(queries, ret)); | ||
@@ -353,3 +350,3 @@ })); | ||
transactionQueries.push.apply(transactionQueries, queries); | ||
return of_1.of(null); | ||
return Observable_1.Observable.of(null); | ||
}; | ||
@@ -368,3 +365,3 @@ } | ||
return acc.pipe(tap_1.tap(curr)); | ||
}, from_1.from(tx.exec(transactionQueries))).pipe(map_1.map(function (r) { | ||
}, Observable_1.Observable.from(tx.exec(transactionQueries))).pipe(map_1.map(function (r) { | ||
return tslib_1.__assign({ result: true }, helper_1.mergeTransactionResult(transactionQueries, r)); | ||
@@ -416,3 +413,3 @@ })); | ||
if (def.primaryKey) { | ||
utils_1.assert(!primaryKey[0], Exception.PrimaryKeyConflict()); | ||
utils_1.assert(!primaryKey[0], exception_1.dbErrMsg.PrimaryKeyConflict()); | ||
primaryKey.push(key); | ||
@@ -426,3 +423,3 @@ } | ||
} | ||
var isNullable = ![def.primaryKey, def.index, def.unique].some(utils_1.isNonNullable); | ||
var isNullable = ![def.primaryKey, def.index, def.unique].some(utils_1.identity); | ||
if (isNullable) { | ||
@@ -515,3 +512,3 @@ nullable.push(key); | ||
default: | ||
throw Exception.InvalidType(); | ||
throw new exception_1.Exception(exception_1.dbErrMsg.InvalidType()); | ||
} | ||
@@ -544,3 +541,3 @@ }; | ||
.every(function (key) { return utils_1.contains(key, navigators); }); | ||
utils_1.assert(!onlyNavigator, Exception.InvalidQuery()); | ||
utils_1.assert(!onlyNavigator, exception_1.dbErrMsg.InvalidQuery()); | ||
if (!hasKey) { | ||
@@ -561,3 +558,3 @@ // 保证主键一定比关联字段更早的被遍历到 | ||
columns.push.apply(columns, ret.columns); | ||
utils_1.assert(!rootDefinition[key], Exception.AliasConflict(key, tableName)); | ||
utils_1.assert(!rootDefinition[key], exception_1.dbErrMsg.AliasConflict(key, tableName)); | ||
if (defs.column) { | ||
@@ -633,3 +630,3 @@ rootDefinition[key] = defs; | ||
var pkVal = compoundEntites[pk]; | ||
utils_1.assert(pkVal !== undefined, Exception.PrimaryKeyNotProvided()); | ||
utils_1.assert(pkVal !== undefined, exception_1.dbErrMsg.PrimaryKeyNotProvided()); | ||
var table = Database.getTables(db, tableName)[0]; | ||
@@ -728,3 +725,3 @@ var identifier = symbols_1.fieldIdentifier(tableName, pkVal); | ||
var query = helper_1.predicatableQuery(db, table, predicate, enum_1.StatementType.Select); | ||
return fromPromise_1.fromPromise(query.exec()); | ||
return Observable_1.Observable.fromPromise(query.exec()); | ||
}; | ||
@@ -731,0 +728,0 @@ return [get, remove]; |
@@ -7,3 +7,3 @@ "use strict"; | ||
var interface_2 = require("../../interface"); | ||
var Exception = require("../../exception"); | ||
var exception_1 = require("../../exception"); | ||
function revise(relation, def) { | ||
@@ -22,5 +22,5 @@ switch (relation) { | ||
case interface_2.Relationship.manyToMany: | ||
throw Exception.NotImplemented(); | ||
throw new exception_1.Exception(exception_1.dbErrMsg.NotImplemented()); | ||
default: | ||
throw Exception.UnexpectedRelationship(); | ||
throw new exception_1.Exception(exception_1.dbErrMsg.UnexpectedRelationship()); | ||
} | ||
@@ -27,0 +27,0 @@ return def; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var utils_1 = require("../../utils"); | ||
var Exception = require("../../exception"); | ||
var exception_1 = require("../../exception"); | ||
var nestJS = require('nesthydrationjs')(); | ||
@@ -15,3 +15,3 @@ exports.LiteralArray = 'LiteralArray'; | ||
catch (e) { | ||
throw Exception.GraphFailed(e); | ||
throw new exception_1.Exception(exception_1.dbErrMsg.GraphFailed(e)); | ||
} | ||
@@ -18,0 +18,0 @@ } |
@@ -6,3 +6,3 @@ "use strict"; | ||
var symbols_1 = require("../symbols"); | ||
var Exception = require("../../exception"); | ||
var exception_1 = require("../../exception"); | ||
var Mutation = /** @class */ (function () { | ||
@@ -52,5 +52,5 @@ function Mutation(db, table, initialParams) { | ||
var _this = this; | ||
var meta = utils_1.assertValue(this.meta, Exception.PrimaryKeyNotProvided()); | ||
utils_1.assert(this.meta, exception_1.dbErrMsg.PrimaryKeyNotProvided()); | ||
var query = this.db.update(this.table); | ||
query.where(this.table[meta.key].eq(meta.val)); | ||
query.where(this.table[this.meta.key].eq(this.meta.val)); | ||
utils_1.forEach(this.params, function (val, key) { | ||
@@ -68,6 +68,6 @@ var column = _this.table[key]; | ||
Mutation.prototype.toRow = function () { | ||
var meta = utils_1.assertValue(this.meta, Exception.PrimaryKeyNotProvided()); | ||
utils_1.assert(this.meta, exception_1.dbErrMsg.PrimaryKeyNotProvided()); | ||
return { | ||
table: this.table, | ||
row: this.table.createRow(tslib_1.__assign((_a = {}, _a[meta.key] = meta.val, _a), this.params)) | ||
row: this.table.createRow(tslib_1.__assign((_a = {}, _a[this.meta.key] = this.meta.val, _a), this.params)) | ||
}; | ||
@@ -77,3 +77,6 @@ var _a; | ||
Mutation.prototype.patch = function (patch) { | ||
this.params = tslib_1.__assign({}, this.params, patch); | ||
var _this = this; | ||
utils_1.forEach(patch, function (val, key) { | ||
_this.params[key] = val; | ||
}); | ||
return this; | ||
@@ -80,0 +83,0 @@ }; |
@@ -5,2 +5,6 @@ import { Observable } from 'rxjs/Observable'; | ||
import { ProxySelector } from './ProxySelector'; | ||
import { Ops } from '../../utils/diff'; | ||
export declare type TraceResult<T> = Ops & { | ||
result: T[]; | ||
}; | ||
export declare type SelectorMeta<T> = Selector<T> | ProxySelector<T>; | ||
@@ -10,6 +14,9 @@ export declare class QueryToken<T> { | ||
private consumed; | ||
constructor(selector$: Observable<SelectorMeta<T>>); | ||
private lastEmit; | ||
constructor(selector$: Observable<SelectorMeta<T>>, lastEmit?: T[]); | ||
setLastEmit(data: T[]): void; | ||
map<K>(fn: OperatorFunction<T[], K[]>): QueryToken<K>; | ||
values(): Observable<T[]>; | ||
changes(): Observable<T[]>; | ||
traces(pk?: string): Observable<TraceResult<T>>; | ||
concat(...tokens: QueryToken<T>[]): QueryToken<T>; | ||
@@ -16,0 +23,0 @@ combine(...tokens: QueryToken<any>[]): QueryToken<T>; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var from_1 = require("rxjs/observable/from"); | ||
var tslib_1 = require("tslib"); | ||
var Observable_1 = require("rxjs/Observable"); | ||
var combineAll_1 = require("rxjs/operators/combineAll"); | ||
@@ -12,11 +13,18 @@ var map_1 = require("rxjs/operators/map"); | ||
var tap_1 = require("rxjs/operators/tap"); | ||
var filter_1 = require("rxjs/operators/filter"); | ||
var ProxySelector_1 = require("./ProxySelector"); | ||
var assert_1 = require("../../utils/assert"); | ||
var token_1 = require("../../exception/token"); | ||
var diff_1 = require("../../utils/diff"); | ||
var skipWhileProxySelector = skipWhile_1.skipWhile(function (v) { return v instanceof ProxySelector_1.ProxySelector; }); | ||
var QueryToken = /** @class */ (function () { | ||
function QueryToken(selector$) { | ||
function QueryToken(selector$, lastEmit) { | ||
this.consumed = false; | ||
this.lastEmit = []; | ||
this.selector$ = selector$.pipe(publishReplay_1.publishReplay(1), refCount_1.refCount()); | ||
this.lastEmit = lastEmit || []; | ||
} | ||
QueryToken.prototype.setLastEmit = function (data) { | ||
this.lastEmit = data; | ||
}; | ||
QueryToken.prototype.map = function (fn) { | ||
@@ -36,2 +44,12 @@ this.selector$ = this.selector$.pipe(tap_1.tap(function (selector) { return selector.map(fn); })); | ||
}; | ||
QueryToken.prototype.traces = function (pk) { | ||
var _this = this; | ||
return this.changes().pipe(map_1.map(function (result) { | ||
var ops = diff_1.diff(_this.lastEmit, result, pk); | ||
return tslib_1.__assign({ result: result }, ops); | ||
}), filter_1.filter(function (xs) { return xs.type !== diff_1.OpsType.ShouldSkip; }), tap_1.tap(function (_a) { | ||
var result = _a.result; | ||
return (_this.lastEmit = result); | ||
})); | ||
}; | ||
QueryToken.prototype.concat = function () { | ||
@@ -43,3 +61,3 @@ var tokens = []; | ||
tokens.unshift(this); | ||
var newSelector$ = from_1.from(tokens).pipe(map_1.map(function (token) { return token.selector$.pipe(skipWhileProxySelector); }), combineAll_1.combineAll(), map_1.map(function (r) { | ||
var newSelector$ = Observable_1.Observable.from(tokens).pipe(map_1.map(function (token) { return token.selector$.pipe(skipWhileProxySelector); }), combineAll_1.combineAll(), map_1.map(function (r) { | ||
var first = r.shift(); | ||
@@ -49,3 +67,3 @@ return (_a = first).concat.apply(_a, r); | ||
})); | ||
return new QueryToken(newSelector$); | ||
return new QueryToken(newSelector$, this.lastEmit); | ||
}; | ||
@@ -58,3 +76,3 @@ QueryToken.prototype.combine = function () { | ||
tokens.unshift(this); | ||
var newSelector$ = from_1.from(tokens).pipe(map_1.map(function (token) { return token.selector$.pipe(skipWhileProxySelector); }), combineAll_1.combineAll(), map_1.map(function (r) { | ||
var newSelector$ = Observable_1.Observable.from(tokens).pipe(map_1.map(function (token) { return token.selector$.pipe(skipWhileProxySelector); }), combineAll_1.combineAll(), map_1.map(function (r) { | ||
var first = r.shift(); | ||
@@ -64,3 +82,3 @@ return (_a = first).combine.apply(_a, r); | ||
})); | ||
return new QueryToken(newSelector$); | ||
return new QueryToken(newSelector$, this.lastEmit); | ||
}; | ||
@@ -67,0 +85,0 @@ QueryToken.prototype.toString = function () { |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var Observable_1 = require("rxjs/Observable"); | ||
var filter_1 = require("rxjs/operators/filter"); | ||
var from_1 = require("rxjs/observable/from"); | ||
var fromPromise_1 = require("rxjs/observable/fromPromise"); | ||
var combineAll_1 = require("rxjs/operators/combineAll"); | ||
@@ -14,7 +11,6 @@ var debounceTime_1 = require("rxjs/operators/debounceTime"); | ||
var refCount_1 = require("rxjs/operators/refCount"); | ||
var scan_1 = require("rxjs/operators/scan"); | ||
var switchMap_1 = require("rxjs/operators/switchMap"); | ||
var async_1 = require("rxjs/scheduler/async"); | ||
var lf = require("lovefield"); | ||
var Exception = require("../../exception"); | ||
var exception_1 = require("../../exception"); | ||
var helper_1 = require("../helper"); | ||
@@ -53,3 +49,3 @@ var utils_1 = require("../../utils"); | ||
var nextSkip = acc.skip + acc.limit; | ||
utils_1.assert(current.skip === nextSkip, Exception.TokenConcatFailed("\n skip should be serial,\n expect: " + JSON.stringify(acc, null, 2) + "\n actual: " + nextSkip + "\n ")); | ||
utils_1.assert(current.skip === nextSkip, exception_1.tokenErrMsg.TokenConcatFailed("\n skip should be serial,\n expect: " + JSON.stringify(acc, null, 2) + "\n actual: " + nextSkip + "\n ")); | ||
return current; | ||
@@ -69,7 +65,7 @@ }); | ||
var dist = new Selector(originalToken.db, fakeQuery, {}); | ||
dist.change$ = from_1.from(metaDatas).pipe(map_1.map(function (metas) { return metas.mapFn(metas.change$); }), combineAll_1.combineAll(), map_1.map(function (r) { return r.reduce(function (acc, val) { return acc.concat(val); }); }), debounceTime_1.debounceTime(0, async_1.async), publishReplay_1.publishReplay(1), refCount_1.refCount()); | ||
dist.change$ = Observable_1.Observable.from(metaDatas).pipe(map_1.map(function (metas) { return metas.mapFn(metas.change$); }), combineAll_1.combineAll(), map_1.map(function (r) { return r.reduce(function (acc, val) { return acc.concat(val); }); }), debounceTime_1.debounceTime(0, async_1.async), publishReplay_1.publishReplay(1), refCount_1.refCount()); | ||
dist.values = function () { | ||
utils_1.assert(!dist.consumed, Exception.TokenConsumed()); | ||
utils_1.assert(!dist.consumed, exception_1.tokenErrMsg.TokenConsumed()); | ||
dist.consumed = true; | ||
return from_1.from(metaDatas).pipe(mergeMap_1.mergeMap(function (metaData) { return metaData.values(); }), reduce_1.reduce(function (acc, val) { return acc.concat(val); })); | ||
return Observable_1.Observable.from(metaDatas).pipe(mergeMap_1.mergeMap(function (metaData) { return metaData.values(); }), reduce_1.reduce(function (acc, val) { return acc.concat(val); })); | ||
}; | ||
@@ -121,3 +117,5 @@ dist.toString = function () { | ||
: observeOn(this.getQuery()); | ||
return lfIssueFix(changesOnQuery).pipe(publishReplay_1.publishReplay(1), refCount_1.refCount()); | ||
return lfIssueFix(changesOnQuery) | ||
.publishReplay(1) | ||
.refCount(); | ||
}, | ||
@@ -186,6 +184,6 @@ set: function (dist$) { | ||
.then(function (pks) { return _this.getValue(_this.getQuery(_this.inPKs(pks))); }); | ||
return this.mapFn(fromPromise_1.fromPromise(p)); | ||
return this.mapFn(Observable_1.Observable.fromPromise(p)); | ||
} | ||
else { | ||
return this.mapFn(fromPromise_1.fromPromise(this.getValue(this.getQuery()))); | ||
return this.mapFn(Observable_1.Observable.fromPromise(this.getValue(this.getQuery()))); | ||
} | ||
@@ -215,3 +213,3 @@ }; | ||
}); | ||
utils_1.assert(equal, Exception.TokenConcatFailed()); | ||
utils_1.assert(equal, exception_1.tokenErrMsg.TokenConcatFailed()); | ||
return Selector.concatFactory.apply(Selector, [this].concat(selectors)); | ||
@@ -296,4 +294,4 @@ }; | ||
}; | ||
return changes.pipe(scan_1.scan(doKeep, null), filter_1.filter(utils_1.isNonNullable)); | ||
return changes.scan(doKeep, null).filter(Boolean); | ||
}; | ||
//# sourceMappingURL=Selector.js.map |
@@ -1,3 +0,1 @@ | ||
import { Truthy } from './truthy'; | ||
export declare function assert(condition: boolean, error: Error | string): void; | ||
export declare function assertValue<T>(value: T, error: Error | string): Truthy<T> | never; | ||
export declare function assert(condition: any, message: string): void; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
function assert(condition, error) { | ||
truthyOrThrow(condition, error); | ||
var Exception_1 = require("../exception/Exception"); | ||
function assert(condition, message) { | ||
if (!condition) { | ||
throw new Exception_1.ReactiveDBException(message); | ||
} | ||
} | ||
exports.assert = assert; | ||
function assertValue(value, error) { | ||
return truthyOrThrow(value, error); | ||
} | ||
exports.assertValue = assertValue; | ||
function truthyOrThrow(x, error) { | ||
if (x) { | ||
return x; | ||
} | ||
if (error instanceof Error) { | ||
throw error; | ||
} | ||
else { | ||
throw new Error(error); | ||
} | ||
} | ||
//# sourceMappingURL=assert.js.map |
@@ -11,4 +11,4 @@ export * from './hash'; | ||
export * from './get-type'; | ||
export * from './truthy'; | ||
export * from './try-catch'; | ||
export * from './diff'; | ||
export { warn } from './warn'; |
@@ -14,6 +14,6 @@ "use strict"; | ||
tslib_1.__exportStar(require("./get-type"), exports); | ||
tslib_1.__exportStar(require("./truthy"), exports); | ||
tslib_1.__exportStar(require("./try-catch"), exports); | ||
tslib_1.__exportStar(require("./diff"), exports); | ||
var warn_1 = require("./warn"); | ||
exports.warn = warn_1.warn; | ||
//# sourceMappingURL=index.js.map |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var Observable_1 = require("rxjs/Observable"); | ||
var empty_1 = require("rxjs/observable/empty"); | ||
var skip_1 = require("rxjs/operators/skip"); | ||
@@ -11,5 +10,5 @@ // think it as asynchronous assert | ||
} | ||
return empty_1.empty().pipe(skip_1.skip(1)); | ||
return Observable_1.Observable.empty().pipe(skip_1.skip(1)); | ||
} | ||
exports.valid = valid; | ||
//# sourceMappingURL=valid.js.map |
@@ -1,2 +0,2 @@ | ||
declare const _default: "0.10.3"; | ||
declare const _default: "0.10.4-alpha.10-diff-alpha0.10.4-alpha.10-diff-diff"; | ||
export default _default; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.default = '0.10.3'; | ||
exports.default = '0.10.4-alpha.10-diff-alpha0.10.4-alpha.10-diff-diff'; | ||
//# sourceMappingURL=version.js.map |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
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
294987
215
5281