@koala-ts/framework 2.12.0 → 2.13.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,3 @@
1
+ import { Violation } from '../validator/types.js';
2
+ export declare function flattenViolations(violations: Violation[]): Record<string, string[]>;
3
+ //# sourceMappingURL=flatten-violations.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"flatten-violations.d.ts","sourceRoot":"","sources":["../../src/validator/flatten-violations.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAE9C,wBAAgB,iBAAiB,CAAC,UAAU,EAAE,SAAS,EAAE,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,CAAC,CAQnF"}
@@ -0,0 +1,6 @@
1
+ export function flattenViolations(violations) {
2
+ const groupedViolations = Object.groupBy(violations, violation => violation.path);
3
+ const violationEntries = Object.entries(groupedViolations).map(([field, violations]) => [field, violations.map(v => v.message)]);
4
+ return Object.fromEntries(violationEntries);
5
+ }
6
+ //# sourceMappingURL=flatten-violations.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"flatten-violations.js","sourceRoot":"","sources":["../../src/validator/flatten-violations.ts"],"names":[],"mappings":"AAEA,MAAM,UAAU,iBAAiB,CAAC,UAAuB;IACvD,MAAM,iBAAiB,GAAG,MAAM,CAAC,OAAO,CAAC,UAAU,EAAE,SAAS,CAAC,EAAE,CAAC,SAAS,CAAC,IAAI,CAAgC,CAAC;IAEjH,MAAM,gBAAgB,GAA+C,MAAM,CAAC,OAAO,CAAC,iBAAiB,CAAC,CAAC,GAAG,CACxG,CAAC,CAAC,KAAK,EAAE,UAAU,CAAC,EAAE,EAAE,CAAC,CAAC,KAAK,EAAE,UAAU,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CACjE,CAAC;IAEF,OAAO,MAAM,CAAC,WAAW,CAAC,gBAAgB,CAAC,CAAC;AAC9C,CAAC"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=flatten-violations.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"flatten-violations.test.d.ts","sourceRoot":"","sources":["../../src/validator/flatten-violations.test.ts"],"names":[],"mappings":""}
@@ -0,0 +1,25 @@
1
+ import { flattenViolations } from '../validator/flatten-violations.js';
2
+ import { describe, expect, test } from 'vitest';
3
+ describe('Flatten violations', () => {
4
+ test('it should flatten violations into JSON API format', () => {
5
+ const violations = [
6
+ {
7
+ path: 'username',
8
+ message: 'The username is required.',
9
+ constraint: 'notBlank',
10
+ value: undefined,
11
+ },
12
+ {
13
+ path: 'username',
14
+ message: 'The username must be unique.',
15
+ constraint: 'uniqueUsername',
16
+ value: 'existing_user',
17
+ },
18
+ ];
19
+ const actual = flattenViolations(violations);
20
+ expect(actual).toEqual({
21
+ username: ['The username is required.', 'The username must be unique.'],
22
+ });
23
+ });
24
+ });
25
+ //# sourceMappingURL=flatten-violations.test.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"flatten-violations.test.js","sourceRoot":"","sources":["../../src/validator/flatten-violations.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,gCAAgC,CAAC;AAEnE,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAC;AAEhD,QAAQ,CAAC,oBAAoB,EAAE,GAAG,EAAE;IAClC,IAAI,CAAC,mDAAmD,EAAE,GAAG,EAAE;QAC7D,MAAM,UAAU,GAAgB;YAC9B;gBACE,IAAI,EAAE,UAAU;gBAChB,OAAO,EAAE,2BAA2B;gBACpC,UAAU,EAAE,UAAU;gBACtB,KAAK,EAAE,SAAS;aACjB;YACD;gBACE,IAAI,EAAE,UAAU;gBAChB,OAAO,EAAE,8BAA8B;gBACvC,UAAU,EAAE,gBAAgB;gBAC5B,KAAK,EAAE,eAAe;aACvB;SACF,CAAC;QAEF,MAAM,MAAM,GAAG,iBAAiB,CAAC,UAAU,CAAC,CAAC;QAE7C,MAAM,CAAC,MAAM,CAAC,CAAC,OAAO,CAAC;YACrB,QAAQ,EAAE,CAAC,2BAA2B,EAAE,8BAA8B,CAAC;SACxE,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
@@ -1,4 +1,5 @@
1
1
  export * from './validator.js';
2
2
  export * from './types.js';
3
3
  export * from './constraints/index.js';
4
+ export * from './flatten-violations.js';
4
5
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/validator/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAC;AAC5B,cAAc,SAAS,CAAC;AACxB,cAAc,eAAe,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/validator/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAC;AAC5B,cAAc,SAAS,CAAC;AACxB,cAAc,eAAe,CAAC;AAC9B,cAAc,sBAAsB,CAAC"}
@@ -1,4 +1,5 @@
1
1
  export * from './validator.js';
2
2
  export * from './types.js';
3
3
  export * from './constraints/index.js';
4
+ export * from './flatten-violations.js';
4
5
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/validator/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAC;AAC5B,cAAc,SAAS,CAAC;AACxB,cAAc,eAAe,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/validator/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAC;AAC5B,cAAc,SAAS,CAAC;AACxB,cAAc,eAAe,CAAC;AAC9B,cAAc,sBAAsB,CAAC"}
package/package.json CHANGED
@@ -18,7 +18,7 @@
18
18
  ]
19
19
  }
20
20
  },
21
- "version": "2.12.0",
21
+ "version": "2.13.0",
22
22
  "description": "A NodeJS framework for lazy developers",
23
23
  "keywords": [
24
24
  "koala",