@webiny/handler-graphql 0.0.0-unstable.78f581c1d2 → 0.0.0-unstable.7be00a75a9
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/README.md +9 -5
- package/ResolverDecoration.d.ts +6 -0
- package/ResolverDecoration.js +23 -0
- package/ResolverDecoration.js.map +1 -0
- package/builtInTypes/AnyScalar.d.ts +1 -1
- package/builtInTypes/AnyScalar.js +9 -18
- package/builtInTypes/AnyScalar.js.map +1 -1
- package/builtInTypes/DateScalar.d.ts +1 -1
- package/builtInTypes/DateScalar.js +16 -32
- package/builtInTypes/DateScalar.js.map +1 -1
- package/builtInTypes/DateTimeScalar.d.ts +1 -1
- package/builtInTypes/DateTimeScalar.js +16 -32
- package/builtInTypes/DateTimeScalar.js.map +1 -1
- package/builtInTypes/DateTimeZScalar.d.ts +1 -1
- package/builtInTypes/DateTimeZScalar.js +27 -58
- package/builtInTypes/DateTimeZScalar.js.map +1 -1
- package/builtInTypes/IconScalar.d.ts +10 -0
- package/builtInTypes/IconScalar.js +65 -0
- package/builtInTypes/IconScalar.js.map +1 -0
- package/builtInTypes/JsonScalar.d.ts +1 -1
- package/builtInTypes/JsonScalar.js +4 -10
- package/builtInTypes/JsonScalar.js.map +1 -1
- package/builtInTypes/LongScalar.d.ts +2 -1
- package/builtInTypes/LongScalar.js +38 -9
- package/builtInTypes/LongScalar.js.map +1 -1
- package/builtInTypes/NumberScalar.d.ts +1 -1
- package/builtInTypes/NumberScalar.js +35 -58
- package/builtInTypes/NumberScalar.js.map +1 -1
- package/builtInTypes/RefInputScalar.d.ts +1 -1
- package/builtInTypes/RefInputScalar.js +48 -60
- package/builtInTypes/RefInputScalar.js.map +1 -1
- package/builtInTypes/TimeScalar.d.ts +1 -1
- package/builtInTypes/TimeScalar.js +31 -62
- package/builtInTypes/TimeScalar.js.map +1 -1
- package/builtInTypes/index.d.ts +10 -9
- package/builtInTypes/index.js +10 -122
- package/createGraphQLHandler.d.ts +3 -3
- package/createGraphQLHandler.js +77 -55
- package/createGraphQLHandler.js.map +1 -1
- package/createGraphQLSchema.d.ts +4 -2
- package/createGraphQLSchema.js +67 -54
- package/createGraphQLSchema.js.map +1 -1
- package/createRequestBody.d.ts +2 -0
- package/createRequestBody.js +28 -0
- package/createRequestBody.js.map +1 -0
- package/createResolverDecorator.d.ts +2 -0
- package/createResolverDecorator.js +4 -0
- package/createResolverDecorator.js.map +1 -0
- package/debugPlugins.d.ts +2 -2
- package/debugPlugins.js +28 -45
- package/debugPlugins.js.map +1 -1
- package/errors.js +7 -17
- package/errors.js.map +1 -1
- package/exports/api/graphql.d.ts +2 -0
- package/exports/api/graphql.js +2 -0
- package/features/GraphQLSchemaBuilder/GraphQLSchemaBuilder.d.ts +16 -0
- package/features/GraphQLSchemaBuilder/GraphQLSchemaBuilder.js +57 -0
- package/features/GraphQLSchemaBuilder/GraphQLSchemaBuilder.js.map +1 -0
- package/features/GraphQLSchemaBuilder/GraphQLSchemaComposer.d.ts +13 -0
- package/features/GraphQLSchemaBuilder/GraphQLSchemaComposer.js +35 -0
- package/features/GraphQLSchemaBuilder/GraphQLSchemaComposer.js.map +1 -0
- package/features/GraphQLSchemaBuilder/abstractions.d.ts +34 -0
- package/features/GraphQLSchemaBuilder/abstractions.js +6 -0
- package/features/GraphQLSchemaBuilder/abstractions.js.map +1 -0
- package/features/GraphQLSchemaBuilder/feature.d.ts +4 -0
- package/features/GraphQLSchemaBuilder/feature.js +11 -0
- package/features/GraphQLSchemaBuilder/feature.js.map +1 -0
- package/graphql/abstractions.core.d.ts +11 -0
- package/graphql/abstractions.core.js +5 -0
- package/graphql/abstractions.core.js.map +1 -0
- package/graphql/abstractions.d.ts +2 -0
- package/graphql/abstractions.js +2 -0
- package/graphql/abstractions.public.d.ts +18 -0
- package/graphql/abstractions.public.js +5 -0
- package/graphql/abstractions.public.js.map +1 -0
- package/index.d.ts +10 -5
- package/index.js +12 -57
- package/index.js.map +1 -1
- package/interceptConsole.js +31 -39
- package/interceptConsole.js.map +1 -1
- package/package.json +32 -29
- package/plugins/GraphQLSchemaPlugin.d.ts +13 -5
- package/plugins/GraphQLSchemaPlugin.js +23 -29
- package/plugins/GraphQLSchemaPlugin.js.map +1 -1
- package/plugins/index.d.ts +1 -1
- package/plugins/index.js +1 -18
- package/processRequestBody.d.ts +4 -5
- package/processRequestBody.js +35 -42
- package/processRequestBody.js.map +1 -1
- package/responses.d.ts +11 -1
- package/responses.js +44 -92
- package/responses.js.map +1 -1
- package/types.d.ts +20 -13
- package/types.js +0 -5
- package/utils/index.d.ts +1 -0
- package/utils/index.js +1 -0
- package/utils/resolve.d.ts +21 -0
- package/utils/resolve.js +20 -0
- package/utils/resolve.js.map +1 -0
- package/builtInTypes/index.js.map +0 -1
- package/plugins/index.js.map +0 -1
- package/types.js.map +0 -1
|
@@ -1,64 +1,41 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
});
|
|
8
|
-
exports.NumberScalar = void 0;
|
|
9
|
-
|
|
10
|
-
var _graphql = require("graphql");
|
|
11
|
-
|
|
12
|
-
var _language = require("graphql/language");
|
|
13
|
-
|
|
14
|
-
var _error = _interopRequireDefault(require("@webiny/error"));
|
|
15
|
-
|
|
16
|
-
const parseValue = value => {
|
|
17
|
-
if (String(value).match(/^0x/) !== null) {
|
|
18
|
-
throw new _error.default("Value sent must be a non-hex number.", "INVALID_VALUE", {
|
|
19
|
-
value
|
|
1
|
+
import { GraphQLScalarType } from "graphql";
|
|
2
|
+
import { Kind } from "graphql/language/index.js";
|
|
3
|
+
import error from "@webiny/error";
|
|
4
|
+
const parseValue = (value)=>{
|
|
5
|
+
if (null !== String(value).match(/^0x/)) throw new error("Value sent must be a non-hex number.", "INVALID_VALUE", {
|
|
6
|
+
value
|
|
20
7
|
});
|
|
21
|
-
|
|
22
|
-
return
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
} else if (isNaN(value) === true) {
|
|
26
|
-
throw new _error.default("Value sent must be a number.", "INVALID_VALUE", {
|
|
27
|
-
value
|
|
8
|
+
if ("number" == typeof value) return value;
|
|
9
|
+
if (null == value) return null;
|
|
10
|
+
if (true === isNaN(value)) throw new error("Value sent must be a number.", "INVALID_VALUE", {
|
|
11
|
+
value
|
|
28
12
|
});
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
return parseFloat(value);
|
|
13
|
+
return parseFloat(value);
|
|
32
14
|
};
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
15
|
+
const NumberScalar = new GraphQLScalarType({
|
|
16
|
+
name: "Number",
|
|
17
|
+
description: "A custom input type to be used with numbers. Supports Int and Float.",
|
|
18
|
+
serialize: (value)=>{
|
|
19
|
+
try {
|
|
20
|
+
return parseValue(value);
|
|
21
|
+
} catch {
|
|
22
|
+
console.log({
|
|
23
|
+
message: "Value sent must be a number.",
|
|
24
|
+
code: "INVALID_VALUE",
|
|
25
|
+
data: {
|
|
26
|
+
value
|
|
27
|
+
}
|
|
28
|
+
});
|
|
29
|
+
return null;
|
|
46
30
|
}
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
const value = ast.value;
|
|
54
|
-
|
|
55
|
-
if (ast.kind === _language.Kind.INT) {
|
|
56
|
-
return Number(value);
|
|
57
|
-
} else if (ast.kind === _language.Kind.FLOAT) {
|
|
58
|
-
return parseFloat(value);
|
|
31
|
+
},
|
|
32
|
+
parseValue: parseValue,
|
|
33
|
+
parseLiteral: (ast)=>{
|
|
34
|
+
if (ast.kind === Kind.INT) return Number(ast.value);
|
|
35
|
+
if (ast.kind === Kind.FLOAT) return parseFloat(ast.value);
|
|
36
|
+
throw new Error(`Expected type Number, found {${ast.kind}}`);
|
|
59
37
|
}
|
|
60
|
-
|
|
61
|
-
throw new Error(`Expected type Number, found {${value}}`);
|
|
62
|
-
}
|
|
63
38
|
});
|
|
64
|
-
|
|
39
|
+
export { NumberScalar };
|
|
40
|
+
|
|
41
|
+
//# sourceMappingURL=NumberScalar.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"builtInTypes/NumberScalar.js","sources":["../../src/builtInTypes/NumberScalar.ts"],"sourcesContent":["import { GraphQLScalarType } from \"graphql\";\nimport { Kind } from \"graphql/language/index.js\";\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 {\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"],"names":["parseValue","value","String","WebinyError","isNaN","parseFloat","NumberScalar","GraphQLScalarType","console","ast","Kind","Number","Error"],"mappings":";;;AAIA,MAAMA,aAAa,CAACC;IAChB,IAAIC,AAA+B,SAA/BA,OAAOD,OAAO,KAAK,CAAC,QACpB,MAAM,IAAIE,MAAY,wCAAwC,iBAAiB;QAC3EF;IACJ;IACG,IAAI,AAAiB,YAAjB,OAAOA,OACd,OAAOA;IACJ,IAAIA,QAAAA,OACP,OAAO;IACJ,IAAIG,AAAiB,SAAjBA,MAAMH,QACb,MAAM,IAAIE,MAAY,gCAAgC,iBAAiB;QACnEF;IACJ;IAEJ,OAAOI,WAAWJ;AACtB;AAEO,MAAMK,eAAe,IAAIC,kBAAkB;IAC9C,MAAM;IACN,aAAa;IACb,WAAW,CAACN;QACR,IAAI;YACA,OAAOD,WAAWC;QACtB,EAAE,OAAM;YACJO,QAAQ,GAAG,CAAC;gBACR,SAAS;gBACT,MAAM;gBACN,MAAM;oBACFP;gBACJ;YACJ;YACA,OAAO;QACX;IACJ;IACAD,YAAAA;IACA,cAAcS,CAAAA;QACV,IAAIA,IAAI,IAAI,KAAKC,KAAK,GAAG,EACrB,OAAOC,OAAOF,IAAI,KAAK;QACpB,IAAIA,IAAI,IAAI,KAAKC,KAAK,KAAK,EAC9B,OAAOL,WAAWI,IAAI,KAAK;QAE/B,MAAM,IAAIG,MAAM,CAAC,6BAA6B,EAAEH,IAAI,IAAI,CAAC,CAAC,CAAC;IAC/D;AACJ"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import { GraphQLScalarType } from "graphql";
|
|
2
|
-
export declare const
|
|
2
|
+
export declare const RefInputScalar: GraphQLScalarType<string | null, any>;
|
|
@@ -1,65 +1,53 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
1
|
+
import { GraphQLScalarType } from "graphql";
|
|
2
|
+
const tests = [
|
|
3
|
+
{
|
|
4
|
+
re: /^([0-9a-zA-Z_-]+)$/,
|
|
5
|
+
message: "Must be a string matching a-z, A-Z, 0-9, underscore (_) or dash(-)!"
|
|
6
|
+
},
|
|
7
|
+
{
|
|
8
|
+
re: /^-/,
|
|
9
|
+
message: "Must not start with a dash (-)!"
|
|
10
|
+
},
|
|
11
|
+
{
|
|
12
|
+
re: /-$/,
|
|
13
|
+
message: "Must not end with a dash (-)!"
|
|
14
|
+
},
|
|
15
|
+
{
|
|
16
|
+
re: /^_/,
|
|
17
|
+
message: "Must not start with an underscore (_)!"
|
|
18
|
+
},
|
|
19
|
+
{
|
|
20
|
+
re: /_$/,
|
|
21
|
+
message: "Must not end with an underscore (_)!"
|
|
22
|
+
}
|
|
23
|
+
];
|
|
24
|
+
const isValidId = (value)=>{
|
|
25
|
+
if ("string" != typeof value || value.length < 1) throw new Error("Must be a string with at least 1 character!");
|
|
26
|
+
for (const test of tests)if (null === test.re.test(value)) throw new Error(test.message);
|
|
12
27
|
return value;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
throw new Error("Must be a valid Mongo ID!");
|
|
16
28
|
};
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
if ("id" in value) {
|
|
38
|
-
return isMongoId(value.id);
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
throw new Error("Invalid RefInput value!");
|
|
42
|
-
},
|
|
43
|
-
parseLiteral: ast => {
|
|
44
|
-
if (ast.kind === "StringValue") {
|
|
45
|
-
return isMongoId(ast.value);
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
if (ast.kind === "ObjectValue") {
|
|
49
|
-
for (let i = 0; i < ast.fields.length; i++) {
|
|
50
|
-
const {
|
|
51
|
-
name,
|
|
52
|
-
value
|
|
53
|
-
} = ast.fields[i];
|
|
54
|
-
|
|
55
|
-
if (name.value === "id") {
|
|
56
|
-
// @ts-ignore
|
|
57
|
-
return isMongoId(value.value);
|
|
29
|
+
const RefInputScalar = new GraphQLScalarType({
|
|
30
|
+
name: "RefInput",
|
|
31
|
+
description: "A custom input type to be used with references. Supports plain ID and `{ id: ID }` Object literal.",
|
|
32
|
+
serialize: (value)=>{
|
|
33
|
+
if (!value || null === value.id) return null;
|
|
34
|
+
return "string" == typeof value ? value : value.id;
|
|
35
|
+
},
|
|
36
|
+
parseValue: (value)=>{
|
|
37
|
+
if (!value || null === value.id) return null;
|
|
38
|
+
if ("string" == typeof value) return isValidId(value);
|
|
39
|
+
if ("id" in value) return isValidId(value.id);
|
|
40
|
+
throw new Error("Invalid RefInput value!");
|
|
41
|
+
},
|
|
42
|
+
parseLiteral: (ast)=>{
|
|
43
|
+
if ("StringValue" === ast.kind) return isValidId(ast.value);
|
|
44
|
+
if ("ObjectValue" === ast.kind) for(let i = 0; i < ast.fields.length; i++){
|
|
45
|
+
const { name, value } = ast.fields[i];
|
|
46
|
+
if ("id" === name.value) return isValidId(value.value);
|
|
58
47
|
}
|
|
59
|
-
|
|
48
|
+
throw new Error("Invalid RefInput value!");
|
|
60
49
|
}
|
|
61
|
-
|
|
62
|
-
throw new Error("Invalid RefInput value!");
|
|
63
|
-
}
|
|
64
50
|
});
|
|
65
|
-
|
|
51
|
+
export { RefInputScalar };
|
|
52
|
+
|
|
53
|
+
//# sourceMappingURL=RefInputScalar.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"builtInTypes/RefInputScalar.js","sources":["../../src/builtInTypes/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 /**\n * We can set value as any because we are handling it.\n */\n serialize: (value: any) => {\n if (!value || value.id === null) {\n return null;\n }\n\n return typeof value === \"string\" ? value : value.id;\n },\n /**\n * We can set value as any because we are handling it.\n */\n parseValue: (value: any) => {\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"],"names":["tests","isValidId","value","Error","test","RefInputScalar","GraphQLScalarType","ast","i","name"],"mappings":";AAEA,MAAMA,QAAQ;IACV;QACI,IAAI;QACJ,SAAS;IACb;IACA;QACI,IAAI;QACJ,SAAS;IACb;IACA;QACI,IAAI;QACJ,SAAS;IACb;IACA;QACI,IAAI;QACJ,SAAS;IACb;IACA;QACI,IAAI;QACJ,SAAS;IACb;CACH;AAED,MAAMC,YAAY,CAACC;IACf,IAAI,AAAiB,YAAjB,OAAOA,SAAsBA,MAAM,MAAM,GAAG,GAC5C,MAAM,IAAIC,MAAM;IAEpB,KAAK,MAAMC,QAAQJ,MACf,IAAII,AAAwB,SAAxBA,KAAK,EAAE,CAAC,IAAI,CAACF,QACb,MAAM,IAAIC,MAAMC,KAAK,OAAO;IAGpC,OAAOF;AACX;AAEO,MAAMG,iBAAiB,IAAIC,kBAAkB;IAChD,MAAM;IACN,aACI;IAIJ,WAAW,CAACJ;QACR,IAAI,CAACA,SAASA,AAAa,SAAbA,MAAM,EAAE,EAClB,OAAO;QAGX,OAAO,AAAiB,YAAjB,OAAOA,QAAqBA,QAAQA,MAAM,EAAE;IACvD;IAIA,YAAY,CAACA;QACT,IAAI,CAACA,SAASA,AAAa,SAAbA,MAAM,EAAE,EAClB,OAAO;QAGX,IAAI,AAAiB,YAAjB,OAAOA,OACP,OAAOD,UAAUC;QAGrB,IAAI,QAAQA,OACR,OAAOD,UAAUC,MAAM,EAAE;QAG7B,MAAM,IAAIC,MAAM;IACpB;IACA,cAAcI,CAAAA;QACV,IAAIA,AAAa,kBAAbA,IAAI,IAAI,EACR,OAAON,UAAUM,IAAI,KAAK;QAG9B,IAAIA,AAAa,kBAAbA,IAAI,IAAI,EACR,IAAK,IAAIC,IAAI,GAAGA,IAAID,IAAI,MAAM,CAAC,MAAM,EAAEC,IAAK;YACxC,MAAM,EAAEC,IAAI,EAAEP,KAAK,EAAE,GAAGK,IAAI,MAAM,CAACC,EAAE;YACrC,IAAIC,AAAe,SAAfA,KAAK,KAAK,EAEV,OAAOR,UAAUC,MAAM,KAAK;QAEpC;QAGJ,MAAM,IAAIC,MAAM;IACpB;AACJ"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import { GraphQLScalarType } from "graphql";
|
|
2
|
-
export declare const TimeScalar: GraphQLScalarType
|
|
2
|
+
export declare const TimeScalar: GraphQLScalarType<string, string>;
|
|
@@ -1,71 +1,40 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
|
-
|
|
5
|
-
Object.defineProperty(exports, "__esModule", {
|
|
6
|
-
value: true
|
|
7
|
-
});
|
|
8
|
-
exports.TimeScalar = void 0;
|
|
9
|
-
|
|
10
|
-
var _graphql = require("graphql");
|
|
11
|
-
|
|
12
|
-
var _error = _interopRequireDefault(require("@webiny/error"));
|
|
13
|
-
|
|
1
|
+
import { GraphQLScalarType } from "graphql";
|
|
2
|
+
import error from "@webiny/error";
|
|
14
3
|
const re = /^([0-9]{2}):([0-9]{2})(:([0-9]{2}))?$/;
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
throw new _error.default("Value does not look like time.", "TIME_VALIDATION_ERROR", {
|
|
19
|
-
value
|
|
4
|
+
const parseTime = (value)=>{
|
|
5
|
+
if ("string" != typeof value || !value || null === value.match(re)) throw new error("Value does not look like time.", "TIME_VALIDATION_ERROR", {
|
|
6
|
+
value
|
|
20
7
|
});
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
if (parsed.length < 2) {
|
|
26
|
-
throw new _error.default(`Could not parse the value.`, "TIME_VALIDATION_ERROR", {
|
|
27
|
-
value
|
|
8
|
+
const parsed = value.split(":").map(Number);
|
|
9
|
+
if (parsed.length < 2) throw new error("Could not parse the value.", "TIME_VALIDATION_ERROR", {
|
|
10
|
+
value
|
|
28
11
|
});
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
if (hours >= 24) {
|
|
34
|
-
throw new _error.default(`There cannot be more than 24 hours.`, "TIME_VALIDATION_ERROR", {
|
|
35
|
-
value
|
|
12
|
+
const [hours, minutes, seconds = 0] = parsed;
|
|
13
|
+
if (hours >= 24) throw new error("There cannot be more than 24 hours.", "TIME_VALIDATION_ERROR", {
|
|
14
|
+
value
|
|
36
15
|
});
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
value
|
|
16
|
+
if (minutes >= 60) throw new error("There cannot be more than 59 minutes.", "TIME_VALIDATION_ERROR", {
|
|
17
|
+
value
|
|
40
18
|
});
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
value
|
|
19
|
+
if (seconds >= 60) throw new error("There cannot be more than 59 seconds.", "TIME_VALIDATION_ERROR", {
|
|
20
|
+
value
|
|
44
21
|
});
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
seconds
|
|
51
|
-
};
|
|
22
|
+
return {
|
|
23
|
+
hours,
|
|
24
|
+
minutes,
|
|
25
|
+
seconds
|
|
26
|
+
};
|
|
52
27
|
};
|
|
53
|
-
|
|
54
|
-
const
|
|
55
|
-
|
|
56
|
-
hours,
|
|
57
|
-
minutes,
|
|
58
|
-
seconds
|
|
59
|
-
} = parseTime(value);
|
|
60
|
-
return `${String(hours).padStart(2, "0")}:${String(minutes).padStart(2, "0")}:${String(seconds).padStart(2, "0")}`;
|
|
28
|
+
const convertToTime = (value)=>{
|
|
29
|
+
const { hours, minutes, seconds } = parseTime(value);
|
|
30
|
+
return `${String(hours).padStart(2, "0")}:${String(minutes).padStart(2, "0")}:${String(seconds).padStart(2, "0")}`;
|
|
61
31
|
};
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
serialize: convertToTime,
|
|
68
|
-
// received from client
|
|
69
|
-
parseValue: convertToTime
|
|
32
|
+
const TimeScalar = new GraphQLScalarType({
|
|
33
|
+
name: "Time",
|
|
34
|
+
description: "A custom type to support time-only input.",
|
|
35
|
+
serialize: convertToTime,
|
|
36
|
+
parseValue: convertToTime
|
|
70
37
|
});
|
|
71
|
-
|
|
38
|
+
export { TimeScalar };
|
|
39
|
+
|
|
40
|
+
//# sourceMappingURL=TimeScalar.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"builtInTypes/TimeScalar.js","sources":["../../src/builtInTypes/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?: unknown) => {\n if (typeof value !== \"string\" || !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: unknown): 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"],"names":["re","parseTime","value","WebinyError","parsed","Number","hours","minutes","seconds","convertToTime","String","TimeScalar","GraphQLScalarType"],"mappings":";;AAGA,MAAMA,KAAK;AAEX,MAAMC,YAAY,CAACC;IACf,IAAI,AAAiB,YAAjB,OAAOA,SAAsB,CAACA,SAASA,AAAoB,SAApBA,MAAM,KAAK,CAACF,KACnD,MAAM,IAAIG,MAAY,kCAAkC,yBAAyB;QAAED;IAAM;IAE7F,MAAME,SAASF,MAAM,KAAK,CAAC,KAAK,GAAG,CAACG;IACpC,IAAID,OAAO,MAAM,GAAG,GAChB,MAAM,IAAID,MAAY,8BAA8B,yBAAyB;QAAED;IAAM;IAEzF,MAAM,CAACI,OAAOC,SAASC,UAAU,CAAC,CAAC,GAAGJ;IACtC,IAAIE,SAAS,IACT,MAAM,IAAIH,MAAY,uCAAuC,yBAAyB;QAClFD;IACJ;IACG,IAAIK,WAAW,IAClB,MAAM,IAAIJ,MAAY,yCAAyC,yBAAyB;QACpFD;IACJ;IACG,IAAIM,WAAW,IAClB,MAAM,IAAIL,MAAY,yCAAyC,yBAAyB;QACpFD;IACJ;IAEJ,OAAO;QACHI;QACAC;QACAC;IACJ;AACJ;AAEA,MAAMC,gBAAgB,CAACP;IACnB,MAAM,EAAEI,KAAK,EAAEC,OAAO,EAAEC,OAAO,EAAE,GAAGP,UAAUC;IAC9C,OAAO,GAAGQ,OAAOJ,OAAO,QAAQ,CAAC,GAAG,KAAK,CAAC,EAAEI,OAAOH,SAAS,QAAQ,CAAC,GAAG,KAAK,CAAC,EAAEG,OAC5EF,SACF,QAAQ,CAAC,GAAG,MAAM;AACxB;AAEO,MAAMG,aAAa,IAAIC,kBAAkB;IAC5C,MAAM;IACN,aAAa;IAEb,WAAWH;IAEX,YAAYA;AAChB"}
|
package/builtInTypes/index.d.ts
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
export * from "./AnyScalar";
|
|
2
|
-
export * from "./DateScalar";
|
|
3
|
-
export * from "./DateTimeScalar";
|
|
4
|
-
export * from "./DateTimeZScalar";
|
|
5
|
-
export * from "./JsonScalar";
|
|
6
|
-
export * from "./LongScalar";
|
|
7
|
-
export * from "./NumberScalar";
|
|
8
|
-
export * from "./RefInputScalar";
|
|
9
|
-
export * from "./TimeScalar";
|
|
1
|
+
export * from "./AnyScalar.js";
|
|
2
|
+
export * from "./DateScalar.js";
|
|
3
|
+
export * from "./DateTimeScalar.js";
|
|
4
|
+
export * from "./DateTimeZScalar.js";
|
|
5
|
+
export * from "./JsonScalar.js";
|
|
6
|
+
export * from "./LongScalar.js";
|
|
7
|
+
export * from "./NumberScalar.js";
|
|
8
|
+
export * from "./RefInputScalar.js";
|
|
9
|
+
export * from "./TimeScalar.js";
|
|
10
|
+
export * from "./IconScalar.js";
|
package/builtInTypes/index.js
CHANGED
|
@@ -1,122 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
if (key in exports && exports[key] === _AnyScalar[key]) return;
|
|
12
|
-
Object.defineProperty(exports, key, {
|
|
13
|
-
enumerable: true,
|
|
14
|
-
get: function () {
|
|
15
|
-
return _AnyScalar[key];
|
|
16
|
-
}
|
|
17
|
-
});
|
|
18
|
-
});
|
|
19
|
-
|
|
20
|
-
var _DateScalar = require("./DateScalar");
|
|
21
|
-
|
|
22
|
-
Object.keys(_DateScalar).forEach(function (key) {
|
|
23
|
-
if (key === "default" || key === "__esModule") return;
|
|
24
|
-
if (key in exports && exports[key] === _DateScalar[key]) return;
|
|
25
|
-
Object.defineProperty(exports, key, {
|
|
26
|
-
enumerable: true,
|
|
27
|
-
get: function () {
|
|
28
|
-
return _DateScalar[key];
|
|
29
|
-
}
|
|
30
|
-
});
|
|
31
|
-
});
|
|
32
|
-
|
|
33
|
-
var _DateTimeScalar = require("./DateTimeScalar");
|
|
34
|
-
|
|
35
|
-
Object.keys(_DateTimeScalar).forEach(function (key) {
|
|
36
|
-
if (key === "default" || key === "__esModule") return;
|
|
37
|
-
if (key in exports && exports[key] === _DateTimeScalar[key]) return;
|
|
38
|
-
Object.defineProperty(exports, key, {
|
|
39
|
-
enumerable: true,
|
|
40
|
-
get: function () {
|
|
41
|
-
return _DateTimeScalar[key];
|
|
42
|
-
}
|
|
43
|
-
});
|
|
44
|
-
});
|
|
45
|
-
|
|
46
|
-
var _DateTimeZScalar = require("./DateTimeZScalar");
|
|
47
|
-
|
|
48
|
-
Object.keys(_DateTimeZScalar).forEach(function (key) {
|
|
49
|
-
if (key === "default" || key === "__esModule") return;
|
|
50
|
-
if (key in exports && exports[key] === _DateTimeZScalar[key]) return;
|
|
51
|
-
Object.defineProperty(exports, key, {
|
|
52
|
-
enumerable: true,
|
|
53
|
-
get: function () {
|
|
54
|
-
return _DateTimeZScalar[key];
|
|
55
|
-
}
|
|
56
|
-
});
|
|
57
|
-
});
|
|
58
|
-
|
|
59
|
-
var _JsonScalar = require("./JsonScalar");
|
|
60
|
-
|
|
61
|
-
Object.keys(_JsonScalar).forEach(function (key) {
|
|
62
|
-
if (key === "default" || key === "__esModule") return;
|
|
63
|
-
if (key in exports && exports[key] === _JsonScalar[key]) return;
|
|
64
|
-
Object.defineProperty(exports, key, {
|
|
65
|
-
enumerable: true,
|
|
66
|
-
get: function () {
|
|
67
|
-
return _JsonScalar[key];
|
|
68
|
-
}
|
|
69
|
-
});
|
|
70
|
-
});
|
|
71
|
-
|
|
72
|
-
var _LongScalar = require("./LongScalar");
|
|
73
|
-
|
|
74
|
-
Object.keys(_LongScalar).forEach(function (key) {
|
|
75
|
-
if (key === "default" || key === "__esModule") return;
|
|
76
|
-
if (key in exports && exports[key] === _LongScalar[key]) return;
|
|
77
|
-
Object.defineProperty(exports, key, {
|
|
78
|
-
enumerable: true,
|
|
79
|
-
get: function () {
|
|
80
|
-
return _LongScalar[key];
|
|
81
|
-
}
|
|
82
|
-
});
|
|
83
|
-
});
|
|
84
|
-
|
|
85
|
-
var _NumberScalar = require("./NumberScalar");
|
|
86
|
-
|
|
87
|
-
Object.keys(_NumberScalar).forEach(function (key) {
|
|
88
|
-
if (key === "default" || key === "__esModule") return;
|
|
89
|
-
if (key in exports && exports[key] === _NumberScalar[key]) return;
|
|
90
|
-
Object.defineProperty(exports, key, {
|
|
91
|
-
enumerable: true,
|
|
92
|
-
get: function () {
|
|
93
|
-
return _NumberScalar[key];
|
|
94
|
-
}
|
|
95
|
-
});
|
|
96
|
-
});
|
|
97
|
-
|
|
98
|
-
var _RefInputScalar = require("./RefInputScalar");
|
|
99
|
-
|
|
100
|
-
Object.keys(_RefInputScalar).forEach(function (key) {
|
|
101
|
-
if (key === "default" || key === "__esModule") return;
|
|
102
|
-
if (key in exports && exports[key] === _RefInputScalar[key]) return;
|
|
103
|
-
Object.defineProperty(exports, key, {
|
|
104
|
-
enumerable: true,
|
|
105
|
-
get: function () {
|
|
106
|
-
return _RefInputScalar[key];
|
|
107
|
-
}
|
|
108
|
-
});
|
|
109
|
-
});
|
|
110
|
-
|
|
111
|
-
var _TimeScalar = require("./TimeScalar");
|
|
112
|
-
|
|
113
|
-
Object.keys(_TimeScalar).forEach(function (key) {
|
|
114
|
-
if (key === "default" || key === "__esModule") return;
|
|
115
|
-
if (key in exports && exports[key] === _TimeScalar[key]) return;
|
|
116
|
-
Object.defineProperty(exports, key, {
|
|
117
|
-
enumerable: true,
|
|
118
|
-
get: function () {
|
|
119
|
-
return _TimeScalar[key];
|
|
120
|
-
}
|
|
121
|
-
});
|
|
122
|
-
});
|
|
1
|
+
export * from "./AnyScalar.js";
|
|
2
|
+
export * from "./DateScalar.js";
|
|
3
|
+
export * from "./DateTimeScalar.js";
|
|
4
|
+
export * from "./DateTimeZScalar.js";
|
|
5
|
+
export * from "./JsonScalar.js";
|
|
6
|
+
export * from "./LongScalar.js";
|
|
7
|
+
export * from "./NumberScalar.js";
|
|
8
|
+
export * from "./RefInputScalar.js";
|
|
9
|
+
export * from "./TimeScalar.js";
|
|
10
|
+
export * from "./IconScalar.js";
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
declare const _default: (options?: HandlerGraphQLOptions) =>
|
|
1
|
+
import type { Plugin } from "@webiny/plugins/types.js";
|
|
2
|
+
import type { HandlerGraphQLOptions } from "./types.js";
|
|
3
|
+
declare const _default: (options?: HandlerGraphQLOptions) => Plugin[];
|
|
4
4
|
export default _default;
|