mirror of
https://github.com/Azure/cosmos-explorer.git
synced 2026-06-12 15:37:27 +01:00
add copy of cosmos node.js SDK as local dependency
This commit is contained in:
committed by
Chris Anderson
parent
ff1e733679
commit
ca396cdfbe
@@ -0,0 +1,54 @@
|
||||
import { DiagnosticNodeInternal } from "../diagnostics/DiagnosticNodeInternal";
|
||||
import { RequestContext } from "../request/RequestContext";
|
||||
import { Response } from "../request/Response";
|
||||
/**
|
||||
* Used to specify which type of events to execute this plug in on.
|
||||
*
|
||||
* @hidden
|
||||
*/
|
||||
export declare enum PluginOn {
|
||||
/**
|
||||
* Will be executed per network request
|
||||
*/
|
||||
request = "request",
|
||||
/**
|
||||
* Will be executed per API operation
|
||||
*/
|
||||
operation = "operation"
|
||||
}
|
||||
/**
|
||||
* Specifies which event to run for the specified plugin
|
||||
*
|
||||
* @hidden
|
||||
*/
|
||||
export interface PluginConfig {
|
||||
/**
|
||||
* The event to run the plugin on
|
||||
*/
|
||||
on: keyof typeof PluginOn;
|
||||
/**
|
||||
* The plugin to run
|
||||
*/
|
||||
plugin: Plugin<any>;
|
||||
}
|
||||
/**
|
||||
* Plugins allow you to customize the behavior of the SDk with additional logging, retry, or additional functionality.
|
||||
*
|
||||
* A plugin is a function which returns a `Promise<Response<T>>`, and is passed a RequestContext and Next object.
|
||||
*
|
||||
* Next is a function which takes in requestContext returns a promise. You must await/then that promise which will contain the response from further plugins,
|
||||
* allowing you to log those results or handle errors.
|
||||
*
|
||||
* RequestContext is an object which controls what operation is happening, against which endpoint, and more. Modifying this and passing it along via next is how
|
||||
* you modify future SDK behavior.
|
||||
*
|
||||
* @hidden
|
||||
*/
|
||||
export type Plugin<T> = (context: RequestContext, diagnosticNode: DiagnosticNodeInternal, next: Next<T>) => Promise<Response<T>>;
|
||||
/**
|
||||
* Next is a function which takes in requestContext returns a promise. You must await/then that promise which will contain the response from further plugins,
|
||||
* allowing you to log those results or handle errors.
|
||||
* @hidden
|
||||
*/
|
||||
export type Next<T> = (context: RequestContext) => Promise<Response<T>>;
|
||||
//# sourceMappingURL=Plugin.d.ts.map
|
||||
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"Plugin.d.ts","sourceRoot":"","sources":["../../../src/plugins/Plugin.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,sBAAsB,EAAE,MAAM,uCAAuC,CAAC;AAC/E,OAAO,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAC3D,OAAO,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AAE/C;;;;GAIG;AACH,oBAAY,QAAQ;IAClB;;OAEG;IACH,OAAO,YAAY;IACnB;;OAEG;IACH,SAAS,cAAc;CACxB;AAED;;;;GAIG;AACH,MAAM,WAAW,YAAY;IAC3B;;OAEG;IACH,EAAE,EAAE,MAAM,OAAO,QAAQ,CAAC;IAC1B;;OAEG;IACH,MAAM,EAAE,MAAM,CAAC,GAAG,CAAC,CAAC;CACrB;AAED;;;;;;;;;;;;GAYG;AACH,MAAM,MAAM,MAAM,CAAC,CAAC,IAAI,CACtB,OAAO,EAAE,cAAc,EACvB,cAAc,EAAE,sBAAsB,EACtC,IAAI,EAAE,IAAI,CAAC,CAAC,CAAC,KACV,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC;AAE1B;;;;GAIG;AACH,MAAM,MAAM,IAAI,CAAC,CAAC,IAAI,CAAC,OAAO,EAAE,cAAc,KAAK,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC"}
|
||||
@@ -0,0 +1,43 @@
|
||||
/**
|
||||
* Used to specify which type of events to execute this plug in on.
|
||||
*
|
||||
* @hidden
|
||||
*/
|
||||
export var PluginOn;
|
||||
(function (PluginOn) {
|
||||
/**
|
||||
* Will be executed per network request
|
||||
*/
|
||||
PluginOn["request"] = "request";
|
||||
/**
|
||||
* Will be executed per API operation
|
||||
*/
|
||||
PluginOn["operation"] = "operation";
|
||||
})(PluginOn || (PluginOn = {}));
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
export async function executePlugins(diagnosticNode, requestContext, next, on) {
|
||||
if (!requestContext.plugins) {
|
||||
return next(requestContext, diagnosticNode, undefined);
|
||||
}
|
||||
let level = 0;
|
||||
const _ = (inner) => {
|
||||
if (++level >= inner.plugins.length) {
|
||||
return next(requestContext, diagnosticNode, undefined);
|
||||
}
|
||||
else if (inner.plugins[level].on !== on) {
|
||||
return _(requestContext);
|
||||
}
|
||||
else {
|
||||
return inner.plugins[level].plugin(inner, diagnosticNode, _);
|
||||
}
|
||||
};
|
||||
if (requestContext.plugins[level].on !== on) {
|
||||
return _(requestContext);
|
||||
}
|
||||
else {
|
||||
return requestContext.plugins[level].plugin(requestContext, diagnosticNode, _);
|
||||
}
|
||||
}
|
||||
//# sourceMappingURL=Plugin.js.map
|
||||
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"Plugin.js","sourceRoot":"","sources":["../../../src/plugins/Plugin.ts"],"names":[],"mappings":"AAMA;;;;GAIG;AACH,MAAM,CAAN,IAAY,QASX;AATD,WAAY,QAAQ;IAClB;;OAEG;IACH,+BAAmB,CAAA;IACnB;;OAEG;IACH,mCAAuB,CAAA;AACzB,CAAC,EATW,QAAQ,KAAR,QAAQ,QASnB;AA4CD;;GAEG;AACH,MAAM,CAAC,KAAK,UAAU,cAAc,CAClC,cAAsC,EACtC,cAA8B,EAC9B,IAAiB,EACjB,EAAY;IAEZ,IAAI,CAAC,cAAc,CAAC,OAAO,EAAE;QAC3B,OAAO,IAAI,CAAC,cAAc,EAAE,cAAc,EAAE,SAAS,CAAC,CAAC;KACxD;IACD,IAAI,KAAK,GAAG,CAAC,CAAC;IACd,MAAM,CAAC,GAAc,CAAC,KAAqB,EAA0B,EAAE;QACrE,IAAI,EAAE,KAAK,IAAI,KAAK,CAAC,OAAO,CAAC,MAAM,EAAE;YACnC,OAAO,IAAI,CAAC,cAAc,EAAE,cAAc,EAAE,SAAS,CAAC,CAAC;SACxD;aAAM,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,EAAE,KAAK,EAAE,EAAE;YACzC,OAAO,CAAC,CAAC,cAAc,CAAC,CAAC;SAC1B;aAAM;YACL,OAAO,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,MAAM,CAAC,KAAK,EAAE,cAAc,EAAE,CAAC,CAAC,CAAC;SAC9D;IACH,CAAC,CAAC;IACF,IAAI,cAAc,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,EAAE,KAAK,EAAE,EAAE;QAC3C,OAAO,CAAC,CAAC,cAAc,CAAC,CAAC;KAC1B;SAAM;QACL,OAAO,cAAc,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,MAAM,CAAC,cAAc,EAAE,cAAc,EAAE,CAAC,CAAC,CAAC;KAChF;AACH,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\nimport { DiagnosticNodeInternal } from \"../diagnostics/DiagnosticNodeInternal\";\nimport { RequestContext } from \"../request/RequestContext\";\nimport { Response } from \"../request/Response\";\n\n/**\n * Used to specify which type of events to execute this plug in on.\n *\n * @hidden\n */\nexport enum PluginOn {\n /**\n * Will be executed per network request\n */\n request = \"request\",\n /**\n * Will be executed per API operation\n */\n operation = \"operation\",\n}\n\n/**\n * Specifies which event to run for the specified plugin\n *\n * @hidden\n */\nexport interface PluginConfig {\n /**\n * The event to run the plugin on\n */\n on: keyof typeof PluginOn;\n /**\n * The plugin to run\n */\n plugin: Plugin<any>;\n}\n\n/**\n * Plugins allow you to customize the behavior of the SDk with additional logging, retry, or additional functionality.\n *\n * A plugin is a function which returns a `Promise<Response<T>>`, and is passed a RequestContext and Next object.\n *\n * Next is a function which takes in requestContext returns a promise. You must await/then that promise which will contain the response from further plugins,\n * allowing you to log those results or handle errors.\n *\n * RequestContext is an object which controls what operation is happening, against which endpoint, and more. Modifying this and passing it along via next is how\n * you modify future SDK behavior.\n *\n * @hidden\n */\nexport type Plugin<T> = (\n context: RequestContext,\n diagnosticNode: DiagnosticNodeInternal,\n next: Next<T>,\n) => Promise<Response<T>>;\n\n/**\n * Next is a function which takes in requestContext returns a promise. You must await/then that promise which will contain the response from further plugins,\n * allowing you to log those results or handle errors.\n * @hidden\n */\nexport type Next<T> = (context: RequestContext) => Promise<Response<T>>;\n\n/**\n * @internal\n */\nexport async function executePlugins(\n diagnosticNode: DiagnosticNodeInternal,\n requestContext: RequestContext,\n next: Plugin<any>,\n on: PluginOn,\n): Promise<Response<any>> {\n if (!requestContext.plugins) {\n return next(requestContext, diagnosticNode, undefined);\n }\n let level = 0;\n const _: Next<any> = (inner: RequestContext): Promise<Response<any>> => {\n if (++level >= inner.plugins.length) {\n return next(requestContext, diagnosticNode, undefined);\n } else if (inner.plugins[level].on !== on) {\n return _(requestContext);\n } else {\n return inner.plugins[level].plugin(inner, diagnosticNode, _);\n }\n };\n if (requestContext.plugins[level].on !== on) {\n return _(requestContext);\n } else {\n return requestContext.plugins[level].plugin(requestContext, diagnosticNode, _);\n }\n}\n"]}
|
||||
Reference in New Issue
Block a user