@turystack/entity 0.0.1 → 0.0.4

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.
@@ -1,2 +1,2 @@
1
- export { Entity } from './entity.js';
1
+ export * from './entity.js';
2
2
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/entity/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/entity/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAA"}
@@ -1,2 +1,2 @@
1
- export { Entity } from './entity.js';
1
+ export * from './entity.js';
2
2
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/entity/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAA"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/entity/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAA"}
@@ -0,0 +1,3 @@
1
+ import type { ExceptionBuilder } from './exceptions.types.js';
2
+ export declare function createExceptions<T>(factory: (e: ExceptionBuilder) => T): T;
3
+ //# sourceMappingURL=exceptions.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"exceptions.d.ts","sourceRoot":"","sources":["../../src/exceptions/exceptions.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAmB,MAAM,uBAAuB,CAAA;AAsB9E,wBAAgB,gBAAgB,CAAC,CAAC,EAAE,OAAO,EAAE,CAAC,CAAC,EAAE,gBAAgB,KAAK,CAAC,GAAG,CAAC,CAmB1E"}
@@ -0,0 +1,15 @@
1
+ export function createExceptions(factory) {
2
+ const builder = {
3
+ module: (prefix, codes) => {
4
+ const result = {
5
+ not_found: `${prefix}.not_found`,
6
+ };
7
+ for (const code of codes) {
8
+ result[code] = `${prefix}.${code}`;
9
+ }
10
+ return result;
11
+ },
12
+ };
13
+ return factory(builder);
14
+ }
15
+ //# sourceMappingURL=exceptions.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"exceptions.js","sourceRoot":"","sources":["../../src/exceptions/exceptions.ts"],"names":[],"mappings":"AAsBA,MAAM,UAAU,gBAAgB,CAAI,OAAmC;IACtE,MAAM,OAAO,GAAqB;QACjC,MAAM,EAAE,CACP,MAAS,EACT,KAAQ,EACgB,EAAE;YAC1B,MAAM,MAAM,GAAG;gBACd,SAAS,EAAE,GAAG,MAAM,YAAY;aACN,CAAA;YAE3B,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;gBAC1B,MAAM,CAAC,IAAI,CAAC,GAAG,GAAG,MAAM,IAAI,IAAI,EAAE,CAAA;YACnC,CAAC;YAED,OAAO,MAA+B,CAAA;QACvC,CAAC;KACD,CAAA;IAED,OAAO,OAAO,CAAC,OAAO,CAAC,CAAA;AACxB,CAAC"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=exceptions.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"exceptions.test.d.ts","sourceRoot":"","sources":["../../src/exceptions/exceptions.test.ts"],"names":[],"mappings":""}
@@ -0,0 +1,59 @@
1
+ import { describe, expect, it } from 'vitest';
2
+ import { createExceptions } from './exceptions.js';
3
+ describe('createExceptions', () => {
4
+ it('should create exceptions with not_found default', () => {
5
+ const exceptions = createExceptions((e) => ({
6
+ user: e.module('user', []),
7
+ }));
8
+ expect(exceptions.user.not_found).toBe('user.not_found');
9
+ });
10
+ it('should prefix custom codes with module name', () => {
11
+ const exceptions = createExceptions((e) => ({
12
+ billing: e.module('billing_threshold', [
13
+ 'cannot_deactivate',
14
+ 'currency_not_compatible',
15
+ ]),
16
+ }));
17
+ expect(exceptions.billing.not_found).toBe('billing_threshold.not_found');
18
+ expect(exceptions.billing.cannot_deactivate).toBe('billing_threshold.cannot_deactivate');
19
+ expect(exceptions.billing.currency_not_compatible).toBe('billing_threshold.currency_not_compatible');
20
+ });
21
+ it('should support multiple modules', () => {
22
+ const exceptions = createExceptions((e) => ({
23
+ coupon: e.module('coupon', [
24
+ 'code_already_exists',
25
+ 'not_available',
26
+ ]),
27
+ invoice: e.module('invoice', [
28
+ 'not_expired',
29
+ 'not_payable',
30
+ ]),
31
+ }));
32
+ expect(exceptions.coupon.not_found).toBe('coupon.not_found');
33
+ expect(exceptions.coupon.code_already_exists).toBe('coupon.code_already_exists');
34
+ expect(exceptions.invoice.not_found).toBe('invoice.not_found');
35
+ expect(exceptions.invoice.not_payable).toBe('invoice.not_payable');
36
+ });
37
+ it('should match billing-service pattern', () => {
38
+ const exceptions = createExceptions((e) => ({
39
+ billingThreshold: e.module('billing_threshold', [
40
+ 'cannot_deactivate',
41
+ 'cannot_reactivate',
42
+ 'currency_not_compatible',
43
+ 'not_available',
44
+ ]),
45
+ customer: e.module('customer', [
46
+ 'no_active_subscription',
47
+ 'no_had_subscription',
48
+ 'organization_id_already_exists',
49
+ ]),
50
+ voucher: e.module('voucher', []),
51
+ }));
52
+ expect(exceptions.billingThreshold.not_found).toBe('billing_threshold.not_found');
53
+ expect(exceptions.billingThreshold.cannot_deactivate).toBe('billing_threshold.cannot_deactivate');
54
+ expect(exceptions.customer.not_found).toBe('customer.not_found');
55
+ expect(exceptions.customer.organization_id_already_exists).toBe('customer.organization_id_already_exists');
56
+ expect(exceptions.voucher.not_found).toBe('voucher.not_found');
57
+ });
58
+ });
59
+ //# sourceMappingURL=exceptions.test.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"exceptions.test.js","sourceRoot":"","sources":["../../src/exceptions/exceptions.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,QAAQ,CAAA;AAE7C,OAAO,EAAE,gBAAgB,EAAE,MAAM,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AC,CAAC,IAAI,CAC9D,yCAAyC,CACzC,CAAA;QACD,MAAM,CAAC,UAAU,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC,IAAI,CAAC,mBAAmB,CAAC,CAAA;IAC/D,CAAC,CAAC,CAAA;AACH,CAAC,CAAC,CAAA"}
@@ -0,0 +1,9 @@
1
+ export type ExceptionModule<P extends string, T extends readonly string[]> = {
2
+ not_found: `${P}.not_found`;
3
+ } & {
4
+ [K in T[number]]: `${P}.${K}`;
5
+ };
6
+ export type ExceptionBuilder = {
7
+ module: <const P extends string, const T extends readonly string[]>(prefix: P, codes: T) => ExceptionModule<P, T>;
8
+ };
9
+ //# sourceMappingURL=exceptions.types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"exceptions.types.d.ts","sourceRoot":"","sources":["../../src/exceptions/exceptions.types.ts"],"names":[],"mappings":"AAKA,MAAM,MAAM,eAAe,CAAC,CAAC,SAAS,MAAM,EAAE,CAAC,SAAS,SAAS,MAAM,EAAE,IAAI;IAC5E,SAAS,EAAE,GAAG,CAAC,YAAY,CAAA;CAC3B,GAAG;KAAG,CAAC,IAAI,CAAC,CAAC,MAAM,CAAC,GAAG,GAAG,CAAC,IAAI,CAAC,EAAE;CAAE,CAAA;AAGrC,MAAM,MAAM,gBAAgB,GAAG;IAO9B,MAAM,EAAE,CAAC,KAAK,CAAC,CAAC,SAAS,MAAM,EAAE,KAAK,CAAC,CAAC,SAAS,SAAS,MAAM,EAAE,EACjE,MAAM,EAAE,CAAC,EACT,KAAK,EAAE,CAAC,KACJ,eAAe,CAAC,CAAC,EAAE,CAAC,CAAC,CAAA;CAC1B,CAAA"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=exceptions.types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"exceptions.types.js","sourceRoot":"","sources":["../../src/exceptions/exceptions.types.ts"],"names":[],"mappings":""}
@@ -0,0 +1,2 @@
1
+ export * from './exceptions.js';
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/exceptions/index.ts"],"names":[],"mappings":"AAAA,cAAc,iBAAiB,CAAA"}
@@ -0,0 +1,2 @@
1
+ export * from './exceptions.js';
2
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/exceptions/index.ts"],"names":[],"mappings":"AAAA,cAAc,iBAAiB,CAAA"}
package/dist/index.d.ts CHANGED
@@ -1,2 +1,3 @@
1
1
  export * from './entity/index.js';
2
+ export * from './exceptions/exceptions.test.js';
2
3
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,mBAAmB,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,mBAAmB,CAAA;AACjC,cAAc,iCAAiC,CAAA"}
package/dist/index.js CHANGED
@@ -1,2 +1,3 @@
1
1
  export * from './entity/index.js';
2
+ export * from './exceptions/exceptions.test.js';
2
3
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,mBAAmB,CAAA"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,mBAAmB,CAAA;AACjC,cAAc,iCAAiC,CAAA"}
package/package.json CHANGED
@@ -1,46 +1,46 @@
1
1
  {
2
- "name": "@turystack/entity",
3
- "private": false,
4
- "version": "0.0.1",
5
- "type": "module",
6
- "main": "./dist/index.js",
7
- "module": "./dist/index.js",
8
- "types": "./dist/index.d.ts",
9
- "exports": {
10
- ".": {
11
- "types": "./dist/index.d.ts",
12
- "import": "./dist/index.js",
13
- "default": "./dist/index.js"
14
- }
15
- },
16
- "publishConfig": {
17
- "access": "public"
18
- },
19
- "files": [
20
- "dist"
21
- ],
22
- "scripts": {
23
- "build": "tsc -p tsconfig.build.json && tsc-alias -p tsconfig.build.json",
24
- "test": "vitest run",
25
- "test:cov": "vitest run --coverage",
26
- "lint": "biome lint ./src",
27
- "format": "biome format --write ./src",
28
- "check": "biome check --write ./src"
29
- },
30
- "repository": {
31
- "type": "git",
32
- "url": "https://github.com/turystack/entity.git"
33
- },
34
- "peerDependencies": {
35
- "superjson": "^2.0.0"
36
- },
37
- "devDependencies": {
38
- "@biomejs/biome": "2.2.2",
39
- "@vitest/coverage-v8": "^2.1.0",
40
- "reflect-metadata": "^0.2.2",
41
- "superjson": "^2.0.0",
42
- "tsc-alias": "^1.8.16",
43
- "typescript": "^5.5.0",
44
- "vitest": "^2.1.0"
45
- }
46
- }
2
+ "name": "@turystack/entity",
3
+ "private": false,
4
+ "version": "0.0.4",
5
+ "type": "module",
6
+ "main": "./dist/index.js",
7
+ "module": "./dist/index.js",
8
+ "types": "./dist/index.d.ts",
9
+ "exports": {
10
+ ".": {
11
+ "types": "./dist/index.d.ts",
12
+ "import": "./dist/index.js",
13
+ "default": "./dist/index.js"
14
+ }
15
+ },
16
+ "publishConfig": {
17
+ "access": "public"
18
+ },
19
+ "files": [
20
+ "dist"
21
+ ],
22
+ "repository": {
23
+ "type": "git",
24
+ "url": "https://github.com/turystack/entity.git"
25
+ },
26
+ "peerDependencies": {
27
+ "superjson": "^2.0.0"
28
+ },
29
+ "devDependencies": {
30
+ "@biomejs/biome": "2.2.2",
31
+ "@vitest/coverage-v8": "^2.1.0",
32
+ "reflect-metadata": "^0.2.2",
33
+ "superjson": "^2.0.0",
34
+ "tsc-alias": "^1.8.16",
35
+ "typescript": "^5.5.0",
36
+ "vitest": "^2.1.0"
37
+ },
38
+ "scripts": {
39
+ "build": "tsc -p tsconfig.build.json && tsc-alias -p tsconfig.build.json",
40
+ "test": "vitest run",
41
+ "test:cov": "vitest run --coverage",
42
+ "lint": "biome lint ./src",
43
+ "format": "biome format --write ./src",
44
+ "check": "biome check --write ./src"
45
+ }
46
+ }