@bingtsingw/orchid-helper 0.5.0 → 1.0.1
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/index.d.ts +82 -55
- package/dist/index.js +1 -1
- package/package.json +12 -5
- package/src/base-table.ts +31 -6
package/dist/index.d.ts
CHANGED
|
@@ -1,58 +1,41 @@
|
|
|
1
1
|
import * as orchid_orm from 'orchid-orm';
|
|
2
2
|
import { DefaultSchemaConfig } from 'orchid-orm';
|
|
3
|
-
import * as orchid_core from 'orchid-core';
|
|
4
3
|
|
|
5
4
|
declare const BaseTable: orchid_orm.BaseTableClass<DefaultSchemaConfig, {
|
|
6
5
|
xEnum: <T extends Record<any, any>>(_: T) => {
|
|
7
|
-
toCode: (ctx:
|
|
6
|
+
toCode: (ctx: orchid_orm.ColumnToCodeCtx, key: string) => orchid_orm.Code;
|
|
8
7
|
dataType: "varchar";
|
|
9
8
|
data: orchid_orm.TextColumnData & {
|
|
10
9
|
maxChars?: number;
|
|
11
10
|
};
|
|
11
|
+
operators: orchid_orm.OperatorsOrdinalText;
|
|
12
12
|
toSQL: () => string;
|
|
13
|
-
operators: orchid_orm.OperatorsText;
|
|
14
|
-
primaryKey: <T_1 extends orchid_core.PickColumnBaseData, Name extends string>(this: T_1, name?: Name) => orchid_core.PrimaryKeyColumn<T_1, Name>;
|
|
15
|
-
foreignKey: {
|
|
16
|
-
<T_1, Table extends orchid_core.ForeignKeyTable, Column extends orchid_core.ColumnNameOfTable<Table>>(this: T_1, fn: () => Table, column: Column, options?: orchid_orm.TableData.References.Options): T_1;
|
|
17
|
-
<T_1, Table_1 extends string, Column_1 extends string>(this: T_1, table: Table_1, column: Column_1, options?: orchid_orm.TableData.References.Options): T_1;
|
|
18
|
-
};
|
|
19
|
-
index: <T_1 extends orchid_orm.PickColumnData>(this: T_1, ...args: [options?: orchid_orm.TableData.Index.ColumnArg] | [name: string, options?: orchid_orm.TableData.Index.ColumnArg]) => T_1;
|
|
20
|
-
searchIndex: <T_1 extends {
|
|
21
|
-
data: orchid_orm.ColumnType["data"];
|
|
22
|
-
dataType: string;
|
|
23
|
-
}>(this: T_1, ...args: [options?: orchid_orm.TableData.Index.TsVectorColumnArg] | [name: string, options?: orchid_orm.TableData.Index.TsVectorColumnArg]) => T_1;
|
|
24
|
-
unique: <T_1 extends orchid_orm.PickColumnData, Name_1 extends string>(this: T_1, ...args: [options?: orchid_orm.TableData.Index.UniqueColumnArg] | [name: Name_1, options?: orchid_orm.TableData.Index.UniqueColumnArg]) => orchid_core.UniqueColumn<T_1, Name_1>;
|
|
25
|
-
comment: <T_1 extends orchid_orm.PickColumnData>(this: T_1, comment: string) => T_1;
|
|
26
|
-
compression: <T_1 extends orchid_orm.PickColumnData>(this: T_1, compression: string) => T_1;
|
|
27
|
-
collate: <T_1 extends orchid_orm.PickColumnData>(this: T_1, collate: string) => T_1;
|
|
28
|
-
modifyQuery: <T_1 extends orchid_orm.PickColumnData>(this: T_1, cb: (q: orchid_orm.Query) => void) => T_1;
|
|
29
|
-
generated: <T_1 extends orchid_orm.PickColumnData>(this: T_1, ...args: orchid_core.StaticSQLArgs) => T_1;
|
|
30
13
|
inputSchema: unknown;
|
|
31
14
|
outputSchema: unknown;
|
|
32
15
|
querySchema: unknown;
|
|
33
|
-
type:
|
|
16
|
+
type: string;
|
|
34
17
|
inputType: T[keyof T];
|
|
35
18
|
outputType: T[keyof T];
|
|
36
19
|
queryType: T[keyof T];
|
|
20
|
+
nullType: unknown;
|
|
21
|
+
nullSchema: unknown;
|
|
22
|
+
isNullable: boolean;
|
|
37
23
|
error: unknown;
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
check: <T_1 extends orchid_core.PickColumnBaseData>(this: T_1, sql: orchid_core.RawSQLBase, name?: string) => T_1;
|
|
44
|
-
nullable: <T_1 extends orchid_core.ColumnTypeBase>(this: T_1) => orchid_core.NullableColumn<T_1, unknown, unknown, unknown>;
|
|
24
|
+
_parse?: ((input: unknown) => unknown) | undefined;
|
|
25
|
+
default: <T_1 extends orchid_orm.Column.Pick.DataAndInputType, Value extends orchid_orm.RawSqlBase | T_1["inputType"] | (() => T_1["inputType"]) | null>(this: T_1, value: Value) => orchid_orm.Column.Modifiers.Default<T_1, Value>;
|
|
26
|
+
hasDefault: <T_1 extends orchid_orm.Column.Pick.Data>(this: T_1) => orchid_orm.Column.Modifiers.Default<T_1, orchid_orm.RawSqlBase>;
|
|
27
|
+
check: <T_1 extends orchid_orm.Column.Pick.Data>(this: T_1, sql: orchid_orm.RawSqlBase, name?: string) => T_1;
|
|
28
|
+
nullable: <T_1 extends orchid_orm.Column.Pick.ForNullable>(this: T_1) => orchid_orm.Column.Modifiers.Nullable<T_1, unknown, unknown, unknown>;
|
|
45
29
|
encode: <T_1 extends {
|
|
46
30
|
type: unknown;
|
|
47
|
-
}, Input>(this: T_1, fn: (input: Input) => unknown) =>
|
|
48
|
-
parse: <T_1 extends
|
|
49
|
-
|
|
50
|
-
}, Output>(this: T_1, fn: (input: T_1["type"]) => Output) => orchid_core.ParseColumn<T_1, unknown, Output>;
|
|
31
|
+
}, Input>(this: T_1, fn: (input: Input) => unknown) => orchid_orm.Column.Modifiers.Encode<T_1, unknown, Input>;
|
|
32
|
+
parse: <T_1 extends orchid_orm.Column.Pick.ForParse, Output>(this: T_1, fn: (input: T_1["type"]) => Output) => orchid_orm.Column.Modifiers.Parse<T_1, unknown, Output>;
|
|
33
|
+
parseNull: <T_1 extends orchid_orm.Column.Pick.ForParseNull, Output_1>(this: T_1, fn: () => Output_1) => orchid_orm.Column.Modifiers.ParseNull<T_1, unknown, Output_1>;
|
|
51
34
|
as: <T_1 extends {
|
|
52
35
|
inputType: unknown;
|
|
53
36
|
outputType: unknown;
|
|
54
|
-
data:
|
|
55
|
-
}, C extends
|
|
37
|
+
data: orchid_orm.Column.Data;
|
|
38
|
+
}, C extends {
|
|
56
39
|
inputType: T_1["inputType"];
|
|
57
40
|
outputType: T_1["outputType"];
|
|
58
41
|
}>(this: T_1, column: C) => C;
|
|
@@ -61,12 +44,26 @@ declare const BaseTable: orchid_orm.BaseTableClass<DefaultSchemaConfig, {
|
|
|
61
44
|
inputType: unknown;
|
|
62
45
|
outputType: unknown;
|
|
63
46
|
queryType: unknown;
|
|
64
|
-
}>(this: T_1, _fn: (type: <Type, Input_1 = Type,
|
|
47
|
+
}>(this: T_1, _fn: (type: <Type, Input_1 = Type, Output_2 = Type, Query = Type>() => {
|
|
65
48
|
type: Type;
|
|
66
49
|
inputType: Input_1;
|
|
67
|
-
outputType:
|
|
50
|
+
outputType: Output_2;
|
|
68
51
|
queryType: Query;
|
|
69
52
|
}) => Types) => { [K in keyof T_1]: K extends keyof Types ? Types[K] : T_1[K]; };
|
|
53
|
+
narrowType: <T_1 extends orchid_orm.Column.InputOutputQueryTypes, Types_1 extends orchid_orm.Column.InputOutputQueryTypes>(this: T_1, _fn: (type: <Type extends T_1["inputType"] extends T_1["outputType"] & T_1["queryType"] ? T_1["outputType"] & T_1["queryType"] : T_1["inputType"] & T_1["outputType"] & T_1["queryType"]>() => {
|
|
54
|
+
inputType: T_1["inputType"] extends never ? never : Type;
|
|
55
|
+
outputType: Type;
|
|
56
|
+
queryType: Type;
|
|
57
|
+
}) => Types_1) => { [K in keyof T_1]: K extends keyof Types_1 ? Types_1[K] : T_1[K]; };
|
|
58
|
+
narrowAllTypes: <T_1 extends orchid_orm.Column.InputOutputQueryTypes, Types_2 extends orchid_orm.Column.InputOutputQueryTypes>(this: T_1, _fn: (type: <Types_3 extends {
|
|
59
|
+
input?: T_1["inputType"];
|
|
60
|
+
output?: T_1["outputType"];
|
|
61
|
+
query?: T_1["queryType"];
|
|
62
|
+
}>() => {
|
|
63
|
+
inputType: undefined extends Types_3["input"] ? T_1["inputType"] : Types_3["input"];
|
|
64
|
+
outputType: undefined extends Types_3["output"] ? T_1["outputType"] : Types_3["output"];
|
|
65
|
+
queryType: undefined extends Types_3["query"] ? T_1["queryType"] : Types_3["query"];
|
|
66
|
+
}) => Types_2) => { [K in keyof T_1]: K extends keyof Types_2 ? Types_2[K] : T_1[K]; };
|
|
70
67
|
input: <T_1 extends {
|
|
71
68
|
inputSchema: unknown;
|
|
72
69
|
}, InputSchema extends unknown>(this: T_1, fn: (schema: T_1["inputSchema"]) => InputSchema) => { [K in keyof T_1]: K extends "inputSchema" ? InputSchema : T_1[K]; };
|
|
@@ -76,23 +73,50 @@ declare const BaseTable: orchid_orm.BaseTableClass<DefaultSchemaConfig, {
|
|
|
76
73
|
query: <T_1 extends {
|
|
77
74
|
querySchema: unknown;
|
|
78
75
|
}, QuerySchema extends unknown>(this: T_1, fn: (schema: T_1["querySchema"]) => QuerySchema) => { [K in keyof T_1]: K extends "querySchema" ? QuerySchema : T_1[K]; };
|
|
79
|
-
name: <T_1 extends
|
|
80
|
-
|
|
76
|
+
name: <T_1 extends orchid_orm.Column.Pick.Data>(this: T_1, name: string) => T_1;
|
|
77
|
+
select: <T_1 extends orchid_orm.Column.Pick.Data, Value_1 extends boolean>(this: T_1, value: Value_1) => orchid_orm.Column.Modifiers.DefaultSelect<T_1, Value_1>;
|
|
78
|
+
readOnly: <T_1>(this: T_1) => T_1 & orchid_orm.Column.Modifiers.IsAppReadOnly;
|
|
79
|
+
setOnCreate: <T_1 extends orchid_orm.Column.Pick.QueryInit>(this: T_1, fn: (arg: orchid_orm.QueryHookUtils<orchid_orm.PickQueryInputType>) => void | T_1["inputType"]) => T_1;
|
|
80
|
+
setOnUpdate: <T_1 extends orchid_orm.Column.Pick.QueryInit>(this: T_1, fn: (arg: orchid_orm.QueryHookUtils<orchid_orm.PickQueryInputType>) => void | T_1["inputType"]) => T_1;
|
|
81
|
+
setOnSave: <T_1 extends orchid_orm.Column.Pick.QueryInit>(this: T_1, fn: (arg: orchid_orm.QueryHookUtils<orchid_orm.PickQueryInputType>) => void | T_1["inputType"]) => T_1;
|
|
82
|
+
primaryKey: <T_1 extends orchid_orm.Column.Pick.Data, Name extends string>(this: T_1, name?: Name | undefined) => T_1 & orchid_orm.Column.Modifiers.IsPrimaryKey<Name>;
|
|
83
|
+
foreignKey: {
|
|
84
|
+
<T_1, Shape>(this: T_1, fn: () => new () => {
|
|
85
|
+
columns: {
|
|
86
|
+
shape: Shape;
|
|
87
|
+
};
|
|
88
|
+
}, column: keyof Shape, options?: orchid_orm.TableData.References.Options): T_1;
|
|
89
|
+
<T_1, Table extends string, Column extends string>(this: T_1, table: Table, column: Column, options?: orchid_orm.TableData.References.Options): T_1;
|
|
90
|
+
};
|
|
91
|
+
index: <T_1 extends orchid_orm.Column.Pick.Data>(this: T_1, options?: orchid_orm.TableData.Index.ColumnArg | undefined) => T_1;
|
|
92
|
+
searchIndex: <T_1 extends {
|
|
93
|
+
data: orchid_orm.Column["data"];
|
|
94
|
+
dataType: string;
|
|
95
|
+
}>(this: T_1, options?: orchid_orm.TableData.Index.TsVectorColumnArg | undefined) => T_1;
|
|
96
|
+
unique: <T_1 extends orchid_orm.Column.Pick.Data, const Options extends orchid_orm.TableData.Index.ColumnArg>(this: T_1, options?: Options | undefined) => T_1 & orchid_orm.Column.Modifiers.IsUnique<Options["name"] & string>;
|
|
97
|
+
exclude: <T_1 extends orchid_orm.Column.Pick.Data>(this: T_1, op: string, options?: orchid_orm.TableData.Exclude.ColumnArg | undefined) => T_1;
|
|
98
|
+
comment: <T_1 extends orchid_orm.Column.Pick.Data>(this: T_1, comment: string) => T_1;
|
|
99
|
+
compression: <T_1 extends orchid_orm.Column.Pick.Data>(this: T_1, compression: string) => T_1;
|
|
100
|
+
collate: <T_1 extends orchid_orm.Column.Pick.Data>(this: T_1, collate: string) => T_1;
|
|
101
|
+
modifyQuery: <T_1 extends orchid_orm.Column.Pick.Data>(this: T_1, cb: (q: orchid_orm.Query) => void) => T_1;
|
|
102
|
+
generated: <T_1 extends orchid_orm.Column.Pick.Data>(this: T_1, ...args: orchid_orm.StaticSQLArgs) => orchid_orm.Column.Modifiers.Generated<T_1>;
|
|
81
103
|
};
|
|
82
|
-
xJsonText: () =>
|
|
83
|
-
xTimestamp: () =>
|
|
84
|
-
createdAt: () =>
|
|
85
|
-
updatedAt: () =>
|
|
86
|
-
deletedAt: () =>
|
|
87
|
-
cuid: () =>
|
|
88
|
-
baseColumns: (
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
104
|
+
xJsonText: () => orchid_orm.Column.Modifiers.Encode<orchid_orm.JSONTextColumn<DefaultSchemaConfig>, unknown, any[] | Record<string, any>>;
|
|
105
|
+
xTimestamp: () => orchid_orm.Column.Modifiers.Parse<orchid_orm.TimestampColumn<DefaultSchemaConfig>, unknown, Date>;
|
|
106
|
+
createdAt: () => orchid_orm.Column.Modifiers.Parse<orchid_orm.Column.Modifiers.Default<orchid_orm.Column.Modifiers.Default<orchid_orm.TimestampColumn<DefaultSchemaConfig>, orchid_orm.RawSqlBase>, () => string>, unknown, Date>;
|
|
107
|
+
updatedAt: () => orchid_orm.Column.Modifiers.Parse<orchid_orm.Column.Modifiers.Default<orchid_orm.Column.Modifiers.Default<orchid_orm.TimestampColumn<DefaultSchemaConfig>, orchid_orm.RawSqlBase>, () => string>, unknown, Date>;
|
|
108
|
+
deletedAt: () => orchid_orm.Column.Modifiers.Nullable<orchid_orm.Column.Modifiers.Parse<orchid_orm.TimestampColumn<DefaultSchemaConfig>, unknown, Date>, unknown, unknown, unknown>;
|
|
109
|
+
cuid: () => orchid_orm.Column.Modifiers.Default<orchid_orm.StringColumn<DefaultSchemaConfig> & orchid_orm.Column.Modifiers.IsPrimaryKey<string>, () => string>;
|
|
110
|
+
baseColumns: (option?: {
|
|
111
|
+
strategy: "uuid25" | "cuid2" | "shortid";
|
|
112
|
+
}) => {
|
|
113
|
+
id: orchid_orm.Column.Modifiers.Default<orchid_orm.StringColumn<DefaultSchemaConfig> & orchid_orm.Column.Modifiers.IsPrimaryKey<string>, () => string>;
|
|
114
|
+
createdAt: orchid_orm.Column.Modifiers.Parse<orchid_orm.Column.Modifiers.Default<orchid_orm.Column.Modifiers.Default<orchid_orm.TimestampColumn<DefaultSchemaConfig>, orchid_orm.RawSqlBase>, () => string>, unknown, Date>;
|
|
115
|
+
updatedAt: orchid_orm.Column.Modifiers.Parse<orchid_orm.Column.Modifiers.Default<orchid_orm.Column.Modifiers.Default<orchid_orm.TimestampColumn<DefaultSchemaConfig>, orchid_orm.RawSqlBase>, () => string>, unknown, Date>;
|
|
116
|
+
deletedAt: orchid_orm.Column.Modifiers.Nullable<orchid_orm.Column.Modifiers.Parse<orchid_orm.TimestampColumn<DefaultSchemaConfig>, unknown, Date>, unknown, unknown, unknown>;
|
|
93
117
|
};
|
|
94
118
|
schema: DefaultSchemaConfig;
|
|
95
|
-
enum: <
|
|
119
|
+
enum: <const T extends readonly [string, ...string[]]>(dataType: string, type: T) => orchid_orm.EnumColumn<DefaultSchemaConfig, unknown, T>;
|
|
96
120
|
array: <Item extends orchid_orm.ArrayColumnValue>(item: Item) => orchid_orm.ArrayColumn<DefaultSchemaConfig, Item, unknown, unknown, unknown>;
|
|
97
121
|
name<T>(this: T, name: string): T;
|
|
98
122
|
sql: orchid_orm.SqlFn;
|
|
@@ -103,7 +127,7 @@ declare const BaseTable: orchid_orm.BaseTableClass<DefaultSchemaConfig, {
|
|
|
103
127
|
decimal: (precision?: number, scale?: number) => orchid_orm.DecimalColumn<DefaultSchemaConfig>;
|
|
104
128
|
real: () => orchid_orm.RealColumn<DefaultSchemaConfig>;
|
|
105
129
|
doublePrecision: () => orchid_orm.DoublePrecisionColumn<DefaultSchemaConfig>;
|
|
106
|
-
identity(options?: orchid_orm.TableData.Identity):
|
|
130
|
+
identity(options?: orchid_orm.TableData.Identity): orchid_orm.Column.Modifiers.Default<orchid_orm.IntegerColumn<DefaultSchemaConfig>, orchid_orm.Expression<orchid_orm.Column.Pick.QueryColumn>>;
|
|
107
131
|
smallSerial: () => orchid_orm.SmallSerialColumn<DefaultSchemaConfig>;
|
|
108
132
|
serial: () => orchid_orm.SerialColumn<DefaultSchemaConfig>;
|
|
109
133
|
bigSerial: () => orchid_orm.BigSerialColumn<DefaultSchemaConfig>;
|
|
@@ -136,16 +160,19 @@ declare const BaseTable: orchid_orm.BaseTableClass<DefaultSchemaConfig, {
|
|
|
136
160
|
tsquery(): orchid_orm.TsQueryColumn<DefaultSchemaConfig>;
|
|
137
161
|
uuid(): orchid_orm.UUIDColumn<DefaultSchemaConfig>;
|
|
138
162
|
xml(): orchid_orm.XMLColumn<DefaultSchemaConfig>;
|
|
139
|
-
json: <T>() => orchid_orm.JSONColumn<unknown extends T ?
|
|
163
|
+
json: <T>() => orchid_orm.JSONColumn<unknown extends T ? orchid_orm.MaybeArray<string | number | boolean | object> : T, DefaultSchemaConfig>;
|
|
140
164
|
jsonText(): orchid_orm.JSONTextColumn<DefaultSchemaConfig>;
|
|
141
165
|
type(dataType: string): orchid_orm.CustomTypeColumn<DefaultSchemaConfig>;
|
|
142
166
|
domain(dataType: string): orchid_orm.DomainColumn<DefaultSchemaConfig>;
|
|
143
|
-
|
|
167
|
+
geography: {
|
|
168
|
+
point(): orchid_orm.PostgisGeographyPointColumn<DefaultSchemaConfig>;
|
|
169
|
+
};
|
|
170
|
+
timestamps<T extends orchid_orm.Column.Pick.Data>(this: {
|
|
144
171
|
timestamp(): T;
|
|
145
|
-
}):
|
|
146
|
-
timestampsNoTZ<T extends
|
|
172
|
+
}): orchid_orm.Timestamps<T>;
|
|
173
|
+
timestampsNoTZ<T extends orchid_orm.Column.Pick.Data>(this: {
|
|
147
174
|
timestampNoTZ(): T;
|
|
148
|
-
}):
|
|
175
|
+
}): orchid_orm.Timestamps<T>;
|
|
149
176
|
}>;
|
|
150
177
|
|
|
151
178
|
export { BaseTable };
|
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{cuid2 as s}from"@xstools/utility/cuid2";import{uuid25encode as i}from"@xstools/utility/string";import{createBaseTable as m}from"orchid-orm";import{v7 as d}from"uuid";var o=e=>()=>e.string(36).primaryKey().default(()=>s()),l=e=>()=>e.string(36).primaryKey().default(()=>{let t="";return typeof Bun<"u"?t=Bun.randomUUIDv7():t=d(),i(t)}),f=e=>()=>e.string(36).primaryKey().default(()=>s(6)),n=e=>()=>e.timestampsNoTZ().createdAt.default(()=>new Date().toISOString()).asDate(),r=e=>()=>e.timestampsNoTZ().updatedAt.default(()=>new Date().toISOString()).asDate(),u=e=>()=>e.timestampNoTZ().asDate().nullable(),D=m({snakeCase:!0,nowSQL:"clock_timestamp()::timestamptz(3) AT TIME ZONE 'UTC'",columnTypes:e=>({...e,xEnum:t=>e.string().narrowType(a=>a()),xJsonText:()=>e.jsonText().encode(t=>{if(typeof t!="object")throw new Error("Invalid value for JSON column");return JSON.stringify(t)}),xTimestamp:()=>e.timestampNoTZ().asDate(),createdAt:n(e),updatedAt:r(e),deletedAt:u(e),cuid:o(e),baseColumns:t=>({id:t?.strategy==="cuid2"?o(e)():t?.strategy==="shortid"?f(e)():l(e)(),createdAt:n(e)(),updatedAt:r(e)(),deletedAt:u(e)()})})});export{D as BaseTable};
|
package/package.json
CHANGED
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bingtsingw/orchid-helper",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "1.0.1",
|
|
4
|
+
"repository": {
|
|
5
|
+
"type": "git",
|
|
6
|
+
"url": "git+https://github.com/bingtsingw/orchid-helper.git",
|
|
7
|
+
"directory": "packages/helper"
|
|
8
|
+
},
|
|
4
9
|
"license": "MIT",
|
|
5
10
|
"type": "module",
|
|
6
11
|
"main": "./dist/index.js",
|
|
@@ -12,13 +17,15 @@
|
|
|
12
17
|
"eslintConfig": {
|
|
13
18
|
"extends": "@xstools-dev/eslint-config/base"
|
|
14
19
|
},
|
|
20
|
+
"dependencies": {
|
|
21
|
+
"@xstools/utility": "^0.20.2",
|
|
22
|
+
"uuid": "^13.0.0"
|
|
23
|
+
},
|
|
15
24
|
"devDependencies": {
|
|
16
|
-
"
|
|
17
|
-
"orchid-orm": "^1.35.0"
|
|
25
|
+
"orchid-orm": "1.62.1"
|
|
18
26
|
},
|
|
19
27
|
"peerDependencies": {
|
|
20
|
-
"
|
|
21
|
-
"orchid-orm": "^1.34.5"
|
|
28
|
+
"orchid-orm": "^1.62.1"
|
|
22
29
|
},
|
|
23
30
|
"publishConfig": {
|
|
24
31
|
"access": "public",
|
package/src/base-table.ts
CHANGED
|
@@ -1,12 +1,34 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { cuid2 } from '@xstools/utility/cuid2';
|
|
2
|
+
import { uuid25encode } from '@xstools/utility/string';
|
|
2
3
|
import type { DefaultColumnTypes, DefaultSchemaConfig } from 'orchid-orm';
|
|
3
4
|
import { createBaseTable } from 'orchid-orm';
|
|
5
|
+
import { v7 } from 'uuid';
|
|
4
6
|
|
|
5
7
|
const cuid = (t: DefaultColumnTypes<DefaultSchemaConfig>) => () =>
|
|
6
8
|
t
|
|
7
9
|
.string(36)
|
|
8
10
|
.primaryKey()
|
|
9
|
-
.default(() =>
|
|
11
|
+
.default(() => cuid2());
|
|
12
|
+
|
|
13
|
+
const uuid25 = (t: DefaultColumnTypes<DefaultSchemaConfig>) => () =>
|
|
14
|
+
t
|
|
15
|
+
.string(36)
|
|
16
|
+
.primaryKey()
|
|
17
|
+
.default(() => {
|
|
18
|
+
let uuid = '';
|
|
19
|
+
if (typeof Bun !== 'undefined') {
|
|
20
|
+
uuid = Bun.randomUUIDv7();
|
|
21
|
+
} else {
|
|
22
|
+
uuid = v7();
|
|
23
|
+
}
|
|
24
|
+
return uuid25encode(uuid);
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
const shortid = (t: DefaultColumnTypes<DefaultSchemaConfig>) => () =>
|
|
28
|
+
t
|
|
29
|
+
.string(36)
|
|
30
|
+
.primaryKey()
|
|
31
|
+
.default(() => cuid2(6));
|
|
10
32
|
|
|
11
33
|
const createdAt = (t: DefaultColumnTypes<DefaultSchemaConfig>) => () =>
|
|
12
34
|
t
|
|
@@ -24,13 +46,13 @@ const deletedAt = (t: DefaultColumnTypes<DefaultSchemaConfig>) => () => t.timest
|
|
|
24
46
|
|
|
25
47
|
export const BaseTable = createBaseTable({
|
|
26
48
|
snakeCase: true,
|
|
27
|
-
nowSQL: `
|
|
49
|
+
nowSQL: `clock_timestamp()::timestamptz(3) AT TIME ZONE 'UTC'`,
|
|
28
50
|
|
|
29
51
|
columnTypes: (t) => ({
|
|
30
52
|
...t,
|
|
31
53
|
|
|
32
54
|
// Extend built-in methods
|
|
33
|
-
xEnum: <T extends Record<any, any>>(_: T) => t.string().
|
|
55
|
+
xEnum: <T extends Record<any, any>>(_: T) => t.string().narrowType((t) => t<T[keyof T]>()),
|
|
34
56
|
xJsonText: () =>
|
|
35
57
|
t.jsonText().encode((v: Record<string, any> | any[]) => {
|
|
36
58
|
if (typeof v !== 'object') throw new Error('Invalid value for JSON column');
|
|
@@ -45,9 +67,12 @@ export const BaseTable = createBaseTable({
|
|
|
45
67
|
deletedAt: deletedAt(t),
|
|
46
68
|
cuid: cuid(t),
|
|
47
69
|
|
|
48
|
-
|
|
70
|
+
// default to uuid25
|
|
71
|
+
baseColumns: (option?: { strategy: 'uuid25' | 'cuid2' | 'shortid' }) => {
|
|
72
|
+
const id = option?.strategy === 'cuid2' ? cuid(t)() : option?.strategy === 'shortid' ? shortid(t)() : uuid25(t)();
|
|
73
|
+
|
|
49
74
|
return {
|
|
50
|
-
id
|
|
75
|
+
id,
|
|
51
76
|
createdAt: createdAt(t)(),
|
|
52
77
|
updatedAt: updatedAt(t)(),
|
|
53
78
|
deletedAt: deletedAt(t)(),
|