@auto-engineer/frontend-generator-react-graphql 0.8.13 → 0.9.0
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/CHANGELOG.md +21 -0
- package/dist/src/scaffold-gql-operations.d.ts +7 -0
- package/dist/src/scaffold-gql-operations.d.ts.map +1 -1
- package/dist/src/scaffold-gql-operations.js +123 -14
- package/dist/src/scaffold-gql-operations.js.map +1 -1
- package/dist/src/scaffold-gql-operations.specs.d.ts +2 -0
- package/dist/src/scaffold-gql-operations.specs.d.ts.map +1 -0
- package/dist/src/scaffold-gql-operations.specs.js +195 -0
- package/dist/src/scaffold-gql-operations.specs.js.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +4 -4
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,26 @@
|
|
|
1
1
|
# @auto-engineer/frontend-react-graphql-generator
|
|
2
2
|
|
|
3
|
+
## 0.9.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- add a new experience slice type
|
|
8
|
+
|
|
9
|
+
### Patch Changes
|
|
10
|
+
|
|
11
|
+
- Updated dependencies
|
|
12
|
+
- @auto-engineer/ai-gateway@0.9.0
|
|
13
|
+
- @auto-engineer/message-bus@0.9.0
|
|
14
|
+
|
|
15
|
+
## 0.8.14
|
|
16
|
+
|
|
17
|
+
### Patch Changes
|
|
18
|
+
|
|
19
|
+
- Update flow to not require slice
|
|
20
|
+
- Updated dependencies
|
|
21
|
+
- @auto-engineer/ai-gateway@0.8.14
|
|
22
|
+
- @auto-engineer/message-bus@0.8.14
|
|
23
|
+
|
|
3
24
|
## 0.8.13
|
|
4
25
|
|
|
5
26
|
### Patch Changes
|
|
@@ -1,3 +1,10 @@
|
|
|
1
1
|
import { IAScheme } from './types';
|
|
2
|
+
interface GqlOperation {
|
|
3
|
+
operationType: 'query' | 'mutation';
|
|
4
|
+
operationName: string;
|
|
5
|
+
raw: string;
|
|
6
|
+
}
|
|
7
|
+
export declare function mergeGraphQLQueries(operations: GqlOperation[]): GqlOperation[];
|
|
2
8
|
export declare function writeGqlOperationsToFolder(iaScheme: IAScheme, outputDir: string): void;
|
|
9
|
+
export {};
|
|
3
10
|
//# sourceMappingURL=scaffold-gql-operations.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"scaffold-gql-operations.d.ts","sourceRoot":"","sources":["../../src/scaffold-gql-operations.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"scaffold-gql-operations.d.ts","sourceRoot":"","sources":["../../src/scaffold-gql-operations.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAEnC,UAAU,YAAY;IACpB,aAAa,EAAE,OAAO,GAAG,UAAU,CAAC;IACpC,aAAa,EAAE,MAAM,CAAC;IACtB,GAAG,EAAE,MAAM,CAAC;CACb;AAyID,wBAAgB,mBAAmB,CAAC,UAAU,EAAE,YAAY,EAAE,GAAG,YAAY,EAAE,CA8D9E;AAWD,wBAAgB,0BAA0B,CAAC,QAAQ,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,QAiB/E"}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import * as fs from 'fs';
|
|
2
2
|
import * as path from 'path';
|
|
3
|
+
import { parse, print, Kind } from 'graphql';
|
|
3
4
|
function extractOperationName(gql) {
|
|
4
5
|
const match = gql.match(/(query|mutation)\s+(\w+)/);
|
|
5
6
|
return match ? match[2] : 'UnknownOperation';
|
|
@@ -16,10 +17,10 @@ function isValidDataRequirement(req) {
|
|
|
16
17
|
typeof req.details.gql === 'string');
|
|
17
18
|
}
|
|
18
19
|
function processDataRequirements(record, operations) {
|
|
19
|
-
const
|
|
20
|
-
if (!Array.isArray(
|
|
20
|
+
const dataRequirements = record['data_requirements'];
|
|
21
|
+
if (!Array.isArray(dataRequirements))
|
|
21
22
|
return;
|
|
22
|
-
for (const req of
|
|
23
|
+
for (const req of dataRequirements) {
|
|
23
24
|
if (isValidDataRequirement(req)) {
|
|
24
25
|
operations.push({
|
|
25
26
|
operationType: req.type,
|
|
@@ -47,6 +48,121 @@ function extractGqlOperationsFromIAScheme(schema) {
|
|
|
47
48
|
walk(schema, operations);
|
|
48
49
|
return operations;
|
|
49
50
|
}
|
|
51
|
+
function getFieldKey(selection) {
|
|
52
|
+
return selection.alias?.value ?? selection.name.value;
|
|
53
|
+
}
|
|
54
|
+
function processFieldSelection(fieldMap, selection) {
|
|
55
|
+
const key = getFieldKey(selection);
|
|
56
|
+
const existing = fieldMap.get(key);
|
|
57
|
+
if (existing !== undefined && existing.selectionSet !== undefined && selection.selectionSet !== undefined) {
|
|
58
|
+
// Merge nested selection sets
|
|
59
|
+
const mergedSelectionSet = mergeSelectionSets(existing.selectionSet, selection.selectionSet);
|
|
60
|
+
fieldMap.set(key, {
|
|
61
|
+
...existing,
|
|
62
|
+
selectionSet: mergedSelectionSet,
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
else if (existing === undefined) {
|
|
66
|
+
// Add new field
|
|
67
|
+
fieldMap.set(key, selection);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
function mergeSelectionSets(selectionSet1, selectionSet2) {
|
|
71
|
+
const fieldMap = new Map();
|
|
72
|
+
// Process first selection set
|
|
73
|
+
for (const selection of selectionSet1.selections) {
|
|
74
|
+
if (selection.kind === 'Field') {
|
|
75
|
+
const key = getFieldKey(selection);
|
|
76
|
+
fieldMap.set(key, selection);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
// Process second selection set, merging nested selections
|
|
80
|
+
for (const selection of selectionSet2.selections) {
|
|
81
|
+
if (selection.kind === 'Field') {
|
|
82
|
+
processFieldSelection(fieldMap, selection);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
return {
|
|
86
|
+
kind: Kind.SELECTION_SET,
|
|
87
|
+
selections: Array.from(fieldMap.values()),
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
function mergeOperations(operation1, operation2) {
|
|
91
|
+
const selectionSet1 = operation1.selectionSet;
|
|
92
|
+
const selectionSet2 = operation2.selectionSet;
|
|
93
|
+
if (selectionSet1 === undefined || selectionSet2 === undefined) {
|
|
94
|
+
throw new Error('Operations must have selection sets');
|
|
95
|
+
}
|
|
96
|
+
const mergedSelectionSet = mergeSelectionSets(selectionSet1, selectionSet2);
|
|
97
|
+
return {
|
|
98
|
+
...operation1,
|
|
99
|
+
selectionSet: mergedSelectionSet,
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
function getOperationSignature(operation) {
|
|
103
|
+
const name = operation.name?.value ?? 'Anonymous';
|
|
104
|
+
const variables = operation.variableDefinitions
|
|
105
|
+
? operation.variableDefinitions.map((v) => `${v.variable.name.value}: ${print(v.type)}`).join(', ')
|
|
106
|
+
: '';
|
|
107
|
+
return `${operation.operation}:${name}:(${variables})`;
|
|
108
|
+
}
|
|
109
|
+
export function mergeGraphQLQueries(operations) {
|
|
110
|
+
const operationGroups = new Map();
|
|
111
|
+
// Group operations by signature (operation type, name, and variables)
|
|
112
|
+
for (const op of operations) {
|
|
113
|
+
try {
|
|
114
|
+
const document = parse(op.raw);
|
|
115
|
+
const operation = document.definitions[0];
|
|
116
|
+
const signature = getOperationSignature(operation);
|
|
117
|
+
if (!operationGroups.has(signature)) {
|
|
118
|
+
operationGroups.set(signature, []);
|
|
119
|
+
}
|
|
120
|
+
operationGroups.get(signature).push(op);
|
|
121
|
+
}
|
|
122
|
+
catch {
|
|
123
|
+
// If parsing fails, keep the original operation
|
|
124
|
+
const fallbackSignature = `${op.operationType}:${op.operationName}:fallback:${Math.random()}`;
|
|
125
|
+
operationGroups.set(fallbackSignature, [op]);
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
const mergedOperations = [];
|
|
129
|
+
// Merge operations within each group
|
|
130
|
+
for (const [, group] of operationGroups) {
|
|
131
|
+
if (group.length === 1) {
|
|
132
|
+
mergedOperations.push(group[0]);
|
|
133
|
+
}
|
|
134
|
+
else {
|
|
135
|
+
try {
|
|
136
|
+
// Parse all operations in the group
|
|
137
|
+
const parsedOperations = group.map((op) => {
|
|
138
|
+
const document = parse(op.raw);
|
|
139
|
+
return document.definitions[0];
|
|
140
|
+
});
|
|
141
|
+
// Merge all operations in the group
|
|
142
|
+
let mergedOperation = parsedOperations[0];
|
|
143
|
+
for (let i = 1; i < parsedOperations.length; i++) {
|
|
144
|
+
mergedOperation = mergeOperations(mergedOperation, parsedOperations[i]);
|
|
145
|
+
}
|
|
146
|
+
// Create the merged document and print it
|
|
147
|
+
const mergedDocument = {
|
|
148
|
+
kind: Kind.DOCUMENT,
|
|
149
|
+
definitions: [mergedOperation],
|
|
150
|
+
};
|
|
151
|
+
const mergedRaw = print(mergedDocument);
|
|
152
|
+
mergedOperations.push({
|
|
153
|
+
operationType: group[0].operationType,
|
|
154
|
+
operationName: group[0].operationName,
|
|
155
|
+
raw: mergedRaw,
|
|
156
|
+
});
|
|
157
|
+
}
|
|
158
|
+
catch {
|
|
159
|
+
// If merging fails, keep the first operation from the group
|
|
160
|
+
mergedOperations.push(group[0]);
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
return mergedOperations;
|
|
165
|
+
}
|
|
50
166
|
function buildFileContent(operations) {
|
|
51
167
|
const header = `import { graphql } from '../gql';\n`;
|
|
52
168
|
const entries = operations.map((op) => {
|
|
@@ -56,17 +172,10 @@ function buildFileContent(operations) {
|
|
|
56
172
|
}
|
|
57
173
|
export function writeGqlOperationsToFolder(iaScheme, outputDir) {
|
|
58
174
|
const allOperations = extractGqlOperationsFromIAScheme(iaScheme);
|
|
59
|
-
|
|
60
|
-
const
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
if (!uniqueSet.has(key)) {
|
|
64
|
-
uniqueOperations.push(op);
|
|
65
|
-
uniqueSet.add(key);
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
const queries = uniqueOperations.filter((op) => op.operationType === 'query');
|
|
69
|
-
const mutations = uniqueOperations.filter((op) => op.operationType === 'mutation');
|
|
175
|
+
// Use the new intelligent merging instead of simple deduplication
|
|
176
|
+
const mergedOperations = mergeGraphQLQueries(allOperations);
|
|
177
|
+
const queries = mergedOperations.filter((op) => op.operationType === 'query');
|
|
178
|
+
const mutations = mergedOperations.filter((op) => op.operationType === 'mutation');
|
|
70
179
|
const graphqlDir = path.join(outputDir, 'graphql');
|
|
71
180
|
fs.mkdirSync(graphqlDir, { recursive: true });
|
|
72
181
|
const queriesPath = path.join(graphqlDir, 'queries.ts');
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"scaffold-gql-operations.js","sourceRoot":"","sources":["../../src/scaffold-gql-operations.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,IAAI,CAAC;AACzB,OAAO,KAAK,IAAI,MAAM,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"scaffold-gql-operations.js","sourceRoot":"","sources":["../../src/scaffold-gql-operations.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,IAAI,CAAC;AACzB,OAAO,KAAK,IAAI,MAAM,MAAM,CAAC;AAC7B,OAAO,EAAE,KAAK,EAAE,KAAK,EAAsE,IAAI,EAAE,MAAM,SAAS,CAAC;AAgBjH,SAAS,oBAAoB,CAAC,GAAW;IACvC,MAAM,KAAK,GAAG,GAAG,CAAC,KAAK,CAAC,0BAA0B,CAAC,CAAC;IACpD,OAAO,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,kBAAkB,CAAC;AAC/C,CAAC;AAED,SAAS,sBAAsB,CAAC,GAAY;IAC1C,OAAO,CACL,OAAO,GAAG,KAAK,QAAQ;QACvB,GAAG,KAAK,IAAI;QACZ,MAAM,IAAI,GAAG;QACb,CAAC,GAAG,CAAC,IAAI,KAAK,OAAO,IAAI,GAAG,CAAC,IAAI,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0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"scaffold-gql-operations.specs.d.ts","sourceRoot":"","sources":["../../src/scaffold-gql-operations.specs.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
import { describe, test, expect } from 'vitest';
|
|
2
|
+
import { mergeGraphQLQueries } from './scaffold-gql-operations.js';
|
|
3
|
+
describe('GraphQL Query Field Merging', () => {
|
|
4
|
+
test('should merge identical queries with different field selections', () => {
|
|
5
|
+
const query1 = `
|
|
6
|
+
query QuestionnaireProgress($participantId: ID!) {
|
|
7
|
+
questionnaireProgress(participantId: $participantId) {
|
|
8
|
+
questionnaireId
|
|
9
|
+
status
|
|
10
|
+
answers {
|
|
11
|
+
questionId
|
|
12
|
+
value
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
`;
|
|
17
|
+
const query2 = `
|
|
18
|
+
query QuestionnaireProgress($participantId: ID!) {
|
|
19
|
+
questionnaireProgress(participantId: $participantId) {
|
|
20
|
+
questionnaireId
|
|
21
|
+
participantId
|
|
22
|
+
status
|
|
23
|
+
currentQuestionId
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
`;
|
|
27
|
+
const operations = [
|
|
28
|
+
{
|
|
29
|
+
operationType: 'query',
|
|
30
|
+
operationName: 'QuestionnaireProgress',
|
|
31
|
+
raw: query1.trim(),
|
|
32
|
+
},
|
|
33
|
+
{
|
|
34
|
+
operationType: 'query',
|
|
35
|
+
operationName: 'QuestionnaireProgress',
|
|
36
|
+
raw: query2.trim(),
|
|
37
|
+
},
|
|
38
|
+
];
|
|
39
|
+
const merged = mergeGraphQLQueries(operations);
|
|
40
|
+
expect(merged).toHaveLength(1);
|
|
41
|
+
expect(merged[0].operationName).toBe('QuestionnaireProgress');
|
|
42
|
+
// Check that all fields from both queries are present
|
|
43
|
+
const mergedQuery = merged[0].raw;
|
|
44
|
+
expect(mergedQuery).toContain('questionnaireId');
|
|
45
|
+
expect(mergedQuery).toContain('participantId');
|
|
46
|
+
expect(mergedQuery).toContain('status');
|
|
47
|
+
expect(mergedQuery).toContain('currentQuestionId');
|
|
48
|
+
expect(mergedQuery).toContain('answers {');
|
|
49
|
+
expect(mergedQuery).toContain('questionId');
|
|
50
|
+
expect(mergedQuery).toContain('value');
|
|
51
|
+
});
|
|
52
|
+
test('should handle nested field merging correctly', () => {
|
|
53
|
+
const query1 = `
|
|
54
|
+
query UserProfile($id: ID!) {
|
|
55
|
+
user(id: $id) {
|
|
56
|
+
id
|
|
57
|
+
profile {
|
|
58
|
+
name
|
|
59
|
+
email
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
`;
|
|
64
|
+
const query2 = `
|
|
65
|
+
query UserProfile($id: ID!) {
|
|
66
|
+
user(id: $id) {
|
|
67
|
+
id
|
|
68
|
+
username
|
|
69
|
+
profile {
|
|
70
|
+
avatar
|
|
71
|
+
bio
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
`;
|
|
76
|
+
const operations = [
|
|
77
|
+
{
|
|
78
|
+
operationType: 'query',
|
|
79
|
+
operationName: 'UserProfile',
|
|
80
|
+
raw: query1.trim(),
|
|
81
|
+
},
|
|
82
|
+
{
|
|
83
|
+
operationType: 'query',
|
|
84
|
+
operationName: 'UserProfile',
|
|
85
|
+
raw: query2.trim(),
|
|
86
|
+
},
|
|
87
|
+
];
|
|
88
|
+
const merged = mergeGraphQLQueries(operations);
|
|
89
|
+
expect(merged).toHaveLength(1);
|
|
90
|
+
const mergedQuery = merged[0].raw;
|
|
91
|
+
expect(mergedQuery).toContain('id');
|
|
92
|
+
expect(mergedQuery).toContain('username');
|
|
93
|
+
expect(mergedQuery).toContain('profile {');
|
|
94
|
+
expect(mergedQuery).toContain('name');
|
|
95
|
+
expect(mergedQuery).toContain('email');
|
|
96
|
+
expect(mergedQuery).toContain('avatar');
|
|
97
|
+
expect(mergedQuery).toContain('bio');
|
|
98
|
+
});
|
|
99
|
+
test('should not merge queries with different operation names', () => {
|
|
100
|
+
const query1 = `
|
|
101
|
+
query QuestionnaireProgress($participantId: ID!) {
|
|
102
|
+
questionnaireProgress(participantId: $participantId) {
|
|
103
|
+
questionnaireId
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
`;
|
|
107
|
+
const query2 = `
|
|
108
|
+
query UserProfile($id: ID!) {
|
|
109
|
+
user(id: $id) {
|
|
110
|
+
id
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
`;
|
|
114
|
+
const operations = [
|
|
115
|
+
{
|
|
116
|
+
operationType: 'query',
|
|
117
|
+
operationName: 'QuestionnaireProgress',
|
|
118
|
+
raw: query1.trim(),
|
|
119
|
+
},
|
|
120
|
+
{
|
|
121
|
+
operationType: 'query',
|
|
122
|
+
operationName: 'UserProfile',
|
|
123
|
+
raw: query2.trim(),
|
|
124
|
+
},
|
|
125
|
+
];
|
|
126
|
+
const merged = mergeGraphQLQueries(operations);
|
|
127
|
+
expect(merged).toHaveLength(2);
|
|
128
|
+
expect(merged.map((op) => op.operationName)).toContain('QuestionnaireProgress');
|
|
129
|
+
expect(merged.map((op) => op.operationName)).toContain('UserProfile');
|
|
130
|
+
});
|
|
131
|
+
test('should not merge queries with different variables', () => {
|
|
132
|
+
const query1 = `
|
|
133
|
+
query QuestionnaireProgress($participantId: ID!) {
|
|
134
|
+
questionnaireProgress(participantId: $participantId) {
|
|
135
|
+
questionnaireId
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
`;
|
|
139
|
+
const query2 = `
|
|
140
|
+
query QuestionnaireProgress($userId: ID!) {
|
|
141
|
+
questionnaireProgress(participantId: $userId) {
|
|
142
|
+
questionnaireId
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
`;
|
|
146
|
+
const operations = [
|
|
147
|
+
{
|
|
148
|
+
operationType: 'query',
|
|
149
|
+
operationName: 'QuestionnaireProgress',
|
|
150
|
+
raw: query1.trim(),
|
|
151
|
+
},
|
|
152
|
+
{
|
|
153
|
+
operationType: 'query',
|
|
154
|
+
operationName: 'QuestionnaireProgress',
|
|
155
|
+
raw: query2.trim(),
|
|
156
|
+
},
|
|
157
|
+
];
|
|
158
|
+
const merged = mergeGraphQLQueries(operations);
|
|
159
|
+
// Should not merge since variables are different
|
|
160
|
+
expect(merged).toHaveLength(2);
|
|
161
|
+
});
|
|
162
|
+
test('should handle mutations separately from queries', () => {
|
|
163
|
+
const query = `
|
|
164
|
+
query GetUser($id: ID!) {
|
|
165
|
+
user(id: $id) {
|
|
166
|
+
id
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
`;
|
|
170
|
+
const mutation = `
|
|
171
|
+
mutation CreateUser($input: CreateUserInput!) {
|
|
172
|
+
createUser(input: $input) {
|
|
173
|
+
id
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
`;
|
|
177
|
+
const operations = [
|
|
178
|
+
{
|
|
179
|
+
operationType: 'query',
|
|
180
|
+
operationName: 'GetUser',
|
|
181
|
+
raw: query.trim(),
|
|
182
|
+
},
|
|
183
|
+
{
|
|
184
|
+
operationType: 'mutation',
|
|
185
|
+
operationName: 'CreateUser',
|
|
186
|
+
raw: mutation.trim(),
|
|
187
|
+
},
|
|
188
|
+
];
|
|
189
|
+
const merged = mergeGraphQLQueries(operations);
|
|
190
|
+
expect(merged).toHaveLength(2);
|
|
191
|
+
expect(merged.find((op) => op.operationType === 'query')).toBeDefined();
|
|
192
|
+
expect(merged.find((op) => op.operationType === 'mutation')).toBeDefined();
|
|
193
|
+
});
|
|
194
|
+
});
|
|
195
|
+
//# sourceMappingURL=scaffold-gql-operations.specs.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"scaffold-gql-operations.specs.js","sourceRoot":"","sources":["../../src/scaffold-gql-operations.specs.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AACh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