sedentary 0.0.47 → 0.0.48

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/dist/cjs/db.js CHANGED
@@ -1,8 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.differ = exports.Transaction = exports.DB = exports.Table = exports.Attribute = exports.Type = exports.EntryBase = exports.loaded = exports.actions = void 0;
3
+ exports.differ = exports.Transaction = exports.DB = exports.Table = exports.Attribute = exports.Type = exports.EntryBase = exports.transaction = exports.loaded = exports.actions = void 0;
4
4
  exports.actions = Symbol("actions");
5
5
  exports.loaded = Symbol("loaded");
6
+ exports.transaction = Symbol("transaction");
6
7
  class EntryBase {
7
8
  constructor(from) {
8
9
  if (from === "load")
@@ -104,14 +105,14 @@ class Transaction {
104
105
  this.log = log;
105
106
  }
106
107
  addEntry(entry) {
107
- Object.defineProperty(entry, "tx", { configurable: true, value: this });
108
+ Object.defineProperty(entry, exports.transaction, { configurable: true, value: this });
108
109
  this.entries.push(entry);
109
110
  }
110
111
  clean() {
111
112
  const { entries } = this;
112
113
  for (const entry of entries) {
113
114
  Object.defineProperty(entry, exports.actions, { configurable: true, value: undefined });
114
- Object.defineProperty(entry, "tx", { configurable: true, value: undefined });
115
+ Object.defineProperty(entry, exports.transaction, { configurable: true, value: undefined });
115
116
  }
116
117
  this.entries = [];
117
118
  }
package/dist/cjs/index.js CHANGED
@@ -14,26 +14,7 @@ const operators = ["=", ">", "<", ">=", "<=", "<>", "IN", "IS NULL", "LIKE", "NO
14
14
  const allowedOption = ["indexes", "int8id", "parent", "primaryKey", "sync", "tableName"];
15
15
  const reservedNames = [
16
16
  ...["attr2field", "attributeName", "attributes", "base", "class", "construct", "constructor", "defaultValue", "entry", "fieldName", "foreignKeys", "load"],
17
- ...[
18
- "loaded",
19
- "methods",
20
- "name",
21
- "postCommit",
22
- "postLoad",
23
- "postRemove",
24
- "postSave",
25
- "preCommit",
26
- "preLoad",
27
- "preRemove",
28
- "preSave",
29
- "primaryKey",
30
- "prototype",
31
- "save",
32
- "size",
33
- "tableName",
34
- "tx",
35
- "type"
36
- ]
17
+ ...["methods", "name", "postCommit", "postLoad", "postRemove", "postSave", "preCommit", "preLoad", "preRemove", "preSave", "primaryKey", "prototype", "save", "size", "tableName", "type"]
37
18
  ];
38
19
  class Sedentary {
39
20
  constructor(options) {
@@ -85,6 +66,9 @@ class Sedentary {
85
66
  Number() {
86
67
  return new db_1.Type({ base: Number, type: "NUMBER" });
87
68
  }
69
+ None() {
70
+ return new db_1.Type({ base: undefined, type: "NONE" });
71
+ }
88
72
  VarChar(size) {
89
73
  const message = "Sedentary.VARCHAR: 'size' argument: Wrong value, expected positive integer";
90
74
  size = size ? this.checkSize(size, message) : undefined;
@@ -281,7 +265,7 @@ class Sedentary {
281
265
  const call = (defaultValue, fieldName, notNull, unique, func, message1, message2) => {
282
266
  if (func === this.FKey)
283
267
  throw new Error(`${message1} 'this.FKey' can't be used directly`);
284
- if (![this.Boolean, this.DateTime, this.Int, this.JSON, this.Int8, this.Number, this.VarChar].includes(func))
268
+ if (![this.Boolean, this.DateTime, this.Int, this.JSON, this.Int8, this.None, this.Number, this.VarChar].includes(func))
285
269
  throw new Error(`${message1} ${message2}`);
286
270
  return new db_1.Attribute({ attributeName, defaultValue, fieldName, modelName, notNull, tableName, unique, ...func() });
287
271
  };
@@ -511,18 +495,20 @@ class Sedentary {
511
495
  Object.defineProperty(ret, "foreignKeys", { value: foreignKeys });
512
496
  Object.defineProperty(ret, "methods", { value: methods });
513
497
  Object.assign(ret.prototype, methods);
498
+ const ensureActions = (entry) => {
499
+ if (!entry[db_1.actions])
500
+ Object.defineProperty(entry, db_1.actions, { configurable: true, value: [] });
501
+ return entry[db_1.actions];
502
+ };
514
503
  const remove = this.db.remove(tableName, pk);
515
504
  ret.prototype.remove = async function () {
516
- if (!this.loaded)
505
+ if (!this[db_1.loaded])
517
506
  throw new Error(`${modelName}.remove: Can't remove a never saved Entry`);
518
507
  this.preRemove();
519
508
  const records = await remove.call(this);
520
509
  this.postRemove(records);
521
- if (this.tx) {
522
- if (!this[db_1.actions])
523
- Object.defineProperty(this, db_1.actions, { configurable: true, value: [] });
524
- this[db_1.actions].push({ action: "remove", records });
525
- }
510
+ if (this[db_1.transaction])
511
+ ensureActions(this).push({ action: "remove", records });
526
512
  return records;
527
513
  };
528
514
  Object.defineProperty(ret.prototype.remove, "name", { value: modelName + ".remove" });
@@ -531,11 +517,8 @@ class Sedentary {
531
517
  this.preSave();
532
518
  const records = await save.call(this);
533
519
  this.postSave(records);
534
- if (this.tx) {
535
- if (!this[db_1.actions])
536
- Object.defineProperty(this, db_1.actions, { configurable: true, value: [] });
537
- this[db_1.actions].push({ action: "save", records });
538
- }
520
+ if (this[db_1.transaction])
521
+ ensureActions(this).push({ action: "save", records });
539
522
  return records;
540
523
  };
541
524
  Object.defineProperty(ret.prototype.save, "name", { value: modelName + ".save" });
package/dist/es/db.js CHANGED
@@ -1,5 +1,6 @@
1
1
  export const actions = Symbol("actions");
2
2
  export const loaded = Symbol("loaded");
3
+ export const transaction = Symbol("transaction");
3
4
  export class EntryBase {
4
5
  constructor(from) {
5
6
  if (from === "load")
@@ -100,14 +101,14 @@ export class Transaction {
100
101
  this.log = log;
101
102
  }
102
103
  addEntry(entry) {
103
- Object.defineProperty(entry, "tx", { configurable: true, value: this });
104
+ Object.defineProperty(entry, transaction, { configurable: true, value: this });
104
105
  this.entries.push(entry);
105
106
  }
106
107
  clean() {
107
108
  const { entries } = this;
108
109
  for (const entry of entries) {
109
110
  Object.defineProperty(entry, actions, { configurable: true, value: undefined });
110
- Object.defineProperty(entry, "tx", { configurable: true, value: undefined });
111
+ Object.defineProperty(entry, transaction, { configurable: true, value: undefined });
111
112
  }
112
113
  this.entries = [];
113
114
  }
package/dist/es/index.js CHANGED
@@ -1,29 +1,10 @@
1
- import { actions, Attribute, EntryBase, Table, Transaction, Type } from "./db";
1
+ import { actions, Attribute, EntryBase, loaded, Table, Transaction, transaction, Type } from "./db";
2
2
  export { Attribute, DB, differ, EntryBase, Table, Transaction, Type } from "./db";
3
3
  const operators = ["=", ">", "<", ">=", "<=", "<>", "IN", "IS NULL", "LIKE", "NOT"];
4
4
  const allowedOption = ["indexes", "int8id", "parent", "primaryKey", "sync", "tableName"];
5
5
  const reservedNames = [
6
6
  ...["attr2field", "attributeName", "attributes", "base", "class", "construct", "constructor", "defaultValue", "entry", "fieldName", "foreignKeys", "load"],
7
- ...[
8
- "loaded",
9
- "methods",
10
- "name",
11
- "postCommit",
12
- "postLoad",
13
- "postRemove",
14
- "postSave",
15
- "preCommit",
16
- "preLoad",
17
- "preRemove",
18
- "preSave",
19
- "primaryKey",
20
- "prototype",
21
- "save",
22
- "size",
23
- "tableName",
24
- "tx",
25
- "type"
26
- ]
7
+ ...["methods", "name", "postCommit", "postLoad", "postRemove", "postSave", "preCommit", "preLoad", "preRemove", "preSave", "primaryKey", "prototype", "save", "size", "tableName", "type"]
27
8
  ];
28
9
  export class Sedentary {
29
10
  autoSync;
@@ -78,6 +59,9 @@ export class Sedentary {
78
59
  Number() {
79
60
  return new Type({ base: Number, type: "NUMBER" });
80
61
  }
62
+ None() {
63
+ return new Type({ base: undefined, type: "NONE" });
64
+ }
81
65
  VarChar(size) {
82
66
  const message = "Sedentary.VARCHAR: 'size' argument: Wrong value, expected positive integer";
83
67
  size = size ? this.checkSize(size, message) : undefined;
@@ -274,7 +258,7 @@ export class Sedentary {
274
258
  const call = (defaultValue, fieldName, notNull, unique, func, message1, message2) => {
275
259
  if (func === this.FKey)
276
260
  throw new Error(`${message1} 'this.FKey' can't be used directly`);
277
- if (![this.Boolean, this.DateTime, this.Int, this.JSON, this.Int8, this.Number, this.VarChar].includes(func))
261
+ if (![this.Boolean, this.DateTime, this.Int, this.JSON, this.Int8, this.None, this.Number, this.VarChar].includes(func))
278
262
  throw new Error(`${message1} ${message2}`);
279
263
  return new Attribute({ attributeName, defaultValue, fieldName, modelName, notNull, tableName, unique, ...func() });
280
264
  };
@@ -504,18 +488,20 @@ export class Sedentary {
504
488
  Object.defineProperty(ret, "foreignKeys", { value: foreignKeys });
505
489
  Object.defineProperty(ret, "methods", { value: methods });
506
490
  Object.assign(ret.prototype, methods);
491
+ const ensureActions = (entry) => {
492
+ if (!entry[actions])
493
+ Object.defineProperty(entry, actions, { configurable: true, value: [] });
494
+ return entry[actions];
495
+ };
507
496
  const remove = this.db.remove(tableName, pk);
508
497
  ret.prototype.remove = async function () {
509
- if (!this.loaded)
498
+ if (!this[loaded])
510
499
  throw new Error(`${modelName}.remove: Can't remove a never saved Entry`);
511
500
  this.preRemove();
512
501
  const records = await remove.call(this);
513
502
  this.postRemove(records);
514
- if (this.tx) {
515
- if (!this[actions])
516
- Object.defineProperty(this, actions, { configurable: true, value: [] });
517
- this[actions].push({ action: "remove", records });
518
- }
503
+ if (this[transaction])
504
+ ensureActions(this).push({ action: "remove", records });
519
505
  return records;
520
506
  };
521
507
  Object.defineProperty(ret.prototype.remove, "name", { value: modelName + ".remove" });
@@ -524,11 +510,8 @@ export class Sedentary {
524
510
  this.preSave();
525
511
  const records = await save.call(this);
526
512
  this.postSave(records);
527
- if (this.tx) {
528
- if (!this[actions])
529
- Object.defineProperty(this, actions, { configurable: true, value: [] });
530
- this[actions].push({ action: "save", records });
531
- }
513
+ if (this[transaction])
514
+ ensureActions(this).push({ action: "save", records });
532
515
  return records;
533
516
  };
534
517
  Object.defineProperty(ret.prototype.save, "name", { value: modelName + ".save" });
@@ -1,5 +1,6 @@
1
1
  export declare const actions: unique symbol;
2
2
  export declare const loaded: unique symbol;
3
+ export declare const transaction: unique symbol;
3
4
  export interface Action {
4
5
  action: "remove" | "save";
5
6
  records: number | false;
@@ -120,6 +120,7 @@ export declare class Sedentary<D extends DB<T>, T extends Transaction> {
120
120
  Int8(): Type<bigint, unknown>;
121
121
  JSON<T>(): Type<T, unknown>;
122
122
  Number(): Type<number, unknown>;
123
+ None<T>(): Type<T, unknown>;
123
124
  VarChar<S extends string>(size?: number): Type<S, unknown>;
124
125
  private checkDB;
125
126
  private checkOrderBy;
package/package.json CHANGED
@@ -58,5 +58,5 @@
58
58
  }
59
59
  },
60
60
  "types": "./dist/types/index.d.ts",
61
- "version": "0.0.47"
61
+ "version": "0.0.48"
62
62
  }