@thisisagile/easy 8.39.2 → 8.39.3

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.
@@ -4,23 +4,20 @@ export declare type Viewer = {
4
4
  key: string;
5
5
  f?: Func;
6
6
  };
7
- out?: {
8
- key: string;
9
- f?: Func;
10
- };
11
7
  };
12
- declare type InOut = {
8
+ export declare type InOut = {
13
9
  in?: Func | View;
14
- out?: Func | View;
15
10
  col?: string;
16
11
  };
12
+ export declare const isInOut: (v: unknown) => v is InOut;
17
13
  declare type Views = {
18
14
  [key: string]: string | Func | InOut;
19
15
  };
20
16
  export declare class View {
21
17
  readonly views: Viewer[];
22
- readonly from: 'scratch' | 'source';
23
- constructor(views?: Viewer[], from?: 'scratch' | 'source');
18
+ readonly startsFrom: 'scratch' | 'source';
19
+ constructor(views?: Viewer[], startsFrom?: 'scratch' | 'source');
20
+ from: (source: unknown) => unknown;
24
21
  }
25
- export declare const view: (map: Views, from?: "scratch" | "source" | undefined) => View;
22
+ export declare const view: (views: Views, startsFrom?: "scratch" | "source" | undefined) => View;
26
23
  export {};
@@ -1,13 +1,17 @@
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.isInOut = void 0;
4
+ const types_1 = require("../types");
5
+ const isInOut = (v) => (0, types_1.isObject)(v) && ((0, types_1.isFunction)(v.in) || v.in instanceof View);
6
+ exports.isInOut = isInOut;
4
7
  class View {
5
- constructor(views = [], from = 'scratch') {
8
+ constructor(views = [], startsFrom = 'scratch') {
6
9
  this.views = views;
7
- this.from = from;
10
+ this.startsFrom = startsFrom;
11
+ this.from = (source) => (0, types_1.tryTo)((0, types_1.asJson)(source)).map(s => this.views.reduce((a, m) => ({ ...a, ...{ [m.in?.key ?? '']: m.in?.f && m.in.f(s) } }), this.startsFrom === 'scratch' ? {} : s)).value;
8
12
  }
9
13
  }
10
14
  exports.View = View;
11
- const view = (map, from) => new View([], from);
15
+ const view = (views, startsFrom) => new View([], startsFrom);
12
16
  exports.view = view;
13
17
  //# 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,oCAA+D;AAOxD,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;AAI7G,MAAa,IAAI;IACf,YAAqB,QAAkB,EAAE,EAAW,aAAmC,SAAS;QAA3E,UAAK,GAAL,KAAK,CAAe;QAAW,eAAU,GAAV,UAAU,CAAkC;QAGhG,SAAI,GAAG,CAAC,MAAe,EAAW,EAAE,CAAC,IAAA,aAAK,EAAC,IAAA,cAAM,EAAC,MAAM,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,CAAM,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,EAAE,GAAG,CAAC,EAAE,GAAG,EAAE,CAAC,CAAC,CAAC,EAAE,EAAE,GAAG,IAAI,EAAE,CAAC,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,IAAI,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,EAAE,IAAI,CAAC,UAAU,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC;IAFhN,CAAC;CAGF;AALD,oBAKC;AAEM,MAAM,IAAI,GAAG,CAAC,KAAY,EAAE,UAAiC,EAAQ,EAAE,CAAC,IAAI,IAAI,CAAC,EAAE,EAAE,UAAU,CAAC,CAAC;AAA3F,QAAA,IAAI,QAAuF"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@thisisagile/easy",
3
- "version": "8.39.2",
3
+ "version": "8.39.3",
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.3",
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,19 @@
1
+ import { asJson, isFunction, isObject, tryTo } from '../types';
2
+
1
3
  type Func<T = unknown> = (a: any) => T;
2
- export type Viewer = { in?: { key: string, f?: Func }, out?: { key: string, f?: Func } };
3
4
 
4
- type InOut = { in?: Func | View, out?: Func | View, col?: string };
5
- type Views = { [key: string]: string | Func | InOut };
5
+ export type Viewer = { in?: { key: string, f?: Func }};
6
6
 
7
+ export type InOut = { in?: Func | View, col?: string };
8
+ export const isInOut = (v: unknown): v is InOut => isObject(v) && (isFunction(v.in) || v.in instanceof View);
9
+
10
+ type Views = { [key: string]: string | Func | InOut };
7
11
 
8
12
  export class View {
9
- constructor(readonly views: Viewer[] = [], readonly from: 'scratch' | 'source' = 'scratch') {
13
+ constructor(readonly views: Viewer[] = [], readonly startsFrom: 'scratch' | 'source' = 'scratch') {
10
14
  }
15
+
16
+ from = (source: unknown): unknown => tryTo(asJson(source)).map(s => this.views.reduce((a: any, m) => ({ ...a, ...{ [m.in?.key ?? '']: m.in?.f && m.in.f(s) } }), this.startsFrom === 'scratch' ? {} : s)).value;
11
17
  }
12
18
 
13
- export const view = (map: Views, from?: 'scratch' | 'source'): View => new View([], from);
19
+ export const view = (views: Views, startsFrom?: 'scratch' | 'source'): View => new View([], startsFrom);