@creator.co/wapi 1.2.0-beta14 → 1.2.0-beta15
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/package.json +1 -1
- package/dist/src/Config/Configuration.d.ts +18 -12
- package/dist/src/Config/Configuration.js +11 -11
- package/dist/src/Config/Configuration.js.map +1 -1
- package/dist/src/Server/Router.js.map +1 -1
- package/package.json +1 -1
- package/src/Config/Configuration.ts +38 -23
- package/src/Server/Router.ts +6 -0
package/dist/package.json
CHANGED
|
@@ -1,27 +1,33 @@
|
|
|
1
|
-
import { EnvironmentType } from "./EnvironmentVar";
|
|
2
1
|
export type ConfigurationSchema = {
|
|
3
2
|
[name: string]: {
|
|
4
|
-
|
|
3
|
+
isLocal?: boolean;
|
|
4
|
+
isRemote?: boolean;
|
|
5
5
|
required?: boolean;
|
|
6
6
|
cachingPolicy?: string;
|
|
7
7
|
};
|
|
8
8
|
};
|
|
9
|
-
type ExtractRemote<Type> =
|
|
10
|
-
[Property in keyof Type]
|
|
11
|
-
|
|
12
|
-
} ? Property :
|
|
9
|
+
type ExtractRemote<Type> = {
|
|
10
|
+
[Property in keyof Type]-?: Type[Property] extends {
|
|
11
|
+
isRemote: true;
|
|
12
|
+
} ? Property : null;
|
|
13
13
|
};
|
|
14
|
-
type ExtractLocal<Type> =
|
|
15
|
-
[Property in keyof Type]
|
|
16
|
-
|
|
17
|
-
} ? Property :
|
|
14
|
+
type ExtractLocal<Type> = {
|
|
15
|
+
[Property in keyof Type]-?: Type[Property] extends {
|
|
16
|
+
isLocal: true;
|
|
17
|
+
} ? Property : null;
|
|
18
18
|
};
|
|
19
|
+
type OmitKeysByValueType<T, U> = {
|
|
20
|
+
[P in keyof T]: T[P] extends U ? never : P;
|
|
21
|
+
}[keyof T];
|
|
22
|
+
type OmitByValueType<T, V> = T extends infer _ ? {
|
|
23
|
+
[key in OmitKeysByValueType<T, V>]: T[key];
|
|
24
|
+
} : never;
|
|
19
25
|
export default class Configuration<T extends ConfigurationSchema> {
|
|
20
26
|
private readonly schema;
|
|
21
27
|
private readonly remotePrefix;
|
|
22
28
|
constructor(schema: T, remotePrefix: string);
|
|
23
|
-
get(propName: ExtractLocal<T>): any;
|
|
24
|
-
asyncGet(propName: ExtractRemote<T>): Promise<any>;
|
|
29
|
+
get(propName: keyof OmitByValueType<ExtractLocal<T>, null>): any;
|
|
30
|
+
asyncGet(propName: keyof OmitByValueType<ExtractRemote<T>, null>): Promise<any>;
|
|
25
31
|
private getCachedValue;
|
|
26
32
|
private cacheValue;
|
|
27
33
|
}
|
|
@@ -47,33 +47,33 @@ var Configuration = /** @class */ (function () {
|
|
|
47
47
|
this.remotePrefix = remotePrefix;
|
|
48
48
|
}
|
|
49
49
|
Configuration.prototype.get = function (propName) {
|
|
50
|
-
|
|
51
|
-
var propSchema = this.schema[
|
|
52
|
-
var v = this.getCachedValue(
|
|
50
|
+
var propString = propName;
|
|
51
|
+
var propSchema = this.schema[propString];
|
|
52
|
+
var v = this.getCachedValue(propString);
|
|
53
53
|
v =
|
|
54
54
|
v ||
|
|
55
|
-
new EnvironmentVar_1.default(
|
|
56
|
-
this.cacheValue(
|
|
55
|
+
new EnvironmentVar_1.default(propString, EnvironmentVar_1.EnvironmentType.Local, propSchema.required, this.remotePrefix).syncResolve();
|
|
56
|
+
this.cacheValue(propString, v, propSchema.cachingPolicy);
|
|
57
57
|
return v;
|
|
58
58
|
};
|
|
59
59
|
Configuration.prototype.asyncGet = function (propName) {
|
|
60
60
|
return __awaiter(this, void 0, void 0, function () {
|
|
61
|
-
var propSchema, v, _a;
|
|
61
|
+
var propString, propSchema, v, _a;
|
|
62
62
|
return __generator(this, function (_b) {
|
|
63
63
|
switch (_b.label) {
|
|
64
64
|
case 0:
|
|
65
|
-
|
|
66
|
-
propSchema = this.schema[
|
|
67
|
-
v = this.getCachedValue(
|
|
65
|
+
propString = propName;
|
|
66
|
+
propSchema = this.schema[propString];
|
|
67
|
+
v = this.getCachedValue(propString);
|
|
68
68
|
_a = v;
|
|
69
69
|
if (_a) return [3 /*break*/, 2];
|
|
70
|
-
return [4 /*yield*/, new EnvironmentVar_1.default(
|
|
70
|
+
return [4 /*yield*/, new EnvironmentVar_1.default(propString, EnvironmentVar_1.EnvironmentType.PlainRemote, propSchema.required, this.remotePrefix).resolve()];
|
|
71
71
|
case 1:
|
|
72
72
|
_a = (_b.sent());
|
|
73
73
|
_b.label = 2;
|
|
74
74
|
case 2:
|
|
75
75
|
v = _a;
|
|
76
|
-
this.cacheValue(
|
|
76
|
+
this.cacheValue(propString, v, propSchema.cachingPolicy);
|
|
77
77
|
return [2 /*return*/, v];
|
|
78
78
|
}
|
|
79
79
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Configuration.js","sourceRoot":"","sources":["../../../src/Config/Configuration.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,qCAAsC;AACtC,+CAAgD;AAEhD,mDAAkE;AAElE,qCAAqC;AACrC,IAAM,UAAU,GAAG,IAAI,QAAQ,EAAE,CAAA;
|
|
1
|
+
{"version":3,"file":"Configuration.js","sourceRoot":"","sources":["../../../src/Config/Configuration.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,qCAAsC;AACtC,+CAAgD;AAEhD,mDAAkE;AAElE,qCAAqC;AACrC,IAAM,UAAU,GAAG,IAAI,QAAQ,EAAE,CAAA;AAwCjC;IAGE,uBAAY,MAAS,EAAE,YAAoB;QACzC,IAAI,CAAC,MAAM,GAAG,MAAM,CAAA;QACpB,IAAI,CAAC,YAAY,GAAG,YAAY,CAAA;IAClC,CAAC;IAEM,2BAAG,GAAV,UAAW,QAAsD;QAC/D,IAAM,UAAU,GAAG,QAAkB,CAAA;QACrC,IAAM,UAAU,GAAG,IAAI,CAAC,MAAM,CAAC,UAAU,CAAC,CAAA;QAC1C,IAAI,CAAC,GAAG,IAAI,CA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@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Router.js","sourceRoot":"","sources":["../../../src/Server/Router.ts"],"names":[],"mappings":";;AAEA,yDAAmD;AACnD,uCAAiC;AAEjC,sCAAgC;
|
|
1
|
+
{"version":3,"file":"Router.js","sourceRoot":"","sources":["../../../src/Server/Router.ts"],"names":[],"mappings":";;AAEA,yDAAmD;AACnD,uCAAiC;AAEjC,sCAAgC;AAqChC;IAGE,gBAAY,MAAoB;QAC9B,IAAI,CAAC,MAAM,GAAG,MAAM,CAAA;QACpB,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,WAAW,EAAE;YAC9B,CAAC,CAAC,IAAI,yBAAe,CAAC,MAAM,CAAC;YAC7B,CAAC,CAAC,IAAI,gBAAM,CAAC,MAAM,CAAC,CAAA;IACxB,CAAC;IACM,0BAAS,GAAhB;QACE,OAAO,IAAI,CAAC,MAAM,CAAC,SAAS,EAAE,CAAA;IAChC,CAAC;IACO,4BAAW,GAAnB;QACE,OAAO,eAAK,CAAC,qBAAqB,EAAE,CAAA;IACtC,CAAC;IACH,aAAC;AAAD,CAAC,AAfD,IAeC"}
|
package/package.json
CHANGED
|
@@ -8,29 +8,42 @@ const cacheStore = new MemCache()
|
|
|
8
8
|
|
|
9
9
|
export type ConfigurationSchema = {
|
|
10
10
|
[name: string]: {
|
|
11
|
-
|
|
11
|
+
isLocal?: boolean
|
|
12
|
+
isRemote?: boolean
|
|
12
13
|
required?: boolean
|
|
13
14
|
cachingPolicy?: string
|
|
14
15
|
}
|
|
15
16
|
}
|
|
16
17
|
|
|
17
18
|
// runtime type infer to ConfigurationSchema keys, which type is remote
|
|
18
|
-
type ExtractRemote<Type> =
|
|
19
|
-
[Property in keyof Type]
|
|
20
|
-
|
|
19
|
+
type ExtractRemote<Type> = {
|
|
20
|
+
[Property in keyof Type]-?: Type[Property] extends {
|
|
21
|
+
isRemote: true
|
|
21
22
|
}
|
|
22
23
|
? Property
|
|
23
|
-
:
|
|
24
|
+
: null
|
|
24
25
|
}
|
|
25
26
|
// runtime type infer to ConfigurationSchema keys, which type is local
|
|
26
|
-
type ExtractLocal<Type> =
|
|
27
|
-
[Property in keyof Type]
|
|
28
|
-
|
|
27
|
+
type ExtractLocal<Type> = {
|
|
28
|
+
[Property in keyof Type]-?: Type[Property] extends {
|
|
29
|
+
isLocal: true
|
|
29
30
|
}
|
|
30
31
|
? Property
|
|
31
|
-
:
|
|
32
|
+
: null
|
|
32
33
|
}
|
|
33
34
|
|
|
35
|
+
// Helpers to filter null keys
|
|
36
|
+
type OmitKeysByValueType<T, U> = {
|
|
37
|
+
[P in keyof T]: T[P] extends U ? never : P
|
|
38
|
+
}[keyof T]
|
|
39
|
+
|
|
40
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
41
|
+
type OmitByValueType<T, V> = T extends infer _
|
|
42
|
+
? {
|
|
43
|
+
[key in OmitKeysByValueType<T, V>]: T[key]
|
|
44
|
+
}
|
|
45
|
+
: never
|
|
46
|
+
|
|
34
47
|
export default class Configuration<T extends ConfigurationSchema> {
|
|
35
48
|
private readonly schema: T
|
|
36
49
|
private readonly remotePrefix: string
|
|
@@ -39,34 +52,36 @@ export default class Configuration<T extends ConfigurationSchema> {
|
|
|
39
52
|
this.remotePrefix = remotePrefix
|
|
40
53
|
}
|
|
41
54
|
|
|
42
|
-
public get(propName: ExtractLocal<T>): any {
|
|
43
|
-
|
|
44
|
-
const propSchema = this.schema[
|
|
45
|
-
let v = this.getCachedValue(
|
|
55
|
+
public get(propName: keyof OmitByValueType<ExtractLocal<T>, null>): any {
|
|
56
|
+
const propString = propName as string
|
|
57
|
+
const propSchema = this.schema[propString]
|
|
58
|
+
let v = this.getCachedValue(propString)
|
|
46
59
|
v =
|
|
47
60
|
v ||
|
|
48
61
|
new EnvironmentVar<string>(
|
|
49
|
-
|
|
50
|
-
|
|
62
|
+
propString,
|
|
63
|
+
EnvironmentType.Local,
|
|
51
64
|
propSchema.required,
|
|
52
65
|
this.remotePrefix,
|
|
53
66
|
).syncResolve()
|
|
54
|
-
this.cacheValue(
|
|
67
|
+
this.cacheValue(propString, v, propSchema.cachingPolicy)
|
|
55
68
|
return v
|
|
56
69
|
}
|
|
57
|
-
public async asyncGet(
|
|
58
|
-
propName
|
|
59
|
-
|
|
60
|
-
|
|
70
|
+
public async asyncGet(
|
|
71
|
+
propName: keyof OmitByValueType<ExtractRemote<T>, null>,
|
|
72
|
+
): Promise<any> {
|
|
73
|
+
const propString = propName as string
|
|
74
|
+
const propSchema = this.schema[propString]
|
|
75
|
+
let v = this.getCachedValue(propString)
|
|
61
76
|
v =
|
|
62
77
|
v ||
|
|
63
78
|
(await new EnvironmentVar<string>(
|
|
64
|
-
|
|
65
|
-
|
|
79
|
+
propString,
|
|
80
|
+
EnvironmentType.PlainRemote,
|
|
66
81
|
propSchema.required,
|
|
67
82
|
this.remotePrefix,
|
|
68
83
|
).resolve())
|
|
69
|
-
this.cacheValue(
|
|
84
|
+
this.cacheValue(propString, v, propSchema.cachingPolicy)
|
|
70
85
|
return v
|
|
71
86
|
}
|
|
72
87
|
// caching layer
|
package/src/Server/Router.ts
CHANGED
|
@@ -13,6 +13,12 @@ import Transaction, {
|
|
|
13
13
|
export interface Route<InputType = any, OutputType = any> {
|
|
14
14
|
path: string
|
|
15
15
|
method: string
|
|
16
|
+
/* If you are here to know why implementing this method
|
|
17
|
+
does not auto infer the param type, check long discussion on TS
|
|
18
|
+
- https://github.com/Microsoft/TypeScript/issues/1373
|
|
19
|
+
- https://github.com/microsoft/TypeScript/issues/23911#issuecomment-1351020050 (proposed solution)
|
|
20
|
+
- https://github.com/microsoft/TypeScript/issues/10570
|
|
21
|
+
*/
|
|
16
22
|
handler: TransactionExecution<
|
|
17
23
|
Transaction<InputType, OutputType | ResponseErrorType>,
|
|
18
24
|
OutputType | ResponseErrorType
|