@ctil/gql 1.0.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/.vscode/launch.json +18 -0
- package/README.md +248 -0
- package/cc-request-1.0.0.tgz +0 -0
- package/dist/fp.esm-VY6KF7TP.js +2699 -0
- package/dist/fp.esm-VY6KF7TP.js.map +1 -0
- package/dist/index.cjs +4632 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +300 -0
- package/dist/index.d.ts +300 -0
- package/dist/index.js +1865 -0
- package/dist/index.js.map +1 -0
- package/package.json +46 -0
- package/src/builders/auth.ts +182 -0
- package/src/builders/baseType.ts +194 -0
- package/src/builders/index.ts +5 -0
- package/src/builders/mutation.ts +341 -0
- package/src/builders/query.ts +180 -0
- package/src/builders/sms.ts +59 -0
- package/src/cache/memoryCache.ts +34 -0
- package/src/core/api/auth.ts +86 -0
- package/src/core/api/gql.ts +22 -0
- package/src/core/api/mutation.ts +100 -0
- package/src/core/api/query.ts +82 -0
- package/src/core/api/sms.ts +18 -0
- package/src/core/client.ts +47 -0
- package/src/core/core.ts +281 -0
- package/src/core/executor.ts +19 -0
- package/src/core/type.ts +76 -0
- package/src/device/index.ts +116 -0
- package/src/index.ts +60 -0
- package/src/rateLimit/rateLimit.ts +51 -0
- package/src/rateLimit/rateLimitConfig.ts +12 -0
- package/src/test.ts +80 -0
- package/tsconfig.json +17 -0
- package/tsup.config.ts +10 -0
package/dist/index.js
ADDED
|
@@ -0,0 +1,1865 @@
|
|
|
1
|
+
// src/core/core.ts
|
|
2
|
+
import { GraphQLClient } from "graphql-request";
|
|
3
|
+
|
|
4
|
+
// node_modules/graphql/jsutils/devAssert.mjs
|
|
5
|
+
function devAssert(condition, message) {
|
|
6
|
+
const booleanCondition = Boolean(condition);
|
|
7
|
+
if (!booleanCondition) {
|
|
8
|
+
throw new Error(message);
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
// node_modules/graphql/language/ast.mjs
|
|
13
|
+
var QueryDocumentKeys = {
|
|
14
|
+
Name: [],
|
|
15
|
+
Document: ["definitions"],
|
|
16
|
+
OperationDefinition: [
|
|
17
|
+
"name",
|
|
18
|
+
"variableDefinitions",
|
|
19
|
+
"directives",
|
|
20
|
+
"selectionSet"
|
|
21
|
+
],
|
|
22
|
+
VariableDefinition: ["variable", "type", "defaultValue", "directives"],
|
|
23
|
+
Variable: ["name"],
|
|
24
|
+
SelectionSet: ["selections"],
|
|
25
|
+
Field: ["alias", "name", "arguments", "directives", "selectionSet"],
|
|
26
|
+
Argument: ["name", "value"],
|
|
27
|
+
FragmentSpread: ["name", "directives"],
|
|
28
|
+
InlineFragment: ["typeCondition", "directives", "selectionSet"],
|
|
29
|
+
FragmentDefinition: [
|
|
30
|
+
"name",
|
|
31
|
+
// Note: fragment variable definitions are deprecated and will removed in v17.0.0
|
|
32
|
+
"variableDefinitions",
|
|
33
|
+
"typeCondition",
|
|
34
|
+
"directives",
|
|
35
|
+
"selectionSet"
|
|
36
|
+
],
|
|
37
|
+
IntValue: [],
|
|
38
|
+
FloatValue: [],
|
|
39
|
+
StringValue: [],
|
|
40
|
+
BooleanValue: [],
|
|
41
|
+
NullValue: [],
|
|
42
|
+
EnumValue: [],
|
|
43
|
+
ListValue: ["values"],
|
|
44
|
+
ObjectValue: ["fields"],
|
|
45
|
+
ObjectField: ["name", "value"],
|
|
46
|
+
Directive: ["name", "arguments"],
|
|
47
|
+
NamedType: ["name"],
|
|
48
|
+
ListType: ["type"],
|
|
49
|
+
NonNullType: ["type"],
|
|
50
|
+
SchemaDefinition: ["description", "directives", "operationTypes"],
|
|
51
|
+
OperationTypeDefinition: ["type"],
|
|
52
|
+
ScalarTypeDefinition: ["description", "name", "directives"],
|
|
53
|
+
ObjectTypeDefinition: [
|
|
54
|
+
"description",
|
|
55
|
+
"name",
|
|
56
|
+
"interfaces",
|
|
57
|
+
"directives",
|
|
58
|
+
"fields"
|
|
59
|
+
],
|
|
60
|
+
FieldDefinition: ["description", "name", "arguments", "type", "directives"],
|
|
61
|
+
InputValueDefinition: [
|
|
62
|
+
"description",
|
|
63
|
+
"name",
|
|
64
|
+
"type",
|
|
65
|
+
"defaultValue",
|
|
66
|
+
"directives"
|
|
67
|
+
],
|
|
68
|
+
InterfaceTypeDefinition: [
|
|
69
|
+
"description",
|
|
70
|
+
"name",
|
|
71
|
+
"interfaces",
|
|
72
|
+
"directives",
|
|
73
|
+
"fields"
|
|
74
|
+
],
|
|
75
|
+
UnionTypeDefinition: ["description", "name", "directives", "types"],
|
|
76
|
+
EnumTypeDefinition: ["description", "name", "directives", "values"],
|
|
77
|
+
EnumValueDefinition: ["description", "name", "directives"],
|
|
78
|
+
InputObjectTypeDefinition: ["description", "name", "directives", "fields"],
|
|
79
|
+
DirectiveDefinition: ["description", "name", "arguments", "locations"],
|
|
80
|
+
SchemaExtension: ["directives", "operationTypes"],
|
|
81
|
+
ScalarTypeExtension: ["name", "directives"],
|
|
82
|
+
ObjectTypeExtension: ["name", "interfaces", "directives", "fields"],
|
|
83
|
+
InterfaceTypeExtension: ["name", "interfaces", "directives", "fields"],
|
|
84
|
+
UnionTypeExtension: ["name", "directives", "types"],
|
|
85
|
+
EnumTypeExtension: ["name", "directives", "values"],
|
|
86
|
+
InputObjectTypeExtension: ["name", "directives", "fields"]
|
|
87
|
+
};
|
|
88
|
+
var kindValues = new Set(Object.keys(QueryDocumentKeys));
|
|
89
|
+
function isNode(maybeNode) {
|
|
90
|
+
const maybeKind = maybeNode === null || maybeNode === void 0 ? void 0 : maybeNode.kind;
|
|
91
|
+
return typeof maybeKind === "string" && kindValues.has(maybeKind);
|
|
92
|
+
}
|
|
93
|
+
var OperationTypeNode;
|
|
94
|
+
(function(OperationTypeNode2) {
|
|
95
|
+
OperationTypeNode2["QUERY"] = "query";
|
|
96
|
+
OperationTypeNode2["MUTATION"] = "mutation";
|
|
97
|
+
OperationTypeNode2["SUBSCRIPTION"] = "subscription";
|
|
98
|
+
})(OperationTypeNode || (OperationTypeNode = {}));
|
|
99
|
+
|
|
100
|
+
// node_modules/graphql/language/kinds.mjs
|
|
101
|
+
var Kind;
|
|
102
|
+
(function(Kind2) {
|
|
103
|
+
Kind2["NAME"] = "Name";
|
|
104
|
+
Kind2["DOCUMENT"] = "Document";
|
|
105
|
+
Kind2["OPERATION_DEFINITION"] = "OperationDefinition";
|
|
106
|
+
Kind2["VARIABLE_DEFINITION"] = "VariableDefinition";
|
|
107
|
+
Kind2["SELECTION_SET"] = "SelectionSet";
|
|
108
|
+
Kind2["FIELD"] = "Field";
|
|
109
|
+
Kind2["ARGUMENT"] = "Argument";
|
|
110
|
+
Kind2["FRAGMENT_SPREAD"] = "FragmentSpread";
|
|
111
|
+
Kind2["INLINE_FRAGMENT"] = "InlineFragment";
|
|
112
|
+
Kind2["FRAGMENT_DEFINITION"] = "FragmentDefinition";
|
|
113
|
+
Kind2["VARIABLE"] = "Variable";
|
|
114
|
+
Kind2["INT"] = "IntValue";
|
|
115
|
+
Kind2["FLOAT"] = "FloatValue";
|
|
116
|
+
Kind2["STRING"] = "StringValue";
|
|
117
|
+
Kind2["BOOLEAN"] = "BooleanValue";
|
|
118
|
+
Kind2["NULL"] = "NullValue";
|
|
119
|
+
Kind2["ENUM"] = "EnumValue";
|
|
120
|
+
Kind2["LIST"] = "ListValue";
|
|
121
|
+
Kind2["OBJECT"] = "ObjectValue";
|
|
122
|
+
Kind2["OBJECT_FIELD"] = "ObjectField";
|
|
123
|
+
Kind2["DIRECTIVE"] = "Directive";
|
|
124
|
+
Kind2["NAMED_TYPE"] = "NamedType";
|
|
125
|
+
Kind2["LIST_TYPE"] = "ListType";
|
|
126
|
+
Kind2["NON_NULL_TYPE"] = "NonNullType";
|
|
127
|
+
Kind2["SCHEMA_DEFINITION"] = "SchemaDefinition";
|
|
128
|
+
Kind2["OPERATION_TYPE_DEFINITION"] = "OperationTypeDefinition";
|
|
129
|
+
Kind2["SCALAR_TYPE_DEFINITION"] = "ScalarTypeDefinition";
|
|
130
|
+
Kind2["OBJECT_TYPE_DEFINITION"] = "ObjectTypeDefinition";
|
|
131
|
+
Kind2["FIELD_DEFINITION"] = "FieldDefinition";
|
|
132
|
+
Kind2["INPUT_VALUE_DEFINITION"] = "InputValueDefinition";
|
|
133
|
+
Kind2["INTERFACE_TYPE_DEFINITION"] = "InterfaceTypeDefinition";
|
|
134
|
+
Kind2["UNION_TYPE_DEFINITION"] = "UnionTypeDefinition";
|
|
135
|
+
Kind2["ENUM_TYPE_DEFINITION"] = "EnumTypeDefinition";
|
|
136
|
+
Kind2["ENUM_VALUE_DEFINITION"] = "EnumValueDefinition";
|
|
137
|
+
Kind2["INPUT_OBJECT_TYPE_DEFINITION"] = "InputObjectTypeDefinition";
|
|
138
|
+
Kind2["DIRECTIVE_DEFINITION"] = "DirectiveDefinition";
|
|
139
|
+
Kind2["SCHEMA_EXTENSION"] = "SchemaExtension";
|
|
140
|
+
Kind2["SCALAR_TYPE_EXTENSION"] = "ScalarTypeExtension";
|
|
141
|
+
Kind2["OBJECT_TYPE_EXTENSION"] = "ObjectTypeExtension";
|
|
142
|
+
Kind2["INTERFACE_TYPE_EXTENSION"] = "InterfaceTypeExtension";
|
|
143
|
+
Kind2["UNION_TYPE_EXTENSION"] = "UnionTypeExtension";
|
|
144
|
+
Kind2["ENUM_TYPE_EXTENSION"] = "EnumTypeExtension";
|
|
145
|
+
Kind2["INPUT_OBJECT_TYPE_EXTENSION"] = "InputObjectTypeExtension";
|
|
146
|
+
})(Kind || (Kind = {}));
|
|
147
|
+
|
|
148
|
+
// node_modules/graphql/language/characterClasses.mjs
|
|
149
|
+
function isWhiteSpace(code) {
|
|
150
|
+
return code === 9 || code === 32;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
// node_modules/graphql/language/blockString.mjs
|
|
154
|
+
function printBlockString(value, options) {
|
|
155
|
+
const escapedValue = value.replace(/"""/g, '\\"""');
|
|
156
|
+
const lines = escapedValue.split(/\r\n|[\n\r]/g);
|
|
157
|
+
const isSingleLine = lines.length === 1;
|
|
158
|
+
const forceLeadingNewLine = lines.length > 1 && lines.slice(1).every((line) => line.length === 0 || isWhiteSpace(line.charCodeAt(0)));
|
|
159
|
+
const hasTrailingTripleQuotes = escapedValue.endsWith('\\"""');
|
|
160
|
+
const hasTrailingQuote = value.endsWith('"') && !hasTrailingTripleQuotes;
|
|
161
|
+
const hasTrailingSlash = value.endsWith("\\");
|
|
162
|
+
const forceTrailingNewline = hasTrailingQuote || hasTrailingSlash;
|
|
163
|
+
const printAsMultipleLines = !(options !== null && options !== void 0 && options.minimize) && // add leading and trailing new lines only if it improves readability
|
|
164
|
+
(!isSingleLine || value.length > 70 || forceTrailingNewline || forceLeadingNewLine || hasTrailingTripleQuotes);
|
|
165
|
+
let result = "";
|
|
166
|
+
const skipLeadingNewLine = isSingleLine && isWhiteSpace(value.charCodeAt(0));
|
|
167
|
+
if (printAsMultipleLines && !skipLeadingNewLine || forceLeadingNewLine) {
|
|
168
|
+
result += "\n";
|
|
169
|
+
}
|
|
170
|
+
result += escapedValue;
|
|
171
|
+
if (printAsMultipleLines || forceTrailingNewline) {
|
|
172
|
+
result += "\n";
|
|
173
|
+
}
|
|
174
|
+
return '"""' + result + '"""';
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
// node_modules/graphql/jsutils/inspect.mjs
|
|
178
|
+
var MAX_ARRAY_LENGTH = 10;
|
|
179
|
+
var MAX_RECURSIVE_DEPTH = 2;
|
|
180
|
+
function inspect(value) {
|
|
181
|
+
return formatValue(value, []);
|
|
182
|
+
}
|
|
183
|
+
function formatValue(value, seenValues) {
|
|
184
|
+
switch (typeof value) {
|
|
185
|
+
case "string":
|
|
186
|
+
return JSON.stringify(value);
|
|
187
|
+
case "function":
|
|
188
|
+
return value.name ? `[function ${value.name}]` : "[function]";
|
|
189
|
+
case "object":
|
|
190
|
+
return formatObjectValue(value, seenValues);
|
|
191
|
+
default:
|
|
192
|
+
return String(value);
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
function formatObjectValue(value, previouslySeenValues) {
|
|
196
|
+
if (value === null) {
|
|
197
|
+
return "null";
|
|
198
|
+
}
|
|
199
|
+
if (previouslySeenValues.includes(value)) {
|
|
200
|
+
return "[Circular]";
|
|
201
|
+
}
|
|
202
|
+
const seenValues = [...previouslySeenValues, value];
|
|
203
|
+
if (isJSONable(value)) {
|
|
204
|
+
const jsonValue = value.toJSON();
|
|
205
|
+
if (jsonValue !== value) {
|
|
206
|
+
return typeof jsonValue === "string" ? jsonValue : formatValue(jsonValue, seenValues);
|
|
207
|
+
}
|
|
208
|
+
} else if (Array.isArray(value)) {
|
|
209
|
+
return formatArray(value, seenValues);
|
|
210
|
+
}
|
|
211
|
+
return formatObject(value, seenValues);
|
|
212
|
+
}
|
|
213
|
+
function isJSONable(value) {
|
|
214
|
+
return typeof value.toJSON === "function";
|
|
215
|
+
}
|
|
216
|
+
function formatObject(object, seenValues) {
|
|
217
|
+
const entries = Object.entries(object);
|
|
218
|
+
if (entries.length === 0) {
|
|
219
|
+
return "{}";
|
|
220
|
+
}
|
|
221
|
+
if (seenValues.length > MAX_RECURSIVE_DEPTH) {
|
|
222
|
+
return "[" + getObjectTag(object) + "]";
|
|
223
|
+
}
|
|
224
|
+
const properties = entries.map(
|
|
225
|
+
([key, value]) => key + ": " + formatValue(value, seenValues)
|
|
226
|
+
);
|
|
227
|
+
return "{ " + properties.join(", ") + " }";
|
|
228
|
+
}
|
|
229
|
+
function formatArray(array, seenValues) {
|
|
230
|
+
if (array.length === 0) {
|
|
231
|
+
return "[]";
|
|
232
|
+
}
|
|
233
|
+
if (seenValues.length > MAX_RECURSIVE_DEPTH) {
|
|
234
|
+
return "[Array]";
|
|
235
|
+
}
|
|
236
|
+
const len = Math.min(MAX_ARRAY_LENGTH, array.length);
|
|
237
|
+
const remaining = array.length - len;
|
|
238
|
+
const items = [];
|
|
239
|
+
for (let i = 0; i < len; ++i) {
|
|
240
|
+
items.push(formatValue(array[i], seenValues));
|
|
241
|
+
}
|
|
242
|
+
if (remaining === 1) {
|
|
243
|
+
items.push("... 1 more item");
|
|
244
|
+
} else if (remaining > 1) {
|
|
245
|
+
items.push(`... ${remaining} more items`);
|
|
246
|
+
}
|
|
247
|
+
return "[" + items.join(", ") + "]";
|
|
248
|
+
}
|
|
249
|
+
function getObjectTag(object) {
|
|
250
|
+
const tag = Object.prototype.toString.call(object).replace(/^\[object /, "").replace(/]$/, "");
|
|
251
|
+
if (tag === "Object" && typeof object.constructor === "function") {
|
|
252
|
+
const name = object.constructor.name;
|
|
253
|
+
if (typeof name === "string" && name !== "") {
|
|
254
|
+
return name;
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
return tag;
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
// node_modules/graphql/language/printString.mjs
|
|
261
|
+
function printString(str) {
|
|
262
|
+
return `"${str.replace(escapedRegExp, escapedReplacer)}"`;
|
|
263
|
+
}
|
|
264
|
+
var escapedRegExp = /[\x00-\x1f\x22\x5c\x7f-\x9f]/g;
|
|
265
|
+
function escapedReplacer(str) {
|
|
266
|
+
return escapeSequences[str.charCodeAt(0)];
|
|
267
|
+
}
|
|
268
|
+
var escapeSequences = [
|
|
269
|
+
"\\u0000",
|
|
270
|
+
"\\u0001",
|
|
271
|
+
"\\u0002",
|
|
272
|
+
"\\u0003",
|
|
273
|
+
"\\u0004",
|
|
274
|
+
"\\u0005",
|
|
275
|
+
"\\u0006",
|
|
276
|
+
"\\u0007",
|
|
277
|
+
"\\b",
|
|
278
|
+
"\\t",
|
|
279
|
+
"\\n",
|
|
280
|
+
"\\u000B",
|
|
281
|
+
"\\f",
|
|
282
|
+
"\\r",
|
|
283
|
+
"\\u000E",
|
|
284
|
+
"\\u000F",
|
|
285
|
+
"\\u0010",
|
|
286
|
+
"\\u0011",
|
|
287
|
+
"\\u0012",
|
|
288
|
+
"\\u0013",
|
|
289
|
+
"\\u0014",
|
|
290
|
+
"\\u0015",
|
|
291
|
+
"\\u0016",
|
|
292
|
+
"\\u0017",
|
|
293
|
+
"\\u0018",
|
|
294
|
+
"\\u0019",
|
|
295
|
+
"\\u001A",
|
|
296
|
+
"\\u001B",
|
|
297
|
+
"\\u001C",
|
|
298
|
+
"\\u001D",
|
|
299
|
+
"\\u001E",
|
|
300
|
+
"\\u001F",
|
|
301
|
+
"",
|
|
302
|
+
"",
|
|
303
|
+
'\\"',
|
|
304
|
+
"",
|
|
305
|
+
"",
|
|
306
|
+
"",
|
|
307
|
+
"",
|
|
308
|
+
"",
|
|
309
|
+
"",
|
|
310
|
+
"",
|
|
311
|
+
"",
|
|
312
|
+
"",
|
|
313
|
+
"",
|
|
314
|
+
"",
|
|
315
|
+
"",
|
|
316
|
+
"",
|
|
317
|
+
// 2F
|
|
318
|
+
"",
|
|
319
|
+
"",
|
|
320
|
+
"",
|
|
321
|
+
"",
|
|
322
|
+
"",
|
|
323
|
+
"",
|
|
324
|
+
"",
|
|
325
|
+
"",
|
|
326
|
+
"",
|
|
327
|
+
"",
|
|
328
|
+
"",
|
|
329
|
+
"",
|
|
330
|
+
"",
|
|
331
|
+
"",
|
|
332
|
+
"",
|
|
333
|
+
"",
|
|
334
|
+
// 3F
|
|
335
|
+
"",
|
|
336
|
+
"",
|
|
337
|
+
"",
|
|
338
|
+
"",
|
|
339
|
+
"",
|
|
340
|
+
"",
|
|
341
|
+
"",
|
|
342
|
+
"",
|
|
343
|
+
"",
|
|
344
|
+
"",
|
|
345
|
+
"",
|
|
346
|
+
"",
|
|
347
|
+
"",
|
|
348
|
+
"",
|
|
349
|
+
"",
|
|
350
|
+
"",
|
|
351
|
+
// 4F
|
|
352
|
+
"",
|
|
353
|
+
"",
|
|
354
|
+
"",
|
|
355
|
+
"",
|
|
356
|
+
"",
|
|
357
|
+
"",
|
|
358
|
+
"",
|
|
359
|
+
"",
|
|
360
|
+
"",
|
|
361
|
+
"",
|
|
362
|
+
"",
|
|
363
|
+
"",
|
|
364
|
+
"\\\\",
|
|
365
|
+
"",
|
|
366
|
+
"",
|
|
367
|
+
"",
|
|
368
|
+
// 5F
|
|
369
|
+
"",
|
|
370
|
+
"",
|
|
371
|
+
"",
|
|
372
|
+
"",
|
|
373
|
+
"",
|
|
374
|
+
"",
|
|
375
|
+
"",
|
|
376
|
+
"",
|
|
377
|
+
"",
|
|
378
|
+
"",
|
|
379
|
+
"",
|
|
380
|
+
"",
|
|
381
|
+
"",
|
|
382
|
+
"",
|
|
383
|
+
"",
|
|
384
|
+
"",
|
|
385
|
+
// 6F
|
|
386
|
+
"",
|
|
387
|
+
"",
|
|
388
|
+
"",
|
|
389
|
+
"",
|
|
390
|
+
"",
|
|
391
|
+
"",
|
|
392
|
+
"",
|
|
393
|
+
"",
|
|
394
|
+
"",
|
|
395
|
+
"",
|
|
396
|
+
"",
|
|
397
|
+
"",
|
|
398
|
+
"",
|
|
399
|
+
"",
|
|
400
|
+
"",
|
|
401
|
+
"\\u007F",
|
|
402
|
+
"\\u0080",
|
|
403
|
+
"\\u0081",
|
|
404
|
+
"\\u0082",
|
|
405
|
+
"\\u0083",
|
|
406
|
+
"\\u0084",
|
|
407
|
+
"\\u0085",
|
|
408
|
+
"\\u0086",
|
|
409
|
+
"\\u0087",
|
|
410
|
+
"\\u0088",
|
|
411
|
+
"\\u0089",
|
|
412
|
+
"\\u008A",
|
|
413
|
+
"\\u008B",
|
|
414
|
+
"\\u008C",
|
|
415
|
+
"\\u008D",
|
|
416
|
+
"\\u008E",
|
|
417
|
+
"\\u008F",
|
|
418
|
+
"\\u0090",
|
|
419
|
+
"\\u0091",
|
|
420
|
+
"\\u0092",
|
|
421
|
+
"\\u0093",
|
|
422
|
+
"\\u0094",
|
|
423
|
+
"\\u0095",
|
|
424
|
+
"\\u0096",
|
|
425
|
+
"\\u0097",
|
|
426
|
+
"\\u0098",
|
|
427
|
+
"\\u0099",
|
|
428
|
+
"\\u009A",
|
|
429
|
+
"\\u009B",
|
|
430
|
+
"\\u009C",
|
|
431
|
+
"\\u009D",
|
|
432
|
+
"\\u009E",
|
|
433
|
+
"\\u009F"
|
|
434
|
+
];
|
|
435
|
+
|
|
436
|
+
// node_modules/graphql/language/visitor.mjs
|
|
437
|
+
var BREAK = Object.freeze({});
|
|
438
|
+
function visit(root, visitor, visitorKeys = QueryDocumentKeys) {
|
|
439
|
+
const enterLeaveMap = /* @__PURE__ */ new Map();
|
|
440
|
+
for (const kind of Object.values(Kind)) {
|
|
441
|
+
enterLeaveMap.set(kind, getEnterLeaveForKind(visitor, kind));
|
|
442
|
+
}
|
|
443
|
+
let stack = void 0;
|
|
444
|
+
let inArray = Array.isArray(root);
|
|
445
|
+
let keys = [root];
|
|
446
|
+
let index = -1;
|
|
447
|
+
let edits = [];
|
|
448
|
+
let node = root;
|
|
449
|
+
let key = void 0;
|
|
450
|
+
let parent = void 0;
|
|
451
|
+
const path2 = [];
|
|
452
|
+
const ancestors = [];
|
|
453
|
+
do {
|
|
454
|
+
index++;
|
|
455
|
+
const isLeaving = index === keys.length;
|
|
456
|
+
const isEdited = isLeaving && edits.length !== 0;
|
|
457
|
+
if (isLeaving) {
|
|
458
|
+
key = ancestors.length === 0 ? void 0 : path2[path2.length - 1];
|
|
459
|
+
node = parent;
|
|
460
|
+
parent = ancestors.pop();
|
|
461
|
+
if (isEdited) {
|
|
462
|
+
if (inArray) {
|
|
463
|
+
node = node.slice();
|
|
464
|
+
let editOffset = 0;
|
|
465
|
+
for (const [editKey, editValue] of edits) {
|
|
466
|
+
const arrayKey = editKey - editOffset;
|
|
467
|
+
if (editValue === null) {
|
|
468
|
+
node.splice(arrayKey, 1);
|
|
469
|
+
editOffset++;
|
|
470
|
+
} else {
|
|
471
|
+
node[arrayKey] = editValue;
|
|
472
|
+
}
|
|
473
|
+
}
|
|
474
|
+
} else {
|
|
475
|
+
node = { ...node };
|
|
476
|
+
for (const [editKey, editValue] of edits) {
|
|
477
|
+
node[editKey] = editValue;
|
|
478
|
+
}
|
|
479
|
+
}
|
|
480
|
+
}
|
|
481
|
+
index = stack.index;
|
|
482
|
+
keys = stack.keys;
|
|
483
|
+
edits = stack.edits;
|
|
484
|
+
inArray = stack.inArray;
|
|
485
|
+
stack = stack.prev;
|
|
486
|
+
} else if (parent) {
|
|
487
|
+
key = inArray ? index : keys[index];
|
|
488
|
+
node = parent[key];
|
|
489
|
+
if (node === null || node === void 0) {
|
|
490
|
+
continue;
|
|
491
|
+
}
|
|
492
|
+
path2.push(key);
|
|
493
|
+
}
|
|
494
|
+
let result;
|
|
495
|
+
if (!Array.isArray(node)) {
|
|
496
|
+
var _enterLeaveMap$get, _enterLeaveMap$get2;
|
|
497
|
+
isNode(node) || devAssert(false, `Invalid AST Node: ${inspect(node)}.`);
|
|
498
|
+
const visitFn = isLeaving ? (_enterLeaveMap$get = enterLeaveMap.get(node.kind)) === null || _enterLeaveMap$get === void 0 ? void 0 : _enterLeaveMap$get.leave : (_enterLeaveMap$get2 = enterLeaveMap.get(node.kind)) === null || _enterLeaveMap$get2 === void 0 ? void 0 : _enterLeaveMap$get2.enter;
|
|
499
|
+
result = visitFn === null || visitFn === void 0 ? void 0 : visitFn.call(visitor, node, key, parent, path2, ancestors);
|
|
500
|
+
if (result === BREAK) {
|
|
501
|
+
break;
|
|
502
|
+
}
|
|
503
|
+
if (result === false) {
|
|
504
|
+
if (!isLeaving) {
|
|
505
|
+
path2.pop();
|
|
506
|
+
continue;
|
|
507
|
+
}
|
|
508
|
+
} else if (result !== void 0) {
|
|
509
|
+
edits.push([key, result]);
|
|
510
|
+
if (!isLeaving) {
|
|
511
|
+
if (isNode(result)) {
|
|
512
|
+
node = result;
|
|
513
|
+
} else {
|
|
514
|
+
path2.pop();
|
|
515
|
+
continue;
|
|
516
|
+
}
|
|
517
|
+
}
|
|
518
|
+
}
|
|
519
|
+
}
|
|
520
|
+
if (result === void 0 && isEdited) {
|
|
521
|
+
edits.push([key, node]);
|
|
522
|
+
}
|
|
523
|
+
if (isLeaving) {
|
|
524
|
+
path2.pop();
|
|
525
|
+
} else {
|
|
526
|
+
var _node$kind;
|
|
527
|
+
stack = {
|
|
528
|
+
inArray,
|
|
529
|
+
index,
|
|
530
|
+
keys,
|
|
531
|
+
edits,
|
|
532
|
+
prev: stack
|
|
533
|
+
};
|
|
534
|
+
inArray = Array.isArray(node);
|
|
535
|
+
keys = inArray ? node : (_node$kind = visitorKeys[node.kind]) !== null && _node$kind !== void 0 ? _node$kind : [];
|
|
536
|
+
index = -1;
|
|
537
|
+
edits = [];
|
|
538
|
+
if (parent) {
|
|
539
|
+
ancestors.push(parent);
|
|
540
|
+
}
|
|
541
|
+
parent = node;
|
|
542
|
+
}
|
|
543
|
+
} while (stack !== void 0);
|
|
544
|
+
if (edits.length !== 0) {
|
|
545
|
+
return edits[edits.length - 1][1];
|
|
546
|
+
}
|
|
547
|
+
return root;
|
|
548
|
+
}
|
|
549
|
+
function getEnterLeaveForKind(visitor, kind) {
|
|
550
|
+
const kindVisitor = visitor[kind];
|
|
551
|
+
if (typeof kindVisitor === "object") {
|
|
552
|
+
return kindVisitor;
|
|
553
|
+
} else if (typeof kindVisitor === "function") {
|
|
554
|
+
return {
|
|
555
|
+
enter: kindVisitor,
|
|
556
|
+
leave: void 0
|
|
557
|
+
};
|
|
558
|
+
}
|
|
559
|
+
return {
|
|
560
|
+
enter: visitor.enter,
|
|
561
|
+
leave: visitor.leave
|
|
562
|
+
};
|
|
563
|
+
}
|
|
564
|
+
|
|
565
|
+
// node_modules/graphql/language/printer.mjs
|
|
566
|
+
function print(ast) {
|
|
567
|
+
return visit(ast, printDocASTReducer);
|
|
568
|
+
}
|
|
569
|
+
var MAX_LINE_LENGTH = 80;
|
|
570
|
+
var printDocASTReducer = {
|
|
571
|
+
Name: {
|
|
572
|
+
leave: (node) => node.value
|
|
573
|
+
},
|
|
574
|
+
Variable: {
|
|
575
|
+
leave: (node) => "$" + node.name
|
|
576
|
+
},
|
|
577
|
+
// Document
|
|
578
|
+
Document: {
|
|
579
|
+
leave: (node) => join(node.definitions, "\n\n")
|
|
580
|
+
},
|
|
581
|
+
OperationDefinition: {
|
|
582
|
+
leave(node) {
|
|
583
|
+
const varDefs = wrap("(", join(node.variableDefinitions, ", "), ")");
|
|
584
|
+
const prefix = join(
|
|
585
|
+
[
|
|
586
|
+
node.operation,
|
|
587
|
+
join([node.name, varDefs]),
|
|
588
|
+
join(node.directives, " ")
|
|
589
|
+
],
|
|
590
|
+
" "
|
|
591
|
+
);
|
|
592
|
+
return (prefix === "query" ? "" : prefix + " ") + node.selectionSet;
|
|
593
|
+
}
|
|
594
|
+
},
|
|
595
|
+
VariableDefinition: {
|
|
596
|
+
leave: ({ variable, type, defaultValue, directives }) => variable + ": " + type + wrap(" = ", defaultValue) + wrap(" ", join(directives, " "))
|
|
597
|
+
},
|
|
598
|
+
SelectionSet: {
|
|
599
|
+
leave: ({ selections }) => block(selections)
|
|
600
|
+
},
|
|
601
|
+
Field: {
|
|
602
|
+
leave({ alias, name, arguments: args, directives, selectionSet }) {
|
|
603
|
+
const prefix = wrap("", alias, ": ") + name;
|
|
604
|
+
let argsLine = prefix + wrap("(", join(args, ", "), ")");
|
|
605
|
+
if (argsLine.length > MAX_LINE_LENGTH) {
|
|
606
|
+
argsLine = prefix + wrap("(\n", indent(join(args, "\n")), "\n)");
|
|
607
|
+
}
|
|
608
|
+
return join([argsLine, join(directives, " "), selectionSet], " ");
|
|
609
|
+
}
|
|
610
|
+
},
|
|
611
|
+
Argument: {
|
|
612
|
+
leave: ({ name, value }) => name + ": " + value
|
|
613
|
+
},
|
|
614
|
+
// Fragments
|
|
615
|
+
FragmentSpread: {
|
|
616
|
+
leave: ({ name, directives }) => "..." + name + wrap(" ", join(directives, " "))
|
|
617
|
+
},
|
|
618
|
+
InlineFragment: {
|
|
619
|
+
leave: ({ typeCondition, directives, selectionSet }) => join(
|
|
620
|
+
[
|
|
621
|
+
"...",
|
|
622
|
+
wrap("on ", typeCondition),
|
|
623
|
+
join(directives, " "),
|
|
624
|
+
selectionSet
|
|
625
|
+
],
|
|
626
|
+
" "
|
|
627
|
+
)
|
|
628
|
+
},
|
|
629
|
+
FragmentDefinition: {
|
|
630
|
+
leave: ({ name, typeCondition, variableDefinitions, directives, selectionSet }) => (
|
|
631
|
+
// or removed in the future.
|
|
632
|
+
`fragment ${name}${wrap("(", join(variableDefinitions, ", "), ")")} on ${typeCondition} ${wrap("", join(directives, " "), " ")}` + selectionSet
|
|
633
|
+
)
|
|
634
|
+
},
|
|
635
|
+
// Value
|
|
636
|
+
IntValue: {
|
|
637
|
+
leave: ({ value }) => value
|
|
638
|
+
},
|
|
639
|
+
FloatValue: {
|
|
640
|
+
leave: ({ value }) => value
|
|
641
|
+
},
|
|
642
|
+
StringValue: {
|
|
643
|
+
leave: ({ value, block: isBlockString }) => isBlockString ? printBlockString(value) : printString(value)
|
|
644
|
+
},
|
|
645
|
+
BooleanValue: {
|
|
646
|
+
leave: ({ value }) => value ? "true" : "false"
|
|
647
|
+
},
|
|
648
|
+
NullValue: {
|
|
649
|
+
leave: () => "null"
|
|
650
|
+
},
|
|
651
|
+
EnumValue: {
|
|
652
|
+
leave: ({ value }) => value
|
|
653
|
+
},
|
|
654
|
+
ListValue: {
|
|
655
|
+
leave: ({ values }) => "[" + join(values, ", ") + "]"
|
|
656
|
+
},
|
|
657
|
+
ObjectValue: {
|
|
658
|
+
leave: ({ fields }) => "{" + join(fields, ", ") + "}"
|
|
659
|
+
},
|
|
660
|
+
ObjectField: {
|
|
661
|
+
leave: ({ name, value }) => name + ": " + value
|
|
662
|
+
},
|
|
663
|
+
// Directive
|
|
664
|
+
Directive: {
|
|
665
|
+
leave: ({ name, arguments: args }) => "@" + name + wrap("(", join(args, ", "), ")")
|
|
666
|
+
},
|
|
667
|
+
// Type
|
|
668
|
+
NamedType: {
|
|
669
|
+
leave: ({ name }) => name
|
|
670
|
+
},
|
|
671
|
+
ListType: {
|
|
672
|
+
leave: ({ type }) => "[" + type + "]"
|
|
673
|
+
},
|
|
674
|
+
NonNullType: {
|
|
675
|
+
leave: ({ type }) => type + "!"
|
|
676
|
+
},
|
|
677
|
+
// Type System Definitions
|
|
678
|
+
SchemaDefinition: {
|
|
679
|
+
leave: ({ description, directives, operationTypes }) => wrap("", description, "\n") + join(["schema", join(directives, " "), block(operationTypes)], " ")
|
|
680
|
+
},
|
|
681
|
+
OperationTypeDefinition: {
|
|
682
|
+
leave: ({ operation, type }) => operation + ": " + type
|
|
683
|
+
},
|
|
684
|
+
ScalarTypeDefinition: {
|
|
685
|
+
leave: ({ description, name, directives }) => wrap("", description, "\n") + join(["scalar", name, join(directives, " ")], " ")
|
|
686
|
+
},
|
|
687
|
+
ObjectTypeDefinition: {
|
|
688
|
+
leave: ({ description, name, interfaces, directives, fields }) => wrap("", description, "\n") + join(
|
|
689
|
+
[
|
|
690
|
+
"type",
|
|
691
|
+
name,
|
|
692
|
+
wrap("implements ", join(interfaces, " & ")),
|
|
693
|
+
join(directives, " "),
|
|
694
|
+
block(fields)
|
|
695
|
+
],
|
|
696
|
+
" "
|
|
697
|
+
)
|
|
698
|
+
},
|
|
699
|
+
FieldDefinition: {
|
|
700
|
+
leave: ({ description, name, arguments: args, type, directives }) => wrap("", description, "\n") + name + (hasMultilineItems(args) ? wrap("(\n", indent(join(args, "\n")), "\n)") : wrap("(", join(args, ", "), ")")) + ": " + type + wrap(" ", join(directives, " "))
|
|
701
|
+
},
|
|
702
|
+
InputValueDefinition: {
|
|
703
|
+
leave: ({ description, name, type, defaultValue, directives }) => wrap("", description, "\n") + join(
|
|
704
|
+
[name + ": " + type, wrap("= ", defaultValue), join(directives, " ")],
|
|
705
|
+
" "
|
|
706
|
+
)
|
|
707
|
+
},
|
|
708
|
+
InterfaceTypeDefinition: {
|
|
709
|
+
leave: ({ description, name, interfaces, directives, fields }) => wrap("", description, "\n") + join(
|
|
710
|
+
[
|
|
711
|
+
"interface",
|
|
712
|
+
name,
|
|
713
|
+
wrap("implements ", join(interfaces, " & ")),
|
|
714
|
+
join(directives, " "),
|
|
715
|
+
block(fields)
|
|
716
|
+
],
|
|
717
|
+
" "
|
|
718
|
+
)
|
|
719
|
+
},
|
|
720
|
+
UnionTypeDefinition: {
|
|
721
|
+
leave: ({ description, name, directives, types }) => wrap("", description, "\n") + join(
|
|
722
|
+
["union", name, join(directives, " "), wrap("= ", join(types, " | "))],
|
|
723
|
+
" "
|
|
724
|
+
)
|
|
725
|
+
},
|
|
726
|
+
EnumTypeDefinition: {
|
|
727
|
+
leave: ({ description, name, directives, values }) => wrap("", description, "\n") + join(["enum", name, join(directives, " "), block(values)], " ")
|
|
728
|
+
},
|
|
729
|
+
EnumValueDefinition: {
|
|
730
|
+
leave: ({ description, name, directives }) => wrap("", description, "\n") + join([name, join(directives, " ")], " ")
|
|
731
|
+
},
|
|
732
|
+
InputObjectTypeDefinition: {
|
|
733
|
+
leave: ({ description, name, directives, fields }) => wrap("", description, "\n") + join(["input", name, join(directives, " "), block(fields)], " ")
|
|
734
|
+
},
|
|
735
|
+
DirectiveDefinition: {
|
|
736
|
+
leave: ({ description, name, arguments: args, repeatable, locations }) => wrap("", description, "\n") + "directive @" + name + (hasMultilineItems(args) ? wrap("(\n", indent(join(args, "\n")), "\n)") : wrap("(", join(args, ", "), ")")) + (repeatable ? " repeatable" : "") + " on " + join(locations, " | ")
|
|
737
|
+
},
|
|
738
|
+
SchemaExtension: {
|
|
739
|
+
leave: ({ directives, operationTypes }) => join(
|
|
740
|
+
["extend schema", join(directives, " "), block(operationTypes)],
|
|
741
|
+
" "
|
|
742
|
+
)
|
|
743
|
+
},
|
|
744
|
+
ScalarTypeExtension: {
|
|
745
|
+
leave: ({ name, directives }) => join(["extend scalar", name, join(directives, " ")], " ")
|
|
746
|
+
},
|
|
747
|
+
ObjectTypeExtension: {
|
|
748
|
+
leave: ({ name, interfaces, directives, fields }) => join(
|
|
749
|
+
[
|
|
750
|
+
"extend type",
|
|
751
|
+
name,
|
|
752
|
+
wrap("implements ", join(interfaces, " & ")),
|
|
753
|
+
join(directives, " "),
|
|
754
|
+
block(fields)
|
|
755
|
+
],
|
|
756
|
+
" "
|
|
757
|
+
)
|
|
758
|
+
},
|
|
759
|
+
InterfaceTypeExtension: {
|
|
760
|
+
leave: ({ name, interfaces, directives, fields }) => join(
|
|
761
|
+
[
|
|
762
|
+
"extend interface",
|
|
763
|
+
name,
|
|
764
|
+
wrap("implements ", join(interfaces, " & ")),
|
|
765
|
+
join(directives, " "),
|
|
766
|
+
block(fields)
|
|
767
|
+
],
|
|
768
|
+
" "
|
|
769
|
+
)
|
|
770
|
+
},
|
|
771
|
+
UnionTypeExtension: {
|
|
772
|
+
leave: ({ name, directives, types }) => join(
|
|
773
|
+
[
|
|
774
|
+
"extend union",
|
|
775
|
+
name,
|
|
776
|
+
join(directives, " "),
|
|
777
|
+
wrap("= ", join(types, " | "))
|
|
778
|
+
],
|
|
779
|
+
" "
|
|
780
|
+
)
|
|
781
|
+
},
|
|
782
|
+
EnumTypeExtension: {
|
|
783
|
+
leave: ({ name, directives, values }) => join(["extend enum", name, join(directives, " "), block(values)], " ")
|
|
784
|
+
},
|
|
785
|
+
InputObjectTypeExtension: {
|
|
786
|
+
leave: ({ name, directives, fields }) => join(["extend input", name, join(directives, " "), block(fields)], " ")
|
|
787
|
+
}
|
|
788
|
+
};
|
|
789
|
+
function join(maybeArray, separator = "") {
|
|
790
|
+
var _maybeArray$filter$jo;
|
|
791
|
+
return (_maybeArray$filter$jo = maybeArray === null || maybeArray === void 0 ? void 0 : maybeArray.filter((x) => x).join(separator)) !== null && _maybeArray$filter$jo !== void 0 ? _maybeArray$filter$jo : "";
|
|
792
|
+
}
|
|
793
|
+
function block(array) {
|
|
794
|
+
return wrap("{\n", indent(join(array, "\n")), "\n}");
|
|
795
|
+
}
|
|
796
|
+
function wrap(start, maybeString, end = "") {
|
|
797
|
+
return maybeString != null && maybeString !== "" ? start + maybeString + end : "";
|
|
798
|
+
}
|
|
799
|
+
function indent(str) {
|
|
800
|
+
return wrap(" ", str.replace(/\n/g, "\n "));
|
|
801
|
+
}
|
|
802
|
+
function hasMultilineItems(maybeArray) {
|
|
803
|
+
var _maybeArray$some;
|
|
804
|
+
return (_maybeArray$some = maybeArray === null || maybeArray === void 0 ? void 0 : maybeArray.some((str) => str.includes("\n"))) !== null && _maybeArray$some !== void 0 ? _maybeArray$some : false;
|
|
805
|
+
}
|
|
806
|
+
|
|
807
|
+
// src/device/index.ts
|
|
808
|
+
import { v4 as uuidv4 } from "uuid";
|
|
809
|
+
function getDeviceIdFromIndexedDB() {
|
|
810
|
+
return new Promise((resolve) => {
|
|
811
|
+
if (typeof indexedDB === "undefined") return resolve(null);
|
|
812
|
+
const request = indexedDB.open("DeviceDB", 1);
|
|
813
|
+
request.onupgradeneeded = () => {
|
|
814
|
+
const db = request.result;
|
|
815
|
+
db.createObjectStore("info");
|
|
816
|
+
};
|
|
817
|
+
request.onsuccess = () => {
|
|
818
|
+
const db = request.result;
|
|
819
|
+
const tx = db.transaction("info", "readonly");
|
|
820
|
+
const store = tx.objectStore("info");
|
|
821
|
+
const getReq = store.get("deviceId");
|
|
822
|
+
getReq.onsuccess = () => resolve(getReq.result ?? null);
|
|
823
|
+
getReq.onerror = () => resolve(null);
|
|
824
|
+
};
|
|
825
|
+
request.onerror = () => resolve(null);
|
|
826
|
+
});
|
|
827
|
+
}
|
|
828
|
+
function setDeviceIdToIndexedDB(id) {
|
|
829
|
+
return new Promise((resolve) => {
|
|
830
|
+
if (typeof indexedDB === "undefined") return resolve();
|
|
831
|
+
const request = indexedDB.open("DeviceDB", 1);
|
|
832
|
+
request.onupgradeneeded = () => {
|
|
833
|
+
const db = request.result;
|
|
834
|
+
db.createObjectStore("info");
|
|
835
|
+
};
|
|
836
|
+
request.onsuccess = () => {
|
|
837
|
+
const db = request.result;
|
|
838
|
+
const tx = db.transaction("info", "readwrite");
|
|
839
|
+
const store = tx.objectStore("info");
|
|
840
|
+
store.put(id, "deviceId");
|
|
841
|
+
tx.oncomplete = () => resolve();
|
|
842
|
+
tx.onerror = () => resolve();
|
|
843
|
+
};
|
|
844
|
+
request.onerror = () => resolve();
|
|
845
|
+
});
|
|
846
|
+
}
|
|
847
|
+
async function getBrowserDeviceInfo() {
|
|
848
|
+
let deviceId;
|
|
849
|
+
try {
|
|
850
|
+
const { load } = await import("./fp.esm-VY6KF7TP.js");
|
|
851
|
+
const fp = await load();
|
|
852
|
+
const result = await fp.get();
|
|
853
|
+
deviceId = result.visitorId;
|
|
854
|
+
} catch {
|
|
855
|
+
let id = await getDeviceIdFromIndexedDB();
|
|
856
|
+
if (!id) {
|
|
857
|
+
id = uuidv4();
|
|
858
|
+
await setDeviceIdToIndexedDB(id);
|
|
859
|
+
}
|
|
860
|
+
deviceId = id;
|
|
861
|
+
}
|
|
862
|
+
const deviceName = (() => {
|
|
863
|
+
const platform = navigator.platform || "unknown";
|
|
864
|
+
const width = screen.width || 0;
|
|
865
|
+
const height = screen.height || 0;
|
|
866
|
+
const colorDepth = screen.colorDepth || 24;
|
|
867
|
+
return `${platform}-${width}x${height}x${colorDepth}`;
|
|
868
|
+
})();
|
|
869
|
+
return {
|
|
870
|
+
deviceId,
|
|
871
|
+
deviceName,
|
|
872
|
+
env: "browser"
|
|
873
|
+
};
|
|
874
|
+
}
|
|
875
|
+
async function getNodeDeviceInfo() {
|
|
876
|
+
const os = await import("os");
|
|
877
|
+
const machine = await import("node-machine-id");
|
|
878
|
+
const machineIdSync = machine.machineIdSync || machine.default?.machineIdSync;
|
|
879
|
+
if (typeof machineIdSync !== "function") {
|
|
880
|
+
throw new Error("node-machine-id: machineIdSync not found");
|
|
881
|
+
}
|
|
882
|
+
const id = machineIdSync(true);
|
|
883
|
+
return {
|
|
884
|
+
deviceId: id,
|
|
885
|
+
deviceName: os.hostname(),
|
|
886
|
+
env: "node"
|
|
887
|
+
};
|
|
888
|
+
}
|
|
889
|
+
async function getDeviceInfo() {
|
|
890
|
+
const isBrowser2 = typeof window !== "undefined" && typeof navigator !== "undefined" && typeof screen !== "undefined";
|
|
891
|
+
return isBrowser2 ? getBrowserDeviceInfo() : getNodeDeviceInfo();
|
|
892
|
+
}
|
|
893
|
+
|
|
894
|
+
// src/core/executor.ts
|
|
895
|
+
async function execute(payload) {
|
|
896
|
+
const client2 = getClient();
|
|
897
|
+
return client2.request(payload.query, payload.variables);
|
|
898
|
+
}
|
|
899
|
+
|
|
900
|
+
// src/builders/baseType.ts
|
|
901
|
+
function buildWhere(where) {
|
|
902
|
+
if (!where) return "";
|
|
903
|
+
const parts = [];
|
|
904
|
+
for (const key in where) {
|
|
905
|
+
const value = where[key];
|
|
906
|
+
if (key === "_and" || key === "_or") {
|
|
907
|
+
const sub = value.map((w) => `{ ${buildWhere(w)} }`).filter(Boolean).join(", ");
|
|
908
|
+
if (sub) parts.push(`${key}: [${sub}]`);
|
|
909
|
+
} else if (key === "_not") {
|
|
910
|
+
const sub = buildWhere(value);
|
|
911
|
+
if (sub) parts.push(`${key}: { ${sub} }`);
|
|
912
|
+
} else if (typeof value === "object" && value !== null) {
|
|
913
|
+
const conds = Object.entries(value).map(([op, val]) => {
|
|
914
|
+
if (typeof val === "string" && val.startsWith("$")) return `${op}: ${val}`;
|
|
915
|
+
return `${op}: ${JSON.stringify(String(val))}`;
|
|
916
|
+
}).join(", ");
|
|
917
|
+
parts.push(`${key}: { ${conds} }`);
|
|
918
|
+
} else {
|
|
919
|
+
if (typeof value === "string" && value.startsWith("$")) {
|
|
920
|
+
parts.push(`${key}: ${value}`);
|
|
921
|
+
} else {
|
|
922
|
+
parts.push(`${key}: ${JSON.stringify(String(value))}`);
|
|
923
|
+
}
|
|
924
|
+
}
|
|
925
|
+
}
|
|
926
|
+
return parts.join(", ");
|
|
927
|
+
}
|
|
928
|
+
function buildFields(fields) {
|
|
929
|
+
return fields.map((f) => {
|
|
930
|
+
if (typeof f === "string") return f;
|
|
931
|
+
const [key, node] = Object.entries(f)[0];
|
|
932
|
+
const args = [];
|
|
933
|
+
if (node.where) args.push(`where: { ${buildWhere(node.where)} }`);
|
|
934
|
+
if (node.distinctOn) args.push(`distinct_on: [${node.distinctOn.map((s) => `${s}`).join(" ")}]`);
|
|
935
|
+
if (node.orderBy)
|
|
936
|
+
args.push(
|
|
937
|
+
`order_by: {${Object.entries(node.orderBy).map(([k, v]) => `${k}: ${v}`).join(" ")}}`
|
|
938
|
+
);
|
|
939
|
+
if (node.limit !== void 0) args.push(`limit: ${node.limit}`);
|
|
940
|
+
if (node.offset !== void 0) args.push(`offset: ${node.offset}`);
|
|
941
|
+
const argsStr = args.length ? `(${args.join(" ")})` : "";
|
|
942
|
+
return `${key}${argsStr} { ${buildFields(node.fields)} }`;
|
|
943
|
+
}).join(" ");
|
|
944
|
+
}
|
|
945
|
+
function buildMutationFields(fields) {
|
|
946
|
+
return `affected_rows returning { ${buildFields(fields)} }`;
|
|
947
|
+
}
|
|
948
|
+
function buildDataValue(data) {
|
|
949
|
+
const parts = [];
|
|
950
|
+
for (const key in data) {
|
|
951
|
+
const value = data[key];
|
|
952
|
+
if (value === null || value === void 0) continue;
|
|
953
|
+
if (typeof value === "string" && value.startsWith("$")) {
|
|
954
|
+
parts.push(`${key}: ${value}`);
|
|
955
|
+
} else if (typeof value === "object" && !Array.isArray(value) && value.constructor === Object) {
|
|
956
|
+
parts.push(`${key}: { ${buildDataValue(value)} }`);
|
|
957
|
+
} else if (Array.isArray(value)) {
|
|
958
|
+
const arrStr = value.map((v) => {
|
|
959
|
+
if (typeof v === "string" && v.startsWith("$")) return v;
|
|
960
|
+
if (typeof v === "object" && v !== null && v.constructor === Object) {
|
|
961
|
+
return `{ ${buildDataValue(v)} }`;
|
|
962
|
+
}
|
|
963
|
+
return formatGraphQLValue(v);
|
|
964
|
+
}).join(" ");
|
|
965
|
+
parts.push(`${key}: [${arrStr}]`);
|
|
966
|
+
} else {
|
|
967
|
+
parts.push(`${key}: ${formatGraphQLValue(value)}`);
|
|
968
|
+
}
|
|
969
|
+
}
|
|
970
|
+
return parts.join(" ");
|
|
971
|
+
}
|
|
972
|
+
function formatGraphQLValue(value) {
|
|
973
|
+
if (value === null) return "null";
|
|
974
|
+
if (typeof value === "string") {
|
|
975
|
+
return JSON.stringify(value);
|
|
976
|
+
}
|
|
977
|
+
if (typeof value === "number" || typeof value === "boolean") {
|
|
978
|
+
return String(value);
|
|
979
|
+
}
|
|
980
|
+
return JSON.stringify(value);
|
|
981
|
+
}
|
|
982
|
+
function toPascalCase(str) {
|
|
983
|
+
const camel = str.replace(/[-_ ]+(\w)/g, (_, c) => c ? c.toUpperCase() : "").replace(/^\w/, (c) => c.toLowerCase());
|
|
984
|
+
return camel.charAt(0).toUpperCase() + camel.slice(1);
|
|
985
|
+
}
|
|
986
|
+
function buildCommonResultSelection(dataFields) {
|
|
987
|
+
if (dataFields && dataFields.length > 0) {
|
|
988
|
+
return `success code message data { ${buildFields(dataFields)} }`;
|
|
989
|
+
}
|
|
990
|
+
return `success code message data`;
|
|
991
|
+
}
|
|
992
|
+
|
|
993
|
+
// src/builders/query.ts
|
|
994
|
+
function buildGraphQLQueryList(input) {
|
|
995
|
+
const { operationName, fields, variables, where, orderBy, distinctOn, limit, offset } = input;
|
|
996
|
+
const varDefs = variables ? Object.keys(variables).map((k) => `$${k}: String!`).join(", ") : "";
|
|
997
|
+
const topArgs = [];
|
|
998
|
+
if (where) topArgs.push(`where: { ${buildWhere(where)} }`);
|
|
999
|
+
if (distinctOn) topArgs.push(`distinct_on: [${distinctOn.map((s) => `${s}`).join(" ")}]`);
|
|
1000
|
+
if (orderBy)
|
|
1001
|
+
topArgs.push(
|
|
1002
|
+
`order_by: {${Object.entries(orderBy).map(([k, v]) => `${k}: ${v}`).join(" ")}}`
|
|
1003
|
+
);
|
|
1004
|
+
if (limit !== void 0) topArgs.push(`limit: ${limit}`);
|
|
1005
|
+
if (offset !== void 0) topArgs.push(`offset: ${offset}`);
|
|
1006
|
+
const topArgsStr = topArgs.length ? `(${topArgs.join(" ")})` : "";
|
|
1007
|
+
const query2 = `query ${operationName}${varDefs ? `(${varDefs})` : ""} { ${operationName}${topArgsStr} ${fields ? "{" + buildFields(fields) + "}" : ""} }`;
|
|
1008
|
+
return { query: query2, variables };
|
|
1009
|
+
}
|
|
1010
|
+
function buildGraphQLQueryByIdFixed(queryByIdInput) {
|
|
1011
|
+
const { pk, fields, operationName } = queryByIdInput;
|
|
1012
|
+
const variables = { id: pk };
|
|
1013
|
+
const query2 = `query ${operationName + "_by_pk"}($id: Long!) {
|
|
1014
|
+
${operationName + "_by_pk"}(id: $id) {
|
|
1015
|
+
${buildFields(fields)}
|
|
1016
|
+
}
|
|
1017
|
+
}`;
|
|
1018
|
+
return { query: query2, variables };
|
|
1019
|
+
}
|
|
1020
|
+
function buildGraphQLQueryPageList(input) {
|
|
1021
|
+
const { operationName, fields, variables, where, orderBy, distinctOn, page, size } = input;
|
|
1022
|
+
const varDefs = variables ? Object.keys(variables).map((k) => `$${k}: String!`).join(", ") : "";
|
|
1023
|
+
const topArgs = [];
|
|
1024
|
+
if (where) topArgs.push(`where: { ${buildWhere(where)} }`);
|
|
1025
|
+
if (distinctOn) topArgs.push(`distinct_on: [${distinctOn.map((s) => `${s}`).join(" ")}]`);
|
|
1026
|
+
if (orderBy)
|
|
1027
|
+
topArgs.push(
|
|
1028
|
+
`order_by: {${Object.entries(orderBy).map(([k, v]) => `${k}: ${v}`).join(" ")}}`
|
|
1029
|
+
);
|
|
1030
|
+
if (size !== void 0) topArgs.push(`size: ${size}`);
|
|
1031
|
+
if (page !== void 0) topArgs.push(`page: ${page}`);
|
|
1032
|
+
const topArgsStr = topArgs.length ? `(${topArgs.join(" ")})` : "";
|
|
1033
|
+
const query2 = `query ${"get" + toPascalCase(operationName) + "PageList"}${varDefs ? `(${varDefs})` : ""} { ${"get" + toPascalCase(operationName) + "PageList"}${topArgsStr} { hasMore list{${buildFields(fields)}} page size total } }`;
|
|
1034
|
+
return { query: query2, variables };
|
|
1035
|
+
}
|
|
1036
|
+
function buildGraphQLQueryAggregate(input) {
|
|
1037
|
+
const { operationName, fields, aggregateFields, variables, where, distinctOn } = input;
|
|
1038
|
+
const varDefs = variables ? Object.keys(variables).map((k) => `$${k}: String!`).join(", ") : "";
|
|
1039
|
+
const topArgs = [];
|
|
1040
|
+
if (where) topArgs.push(`where: { ${buildWhere(where)} }`);
|
|
1041
|
+
if (distinctOn) topArgs.push(`distinct_on: [${distinctOn.map((s) => `${s}`).join(" ")}]`);
|
|
1042
|
+
const topArgsStr = topArgs.length ? `(${topArgs.join(" ")})` : "";
|
|
1043
|
+
const aggregateParts = [];
|
|
1044
|
+
if (aggregateFields) {
|
|
1045
|
+
if (aggregateFields.count) aggregateParts.push("count");
|
|
1046
|
+
["sum", "avg", "max", "min"].forEach((key) => {
|
|
1047
|
+
const fields2 = aggregateFields[key];
|
|
1048
|
+
if (fields2 && fields2.length > 0) {
|
|
1049
|
+
aggregateParts.push(`${key} { ${fields2.join(" ")} }`);
|
|
1050
|
+
}
|
|
1051
|
+
});
|
|
1052
|
+
} else {
|
|
1053
|
+
aggregateParts.push("count");
|
|
1054
|
+
}
|
|
1055
|
+
const aggregateStr = aggregateParts.join(" ");
|
|
1056
|
+
const query2 = `
|
|
1057
|
+
query ${operationName + "_aggregateount"}${varDefs ? `(${varDefs})` : ""} {
|
|
1058
|
+
${operationName}_aggregateount${topArgsStr} {
|
|
1059
|
+
aggregate { ${aggregateStr} }
|
|
1060
|
+
nodes { ${buildFields(fields)} }
|
|
1061
|
+
}
|
|
1062
|
+
}
|
|
1063
|
+
`;
|
|
1064
|
+
return { query: query2, variables };
|
|
1065
|
+
}
|
|
1066
|
+
|
|
1067
|
+
// src/builders/mutation.ts
|
|
1068
|
+
function buildGraphQLMutationInsertOne(input) {
|
|
1069
|
+
const { operationName, fields, data, variables } = input;
|
|
1070
|
+
const entityName = operationName.toLowerCase();
|
|
1071
|
+
const varDefs = variables ? Object.keys(variables).map((k) => `$${k}: String!`).join(", ") : "";
|
|
1072
|
+
let dataArg;
|
|
1073
|
+
if (variables && variables.data) {
|
|
1074
|
+
dataArg = "$data";
|
|
1075
|
+
} else {
|
|
1076
|
+
dataArg = `{ ${buildDataValue(data)} }`;
|
|
1077
|
+
}
|
|
1078
|
+
const finalVariables = variables || {};
|
|
1079
|
+
if (!variables || !variables.data) {
|
|
1080
|
+
finalVariables.data = data;
|
|
1081
|
+
}
|
|
1082
|
+
const mutationName = `insert_${entityName}_one`;
|
|
1083
|
+
const query2 = `mutation ${mutationName}${varDefs ? `(${varDefs})` : ""} {
|
|
1084
|
+
${mutationName}(${operationName}: ${dataArg}) {
|
|
1085
|
+
${buildMutationFields(fields)}
|
|
1086
|
+
}
|
|
1087
|
+
}`;
|
|
1088
|
+
return { query: query2, variables: finalVariables };
|
|
1089
|
+
}
|
|
1090
|
+
function buildGraphQLMutationBatchInsert(input) {
|
|
1091
|
+
const { operationName, fields, datas, variables } = input;
|
|
1092
|
+
const entityName = operationName.toLowerCase();
|
|
1093
|
+
const varDefs = variables ? Object.keys(variables).map((k) => `$${k}: String!`).join(", ") : "";
|
|
1094
|
+
let datasArg;
|
|
1095
|
+
if (variables && variables.datas) {
|
|
1096
|
+
datasArg = "$datas";
|
|
1097
|
+
} else {
|
|
1098
|
+
const datasArr = datas.map((d) => `{ ${buildDataValue(d)} }`).join(" ");
|
|
1099
|
+
datasArg = `[${datasArr}]`;
|
|
1100
|
+
}
|
|
1101
|
+
const finalVariables = variables || {};
|
|
1102
|
+
if (!variables || !variables.datas) {
|
|
1103
|
+
finalVariables.datas = datas;
|
|
1104
|
+
}
|
|
1105
|
+
const mutationName = `insert_${entityName}s`;
|
|
1106
|
+
const query2 = `mutation ${mutationName}${varDefs ? `(${varDefs})` : ""} {
|
|
1107
|
+
${mutationName}(${operationName}s: ${datasArg}) {
|
|
1108
|
+
affected_rows
|
|
1109
|
+
returning { ${buildFields(fields)} }
|
|
1110
|
+
}
|
|
1111
|
+
}`;
|
|
1112
|
+
return { query: query2, variables: finalVariables };
|
|
1113
|
+
}
|
|
1114
|
+
function buildGraphQLMutationUpdate(input) {
|
|
1115
|
+
const { operationName, fields, _set, where, variables } = input;
|
|
1116
|
+
const entityName = operationName.toLowerCase();
|
|
1117
|
+
const varDefs = variables ? Object.keys(variables).map((k) => `$${k}: String!`).join(", ") : "";
|
|
1118
|
+
const args = [];
|
|
1119
|
+
let setArg;
|
|
1120
|
+
if (variables && variables._set) {
|
|
1121
|
+
setArg = "$_set";
|
|
1122
|
+
} else {
|
|
1123
|
+
setArg = `{ ${buildDataValue(_set)} }`;
|
|
1124
|
+
}
|
|
1125
|
+
args.push(`_set: ${setArg}`);
|
|
1126
|
+
args.push(`where: { ${buildWhere(where)} }`);
|
|
1127
|
+
const finalVariables = variables || {};
|
|
1128
|
+
if (!variables || !variables._set) {
|
|
1129
|
+
finalVariables._set = _set;
|
|
1130
|
+
}
|
|
1131
|
+
const mutationName = `update_${entityName}`;
|
|
1132
|
+
const query2 = `mutation ${mutationName}${varDefs ? `(${varDefs})` : ""} {
|
|
1133
|
+
${mutationName}(${args.join(", ")}) {
|
|
1134
|
+
${buildMutationFields(fields)}
|
|
1135
|
+
}
|
|
1136
|
+
}`;
|
|
1137
|
+
return { query: query2, variables: finalVariables };
|
|
1138
|
+
}
|
|
1139
|
+
function buildGraphQLMutationBatchUpdate(input) {
|
|
1140
|
+
const { operationName, fields, _set, variables } = input;
|
|
1141
|
+
const entityName = operationName.toLowerCase();
|
|
1142
|
+
const varDefs = variables ? Object.keys(variables).map((k) => `$${k}: String!`).join(", ") : "";
|
|
1143
|
+
let setArg;
|
|
1144
|
+
if (variables && variables._set) {
|
|
1145
|
+
setArg = "$_set";
|
|
1146
|
+
} else {
|
|
1147
|
+
const setsArr = _set.map((s) => `{ ${buildDataValue(s)} }`).join(" ");
|
|
1148
|
+
setArg = `[${setsArr}]`;
|
|
1149
|
+
}
|
|
1150
|
+
const finalVariables = variables || {};
|
|
1151
|
+
if (!variables || !variables._set) {
|
|
1152
|
+
finalVariables._set = _set;
|
|
1153
|
+
}
|
|
1154
|
+
const mutationName = `update_${entityName}_many`;
|
|
1155
|
+
const query2 = `mutation ${mutationName}${varDefs ? `(${varDefs})` : ""} {
|
|
1156
|
+
${mutationName}(_set: ${setArg}) {
|
|
1157
|
+
affected_rows
|
|
1158
|
+
returning { ${buildFields(fields)} }
|
|
1159
|
+
}
|
|
1160
|
+
}`;
|
|
1161
|
+
return { query: query2, variables: finalVariables };
|
|
1162
|
+
}
|
|
1163
|
+
function buildGraphQLMutationUpdateByPk(input) {
|
|
1164
|
+
const { operationName, fields, _set, pk_columns, variables } = input;
|
|
1165
|
+
const entityName = operationName.toLowerCase();
|
|
1166
|
+
const varDefs = variables ? Object.keys(variables).map((k) => `$${k}: String!`).join(", ") : "";
|
|
1167
|
+
const args = [];
|
|
1168
|
+
let setArg;
|
|
1169
|
+
if (variables && variables._set) {
|
|
1170
|
+
setArg = "$_set";
|
|
1171
|
+
} else {
|
|
1172
|
+
setArg = `{ ${buildDataValue(_set)} }`;
|
|
1173
|
+
}
|
|
1174
|
+
args.push(`_set: ${setArg}`);
|
|
1175
|
+
args.push(`pk_columns: ${formatGraphQLValue(pk_columns)}`);
|
|
1176
|
+
const finalVariables = variables || {};
|
|
1177
|
+
if (!variables || !variables._set) {
|
|
1178
|
+
finalVariables._set = _set;
|
|
1179
|
+
}
|
|
1180
|
+
const mutationName = `update_${entityName}_by_pk`;
|
|
1181
|
+
const query2 = `mutation ${mutationName}${varDefs ? `(${varDefs})` : ""} {
|
|
1182
|
+
${mutationName}(${args.join(", ")}) {
|
|
1183
|
+
${buildMutationFields(fields)}
|
|
1184
|
+
}
|
|
1185
|
+
}`;
|
|
1186
|
+
return { query: query2, variables: finalVariables };
|
|
1187
|
+
}
|
|
1188
|
+
function buildGraphQLMutationDeleteById(input) {
|
|
1189
|
+
const { operationName, fields, pk_columns, variables } = input;
|
|
1190
|
+
const entityName = operationName.toLowerCase();
|
|
1191
|
+
const varDefs = variables ? Object.keys(variables).map((k) => `$${k}: String!`).join(", ") : "";
|
|
1192
|
+
const args = `pk_columns: ${formatGraphQLValue(pk_columns)}`;
|
|
1193
|
+
const mutationName = `delete_${entityName}_by_pk`;
|
|
1194
|
+
const query2 = `mutation ${mutationName}${varDefs ? `(${varDefs})` : ""} {
|
|
1195
|
+
${mutationName}(${args}) {
|
|
1196
|
+
${buildMutationFields(fields)}
|
|
1197
|
+
}
|
|
1198
|
+
}`;
|
|
1199
|
+
return { query: query2, variables: variables || {} };
|
|
1200
|
+
}
|
|
1201
|
+
function buildGraphQLMutationDelete(input) {
|
|
1202
|
+
const { operationName, fields, where, variables } = input;
|
|
1203
|
+
const entityName = operationName.toLowerCase();
|
|
1204
|
+
const varDefs = variables ? Object.keys(variables).map((k) => `$${k}: String!`).join(", ") : "";
|
|
1205
|
+
const args = `where: { ${buildWhere(where)} }`;
|
|
1206
|
+
const mutationName = `delete_${entityName}`;
|
|
1207
|
+
const query2 = `mutation ${mutationName}${varDefs ? `(${varDefs})` : ""} {
|
|
1208
|
+
${mutationName}(${args}) {
|
|
1209
|
+
affected_rows
|
|
1210
|
+
returning { ${buildFields(fields)} }
|
|
1211
|
+
}
|
|
1212
|
+
}`;
|
|
1213
|
+
return { query: query2, variables: variables || {} };
|
|
1214
|
+
}
|
|
1215
|
+
|
|
1216
|
+
// src/builders/sms.ts
|
|
1217
|
+
function buildGraphQLMutationSendCode(input) {
|
|
1218
|
+
const { phone } = input;
|
|
1219
|
+
const finalVariables = { ...input.variables || {} };
|
|
1220
|
+
if (finalVariables.phone === void 0) finalVariables.phone = phone;
|
|
1221
|
+
const varDefs = Object.keys(finalVariables).length ? Object.keys(finalVariables).map((k) => `$${k}: String!`).join(", ") : "";
|
|
1222
|
+
const selection = buildCommonResultSelection(input.dataFields);
|
|
1223
|
+
const query2 = `mutation sendCode${varDefs ? `(${varDefs})` : ""} {
|
|
1224
|
+
sendCode(phone: $phone) {
|
|
1225
|
+
${selection}
|
|
1226
|
+
}
|
|
1227
|
+
}`;
|
|
1228
|
+
return { query: query2, variables: finalVariables };
|
|
1229
|
+
}
|
|
1230
|
+
function buildGraphQLMutationVerifyCode(input) {
|
|
1231
|
+
const { code, phone } = input;
|
|
1232
|
+
const finalVariables = { ...input.variables || {} };
|
|
1233
|
+
if (finalVariables.code === void 0) finalVariables.code = code;
|
|
1234
|
+
if (finalVariables.phone === void 0) finalVariables.phone = phone;
|
|
1235
|
+
const varDefs = Object.keys(finalVariables).length ? Object.keys(finalVariables).map((k) => `$${k}: String!`).join(", ") : "";
|
|
1236
|
+
const query2 = `mutation verifyCode${varDefs ? `(${varDefs})` : ""} {
|
|
1237
|
+
verifyCode(code: $code, phone: $phone) {
|
|
1238
|
+
${buildCommonResultSelection()}
|
|
1239
|
+
}
|
|
1240
|
+
}`;
|
|
1241
|
+
return { query: query2, variables: finalVariables };
|
|
1242
|
+
}
|
|
1243
|
+
|
|
1244
|
+
// src/builders/auth.ts
|
|
1245
|
+
function buildGraphQLMutationLogin(input) {
|
|
1246
|
+
const fields = [
|
|
1247
|
+
"deviceId",
|
|
1248
|
+
"deviceName",
|
|
1249
|
+
"expireAt",
|
|
1250
|
+
"lastRefreshTime",
|
|
1251
|
+
"loginAccount",
|
|
1252
|
+
"loginTime",
|
|
1253
|
+
"permissions",
|
|
1254
|
+
"refreshExpireAt",
|
|
1255
|
+
"refreshToken",
|
|
1256
|
+
"requestIp",
|
|
1257
|
+
"roles",
|
|
1258
|
+
"token",
|
|
1259
|
+
"userAgent",
|
|
1260
|
+
"userId"
|
|
1261
|
+
];
|
|
1262
|
+
const { account, password, deviceId } = input;
|
|
1263
|
+
const finalVariables = { ...input.variables || {} };
|
|
1264
|
+
if (finalVariables.account === void 0) finalVariables.account = account;
|
|
1265
|
+
if (finalVariables.password === void 0) finalVariables.password = password;
|
|
1266
|
+
if (finalVariables.deviceId === void 0 && deviceId != void 0) finalVariables.deviceId = deviceId;
|
|
1267
|
+
const varDefs = Object.keys(finalVariables).length ? Object.keys(finalVariables).map((k) => `$${k}: String!`).join(", ") : "";
|
|
1268
|
+
const query2 = `mutation login${varDefs ? `(${varDefs})` : ""} {
|
|
1269
|
+
login(account: $account, password: $password ${deviceId ? ", deviceId: $deviceId" : ""}) {
|
|
1270
|
+
${buildFields(fields)}
|
|
1271
|
+
}
|
|
1272
|
+
}`;
|
|
1273
|
+
return { query: query2, variables: finalVariables };
|
|
1274
|
+
}
|
|
1275
|
+
function buildGraphQLMutationRegisterUser(input) {
|
|
1276
|
+
const { user, fields } = input;
|
|
1277
|
+
const finalVariables = { ...input.variables || {} };
|
|
1278
|
+
const useVar = finalVariables.user !== void 0;
|
|
1279
|
+
const varDefs = Object.keys(finalVariables).length ? Object.keys(finalVariables).map((k) => `$${k}: String!`).join(", ") : "";
|
|
1280
|
+
const userArg = useVar ? "$user" : `{ ${buildDataValue(user)} }`;
|
|
1281
|
+
const query2 = `mutation registerUser${varDefs ? `(${varDefs})` : ""} {
|
|
1282
|
+
registerUser(user: ${userArg}) {
|
|
1283
|
+
${buildFields(fields)}
|
|
1284
|
+
}
|
|
1285
|
+
}`;
|
|
1286
|
+
return { query: query2, variables: finalVariables };
|
|
1287
|
+
}
|
|
1288
|
+
function buildGraphQLMutationLogout(input = {}) {
|
|
1289
|
+
const finalVariables = { ...input.variables || {} };
|
|
1290
|
+
const varDefs = Object.keys(finalVariables).length ? Object.keys(finalVariables).map((k) => `$${k}: String!`).join(", ") : "";
|
|
1291
|
+
const query2 = `mutation logout${varDefs ? `(${varDefs})` : ""} {
|
|
1292
|
+
logout {
|
|
1293
|
+
${buildCommonResultSelection(input.dataFields)}
|
|
1294
|
+
}
|
|
1295
|
+
}`;
|
|
1296
|
+
return { query: query2, variables: finalVariables };
|
|
1297
|
+
}
|
|
1298
|
+
function buildGraphQLMutationLogoutAllDevices(input = {}) {
|
|
1299
|
+
const finalVariables = { ...input.variables || {} };
|
|
1300
|
+
const varDefs = Object.keys(finalVariables).length ? Object.keys(finalVariables).map((k) => `$${k}: String!`).join(", ") : "";
|
|
1301
|
+
const query2 = `mutation logoutAllDevices${varDefs ? `(${varDefs})` : ""} {
|
|
1302
|
+
logoutAllDevices {
|
|
1303
|
+
${buildCommonResultSelection(input.dataFields)}
|
|
1304
|
+
}
|
|
1305
|
+
}`;
|
|
1306
|
+
return { query: query2, variables: finalVariables };
|
|
1307
|
+
}
|
|
1308
|
+
function buildGraphQLMutationLogoutDevice(input) {
|
|
1309
|
+
const { deviceId } = input;
|
|
1310
|
+
const finalVariables = { ...input.variables || {} };
|
|
1311
|
+
if (finalVariables.deviceId === void 0) finalVariables.deviceId = deviceId;
|
|
1312
|
+
const varDefs = Object.keys(finalVariables).length ? Object.keys(finalVariables).map((k) => `$${k}: String!`).join(", ") : "";
|
|
1313
|
+
const query2 = `mutation logoutDevice${varDefs ? `(${varDefs})` : ""} {
|
|
1314
|
+
logoutDevice(deviceId: $deviceId) {
|
|
1315
|
+
${buildCommonResultSelection(input.dataFields)}
|
|
1316
|
+
}
|
|
1317
|
+
}`;
|
|
1318
|
+
return { query: query2, variables: finalVariables };
|
|
1319
|
+
}
|
|
1320
|
+
function buildGraphQLMutationRefreshToken(input) {
|
|
1321
|
+
const fields = [
|
|
1322
|
+
"deviceId",
|
|
1323
|
+
"deviceName",
|
|
1324
|
+
"expireAt",
|
|
1325
|
+
"lastRefreshTime",
|
|
1326
|
+
"loginAccount",
|
|
1327
|
+
"loginTime",
|
|
1328
|
+
"permissions",
|
|
1329
|
+
"refreshExpireAt",
|
|
1330
|
+
"refreshToken",
|
|
1331
|
+
"requestIp",
|
|
1332
|
+
"roles",
|
|
1333
|
+
"token",
|
|
1334
|
+
"userAgent",
|
|
1335
|
+
"userId"
|
|
1336
|
+
];
|
|
1337
|
+
const { refreshToken } = input;
|
|
1338
|
+
const finalVariables = { ...input.variables || {} };
|
|
1339
|
+
if (finalVariables.refreshToken === void 0) finalVariables.refreshToken = refreshToken;
|
|
1340
|
+
const varDefs = Object.keys(finalVariables).length ? Object.keys(finalVariables).map((k) => `$${k}: String!`).join(", ") : "";
|
|
1341
|
+
const query2 = `mutation refreshToken${varDefs ? `(${varDefs})` : ""} {
|
|
1342
|
+
refreshToken(refreshToken: $refreshToken) {
|
|
1343
|
+
${buildFields(fields)}
|
|
1344
|
+
}
|
|
1345
|
+
}`;
|
|
1346
|
+
return { query: query2, variables: finalVariables };
|
|
1347
|
+
}
|
|
1348
|
+
|
|
1349
|
+
// src/rateLimit/rateLimitConfig.ts
|
|
1350
|
+
var rateLimitConfig = {
|
|
1351
|
+
defaultRules: {
|
|
1352
|
+
query: { max: 10, window: 1, debounce: 0 },
|
|
1353
|
+
mutation: { max: 3, window: 1, debounce: 200 }
|
|
1354
|
+
},
|
|
1355
|
+
custom: {
|
|
1356
|
+
login: { max: 1, window: 5, debounce: 0 },
|
|
1357
|
+
refreshToken: { max: 2, window: 5, debounce: 0 }
|
|
1358
|
+
}
|
|
1359
|
+
};
|
|
1360
|
+
|
|
1361
|
+
// src/rateLimit/rateLimit.ts
|
|
1362
|
+
var trackers = /* @__PURE__ */ new Map();
|
|
1363
|
+
function getRule(operateName, type, config) {
|
|
1364
|
+
return config.custom?.[operateName] || config.defaultRules[type];
|
|
1365
|
+
}
|
|
1366
|
+
function rateLimit(operateName, type, fn, config = rateLimitConfig) {
|
|
1367
|
+
const rule = getRule(operateName, type, config);
|
|
1368
|
+
const now = Date.now();
|
|
1369
|
+
const key = `${type}::${operateName}`;
|
|
1370
|
+
if (!trackers.has(key)) trackers.set(key, { timestamps: [] });
|
|
1371
|
+
const tracker = trackers.get(key);
|
|
1372
|
+
tracker.timestamps = tracker.timestamps.filter((ts) => now - ts < rule.window * 1e3);
|
|
1373
|
+
return new Promise((resolve, reject) => {
|
|
1374
|
+
const exec = () => {
|
|
1375
|
+
if (tracker.timestamps.length >= rule.max) {
|
|
1376
|
+
return reject(new Error(`Rate limit exceeded for ${operateName}`));
|
|
1377
|
+
}
|
|
1378
|
+
tracker.timestamps.push(Date.now());
|
|
1379
|
+
fn().then(resolve).catch(reject);
|
|
1380
|
+
};
|
|
1381
|
+
if (rule.debounce > 0) {
|
|
1382
|
+
if (tracker.timeout) clearTimeout(tracker.timeout);
|
|
1383
|
+
tracker.timeout = setTimeout(exec, rule.debounce);
|
|
1384
|
+
} else {
|
|
1385
|
+
exec();
|
|
1386
|
+
}
|
|
1387
|
+
});
|
|
1388
|
+
}
|
|
1389
|
+
|
|
1390
|
+
// src/cache/memoryCache.ts
|
|
1391
|
+
var DEFAULT_TTL = 5 * 60 * 1e3;
|
|
1392
|
+
var cache = /* @__PURE__ */ new Map();
|
|
1393
|
+
function getCacheKey(key, variables) {
|
|
1394
|
+
return variables ? `${key}::${JSON.stringify(variables)}` : key;
|
|
1395
|
+
}
|
|
1396
|
+
function getFromCache(key) {
|
|
1397
|
+
const item = cache.get(key);
|
|
1398
|
+
if (!item) return null;
|
|
1399
|
+
if (Date.now() > item.expire) {
|
|
1400
|
+
cache.delete(key);
|
|
1401
|
+
return null;
|
|
1402
|
+
}
|
|
1403
|
+
return item.data;
|
|
1404
|
+
}
|
|
1405
|
+
function setCache(key, data, ttl = DEFAULT_TTL) {
|
|
1406
|
+
cache.set(key, { data, expire: Date.now() + ttl });
|
|
1407
|
+
}
|
|
1408
|
+
function clearCache() {
|
|
1409
|
+
cache.clear();
|
|
1410
|
+
}
|
|
1411
|
+
|
|
1412
|
+
// src/core/api/auth.ts
|
|
1413
|
+
var auth = {
|
|
1414
|
+
async login(input) {
|
|
1415
|
+
return rateLimit("login", "mutation", async () => {
|
|
1416
|
+
const { query: query2, variables } = buildGraphQLMutationLogin(input);
|
|
1417
|
+
const result = await execute({ query: query2, variables });
|
|
1418
|
+
setLoginInfo(result.login, input.remember);
|
|
1419
|
+
clearCache();
|
|
1420
|
+
return result;
|
|
1421
|
+
}, rateLimitConfig);
|
|
1422
|
+
},
|
|
1423
|
+
async refreshToken(input) {
|
|
1424
|
+
return rateLimit("refreshToken", "mutation", async () => {
|
|
1425
|
+
const { query: query2, variables } = buildGraphQLMutationRefreshToken(input);
|
|
1426
|
+
const result = await execute({ query: query2, variables });
|
|
1427
|
+
setLoginInfo(result.refreshToken, input.remember);
|
|
1428
|
+
clearCache();
|
|
1429
|
+
return result;
|
|
1430
|
+
}, rateLimitConfig);
|
|
1431
|
+
},
|
|
1432
|
+
async register(input) {
|
|
1433
|
+
return rateLimit("registerUser", "mutation", async () => {
|
|
1434
|
+
const { query: query2, variables } = buildGraphQLMutationRegisterUser(input);
|
|
1435
|
+
const result = await execute({ query: query2, variables });
|
|
1436
|
+
clearCache();
|
|
1437
|
+
return result;
|
|
1438
|
+
}, rateLimitConfig);
|
|
1439
|
+
},
|
|
1440
|
+
async logout() {
|
|
1441
|
+
return rateLimit("logout", "mutation", async () => {
|
|
1442
|
+
const { query: query2, variables } = buildGraphQLMutationLogout();
|
|
1443
|
+
const result = await execute({ query: query2, variables });
|
|
1444
|
+
removeLoginInfo();
|
|
1445
|
+
clearCache();
|
|
1446
|
+
return result;
|
|
1447
|
+
}, rateLimitConfig);
|
|
1448
|
+
},
|
|
1449
|
+
async logoutAllDevices() {
|
|
1450
|
+
return rateLimit("logoutAllDevices", "mutation", async () => {
|
|
1451
|
+
const { query: query2, variables } = buildGraphQLMutationLogoutAllDevices();
|
|
1452
|
+
const result = await execute({ query: query2, variables });
|
|
1453
|
+
removeLoginInfo();
|
|
1454
|
+
clearCache();
|
|
1455
|
+
return result;
|
|
1456
|
+
}, rateLimitConfig);
|
|
1457
|
+
},
|
|
1458
|
+
async logoutDevice(deviceId) {
|
|
1459
|
+
return rateLimit("logoutDevice", "mutation", async () => {
|
|
1460
|
+
const { query: query2, variables } = buildGraphQLMutationLogoutDevice({ deviceId });
|
|
1461
|
+
const result = await execute({ query: query2, variables });
|
|
1462
|
+
if (getLoginInfo()?.deviceId == deviceId) {
|
|
1463
|
+
removeLoginInfo();
|
|
1464
|
+
}
|
|
1465
|
+
clearCache();
|
|
1466
|
+
return result;
|
|
1467
|
+
}, rateLimitConfig);
|
|
1468
|
+
}
|
|
1469
|
+
};
|
|
1470
|
+
|
|
1471
|
+
// src/core/core.ts
|
|
1472
|
+
import fs from "fs";
|
|
1473
|
+
import path from "path";
|
|
1474
|
+
var isBrowser = typeof window !== "undefined" && typeof window.document !== "undefined";
|
|
1475
|
+
var isNode2 = typeof process !== "undefined" && process.versions?.node != null;
|
|
1476
|
+
var NODE_LOGIN_FILE = path.resolve(process.cwd(), "loginInfo.json");
|
|
1477
|
+
var STORAGE_KEY = "GRAPHQL_LOGIN_INFO";
|
|
1478
|
+
var nodeLoginInfo = null;
|
|
1479
|
+
var CCRequest = class {
|
|
1480
|
+
constructor(config) {
|
|
1481
|
+
this.config = config;
|
|
1482
|
+
this.interceptors = [];
|
|
1483
|
+
this.deviceInfoPromise = getDeviceInfo();
|
|
1484
|
+
this.headers = this.buildHeaders(config);
|
|
1485
|
+
const loginInfo = this.loadLoginInfo();
|
|
1486
|
+
if (loginInfo?.token) this.setToken(loginInfo.token);
|
|
1487
|
+
this.buildClient();
|
|
1488
|
+
}
|
|
1489
|
+
/** 注册一个拦截器(支持多个) */
|
|
1490
|
+
use(interceptor) {
|
|
1491
|
+
this.interceptors.push(interceptor);
|
|
1492
|
+
}
|
|
1493
|
+
/** 构建 GraphQLClient 实例 */
|
|
1494
|
+
buildClient() {
|
|
1495
|
+
this.client = new GraphQLClient(this.config.endpoint || "/graphql", {
|
|
1496
|
+
headers: this.headers
|
|
1497
|
+
});
|
|
1498
|
+
}
|
|
1499
|
+
/** 构建初始 headers */
|
|
1500
|
+
buildHeaders(config) {
|
|
1501
|
+
const headers = {
|
|
1502
|
+
"Content-Type": "application/json",
|
|
1503
|
+
...config.headers
|
|
1504
|
+
};
|
|
1505
|
+
if (config.Authorization) {
|
|
1506
|
+
headers.Authorization = `Bearer ${config.Authorization}`;
|
|
1507
|
+
}
|
|
1508
|
+
return headers;
|
|
1509
|
+
}
|
|
1510
|
+
// ===== Token 管理 =====
|
|
1511
|
+
setToken(token) {
|
|
1512
|
+
this.config.Authorization = token;
|
|
1513
|
+
this.headers.Authorization = `Bearer ${token}`;
|
|
1514
|
+
this.buildClient();
|
|
1515
|
+
}
|
|
1516
|
+
removeToken() {
|
|
1517
|
+
this.config.Authorization = void 0;
|
|
1518
|
+
delete this.headers.Authorization;
|
|
1519
|
+
this.buildClient();
|
|
1520
|
+
}
|
|
1521
|
+
// ===== LoginInfo 管理 =====
|
|
1522
|
+
setLoginInfo(loginInfo, remember = false) {
|
|
1523
|
+
this.config.loginInfo = loginInfo;
|
|
1524
|
+
if (loginInfo.token) this.setToken(loginInfo.token);
|
|
1525
|
+
if (isBrowser) {
|
|
1526
|
+
const storage = remember ? localStorage : sessionStorage;
|
|
1527
|
+
storage.setItem(STORAGE_KEY, JSON.stringify(loginInfo));
|
|
1528
|
+
} else if (isNode2) {
|
|
1529
|
+
nodeLoginInfo = loginInfo;
|
|
1530
|
+
try {
|
|
1531
|
+
fs.writeFileSync(NODE_LOGIN_FILE, JSON.stringify(loginInfo), "utf-8");
|
|
1532
|
+
} catch (err) {
|
|
1533
|
+
console.error("Failed to persist login info to file:", err);
|
|
1534
|
+
}
|
|
1535
|
+
}
|
|
1536
|
+
}
|
|
1537
|
+
/** 加载登录信息(含访问 token 和刷新 token 过期检查) */
|
|
1538
|
+
/** 加载登录信息(仅负责加载,不负责刷新) */
|
|
1539
|
+
loadLoginInfo() {
|
|
1540
|
+
let info = null;
|
|
1541
|
+
if (isBrowser) {
|
|
1542
|
+
const str = localStorage.getItem(STORAGE_KEY) || sessionStorage.getItem(STORAGE_KEY);
|
|
1543
|
+
if (str) {
|
|
1544
|
+
try {
|
|
1545
|
+
info = JSON.parse(str);
|
|
1546
|
+
} catch {
|
|
1547
|
+
info = null;
|
|
1548
|
+
}
|
|
1549
|
+
}
|
|
1550
|
+
} else if (isNode2) {
|
|
1551
|
+
if (nodeLoginInfo) return nodeLoginInfo;
|
|
1552
|
+
if (fs.existsSync(NODE_LOGIN_FILE)) {
|
|
1553
|
+
try {
|
|
1554
|
+
const raw = fs.readFileSync(NODE_LOGIN_FILE, "utf-8");
|
|
1555
|
+
info = JSON.parse(raw);
|
|
1556
|
+
} catch {
|
|
1557
|
+
info = null;
|
|
1558
|
+
}
|
|
1559
|
+
}
|
|
1560
|
+
}
|
|
1561
|
+
if (info) this.config.loginInfo = info;
|
|
1562
|
+
return info;
|
|
1563
|
+
}
|
|
1564
|
+
getLoginInfo() {
|
|
1565
|
+
if (this.config.loginInfo) return this.config.loginInfo;
|
|
1566
|
+
return this.loadLoginInfo();
|
|
1567
|
+
}
|
|
1568
|
+
removeLoginInfo() {
|
|
1569
|
+
delete this.config.loginInfo;
|
|
1570
|
+
if (isBrowser) {
|
|
1571
|
+
localStorage.removeItem(STORAGE_KEY);
|
|
1572
|
+
sessionStorage.removeItem(STORAGE_KEY);
|
|
1573
|
+
} else if (isNode2) {
|
|
1574
|
+
nodeLoginInfo = null;
|
|
1575
|
+
try {
|
|
1576
|
+
} catch {
|
|
1577
|
+
}
|
|
1578
|
+
}
|
|
1579
|
+
this.removeToken();
|
|
1580
|
+
}
|
|
1581
|
+
// ===== Endpoint & Header 管理 =====
|
|
1582
|
+
setEndpoint(endpoint) {
|
|
1583
|
+
this.config.endpoint = endpoint;
|
|
1584
|
+
this.buildClient();
|
|
1585
|
+
}
|
|
1586
|
+
setHeader(key, value) {
|
|
1587
|
+
this.headers[key] = value;
|
|
1588
|
+
}
|
|
1589
|
+
setHeaders(headers) {
|
|
1590
|
+
Object.assign(this.headers, headers);
|
|
1591
|
+
}
|
|
1592
|
+
removeHeader(key) {
|
|
1593
|
+
delete this.headers[key];
|
|
1594
|
+
}
|
|
1595
|
+
clearHeaders() {
|
|
1596
|
+
this.headers = { "Content-Type": "application/json" };
|
|
1597
|
+
}
|
|
1598
|
+
//无感刷新
|
|
1599
|
+
async ensureTokenValid() {
|
|
1600
|
+
const loginInfo = this.getLoginInfo();
|
|
1601
|
+
if (!loginInfo) return;
|
|
1602
|
+
const now = Date.now();
|
|
1603
|
+
const accessExpired = new Date(loginInfo.expireAt).getTime() <= now;
|
|
1604
|
+
const refreshExpired = new Date(loginInfo.refreshExpireAt).getTime() <= now;
|
|
1605
|
+
if (refreshExpired) {
|
|
1606
|
+
this.removeLoginInfo();
|
|
1607
|
+
throw new Error("Login expired. Please login again.");
|
|
1608
|
+
}
|
|
1609
|
+
if (accessExpired && !refreshExpired) {
|
|
1610
|
+
try {
|
|
1611
|
+
const refreshResult = await auth.refreshToken({
|
|
1612
|
+
refreshToken: loginInfo.refreshToken,
|
|
1613
|
+
remember: true
|
|
1614
|
+
});
|
|
1615
|
+
const newInfo = refreshResult.refreshToken ?? refreshResult;
|
|
1616
|
+
this.setLoginInfo(newInfo, true);
|
|
1617
|
+
} catch (err) {
|
|
1618
|
+
this.removeLoginInfo();
|
|
1619
|
+
throw new Error("Failed to refresh token. Please login again.");
|
|
1620
|
+
}
|
|
1621
|
+
}
|
|
1622
|
+
}
|
|
1623
|
+
// ===== 请求逻辑 =====
|
|
1624
|
+
async request(query2, variables) {
|
|
1625
|
+
let queryStr = typeof query2 === "string" ? query2 : print(query2);
|
|
1626
|
+
if (!/refreshToken/i.test(queryStr)) {
|
|
1627
|
+
await this.ensureTokenValid();
|
|
1628
|
+
}
|
|
1629
|
+
const { deviceId, deviceName } = await this.deviceInfoPromise;
|
|
1630
|
+
let headersWithDevice = Object.fromEntries(
|
|
1631
|
+
Object.entries({
|
|
1632
|
+
...this.headers,
|
|
1633
|
+
"X-Device-Id": deviceId,
|
|
1634
|
+
"X-Device-Name": deviceName
|
|
1635
|
+
}).filter(([_, v]) => v !== void 0)
|
|
1636
|
+
);
|
|
1637
|
+
for (const interceptor of this.interceptors) {
|
|
1638
|
+
if (interceptor.onRequest) {
|
|
1639
|
+
const result = await interceptor.onRequest({
|
|
1640
|
+
query: queryStr,
|
|
1641
|
+
variables,
|
|
1642
|
+
headers: headersWithDevice
|
|
1643
|
+
});
|
|
1644
|
+
queryStr = result.query;
|
|
1645
|
+
variables = result.variables;
|
|
1646
|
+
headersWithDevice = Object.fromEntries(
|
|
1647
|
+
Object.entries(result.headers).filter(([_, v]) => v !== void 0)
|
|
1648
|
+
);
|
|
1649
|
+
}
|
|
1650
|
+
}
|
|
1651
|
+
try {
|
|
1652
|
+
const res = await this.client.rawRequest(
|
|
1653
|
+
queryStr,
|
|
1654
|
+
variables,
|
|
1655
|
+
headersWithDevice
|
|
1656
|
+
);
|
|
1657
|
+
let data = res.data;
|
|
1658
|
+
for (const interceptor of this.interceptors) {
|
|
1659
|
+
if (interceptor.onResponse) {
|
|
1660
|
+
data = await interceptor.onResponse(data);
|
|
1661
|
+
}
|
|
1662
|
+
}
|
|
1663
|
+
return data;
|
|
1664
|
+
} catch (err) {
|
|
1665
|
+
const message = err.response?.errors?.[0]?.message ?? err.message;
|
|
1666
|
+
const status = err.response?.errors?.[0]?.extensions?.code ?? 500;
|
|
1667
|
+
const formattedError = {
|
|
1668
|
+
message,
|
|
1669
|
+
status,
|
|
1670
|
+
data: err.response?.data ?? null,
|
|
1671
|
+
errors: err.response?.errors ?? null,
|
|
1672
|
+
request: err.request
|
|
1673
|
+
};
|
|
1674
|
+
for (const interceptor of this.interceptors) {
|
|
1675
|
+
if (interceptor.onError) {
|
|
1676
|
+
await interceptor.onError(formattedError);
|
|
1677
|
+
}
|
|
1678
|
+
}
|
|
1679
|
+
throw formattedError;
|
|
1680
|
+
}
|
|
1681
|
+
}
|
|
1682
|
+
};
|
|
1683
|
+
|
|
1684
|
+
// src/core/client.ts
|
|
1685
|
+
var client = null;
|
|
1686
|
+
function initGraphQLClient(config) {
|
|
1687
|
+
client = new CCRequest(config);
|
|
1688
|
+
return client;
|
|
1689
|
+
}
|
|
1690
|
+
function getClient() {
|
|
1691
|
+
if (!client) throw new Error("GraphQL client not initialized. Call initGraphQLClient() first.");
|
|
1692
|
+
return client;
|
|
1693
|
+
}
|
|
1694
|
+
var useInterceptor = (interceptor) => getClient().use(interceptor);
|
|
1695
|
+
var setToken = (token) => getClient().setToken(token);
|
|
1696
|
+
var removeToken = () => getClient().removeToken();
|
|
1697
|
+
var setLoginInfo = (loginInfo, remember = false) => getClient().setLoginInfo(loginInfo, remember);
|
|
1698
|
+
var removeLoginInfo = () => getClient().removeLoginInfo();
|
|
1699
|
+
var getLoginInfo = () => getClient().getLoginInfo();
|
|
1700
|
+
var setEndpoint = (endpoint) => getClient().setEndpoint(endpoint);
|
|
1701
|
+
var setHeader = (key, value) => getClient().setHeader(key, value);
|
|
1702
|
+
var setHeaders = (headers) => getClient().setHeaders(headers);
|
|
1703
|
+
var removeHeader = (key) => getClient().removeHeader(key);
|
|
1704
|
+
var clearHeaders = () => getClient().clearHeaders();
|
|
1705
|
+
|
|
1706
|
+
// src/core/api/query.ts
|
|
1707
|
+
var query = {
|
|
1708
|
+
async list(input, useCache = true, ttl) {
|
|
1709
|
+
return rateLimit("list", "query", async () => {
|
|
1710
|
+
const { query: q, variables } = buildGraphQLQueryList(input);
|
|
1711
|
+
const key = getCacheKey(q, variables);
|
|
1712
|
+
if (useCache) {
|
|
1713
|
+
const cached = getFromCache(key);
|
|
1714
|
+
if (cached) return cached;
|
|
1715
|
+
}
|
|
1716
|
+
const result = await execute({ query: q, variables });
|
|
1717
|
+
if (useCache) setCache(key, result, ttl ?? DEFAULT_TTL);
|
|
1718
|
+
return result;
|
|
1719
|
+
});
|
|
1720
|
+
},
|
|
1721
|
+
async byId(input, useCache = true, ttl) {
|
|
1722
|
+
return rateLimit("byId", "query", async () => {
|
|
1723
|
+
const { query: q, variables } = buildGraphQLQueryByIdFixed(input);
|
|
1724
|
+
const key = getCacheKey(q, variables);
|
|
1725
|
+
if (useCache) {
|
|
1726
|
+
const cached = getFromCache(key);
|
|
1727
|
+
if (cached) return cached;
|
|
1728
|
+
}
|
|
1729
|
+
const result = await execute({ query: q, variables });
|
|
1730
|
+
if (useCache) setCache(key, result, ttl ?? DEFAULT_TTL);
|
|
1731
|
+
return result;
|
|
1732
|
+
});
|
|
1733
|
+
},
|
|
1734
|
+
async page(input, useCache = true, ttl) {
|
|
1735
|
+
return rateLimit("page", "query", async () => {
|
|
1736
|
+
const { query: q, variables } = buildGraphQLQueryPageList(input);
|
|
1737
|
+
const key = getCacheKey(q, variables);
|
|
1738
|
+
if (useCache) {
|
|
1739
|
+
const cached = getFromCache(key);
|
|
1740
|
+
if (cached) return cached;
|
|
1741
|
+
}
|
|
1742
|
+
const result = await execute({ query: q, variables });
|
|
1743
|
+
if (useCache) setCache(key, result, ttl ?? DEFAULT_TTL);
|
|
1744
|
+
return result;
|
|
1745
|
+
});
|
|
1746
|
+
},
|
|
1747
|
+
async aggregate(input, useCache = true, ttl) {
|
|
1748
|
+
return rateLimit("aggregate", "query", async () => {
|
|
1749
|
+
const { query: q, variables } = buildGraphQLQueryAggregate(input);
|
|
1750
|
+
const key = getCacheKey(q, variables);
|
|
1751
|
+
if (useCache) {
|
|
1752
|
+
const cached = getFromCache(key);
|
|
1753
|
+
if (cached) return cached;
|
|
1754
|
+
}
|
|
1755
|
+
const result = await execute({ query: q, variables });
|
|
1756
|
+
if (useCache) setCache(key, result, ttl ?? DEFAULT_TTL);
|
|
1757
|
+
return result;
|
|
1758
|
+
});
|
|
1759
|
+
}
|
|
1760
|
+
};
|
|
1761
|
+
|
|
1762
|
+
// src/core/api/mutation.ts
|
|
1763
|
+
var mutation = {
|
|
1764
|
+
async insertOne(input) {
|
|
1765
|
+
return rateLimit("insertOne", "mutation", async () => {
|
|
1766
|
+
const { query: query2, variables } = buildGraphQLMutationInsertOne(input);
|
|
1767
|
+
const result = await execute({ query: query2, variables });
|
|
1768
|
+
clearCache();
|
|
1769
|
+
return result;
|
|
1770
|
+
});
|
|
1771
|
+
},
|
|
1772
|
+
async batchInsert(input) {
|
|
1773
|
+
return rateLimit("batchInsert", "mutation", async () => {
|
|
1774
|
+
const { query: query2, variables } = buildGraphQLMutationBatchInsert(input);
|
|
1775
|
+
const result = await execute({ query: query2, variables });
|
|
1776
|
+
clearCache();
|
|
1777
|
+
return result;
|
|
1778
|
+
});
|
|
1779
|
+
},
|
|
1780
|
+
async update(input) {
|
|
1781
|
+
return rateLimit("update", "mutation", async () => {
|
|
1782
|
+
const { query: query2, variables } = buildGraphQLMutationUpdate(input);
|
|
1783
|
+
const result = await execute({ query: query2, variables });
|
|
1784
|
+
clearCache();
|
|
1785
|
+
return result;
|
|
1786
|
+
});
|
|
1787
|
+
},
|
|
1788
|
+
async batchUpdate(input) {
|
|
1789
|
+
return rateLimit("batchUpdate", "mutation", async () => {
|
|
1790
|
+
const { query: query2, variables } = buildGraphQLMutationBatchUpdate(input);
|
|
1791
|
+
const result = await execute({ query: query2, variables });
|
|
1792
|
+
clearCache();
|
|
1793
|
+
return result;
|
|
1794
|
+
});
|
|
1795
|
+
},
|
|
1796
|
+
async updateByPk(input) {
|
|
1797
|
+
return rateLimit("updateByPk", "mutation", async () => {
|
|
1798
|
+
const { query: query2, variables } = buildGraphQLMutationUpdateByPk(input);
|
|
1799
|
+
const result = await execute({ query: query2, variables });
|
|
1800
|
+
clearCache();
|
|
1801
|
+
return result;
|
|
1802
|
+
});
|
|
1803
|
+
},
|
|
1804
|
+
async delete(input) {
|
|
1805
|
+
return rateLimit("delete", "mutation", async () => {
|
|
1806
|
+
const { query: query2, variables } = buildGraphQLMutationDelete(input);
|
|
1807
|
+
const result = await execute({ query: query2, variables });
|
|
1808
|
+
clearCache();
|
|
1809
|
+
return result;
|
|
1810
|
+
});
|
|
1811
|
+
},
|
|
1812
|
+
async deleteById(input) {
|
|
1813
|
+
return rateLimit("deleteById", "mutation", async () => {
|
|
1814
|
+
const { query: query2, variables } = buildGraphQLMutationDeleteById(input);
|
|
1815
|
+
const result = await execute({ query: query2, variables });
|
|
1816
|
+
clearCache();
|
|
1817
|
+
return result;
|
|
1818
|
+
});
|
|
1819
|
+
}
|
|
1820
|
+
};
|
|
1821
|
+
|
|
1822
|
+
// src/core/api/sms.ts
|
|
1823
|
+
var sms = {
|
|
1824
|
+
async send(input) {
|
|
1825
|
+
const { query: query2, variables } = buildGraphQLMutationSendCode(input);
|
|
1826
|
+
return execute({ query: query2, variables });
|
|
1827
|
+
},
|
|
1828
|
+
async verify(input) {
|
|
1829
|
+
const { query: query2, variables } = buildGraphQLMutationVerifyCode(input);
|
|
1830
|
+
return execute({ query: query2, variables });
|
|
1831
|
+
}
|
|
1832
|
+
};
|
|
1833
|
+
|
|
1834
|
+
// src/core/api/gql.ts
|
|
1835
|
+
var gql = {
|
|
1836
|
+
/**
|
|
1837
|
+
* 执行任意 GraphQL 文本或 DocumentNode
|
|
1838
|
+
* @param query 原生 GQL 文本或 DocumentNode
|
|
1839
|
+
* @param variables 可选变量
|
|
1840
|
+
* @returns Promise<T>
|
|
1841
|
+
*/
|
|
1842
|
+
async execute(query2, variables) {
|
|
1843
|
+
return execute({ query: query2, variables });
|
|
1844
|
+
}
|
|
1845
|
+
};
|
|
1846
|
+
export {
|
|
1847
|
+
auth,
|
|
1848
|
+
clearHeaders,
|
|
1849
|
+
getBrowserDeviceInfo,
|
|
1850
|
+
getClient,
|
|
1851
|
+
getDeviceInfo,
|
|
1852
|
+
gql,
|
|
1853
|
+
initGraphQLClient,
|
|
1854
|
+
mutation,
|
|
1855
|
+
query,
|
|
1856
|
+
removeHeader,
|
|
1857
|
+
removeToken,
|
|
1858
|
+
setEndpoint,
|
|
1859
|
+
setHeader,
|
|
1860
|
+
setHeaders,
|
|
1861
|
+
setToken,
|
|
1862
|
+
sms,
|
|
1863
|
+
useInterceptor
|
|
1864
|
+
};
|
|
1865
|
+
//# sourceMappingURL=index.js.map
|