@lark-apaas/devtool-kits 1.0.11 → 1.1.0
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.cjs +384 -28573
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +3 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +373 -28589
- package/dist/index.js.map +1 -1
- package/dist/template/types.ts +82 -0
- package/package.json +1 -1
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { sql } from 'drizzle-orm';
|
|
2
|
+
import { customType } from 'drizzle-orm/pg-core';
|
|
3
|
+
|
|
4
|
+
export type UserProfile = {
|
|
5
|
+
user_id: string;
|
|
6
|
+
};
|
|
7
|
+
|
|
8
|
+
export const userProfile = customType<{
|
|
9
|
+
data: UserProfile;
|
|
10
|
+
driverData: unknown;
|
|
11
|
+
}>({
|
|
12
|
+
dataType() {
|
|
13
|
+
return 'user_profile';
|
|
14
|
+
},
|
|
15
|
+
toDriver(value: UserProfile | string) {
|
|
16
|
+
if(typeof value === 'string') {
|
|
17
|
+
return sql`ROW(${value})::user_profile`;
|
|
18
|
+
}
|
|
19
|
+
return sql`ROW(${value.user_id})::user_profile`;
|
|
20
|
+
},
|
|
21
|
+
fromDriver(value: unknown): UserProfile {
|
|
22
|
+
if (typeof value !== 'string') {
|
|
23
|
+
throw new Error('Invalid user profile value');
|
|
24
|
+
}
|
|
25
|
+
const [userId] = value.slice(1, -1).split(',');
|
|
26
|
+
return { user_id: userId.trim() };
|
|
27
|
+
},
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
export type FileAttachment = {
|
|
31
|
+
bucket_id: string;
|
|
32
|
+
file_path: string;
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
export const fileAttachment = customType<{
|
|
36
|
+
data: FileAttachment;
|
|
37
|
+
driverData: unknown;
|
|
38
|
+
}>({
|
|
39
|
+
dataType() {
|
|
40
|
+
return 'file_attachment';
|
|
41
|
+
},
|
|
42
|
+
toDriver(value: FileAttachment) {
|
|
43
|
+
return sql`ROW(${value.bucket_id},${value.file_path})::file_attachment`;
|
|
44
|
+
},
|
|
45
|
+
fromDriver(value: unknown): FileAttachment {
|
|
46
|
+
if (typeof value !== 'string') {
|
|
47
|
+
throw new Error('Invalid file attachment value');
|
|
48
|
+
}
|
|
49
|
+
const [bucketId, filePath] = value.slice(1, -1).split(',');
|
|
50
|
+
return { bucket_id: bucketId.trim(), file_path: filePath.trim() };
|
|
51
|
+
},
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
export const customTimestamptz = customType<{
|
|
55
|
+
data: Date;
|
|
56
|
+
driverData: string;
|
|
57
|
+
config: { precision?: number};
|
|
58
|
+
}>({
|
|
59
|
+
dataType(config) {
|
|
60
|
+
const precision = typeof config?.precision !== 'undefined'
|
|
61
|
+
? ` (${config.precision})`
|
|
62
|
+
: '';
|
|
63
|
+
return `timestamptz${precision}`;
|
|
64
|
+
},
|
|
65
|
+
toDriver(value: Date | string | number){
|
|
66
|
+
if(value == null) return value as any;
|
|
67
|
+
if (typeof value === 'number') {
|
|
68
|
+
return new Date(value).toISOString();
|
|
69
|
+
}
|
|
70
|
+
if(typeof value === 'string') {
|
|
71
|
+
return value;
|
|
72
|
+
}
|
|
73
|
+
if (value instanceof Date) {
|
|
74
|
+
return value.toISOString();
|
|
75
|
+
}
|
|
76
|
+
throw new Error('Invalid timestamp value');
|
|
77
|
+
},
|
|
78
|
+
fromDriver(value: string | Date): Date {
|
|
79
|
+
if(value instanceof Date) return value;
|
|
80
|
+
return new Date(value);
|
|
81
|
+
},
|
|
82
|
+
});
|