sedentary 0.0.29 → 0.0.30

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -97,8 +97,8 @@ The full documentation is on [sedentary.readthedocs.io](https://sedentary.readth
97
97
 
98
98
  Requires:
99
99
 
100
- - Node.js: **v12**
101
- - TypeScript: **v4.1** (or none if used in a JavaScript project).
100
+ - Node.js: **v14**
101
+ - TypeScript: **v4.6** (or none if used in a JavaScript project).
102
102
 
103
103
  The package is tested under [all Node.js versions](https://app.travis-ci.com/github/iccicci/sedentary)
104
104
  currently supported accordingly to [Node.js Release](https://github.com/nodejs/Release#readme).
package/dist/cjs/db.js CHANGED
@@ -86,16 +86,18 @@ class DB {
86
86
  }
87
87
  exports.DB = DB;
88
88
  class Transaction {
89
- constructor() {
89
+ constructor(log) {
90
90
  this.entries = [];
91
+ this.log = log;
91
92
  }
92
93
  addEntry(entry) {
94
+ Object.defineProperty(entry, "tx", { configurable: true, value: this });
93
95
  this.entries.push(entry);
94
96
  }
95
97
  clean() {
96
98
  const { entries } = this;
97
99
  for (const entry of entries)
98
- delete entry.tx;
100
+ Object.defineProperty(entry, "tx", { configurable: true, value: null });
99
101
  this.entries = [];
100
102
  }
101
103
  async commit() {
package/dist/cjs/index.js CHANGED
@@ -419,19 +419,26 @@ class Sedentary {
419
419
  };
420
420
  checkParent(parent);
421
421
  const ret = class extends (parent || db_1.EntryBase) {
422
+ constructor(from, tx) {
423
+ super(from);
424
+ if (tx)
425
+ tx.addEntry(this);
426
+ }
422
427
  };
423
428
  const table = new db_1.Table({ autoIncrement, constraints, attributes: aarray, indexes: iarray, model: ret, parent, pk, sync, tableName });
424
429
  this.db.tables.push(table);
425
430
  const load_ = this.db.load(tableName, attr2field, pk, ret, table);
426
- const load = async (where, order, tx) => {
431
+ const load = async (where, order, tx, lock) => {
427
432
  if (order instanceof db_1.Transaction) {
433
+ if (typeof tx === "boolean" && tx)
434
+ lock = true;
428
435
  tx = order;
429
436
  order = undefined;
430
437
  }
431
438
  if (!this.checkOrderBy(order, attr2field, modelName))
432
439
  throw new Error(`${modelName}.load: 'order' argument: Wrong type, expected 'string[]'`);
433
440
  const [str] = this.createWhere(modelName, attr2field, where);
434
- const ret = await load_(str, order, tx);
441
+ const ret = await load_(str, order, tx, lock);
435
442
  return ret;
436
443
  };
437
444
  Object.defineProperty(load, "name", { value: modelName + ".load" });
package/dist/es/db.js CHANGED
@@ -82,13 +82,18 @@ export class DB {
82
82
  }
83
83
  export class Transaction {
84
84
  entries = [];
85
+ log;
86
+ constructor(log) {
87
+ this.log = log;
88
+ }
85
89
  addEntry(entry) {
90
+ Object.defineProperty(entry, "tx", { configurable: true, value: this });
86
91
  this.entries.push(entry);
87
92
  }
88
93
  clean() {
89
94
  const { entries } = this;
90
95
  for (const entry of entries)
91
- delete entry.tx;
96
+ Object.defineProperty(entry, "tx", { configurable: true, value: null });
92
97
  this.entries = [];
93
98
  }
94
99
  async commit() {
package/dist/es/index.js CHANGED
@@ -413,19 +413,26 @@ export class Sedentary {
413
413
  };
414
414
  checkParent(parent);
415
415
  const ret = class extends (parent || EntryBase) {
416
+ constructor(from, tx) {
417
+ super(from);
418
+ if (tx)
419
+ tx.addEntry(this);
420
+ }
416
421
  };
417
422
  const table = new Table({ autoIncrement, constraints, attributes: aarray, indexes: iarray, model: ret, parent, pk, sync, tableName });
418
423
  this.db.tables.push(table);
419
424
  const load_ = this.db.load(tableName, attr2field, pk, ret, table);
420
- const load = async (where, order, tx) => {
425
+ const load = async (where, order, tx, lock) => {
421
426
  if (order instanceof Transaction) {
427
+ if (typeof tx === "boolean" && tx)
428
+ lock = true;
422
429
  tx = order;
423
430
  order = undefined;
424
431
  }
425
432
  if (!this.checkOrderBy(order, attr2field, modelName))
426
433
  throw new Error(`${modelName}.load: 'order' argument: Wrong type, expected 'string[]'`);
427
434
  const [str] = this.createWhere(modelName, attr2field, where);
428
- const ret = await load_(str, order, tx);
435
+ const ret = await load_(str, order, tx, lock);
429
436
  return ret;
430
437
  };
431
438
  Object.defineProperty(load, "name", { value: modelName + ".load" });
@@ -84,7 +84,7 @@ export declare abstract class DB<T extends Transaction> {
84
84
  protected syncLog(message: string): void;
85
85
  abstract begin(): Promise<T>;
86
86
  abstract escape(value: Natural): string;
87
- abstract load(tableName: string, attributes: Record<string, string>, pk: Attribute<Natural, unknown>, model: new () => EntryBase, table: Table): (where: string, order?: string[], tx?: Transaction) => Promise<EntryBase[]>;
87
+ abstract load(tableName: string, attributes: Record<string, string>, pk: Attribute<Natural, unknown>, model: new () => EntryBase, table: Table): (where: string, order?: string[], tx?: Transaction, lock?: boolean) => Promise<EntryBase[]>;
88
88
  abstract save(tableName: string, attributes: Record<string, string>, pk: Attribute<Natural, unknown>): (this: EntryBase & Record<string, Natural>) => Promise<boolean>;
89
89
  abstract dropConstraints(table: Table): Promise<number[]>;
90
90
  abstract dropFields(table: Table): Promise<void>;
@@ -97,6 +97,8 @@ export declare abstract class DB<T extends Transaction> {
97
97
  }
98
98
  export declare class Transaction {
99
99
  private entries;
100
+ protected log: (message: string) => void;
101
+ constructor(log: (message: string) => void);
100
102
  addEntry(entry: EntryBase): void;
101
103
  clean(): void;
102
104
  commit(): Promise<void>;
@@ -64,10 +64,10 @@ declare type ModelAttributes<A extends AttributesDefinition, B extends boolean,
64
64
  }>;
65
65
  interface ModelLoad<A extends AttributesDefinition, E extends EntryBase> {
66
66
  attributes: A;
67
- load(where: Condition<A>, order?: Order<A>, tx?: Transaction): Promise<E[]>;
68
- load(where: Condition<A>, tx: Transaction): Promise<E[]>;
67
+ load(where: Condition<A>, order?: Order<A>, tx?: Transaction, lock?: boolean): Promise<E[]>;
68
+ load(where: Condition<A>, tx: Transaction, lock?: boolean): Promise<E[]>;
69
69
  }
70
- declare type ModelBase<N extends Natural, A extends AttributesDefinition, EA extends Record<string, Natural | undefined>, EM extends EntryBase, E extends EntryBase> = (new (from?: EA) => E) & Attribute<N, E> & {
70
+ declare type ModelBase<N extends Natural, A extends AttributesDefinition, EA extends Record<string, Natural | undefined>, EM extends EntryBase, E extends EntryBase> = (new (from?: EA, tx?: Transaction) => E) & Attribute<N, E> & {
71
71
  foreignKeys: Record<string, boolean>;
72
72
  methods: EM;
73
73
  parent?: ModelStd;
@@ -100,7 +100,7 @@ export declare class Sedentary<D extends DB<T>, T extends Transaction> {
100
100
  protected autoSync: boolean;
101
101
  protected db: D;
102
102
  protected doSync: boolean;
103
- protected log: (...data: unknown[]) => void;
103
+ protected log: (message: string) => void;
104
104
  private models;
105
105
  constructor(options?: SedentaryOptions);
106
106
  DATETIME(): Type<Date, unknown>;
package/package.json CHANGED
@@ -9,21 +9,21 @@
9
9
  "description": "The ORM which never needs to migrate",
10
10
  "devDependencies": {
11
11
  "@types/mocha": "9.1.0",
12
- "@types/node": "17.0.19",
12
+ "@types/node": "17.0.23",
13
13
  "@types/yamljs": "0.2.31",
14
- "@typescript-eslint/eslint-plugin": "5.12.1",
15
- "@typescript-eslint/parser": "5.12.1",
16
- "eslint": "8.9.0",
17
- "mocha": "9.2.1",
14
+ "@typescript-eslint/eslint-plugin": "5.17.0",
15
+ "@typescript-eslint/parser": "5.17.0",
16
+ "eslint": "8.12.0",
17
+ "mocha": "9.2.2",
18
18
  "nyc": "15.1.0",
19
- "prettier": "2.5.1",
20
- "ts-node": "10.5.0",
19
+ "prettier": "2.6.1",
20
+ "ts-node": "10.7.0",
21
21
  "tsd": "0.19.1",
22
- "typescript": "4.5.5",
22
+ "typescript": "4.6.3",
23
23
  "yamljs": "0.3.0"
24
24
  },
25
25
  "engines": {
26
- "node": ">=12.0"
26
+ "node": ">=14.0"
27
27
  },
28
28
  "funding": {
29
29
  "url": "https://blockchain.info/address/1Md9WFAHrXTb3yPBwQWmUfv2RmzrtbHioB"
@@ -79,5 +79,5 @@
79
79
  }
80
80
  },
81
81
  "types": "./dist/types/index.d.ts",
82
- "version": "0.0.29"
82
+ "version": "0.0.30"
83
83
  }