@alterior/common 3.13.3 → 3.13.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.
- package/dist/base64.d.ts +6 -6
- package/dist/base64.js +52 -52
- package/dist/base64.js.map +1 -1
- package/dist/base64.test.d.ts +1 -1
- package/dist/cache.d.ts +84 -84
- package/dist/cache.js +148 -148
- package/dist/cache.js.map +1 -1
- package/dist/cache.test.d.ts +1 -1
- package/dist/check-native-async.d.ts +1 -1
- package/dist/check-native-async.js +27 -28
- package/dist/check-native-async.js.map +1 -1
- package/dist/clone.d.ts +23 -23
- package/dist/clone.js +59 -60
- package/dist/clone.js.map +1 -1
- package/dist/clone.test.d.ts +1 -1
- package/dist/coalesce.d.ts +5 -5
- package/dist/coalesce.js +15 -16
- package/dist/coalesce.js.map +1 -1
- package/dist/coalesce.test.d.ts +1 -1
- package/dist/colors.d.ts +62 -62
- package/dist/colors.js +66 -66
- package/dist/console.d.ts +31 -31
- package/dist/console.d.ts.map +1 -1
- package/dist/console.js +65 -86
- package/dist/console.js.map +1 -1
- package/dist/constructor.d.ts +6 -6
- package/dist/constructor.js +2 -2
- package/dist/decorators.d.ts +1 -1
- package/dist/decorators.d.ts.map +1 -1
- package/dist/decorators.js +6 -7
- package/dist/decorators.js.map +1 -1
- package/dist/environment.d.ts +11 -11
- package/dist/environment.d.ts.map +1 -1
- package/dist/environment.js +27 -27
- package/dist/environment.js.map +1 -1
- package/dist/errors.d.ts +66 -66
- package/dist/errors.js +133 -133
- package/dist/errors.test.d.ts +1 -1
- package/dist/get-param-names.d.ts +5 -5
- package/dist/get-param-names.js +48 -49
- package/dist/get-param-names.js.map +1 -1
- package/dist/index.d.ts +20 -20
- package/dist/index.js +23 -23
- package/dist/is-constructor.d.ts +12 -12
- package/dist/is-constructor.js +28 -29
- package/dist/is-constructor.js.map +1 -1
- package/dist/is-constructor.test.d.ts +1 -1
- package/dist/lazy-promise.d.ts +14 -14
- package/dist/lazy-promise.js +32 -32
- package/dist/lazy-promise.js.map +1 -1
- package/dist/lazy-subject.d.ts +22 -22
- package/dist/lazy-subject.js +22 -23
- package/dist/lazy-subject.js.map +1 -1
- package/dist/locks.d.ts +23 -23
- package/dist/locks.js +76 -76
- package/dist/locks.js.map +1 -1
- package/dist/locks.test.d.ts +1 -1
- package/dist/locks.test.js.map +1 -1
- package/dist/padding.d.ts +22 -22
- package/dist/padding.js +42 -43
- package/dist/padding.js.map +1 -1
- package/dist/presentation.d.ts +49 -49
- package/dist/presentation.d.ts.map +1 -1
- package/dist/presentation.js +132 -132
- package/dist/presentation.js.map +1 -1
- package/dist/presentation.test.d.ts +1 -1
- package/dist/presentation.test.js.map +1 -1
- package/dist/serializer.d.ts +8 -8
- package/dist/serializer.js +23 -24
- package/dist/serializer.js.map +1 -1
- package/dist/test.d.ts +2 -2
- package/dist/time.d.ts +9 -9
- package/dist/time.js +22 -22
- package/dist/time.js.map +1 -1
- package/dist/timeout.d.ts +13 -13
- package/dist/timeout.js +27 -28
- package/dist/timeout.js.map +1 -1
- package/dist/zones.d.ts +46 -46
- package/dist/zones.js +139 -139
- package/dist/zones.js.map +1 -1
- package/dist.esm/base64.d.ts +6 -6
- package/dist.esm/base64.js +48 -48
- package/dist.esm/base64.js.map +1 -1
- package/dist.esm/base64.test.d.ts +1 -1
- package/dist.esm/cache.d.ts +84 -84
- package/dist.esm/cache.js +144 -144
- package/dist.esm/cache.js.map +1 -1
- package/dist.esm/cache.test.d.ts +1 -1
- package/dist.esm/check-native-async.d.ts +1 -1
- package/dist.esm/check-native-async.js +24 -24
- package/dist.esm/check-native-async.js.map +1 -1
- package/dist.esm/clone.d.ts +23 -23
- package/dist.esm/clone.js +53 -53
- package/dist.esm/clone.js.map +1 -1
- package/dist.esm/clone.test.d.ts +1 -1
- package/dist.esm/coalesce.d.ts +5 -5
- package/dist.esm/coalesce.js +12 -12
- package/dist.esm/coalesce.js.map +1 -1
- package/dist.esm/coalesce.test.d.ts +1 -1
- package/dist.esm/colors.d.ts +62 -62
- package/dist.esm/colors.js +63 -63
- package/dist.esm/console.d.ts +31 -31
- package/dist.esm/console.d.ts.map +1 -1
- package/dist.esm/console.js +60 -80
- package/dist.esm/console.js.map +1 -1
- package/dist.esm/constructor.d.ts +6 -6
- package/dist.esm/constructor.js +1 -1
- package/dist.esm/decorators.d.ts +1 -1
- package/dist.esm/decorators.d.ts.map +1 -1
- package/dist.esm/decorators.js +3 -3
- package/dist.esm/environment.d.ts +11 -11
- package/dist.esm/environment.d.ts.map +1 -1
- package/dist.esm/environment.js +24 -24
- package/dist.esm/environment.js.map +1 -1
- package/dist.esm/errors.d.ts +66 -66
- package/dist.esm/errors.js +115 -115
- package/dist.esm/errors.test.d.ts +1 -1
- package/dist.esm/get-param-names.d.ts +5 -5
- package/dist.esm/get-param-names.js +45 -45
- package/dist.esm/get-param-names.js.map +1 -1
- package/dist.esm/index.d.ts +20 -20
- package/dist.esm/index.js +20 -20
- package/dist.esm/is-constructor.d.ts +12 -12
- package/dist.esm/is-constructor.js +24 -24
- package/dist.esm/is-constructor.js.map +1 -1
- package/dist.esm/is-constructor.test.d.ts +1 -1
- package/dist.esm/lazy-promise.d.ts +14 -14
- package/dist.esm/lazy-promise.js +28 -28
- package/dist.esm/lazy-promise.js.map +1 -1
- package/dist.esm/lazy-subject.d.ts +22 -22
- package/dist.esm/lazy-subject.js +19 -19
- package/dist.esm/locks.d.ts +23 -23
- package/dist.esm/locks.js +71 -71
- package/dist.esm/locks.js.map +1 -1
- package/dist.esm/locks.test.d.ts +1 -1
- package/dist.esm/locks.test.js.map +1 -1
- package/dist.esm/padding.d.ts +22 -22
- package/dist.esm/padding.js +37 -37
- package/dist.esm/presentation.d.ts +49 -49
- package/dist.esm/presentation.d.ts.map +1 -1
- package/dist.esm/presentation.js +126 -126
- package/dist.esm/presentation.js.map +1 -1
- package/dist.esm/presentation.test.d.ts +1 -1
- package/dist.esm/presentation.test.js.map +1 -1
- package/dist.esm/serializer.d.ts +8 -8
- package/dist.esm/serializer.js +20 -20
- package/dist.esm/test.d.ts +2 -2
- package/dist.esm/time.d.ts +9 -9
- package/dist.esm/time.js +19 -19
- package/dist.esm/time.js.map +1 -1
- package/dist.esm/timeout.d.ts +13 -13
- package/dist.esm/timeout.js +23 -23
- package/dist.esm/tsconfig.esm.tsbuildinfo +1 -0
- package/dist.esm/zones.d.ts +46 -46
- package/dist.esm/zones.js +135 -135
- package/dist.esm/zones.js.map +1 -1
- package/package.json +10 -7
- package/src/console.ts +2 -22
- package/src/environment.ts +2 -0
- package/tsconfig.esm.json +0 -3
- package/tsconfig.json +0 -2
- package/tsconfig.tsbuildinfo +1 -3791
package/dist.esm/padding.js
CHANGED
|
@@ -1,38 +1,38 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Pad the given string until its at least `length` characters long by adding spaces to the end.
|
|
3
|
-
*
|
|
4
|
-
* @param str
|
|
5
|
-
* @param length
|
|
6
|
-
* @returns
|
|
7
|
-
*/
|
|
8
|
-
export function rightPad(str, length) {
|
|
9
|
-
str = String(str);
|
|
10
|
-
while (str.length < length)
|
|
11
|
-
str += ' ';
|
|
12
|
-
return str;
|
|
13
|
-
}
|
|
14
|
-
/**
|
|
15
|
-
* Pad the given string until its at least `length` characters long by adding spaces to the beginning.
|
|
16
|
-
* @param str
|
|
17
|
-
* @param length
|
|
18
|
-
* @returns
|
|
19
|
-
*/
|
|
20
|
-
export function leftPad(str, length) {
|
|
21
|
-
str = String(str);
|
|
22
|
-
while (str.length < length)
|
|
23
|
-
str = ' ' + str;
|
|
24
|
-
return str;
|
|
25
|
-
}
|
|
26
|
-
/**
|
|
27
|
-
* Pad the given number (creating a string) until its at least `length` digits long by adding zeros to the beginning.
|
|
28
|
-
* @param number
|
|
29
|
-
* @param digits
|
|
30
|
-
* @returns
|
|
31
|
-
*/
|
|
32
|
-
export function zeroPad(number, digits = 2) {
|
|
33
|
-
let str = `${number}`;
|
|
34
|
-
while (str.length < digits)
|
|
35
|
-
str = '0' + str;
|
|
36
|
-
return str;
|
|
37
|
-
}
|
|
1
|
+
/**
|
|
2
|
+
* Pad the given string until its at least `length` characters long by adding spaces to the end.
|
|
3
|
+
*
|
|
4
|
+
* @param str
|
|
5
|
+
* @param length
|
|
6
|
+
* @returns
|
|
7
|
+
*/
|
|
8
|
+
export function rightPad(str, length) {
|
|
9
|
+
str = String(str);
|
|
10
|
+
while (str.length < length)
|
|
11
|
+
str += ' ';
|
|
12
|
+
return str;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Pad the given string until its at least `length` characters long by adding spaces to the beginning.
|
|
16
|
+
* @param str
|
|
17
|
+
* @param length
|
|
18
|
+
* @returns
|
|
19
|
+
*/
|
|
20
|
+
export function leftPad(str, length) {
|
|
21
|
+
str = String(str);
|
|
22
|
+
while (str.length < length)
|
|
23
|
+
str = ' ' + str;
|
|
24
|
+
return str;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Pad the given number (creating a string) until its at least `length` digits long by adding zeros to the beginning.
|
|
28
|
+
* @param number
|
|
29
|
+
* @param digits
|
|
30
|
+
* @returns
|
|
31
|
+
*/
|
|
32
|
+
export function zeroPad(number, digits = 2) {
|
|
33
|
+
let str = `${number}`;
|
|
34
|
+
while (str.length < digits)
|
|
35
|
+
str = '0' + str;
|
|
36
|
+
return str;
|
|
37
|
+
}
|
|
38
38
|
//# sourceMappingURL=padding.js.map
|
|
@@ -1,50 +1,50 @@
|
|
|
1
|
-
import { Constructor } from "./constructor";
|
|
2
|
-
export declare const EXPOSE_PROTOTYPE_STORAGE_KEY = "@alterior/common:Expose";
|
|
3
|
-
export interface PresentedPropertyOptions {
|
|
4
|
-
useProperty?: string;
|
|
5
|
-
class?: Constructor<Presentation<any>>;
|
|
6
|
-
defaultValue?: any;
|
|
7
|
-
}
|
|
8
|
-
export interface PresentedProperty {
|
|
9
|
-
propertyKey: string;
|
|
10
|
-
options: PresentedPropertyOptions;
|
|
11
|
-
designType?: any;
|
|
12
|
-
}
|
|
13
|
-
export declare class PresentationSchema<T> {
|
|
14
|
-
readonly type: Constructor<Presentation<T>>;
|
|
15
|
-
constructor(type: Constructor<Presentation<T>>);
|
|
16
|
-
private populate;
|
|
17
|
-
properties: PresentedProperty[];
|
|
18
|
-
}
|
|
19
|
-
/**
|
|
20
|
-
* Allows for transforming data from one form to another using declarative rules.
|
|
21
|
-
* To use, you must declare a subclass which has one or more properties annotated
|
|
22
|
-
* with the `@Expose()` decorator. When the presentation is converted to JSON,
|
|
23
|
-
* the property values from the `instance` given during instantiation will be used
|
|
24
|
-
* within the JSON. If any property declaration within the `Presentation<T>` subclass
|
|
25
|
-
* has a property type annotation for a type that extends `Presentation<T>`, a
|
|
26
|
-
* new instance of that type will be constructed and passed the property value from
|
|
27
|
-
* the given `instance`. This allows you to control the presentation of subobjects.
|
|
28
|
-
*/
|
|
29
|
-
export declare class Presentation<T> {
|
|
30
|
-
readonly instance: T;
|
|
31
|
-
constructor(instance: T);
|
|
32
|
-
/**
|
|
33
|
-
* Construct a new set of presentations with the type of calling class
|
|
34
|
-
* for the items within the given array.
|
|
35
|
-
*
|
|
36
|
-
* @param this
|
|
37
|
-
* @param array
|
|
38
|
-
*/
|
|
39
|
-
static from<T extends Presentation<U>, U>(this: Constructor<T>, array: U[]): T[];
|
|
40
|
-
static get properties(): PresentedProperty[];
|
|
41
|
-
toJSON(): {};
|
|
42
|
-
}
|
|
43
|
-
/**
|
|
44
|
-
* When used on properties declared within a subclass of `Presentation<T>`,
|
|
45
|
-
* specifies that the property should be included in the final JSON presentation.
|
|
46
|
-
*
|
|
47
|
-
* @see Presentation<T>
|
|
48
|
-
*/
|
|
49
|
-
export declare function Expose(options?: PresentedPropertyOptions): (target: Object, propertyKey: string, descriptor?: PropertyDescriptor) => void;
|
|
1
|
+
import { Constructor } from "./constructor";
|
|
2
|
+
export declare const EXPOSE_PROTOTYPE_STORAGE_KEY = "@alterior/common:Expose";
|
|
3
|
+
export interface PresentedPropertyOptions {
|
|
4
|
+
useProperty?: string;
|
|
5
|
+
class?: Constructor<Presentation<any>>;
|
|
6
|
+
defaultValue?: any;
|
|
7
|
+
}
|
|
8
|
+
export interface PresentedProperty {
|
|
9
|
+
propertyKey: string;
|
|
10
|
+
options: PresentedPropertyOptions;
|
|
11
|
+
designType?: any;
|
|
12
|
+
}
|
|
13
|
+
export declare class PresentationSchema<T> {
|
|
14
|
+
readonly type: Constructor<Presentation<T>>;
|
|
15
|
+
constructor(type: Constructor<Presentation<T>>);
|
|
16
|
+
private populate;
|
|
17
|
+
properties: PresentedProperty[];
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Allows for transforming data from one form to another using declarative rules.
|
|
21
|
+
* To use, you must declare a subclass which has one or more properties annotated
|
|
22
|
+
* with the `@Expose()` decorator. When the presentation is converted to JSON,
|
|
23
|
+
* the property values from the `instance` given during instantiation will be used
|
|
24
|
+
* within the JSON. If any property declaration within the `Presentation<T>` subclass
|
|
25
|
+
* has a property type annotation for a type that extends `Presentation<T>`, a
|
|
26
|
+
* new instance of that type will be constructed and passed the property value from
|
|
27
|
+
* the given `instance`. This allows you to control the presentation of subobjects.
|
|
28
|
+
*/
|
|
29
|
+
export declare class Presentation<T> {
|
|
30
|
+
readonly instance: T;
|
|
31
|
+
constructor(instance: T);
|
|
32
|
+
/**
|
|
33
|
+
* Construct a new set of presentations with the type of calling class
|
|
34
|
+
* for the items within the given array.
|
|
35
|
+
*
|
|
36
|
+
* @param this
|
|
37
|
+
* @param array
|
|
38
|
+
*/
|
|
39
|
+
static from<T extends Presentation<U>, U>(this: Constructor<T>, array: U[]): T[];
|
|
40
|
+
static get properties(): PresentedProperty[];
|
|
41
|
+
toJSON(): {};
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* When used on properties declared within a subclass of `Presentation<T>`,
|
|
45
|
+
* specifies that the property should be included in the final JSON presentation.
|
|
46
|
+
*
|
|
47
|
+
* @see Presentation<T>
|
|
48
|
+
*/
|
|
49
|
+
export declare function Expose(options?: PresentedPropertyOptions): (target: Object, propertyKey: string, descriptor?: PropertyDescriptor) => void;
|
|
50
50
|
//# sourceMappingURL=presentation.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"presentation.d.ts","sourceRoot":"","sources":["../src/presentation.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAG5C,eAAO,MAAM,4BAA4B,4BAA4B,CAAC;AAEtE,MAAM,WAAW,wBAAwB;IACrC,WAAW,CAAC,EAAG,MAAM,CAAC;IACtB,KAAK,CAAC,EAAG,WAAW,CAAC,YAAY,CAAC,GAAG,CAAC,CAAC,CAAC;IACxC,YAAY,CAAC,EAAG,GAAG,CAAC;CACvB;AAED,MAAM,WAAW,iBAAiB;IAC9B,WAAW,EAAG,MAAM,CAAC;IACrB,OAAO,EAAG,wBAAwB,CAAC;IACnC,UAAU,CAAC,EAAG,GAAG,CAAC;CACrB;AAED,qBAAa,kBAAkB,CAAC,CAAC;IACjB,QAAQ,CAAC,IAAI,EAAG,WAAW,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC;gBAAnC,IAAI,EAAG,WAAW,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC;IAIxD,OAAO,CAAC,QAAQ;IA8ChB,UAAU,EAAG,iBAAiB,EAAE,CAAC;CACpC;AAED;;;;;;;;;GASG;AACH,qBAAa,YAAY,CAAC,CAAC;IAEnB,QAAQ,CAAC,QAAQ,EAAG,CAAC;gBAAZ,QAAQ,EAAG,CAAC;IAIzB;;;;;;OAMG;WACW,IAAI,CAAC,CAAC,SAAS,YAAY,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,IAAI,EAAG,WAAW,CAAC,CAAC,CAAC,EAAE,KAAK,EAAG,CAAC,EAAE,GAAI,CAAC,EAAE;IAI1F,WAAkB,UAAU,IAAK,iBAAiB,EAAE,CAEnD;IAEM,MAAM;CA4ChB;AAED;;;;;GAKG;AACH,wBAAgB,MAAM,CAAC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
package/dist.esm/presentation.js
CHANGED
|
@@ -1,127 +1,127 @@
|
|
|
1
|
-
/// <reference types="reflect-metadata" />
|
|
2
|
-
import { clone } from "./clone";
|
|
3
|
-
export const EXPOSE_PROTOTYPE_STORAGE_KEY = '@alterior/common:Expose';
|
|
4
|
-
export class PresentationSchema {
|
|
5
|
-
constructor(type) {
|
|
6
|
-
this.type = type;
|
|
7
|
-
this.populate();
|
|
8
|
-
}
|
|
9
|
-
populate() {
|
|
10
|
-
let exposureSets = [];
|
|
11
|
-
let prototype = this.type.prototype;
|
|
12
|
-
let prototypes = [];
|
|
13
|
-
while (prototype) {
|
|
14
|
-
prototypes.push(prototype);
|
|
15
|
-
let value = prototype[EXPOSE_PROTOTYPE_STORAGE_KEY];
|
|
16
|
-
if (value)
|
|
17
|
-
exposureSets.push(value);
|
|
18
|
-
prototype = Object.getPrototypeOf(prototype);
|
|
19
|
-
}
|
|
20
|
-
// Reverse the order so that the super-most properties appear first,
|
|
21
|
-
// followed by the subproperties.
|
|
22
|
-
exposureSets = exposureSets.reverse();
|
|
23
|
-
let exposures = exposureSets
|
|
24
|
-
.reduce((pv, cv) => (pv.push(...cv), pv), [])
|
|
25
|
-
.map(x => clone(x));
|
|
26
|
-
for (let exposure of exposures) {
|
|
27
|
-
let key = exposure.propertyKey;
|
|
28
|
-
if (exposure.options && exposure.options.useProperty) {
|
|
29
|
-
key = exposure.options.useProperty;
|
|
30
|
-
}
|
|
31
|
-
let designType = null;
|
|
32
|
-
for (let prototype of prototypes) {
|
|
33
|
-
designType = Reflect.getMetadata('design:type', prototype, key);
|
|
34
|
-
if (designType)
|
|
35
|
-
break;
|
|
36
|
-
}
|
|
37
|
-
if (!exposure.designType)
|
|
38
|
-
exposure.designType = designType;
|
|
39
|
-
}
|
|
40
|
-
this.properties = exposures;
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
/**
|
|
44
|
-
* Allows for transforming data from one form to another using declarative rules.
|
|
45
|
-
* To use, you must declare a subclass which has one or more properties annotated
|
|
46
|
-
* with the `@Expose()` decorator. When the presentation is converted to JSON,
|
|
47
|
-
* the property values from the `instance` given during instantiation will be used
|
|
48
|
-
* within the JSON. If any property declaration within the `Presentation<T>` subclass
|
|
49
|
-
* has a property type annotation for a type that extends `Presentation<T>`, a
|
|
50
|
-
* new instance of that type will be constructed and passed the property value from
|
|
51
|
-
* the given `instance`. This allows you to control the presentation of subobjects.
|
|
52
|
-
*/
|
|
53
|
-
export class Presentation {
|
|
54
|
-
constructor(instance) {
|
|
55
|
-
this.instance = instance;
|
|
56
|
-
}
|
|
57
|
-
/**
|
|
58
|
-
* Construct a new set of presentations with the type of calling class
|
|
59
|
-
* for the items within the given array.
|
|
60
|
-
*
|
|
61
|
-
* @param this
|
|
62
|
-
* @param array
|
|
63
|
-
*/
|
|
64
|
-
static from(array) {
|
|
65
|
-
return array.map(x => new this(x));
|
|
66
|
-
}
|
|
67
|
-
static get properties() {
|
|
68
|
-
return new PresentationSchema(this).properties;
|
|
69
|
-
}
|
|
70
|
-
toJSON() {
|
|
71
|
-
if (!this.instance)
|
|
72
|
-
return null;
|
|
73
|
-
let properties = {};
|
|
74
|
-
let exposures = this.constructor.properties;
|
|
75
|
-
for (let exposure of exposures) {
|
|
76
|
-
let key = exposure.propertyKey;
|
|
77
|
-
let options = exposure.options;
|
|
78
|
-
let prototype = Object.getPrototypeOf(this);
|
|
79
|
-
let propertyType = Reflect.getMetadata('design:type', this.constructor.prototype, key);
|
|
80
|
-
let propertyDescriptor = Object.getOwnPropertyDescriptor(prototype, key);
|
|
81
|
-
let value = this[key];
|
|
82
|
-
if (options.useProperty) {
|
|
83
|
-
value = this.instance[options.useProperty];
|
|
84
|
-
}
|
|
85
|
-
else if (!propertyDescriptor || !propertyDescriptor.get) {
|
|
86
|
-
// Data property, fill from original object.
|
|
87
|
-
value = this.instance[key];
|
|
88
|
-
}
|
|
89
|
-
let entityType;
|
|
90
|
-
if (options.class) {
|
|
91
|
-
entityType = options.class;
|
|
92
|
-
}
|
|
93
|
-
else if (propertyType && propertyType.prototype instanceof Presentation) {
|
|
94
|
-
entityType = propertyType;
|
|
95
|
-
}
|
|
96
|
-
// Transform...
|
|
97
|
-
if (entityType)
|
|
98
|
-
value = new entityType(value);
|
|
99
|
-
if (value && value.toJSON)
|
|
100
|
-
value = value.toJSON();
|
|
101
|
-
properties[key] = value;
|
|
102
|
-
}
|
|
103
|
-
return properties;
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
/**
|
|
107
|
-
* When used on properties declared within a subclass of `Presentation<T>`,
|
|
108
|
-
* specifies that the property should be included in the final JSON presentation.
|
|
109
|
-
*
|
|
110
|
-
* @see Presentation<T>
|
|
111
|
-
*/
|
|
112
|
-
export function Expose(options = {}) {
|
|
113
|
-
return function (target, propertyKey, descriptor) {
|
|
114
|
-
if (!target.hasOwnProperty(EXPOSE_PROTOTYPE_STORAGE_KEY)) {
|
|
115
|
-
Object.defineProperty(target, EXPOSE_PROTOTYPE_STORAGE_KEY, {
|
|
116
|
-
enumerable: false,
|
|
117
|
-
value: []
|
|
118
|
-
});
|
|
119
|
-
}
|
|
120
|
-
let exposures = target[EXPOSE_PROTOTYPE_STORAGE_KEY];
|
|
121
|
-
exposures.push({
|
|
122
|
-
propertyKey: propertyKey,
|
|
123
|
-
options
|
|
124
|
-
});
|
|
125
|
-
};
|
|
126
|
-
}
|
|
1
|
+
/// <reference types="reflect-metadata" />
|
|
2
|
+
import { clone } from "./clone";
|
|
3
|
+
export const EXPOSE_PROTOTYPE_STORAGE_KEY = '@alterior/common:Expose';
|
|
4
|
+
export class PresentationSchema {
|
|
5
|
+
constructor(type) {
|
|
6
|
+
this.type = type;
|
|
7
|
+
this.populate();
|
|
8
|
+
}
|
|
9
|
+
populate() {
|
|
10
|
+
let exposureSets = [];
|
|
11
|
+
let prototype = this.type.prototype;
|
|
12
|
+
let prototypes = [];
|
|
13
|
+
while (prototype) {
|
|
14
|
+
prototypes.push(prototype);
|
|
15
|
+
let value = prototype[EXPOSE_PROTOTYPE_STORAGE_KEY];
|
|
16
|
+
if (value)
|
|
17
|
+
exposureSets.push(value);
|
|
18
|
+
prototype = Object.getPrototypeOf(prototype);
|
|
19
|
+
}
|
|
20
|
+
// Reverse the order so that the super-most properties appear first,
|
|
21
|
+
// followed by the subproperties.
|
|
22
|
+
exposureSets = exposureSets.reverse();
|
|
23
|
+
let exposures = exposureSets
|
|
24
|
+
.reduce((pv, cv) => (pv.push(...cv), pv), [])
|
|
25
|
+
.map(x => clone(x));
|
|
26
|
+
for (let exposure of exposures) {
|
|
27
|
+
let key = exposure.propertyKey;
|
|
28
|
+
if (exposure.options && exposure.options.useProperty) {
|
|
29
|
+
key = exposure.options.useProperty;
|
|
30
|
+
}
|
|
31
|
+
let designType = null;
|
|
32
|
+
for (let prototype of prototypes) {
|
|
33
|
+
designType = Reflect.getMetadata('design:type', prototype, key);
|
|
34
|
+
if (designType)
|
|
35
|
+
break;
|
|
36
|
+
}
|
|
37
|
+
if (!exposure.designType)
|
|
38
|
+
exposure.designType = designType;
|
|
39
|
+
}
|
|
40
|
+
this.properties = exposures;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Allows for transforming data from one form to another using declarative rules.
|
|
45
|
+
* To use, you must declare a subclass which has one or more properties annotated
|
|
46
|
+
* with the `@Expose()` decorator. When the presentation is converted to JSON,
|
|
47
|
+
* the property values from the `instance` given during instantiation will be used
|
|
48
|
+
* within the JSON. If any property declaration within the `Presentation<T>` subclass
|
|
49
|
+
* has a property type annotation for a type that extends `Presentation<T>`, a
|
|
50
|
+
* new instance of that type will be constructed and passed the property value from
|
|
51
|
+
* the given `instance`. This allows you to control the presentation of subobjects.
|
|
52
|
+
*/
|
|
53
|
+
export class Presentation {
|
|
54
|
+
constructor(instance) {
|
|
55
|
+
this.instance = instance;
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Construct a new set of presentations with the type of calling class
|
|
59
|
+
* for the items within the given array.
|
|
60
|
+
*
|
|
61
|
+
* @param this
|
|
62
|
+
* @param array
|
|
63
|
+
*/
|
|
64
|
+
static from(array) {
|
|
65
|
+
return array.map(x => new this(x));
|
|
66
|
+
}
|
|
67
|
+
static get properties() {
|
|
68
|
+
return new PresentationSchema(this).properties;
|
|
69
|
+
}
|
|
70
|
+
toJSON() {
|
|
71
|
+
if (!this.instance)
|
|
72
|
+
return null;
|
|
73
|
+
let properties = {};
|
|
74
|
+
let exposures = this.constructor.properties;
|
|
75
|
+
for (let exposure of exposures) {
|
|
76
|
+
let key = exposure.propertyKey;
|
|
77
|
+
let options = exposure.options;
|
|
78
|
+
let prototype = Object.getPrototypeOf(this);
|
|
79
|
+
let propertyType = Reflect.getMetadata('design:type', this.constructor.prototype, key);
|
|
80
|
+
let propertyDescriptor = Object.getOwnPropertyDescriptor(prototype, key);
|
|
81
|
+
let value = this[key];
|
|
82
|
+
if (options.useProperty) {
|
|
83
|
+
value = this.instance[options.useProperty];
|
|
84
|
+
}
|
|
85
|
+
else if (!propertyDescriptor || !propertyDescriptor.get) {
|
|
86
|
+
// Data property, fill from original object.
|
|
87
|
+
value = this.instance[key];
|
|
88
|
+
}
|
|
89
|
+
let entityType;
|
|
90
|
+
if (options.class) {
|
|
91
|
+
entityType = options.class;
|
|
92
|
+
}
|
|
93
|
+
else if (propertyType && propertyType.prototype instanceof Presentation) {
|
|
94
|
+
entityType = propertyType;
|
|
95
|
+
}
|
|
96
|
+
// Transform...
|
|
97
|
+
if (entityType)
|
|
98
|
+
value = new entityType(value);
|
|
99
|
+
if (value && value.toJSON)
|
|
100
|
+
value = value.toJSON();
|
|
101
|
+
properties[key] = value;
|
|
102
|
+
}
|
|
103
|
+
return properties;
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* When used on properties declared within a subclass of `Presentation<T>`,
|
|
108
|
+
* specifies that the property should be included in the final JSON presentation.
|
|
109
|
+
*
|
|
110
|
+
* @see Presentation<T>
|
|
111
|
+
*/
|
|
112
|
+
export function Expose(options = {}) {
|
|
113
|
+
return function (target, propertyKey, descriptor) {
|
|
114
|
+
if (!target.hasOwnProperty(EXPOSE_PROTOTYPE_STORAGE_KEY)) {
|
|
115
|
+
Object.defineProperty(target, EXPOSE_PROTOTYPE_STORAGE_KEY, {
|
|
116
|
+
enumerable: false,
|
|
117
|
+
value: []
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
let exposures = target[EXPOSE_PROTOTYPE_STORAGE_KEY];
|
|
121
|
+
exposures.push({
|
|
122
|
+
propertyKey: propertyKey,
|
|
123
|
+
options
|
|
124
|
+
});
|
|
125
|
+
};
|
|
126
|
+
}
|
|
127
127
|
//# sourceMappingURL=presentation.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"presentation.js","sourceRoot":"","sources":["../src/presentation.ts"],"names":[],"mappings":"AAAA,0CAA0C;AAG1C,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAEhC,MAAM,CAAC,MAAM,4BAA4B,GAAG,yBAAyB,CAAC;AActE,MAAM,OAAO,kBAAkB;IAC3B,YAAqB,IAAmC;QAAnC,SAAI,GAAJ,IAAI,CAA+B;QACpD,IAAI,CAAC,QAAQ,EAAE,CAAC;IACpB,CAAC;IAEO,QAAQ;QACZ,IAAI,YAAY,GAA2B,EAAE,CAAC;QAE9C,IAAI,SAAS,GAAG,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC;QACpC,IAAI,UAAU,GAAG,EAAG,CAAC;QAErB,OAAO,SAAS,EAAE;
|
|
1
|
+
{"version":3,"file":"presentation.js","sourceRoot":"","sources":["../src/presentation.ts"],"names":[],"mappings":"AAAA,0CAA0C;AAG1C,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAEhC,MAAM,CAAC,MAAM,4BAA4B,GAAG,yBAAyB,CAAC;AActE,MAAM,OAAO,kBAAkB;IAC3B,YAAqB,IAAmC;QAAnC,SAAI,GAAJ,IAAI,CAA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,CAAC;IACV,CAAC,CAAC;AACH,CAAC"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export {};
|
|
1
|
+
export {};
|
|
2
2
|
//# sourceMappingURL=presentation.test.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"presentation.test.js","sourceRoot":"","sources":["../src/presentation.test.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,QAAQ,CAAC;AAC/B,OAAO,EAAE,MAAM,EAAE,MAAM,MAAM,CAAC;AAC9B,OAAO,EAAE,YAAY,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AAEtD,KAAK,CAAC,QAAQ,CAAC,EAAE;IACb,QAAQ,CAAC,iBAAiB,EAAE,EAAE,CAAC,EAAE;QAC7B,EAAE,CAAC,4CAA4C,EAAE,GAAG,EAAE;YAQlD,SAAS,OAAO;gBACZ,OAAO,CAAC,MAAM,EAAE,GAAG,IAAI,EAAE,EAAE,CAAC,MAAM,CAAC;YACvC,CAAC;YAGD,IAAM,QAAQ,GAAd,MAAM,QAAS,SAAQ,YAAmB;aAIzC,CAAA;
|
|
1
|
+
{"version":3,"file":"presentation.test.js","sourceRoot":"","sources":["../src/presentation.test.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,QAAQ,CAAC;AAC/B,OAAO,EAAE,MAAM,EAAE,MAAM,MAAM,CAAC;AAC9B,OAAO,EAAE,YAAY,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AAEtD,KAAK,CAAC,QAAQ,CAAC,EAAE;IACb,QAAQ,CAAC,iBAAiB,EAAE,EAAE,CAAC,EAAE;QAC7B,EAAE,CAAC,4CAA4C,EAAE,GAAG,EAAE;YAQlD,SAAS,OAAO;gBACZ,OAAO,CAAC,MAAM,EAAE,GAAG,IAAI,EAAE,EAAE,CAAC,MAAM,CAAC;YACvC,CAAC;YAGD,IAAM,QAAQ,GAAd,MAAM,QAAS,SAAQ,Y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ADa;gBAAT,MAAM,EAAE;;2DAAgB;YAG7B,MAAM,QAAS,SAAQ,gBAAgB;aAEtC;YADa;gBAAT,MAAM,EAAE;;yDAAsB;YAGnC,IAAI,iBAAiB,GAAG,IAAI,gBAAgB,CAAC,EAAE,KAAK,EAAE,OAAO,EAAE,WAAW,EAAE,aAAa,EAAE,CAAC,CAAC;YAC7F,IAAI,YAAY,GAAS,iBAAiB,CAAC,MAAM,EAAE,CAAC;YAEpD,MAAM,CAAC,YAAY,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;YAC7C,MAAM,CAAC,YAAY,CAAC,WAAW,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,SAAS,CAAC;YAEjD,IAAI,SAAS,GAAG,IAAI,QAAQ,CAAC,EAAE,KAAK,EAAE,OAAO,EAAE,WAAW,EAAE,aAAa,EAAE,CAAC,CAAC;YAC7E,IAAI,IAAI,GAAS,SAAS,CAAC,MAAM,EAAE,CAAC;YAEpC,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;YACrC,MAAM,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,aAAa,CAAC,CAAC;QACrD,CAAC,CAAC,CAAC;IACP,CAAC,CAAC,CAAC;AACP,CAAC,CAAC,CAAC"}
|
package/dist.esm/serializer.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Prepare an object for serialization by removing any fields which are undefined
|
|
3
|
-
* or functions and return the result. The operation is recursive across all subobjects.
|
|
4
|
-
* The original object is not modified.
|
|
5
|
-
*
|
|
6
|
-
* @param data
|
|
7
|
-
*/
|
|
8
|
-
export declare function prepareForSerialization<T>(data: T): T;
|
|
1
|
+
/**
|
|
2
|
+
* Prepare an object for serialization by removing any fields which are undefined
|
|
3
|
+
* or functions and return the result. The operation is recursive across all subobjects.
|
|
4
|
+
* The original object is not modified.
|
|
5
|
+
*
|
|
6
|
+
* @param data
|
|
7
|
+
*/
|
|
8
|
+
export declare function prepareForSerialization<T>(data: T): T;
|
|
9
9
|
//# sourceMappingURL=serializer.d.ts.map
|
package/dist.esm/serializer.js
CHANGED
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Prepare an object for serialization by removing any fields which are undefined
|
|
3
|
-
* or functions and return the result. The operation is recursive across all subobjects.
|
|
4
|
-
* The original object is not modified.
|
|
5
|
-
*
|
|
6
|
-
* @param data
|
|
7
|
-
*/
|
|
8
|
-
export function prepareForSerialization(data) {
|
|
9
|
-
if (data === undefined || data === null)
|
|
10
|
-
return null;
|
|
11
|
-
if (data['toJSON'])
|
|
12
|
-
data = data['toJSON']();
|
|
13
|
-
if (typeof data !== 'object')
|
|
14
|
-
return data;
|
|
15
|
-
return Object.entries(data)
|
|
16
|
-
.filter(x => x[1] !== undefined)
|
|
17
|
-
.filter(x => typeof x[1] !== 'function')
|
|
18
|
-
.map(x => [x[0], prepareForSerialization(x[1])])
|
|
19
|
-
.reduce((o, [k, v]) => (o[k] = v, o), {});
|
|
20
|
-
}
|
|
1
|
+
/**
|
|
2
|
+
* Prepare an object for serialization by removing any fields which are undefined
|
|
3
|
+
* or functions and return the result. The operation is recursive across all subobjects.
|
|
4
|
+
* The original object is not modified.
|
|
5
|
+
*
|
|
6
|
+
* @param data
|
|
7
|
+
*/
|
|
8
|
+
export function prepareForSerialization(data) {
|
|
9
|
+
if (data === undefined || data === null)
|
|
10
|
+
return null;
|
|
11
|
+
if (data['toJSON'])
|
|
12
|
+
data = data['toJSON']();
|
|
13
|
+
if (typeof data !== 'object')
|
|
14
|
+
return data;
|
|
15
|
+
return Object.entries(data)
|
|
16
|
+
.filter(x => x[1] !== undefined)
|
|
17
|
+
.filter(x => typeof x[1] !== 'function')
|
|
18
|
+
.map(x => [x[0], prepareForSerialization(x[1])])
|
|
19
|
+
.reduce((o, [k, v]) => (o[k] = v, o), {});
|
|
20
|
+
}
|
|
21
21
|
//# sourceMappingURL=serializer.js.map
|
package/dist.esm/test.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import "reflect-metadata";
|
|
2
|
-
import "source-map-support/register";
|
|
1
|
+
import "reflect-metadata";
|
|
2
|
+
import "source-map-support/register";
|
|
3
3
|
//# sourceMappingURL=test.d.ts.map
|
package/dist.esm/time.d.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* A DI service to get the current time.
|
|
3
|
-
* Useful if you need to mock or redfine
|
|
4
|
-
* the concept of "current time"
|
|
5
|
-
*/
|
|
6
|
-
export declare class Time {
|
|
7
|
-
now(): number;
|
|
8
|
-
current(): Date;
|
|
9
|
-
}
|
|
1
|
+
/**
|
|
2
|
+
* A DI service to get the current time.
|
|
3
|
+
* Useful if you need to mock or redfine
|
|
4
|
+
* the concept of "current time"
|
|
5
|
+
*/
|
|
6
|
+
export declare class Time {
|
|
7
|
+
now(): number;
|
|
8
|
+
current(): Date;
|
|
9
|
+
}
|
|
10
10
|
//# sourceMappingURL=time.d.ts.map
|
package/dist.esm/time.js
CHANGED
|
@@ -1,20 +1,20 @@
|
|
|
1
|
-
import { __decorate } from "tslib";
|
|
2
|
-
import { Injectable } from './decorators';
|
|
3
|
-
/**
|
|
4
|
-
* A DI service to get the current time.
|
|
5
|
-
* Useful if you need to mock or redfine
|
|
6
|
-
* the concept of "current time"
|
|
7
|
-
*/
|
|
8
|
-
let Time = class Time {
|
|
9
|
-
now() {
|
|
10
|
-
return Date.now();
|
|
11
|
-
}
|
|
12
|
-
current() {
|
|
13
|
-
return new Date();
|
|
14
|
-
}
|
|
15
|
-
};
|
|
16
|
-
Time = __decorate([
|
|
17
|
-
Injectable()
|
|
18
|
-
], Time);
|
|
19
|
-
export { Time };
|
|
1
|
+
import { __decorate } from "tslib";
|
|
2
|
+
import { Injectable } from './decorators';
|
|
3
|
+
/**
|
|
4
|
+
* A DI service to get the current time.
|
|
5
|
+
* Useful if you need to mock or redfine
|
|
6
|
+
* the concept of "current time"
|
|
7
|
+
*/
|
|
8
|
+
let Time = class Time {
|
|
9
|
+
now() {
|
|
10
|
+
return Date.now();
|
|
11
|
+
}
|
|
12
|
+
current() {
|
|
13
|
+
return new Date();
|
|
14
|
+
}
|
|
15
|
+
};
|
|
16
|
+
Time = __decorate([
|
|
17
|
+
Injectable()
|
|
18
|
+
], Time);
|
|
19
|
+
export { Time };
|
|
20
20
|
//# sourceMappingURL=time.js.map
|
package/dist.esm/time.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"time.js","sourceRoot":"","sources":["../src/time.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAE1C;;;;GAIG;AAEI,IAAM,IAAI,GAAV,MAAM,IAAI;IACb,GAAG;QACC,OAAO,IAAI,CAAC,GAAG,EAAE,CAAC;IACtB,CAAC;IAED,OAAO;QACH,OAAO,IAAI,IAAI,EAAE,CAAC;IACtB,CAAC;CACJ,CAAA;AARY,IAAI;IADhB,UAAU,EAAE;GACA,IAAI,CAQhB
|
|
1
|
+
{"version":3,"file":"time.js","sourceRoot":"","sources":["../src/time.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAE1C;;;;GAIG;AAEI,IAAM,IAAI,GAAV,MAAM,IAAI;IACb,GAAG;QACC,OAAO,IAAI,CAAC,GAAG,EAAE,CAAC;IACtB,CAAC;IAED,OAAO;QACH,OAAO,IAAI,IAAI,EAAE,CAAC;IACtB,CAAC;CACJ,CAAA;AARY,IAAI;IADhB,UAAU,EAAE;GACA,IAAI,CAQhB"}
|
package/dist.esm/timeout.d.ts
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
import { Observable } from 'rxjs';
|
|
2
|
-
/**
|
|
3
|
-
* Wait a specified amount of time before resolving.
|
|
4
|
-
* @param time
|
|
5
|
-
*/
|
|
6
|
-
export declare function timeout(time?: number): Promise<void>;
|
|
7
|
-
/**
|
|
8
|
-
* Return an observable that fires at regular intervals as long as
|
|
9
|
-
* it has subscribers. To stop the interval, remove all subscribers.
|
|
10
|
-
*
|
|
11
|
-
* @param time
|
|
12
|
-
*/
|
|
13
|
-
export declare function interval(time: number): Observable<void>;
|
|
1
|
+
import { Observable } from 'rxjs';
|
|
2
|
+
/**
|
|
3
|
+
* Wait a specified amount of time before resolving.
|
|
4
|
+
* @param time
|
|
5
|
+
*/
|
|
6
|
+
export declare function timeout(time?: number): Promise<void>;
|
|
7
|
+
/**
|
|
8
|
+
* Return an observable that fires at regular intervals as long as
|
|
9
|
+
* it has subscribers. To stop the interval, remove all subscribers.
|
|
10
|
+
*
|
|
11
|
+
* @param time
|
|
12
|
+
*/
|
|
13
|
+
export declare function interval(time: number): Observable<void>;
|
|
14
14
|
//# sourceMappingURL=timeout.d.ts.map
|