@webiny/handler-graphql 0.0.0-unstable.df6d94b531 → 0.0.0-unstable.e0bfc55d5a
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/ResolverDecoration.d.ts +6 -0
- package/ResolverDecoration.js +26 -0
- package/ResolverDecoration.js.map +1 -0
- package/builtInTypes/AnyScalar.js +3 -2
- package/builtInTypes/AnyScalar.js.map +1 -1
- package/builtInTypes/DateScalar.js +5 -5
- package/builtInTypes/DateScalar.js.map +1 -1
- package/builtInTypes/DateTimeScalar.js +5 -5
- package/builtInTypes/DateTimeScalar.js.map +1 -1
- package/builtInTypes/DateTimeZScalar.js +3 -2
- package/builtInTypes/DateTimeZScalar.js.map +1 -1
- package/builtInTypes/JsonScalar.js +3 -2
- package/builtInTypes/JsonScalar.js.map +1 -1
- package/builtInTypes/LongScalar.js +5 -5
- package/builtInTypes/LongScalar.js.map +1 -1
- package/builtInTypes/NumberScalar.js +6 -6
- package/builtInTypes/NumberScalar.js.map +1 -1
- package/builtInTypes/RefInputScalar.js +33 -11
- package/builtInTypes/RefInputScalar.js.map +1 -1
- package/builtInTypes/TimeScalar.js +3 -2
- package/builtInTypes/TimeScalar.js.map +1 -1
- package/builtInTypes/index.js +3 -1
- package/builtInTypes/index.js.map +1 -1
- package/createGraphQLHandler.d.ts +3 -3
- package/createGraphQLHandler.js +31 -5
- package/createGraphQLHandler.js.map +1 -1
- package/createGraphQLSchema.d.ts +3 -1
- package/createGraphQLSchema.js +47 -19
- package/createGraphQLSchema.js.map +1 -1
- package/createResolverDecorator.d.ts +2 -0
- package/createResolverDecorator.js +12 -0
- package/createResolverDecorator.js.map +1 -0
- package/debugPlugins.d.ts +2 -2
- package/debugPlugins.js +3 -1
- package/debugPlugins.js.map +1 -1
- package/errors.js +3 -1
- package/errors.js.map +1 -1
- package/index.d.ts +7 -2
- package/index.js +54 -2
- package/index.js.map +1 -1
- package/interceptConsole.js +8 -6
- package/interceptConsole.js.map +1 -1
- package/package.json +19 -22
- package/plugins/GraphQLSchemaPlugin.d.ts +13 -5
- package/plugins/GraphQLSchemaPlugin.js +16 -6
- package/plugins/GraphQLSchemaPlugin.js.map +1 -1
- package/plugins/index.js +3 -1
- package/plugins/index.js.map +1 -1
- package/processRequestBody.d.ts +4 -5
- package/processRequestBody.js +16 -7
- package/processRequestBody.js.map +1 -1
- package/responses.js +3 -13
- package/responses.js.map +1 -1
- package/types.d.ts +17 -10
- package/types.js +3 -1
- package/types.js.map +1 -1
- package/utils/index.d.ts +1 -0
- package/utils/index.js +18 -0
- package/utils/index.js.map +1 -0
- package/utils/resolve.d.ts +21 -0
- package/utils/resolve.js +28 -0
- package/utils/resolve.js.map +1 -0
package/responses.js
CHANGED
|
@@ -1,11 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
3
|
Object.defineProperty(exports, "__esModule", {
|
|
5
4
|
value: true
|
|
6
5
|
});
|
|
7
6
|
exports.Response = exports.NotFoundResponse = exports.ListResponse = exports.ListErrorResponse = exports.ErrorResponse = void 0;
|
|
8
|
-
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
9
7
|
const defaultParams = {
|
|
10
8
|
code: "",
|
|
11
9
|
message: "",
|
|
@@ -14,8 +12,6 @@ const defaultParams = {
|
|
|
14
12
|
};
|
|
15
13
|
class ErrorResponse {
|
|
16
14
|
constructor(params) {
|
|
17
|
-
(0, _defineProperty2.default)(this, "data", void 0);
|
|
18
|
-
(0, _defineProperty2.default)(this, "error", void 0);
|
|
19
15
|
this.data = null;
|
|
20
16
|
const debug = process.env.DEBUG === "true";
|
|
21
17
|
|
|
@@ -44,9 +40,6 @@ class NotFoundResponse extends ErrorResponse {
|
|
|
44
40
|
exports.NotFoundResponse = NotFoundResponse;
|
|
45
41
|
class ListErrorResponse {
|
|
46
42
|
constructor(params) {
|
|
47
|
-
(0, _defineProperty2.default)(this, "data", void 0);
|
|
48
|
-
(0, _defineProperty2.default)(this, "meta", void 0);
|
|
49
|
-
(0, _defineProperty2.default)(this, "error", void 0);
|
|
50
43
|
this.meta = null;
|
|
51
44
|
this.data = null;
|
|
52
45
|
const debug = process.env.DEBUG === "true";
|
|
@@ -67,8 +60,6 @@ class ListErrorResponse {
|
|
|
67
60
|
exports.ListErrorResponse = ListErrorResponse;
|
|
68
61
|
class Response {
|
|
69
62
|
constructor(data) {
|
|
70
|
-
(0, _defineProperty2.default)(this, "data", void 0);
|
|
71
|
-
(0, _defineProperty2.default)(this, "error", void 0);
|
|
72
63
|
this.data = data;
|
|
73
64
|
this.error = null;
|
|
74
65
|
}
|
|
@@ -76,12 +67,11 @@ class Response {
|
|
|
76
67
|
exports.Response = Response;
|
|
77
68
|
class ListResponse {
|
|
78
69
|
constructor(data, meta) {
|
|
79
|
-
(0, _defineProperty2.default)(this, "data", void 0);
|
|
80
|
-
(0, _defineProperty2.default)(this, "meta", void 0);
|
|
81
|
-
(0, _defineProperty2.default)(this, "error", void 0);
|
|
82
70
|
this.data = Array.isArray(data) ? data : [];
|
|
83
71
|
this.meta = meta || {};
|
|
84
72
|
this.error = null;
|
|
85
73
|
}
|
|
86
74
|
}
|
|
87
|
-
exports.ListResponse = ListResponse;
|
|
75
|
+
exports.ListResponse = ListResponse;
|
|
76
|
+
|
|
77
|
+
//# sourceMappingURL=responses.js.map
|
package/responses.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["defaultParams","code","message","data","stack","ErrorResponse","constructor","params","debug","process","env","DEBUG","error","NotFoundResponse","ListErrorResponse","meta","Response","ListResponse","Array","isArray"],"sources":["responses.ts"],"sourcesContent":["export interface ErrorResponseParams {\n message: string;\n code?: string;\n data?: any;\n stack?: string | null;\n}\n\nconst defaultParams: Required<ErrorResponseParams> = {\n code: \"\",\n message: \"\",\n data: null,\n stack: null\n};\n\nexport class ErrorResponse {\n public readonly data: null;\n public readonly error: {\n code: string;\n message: string;\n data: any;\n stack: string | null;\n };\n\n constructor(params: ErrorResponseParams) {\n this.data = null;\n\n const debug = process.env.DEBUG === \"true\";\n\n // Ensure `stack` is either `string` or `null`.\n let stack = defaultParams.stack;\n if (debug && params.stack) {\n stack = params.stack;\n }\n\n this.error = {\n code: params.code || defaultParams.code,\n message: params.message || defaultParams.message,\n data: params.data || defaultParams.data,\n stack: stack\n };\n }\n}\n\nexport class NotFoundResponse extends ErrorResponse {\n constructor(message: string) {\n super({\n code: \"NOT_FOUND\",\n message\n });\n }\n}\n\nexport class ListErrorResponse {\n public readonly data: null;\n public readonly meta: null;\n public readonly error: {\n code: string;\n message: string;\n data: any;\n stack: string | null;\n };\n\n constructor(params: ErrorResponseParams) {\n this.meta = null;\n this.data = null;\n\n const debug = process.env.DEBUG === \"true\";\n\n // Ensure `stack` is either `string` or `null`.\n let stack = defaultParams.stack;\n if (debug && params.stack) {\n stack = params.stack;\n }\n\n this.error = {\n code: params.code || defaultParams.code,\n message: params.message || defaultParams.message,\n data: params.data || defaultParams.data,\n stack: stack\n };\n }\n}\n\nexport class Response<T = any> {\n public readonly data: T;\n public readonly error: null;\n\n constructor(data: T) {\n this.data = data;\n this.error = null;\n }\n}\n\nexport class ListResponse<T, M> {\n public readonly data: Array<T>;\n public readonly meta: M;\n public readonly error: null;\n\n constructor(data: Array<T>, meta?: M) {\n this.data = Array.isArray(data) ? data : [];\n this.meta = meta || ({} as M);\n this.error = null;\n }\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"names":["defaultParams","code","message","data","stack","ErrorResponse","constructor","params","debug","process","env","DEBUG","error","exports","NotFoundResponse","ListErrorResponse","meta","Response","ListResponse","Array","isArray"],"sources":["responses.ts"],"sourcesContent":["export interface ErrorResponseParams {\n message: string;\n code?: string;\n data?: any;\n stack?: string | null;\n}\n\nconst defaultParams: Required<ErrorResponseParams> = {\n code: \"\",\n message: \"\",\n data: null,\n stack: null\n};\n\nexport class ErrorResponse {\n public readonly data: null;\n public readonly error: {\n code: string;\n message: string;\n data: any;\n stack: string | null;\n };\n\n constructor(params: ErrorResponseParams) {\n this.data = null;\n\n const debug = process.env.DEBUG === \"true\";\n\n // Ensure `stack` is either `string` or `null`.\n let stack = defaultParams.stack;\n if (debug && params.stack) {\n stack = params.stack;\n }\n\n this.error = {\n code: params.code || defaultParams.code,\n message: params.message || defaultParams.message,\n data: params.data || defaultParams.data,\n stack: stack\n };\n }\n}\n\nexport class NotFoundResponse extends ErrorResponse {\n constructor(message: string) {\n super({\n code: \"NOT_FOUND\",\n message\n });\n }\n}\n\nexport class ListErrorResponse {\n public readonly data: null;\n public readonly meta: null;\n public readonly error: {\n code: string;\n message: string;\n data: any;\n stack: string | null;\n };\n\n constructor(params: ErrorResponseParams) {\n this.meta = null;\n this.data = null;\n\n const debug = process.env.DEBUG === \"true\";\n\n // Ensure `stack` is either `string` or `null`.\n let stack = defaultParams.stack;\n if (debug && params.stack) {\n stack = params.stack;\n }\n\n this.error = {\n code: params.code || defaultParams.code,\n message: params.message || defaultParams.message,\n data: params.data || defaultParams.data,\n stack: stack\n };\n }\n}\n\nexport class Response<T = any> {\n public readonly data: T;\n public readonly error: null;\n\n constructor(data: T) {\n this.data = data;\n this.error = null;\n }\n}\n\nexport class ListResponse<T, M> {\n public readonly data: Array<T>;\n public readonly meta: M;\n public readonly error: null;\n\n constructor(data: Array<T>, meta?: M) {\n this.data = Array.isArray(data) ? data : [];\n this.meta = meta || ({} as M);\n this.error = null;\n }\n}\n"],"mappings":";;;;;;AAOA,MAAMA,aAA4C,GAAG;EACjDC,IAAI,EAAE,EAAE;EACRC,OAAO,EAAE,EAAE;EACXC,IAAI,EAAE,IAAI;EACVC,KAAK,EAAE;AACX,CAAC;AAEM,MAAMC,aAAa,CAAC;EASvBC,WAAWA,CAACC,MAA2B,EAAE;IACrC,IAAI,CAACJ,IAAI,GAAG,IAAI;IAEhB,MAAMK,KAAK,GAAGC,OAAO,CAACC,GAAG,CAACC,KAAK,KAAK,MAAM;;IAE1C;IACA,IAAIP,KAAK,GAAGJ,aAAa,CAACI,KAAK;IAC/B,IAAII,KAAK,IAAID,MAAM,CAACH,KAAK,EAAE;MACvBA,KAAK,GAAGG,MAAM,CAACH,KAAK;IACxB;IAEA,IAAI,CAACQ,KAAK,GAAG;MACTX,IAAI,EAAEM,MAAM,CAACN,IAAI,IAAID,aAAa,CAACC,IAAI;MACvCC,OAAO,EAAEK,MAAM,CAACL,OAAO,IAAIF,aAAa,CAACE,OAAO;MAChDC,IAAI,EAAEI,MAAM,CAACJ,IAAI,IAAIH,aAAa,CAACG,IAAI;MACvCC,KAAK,EAAEA;IACX,CAAC;EACL;AACJ;AAACS,OAAA,CAAAR,aAAA,GAAAA,aAAA;AAEM,MAAMS,gBAAgB,SAAST,aAAa,CAAC;EAChDC,WAAWA,CAACJ,OAAe,EAAE;IACzB,KAAK,CAAC;MACFD,IAAI,EAAE,WAAW;MACjBC;IACJ,CAAC,CAAC;EACN;AACJ;AAACW,OAAA,CAAAC,gBAAA,GAAAA,gBAAA;AAEM,MAAMC,iBAAiB,CAAC;EAU3BT,WAAWA,CAACC,MAA2B,EAAE;IACrC,IAAI,CAACS,IAAI,GAAG,IAAI;IAChB,IAAI,CAACb,IAAI,GAAG,IAAI;IAEhB,MAAMK,KAAK,GAAGC,OAAO,CAACC,GAAG,CAACC,KAAK,KAAK,MAAM;;IAE1C;IACA,IAAIP,KAAK,GAAGJ,aAAa,CAACI,KAAK;IAC/B,IAAII,KAAK,IAAID,MAAM,CAACH,KAAK,EAAE;MACvBA,KAAK,GAAGG,MAAM,CAACH,KAAK;IACxB;IAEA,IAAI,CAACQ,KAAK,GAAG;MACTX,IAAI,EAAEM,MAAM,CAACN,IAAI,IAAID,aAAa,CAACC,IAAI;MACvCC,OAAO,EAAEK,MAAM,CAACL,OAAO,IAAIF,aAAa,CAACE,OAAO;MAChDC,IAAI,EAAEI,MAAM,CAACJ,IAAI,IAAIH,aAAa,CAACG,IAAI;MACvCC,KAAK,EAAEA;IACX,CAAC;EACL;AACJ;AAACS,OAAA,CAAAE,iBAAA,GAAAA,iBAAA;AAEM,MAAME,QAAQ,CAAU;EAI3BX,WAAWA,CAACH,IAAO,EAAE;IACjB,IAAI,CAACA,IAAI,GAAGA,IAAI;IAChB,IAAI,CAACS,KAAK,GAAG,IAAI;EACrB;AACJ;AAACC,OAAA,CAAAI,QAAA,GAAAA,QAAA;AAEM,MAAMC,YAAY,CAAO;EAK5BZ,WAAWA,CAACH,IAAc,EAAEa,IAAQ,EAAE;IAClC,IAAI,CAACb,IAAI,GAAGgB,KAAK,CAACC,OAAO,CAACjB,IAAI,CAAC,GAAGA,IAAI,GAAG,EAAE;IAC3C,IAAI,CAACa,IAAI,GAAGA,IAAI,IAAK,CAAC,CAAO;IAC7B,IAAI,CAACJ,KAAK,GAAG,IAAI;EACrB;AACJ;AAACC,OAAA,CAAAK,YAAA,GAAAA,YAAA","ignoreList":[]}
|
package/types.d.ts
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
|
-
import { GraphQLScalarType, GraphQLFieldResolver as BaseGraphQLFieldResolver, GraphQLSchema } from "graphql";
|
|
2
|
-
import { Plugin } from "@webiny/plugins/types";
|
|
3
|
-
import { Context } from "@webiny/api/types";
|
|
4
|
-
import { RouteMethodPath } from "@webiny/handler/types";
|
|
1
|
+
import type { GraphQLScalarType, GraphQLFieldResolver as BaseGraphQLFieldResolver, GraphQLSchema } from "graphql";
|
|
2
|
+
import type { Plugin } from "@webiny/plugins/types";
|
|
3
|
+
import type { Context, GenericRecord } from "@webiny/api/types";
|
|
4
|
+
import type { RouteMethodPath } from "@webiny/handler/types";
|
|
5
|
+
import type { ResolversComposition } from "@graphql-tools/resolvers-composition";
|
|
6
|
+
import type { IResolvers, TypeSource } from "@graphql-tools/utils";
|
|
5
7
|
export interface GraphQLScalarPlugin extends Plugin {
|
|
6
8
|
type: "graphql-scalar";
|
|
7
9
|
scalar: GraphQLScalarType;
|
|
@@ -10,19 +12,24 @@ export interface HandlerGraphQLOptions {
|
|
|
10
12
|
path?: RouteMethodPath;
|
|
11
13
|
debug?: boolean | string;
|
|
12
14
|
}
|
|
13
|
-
export
|
|
14
|
-
|
|
15
|
+
export type GraphQLFieldResolver<TSource = any, TArgs = any, TContext = Context> = BaseGraphQLFieldResolver<TSource, TContext, TArgs>;
|
|
16
|
+
/**
|
|
17
|
+
* @deprecated Use `TypeDefs` instead.
|
|
18
|
+
*/
|
|
19
|
+
export type Types = TypeDefs;
|
|
20
|
+
export type TypeDefs = TypeSource;
|
|
15
21
|
export interface GraphQLSchemaPluginTypeArgs {
|
|
16
22
|
context?: any;
|
|
17
23
|
args?: any;
|
|
18
24
|
source?: any;
|
|
19
25
|
}
|
|
20
|
-
export
|
|
21
|
-
|
|
22
|
-
|
|
26
|
+
export type Resolvers<TContext> = IResolvers<any, TContext>;
|
|
27
|
+
export type ResolverDecorator<TSource = any, TContext = any, TArgs = any> = ResolversComposition<GraphQLFieldResolver<TSource, TContext, TArgs>>;
|
|
28
|
+
export type ResolverDecorators = GenericRecord<string, ResolverDecorator[]>;
|
|
23
29
|
export interface GraphQLSchemaDefinition<TContext> {
|
|
24
|
-
typeDefs:
|
|
30
|
+
typeDefs: TypeDefs;
|
|
25
31
|
resolvers?: Resolvers<TContext>;
|
|
32
|
+
resolverDecorators?: ResolverDecorators;
|
|
26
33
|
}
|
|
27
34
|
export interface GraphQLSchemaPlugin<TContext extends Context = Context> extends Plugin {
|
|
28
35
|
type: "graphql-schema";
|
package/types.js
CHANGED
package/types.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":[],"sources":["types.ts"],"sourcesContent":["import {\n GraphQLScalarType,\n GraphQLFieldResolver as BaseGraphQLFieldResolver,\n GraphQLSchema\n} from \"graphql\";\nimport { Plugin } from \"@webiny/plugins/types\";\nimport { Context } from \"@webiny/api/types\";\nimport { RouteMethodPath } from \"@webiny/handler/types\";\n\nexport interface GraphQLScalarPlugin extends Plugin {\n type: \"graphql-scalar\";\n scalar: GraphQLScalarType;\n}\n\nexport interface HandlerGraphQLOptions {\n path?: RouteMethodPath;\n debug?: boolean | string;\n}\n\nexport type GraphQLFieldResolver<\n TSource = any,\n TArgs = any,\n TContext = Context\n> = BaseGraphQLFieldResolver<TSource, TContext, TArgs>;\n\n
|
|
1
|
+
{"version":3,"names":[],"sources":["types.ts"],"sourcesContent":["import type {\n GraphQLScalarType,\n GraphQLFieldResolver as BaseGraphQLFieldResolver,\n GraphQLSchema\n} from \"graphql\";\nimport type { Plugin } from \"@webiny/plugins/types\";\nimport type { Context, GenericRecord } from \"@webiny/api/types\";\nimport type { RouteMethodPath } from \"@webiny/handler/types\";\nimport type { ResolversComposition } from \"@graphql-tools/resolvers-composition\";\nimport type { IResolvers, TypeSource } from \"@graphql-tools/utils\";\n\nexport interface GraphQLScalarPlugin extends Plugin {\n type: \"graphql-scalar\";\n scalar: GraphQLScalarType;\n}\n\nexport interface HandlerGraphQLOptions {\n path?: RouteMethodPath;\n debug?: boolean | string;\n}\n\nexport type GraphQLFieldResolver<\n TSource = any,\n TArgs = any,\n TContext = Context\n> = BaseGraphQLFieldResolver<TSource, TContext, TArgs>;\n\n/**\n * @deprecated Use `TypeDefs` instead.\n */\nexport type Types = TypeDefs;\nexport type TypeDefs = TypeSource;\n\nexport interface GraphQLSchemaPluginTypeArgs {\n context?: any;\n args?: any;\n source?: any;\n}\n\nexport type Resolvers<TContext> = IResolvers<any, TContext>;\n\nexport type ResolverDecorator<TSource = any, TContext = any, TArgs = any> = ResolversComposition<\n GraphQLFieldResolver<TSource, TContext, TArgs>\n>;\n\nexport type ResolverDecorators = GenericRecord<string, ResolverDecorator[]>;\n\nexport interface GraphQLSchemaDefinition<TContext> {\n typeDefs: TypeDefs;\n resolvers?: Resolvers<TContext>;\n resolverDecorators?: ResolverDecorators;\n}\n\nexport interface GraphQLSchemaPlugin<TContext extends Context = Context> extends Plugin {\n type: \"graphql-schema\";\n schema: GraphQLSchemaDefinition<TContext>;\n}\n\nexport interface GraphQLRequestBody {\n query: string;\n variables: Record<string, any>;\n operationName: string;\n}\n\nexport interface GraphQLBeforeQueryPlugin<TContext extends Context = Context> extends Plugin {\n type: \"graphql-before-query\";\n apply(params: { body: GraphQLRequestBody; schema: GraphQLSchema; context: TContext }): void;\n}\n\nexport interface GraphQLAfterQueryPlugin<TContext extends Context = Context> extends Plugin {\n type: \"graphql-after-query\";\n apply(params: {\n result: any;\n body: GraphQLRequestBody;\n schema: GraphQLSchema;\n context: TContext;\n }): void;\n}\n"],"mappings":"","ignoreList":[]}
|
package/utils/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./resolve";
|
package/utils/index.js
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
var _resolve = require("./resolve");
|
|
7
|
+
Object.keys(_resolve).forEach(function (key) {
|
|
8
|
+
if (key === "default" || key === "__esModule") return;
|
|
9
|
+
if (key in exports && exports[key] === _resolve[key]) return;
|
|
10
|
+
Object.defineProperty(exports, key, {
|
|
11
|
+
enumerable: true,
|
|
12
|
+
get: function () {
|
|
13
|
+
return _resolve[key];
|
|
14
|
+
}
|
|
15
|
+
});
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["_resolve","require","Object","keys","forEach","key","exports","defineProperty","enumerable","get"],"sources":["index.ts"],"sourcesContent":["export * from \"./resolve\";\n"],"mappings":";;;;;AAAA,IAAAA,QAAA,GAAAC,OAAA;AAAAC,MAAA,CAAAC,IAAA,CAAAH,QAAA,EAAAI,OAAA,WAAAC,GAAA;EAAA,IAAAA,GAAA,kBAAAA,GAAA;EAAA,IAAAA,GAAA,IAAAC,OAAA,IAAAA,OAAA,CAAAD,GAAA,MAAAL,QAAA,CAAAK,GAAA;EAAAH,MAAA,CAAAK,cAAA,CAAAD,OAAA,EAAAD,GAAA;IAAAG,UAAA;IAAAC,GAAA,WAAAA,CAAA;MAAA,OAAAT,QAAA,CAAAK,GAAA;IAAA;EAAA;AAAA","ignoreList":[]}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { ErrorResponse, ListErrorResponse, ListResponse, Response } from "../responses";
|
|
2
|
+
import type { GenericRecord } from "@webiny/api/types";
|
|
3
|
+
export interface Meta {
|
|
4
|
+
totalCount: number;
|
|
5
|
+
hasMoreItems: boolean;
|
|
6
|
+
cursor: string | null;
|
|
7
|
+
}
|
|
8
|
+
export declare const emptyResolver: () => {};
|
|
9
|
+
interface ResolveCallable<T = GenericRecord> {
|
|
10
|
+
(): Promise<T>;
|
|
11
|
+
}
|
|
12
|
+
export declare const resolve: <T = GenericRecord>(fn: ResolveCallable<T>) => Promise<ErrorResponse | Response<Awaited<T>>>;
|
|
13
|
+
interface ResolveListCallable<T> {
|
|
14
|
+
(): Promise<IListResult<T>>;
|
|
15
|
+
}
|
|
16
|
+
interface IListResult<T = GenericRecord> {
|
|
17
|
+
items: T[];
|
|
18
|
+
meta: Meta;
|
|
19
|
+
}
|
|
20
|
+
export declare const resolveList: <T = GenericRecord>(fn: ResolveListCallable<T>) => Promise<ListErrorResponse | ListResponse<T, Meta>>;
|
|
21
|
+
export {};
|
package/utils/resolve.js
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.resolveList = exports.resolve = exports.emptyResolver = void 0;
|
|
7
|
+
var _responses = require("../responses");
|
|
8
|
+
const emptyResolver = () => ({});
|
|
9
|
+
exports.emptyResolver = emptyResolver;
|
|
10
|
+
const resolve = async fn => {
|
|
11
|
+
try {
|
|
12
|
+
return new _responses.Response(await fn());
|
|
13
|
+
} catch (ex) {
|
|
14
|
+
return new _responses.ErrorResponse(ex);
|
|
15
|
+
}
|
|
16
|
+
};
|
|
17
|
+
exports.resolve = resolve;
|
|
18
|
+
const resolveList = async fn => {
|
|
19
|
+
try {
|
|
20
|
+
const result = await fn();
|
|
21
|
+
return new _responses.ListResponse(result.items, result.meta);
|
|
22
|
+
} catch (ex) {
|
|
23
|
+
return new _responses.ListErrorResponse(ex);
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
exports.resolveList = resolveList;
|
|
27
|
+
|
|
28
|
+
//# sourceMappingURL=resolve.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["_responses","require","emptyResolver","exports","resolve","fn","Response","ex","ErrorResponse","resolveList","result","ListResponse","items","meta","ListErrorResponse"],"sources":["resolve.ts"],"sourcesContent":["import { ErrorResponse, ListErrorResponse, ListResponse, Response } from \"~/responses\";\nimport type { GenericRecord } from \"@webiny/api/types\";\n\nexport interface Meta {\n totalCount: number;\n hasMoreItems: boolean;\n cursor: string | null;\n}\n\nexport const emptyResolver = () => ({});\n\ninterface ResolveCallable<T = GenericRecord> {\n (): Promise<T>;\n}\n\nexport const resolve = async <T = GenericRecord>(fn: ResolveCallable<T>) => {\n try {\n return new Response(await fn());\n } catch (ex) {\n return new ErrorResponse(ex);\n }\n};\n\ninterface ResolveListCallable<T> {\n (): Promise<IListResult<T>>;\n}\n\ninterface IListResult<T = GenericRecord> {\n items: T[];\n meta: Meta;\n}\n\nexport const resolveList = async <T = GenericRecord>(fn: ResolveListCallable<T>) => {\n try {\n const result = (await fn()) as IListResult<T>;\n return new ListResponse(result.items, result.meta);\n } catch (ex) {\n return new ListErrorResponse(ex);\n }\n};\n"],"mappings":";;;;;;AAAA,IAAAA,UAAA,GAAAC,OAAA;AASO,MAAMC,aAAa,GAAGA,CAAA,MAAO,CAAC,CAAC,CAAC;AAACC,OAAA,CAAAD,aAAA,GAAAA,aAAA;AAMjC,MAAME,OAAO,GAAG,MAA0BC,EAAsB,IAAK;EACxE,IAAI;IACA,OAAO,IAAIC,mBAAQ,CAAC,MAAMD,EAAE,CAAC,CAAC,CAAC;EACnC,CAAC,CAAC,OAAOE,EAAE,EAAE;IACT,OAAO,IAAIC,wBAAa,CAACD,EAAE,CAAC;EAChC;AACJ,CAAC;AAACJ,OAAA,CAAAC,OAAA,GAAAA,OAAA;AAWK,MAAMK,WAAW,GAAG,MAA0BJ,EAA0B,IAAK;EAChF,IAAI;IACA,MAAMK,MAAM,GAAI,MAAML,EAAE,CAAC,CAAoB;IAC7C,OAAO,IAAIM,uBAAY,CAACD,MAAM,CAACE,KAAK,EAAEF,MAAM,CAACG,IAAI,CAAC;EACtD,CAAC,CAAC,OAAON,EAAE,EAAE;IACT,OAAO,IAAIO,4BAAiB,CAACP,EAAE,CAAC;EACpC;AACJ,CAAC;AAACJ,OAAA,CAAAM,WAAA,GAAAA,WAAA","ignoreList":[]}
|