@thisisagile/easy 8.38.1 → 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.
@@ -1 +1 @@
1
- export declare const traverse: (subject: unknown, property: string) => unknown;
1
+ export declare const traverse: (subject?: unknown, property?: string) => unknown;
@@ -1,12 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.traverse = void 0;
4
- const traverse = (subject = {}, property) => {
4
+ const traverse = (subject = {}, property = '') => {
5
5
  const [p, ...props] = property.split('.');
6
- if (props.length === 0) {
7
- return subject[p ?? ''];
8
- }
9
- return (0, exports.traverse)(subject[p], props.join('.'));
6
+ return (props.length === 0) ? subject[p] : (0, exports.traverse)(subject[p], props.join('.'));
10
7
  };
11
8
  exports.traverse = traverse;
12
9
  //# sourceMappingURL=Traverse.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"Traverse.js","sourceRoot":"","sources":["../../src/utils/Traverse.ts"],"names":[],"mappings":";;;AAAO,MAAM,QAAQ,GAAG,CAAC,UAAmB,EAAE,EAAE,QAAgB,EAAW,EAAE;IAC3E,MAAM,CAAC,CAAC,EAAE,GAAG,KAAK,CAAC,GAAG,QAAQ,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;IAC1C,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC,EAAE;QACtB,OAAQ,OAAe,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC;KAClC;IACD,OAAO,IAAA,gBAAQ,EAAE,OAAe,CAAC,CAAC,CAAC,EAAE,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC;AACxD,CAAC,CAAC;AANW,QAAA,QAAQ,YAMnB"}
1
+ {"version":3,"file":"Traverse.js","sourceRoot":"","sources":["../../src/utils/Traverse.ts"],"names":[],"mappings":";;;AAAO,MAAM,QAAQ,GAAG,CAAC,UAAmB,EAAE,EAAE,QAAQ,GAAG,EAAE,EAAW,EAAE;IACxE,MAAM,CAAC,CAAC,EAAE,GAAG,KAAK,CAAC,GAAG,QAAQ,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;IAC1C,OAAO,CAAC,KAAK,CAAC,MAAM,KAAK,CAAC,CAAC,CAAC,CAAC,CAAE,OAAe,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,IAAA,gBAAQ,EAAE,OAAe,CAAC,CAAC,CAAC,EAAE,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC;AACrG,CAAC,CAAC;AAHW,QAAA,QAAQ,YAGnB"}
@@ -0,0 +1,23 @@
1
+ declare type Func<T = unknown> = (a: any) => T;
2
+ export declare type Viewer = {
3
+ in?: {
4
+ key: string;
5
+ f?: Func;
6
+ };
7
+ };
8
+ export declare type InOut = {
9
+ in?: Func | View;
10
+ col?: string;
11
+ };
12
+ export declare const isInOut: (v: unknown) => v is InOut;
13
+ declare type Views = {
14
+ [key: string]: string | Func | InOut;
15
+ };
16
+ export declare class View {
17
+ readonly views: Viewer[];
18
+ readonly startsFrom: 'scratch' | 'source';
19
+ constructor(views?: Viewer[], startsFrom?: 'scratch' | 'source');
20
+ from: (source: unknown) => unknown;
21
+ }
22
+ export declare const view: (views: Views, startsFrom?: "scratch" | "source" | undefined) => View;
23
+ export {};
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
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;
7
+ class View {
8
+ constructor(views = [], startsFrom = 'scratch') {
9
+ this.views = views;
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;
12
+ }
13
+ }
14
+ exports.View = View;
15
+ const view = (views, startsFrom) => new View([], startsFrom);
16
+ exports.view = view;
17
+ //# sourceMappingURL=View.js.map
@@ -0,0 +1 @@
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"}
@@ -8,3 +8,4 @@ export * from './Property';
8
8
  export * from './State';
9
9
  export * from './Sentence';
10
10
  export * from './Traverse';
11
+ export * from './View';
@@ -20,4 +20,5 @@ __exportStar(require("./Property"), exports);
20
20
  __exportStar(require("./State"), exports);
21
21
  __exportStar(require("./Sentence"), exports);
22
22
  __exportStar(require("./Traverse"), exports);
23
+ __exportStar(require("./View"), exports);
23
24
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,yCAAuB;AACvB,4CAA0B;AAC1B,uCAAqB;AACrB,wCAAsB;AACtB,2CAAyB;AACzB,4CAA0B;AAC1B,6CAA2B;AAC3B,0CAAwB;AACxB,6CAA2B;AAC3B,6CAA2B"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,yCAAuB;AACvB,4CAA0B;AAC1B,uCAAqB;AACrB,wCAAsB;AACtB,2CAAyB;AACzB,4CAA0B;AAC1B,6CAA2B;AAC3B,0CAAwB;AACxB,6CAA2B;AAC3B,6CAA2B;AAC3B,yCAAuB"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@thisisagile/easy",
3
- "version": "8.38.1",
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.38.1",
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"
@@ -1,7 +1,4 @@
1
- export const traverse = (subject: unknown = {}, property: string): unknown => {
1
+ export const traverse = (subject: unknown = {}, property = ''): unknown => {
2
2
  const [p, ...props] = property.split('.');
3
- if (props.length === 0) {
4
- return (subject as any)[p ?? ''];
5
- }
6
- return traverse((subject as any)[p], props.join('.'));
3
+ return (props.length === 0) ? (subject as any)[p] : traverse((subject as any)[p], props.join('.'));
7
4
  };
@@ -0,0 +1,19 @@
1
+ import { asJson, isFunction, isObject, tryTo } from '../types';
2
+
3
+ type Func<T = unknown> = (a: any) => T;
4
+
5
+ export type Viewer = { in?: { key: string, f?: Func }};
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 };
11
+
12
+ export class View {
13
+ constructor(readonly views: Viewer[] = [], readonly startsFrom: 'scratch' | 'source' = 'scratch') {
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;
17
+ }
18
+
19
+ export const view = (views: Views, startsFrom?: 'scratch' | 'source'): View => new View([], startsFrom);
@@ -8,3 +8,4 @@ export * from './Property';
8
8
  export * from './State';
9
9
  export * from './Sentence';
10
10
  export * from './Traverse';
11
+ export * from './View';