@snowtop/ent 0.1.0-alpha96 → 0.1.0-alpha97

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@snowtop/ent",
3
- "version": "0.1.0-alpha96",
3
+ "version": "0.1.0-alpha97",
4
4
  "description": "snowtop ent framework",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",
package/schema/field.d.ts CHANGED
@@ -25,31 +25,36 @@ export declare class UUIDField extends BaseField implements Field {
25
25
  valid(val: any): Promise<boolean>;
26
26
  }
27
27
  export declare function UUIDType(options?: FieldOptions): UUIDField;
28
- export interface IntegerOptions extends FieldOptions {
29
- min?: number;
30
- max?: number;
28
+ export interface IntegerOptions extends NumberOptions<number> {
31
29
  }
32
- export declare class IntegerField extends BaseField implements Field {
30
+ export interface NumberOptions<T> extends FieldOptions {
31
+ min?: T;
32
+ max?: T;
33
+ }
34
+ export declare class NumberField<T> extends BaseField {
33
35
  type: Type;
34
36
  private validators;
35
37
  private options;
36
- constructor(options?: IntegerOptions);
37
- getOptions(): IntegerOptions;
38
+ constructor(options?: NumberOptions<T>);
39
+ getOptions(): NumberOptions<T>;
38
40
  private handleOptions;
39
- min(l: number): this;
40
- max(l: number): this;
41
+ min(l: T): this;
42
+ max(l: T): this;
41
43
  valid(val: any): boolean;
42
44
  validate(validator: (str: number) => boolean): this;
43
45
  }
46
+ export declare class IntegerField extends NumberField<number> implements Field {
47
+ type: Type;
48
+ }
44
49
  export declare function IntegerType(options?: IntegerOptions): IntegerField;
45
- export declare class BigIntegerField extends BaseField implements Field {
50
+ export declare class BigIntegerField extends NumberField<BigInt> implements Field {
46
51
  type: Type;
47
52
  }
48
- export declare function BigIntegerType(options?: FieldOptions): BigIntegerField;
49
- export declare class FloatField extends BaseField implements Field {
53
+ export declare function BigIntegerType(options?: NumberOptions<BigInt>): BigIntegerField;
54
+ export declare class FloatField extends NumberField<number> implements Field {
50
55
  type: Type;
51
56
  }
52
- export declare function FloatType(options?: FieldOptions): FloatField;
57
+ export declare function FloatType(options?: NumberOptions<number>): FloatField;
53
58
  export declare class BooleanField extends BaseField implements Field {
54
59
  type: Type;
55
60
  }
package/schema/field.js CHANGED
@@ -23,7 +23,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
23
23
  return result;
24
24
  };
25
25
  Object.defineProperty(exports, "__esModule", { value: true });
26
- exports.UUIDListType = exports.IntegerEnumListType = exports.EnumListType = exports.DateListType = exports.TimetzListType = exports.TimeListType = exports.TimestamptzListType = exports.TimestampListType = exports.BooleanListType = exports.BigIntegerListType = exports.FloatListType = exports.IntegerListType = exports.IntListType = exports.StringListType = exports.ListField = exports.IntegerEnumType = exports.IntegerEnumField = exports.EnumType = exports.StringEnumField = exports.EnumField = exports.DateType = exports.DateField = exports.TimetzType = exports.TimeType = exports.TimeField = exports.leftPad = exports.TimestamptzType = exports.TimestampType = exports.TimestampField = exports.StringType = exports.PolymorphicStringField = exports.StringField = exports.BooleanType = exports.BooleanField = exports.FloatType = exports.FloatField = exports.BigIntegerType = exports.BigIntegerField = exports.IntegerType = exports.IntegerField = exports.UUIDType = exports.UUIDField = exports.BaseField = void 0;
26
+ exports.UUIDListType = exports.IntegerEnumListType = exports.EnumListType = exports.DateListType = exports.TimetzListType = exports.TimeListType = exports.TimestamptzListType = exports.TimestampListType = exports.BooleanListType = exports.BigIntegerListType = exports.FloatListType = exports.IntegerListType = exports.IntListType = exports.StringListType = exports.ListField = exports.IntegerEnumType = exports.IntegerEnumField = exports.EnumType = exports.StringEnumField = exports.EnumField = exports.DateType = exports.DateField = exports.TimetzType = exports.TimeType = exports.TimeField = exports.leftPad = exports.TimestamptzType = exports.TimestampType = exports.TimestampField = exports.StringType = exports.PolymorphicStringField = exports.StringField = exports.BooleanType = exports.BooleanField = exports.FloatType = exports.FloatField = exports.BigIntegerType = exports.BigIntegerField = exports.IntegerType = exports.IntegerField = exports.NumberField = exports.UUIDType = exports.UUIDField = exports.BaseField = void 0;
27
27
  const luxon_1 = require("luxon");
28
28
  const camel_case_1 = require("camel-case");
29
29
  const util_1 = require("util");
@@ -119,9 +119,10 @@ function UUIDType(options) {
119
119
  return Object.assign(result, options);
120
120
  }
121
121
  exports.UUIDType = UUIDType;
122
- class IntegerField extends BaseField {
122
+ class NumberField extends BaseField {
123
123
  constructor(options) {
124
124
  super();
125
+ // to be overriden as needed
125
126
  this.type = { dbType: schema_1.DBType.Int };
126
127
  this.validators = [];
127
128
  this.options = {};
@@ -145,9 +146,11 @@ class IntegerField extends BaseField {
145
146
  this.options = options;
146
147
  }
147
148
  min(l) {
149
+ // @ts-ignore Operator '>=' cannot be applied to types 'number' and 'T'.
148
150
  return this.validate((val) => val >= l);
149
151
  }
150
152
  max(l) {
153
+ // @ts-ignore Operator '<=' cannot be applied to types 'number' and 'T'.
151
154
  return this.validate((val) => val <= l);
152
155
  }
153
156
  valid(val) {
@@ -163,13 +166,20 @@ class IntegerField extends BaseField {
163
166
  return this;
164
167
  }
165
168
  }
169
+ exports.NumberField = NumberField;
170
+ class IntegerField extends NumberField {
171
+ constructor() {
172
+ super(...arguments);
173
+ this.type = { dbType: schema_1.DBType.Int };
174
+ }
175
+ }
166
176
  exports.IntegerField = IntegerField;
167
177
  function IntegerType(options) {
168
178
  let result = new IntegerField(options);
169
179
  return Object.assign(result, options);
170
180
  }
171
181
  exports.IntegerType = IntegerType;
172
- class BigIntegerField extends BaseField {
182
+ class BigIntegerField extends NumberField {
173
183
  constructor() {
174
184
  super(...arguments);
175
185
  this.type = { dbType: schema_1.DBType.BigInt };
@@ -177,11 +187,11 @@ class BigIntegerField extends BaseField {
177
187
  }
178
188
  exports.BigIntegerField = BigIntegerField;
179
189
  function BigIntegerType(options) {
180
- let result = new BigIntegerField();
190
+ let result = new BigIntegerField(options);
181
191
  return Object.assign(result, options);
182
192
  }
183
193
  exports.BigIntegerType = BigIntegerType;
184
- class FloatField extends BaseField {
194
+ class FloatField extends NumberField {
185
195
  constructor() {
186
196
  super(...arguments);
187
197
  this.type = { dbType: schema_1.DBType.Float };
@@ -189,7 +199,7 @@ class FloatField extends BaseField {
189
199
  }
190
200
  exports.FloatField = FloatField;
191
201
  function FloatType(options) {
192
- let result = new FloatField();
202
+ let result = new FloatField(options);
193
203
  return Object.assign(result, options);
194
204
  }
195
205
  exports.FloatType = FloatType;