@proteinjs/service 1.2.0 → 1.2.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/dist/generated/index.js +1 -1
- package/dist/generated/index.js.map +1 -1
- package/dist/src/Service.d.ts +9 -2
- package/dist/src/Service.d.ts.map +1 -1
- package/dist/src/Service.js +3 -3
- package/dist/src/Service.js.map +1 -1
- package/dist/src/ServiceClient.js +1 -1
- package/dist/src/ServiceClient.js.map +1 -1
- package/dist/src/ServiceExecutor.d.ts +1 -0
- package/dist/src/ServiceExecutor.d.ts.map +1 -1
- package/dist/src/ServiceExecutor.js +19 -9
- package/dist/src/ServiceExecutor.js.map +1 -1
- package/generated/index.ts +7 -4
- package/package.json +9 -10
- package/src/Service.ts +12 -5
- package/src/ServiceClient.ts +1 -1
- package/src/ServiceExecutor.ts +14 -1
- package/LICENSE +0 -21
package/dist/generated/index.js
CHANGED
|
@@ -22,7 +22,7 @@ require("@proteinjs/server-api");
|
|
|
22
22
|
require("@proteinjs/user-auth");
|
|
23
23
|
require("@proteinjs/util");
|
|
24
24
|
/** Generate Source Graph */
|
|
25
|
-
var sourceGraph = "{\"options\":{\"directed\":true,\"multigraph\":false,\"compound\":false},\"nodes\":[{\"v\":\"@proteinjs/service/Service\",\"value\":{\"packageName\":\"@proteinjs/service\",\"name\":\"Service\",\"filePath\":\"/
|
|
25
|
+
var sourceGraph = "{\"options\":{\"directed\":true,\"multigraph\":false,\"compound\":false},\"nodes\":[{\"v\":\"@proteinjs/service/MethodDebounceConfig\"},{\"v\":\"@proteinjs/service/Service\",\"value\":{\"packageName\":\"@proteinjs/service\",\"name\":\"Service\",\"filePath\":\"/Users/brentbahry/repos/n3xa/packages/proteinjs/packages/service/packages/service/src/Service.ts\",\"qualifiedName\":\"@proteinjs/service/Service\",\"properties\":[{\"name\":\"serviceMetadata\",\"type\":{\"packageName\":\"@proteinjs/service\",\"name\":\"{\\n auth?: {\\n /** If true, the user does not need to be logged in or have any roles to call this service. If blank, defaults to false. */\\n public?: boolean;\\n /** If true, the user does not need to have any roles to call this service, but must be logged in. If blank, defaults to false. */\\n allUsers?: boolean;\\n /** The user must be logged in and have these roles to call this service. If blank, defaults to requiring the 'admin' role. */\\n roles?: string[];\\n /**\\n * Custom auth function. If provided, all other auth properties are ignored.\\n * @param methodName the name of the service method to be executed\\n * @param args the args[] that will be passed into the method\\n * @return true if the user can access the service method\\n */\\n canAccess?: (methodName: string, args: any[]) => boolean;\\n };\\n /** Don't await the service's execution, return a response to the client immediately */\\n doNotAwait?: boolean;\\n /** Don't await the service's execution, return a response to the client immediately (configured per method) */\\n doNotAwaitMethod?: MethodAwaitConfig;\\n }\",\"filePath\":null,\"qualifiedName\":\"@proteinjs/service/{\\n auth?: {\\n /** If true, the user does not need to be logged in or have any roles to call this service. If blank, defaults to false. */\\n public?: boolean;\\n /** If true, the user does not need to have any roles to call this service, but must be logged in. If blank, defaults to false. */\\n allUsers?: boolean;\\n /** The user must be logged in and have these roles to call this service. If blank, defaults to requiring the 'admin' role. */\\n roles?: string[];\\n /**\\n * Custom auth function. If provided, all other auth properties are ignored.\\n * @param methodName the name of the service method to be executed\\n * @param args the args[] that will be passed into the method\\n * @return true if the user can access the service method\\n */\\n canAccess?: (methodName: string, args: any[]) => boolean;\\n };\\n /** Don't await the service's execution, return a response to the client immediately */\\n doNotAwait?: boolean;\\n /** Don't await the service's execution, return a response to the client immediately (configured per method) */\\n doNotAwaitMethod?: MethodAwaitConfig;\\n }\",\"typeParameters\":null,\"directParents\":null},\"isOptional\":true,\"isAbstract\":false,\"isStatic\":false,\"visibility\":\"public\"}],\"methods\":[],\"typeParameters\":[],\"directParents\":[{\"packageName\":\"@proteinjs/reflection\",\"name\":\"Loadable\",\"filePath\":null,\"qualifiedName\":\"@proteinjs/reflection/Loadable\",\"properties\":[],\"methods\":[],\"typeParameters\":[],\"directParents\":[]}],\"sourceType\":3}},{\"v\":\"@proteinjs/reflection/Loadable\"},{\"v\":\"/Error\"},{\"v\":\"@proteinjs/service/ServiceRouter\",\"value\":{\"packageName\":\"@proteinjs/service\",\"name\":\"ServiceRouter\",\"filePath\":\"/Users/brentbahry/repos/n3xa/packages/proteinjs/packages/service/packages/service/src/ServiceRouter.ts\",\"qualifiedName\":\"@proteinjs/service/ServiceRouter\",\"isAbstract\":false,\"isStatic\":false,\"visibility\":\"public\",\"properties\":[{\"name\":\"logger\",\"type\":null,\"isOptional\":false,\"isAbstract\":false,\"isStatic\":false,\"visibility\":\"private\"},{\"name\":\"serviceExecutorMap\",\"type\":{\"packageName\":\"@proteinjs/service\",\"name\":\"{ [path: string]: ServiceExecutor } | undefined\",\"filePath\":null,\"qualifiedName\":\"@proteinjs/service/{ [path: string]: ServiceExecutor } | undefined\",\"typeParameters\":null,\"directParents\":null},\"isOptional\":false,\"isAbstract\":false,\"isStatic\":false,\"visibility\":\"private\"},{\"name\":\"path\",\"type\":null,\"isOptional\":false,\"isAbstract\":false,\"isStatic\":false,\"visibility\":\"public\"},{\"name\":\"method\",\"type\":{\"packageName\":\"\",\"name\":\"'post'\",\"filePath\":null,\"qualifiedName\":\"/'post'\",\"typeParameters\":null,\"directParents\":null},\"isOptional\":false,\"isAbstract\":false,\"isStatic\":false,\"visibility\":\"public\"}],\"methods\":[{\"name\":\"getServiceExecutorMap\",\"returnType\":null,\"isAsync\":false,\"isOptional\":false,\"isAbstract\":false,\"isStatic\":false,\"visibility\":\"private\",\"parameters\":[]},{\"name\":\"onRequest\",\"returnType\":{\"packageName\":\"\",\"name\":\"Promise<any>\",\"filePath\":null,\"qualifiedName\":\"/Promise<any>\",\"typeParameters\":null,\"directParents\":null},\"isAsync\":true,\"isOptional\":false,\"isAbstract\":false,\"isStatic\":false,\"visibility\":\"public\",\"parameters\":[{\"name\":\"request\",\"type\":{\"packageName\":\"\",\"name\":\"any\",\"filePath\":null,\"qualifiedName\":\"/any\",\"typeParameters\":null,\"directParents\":null}},{\"name\":\"response\",\"type\":{\"packageName\":\"\",\"name\":\"any\",\"filePath\":null,\"qualifiedName\":\"/any\",\"typeParameters\":null,\"directParents\":null}}]}],\"typeParameters\":[],\"directParentInterfaces\":[{\"packageName\":\"@proteinjs/server-api\",\"name\":\"Route\",\"filePath\":null,\"qualifiedName\":\"@proteinjs/server-api/Route\",\"properties\":[],\"methods\":[],\"typeParameters\":[],\"directParents\":[]}],\"directParentClasses\":[],\"sourceType\":2}},{\"v\":\"@proteinjs/server-api/Route\"}],\"edges\":[{\"v\":\"@proteinjs/service/Service\",\"w\":\"@proteinjs/reflection/Loadable\",\"value\":\"extends interface\"},{\"v\":\"@proteinjs/service/ServiceRouter\",\"w\":\"@proteinjs/server-api/Route\",\"value\":\"implements interface\"}]}";
|
|
26
26
|
/** Generate Source Links */
|
|
27
27
|
var ServiceRouter_1 = require("../src/ServiceRouter");
|
|
28
28
|
var sourceLinks = {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../generated/index.ts"],"names":[],"mappings":";AAAA,oCAAoC;;;;;;;;;;;;;;;;AAEpC,6BAA2B;AAC3B,iCAA+B;AAC/B,iCAA+B;AAC/B,iCAA+B;AAC/B,gCAA8B;AAC9B,2BAAyB;AAGzB,4BAA4B;AAE5B,IAAM,WAAW,GAAG,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../generated/index.ts"],"names":[],"mappings":";AAAA,oCAAoC;;;;;;;;;;;;;;;;AAEpC,6BAA2B;AAC3B,iCAA+B;AAC/B,iCAA+B;AAC/B,iCAA+B;AAC/B,gCAA8B;AAC9B,2BAAyB;AAGzB,4BAA4B;AAE5B,IAAM,WAAW,GAAG,i/LAAi/L,CAAC;AAGtgM,4BAA4B;AAE5B,sDAAqD;AAErD,IAAM,WAAW,GAAG;IACnB,kCAAkC,EAAE,6BAAa;CACjD,CAAC;AAGF,kCAAkC;AAElC,oDAAyD;AACzD,6BAAgB,CAAC,KAAK,CAAC,WAAW,EAAE,WAAW,CAAC,CAAC;AAGjD,2CAAyB"}
|
package/dist/src/Service.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { SerializableFunction, NotFunction } from '@proteinjs/serializer';
|
|
2
2
|
import { Loadable } from '@proteinjs/reflection';
|
|
3
|
-
import { Debouncer } from '@proteinjs/util';
|
|
3
|
+
import { Debouncer, GetDebounceKey } from '@proteinjs/util';
|
|
4
4
|
type RemoveIndex<T> = {
|
|
5
5
|
[K in keyof T as string extends K ? never : number extends K ? never : symbol extends K ? never : K]: T[K];
|
|
6
6
|
};
|
|
@@ -12,10 +12,15 @@ type RetryConfig<T extends Service> = {
|
|
|
12
12
|
};
|
|
13
13
|
interface DebounceConfig {
|
|
14
14
|
waitTime: number;
|
|
15
|
+
getDebounceKey?: GetDebounceKey;
|
|
15
16
|
}
|
|
16
17
|
type MethodDebounceConfig<T extends Service> = {
|
|
17
18
|
[K in KeysWithoutService<T>]?: DebounceConfig;
|
|
18
19
|
};
|
|
20
|
+
type MethodAwaitConfig = {
|
|
21
|
+
[methodName: string]: boolean;
|
|
22
|
+
};
|
|
23
|
+
export type ServiceDebounceConfig<T extends Service> = MethodDebounceConfig<T> | Debouncer;
|
|
19
24
|
export interface Service extends Loadable {
|
|
20
25
|
serviceMetadata?: {
|
|
21
26
|
auth?: {
|
|
@@ -35,6 +40,8 @@ export interface Service extends Loadable {
|
|
|
35
40
|
};
|
|
36
41
|
/** Don't await the service's execution, return a response to the client immediately */
|
|
37
42
|
doNotAwait?: boolean;
|
|
43
|
+
/** Don't await the service's execution, return a response to the client immediately (configured per method) */
|
|
44
|
+
doNotAwaitMethod?: MethodAwaitConfig;
|
|
38
45
|
};
|
|
39
46
|
[prop: string]: SerializableFunction | NotFunction<any>;
|
|
40
47
|
}
|
|
@@ -45,6 +52,6 @@ export interface Service extends Loadable {
|
|
|
45
52
|
* @param debouncer pass in either a single debouncer instance or method-specific debounce configurations
|
|
46
53
|
* @returns a function that creates a Service
|
|
47
54
|
*/
|
|
48
|
-
export declare const serviceFactory: <T extends Service>(serviceInterfaceQualifiedName: string, debouncer?:
|
|
55
|
+
export declare const serviceFactory: <T extends Service>(serviceInterfaceQualifiedName: string, debouncer?: ServiceDebounceConfig<T> | undefined, retryConfig?: RetryConfig<T> | undefined) => () => T;
|
|
49
56
|
export {};
|
|
50
57
|
//# sourceMappingURL=Service.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Service.d.ts","sourceRoot":"","sources":["../../src/Service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AAC1E,OAAO,EAAE,QAAQ,EAAoB,MAAM,uBAAuB,CAAC;AAEnE,OAAO,EAAE,SAAS,EAAgB,MAAM,iBAAiB,CAAC;
|
|
1
|
+
{"version":3,"file":"Service.d.ts","sourceRoot":"","sources":["../../src/Service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AAC1E,OAAO,EAAE,QAAQ,EAAoB,MAAM,uBAAuB,CAAC;AAEnE,OAAO,EAAE,SAAS,EAAE,cAAc,EAAgB,MAAM,iBAAiB,CAAC;AAE1E,KAAK,WAAW,CAAC,CAAC,IAAI;KACnB,CAAC,IAAI,MAAM,CAAC,IAAI,MAAM,SAAS,CAAC,GAAG,KAAK,GAAG,MAAM,SAAS,CAAC,GAAG,KAAK,GAAG,MAAM,SAAS,CAAC,GAAG,KAAK,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;CAC3G,CAAC;AACF,KAAK,yBAAyB,CAAC,CAAC,IAAI,MAAM,WAAW,CAAC,CAAC,CAAC,CAAC;AAGzD,KAAK,IAAI,CAAC,CAAC,EAAE,CAAC,IAAI,CAAC,SAAS,CAAC,GAAG,KAAK,GAAG,CAAC,CAAC;AAG1C,KAAK,kBAAkB,CAAC,CAAC,SAAS,OAAO,IAAI,IAAI,CAAC,yBAAyB,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AM,wGAkCtC,CAAC"}
|
package/dist/src/Service.js
CHANGED
|
@@ -8,9 +8,9 @@ var debouncerMap = {};
|
|
|
8
8
|
/** Retrieve an existing debouncer from the map or make a new one.
|
|
9
9
|
* This allows the debouncer instance per method to remain the same across multiple service calls.
|
|
10
10
|
*/
|
|
11
|
-
function getOrCreateDebouncer(methodName,
|
|
11
|
+
function getOrCreateDebouncer(methodName, config) {
|
|
12
12
|
if (!debouncerMap[methodName]) {
|
|
13
|
-
debouncerMap[methodName] = new util_1.Debouncer(waitTime);
|
|
13
|
+
debouncerMap[methodName] = new util_1.Debouncer(config.waitTime, config.getDebounceKey);
|
|
14
14
|
}
|
|
15
15
|
return debouncerMap[methodName];
|
|
16
16
|
}
|
|
@@ -41,7 +41,7 @@ var serviceFactory = function (serviceInterfaceQualifiedName, debouncer, retryCo
|
|
|
41
41
|
else if (methodName in debouncer) {
|
|
42
42
|
var methodConfig = debouncer[methodName];
|
|
43
43
|
if (methodConfig) {
|
|
44
|
-
methodDebouncer = getOrCreateDebouncer(methodName, methodConfig
|
|
44
|
+
methodDebouncer = getOrCreateDebouncer(methodName, methodConfig);
|
|
45
45
|
}
|
|
46
46
|
}
|
|
47
47
|
}
|
package/dist/src/Service.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Service.js","sourceRoot":"","sources":["../../src/Service.ts"],"names":[],"mappings":";;;AACA,oDAAmE;AACnE,iDAAgD;AAChD,
|
|
1
|
+
{"version":3,"file":"Service.js","sourceRoot":"","sources":["../../src/Service.ts"],"names":[],"mappings":";;;AACA,oDAAmE;AACnE,iDAAgD;AAChD,wCAA0E;AAuD1E,IAAM,YAAY,GAAiC,EAAE,CAAC;AACtD;;GAEG;AACH,SAAS,oBAAoB,CAAC,UAAkB,EAAE,MAAsB;IACtE,IAAI,CAAC,YAAY,CAAC,UAAU,CAAC,EAAE;QAC7B,YAAY,CAAC,UAAU,CAAC,GAAG,IAAI,gBAAS,CAAC,MAAM,CAA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CAAC,IAAI,CAAC,aAAa,CAAC,CAAC;SAC9D;QAED,OAAO,OAAO,CAAC;IACjB,CAAC,CAAC;AACJ,CAAC,CAAC;AAnCW,QAAA,cAAc,kBAmCzB"}
|
|
@@ -111,7 +111,7 @@ var ServiceClient = /** @class */ (function () {
|
|
|
111
111
|
}); };
|
|
112
112
|
executeRequest = this.retryCount > 0 ? executeWithRetry : function (fn) { return fn(); };
|
|
113
113
|
if (this.debouncer) {
|
|
114
|
-
return [2 /*return*/, this.debouncer.debounce(function () { return executeRequest(sendRequest); })];
|
|
114
|
+
return [2 /*return*/, this.debouncer.debounce(function () { return executeRequest(sendRequest); }, args)];
|
|
115
115
|
}
|
|
116
116
|
else {
|
|
117
117
|
return [2 /*return*/, executeRequest(sendRequest)];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ServiceClient.js","sourceRoot":"","sources":["../../src/ServiceClient.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACA,oDAAmD;AAEnD,uDAAsD;AAEtD;IAGE,uBACU,WAAmB,EACnB,aAAqB,EACrB,SAAqB,EACrB,UAAsB;QAAtB,2BAAA,EAAA,cAAsB;QAHtB,gBAAW,GAAX,WAAW,CAAQ;QACnB,kBAAa,GAAb,aAAa,CAAQ;QACrB,cAAS,GAAT,SAAS,CAAY;QACrB,eAAU,GAAV,UAAU,CAAY;IAC7B,CAAC;IAEE,4BAAI,GAAV;QAAW,cAAc;aAAd,UAAc,EAAd,qBAAc,EAAd,IAAc;YAAd,yBAAc;;;;;;gBACjB,WAAW,GAAG;;;;;gCACZ,cAAc,GAAG,uBAAU,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC;gCAC5C,aAAa,GAAG,aAAa,CAAC,cAAc,CAAC;gCACnD,aAAa,CAAC,cAAc,EAAE,CAAC;gCAC/B,OAAO,CAAC,cAAc,CAAC,YAAK,aAAa,wCAA8B,IAAI,CAAC,WAAW,YAAS,CAAC,CA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vD,OAAO,GAAG,IAAI,OAAO,CAAC,WAAW,EAAE;4BACvC,MAAM,EAAE,MAAM;4BACd,IAAI,EAAE,cAAc;4BACpB,QAAQ,EAAE,QAAQ;4BAClB,WAAW,EAAE,aAAa;4BAC1B,OAAO,EAAE;gCACP,cAAc,EAAE,kBAAkB;6BACnC;yBACF,CAAC,CAAC;wBACc,qBAAM,KAAK,CAAC,OAAO,CAAC,EAAA;;wBAA/B,QAAQ,GAAG,SAAoB;wBACrC,IAAI,QAAQ,CAAC,MAAM,IAAI,GAAG,EAAE;4BAC1B,MAAM,IAAI,KAAK,CAAC,6CAAsC,WAAW,sBAAY,QAAQ,CAAC,UAAU,CAAE,CAAC,CAAC;yBACrG;wBAEY,qBAAM,QAAQ,CAAC,IAAI,EAAE,EAAA;;wBAA5B,IAAI,GAAG,SAAqB;wBAClC,IAAI,IAAI,CAAC,KAAK,EAAE;4BACd,MAAM,IAAI,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;yBAC7B;wBAED,sBAAO,IAAI,CAAC,gBAAgB,EAAC;;;;KAC9B;IAxEc,4BAAc,GAAG,CAAC,CAAC;IAyEpC,oBAAC;CAAA,AA1ED,IA0EC;AA1EY,sCAAa"}
|
|
@@ -12,6 +12,7 @@ export declare class ServiceExecutor {
|
|
|
12
12
|
private serviceMethodName;
|
|
13
13
|
constructor(service: Service, _interface: Interface, method: Method);
|
|
14
14
|
execute(requestBody: any): Promise<any>;
|
|
15
|
+
private doNotAwait;
|
|
15
16
|
private shouldLogArgsAndReturn;
|
|
16
17
|
}
|
|
17
18
|
//# sourceMappingURL=ServiceExecutor.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ServiceExecutor.d.ts","sourceRoot":"","sources":["../../src/ServiceExecutor.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,uBAAuB,CAAC;AAC1D,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAOpC,qBAAa,YAAa,SAAQ,KAAK;gBACzB,OAAO,EAAE,MAAM;CAI5B;AAED,qBAAa,eAAe;IAKjB,OAAO,EAAE,OAAO;IACvB,OAAO,CAAC,UAAU;IAClB,OAAO,CAAC,MAAM;IANhB,OAAO,CAAC,MAAM,CAAS;IAChB,gBAAgB,EAAE,GAAG,CAAC;IAC7B,OAAO,CAAC,iBAAiB,CAAS;gBAEzB,OAAO,EAAE,OAAO,EACf,UAAU,EAAE,SAAS,EACrB,MAAM,EAAE,MAAM;IAMlB,OAAO,CAAC,WAAW,EAAE,GAAG,GAAG,OAAO,CAAC,GAAG,CAAC;IA4C7C,OAAO,CAAC,sBAAsB;CAG/B"}
|
|
1
|
+
{"version":3,"file":"ServiceExecutor.d.ts","sourceRoot":"","sources":["../../src/ServiceExecutor.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,uBAAuB,CAAC;AAC1D,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAOpC,qBAAa,YAAa,SAAQ,KAAK;gBACzB,OAAO,EAAE,MAAM;CAI5B;AAED,qBAAa,eAAe;IAKjB,OAAO,EAAE,OAAO;IACvB,OAAO,CAAC,UAAU;IAClB,OAAO,CAAC,MAAM;IANhB,OAAO,CAAC,MAAM,CAAS;IAChB,gBAAgB,EAAE,GAAG,CAAC;IAC7B,OAAO,CAAC,iBAAiB,CAAS;gBAEzB,OAAO,EAAE,OAAO,EACf,UAAU,EAAE,SAAS,EACrB,MAAM,EAAE,MAAM;IAMlB,OAAO,CAAC,WAAW,EAAE,GAAG,GAAG,OAAO,CAAC,GAAG,CAAC;IA4C7C,OAAO,CAAC,UAAU;IAalB,OAAO,CAAC,sBAAsB;CAG/B"}
|
|
@@ -76,11 +76,10 @@ var ServiceExecutor = /** @class */ (function () {
|
|
|
76
76
|
this.logger = new logger_1.Logger({ name: this.serviceMethodName });
|
|
77
77
|
}
|
|
78
78
|
ServiceExecutor.prototype.execute = function (requestBody) {
|
|
79
|
-
var _a;
|
|
80
79
|
return __awaiter(this, void 0, void 0, function () {
|
|
81
80
|
var method, deserializedArgs, error, _return, error_1, serializedReturn;
|
|
82
|
-
return __generator(this, function (
|
|
83
|
-
switch (
|
|
81
|
+
return __generator(this, function (_a) {
|
|
82
|
+
switch (_a.label) {
|
|
84
83
|
case 0:
|
|
85
84
|
method = this.service[this.method.name].bind(this.service);
|
|
86
85
|
deserializedArgs = serializer_1.Serializer.deserialize(requestBody);
|
|
@@ -91,19 +90,19 @@ var ServiceExecutor = /** @class */ (function () {
|
|
|
91
90
|
error = "User not authorized to run service: ".concat(this._interface.name, ".").concat(this.method.name);
|
|
92
91
|
throw new Error(error);
|
|
93
92
|
}
|
|
94
|
-
|
|
93
|
+
_a.label = 1;
|
|
95
94
|
case 1:
|
|
96
|
-
|
|
97
|
-
if (!
|
|
95
|
+
_a.trys.push([1, 5, , 6]);
|
|
96
|
+
if (!this.doNotAwait()) return [3 /*break*/, 2];
|
|
98
97
|
method.apply(void 0, deserializedArgs);
|
|
99
98
|
return [3 /*break*/, 4];
|
|
100
99
|
case 2: return [4 /*yield*/, method.apply(void 0, deserializedArgs)];
|
|
101
100
|
case 3:
|
|
102
|
-
_return =
|
|
103
|
-
|
|
101
|
+
_return = _a.sent();
|
|
102
|
+
_a.label = 4;
|
|
104
103
|
case 4: return [3 /*break*/, 6];
|
|
105
104
|
case 5:
|
|
106
|
-
error_1 =
|
|
105
|
+
error_1 = _a.sent();
|
|
107
106
|
this.logger.error({
|
|
108
107
|
message: "Failed",
|
|
109
108
|
error: error_1,
|
|
@@ -129,6 +128,17 @@ var ServiceExecutor = /** @class */ (function () {
|
|
|
129
128
|
});
|
|
130
129
|
});
|
|
131
130
|
};
|
|
131
|
+
ServiceExecutor.prototype.doNotAwait = function () {
|
|
132
|
+
var _a, _b, _c;
|
|
133
|
+
if ((_a = this.service.serviceMetadata) === null || _a === void 0 ? void 0 : _a.doNotAwait) {
|
|
134
|
+
return true;
|
|
135
|
+
}
|
|
136
|
+
if ((_b = this.service.serviceMetadata) === null || _b === void 0 ? void 0 : _b.doNotAwaitMethod) {
|
|
137
|
+
var methodDoNotAwait = (_c = this.service.serviceMetadata) === null || _c === void 0 ? void 0 : _c.doNotAwaitMethod[this.method.name];
|
|
138
|
+
return typeof methodDoNotAwait === 'boolean' ? methodDoNotAwait : false;
|
|
139
|
+
}
|
|
140
|
+
return false;
|
|
141
|
+
};
|
|
132
142
|
ServiceExecutor.prototype.shouldLogArgsAndReturn = function () {
|
|
133
143
|
return !server_api_1.EnvInfo.isDev() || process.env.DETAILED_SERVICE_LOGS;
|
|
134
144
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ServiceExecutor.js","sourceRoot":"","sources":["../../src/ServiceExecutor.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEA,4CAA2C;AAC3C,oDAAmD;AACnD,6CAA4C;AAC5C,uDAAsD;AACtD,oDAAgD;AAEhD;IAAkC,gCAAK;IACrC,sBAAY,OAAe;QAA3B,YACE,kBAAM,OAAO,CAAC,SAEf;QADC,KAAI,CAAC,IAAI,GAAG,cAAc,CAAC;;IAC7B,CAAC;IACH,mBAAC;AAAD,CAAC,AALD,CAAkC,KAAK,GAKtC;AALY,oCAAY;AAOzB;IAIE,yBACS,OAAgB,EACf,UAAqB,EACrB,MAAc;QAFf,YAAO,GAAP,OAAO,CAAS;QACf,eAAU,GAAV,UAAU,CAAW;QACrB,WAAM,GAAN,MAAM,CAAQ;QAEtB,IAAI,CAAC,iBAAiB,GAAG,UAAG,UAAU,CAAC,IAAI,cAAI,MAAM,CAAC,IAAI,CAAE,CAAC;QAC7D,IAAI,CAAC,MAAM,GAAG,IAAI,eAAM,CAAC,EAAE,IAAI,EAAE,IAAI,CAAC,iBAAiB,EAAE,CAAC,CAAC;IAC7D,CAAC;IAEK,iCAAO,GAAb,UAA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E,YAAY,EAAE,IAAI,CAAC,iBAAiB,EAAE,MAAM,EAAE,OAAO,EAAE,EAAE,CAAC,CAAC;yBAC5G;wBACD,sBAAO,gBAAgB,EAAC;;;;KACzB;IAEO,oCAAU,GAAlB;;QACE,IAAI,MAAA,IAAI,CAAC,OAAO,CAAC,eAAe,0CAAE,UAAU,EAAE;YAC5C,OAAO,IAAI,CAAC;SACb;QAED,IAAI,MAAA,IAAI,CAAC,OAAO,CAAC,eAAe,0CAAE,gBAAgB,EAAE;YAClD,IAAM,gBAAgB,GAAG,MAAA,IAAI,CAAC,OAAO,CAAC,eAAe,0CAAE,gBAAgB,CAAC,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;YAC1F,OAAO,OAAO,gBAAgB,KAAK,SAAS,CAAC,CAAC,CAAC,gBAAgB,CAAC,CAAC,CAAC,KAAK,CAAC;SACzE;QAED,OAAO,KAAK,CAAC;IACf,CAAC;IAEO,gDAAsB,GAA9B;QACE,OAAO,CAAC,oBAAO,CAAC,KAAK,EAAE,IAAI,OAAO,CAAC,GAAG,CAAC,qBAAqB,CAAC;IAC/D,CAAC;IACH,sBAAC;AAAD,CAAC,AAzED,IAyEC;AAzEY,0CAAe"}
|
package/generated/index.ts
CHANGED
|
@@ -7,22 +7,25 @@ import '@proteinjs/server-api';
|
|
|
7
7
|
import '@proteinjs/user-auth';
|
|
8
8
|
import '@proteinjs/util';
|
|
9
9
|
|
|
10
|
+
|
|
10
11
|
/** Generate Source Graph */
|
|
11
12
|
|
|
12
|
-
const sourceGraph =
|
|
13
|
-
|
|
13
|
+
const sourceGraph = "{\"options\":{\"directed\":true,\"multigraph\":false,\"compound\":false},\"nodes\":[{\"v\":\"@proteinjs/service/MethodDebounceConfig\"},{\"v\":\"@proteinjs/service/Service\",\"value\":{\"packageName\":\"@proteinjs/service\",\"name\":\"Service\",\"filePath\":\"/Users/brentbahry/repos/n3xa/packages/proteinjs/packages/service/packages/service/src/Service.ts\",\"qualifiedName\":\"@proteinjs/service/Service\",\"properties\":[{\"name\":\"serviceMetadata\",\"type\":{\"packageName\":\"@proteinjs/service\",\"name\":\"{\\n auth?: {\\n /** If true, the user does not need to be logged in or have any roles to call this service. If blank, defaults to false. */\\n public?: boolean;\\n /** If true, the user does not need to have any roles to call this service, but must be logged in. If blank, defaults to false. */\\n allUsers?: boolean;\\n /** The user must be logged in and have these roles to call this service. If blank, defaults to requiring the 'admin' role. */\\n roles?: string[];\\n /**\\n * Custom auth function. If provided, all other auth properties are ignored.\\n * @param methodName the name of the service method to be executed\\n * @param args the args[] that will be passed into the method\\n * @return true if the user can access the service method\\n */\\n canAccess?: (methodName: string, args: any[]) => boolean;\\n };\\n /** Don't await the service's execution, return a response to the client immediately */\\n doNotAwait?: boolean;\\n /** Don't await the service's execution, return a response to the client immediately (configured per method) */\\n doNotAwaitMethod?: MethodAwaitConfig;\\n }\",\"filePath\":null,\"qualifiedName\":\"@proteinjs/service/{\\n auth?: {\\n /** If true, the user does not need to be logged in or have any roles to call this service. If blank, defaults to false. */\\n public?: boolean;\\n /** If true, the user does not need to have any roles to call this service, but must be logged in. If blank, defaults to false. */\\n allUsers?: boolean;\\n /** The user must be logged in and have these roles to call this service. If blank, defaults to requiring the 'admin' role. */\\n roles?: string[];\\n /**\\n * Custom auth function. If provided, all other auth properties are ignored.\\n * @param methodName the name of the service method to be executed\\n * @param args the args[] that will be passed into the method\\n * @return true if the user can access the service method\\n */\\n canAccess?: (methodName: string, args: any[]) => boolean;\\n };\\n /** Don't await the service's execution, return a response to the client immediately */\\n doNotAwait?: boolean;\\n /** Don't await the service's execution, return a response to the client immediately (configured per method) */\\n doNotAwaitMethod?: MethodAwaitConfig;\\n }\",\"typeParameters\":null,\"directParents\":null},\"isOptional\":true,\"isAbstract\":false,\"isStatic\":false,\"visibility\":\"public\"}],\"methods\":[],\"typeParameters\":[],\"directParents\":[{\"packageName\":\"@proteinjs/reflection\",\"name\":\"Loadable\",\"filePath\":null,\"qualifiedName\":\"@proteinjs/reflection/Loadable\",\"properties\":[],\"methods\":[],\"typeParameters\":[],\"directParents\":[]}],\"sourceType\":3}},{\"v\":\"@proteinjs/reflection/Loadable\"},{\"v\":\"/Error\"},{\"v\":\"@proteinjs/service/ServiceRouter\",\"value\":{\"packageName\":\"@proteinjs/service\",\"name\":\"ServiceRouter\",\"filePath\":\"/Users/brentbahry/repos/n3xa/packages/proteinjs/packages/service/packages/service/src/ServiceRouter.ts\",\"qualifiedName\":\"@proteinjs/service/ServiceRouter\",\"isAbstract\":false,\"isStatic\":false,\"visibility\":\"public\",\"properties\":[{\"name\":\"logger\",\"type\":null,\"isOptional\":false,\"isAbstract\":false,\"isStatic\":false,\"visibility\":\"private\"},{\"name\":\"serviceExecutorMap\",\"type\":{\"packageName\":\"@proteinjs/service\",\"name\":\"{ [path: string]: ServiceExecutor } | undefined\",\"filePath\":null,\"qualifiedName\":\"@proteinjs/service/{ [path: string]: ServiceExecutor } | undefined\",\"typeParameters\":null,\"directParents\":null},\"isOptional\":false,\"isAbstract\":false,\"isStatic\":false,\"visibility\":\"private\"},{\"name\":\"path\",\"type\":null,\"isOptional\":false,\"isAbstract\":false,\"isStatic\":false,\"visibility\":\"public\"},{\"name\":\"method\",\"type\":{\"packageName\":\"\",\"name\":\"'post'\",\"filePath\":null,\"qualifiedName\":\"/'post'\",\"typeParameters\":null,\"directParents\":null},\"isOptional\":false,\"isAbstract\":false,\"isStatic\":false,\"visibility\":\"public\"}],\"methods\":[{\"name\":\"getServiceExecutorMap\",\"returnType\":null,\"isAsync\":false,\"isOptional\":false,\"isAbstract\":false,\"isStatic\":false,\"visibility\":\"private\",\"parameters\":[]},{\"name\":\"onRequest\",\"returnType\":{\"packageName\":\"\",\"name\":\"Promise<any>\",\"filePath\":null,\"qualifiedName\":\"/Promise<any>\",\"typeParameters\":null,\"directParents\":null},\"isAsync\":true,\"isOptional\":false,\"isAbstract\":false,\"isStatic\":false,\"visibility\":\"public\",\"parameters\":[{\"name\":\"request\",\"type\":{\"packageName\":\"\",\"name\":\"any\",\"filePath\":null,\"qualifiedName\":\"/any\",\"typeParameters\":null,\"directParents\":null}},{\"name\":\"response\",\"type\":{\"packageName\":\"\",\"name\":\"any\",\"filePath\":null,\"qualifiedName\":\"/any\",\"typeParameters\":null,\"directParents\":null}}]}],\"typeParameters\":[],\"directParentInterfaces\":[{\"packageName\":\"@proteinjs/server-api\",\"name\":\"Route\",\"filePath\":null,\"qualifiedName\":\"@proteinjs/server-api/Route\",\"properties\":[],\"methods\":[],\"typeParameters\":[],\"directParents\":[]}],\"directParentClasses\":[],\"sourceType\":2}},{\"v\":\"@proteinjs/server-api/Route\"}],\"edges\":[{\"v\":\"@proteinjs/service/Service\",\"w\":\"@proteinjs/reflection/Loadable\",\"value\":\"extends interface\"},{\"v\":\"@proteinjs/service/ServiceRouter\",\"w\":\"@proteinjs/server-api/Route\",\"value\":\"implements interface\"}]}";
|
|
14
|
+
|
|
14
15
|
|
|
15
16
|
/** Generate Source Links */
|
|
16
17
|
|
|
17
18
|
import { ServiceRouter } from '../src/ServiceRouter';
|
|
18
19
|
|
|
19
20
|
const sourceLinks = {
|
|
20
|
-
|
|
21
|
+
'@proteinjs/service/ServiceRouter': ServiceRouter,
|
|
21
22
|
};
|
|
22
23
|
|
|
24
|
+
|
|
23
25
|
/** Load Source Graph and Links */
|
|
24
26
|
|
|
25
27
|
import { SourceRepository } from '@proteinjs/reflection';
|
|
26
28
|
SourceRepository.merge(sourceGraph, sourceLinks);
|
|
27
29
|
|
|
28
|
-
|
|
30
|
+
|
|
31
|
+
export * from '../index';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@proteinjs/service",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.1",
|
|
4
4
|
"description": "Service api",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
@@ -21,15 +21,15 @@
|
|
|
21
21
|
"watch": "reflection-watch"
|
|
22
22
|
},
|
|
23
23
|
"dependencies": {
|
|
24
|
-
"@proteinjs/logger": "1.0.
|
|
25
|
-
"@proteinjs/reflection": "1.1.
|
|
26
|
-
"@proteinjs/serializer": "1.0.
|
|
27
|
-
"@proteinjs/server-api": "1.5.
|
|
28
|
-
"@proteinjs/user-auth": "1.1.
|
|
29
|
-
"@proteinjs/util": "1.
|
|
24
|
+
"@proteinjs/logger": "1.0.7",
|
|
25
|
+
"@proteinjs/reflection": "1.1.10",
|
|
26
|
+
"@proteinjs/serializer": "1.0.16",
|
|
27
|
+
"@proteinjs/server-api": "1.5.1",
|
|
28
|
+
"@proteinjs/user-auth": "1.1.2",
|
|
29
|
+
"@proteinjs/util": "1.5.0"
|
|
30
30
|
},
|
|
31
31
|
"devDependencies": {
|
|
32
|
-
"@proteinjs/reflection-build": "1.0.
|
|
32
|
+
"@proteinjs/reflection-build": "1.0.25",
|
|
33
33
|
"@types/jest": "29.5.5",
|
|
34
34
|
"@types/node": "14.0.27",
|
|
35
35
|
"@typescript-eslint/eslint-plugin": "7.8.0",
|
|
@@ -42,6 +42,5 @@
|
|
|
42
42
|
"typescript": "5.2.2"
|
|
43
43
|
},
|
|
44
44
|
"main": "./dist/generated/index.js",
|
|
45
|
-
"types": "./dist/generated/index.d.ts"
|
|
46
|
-
"gitHead": "3de027b69d80594ca40d10c2069b6ec1ef119f89"
|
|
45
|
+
"types": "./dist/generated/index.d.ts"
|
|
47
46
|
}
|
package/src/Service.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { SerializableFunction, NotFunction } from '@proteinjs/serializer';
|
|
2
2
|
import { Loadable, SourceRepository } from '@proteinjs/reflection';
|
|
3
3
|
import { ServiceClient } from './ServiceClient';
|
|
4
|
-
import { Debouncer, isInstanceOf } from '@proteinjs/util';
|
|
4
|
+
import { Debouncer, GetDebounceKey, isInstanceOf } from '@proteinjs/util';
|
|
5
5
|
|
|
6
6
|
type RemoveIndex<T> = {
|
|
7
7
|
[K in keyof T as string extends K ? never : number extends K ? never : symbol extends K ? never : K]: T[K];
|
|
@@ -20,12 +20,17 @@ type RetryConfig<T extends Service> = {
|
|
|
20
20
|
|
|
21
21
|
interface DebounceConfig {
|
|
22
22
|
waitTime: number;
|
|
23
|
+
getDebounceKey?: GetDebounceKey;
|
|
23
24
|
}
|
|
24
25
|
|
|
25
26
|
type MethodDebounceConfig<T extends Service> = {
|
|
26
27
|
[K in KeysWithoutService<T>]?: DebounceConfig;
|
|
27
28
|
};
|
|
28
29
|
|
|
30
|
+
type MethodAwaitConfig = { [methodName: string]: boolean };
|
|
31
|
+
|
|
32
|
+
export type ServiceDebounceConfig<T extends Service> = MethodDebounceConfig<T> | Debouncer;
|
|
33
|
+
|
|
29
34
|
export interface Service extends Loadable {
|
|
30
35
|
serviceMetadata?: {
|
|
31
36
|
auth?: {
|
|
@@ -45,6 +50,8 @@ export interface Service extends Loadable {
|
|
|
45
50
|
};
|
|
46
51
|
/** Don't await the service's execution, return a response to the client immediately */
|
|
47
52
|
doNotAwait?: boolean;
|
|
53
|
+
/** Don't await the service's execution, return a response to the client immediately (configured per method) */
|
|
54
|
+
doNotAwaitMethod?: MethodAwaitConfig;
|
|
48
55
|
};
|
|
49
56
|
[prop: string]: SerializableFunction | NotFunction<any>;
|
|
50
57
|
}
|
|
@@ -53,9 +60,9 @@ const debouncerMap: { [key: string]: Debouncer } = {};
|
|
|
53
60
|
/** Retrieve an existing debouncer from the map or make a new one.
|
|
54
61
|
* This allows the debouncer instance per method to remain the same across multiple service calls.
|
|
55
62
|
*/
|
|
56
|
-
function getOrCreateDebouncer(methodName: string,
|
|
63
|
+
function getOrCreateDebouncer(methodName: string, config: DebounceConfig): Debouncer {
|
|
57
64
|
if (!debouncerMap[methodName]) {
|
|
58
|
-
debouncerMap[methodName] = new Debouncer(waitTime);
|
|
65
|
+
debouncerMap[methodName] = new Debouncer(config.waitTime, config.getDebounceKey);
|
|
59
66
|
}
|
|
60
67
|
return debouncerMap[methodName];
|
|
61
68
|
}
|
|
@@ -69,7 +76,7 @@ function getOrCreateDebouncer(methodName: string, waitTime: number): Debouncer {
|
|
|
69
76
|
*/
|
|
70
77
|
export const serviceFactory = <T extends Service>(
|
|
71
78
|
serviceInterfaceQualifiedName: string,
|
|
72
|
-
debouncer?:
|
|
79
|
+
debouncer?: ServiceDebounceConfig<T>,
|
|
73
80
|
retryConfig?: RetryConfig<T>
|
|
74
81
|
): (() => T) => {
|
|
75
82
|
return () => {
|
|
@@ -91,7 +98,7 @@ export const serviceFactory = <T extends Service>(
|
|
|
91
98
|
} else if (methodName in debouncer) {
|
|
92
99
|
const methodConfig = (debouncer as MethodDebounceConfig<T>)[methodName];
|
|
93
100
|
if (methodConfig) {
|
|
94
|
-
methodDebouncer = getOrCreateDebouncer(methodName as string, methodConfig
|
|
101
|
+
methodDebouncer = getOrCreateDebouncer(methodName as string, methodConfig);
|
|
95
102
|
}
|
|
96
103
|
}
|
|
97
104
|
}
|
package/src/ServiceClient.ts
CHANGED
|
@@ -49,7 +49,7 @@ export class ServiceClient {
|
|
|
49
49
|
const executeRequest = this.retryCount > 0 ? executeWithRetry : (fn: () => Promise<any>) => fn();
|
|
50
50
|
|
|
51
51
|
if (this.debouncer) {
|
|
52
|
-
return this.debouncer.debounce(() => executeRequest(sendRequest));
|
|
52
|
+
return this.debouncer.debounce(() => executeRequest(sendRequest), args);
|
|
53
53
|
} else {
|
|
54
54
|
return executeRequest(sendRequest);
|
|
55
55
|
}
|
package/src/ServiceExecutor.ts
CHANGED
|
@@ -39,7 +39,7 @@ export class ServiceExecutor {
|
|
|
39
39
|
|
|
40
40
|
let _return: any;
|
|
41
41
|
try {
|
|
42
|
-
if (this.
|
|
42
|
+
if (this.doNotAwait()) {
|
|
43
43
|
method(...deserializedArgs);
|
|
44
44
|
} else {
|
|
45
45
|
_return = await method(...deserializedArgs);
|
|
@@ -70,6 +70,19 @@ export class ServiceExecutor {
|
|
|
70
70
|
return serializedReturn;
|
|
71
71
|
}
|
|
72
72
|
|
|
73
|
+
private doNotAwait() {
|
|
74
|
+
if (this.service.serviceMetadata?.doNotAwait) {
|
|
75
|
+
return true;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
if (this.service.serviceMetadata?.doNotAwaitMethod) {
|
|
79
|
+
const methodDoNotAwait = this.service.serviceMetadata?.doNotAwaitMethod[this.method.name];
|
|
80
|
+
return typeof methodDoNotAwait === 'boolean' ? methodDoNotAwait : false;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
return false;
|
|
84
|
+
}
|
|
85
|
+
|
|
73
86
|
private shouldLogArgsAndReturn() {
|
|
74
87
|
return !EnvInfo.isDev() || process.env.DETAILED_SERVICE_LOGS;
|
|
75
88
|
}
|
package/LICENSE
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
MIT License
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2023 Brent Bahry
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
-
in the Software without restriction, including without limitation the rights
|
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
furnished to do so, subject to the following conditions:
|
|
11
|
-
|
|
12
|
-
The above copyright notice and this permission notice shall be included in all
|
|
13
|
-
copies or substantial portions of the Software.
|
|
14
|
-
|
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
-
SOFTWARE.
|