@webiny/handler-graphql 0.0.0-mt-2 → 0.0.0-unstable.06b2ede40f
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.d.ts +1 -1
- package/builtInTypes/AnyScalar.js +4 -6
- package/builtInTypes/AnyScalar.js.map +1 -0
- package/builtInTypes/DateScalar.js +7 -18
- package/builtInTypes/DateScalar.js.map +1 -0
- package/builtInTypes/DateTimeScalar.js +5 -16
- package/builtInTypes/DateTimeScalar.js.map +1 -0
- package/builtInTypes/DateTimeZScalar.js +4 -16
- package/builtInTypes/DateTimeZScalar.js.map +1 -0
- package/builtInTypes/JsonScalar.js +2 -3
- package/builtInTypes/JsonScalar.js.map +1 -0
- package/builtInTypes/LongScalar.d.ts +2 -1
- package/builtInTypes/LongScalar.js +49 -4
- package/builtInTypes/LongScalar.js.map +1 -0
- package/builtInTypes/NumberScalar.d.ts +1 -1
- package/builtInTypes/NumberScalar.js +10 -15
- package/builtInTypes/NumberScalar.js.map +1 -0
- package/builtInTypes/RefInputScalar.d.ts +1 -1
- package/builtInTypes/RefInputScalar.js +34 -23
- package/builtInTypes/RefInputScalar.js.map +1 -0
- package/builtInTypes/TimeScalar.js +4 -15
- package/builtInTypes/TimeScalar.js.map +1 -0
- package/builtInTypes/index.js +3 -19
- package/builtInTypes/index.js.map +1 -0
- package/createGraphQLHandler.d.ts +3 -3
- package/createGraphQLHandler.js +90 -57
- package/createGraphQLHandler.js.map +1 -0
- package/createGraphQLSchema.d.ts +4 -3
- package/createGraphQLSchema.js +58 -30
- package/createGraphQLSchema.js.map +1 -0
- package/createResolverDecorator.d.ts +2 -0
- package/createResolverDecorator.js +12 -0
- package/createResolverDecorator.js.map +1 -0
- package/debugPlugins.d.ts +10 -8
- package/debugPlugins.js +18 -28
- package/debugPlugins.js.map +1 -0
- package/errors.d.ts +2 -2
- package/errors.js +3 -6
- package/errors.js.map +1 -0
- package/index.d.ts +8 -6
- package/index.js +67 -22
- package/index.js.map +1 -0
- package/interceptConsole.d.ts +5 -1
- package/interceptConsole.js +7 -7
- package/interceptConsole.js.map +1 -0
- package/package.json +21 -23
- package/plugins/GraphQLSchemaPlugin.d.ts +14 -6
- package/plugins/GraphQLSchemaPlugin.js +16 -13
- package/plugins/GraphQLSchemaPlugin.js.map +1 -0
- package/plugins/index.js +3 -3
- package/plugins/index.js.map +1 -0
- package/processRequestBody.d.ts +4 -2
- package/processRequestBody.js +19 -18
- package/processRequestBody.js.map +1 -0
- package/responses.d.ts +20 -18
- package/responses.js +23 -34
- package/responses.js.map +1 -0
- package/types.d.ts +21 -12
- package/types.js +3 -1
- package/types.js.map +1 -0
- 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
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.ResolverDecoration = void 0;
|
|
7
|
+
var _resolversComposition = require("@graphql-tools/resolvers-composition");
|
|
8
|
+
class ResolverDecoration {
|
|
9
|
+
decorators = {};
|
|
10
|
+
addDecorators(resolverDecorators) {
|
|
11
|
+
for (const key in resolverDecorators) {
|
|
12
|
+
const decorators = resolverDecorators[key];
|
|
13
|
+
if (!decorators) {
|
|
14
|
+
continue;
|
|
15
|
+
}
|
|
16
|
+
const existingDecorators = this.decorators[key] ?? [];
|
|
17
|
+
this.decorators[key] = [...existingDecorators, ...decorators];
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
decorateResolvers(resolvers) {
|
|
21
|
+
return (0, _resolversComposition.composeResolvers)(resolvers, this.decorators);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
exports.ResolverDecoration = ResolverDecoration;
|
|
25
|
+
|
|
26
|
+
//# sourceMappingURL=ResolverDecoration.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["_resolversComposition","require","ResolverDecoration","decorators","addDecorators","resolverDecorators","key","existingDecorators","decorateResolvers","resolvers","composeResolvers","exports"],"sources":["ResolverDecoration.ts"],"sourcesContent":["import { composeResolvers } from \"@graphql-tools/resolvers-composition\";\nimport type { ResolverDecorators, Resolvers } from \"./types\";\n\nexport class ResolverDecoration {\n private decorators: ResolverDecorators = {};\n\n addDecorators(resolverDecorators: ResolverDecorators) {\n for (const key in resolverDecorators) {\n const decorators = resolverDecorators[key];\n if (!decorators) {\n continue;\n }\n\n const existingDecorators = this.decorators[key] ?? [];\n this.decorators[key] = [...existingDecorators, ...decorators];\n }\n }\n\n decorateResolvers(resolvers: Resolvers<unknown>) {\n return composeResolvers(resolvers, this.decorators);\n }\n}\n"],"mappings":";;;;;;AAAA,IAAAA,qBAAA,GAAAC,OAAA;AAGO,MAAMC,kBAAkB,CAAC;EACpBC,UAAU,GAAuB,CAAC,CAAC;EAE3CC,aAAaA,CAACC,kBAAsC,EAAE;IAClD,KAAK,MAAMC,GAAG,IAAID,kBAAkB,EAAE;MAClC,MAAMF,UAAU,GAAGE,kBAAkB,CAACC,GAAG,CAAC;MAC1C,IAAI,CAACH,UAAU,EAAE;QACb;MACJ;MAEA,MAAMI,kBAAkB,GAAG,IAAI,CAACJ,UAAU,CAACG,GAAG,CAAC,IAAI,EAAE;MACrD,IAAI,CAACH,UAAU,CAACG,GAAG,CAAC,GAAG,CAAC,GAAGC,kBAAkB,EAAE,GAAGJ,UAAU,CAAC;IACjE;EACJ;EAEAK,iBAAiBA,CAACC,SAA6B,EAAE;IAC7C,OAAO,IAAAC,sCAAgB,EAACD,SAAS,EAAE,IAAI,CAACN,UAAU,CAAC;EACvD;AACJ;AAACQ,OAAA,CAAAT,kBAAA,GAAAA,kBAAA","ignoreList":[]}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import { GraphQLScalarType } from "graphql";
|
|
2
|
-
export declare const
|
|
2
|
+
export declare const AnyScalar: GraphQLScalarType;
|
|
@@ -3,18 +3,16 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.
|
|
7
|
-
|
|
6
|
+
exports.AnyScalar = void 0;
|
|
8
7
|
var _graphql = require("graphql");
|
|
9
|
-
|
|
10
8
|
const returnValue = value => {
|
|
11
9
|
return value;
|
|
12
10
|
};
|
|
13
|
-
|
|
14
|
-
const Any = new _graphql.GraphQLScalarType({
|
|
11
|
+
const AnyScalar = exports.AnyScalar = new _graphql.GraphQLScalarType({
|
|
15
12
|
name: "Any",
|
|
16
13
|
description: `A scalar type that represents an ambiguous value.`,
|
|
17
14
|
serialize: returnValue,
|
|
18
15
|
parseValue: returnValue
|
|
19
16
|
});
|
|
20
|
-
|
|
17
|
+
|
|
18
|
+
//# sourceMappingURL=AnyScalar.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["_graphql","require","returnValue","value","AnyScalar","exports","GraphQLScalarType","name","description","serialize","parseValue"],"sources":["AnyScalar.ts"],"sourcesContent":["import { GraphQLScalarType } from \"graphql\";\n\nconst returnValue = (value: any): any => {\n return value;\n};\n\nexport const AnyScalar = new GraphQLScalarType({\n name: \"Any\",\n description: `A scalar type that represents an ambiguous value.`,\n serialize: returnValue,\n parseValue: returnValue\n});\n"],"mappings":";;;;;;AAAA,IAAAA,QAAA,GAAAC,OAAA;AAEA,MAAMC,WAAW,GAAIC,KAAU,IAAU;EACrC,OAAOA,KAAK;AAChB,CAAC;AAEM,MAAMC,SAAS,GAAAC,OAAA,CAAAD,SAAA,GAAG,IAAIE,0BAAiB,CAAC;EAC3CC,IAAI,EAAE,KAAK;EACXC,WAAW,EAAE,mDAAmD;EAChEC,SAAS,EAAEP,WAAW;EACtBQ,UAAU,EAAER;AAChB,CAAC,CAAC","ignoreList":[]}
|
|
@@ -1,38 +1,27 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
|
|
5
3
|
Object.defineProperty(exports, "__esModule", {
|
|
6
4
|
value: true
|
|
7
5
|
});
|
|
8
6
|
exports.DateScalar = void 0;
|
|
9
|
-
|
|
10
|
-
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
11
|
-
|
|
12
7
|
var _graphqlScalars = require("graphql-scalars");
|
|
13
|
-
|
|
14
8
|
var _graphql = require("graphql");
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { (0, _defineProperty2.default)(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
|
|
19
|
-
|
|
20
|
-
const DateScalar = new _graphql.GraphQLScalarType(_objectSpread(_objectSpread({}, _graphqlScalars.DateResolver), {}, {
|
|
9
|
+
const DateScalar = exports.DateScalar = new _graphql.GraphQLScalarType({
|
|
10
|
+
..._graphqlScalars.DateResolver,
|
|
21
11
|
serialize: value => {
|
|
22
12
|
if (!value) {
|
|
23
13
|
return null;
|
|
24
14
|
}
|
|
25
|
-
|
|
26
15
|
try {
|
|
27
16
|
const date = new Date(value);
|
|
28
|
-
return date.toISOString().
|
|
17
|
+
return date.toISOString().slice(0, 10);
|
|
29
18
|
} catch (ex) {
|
|
30
19
|
if (value.toISOString) {
|
|
31
|
-
return value.toISOString().
|
|
20
|
+
return value.toISOString().slice(0, 10);
|
|
32
21
|
}
|
|
33
|
-
|
|
34
22
|
throw ex;
|
|
35
23
|
}
|
|
36
24
|
}
|
|
37
|
-
})
|
|
38
|
-
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
//# sourceMappingURL=DateScalar.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["_graphqlScalars","require","_graphql","DateScalar","exports","GraphQLScalarType","DateResolver","serialize","value","date","Date","toISOString","slice","ex"],"sources":["DateScalar.ts"],"sourcesContent":["import { DateResolver } from \"graphql-scalars\";\nimport { GraphQLScalarType } from \"graphql\";\nexport const DateScalar = new GraphQLScalarType({\n ...DateResolver,\n serialize: value => {\n if (!value) {\n return null;\n }\n try {\n const date = new Date(value);\n return date.toISOString().slice(0, 10);\n } catch (ex) {\n if (value.toISOString) {\n return value.toISOString().slice(0, 10);\n }\n throw ex;\n }\n }\n});\n"],"mappings":";;;;;;AAAA,IAAAA,eAAA,GAAAC,OAAA;AACA,IAAAC,QAAA,GAAAD,OAAA;AACO,MAAME,UAAU,GAAAC,OAAA,CAAAD,UAAA,GAAG,IAAIE,0BAAiB,CAAC;EAC5C,GAAGC,4BAAY;EACfC,SAAS,EAAEC,KAAK,IAAI;IAChB,IAAI,CAACA,KAAK,EAAE;MACR,OAAO,IAAI;IACf;IACA,IAAI;MACA,MAAMC,IAAI,GAAG,IAAIC,IAAI,CAACF,KAAK,CAAC;MAC5B,OAAOC,IAAI,CAACE,WAAW,CAAC,CAAC,CAACC,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC;IAC1C,CAAC,CAAC,OAAOC,EAAE,EAAE;MACT,IAAIL,KAAK,CAACG,WAAW,EAAE;QACnB,OAAOH,KAAK,CAACG,WAAW,CAAC,CAAC,CAACC,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC;MAC3C;MACA,MAAMC,EAAE;IACZ;EACJ;AACJ,CAAC,CAAC","ignoreList":[]}
|
|
@@ -1,28 +1,17 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
|
|
5
3
|
Object.defineProperty(exports, "__esModule", {
|
|
6
4
|
value: true
|
|
7
5
|
});
|
|
8
6
|
exports.DateTimeScalar = void 0;
|
|
9
|
-
|
|
10
|
-
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
11
|
-
|
|
12
7
|
var _graphqlScalars = require("graphql-scalars");
|
|
13
|
-
|
|
14
8
|
var _graphql = require("graphql");
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { (0, _defineProperty2.default)(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
|
|
19
|
-
|
|
20
|
-
const DateTimeScalar = new _graphql.GraphQLScalarType(_objectSpread(_objectSpread({}, _graphqlScalars.DateTimeResolver), {}, {
|
|
9
|
+
const DateTimeScalar = exports.DateTimeScalar = new _graphql.GraphQLScalarType({
|
|
10
|
+
..._graphqlScalars.DateTimeResolver,
|
|
21
11
|
serialize: value => {
|
|
22
12
|
if (!value) {
|
|
23
13
|
return null;
|
|
24
14
|
}
|
|
25
|
-
|
|
26
15
|
try {
|
|
27
16
|
const date = new Date(value);
|
|
28
17
|
return date.toISOString();
|
|
@@ -30,9 +19,9 @@ const DateTimeScalar = new _graphql.GraphQLScalarType(_objectSpread(_objectSprea
|
|
|
30
19
|
if (value.toISOString) {
|
|
31
20
|
return value.toISOString();
|
|
32
21
|
}
|
|
33
|
-
|
|
34
22
|
throw ex;
|
|
35
23
|
}
|
|
36
24
|
}
|
|
37
|
-
})
|
|
38
|
-
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
//# sourceMappingURL=DateTimeScalar.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["_graphqlScalars","require","_graphql","DateTimeScalar","exports","GraphQLScalarType","DateTimeResolver","serialize","value","date","Date","toISOString","ex"],"sources":["DateTimeScalar.ts"],"sourcesContent":["import { DateTimeResolver } from \"graphql-scalars\";\nimport { GraphQLScalarType } from \"graphql\";\nexport const DateTimeScalar = new GraphQLScalarType({\n ...DateTimeResolver,\n serialize: value => {\n if (!value) {\n return null;\n }\n try {\n const date = new Date(value);\n return date.toISOString();\n } catch (ex) {\n if (value.toISOString) {\n return value.toISOString();\n }\n throw ex;\n }\n }\n});\n"],"mappings":";;;;;;AAAA,IAAAA,eAAA,GAAAC,OAAA;AACA,IAAAC,QAAA,GAAAD,OAAA;AACO,MAAME,cAAc,GAAAC,OAAA,CAAAD,cAAA,GAAG,IAAIE,0BAAiB,CAAC;EAChD,GAAGC,gCAAgB;EACnBC,SAAS,EAAEC,KAAK,IAAI;IAChB,IAAI,CAACA,KAAK,EAAE;MACR,OAAO,IAAI;IACf;IACA,IAAI;MACA,MAAMC,IAAI,GAAG,IAAIC,IAAI,CAACF,KAAK,CAAC;MAC5B,OAAOC,IAAI,CAACE,WAAW,CAAC,CAAC;IAC7B,CAAC,CAAC,OAAOC,EAAE,EAAE;MACT,IAAIJ,KAAK,CAACG,WAAW,EAAE;QACnB,OAAOH,KAAK,CAACG,WAAW,CAAC,CAAC;MAC9B;MACA,MAAMC,EAAE;IACZ;EACJ;AACJ,CAAC,CAAC","ignoreList":[]}
|
|
@@ -1,39 +1,29 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
5
4
|
Object.defineProperty(exports, "__esModule", {
|
|
6
5
|
value: true
|
|
7
6
|
});
|
|
8
7
|
exports.DateTimeZScalar = void 0;
|
|
9
|
-
|
|
10
8
|
var _graphqlScalars = require("graphql-scalars");
|
|
11
|
-
|
|
12
9
|
var _graphql = require("graphql");
|
|
13
|
-
|
|
14
10
|
var _error = _interopRequireDefault(require("@webiny/error"));
|
|
15
|
-
|
|
16
11
|
const validateTimeZone = value => {
|
|
17
12
|
const timeWithTimezone = value.split("T")[1];
|
|
18
|
-
|
|
19
13
|
if (!timeWithTimezone) {
|
|
20
14
|
throw new _error.default("Could not extract time with timezone from value.", "DATE_TIME_TIMEZONE_ERROR", {
|
|
21
15
|
value
|
|
22
16
|
});
|
|
23
17
|
}
|
|
24
|
-
|
|
25
18
|
const separator = timeWithTimezone.includes("-") ? "-" : "+";
|
|
26
19
|
const zone = timeWithTimezone.split(separator)[1];
|
|
27
|
-
|
|
28
20
|
if (!zone) {
|
|
29
21
|
throw new _error.default("Could not extract timezone from value.", "DATE_TIME_TIMEZONE_ERROR", {
|
|
30
22
|
value: timeWithTimezone
|
|
31
23
|
});
|
|
32
24
|
}
|
|
33
|
-
|
|
34
25
|
const hoursMinutes = zone.split(":");
|
|
35
26
|
const [hours, minutes] = hoursMinutes;
|
|
36
|
-
|
|
37
27
|
if (hours === undefined || minutes === undefined || hoursMinutes.length !== 2) {
|
|
38
28
|
throw new _error.default("Could not extract hours or minutes from value.", "DATE_TIME_TIMEZONE_ERROR", {
|
|
39
29
|
value: zone
|
|
@@ -44,15 +34,12 @@ const validateTimeZone = value => {
|
|
|
44
34
|
* A custom type for dateTime with the timezone.
|
|
45
35
|
* Must be in format "YYYY-MM-ddTHH:mm:ss+HH:mm".
|
|
46
36
|
*/
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
const DateTimeZScalar = new _graphql.GraphQLScalarType({
|
|
37
|
+
const DateTimeZScalar = exports.DateTimeZScalar = new _graphql.GraphQLScalarType({
|
|
50
38
|
name: "DateTimeZ",
|
|
51
39
|
description: "A custom type for dateTime with the timezone.",
|
|
52
40
|
parseValue: value => {
|
|
53
41
|
// this serves as validator
|
|
54
42
|
_graphqlScalars.DateTimeResolver.parseValue(value);
|
|
55
|
-
|
|
56
43
|
validateTimeZone(value);
|
|
57
44
|
return value;
|
|
58
45
|
},
|
|
@@ -60,4 +47,5 @@ const DateTimeZScalar = new _graphql.GraphQLScalarType({
|
|
|
60
47
|
return value;
|
|
61
48
|
}
|
|
62
49
|
});
|
|
63
|
-
|
|
50
|
+
|
|
51
|
+
//# sourceMappingURL=DateTimeZScalar.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["_graphqlScalars","require","_graphql","_error","_interopRequireDefault","validateTimeZone","value","timeWithTimezone","split","WebinyError","separator","includes","zone","hoursMinutes","hours","minutes","undefined","length","DateTimeZScalar","exports","GraphQLScalarType","name","description","parseValue","DateTimeResolver","serialize"],"sources":["DateTimeZScalar.ts"],"sourcesContent":["import { DateTimeResolver } from \"graphql-scalars\";\nimport { GraphQLScalarType } from \"graphql\";\nimport WebinyError from \"@webiny/error\";\n\nconst validateTimeZone = (value: string): void => {\n const timeWithTimezone = value.split(\"T\")[1];\n if (!timeWithTimezone) {\n throw new WebinyError(\n \"Could not extract time with timezone from value.\",\n \"DATE_TIME_TIMEZONE_ERROR\",\n {\n value\n }\n );\n }\n const separator = timeWithTimezone.includes(\"-\") ? \"-\" : \"+\";\n const zone = timeWithTimezone.split(separator)[1];\n if (!zone) {\n throw new WebinyError(\n \"Could not extract timezone from value.\",\n \"DATE_TIME_TIMEZONE_ERROR\",\n {\n value: timeWithTimezone\n }\n );\n }\n const hoursMinutes = zone.split(\":\");\n const [hours, minutes] = hoursMinutes;\n if (hours === undefined || minutes === undefined || hoursMinutes.length !== 2) {\n throw new WebinyError(\n \"Could not extract hours or minutes from value.\",\n \"DATE_TIME_TIMEZONE_ERROR\",\n {\n value: zone\n }\n );\n }\n};\n/**\n * A custom type for dateTime with the timezone.\n * Must be in format \"YYYY-MM-ddTHH:mm:ss+HH:mm\".\n */\nexport const DateTimeZScalar = new GraphQLScalarType({\n name: \"DateTimeZ\",\n description: \"A custom type for dateTime with the timezone.\",\n parseValue: value => {\n // this serves as validator\n DateTimeResolver.parseValue(value);\n validateTimeZone(value);\n return value;\n },\n serialize: value => {\n return value;\n }\n});\n"],"mappings":";;;;;;;AAAA,IAAAA,eAAA,GAAAC,OAAA;AACA,IAAAC,QAAA,GAAAD,OAAA;AACA,IAAAE,MAAA,GAAAC,sBAAA,CAAAH,OAAA;AAEA,MAAMI,gBAAgB,GAAIC,KAAa,IAAW;EAC9C,MAAMC,gBAAgB,GAAGD,KAAK,CAACE,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;EAC5C,IAAI,CAACD,gBAAgB,EAAE;IACnB,MAAM,IAAIE,cAAW,CACjB,kDAAkD,EAClD,0BAA0B,EAC1B;MACIH;IACJ,CACJ,CAAC;EACL;EACA,MAAMI,SAAS,GAAGH,gBAAgB,CAACI,QAAQ,CAAC,GAAG,CAAC,GAAG,GAAG,GAAG,GAAG;EAC5D,MAAMC,IAAI,GAAGL,gBAAgB,CAACC,KAAK,CAACE,SAAS,CAAC,CAAC,CAAC,CAAC;EACjD,IAAI,CAACE,IAAI,EAAE;IACP,MAAM,IAAIH,cAAW,CACjB,wCAAwC,EACxC,0BAA0B,EAC1B;MACIH,KAAK,EAAEC;IACX,CACJ,CAAC;EACL;EACA,MAAMM,YAAY,GAAGD,IAAI,CAACJ,KAAK,CAAC,GAAG,CAAC;EACpC,MAAM,CAACM,KAAK,EAAEC,OAAO,CAAC,GAAGF,YAAY;EACrC,IAAIC,KAAK,KAAKE,SAAS,IAAID,OAAO,KAAKC,SAAS,IAAIH,YAAY,CAACI,MAAM,KAAK,CAAC,EAAE;IAC3E,MAAM,IAAIR,cAAW,CACjB,gDAAgD,EAChD,0BAA0B,EAC1B;MACIH,KAAK,EAAEM;IACX,CACJ,CAAC;EACL;AACJ,CAAC;AACD;AACA;AACA;AACA;AACO,MAAMM,eAAe,GAAAC,OAAA,CAAAD,eAAA,GAAG,IAAIE,0BAAiB,CAAC;EACjDC,IAAI,EAAE,WAAW;EACjBC,WAAW,EAAE,+CAA+C;EAC5DC,UAAU,EAAEjB,KAAK,IAAI;IACjB;IACAkB,gCAAgB,CAACD,UAAU,CAACjB,KAAK,CAAC;IAClCD,gBAAgB,CAACC,KAAK,CAAC;IACvB,OAAOA,KAAK;EAChB,CAAC;EACDmB,SAAS,EAAEnB,KAAK,IAAI;IAChB,OAAOA,KAAK;EAChB;AACJ,CAAC,CAAC","ignoreList":[]}
|
|
@@ -4,8 +4,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.JsonScalar = void 0;
|
|
7
|
-
|
|
8
7
|
var _graphqlScalars = require("graphql-scalars");
|
|
8
|
+
const JsonScalar = exports.JsonScalar = _graphqlScalars.JSONResolver;
|
|
9
9
|
|
|
10
|
-
|
|
11
|
-
exports.JsonScalar = JsonScalar;
|
|
10
|
+
//# sourceMappingURL=JsonScalar.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["_graphqlScalars","require","JsonScalar","exports","JSONResolver"],"sources":["JsonScalar.ts"],"sourcesContent":["import { JSONResolver } from \"graphql-scalars\";\nexport const JsonScalar = JSONResolver;\n"],"mappings":";;;;;;AAAA,IAAAA,eAAA,GAAAC,OAAA;AACO,MAAMC,UAAU,GAAAC,OAAA,CAAAD,UAAA,GAAGE,4BAAY","ignoreList":[]}
|
|
@@ -1 +1,2 @@
|
|
|
1
|
-
|
|
1
|
+
import { GraphQLScalarType } from "graphql";
|
|
2
|
+
export declare const LongScalar: GraphQLScalarType;
|
|
@@ -1,11 +1,56 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
3
4
|
Object.defineProperty(exports, "__esModule", {
|
|
4
5
|
value: true
|
|
5
6
|
});
|
|
6
7
|
exports.LongScalar = void 0;
|
|
8
|
+
var _graphql = require("graphql");
|
|
9
|
+
var _language = require("graphql/language");
|
|
10
|
+
var _error = _interopRequireDefault(require("@webiny/error"));
|
|
11
|
+
const parseValue = value => {
|
|
12
|
+
if (String(value).includes(".")) {
|
|
13
|
+
throw new _error.default("Value sent must be an integer.", "INVALID_VALUE", {
|
|
14
|
+
value
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
if (typeof value === "number") {
|
|
18
|
+
return value;
|
|
19
|
+
}
|
|
20
|
+
if (value === null || value === undefined) {
|
|
21
|
+
return null;
|
|
22
|
+
}
|
|
23
|
+
if (isNaN(value) === true) {
|
|
24
|
+
throw new _error.default("Value sent must be an integer.", "INVALID_VALUE", {
|
|
25
|
+
value
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
return parseInt(value);
|
|
29
|
+
};
|
|
30
|
+
const LongScalar = exports.LongScalar = new _graphql.GraphQLScalarType({
|
|
31
|
+
name: "Long",
|
|
32
|
+
description: "A custom input type to be used for large integers (Long).",
|
|
33
|
+
serialize: value => {
|
|
34
|
+
try {
|
|
35
|
+
return parseValue(value);
|
|
36
|
+
} catch (ex) {
|
|
37
|
+
console.log({
|
|
38
|
+
message: "Value sent must be an integer.",
|
|
39
|
+
code: "INVALID_VALUE",
|
|
40
|
+
data: {
|
|
41
|
+
value
|
|
42
|
+
}
|
|
43
|
+
});
|
|
44
|
+
return null;
|
|
45
|
+
}
|
|
46
|
+
},
|
|
47
|
+
parseValue,
|
|
48
|
+
parseLiteral: ast => {
|
|
49
|
+
if (ast.kind === _language.Kind.INT) {
|
|
50
|
+
return parseInt(ast.value);
|
|
51
|
+
}
|
|
52
|
+
throw new Error(`Expected type Long, found {${ast.kind}}`);
|
|
53
|
+
}
|
|
54
|
+
});
|
|
7
55
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
const LongScalar = _graphqlScalars.LongResolver;
|
|
11
|
-
exports.LongScalar = LongScalar;
|
|
56
|
+
//# sourceMappingURL=LongScalar.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["_graphql","require","_language","_error","_interopRequireDefault","parseValue","value","String","includes","WebinyError","undefined","isNaN","parseInt","LongScalar","exports","GraphQLScalarType","name","description","serialize","ex","console","log","message","code","data","parseLiteral","ast","kind","Kind","INT","Error"],"sources":["LongScalar.ts"],"sourcesContent":["import { GraphQLScalarType } from \"graphql\";\nimport { Kind } from \"graphql/language\";\nimport WebinyError from \"@webiny/error\";\n\nconst parseValue = (value: any) => {\n if (String(value).includes(\".\")) {\n throw new WebinyError(\"Value sent must be an integer.\", \"INVALID_VALUE\", {\n value\n });\n }\n if (typeof value === \"number\") {\n return value;\n }\n\n if (value === null || value === undefined) {\n return null;\n }\n\n if (isNaN(value) === true) {\n throw new WebinyError(\"Value sent must be an integer.\", \"INVALID_VALUE\", {\n value\n });\n }\n\n return parseInt(value);\n};\n\nexport const LongScalar = new GraphQLScalarType({\n name: \"Long\",\n description: \"A custom input type to be used for large integers (Long).\",\n serialize: (value: any) => {\n try {\n return parseValue(value);\n } catch (ex) {\n console.log({\n message: \"Value sent must be an integer.\",\n code: \"INVALID_VALUE\",\n data: {\n value\n }\n });\n return null;\n }\n },\n parseValue,\n parseLiteral: ast => {\n if (ast.kind === Kind.INT) {\n return parseInt(ast.value);\n }\n\n throw new Error(`Expected type Long, found {${ast.kind}}`);\n }\n});\n"],"mappings":";;;;;;;AAAA,IAAAA,QAAA,GAAAC,OAAA;AACA,IAAAC,SAAA,GAAAD,OAAA;AACA,IAAAE,MAAA,GAAAC,sBAAA,CAAAH,OAAA;AAEA,MAAMI,UAAU,GAAIC,KAAU,IAAK;EAC/B,IAAIC,MAAM,CAACD,KAAK,CAAC,CAACE,QAAQ,CAAC,GAAG,CAAC,EAAE;IAC7B,MAAM,IAAIC,cAAW,CAAC,gCAAgC,EAAE,eAAe,EAAE;MACrEH;IACJ,CAAC,CAAC;EACN;EACA,IAAI,OAAOA,KAAK,KAAK,QAAQ,EAAE;IAC3B,OAAOA,KAAK;EAChB;EAEA,IAAIA,KAAK,KAAK,IAAI,IAAIA,KAAK,KAAKI,SAAS,EAAE;IACvC,OAAO,IAAI;EACf;EAEA,IAAIC,KAAK,CAACL,KAAK,CAAC,KAAK,IAAI,EAAE;IACvB,MAAM,IAAIG,cAAW,CAAC,gCAAgC,EAAE,eAAe,EAAE;MACrEH;IACJ,CAAC,CAAC;EACN;EAEA,OAAOM,QAAQ,CAACN,KAAK,CAAC;AAC1B,CAAC;AAEM,MAAMO,UAAU,GAAAC,OAAA,CAAAD,UAAA,GAAG,IAAIE,0BAAiB,CAAC;EAC5CC,IAAI,EAAE,MAAM;EACZC,WAAW,EAAE,2DAA2D;EACxEC,SAAS,EAAGZ,KAAU,IAAK;IACvB,IAAI;MACA,OAAOD,UAAU,CAACC,KAAK,CAAC;IAC5B,CAAC,CAAC,OAAOa,EAAE,EAAE;MACTC,OAAO,CAACC,GAAG,CAAC;QACRC,OAAO,EAAE,gCAAgC;QACzCC,IAAI,EAAE,eAAe;QACrBC,IAAI,EAAE;UACFlB;QACJ;MACJ,CAAC,CAAC;MACF,OAAO,IAAI;IACf;EACJ,CAAC;EACDD,UAAU;EACVoB,YAAY,EAAEC,GAAG,IAAI;IACjB,IAAIA,GAAG,CAACC,IAAI,KAAKC,cAAI,CAACC,GAAG,EAAE;MACvB,OAAOjB,QAAQ,CAACc,GAAG,CAACpB,KAAK,CAAC;IAC9B;IAEA,MAAM,IAAIwB,KAAK,CAAC,8BAA8BJ,GAAG,CAACC,IAAI,GAAG,CAAC;EAC9D;AACJ,CAAC,CAAC","ignoreList":[]}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import { GraphQLScalarType } from "graphql";
|
|
2
|
-
export declare const
|
|
2
|
+
export declare const NumberScalar: GraphQLScalarType;
|
|
@@ -1,18 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
5
4
|
Object.defineProperty(exports, "__esModule", {
|
|
6
5
|
value: true
|
|
7
6
|
});
|
|
8
|
-
exports.
|
|
9
|
-
|
|
7
|
+
exports.NumberScalar = void 0;
|
|
10
8
|
var _graphql = require("graphql");
|
|
11
|
-
|
|
12
9
|
var _language = require("graphql/language");
|
|
13
|
-
|
|
14
10
|
var _error = _interopRequireDefault(require("@webiny/error"));
|
|
15
|
-
|
|
16
11
|
const parseValue = value => {
|
|
17
12
|
if (String(value).match(/^0x/) !== null) {
|
|
18
13
|
throw new _error.default("Value sent must be a non-hex number.", "INVALID_VALUE", {
|
|
@@ -27,11 +22,9 @@ const parseValue = value => {
|
|
|
27
22
|
value
|
|
28
23
|
});
|
|
29
24
|
}
|
|
30
|
-
|
|
31
25
|
return parseFloat(value);
|
|
32
26
|
};
|
|
33
|
-
|
|
34
|
-
const Number = new _graphql.GraphQLScalarType({
|
|
27
|
+
const NumberScalar = exports.NumberScalar = new _graphql.GraphQLScalarType({
|
|
35
28
|
name: "Number",
|
|
36
29
|
description: "A custom input type to be used with numbers. Supports Int and Float.",
|
|
37
30
|
serialize: value => {
|
|
@@ -50,11 +43,13 @@ const Number = new _graphql.GraphQLScalarType({
|
|
|
50
43
|
},
|
|
51
44
|
parseValue,
|
|
52
45
|
parseLiteral: ast => {
|
|
53
|
-
if (ast.kind === _language.Kind.INT
|
|
54
|
-
return ast.value;
|
|
46
|
+
if (ast.kind === _language.Kind.INT) {
|
|
47
|
+
return Number(ast.value);
|
|
48
|
+
} else if (ast.kind === _language.Kind.FLOAT) {
|
|
49
|
+
return parseFloat(ast.value);
|
|
55
50
|
}
|
|
56
|
-
|
|
57
|
-
throw new Error(`Expected type Number, found {${ast.value}}`);
|
|
51
|
+
throw new Error(`Expected type Number, found {${ast.kind}}`);
|
|
58
52
|
}
|
|
59
53
|
});
|
|
60
|
-
|
|
54
|
+
|
|
55
|
+
//# sourceMappingURL=NumberScalar.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["_graphql","require","_language","_error","_interopRequireDefault","parseValue","value","String","match","WebinyError","undefined","isNaN","parseFloat","NumberScalar","exports","GraphQLScalarType","name","description","serialize","ex","console","log","message","code","data","parseLiteral","ast","kind","Kind","INT","Number","FLOAT","Error"],"sources":["NumberScalar.ts"],"sourcesContent":["import { GraphQLScalarType } from \"graphql\";\nimport { Kind } from \"graphql/language\";\nimport WebinyError from \"@webiny/error\";\n\nconst parseValue = (value: any) => {\n if (String(value).match(/^0x/) !== null) {\n throw new WebinyError(\"Value sent must be a non-hex number.\", \"INVALID_VALUE\", {\n value\n });\n } else if (typeof value === \"number\") {\n return value;\n } else if (value === null || value === undefined) {\n return null;\n } else if (isNaN(value) === true) {\n throw new WebinyError(\"Value sent must be a number.\", \"INVALID_VALUE\", {\n value\n });\n }\n return parseFloat(value);\n};\n\nexport const NumberScalar = new GraphQLScalarType({\n name: \"Number\",\n description: \"A custom input type to be used with numbers. Supports Int and Float.\",\n serialize: (value: any) => {\n try {\n return parseValue(value);\n } catch (ex) {\n console.log({\n message: \"Value sent must be a number.\",\n code: \"INVALID_VALUE\",\n data: {\n value\n }\n });\n return null;\n }\n },\n parseValue,\n parseLiteral: ast => {\n if (ast.kind === Kind.INT) {\n return Number(ast.value);\n } else if (ast.kind === Kind.FLOAT) {\n return parseFloat(ast.value);\n }\n throw new Error(`Expected type Number, found {${ast.kind}}`);\n }\n});\n"],"mappings":";;;;;;;AAAA,IAAAA,QAAA,GAAAC,OAAA;AACA,IAAAC,SAAA,GAAAD,OAAA;AACA,IAAAE,MAAA,GAAAC,sBAAA,CAAAH,OAAA;AAEA,MAAMI,UAAU,GAAIC,KAAU,IAAK;EAC/B,IAAIC,MAAM,CAACD,KAAK,CAAC,CAACE,KAAK,CAAC,KAAK,CAAC,KAAK,IAAI,E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AG,CAAC;EAChE;AACJ,CAAC,CAAC","ignoreList":[]}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import { GraphQLScalarType } from "graphql";
|
|
2
|
-
export declare const
|
|
2
|
+
export declare const RefInputScalar: GraphQLScalarType;
|
|
@@ -3,63 +3,74 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.
|
|
7
|
-
|
|
6
|
+
exports.RefInputScalar = void 0;
|
|
8
7
|
var _graphql = require("graphql");
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
8
|
+
const tests = [{
|
|
9
|
+
re: /^([0-9a-zA-Z_-]+)$/,
|
|
10
|
+
message: "Must be a string matching a-z, A-Z, 0-9, underscore (_) or dash(-)!"
|
|
11
|
+
}, {
|
|
12
|
+
re: /^-/,
|
|
13
|
+
message: "Must not start with a dash (-)!"
|
|
14
|
+
}, {
|
|
15
|
+
re: /-$/,
|
|
16
|
+
message: "Must not end with a dash (-)!"
|
|
17
|
+
}, {
|
|
18
|
+
re: /^_/,
|
|
19
|
+
message: "Must not start with an underscore (_)!"
|
|
20
|
+
}, {
|
|
21
|
+
re: /_$/,
|
|
22
|
+
message: "Must not end with an underscore (_)!"
|
|
23
|
+
}];
|
|
24
|
+
const isValidId = value => {
|
|
25
|
+
if (typeof value !== "string" || value.length < 1) {
|
|
26
|
+
throw new Error("Must be a string with at least 1 character!");
|
|
13
27
|
}
|
|
14
|
-
|
|
15
|
-
|
|
28
|
+
for (const test of tests) {
|
|
29
|
+
if (test.re.test(value) === null) {
|
|
30
|
+
throw new Error(test.message);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
return value;
|
|
16
34
|
};
|
|
17
|
-
|
|
18
|
-
const RefInput = new _graphql.GraphQLScalarType({
|
|
35
|
+
const RefInputScalar = exports.RefInputScalar = new _graphql.GraphQLScalarType({
|
|
19
36
|
name: "RefInput",
|
|
20
37
|
description: "A custom input type to be used with references. Supports plain ID and `{ id: ID }` Object literal.",
|
|
21
38
|
serialize: value => {
|
|
22
39
|
if (!value || value.id === null) {
|
|
23
40
|
return null;
|
|
24
41
|
}
|
|
25
|
-
|
|
26
42
|
return typeof value === "string" ? value : value.id;
|
|
27
43
|
},
|
|
28
44
|
parseValue: value => {
|
|
29
45
|
if (!value || value.id === null) {
|
|
30
46
|
return null;
|
|
31
47
|
}
|
|
32
|
-
|
|
33
48
|
if (typeof value === "string") {
|
|
34
|
-
return
|
|
49
|
+
return isValidId(value);
|
|
35
50
|
}
|
|
36
|
-
|
|
37
51
|
if ("id" in value) {
|
|
38
|
-
return
|
|
52
|
+
return isValidId(value.id);
|
|
39
53
|
}
|
|
40
|
-
|
|
41
54
|
throw new Error("Invalid RefInput value!");
|
|
42
55
|
},
|
|
43
56
|
parseLiteral: ast => {
|
|
44
57
|
if (ast.kind === "StringValue") {
|
|
45
|
-
return
|
|
58
|
+
return isValidId(ast.value);
|
|
46
59
|
}
|
|
47
|
-
|
|
48
60
|
if (ast.kind === "ObjectValue") {
|
|
49
61
|
for (let i = 0; i < ast.fields.length; i++) {
|
|
50
62
|
const {
|
|
51
63
|
name,
|
|
52
64
|
value
|
|
53
65
|
} = ast.fields[i];
|
|
54
|
-
|
|
55
66
|
if (name.value === "id") {
|
|
56
|
-
// @ts-
|
|
57
|
-
return
|
|
67
|
+
// @ts-expect-error
|
|
68
|
+
return isValidId(value.value);
|
|
58
69
|
}
|
|
59
70
|
}
|
|
60
71
|
}
|
|
61
|
-
|
|
62
72
|
throw new Error("Invalid RefInput value!");
|
|
63
73
|
}
|
|
64
74
|
});
|
|
65
|
-
|
|
75
|
+
|
|
76
|
+
//# sourceMappingURL=RefInputScalar.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["_graphql","require","tests","re","message","isValidId","value","length","Error","test","RefInputScalar","exports","GraphQLScalarType","name","description","serialize","id","parseValue","parseLiteral","ast","kind","i","fields"],"sources":["RefInputScalar.ts"],"sourcesContent":["import { GraphQLScalarType } from \"graphql\";\n\nconst tests = [\n {\n re: /^([0-9a-zA-Z_-]+)$/,\n message: \"Must be a string matching a-z, A-Z, 0-9, underscore (_) or dash(-)!\"\n },\n {\n re: /^-/,\n message: \"Must not start with a dash (-)!\"\n },\n {\n re: /-$/,\n message: \"Must not end with a dash (-)!\"\n },\n {\n re: /^_/,\n message: \"Must not start with an underscore (_)!\"\n },\n {\n re: /_$/,\n message: \"Must not end with an underscore (_)!\"\n }\n];\n\nconst isValidId = (value: any): string => {\n if (typeof value !== \"string\" || value.length < 1) {\n throw new Error(\"Must be a string with at least 1 character!\");\n }\n for (const test of tests) {\n if (test.re.test(value) === null) {\n throw new Error(test.message);\n }\n }\n return value;\n};\n\nexport const RefInputScalar = new GraphQLScalarType({\n name: \"RefInput\",\n description:\n \"A custom input type to be used with references. Supports plain ID and `{ id: ID }` Object literal.\",\n serialize: value => {\n if (!value || value.id === null) {\n return null;\n }\n\n return typeof value === \"string\" ? value : value.id;\n },\n parseValue: value => {\n if (!value || value.id === null) {\n return null;\n }\n\n if (typeof value === \"string\") {\n return isValidId(value);\n }\n\n if (\"id\" in value) {\n return isValidId(value.id);\n }\n\n throw new Error(\"Invalid RefInput value!\");\n },\n parseLiteral: ast => {\n if (ast.kind === \"StringValue\") {\n return isValidId(ast.value);\n }\n\n if (ast.kind === \"ObjectValue\") {\n for (let i = 0; i < ast.fields.length; i++) {\n const { name, value } = ast.fields[i];\n if (name.value === \"id\") {\n // @ts-expect-error\n return isValidId(value.value);\n }\n }\n }\n\n throw new Error(\"Invalid RefInput value!\");\n }\n});\n"],"mappings":";;;;;;AAAA,IAAAA,QAAA,GAAAC,OAAA;AAEA,MAAMC,KAAK,GAAG,CACV;EACIC,EAAE,EAAE,oBAAoB;EACxBC,OAAO,EAAE;AACb,CAAC,EACD;EACID,EAAE,EAAE,IAAI;EACRC,OAAO,EAAE;AACb,CAAC,EACD;EACID,EAAE,EAAE,I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C;EAC9C,CAAC;EACDU,YAAY,EAAEC,GAAG,IAAI;IACjB,IAAIA,GAAG,CAACC,IAAI,KAAK,aAAa,EAAE;MAC5B,OAAOf,SAAS,CAACc,GAAG,CAACb,KAAK,CAAC;IAC/B;IAEA,IAAIa,GAAG,CAACC,IAAI,KAAK,aAAa,EAAE;MAC5B,KAAK,IAAIC,CAAC,GAAG,CAAC,EAAEA,CAAC,GAAGF,GAAG,CAACG,MAAM,CAACf,MAAM,EAAEc,CAAC,EAAE,EAAE;QACxC,MAAM;UAAER,IAAI;UAAEP;QAAM,CAAC,GAAGa,GAAG,CAACG,MAAM,CAACD,CAAC,CAAC;QACrC,IAAIR,IAAI,CAACP,KAAK,KAAK,IAAI,EAAE;UACrB;UACA,OAAOD,SAAS,CAACC,KAAK,CAACA,KAAK,CAAC;QACjC;MACJ;IACJ;IAEA,MAAM,IAAIE,KAAK,CAAC,yBAAyB,CAAC;EAC9C;AACJ,CAAC,CAAC","ignoreList":[]}
|
|
@@ -1,35 +1,26 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
5
4
|
Object.defineProperty(exports, "__esModule", {
|
|
6
5
|
value: true
|
|
7
6
|
});
|
|
8
7
|
exports.TimeScalar = void 0;
|
|
9
|
-
|
|
10
8
|
var _graphql = require("graphql");
|
|
11
|
-
|
|
12
9
|
var _error = _interopRequireDefault(require("@webiny/error"));
|
|
13
|
-
|
|
14
10
|
const re = /^([0-9]{2}):([0-9]{2})(:([0-9]{2}))?$/;
|
|
15
|
-
|
|
16
11
|
const parseTime = value => {
|
|
17
12
|
if (!value || value.match(re) === null) {
|
|
18
13
|
throw new _error.default("Value does not look like time.", "TIME_VALIDATION_ERROR", {
|
|
19
14
|
value
|
|
20
15
|
});
|
|
21
16
|
}
|
|
22
|
-
|
|
23
17
|
const parsed = value.split(":").map(Number);
|
|
24
|
-
|
|
25
18
|
if (parsed.length < 2) {
|
|
26
19
|
throw new _error.default(`Could not parse the value.`, "TIME_VALIDATION_ERROR", {
|
|
27
20
|
value
|
|
28
21
|
});
|
|
29
22
|
}
|
|
30
|
-
|
|
31
23
|
const [hours, minutes, seconds = 0] = parsed;
|
|
32
|
-
|
|
33
24
|
if (hours >= 24) {
|
|
34
25
|
throw new _error.default(`There cannot be more than 24 hours.`, "TIME_VALIDATION_ERROR", {
|
|
35
26
|
value
|
|
@@ -43,14 +34,12 @@ const parseTime = value => {
|
|
|
43
34
|
value
|
|
44
35
|
});
|
|
45
36
|
}
|
|
46
|
-
|
|
47
37
|
return {
|
|
48
38
|
hours,
|
|
49
39
|
minutes,
|
|
50
40
|
seconds
|
|
51
41
|
};
|
|
52
42
|
};
|
|
53
|
-
|
|
54
43
|
const convertToTime = value => {
|
|
55
44
|
const {
|
|
56
45
|
hours,
|
|
@@ -59,8 +48,7 @@ const convertToTime = value => {
|
|
|
59
48
|
} = parseTime(value);
|
|
60
49
|
return `${String(hours).padStart(2, "0")}:${String(minutes).padStart(2, "0")}:${String(seconds).padStart(2, "0")}`;
|
|
61
50
|
};
|
|
62
|
-
|
|
63
|
-
const TimeScalar = new _graphql.GraphQLScalarType({
|
|
51
|
+
const TimeScalar = exports.TimeScalar = new _graphql.GraphQLScalarType({
|
|
64
52
|
name: "Time",
|
|
65
53
|
description: "A custom type to support time-only input.",
|
|
66
54
|
// sending to client
|
|
@@ -68,4 +56,5 @@ const TimeScalar = new _graphql.GraphQLScalarType({
|
|
|
68
56
|
// received from client
|
|
69
57
|
parseValue: convertToTime
|
|
70
58
|
});
|
|
71
|
-
|
|
59
|
+
|
|
60
|
+
//# sourceMappingURL=TimeScalar.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["_graphql","require","_error","_interopRequireDefault","re","parseTime","value","match","WebinyError","parsed","split","map","Number","length","hours","minutes","seconds","convertToTime","String","padStart","TimeScalar","exports","GraphQLScalarType","name","description","serialize","parseValue"],"sources":["TimeScalar.ts"],"sourcesContent":["import { GraphQLScalarType } from \"graphql\";\nimport WebinyError from \"@webiny/error\";\n\nconst re = /^([0-9]{2}):([0-9]{2})(:([0-9]{2}))?$/;\n\nconst parseTime = (value?: string) => {\n if (!value || value.match(re) === null) {\n throw new WebinyError(\"Value does not look like time.\", \"TIME_VALIDATION_ERROR\", { value });\n }\n const parsed = value.split(\":\").map(Number);\n if (parsed.length < 2) {\n throw new WebinyError(`Could not parse the value.`, \"TIME_VALIDATION_ERROR\", { value });\n }\n const [hours, minutes, seconds = 0] = parsed;\n if (hours >= 24) {\n throw new WebinyError(`There cannot be more than 24 hours.`, \"TIME_VALIDATION_ERROR\", {\n value\n });\n } else if (minutes >= 60) {\n throw new WebinyError(`There cannot be more than 59 minutes.`, \"TIME_VALIDATION_ERROR\", {\n value\n });\n } else if (seconds >= 60) {\n throw new WebinyError(`There cannot be more than 59 seconds.`, \"TIME_VALIDATION_ERROR\", {\n value\n });\n }\n return {\n hours,\n minutes,\n seconds\n };\n};\n\nconst convertToTime = (value: string): string => {\n const { hours, minutes, seconds } = parseTime(value);\n return `${String(hours).padStart(2, \"0\")}:${String(minutes).padStart(2, \"0\")}:${String(\n seconds\n ).padStart(2, \"0\")}`;\n};\n\nexport const TimeScalar = new GraphQLScalarType({\n name: \"Time\",\n description: \"A custom type to support time-only input.\",\n // sending to client\n serialize: convertToTime,\n // received from client\n parseValue: convertToTime\n});\n"],"mappings":";;;;;;;AAAA,IAAAA,QAAA,GAAAC,OAAA;AACA,IAAAC,MAAA,GAAAC,sBAAA,CAAAF,OAAA;AAEA,MAAMG,EAAE,GAAG,uCAAuC;AAElD,MAAMC,SAAS,GAAIC,KAAc,IAAK;EAClC,IAAI,CAACA,KAAK,IAAIA,KAAK,CAACC,KAAK,CAACH,EAAE,CAAC,KAAK,IAAI,EAAE;IACpC,MAAM,IAAII,cAAW,CAAC,gCAAg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