@itrocks/mysql-to-schema 0.0.4 → 0.0.5

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/cjs/to-type.d.ts CHANGED
@@ -4,6 +4,7 @@ export declare class ToType {
4
4
  defaultLength(rawType: string): number | undefined;
5
5
  defaultPrecision(rawType: string): number | undefined;
6
6
  length(rawType: string, mysqlType: string): number | undefined;
7
+ lengthMaxValue(mysqlType: string, signed: boolean): bigint | number | undefined;
7
8
  normalize(type: Type): void;
8
9
  precision(rawType: string, mysqlType: string): number | undefined;
9
10
  values(mysqlType: string): string[];
package/cjs/to-type.js CHANGED
@@ -43,6 +43,7 @@ class ToType {
43
43
  case 'tinyint':
44
44
  return new schema_1.Type('integer', {
45
45
  length: this.length(rawType, mysqlType),
46
+ maxValue: this.lengthMaxValue(mysqlType, !mysqlType.includes('unsigned')),
46
47
  signed: !mysqlType.includes('unsigned'),
47
48
  zeroFill: mysqlType.includes('zerofill')
48
49
  });
@@ -131,6 +132,17 @@ class ToType {
131
132
  ? +mysqlType.substring(position, Math.min(mysqlType.indexOf(')', position), (mysqlType + ',').indexOf(',', position)))
132
133
  : this.defaultLength(rawType);
133
134
  }
135
+ lengthMaxValue(mysqlType, signed) {
136
+ switch (mysqlType) {
137
+ case 'tinyint': return signed ? 127 : 255;
138
+ case 'smallint': return signed ? 32767 : 65535;
139
+ case 'mediumint': return signed ? 8388607 : 16777215;
140
+ case 'int':
141
+ case 'integer': return signed ? 2147483647 : 4294967295;
142
+ case 'bigint': return signed ? 2n ** 63n - 1n : 2n ** 64n - 1n;
143
+ }
144
+ return undefined;
145
+ }
134
146
  normalize(type) {
135
147
  switch (type.name) {
136
148
  case 'bit':
package/esm/to-type.d.ts CHANGED
@@ -4,6 +4,7 @@ export declare class ToType {
4
4
  defaultLength(rawType: string): number | undefined;
5
5
  defaultPrecision(rawType: string): number | undefined;
6
6
  length(rawType: string, mysqlType: string): number | undefined;
7
+ lengthMaxValue(mysqlType: string, signed: boolean): bigint | number | undefined;
7
8
  normalize(type: Type): void;
8
9
  precision(rawType: string, mysqlType: string): number | undefined;
9
10
  values(mysqlType: string): string[];
package/esm/to-type.js CHANGED
@@ -40,6 +40,7 @@ export class ToType {
40
40
  case 'tinyint':
41
41
  return new Type('integer', {
42
42
  length: this.length(rawType, mysqlType),
43
+ maxValue: this.lengthMaxValue(mysqlType, !mysqlType.includes('unsigned')),
43
44
  signed: !mysqlType.includes('unsigned'),
44
45
  zeroFill: mysqlType.includes('zerofill')
45
46
  });
@@ -128,6 +129,17 @@ export class ToType {
128
129
  ? +mysqlType.substring(position, Math.min(mysqlType.indexOf(')', position), (mysqlType + ',').indexOf(',', position)))
129
130
  : this.defaultLength(rawType);
130
131
  }
132
+ lengthMaxValue(mysqlType, signed) {
133
+ switch (mysqlType) {
134
+ case 'tinyint': return signed ? 127 : 255;
135
+ case 'smallint': return signed ? 32767 : 65535;
136
+ case 'mediumint': return signed ? 8388607 : 16777215;
137
+ case 'int':
138
+ case 'integer': return signed ? 2147483647 : 4294967295;
139
+ case 'bigint': return signed ? 2n ** 63n - 1n : 2n ** 64n - 1n;
140
+ }
141
+ return undefined;
142
+ }
131
143
  normalize(type) {
132
144
  switch (type.name) {
133
145
  case 'bit':
package/package.json CHANGED
@@ -45,5 +45,5 @@
45
45
  "build:esm": "tsc -p tsconfig.esm.json"
46
46
  },
47
47
  "types": "./esm/mysql-to-schema.d.ts",
48
- "version": "0.0.4"
48
+ "version": "0.0.5"
49
49
  }