@tstdl/base 0.91.39 → 0.91.41
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/examples/orm/test.js +1 -0
- package/examples/orm/user.model.d.ts +8 -1
- package/examples/orm/user.model.js +18 -2
- package/orm/types.d.ts +6 -5
- package/orm/types.js +2 -2
- package/package.json +3 -2
- package/schema/schemas/number.js +2 -1
package/examples/orm/test.js
CHANGED
|
@@ -1,9 +1,16 @@
|
|
|
1
|
-
import { Entity, Integer } from '../../orm/index.js';
|
|
1
|
+
import { Array, Entity, Integer, Text } from '../../orm/index.js';
|
|
2
|
+
export declare enum Foo {
|
|
3
|
+
Bar = 0,
|
|
4
|
+
Baz = 1
|
|
5
|
+
}
|
|
2
6
|
export declare class User extends Entity {
|
|
3
7
|
static entityName: string;
|
|
4
8
|
name: string;
|
|
5
9
|
nickNames: string[];
|
|
10
|
+
nickNames2: Array<Text>;
|
|
6
11
|
age: Integer | null;
|
|
12
|
+
age2: number | null;
|
|
7
13
|
hasAge: boolean;
|
|
8
14
|
mail: string;
|
|
15
|
+
foo: Foo;
|
|
9
16
|
}
|
|
@@ -7,15 +7,23 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
|
7
7
|
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
8
8
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
9
9
|
};
|
|
10
|
-
import { Entity, Integer, Unique } from '../../orm/index.js';
|
|
11
|
-
import {
|
|
10
|
+
import { Array, Entity, Integer, Unique } from '../../orm/index.js';
|
|
11
|
+
import { BooleanProperty, StringProperty } from '../../schema/index.js';
|
|
12
|
+
export var Foo;
|
|
13
|
+
(function (Foo) {
|
|
14
|
+
Foo[Foo["Bar"] = 0] = "Bar";
|
|
15
|
+
Foo[Foo["Baz"] = 1] = "Baz";
|
|
16
|
+
})(Foo || (Foo = {}));
|
|
12
17
|
export class User extends Entity {
|
|
13
18
|
static entityName = 'User';
|
|
14
19
|
name;
|
|
15
20
|
nickNames;
|
|
21
|
+
nickNames2;
|
|
16
22
|
age;
|
|
23
|
+
age2;
|
|
17
24
|
hasAge;
|
|
18
25
|
mail;
|
|
26
|
+
foo;
|
|
19
27
|
}
|
|
20
28
|
__decorate([
|
|
21
29
|
StringProperty(),
|
|
@@ -25,10 +33,18 @@ __decorate([
|
|
|
25
33
|
Array(String),
|
|
26
34
|
__metadata("design:type", Array)
|
|
27
35
|
], User.prototype, "nickNames", void 0);
|
|
36
|
+
__decorate([
|
|
37
|
+
Array(String),
|
|
38
|
+
__metadata("design:type", Object)
|
|
39
|
+
], User.prototype, "nickNames2", void 0);
|
|
28
40
|
__decorate([
|
|
29
41
|
Integer({ nullable: true }),
|
|
30
42
|
__metadata("design:type", Object)
|
|
31
43
|
], User.prototype, "age", void 0);
|
|
44
|
+
__decorate([
|
|
45
|
+
BooleanProperty(),
|
|
46
|
+
__metadata("design:type", Object)
|
|
47
|
+
], User.prototype, "age2", void 0);
|
|
32
48
|
__decorate([
|
|
33
49
|
BooleanProperty(),
|
|
34
50
|
__metadata("design:type", Boolean)
|
package/orm/types.d.ts
CHANGED
|
@@ -1,21 +1,22 @@
|
|
|
1
1
|
import type { HasDefault as DrizzleHasDefault, IsPrimaryKey as DrizzleIsPrimaryKey } from 'drizzle-orm';
|
|
2
|
-
import type { boolean, doublePrecision, integer, PgColumnBuilderBase, text, uuid } from 'drizzle-orm/pg-core';
|
|
2
|
+
import type { boolean, doublePrecision, integer, PgColumnBuilder, PgColumnBuilderBase, text, uuid } from 'drizzle-orm/pg-core';
|
|
3
3
|
import type { GetTagMetadata, Tagged, UnwrapTagged } from 'type-fest';
|
|
4
|
-
import { Integer } from '../schema/index.js';
|
|
5
|
-
import type { Record } from '../types.js';
|
|
4
|
+
import { Integer, Array } from '../schema/index.js';
|
|
5
|
+
import type { ObjectLiteral, Record } from '../types.js';
|
|
6
6
|
import { Uuid } from './schemas/index.js';
|
|
7
7
|
export type IsPrimaryKey<T> = T extends Tagged<unknown, 'column', PgColumnBuilderBase> ? Tagged<UnwrapTagged<T>, 'column', DrizzleIsPrimaryKey<GetTagMetadata<T, 'column'>>> : Tagged<T, 'column', ColumnBuilder<T>>;
|
|
8
8
|
export type HasDefault<T> = T extends Tagged<unknown, 'column', PgColumnBuilderBase> ? Tagged<UnwrapTagged<T>, 'column', DrizzleHasDefault<GetTagMetadata<T, 'column'>>> : Tagged<T, 'column', ColumnBuilder<T>>;
|
|
9
9
|
export type Nested<T extends Record> = Tagged<T, 'column', {
|
|
10
10
|
nested: T;
|
|
11
11
|
}>;
|
|
12
|
-
export type ColumnBuilder<T, ColumnName extends string = never> = T extends Tagged<T, 'column', any> ? GetTagMetadata<T, 'column'> : T extends string ? string extends ColumnName ? ReturnType<typeof text<ColumnName, string, [string, ...string[]]>> : ReturnType<typeof text<string, [string, ...string[]]>> : T extends number ? string extends ColumnName ? ReturnType<typeof doublePrecision<ColumnName>> : ReturnType<typeof doublePrecision> : T extends boolean ? string extends ColumnName ? ReturnType<typeof boolean<ColumnName>> : ReturnType<typeof boolean> : never;
|
|
12
|
+
export type ColumnBuilder<T, ColumnName extends string = never> = T extends Tagged<T, 'column', any> ? GetTagMetadata<T, 'column'> : T extends string ? string extends ColumnName ? ReturnType<typeof text<ColumnName, string, [string, ...string[]]>> : ReturnType<typeof text<string, [string, ...string[]]>> : T extends number ? string extends ColumnName ? ReturnType<typeof doublePrecision<ColumnName>> : ReturnType<typeof doublePrecision> : T extends boolean ? string extends ColumnName ? ReturnType<typeof boolean<ColumnName>> : ReturnType<typeof boolean> : T extends (infer U)[] ? string extends ColumnName ? ReturnType<ColumnBuilder<U, ColumnName>['array']> : ReturnType<ColumnBuilder<U>['array']> : never;
|
|
13
13
|
export type TypeBuilder<T, ColumnName extends string = never> = [
|
|
14
14
|
ColumnName
|
|
15
15
|
] extends [never] ? T extends Tagged<any, 'column', PgColumnBuilderBase> ? T : T extends infer U ? Tagged<U, 'column', ColumnBuilder<U>> : never : never;
|
|
16
|
+
export type Array<T extends Tagged<ObjectLiteral, 'column', PgColumnBuilder<any>>> = Tagged<UnwrapTagged<T>[], 'column', ReturnType<GetTagMetadata<T, 'column'>['array']>>;
|
|
16
17
|
export type Text = Tagged<string, 'column', ReturnType<typeof text<string, [string, ...string[]]>>>;
|
|
17
18
|
export type Uuid = Tagged<string, 'column', ReturnType<typeof uuid>>;
|
|
18
19
|
export type Integer = Tagged<number, 'column', ReturnType<typeof integer>>;
|
|
19
20
|
export type DoublePrecision = Tagged<number, 'column', ReturnType<typeof doublePrecision>>;
|
|
20
21
|
export type Boolean = Tagged<number, 'column', ReturnType<typeof boolean>>;
|
|
21
|
-
export { Integer, Uuid };
|
|
22
|
+
export { Integer, Uuid, Array };
|
package/orm/types.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
/* eslint-disable @typescript-eslint/no-redeclare, @typescript-eslint/naming-convention */
|
|
2
|
-
import { Integer } from '../schema/index.js';
|
|
2
|
+
import { Integer, Array } from '../schema/index.js';
|
|
3
3
|
import { Uuid } from './schemas/index.js';
|
|
4
|
-
export { Integer, Uuid };
|
|
4
|
+
export { Integer, Uuid, Array };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tstdl/base",
|
|
3
|
-
"version": "0.91.
|
|
3
|
+
"version": "0.91.41",
|
|
4
4
|
"author": "Patrick Hein",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
@@ -68,6 +68,7 @@
|
|
|
68
68
|
"./module": "./module/index.js",
|
|
69
69
|
"./object-storage": "./object-storage/index.js",
|
|
70
70
|
"./openid-connect": "./openid-connect/index.js",
|
|
71
|
+
"./orm": "./orm/index.js",
|
|
71
72
|
"./password": "./password/index.js",
|
|
72
73
|
"./pdf": "./pdf/index.js",
|
|
73
74
|
"./pool": "./pool/index.js",
|
|
@@ -129,7 +130,7 @@
|
|
|
129
130
|
"@types/pg": "8.11",
|
|
130
131
|
"@typescript-eslint/eslint-plugin": "7.17",
|
|
131
132
|
"concurrently": "9.1",
|
|
132
|
-
"drizzle-kit": "0.
|
|
133
|
+
"drizzle-kit": "0.28",
|
|
133
134
|
"eslint": "8.57",
|
|
134
135
|
"eslint-import-resolver-typescript": "3.6",
|
|
135
136
|
"eslint-plugin-import": "2.31",
|
package/schema/schemas/number.js
CHANGED
|
@@ -22,11 +22,12 @@ export class NumberSchema extends SimpleSchema {
|
|
|
22
22
|
constraints: [
|
|
23
23
|
(options?.integer == true) ? (value) => globalThis.Number.isInteger(value) ? ({ success: true }) : ({ success: false, error: 'Value is not an integer.' }) : null,
|
|
24
24
|
isNumber(options?.minimum) ? (value) => (value >= this.minimum) ? ({ success: true }) : ({ success: false, error: `Value must be more than or equal to ${this.minimum}.` }) : null,
|
|
25
|
-
isNumber(options?.maximum) ? (value) => (value
|
|
25
|
+
isNumber(options?.maximum) ? (value) => (value <= this.maximum) ? ({ success: true }) : ({ success: false, error: `Value must be less than or equal to ${this.maximum}.` }) : null
|
|
26
26
|
]
|
|
27
27
|
});
|
|
28
28
|
this.integer = options?.integer ?? false;
|
|
29
29
|
this.minimum = options?.minimum ?? null;
|
|
30
|
+
this.maximum = options?.maximum ?? null;
|
|
30
31
|
}
|
|
31
32
|
}
|
|
32
33
|
export function number(options) {
|