ts-redis-orm
Advanced tools
Comparing version 0.1.18 to 0.1.19
@@ -143,3 +143,3 @@ import { | ||
// events | ||
const events = MyEntity.getEventEmitter(); | ||
const events = MyEntity.getEvents(); | ||
events.on("create", (entity) => { /* */ }); | ||
@@ -146,0 +146,0 @@ events.on("update", (entity) => { /* */ }); |
/// <reference types="ioredis" /> | ||
import { Query } from "./Query"; | ||
import { IArgvValues, IEvent, IIdObject, IInstanceValues } from "./types"; | ||
import { IArgvValues, IEvents, IIdObject, IInstanceValues } from "./types"; | ||
export declare class BaseEntity { | ||
@@ -15,3 +15,3 @@ static connect(table?: string): Promise<import("ioredis").Redis>; | ||
static truncate(className: string, table?: string): Promise<void>; | ||
static getEventEmitter<T extends typeof BaseEntity>(this: T): IEvent<InstanceType<T>>; | ||
static getEvents<T extends typeof BaseEntity>(this: T): IEvents<InstanceType<T>>; | ||
static getSchemas(): { | ||
@@ -18,0 +18,0 @@ columnTypes: any; |
@@ -147,3 +147,3 @@ "use strict"; | ||
} | ||
static getEventEmitter() { | ||
static getEvents() { | ||
return eventEmitters_1.eventEmitters.getEventEmitter(this); | ||
@@ -421,10 +421,10 @@ } | ||
if (isRestore) { | ||
eventEmitters_1.eventEmitters.getEventEmitter(this.constructor).emit("restore", this); | ||
eventEmitters_1.eventEmitters.emit("restore", this); | ||
} | ||
else { | ||
if (isNew) { | ||
eventEmitters_1.eventEmitters.getEventEmitter(this.constructor).emit("create", this); | ||
eventEmitters_1.eventEmitters.emit("create", this); | ||
} | ||
else { | ||
eventEmitters_1.eventEmitters.getEventEmitter(this.constructor).emit("update", this); | ||
eventEmitters_1.eventEmitters.emit("update", this); | ||
} | ||
@@ -476,6 +476,6 @@ } | ||
if (forceDelete) { | ||
eventEmitters_1.eventEmitters.getEventEmitter(this.constructor).emit("forceDelete", this); | ||
eventEmitters_1.eventEmitters.emit("forceDelete", this); | ||
} | ||
else { | ||
eventEmitters_1.eventEmitters.getEventEmitter(this.constructor).emit("delete", this); | ||
eventEmitters_1.eventEmitters.emit("delete", this); | ||
} | ||
@@ -482,0 +482,0 @@ return this; |
import { BaseEntity } from "./BaseEntity"; | ||
import { IEvent } from "./types"; | ||
import { IEvents, IEventsType } from "./types"; | ||
declare class EventEmitters { | ||
private _eventEmitters; | ||
getEventEmitter<T extends typeof BaseEntity>(target: T): IEvent<InstanceType<T>>; | ||
getEventEmitter<T extends typeof BaseEntity>(target: T): IEvents<InstanceType<T>>; | ||
emit<T extends BaseEntity>(eventType: IEventsType, entity: T): void; | ||
} | ||
export declare const eventEmitters: EventEmitters; | ||
export {}; |
@@ -14,3 +14,9 @@ "use strict"; | ||
} | ||
emit(eventType, entity) { | ||
const eventEmitter = this.getEventEmitter(entity.constructor); | ||
if (eventEmitter) { | ||
setImmediate(() => eventEmitter.emit(eventType, entity)); | ||
} | ||
} | ||
} | ||
exports.eventEmitters = new EventEmitters(); |
@@ -362,3 +362,2 @@ "use strict"; | ||
const indexStorageKey = redisOrm_1.redisOrm.getIndexStorageKey(this._tableName, column); | ||
const extraParams = ["LIMIT", this._offset.toString(), this._limit.toString()]; | ||
// collect result ids | ||
@@ -368,6 +367,6 @@ const redis = yield this._getRedis(); | ||
if (order === "asc") { | ||
ids = yield redis.zrangebyscore(indexStorageKey, min, max, ...extraParams); | ||
ids = yield redis.zrangebyscore(indexStorageKey, min, max, "LIMIT", this._offset, this._limit); | ||
} | ||
else if (order === "desc") { | ||
ids = yield redis.zrevrangebyscore(indexStorageKey, max, min, ...extraParams); | ||
ids = yield redis.zrevrangebyscore(indexStorageKey, max, min, "LIMIT", this._offset, this._limit); | ||
} | ||
@@ -374,0 +373,0 @@ return yield this.findMany(ids); |
@@ -73,10 +73,10 @@ import * as IORedis from "ioredis"; | ||
export declare type IIdObject<T> = IArgvValues<T> | number | string; | ||
export declare type IEventType = "create" | "update" | "delete" | "forceDelete" | "restore"; | ||
export interface IEvent<T> { | ||
on(type: IEventType, callback: (entity: T) => void): this; | ||
addListener(type: IEventType, callback: (entity: T) => void): this; | ||
removeListener(type: IEventType, callback: (entity: T) => void): this; | ||
once(type: IEventType, callback: (entity: T) => void): this; | ||
off(type: IEventType, callback: (entity: T) => void): this; | ||
emit(type: IEventType, entity: T): void; | ||
export declare type IEventsType = "create" | "update" | "delete" | "forceDelete" | "restore"; | ||
export interface IEvents<T> { | ||
on(type: IEventsType, callback: (entity: T) => void): this; | ||
addListener(type: IEventsType, callback: (entity: T) => void): this; | ||
removeListener(type: IEventsType, callback: (entity: T) => void): this; | ||
once(type: IEventsType, callback: (entity: T) => void): this; | ||
off(type: IEventsType, callback: (entity: T) => void): this; | ||
emit(type: IEventsType, entity: T): void; | ||
} |
{ | ||
"name": "ts-redis-orm", | ||
"version": "0.1.18", | ||
"version": "0.1.19", | ||
"description": "A full functional Redis Orm library written in Typescript.", | ||
@@ -25,3 +25,3 @@ "main": "build/index.js", | ||
"ioredis": "^4.14.1", | ||
"@types/ioredis": "^4.0.20", | ||
"@types/ioredis": "^4.14.3", | ||
"reflect-metadata": "^0.1.13", | ||
@@ -32,9 +32,9 @@ "debug": "^4.1.1", | ||
"devDependencies": { | ||
"@types/chai": "^4.2.5", | ||
"@types/chai": "^4.2.7", | ||
"@types/mocha": "^5.2.7", | ||
"@types/node": "^12.12.14", | ||
"@types/node": "^12.12.21", | ||
"chai": "^4.2.0", | ||
"mocha": "^6.2.2", | ||
"ts-node": "^8.5.4", | ||
"typescript": "^3.7.2", | ||
"typescript": "^3.7.3", | ||
"clone": "^2.1.2" | ||
@@ -41,0 +41,0 @@ }, |
@@ -172,3 +172,3 @@ # Redis ORM (Typescript) | ||
// events | ||
const events = MyEntity.getEventEmitter(); | ||
const events = MyEntity.getEvents(); | ||
events.on("create", (entity) => { /* */ }); | ||
@@ -175,0 +175,0 @@ events.on("update", (entity) => { /* */ }); |
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
147488
44
2401
Updated@types/ioredis@^4.14.3