@gqlbase/plugins 0.0.6 → 0.0.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/appsync/AppSyncSchemaGeneratorPlugin/AppSyncSchemaGeneratorPlugin.d.ts +31 -0
- package/dist/appsync/AppSyncSchemaGeneratorPlugin/AppSyncSchemaGeneratorPlugin.d.ts.map +1 -0
- package/dist/appsync/AppSyncSchemaGeneratorPlugin/AppSyncSchemaGeneratorPlugin.js +139 -0
- package/dist/appsync/AppSyncSchemaGeneratorPlugin/AppSyncSchemaGeneratorPlugin.js.map +1 -0
- package/dist/appsync/AppSyncSchemaGeneratorPlugin/AppSyncSchemaGeneratorPlugin.utils.d.ts +18 -0
- package/dist/appsync/AppSyncSchemaGeneratorPlugin/AppSyncSchemaGeneratorPlugin.utils.d.ts.map +1 -0
- package/dist/appsync/AppSyncSchemaGeneratorPlugin/AppSyncSchemaGeneratorPlugin.utils.js +8 -0
- package/dist/appsync/AppSyncSchemaGeneratorPlugin/AppSyncSchemaGeneratorPlugin.utils.js.map +1 -0
- package/dist/appsync/AppSyncSchemaGeneratorPlugin/index.d.ts +3 -0
- package/dist/appsync/AppSyncSchemaGeneratorPlugin/index.d.ts.map +1 -0
- package/dist/appsync/AppSyncSchemaGeneratorPlugin/index.js +2 -0
- package/dist/appsync/AppSyncSchemaGeneratorPlugin/index.js.map +1 -0
- package/dist/appsync/AppSyncUtilsPlugin/AppSyncUtilsPlugin.d.ts +33 -0
- package/dist/appsync/AppSyncUtilsPlugin/AppSyncUtilsPlugin.d.ts.map +1 -0
- package/dist/appsync/AppSyncUtilsPlugin/AppSyncUtilsPlugin.js +91 -0
- package/dist/appsync/AppSyncUtilsPlugin/AppSyncUtilsPlugin.js.map +1 -0
- package/dist/appsync/AppSyncUtilsPlugin/AppSyncUtilsPlugin.utils.d.ts +29 -0
- package/dist/appsync/AppSyncUtilsPlugin/AppSyncUtilsPlugin.utils.d.ts.map +1 -0
- package/dist/appsync/AppSyncUtilsPlugin/AppSyncUtilsPlugin.utils.js +53 -0
- package/dist/appsync/AppSyncUtilsPlugin/AppSyncUtilsPlugin.utils.js.map +1 -0
- package/dist/appsync/AppSyncUtilsPlugin/index.d.ts +3 -0
- package/dist/appsync/AppSyncUtilsPlugin/index.d.ts.map +1 -0
- package/dist/appsync/AppSyncUtilsPlugin/index.js +3 -0
- package/dist/appsync/AppSyncUtilsPlugin/index.js.map +1 -0
- package/dist/appsync/appSyncPreset.d.ts +17 -0
- package/dist/appsync/appSyncPreset.d.ts.map +1 -0
- package/dist/appsync/appSyncPreset.js +21 -0
- package/dist/appsync/appSyncPreset.js.map +1 -0
- package/dist/appsync/index.d.ts +2 -0
- package/dist/appsync/index.d.ts.map +1 -0
- package/dist/appsync/index.js +2 -0
- package/dist/appsync/index.js.map +1 -0
- package/dist/base/InterfaceUtilsPlugin/InterfaceUtilsPlugin.d.ts +55 -0
- package/dist/base/InterfaceUtilsPlugin/InterfaceUtilsPlugin.d.ts.map +1 -0
- package/dist/base/InterfaceUtilsPlugin/InterfaceUtilsPlugin.js +100 -0
- package/dist/base/InterfaceUtilsPlugin/InterfaceUtilsPlugin.js.map +1 -0
- package/dist/base/InterfaceUtilsPlugin/InterfaceUtilsPlugin.utils.d.ts +3 -0
- package/dist/base/InterfaceUtilsPlugin/InterfaceUtilsPlugin.utils.d.ts.map +1 -0
- package/dist/base/InterfaceUtilsPlugin/InterfaceUtilsPlugin.utils.js +4 -0
- package/dist/base/InterfaceUtilsPlugin/InterfaceUtilsPlugin.utils.js.map +1 -0
- package/dist/base/InterfaceUtilsPlugin/index.d.ts +3 -0
- package/dist/base/InterfaceUtilsPlugin/index.d.ts.map +1 -0
- package/dist/base/InterfaceUtilsPlugin/index.js +3 -0
- package/dist/base/InterfaceUtilsPlugin/index.js.map +1 -0
- package/dist/base/ModelTypesGeneratorPlugin/ModelTypesGeneratorPlugin.d.ts +9 -3
- package/dist/base/ModelTypesGeneratorPlugin/ModelTypesGeneratorPlugin.d.ts.map +1 -1
- package/dist/base/ModelTypesGeneratorPlugin/ModelTypesGeneratorPlugin.js +26 -16
- package/dist/base/ModelTypesGeneratorPlugin/ModelTypesGeneratorPlugin.js.map +1 -1
- package/dist/base/ModelTypesGeneratorPlugin/ModelTypesGeneratorPlugin.utils.d.ts +19 -9
- package/dist/base/ModelTypesGeneratorPlugin/ModelTypesGeneratorPlugin.utils.d.ts.map +1 -1
- package/dist/base/ModelTypesGeneratorPlugin/ModelTypesGeneratorPlugin.utils.js +11 -11
- package/dist/base/ModelTypesGeneratorPlugin/ModelTypesGeneratorPlugin.utils.js.map +1 -1
- package/dist/base/RelationsPlugin/RelationsPlugin.d.ts +13 -8
- package/dist/base/RelationsPlugin/RelationsPlugin.d.ts.map +1 -1
- package/dist/base/RelationsPlugin/RelationsPlugin.js +30 -46
- package/dist/base/RelationsPlugin/RelationsPlugin.js.map +1 -1
- package/dist/base/RelationsPlugin/RelationsPlugin.utils.d.ts +5 -3
- package/dist/base/RelationsPlugin/RelationsPlugin.utils.d.ts.map +1 -1
- package/dist/base/RelationsPlugin/RelationsPlugin.utils.js +26 -1
- package/dist/base/RelationsPlugin/RelationsPlugin.utils.js.map +1 -1
- package/dist/base/RelationsPlugin/index.d.ts +1 -1
- package/dist/base/RelationsPlugin/index.d.ts.map +1 -1
- package/dist/base/RelationsPlugin/index.js +1 -1
- package/dist/base/RelationsPlugin/index.js.map +1 -1
- package/dist/base/RfcFeaturesPlugin/RfcFeaturesPlugin.d.ts +28 -0
- package/dist/base/RfcFeaturesPlugin/RfcFeaturesPlugin.d.ts.map +1 -0
- package/dist/base/RfcFeaturesPlugin/RfcFeaturesPlugin.js +33 -0
- package/dist/base/RfcFeaturesPlugin/RfcFeaturesPlugin.js.map +1 -0
- package/dist/base/RfcFeaturesPlugin/RfcFeaturesPlugin.utils.d.ts +14 -0
- package/dist/base/RfcFeaturesPlugin/RfcFeaturesPlugin.utils.d.ts.map +1 -0
- package/dist/base/RfcFeaturesPlugin/RfcFeaturesPlugin.utils.js +39 -0
- package/dist/base/RfcFeaturesPlugin/RfcFeaturesPlugin.utils.js.map +1 -0
- package/dist/base/RfcFeaturesPlugin/index.d.ts +3 -0
- package/dist/base/RfcFeaturesPlugin/index.d.ts.map +1 -0
- package/dist/base/RfcFeaturesPlugin/index.js +3 -0
- package/dist/base/RfcFeaturesPlugin/index.js.map +1 -0
- package/dist/base/ScalarsPlugin/ScalarsPlugin.utils.d.ts +15 -0
- package/dist/base/ScalarsPlugin/ScalarsPlugin.utils.d.ts.map +1 -0
- package/dist/base/ScalarsPlugin/ScalarsPlugin.utils.js +16 -0
- package/dist/base/ScalarsPlugin/ScalarsPlugin.utils.js.map +1 -0
- package/dist/base/ScalarsPlugin/index.d.ts +1 -0
- package/dist/base/ScalarsPlugin/index.d.ts.map +1 -1
- package/dist/base/ScalarsPlugin/index.js +1 -0
- package/dist/base/ScalarsPlugin/index.js.map +1 -1
- package/dist/base/basePreset.d.ts +2 -0
- package/dist/base/basePreset.d.ts.map +1 -1
- package/dist/base/basePreset.js +6 -0
- package/dist/base/basePreset.js.map +1 -1
- package/dist/base/index.d.ts +2 -0
- package/dist/base/index.d.ts.map +1 -1
- package/dist/base/index.js +2 -0
- package/dist/base/index.js.map +1 -1
- package/dist/index.d.ts +4 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +4 -0
- package/dist/index.js.map +1 -0
- package/dist/relay/ConnectionPlugin/ConnectionPlugin.d.ts +63 -0
- package/dist/relay/ConnectionPlugin/ConnectionPlugin.d.ts.map +1 -0
- package/dist/relay/ConnectionPlugin/ConnectionPlugin.js +156 -0
- package/dist/relay/ConnectionPlugin/ConnectionPlugin.js.map +1 -0
- package/dist/relay/ConnectionPlugin/ConnectionPlugin.utils.d.ts +4 -0
- package/dist/relay/ConnectionPlugin/ConnectionPlugin.utils.d.ts.map +1 -0
- package/dist/relay/ConnectionPlugin/ConnectionPlugin.utils.js +26 -0
- package/dist/relay/ConnectionPlugin/ConnectionPlugin.utils.js.map +1 -0
- package/dist/relay/ConnectionPlugin/index.d.ts +3 -0
- package/dist/relay/ConnectionPlugin/index.d.ts.map +1 -0
- package/dist/relay/ConnectionPlugin/index.js +3 -0
- package/dist/relay/ConnectionPlugin/index.js.map +1 -0
- package/dist/relay/{NodeInterfacePlugin.d.ts → NodeInterfacePlugin/NodeInterfacePlugin.d.ts} +30 -6
- package/dist/relay/NodeInterfacePlugin/NodeInterfacePlugin.d.ts.map +1 -0
- package/dist/relay/{NodeInterfacePlugin.js → NodeInterfacePlugin/NodeInterfacePlugin.js} +37 -27
- package/dist/relay/NodeInterfacePlugin/NodeInterfacePlugin.js.map +1 -0
- package/dist/relay/NodeInterfacePlugin/index.d.ts +2 -0
- package/dist/relay/NodeInterfacePlugin/index.d.ts.map +1 -0
- package/dist/relay/NodeInterfacePlugin/index.js +2 -0
- package/dist/relay/NodeInterfacePlugin/index.js.map +1 -0
- package/dist/relay/index.d.ts +3 -2
- package/dist/relay/index.d.ts.map +1 -1
- package/dist/relay/index.js +3 -2
- package/dist/relay/index.js.map +1 -1
- package/dist/relay/relayPreset.js +2 -2
- package/dist/relay/relayPreset.js.map +1 -1
- package/package.json +7 -3
- package/dist/relay/ConnectionPlugin.d.ts +0 -46
- package/dist/relay/ConnectionPlugin.d.ts.map +0 -1
- package/dist/relay/ConnectionPlugin.js +0 -200
- package/dist/relay/ConnectionPlugin.js.map +0 -1
- package/dist/relay/NodeInterfacePlugin.d.ts.map +0 -1
- package/dist/relay/NodeInterfacePlugin.js.map +0 -1
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
import { createPluginFactory, TransformerPluginBase } from "@gqlbase/core/plugins";
|
|
2
|
+
import { InputValueNode, InterfaceNode, ObjectNode, FieldNode, NonNullTypeNode, ListTypeNode, NamedTypeNode, DirectiveNode, ArgumentNode, ValueNode, } from "@gqlbase/core/definition";
|
|
3
|
+
import { TransformerPluginExecutionError } from "@gqlbase/shared/errors";
|
|
4
|
+
import { pascalCase } from "@gqlbase/shared/format";
|
|
5
|
+
import { RfcDirective, UtilityDirective } from "../../base/index.js";
|
|
6
|
+
import { isPaginationConnection, isRelationField, isValidRelationTarget, parseFieldRelation, } from "../../base/RelationsPlugin/index.js";
|
|
7
|
+
import { isRelayConnection, isRelayEdge } from "./ConnectionPlugin.utils.js";
|
|
8
|
+
/**
|
|
9
|
+
* Transforms many relationships into Relay compaticale connections, and adds the necessary fields and arguments to support cursor based pagination.
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```graphql
|
|
13
|
+
* # Before
|
|
14
|
+
* type User {
|
|
15
|
+
* id: ID!
|
|
16
|
+
* name: String!
|
|
17
|
+
* posts: Post `@hasMany`
|
|
18
|
+
* }
|
|
19
|
+
*
|
|
20
|
+
* type Post {
|
|
21
|
+
* id: ID!
|
|
22
|
+
* title: String!
|
|
23
|
+
* }
|
|
24
|
+
*
|
|
25
|
+
* # After
|
|
26
|
+
* type User {
|
|
27
|
+
* id: ID!
|
|
28
|
+
* name: String!
|
|
29
|
+
* posts: PostConnection
|
|
30
|
+
* }
|
|
31
|
+
*
|
|
32
|
+
* type Post {
|
|
33
|
+
* id: ID!
|
|
34
|
+
* title: String!
|
|
35
|
+
* }
|
|
36
|
+
*
|
|
37
|
+
* type PostConnection {
|
|
38
|
+
* edges: [PostEdge]
|
|
39
|
+
* pageInfo: PageInfo!
|
|
40
|
+
* }
|
|
41
|
+
*
|
|
42
|
+
* type PostEdge {
|
|
43
|
+
* cursor: String
|
|
44
|
+
* node: Post
|
|
45
|
+
* }
|
|
46
|
+
*
|
|
47
|
+
* type PageInfo {
|
|
48
|
+
* hasNextPage: Boolean!
|
|
49
|
+
* hasPreviousPage: Boolean!
|
|
50
|
+
* startCursor: String
|
|
51
|
+
* endCursor: String
|
|
52
|
+
* }
|
|
53
|
+
*
|
|
54
|
+
* ```
|
|
55
|
+
*/
|
|
56
|
+
export class ConnectionPlugin extends TransformerPluginBase {
|
|
57
|
+
constructor(context) {
|
|
58
|
+
super("ConnectionPlugin", context);
|
|
59
|
+
}
|
|
60
|
+
_getConnectionTarget(object, field) {
|
|
61
|
+
const target = this.context.document.getNode(field.type.getTypeName());
|
|
62
|
+
if (!target || !isValidRelationTarget(target)) {
|
|
63
|
+
throw new TransformerPluginExecutionError(this.name, `Type ${target?.name ?? "unknwon type"} is not a valid connection target for ${object.name}.${field.name} `);
|
|
64
|
+
}
|
|
65
|
+
if (isPaginationConnection(target)) {
|
|
66
|
+
throw new TransformerPluginExecutionError(this.name, `Unexpected conflicting pagination connection type ${target.name} used as a connection target for ${object.name}.${field.name}. Make sure you set "usePaginationTypes" to "false" when using relay ConnectionPlugin.`);
|
|
67
|
+
}
|
|
68
|
+
return target;
|
|
69
|
+
}
|
|
70
|
+
_getFieldConnection(object, field) {
|
|
71
|
+
if (!isRelationField(field)) {
|
|
72
|
+
return null;
|
|
73
|
+
}
|
|
74
|
+
const target = this._getConnectionTarget(object, field);
|
|
75
|
+
return parseFieldRelation(object, field, target);
|
|
76
|
+
}
|
|
77
|
+
_setConnectionArguments(field) {
|
|
78
|
+
if (!field.hasArgument("first")) {
|
|
79
|
+
field.addArgument(InputValueNode.create("first", NamedTypeNode.create("Int")));
|
|
80
|
+
}
|
|
81
|
+
if (!field.hasArgument("after")) {
|
|
82
|
+
field.addArgument(InputValueNode.create("after", NamedTypeNode.create("String")));
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
_createConnection(field, connection) {
|
|
86
|
+
const { target } = connection;
|
|
87
|
+
const hasSemanticNonNull = this.context.document.hasNode(RfcDirective.SEMANTIC_NON_NULL);
|
|
88
|
+
if (!isRelayConnection(target)) {
|
|
89
|
+
const connectionTypeName = pascalCase(target.name, "connection");
|
|
90
|
+
const edgeTypeName = pascalCase(target.name, "edge");
|
|
91
|
+
let connectionType = this.context.document.getNode(connectionTypeName);
|
|
92
|
+
let edgeType = this.context.document.getNode(edgeTypeName);
|
|
93
|
+
if (!connectionType) {
|
|
94
|
+
connectionType = ObjectNode.create(connectionTypeName, [
|
|
95
|
+
FieldNode.create("edges", ListTypeNode.create(NamedTypeNode.create(edgeTypeName)), null, hasSemanticNonNull
|
|
96
|
+
? [
|
|
97
|
+
DirectiveNode.create(RfcDirective.SEMANTIC_NON_NULL, [
|
|
98
|
+
ArgumentNode.create("levels", ValueNode.list([ValueNode.int(0), ValueNode.int(1)])),
|
|
99
|
+
]),
|
|
100
|
+
]
|
|
101
|
+
: undefined),
|
|
102
|
+
FieldNode.create("pageInfo", NonNullTypeNode.create("PageInfo")),
|
|
103
|
+
]);
|
|
104
|
+
this.context.document.addNode(connectionType);
|
|
105
|
+
}
|
|
106
|
+
if (!edgeType) {
|
|
107
|
+
edgeType = ObjectNode.create(edgeTypeName, [
|
|
108
|
+
FieldNode.create("cursor", NamedTypeNode.create("String"), null, [
|
|
109
|
+
DirectiveNode.create(UtilityDirective.CLIENT_ONLY),
|
|
110
|
+
]),
|
|
111
|
+
FieldNode.create("node", NamedTypeNode.create(target.name), null, [
|
|
112
|
+
DirectiveNode.create(UtilityDirective.CLIENT_ONLY),
|
|
113
|
+
]),
|
|
114
|
+
]);
|
|
115
|
+
this.context.document.addNode(edgeType);
|
|
116
|
+
}
|
|
117
|
+
this._setConnectionArguments(field);
|
|
118
|
+
field.setType(NonNullTypeNode.create(connectionTypeName));
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
before() {
|
|
122
|
+
if (!this.context.document.hasNode("PageInfo")) {
|
|
123
|
+
this.context.document.addNode(ObjectNode.create("PageInfo", [
|
|
124
|
+
FieldNode.create("hasNextPage", NonNullTypeNode.create("Boolean")),
|
|
125
|
+
FieldNode.create("hasPreviousPage", NonNullTypeNode.create("Boolean")),
|
|
126
|
+
FieldNode.create("startCursor", NamedTypeNode.create("String")),
|
|
127
|
+
FieldNode.create("endCursor", NamedTypeNode.create("String")),
|
|
128
|
+
]));
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
match(definition) {
|
|
132
|
+
if (definition instanceof InterfaceNode || definition instanceof ObjectNode) {
|
|
133
|
+
if (definition.name === "Mutation")
|
|
134
|
+
return false;
|
|
135
|
+
if (isRelayConnection(definition) || isRelayEdge(definition))
|
|
136
|
+
return false;
|
|
137
|
+
if (!definition.fields?.length)
|
|
138
|
+
return false;
|
|
139
|
+
return true;
|
|
140
|
+
}
|
|
141
|
+
return false;
|
|
142
|
+
}
|
|
143
|
+
execute(definition) {
|
|
144
|
+
for (const field of definition.fields ?? []) {
|
|
145
|
+
const connection = this._getFieldConnection(definition, field);
|
|
146
|
+
if (!connection) {
|
|
147
|
+
continue;
|
|
148
|
+
}
|
|
149
|
+
if (connection.type === "oneToMany") {
|
|
150
|
+
this._createConnection(field, connection);
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
export const connectionPlugin = createPluginFactory(ConnectionPlugin);
|
|
156
|
+
//# sourceMappingURL=ConnectionPlugin.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ConnectionPlugin.js","sourceRoot":"","sources":["../../../src/relay/ConnectionPlugin/ConnectionPlugin.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,mBAAmB,EAAE,qBAAqB,EAAE,MAAM,uBAAuB,CAAC;AACnF,OAAO,EAEL,cAAc,EACd,aAAa,EACb,UAAU,EACV,SAAS,EACT,eAAe,EACf,YAAY,EACZ,aAAa,EACb,aAAa,EACb,YAAY,EACZ,SAAS,GACV,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAE,+BAA+B,EAAE,MAAM,wBAAwB,CAAC;AACzE,OAAO,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AACpD,OAAO,EAAE,YAAY,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AACrE,OAAO,EAEL,sBAAsB,EACtB,eAAe,EACf,qBAAqB,EACrB,kBAAkB,GACnB,MAAM,qCAAqC,CAAC;AAC7C,OAAO,EAAE,iBAAiB,EAAE,WAAW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,CAAC,iBAAiB,CAAC,KAAK,EAAE,UAAU,CAAC,CAAC;YAC5C,CAAC;QACH,CAAC;IACH,CAAC;CACF;AAED,MAAM,CAAC,MAAM,gBAAgB,GAAG,mBAAmB,CAAC,gBAAgB,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ConnectionPlugin.utils.d.ts","sourceRoot":"","sources":["../../../src/relay/ConnectionPlugin/ConnectionPlugin.utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAc,MAAM,0BAA0B,CAAC;AAEtE,eAAO,MAAM,iBAAiB,GAAI,MAAM,cAAc,KAAG,OASxD,CAAC;AAEF,eAAO,MAAM,WAAW,GAAI,MAAM,cAAc,KAAG,OASlD,CAAC"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { ObjectNode } from "@gqlbase/core/definition";
|
|
2
|
+
export const isRelayConnection = (node) => {
|
|
3
|
+
if (node instanceof ObjectNode) {
|
|
4
|
+
if (!node.name.endsWith("Connection"))
|
|
5
|
+
return false;
|
|
6
|
+
if (!node.fields || node.fields.length < 2)
|
|
7
|
+
return false;
|
|
8
|
+
if (!node.hasField("edges") || !node.hasField("pageInfo"))
|
|
9
|
+
return false;
|
|
10
|
+
return true;
|
|
11
|
+
}
|
|
12
|
+
return false;
|
|
13
|
+
};
|
|
14
|
+
export const isRelayEdge = (node) => {
|
|
15
|
+
if (node instanceof ObjectNode) {
|
|
16
|
+
if (!node.name.endsWith("Edge"))
|
|
17
|
+
return false;
|
|
18
|
+
if (!node.fields || node.fields.length < 2)
|
|
19
|
+
return false;
|
|
20
|
+
if (!node.hasField("node") || !node.hasField("cursor"))
|
|
21
|
+
return false;
|
|
22
|
+
return true;
|
|
23
|
+
}
|
|
24
|
+
return false;
|
|
25
|
+
};
|
|
26
|
+
//# sourceMappingURL=ConnectionPlugin.utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ConnectionPlugin.utils.js","sourceRoot":"","sources":["../../../src/relay/ConnectionPlugin/ConnectionPlugin.utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAkB,UAAU,EAAE,MAAM,0BAA0B,CAAC;AAEtE,MAAM,CAAC,MAAM,iBAAiB,GAAG,CAAC,IAAoB,EAAW,EAAE;IACjE,IAAI,IAAI,YAAY,UAAU,EAAE,CAAC;QAC/B,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,YAAY,CAAC;YAAE,OAAO,KAAK,CAAC;QACpD,IAAI,CAAC,IAAI,CAAC,MAAM,IAAI,IAAI,CAAC,MAAM,CAAC,MAAM,GAAG,CAAC;YAAE,OAAO,KAAK,CAAC;QACzD,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,UAAU,CAAC;YAAE,OAAO,KAAK,CAAC;QACxE,OAAO,IAAI,CAAC;IACd,CAAC;IAED,OAAO,KAAK,CAAC;AACf,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,WAAW,GAAG,CAAC,IAAoB,EAAW,EAAE;IAC3D,IAAI,IAAI,YAAY,UAAU,EAAE,CAAC;QAC/B,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC;YAAE,OAAO,KAAK,CAAC;QAC9C,IAAI,CAAC,IAAI,CAAC,MAAM,IAAI,IAAI,CAAC,MAAM,CAAC,MAAM,GAAG,CAAC;YAAE,OAAO,KAAK,CAAC;QACzD,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,QAAQ,CAAC;YAAE,OAAO,KAAK,CAAC;QACrE,OAAO,IAAI,CAAC;IACd,CAAC;IAED,OAAO,KAAK,CAAC;AACf,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/relay/ConnectionPlugin/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AAC3E,OAAO,EAAE,iBAAiB,EAAE,WAAW,EAAE,MAAM,6BAA6B,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/relay/ConnectionPlugin/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AAC3E,OAAO,EAAE,iBAAiB,EAAE,WAAW,EAAE,MAAM,6BAA6B,CAAC"}
|
package/dist/relay/{NodeInterfacePlugin.d.ts → NodeInterfacePlugin/NodeInterfacePlugin.d.ts}
RENAMED
|
@@ -1,16 +1,40 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { TransformerPluginBase } from "@gqlbase/core/plugins";
|
|
2
2
|
import type { ITransformerContext } from "@gqlbase/core/context";
|
|
3
3
|
import { DefinitionNode, ObjectNode } from "@gqlbase/core/definition";
|
|
4
4
|
/**
|
|
5
5
|
* Adds a `Node` interface with an `id: ID!` field to the schema and ensures that all types that implement the `Node` interface also have the `id: ID!` field.
|
|
6
6
|
*
|
|
7
|
-
* @
|
|
7
|
+
* @definition
|
|
8
|
+
* ```graphql
|
|
9
|
+
* interface Node {
|
|
10
|
+
* id: ID!
|
|
11
|
+
* }
|
|
12
|
+
* ```
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* ```graphql
|
|
16
|
+
* # Before
|
|
17
|
+
* type User `@model` {
|
|
18
|
+
* name: String!
|
|
19
|
+
* }
|
|
20
|
+
*
|
|
21
|
+
* # After
|
|
22
|
+
* interface Node {
|
|
23
|
+
* id: ID!
|
|
24
|
+
* }
|
|
25
|
+
*
|
|
26
|
+
* type User implements Node `@model` {
|
|
27
|
+
* id: ID!
|
|
28
|
+
* name: String!
|
|
29
|
+
* }
|
|
30
|
+
*
|
|
31
|
+
* type Query {
|
|
32
|
+
* node(id: ID!): Node @hasOne
|
|
33
|
+
* }
|
|
34
|
+
* ```
|
|
8
35
|
*/
|
|
9
|
-
export declare class NodeInterfacePlugin
|
|
10
|
-
readonly name = "NodeInterfacePlugin";
|
|
11
|
-
readonly context: ITransformerContext;
|
|
36
|
+
export declare class NodeInterfacePlugin extends TransformerPluginBase {
|
|
12
37
|
constructor(context: ITransformerContext);
|
|
13
|
-
init(): void;
|
|
14
38
|
match(definition: DefinitionNode): boolean;
|
|
15
39
|
before(): void;
|
|
16
40
|
execute(definition: ObjectNode): void;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"NodeInterfacePlugin.d.ts","sourceRoot":"","sources":["../../../src/relay/NodeInterfacePlugin/NodeInterfacePlugin.ts"],"names":[],"mappings":"AAAA,OAAO,EAAuB,qBAAqB,EAAE,MAAM,uBAAuB,CAAC;AACnF,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AACjE,OAAO,EACL,cAAc,EAOd,UAAU,EACX,MAAM,0BAA0B,CAAC;AAIlC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AAEH,qBAAa,mBAAoB,SAAQ,qBAAqB;gBAChD,OAAO,EAAE,mBAAmB;IAIxC,KAAK,CAAC,UAAU,EAAE,cAAc,GAAG,OAAO;IAU1C,MAAM,IAAI,IAAI;IAyBd,OAAO,CAAC,UAAU,EAAE,UAAU,GAAG,IAAI;IA4B9B,KAAK,IAAI,IAAI;CAUrB;AAED,eAAO,MAAM,mBAAmB,uEAA2C,CAAC"}
|
|
@@ -1,20 +1,42 @@
|
|
|
1
|
-
import { createPluginFactory } from "@gqlbase/core/plugins";
|
|
1
|
+
import { createPluginFactory, TransformerPluginBase } from "@gqlbase/core/plugins";
|
|
2
2
|
import { DirectiveNode, FieldNode, InputValueNode, InterfaceNode, NamedTypeNode, NonNullTypeNode, ObjectNode, } from "@gqlbase/core/definition";
|
|
3
3
|
import { InvalidDefinitionError, TransformerPluginExecutionError } from "@gqlbase/shared/errors";
|
|
4
|
-
import { isModel } from "
|
|
4
|
+
import { isModel } from "../../base/index.js";
|
|
5
5
|
/**
|
|
6
6
|
* Adds a `Node` interface with an `id: ID!` field to the schema and ensures that all types that implement the `Node` interface also have the `id: ID!` field.
|
|
7
7
|
*
|
|
8
|
-
* @
|
|
8
|
+
* @definition
|
|
9
|
+
* ```graphql
|
|
10
|
+
* interface Node {
|
|
11
|
+
* id: ID!
|
|
12
|
+
* }
|
|
13
|
+
* ```
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* ```graphql
|
|
17
|
+
* # Before
|
|
18
|
+
* type User `@model` {
|
|
19
|
+
* name: String!
|
|
20
|
+
* }
|
|
21
|
+
*
|
|
22
|
+
* # After
|
|
23
|
+
* interface Node {
|
|
24
|
+
* id: ID!
|
|
25
|
+
* }
|
|
26
|
+
*
|
|
27
|
+
* type User implements Node `@model` {
|
|
28
|
+
* id: ID!
|
|
29
|
+
* name: String!
|
|
30
|
+
* }
|
|
31
|
+
*
|
|
32
|
+
* type Query {
|
|
33
|
+
* node(id: ID!): Node @hasOne
|
|
34
|
+
* }
|
|
35
|
+
* ```
|
|
9
36
|
*/
|
|
10
|
-
export class NodeInterfacePlugin {
|
|
11
|
-
name = "NodeInterfacePlugin";
|
|
12
|
-
context;
|
|
37
|
+
export class NodeInterfacePlugin extends TransformerPluginBase {
|
|
13
38
|
constructor(context) {
|
|
14
|
-
|
|
15
|
-
}
|
|
16
|
-
init() {
|
|
17
|
-
// No initialization needed
|
|
39
|
+
super("NodeInterfacePlugin", context);
|
|
18
40
|
}
|
|
19
41
|
match(definition) {
|
|
20
42
|
if (definition instanceof ObjectNode) {
|
|
@@ -25,15 +47,9 @@ export class NodeInterfacePlugin {
|
|
|
25
47
|
return false;
|
|
26
48
|
}
|
|
27
49
|
before() {
|
|
28
|
-
|
|
29
|
-
if (node) {
|
|
30
|
-
|
|
31
|
-
throw new InvalidDefinitionError("Node type must be an interface");
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
else {
|
|
35
|
-
node = InterfaceNode.create("Node", []);
|
|
36
|
-
this.context.document.addNode(node);
|
|
50
|
+
const node = this.context.document.getOrCreateNode("Node", InterfaceNode.create("Node", []));
|
|
51
|
+
if (!(node instanceof InterfaceNode)) {
|
|
52
|
+
throw new InvalidDefinitionError("Node type must be an interface");
|
|
37
53
|
}
|
|
38
54
|
if (!node.hasField("id")) {
|
|
39
55
|
node.addField(FieldNode.create("id", NonNullTypeNode.create(NamedTypeNode.create("ID"))));
|
|
@@ -44,10 +60,7 @@ export class NodeInterfacePlugin {
|
|
|
44
60
|
}
|
|
45
61
|
}
|
|
46
62
|
execute(definition) {
|
|
47
|
-
const nodeInterface = this.context.document.
|
|
48
|
-
if (!nodeInterface) {
|
|
49
|
-
throw new TransformerPluginExecutionError(this.name, "Node Interface not found. Make sure you run `plugin.init()` before executing.");
|
|
50
|
-
}
|
|
63
|
+
const nodeInterface = this.context.document.getNodeOrThrow("Node");
|
|
51
64
|
// In definition has directive `@model` it should also implement `Node` interface
|
|
52
65
|
if (isModel(definition) && !definition.hasInterface("Node")) {
|
|
53
66
|
definition.addInterface(nodeInterface.name);
|
|
@@ -68,10 +81,7 @@ export class NodeInterfacePlugin {
|
|
|
68
81
|
}
|
|
69
82
|
}
|
|
70
83
|
after() {
|
|
71
|
-
const iface = this.context.document.
|
|
72
|
-
if (!iface || !(iface instanceof InterfaceNode)) {
|
|
73
|
-
throw new TransformerPluginExecutionError(this.name, "Node Interface not found. Make sure you run `plugin.init()` before executing.");
|
|
74
|
-
}
|
|
84
|
+
const iface = this.context.document.getNodeOrThrow("Node");
|
|
75
85
|
// Node interface should have only 1 field, the `id`
|
|
76
86
|
for (const field of iface.fields ?? []) {
|
|
77
87
|
if (field.name !== "id") {
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"NodeInterfacePlugin.js","sourceRoot":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;gBACnD,MAAM,aAAa,GAAG,UAAU,CAAC,QAAQ,CAAC,KAAK,CAAC,IAAI,CAAC,EAAE,IAAI,CAAC,WAAW,EAAE,CAAC;gBAE1E,IAAI,iBAAiB,KAAK,aAAa,EAAE,CAAC;oBACxC,MAAM,IAAI,+BAA+B,CACvC,IAAI,CAAC,IAAI,EACT,SAAS,KAAK,CAAC,IAAI,OAAO,UAAU,CAAC,IAAI,yEAAyE,iBAAiB,SAAS,aAAa,EAAE,CAC5J,CAAC;gBACJ,CAAC;YACH,CAAC;QACH,CAAC;IACH,CAAC;IAEM,KAAK;QACV,MAAM,KAAK,GAAG,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,cAAc,CAAC,MAAM,CAAkB,CAAC;QAE5E,oDAAoD;QACpD,KAAK,MAAM,KAAK,IAAI,KAAK,CAAC,MAAM,IAAI,EAAE,EAAE,CAAC;YACvC,IAAI,KAAK,CAAC,IAAI,KAAK,IAAI,EAAE,CAAC;gBACxB,KAAK,CAAC,WAAW,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;YAChC,CAAC;QACH,CAAC;IACH,CAAC;CACF;AAED,MAAM,CAAC,MAAM,mBAAmB,GAAG,mBAAmB,CAAC,mBAAmB,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/relay/NodeInterfacePlugin/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/relay/NodeInterfacePlugin/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC"}
|
package/dist/relay/index.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
-
export {
|
|
2
|
-
export {
|
|
1
|
+
export { NodeInterfacePlugin, nodeInterfacePlugin } from "./NodeInterfacePlugin/index.js";
|
|
2
|
+
export { ConnectionPlugin, connectionPlugin, isRelayConnection, isRelayEdge, } from "./ConnectionPlugin/index.js";
|
|
3
|
+
export { relayPreset } from "./relayPreset.js";
|
|
3
4
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/relay/index.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/relay/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,mBAAmB,EAAE,MAAM,gCAAgC,CAAC;AAC1F,OAAO,EACL,gBAAgB,EAChB,gBAAgB,EAChB,iBAAiB,EACjB,WAAW,GACZ,MAAM,6BAA6B,CAAC;AACrC,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC"}
|
package/dist/relay/index.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
-
export {
|
|
2
|
-
export {
|
|
1
|
+
export { NodeInterfacePlugin, nodeInterfacePlugin } from "./NodeInterfacePlugin/index.js";
|
|
2
|
+
export { ConnectionPlugin, connectionPlugin, isRelayConnection, isRelayEdge, } from "./ConnectionPlugin/index.js";
|
|
3
|
+
export { relayPreset } from "./relayPreset.js";
|
|
3
4
|
//# sourceMappingURL=index.js.map
|
package/dist/relay/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/relay/index.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/relay/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,mBAAmB,EAAE,MAAM,gCAAgC,CAAC;AAC1F,OAAO,EACL,gBAAgB,EAChB,gBAAgB,EAChB,iBAAiB,EACjB,WAAW,GACZ,MAAM,6BAA6B,CAAC;AACrC,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { connectionPlugin } from "./ConnectionPlugin.js";
|
|
2
|
-
import { nodeInterfacePlugin } from "./NodeInterfacePlugin.js";
|
|
1
|
+
import { connectionPlugin } from "./ConnectionPlugin/index.js";
|
|
2
|
+
import { nodeInterfacePlugin } from "./NodeInterfacePlugin/index.js";
|
|
3
3
|
/**
|
|
4
4
|
* A preset that includes all the Relay plugins
|
|
5
5
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"relayPreset.js","sourceRoot":"","sources":["../../src/relay/relayPreset.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"relayPreset.js","sourceRoot":"","sources":["../../src/relay/relayPreset.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,6BAA6B,CAAC;AAC/D,OAAO,EAAE,mBAAmB,EAAE,MAAM,gCAAgC,CAAC;AAErE;;;;;;;;GAQG;AAEH,MAAM,UAAU,WAAW;IACzB,OAAO,CAAC,mBAAmB,EAAE,EAAE,gBAAgB,EAAE,CAAC,CAAC;AACrD,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gqlbase/plugins",
|
|
3
3
|
"description": "Collection of plugins and presets for gqlbase, providing common transformations and utilities that can be used in GraphQL schema transformation processes.",
|
|
4
|
-
"version": "0.0.
|
|
4
|
+
"version": "0.0.8",
|
|
5
5
|
"sideEffects": false,
|
|
6
6
|
"type": "module",
|
|
7
7
|
"license": "MIT",
|
|
@@ -30,6 +30,10 @@
|
|
|
30
30
|
"main": "dist/index.js",
|
|
31
31
|
"types": "dist/index.d.ts",
|
|
32
32
|
"exports": {
|
|
33
|
+
".": {
|
|
34
|
+
"default": "./dist/index.js",
|
|
35
|
+
"types": "./dist/index.d.ts"
|
|
36
|
+
},
|
|
33
37
|
"./*": {
|
|
34
38
|
"default": "./dist/*/index.js",
|
|
35
39
|
"types": "./dist/*/index.d.ts"
|
|
@@ -42,8 +46,8 @@
|
|
|
42
46
|
"test": "vitest run"
|
|
43
47
|
},
|
|
44
48
|
"dependencies": {
|
|
45
|
-
"@gqlbase/core": "^0.0.
|
|
46
|
-
"@gqlbase/shared": "^0.0.
|
|
49
|
+
"@gqlbase/core": "^0.0.8",
|
|
50
|
+
"@gqlbase/shared": "^0.0.8"
|
|
47
51
|
},
|
|
48
52
|
"peerDependencies": {
|
|
49
53
|
"graphql": ">=16"
|
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
import { ITransformerContext } from "@gqlbase/core/context";
|
|
2
|
-
import { ITransformerPlugin } from "@gqlbase/core/plugins";
|
|
3
|
-
import { DefinitionNode, InterfaceNode, ObjectNode, UnionNode } from "@gqlbase/core/definition";
|
|
4
|
-
export declare const ConnectionDirective: {
|
|
5
|
-
readonly HAS_ONE: "hasOne";
|
|
6
|
-
readonly HAS_MANY: "hasMany";
|
|
7
|
-
};
|
|
8
|
-
export declare const RelationType: {
|
|
9
|
-
readonly ONE_TO_ONE: "oneToOne";
|
|
10
|
-
readonly ONE_TO_MANY: "oneToMany";
|
|
11
|
-
readonly MANY_TO_MANY: "manyToMany";
|
|
12
|
-
};
|
|
13
|
-
type Relation = (typeof RelationType)[keyof typeof RelationType];
|
|
14
|
-
export declare const isConnectionNode: (node: DefinitionNode) => boolean;
|
|
15
|
-
export declare const isEdgeNode: (node: DefinitionNode) => boolean;
|
|
16
|
-
export interface DirectiveArgs {
|
|
17
|
-
relation?: Relation;
|
|
18
|
-
key?: string;
|
|
19
|
-
}
|
|
20
|
-
export interface FieldConnection {
|
|
21
|
-
relation: Relation;
|
|
22
|
-
target: ObjectNode | InterfaceNode | UnionNode;
|
|
23
|
-
key?: string;
|
|
24
|
-
}
|
|
25
|
-
export declare class ConnectionPlugin implements ITransformerPlugin {
|
|
26
|
-
readonly name = "ConnectionPlugin";
|
|
27
|
-
readonly context: ITransformerContext;
|
|
28
|
-
constructor(context: ITransformerContext);
|
|
29
|
-
private _getConnectionTarget;
|
|
30
|
-
private _getFieldConnection;
|
|
31
|
-
private _setConnectionArguments;
|
|
32
|
-
/**
|
|
33
|
-
* For one-to-many connections user should be able to add the connection key via mutations.
|
|
34
|
-
* By default the connection key is _writeOnly_ meaning we only add it to the mutation inputs.
|
|
35
|
-
*/
|
|
36
|
-
private _setConnectionKey;
|
|
37
|
-
private _createConnectionTypes;
|
|
38
|
-
private _createEdgesConnection;
|
|
39
|
-
init(): void;
|
|
40
|
-
match(definition: DefinitionNode): boolean;
|
|
41
|
-
normalize(definition: ObjectNode | InterfaceNode): void;
|
|
42
|
-
execute(definition: ObjectNode | InterfaceNode): void;
|
|
43
|
-
}
|
|
44
|
-
export declare const connectionPlugin: (options?: unknown) => import("@gqlbase/core/plugins").IPluginFactory;
|
|
45
|
-
export {};
|
|
46
|
-
//# sourceMappingURL=ConnectionPlugin.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"ConnectionPlugin.d.ts","sourceRoot":"","sources":["../../src/relay/ConnectionPlugin.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAC5D,OAAO,EAAuB,kBAAkB,EAAE,MAAM,uBAAuB,CAAC;AAChF,OAAO,EACL,cAAc,EAEd,aAAa,EACb,UAAU,EAEV,SAAS,EAKV,MAAM,0BAA0B,CAAC;AAMlC,eAAO,MAAM,mBAAmB;;;CAGtB,CAAC;AAEX,eAAO,MAAM,YAAY;;;;CAIf,CAAC;AAEX,KAAK,QAAQ,GAAG,CAAC,OAAO,YAAY,CAAC,CAAC,MAAM,OAAO,YAAY,CAAC,CAAC;AAEjE,eAAO,MAAM,gBAAgB,GAAI,MAAM,cAAc,KAAG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