@webiny/api 5.43.3 → 6.0.0-alpha.1
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.map +1 -1
- package/ServiceDiscovery.d.ts +7 -3
- package/ServiceDiscovery.js +9 -0
- package/ServiceDiscovery.js.map +1 -1
- package/createConditionalPluginFactory.d.ts +1 -1
- package/createConditionalPluginFactory.js.map +1 -1
- package/package.json +6 -6
- package/plugins/BenchmarkPlugin.d.ts +1 -1
- package/plugins/BenchmarkPlugin.js.map +1 -1
- package/plugins/CompressorPlugin.d.ts +1 -1
- package/plugins/CompressorPlugin.js.map +1 -1
- package/plugins/ContextPlugin.d.ts +6 -2
- package/plugins/ContextPlugin.js +6 -2
- package/plugins/ContextPlugin.js.map +1 -1
- package/types.d.ts +5 -2
- package/types.js.map +1 -1
package/Benchmark.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Benchmark as BenchmarkInterface, BenchmarkEnableOnCallable, BenchmarkMeasurement, BenchmarkMeasureOptions, BenchmarkOutputCallable, BenchmarkRuns } from "./types";
|
|
1
|
+
import type { Benchmark as BenchmarkInterface, BenchmarkEnableOnCallable, BenchmarkMeasurement, BenchmarkMeasureOptions, BenchmarkOutputCallable, BenchmarkRuns } from "./types";
|
|
2
2
|
export declare class Benchmark implements BenchmarkInterface {
|
|
3
3
|
readonly measurements: BenchmarkMeasurement[];
|
|
4
4
|
private outputDone;
|
package/Benchmark.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["BenchmarkState","createDefaultOutputCallable","benchmark","console","log","elapsed","measurements","Benchmark","outputDone","isAlreadyRunning","totalElapsed","runs","enableOnCallables","onOutputCallables","state","UNDETERMINED","enableOn","cb","push","onOutput","enable","setState","ENABLED","disable","DISABLED","output","length","callables","reverse","result","stop","measure","options","enabled","getIsEnabled","measurement","startMeasurement","getIsAlreadyRunning","startRunning","measurementEnded","stopMeasurement","addRun","addElapsed","endRunning","name","category","start","Date","memoryStart","process","memoryUsage","heapUsed","end","memoryEnd","getTime","memory","exports"],"sources":["Benchmark.ts"],"sourcesContent":["import {\n Benchmark as BenchmarkInterface,\n BenchmarkEnableOnCallable,\n BenchmarkMeasurement,\n BenchmarkMeasureOptions,\n BenchmarkOutputCallable,\n BenchmarkRuns\n} from \"~/types\";\n\nenum BenchmarkState {\n DISABLED = \"disabled\",\n ENABLED = \"enabled\",\n UNDETERMINED = \"undetermined\"\n}\n\ninterface BenchmarkMeasurementStart\n extends Pick<BenchmarkMeasurement, \"name\" | \"category\" | \"start\"> {\n memoryStart: number;\n}\n\nconst createDefaultOutputCallable = (): BenchmarkOutputCallable => {\n return async ({ benchmark }) => {\n console.log(`Benchmark total time elapsed: ${benchmark.elapsed}ms`);\n console.log(\"Benchmark measurements:\");\n console.log(benchmark.measurements);\n };\n};\n\nexport class Benchmark implements BenchmarkInterface {\n public readonly measurements: BenchmarkMeasurement[] = [];\n\n private outputDone = false;\n private isAlreadyRunning = false;\n private totalElapsed = 0;\n public readonly runs: BenchmarkRuns = {};\n private readonly enableOnCallables: BenchmarkEnableOnCallable[] = [];\n private readonly onOutputCallables: BenchmarkOutputCallable[] = [];\n private state: BenchmarkState = BenchmarkState.UNDETERMINED;\n\n public get elapsed(): number {\n return this.totalElapsed;\n }\n\n public enableOn(cb: BenchmarkEnableOnCallable): void {\n this.enableOnCallables.push(cb);\n }\n\n public onOutput(cb: BenchmarkOutputCallable): void {\n this.onOutputCallables.push(cb);\n }\n\n public enable(): void {\n this.setState(BenchmarkState.ENABLED);\n }\n\n public disable(): void {\n this.setState(BenchmarkState.DISABLED);\n }\n\n /**\n * When running the output, we need to reverse the callables array, so that the last one added is the first one executed.\n *\n * The last one is our built-in console.log output.\n */\n public async output(): Promise<void> {\n /**\n * No point in outputting more than once or if no measurements were made.\n */\n if (this.outputDone || this.measurements.length === 0) {\n return;\n }\n const callables = [...this.onOutputCallables].reverse();\n callables.push(createDefaultOutputCallable());\n for (const cb of callables) {\n const result = await cb({\n benchmark: this,\n stop: () => \"stop\"\n });\n if (result === \"stop\") {\n return;\n }\n }\n this.outputDone = true;\n }\n\n public async measure<T = any>(\n options: BenchmarkMeasureOptions | string,\n cb: () => Promise<T>\n ): Promise<T> {\n const enabled = await this.getIsEnabled();\n if (!enabled) {\n return cb();\n }\n const measurement = this.startMeasurement(options);\n const isAlreadyRunning = this.getIsAlreadyRunning();\n this.startRunning();\n try {\n return await cb();\n } finally {\n const measurementEnded = this.stopMeasurement(measurement);\n this.measurements.push(measurementEnded);\n this.addRun(measurementEnded);\n /**\n * Only add to total time if this run is not a child of another run.\n * And then end running.\n */\n if (!isAlreadyRunning) {\n this.addElapsed(measurementEnded);\n this.endRunning();\n }\n }\n }\n\n private getIsAlreadyRunning(): boolean {\n return this.isAlreadyRunning;\n }\n private startRunning(): void {\n this.isAlreadyRunning = true;\n }\n private endRunning(): void {\n this.isAlreadyRunning = false;\n }\n\n private async getIsEnabled(): Promise<boolean> {\n if (this.state === BenchmarkState.ENABLED) {\n return true;\n } else if (this.state === BenchmarkState.DISABLED) {\n return false;\n }\n\n for (const cb of this.enableOnCallables) {\n const result = await cb();\n if (result) {\n this.enable();\n return true;\n }\n }\n this.disable();\n return false;\n }\n\n private addElapsed(measurement: Pick<BenchmarkMeasurement, \"elapsed\">): void {\n this.totalElapsed = this.totalElapsed + measurement.elapsed;\n }\n\n private addRun(measurement: Pick<BenchmarkMeasurement, \"name\" | \"category\">): void {\n const name = `${measurement.category}#${measurement.name}`;\n if (!this.runs[name]) {\n this.runs[name] = 0;\n }\n this.runs[name]++;\n }\n\n private setState(state: BenchmarkState): void {\n this.state = state;\n }\n\n private startMeasurement(options: BenchmarkMeasureOptions | string): BenchmarkMeasurementStart {\n const name = typeof options === \"string\" ? options : options.name;\n const category = typeof options === \"string\" ? \"webiny\" : options.category;\n return {\n name,\n category,\n start: new Date(),\n memoryStart: process.memoryUsage().heapUsed\n };\n }\n\n private stopMeasurement(measurement: BenchmarkMeasurementStart): BenchmarkMeasurement {\n const end = new Date();\n const memoryEnd = process.memoryUsage().heapUsed;\n const elapsed = end.getTime() - measurement.start.getTime();\n return {\n name: measurement.name,\n category: measurement.category,\n start: measurement.start,\n end,\n elapsed,\n memory: memoryEnd - measurement.memoryStart\n };\n }\n}\n"],"mappings":";;;;;;IASKA,cAAc,0BAAdA,cAAc;EAAdA,cAAc;EAAdA,cAAc;EAAdA,cAAc;EAAA,OAAdA,cAAc;AAAA,EAAdA,cAAc;AAWnB,MAAMC,2BAA2B,GAAGA,CAAA,KAA+B;EAC/D,OAAO,OAAO;IAAEC;EAAU,CAAC,KAAK;IAC5BC,OAAO,CAACC,GAAG,CAAC,iCAAiCF,SAAS,CAACG,OAAO,IAAI,CAAC;IACnEF,OAAO,CAACC,GAAG,CAAC,yBAAyB,CAAC;IACtCD,OAAO,CAACC,GAAG,CAACF,SAAS,CAACI,YAAY,CAAC;EACvC,CAAC;AACL,CAAC;AAEM,MAAMC,SAAS,CAA+B;EACjCD,YAAY,GAA2B,EAAE;EAEjDE,UAAU,GAAG,KAAK;EAClBC,gBAAgB,GAAG,KAAK;EACxBC,YAAY,GAAG,CAAC;EACRC,IAAI,GAAkB,CAAC,CAAC;EACvBC,iBAAiB,GAAgC,EAAE;EACnDC,iBAAiB,GAA8B,EAAE;EAC1DC,KAAK,GAAmBd,cAAc,CAACe,YAAY;EAE3D,IAAWV,OAAOA,CAAA,EAAW;IACzB,OAAO,IAAI,CAACK,YAAY;EAC5B;EAEOM,QAAQA,CAACC,EAA6B,EAAQ;IACjD,IAAI,CAACL,iBAAiB,CAACM,IAAI,CAACD,EAAE,CAAC;EACnC;EAEOE,QAAQA,CAACF,EAA2B,EAAQ;IAC/C,IAAI,CAACJ,iBAAiB,CAACK,IAAI,CAACD,EAAE,CAAC;EACnC;EAEOG,MAAMA,CAAA,EAAS;IAClB,IAAI,CAACC,QAAQ,CAACrB,cAAc,CAACsB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IAAI,CAAC,GAAG,CAAC;IACvB;IACA,IAAI,CAACjC,IAAI,CAACiC,IAAI,CAAC,EAAE;EACrB;EAEQvB,QAAQA,CAACP,KAAqB,EAAQ;IAC1C,IAAI,CAACA,KAAK,GAAGA,KAAK;EACtB;EAEQsB,gBAAgBA,CAACJ,OAAyC,EAA6B;IAC3F,MAAMY,IAAI,GAAG,OAAOZ,OAAO,KAAK,QAAQ,GAAGA,OAAO,GAAGA,OAAO,CAACY,IAAI;IACjE,MAAMC,QAAQ,GAAG,OAAOb,OAAO,KAAK,QAAQ,GAAG,QAAQ,GAAGA,OAAO,CAACa,QAAQ;IAC1E,OAAO;MACHD,IAAI;MACJC,QAAQ;MACRC,KAAK,EAAE,IAAIC,IAAI,CAAC,CAAC;MACjBC,WAAW,EAAEC,OAAO,CAACC,WAAW,CAAC,CAAC,CAACC;IACvC,CAAC;EACL;EAEQX,eAAeA,CAACL,WAAsC,EAAwB;IAClF,MAAMiB,GAAG,GAAG,IAAIL,IAAI,CAAC,CAAC;IACtB,MAAMM,SAAS,GAAGJ,OAAO,CAACC,WAAW,CAAC,CAAC,CAACC,QAAQ;IAChD,MAAM9C,OAAO,GAAG+C,GAAG,CAACE,OAAO,CAAC,CAAC,GAAGnB,WAAW,CAACW,KAAK,CAACQ,OAAO,CAAC,CAAC;IAC3D,OAAO;MACHV,IAAI,EAAET,WAAW,CAACS,IAAI;MACtBC,QAAQ,EAAEV,WAAW,CAACU,QAAQ;MAC9BC,KAAK,EAAEX,WAAW,CAACW,KAAK;MACxBM,GAAG;MACH/C,OAAO;MACPkD,MAAM,EAAEF,SAAS,GAAGlB,WAAW,CAACa;IACpC,CAAC;EACL;AACJ;AAACQ,OAAA,CAAAjD,SAAA,GAAAA,SAAA","ignoreList":[]}
|
|
1
|
+
{"version":3,"names":["BenchmarkState","createDefaultOutputCallable","benchmark","console","log","elapsed","measurements","Benchmark","outputDone","isAlreadyRunning","totalElapsed","runs","enableOnCallables","onOutputCallables","state","UNDETERMINED","enableOn","cb","push","onOutput","enable","setState","ENABLED","disable","DISABLED","output","length","callables","reverse","result","stop","measure","options","enabled","getIsEnabled","measurement","startMeasurement","getIsAlreadyRunning","startRunning","measurementEnded","stopMeasurement","addRun","addElapsed","endRunning","name","category","start","Date","memoryStart","process","memoryUsage","heapUsed","end","memoryEnd","getTime","memory","exports"],"sources":["Benchmark.ts"],"sourcesContent":["import type {\n Benchmark as BenchmarkInterface,\n BenchmarkEnableOnCallable,\n BenchmarkMeasurement,\n BenchmarkMeasureOptions,\n BenchmarkOutputCallable,\n BenchmarkRuns\n} from \"~/types\";\n\nenum BenchmarkState {\n DISABLED = \"disabled\",\n ENABLED = \"enabled\",\n UNDETERMINED = \"undetermined\"\n}\n\ninterface BenchmarkMeasurementStart\n extends Pick<BenchmarkMeasurement, \"name\" | \"category\" | \"start\"> {\n memoryStart: number;\n}\n\nconst createDefaultOutputCallable = (): BenchmarkOutputCallable => {\n return async ({ benchmark }) => {\n console.log(`Benchmark total time elapsed: ${benchmark.elapsed}ms`);\n console.log(\"Benchmark measurements:\");\n console.log(benchmark.measurements);\n };\n};\n\nexport class Benchmark implements BenchmarkInterface {\n public readonly measurements: BenchmarkMeasurement[] = [];\n\n private outputDone = false;\n private isAlreadyRunning = false;\n private totalElapsed = 0;\n public readonly runs: BenchmarkRuns = {};\n private readonly enableOnCallables: BenchmarkEnableOnCallable[] = [];\n private readonly onOutputCallables: BenchmarkOutputCallable[] = [];\n private state: BenchmarkState = BenchmarkState.UNDETERMINED;\n\n public get elapsed(): number {\n return this.totalElapsed;\n }\n\n public enableOn(cb: BenchmarkEnableOnCallable): void {\n this.enableOnCallables.push(cb);\n }\n\n public onOutput(cb: BenchmarkOutputCallable): void {\n this.onOutputCallables.push(cb);\n }\n\n public enable(): void {\n this.setState(BenchmarkState.ENABLED);\n }\n\n public disable(): void {\n this.setState(BenchmarkState.DISABLED);\n }\n\n /**\n * When running the output, we need to reverse the callables array, so that the last one added is the first one executed.\n *\n * The last one is our built-in console.log output.\n */\n public async output(): Promise<void> {\n /**\n * No point in outputting more than once or if no measurements were made.\n */\n if (this.outputDone || this.measurements.length === 0) {\n return;\n }\n const callables = [...this.onOutputCallables].reverse();\n callables.push(createDefaultOutputCallable());\n for (const cb of callables) {\n const result = await cb({\n benchmark: this,\n stop: () => \"stop\"\n });\n if (result === \"stop\") {\n return;\n }\n }\n this.outputDone = true;\n }\n\n public async measure<T = any>(\n options: BenchmarkMeasureOptions | string,\n cb: () => Promise<T>\n ): Promise<T> {\n const enabled = await this.getIsEnabled();\n if (!enabled) {\n return cb();\n }\n const measurement = this.startMeasurement(options);\n const isAlreadyRunning = this.getIsAlreadyRunning();\n this.startRunning();\n try {\n return await cb();\n } finally {\n const measurementEnded = this.stopMeasurement(measurement);\n this.measurements.push(measurementEnded);\n this.addRun(measurementEnded);\n /**\n * Only add to total time if this run is not a child of another run.\n * And then end running.\n */\n if (!isAlreadyRunning) {\n this.addElapsed(measurementEnded);\n this.endRunning();\n }\n }\n }\n\n private getIsAlreadyRunning(): boolean {\n return this.isAlreadyRunning;\n }\n private startRunning(): void {\n this.isAlreadyRunning = true;\n }\n private endRunning(): void {\n this.isAlreadyRunning = false;\n }\n\n private async getIsEnabled(): Promise<boolean> {\n if (this.state === BenchmarkState.ENABLED) {\n return true;\n } else if (this.state === BenchmarkState.DISABLED) {\n return false;\n }\n\n for (const cb of this.enableOnCallables) {\n const result = await cb();\n if (result) {\n this.enable();\n return true;\n }\n }\n this.disable();\n return false;\n }\n\n private addElapsed(measurement: Pick<BenchmarkMeasurement, \"elapsed\">): void {\n this.totalElapsed = this.totalElapsed + measurement.elapsed;\n }\n\n private addRun(measurement: Pick<BenchmarkMeasurement, \"name\" | \"category\">): void {\n const name = `${measurement.category}#${measurement.name}`;\n if (!this.runs[name]) {\n this.runs[name] = 0;\n }\n this.runs[name]++;\n }\n\n private setState(state: BenchmarkState): void {\n this.state = state;\n }\n\n private startMeasurement(options: BenchmarkMeasureOptions | string): BenchmarkMeasurementStart {\n const name = typeof options === \"string\" ? options : options.name;\n const category = typeof options === \"string\" ? \"webiny\" : options.category;\n return {\n name,\n category,\n start: new Date(),\n memoryStart: process.memoryUsage().heapUsed\n };\n }\n\n private stopMeasurement(measurement: BenchmarkMeasurementStart): BenchmarkMeasurement {\n const end = new Date();\n const memoryEnd = process.memoryUsage().heapUsed;\n const elapsed = end.getTime() - measurement.start.getTime();\n return {\n name: measurement.name,\n category: measurement.category,\n start: measurement.start,\n end,\n elapsed,\n memory: memoryEnd - measurement.memoryStart\n };\n }\n}\n"],"mappings":";;;;;;IASKA,cAAc,0BAAdA,cAAc;EAAdA,cAAc;EAAdA,cAAc;EAAdA,cAAc;EAAA,OAAdA,cAAc;AAAA,EAAdA,cAAc;AAWnB,MAAMC,2BAA2B,GAAGA,CAAA,KAA+B;EAC/D,OAAO,OAAO;IAAEC;EAAU,CAAC,KAAK;IAC5BC,OAAO,CAACC,GAAG,CAAC,iCAAiCF,SAAS,CAACG,OAAO,IAAI,CAAC;IACnEF,OAAO,CAACC,GAAG,CAAC,yBAAyB,CAAC;IACtCD,OAAO,CAACC,GAAG,CAACF,SAAS,CAACI,YAAY,CAAC;EACvC,CAAC;AACL,CAAC;AAEM,MAAMC,SAAS,CAA+B;EACjCD,YAAY,GAA2B,EAAE;EAEjDE,UAAU,GAAG,KAAK;EAClBC,gBAAgB,GAAG,KAAK;EACxBC,YAAY,GAAG,CAAC;EACRC,IAAI,GAAkB,CAAC,CAAC;EACvBC,iBAAiB,GAAgC,EAAE;EACnDC,iBAAiB,GAA8B,EAAE;EAC1DC,KAAK,GAAmBd,cAAc,CAACe,YAAY;EAE3D,IAAWV,OAAOA,CAAA,EAAW;IACzB,OAAO,IAAI,CAACK,YAAY;EAC5B;EAEOM,QAAQA,CAACC,EAA6B,EAAQ;IACjD,IAAI,CAACL,iBAAiB,CAACM,IAAI,CAACD,EAAE,CAAC;EACnC;EAEOE,QAAQA,CAACF,EAA2B,EAAQ;IAC/C,IAAI,CAACJ,iBA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GED
|
@@ -1,8 +1,12 @@
|
|
|
1
|
-
import { DynamoDBDocument } from "@webiny/aws-sdk/client-dynamodb";
|
|
2
|
-
import { GenericRecord } from "./types";
|
|
1
|
+
import type { DynamoDBDocument } from "@webiny/aws-sdk/client-dynamodb";
|
|
2
|
+
import type { GenericRecord } from "./types";
|
|
3
3
|
type Manifest = GenericRecord<string>;
|
|
4
4
|
export declare class ServiceDiscovery {
|
|
5
|
-
static setDocumentClient(client: DynamoDBDocument): void;
|
|
5
|
+
static setDocumentClient(client: Pick<DynamoDBDocument, "send">): void;
|
|
6
6
|
static load(): Promise<Manifest | undefined>;
|
|
7
|
+
/**
|
|
8
|
+
* Should be used for testing purposes only!
|
|
9
|
+
*/
|
|
10
|
+
static clear(): void;
|
|
7
11
|
}
|
|
8
12
|
export {};
|
package/ServiceDiscovery.js
CHANGED
|
@@ -31,6 +31,9 @@ class ServiceManifestLoader {
|
|
|
31
31
|
setDocumentClient(client) {
|
|
32
32
|
this.client = client;
|
|
33
33
|
}
|
|
34
|
+
clear() {
|
|
35
|
+
this.manifest = undefined;
|
|
36
|
+
}
|
|
34
37
|
async loadManifests() {
|
|
35
38
|
const client = this.client || (0, _clientDynamodb.getDocumentClient)();
|
|
36
39
|
const {
|
|
@@ -62,6 +65,12 @@ class ServiceDiscovery {
|
|
|
62
65
|
static async load() {
|
|
63
66
|
return serviceManifestLoader.load();
|
|
64
67
|
}
|
|
68
|
+
/**
|
|
69
|
+
* Should be used for testing purposes only!
|
|
70
|
+
*/
|
|
71
|
+
static clear() {
|
|
72
|
+
serviceManifestLoader.clear();
|
|
73
|
+
}
|
|
65
74
|
}
|
|
66
75
|
exports.ServiceDiscovery = ServiceDiscovery;
|
|
67
76
|
|
package/ServiceDiscovery.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_clientDynamodb","require","ServiceManifestLoader","manifest","undefined","load","manifests","loadManifests","reduce","acc","name","setDocumentClient","client","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 {\
|
|
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":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["createConditionalPluginFactory","condition","cb","Promise","resolve","exports"],"sources":["createConditionalPluginFactory.ts"],"sourcesContent":["import { PluginFactory } from \"@webiny/plugins/types\";\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"],"mappings":";;;;;;AAIO,MAAMA,8BAA8B,GAAGA,CAC1CC,SAAoB,EACpBC,EAAiB,KACD;EAChB,OAAO,MAAM;IACT,IAAID,SAAS,CAAC,CAAC,EAAE;MACb,OAAOC,EAAE,CAAC,CAAC;IACf;IAEA,OAAOC,OAAO,CAACC,OAAO,CAAC,EAAE,CAAC;EAC9B,CAAC;AACL,CAAC;AAACC,OAAA,CAAAL,8BAAA,GAAAA,8BAAA","ignoreList":[]}
|
|
1
|
+
{"version":3,"names":["createConditionalPluginFactory","condition","cb","Promise","resolve","exports"],"sources":["createConditionalPluginFactory.ts"],"sourcesContent":["import type { PluginFactory } from \"@webiny/plugins/types\";\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"],"mappings":";;;;;;AAIO,MAAMA,8BAA8B,GAAGA,CAC1CC,SAAoB,EACpBC,EAAiB,KACD;EAChB,OAAO,MAAM;IACT,IAAID,SAAS,CAAC,CAAC,EAAE;MACb,OAAOC,EAAE,CAAC,CAAC;IACf;IAEA,OAAOC,OAAO,CAACC,OAAO,CAAC,EAAE,CAAC;EAC9B,CAAC;AACL,CAAC;AAACC,OAAA,CAAAL,8BAAA,GAAAA,8BAAA","ignoreList":[]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@webiny/api",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "6.0.0-alpha.1",
|
|
4
4
|
"main": "index.js",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -12,12 +12,12 @@
|
|
|
12
12
|
],
|
|
13
13
|
"license": "MIT",
|
|
14
14
|
"dependencies": {
|
|
15
|
-
"@webiny/aws-sdk": "
|
|
16
|
-
"@webiny/plugins": "
|
|
17
|
-
"@webiny/utils": "
|
|
15
|
+
"@webiny/aws-sdk": "6.0.0-alpha.1",
|
|
16
|
+
"@webiny/plugins": "6.0.0-alpha.1",
|
|
17
|
+
"@webiny/utils": "6.0.0-alpha.1"
|
|
18
18
|
},
|
|
19
19
|
"devDependencies": {
|
|
20
|
-
"@webiny/project-utils": "
|
|
20
|
+
"@webiny/project-utils": "6.0.0-alpha.1",
|
|
21
21
|
"rimraf": "6.0.1",
|
|
22
22
|
"typescript": "5.3.3"
|
|
23
23
|
},
|
|
@@ -29,5 +29,5 @@
|
|
|
29
29
|
"build": "node ../cli/bin.js run build",
|
|
30
30
|
"watch": "node ../cli/bin.js run watch"
|
|
31
31
|
},
|
|
32
|
-
"gitHead": "
|
|
32
|
+
"gitHead": "9bd236cf5e689f209a11bec089207dcc2d41a53c"
|
|
33
33
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_plugins","require","BenchmarkPlugin","Plugin","type","name","constructor","benchmark","enable","disable","measure","cb","exports"],"sources":["BenchmarkPlugin.ts"],"sourcesContent":["import { Plugin } from \"@webiny/plugins\";\nimport { Benchmark } from \"~/types\";\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"],"mappings":";;;;;;AAAA,IAAAA,QAAA,GAAAC,OAAA;AAGA;AACA;AACA;AACO,MAAMC,eAAe,SAASC,eAAM,CAAC;EACxC,OAAgCC,IAAI,GAAW,mBAAmB;EAClDC,IAAI,GAAG,mBAAmB;EAGnCC,WAAWA,CAACC,SAAoB,EAAE;IACrC,KAAK,CAAC,CAAC;IACP,IAAI,CAACA,SAAS,GAAGA,SAAS;EAC9B;EAEOC,MAAMA,CAAA,EAAS;IAClB,IAAI,CAACD,SAAS,CAACC,MAAM,CAAC,CAAC;EAC3B;EAEOC,OAAOA,CAAA,EAAS;IACnB,IAAI,CAACF,SAAS,CAACE,OAAO,CAAC,CAAC;EAC5B;EAEA,MAAaC,OAAOA,CAAUL,IAAY,EAAEM,EAAoB,EAAc;IAC1E,OAAO,IAAI,CAACJ,SAAS,CAACG,OAAO,CAAIL,IAAI,EAAEM,EAAE,CAAC;EAC9C;AACJ;AAACC,OAAA,CAAAV,eAAA,GAAAA,eAAA","ignoreList":[]}
|
|
1
|
+
{"version":3,"names":["_plugins","require","BenchmarkPlugin","Plugin","type","name","constructor","benchmark","enable","disable","measure","cb","exports"],"sources":["BenchmarkPlugin.ts"],"sourcesContent":["import { Plugin } from \"@webiny/plugins\";\nimport type { Benchmark } from \"~/types\";\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"],"mappings":";;;;;;AAAA,IAAAA,QAAA,GAAAC,OAAA;AAGA;AACA;AACA;AACO,MAAMC,eAAe,SAASC,eAAM,CAAC;EACxC,OAAgCC,IAAI,GAAW,mBAAmB;EAClDC,IAAI,GAAG,mBAAmB;EAGnCC,WAAWA,CAACC,SAAoB,EAAE;IACrC,KAAK,CAAC,CAAC;IACP,IAAI,CAACA,SAAS,GAAGA,SAAS;EAC9B;EAEOC,MAAMA,CAAA,EAAS;IAClB,IAAI,CAACD,SAAS,CAACC,MAAM,CAAC,CAAC;EAC3B;EAEOC,OAAOA,CAAA,EAAS;IACnB,IAAI,CAACF,SAAS,CAACE,OAAO,CAAC,CAAC;EAC5B;EAEA,MAAaC,OAAOA,CAAUL,IAAY,EAAEM,EAAoB,EAAc;IAC1E,OAAO,IAAI,CAACJ,SAAS,CAACG,OAAO,CAAIL,IAAI,EAAEM,EAAE,CAAC;EAC9C;AACJ;AAACC,OAAA,CAAAV,eAAA,GAAAA,eAAA","ignoreList":[]}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Plugin } from "@webiny/plugins/Plugin";
|
|
2
|
-
import { ICompressor } from "@webiny/utils/compression/Compressor";
|
|
2
|
+
import type { ICompressor } from "@webiny/utils/compression/Compressor";
|
|
3
3
|
export interface ICompressorPluginParams {
|
|
4
4
|
getCompressor(): ICompressor;
|
|
5
5
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_Plugin","require","CompressorPlugin","Plugin","name","type","constructor","params","getCompressor","exports"],"sources":["CompressorPlugin.ts"],"sourcesContent":["import { Plugin } from \"@webiny/plugins/Plugin\";\nimport { ICompressor } from \"@webiny/utils/compression/Compressor\";\n\nexport interface ICompressorPluginParams {\n getCompressor(): ICompressor;\n}\n\n/**\n * Should never be initialized outside the api package.\n */\nexport class CompressorPlugin extends Plugin {\n public override readonly name: string = \"context.compressor\";\n public static override type: string = \"context.compressor\";\n\n public readonly getCompressor: () => ICompressor;\n\n public constructor(params: ICompressorPluginParams) {\n super();\n this.getCompressor = params.getCompressor;\n }\n}\n"],"mappings":";;;;;;AAAA,IAAAA,OAAA,GAAAC,OAAA;AAOA;AACA;AACA;AACO,MAAMC,gBAAgB,SAASC,cAAM,CAAC;EAChBC,IAAI,GAAW,oBAAoB;EAC5D,OAAuBC,IAAI,GAAW,oBAAoB;EAInDC,WAAWA,CAACC,MAA+B,EAAE;IAChD,KAAK,CAAC,CAAC;IACP,IAAI,CAACC,aAAa,GAAGD,MAAM,CAACC,aAAa;EAC7C;AACJ;AAACC,OAAA,CAAAP,gBAAA,GAAAA,gBAAA","ignoreList":[]}
|
|
1
|
+
{"version":3,"names":["_Plugin","require","CompressorPlugin","Plugin","name","type","constructor","params","getCompressor","exports"],"sources":["CompressorPlugin.ts"],"sourcesContent":["import { Plugin } from \"@webiny/plugins/Plugin\";\nimport type { ICompressor } from \"@webiny/utils/compression/Compressor\";\n\nexport interface ICompressorPluginParams {\n getCompressor(): ICompressor;\n}\n\n/**\n * Should never be initialized outside the api package.\n */\nexport class CompressorPlugin extends Plugin {\n public override readonly name: string = \"context.compressor\";\n public static override type: string = \"context.compressor\";\n\n public readonly getCompressor: () => ICompressor;\n\n public constructor(params: ICompressorPluginParams) {\n super();\n this.getCompressor = params.getCompressor;\n }\n}\n"],"mappings":";;;;;;AAAA,IAAAA,OAAA,GAAAC,OAAA;AAOA;AACA;AACA;AACO,MAAMC,gBAAgB,SAASC,cAAM,CAAC;EAChBC,IAAI,GAAW,oBAAoB;EAC5D,OAAuBC,IAAI,GAAW,oBAAoB;EAInDC,WAAWA,CAACC,MAA+B,EAAE;IAChD,KAAK,CAAC,CAAC;IACP,IAAI,CAACC,aAAa,GAAGD,MAAM,CAACC,aAAa;EAC7C;AACJ;AAACC,OAAA,CAAAP,gBAAA,GAAAA,gBAAA","ignoreList":[]}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Plugin } from "@webiny/plugins";
|
|
2
|
-
import { Context } from "../types";
|
|
2
|
+
import type { Context } from "../types";
|
|
3
3
|
export interface ContextPluginCallable<T extends Context = Context> {
|
|
4
4
|
(context: T): void | Promise<void>;
|
|
5
5
|
}
|
|
@@ -9,4 +9,8 @@ export declare class ContextPlugin<T extends Context = Context> extends Plugin {
|
|
|
9
9
|
constructor(callable: ContextPluginCallable<T>);
|
|
10
10
|
apply(context: T): Promise<void>;
|
|
11
11
|
}
|
|
12
|
-
|
|
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
CHANGED
|
@@ -19,8 +19,12 @@ class ContextPlugin extends _plugins.Plugin {
|
|
|
19
19
|
}
|
|
20
20
|
}
|
|
21
21
|
exports.ContextPlugin = ContextPlugin;
|
|
22
|
-
const createContextPlugin = callable => {
|
|
23
|
-
|
|
22
|
+
const createContextPlugin = (callable, options) => {
|
|
23
|
+
const plugin = new ContextPlugin(callable);
|
|
24
|
+
if (options && options.name) {
|
|
25
|
+
plugin.name = options.name;
|
|
26
|
+
}
|
|
27
|
+
return plugin;
|
|
24
28
|
};
|
|
25
29
|
exports.createContextPlugin = createContextPlugin;
|
|
26
30
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_plugins","require","ContextPlugin","Plugin","type","constructor","callable","_callable","apply","context","Error","exports","createContextPlugin"],"sources":["ContextPlugin.ts"],"sourcesContent":["import { Plugin } from \"@webiny/plugins\";\nimport { Context } from \"~/types\";\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\nexport const createContextPlugin = <T extends Context = Context>(\n callable: ContextPluginCallable<T
|
|
1
|
+
{"version":3,"names":["_plugins","require","ContextPlugin","Plugin","type","constructor","callable","_callable","apply","context","Error","exports","createContextPlugin","options","plugin","name"],"sources":["ContextPlugin.ts"],"sourcesContent":["import { Plugin } from \"@webiny/plugins\";\nimport type { Context } from \"~/types\";\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"],"mappings":";;;;;;AAAA,IAAAA,QAAA,GAAAC,OAAA;AAOO,MAAMC,aAAa,SAAsCC,eAAM,CAAC;EACnE,OAAgCC,IAAI,GAAW,SAAS;EAGxDC,WAAWA,CAACC,QAAkC,EAAE;IAC5C,KAAK,CAAC,CAAC;IACP,IAAI,CAACC,SAAS,GAAGD,QAAQ;EAC7B;EAEA,MAAaE,KAAKA,CAACC,OAAU,EAAiB;IAC1C,IAAI,OAAO,IAAI,CAACF,SAAS,KAAK,UAAU,EAAE;MACtC,MAAMG,KAAK,CACP,uIACJ,CAAC;IACL;IAEA,OAAO,IAAI,CAACH,SAAS,CAACE,OAAO,CAAC;EAClC;AACJ;AAACE,OAAA,CAAAT,aAAA,GAAAA,aAAA;AAMM,MAAMU,mBAAmB,GAAGA,CAC/BN,QAAkC,EAClCO,OAA8B,KACX;EACnB,MAAMC,MAAM,GAAG,IAAIZ,aAAa,CAAII,QAAQ,CAAC;EAC7C,IAAIO,OAAO,IAAIA,OAAO,CAACE,IAAI,EAAE;IACzBD,MAAM,CAACC,IAAI,GAAGF,OAAO,CAACE,IAAI;EAC9B;EACA,OAAOD,MAAM;AACjB,CAAC;AAACH,OAAA,CAAAC,mBAAA,GAAAA,mBAAA","ignoreList":[]}
|
package/types.d.ts
CHANGED
|
@@ -1,7 +1,10 @@
|
|
|
1
|
-
import { PluginsContainer } from "@webiny/plugins";
|
|
2
|
-
import { ICompressor } from "@webiny/utils/compression/Compressor";
|
|
1
|
+
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
|
+
export type PossiblyUndefinedProperties<T> = {
|
|
6
|
+
[K in keyof T]: T[K] extends undefined ? T[K] : T[K] | undefined;
|
|
7
|
+
};
|
|
5
8
|
export type BenchmarkRuns = GenericRecord<string, number>;
|
|
6
9
|
export interface BenchmarkMeasurement {
|
|
7
10
|
name: string;
|
package/types.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":[],"sources":["types.ts"],"sourcesContent":["import { PluginsContainer } from \"@webiny/plugins\";\nimport { ICompressor } from \"@webiny/utils/compression/Compressor\";\n\nexport type GenericRecord<K extends PropertyKey = PropertyKey, V = any> = Record<K, V>;\n\nexport type NonEmptyArray<T> = [T, ...T[]];\n\nexport type BenchmarkRuns = GenericRecord<string, number>;\n\nexport interface BenchmarkMeasurement {\n name: string;\n category: string;\n start: Date;\n end: Date;\n elapsed: number;\n memory: number;\n}\n\nexport interface BenchmarkEnableOnCallable {\n (): Promise<boolean>;\n}\n\nexport interface BenchmarkOutputCallableParams {\n benchmark: Benchmark;\n stop: () => \"stop\";\n}\nexport interface BenchmarkOutputCallable {\n (params: BenchmarkOutputCallableParams): Promise<\"stop\" | undefined | null | void>;\n}\nexport interface BenchmarkMeasureOptions {\n name: string;\n category: string;\n}\nexport interface Benchmark {\n elapsed: number;\n runs: BenchmarkRuns;\n measurements: BenchmarkMeasurement[];\n output: () => Promise<void>;\n onOutput: (cb: BenchmarkOutputCallable) => void;\n enableOn: (cb: BenchmarkEnableOnCallable) => void;\n measure: <T = any>(\n options: BenchmarkMeasureOptions | string,\n cb: () => Promise<T>\n ) => Promise<T>;\n enable: () => void;\n disable: () => void;\n}\n\n/**\n * The main context which is constructed on every request.\n * All other contexts should extend or augment this one.\n */\nexport interface Context {\n plugins: PluginsContainer;\n readonly WEBINY_VERSION: string;\n /**\n * Not to be used outside of Webiny internal code.\n * @internal\n */\n hasResult: () => boolean;\n /**\n * Not to be used outside of Webiny internal code.\n * @internal\n *\n * @private\n */\n _result?: unknown;\n /**\n * Not to be used outside of Webiny internal code.\n * @internal\n */\n setResult: (value: unknown) => void;\n /**\n * Not to be used outside of Webiny internal code.\n * @internal\n */\n getResult: () => void;\n /**\n * Wait for property to be defined on the object and then execute the callable.\n * In case of multiple objects defined, wait for all of them.\n */\n waitFor: <T extends Context = Context>(\n obj: string[] | string,\n cb: (context: T) => void\n ) => void;\n /**\n * Benchmark instance to help determine possible bugs and slow code.\n */\n benchmark: Benchmark;\n /**\n * Compressor instance to compress and decompress the data.\n */\n compressor: ICompressor;\n}\n"],"mappings":"","ignoreList":[]}
|
|
1
|
+
{"version":3,"names":[],"sources":["types.ts"],"sourcesContent":["import type { PluginsContainer } from \"@webiny/plugins\";\nimport type { ICompressor } from \"@webiny/utils/compression/Compressor\";\n\nexport type GenericRecord<K extends PropertyKey = PropertyKey, V = any> = Record<K, V>;\n\nexport type NonEmptyArray<T> = [T, ...T[]];\n\nexport type PossiblyUndefinedProperties<T> = {\n [K in keyof T]: T[K] extends undefined ? T[K] : T[K] | undefined;\n};\n\nexport type BenchmarkRuns = GenericRecord<string, number>;\n\nexport interface BenchmarkMeasurement {\n name: string;\n category: string;\n start: Date;\n end: Date;\n elapsed: number;\n memory: number;\n}\n\nexport interface BenchmarkEnableOnCallable {\n (): Promise<boolean>;\n}\n\nexport interface BenchmarkOutputCallableParams {\n benchmark: Benchmark;\n stop: () => \"stop\";\n}\nexport interface BenchmarkOutputCallable {\n (params: BenchmarkOutputCallableParams): Promise<\"stop\" | undefined | null | void>;\n}\nexport interface BenchmarkMeasureOptions {\n name: string;\n category: string;\n}\nexport interface Benchmark {\n elapsed: number;\n runs: BenchmarkRuns;\n measurements: BenchmarkMeasurement[];\n output: () => Promise<void>;\n onOutput: (cb: BenchmarkOutputCallable) => void;\n enableOn: (cb: BenchmarkEnableOnCallable) => void;\n measure: <T = any>(\n options: BenchmarkMeasureOptions | string,\n cb: () => Promise<T>\n ) => Promise<T>;\n enable: () => void;\n disable: () => void;\n}\n\n/**\n * The main context which is constructed on every request.\n * All other contexts should extend or augment this one.\n */\nexport interface Context {\n plugins: PluginsContainer;\n readonly WEBINY_VERSION: string;\n /**\n * Not to be used outside of Webiny internal code.\n * @internal\n */\n hasResult: () => boolean;\n /**\n * Not to be used outside of Webiny internal code.\n * @internal\n *\n * @private\n */\n _result?: unknown;\n /**\n * Not to be used outside of Webiny internal code.\n * @internal\n */\n setResult: (value: unknown) => void;\n /**\n * Not to be used outside of Webiny internal code.\n * @internal\n */\n getResult: () => void;\n /**\n * Wait for property to be defined on the object and then execute the callable.\n * In case of multiple objects defined, wait for all of them.\n */\n waitFor: <T extends Context = Context>(\n obj: string[] | string,\n cb: (context: T) => void\n ) => void;\n /**\n * Benchmark instance to help determine possible bugs and slow code.\n */\n benchmark: Benchmark;\n /**\n * Compressor instance to compress and decompress the data.\n */\n compressor: ICompressor;\n}\n"],"mappings":"","ignoreList":[]}
|