sedentary 0.0.30 → 0.0.33

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,7 @@ 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
58
  }
59
59
  VARCHAR(size) {
60
60
  const message = "Sedentary.VARCHAR: 'size' argument: Wrong value, expected positive integer";
@@ -280,6 +280,8 @@ class Sedentary {
280
280
  })();
281
281
  const { base, defaultValue } = ret;
282
282
  if (defaultValue !== undefined) {
283
+ if (base === BigInt && typeof defaultValue !== "bigint")
284
+ throw new Error(`Sedentary.model: '${modelName}' model: '${attributeName}' attribute: 'defaultValue' option: Wrong type, expected 'BigInt'`);
283
285
  if (base === Date && !(defaultValue instanceof Date))
284
286
  throw new Error(`Sedentary.model: '${modelName}' model: '${attributeName}' attribute: 'defaultValue' option: Wrong type, expected 'Date'`);
285
287
  if (base === Number && typeof defaultValue !== "number")
@@ -449,6 +451,17 @@ class Sedentary {
449
451
  Object.defineProperty(ret, "foreignKeys", { value: foreignKeys });
450
452
  Object.defineProperty(ret, "methods", { value: methods });
451
453
  Object.assign(ret.prototype, methods);
454
+ const remove = this.db.remove(tableName, pk);
455
+ ret.prototype.remove = async function () {
456
+ if (!this.loaded)
457
+ throw new Error(`${modelName}.remove: Can't remove a never saved Entry`);
458
+ this.preRemove();
459
+ const ret = await remove.call(this);
460
+ if (ret)
461
+ this.postRemove();
462
+ return ret;
463
+ };
464
+ Object.defineProperty(ret.prototype.remove, "name", { value: modelName + ".remove" });
452
465
  const save = this.db.save(tableName, attr2field, pk);
453
466
  ret.prototype.save = async function () {
454
467
  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,7 @@ 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
52
  }
53
53
  VARCHAR(size) {
54
54
  const message = "Sedentary.VARCHAR: 'size' argument: Wrong value, expected positive integer";
@@ -274,6 +274,8 @@ export class Sedentary {
274
274
  })();
275
275
  const { base, defaultValue } = ret;
276
276
  if (defaultValue !== undefined) {
277
+ if (base === BigInt && typeof defaultValue !== "bigint")
278
+ throw new Error(`Sedentary.model: '${modelName}' model: '${attributeName}' attribute: 'defaultValue' option: Wrong type, expected 'BigInt'`);
277
279
  if (base === Date && !(defaultValue instanceof Date))
278
280
  throw new Error(`Sedentary.model: '${modelName}' model: '${attributeName}' attribute: 'defaultValue' option: Wrong type, expected 'Date'`);
279
281
  if (base === Number && typeof defaultValue !== "number")
@@ -443,6 +445,17 @@ export class Sedentary {
443
445
  Object.defineProperty(ret, "foreignKeys", { value: foreignKeys });
444
446
  Object.defineProperty(ret, "methods", { value: methods });
445
447
  Object.assign(ret.prototype, methods);
448
+ const remove = this.db.remove(tableName, pk);
449
+ ret.prototype.remove = async function () {
450
+ if (!this.loaded)
451
+ throw new Error(`${modelName}.remove: Can't remove a never saved Entry`);
452
+ this.preRemove();
453
+ const ret = await remove.call(this);
454
+ if (ret)
455
+ this.postRemove();
456
+ return ret;
457
+ };
458
+ Object.defineProperty(ret.prototype.remove, "name", { value: modelName + ".remove" });
446
459
  const save = this.db.save(tableName, attr2field, pk);
447
460
  ret.prototype.save = async function () {
448
461
  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>;
@@ -62,7 +62,7 @@ declare type ModelAttributesIf<A extends AttributesDefinition, T> = keyof A exte
62
62
  declare type ModelAttributes<A extends AttributesDefinition, B extends boolean, K extends string, P extends ModelStd> = K extends keyof A ? A : ModelAttributesIf<A, P extends new () => EntryBase ? P["attributes"] : {
63
63
  id: Type<BaseKeyType<B>, unknown>;
64
64
  }>;
65
- interface ModelLoad<A extends AttributesDefinition, E extends EntryBase> {
65
+ export interface ModelLoad<A extends AttributesDefinition, E extends EntryBase> {
66
66
  attributes: A;
67
67
  load(where: Condition<A>, order?: Order<A>, tx?: Transaction, lock?: boolean): Promise<E[]>;
68
68
  load(where: Condition<A>, tx: Transaction, lock?: boolean): Promise<E[]>;
@@ -106,7 +106,7 @@ 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
110
  VARCHAR(size?: number): Type<string, unknown>;
111
111
  private checkDB;
112
112
  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.30"
82
+ "version": "0.0.33"
83
83
  }