sedentary 0.0.31 → 0.0.34

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
@@ -13,9 +13,14 @@ class EntryBase {
13
13
  }
14
14
  construct() { }
15
15
  postLoad() { }
16
+ postRemove() { }
16
17
  postSave() { }
17
18
  preLoad() { }
19
+ preRemove() { }
18
20
  preSave() { }
21
+ async remove() {
22
+ return false;
23
+ }
19
24
  async save() {
20
25
  return false;
21
26
  }
package/dist/cjs/index.js CHANGED
@@ -54,7 +54,10 @@ class Sedentary {
54
54
  return new db_1.Type({ base: Number, size, type: "INT" });
55
55
  }
56
56
  INT8() {
57
- return new db_1.Type({ base: String, size: 8, type: "INT8" });
57
+ return new db_1.Type({ base: BigInt, size: 8, type: "INT8" });
58
+ }
59
+ NUMBER() {
60
+ return new db_1.Type({ base: Number, type: "NUMBER" });
58
61
  }
59
62
  VARCHAR(size) {
60
63
  const message = "Sedentary.VARCHAR: 'size' argument: Wrong value, expected positive integer";
@@ -247,7 +250,7 @@ class Sedentary {
247
250
  const call = (defaultValue, fieldName, notNull, unique, func, message1, message2) => {
248
251
  if (func === this.FKEY)
249
252
  throw new Error(`${message1} 'this.FKEY' can't be used directly`);
250
- if (func !== this.DATETIME && func !== this.INT && func !== this.INT8 && func !== this.VARCHAR)
253
+ if (![this.DATETIME, this.NUMBER, this.INT, this.INT8, this.VARCHAR].includes(func))
251
254
  throw new Error(`${message1} ${message2}`);
252
255
  return new db_1.Attribute({ attributeName, defaultValue, fieldName, modelName, notNull, tableName, unique, ...func() });
253
256
  };
@@ -280,6 +283,8 @@ class Sedentary {
280
283
  })();
281
284
  const { base, defaultValue } = ret;
282
285
  if (defaultValue !== undefined) {
286
+ if (base === BigInt && typeof defaultValue !== "bigint")
287
+ throw new Error(`Sedentary.model: '${modelName}' model: '${attributeName}' attribute: 'defaultValue' option: Wrong type, expected 'BigInt'`);
283
288
  if (base === Date && !(defaultValue instanceof Date))
284
289
  throw new Error(`Sedentary.model: '${modelName}' model: '${attributeName}' attribute: 'defaultValue' option: Wrong type, expected 'Date'`);
285
290
  if (base === Number && typeof defaultValue !== "number")
@@ -449,6 +454,17 @@ class Sedentary {
449
454
  Object.defineProperty(ret, "foreignKeys", { value: foreignKeys });
450
455
  Object.defineProperty(ret, "methods", { value: methods });
451
456
  Object.assign(ret.prototype, methods);
457
+ const remove = this.db.remove(tableName, pk);
458
+ ret.prototype.remove = async function () {
459
+ if (!this.loaded)
460
+ throw new Error(`${modelName}.remove: Can't remove a never saved Entry`);
461
+ this.preRemove();
462
+ const ret = await remove.call(this);
463
+ if (ret)
464
+ this.postRemove();
465
+ return ret;
466
+ };
467
+ Object.defineProperty(ret.prototype.remove, "name", { value: modelName + ".remove" });
452
468
  const save = this.db.save(tableName, attr2field, pk);
453
469
  ret.prototype.save = async function () {
454
470
  this.preSave();
package/dist/es/db.js CHANGED
@@ -10,9 +10,14 @@ export class EntryBase {
10
10
  }
11
11
  construct() { }
12
12
  postLoad() { }
13
+ postRemove() { }
13
14
  postSave() { }
14
15
  preLoad() { }
16
+ preRemove() { }
15
17
  preSave() { }
18
+ async remove() {
19
+ return false;
20
+ }
16
21
  async save() {
17
22
  return false;
18
23
  }
package/dist/es/index.js CHANGED
@@ -48,7 +48,10 @@ export class Sedentary {
48
48
  return new Type({ base: Number, size, type: "INT" });
49
49
  }
50
50
  INT8() {
51
- return new Type({ base: String, size: 8, type: "INT8" });
51
+ return new Type({ base: BigInt, size: 8, type: "INT8" });
52
+ }
53
+ NUMBER() {
54
+ return new Type({ base: Number, type: "NUMBER" });
52
55
  }
53
56
  VARCHAR(size) {
54
57
  const message = "Sedentary.VARCHAR: 'size' argument: Wrong value, expected positive integer";
@@ -241,7 +244,7 @@ export class Sedentary {
241
244
  const call = (defaultValue, fieldName, notNull, unique, func, message1, message2) => {
242
245
  if (func === this.FKEY)
243
246
  throw new Error(`${message1} 'this.FKEY' can't be used directly`);
244
- if (func !== this.DATETIME && func !== this.INT && func !== this.INT8 && func !== this.VARCHAR)
247
+ if (![this.DATETIME, this.NUMBER, this.INT, this.INT8, this.VARCHAR].includes(func))
245
248
  throw new Error(`${message1} ${message2}`);
246
249
  return new Attribute({ attributeName, defaultValue, fieldName, modelName, notNull, tableName, unique, ...func() });
247
250
  };
@@ -274,6 +277,8 @@ export class Sedentary {
274
277
  })();
275
278
  const { base, defaultValue } = ret;
276
279
  if (defaultValue !== undefined) {
280
+ if (base === BigInt && typeof defaultValue !== "bigint")
281
+ throw new Error(`Sedentary.model: '${modelName}' model: '${attributeName}' attribute: 'defaultValue' option: Wrong type, expected 'BigInt'`);
277
282
  if (base === Date && !(defaultValue instanceof Date))
278
283
  throw new Error(`Sedentary.model: '${modelName}' model: '${attributeName}' attribute: 'defaultValue' option: Wrong type, expected 'Date'`);
279
284
  if (base === Number && typeof defaultValue !== "number")
@@ -443,6 +448,17 @@ export class Sedentary {
443
448
  Object.defineProperty(ret, "foreignKeys", { value: foreignKeys });
444
449
  Object.defineProperty(ret, "methods", { value: methods });
445
450
  Object.assign(ret.prototype, methods);
451
+ const remove = this.db.remove(tableName, pk);
452
+ ret.prototype.remove = async function () {
453
+ if (!this.loaded)
454
+ throw new Error(`${modelName}.remove: Can't remove a never saved Entry`);
455
+ this.preRemove();
456
+ const ret = await remove.call(this);
457
+ if (ret)
458
+ this.postRemove();
459
+ return ret;
460
+ };
461
+ Object.defineProperty(ret.prototype.remove, "name", { value: modelName + ".remove" });
446
462
  const save = this.db.save(tableName, attr2field, pk);
447
463
  ret.prototype.save = async function () {
448
464
  this.preSave();
@@ -1,11 +1,14 @@
1
- export declare type Natural = Date | Record<string, unknown> | boolean | number | string | null;
1
+ export declare type Natural = BigInt | Date | Record<string, unknown> | boolean | number | string | null;
2
2
  export declare class EntryBase {
3
3
  constructor(from?: Partial<EntryBase>);
4
4
  construct(): void;
5
5
  postLoad(): void;
6
+ postRemove(): void;
6
7
  postSave(): void;
7
8
  preLoad(): void;
9
+ preRemove(): void;
8
10
  preSave(): void;
11
+ remove(): Promise<boolean>;
9
12
  save(): Promise<boolean>;
10
13
  }
11
14
  export declare type ForeignKeyActions = "cascade" | "no action" | "restrict" | "set default" | "set null";
@@ -85,6 +88,7 @@ export declare abstract class DB<T extends Transaction> {
85
88
  abstract begin(): Promise<T>;
86
89
  abstract escape(value: Natural): string;
87
90
  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[]>;
91
+ abstract remove(tableName: string, pk: Attribute<Natural, unknown>): (this: EntryBase & Record<string, Natural>) => Promise<boolean>;
88
92
  abstract save(tableName: string, attributes: Record<string, string>, pk: Attribute<Natural, unknown>): (this: EntryBase & Record<string, Natural>) => Promise<boolean>;
89
93
  abstract dropConstraints(table: Table): Promise<number[]>;
90
94
  abstract dropFields(table: Table): Promise<void>;
@@ -106,7 +106,8 @@ export declare class Sedentary<D extends DB<T>, T extends Transaction> {
106
106
  DATETIME(): Type<Date, unknown>;
107
107
  FKEY<N extends Natural, E extends EntryBase>(attribute: Attribute<N, E>, options?: ForeignKeyOptions): Type<N, E>;
108
108
  INT(size?: number): Type<number, unknown>;
109
- INT8(): Type<string, unknown>;
109
+ INT8(): Type<BigInt, unknown>;
110
+ NUMBER(): Type<number, unknown>;
110
111
  VARCHAR(size?: number): Type<string, unknown>;
111
112
  private checkDB;
112
113
  private checkOrderBy;
package/package.json CHANGED
@@ -9,16 +9,16 @@
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.23",
12
+ "@types/node": "17.0.24",
13
13
  "@types/yamljs": "0.2.31",
14
- "@typescript-eslint/eslint-plugin": "5.17.0",
15
- "@typescript-eslint/parser": "5.17.0",
16
- "eslint": "8.12.0",
14
+ "@typescript-eslint/eslint-plugin": "5.19.0",
15
+ "@typescript-eslint/parser": "5.19.0",
16
+ "eslint": "8.13.0",
17
17
  "mocha": "9.2.2",
18
18
  "nyc": "15.1.0",
19
- "prettier": "2.6.1",
19
+ "prettier": "2.6.2",
20
20
  "ts-node": "10.7.0",
21
- "tsd": "0.19.1",
21
+ "tsd": "0.20.0",
22
22
  "typescript": "4.6.3",
23
23
  "yamljs": "0.3.0"
24
24
  },
@@ -79,5 +79,5 @@
79
79
  }
80
80
  },
81
81
  "types": "./dist/types/index.d.ts",
82
- "version": "0.0.31"
82
+ "version": "0.0.34"
83
83
  }