Comparing version 0.0.45 to 0.0.46
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.Transaction = exports.DB = exports.Table = exports.Attribute = exports.Type = exports.EntryBase = void 0; | ||
exports.Transaction = exports.DB = exports.Table = exports.Attribute = exports.Type = exports.EntryBase = exports.loaded = exports.actions = void 0; | ||
exports.actions = Symbol("actions"); | ||
exports.loaded = Symbol("loaded"); | ||
class EntryBase { | ||
@@ -15,5 +17,11 @@ constructor(from) { | ||
construct() { } | ||
// eslint-disable-next-line @typescript-eslint/no-unused-vars | ||
postCommit(actions) { } | ||
postLoad() { } | ||
postRemove() { } | ||
postSave() { } | ||
// eslint-disable-next-line @typescript-eslint/no-unused-vars | ||
postRemove(deletedRecords) { } | ||
// eslint-disable-next-line @typescript-eslint/no-unused-vars | ||
postSave(savedRecords) { } | ||
// eslint-disable-next-line @typescript-eslint/no-unused-vars | ||
preCommit(actions) { } | ||
preLoad() { } | ||
@@ -105,9 +113,21 @@ preRemove() { } | ||
const { entries } = this; | ||
for (const entry of entries) | ||
Object.defineProperty(entry, "tx", { configurable: true, value: null }); | ||
for (const entry of entries) { | ||
Object.defineProperty(entry, exports.actions, { configurable: true, value: undefined }); | ||
Object.defineProperty(entry, "tx", { configurable: true, value: undefined }); | ||
} | ||
this.entries = []; | ||
} | ||
async commit() { | ||
const { entries } = this; | ||
for (const entry of entries) | ||
if (entry[exports.actions]) | ||
entry.postCommit(entry[exports.actions]); | ||
this.clean(); | ||
} | ||
preCommit() { | ||
const { entries } = this; | ||
for (const entry of entries) | ||
if (entry[exports.actions]) | ||
entry.preCommit(entry[exports.actions]); | ||
} | ||
async rollback() { | ||
@@ -114,0 +134,0 @@ this.clean(); |
@@ -16,3 +16,22 @@ "use strict"; | ||
...["attr2field", "attributeName", "attributes", "base", "class", "construct", "constructor", "defaultValue", "entry", "fieldName", "foreignKeys", "load"], | ||
...["loaded", "methods", "name", "postLoad", "postSave", "preLoad", "preSave", "primaryKey", "prototype", "save", "size", "tableName", "tx", "type"] | ||
...[ | ||
"loaded", | ||
"methods", | ||
"name", | ||
"postCommit", | ||
"postLoad", | ||
"postRemove", | ||
"postSave", | ||
"preCommit", | ||
"preLoad", | ||
"preRemove", | ||
"preSave", | ||
"primaryKey", | ||
"prototype", | ||
"save", | ||
"size", | ||
"tableName", | ||
"tx", | ||
"type" | ||
] | ||
]; | ||
@@ -500,6 +519,10 @@ class Sedentary { | ||
this.preRemove(); | ||
const ret = await remove.call(this); | ||
if (ret) | ||
this.postRemove(); | ||
return ret; | ||
const records = await remove.call(this); | ||
this.postRemove(records); | ||
if (this.tx) { | ||
if (!this[db_1.actions]) | ||
Object.defineProperty(this, db_1.actions, { configurable: true, value: [] }); | ||
this[db_1.actions].push({ action: "remove", records }); | ||
} | ||
return records; | ||
}; | ||
@@ -510,6 +533,10 @@ Object.defineProperty(ret.prototype.remove, "name", { value: modelName + ".remove" }); | ||
this.preSave(); | ||
const ret = await save.call(this); | ||
if (ret) | ||
this.postSave(); | ||
return ret; | ||
const records = await save.call(this); | ||
this.postSave(records); | ||
if (this.tx) { | ||
if (!this[db_1.actions]) | ||
Object.defineProperty(this, db_1.actions, { configurable: true, value: [] }); | ||
this[db_1.actions].push({ action: "save", records }); | ||
} | ||
return records; | ||
}; | ||
@@ -516,0 +543,0 @@ Object.defineProperty(ret.prototype.save, "name", { value: modelName + ".save" }); |
@@ -0,1 +1,3 @@ | ||
export const actions = Symbol("actions"); | ||
export const loaded = Symbol("loaded"); | ||
export class EntryBase { | ||
@@ -12,5 +14,11 @@ constructor(from) { | ||
construct() { } | ||
// eslint-disable-next-line @typescript-eslint/no-unused-vars | ||
postCommit(actions) { } | ||
postLoad() { } | ||
postRemove() { } | ||
postSave() { } | ||
// eslint-disable-next-line @typescript-eslint/no-unused-vars | ||
postRemove(deletedRecords) { } | ||
// eslint-disable-next-line @typescript-eslint/no-unused-vars | ||
postSave(savedRecords) { } | ||
// eslint-disable-next-line @typescript-eslint/no-unused-vars | ||
preCommit(actions) { } | ||
preLoad() { } | ||
@@ -101,9 +109,21 @@ preRemove() { } | ||
const { entries } = this; | ||
for (const entry of entries) | ||
Object.defineProperty(entry, "tx", { configurable: true, value: null }); | ||
for (const entry of entries) { | ||
Object.defineProperty(entry, actions, { configurable: true, value: undefined }); | ||
Object.defineProperty(entry, "tx", { configurable: true, value: undefined }); | ||
} | ||
this.entries = []; | ||
} | ||
async commit() { | ||
const { entries } = this; | ||
for (const entry of entries) | ||
if (entry[actions]) | ||
entry.postCommit(entry[actions]); | ||
this.clean(); | ||
} | ||
preCommit() { | ||
const { entries } = this; | ||
for (const entry of entries) | ||
if (entry[actions]) | ||
entry.preCommit(entry[actions]); | ||
} | ||
async rollback() { | ||
@@ -110,0 +130,0 @@ this.clean(); |
@@ -1,2 +0,2 @@ | ||
import { Attribute, EntryBase, Table, Transaction, Type } from "./db"; | ||
import { actions, Attribute, EntryBase, Table, Transaction, Type } from "./db"; | ||
export { Attribute, DB, EntryBase, Table, Transaction, Type } from "./db"; | ||
@@ -7,3 +7,22 @@ const operators = ["=", ">", "<", ">=", "<=", "<>", "IN", "IS NULL", "LIKE", "NOT"]; | ||
...["attr2field", "attributeName", "attributes", "base", "class", "construct", "constructor", "defaultValue", "entry", "fieldName", "foreignKeys", "load"], | ||
...["loaded", "methods", "name", "postLoad", "postSave", "preLoad", "preSave", "primaryKey", "prototype", "save", "size", "tableName", "tx", "type"] | ||
...[ | ||
"loaded", | ||
"methods", | ||
"name", | ||
"postCommit", | ||
"postLoad", | ||
"postRemove", | ||
"postSave", | ||
"preCommit", | ||
"preLoad", | ||
"preRemove", | ||
"preSave", | ||
"primaryKey", | ||
"prototype", | ||
"save", | ||
"size", | ||
"tableName", | ||
"tx", | ||
"type" | ||
] | ||
]; | ||
@@ -494,6 +513,10 @@ export class Sedentary { | ||
this.preRemove(); | ||
const ret = await remove.call(this); | ||
if (ret) | ||
this.postRemove(); | ||
return ret; | ||
const records = await remove.call(this); | ||
this.postRemove(records); | ||
if (this.tx) { | ||
if (!this[actions]) | ||
Object.defineProperty(this, actions, { configurable: true, value: [] }); | ||
this[actions].push({ action: "remove", records }); | ||
} | ||
return records; | ||
}; | ||
@@ -504,6 +527,10 @@ Object.defineProperty(ret.prototype.remove, "name", { value: modelName + ".remove" }); | ||
this.preSave(); | ||
const ret = await save.call(this); | ||
if (ret) | ||
this.postSave(); | ||
return ret; | ||
const records = await save.call(this); | ||
this.postSave(records); | ||
if (this.tx) { | ||
if (!this[actions]) | ||
Object.defineProperty(this, actions, { configurable: true, value: [] }); | ||
this[actions].push({ action: "save", records }); | ||
} | ||
return records; | ||
}; | ||
@@ -510,0 +537,0 @@ Object.defineProperty(ret.prototype.save, "name", { value: modelName + ".save" }); |
@@ -0,7 +1,15 @@ | ||
export declare const actions: unique symbol; | ||
export declare const loaded: unique symbol; | ||
export interface Action { | ||
action: "remove" | "save"; | ||
records: number | false; | ||
} | ||
export declare class EntryBase { | ||
constructor(from?: Partial<EntryBase>); | ||
construct(): void; | ||
postCommit(actions: Action[]): void; | ||
postLoad(): void; | ||
postRemove(): void; | ||
postSave(): void; | ||
postRemove(deletedRecords: number): void; | ||
postSave(savedRecords: number | false): void; | ||
preCommit(actions: Action[]): void; | ||
preLoad(): void; | ||
@@ -91,4 +99,4 @@ preRemove(): void; | ||
abstract load(tableName: string, attributes: Record<string, string>, pk: Attribute<unknown, unknown>, model: new () => EntryBase, table: Table): (where: string, order?: string | string[], limit?: number, tx?: Transaction, lock?: boolean) => Promise<EntryBase[]>; | ||
abstract remove(tableName: string, pk: Attribute<unknown, unknown>): (this: EntryBase & Record<string, unknown>) => Promise<boolean>; | ||
abstract save(tableName: string, attributes: Record<string, string>, pk: Attribute<unknown, unknown>): (this: EntryBase & Record<string, unknown>) => Promise<boolean>; | ||
abstract remove(tableName: string, pk: Attribute<unknown, unknown>): (this: EntryBase & Record<string, unknown>) => Promise<number>; | ||
abstract save(tableName: string, attributes: Record<string, string>, pk: Attribute<unknown, unknown>): (this: EntryBase & Record<string, unknown>) => Promise<number | false>; | ||
abstract dropConstraints(table: Table): Promise<number[]>; | ||
@@ -110,4 +118,5 @@ abstract dropFields(table: Table): Promise<void>; | ||
commit(): Promise<void>; | ||
protected preCommit(): void; | ||
rollback(): Promise<void>; | ||
} | ||
export {}; |
import { Attribute, DB, EntryBase, ForeignKeyOptions, Transaction, Type } from "./db"; | ||
export { Attribute, DB, EntryBase, ForeignKeyActions, ForeignKeyOptions, Index, Table, Transaction, Type } from "./db"; | ||
export { Action, Attribute, DB, EntryBase, ForeignKeyActions, ForeignKeyOptions, Index, Table, Transaction, Type } from "./db"; | ||
export declare type TypeDefinition<T, E> = (() => Type<T, E>) | Type<T, E>; | ||
@@ -4,0 +4,0 @@ export interface AttributeOptions<T, E> { |
@@ -61,3 +61,3 @@ { | ||
"types": "./dist/types/index.d.ts", | ||
"version": "0.0.45" | ||
"version": "0.0.46" | ||
} |
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
87996
9
1618