@fragno-dev/db 0.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.
@@ -0,0 +1,18 @@
1
+ import type { Kysely } from "kysely";
2
+ import type { SQLProvider } from "./providers";
3
+ import type { AnySchema } from "../schema/create";
4
+
5
+ export interface LibraryConfig<TSchemas extends AnySchema[] = AnySchema[]> {
6
+ namespace: string;
7
+
8
+ /**
9
+ * different versions of schemas (sorted in ascending order)
10
+ */
11
+ schemas: TSchemas;
12
+ }
13
+
14
+ export interface KyselyConfig {
15
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
16
+ db: Kysely<any>;
17
+ provider: SQLProvider;
18
+ }
@@ -0,0 +1,45 @@
1
+ export type PrismaClient = Record<
2
+ string,
3
+ {
4
+ count: (options: {
5
+ select: Record<string, unknown>;
6
+ where?: object;
7
+ }) => Promise<Record<string, number>>;
8
+ upsert: (options: {
9
+ where: object;
10
+ update: Record<string, unknown>;
11
+ create: Record<string, unknown>;
12
+ }) => Promise<void>;
13
+
14
+ create: (options: { data: Record<string, unknown> }) => Promise<Record<string, unknown>>;
15
+
16
+ createMany: (options: { data: Record<string, unknown>[] }) => Promise<void>;
17
+
18
+ delete: (options: { where: object }) => Promise<Record<string, unknown>>;
19
+
20
+ deleteMany: (options: { where?: object }) => Promise<void>;
21
+
22
+ findFirst: (options: {
23
+ where: object;
24
+ select?: Record<string, unknown>;
25
+ orderBy?: OrderBy | OrderBy[];
26
+ skip?: number;
27
+ }) => Promise<Record<string, unknown> | null>;
28
+
29
+ findMany: (options: {
30
+ where?: object;
31
+ select?: Record<string, unknown>;
32
+ orderBy?: OrderBy | OrderBy[];
33
+ skip?: number;
34
+ take?: number;
35
+ }) => Promise<Record<string, unknown>[]>;
36
+
37
+ updateMany: (options: { where?: object; data: Record<string, unknown> }) => Promise<void>;
38
+ }
39
+ > & {
40
+ $transaction: <T>(v: (tx: PrismaClient) => T | Promise<T>) => Promise<T>;
41
+ };
42
+
43
+ export type OrderBy = {
44
+ [k: string]: "asc" | "desc" | OrderBy;
45
+ };
@@ -0,0 +1,10 @@
1
+ export const sqlProviders = ["sqlite", "cockroachdb", "mysql", "postgresql", "mssql"] as const;
2
+
3
+ export const noSqlProviders = ["mongodb"] as const;
4
+
5
+ export const providers = [...sqlProviders, ...noSqlProviders] as const;
6
+
7
+ export type Provider = (typeof providers)[number];
8
+
9
+ export type SQLProvider = (typeof sqlProviders)[number];
10
+ export type NoSQLProvider = (typeof noSqlProviders)[number];
@@ -0,0 +1,29 @@
1
+ // Minimal deep equal utility for primitives, arrays, and plain objects
2
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
3
+ export function deepEqual(a: any, b: any): boolean {
4
+ if (a === b) return true;
5
+ if (typeof a !== typeof b) return false;
6
+
7
+ if (Array.isArray(a) && Array.isArray(b)) {
8
+ if (a.length !== b.length) return false;
9
+ for (let i = 0; i < a.length; i++) {
10
+ if (!deepEqual(a[i], b[i])) return false;
11
+ }
12
+ return true;
13
+ }
14
+
15
+ if (typeof a === "object" && typeof b === "object") {
16
+ const aKeys = Object.keys(a);
17
+ const bKeys = Object.keys(b);
18
+ if (aKeys.length !== bKeys.length) return false;
19
+ for (const key of aKeys) {
20
+ if (!(key in b)) return false;
21
+
22
+ if (!Object.hasOwn(b, key) || !deepEqual(a[key], b[key])) return false;
23
+ }
24
+
25
+ return true;
26
+ }
27
+
28
+ return false;
29
+ }
package/tsconfig.json ADDED
@@ -0,0 +1,10 @@
1
+ {
2
+ "extends": "@fragno-private/typescript-config/tsconfig.base.json",
3
+ "compilerOptions": {
4
+ "outDir": "./dist",
5
+ "rootDir": ".",
6
+ "composite": true
7
+ },
8
+ "include": ["src"],
9
+ "exclude": ["node_modules", "dist"]
10
+ }
@@ -0,0 +1,7 @@
1
+ import { defineConfig } from "tsdown";
2
+
3
+ export default defineConfig({
4
+ entry: ["./src/mod.ts", "./src/schema/create.ts"],
5
+ dts: true,
6
+ unbundle: true,
7
+ });
@@ -0,0 +1,7 @@
1
+ import { defineConfig } from "vitest/config";
2
+
3
+ export default defineConfig({
4
+ test: {
5
+ environment: "node",
6
+ },
7
+ });