@webiny/handler-graphql 0.0.0-unstable.aad28a72ae → 0.0.0-unstable.ac6ebf63c6
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 +19 -0
- package/ResolverDecoration.js.map +1 -0
- package/builtInTypes/AnyScalar.d.ts +1 -1
- package/builtInTypes/AnyScalar.js +4 -12
- package/builtInTypes/AnyScalar.js.map +1 -1
- package/builtInTypes/DateScalar.d.ts +1 -1
- package/builtInTypes/DateScalar.js +10 -20
- package/builtInTypes/DateScalar.js.map +1 -1
- package/builtInTypes/DateTimeScalar.d.ts +1 -1
- package/builtInTypes/DateTimeScalar.js +10 -20
- package/builtInTypes/DateTimeScalar.js.map +1 -1
- package/builtInTypes/DateTimeZScalar.d.ts +1 -1
- package/builtInTypes/DateTimeZScalar.js +10 -29
- package/builtInTypes/DateTimeZScalar.js.map +1 -1
- package/builtInTypes/IconScalar.d.ts +10 -0
- package/builtInTypes/IconScalar.js +93 -0
- package/builtInTypes/IconScalar.js.map +1 -0
- package/builtInTypes/JsonScalar.d.ts +1 -1
- package/builtInTypes/JsonScalar.js +3 -10
- package/builtInTypes/JsonScalar.js.map +1 -1
- package/builtInTypes/LongScalar.d.ts +2 -1
- package/builtInTypes/LongScalar.js +47 -9
- package/builtInTypes/LongScalar.js.map +1 -1
- package/builtInTypes/NumberScalar.d.ts +1 -1
- package/builtInTypes/NumberScalar.js +14 -30
- package/builtInTypes/NumberScalar.js.map +1 -1
- package/builtInTypes/RefInputScalar.d.ts +1 -1
- package/builtInTypes/RefInputScalar.js +40 -29
- package/builtInTypes/RefInputScalar.js.map +1 -1
- package/builtInTypes/TimeScalar.d.ts +1 -1
- package/builtInTypes/TimeScalar.js +11 -29
- package/builtInTypes/TimeScalar.js.map +1 -1
- package/builtInTypes/index.d.ts +10 -9
- package/builtInTypes/index.js +12 -122
- package/builtInTypes/index.js.map +1 -1
- package/createGraphQLHandler.d.ts +3 -3
- package/createGraphQLHandler.js +59 -48
- package/createGraphQLHandler.js.map +1 -1
- package/createGraphQLSchema.d.ts +4 -2
- package/createGraphQLSchema.js +76 -46
- package/createGraphQLSchema.js.map +1 -1
- package/createRequestBody.d.ts +2 -0
- package/createRequestBody.js +26 -0
- package/createRequestBody.js.map +1 -0
- package/createResolverDecorator.d.ts +2 -0
- package/createResolverDecorator.js +5 -0
- package/createResolverDecorator.js.map +1 -0
- package/debugPlugins.d.ts +2 -2
- package/debugPlugins.js +5 -19
- package/debugPlugins.js.map +1 -1
- package/errors.js +3 -14
- package/errors.js.map +1 -1
- package/exports/api/graphql.d.ts +2 -0
- package/exports/api/graphql.js +4 -0
- package/exports/api/graphql.js.map +1 -0
- package/features/GraphQLSchemaBuilder/GraphQLSchemaBuilder.d.ts +16 -0
- package/features/GraphQLSchemaBuilder/GraphQLSchemaBuilder.js +64 -0
- package/features/GraphQLSchemaBuilder/GraphQLSchemaBuilder.js.map +1 -0
- package/features/GraphQLSchemaBuilder/GraphQLSchemaComposer.d.ts +13 -0
- package/features/GraphQLSchemaBuilder/GraphQLSchemaComposer.js +29 -0
- package/features/GraphQLSchemaBuilder/GraphQLSchemaComposer.js.map +1 -0
- package/features/GraphQLSchemaBuilder/abstractions.d.ts +34 -0
- package/features/GraphQLSchemaBuilder/abstractions.js +5 -0
- package/features/GraphQLSchemaBuilder/abstractions.js.map +1 -0
- package/features/GraphQLSchemaBuilder/feature.d.ts +1 -0
- package/features/GraphQLSchemaBuilder/feature.js +10 -0
- package/features/GraphQLSchemaBuilder/feature.js.map +1 -0
- package/graphql/abstractions.core.d.ts +11 -0
- package/graphql/abstractions.core.js +10 -0
- package/graphql/abstractions.core.js.map +1 -0
- package/graphql/abstractions.d.ts +2 -0
- package/graphql/abstractions.js +4 -0
- package/graphql/abstractions.js.map +1 -0
- package/graphql/abstractions.public.d.ts +19 -0
- package/graphql/abstractions.public.js +12 -0
- package/graphql/abstractions.public.js.map +1 -0
- package/index.d.ts +10 -5
- package/index.js +13 -57
- package/index.js.map +1 -1
- package/interceptConsole.js +9 -20
- package/interceptConsole.js.map +1 -1
- package/package.json +23 -25
- package/plugins/GraphQLSchemaPlugin.d.ts +13 -5
- package/plugins/GraphQLSchemaPlugin.js +15 -20
- package/plugins/GraphQLSchemaPlugin.js.map +1 -1
- package/plugins/index.d.ts +1 -1
- package/plugins/index.js +2 -17
- package/plugins/index.js.map +1 -1
- package/processRequestBody.d.ts +4 -5
- package/processRequestBody.js +19 -23
- package/processRequestBody.js.map +1 -1
- package/responses.js +10 -51
- package/responses.js.map +1 -1
- package/types.d.ts +20 -13
- package/types.js +2 -4
- package/types.js.map +1 -1
- package/utils/index.d.ts +1 -0
- package/utils/index.js +3 -0
- package/utils/index.js.map +1 -0
- package/utils/resolve.d.ts +21 -0
- package/utils/resolve.js +19 -0
- package/utils/resolve.js.map +1 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["parseValue","value","String","match","
|
|
1
|
+
{"version":3,"names":["GraphQLScalarType","Kind","WebinyError","parseValue","value","String","match","undefined","isNaN","parseFloat","NumberScalar","name","description","serialize","console","log","message","code","data","parseLiteral","ast","kind","INT","Number","FLOAT","Error"],"sources":["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"],"mappings":"AAAA,SAASA,iBAAiB,QAAQ,SAAS;AAC3C,SAASC,IAAI,QAAQ,2BAA2B;AAChD,OAAOC,WAAW,MAAM,eAAe;AAEvC,MAAMC,UAAU,GAAIC,KAAU,IAAK;EAC/B,IAAIC,MAAM,CAACD,KAAK,CAAC,CAACE,KAAK,CAAC,KAAK,CAAC,KAAK,IAAI,EAAE;IACrC,MAAM,IAAIJ,WAAW,CAAC,sCAAsC,EAAE,eAAe,EAAE;MAC3EE;IACJ,CAAC,CAAC;EACN,CAAC,MAAM,IAAI,OAAOA,KAAK,KAAK,QAAQ,EAAE;IAClC,OAAOA,KAAK;EAChB,CAAC,MAAM,IAAIA,KAAK,KAAK,IAAI,IAAIA,KAAK,KAAKG,SAAS,EAAE;IAC9C,OAAO,IAAI;EACf,CAAC,MAAM,IAAIC,KAAK,CAACJ,KAAK,CAAC,KAAK,IAAI,EAAE;IAC9B,MAAM,IAAIF,WAAW,CAAC,8BAA8B,EAAE,eAAe,EAAE;MACnEE;IACJ,CAAC,CAAC;EACN;EACA,OAAOK,UAAU,CAACL,KAAK,CAAC;AAC5B,CAAC;AAED,OAAO,MAAMM,YAAY,GAAG,IAAIV,iBAAiB,CAAC;EAC9CW,IAAI,EAAE,QAAQ;EACdC,WAAW,EAAE,sEAAsE;EACnFC,SAAS,EAAGT,KAAU,IAAK;IACvB,IAAI;MACA,OAAOD,UAAU,CAACC,KAAK,CAAC;IAC5B,CAAC,CAAC,MAAM;MACJU,OAAO,CAACC,GAAG,CAAC;QACRC,OAAO,EAAE,8BAA8B;QACvCC,IAAI,EAAE,eAAe;QACrBC,IAAI,EAAE;UACFd;QACJ;MACJ,CAAC,CAAC;MACF,OAAO,IAAI;IACf;EACJ,CAAC;EACDD,UAAU;EACVgB,YAAY,EAAEC,GAAG,IAAI;IACjB,IAAIA,GAAG,CAACC,IAAI,KAAKpB,IAAI,CAACqB,GAAG,EAAE;MACvB,OAAOC,MAAM,CAACH,GAAG,CAAChB,KAAK,CAAC;IAC5B,CAAC,MAAM,IAAIgB,GAAG,CAACC,IAAI,KAAKpB,IAAI,CAACuB,KAAK,EAAE;MAChC,OAAOf,UAAU,CAACW,GAAG,CAAChB,KAAK,CAAC;IAChC;IACA,MAAM,IAAIqB,KAAK,CAAC,gCAAgCL,GAAG,CAACC,IAAI,GAAG,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<string | null, any>;
|
|
@@ -1,65 +1,76 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
}
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
1
|
+
import { GraphQLScalarType } from "graphql";
|
|
2
|
+
const tests = [{
|
|
3
|
+
re: /^([0-9a-zA-Z_-]+)$/,
|
|
4
|
+
message: "Must be a string matching a-z, A-Z, 0-9, underscore (_) or dash(-)!"
|
|
5
|
+
}, {
|
|
6
|
+
re: /^-/,
|
|
7
|
+
message: "Must not start with a dash (-)!"
|
|
8
|
+
}, {
|
|
9
|
+
re: /-$/,
|
|
10
|
+
message: "Must not end with a dash (-)!"
|
|
11
|
+
}, {
|
|
12
|
+
re: /^_/,
|
|
13
|
+
message: "Must not start with an underscore (_)!"
|
|
14
|
+
}, {
|
|
15
|
+
re: /_$/,
|
|
16
|
+
message: "Must not end with an underscore (_)!"
|
|
17
|
+
}];
|
|
18
|
+
const isValidId = value => {
|
|
19
|
+
if (typeof value !== "string" || value.length < 1) {
|
|
20
|
+
throw new Error("Must be a string with at least 1 character!");
|
|
13
21
|
}
|
|
14
|
-
|
|
15
|
-
|
|
22
|
+
for (const test of tests) {
|
|
23
|
+
if (test.re.test(value) === null) {
|
|
24
|
+
throw new Error(test.message);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
return value;
|
|
16
28
|
};
|
|
17
|
-
|
|
18
|
-
const RefInput = new _graphql.GraphQLScalarType({
|
|
29
|
+
export const RefInputScalar = new GraphQLScalarType({
|
|
19
30
|
name: "RefInput",
|
|
20
31
|
description: "A custom input type to be used with references. Supports plain ID and `{ id: ID }` Object literal.",
|
|
32
|
+
/**
|
|
33
|
+
* We can set value as any because we are handling it.
|
|
34
|
+
*/
|
|
21
35
|
serialize: value => {
|
|
22
36
|
if (!value || value.id === null) {
|
|
23
37
|
return null;
|
|
24
38
|
}
|
|
25
|
-
|
|
26
39
|
return typeof value === "string" ? value : value.id;
|
|
27
40
|
},
|
|
41
|
+
/**
|
|
42
|
+
* We can set value as any because we are handling it.
|
|
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
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["
|
|
1
|
+
{"version":3,"names":["GraphQLScalarType","tests","re","message","isValidId","value","length","Error","test","RefInputScalar","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 /**\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"],"mappings":"AAAA,SAASA,iBAAiB,QAAQ,SAAS;AAE3C,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,IAAI;EACRC,OAAO,EAAE;AACb,CAAC,EACD;EACID,EAAE,EAAE,IAAI;EACRC,OAAO,EAAE;AACb,CAAC,EACD;EACID,EAAE,EAAE,IAAI;EACRC,OAAO,EAAE;AACb,CAAC,CACJ;AAED,MAAMC,SAAS,GAAIC,KAAU,IAAa;EACtC,IAAI,OAAOA,KAAK,KAAK,QAAQ,IAAIA,KAAK,CAACC,MAAM,GAAG,CAAC,EAAE;IAC/C,MAAM,IAAIC,KAAK,CAAC,6CAA6C,CAAC;EAClE;EACA,KAAK,MAAMC,IAAI,IAAIP,KAAK,EAAE;IACtB,IAAIO,IAAI,CAACN,EAAE,CAACM,IAAI,CAACH,KAAK,CAAC,KAAK,IAAI,EAAE;MAC9B,MAAM,IAAIE,KAAK,CAACC,IAAI,CAACL,OAAO,CAAC;IACjC;EACJ;EACA,OAAOE,KAAK;AAChB,CAAC;AAED,OAAO,MAAMI,cAAc,GAAG,IAAIT,iBAAiB,CAAC;EAChDU,IAAI,EAAE,UAA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[]}
|
|
@@ -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,56 +1,38 @@
|
|
|
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 WebinyError from "@webiny/error";
|
|
14
3
|
const re = /^([0-9]{2}):([0-9]{2})(:([0-9]{2}))?$/;
|
|
15
|
-
|
|
16
4
|
const parseTime = value => {
|
|
17
|
-
if (!value || value.match(re) === null) {
|
|
18
|
-
throw new
|
|
5
|
+
if (typeof value !== "string" || !value || value.match(re) === null) {
|
|
6
|
+
throw new WebinyError("Value does not look like time.", "TIME_VALIDATION_ERROR", {
|
|
19
7
|
value
|
|
20
8
|
});
|
|
21
9
|
}
|
|
22
|
-
|
|
23
10
|
const parsed = value.split(":").map(Number);
|
|
24
|
-
|
|
25
11
|
if (parsed.length < 2) {
|
|
26
|
-
throw new
|
|
12
|
+
throw new WebinyError(`Could not parse the value.`, "TIME_VALIDATION_ERROR", {
|
|
27
13
|
value
|
|
28
14
|
});
|
|
29
15
|
}
|
|
30
|
-
|
|
31
16
|
const [hours, minutes, seconds = 0] = parsed;
|
|
32
|
-
|
|
33
17
|
if (hours >= 24) {
|
|
34
|
-
throw new
|
|
18
|
+
throw new WebinyError(`There cannot be more than 24 hours.`, "TIME_VALIDATION_ERROR", {
|
|
35
19
|
value
|
|
36
20
|
});
|
|
37
21
|
} else if (minutes >= 60) {
|
|
38
|
-
throw new
|
|
22
|
+
throw new WebinyError(`There cannot be more than 59 minutes.`, "TIME_VALIDATION_ERROR", {
|
|
39
23
|
value
|
|
40
24
|
});
|
|
41
25
|
} else if (seconds >= 60) {
|
|
42
|
-
throw new
|
|
26
|
+
throw new WebinyError(`There cannot be more than 59 seconds.`, "TIME_VALIDATION_ERROR", {
|
|
43
27
|
value
|
|
44
28
|
});
|
|
45
29
|
}
|
|
46
|
-
|
|
47
30
|
return {
|
|
48
31
|
hours,
|
|
49
32
|
minutes,
|
|
50
33
|
seconds
|
|
51
34
|
};
|
|
52
35
|
};
|
|
53
|
-
|
|
54
36
|
const convertToTime = value => {
|
|
55
37
|
const {
|
|
56
38
|
hours,
|
|
@@ -59,8 +41,7 @@ const convertToTime = value => {
|
|
|
59
41
|
} = parseTime(value);
|
|
60
42
|
return `${String(hours).padStart(2, "0")}:${String(minutes).padStart(2, "0")}:${String(seconds).padStart(2, "0")}`;
|
|
61
43
|
};
|
|
62
|
-
|
|
63
|
-
const TimeScalar = new _graphql.GraphQLScalarType({
|
|
44
|
+
export const TimeScalar = new GraphQLScalarType({
|
|
64
45
|
name: "Time",
|
|
65
46
|
description: "A custom type to support time-only input.",
|
|
66
47
|
// sending to client
|
|
@@ -68,4 +49,5 @@ const TimeScalar = new _graphql.GraphQLScalarType({
|
|
|
68
49
|
// received from client
|
|
69
50
|
parseValue: convertToTime
|
|
70
51
|
});
|
|
71
|
-
|
|
52
|
+
|
|
53
|
+
//# sourceMappingURL=TimeScalar.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["re","parseTime","value","match","
|
|
1
|
+
{"version":3,"names":["GraphQLScalarType","WebinyError","re","parseTime","value","match","parsed","split","map","Number","length","hours","minutes","seconds","convertToTime","String","padStart","TimeScalar","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?: 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"],"mappings":"AAAA,SAASA,iBAAiB,QAAQ,SAAS;AAC3C,OAAOC,WAAW,MAAM,eAAe;AAEvC,MAAMC,EAAE,GAAG,uCAAuC;AAElD,MAAMC,SAAS,GAAIC,KAAe,IAAK;EACnC,IAAI,OAAOA,KAAK,KAAK,QAAQ,IAAI,CAACA,KAAK,IAAIA,KAAK,CAACC,KAAK,CAACH,EAAE,CAAC,KAAK,IAAI,EAAE;IACjE,MAAM,IAAID,WAAW,CAAC,gCAAgC,EAAE,uBAAuB,EAAE;MAAEG;IAAM,CAAC,CAAC;EAC/F;EACA,MAAME,MAAM,GAAGF,KAAK,CAACG,KAAK,CAAC,G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,EAAEN,aAAa;EACxB;EACAO,UAAU,EAAEP;AAChB,CAAC,CAAC","ignoreList":[]}
|
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,12 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
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";
|
|
11
|
+
|
|
12
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":[],"sources":["index.ts"],"sourcesContent":["export * from \"./AnyScalar\";\nexport * from \"./DateScalar\";\nexport * from \"./DateTimeScalar\";\nexport * from \"./DateTimeZScalar\";\nexport * from \"./JsonScalar\";\nexport * from \"./LongScalar\";\nexport * from \"./NumberScalar\";\nexport * from \"./RefInputScalar\";\nexport * from \"./TimeScalar\";\n"],"mappings":"
|
|
1
|
+
{"version":3,"names":[],"sources":["index.ts"],"sourcesContent":["export * from \"./AnyScalar.js\";\nexport * from \"./DateScalar.js\";\nexport * from \"./DateTimeScalar.js\";\nexport * from \"./DateTimeZScalar.js\";\nexport * from \"./JsonScalar.js\";\nexport * from \"./LongScalar.js\";\nexport * from \"./NumberScalar.js\";\nexport * from \"./RefInputScalar.js\";\nexport * from \"./TimeScalar.js\";\nexport * from \"./IconScalar.js\";\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA","ignoreList":[]}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { HandlerGraphQLOptions } from "./types";
|
|
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;
|
package/createGraphQLHandler.js
CHANGED
|
@@ -1,55 +1,45 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
}
|
|
8
|
-
exports.default = void 0;
|
|
9
|
-
|
|
10
|
-
var _boolean = require("boolean");
|
|
11
|
-
|
|
12
|
-
var _handler = require("@webiny/handler");
|
|
13
|
-
|
|
14
|
-
var _error = _interopRequireDefault(require("@webiny/error"));
|
|
15
|
-
|
|
16
|
-
var _createGraphQLSchema = require("./createGraphQLSchema");
|
|
17
|
-
|
|
18
|
-
var _debugPlugins = _interopRequireDefault(require("./debugPlugins"));
|
|
19
|
-
|
|
20
|
-
var _processRequestBody = _interopRequireDefault(require("./processRequestBody"));
|
|
21
|
-
|
|
1
|
+
import { boolean } from "boolean";
|
|
2
|
+
import { RoutePlugin } from "@webiny/handler";
|
|
3
|
+
import WebinyError from "@webiny/error";
|
|
4
|
+
import { createGraphQLSchema, getSchemaPlugins } from "./createGraphQLSchema.js";
|
|
5
|
+
import debugPlugins from "./debugPlugins.js";
|
|
6
|
+
import { processRequestBody } from "./processRequestBody.js";
|
|
7
|
+
import { createRequestBody } from "./createRequestBody.js";
|
|
22
8
|
const DEFAULT_CACHE_MAX_AGE = 30758400; // 1 year
|
|
23
9
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
10
|
+
const createCacheKey = context => {
|
|
11
|
+
const plugins = getSchemaPlugins(context);
|
|
12
|
+
// TODO: in the near future, we have to assign a fixed name to every
|
|
13
|
+
// TODO: GraphQLSchema plugin, to be able to create a reliable cache key.
|
|
27
14
|
|
|
28
|
-
|
|
29
|
-
|
|
15
|
+
// TODO: `getCurrentTenant` should be injected as a parameter.
|
|
16
|
+
// @ts-expect-error TODO: We should not be accessing `context` like this here.
|
|
17
|
+
const tenant = context.tenancy?.getCurrentTenant();
|
|
18
|
+
return [tenant ? `tenant:${tenant.id}` : null, plugins.length.toString()].filter(Boolean).join("#");
|
|
30
19
|
};
|
|
31
|
-
|
|
32
20
|
const formatErrorPayload = error => {
|
|
33
|
-
if (error instanceof
|
|
34
|
-
return {
|
|
21
|
+
if (error instanceof WebinyError) {
|
|
22
|
+
return JSON.stringify({
|
|
23
|
+
type: "CoreGraphQLWebinyError",
|
|
35
24
|
message: error.message,
|
|
36
25
|
code: error.code,
|
|
37
|
-
data: error.data
|
|
38
|
-
|
|
26
|
+
data: error.data,
|
|
27
|
+
stack: error.stack
|
|
28
|
+
});
|
|
39
29
|
}
|
|
40
|
-
|
|
41
|
-
|
|
30
|
+
return JSON.stringify({
|
|
31
|
+
type: "Error",
|
|
42
32
|
name: error.name,
|
|
43
33
|
message: error.message,
|
|
44
34
|
stack: error.stack
|
|
45
|
-
};
|
|
35
|
+
});
|
|
46
36
|
};
|
|
47
|
-
|
|
48
|
-
var _default = (options = {}) => {
|
|
37
|
+
export default (options = {}) => {
|
|
49
38
|
let schema = undefined;
|
|
50
|
-
|
|
51
|
-
const
|
|
52
|
-
const
|
|
39
|
+
let cacheKey = undefined;
|
|
40
|
+
const debug = boolean(options.debug);
|
|
41
|
+
const path = options?.path || "/graphql";
|
|
42
|
+
const route = new RoutePlugin(async ({
|
|
53
43
|
onPost,
|
|
54
44
|
onOptions,
|
|
55
45
|
context
|
|
@@ -57,26 +47,47 @@ var _default = (options = {}) => {
|
|
|
57
47
|
onOptions(path, async (_, reply) => {
|
|
58
48
|
return reply.status(204).headers({
|
|
59
49
|
"Cache-Control": `public, max-age=${DEFAULT_CACHE_MAX_AGE}`
|
|
60
|
-
}).send({});
|
|
50
|
+
}).send({}).hijack();
|
|
61
51
|
});
|
|
62
52
|
onPost(path, async (request, reply) => {
|
|
63
|
-
|
|
53
|
+
const contextCacheKey = createCacheKey(context);
|
|
54
|
+
if (!schema || cacheKey !== contextCacheKey) {
|
|
64
55
|
try {
|
|
65
|
-
schema =
|
|
56
|
+
schema = await createGraphQLSchema(context);
|
|
57
|
+
cacheKey = contextCacheKey;
|
|
66
58
|
} catch (ex) {
|
|
67
59
|
return reply.code(500).send(formatErrorPayload(ex));
|
|
68
60
|
}
|
|
69
61
|
}
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
62
|
+
let body;
|
|
63
|
+
try {
|
|
64
|
+
body = createRequestBody(request.body);
|
|
65
|
+
} catch (ex) {
|
|
66
|
+
console.error(`Error while creating the body request.`);
|
|
67
|
+
console.error(formatErrorPayload(ex));
|
|
68
|
+
throw ex;
|
|
69
|
+
}
|
|
70
|
+
try {
|
|
71
|
+
const result = await processRequestBody(body, schema, context);
|
|
72
|
+
/**
|
|
73
|
+
* IMPORTANT! Do not send anything if reply was already sent.
|
|
74
|
+
*/
|
|
75
|
+
if (reply.sent) {
|
|
76
|
+
console.warn("Reply already sent, cannot send the result (handler-graphql).");
|
|
77
|
+
return reply;
|
|
78
|
+
}
|
|
79
|
+
return reply.status(200).send(result);
|
|
80
|
+
} catch (ex) {
|
|
81
|
+
console.error(`Error while processing the body request.`);
|
|
82
|
+
console.error(formatErrorPayload(ex));
|
|
83
|
+
throw ex;
|
|
84
|
+
}
|
|
74
85
|
});
|
|
75
86
|
});
|
|
76
87
|
route.name = "handler.graphql.route.default";
|
|
77
|
-
return [...(debug ? (
|
|
88
|
+
return [...(debug ? debugPlugins() : []), {
|
|
78
89
|
type: "wcp-telemetry-tracker"
|
|
79
90
|
}, route];
|
|
80
91
|
};
|
|
81
92
|
|
|
82
|
-
|
|
93
|
+
//# sourceMappingURL=createGraphQLHandler.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["
|
|
1
|
+
{"version":3,"names":["boolean","RoutePlugin","WebinyError","createGraphQLSchema","getSchemaPlugins","debugPlugins","processRequestBody","createRequestBody","DEFAULT_CACHE_MAX_AGE","createCacheKey","context","plugins","tenant","tenancy","getCurrentTenant","id","length","toString","filter","Boolean","join","formatErrorPayload","error","JSON","stringify","type","message","code","data","stack","name","options","schema","undefined","cacheKey","debug","path","route","onPost","onOptions","_","reply","status","headers","send","hijack","request","contextCacheKey","ex","body","console","result","sent","warn"],"sources":["createGraphQLHandler.ts"],"sourcesContent":["import { boolean } from \"boolean\";\nimport type { GraphQLSchema } from \"graphql\";\nimport type { Context } from \"@webiny/handler\";\nimport { RoutePlugin } from \"@webiny/handler\";\nimport WebinyError from \"@webiny/error\";\nimport type { Plugin } from \"@webiny/plugins/types.js\";\nimport type { GraphQLRequestBody, HandlerGraphQLOptions } from \"./types.js\";\nimport { createGraphQLSchema, getSchemaPlugins } from \"./createGraphQLSchema.js\";\nimport debugPlugins from \"./debugPlugins.js\";\nimport { processRequestBody } from \"./processRequestBody.js\";\nimport { createRequestBody } from \"~/createRequestBody.js\";\n\nconst DEFAULT_CACHE_MAX_AGE = 30758400; // 1 year\n\nconst createCacheKey = (context: Context) => {\n const plugins = getSchemaPlugins(context);\n // TODO: in the near future, we have to assign a fixed name to every\n // TODO: GraphQLSchema plugin, to be able to create a reliable cache key.\n\n // TODO: `getCurrentTenant` should be injected as a parameter.\n // @ts-expect-error TODO: We should not be accessing `context` like this here.\n const tenant = context.tenancy?.getCurrentTenant();\n\n return [tenant ? `tenant:${tenant.id}` : null, plugins.length.toString()]\n .filter(Boolean)\n .join(\"#\");\n};\n\nconst formatErrorPayload = (error: Error): string => {\n if (error instanceof WebinyError) {\n return JSON.stringify({\n type: \"CoreGraphQLWebinyError\",\n message: error.message,\n code: error.code,\n data: error.data,\n stack: error.stack\n });\n }\n\n return JSON.stringify({\n type: \"Error\",\n name: error.name,\n message: error.message,\n stack: error.stack\n });\n};\n\nexport default (options: HandlerGraphQLOptions = {}): Plugin[] => {\n let schema: GraphQLSchema | undefined = undefined;\n let cacheKey: string | undefined = undefined;\n\n const debug = boolean(options.debug);\n\n const path = options?.path || \"/graphql\";\n\n const route = new RoutePlugin(async ({ onPost, onOptions, context }) => {\n onOptions(path, async (_, reply) => {\n return reply\n .status(204)\n .headers({\n \"Cache-Control\": `public, max-age=${DEFAULT_CACHE_MAX_AGE}`\n })\n .send({})\n .hijack();\n });\n onPost(path, async (request, reply) => {\n const contextCacheKey = createCacheKey(context as Context);\n if (!schema || cacheKey !== contextCacheKey) {\n try {\n schema = await createGraphQLSchema(context);\n cacheKey = contextCacheKey;\n } catch (ex) {\n return reply.code(500).send(formatErrorPayload(ex));\n }\n }\n let body: GraphQLRequestBody | GraphQLRequestBody[];\n try {\n body = createRequestBody(request.body);\n } catch (ex) {\n console.error(`Error while creating the body request.`);\n console.error(formatErrorPayload(ex));\n throw ex;\n }\n try {\n const result = await processRequestBody(body, schema, context);\n /**\n * IMPORTANT! Do not send anything if reply was already sent.\n */\n if (reply.sent) {\n console.warn(\"Reply already sent, cannot send the result (handler-graphql).\");\n return reply;\n }\n return reply.status(200).send(result);\n } catch (ex) {\n console.error(`Error while processing the body request.`);\n console.error(formatErrorPayload(ex));\n throw ex;\n }\n });\n });\n\n route.name = \"handler.graphql.route.default\";\n\n return [\n ...(debug ? debugPlugins() : []),\n {\n type: \"wcp-telemetry-tracker\"\n },\n route\n ];\n};\n"],"mappings":"AAAA,SAASA,OAAO,QAAQ,SAAS;AAGjC,SAASC,WAAW,QAAQ,iBAAiB;AAC7C,OAAOC,WAAW,MAAM,eAAe;AAGvC,SAASC,mBAAmB,EAAEC,gBAAgB;AAC9C,OAAOC,YAAY;AACnB,SAASC,kBAAkB;AAC3B,SAASC,iBAAiB;AAE1B,MAAMC,qBAAqB,GAAG,QAAQ,CAAC,CAAC;;AAExC,MAAMC,cAAc,GAAIC,OAAgB,IAAK;EACzC,MAAMC,OAAO,GAAGP,gBAAgB,CAACM,OAAO,CAAC;EACzC;EACA;;EAEA;EACA;EACA,MAAME,MAAM,GAAGF,OAAO,CAACG,OAAO,EAAEC,gBAAgB,CAAC,CAAC;EAElD,OAAO,CAACF,MAAM,GAAG,UAAUA,MAAM,CAACG,EAAE,EAAE,GAAG,IAAI,EAAEJ,OAAO,CAACK,MAAM,CAACC,QAAQ,CAAC,CAAC,CAAC,CACpEC,MAAM,CAACC,OAAO,CAAC,CACfC,IAAI,CAAC,GAAG,CAAC;AAClB,CAAC;AAED,MAAMC,kBAAkB,GAAIC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