@veloxts/orm 0.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.
@@ -0,0 +1,146 @@
1
+ /**
2
+ * Type definitions for @veloxts/orm
3
+ *
4
+ * Provides type-safe abstractions for Prisma client integration
5
+ * without requiring direct Prisma dependency.
6
+ *
7
+ * @module types
8
+ */
9
+ /**
10
+ * Extend the VeloxErrorCodeRegistry to include ORM-specific error codes
11
+ *
12
+ * This enables type-safe error handling for database-related errors
13
+ */
14
+ declare module '@veloxts/core' {
15
+ interface VeloxErrorCodeRegistry {
16
+ orm: 'DATABASE_CONNECTION_ERROR' | 'DATABASE_DISCONNECTION_ERROR' | 'DATABASE_NOT_CONNECTED' | 'DATABASE_ALREADY_CONNECTED' | 'DATABASE_CONNECTION_IN_PROGRESS' | 'DATABASE_DISCONNECTION_IN_PROGRESS';
17
+ }
18
+ }
19
+ /**
20
+ * Minimal interface that any Prisma client must satisfy
21
+ *
22
+ * This interface allows the ORM package to work with any Prisma client
23
+ * without requiring @prisma/client as a direct dependency.
24
+ *
25
+ * @example
26
+ * ```typescript
27
+ * import { PrismaClient } from '@prisma/client';
28
+ *
29
+ * // PrismaClient satisfies DatabaseClient
30
+ * const prisma: DatabaseClient = new PrismaClient();
31
+ * ```
32
+ */
33
+ export interface DatabaseClient {
34
+ /**
35
+ * Establishes connection to the database
36
+ *
37
+ * Called automatically when using createDatabasePlugin,
38
+ * or can be called manually with createDatabase.
39
+ */
40
+ $connect: () => Promise<void>;
41
+ /**
42
+ * Disconnects from the database
43
+ *
44
+ * Called automatically during app shutdown when using createDatabasePlugin,
45
+ * or can be called manually with createDatabase.
46
+ */
47
+ $disconnect: () => Promise<void>;
48
+ }
49
+ /**
50
+ * Type guard to check if an object is a valid DatabaseClient
51
+ *
52
+ * Uses property checks to ensure the object has the required methods
53
+ * without using type assertions.
54
+ *
55
+ * @param value - Value to check
56
+ * @returns true if value satisfies DatabaseClient interface
57
+ *
58
+ * @example
59
+ * ```typescript
60
+ * if (isDatabaseClient(unknownValue)) {
61
+ * await unknownValue.$connect();
62
+ * }
63
+ * ```
64
+ */
65
+ export declare function isDatabaseClient(value: unknown): value is DatabaseClient;
66
+ /**
67
+ * Configuration options for the database plugin
68
+ *
69
+ * @template TClient - Type of the Prisma client
70
+ */
71
+ export interface OrmPluginConfig<TClient extends DatabaseClient> {
72
+ /**
73
+ * The Prisma client instance to use
74
+ *
75
+ * Must be an already-instantiated PrismaClient. Connection will be
76
+ * managed by the plugin (connect on start, disconnect on shutdown).
77
+ *
78
+ * @example
79
+ * ```typescript
80
+ * const prisma = new PrismaClient();
81
+ * const plugin = createDatabasePlugin({ client: prisma });
82
+ * ```
83
+ */
84
+ client: TClient;
85
+ /**
86
+ * Custom name for the plugin registration
87
+ *
88
+ * Defaults to '@veloxts/orm'. Useful when registering multiple database
89
+ * connections with different names.
90
+ *
91
+ * @default '@veloxts/orm'
92
+ */
93
+ name?: string;
94
+ }
95
+ /**
96
+ * Configuration options for the database wrapper
97
+ */
98
+ export interface DatabaseWrapperConfig<TClient extends DatabaseClient> {
99
+ /**
100
+ * The Prisma client instance to wrap
101
+ */
102
+ client: TClient;
103
+ }
104
+ /**
105
+ * Possible states of a database connection
106
+ */
107
+ export type ConnectionState = 'disconnected' | 'connecting' | 'connected' | 'disconnecting';
108
+ /**
109
+ * Database connection status information
110
+ */
111
+ export interface ConnectionStatus {
112
+ /**
113
+ * Current connection state
114
+ */
115
+ state: ConnectionState;
116
+ /**
117
+ * Whether the database is currently connected and ready for queries
118
+ */
119
+ isConnected: boolean;
120
+ /**
121
+ * Timestamp of last successful connection, if any
122
+ */
123
+ connectedAt?: Date;
124
+ }
125
+ /**
126
+ * Infer the client type from an OrmPluginConfig
127
+ *
128
+ * @template T - OrmPluginConfig type
129
+ *
130
+ * @example
131
+ * ```typescript
132
+ * const config = { client: new PrismaClient() };
133
+ * type Client = InferClientType<typeof config>;
134
+ * // Client = PrismaClient
135
+ * ```
136
+ */
137
+ export type InferClientType<T> = T extends OrmPluginConfig<infer C> ? C : never;
138
+ /**
139
+ * Infer the client type from a Database wrapper
140
+ *
141
+ * @template T - Database wrapper type
142
+ */
143
+ export type InferDatabaseClient<T> = T extends {
144
+ client: infer C;
145
+ } ? C : never;
146
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAMH;;;;GAIG;AACH,OAAO,QAAQ,eAAe,CAAC;IAC7B,UAAU,sBAAsB;QAC9B,GAAG,EACC,2BAA2B,GAC3B,8BAA8B,GAC9B,wBAAwB,GACxB,4BAA4B,GAC5B,iCAAiC,GACjC,oCAAoC,CAAC;KAC1C;CACF;AAMD;;;;;;;;;;;;;GAaG;AACH,MAAM,WAAW,cAAc;IAC7B;;;;;OAKG;IACH,QAAQ,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;IAE9B;;;;;OAKG;IACH,WAAW,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;CAClC;AAED;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,cAAc,CAYxE;AAMD;;;;GAIG;AACH,MAAM,WAAW,eAAe,CAAC,OAAO,SAAS,cAAc;IAC7D;;;;;;;;;;;OAWG;IACH,MAAM,EAAE,OAAO,CAAC;IAEhB;;;;;;;OAOG;IACH,IAAI,CAAC,EAAE,MAAM,CAAC;CACf;AAED;;GAEG;AACH,MAAM,WAAW,qBAAqB,CAAC,OAAO,SAAS,cAAc;IACnE;;OAEG;IACH,MAAM,EAAE,OAAO,CAAC;CACjB;AAMD;;GAEG;AACH,MAAM,MAAM,eAAe,GAAG,cAAc,GAAG,YAAY,GAAG,WAAW,GAAG,eAAe,CAAC;AAE5F;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAC/B;;OAEG;IACH,KAAK,EAAE,eAAe,CAAC;IAEvB;;OAEG;IACH,WAAW,EAAE,OAAO,CAAC;IAErB;;OAEG;IACH,WAAW,CAAC,EAAE,IAAI,CAAC;CACpB;AAMD;;;;;;;;;;;GAWG;AACH,MAAM,MAAM,eAAe,CAAC,CAAC,IAAI,CAAC,SAAS,eAAe,CAAC,MAAM,CAAC,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC;AAEhF;;;;GAIG;AACH,MAAM,MAAM,mBAAmB,CAAC,CAAC,IAAI,CAAC,SAAS;IAAE,MAAM,EAAE,MAAM,CAAC,CAAA;CAAE,GAAG,CAAC,GAAG,KAAK,CAAC"}
package/dist/types.js ADDED
@@ -0,0 +1,35 @@
1
+ /**
2
+ * Type definitions for @veloxts/orm
3
+ *
4
+ * Provides type-safe abstractions for Prisma client integration
5
+ * without requiring direct Prisma dependency.
6
+ *
7
+ * @module types
8
+ */
9
+ /**
10
+ * Type guard to check if an object is a valid DatabaseClient
11
+ *
12
+ * Uses property checks to ensure the object has the required methods
13
+ * without using type assertions.
14
+ *
15
+ * @param value - Value to check
16
+ * @returns true if value satisfies DatabaseClient interface
17
+ *
18
+ * @example
19
+ * ```typescript
20
+ * if (isDatabaseClient(unknownValue)) {
21
+ * await unknownValue.$connect();
22
+ * }
23
+ * ```
24
+ */
25
+ export function isDatabaseClient(value) {
26
+ if (typeof value !== 'object' || value === null) {
27
+ return false;
28
+ }
29
+ // Check for required methods
30
+ return ('$connect' in value &&
31
+ typeof value.$connect === 'function' &&
32
+ '$disconnect' in value &&
33
+ typeof value.$disconnect === 'function');
34
+ }
35
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AA2DH;;;;;;;;;;;;;;;GAeG;AACH,MAAM,UAAU,gBAAgB,CAAC,KAAc;IAC7C,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,EAAE,CAAC;QAChD,OAAO,KAAK,CAAC;IACf,CAAC;IAED,6BAA6B;IAC7B,OAAO,CACL,UAAU,IAAI,KAAK;QACnB,OAAO,KAAK,CAAC,QAAQ,KAAK,UAAU;QACpC,aAAa,IAAI,KAAK;QACtB,OAAO,KAAK,CAAC,WAAW,KAAK,UAAU,CACxC,CAAC;AACJ,CAAC"}
package/package.json ADDED
@@ -0,0 +1,62 @@
1
+ {
2
+ "name": "@veloxts/orm",
3
+ "version": "0.1.0",
4
+ "description": "Prisma wrapper with enhanced DX for VeloxTS framework",
5
+ "type": "module",
6
+ "main": "dist/index.js",
7
+ "types": "dist/index.d.ts",
8
+ "exports": {
9
+ ".": {
10
+ "types": "./dist/index.d.ts",
11
+ "import": "./dist/index.js"
12
+ }
13
+ },
14
+ "dependencies": {
15
+ "fastify": "5.6.2",
16
+ "@veloxts/core": "0.1.0"
17
+ },
18
+ "devDependencies": {
19
+ "typescript": "5.9.3",
20
+ "vitest": "4.0.15"
21
+ },
22
+ "peerDependencies": {
23
+ "@prisma/client": ">=5.0.0"
24
+ },
25
+ "peerDependenciesMeta": {
26
+ "@prisma/client": {
27
+ "optional": true
28
+ }
29
+ },
30
+ "files": [
31
+ "dist",
32
+ "README.md"
33
+ ],
34
+ "keywords": [
35
+ "velox",
36
+ "orm",
37
+ "prisma",
38
+ "database",
39
+ "fullstack",
40
+ "typescript"
41
+ ],
42
+ "license": "MIT",
43
+ "repository": {
44
+ "type": "git",
45
+ "url": "https://github.com/veloxts/velox-ts-framework",
46
+ "directory": "packages/orm"
47
+ },
48
+ "engines": {
49
+ "node": ">=20.0.0"
50
+ },
51
+ "publishConfig": {
52
+ "access": "public"
53
+ },
54
+ "scripts": {
55
+ "build": "tsc",
56
+ "dev": "tsc --watch",
57
+ "type-check": "tsc --noEmit",
58
+ "clean": "rm -rf dist tsconfig.tsbuildinfo",
59
+ "test": "vitest run",
60
+ "test:watch": "vitest"
61
+ }
62
+ }