@hazeljs/prisma 0.8.5 → 0.8.7

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hazeljs/prisma",
3
- "version": "0.8.5",
3
+ "version": "0.8.7",
4
4
  "description": "Prisma ORM integration for HazelJS framework",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -48,7 +48,7 @@
48
48
  },
49
49
  "homepage": "https://hazeljs.ai",
50
50
  "peerDependencies": {
51
- "@hazeljs/core": "^0.8.5"
51
+ "@hazeljs/core": "^0.8.7"
52
52
  },
53
- "gitHead": "17874837994b8ce260f70ae09d2fe58d5606d18a"
53
+ "gitHead": "7e6f4d6ed5e9d92cdd5f43f3577f5e0361202878"
54
54
  }
@@ -1,39 +0,0 @@
1
- /**
2
- * Prisma implementation of the unified BaseRepository
3
- * Provides consistent repository interface for Prisma models
4
- */
5
- import { BaseRepository, FindOptions, FindOneOptions, CountOptions } from '@hazeljs/database';
6
- import { PrismaService } from './prisma.service';
7
- /**
8
- * Prisma-specific repository implementation
9
- */
10
- export declare class PrismaBaseRepository<T = any> extends BaseRepository<T> {
11
- protected readonly prisma: PrismaService;
12
- protected entity: string;
13
- private modelDelegate;
14
- constructor(prisma: PrismaService, entity: string);
15
- find(options?: FindOptions): Promise<T[]>;
16
- findOne(id: string | number | FindOneOptions): Promise<T | null>;
17
- create(data: Partial<T>): Promise<T>;
18
- update(id: string | number, data: Partial<T>): Promise<T>;
19
- delete(id: string | number): Promise<void>;
20
- count(options?: CountOptions): Promise<number>;
21
- exists(id: string | number): Promise<boolean>;
22
- /**
23
- * Convert unified FindOptions to Prisma-specific options
24
- */
25
- private convertFindOptions;
26
- /**
27
- * Convert unified FindOneOptions to Prisma-specific options
28
- */
29
- private convertFindOneOptions;
30
- /**
31
- * Convert unified CountOptions to Prisma-specific options
32
- */
33
- private convertCountOptions;
34
- /**
35
- * Handle database errors consistently
36
- */
37
- private handleError;
38
- }
39
- //# sourceMappingURL=prisma.repository.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"prisma.repository.d.ts","sourceRoot":"","sources":["../src/prisma.repository.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,EAAE,cAAc,EAAE,WAAW,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAC9F,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AAGjD;;GAEG;AACH,qBACa,oBAAoB,CAAC,CAAC,GAAG,GAAG,CAAE,SAAQ,cAAc,CAAC,CAAC,CAAC;IAKhE,SAAS,CAAC,QAAQ,CAAC,MAAM,EAAE,aAAa;IAJ1C,SAAS,CAAC,MAAM,EAAE,MAAM,CAAC;IACzB,OAAO,CAAC,aAAa,CAAM;gBAGN,MAAM,EAAE,aAAa,EACxC,MAAM,EAAE,MAAM;IAOV,IAAI,CAAC,OAAO,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,CAAC,EAAE,CAAC;IASzC,OAAO,CAAC,EAAE,EAAE,MAAM,GAAG,MAAM,GAAG,cAAc,GAAG,OAAO,CAAC,CAAC,GAAG,IAAI,CAAC;IAehE,MAAM,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC;IAUpC,MAAM,CAAC,EAAE,EAAE,MAAM,GAAG,MAAM,EAAE,IAAI,EAAE,OAAO,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC;IAWzD,MAAM,CAAC,EAAE,EAAE,MAAM,GAAG,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAU1C,KAAK,CAAC,OAAO,CAAC,EAAE,YAAY,GAAG,OAAO,CAAC,MAAM,CAAC;IAS9C,MAAM,CAAC,EAAE,EAAE,MAAM,GAAG,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAYnD;;OAEG;IACH,OAAO,CAAC,kBAAkB;IAqC1B;;OAEG;IACH,OAAO,CAAC,qBAAqB;IAuB7B;;OAEG;IACH,OAAO,CAAC,mBAAmB;IAY3B;;OAEG;IACH,OAAO,CAAC,WAAW;CAgBpB"}
@@ -1,191 +0,0 @@
1
- "use strict";
2
- /**
3
- * Prisma implementation of the unified BaseRepository
4
- * Provides consistent repository interface for Prisma models
5
- */
6
- var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
7
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
8
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
9
- else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
10
- return c > 3 && r && Object.defineProperty(target, key, r), r;
11
- };
12
- var __metadata = (this && this.__metadata) || function (k, v) {
13
- if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
14
- };
15
- Object.defineProperty(exports, "__esModule", { value: true });
16
- exports.PrismaBaseRepository = void 0;
17
- const core_1 = require("@hazeljs/core");
18
- const database_1 = require("@hazeljs/database");
19
- const prisma_service_1 = require("./prisma.service");
20
- const database_2 = require("@hazeljs/database");
21
- /**
22
- * Prisma-specific repository implementation
23
- */
24
- let PrismaBaseRepository = class PrismaBaseRepository extends database_1.BaseRepository {
25
- constructor(prisma, entity) {
26
- super();
27
- this.prisma = prisma;
28
- this.entity = entity;
29
- this.modelDelegate = prisma[entity];
30
- }
31
- async find(options) {
32
- try {
33
- const prismaOptions = this.convertFindOptions(options);
34
- return await this.modelDelegate.findMany(prismaOptions);
35
- }
36
- catch (error) {
37
- throw this.handleError(error);
38
- }
39
- }
40
- async findOne(id) {
41
- try {
42
- if (typeof id === 'object') {
43
- const prismaOptions = this.convertFindOneOptions(id);
44
- return await this.modelDelegate.findUnique(prismaOptions);
45
- }
46
- else {
47
- return await this.modelDelegate.findUnique({
48
- where: { id },
49
- });
50
- }
51
- }
52
- catch (error) {
53
- throw this.handleError(error);
54
- }
55
- }
56
- async create(data) {
57
- try {
58
- return await this.modelDelegate.create({
59
- data,
60
- });
61
- }
62
- catch (error) {
63
- throw this.handleError(error);
64
- }
65
- }
66
- async update(id, data) {
67
- try {
68
- return await this.modelDelegate.update({
69
- where: { id },
70
- data,
71
- });
72
- }
73
- catch (error) {
74
- throw this.handleError(error);
75
- }
76
- }
77
- async delete(id) {
78
- try {
79
- await this.modelDelegate.delete({
80
- where: { id },
81
- });
82
- }
83
- catch (error) {
84
- throw this.handleError(error);
85
- }
86
- }
87
- async count(options) {
88
- try {
89
- const prismaOptions = this.convertCountOptions(options);
90
- return await this.modelDelegate.count(prismaOptions);
91
- }
92
- catch (error) {
93
- throw this.handleError(error);
94
- }
95
- }
96
- async exists(id) {
97
- try {
98
- const result = await this.modelDelegate.findUnique({
99
- where: { id },
100
- select: { id: true },
101
- });
102
- return result !== null;
103
- }
104
- catch (error) {
105
- throw this.handleError(error);
106
- }
107
- }
108
- /**
109
- * Convert unified FindOptions to Prisma-specific options
110
- */
111
- convertFindOptions(options) {
112
- if (!options)
113
- return {};
114
- const prismaOptions = {};
115
- if (options.where) {
116
- prismaOptions.where = options.where;
117
- }
118
- if (options.orderBy) {
119
- prismaOptions.orderBy = Array.isArray(options.orderBy)
120
- ? options.orderBy
121
- : [options.orderBy];
122
- }
123
- if (options.limit) {
124
- prismaOptions.take = options.limit;
125
- }
126
- if (options.offset) {
127
- prismaOptions.skip = options.offset;
128
- }
129
- if (options.include) {
130
- prismaOptions.include = options.include;
131
- }
132
- if (options.select) {
133
- prismaOptions.select = options.select.reduce((acc, field) => {
134
- acc[field] = true;
135
- return acc;
136
- }, {});
137
- }
138
- return prismaOptions;
139
- }
140
- /**
141
- * Convert unified FindOneOptions to Prisma-specific options
142
- */
143
- convertFindOneOptions(options) {
144
- if (!options)
145
- return {};
146
- const prismaOptions = {};
147
- if (options.where) {
148
- prismaOptions.where = options.where;
149
- }
150
- if (options.include) {
151
- prismaOptions.include = options.include;
152
- }
153
- if (options.select) {
154
- prismaOptions.select = options.select.reduce((acc, field) => {
155
- acc[field] = true;
156
- return acc;
157
- }, {});
158
- }
159
- return prismaOptions;
160
- }
161
- /**
162
- * Convert unified CountOptions to Prisma-specific options
163
- */
164
- convertCountOptions(options) {
165
- if (!options)
166
- return {};
167
- const prismaOptions = {};
168
- if (options.where) {
169
- prismaOptions.where = options.where;
170
- }
171
- return prismaOptions;
172
- }
173
- /**
174
- * Handle database errors consistently
175
- */
176
- handleError(error) {
177
- if (error.code === 'P2025') {
178
- throw new database_2.NotFoundError('Record not found', this.entity, error.meta?.cause);
179
- }
180
- // Convert Prisma errors to unified database errors
181
- if (error instanceof database_2.DatabaseError) {
182
- throw error;
183
- }
184
- throw new database_2.DatabaseError(`Prisma error: ${error.message}`, error.code, { entity: this.entity, originalError: error });
185
- }
186
- };
187
- exports.PrismaBaseRepository = PrismaBaseRepository;
188
- exports.PrismaBaseRepository = PrismaBaseRepository = __decorate([
189
- (0, core_1.Injectable)(),
190
- __metadata("design:paramtypes", [prisma_service_1.PrismaService, String])
191
- ], PrismaBaseRepository);