@webiny/api 0.0.0-unstable.9bd236cf5e → 0.0.0-unstable.9f53ea597d
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/Benchmark.d.ts +1 -1
- package/Benchmark.js +120 -156
- package/Benchmark.js.map +1 -1
- package/Context.d.ts +5 -5
- package/Context.js +61 -137
- package/Context.js.map +1 -1
- package/README.md +10 -14
- package/createConditionalPluginFactory.d.ts +1 -1
- package/createConditionalPluginFactory.js +5 -15
- package/createConditionalPluginFactory.js.map +1 -1
- package/decorateContext.js +10 -19
- package/decorateContext.js.map +1 -1
- package/helpers/InterfaceGenerator/date.d.ts +15 -0
- package/helpers/InterfaceGenerator/date.js +0 -0
- package/helpers/InterfaceGenerator/id.d.ts +23 -0
- package/helpers/InterfaceGenerator/id.js +0 -0
- package/helpers/InterfaceGenerator/identity.d.ts +10 -0
- package/helpers/InterfaceGenerator/identity.js +0 -0
- package/helpers/InterfaceGenerator/index.d.ts +6 -0
- package/helpers/InterfaceGenerator/index.js +0 -0
- package/helpers/InterfaceGenerator/numeric.d.ts +12 -0
- package/helpers/InterfaceGenerator/numeric.js +0 -0
- package/helpers/InterfaceGenerator/text.d.ts +11 -0
- package/helpers/InterfaceGenerator/text.js +0 -0
- package/helpers/InterfaceGenerator/truthful.d.ts +7 -0
- package/helpers/InterfaceGenerator/truthful.js +0 -0
- package/index.d.ts +5 -6
- package/index.js +5 -73
- package/package.json +19 -15
- package/plugins/BenchmarkPlugin.d.ts +1 -1
- package/plugins/BenchmarkPlugin.js +19 -27
- package/plugins/BenchmarkPlugin.js.map +1 -1
- package/plugins/ContextPlugin.d.ts +1 -1
- package/plugins/ContextPlugin.js +17 -26
- package/plugins/ContextPlugin.js.map +1 -1
- package/types.d.ts +5 -10
- package/types.js +0 -7
- package/ServiceDiscovery.d.ts +0 -12
- package/ServiceDiscovery.js +0 -77
- package/ServiceDiscovery.js.map +0 -1
- package/index.js.map +0 -1
- package/plugins/CompressorPlugin.d.ts +0 -14
- package/plugins/CompressorPlugin.js +0 -21
- package/plugins/CompressorPlugin.js.map +0 -1
- package/types.js.map +0 -1
|
@@ -1,17 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
}
|
|
6
|
-
exports.createConditionalPluginFactory = void 0;
|
|
7
|
-
const createConditionalPluginFactory = (condition, cb) => {
|
|
8
|
-
return () => {
|
|
9
|
-
if (condition()) {
|
|
10
|
-
return cb();
|
|
11
|
-
}
|
|
12
|
-
return Promise.resolve([]);
|
|
13
|
-
};
|
|
14
|
-
};
|
|
15
|
-
exports.createConditionalPluginFactory = createConditionalPluginFactory;
|
|
1
|
+
const createConditionalPluginFactory = (condition, cb)=>()=>{
|
|
2
|
+
if (condition()) return cb();
|
|
3
|
+
return Promise.resolve([]);
|
|
4
|
+
};
|
|
5
|
+
export { createConditionalPluginFactory };
|
|
16
6
|
|
|
17
7
|
//# sourceMappingURL=createConditionalPluginFactory.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"createConditionalPluginFactory.js","sources":["../src/createConditionalPluginFactory.ts"],"sourcesContent":["import type { PluginFactory } from \"@webiny/plugins/types.js\";\n\nexport type Condition = () => boolean;\n\nexport const createConditionalPluginFactory = (\n condition: Condition,\n cb: PluginFactory\n): PluginFactory => {\n return () => {\n if (condition()) {\n return cb();\n }\n\n return Promise.resolve([]);\n };\n};\n"],"names":["createConditionalPluginFactory","condition","cb","Promise"],"mappings":"AAIO,MAAMA,iCAAiC,CAC1CC,WACAC,KAEO;QACH,IAAID,aACA,OAAOC;QAGX,OAAOC,QAAQ,OAAO,CAAC,EAAE;IAC7B"}
|
package/decorateContext.js
CHANGED
|
@@ -1,21 +1,12 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
...acc,
|
|
12
|
-
[key]: function (...args) {
|
|
13
|
-
// @ts-expect-error
|
|
14
|
-
return decorators[key](decoratedMethod.bind(decoratee))(...args);
|
|
15
|
-
}
|
|
16
|
-
};
|
|
17
|
-
}, decoratee);
|
|
18
|
-
};
|
|
19
|
-
exports.decorateContext = decorateContext;
|
|
1
|
+
const decorateContext = (decoratee, decorators)=>Object.keys(decorators).reduce((acc, key)=>{
|
|
2
|
+
const decoratedMethod = acc[key];
|
|
3
|
+
return {
|
|
4
|
+
...acc,
|
|
5
|
+
[key]: function(...args) {
|
|
6
|
+
return decorators[key](decoratedMethod.bind(decoratee))(...args);
|
|
7
|
+
}
|
|
8
|
+
};
|
|
9
|
+
}, decoratee);
|
|
10
|
+
export { decorateContext };
|
|
20
11
|
|
|
21
12
|
//# sourceMappingURL=decorateContext.js.map
|
package/decorateContext.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"decorateContext.js","sources":["../src/decorateContext.ts"],"sourcesContent":["type Decorators<TDecoratee> = {\n [K in keyof TDecoratee]?: (decoratee: TDecoratee[K]) => TDecoratee[K];\n};\n\nexport const decorateContext = <T extends Record<string, any>>(\n decoratee: T,\n decorators: Decorators<T>\n) => {\n return Object.keys(decorators).reduce((acc, key) => {\n const decoratedMethod = acc[key];\n\n return {\n ...acc,\n [key]: function (...args: any[]) {\n // @ts-expect-error\n return decorators[key](decoratedMethod.bind(decoratee))(...args);\n }\n };\n }, decoratee);\n};\n"],"names":["decorateContext","decoratee","decorators","Object","acc","key","decoratedMethod","args"],"mappings":"AAIO,MAAMA,kBAAkB,CAC3BC,WACAC,aAEOC,OAAO,IAAI,CAACD,YAAY,MAAM,CAAC,CAACE,KAAKC;QACxC,MAAMC,kBAAkBF,GAAG,CAACC,IAAI;QAEhC,OAAO;YACH,GAAGD,GAAG;YACN,CAACC,IAAI,EAAE,SAAU,GAAGE,IAAW;gBAE3B,OAAOL,UAAU,CAACG,IAAI,CAACC,gBAAgB,IAAI,CAACL,eAAeM;YAC/D;QACJ;IACJ,GAAGN"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
type DateOps<T> = {
|
|
2
|
+
"": T;
|
|
3
|
+
_gt: T;
|
|
4
|
+
_gte: T;
|
|
5
|
+
_lt: T;
|
|
6
|
+
_lte: T;
|
|
7
|
+
_between: [T, T];
|
|
8
|
+
};
|
|
9
|
+
export type DateInterfaceGenerator<Name extends string> = {
|
|
10
|
+
[K in keyof DateOps<Date> as `${Name}${K}`]?: DateOps<Date>[K];
|
|
11
|
+
};
|
|
12
|
+
export type DateStringInterfaceGenerator<Name extends string> = {
|
|
13
|
+
[K in keyof DateOps<string> as `${Name}${K}`]?: DateOps<string>[K];
|
|
14
|
+
};
|
|
15
|
+
export {};
|
|
File without changes
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
type IdOperators<TType extends string> = {
|
|
2
|
+
"": TType;
|
|
3
|
+
_not: TType;
|
|
4
|
+
_in: TType[];
|
|
5
|
+
_not_in: TType[];
|
|
6
|
+
};
|
|
7
|
+
export type IdInterfaceGenerator<TName extends string, TType extends string = string> = {
|
|
8
|
+
[K in keyof IdOperators<TType> as `${TName}${K}`]?: IdOperators<TType>[K];
|
|
9
|
+
};
|
|
10
|
+
type IdMixedOperators = {
|
|
11
|
+
"": string;
|
|
12
|
+
_not: string;
|
|
13
|
+
_in: string[];
|
|
14
|
+
_not_in: string[];
|
|
15
|
+
_gt: number | string;
|
|
16
|
+
_gte: number | string;
|
|
17
|
+
_lt: number | string;
|
|
18
|
+
_lte: number | string;
|
|
19
|
+
};
|
|
20
|
+
export type IdMixedInterfaceGenerator<TName extends string> = {
|
|
21
|
+
[K in keyof IdMixedOperators as `${TName}${K}`]?: IdMixedOperators[K];
|
|
22
|
+
};
|
|
23
|
+
export {};
|
|
File without changes
|
|
File without changes
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export type { IdInterfaceGenerator, IdMixedInterfaceGenerator } from "./id.js";
|
|
2
|
+
export type { DateInterfaceGenerator, DateStringInterfaceGenerator } from "./date.js";
|
|
3
|
+
export type { IdentityInterfaceGenerator } from "./identity.js";
|
|
4
|
+
export type { NumericInterfaceGenerator } from "./numeric.js";
|
|
5
|
+
export type { TruthfulInterfaceGenerator } from "./truthful.js";
|
|
6
|
+
export type { TextInterfaceGenerator } from "./text.js";
|
|
File without changes
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
type Numeric = {
|
|
2
|
+
"": number;
|
|
3
|
+
_gt: number;
|
|
4
|
+
_gte: number;
|
|
5
|
+
_lt: number;
|
|
6
|
+
_lte: number;
|
|
7
|
+
_between: [number, number];
|
|
8
|
+
};
|
|
9
|
+
export type NumericInterfaceGenerator<Name extends string> = {
|
|
10
|
+
[K in keyof Numeric as `${Name}${K}`]?: Numeric[K];
|
|
11
|
+
};
|
|
12
|
+
export {};
|
|
File without changes
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
type TextOperators<TType extends string> = {
|
|
2
|
+
"": TType;
|
|
3
|
+
_not: TType;
|
|
4
|
+
_in: TType[];
|
|
5
|
+
_not_in: TType[];
|
|
6
|
+
_contains: TType;
|
|
7
|
+
};
|
|
8
|
+
export type TextInterfaceGenerator<TName extends string, TType extends string = string> = {
|
|
9
|
+
[K in keyof TextOperators<TType> as `${TName}${K}`]?: TextOperators<TType>[K];
|
|
10
|
+
};
|
|
11
|
+
export {};
|
|
File without changes
|
|
File without changes
|
package/index.d.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
export * from "./Context";
|
|
2
|
-
export * from "./
|
|
3
|
-
export * from "./
|
|
4
|
-
export * from "./
|
|
5
|
-
export * from "./
|
|
6
|
-
export * from "./plugins/ContextPlugin";
|
|
1
|
+
export * from "./Context.js";
|
|
2
|
+
export * from "./decorateContext.js";
|
|
3
|
+
export * from "./createConditionalPluginFactory.js";
|
|
4
|
+
export * from "./plugins/ContextPlugin.js";
|
|
5
|
+
export * from "./helpers/InterfaceGenerator/index.js";
|
package/index.js
CHANGED
|
@@ -1,73 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
var _Context = require("./Context");
|
|
7
|
-
Object.keys(_Context).forEach(function (key) {
|
|
8
|
-
if (key === "default" || key === "__esModule") return;
|
|
9
|
-
if (key in exports && exports[key] === _Context[key]) return;
|
|
10
|
-
Object.defineProperty(exports, key, {
|
|
11
|
-
enumerable: true,
|
|
12
|
-
get: function () {
|
|
13
|
-
return _Context[key];
|
|
14
|
-
}
|
|
15
|
-
});
|
|
16
|
-
});
|
|
17
|
-
var _CompressorPlugin = require("./plugins/CompressorPlugin");
|
|
18
|
-
Object.keys(_CompressorPlugin).forEach(function (key) {
|
|
19
|
-
if (key === "default" || key === "__esModule") return;
|
|
20
|
-
if (key in exports && exports[key] === _CompressorPlugin[key]) return;
|
|
21
|
-
Object.defineProperty(exports, key, {
|
|
22
|
-
enumerable: true,
|
|
23
|
-
get: function () {
|
|
24
|
-
return _CompressorPlugin[key];
|
|
25
|
-
}
|
|
26
|
-
});
|
|
27
|
-
});
|
|
28
|
-
var _decorateContext = require("./decorateContext");
|
|
29
|
-
Object.keys(_decorateContext).forEach(function (key) {
|
|
30
|
-
if (key === "default" || key === "__esModule") return;
|
|
31
|
-
if (key in exports && exports[key] === _decorateContext[key]) return;
|
|
32
|
-
Object.defineProperty(exports, key, {
|
|
33
|
-
enumerable: true,
|
|
34
|
-
get: function () {
|
|
35
|
-
return _decorateContext[key];
|
|
36
|
-
}
|
|
37
|
-
});
|
|
38
|
-
});
|
|
39
|
-
var _createConditionalPluginFactory = require("./createConditionalPluginFactory");
|
|
40
|
-
Object.keys(_createConditionalPluginFactory).forEach(function (key) {
|
|
41
|
-
if (key === "default" || key === "__esModule") return;
|
|
42
|
-
if (key in exports && exports[key] === _createConditionalPluginFactory[key]) return;
|
|
43
|
-
Object.defineProperty(exports, key, {
|
|
44
|
-
enumerable: true,
|
|
45
|
-
get: function () {
|
|
46
|
-
return _createConditionalPluginFactory[key];
|
|
47
|
-
}
|
|
48
|
-
});
|
|
49
|
-
});
|
|
50
|
-
var _ServiceDiscovery = require("./ServiceDiscovery");
|
|
51
|
-
Object.keys(_ServiceDiscovery).forEach(function (key) {
|
|
52
|
-
if (key === "default" || key === "__esModule") return;
|
|
53
|
-
if (key in exports && exports[key] === _ServiceDiscovery[key]) return;
|
|
54
|
-
Object.defineProperty(exports, key, {
|
|
55
|
-
enumerable: true,
|
|
56
|
-
get: function () {
|
|
57
|
-
return _ServiceDiscovery[key];
|
|
58
|
-
}
|
|
59
|
-
});
|
|
60
|
-
});
|
|
61
|
-
var _ContextPlugin = require("./plugins/ContextPlugin");
|
|
62
|
-
Object.keys(_ContextPlugin).forEach(function (key) {
|
|
63
|
-
if (key === "default" || key === "__esModule") return;
|
|
64
|
-
if (key in exports && exports[key] === _ContextPlugin[key]) return;
|
|
65
|
-
Object.defineProperty(exports, key, {
|
|
66
|
-
enumerable: true,
|
|
67
|
-
get: function () {
|
|
68
|
-
return _ContextPlugin[key];
|
|
69
|
-
}
|
|
70
|
-
});
|
|
71
|
-
});
|
|
72
|
-
|
|
73
|
-
//# sourceMappingURL=index.js.map
|
|
1
|
+
export * from "./Context.js";
|
|
2
|
+
export * from "./decorateContext.js";
|
|
3
|
+
export * from "./createConditionalPluginFactory.js";
|
|
4
|
+
export * from "./plugins/ContextPlugin.js";
|
|
5
|
+
export * from "./helpers/InterfaceGenerator/index.js";
|
package/package.json
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@webiny/api",
|
|
3
|
-
"version": "0.0.0-unstable.
|
|
4
|
-
"
|
|
3
|
+
"version": "0.0.0-unstable.9f53ea597d",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"exports": {
|
|
6
|
+
".": "./index.js",
|
|
7
|
+
"./*": "./*"
|
|
8
|
+
},
|
|
5
9
|
"repository": {
|
|
6
10
|
"type": "git",
|
|
7
11
|
"url": "https://github.com/webiny/webiny-js.git"
|
|
@@ -12,22 +16,22 @@
|
|
|
12
16
|
],
|
|
13
17
|
"license": "MIT",
|
|
14
18
|
"dependencies": {
|
|
15
|
-
"@webiny/
|
|
16
|
-
"@webiny/plugins": "0.0.0-unstable.
|
|
17
|
-
"@webiny/utils": "0.0.0-unstable.
|
|
19
|
+
"@webiny/di": "1.0.2",
|
|
20
|
+
"@webiny/plugins": "0.0.0-unstable.9f53ea597d",
|
|
21
|
+
"@webiny/utils": "0.0.0-unstable.9f53ea597d"
|
|
18
22
|
},
|
|
19
23
|
"devDependencies": {
|
|
20
|
-
"@webiny/
|
|
21
|
-
"
|
|
22
|
-
"
|
|
24
|
+
"@webiny/build-tools": "0.0.0-unstable.9f53ea597d",
|
|
25
|
+
"@webiny/project-utils": "0.0.0-unstable.9f53ea597d",
|
|
26
|
+
"rimraf": "6.1.3",
|
|
27
|
+
"typescript": "7.0.2",
|
|
28
|
+
"vitest": "4.1.10"
|
|
23
29
|
},
|
|
24
30
|
"publishConfig": {
|
|
25
|
-
"access": "public"
|
|
26
|
-
"directory": "dist"
|
|
27
|
-
},
|
|
28
|
-
"scripts": {
|
|
29
|
-
"build": "node ../cli/bin.js run build",
|
|
30
|
-
"watch": "node ../cli/bin.js run watch"
|
|
31
|
+
"access": "public"
|
|
31
32
|
},
|
|
32
|
-
"gitHead": "
|
|
33
|
+
"gitHead": "8476da73b653c89cc1474d968baf55c1b0ae0e5f",
|
|
34
|
+
"webiny": {
|
|
35
|
+
"publishFrom": "dist"
|
|
36
|
+
}
|
|
33
37
|
}
|
|
@@ -1,30 +1,22 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
}
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
this.benchmark.enable();
|
|
20
|
-
}
|
|
21
|
-
disable() {
|
|
22
|
-
this.benchmark.disable();
|
|
23
|
-
}
|
|
24
|
-
async measure(name, cb) {
|
|
25
|
-
return this.benchmark.measure(name, cb);
|
|
26
|
-
}
|
|
1
|
+
import { Plugin } from "@webiny/plugins";
|
|
2
|
+
class BenchmarkPlugin extends Plugin {
|
|
3
|
+
static{
|
|
4
|
+
this.type = "context.benchmark";
|
|
5
|
+
}
|
|
6
|
+
constructor(benchmark){
|
|
7
|
+
super(), this.name = "context.benchmark";
|
|
8
|
+
this.benchmark = benchmark;
|
|
9
|
+
}
|
|
10
|
+
enable() {
|
|
11
|
+
this.benchmark.enable();
|
|
12
|
+
}
|
|
13
|
+
disable() {
|
|
14
|
+
this.benchmark.disable();
|
|
15
|
+
}
|
|
16
|
+
async measure(name, cb) {
|
|
17
|
+
return this.benchmark.measure(name, cb);
|
|
18
|
+
}
|
|
27
19
|
}
|
|
28
|
-
|
|
20
|
+
export { BenchmarkPlugin };
|
|
29
21
|
|
|
30
22
|
//# sourceMappingURL=BenchmarkPlugin.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"plugins/BenchmarkPlugin.js","sources":["../../src/plugins/BenchmarkPlugin.ts"],"sourcesContent":["import { Plugin } from \"@webiny/plugins\";\nimport type { Benchmark } from \"~/types.js\";\n\n/**\n * This plugin should be initialized only once per context, hence the name of the plugin.\n */\nexport class BenchmarkPlugin extends Plugin {\n public static override readonly type: string = \"context.benchmark\";\n public override name = \"context.benchmark\";\n public readonly benchmark: Benchmark;\n\n public constructor(benchmark: Benchmark) {\n super();\n this.benchmark = benchmark;\n }\n\n public enable(): void {\n this.benchmark.enable();\n }\n\n public disable(): void {\n this.benchmark.disable();\n }\n\n public async measure<T = any>(name: string, cb: () => Promise<T>): Promise<T> {\n return this.benchmark.measure<T>(name, cb);\n }\n}\n"],"names":["BenchmarkPlugin","Plugin","benchmark","name","cb"],"mappings":";AAMO,MAAMA,wBAAwBC;;aACD,IAAI,GAAW;;IAI/C,YAAmBC,SAAoB,CAAE;QACrC,KAAK,SAJO,IAAI,GAAG;QAKnB,IAAI,CAAC,SAAS,GAAGA;IACrB;IAEO,SAAe;QAClB,IAAI,CAAC,SAAS,CAAC,MAAM;IACzB;IAEO,UAAgB;QACnB,IAAI,CAAC,SAAS,CAAC,OAAO;IAC1B;IAEA,MAAa,QAAiBC,IAAY,EAAEC,EAAoB,EAAc;QAC1E,OAAO,IAAI,CAAC,SAAS,CAAC,OAAO,CAAID,MAAMC;IAC3C;AACJ"}
|
package/plugins/ContextPlugin.js
CHANGED
|
@@ -1,31 +1,22 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
}
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
}
|
|
14
|
-
async apply(context) {
|
|
15
|
-
if (typeof this._callable !== "function") {
|
|
16
|
-
throw Error(`Missing callable in ContextPlugin! Either pass a callable to plugin constructor or extend the plugin and override the "apply" method.`);
|
|
1
|
+
import { Plugin } from "@webiny/plugins";
|
|
2
|
+
class ContextPlugin extends Plugin {
|
|
3
|
+
static{
|
|
4
|
+
this.type = "context";
|
|
5
|
+
}
|
|
6
|
+
constructor(callable){
|
|
7
|
+
super();
|
|
8
|
+
this._callable = callable;
|
|
9
|
+
}
|
|
10
|
+
async apply(context) {
|
|
11
|
+
if ("function" != typeof this._callable) throw Error('Missing callable in ContextPlugin! Either pass a callable to plugin constructor or extend the plugin and override the "apply" method.');
|
|
12
|
+
return this._callable(context);
|
|
17
13
|
}
|
|
18
|
-
return this._callable(context);
|
|
19
|
-
}
|
|
20
14
|
}
|
|
21
|
-
|
|
22
|
-
const
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
plugin.name = options.name;
|
|
26
|
-
}
|
|
27
|
-
return plugin;
|
|
15
|
+
const createContextPlugin = (callable, options)=>{
|
|
16
|
+
const plugin = new ContextPlugin(callable);
|
|
17
|
+
if (options && options.name) plugin.name = options.name;
|
|
18
|
+
return plugin;
|
|
28
19
|
};
|
|
29
|
-
|
|
20
|
+
export { ContextPlugin, createContextPlugin };
|
|
30
21
|
|
|
31
22
|
//# sourceMappingURL=ContextPlugin.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"plugins/ContextPlugin.js","sources":["../../src/plugins/ContextPlugin.ts"],"sourcesContent":["import { Plugin } from \"@webiny/plugins\";\nimport type { Context } from \"~/types.js\";\n\nexport interface ContextPluginCallable<T extends Context = Context> {\n (context: T): void | Promise<void>;\n}\n\nexport class ContextPlugin<T extends Context = Context> extends Plugin {\n public static override readonly type: string = \"context\";\n private readonly _callable: ContextPluginCallable<T>;\n\n constructor(callable: ContextPluginCallable<T>) {\n super();\n this._callable = callable;\n }\n\n public async apply(context: T): Promise<void> {\n if (typeof this._callable !== \"function\") {\n throw Error(\n `Missing callable in ContextPlugin! Either pass a callable to plugin constructor or extend the plugin and override the \"apply\" method.`\n );\n }\n\n return this._callable(context);\n }\n}\n\ninterface ContextPluginOptions {\n name?: string;\n}\n\nexport const createContextPlugin = <T extends Context = Context>(\n callable: ContextPluginCallable<T>,\n options?: ContextPluginOptions\n): ContextPlugin<T> => {\n const plugin = new ContextPlugin<T>(callable);\n if (options && options.name) {\n plugin.name = options.name;\n }\n return plugin;\n};\n"],"names":["ContextPlugin","Plugin","callable","context","Error","createContextPlugin","options","plugin"],"mappings":";AAOO,MAAMA,sBAAmDC;;aAC5B,IAAI,GAAW;;IAG/C,YAAYC,QAAkC,CAAE;QAC5C,KAAK;QACL,IAAI,CAAC,SAAS,GAAGA;IACrB;IAEA,MAAa,MAAMC,OAAU,EAAiB;QAC1C,IAAI,AAA0B,cAA1B,OAAO,IAAI,CAAC,SAAS,EACrB,MAAMC,MACF;QAIR,OAAO,IAAI,CAAC,SAAS,CAACD;IAC1B;AACJ;AAMO,MAAME,sBAAsB,CAC/BH,UACAI;IAEA,MAAMC,SAAS,IAAIP,cAAiBE;IACpC,IAAII,WAAWA,QAAQ,IAAI,EACvBC,OAAO,IAAI,GAAGD,QAAQ,IAAI;IAE9B,OAAOC;AACX"}
|
package/types.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
+
import type { Container } from "@webiny/di";
|
|
1
2
|
import type { PluginsContainer } from "@webiny/plugins";
|
|
2
|
-
import type { ICompressor } from "@webiny/utils/compression/Compressor";
|
|
3
3
|
export type GenericRecord<K extends PropertyKey = PropertyKey, V = any> = Record<K, V>;
|
|
4
4
|
export type NonEmptyArray<T> = [T, ...T[]];
|
|
5
5
|
export type PossiblyUndefinedProperties<T> = {
|
|
@@ -45,6 +45,10 @@ export interface Benchmark {
|
|
|
45
45
|
*/
|
|
46
46
|
export interface Context {
|
|
47
47
|
plugins: PluginsContainer;
|
|
48
|
+
/**
|
|
49
|
+
* @internal
|
|
50
|
+
*/
|
|
51
|
+
container: Container;
|
|
48
52
|
readonly WEBINY_VERSION: string;
|
|
49
53
|
/**
|
|
50
54
|
* Not to be used outside of Webiny internal code.
|
|
@@ -68,17 +72,8 @@ export interface Context {
|
|
|
68
72
|
* @internal
|
|
69
73
|
*/
|
|
70
74
|
getResult: () => void;
|
|
71
|
-
/**
|
|
72
|
-
* Wait for property to be defined on the object and then execute the callable.
|
|
73
|
-
* In case of multiple objects defined, wait for all of them.
|
|
74
|
-
*/
|
|
75
|
-
waitFor: <T extends Context = Context>(obj: string[] | string, cb: (context: T) => void) => void;
|
|
76
75
|
/**
|
|
77
76
|
* Benchmark instance to help determine possible bugs and slow code.
|
|
78
77
|
*/
|
|
79
78
|
benchmark: Benchmark;
|
|
80
|
-
/**
|
|
81
|
-
* Compressor instance to compress and decompress the data.
|
|
82
|
-
*/
|
|
83
|
-
compressor: ICompressor;
|
|
84
79
|
}
|
package/types.js
CHANGED
package/ServiceDiscovery.d.ts
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import type { DynamoDBDocument } from "@webiny/aws-sdk/client-dynamodb";
|
|
2
|
-
import type { GenericRecord } from "./types";
|
|
3
|
-
type Manifest = GenericRecord<string>;
|
|
4
|
-
export declare class ServiceDiscovery {
|
|
5
|
-
static setDocumentClient(client: Pick<DynamoDBDocument, "send">): void;
|
|
6
|
-
static load(): Promise<Manifest | undefined>;
|
|
7
|
-
/**
|
|
8
|
-
* Should be used for testing purposes only!
|
|
9
|
-
*/
|
|
10
|
-
static clear(): void;
|
|
11
|
-
}
|
|
12
|
-
export {};
|
package/ServiceDiscovery.js
DELETED
|
@@ -1,77 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.ServiceDiscovery = void 0;
|
|
7
|
-
var _clientDynamodb = require("@webiny/aws-sdk/client-dynamodb");
|
|
8
|
-
class ServiceManifestLoader {
|
|
9
|
-
manifest = undefined;
|
|
10
|
-
async load() {
|
|
11
|
-
if (this.manifest) {
|
|
12
|
-
return this.manifest;
|
|
13
|
-
}
|
|
14
|
-
const manifests = await this.loadManifests();
|
|
15
|
-
if (!manifests) {
|
|
16
|
-
return undefined;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
/**
|
|
20
|
-
* Service manifests are already merged by unique names in the database, so we only need to construct
|
|
21
|
-
* a final object containing all manifests by name.
|
|
22
|
-
*/
|
|
23
|
-
this.manifest = manifests.reduce((acc, manifest) => {
|
|
24
|
-
return {
|
|
25
|
-
...acc,
|
|
26
|
-
[manifest.name]: manifest.manifest
|
|
27
|
-
};
|
|
28
|
-
}, {});
|
|
29
|
-
return this.manifest;
|
|
30
|
-
}
|
|
31
|
-
setDocumentClient(client) {
|
|
32
|
-
this.client = client;
|
|
33
|
-
}
|
|
34
|
-
clear() {
|
|
35
|
-
this.manifest = undefined;
|
|
36
|
-
}
|
|
37
|
-
async loadManifests() {
|
|
38
|
-
const client = this.client || (0, _clientDynamodb.getDocumentClient)();
|
|
39
|
-
const {
|
|
40
|
-
Items
|
|
41
|
-
} = await client.send(new _clientDynamodb.QueryCommand({
|
|
42
|
-
TableName: String(process.env.DB_TABLE),
|
|
43
|
-
IndexName: "GSI1",
|
|
44
|
-
KeyConditionExpression: "GSI1_PK = :GSI1_PK AND GSI1_SK > :GSI1_SK",
|
|
45
|
-
ExpressionAttributeValues: {
|
|
46
|
-
":GSI1_PK": {
|
|
47
|
-
S: `SERVICE_MANIFESTS`
|
|
48
|
-
},
|
|
49
|
-
":GSI1_SK": {
|
|
50
|
-
S: " "
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
}));
|
|
54
|
-
if (!Array.isArray(Items)) {
|
|
55
|
-
return undefined;
|
|
56
|
-
}
|
|
57
|
-
return Items.map(item => (0, _clientDynamodb.unmarshall)(item).data);
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
const serviceManifestLoader = new ServiceManifestLoader();
|
|
61
|
-
class ServiceDiscovery {
|
|
62
|
-
static setDocumentClient(client) {
|
|
63
|
-
serviceManifestLoader.setDocumentClient(client);
|
|
64
|
-
}
|
|
65
|
-
static async load() {
|
|
66
|
-
return serviceManifestLoader.load();
|
|
67
|
-
}
|
|
68
|
-
/**
|
|
69
|
-
* Should be used for testing purposes only!
|
|
70
|
-
*/
|
|
71
|
-
static clear() {
|
|
72
|
-
serviceManifestLoader.clear();
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
exports.ServiceDiscovery = ServiceDiscovery;
|
|
76
|
-
|
|
77
|
-
//# sourceMappingURL=ServiceDiscovery.js.map
|
package/ServiceDiscovery.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"names":["_clientDynamodb","require","ServiceManifestLoader","manifest","undefined","load","manifests","loadManifests","reduce","acc","name","setDocumentClient","client","clear","getDocumentClient","Items","send","QueryCommand","TableName","String","process","env","DB_TABLE","IndexName","KeyConditionExpression","ExpressionAttributeValues","S","Array","isArray","map","item","unmarshall","data","serviceManifestLoader","ServiceDiscovery","exports"],"sources":["ServiceDiscovery.ts"],"sourcesContent":["import type { DynamoDBDocument } from \"@webiny/aws-sdk/client-dynamodb\";\nimport { getDocumentClient, QueryCommand, unmarshall } from \"@webiny/aws-sdk/client-dynamodb\";\nimport type { GenericRecord } from \"~/types\";\n\ninterface ServiceManifest {\n name: string;\n manifest: Manifest;\n}\n\ntype Manifest = GenericRecord<string>;\n\nclass ServiceManifestLoader {\n private client: Pick<DynamoDBDocument, \"send\"> | undefined;\n private manifest: Manifest | undefined = undefined;\n\n public async load() {\n if (this.manifest) {\n return this.manifest;\n }\n\n const manifests = await this.loadManifests();\n\n if (!manifests) {\n return undefined;\n }\n\n /**\n * Service manifests are already merged by unique names in the database, so we only need to construct\n * a final object containing all manifests by name.\n */\n this.manifest = manifests.reduce((acc, manifest) => {\n return { ...acc, [manifest.name]: manifest.manifest };\n }, {});\n\n return this.manifest;\n }\n\n public setDocumentClient(client: Pick<DynamoDBDocument, \"send\">) {\n this.client = client;\n }\n\n public clear(): void {\n this.manifest = undefined;\n }\n\n private async loadManifests(): Promise<ServiceManifest[] | undefined> {\n const client = this.client || getDocumentClient();\n const { Items } = await client.send(\n new QueryCommand({\n TableName: String(process.env.DB_TABLE),\n IndexName: \"GSI1\",\n KeyConditionExpression: \"GSI1_PK = :GSI1_PK AND GSI1_SK > :GSI1_SK\",\n ExpressionAttributeValues: {\n \":GSI1_PK\": { S: `SERVICE_MANIFESTS` },\n \":GSI1_SK\": { S: \" \" }\n }\n })\n );\n\n if (!Array.isArray(Items)) {\n return undefined;\n }\n\n return Items.map(item => unmarshall(item).data);\n }\n}\n\nconst serviceManifestLoader = new ServiceManifestLoader();\n\nexport class ServiceDiscovery {\n static setDocumentClient(client: Pick<DynamoDBDocument, \"send\">): void {\n serviceManifestLoader.setDocumentClient(client);\n }\n\n static async load() {\n return serviceManifestLoader.load();\n }\n /**\n * Should be used for testing purposes only!\n */\n static clear(): void {\n serviceManifestLoader.clear();\n }\n}\n"],"mappings":";;;;;;AACA,IAAAA,eAAA,GAAAC,OAAA;AAUA,MAAMC,qBAAqB,CAAC;EAEhBC,QAAQ,GAAyBC,SAAS;EAElD,MAAaC,IAAIA,CAAA,EAAG;IAChB,IAAI,IAAI,CAACF,QAAQ,EAAE;MACf,OAAO,IAAI,CAACA,QAAQ;IACxB;IAEA,MAAMG,SAAS,GAAG,MAAM,IAAI,CAACC,aAAa,CAAC,CAAC;IAE5C,IAAI,CAACD,SAAS,EAAE;MACZ,OAAOF,SAAS;IACpB;;IAEA;AACR;AACA;AACA;IACQ,IAAI,CAACD,QAAQ,GAAGG,SAAS,CAACE,MAAM,CAAC,CAACC,GAAG,EAAEN,QAAQ,KAAK;MAChD,OAAO;QAAE,GAAGM,GAAG;QAAE,CAACN,QAAQ,CAACO,IAAI,GAAGP,QAAQ,CAACA;MAAS,CAAC;IACzD,CAAC,EAAE,CAAC,CAAC,CAAC;IAEN,OAAO,IAAI,CAACA,QAAQ;EACxB;EAEOQ,iBAAiBA,CAACC,MAAsC,EAAE;IAC7D,IAAI,CAACA,MAAM,GAAGA,MAAM;EACxB;EAEOC,KAAKA,CAAA,EAAS;IACjB,IAAI,CAACV,QAAQ,GAAGC,SAAS;EAC7B;EAEA,MAAcG,aAAaA,CAAA,EAA2C;IAClE,MAAMK,MAAM,GAAG,IAAI,CAACA,MAAM,IAAI,IAAAE,iCAAiB,EAAC,CAAC;IACjD,MAAM;MAAEC;IAAM,CAAC,GAAG,MAAMH,MAAM,CAACI,IAAI,CAC/B,IAAIC,4BAAY,CAAC;MACbC,SAAS,EAAEC,MAAM,CAACC,OAAO,CAACC,GAAG,CAACC,QAAQ,CAAC;MACvCC,SAAS,EAAE,MAAM;MACjBC,sBAAsB,EAAE,2CAA2C;MACnEC,yBAAyB,EAAE;QACvB,UAAU,EAAE;UAAEC,CAAC,EAAE;QAAoB,CAAC;QACtC,UAAU,EAAE;UAAEA,CAAC,EAAE;QAAI;MACzB;IACJ,CAAC,CACL,CAAC;IAED,IAAI,CAACC,KAAK,CAACC,OAAO,CAACb,KAAK,CAAC,EAAE;MACvB,OAAOX,SAAS;IACpB;IAEA,OAAOW,KAAK,CAACc,GAAG,CAACC,IAAI,IAAI,IAAAC,0BAAU,EAACD,IAAI,CAAC,CAACE,IAAI,CAAC;EACnD;AACJ;AAEA,MAAMC,qBAAqB,GAAG,IAAI/B,qBAAqB,CAAC,CAAC;AAElD,MAAMgC,gBAAgB,CAAC;EAC1B,OAAOvB,iBAAiBA,CAACC,MAAsC,EAAQ;IACnEqB,qBAAqB,CAACtB,iBAAiB,CAACC,MAAM,CAAC;EACnD;EAEA,aAAaP,IAAIA,CAAA,EAAG;IAChB,OAAO4B,qBAAqB,CAAC5B,IAAI,CAAC,CAAC;EACvC;EACA;AACJ;AACA;EACI,OAAOQ,KAAKA,CAAA,EAAS;IACjBoB,qBAAqB,CAACpB,KAAK,CAAC,CAAC;EACjC;AACJ;AAACsB,OAAA,CAAAD,gBAAA,GAAAA,gBAAA","ignoreList":[]}
|
package/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"names":["_Context","require","Object","keys","forEach","key","exports","defineProperty","enumerable","get","_CompressorPlugin","_decorateContext","_createConditionalPluginFactory","_ServiceDiscovery","_ContextPlugin"],"sources":["index.ts"],"sourcesContent":["export * from \"./Context\";\nexport * from \"./plugins/CompressorPlugin\";\nexport * from \"./decorateContext\";\nexport * from \"./createConditionalPluginFactory\";\nexport * from \"./ServiceDiscovery\";\nexport * from \"./plugins/ContextPlugin\";\n"],"mappings":";;;;;AAAA,IAAAA,QAAA,GAAAC,OAAA;AAAAC,MAAA,CAAAC,IAAA,CAAAH,QAAA,EAAAI,OAAA,WAAAC,GAAA;EAAA,IAAAA,GAAA,kBAAAA,GAAA;EAAA,IAAAA,GAAA,IAAAC,OAAA,IAAAA,OAAA,CAAAD,GAAA,MAAAL,QAAA,CAAAK,GAAA;EAAAH,MAAA,CAAAK,cAAA,CAAAD,OAAA,EAAAD,GAAA;IAAAG,UAAA;IAAAC,GAAA,WAAAA,CAAA;MAAA,OAAAT,QAAA,CAAAK,GAAA;IAAA;EAAA;AAAA;AACA,IAAAK,iBAAA,GAAAT,OAAA;AAAAC,MAAA,CAAAC,IAAA,CAAAO,iBAAA,EAAAN,OAAA,WAAAC,GAAA;EAAA,IAAAA,GAAA,kBAAAA,GAAA;EAAA,IAAAA,GAAA,IAAAC,OAAA,IAAAA,OAAA,CAAAD,GAAA,MAAAK,iBAAA,CAAAL,GAAA;EAAAH,MAAA,CAAAK,cAAA,CAAAD,OAAA,EAAAD,GAAA;IAAAG,UAAA;IAAAC,GAAA,WAAAA,CAAA;MAAA,OAAAC,iBAAA,CAAAL,GAAA;IAAA;EAAA;AAAA;AACA,IAAAM,gBAAA,GAAAV,OAAA;AAAAC,MAAA,CAAAC,IAAA,CAAAQ,gBAAA,EAAAP,OAAA,WAAAC,GAAA;EAAA,IAAAA,GAAA,kBAAAA,GAAA;EAAA,IAAAA,GAAA,IAAAC,OAAA,IAAAA,OAAA,CAAAD,GAAA,MAAAM,gBAAA,CAAAN,GAAA;EAAAH,MAAA,CAAAK,cAAA,CAAAD,OAAA,EAAAD,GAAA;IAAAG,UAAA;IAAAC,GAAA,WAAAA,CAAA;MAAA,OAAAE,gBAAA,CAAAN,GAAA;IAAA;EAAA;AAAA;AACA,IAAAO,+BAAA,GAAAX,OAAA;AAAAC,MAAA,CAAAC,IAAA,CAAAS,+BAAA,EAAAR,OAAA,WAAAC,GAAA;EAAA,IAAAA,GAAA,kBAAAA,GAAA;EAAA,IAAAA,GAAA,IAAAC,OAAA,IAAAA,OAAA,CAAAD,GAAA,MAAAO,+BAAA,CAAAP,GAAA;EAAAH,MAAA,CAAAK,cAAA,CAAAD,OAAA,EAAAD,GAAA;IAAAG,UAAA;IAAAC,GAAA,WAAAA,CAAA;MAAA,OAAAG,+BAAA,CAAAP,GAAA;IAAA;EAAA;AAAA;AACA,IAAAQ,iBAAA,GAAAZ,OAAA;AAAAC,MAAA,CAAAC,IAAA,CAAAU,iBAAA,EAAAT,OAAA,WAAAC,GAAA;EAAA,IAAAA,GAAA,kBAAAA,GAAA;EAAA,IAAAA,GAAA,IAAAC,OAAA,IAAAA,OAAA,CAAAD,GAAA,MAAAQ,iBAAA,CAAAR,GAAA;EAAAH,MAAA,CAAAK,cAAA,CAAAD,OAAA,EAAAD,GAAA;IAAAG,UAAA;IAAAC,GAAA,WAAAA,CAAA;MAAA,OAAAI,iBAAA,CAAAR,GAAA;IAAA;EAAA;AAAA;AACA,IAAAS,cAAA,GAAAb,OAAA;AAAAC,MAAA,CAAAC,IAAA,CAAAW,cAAA,EAAAV,OAAA,WAAAC,GAAA;EAAA,IAAAA,GAAA,kBAAAA,GAAA;EAAA,IAAAA,GAAA,IAAAC,OAAA,IAAAA,OAAA,CAAAD,GAAA,MAAAS,cAAA,CAAAT,GAAA;EAAAH,MAAA,CAAAK,cAAA,CAAAD,OAAA,EAAAD,GAAA;IAAAG,UAAA;IAAAC,GAAA,WAAAA,CAAA;MAAA,OAAAK,cAAA,CAAAT,GAAA;IAAA;EAAA;AAAA","ignoreList":[]}
|