@hazeljs/prisma 0.2.0-rc.8 → 0.2.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.
package/README.md
CHANGED
|
@@ -450,9 +450,9 @@ npx prisma studio
|
|
|
450
450
|
## Links
|
|
451
451
|
|
|
452
452
|
- [TypeORM docs](https://www.prisma.io/docs)
|
|
453
|
-
- [HazelJS](https://hazeljs.
|
|
453
|
+
- [HazelJS](https://hazeljs.ai)
|
|
454
454
|
- [GitHub](https://github.com/hazel-js/hazeljs)
|
|
455
455
|
|
|
456
456
|
## License
|
|
457
457
|
|
|
458
|
-
Apache 2.0 © [HazelJS](https://hazeljs.
|
|
458
|
+
Apache 2.0 © [HazelJS](https://hazeljs.ai)
|
package/dist/prisma.test.js
CHANGED
|
@@ -6,6 +6,12 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
|
6
6
|
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;
|
|
7
7
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
8
8
|
};
|
|
9
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
10
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
11
|
+
};
|
|
12
|
+
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
13
|
+
return function (target, key) { decorator(target, key, paramIndex); }
|
|
14
|
+
};
|
|
9
15
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
10
16
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
11
17
|
};
|
|
@@ -21,6 +27,7 @@ jest.mock('@hazeljs/core', () => ({
|
|
|
21
27
|
default: { info: jest.fn(), debug: jest.fn(), warn: jest.fn(), error: jest.fn() },
|
|
22
28
|
}));
|
|
23
29
|
const core_1 = __importDefault(require("@hazeljs/core"));
|
|
30
|
+
const prisma_module_1 = require("./prisma.module");
|
|
24
31
|
const prisma_service_1 = require("./prisma.service");
|
|
25
32
|
const base_repository_1 = require("./base.repository");
|
|
26
33
|
const repository_decorator_1 = require("./repository.decorator");
|
|
@@ -268,4 +275,57 @@ describe('@Repository decorator', () => {
|
|
|
268
275
|
const injectable = Reflect.getMetadata('hazel:injectable', LogRepo);
|
|
269
276
|
expect(injectable).toEqual({ scope: 'TRANSIENT' });
|
|
270
277
|
});
|
|
278
|
+
it('sets hazel:repository:model for InjectRepository', () => {
|
|
279
|
+
let ProfileRepo = class ProfileRepo {
|
|
280
|
+
};
|
|
281
|
+
ProfileRepo = __decorate([
|
|
282
|
+
(0, repository_decorator_1.Repository)('profile')
|
|
283
|
+
], ProfileRepo);
|
|
284
|
+
const model = Reflect.getMetadata('hazel:repository:model', ProfileRepo);
|
|
285
|
+
expect(model).toBe('profile');
|
|
286
|
+
});
|
|
287
|
+
});
|
|
288
|
+
describe('PrismaModule', () => {
|
|
289
|
+
it('exports PrismaModule class with providers and exports', () => {
|
|
290
|
+
expect(prisma_module_1.PrismaModule).toBeDefined();
|
|
291
|
+
const _meta = Reflect.getMetadata('hazel:module', prisma_module_1.PrismaModule) ?? prisma_module_1.PrismaModule.module;
|
|
292
|
+
expect(prisma_module_1.PrismaModule).toHaveProperty('name', 'PrismaModule');
|
|
293
|
+
});
|
|
294
|
+
});
|
|
295
|
+
describe('InjectRepository', () => {
|
|
296
|
+
it('throws when used on constructor parameter (propertyKey undefined)', () => {
|
|
297
|
+
const decorator = (0, repository_decorator_1.InjectRepository)();
|
|
298
|
+
expect(() => decorator(class C {
|
|
299
|
+
}, undefined, 0)).toThrow('InjectRepository decorator must be used on a method parameter');
|
|
300
|
+
});
|
|
301
|
+
it('pushes repository metadata when used on method parameter', () => {
|
|
302
|
+
let ProductRepo = class ProductRepo {
|
|
303
|
+
};
|
|
304
|
+
ProductRepo = __decorate([
|
|
305
|
+
(0, repository_decorator_1.Repository)('product')
|
|
306
|
+
], ProductRepo);
|
|
307
|
+
class Consumer {
|
|
308
|
+
doSomething(_repo) { }
|
|
309
|
+
}
|
|
310
|
+
__decorate([
|
|
311
|
+
__param(0, (0, repository_decorator_1.InjectRepository)()),
|
|
312
|
+
__metadata("design:type", Function),
|
|
313
|
+
__metadata("design:paramtypes", [ProductRepo]),
|
|
314
|
+
__metadata("design:returntype", void 0)
|
|
315
|
+
], Consumer.prototype, "doSomething", null);
|
|
316
|
+
const repos = Reflect.getMetadata('hazel:repositories', Consumer.prototype);
|
|
317
|
+
expect(repos).toBeDefined();
|
|
318
|
+
expect(repos).toHaveLength(1);
|
|
319
|
+
expect(repos[0]).toEqual({ index: 0, model: 'product' });
|
|
320
|
+
});
|
|
321
|
+
it('throws when repository type is not decorated with @Repository', () => {
|
|
322
|
+
class UndecoratedRepo {
|
|
323
|
+
}
|
|
324
|
+
const proto = class {
|
|
325
|
+
method(_r) { }
|
|
326
|
+
}.prototype;
|
|
327
|
+
Reflect.defineMetadata('design:paramtypes', [UndecoratedRepo], proto, 'method');
|
|
328
|
+
const decorator = (0, repository_decorator_1.InjectRepository)();
|
|
329
|
+
expect(() => decorator(proto, 'method', 0)).toThrow(/not decorated with @Repository/);
|
|
330
|
+
});
|
|
271
331
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"repository.decorator.d.ts","sourceRoot":"","sources":["../src/repository.decorator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC;AAClD,OAAO,kBAAkB,CAAC;AAE1B,wBAAgB,UAAU,CAAC,OAAO,EAAE,iBAAiB,GAAG,MAAM,GAAG,cAAc,
|
|
1
|
+
{"version":3,"file":"repository.decorator.d.ts","sourceRoot":"","sources":["../src/repository.decorator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC;AAClD,OAAO,kBAAkB,CAAC;AAE1B,wBAAgB,UAAU,CAAC,OAAO,EAAE,iBAAiB,GAAG,MAAM,GAAG,cAAc,CAY9E;AAED,wBAAgB,gBAAgB,IAAI,kBAAkB,CA0BrD"}
|
|
@@ -7,6 +7,7 @@ function Repository(options) {
|
|
|
7
7
|
return function (target) {
|
|
8
8
|
const opts = typeof options === 'string' ? { model: options } : options;
|
|
9
9
|
Reflect.defineMetadata('hazel:repository', opts, target);
|
|
10
|
+
Reflect.defineMetadata('hazel:repository:model', opts.model, target);
|
|
10
11
|
// Implicitly mark the class as injectable — @Injectable() is not needed separately.
|
|
11
12
|
// Write metadata directly to avoid the ClassDecorator `Function` type constraint.
|
|
12
13
|
Reflect.defineMetadata('hazel:injectable', opts.scope ? { scope: opts.scope } : {}, target);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hazeljs/prisma",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.1",
|
|
4
4
|
"description": "Prisma ORM integration for HazelJS framework",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -46,9 +46,9 @@
|
|
|
46
46
|
"bugs": {
|
|
47
47
|
"url": "https://github.com/hazeljs/hazel-js/issues"
|
|
48
48
|
},
|
|
49
|
-
"homepage": "https://hazeljs.
|
|
49
|
+
"homepage": "https://hazeljs.ai",
|
|
50
50
|
"peerDependencies": {
|
|
51
51
|
"@hazeljs/core": ">=0.2.0-beta.0"
|
|
52
52
|
},
|
|
53
|
-
"gitHead": "
|
|
53
|
+
"gitHead": "736a56e3d70b51050608cffae2394de3a3487f20"
|
|
54
54
|
}
|