sedentary 0.0.52 → 0.0.54

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/index.js CHANGED
@@ -57,8 +57,15 @@ class Sedentary {
57
57
  const { attributeName, fieldName, tableName, type, [db_1.base]: _base, [db_1.size]: _size } = attribute;
58
58
  return new db_1.Type({ [db_1.base]: _base, foreignKey: { attributeName, fieldName, options, tableName }, [db_1.size]: _size, type });
59
59
  }
60
+ Float(_size) {
61
+ const message = "Sedentary.Float: 'size' argument: Wrong value, expected 4 or 8";
62
+ _size = _size ? this.checkSize(_size, message) : 8;
63
+ if (_size !== 4 && _size !== 8)
64
+ throw new Error(message);
65
+ return new db_1.Type({ [db_1.base]: Number, [db_1.size]: _size, type: "FLOAT" });
66
+ }
60
67
  Int(_size) {
61
- const message = "Sedentary.INT: 'size' argument: Wrong value, expected 2 or 4";
68
+ const message = "Sedentary.Int: 'size' argument: Wrong value, expected 2 or 4";
62
69
  _size = _size ? this.checkSize(_size, message) : 4;
63
70
  if (_size !== 2 && _size !== 4)
64
71
  throw new Error(message);
@@ -77,7 +84,7 @@ class Sedentary {
77
84
  return new db_1.Type({ [db_1.base]: undefined, type: "NONE" });
78
85
  }
79
86
  VarChar(_size) {
80
- const message = "Sedentary.VARCHAR: 'size' argument: Wrong value, expected positive integer";
87
+ const message = "Sedentary.VarChar: 'size' argument: Wrong value, expected positive integer";
81
88
  _size = _size ? this.checkSize(_size, message) : undefined;
82
89
  return new db_1.Type({ [db_1.base]: String, [db_1.size]: _size, type: "VARCHAR" });
83
90
  }
@@ -272,7 +279,7 @@ class Sedentary {
272
279
  const call = (defaultValue, fieldName, notNull, unique, func, message1, message2) => {
273
280
  if (func === this.FKey)
274
281
  throw new Error(`${message1} 'this.FKey' can't be used directly`);
275
- if (![this.Boolean, this.DateTime, this.Int, this.JSON, this.Int8, this.None, this.Number, this.VarChar].includes(func))
282
+ if (![this.Boolean, this.DateTime, this.Float, this.Int, this.JSON, this.Int8, this.None, this.Number, this.VarChar].includes(func))
276
283
  throw new Error(`${message1} ${message2}`);
277
284
  return new db_1.Attribute({ attributeName, defaultValue, fieldName, modelName, notNull, tableName, unique, ...func() });
278
285
  };
package/dist/es/index.js CHANGED
@@ -45,8 +45,15 @@ export class Sedentary {
45
45
  const { attributeName, fieldName, tableName, type, [base]: _base, [size]: _size } = attribute;
46
46
  return new Type({ [base]: _base, foreignKey: { attributeName, fieldName, options, tableName }, [size]: _size, type });
47
47
  }
48
+ Float(_size) {
49
+ const message = "Sedentary.Float: 'size' argument: Wrong value, expected 4 or 8";
50
+ _size = _size ? this.checkSize(_size, message) : 8;
51
+ if (_size !== 4 && _size !== 8)
52
+ throw new Error(message);
53
+ return new Type({ [base]: Number, [size]: _size, type: "FLOAT" });
54
+ }
48
55
  Int(_size) {
49
- const message = "Sedentary.INT: 'size' argument: Wrong value, expected 2 or 4";
56
+ const message = "Sedentary.Int: 'size' argument: Wrong value, expected 2 or 4";
50
57
  _size = _size ? this.checkSize(_size, message) : 4;
51
58
  if (_size !== 2 && _size !== 4)
52
59
  throw new Error(message);
@@ -65,7 +72,7 @@ export class Sedentary {
65
72
  return new Type({ [base]: undefined, type: "NONE" });
66
73
  }
67
74
  VarChar(_size) {
68
- const message = "Sedentary.VARCHAR: 'size' argument: Wrong value, expected positive integer";
75
+ const message = "Sedentary.VarChar: 'size' argument: Wrong value, expected positive integer";
69
76
  _size = _size ? this.checkSize(_size, message) : undefined;
70
77
  return new Type({ [base]: String, [size]: _size, type: "VARCHAR" });
71
78
  }
@@ -260,7 +267,7 @@ export class Sedentary {
260
267
  const call = (defaultValue, fieldName, notNull, unique, func, message1, message2) => {
261
268
  if (func === this.FKey)
262
269
  throw new Error(`${message1} 'this.FKey' can't be used directly`);
263
- if (![this.Boolean, this.DateTime, this.Int, this.JSON, this.Int8, this.None, this.Number, this.VarChar].includes(func))
270
+ if (![this.Boolean, this.DateTime, this.Float, this.Int, this.JSON, this.Int8, this.None, this.Number, this.VarChar].includes(func))
264
271
  throw new Error(`${message1} ${message2}`);
265
272
  return new Attribute({ attributeName, defaultValue, fieldName, modelName, notNull, tableName, unique, ...func() });
266
273
  };
@@ -21,7 +21,7 @@ export declare class EntryBase {
21
21
  remove(): Promise<boolean>;
22
22
  save(): Promise<boolean>;
23
23
  }
24
- export declare type ForeignKeyActions = "cascade" | "no action" | "restrict" | "set default" | "set null";
24
+ export type ForeignKeyActions = "cascade" | "no action" | "restrict" | "set default" | "set null";
25
25
  export interface ForeignKeyOptions {
26
26
  onDelete?: ForeignKeyActions;
27
27
  onUpdate?: ForeignKeyActions;
@@ -1,6 +1,6 @@
1
1
  import { Attribute, DB, EntryBase, ForeignKeyOptions, Transaction, Type } from "./db";
2
2
  export { Action, Attribute, base, DB, deepCopy, deepDiff, EntryBase, ForeignKeyActions, ForeignKeyOptions, Index, loaded, size, Table, Transaction, transaction, Type } from "./db";
3
- export declare type TypeDefinition<T, E> = (() => Type<T, E>) | Type<T, E>;
3
+ export type TypeDefinition<T, E> = (() => Type<T, E>) | Type<T, E>;
4
4
  export interface AttributeOptions<T, E> {
5
5
  defaultValue?: T;
6
6
  fieldName?: string;
@@ -8,30 +8,30 @@ export interface AttributeOptions<T, E> {
8
8
  type: TypeDefinition<T, E>;
9
9
  unique?: boolean;
10
10
  }
11
- export declare type AttributeDefinition<T, E> = TypeDefinition<T, E> | AttributeOptions<T, E>;
12
- export declare type AttributesDefinition = {
11
+ export type AttributeDefinition<T, E> = TypeDefinition<T, E> | AttributeOptions<T, E>;
12
+ export type AttributesDefinition = {
13
13
  [key: string]: AttributeDefinition<unknown, unknown>;
14
14
  };
15
15
  declare const attributes: unique symbol;
16
16
  declare const methods: unique symbol;
17
- declare type ForeignKeysAttributes<T, k> = T extends AttributeDefinition<unknown, infer E> ? (E extends EntryBase ? k : never) : never;
18
- declare type ForeignKeys<A extends AttributesDefinition> = {
17
+ type ForeignKeysAttributes<T, k> = T extends AttributeDefinition<unknown, infer E> ? (E extends EntryBase ? k : never) : never;
18
+ type ForeignKeys<A extends AttributesDefinition> = {
19
19
  [a in keyof A]?: ForeignKeysAttributes<A[a], a>;
20
20
  }[keyof A];
21
- declare type Native___<T> = T extends Type<infer N, unknown> ? N : never;
22
- declare type Native__<T> = T extends () => Type<infer N, infer E> ? Native___<Type<N, E>> : Native___<T>;
23
- declare type Native_<T, N, E> = T extends {
21
+ type Native___<T> = T extends Type<infer N, unknown> ? N : never;
22
+ type Native__<T> = T extends () => Type<infer N, infer E> ? Native___<Type<N, E>> : Native___<T>;
23
+ type Native_<T, N, E> = T extends {
24
24
  notNull: true;
25
25
  } ? Native___<Type<N, E>> : Native___<Type<N, E>> | null;
26
- declare type Native<T> = T extends AttributeOptions<infer N, infer E> ? Native_<T, N, E> : Native__<T> | null;
27
- export declare type IndexAttributes = string[] | string;
26
+ type Native<T> = T extends AttributeOptions<infer N, infer E> ? Native_<T, N, E> : Native__<T> | null;
27
+ export type IndexAttributes = string[] | string;
28
28
  export interface IndexOptions {
29
29
  attributes: IndexAttributes;
30
30
  type?: "btree" | "hash";
31
31
  unique?: boolean;
32
32
  }
33
- export declare type IndexDefinition = IndexAttributes | IndexOptions;
34
- export declare type IndexesDefinition = {
33
+ export type IndexDefinition = IndexAttributes | IndexOptions;
34
+ export type IndexesDefinition = {
35
35
  [key: string]: IndexDefinition;
36
36
  };
37
37
  interface BaseModelOptions {
@@ -44,28 +44,28 @@ export interface ModelOptions extends BaseModelOptions {
44
44
  parent?: Attribute<unknown, EntryBase>;
45
45
  primaryKey?: string;
46
46
  }
47
- declare type ConditionAttribute<T> = T | ["=" | ">" | "<" | ">=" | "<=" | "<>", T] | ["IN", T[]] | ["IS NULL"] | ["LIKE", string] | ["NOT"];
48
- declare type ConditionBase<A extends AttributesDefinition> = string | {
47
+ type ConditionAttribute<T> = T | ["=" | ">" | "<" | ">=" | "<=" | "<>", T] | ["IN", T[]] | ["IS NULL"] | ["LIKE", string] | ["NOT"];
48
+ type ConditionBase<A extends AttributesDefinition> = string | {
49
49
  [a in keyof A]?: ConditionAttribute<Native<A[a]>>;
50
50
  };
51
- declare type Condition<A extends AttributesDefinition> = ConditionBase<A> | ["NOT", Condition<A>] | ["AND", ...Condition<A>[]] | ["OR", ...Condition<A>[]];
52
- declare type Order_<A extends AttributesDefinition> = keyof A | `-${string & keyof A}`;
53
- declare type Order<A extends AttributesDefinition> = Order_<A> | Order_<A>[];
54
- declare type UnionToIntersection<U> = (U extends unknown ? (k: U) => void : never) extends (k: infer I) => void ? I : never;
55
- declare type IsUnion<T> = [T] extends [UnionToIntersection<T>] ? false : true;
56
- declare type BaseKeyType<B extends boolean> = IsUnion<B> extends true ? number : B extends true ? string : number;
57
- declare type KeyType<B extends boolean, P extends ModelStd> = P extends new () => EntryBase ? (P extends Attribute<infer T, EntryBase> ? T : never) : BaseKeyType<B>;
58
- declare type ForeignKey<A> = A extends AttributeDefinition<unknown, infer E> ? () => Promise<E> : never;
59
- declare type EntryBaseAttributes<A extends AttributesDefinition> = {
51
+ type Condition<A extends AttributesDefinition> = ConditionBase<A> | ["NOT", Condition<A>] | ["AND", ...Condition<A>[]] | ["OR", ...Condition<A>[]];
52
+ type Order_<A extends AttributesDefinition> = keyof A | `-${string & keyof A}`;
53
+ type Order<A extends AttributesDefinition> = Order_<A> | Order_<A>[];
54
+ type UnionToIntersection<U> = (U extends unknown ? (k: U) => void : never) extends (k: infer I) => void ? I : never;
55
+ type IsUnion<T> = [T] extends [UnionToIntersection<T>] ? false : true;
56
+ type BaseKeyType<B extends boolean> = IsUnion<B> extends true ? number : B extends true ? string : number;
57
+ type KeyType<B extends boolean, P extends ModelStd> = P extends new () => EntryBase ? (P extends Attribute<infer T, EntryBase> ? T : never) : BaseKeyType<B>;
58
+ type ForeignKey<A> = A extends AttributeDefinition<unknown, infer E> ? () => Promise<E> : never;
59
+ type EntryBaseAttributes<A extends AttributesDefinition> = {
60
60
  [a in keyof A]: Native<A[a]>;
61
61
  };
62
- declare type EntryMethodsBase<P extends ModelStd> = P extends new () => EntryBase ? P[typeof methods] : EntryBase;
63
- declare type EntryMethodsFK<A extends AttributesDefinition> = {
62
+ type EntryMethodsBase<P extends ModelStd> = P extends new () => EntryBase ? P[typeof methods] : EntryBase;
63
+ type EntryMethodsFK<A extends AttributesDefinition> = {
64
64
  [a in ForeignKeys<A> & string as `${a}Load`]: ForeignKey<A[a]>;
65
65
  };
66
- declare type EntryMethods<A extends AttributesDefinition, P extends ModelStd> = keyof EntryMethodsFK<A> extends never ? EntryMethodsBase<P> : EntryMethodsBase<P> & EntryMethodsFK<A>;
67
- declare type ModelAttributesIf<A extends AttributesDefinition, T> = keyof A extends never ? T : T & A;
68
- 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[typeof attributes] : {
66
+ type EntryMethods<A extends AttributesDefinition, P extends ModelStd> = keyof EntryMethodsFK<A> extends never ? EntryMethodsBase<P> : EntryMethodsBase<P> & EntryMethodsFK<A>;
67
+ type ModelAttributesIf<A extends AttributesDefinition, T> = keyof A extends never ? T : T & A;
68
+ 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[typeof attributes] : {
69
69
  id: {
70
70
  notNull: true;
71
71
  type: Type<BaseKeyType<B>, unknown>;
@@ -78,7 +78,7 @@ export interface ModelLoad<A extends AttributesDefinition, E extends EntryBase>
78
78
  load(where: Condition<A>, tx: Transaction, lock?: boolean): Promise<E[]>;
79
79
  cancel(where: Condition<A>, tx?: Transaction): Promise<number>;
80
80
  }
81
- declare type ModelBase<T, A extends AttributesDefinition, EA extends Record<string, unknown>, EM extends EntryBase, E extends EntryBase> = (new (from?: Partial<EA>, tx?: Transaction) => E) & Attribute<T, E> & {
81
+ type ModelBase<T, A extends AttributesDefinition, EA extends Record<string, unknown>, EM extends EntryBase, E extends EntryBase> = (new (from?: Partial<EA>, tx?: Transaction) => E) & Attribute<T, E> & {
82
82
  [attributes]: A;
83
83
  foreignKeys: Record<string, boolean>;
84
84
  [methods]: EM;
@@ -87,20 +87,20 @@ declare type ModelBase<T, A extends AttributesDefinition, EA extends Record<stri
87
87
  } & {
88
88
  [a in keyof A]: Attribute<Native<A[a]>, E>;
89
89
  } & ModelLoad<A, E>;
90
- declare type Model<T, A extends AttributesDefinition, EM extends EntryBase> = ModelBase<T, A, EntryBaseAttributes<A>, EM, EntryBaseAttributes<A> & EM>;
91
- declare type ModelStd = Attribute<unknown, EntryBase> & {
90
+ type Model<T, A extends AttributesDefinition, EM extends EntryBase> = ModelBase<T, A, EntryBaseAttributes<A>, EM, EntryBaseAttributes<A> & EM>;
91
+ type ModelStd = Attribute<unknown, EntryBase> & {
92
92
  [attributes]: AttributesDefinition;
93
93
  foreignKeys: Record<string, boolean>;
94
94
  [methods]: EntryBase;
95
95
  parent?: ModelStd;
96
96
  };
97
- export declare type Entry<M> = M extends new () => infer E ? E : never;
98
- export declare type OrderBy<M> = M extends {
97
+ export type Entry<M> = M extends new () => infer E ? E : never;
98
+ export type OrderBy<M> = M extends {
99
99
  load(where: unknown, order?: infer T): void;
100
100
  load(where: unknown, limit?: number): void;
101
101
  load(where: unknown, tx?: Transaction): void;
102
102
  } ? Exclude<T, undefined> : never;
103
- export declare type Where<M> = M extends {
103
+ export type Where<M> = M extends {
104
104
  load(where: infer T): void;
105
105
  } ? T : never;
106
106
  export interface SedentaryOptions {
@@ -118,6 +118,7 @@ export declare class Sedentary<D extends DB<T>, T extends Transaction> {
118
118
  Boolean(): Type<boolean, unknown>;
119
119
  DateTime(): Type<Date, unknown>;
120
120
  FKey<T, E extends EntryBase>(attribute: Attribute<T, E>, options?: ForeignKeyOptions): Type<T, E>;
121
+ Float(_size?: number): Type<number, unknown>;
121
122
  Int(_size?: number): Type<number, unknown>;
122
123
  Int8(): Type<bigint, unknown>;
123
124
  JSON<T>(): Type<T, unknown>;
package/package.json CHANGED
@@ -7,7 +7,7 @@
7
7
  ],
8
8
  "description": "The ORM which never needs to migrate",
9
9
  "engines": {
10
- "node": ">=14.0"
10
+ "node": ">=18.0"
11
11
  },
12
12
  "funding": {
13
13
  "url": "https://blockchain.info/address/1Md9WFAHrXTb3yPBwQWmUfv2RmzrtbHioB"
@@ -27,10 +27,13 @@
27
27
  "module": "./dist/es/index.js",
28
28
  "name": "sedentary",
29
29
  "optionalDependencies": {
30
- "fsevents": "2.3.2"
30
+ "fsevents": "^2.3.3"
31
31
  },
32
32
  "readmeFilename": "README.md",
33
- "repository": "https://github.com/iccicci/sedentary",
33
+ "repository": {
34
+ "type": "git",
35
+ "url": "git+https://github.com/iccicci/sedentary.git"
36
+ },
34
37
  "scripts": {
35
38
  "build": "make build",
36
39
  "coverage": "jest --coverage --no-cache --runInBand",
@@ -58,5 +61,5 @@
58
61
  }
59
62
  },
60
63
  "types": "./dist/types/index.d.ts",
61
- "version": "0.0.52"
64
+ "version": "0.0.54"
62
65
  }