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