@webiny/api 6.4.5-beta.0 → 6.6.0-alpha.0
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/Context.d.ts +1 -1
- package/Context.js +1 -1
- package/Context.js.map +1 -1
- package/abstractions.d.ts +5 -0
- package/abstractions.js +5 -0
- package/abstractions.js.map +1 -0
- package/index.d.ts +1 -2
- package/index.js +1 -2
- package/package.json +7 -8
- package/types.d.ts +1 -1
- package/ServiceDiscovery.d.ts +0 -12
- package/ServiceDiscovery.js +0 -55
- package/ServiceDiscovery.js.map +0 -1
- package/plugins/ContextPlugin.d.ts +0 -16
- package/plugins/ContextPlugin.js +0 -22
- package/plugins/ContextPlugin.js.map +0 -1
package/Context.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ import type { Context as ContextInterface } from "./types.js";
|
|
|
2
2
|
import { PluginsContainer } from "@webiny/plugins";
|
|
3
3
|
import type { PluginCollection } from "@webiny/plugins/types.js";
|
|
4
4
|
import { Benchmark } from "./Benchmark.js";
|
|
5
|
-
import { Container } from "@webiny/
|
|
5
|
+
import { Container } from "@webiny/feature/api";
|
|
6
6
|
export interface ContextParams {
|
|
7
7
|
plugins?: PluginCollection | PluginsContainer;
|
|
8
8
|
WEBINY_VERSION: string;
|
package/Context.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { PluginsContainer } from "@webiny/plugins";
|
|
2
2
|
import { Benchmark } from "./Benchmark.js";
|
|
3
3
|
import { BenchmarkPlugin } from "./plugins/BenchmarkPlugin.js";
|
|
4
|
-
import { Container } from "@webiny/
|
|
4
|
+
import { Container } from "@webiny/feature/api";
|
|
5
5
|
import { CompressionFeature } from "@webiny/utils/features/compression/feature.js";
|
|
6
6
|
const getPluginsContainer = (plugins)=>{
|
|
7
7
|
if (!plugins) return new PluginsContainer();
|
package/Context.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Context.js","sources":["../src/Context.ts"],"sourcesContent":["import type { Context as ContextInterface } from \"~/types.js\";\nimport { PluginsContainer } from \"@webiny/plugins\";\nimport type { PluginCollection } from \"@webiny/plugins/types.js\";\nimport { Benchmark } from \"~/Benchmark.js\";\nimport { BenchmarkPlugin } from \"~/plugins/BenchmarkPlugin.js\";\nimport { Container } from \"@webiny/
|
|
1
|
+
{"version":3,"file":"Context.js","sources":["../src/Context.ts"],"sourcesContent":["import type { Context as ContextInterface } from \"~/types.js\";\nimport { PluginsContainer } from \"@webiny/plugins\";\nimport type { PluginCollection } from \"@webiny/plugins/types.js\";\nimport { Benchmark } from \"~/Benchmark.js\";\nimport { BenchmarkPlugin } from \"~/plugins/BenchmarkPlugin.js\";\nimport { Container } from \"@webiny/feature/api\";\nimport { CompressionFeature } from \"@webiny/utils/features/compression/feature.js\";\n\ninterface Waiter {\n targets: string[];\n cb: (context: ContextInterface) => void;\n}\n\nexport interface ContextParams {\n plugins?: PluginCollection | PluginsContainer;\n WEBINY_VERSION: string;\n}\n\nconst getPluginsContainer = (plugins?: PluginCollection | PluginsContainer): PluginsContainer => {\n if (!plugins) {\n return new PluginsContainer();\n }\n if (plugins instanceof PluginsContainer) {\n return plugins;\n }\n return new PluginsContainer(plugins);\n};\n\nexport class Context implements ContextInterface {\n public _result: any;\n public args: any;\n public readonly plugins: PluginsContainer;\n public readonly WEBINY_VERSION: string;\n public readonly benchmark: Benchmark;\n public readonly container: Container;\n\n private readonly waiters: Waiter[] = [];\n\n public constructor(params: ContextParams) {\n const { plugins, WEBINY_VERSION } = params;\n this.plugins = getPluginsContainer(plugins);\n this.WEBINY_VERSION = WEBINY_VERSION;\n this.container = new Container();\n /**\n * Register base features.\n */\n CompressionFeature.register(this.container);\n /**\n * At the moment, let's have benchmark as part of the context.\n * Also, register the plugin to have benchmark accessible via plugins container.\n */\n this.benchmark = new Benchmark();\n this.plugins.register(new BenchmarkPlugin(this.benchmark));\n }\n\n public getResult(): any {\n return this._result;\n }\n\n public hasResult(): boolean {\n return !!this._result;\n }\n\n public setResult(value: any): void {\n this._result = value;\n }\n\n public waitFor<T extends ContextInterface = ContextInterface>(\n obj: string | string[],\n cb: (context: T) => void\n ): void {\n const initialTargets = Array.isArray(obj) ? obj : [obj];\n const targets: string[] = [];\n /**\n * We go only through the first level properties\n */\n for (const key in initialTargets) {\n const target = initialTargets[key] as keyof this;\n /**\n * If property already exists, there is no need to wait for it, so we just continue the loop.\n * Also, if target is not a string, skip this property as it will fail to convert properly during the runtime.\n */\n if (this[target]) {\n continue;\n } else if (typeof target !== \"string\") {\n continue;\n }\n /**\n * Since there is no property, we must define it with its setter and getter.\n * We could not know when it got defined otherwise.\n */\n Object.defineProperty(this, target, {\n /**\n * Setter sets the given value to this object.\n * We cannot set it on exact property name it is defined because it would go into loop of setting itself.\n * And that is why we add __ around the property name.\n */\n set: (value: any) => {\n const newTargetKey = `__${target}__` as keyof this;\n this[newTargetKey] = value;\n /**\n * WWhen the property is set, we will go through all the waiters and, if any of them include currently set property, act on it.\n */\n for (const waiter of this.waiters) {\n if (waiter.targets.includes(target) === false) {\n continue;\n }\n /**\n * Remove currently set property so we know if there are any more to be waited for.\n */\n waiter.targets = waiter.targets.filter(t => t !== target);\n /**\n * If there are more to be waited, eg. user added [cms, pageBuilder] as waited properties, we just continue the loop.\n */\n if (waiter.targets.length > 0) {\n continue;\n }\n /**\n * And if there is nothing more to be waited for, we execute the callable.\n * Note that this callable is not async.\n */\n waiter.cb(this);\n }\n },\n /**\n * As we have set property with __ around it, we must get it as well.\n */\n get: (): any => {\n const newTargetKey = `__${target}__` as keyof this;\n return this[newTargetKey];\n },\n configurable: false\n });\n /**\n * We add the target to be awaited.\n */\n targets.push(target as string);\n }\n /**\n * If there are no targets to be awaited, just fire the callable.\n */\n if (targets.length === 0) {\n cb(this as unknown as T);\n return;\n }\n /**\n * Otherwise add the waiter for the target properties.\n */\n this.waiters.push({\n targets,\n /**\n * TODO @ts-refactor\n * Problem with possible subtype initialization\n */\n // @ts-expect-error\n cb\n });\n }\n}\n"],"names":["getPluginsContainer","plugins","PluginsContainer","Context","params","WEBINY_VERSION","Container","CompressionFeature","Benchmark","BenchmarkPlugin","value","obj","cb","initialTargets","Array","targets","key","target","Object","newTargetKey","waiter","t"],"mappings":";;;;;AAkBA,MAAMA,sBAAsB,CAACC;IACzB,IAAI,CAACA,SACD,OAAO,IAAIC;IAEf,IAAID,mBAAmBC,kBACnB,OAAOD;IAEX,OAAO,IAAIC,iBAAiBD;AAChC;AAEO,MAAME;IAUT,YAAmBC,MAAqB,CAAE;aAFzB,OAAO,GAAa,EAAE;QAGnC,MAAM,EAAEH,OAAO,EAAEI,cAAc,EAAE,GAAGD;QACpC,IAAI,CAAC,OAAO,GAAGJ,oBAAoBC;QACnC,IAAI,CAAC,cAAc,GAAGI;QACtB,IAAI,CAAC,SAAS,GAAG,IAAIC;QAIrBC,mBAAmB,QAAQ,CAAC,IAAI,CAAC,SAAS;QAK1C,IAAI,CAAC,SAAS,GAAG,IAAIC;QACrB,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,IAAIC,gBAAgB,IAAI,CAAC,SAAS;IAC5D;IAEO,YAAiB;QACpB,OAAO,IAAI,CAAC,OAAO;IACvB;IAEO,YAAqB;QACxB,OAAO,CAAC,CAAC,IAAI,CAAC,OAAO;IACzB;IAEO,UAAUC,KAAU,EAAQ;QAC/B,IAAI,CAAC,OAAO,GAAGA;IACnB;IAEO,QACHC,GAAsB,EACtBC,EAAwB,EACpB;QACJ,MAAMC,iBAAiBC,MAAM,OAAO,CAACH,OAAOA,MAAM;YAACA;SAAI;QACvD,MAAMI,UAAoB,EAAE;QAI5B,IAAK,MAAMC,OAAOH,eAAgB;YAC9B,MAAMI,SAASJ,cAAc,CAACG,IAAI;YAKlC,KAAI,IAAI,CAACC,OAAO,EAET;gBAAA,IAAI,AAAkB,YAAlB,OAAOA;oBAOlBC,OAAO,cAAc,CAAC,IAAI,EAAED,QAAQ;wBAMhC,KAAK,CAACP;4BACF,MAAMS,eAAe,CAAC,EAAE,EAAEF,OAAO,EAAE,CAAC;4BACpC,IAAI,CAACE,aAAa,GAAGT;4BAIrB,KAAK,MAAMU,UAAU,IAAI,CAAC,OAAO,CAC7B,IAAIA,AAAoC,UAApCA,OAAO,OAAO,CAAC,QAAQ,CAACH;gCAM5BG,OAAO,OAAO,GAAGA,OAAO,OAAO,CAAC,MAAM,CAACC,CAAAA,IAAKA,MAAMJ;gCAIlD,KAAIG,CAAAA,OAAO,OAAO,CAAC,MAAM,GAAG,IAO5BA,OAAO,EAAE,CAAC,IAAI;;wBAEtB;wBAIA,KAAK;4BACD,MAAMD,eAAe,CAAC,EAAE,EAAEF,OAAO,EAAE,CAAC;4BACpC,OAAO,IAAI,CAACE,aAAa;wBAC7B;wBACA,cAAc;oBAClB;oBAIAJ,QAAQ,IAAI,CAACE;;YAlDb;QAmDJ;QAIA,IAAIF,AAAmB,MAAnBA,QAAQ,MAAM,EAAQ,YACtBH,GAAG,IAAI;QAMX,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC;YACdG;YAMAH;QACJ;IACJ;AACJ"}
|
package/abstractions.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"abstractions.js","sources":["../src/abstractions.ts"],"sourcesContent":["import { createAbstraction } from \"@webiny/feature/api\";\nimport type { Benchmark as BenchmarkInterface } from \"./types.js\";\n\nexport const BenchmarkAbstraction = createAbstraction<BenchmarkInterface>(\"Benchmark\");\nexport namespace BenchmarkAbstraction {\n export type Interface = BenchmarkInterface;\n}\n"],"names":["BenchmarkAbstraction","createAbstraction"],"mappings":";AAGO,MAAMA,uBAAuBC,kBAAsC"}
|
package/index.d.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
|
+
export * from "./abstractions.js";
|
|
1
2
|
export * from "./Context.js";
|
|
2
3
|
export * from "./decorateContext.js";
|
|
3
4
|
export * from "./createConditionalPluginFactory.js";
|
|
4
|
-
export * from "./ServiceDiscovery.js";
|
|
5
|
-
export * from "./plugins/ContextPlugin.js";
|
|
6
5
|
export * from "./helpers/InterfaceGenerator/index.js";
|
package/index.js
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
|
+
export * from "./abstractions.js";
|
|
1
2
|
export * from "./Context.js";
|
|
2
3
|
export * from "./decorateContext.js";
|
|
3
4
|
export * from "./createConditionalPluginFactory.js";
|
|
4
|
-
export * from "./ServiceDiscovery.js";
|
|
5
|
-
export * from "./plugins/ContextPlugin.js";
|
|
6
5
|
export * from "./helpers/InterfaceGenerator/index.js";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@webiny/api",
|
|
3
|
-
"version": "6.
|
|
3
|
+
"version": "6.6.0-alpha.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"exports": {
|
|
6
6
|
".": "./index.js",
|
|
@@ -16,16 +16,15 @@
|
|
|
16
16
|
],
|
|
17
17
|
"license": "MIT",
|
|
18
18
|
"dependencies": {
|
|
19
|
-
"@webiny/
|
|
20
|
-
"@webiny/
|
|
21
|
-
"@webiny/
|
|
22
|
-
"@webiny/utils": "6.4.5-beta.0"
|
|
19
|
+
"@webiny/feature": "6.6.0-alpha.0",
|
|
20
|
+
"@webiny/plugins": "6.6.0-alpha.0",
|
|
21
|
+
"@webiny/utils": "6.6.0-alpha.0"
|
|
23
22
|
},
|
|
24
23
|
"devDependencies": {
|
|
25
|
-
"@webiny/build-tools": "6.
|
|
26
|
-
"@webiny/project-utils": "6.
|
|
24
|
+
"@webiny/build-tools": "6.6.0-alpha.0",
|
|
25
|
+
"@webiny/project-utils": "6.6.0-alpha.0",
|
|
27
26
|
"rimraf": "6.1.3",
|
|
28
|
-
"typescript": "
|
|
27
|
+
"typescript": "7.0.2",
|
|
29
28
|
"vitest": "4.1.10"
|
|
30
29
|
},
|
|
31
30
|
"publishConfig": {
|
package/types.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { Container } from "@webiny/
|
|
1
|
+
import type { Container } from "@webiny/feature/api";
|
|
2
2
|
import type { PluginsContainer } from "@webiny/plugins";
|
|
3
3
|
export type GenericRecord<K extends PropertyKey = PropertyKey, V = any> = Record<K, V>;
|
|
4
4
|
export type NonEmptyArray<T> = [T, ...T[]];
|
package/ServiceDiscovery.d.ts
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import type { DynamoDBDocument } from "@webiny/aws-sdk/client-dynamodb/index.js";
|
|
2
|
-
import type { GenericRecord } from "./types.js";
|
|
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,55 +0,0 @@
|
|
|
1
|
-
import { QueryCommand, getDocumentClient, unmarshall } from "@webiny/aws-sdk/client-dynamodb/index.js";
|
|
2
|
-
class ServiceManifestLoader {
|
|
3
|
-
async load() {
|
|
4
|
-
if (this.manifest) return this.manifest;
|
|
5
|
-
const manifests = await this.loadManifests();
|
|
6
|
-
if (!manifests) return;
|
|
7
|
-
this.manifest = manifests.reduce((acc, manifest)=>({
|
|
8
|
-
...acc,
|
|
9
|
-
[manifest.name]: manifest.manifest
|
|
10
|
-
}), {});
|
|
11
|
-
return this.manifest;
|
|
12
|
-
}
|
|
13
|
-
setDocumentClient(client) {
|
|
14
|
-
this.client = client;
|
|
15
|
-
}
|
|
16
|
-
clear() {
|
|
17
|
-
this.manifest = void 0;
|
|
18
|
-
}
|
|
19
|
-
async loadManifests() {
|
|
20
|
-
const client = this.client || getDocumentClient();
|
|
21
|
-
const { Items } = await client.send(new QueryCommand({
|
|
22
|
-
TableName: String(process.env.DB_TABLE),
|
|
23
|
-
IndexName: "GSI1",
|
|
24
|
-
KeyConditionExpression: "GSI1_PK = :GSI1_PK AND GSI1_SK > :GSI1_SK",
|
|
25
|
-
ExpressionAttributeValues: {
|
|
26
|
-
":GSI1_PK": {
|
|
27
|
-
S: "SERVICE_MANIFESTS"
|
|
28
|
-
},
|
|
29
|
-
":GSI1_SK": {
|
|
30
|
-
S: " "
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
}));
|
|
34
|
-
if (!Array.isArray(Items)) return;
|
|
35
|
-
return Items.map((item)=>unmarshall(item).data);
|
|
36
|
-
}
|
|
37
|
-
constructor(){
|
|
38
|
-
this.manifest = void 0;
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
const serviceManifestLoader = new ServiceManifestLoader();
|
|
42
|
-
class ServiceDiscovery {
|
|
43
|
-
static setDocumentClient(client) {
|
|
44
|
-
serviceManifestLoader.setDocumentClient(client);
|
|
45
|
-
}
|
|
46
|
-
static async load() {
|
|
47
|
-
return serviceManifestLoader.load();
|
|
48
|
-
}
|
|
49
|
-
static clear() {
|
|
50
|
-
serviceManifestLoader.clear();
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
export { ServiceDiscovery };
|
|
54
|
-
|
|
55
|
-
//# sourceMappingURL=ServiceDiscovery.js.map
|
package/ServiceDiscovery.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"ServiceDiscovery.js","sources":["../src/ServiceDiscovery.ts"],"sourcesContent":["import type { DynamoDBDocument } from \"@webiny/aws-sdk/client-dynamodb/index.js\";\nimport {\n getDocumentClient,\n QueryCommand,\n unmarshall\n} from \"@webiny/aws-sdk/client-dynamodb/index.js\";\nimport type { GenericRecord } from \"~/types.js\";\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"],"names":["ServiceManifestLoader","manifests","acc","manifest","client","undefined","getDocumentClient","Items","QueryCommand","String","process","Array","item","unmarshall","serviceManifestLoader","ServiceDiscovery"],"mappings":";AAeA,MAAMA;IAIF,MAAa,OAAO;QAChB,IAAI,IAAI,CAAC,QAAQ,EACb,OAAO,IAAI,CAAC,QAAQ;QAGxB,MAAMC,YAAY,MAAM,IAAI,CAAC,aAAa;QAE1C,IAAI,CAACA,WACD;QAOJ,IAAI,CAAC,QAAQ,GAAGA,UAAU,MAAM,CAAC,CAACC,KAAKC,WAC5B;gBAAE,GAAGD,GAAG;gBAAE,CAACC,SAAS,IAAI,CAAC,EAAEA,SAAS,QAAQ;YAAC,IACrD,CAAC;QAEJ,OAAO,IAAI,CAAC,QAAQ;IACxB;IAEO,kBAAkBC,MAAsC,EAAE;QAC7D,IAAI,CAAC,MAAM,GAAGA;IAClB;IAEO,QAAc;QACjB,IAAI,CAAC,QAAQ,GAAGC;IACpB;IAEA,MAAc,gBAAwD;QAClE,MAAMD,SAAS,IAAI,CAAC,MAAM,IAAIE;QAC9B,MAAM,EAAEC,KAAK,EAAE,GAAG,MAAMH,OAAO,IAAI,CAC/B,IAAII,aAAa;YACb,WAAWC,OAAOC,QAAQ,GAAG,CAAC,QAAQ;YACtC,WAAW;YACX,wBAAwB;YACxB,2BAA2B;gBACvB,YAAY;oBAAE,GAAG;gBAAoB;gBACrC,YAAY;oBAAE,GAAG;gBAAI;YACzB;QACJ;QAGJ,IAAI,CAACC,MAAM,OAAO,CAACJ,QACf;QAGJ,OAAOA,MAAM,GAAG,CAACK,CAAAA,OAAQC,WAAWD,MAAM,IAAI;IAClD;;aAnDQ,QAAQ,GAAyBP;;AAoD7C;AAEA,MAAMS,wBAAwB,IAAId;AAE3B,MAAMe;IACT,OAAO,kBAAkBX,MAAsC,EAAQ;QACnEU,sBAAsB,iBAAiB,CAACV;IAC5C;IAEA,aAAa,OAAO;QAChB,OAAOU,sBAAsB,IAAI;IACrC;IAIA,OAAO,QAAc;QACjBA,sBAAsB,KAAK;IAC/B;AACJ"}
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { Plugin } from "@webiny/plugins";
|
|
2
|
-
import type { Context } from "../types.js";
|
|
3
|
-
export interface ContextPluginCallable<T extends Context = Context> {
|
|
4
|
-
(context: T): void | Promise<void>;
|
|
5
|
-
}
|
|
6
|
-
export declare class ContextPlugin<T extends Context = Context> extends Plugin {
|
|
7
|
-
static readonly type: string;
|
|
8
|
-
private readonly _callable;
|
|
9
|
-
constructor(callable: ContextPluginCallable<T>);
|
|
10
|
-
apply(context: T): Promise<void>;
|
|
11
|
-
}
|
|
12
|
-
interface ContextPluginOptions {
|
|
13
|
-
name?: string;
|
|
14
|
-
}
|
|
15
|
-
export declare const createContextPlugin: <T extends Context = Context>(callable: ContextPluginCallable<T>, options?: ContextPluginOptions) => ContextPlugin<T>;
|
|
16
|
-
export {};
|
package/plugins/ContextPlugin.js
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
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);
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
|
-
const createContextPlugin = (callable, options)=>{
|
|
16
|
-
const plugin = new ContextPlugin(callable);
|
|
17
|
-
if (options && options.name) plugin.name = options.name;
|
|
18
|
-
return plugin;
|
|
19
|
-
};
|
|
20
|
-
export { ContextPlugin, createContextPlugin };
|
|
21
|
-
|
|
22
|
-
//# sourceMappingURL=ContextPlugin.js.map
|
|
@@ -1 +0,0 @@
|
|
|
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"}
|