@sidekick-coder/zenith-kit 0.4.2 → 0.4.3
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/server/index.d.mts +24 -20
- package/dist/server/index.mjs +4 -4
- package/dist/shared/index.d.mts +55 -55
- package/package.json +1 -1
- package/src/server/index.ts +3 -1
- package/src/server/queries/index.ts +0 -1
- package/src/server/queries/softDelete.ts +1 -16
- package/src/server/queries/timestamp.ts +0 -36
- package/src/server/utils/addSoftDeleteColumn.ts +17 -0
- package/src/server/utils/addTimestampColumns.ts +39 -0
- /package/src/server/{queries/incremental.ts → utils/addIdColumn.ts} +0 -0
package/package.json
CHANGED
package/src/server/index.ts
CHANGED
|
@@ -177,7 +177,6 @@ export * from './queries/destroy.ts'
|
|
|
177
177
|
export * from './queries/exists.ts'
|
|
178
178
|
export * from './queries/findOne.ts'
|
|
179
179
|
export * from './queries/firstOrCreate.ts'
|
|
180
|
-
export * from './queries/incremental.ts'
|
|
181
180
|
export * from './queries/index.ts'
|
|
182
181
|
export * from './queries/list.ts'
|
|
183
182
|
export * from './queries/paginate.ts'
|
|
@@ -205,6 +204,9 @@ export * from './middlewares/AuthSilenceMiddleware.ts'
|
|
|
205
204
|
export { default as AuthSilenceMiddleware } from './middlewares/AuthSilenceMiddleware.ts'
|
|
206
205
|
export * from './middlewares/AuthorizationMiddleware.ts'
|
|
207
206
|
export { default as AuthorizationMiddleware } from './middlewares/AuthorizationMiddleware.ts'
|
|
207
|
+
export * from './utils/addIdColumn.ts'
|
|
208
|
+
export * from './utils/addSoftDeleteColumn.ts'
|
|
209
|
+
export * from './utils/addTimestampColumns.ts'
|
|
208
210
|
export * from './utils/basePath.ts'
|
|
209
211
|
export * from './utils/createLoaderFactory.ts'
|
|
210
212
|
export * from './utils/cuid.ts'
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { CreateTableBuilder } from 'kysely'
|
|
2
|
-
import type {
|
|
2
|
+
import type { ExpressionBuilder } from 'kysely'
|
|
3
3
|
import type { Selectable } from 'kysely'
|
|
4
4
|
import { now } from './common.ts'
|
|
5
5
|
import type { DatabaseContract as Database } from '#server/contracts/DatabaseContract.ts'
|
|
@@ -20,9 +20,6 @@ export type SoftDeleteResult<T extends keyof Database, O extends SoftDeleteOptio
|
|
|
20
20
|
O extends undefined ? Selectable<Database[T]>[] :
|
|
21
21
|
O extends { serialize: (row: Selectable<Database[T]>) => infer R } ? R[] : Selectable<Database[T]>[]
|
|
22
22
|
|
|
23
|
-
export interface SoftDeleteTable {
|
|
24
|
-
deleted_at: ColumnType<Date | null, never | null | ReturnType<typeof now>, string | null | ReturnType<typeof now>>
|
|
25
|
-
}
|
|
26
23
|
|
|
27
24
|
export function whereNotDeleted<QB extends WhereCapable<QB>>(qb: QB): QB {
|
|
28
25
|
return qb.where('deleted_at', 'is', null)
|
|
@@ -64,15 +61,3 @@ export async function softDelete<T extends keyof Database, O extends SoftDeleteO
|
|
|
64
61
|
|
|
65
62
|
return rows as SoftDeleteResult<T, O>
|
|
66
63
|
}
|
|
67
|
-
|
|
68
|
-
declare module 'kysely' {
|
|
69
|
-
interface CreateTableBuilder<TB extends string, C extends string = never> {
|
|
70
|
-
addSoftDeleteColumn(): CreateTableBuilder<TB, C | 'deleted_at'>
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
CreateTableBuilder.prototype.addSoftDeleteColumn = function (
|
|
75
|
-
this: CreateTableBuilder<any, any>,
|
|
76
|
-
) {
|
|
77
|
-
return this.addColumn('deleted_at', 'timestamp')
|
|
78
|
-
}
|
|
@@ -1,12 +1,6 @@
|
|
|
1
1
|
import { CreateTableBuilder } from 'kysely'
|
|
2
|
-
import type { ColumnType } from 'kysely'
|
|
3
2
|
import { now } from './common.ts'
|
|
4
3
|
|
|
5
|
-
export interface TimestampTable {
|
|
6
|
-
created_at: ColumnType<Date, string | undefined, never>
|
|
7
|
-
updated_at: ColumnType<Date, string | undefined, Date | string | ReturnType<typeof now>>
|
|
8
|
-
}
|
|
9
|
-
|
|
10
4
|
export const addCreatedColumn = (ctb: CreateTableBuilder<any, any>) => {
|
|
11
5
|
return ctb
|
|
12
6
|
.addColumn('created_at', 'timestamp', (col) => col.defaultTo(now()).notNull())
|
|
@@ -22,33 +16,3 @@ export const addTimestampColumns = (ctb: CreateTableBuilder<any, any>) => {
|
|
|
22
16
|
.addColumn('created_at', 'timestamp', (col) => col.defaultTo(now()).notNull())
|
|
23
17
|
.addColumn('updated_at', 'timestamp', (col) => col.defaultTo(now()).notNull())
|
|
24
18
|
}
|
|
25
|
-
|
|
26
|
-
declare module 'kysely' {
|
|
27
|
-
interface CreateTableBuilder<TB extends string, C extends string = never> {
|
|
28
|
-
addTimestampColumns(): CreateTableBuilder<TB, C | 'created_at' | 'updated_at'>
|
|
29
|
-
addCreatedColumn(): CreateTableBuilder<TB, C | 'created_at'>
|
|
30
|
-
addUpdatedColumn(): CreateTableBuilder<TB, C | 'updated_at'>
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
CreateTableBuilder.prototype.addTimestampColumns = function (
|
|
35
|
-
this: CreateTableBuilder<any, any>,
|
|
36
|
-
) {
|
|
37
|
-
return this
|
|
38
|
-
.addColumn('created_at', 'timestamp', (col) => col.defaultTo(now()).notNull())
|
|
39
|
-
.addColumn('updated_at', 'timestamp', (col) => col.defaultTo(now()).notNull())
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
CreateTableBuilder.prototype.addCreatedColumn = function (
|
|
43
|
-
this: CreateTableBuilder<any, any>,
|
|
44
|
-
) {
|
|
45
|
-
return this
|
|
46
|
-
.addColumn('created_at', 'timestamp', (col) => col.defaultTo(now()).notNull())
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
CreateTableBuilder.prototype.addUpdatedColumn = function (
|
|
50
|
-
this: CreateTableBuilder<any, any>,
|
|
51
|
-
) {
|
|
52
|
-
return this
|
|
53
|
-
.addColumn('updated_at', 'timestamp', (col) => col.defaultTo(now()).notNull())
|
|
54
|
-
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { CreateTableBuilder, type ColumnType } from 'kysely'
|
|
2
|
+
|
|
3
|
+
export interface SoftDeleteTable {
|
|
4
|
+
deleted_at: ColumnType<Date | null, never | null | string | null>
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
declare module 'kysely' {
|
|
8
|
+
interface CreateTableBuilder<TB extends string, C extends string = never> {
|
|
9
|
+
addSoftDeleteColumn(): CreateTableBuilder<TB, C | 'deleted_at'>
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
CreateTableBuilder.prototype.addSoftDeleteColumn = function(
|
|
14
|
+
this: CreateTableBuilder<any, any>,
|
|
15
|
+
) {
|
|
16
|
+
return this.addColumn('deleted_at', 'timestamp')
|
|
17
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { CreateTableBuilder, sql } from 'kysely'
|
|
2
|
+
import type { ColumnType } from 'kysely'
|
|
3
|
+
|
|
4
|
+
export interface TimestampTable {
|
|
5
|
+
created_at: ColumnType<Date, string | undefined, never>
|
|
6
|
+
updated_at: ColumnType<Date, string | undefined, Date | string | ReturnType<typeof now>>
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
declare module 'kysely' {
|
|
10
|
+
interface CreateTableBuilder<TB extends string, C extends string = never> {
|
|
11
|
+
addTimestampColumns(): CreateTableBuilder<TB, C | 'created_at' | 'updated_at'>
|
|
12
|
+
addCreatedColumn(): CreateTableBuilder<TB, C | 'created_at'>
|
|
13
|
+
addUpdatedColumn(): CreateTableBuilder<TB, C | 'updated_at'>
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
const now = () => sql<string>`CURRENT_TIMESTAMP`
|
|
18
|
+
|
|
19
|
+
CreateTableBuilder.prototype.addTimestampColumns = function(
|
|
20
|
+
this: CreateTableBuilder<any, any>,
|
|
21
|
+
) {
|
|
22
|
+
return this
|
|
23
|
+
.addColumn('created_at', 'timestamp', (col) => col.defaultTo(now()).notNull())
|
|
24
|
+
.addColumn('updated_at', 'timestamp', (col) => col.defaultTo(now()).notNull())
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
CreateTableBuilder.prototype.addCreatedColumn = function(
|
|
28
|
+
this: CreateTableBuilder<any, any>,
|
|
29
|
+
) {
|
|
30
|
+
return this
|
|
31
|
+
.addColumn('created_at', 'timestamp', (col) => col.defaultTo(now()).notNull())
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
CreateTableBuilder.prototype.addUpdatedColumn = function(
|
|
35
|
+
this: CreateTableBuilder<any, any>,
|
|
36
|
+
) {
|
|
37
|
+
return this
|
|
38
|
+
.addColumn('updated_at', 'timestamp', (col) => col.defaultTo(now()).notNull())
|
|
39
|
+
}
|
|
File without changes
|