@m5kdev/backend 0.1.4 → 0.2.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/src/lib/posthog.d.ts +0 -1
- package/dist/src/lib/sentry.d.ts +0 -1
- package/dist/src/modules/access/access.repository.d.ts +0 -1
- package/dist/src/modules/access/access.service.d.ts +0 -1
- package/dist/src/modules/access/access.test.d.ts +0 -1
- package/dist/src/modules/access/access.utils.d.ts +0 -1
- package/dist/src/modules/ai/ai.db.d.ts +0 -1
- package/dist/src/modules/ai/ai.prompt.d.ts +0 -1
- package/dist/src/modules/ai/ai.repository.d.ts +0 -1
- package/dist/src/modules/ai/ai.router.d.ts +0 -1
- package/dist/src/modules/ai/ai.service.d.ts +0 -1
- package/dist/src/modules/ai/ai.trpc.d.ts +5 -42
- package/dist/src/modules/ai/ai.trpc.js +5 -5
- package/dist/src/modules/ai/ideogram/ideogram.constants.d.ts +0 -1
- package/dist/src/modules/ai/ideogram/ideogram.dto.d.ts +0 -1
- package/dist/src/modules/ai/ideogram/ideogram.prompt.d.ts +0 -1
- package/dist/src/modules/ai/ideogram/ideogram.repository.d.ts +0 -1
- package/dist/src/modules/ai/ideogram/ideogram.service.d.ts +0 -1
- package/dist/src/modules/auth/auth.db.d.ts +0 -1
- package/dist/src/modules/auth/auth.dto.d.ts +7 -8
- package/dist/src/modules/auth/auth.lib.d.ts +8 -9
- package/dist/src/modules/auth/auth.middleware.d.ts +0 -1
- package/dist/src/modules/auth/auth.repository.d.ts +0 -1
- package/dist/src/modules/auth/auth.service.d.ts +0 -1
- package/dist/src/modules/auth/auth.trpc.d.ts +52 -89
- package/dist/src/modules/auth/auth.trpc.js +55 -53
- package/dist/src/modules/auth/auth.utils.d.ts +0 -1
- package/dist/src/modules/base/base.abstract.d.ts +0 -1
- package/dist/src/modules/base/base.dto.d.ts +2 -3
- package/dist/src/modules/base/base.grants.d.ts +0 -1
- package/dist/src/modules/base/base.grants.test.d.ts +0 -1
- package/dist/src/modules/base/base.repository.d.ts +0 -1
- package/dist/src/modules/base/base.service.d.ts +2 -4
- package/dist/src/modules/base/base.types.d.ts +0 -1
- package/dist/src/modules/billing/billing.db.d.ts +0 -1
- package/dist/src/modules/billing/billing.repository.d.ts +0 -1
- package/dist/src/modules/billing/billing.router.d.ts +0 -1
- package/dist/src/modules/billing/billing.service.d.ts +0 -1
- package/dist/src/modules/billing/billing.trpc.d.ts +6 -43
- package/dist/src/modules/billing/billing.trpc.js +7 -7
- package/dist/src/modules/clay/clay.repository.d.ts +0 -1
- package/dist/src/modules/clay/clay.service.d.ts +0 -1
- package/dist/src/modules/connect/connect.db.d.ts +0 -1
- package/dist/src/modules/connect/connect.dto.d.ts +8 -9
- package/dist/src/modules/connect/connect.linkedin.d.ts +0 -1
- package/dist/src/modules/connect/connect.oauth.d.ts +0 -1
- package/dist/src/modules/connect/connect.repository.d.ts +3 -4
- package/dist/src/modules/connect/connect.router.d.ts +0 -1
- package/dist/src/modules/connect/connect.service.d.ts +6 -7
- package/dist/src/modules/connect/connect.trpc.d.ts +9 -46
- package/dist/src/modules/connect/connect.trpc.js +7 -7
- package/dist/src/modules/connect/connect.types.d.ts +0 -1
- package/dist/src/modules/crypto/crypto.db.d.ts +0 -1
- package/dist/src/modules/crypto/crypto.repository.d.ts +0 -1
- package/dist/src/modules/crypto/crypto.service.d.ts +0 -1
- package/dist/src/modules/email/email.service.d.ts +0 -1
- package/dist/src/modules/file/file.repository.d.ts +0 -1
- package/dist/src/modules/file/file.router.d.ts +0 -1
- package/dist/src/modules/file/file.service.d.ts +0 -1
- package/dist/src/modules/recurrence/recurrence.db.d.ts +0 -1
- package/dist/src/modules/recurrence/recurrence.repository.d.ts +0 -1
- package/dist/src/modules/recurrence/recurrence.service.d.ts +0 -1
- package/dist/src/modules/recurrence/recurrence.trpc.d.ts +11 -48
- package/dist/src/modules/recurrence/recurrence.trpc.js +17 -17
- package/dist/src/modules/social/social.dto.d.ts +0 -1
- package/dist/src/modules/social/social.linkedin.d.ts +0 -1
- package/dist/src/modules/social/social.linkedin.test.d.ts +0 -1
- package/dist/src/modules/social/social.service.d.ts +0 -1
- package/dist/src/modules/social/social.types.d.ts +0 -1
- package/dist/src/modules/tag/tag.db.d.ts +0 -1
- package/dist/src/modules/tag/tag.dto.d.ts +0 -1
- package/dist/src/modules/tag/tag.repository.d.ts +0 -1
- package/dist/src/modules/tag/tag.service.d.ts +0 -1
- package/dist/src/modules/tag/tag.trpc.d.ts +10 -47
- package/dist/src/modules/tag/tag.trpc.js +15 -15
- package/dist/src/modules/utils/applyPagination.d.ts +0 -1
- package/dist/src/modules/utils/applySorting.d.ts +0 -1
- package/dist/src/modules/utils/getConditionsFromFilters.d.ts +0 -1
- package/dist/src/modules/video/video.service.d.ts +0 -1
- package/dist/src/modules/webhook/webhook.constants.d.ts +0 -1
- package/dist/src/modules/webhook/webhook.db.d.ts +0 -1
- package/dist/src/modules/webhook/webhook.dto.d.ts +0 -1
- package/dist/src/modules/webhook/webhook.repository.d.ts +0 -1
- package/dist/src/modules/webhook/webhook.router.d.ts +0 -1
- package/dist/src/modules/webhook/webhook.service.d.ts +0 -1
- package/dist/src/modules/workflow/workflow.db.d.ts +0 -1
- package/dist/src/modules/workflow/workflow.repository.d.ts +0 -1
- package/dist/src/modules/workflow/workflow.service.d.ts +0 -1
- package/dist/src/modules/workflow/workflow.trpc.d.ts +6 -43
- package/dist/src/modules/workflow/workflow.trpc.js +7 -7
- package/dist/src/modules/workflow/workflow.types.d.ts +0 -1
- package/dist/src/modules/workflow/workflow.utils.d.ts +0 -1
- package/dist/src/test/stubs/utils.d.ts +0 -1
- package/dist/src/trpc/context.d.ts +4 -5
- package/dist/src/trpc/index.d.ts +0 -1
- package/dist/src/trpc/procedures.d.ts +24 -25
- package/dist/src/trpc/utils.d.ts +0 -1
- package/dist/src/types.d.ts +61 -209
- package/dist/src/types.js +4 -5
- package/dist/src/utils/errors.d.ts +0 -1
- package/dist/src/utils/logger.d.ts +0 -1
- package/dist/src/utils/posthog.d.ts +0 -1
- package/dist/src/utils/trpc.d.ts +58 -0
- package/dist/src/utils/trpc.js +63 -0
- package/dist/src/utils/types.d.ts +0 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +6 -8
- package/.cursor/rules/backend.mdc +0 -70
- package/.turbo/turbo-build.log +0 -5
- package/.turbo/turbo-check-types.log +0 -5
- package/.turbo/turbo-lint$colon$fix.log +0 -255
- package/CHANGELOG.md +0 -37
- package/dist/src/lib/posthog.d.ts.map +0 -1
- package/dist/src/lib/sentry.d.ts.map +0 -1
- package/dist/src/modules/access/access.repository.d.ts.map +0 -1
- package/dist/src/modules/access/access.service.d.ts.map +0 -1
- package/dist/src/modules/access/access.test.d.ts.map +0 -1
- package/dist/src/modules/access/access.utils.d.ts.map +0 -1
- package/dist/src/modules/ai/ai.db.d.ts.map +0 -1
- package/dist/src/modules/ai/ai.prompt.d.ts.map +0 -1
- package/dist/src/modules/ai/ai.repository.d.ts.map +0 -1
- package/dist/src/modules/ai/ai.router.d.ts.map +0 -1
- package/dist/src/modules/ai/ai.service.d.ts.map +0 -1
- package/dist/src/modules/ai/ai.trpc.d.ts.map +0 -1
- package/dist/src/modules/ai/ideogram/ideogram.constants.d.ts.map +0 -1
- package/dist/src/modules/ai/ideogram/ideogram.dto.d.ts.map +0 -1
- package/dist/src/modules/ai/ideogram/ideogram.prompt.d.ts.map +0 -1
- package/dist/src/modules/ai/ideogram/ideogram.repository.d.ts.map +0 -1
- package/dist/src/modules/ai/ideogram/ideogram.service.d.ts.map +0 -1
- package/dist/src/modules/auth/auth.db.d.ts.map +0 -1
- package/dist/src/modules/auth/auth.dto.d.ts.map +0 -1
- package/dist/src/modules/auth/auth.lib.d.ts.map +0 -1
- package/dist/src/modules/auth/auth.middleware.d.ts.map +0 -1
- package/dist/src/modules/auth/auth.repository.d.ts.map +0 -1
- package/dist/src/modules/auth/auth.service.d.ts.map +0 -1
- package/dist/src/modules/auth/auth.trpc.d.ts.map +0 -1
- package/dist/src/modules/auth/auth.utils.d.ts.map +0 -1
- package/dist/src/modules/base/base.abstract.d.ts.map +0 -1
- package/dist/src/modules/base/base.dto.d.ts.map +0 -1
- package/dist/src/modules/base/base.grants.d.ts.map +0 -1
- package/dist/src/modules/base/base.grants.test.d.ts.map +0 -1
- package/dist/src/modules/base/base.repository.d.ts.map +0 -1
- package/dist/src/modules/base/base.service.d.ts.map +0 -1
- package/dist/src/modules/base/base.types.d.ts.map +0 -1
- package/dist/src/modules/billing/billing.db.d.ts.map +0 -1
- package/dist/src/modules/billing/billing.repository.d.ts.map +0 -1
- package/dist/src/modules/billing/billing.router.d.ts.map +0 -1
- package/dist/src/modules/billing/billing.service.d.ts.map +0 -1
- package/dist/src/modules/billing/billing.trpc.d.ts.map +0 -1
- package/dist/src/modules/clay/clay.repository.d.ts.map +0 -1
- package/dist/src/modules/clay/clay.service.d.ts.map +0 -1
- package/dist/src/modules/connect/connect.db.d.ts.map +0 -1
- package/dist/src/modules/connect/connect.dto.d.ts.map +0 -1
- package/dist/src/modules/connect/connect.linkedin.d.ts.map +0 -1
- package/dist/src/modules/connect/connect.oauth.d.ts.map +0 -1
- package/dist/src/modules/connect/connect.repository.d.ts.map +0 -1
- package/dist/src/modules/connect/connect.router.d.ts.map +0 -1
- package/dist/src/modules/connect/connect.service.d.ts.map +0 -1
- package/dist/src/modules/connect/connect.trpc.d.ts.map +0 -1
- package/dist/src/modules/connect/connect.types.d.ts.map +0 -1
- package/dist/src/modules/crypto/crypto.db.d.ts.map +0 -1
- package/dist/src/modules/crypto/crypto.repository.d.ts.map +0 -1
- package/dist/src/modules/crypto/crypto.service.d.ts.map +0 -1
- package/dist/src/modules/email/email.service.d.ts.map +0 -1
- package/dist/src/modules/file/file.repository.d.ts.map +0 -1
- package/dist/src/modules/file/file.router.d.ts.map +0 -1
- package/dist/src/modules/file/file.service.d.ts.map +0 -1
- package/dist/src/modules/recurrence/recurrence.db.d.ts.map +0 -1
- package/dist/src/modules/recurrence/recurrence.repository.d.ts.map +0 -1
- package/dist/src/modules/recurrence/recurrence.service.d.ts.map +0 -1
- package/dist/src/modules/recurrence/recurrence.trpc.d.ts.map +0 -1
- package/dist/src/modules/social/social.dto.d.ts.map +0 -1
- package/dist/src/modules/social/social.linkedin.d.ts.map +0 -1
- package/dist/src/modules/social/social.linkedin.test.d.ts.map +0 -1
- package/dist/src/modules/social/social.service.d.ts.map +0 -1
- package/dist/src/modules/social/social.types.d.ts.map +0 -1
- package/dist/src/modules/tag/tag.db.d.ts.map +0 -1
- package/dist/src/modules/tag/tag.dto.d.ts.map +0 -1
- package/dist/src/modules/tag/tag.repository.d.ts.map +0 -1
- package/dist/src/modules/tag/tag.service.d.ts.map +0 -1
- package/dist/src/modules/tag/tag.trpc.d.ts.map +0 -1
- package/dist/src/modules/utils/applyPagination.d.ts.map +0 -1
- package/dist/src/modules/utils/applySorting.d.ts.map +0 -1
- package/dist/src/modules/utils/getConditionsFromFilters.d.ts.map +0 -1
- package/dist/src/modules/video/video.service.d.ts.map +0 -1
- package/dist/src/modules/webhook/webhook.constants.d.ts.map +0 -1
- package/dist/src/modules/webhook/webhook.db.d.ts.map +0 -1
- package/dist/src/modules/webhook/webhook.dto.d.ts.map +0 -1
- package/dist/src/modules/webhook/webhook.repository.d.ts.map +0 -1
- package/dist/src/modules/webhook/webhook.router.d.ts.map +0 -1
- package/dist/src/modules/webhook/webhook.service.d.ts.map +0 -1
- package/dist/src/modules/workflow/workflow.db.d.ts.map +0 -1
- package/dist/src/modules/workflow/workflow.repository.d.ts.map +0 -1
- package/dist/src/modules/workflow/workflow.service.d.ts.map +0 -1
- package/dist/src/modules/workflow/workflow.trpc.d.ts.map +0 -1
- package/dist/src/modules/workflow/workflow.types.d.ts.map +0 -1
- package/dist/src/modules/workflow/workflow.utils.d.ts.map +0 -1
- package/dist/src/test/stubs/utils.d.ts.map +0 -1
- package/dist/src/trpc/context.d.ts.map +0 -1
- package/dist/src/trpc/index.d.ts.map +0 -1
- package/dist/src/trpc/procedures.d.ts.map +0 -1
- package/dist/src/trpc/utils.d.ts.map +0 -1
- package/dist/src/types.d.ts.map +0 -1
- package/dist/src/utils/errors.d.ts.map +0 -1
- package/dist/src/utils/logger.d.ts.map +0 -1
- package/dist/src/utils/posthog.d.ts.map +0 -1
- package/dist/src/utils/types.d.ts.map +0 -1
- package/jest.config.ts +0 -19
- package/src/lib/posthog.ts +0 -5
- package/src/lib/sentry.ts +0 -8
- package/src/modules/access/access.repository.ts +0 -36
- package/src/modules/access/access.service.ts +0 -81
- package/src/modules/access/access.test.ts +0 -216
- package/src/modules/access/access.utils.ts +0 -46
- package/src/modules/ai/ai.db.ts +0 -38
- package/src/modules/ai/ai.prompt.ts +0 -47
- package/src/modules/ai/ai.repository.ts +0 -53
- package/src/modules/ai/ai.router.ts +0 -148
- package/src/modules/ai/ai.service.ts +0 -310
- package/src/modules/ai/ai.trpc.ts +0 -22
- package/src/modules/ai/ideogram/ideogram.constants.ts +0 -170
- package/src/modules/ai/ideogram/ideogram.dto.ts +0 -64
- package/src/modules/ai/ideogram/ideogram.prompt.ts +0 -858
- package/src/modules/ai/ideogram/ideogram.repository.ts +0 -39
- package/src/modules/ai/ideogram/ideogram.service.ts +0 -14
- package/src/modules/auth/auth.db.ts +0 -224
- package/src/modules/auth/auth.dto.ts +0 -47
- package/src/modules/auth/auth.lib.ts +0 -349
- package/src/modules/auth/auth.middleware.ts +0 -62
- package/src/modules/auth/auth.repository.ts +0 -672
- package/src/modules/auth/auth.service.ts +0 -261
- package/src/modules/auth/auth.trpc.ts +0 -208
- package/src/modules/auth/auth.utils.ts +0 -117
- package/src/modules/base/base.abstract.ts +0 -62
- package/src/modules/base/base.dto.ts +0 -206
- package/src/modules/base/base.grants.test.ts +0 -861
- package/src/modules/base/base.grants.ts +0 -199
- package/src/modules/base/base.repository.ts +0 -433
- package/src/modules/base/base.service.ts +0 -154
- package/src/modules/base/base.types.ts +0 -7
- package/src/modules/billing/billing.db.ts +0 -27
- package/src/modules/billing/billing.repository.ts +0 -328
- package/src/modules/billing/billing.router.ts +0 -77
- package/src/modules/billing/billing.service.ts +0 -177
- package/src/modules/billing/billing.trpc.ts +0 -17
- package/src/modules/clay/clay.repository.ts +0 -29
- package/src/modules/clay/clay.service.ts +0 -61
- package/src/modules/connect/connect.db.ts +0 -32
- package/src/modules/connect/connect.dto.ts +0 -44
- package/src/modules/connect/connect.linkedin.ts +0 -70
- package/src/modules/connect/connect.oauth.ts +0 -288
- package/src/modules/connect/connect.repository.ts +0 -65
- package/src/modules/connect/connect.router.ts +0 -76
- package/src/modules/connect/connect.service.ts +0 -171
- package/src/modules/connect/connect.trpc.ts +0 -26
- package/src/modules/connect/connect.types.ts +0 -27
- package/src/modules/crypto/crypto.db.ts +0 -15
- package/src/modules/crypto/crypto.repository.ts +0 -13
- package/src/modules/crypto/crypto.service.ts +0 -57
- package/src/modules/email/email.service.ts +0 -222
- package/src/modules/file/file.repository.ts +0 -95
- package/src/modules/file/file.router.ts +0 -108
- package/src/modules/file/file.service.ts +0 -186
- package/src/modules/recurrence/recurrence.db.ts +0 -79
- package/src/modules/recurrence/recurrence.repository.ts +0 -70
- package/src/modules/recurrence/recurrence.service.ts +0 -105
- package/src/modules/recurrence/recurrence.trpc.ts +0 -82
- package/src/modules/social/social.dto.ts +0 -22
- package/src/modules/social/social.linkedin.test.ts +0 -277
- package/src/modules/social/social.linkedin.ts +0 -593
- package/src/modules/social/social.service.ts +0 -112
- package/src/modules/social/social.types.ts +0 -43
- package/src/modules/tag/tag.db.ts +0 -41
- package/src/modules/tag/tag.dto.ts +0 -18
- package/src/modules/tag/tag.repository.ts +0 -222
- package/src/modules/tag/tag.service.ts +0 -48
- package/src/modules/tag/tag.trpc.ts +0 -62
- package/src/modules/uploads/0581796b-8845-420d-bd95-cd7de79f6d37.webm +0 -0
- package/src/modules/uploads/33b1e649-6727-4bd0-94d0-a0b363646865.webm +0 -0
- package/src/modules/uploads/49a8c4c0-54d7-4c94-bef4-c93c029f9ed0.webm +0 -0
- package/src/modules/uploads/50e31e38-a2f0-47ca-8b7d-2d7fcad9267d.webm +0 -0
- package/src/modules/uploads/72ac8cf9-c3a7-4cd8-8a78-6d8e137a4c7e.webm +0 -0
- package/src/modules/uploads/75293649-d966-46cd-a675-67518958ae9c.png +0 -0
- package/src/modules/uploads/88b7b867-ce15-4891-bf73-81305a7de1f7.wav +0 -0
- package/src/modules/uploads/a5d6fee8-6a59-42c6-9d4a-ac8a3c5e7245.webm +0 -0
- package/src/modules/uploads/c13a9785-ca5a-4983-af30-b338ed76d370.webm +0 -0
- package/src/modules/uploads/caa1a5a7-71ba-4381-902d-7e2cafdf6dcb.webm +0 -0
- package/src/modules/uploads/cbeb0b81-374d-445b-914b-40ace7c8e031.webm +0 -0
- package/src/modules/uploads/d626aa82-b10f-493f-aee7-87bfb3361dfc.webm +0 -0
- package/src/modules/uploads/d7de4c16-de0c-495d-9612-e72260a6ecca.png +0 -0
- package/src/modules/uploads/e532e38a-6421-400e-8a5f-8e7bc8ce411b.wav +0 -0
- package/src/modules/uploads/e86ec867-6adf-4c51-84e0-00b0836625e8.webm +0 -0
- package/src/modules/utils/applyPagination.ts +0 -13
- package/src/modules/utils/applySorting.ts +0 -21
- package/src/modules/utils/getConditionsFromFilters.ts +0 -216
- package/src/modules/video/video.service.ts +0 -89
- package/src/modules/webhook/webhook.constants.ts +0 -9
- package/src/modules/webhook/webhook.db.ts +0 -15
- package/src/modules/webhook/webhook.dto.ts +0 -9
- package/src/modules/webhook/webhook.repository.ts +0 -68
- package/src/modules/webhook/webhook.router.ts +0 -29
- package/src/modules/webhook/webhook.service.ts +0 -78
- package/src/modules/workflow/workflow.db.ts +0 -29
- package/src/modules/workflow/workflow.repository.ts +0 -171
- package/src/modules/workflow/workflow.service.ts +0 -56
- package/src/modules/workflow/workflow.trpc.ts +0 -26
- package/src/modules/workflow/workflow.types.ts +0 -30
- package/src/modules/workflow/workflow.utils.ts +0 -259
- package/src/test/stubs/utils.ts +0 -2
- package/src/trpc/context.ts +0 -21
- package/src/trpc/index.ts +0 -3
- package/src/trpc/procedures.ts +0 -43
- package/src/trpc/utils.ts +0 -20
- package/src/types.ts +0 -22
- package/src/utils/errors.ts +0 -148
- package/src/utils/logger.ts +0 -8
- package/src/utils/posthog.ts +0 -43
- package/src/utils/types.ts +0 -5
- package/tsconfig.json +0 -21
|
@@ -1,206 +0,0 @@
|
|
|
1
|
-
import { getTableColumns, type InferSelectModel, type Table } from "drizzle-orm";
|
|
2
|
-
import { createSelectSchema } from "drizzle-zod";
|
|
3
|
-
import type { Result } from "neverthrow";
|
|
4
|
-
import { z } from "zod";
|
|
5
|
-
import type { ServerError } from "#utils/errors";
|
|
6
|
-
|
|
7
|
-
type Simplify<T> = { [K in keyof T]: T[K] } & {};
|
|
8
|
-
type StringKeys<T> = Extract<keyof T, string>;
|
|
9
|
-
|
|
10
|
-
export type ServerResult<T> = Result<T, ServerError>;
|
|
11
|
-
export type ServerResultAsync<T> = Promise<ServerResult<T>>;
|
|
12
|
-
|
|
13
|
-
// Wrapper to force the drizzle-zod overload to the Table version
|
|
14
|
-
export const createTableSelectSchema = <T extends Table>(table: T) => createSelectSchema(table);
|
|
15
|
-
|
|
16
|
-
export type ExtractColumnTypes<T extends Table, C extends Record<string, unknown>> = Simplify<
|
|
17
|
-
Pick<InferSelectModel<T>, Extract<keyof C, keyof InferSelectModel<T>>>
|
|
18
|
-
>;
|
|
19
|
-
|
|
20
|
-
export function toZodFilter<const T extends readonly string[]>(array: T): Record<T[number], true> {
|
|
21
|
-
return array.reduce(
|
|
22
|
-
(acc, column) => {
|
|
23
|
-
acc[column as T[number]] = true;
|
|
24
|
-
return acc;
|
|
25
|
-
},
|
|
26
|
-
{} as Record<T[number], true>
|
|
27
|
-
);
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
export function pickSchema<
|
|
31
|
-
Shape extends z.ZodRawShape,
|
|
32
|
-
const Keys extends readonly StringKeys<Shape>[],
|
|
33
|
-
>(schema: z.ZodObject<Shape>, keys: Keys): z.ZodObject<Pick<Shape, Keys[number]>> {
|
|
34
|
-
const mask: Record<keyof Shape, true> = {} as Record<keyof Shape, true>;
|
|
35
|
-
for (const k of keys) {
|
|
36
|
-
mask[k] = true;
|
|
37
|
-
}
|
|
38
|
-
return schema.pick(mask) as z.ZodObject<Pick<Shape, Keys[number]>>;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
export function pickTableSchema<T extends Table, K extends keyof InferSelectModel<T>>(
|
|
42
|
-
table: T,
|
|
43
|
-
columns: readonly K[]
|
|
44
|
-
) {
|
|
45
|
-
return pickSchema(createSelectSchema(table), columns);
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
export function omitSchema<
|
|
49
|
-
Shape extends z.ZodRawShape,
|
|
50
|
-
const Keys extends readonly StringKeys<Shape>[],
|
|
51
|
-
>(schema: z.ZodObject<Shape>, keys: Keys): z.ZodObject<Omit<Shape, Keys[number]>> {
|
|
52
|
-
const mask: Record<keyof Shape, true> = {} as Record<keyof Shape, true>;
|
|
53
|
-
for (const k of keys) {
|
|
54
|
-
mask[k] = true;
|
|
55
|
-
}
|
|
56
|
-
return schema.omit(mask) as z.ZodObject<Omit<Shape, Keys[number]>>;
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
export function omitTableSchema<T extends Table, K extends keyof InferSelectModel<T>>(
|
|
60
|
-
table: T,
|
|
61
|
-
columns: readonly K[]
|
|
62
|
-
) {
|
|
63
|
-
return omitSchema(createSelectSchema(table), columns);
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
export { getTableColumns };
|
|
67
|
-
|
|
68
|
-
export function pickColumns<T extends Table, Shape extends z.ZodRawShape>(
|
|
69
|
-
table: T,
|
|
70
|
-
schema: z.ZodObject<Shape>
|
|
71
|
-
): Pick<ReturnType<typeof getTableColumns<T>>, Extract<keyof Shape, string>> {
|
|
72
|
-
const allColumns = getTableColumns(table);
|
|
73
|
-
const schemaKeys = Object.keys(schema.shape) as Array<Extract<keyof Shape, string>>;
|
|
74
|
-
|
|
75
|
-
const result = {} as Pick<typeof allColumns, Extract<keyof Shape, string>>;
|
|
76
|
-
for (const key of schemaKeys) {
|
|
77
|
-
if (key in allColumns) {
|
|
78
|
-
(result as any)[key] = allColumns[key as keyof typeof allColumns];
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
return result;
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
export function pickTableColumns<T extends Table, K extends keyof InferSelectModel<T>>(
|
|
86
|
-
table: T,
|
|
87
|
-
columns: readonly K[]
|
|
88
|
-
): Pick<ReturnType<typeof getTableColumns<T>>, K> {
|
|
89
|
-
const allColumns = getTableColumns(table);
|
|
90
|
-
const result = {} as Pick<typeof allColumns, K>;
|
|
91
|
-
for (const key of columns) {
|
|
92
|
-
if (key in allColumns) {
|
|
93
|
-
result[key] = allColumns[key];
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
return result;
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
export function omitTableColumns<T extends Table, K extends keyof InferSelectModel<T>>(
|
|
100
|
-
table: T,
|
|
101
|
-
columns: readonly K[]
|
|
102
|
-
): Omit<ReturnType<typeof getTableColumns<T>>, K> {
|
|
103
|
-
const allColumns = getTableColumns(table);
|
|
104
|
-
const columnsToOmit = new Set(columns as readonly string[]);
|
|
105
|
-
const filteredEntries = Object.entries(allColumns).filter(([key]) => !columnsToOmit.has(key));
|
|
106
|
-
return Object.fromEntries(filteredEntries) as Omit<typeof allColumns, K>;
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
// Overloads to narrow return type based on provided partial
|
|
110
|
-
export function createSelectDTO<T extends Table>(
|
|
111
|
-
table: T
|
|
112
|
-
): {
|
|
113
|
-
columns: ReturnType<typeof getTableColumns<T>>;
|
|
114
|
-
schema: ReturnType<typeof createTableSelectSchema<T>>;
|
|
115
|
-
};
|
|
116
|
-
export function createSelectDTO<
|
|
117
|
-
T extends Table,
|
|
118
|
-
K extends Extract<keyof InferSelectModel<T>, string>,
|
|
119
|
-
>(
|
|
120
|
-
table: T,
|
|
121
|
-
partial: { omit: readonly K[] }
|
|
122
|
-
): {
|
|
123
|
-
columns: ReturnType<typeof omitTableColumns<T, K>>;
|
|
124
|
-
schema: ReturnType<typeof omitTableSchema<T, K>>;
|
|
125
|
-
};
|
|
126
|
-
export function createSelectDTO<
|
|
127
|
-
T extends Table,
|
|
128
|
-
K extends Extract<keyof InferSelectModel<T>, string>,
|
|
129
|
-
>(
|
|
130
|
-
table: T,
|
|
131
|
-
partial: { pick: readonly K[] }
|
|
132
|
-
): {
|
|
133
|
-
columns: ReturnType<typeof pickTableColumns<T, K>>;
|
|
134
|
-
schema: ReturnType<typeof pickTableSchema<T, K>>;
|
|
135
|
-
};
|
|
136
|
-
|
|
137
|
-
// Implementation
|
|
138
|
-
export function createSelectDTO<T extends Table>(
|
|
139
|
-
table: T,
|
|
140
|
-
partial?:
|
|
141
|
-
| { omit: readonly (keyof InferSelectModel<T>)[] }
|
|
142
|
-
| { pick: readonly (keyof InferSelectModel<T>)[] }
|
|
143
|
-
): { columns: unknown; schema: unknown } {
|
|
144
|
-
if (partial) {
|
|
145
|
-
if ("omit" in partial && partial.omit) {
|
|
146
|
-
return {
|
|
147
|
-
columns: omitTableColumns(table, partial.omit),
|
|
148
|
-
schema: omitTableSchema(table, partial.omit),
|
|
149
|
-
};
|
|
150
|
-
}
|
|
151
|
-
if ("pick" in partial && partial.pick) {
|
|
152
|
-
return {
|
|
153
|
-
columns: pickTableColumns(table, partial.pick),
|
|
154
|
-
schema: pickTableSchema(table, partial.pick),
|
|
155
|
-
};
|
|
156
|
-
}
|
|
157
|
-
}
|
|
158
|
-
return { columns: getTableColumns(table), schema: createTableSelectSchema(table) };
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
export function createSelectUtils<
|
|
162
|
-
T extends Record<
|
|
163
|
-
string,
|
|
164
|
-
{
|
|
165
|
-
columns: unknown;
|
|
166
|
-
schema: z.ZodTypeAny;
|
|
167
|
-
}
|
|
168
|
-
>,
|
|
169
|
-
S extends z.ZodTypeAny,
|
|
170
|
-
>(
|
|
171
|
-
dtos: T,
|
|
172
|
-
output: S,
|
|
173
|
-
transformer: (rows: Array<{ [K in keyof T]: z.infer<T[K]["schema"]> }>) => z.infer<S>
|
|
174
|
-
): {
|
|
175
|
-
select: { [K in keyof T]: T[K]["columns"] };
|
|
176
|
-
output: S;
|
|
177
|
-
transformer: (rows: Array<{ [K in keyof T]: z.infer<T[K]["schema"]> }>) => z.infer<S>;
|
|
178
|
-
} {
|
|
179
|
-
return {
|
|
180
|
-
select: Object.fromEntries(Object.entries(dtos).map(([key, dto]) => [key, dto.columns])) as {
|
|
181
|
-
[K in keyof T]: T[K]["columns"];
|
|
182
|
-
},
|
|
183
|
-
output,
|
|
184
|
-
transformer,
|
|
185
|
-
};
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
export const uuidOutput = z.object({
|
|
189
|
-
id: z.uuid(),
|
|
190
|
-
});
|
|
191
|
-
|
|
192
|
-
export const uuidManyOutput = z.object({
|
|
193
|
-
ids: z.array(z.uuid()),
|
|
194
|
-
});
|
|
195
|
-
|
|
196
|
-
export const scheduleOutput = z.object({
|
|
197
|
-
jobId: z.string(),
|
|
198
|
-
});
|
|
199
|
-
|
|
200
|
-
export const scheduleManyOutput = z.object({
|
|
201
|
-
jobIds: z.array(z.string()),
|
|
202
|
-
});
|
|
203
|
-
|
|
204
|
-
export const deleteOutput = uuidOutput;
|
|
205
|
-
|
|
206
|
-
export const deleteManyOutput = uuidManyOutput;
|