@thisisagile/easy 8.39.2 → 8.39.5

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,26 +1,24 @@
1
1
  declare type Func<T = unknown> = (a: any) => T;
2
+ export declare type InOut = {
3
+ in?: Func | View;
4
+ col?: string;
5
+ };
6
+ export declare const isInOut: (v: unknown) => v is InOut;
7
+ export declare type Views = {
8
+ [key: string]: string | Func | InOut;
9
+ };
2
10
  export declare type Viewer = {
3
11
  in?: {
4
12
  key: string;
5
13
  f?: Func;
6
14
  };
7
- out?: {
8
- key: string;
9
- f?: Func;
10
- };
11
- };
12
- declare type InOut = {
13
- in?: Func | View;
14
- out?: Func | View;
15
- col?: string;
16
- };
17
- declare type Views = {
18
- [key: string]: string | Func | InOut;
19
15
  };
16
+ export declare const toViewers: (views: Views) => Viewer[];
20
17
  export declare class View {
21
- readonly views: Viewer[];
22
- readonly from: 'scratch' | 'source';
23
- constructor(views?: Viewer[], from?: 'scratch' | 'source');
18
+ readonly startsFrom: 'scratch' | 'source';
19
+ readonly viewers: Viewer[];
20
+ constructor(views?: Views, startsFrom?: 'scratch' | 'source', viewers?: Viewer[]);
21
+ from: (source: unknown) => unknown;
24
22
  }
25
- export declare const view: (map: Views, from?: "scratch" | "source" | undefined) => View;
23
+ export declare const view: (views: Views, startsFrom?: "scratch" | "source" | undefined) => View;
26
24
  export {};
@@ -1,13 +1,22 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.view = exports.View = void 0;
3
+ exports.view = exports.View = exports.toViewers = exports.isInOut = void 0;
4
+ const types_1 = require("../types");
5
+ const Traverse_1 = require("./Traverse");
6
+ const isInOut = (v) => (0, types_1.isObject)(v) && ((0, types_1.isFunction)(v.in) || v.in instanceof View);
7
+ exports.isInOut = isInOut;
8
+ const toViewers = (views) => (0, types_1.meta)(views)
9
+ .entries()
10
+ .map(([key, v]) => ({ in: { key, f: a => (0, Traverse_1.traverse)(a, v) } }));
11
+ exports.toViewers = toViewers;
4
12
  class View {
5
- constructor(views = [], from = 'scratch') {
6
- this.views = views;
7
- this.from = from;
13
+ constructor(views = {}, startsFrom = 'scratch', viewers = (0, exports.toViewers)(views)) {
14
+ this.startsFrom = startsFrom;
15
+ this.viewers = viewers;
16
+ this.from = (source) => (0, types_1.tryTo)((0, types_1.asJson)(source)).map(s => this.viewers.reduce((a, m) => ({ ...a, ...{ [m.in?.key ?? '']: m.in?.f && m.in.f(s) } }), this.startsFrom === 'scratch' ? {} : s)).value;
8
17
  }
9
18
  }
10
19
  exports.View = View;
11
- const view = (map, from) => new View([], from);
20
+ const view = (views, startsFrom) => new View(views, startsFrom);
12
21
  exports.view = view;
13
22
  //# sourceMappingURL=View.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"View.js","sourceRoot":"","sources":["../../src/utils/View.ts"],"names":[],"mappings":";;;AAOA,MAAa,IAAI;IACf,YAAqB,QAAkB,EAAE,EAAW,OAA6B,SAAS;QAArE,UAAK,GAAL,KAAK,CAAe;QAAW,SAAI,GAAJ,IAAI,CAAkC;IAC1F,CAAC;CACF;AAHD,oBAGC;AAEM,MAAM,IAAI,GAAG,CAAC,GAAU,EAAE,IAA2B,EAAQ,EAAE,CAAC,IAAI,IAAI,CAAC,EAAE,EAAE,IAAI,CAAC,CAAC;AAA7E,QAAA,IAAI,QAAyE"}
1
+ {"version":3,"file":"View.js","sourceRoot":"","sources":["../../src/utils/View.ts"],"names":[],"mappings":";;;AAAA,oCAAqE;AACrE,yCAAsC;AAK/B,MAAM,OAAO,GAAG,CAAC,CAAU,EAAc,EAAE,CAAC,IAAA,gBAAQ,EAAC,CAAC,CAAC,IAAI,CAAC,IAAA,kBAAU,EAAC,CAAC,CAAC,EAAE,CAAC,IAAI,CAAC,CAAC,EAAE,YAAY,IAAI,CAAC,CAAC;AAAhG,QAAA,OAAO,WAAyF;AAKtG,MAAM,SAAS,GAAG,CAAC,KAAY,EAAY,EAAE,CAClD,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"name": "@thisisagile/easy",
3
- "version": "8.39.2",
3
+ "version": "8.39.5",
4
4
  "description": "Straightforward library for building domain-driven microservice architectures",
5
5
  "author": "Sander Hoogendoorn",
6
6
  "license": "MIT",
@@ -31,7 +31,7 @@
31
31
  "access": "public"
32
32
  },
33
33
  "devDependencies": {
34
- "@thisisagile/easy-test": "8.39.2",
34
+ "@thisisagile/easy-test": "8.39.5",
35
35
  "@types/form-urlencoded": "^4.4.0",
36
36
  "@types/jsonwebtoken": "^8.5.8",
37
37
  "@types/validator": "^13.7.1"
package/src/utils/View.ts CHANGED
@@ -1,13 +1,25 @@
1
+ import { asJson, isFunction, isObject, meta, tryTo } from '../types';
2
+ import { traverse } from './Traverse';
3
+
1
4
  type Func<T = unknown> = (a: any) => T;
2
- export type Viewer = { in?: { key: string, f?: Func }, out?: { key: string, f?: Func } };
3
5
 
4
- type InOut = { in?: Func | View, out?: Func | View, col?: string };
5
- type Views = { [key: string]: string | Func | InOut };
6
+ export type InOut = { in?: Func | View, col?: string };
7
+ export const isInOut = (v: unknown): v is InOut => isObject(v) && (isFunction(v.in) || v.in instanceof View);
8
+
9
+ export type Views = { [key: string]: string | Func | InOut };
10
+ export type Viewer = { in?: { key: string, f?: Func }};
6
11
 
12
+ export const toViewers = (views: Views): Viewer[] =>
13
+ meta(views)
14
+ .entries()
15
+ .map(([key, v]) => ({in: {key, f: a => traverse(a, v as string)}}));
7
16
 
8
17
  export class View {
9
- constructor(readonly views: Viewer[] = [], readonly from: 'scratch' | 'source' = 'scratch') {
18
+ constructor(views: Views = {}, readonly startsFrom: 'scratch' | 'source' = 'scratch', readonly viewers: Viewer[] = toViewers(views)) {
10
19
  }
20
+
21
+ from = (source: unknown): unknown => tryTo(asJson(source)).map(s => this.viewers.reduce((a: any, m) => ({ ...a, ...{ [m.in?.key ?? '']: m.in?.f && m.in.f(s) } }), this.startsFrom === 'scratch' ? {} : s)).value;
11
22
  }
12
23
 
13
- export const view = (map: Views, from?: 'scratch' | 'source'): View => new View([], from);
24
+
25
+ export const view = (views: Views, startsFrom?: 'scratch' | 'source'): View => new View(views, startsFrom);