@accelbyte/codegen 3.0.6 → 3.1.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.
@@ -66,7 +66,7 @@ const makeNewImportVarMap$1 = () => ({
66
66
  axios: ["AxiosInstance"],
67
67
  "@accelbyte/sdk": ["SDKRequestConfig"]
68
68
  });
69
- const generateImports = (body, importStatements, makeNewImportVarMap2, getImportableVarMap2) => {
69
+ const generateImports$1 = (body, importStatements, makeNewImportVarMap2, getImportableVarMap2) => {
70
70
  const usedImportVarMap = makeNewImportVarMap2;
71
71
  const importableVarMap = getImportableVarMap2;
72
72
  for (const [moduleSource, importableVars] of Object.entries(importableVarMap)) {
@@ -87,16 +87,55 @@ const templateClass = (className, body, importStatements) => {
87
87
  return `/**
88
88
  * AUTO GENERATED
89
89
  */
90
- ${generateImports(body, importStatements, makeNewImportVarMap$1(), getImportableVarMap$1())}
90
+ ${generateImports$1(body, importStatements, makeNewImportVarMap$1(), getImportableVarMap$1())}
91
91
 
92
92
  export class ${className} {
93
93
  // @ts-ignore
94
- constructor(private axiosInstance: AxiosInstance, private namespace: string, private isZodEnabled = true) {}
94
+ constructor(private axiosInstance: AxiosInstance, private namespace: string, private useSchemaValidation = true) {}
95
95
  ${body}
96
96
  }
97
97
  `;
98
98
  };
99
99
 
100
+ const generateImports = (body, className) => {
101
+ const generatedImports = `import { AccelbyteSDK, ApiArgs, ApiError } from '@accelbyte/sdk'
102
+ import { AxiosError } from 'axios'
103
+ // @ts-ignore
104
+ import { useQuery, UseQueryOptions, UseQueryResult, useMutation, UseMutationOptions, UseMutationResult } from '@tanstack/react-query'
105
+ import { ${className} } from "../${className}.js"
106
+ `;
107
+ return generatedImports;
108
+ };
109
+ const templateQuery = (className, body, importStatements, serviceNameTitle, returnMethods, paramImports) => {
110
+ const classNameWithoutApi = className.replace("Api", "");
111
+ const queryKeys = ParserUtils.createQueryKeys(classNameWithoutApi, returnMethods);
112
+ const generatedImports = generateImports(body, className);
113
+ return `/**
114
+ * AUTO GENERATED
115
+ */
116
+ /* eslint-disable camelcase */
117
+ ${generatedImports}
118
+ ${filterUsedImports(paramImports, body)}
119
+
120
+ export enum Key_${classNameWithoutApi} {
121
+ ${queryKeys}
122
+ }
123
+
124
+ ${body}
125
+ `;
126
+ };
127
+ function filterUsedImports(importArr, body) {
128
+ return importArr.filter((path) => {
129
+ const start = path.indexOf("{") + 1;
130
+ const end = path.indexOf("}");
131
+ if (start > 0 && end > start) {
132
+ const importName = path.slice(start, end).trim();
133
+ return body.includes(importName);
134
+ }
135
+ return false;
136
+ }).map((path) => path).join("\n") + "\n";
137
+ }
138
+
100
139
  const getImportableVarMap = () => ({
101
140
  "@accelbyte/sdk": ["CodeGenUtil", "IResponse", "Validate", "ApiArgs", "Network", "AccelbyteSDK"]
102
141
  });
@@ -104,19 +143,22 @@ const makeNewImportVarMap = () => ({
104
143
  "@accelbyte/sdk": ["AccelbyteSDK", "ApiArgs", "ApiUtils"]
105
144
  });
106
145
  const templateApiClass = (className, body, importStatements, returnMethods) => {
146
+ const $className = className.replace("Api", "$");
107
147
  return `/**
108
148
  * AUTO GENERATED
109
149
  */
110
150
  /* eslint-disable camelcase */
111
151
  // @ts-ignore -> ts-expect-error TS6133
112
- ${generateImports(body, importStatements, makeNewImportVarMap(), getImportableVarMap())}
152
+ ${generateImports$1(body, importStatements, makeNewImportVarMap(), getImportableVarMap())}
153
+ ${`import { ${$className} } from './endpoints/${$className}.js'
154
+ `}
113
155
 
114
156
  export function ${className}(sdk: AccelbyteSDK, args?: ApiArgs) {
115
157
  const sdkAssembly = sdk.assembly()
116
158
 
117
159
  const namespace = args?.namespace ? args?.namespace : sdkAssembly.namespace
118
160
  const requestConfig = ApiUtils.mergedConfigs(sdkAssembly.config, args)
119
- const isZodEnabled = typeof window !== "undefined" && localStorage.getItem('ZodEnabled') !== 'false'
161
+ const useSchemaValidation = sdkAssembly.useSchemaValidation
120
162
  ${body}
121
163
 
122
164
  return {
@@ -206,8 +248,35 @@ const REMOVED_KEYWORDS = [
206
248
  "/{namespace}/"
207
249
  ];
208
250
  class ParserUtils {
209
- static replaceAll = (string, search, replace) => {
210
- return string.split(search).join(replace);
251
+ static createQueryKeys(classNameWithoutApi, csvMethodNames) {
252
+ const keys = csvMethodNames.split(",");
253
+ const processedKeys = /* @__PURE__ */ new Set();
254
+ const enumString = keys.reduce((acc, key, index) => {
255
+ const trimmedKey = key.trim();
256
+ const isDeprecated = key.indexOf("_DEPRECATED") > 0;
257
+ if (trimmedKey && !isDeprecated) {
258
+ const cleanedKey = trimmedKey.replace(/^(get|update|create|patch|delete)[_]?/, "");
259
+ if (!processedKeys.has(cleanedKey)) {
260
+ processedKeys.add(cleanedKey);
261
+ acc += `${cleanedKey} = '${classNameWithoutApi}.${cleanedKey}'`;
262
+ if (index < keys.length - 1) {
263
+ acc += ",\n";
264
+ }
265
+ }
266
+ }
267
+ return acc;
268
+ }, "");
269
+ return enumString;
270
+ }
271
+ static addDeprecatedSuffix(isDeprecated, methodName) {
272
+ if (isDeprecated) {
273
+ return methodName + "_DEPRECATED";
274
+ } else {
275
+ return methodName;
276
+ }
277
+ }
278
+ static replaceAll = (text, search, replace) => {
279
+ return text.split(search).join(replace);
211
280
  };
212
281
  static generateClassName = (tag, isAdmin) => {
213
282
  const className = _.upperFirst(_.camelCase(tag));
@@ -347,7 +416,7 @@ class ParserUtils {
347
416
  if (bodyParam?.schema?.type === "array" && bodyParam?.schema?.items?.$ref) {
348
417
  return `${ParserUtils.parseRefType(bodyParam.schema.items.$ref)}[]`;
349
418
  }
350
- if (bodyParam?.schema.$ref) {
419
+ if (bodyParam?.schema?.$ref) {
351
420
  return ParserUtils.parseRefType(bodyParam.schema.$ref);
352
421
  }
353
422
  if (bodyParam?.schema?.additionalProperties?.type === "object") {
@@ -463,6 +532,20 @@ class ParserUtils {
463
532
  const fileContent = templateClass(apiName, apiBuffer, imports);
464
533
  fs__default.writeFileSync(`${distDir}/${apiName}.ts`, ParserUtils.prependCopyrightHeader(fileContent));
465
534
  }
535
+ static writeAtomFile(distDir, apiName, fileContent) {
536
+ ParserUtils.mkdirIfNotExist(distDir);
537
+ fs__default.writeFileSync(`${distDir}/${apiName}.atom.ts`, ParserUtils.prependCopyrightHeader(fileContent));
538
+ }
539
+ static writeQueryFile(distDir, apiName, apiBuffer, imports, serviceNameTitle, returnMethods, paramImports) {
540
+ if (apiBuffer.length < 1) {
541
+ return null;
542
+ }
543
+ const queryFileName = `${apiName.replace("Api", "")}.query`;
544
+ ParserUtils.mkdirIfNotExist(distDir);
545
+ const fileContent = templateQuery(apiName, apiBuffer, imports, serviceNameTitle, returnMethods, paramImports);
546
+ fs__default.writeFileSync(`${distDir}/${queryFileName}.ts`, ParserUtils.prependCopyrightHeader(fileContent));
547
+ return queryFileName;
548
+ }
466
549
  static writeXVersion(distDir, xversionJson, apiInfo) {
467
550
  if (xversionJson) {
468
551
  console.log("x-version:", xversionJson);
@@ -933,7 +1016,7 @@ const apis = {
933
1016
  ${returnStatement}
934
1017
  }
935
1018
 
936
- export const ${ParserUtils.convertDashesToTitleCase(serviceNameTitle)} = apis
1019
+ export const ${serviceNameTitle} = apis
937
1020
  `;
938
1021
  };
939
1022
 
@@ -992,11 +1075,11 @@ const Endpoint = z.object({
992
1075
  })),
993
1076
  parameters: z.array(EndpointParameters).nullish(),
994
1077
  requestBody: z.object({
995
- required: z.boolean(),
1078
+ required: z.boolean().nullish(),
996
1079
  content: z.object({
997
1080
  "application/json": z.object({
998
1081
  schema: Schema.nullish()
999
- })
1082
+ }).nullish()
1000
1083
  }).nullish()
1001
1084
  }).nullish(),
1002
1085
  "x-security": z.any().nullish()
@@ -1094,10 +1177,6 @@ const templateMethod = ({
1094
1177
  methodParams = (queryParamsType ? `${methodParams} ${queryParamsType}` : methodParams).replace(/,\s*$/, "");
1095
1178
  methodParamsNoTypes = queryParamsType ? `${methodParamsNoTypes} queryParams` : methodParamsNoTypes;
1096
1179
  let methodImpl = "";
1097
- const isCacheFetch = ["get"].includes(httpMethod) && resolvedResponseClass !== "unknown";
1098
- const deprecateTag = isCacheFetch ? `/**
1099
- * @deprecated Use "${classMethod}()" instead.
1100
- */` : "";
1101
1180
  const isGuardInvoked = ["get", "post", "put", "patch", "delete"].includes(httpMethod);
1102
1181
  const responseType = resolvedResponseClass !== "unknown" ? `${resolvedResponseClass}` : "unknown";
1103
1182
  const generateMethodName = () => `${classMethod}(${methodParams}): Promise<${responseSyncType}<${responseType}>>`;
@@ -1108,18 +1187,11 @@ const templateMethod = ({
1108
1187
  const url = ${newPath} ${formPayloadString} ${isFileUpload ? "\n// TODO file upload not implemented" : ""}
1109
1188
  const resultPromise = this.axiosInstance.${httpMethod}(url, ${dataPayload})
1110
1189
 
1111
- ${` return Validate.validateOrReturnResponse(this.isZodEnabled, () => resultPromise, ${resolvedResponseClassValidated}, '${resolvedResponseClassValidated}')`}
1190
+ ${` return Validate.validateOrReturnResponse(this.useSchemaValidation, () => resultPromise, ${resolvedResponseClassValidated}, '${resolvedResponseClassValidated}')`}
1112
1191
  }
1113
1192
  `;
1114
1193
  if (!isGuardInvoked) {
1115
- methodImpl = `${descriptionText}
1116
- ${deprecateTag}
1117
- TODO_${classMethod}(${methodParams}): Promise<AxiosResponse<${resolvedResponseClass}>> {
1118
- ${queryParamsDefault}
1119
- const url = ${newPath} ${formPayloadString} ${isFileUpload ? "\n// TODO file upload not implemented" : ""}
1120
- return this.axiosInstance.${httpMethod}(url, ${dataPayload})
1121
- }
1122
- `;
1194
+ methodImpl = ``;
1123
1195
  }
1124
1196
  const res = {
1125
1197
  methodImpl,
@@ -1181,7 +1253,7 @@ const templateApiMethod = ({
1181
1253
  const methodImpl = `
1182
1254
  ${descriptionText}
1183
1255
  async function ${classMethod}(${methodParams}): Promise<${responseType}> {
1184
- const $ = new ${classGenName}(Network.create(requestConfig), namespace, isZodEnabled)
1256
+ const $ = new ${classGenName}(Network.create(requestConfig), namespace, useSchemaValidation)
1185
1257
  const resp = await $.${classMethod}(${methodParamsNoTypes})
1186
1258
  if (resp.error) throw resp.error
1187
1259
  return resp.response.data
@@ -1244,6 +1316,151 @@ const normalizeMethodSnippet = (methodInput, splitWord) => {
1244
1316
  return result;
1245
1317
  };
1246
1318
 
1319
+ const templateQueryMethod = ({
1320
+ classMethod,
1321
+ httpMethod,
1322
+ path,
1323
+ pathParams,
1324
+ responseClass,
1325
+ methodParams,
1326
+ apiGenName,
1327
+ isFormUrlEncoded,
1328
+ deprecated
1329
+ }) => {
1330
+ if (isFormUrlEncoded || deprecated) {
1331
+ return "";
1332
+ }
1333
+ const isPostFetch = httpMethod === "post" && (path.includes("/table-query/") || path.endsWith("/list"));
1334
+ const isAdmin = path.indexOf("/admin/") > 0;
1335
+ const isGet = httpMethod === "get" || isPostFetch;
1336
+ let queryMethod = isGet ? "useQuery" : "useMutation";
1337
+ let mParams = "";
1338
+ let mParamsNoTypes = "";
1339
+ let newPath = `'${path}'`;
1340
+ const sortedPathParams = ParserUtils.sortPathParamsByPath(pathParams, path);
1341
+ for (const pathParam of sortedPathParams) {
1342
+ const type = ParserUtils.parseType(pathParam);
1343
+ if (pathParam.name !== "namespace") {
1344
+ mParams += pathParam.name + `:${type}, `;
1345
+ mParamsNoTypes += pathParam.name + ", ";
1346
+ }
1347
+ const pName = pathParam.name === "namespace" ? "this.namespace" : pathParam.name;
1348
+ if (path.match(`{${pathParam.name}}`)) {
1349
+ if (type === "string") {
1350
+ newPath = `${newPath}.replace('{${pathParam.name}}', ${pName})`;
1351
+ } else {
1352
+ newPath = `${newPath}.replace('{${pathParam.name}}', String(${pName}))`;
1353
+ }
1354
+ }
1355
+ }
1356
+ const resolvedResponseClass = responseClass || "unknown";
1357
+ let _methodName = convertMethodName(classMethod, isPostFetch);
1358
+ _methodName = isAdmin ? _methodName.replace("use", "useAdm") : _methodName;
1359
+ const _responseType = resolvedResponseClass !== "unknown" ? `${resolvedResponseClass}` : "unknown";
1360
+ const _methodParams = methodParams && methodParams.length > 0 ? `& { ${methodParams} }` : "";
1361
+ const _methodParamsImpl = convertToMethodImplArgs(methodParams);
1362
+ const queryMethodImpl = `
1363
+
1364
+ export const ${_methodName} = (
1365
+ sdk: AccelbyteSDK,
1366
+ input: ApiArgs ${_methodParams},
1367
+ options?: Omit<UseQueryOptions<${_responseType}, AxiosError<ApiError>>, 'queryKey'>,
1368
+ callback?: (data: ${_responseType}) => void
1369
+ ): UseQueryResult<${_responseType}, AxiosError<ApiError>> => {
1370
+ //
1371
+ const queryFn = (
1372
+ sdk: AccelbyteSDK,
1373
+ input: Parameters<typeof ${_methodName}>[1]
1374
+ ) => async () => {
1375
+ const data =
1376
+ (await ${apiGenName}(sdk, { namespace: input.namespace }).
1377
+ ${classMethod}(${_methodParamsImpl}))
1378
+ callback && callback(data)
1379
+ return data
1380
+ }
1381
+
1382
+ return ${queryMethod}<${_responseType}, AxiosError<ApiError>>({
1383
+ queryKey: [${createQueryKey(apiGenName, classMethod)}, input],
1384
+ queryFn: queryFn(sdk, input),
1385
+ ...options
1386
+ })
1387
+ }
1388
+
1389
+ `;
1390
+ const mutationMethodImpl = `
1391
+
1392
+ export const ${_methodName} = (
1393
+ sdk: AccelbyteSDK,
1394
+ options?: Omit<UseMutationOptions<${_responseType}, AxiosError<ApiError>, ApiArgs ${_methodParams}>, 'mutationKey'>,
1395
+ callback?: (data: ${_responseType}) => void
1396
+ ): UseMutationResult<${_responseType}, AxiosError<ApiError>, ApiArgs ${_methodParams}> => {
1397
+ //
1398
+ const mutationFn = async (input: ApiArgs ${_methodParams}) => {
1399
+ const data =
1400
+ (await ${apiGenName}(sdk, { namespace: input.namespace, config: input.config }).
1401
+ ${classMethod}(${_methodParamsImpl}))
1402
+ callback && callback(data)
1403
+ return data
1404
+ }
1405
+
1406
+ return useMutation({
1407
+ mutationKey: [${createQueryKey(apiGenName, classMethod)}],
1408
+ mutationFn,
1409
+ ...options
1410
+ })
1411
+ }
1412
+
1413
+ `;
1414
+ return isGet ? queryMethodImpl : mutationMethodImpl;
1415
+ };
1416
+ function createQueryKey(className, methodName) {
1417
+ if (methodName.indexOf("_DEPRECATED") > 0) {
1418
+ return "";
1419
+ }
1420
+ const prefixRegex = /^(get|create|update|delete|patch)[_]?/i;
1421
+ const cleanedMethodName = methodName.replace(prefixRegex, "").trim();
1422
+ const finalMethodName = cleanedMethodName.charAt(0).toUpperCase() + cleanedMethodName.slice(1);
1423
+ return `Key_${className.replace("Api", "")}.${finalMethodName}`;
1424
+ }
1425
+ const prefixMappings = {
1426
+ get: "use",
1427
+ create: "useCreate",
1428
+ patch: "usePatch",
1429
+ update: "useUpdate",
1430
+ delete: "useDelete"
1431
+ };
1432
+ function convertMethodName(classMethod, isPostFetch) {
1433
+ for (const [originalPrefix, newPrefix] of Object.entries(prefixMappings)) {
1434
+ if (classMethod.startsWith(originalPrefix)) {
1435
+ if (isPostFetch) {
1436
+ return classMethod.replace(originalPrefix, "useFetch");
1437
+ }
1438
+ const newMethodName = classMethod.replace(originalPrefix, newPrefix);
1439
+ if (originalPrefix === "get") {
1440
+ return newMethodName;
1441
+ } else {
1442
+ return newMethodName + "Mutation";
1443
+ }
1444
+ }
1445
+ }
1446
+ return classMethod;
1447
+ }
1448
+ function convertToMethodImplArgs(methodArgs) {
1449
+ let properties = methodArgs.split(/,\s*(?![^{}]*\})/).map((prop) => prop.trim()).filter(Boolean);
1450
+ let formattedProperties = [];
1451
+ properties.forEach((prop) => {
1452
+ if (prop.includes(": {")) {
1453
+ const propertyName = prop.split(": {")[0].replace("?", "").trim();
1454
+ formattedProperties.push(`input.${propertyName}`);
1455
+ } else {
1456
+ const colonIndex = prop.indexOf(":");
1457
+ const propertyName = prop.substring(0, colonIndex).replace("?", "").trim();
1458
+ formattedProperties.push(`input.${propertyName}`);
1459
+ }
1460
+ });
1461
+ return formattedProperties.join(", ");
1462
+ }
1463
+
1247
1464
  const GIT_URL = "https://github.com/AccelByte/accelbyte-web-sdk/blob/main/packages";
1248
1465
  class SwaggerReaderHelpers {
1249
1466
  static getServicePrefix = (servicePaths) => servicePaths[servicePaths.length - 1].split("/")[1];
@@ -1260,7 +1477,8 @@ class SwaggerReaderHelpers {
1260
1477
  tagToEndpointClassesRecord: {},
1261
1478
  tagToSdkClientRecord: {},
1262
1479
  tagToSdkFunctionNamesRecord: {},
1263
- tagToSdkImportsRecord: {}
1480
+ tagToSdkImportsRecord: {},
1481
+ tagToEndpointQueryRecord: {}
1264
1482
  },
1265
1483
  public: {
1266
1484
  arrayDefinitions: [],
@@ -1269,7 +1487,8 @@ class SwaggerReaderHelpers {
1269
1487
  tagToEndpointClassesRecord: {},
1270
1488
  tagToSdkClientRecord: {},
1271
1489
  tagToSdkFunctionNamesRecord: {},
1272
- tagToSdkImportsRecord: {}
1490
+ tagToSdkImportsRecord: {},
1491
+ tagToEndpointQueryRecord: {}
1273
1492
  }
1274
1493
  };
1275
1494
  const sortedPathsByLength = new Map(Object.entries(api.paths).sort((a, b) => {
@@ -1298,7 +1517,8 @@ class SwaggerReaderHelpers {
1298
1517
  tagToEndpointClassesRecord,
1299
1518
  tagToSdkClientRecord,
1300
1519
  tagToSdkFunctionNamesRecord,
1301
- tagToSdkImportsRecord
1520
+ tagToSdkImportsRecord,
1521
+ tagToEndpointQueryRecord
1302
1522
  } = picked;
1303
1523
  const tagToClassMethodsMapByType = isAdminEndpoint ? tagToClassMethodsMap.admin : tagToClassMethodsMap.public;
1304
1524
  const httpMethods = Object.keys(operation);
@@ -1345,12 +1565,12 @@ class SwaggerReaderHelpers {
1345
1565
  {
1346
1566
  name: "body",
1347
1567
  in: "body",
1348
- schema: endpoint.requestBody.content["application/json"].schema
1568
+ schema: endpoint.requestBody.content["application/json"]?.schema
1349
1569
  }
1350
1570
  ];
1351
1571
  }
1352
1572
  const { methodImpl, methodParams, methodParamsNoTypes, importStatements } = templateMethod({
1353
- classMethod,
1573
+ classMethod: ParserUtils.addDeprecatedSuffix(deprecated, classMethod),
1354
1574
  description,
1355
1575
  httpMethod,
1356
1576
  path: pathWithBase,
@@ -1362,8 +1582,21 @@ class SwaggerReaderHelpers {
1362
1582
  deprecated
1363
1583
  });
1364
1584
  tagToEndpointClassesRecord[tag] = (tagToEndpointClassesRecord[tag] || "") + methodImpl;
1585
+ const { apiGenName } = ParserUtils.generateApiName(tag, isAdminEndpoint);
1586
+ const queryMethodImpl = templateQueryMethod({
1587
+ classMethod: ParserUtils.addDeprecatedSuffix(deprecated, classMethod),
1588
+ httpMethod,
1589
+ path: pathWithBase,
1590
+ pathParams,
1591
+ responseClass,
1592
+ methodParams,
1593
+ apiGenName,
1594
+ isFormUrlEncoded,
1595
+ deprecated
1596
+ });
1597
+ tagToEndpointQueryRecord[tag] = (tagToEndpointQueryRecord[tag] || "") + queryMethodImpl;
1365
1598
  const { generatedMethodString, snippetApiArgs, snippetMethod, snippetShell } = templateApiMethod({
1366
- classMethod,
1599
+ classMethod: ParserUtils.addDeprecatedSuffix(deprecated, classMethod),
1367
1600
  description,
1368
1601
  httpMethod,
1369
1602
  path: pathWithBase,
@@ -1377,11 +1610,15 @@ class SwaggerReaderHelpers {
1377
1610
  xSecurity: endpoint["x-security"]
1378
1611
  });
1379
1612
  tagToSdkClientRecord[tag] = (tagToSdkClientRecord[tag] || "") + generatedMethodString;
1380
- tagToSdkFunctionNamesRecord[tag] = (tagToSdkFunctionNamesRecord[tag] || "") + classMethod + ",";
1613
+ tagToSdkFunctionNamesRecord[tag] = (tagToSdkFunctionNamesRecord[tag] || "") + ParserUtils.addDeprecatedSuffix(deprecated, classMethod) + ",";
1381
1614
  tagToSdkImportsRecord[tag] = tagToSdkImportsRecord[tag] ? [.../* @__PURE__ */ new Set([...importStatements, ...tagToSdkImportsRecord[tag]])] : [...new Set(importStatements)];
1382
1615
  const serviceNameTitle = ParserUtils.convertDashesToTitleCase(serviceName);
1383
- const { apiGenName } = ParserUtils.generateApiName(tag, isAdminEndpoint);
1384
- const resultSnippet = templateSdkSnippet({ serviceNameTitle, apiName: apiGenName, snippetMethod, snippetApiArgs });
1616
+ const resultSnippet = templateSdkSnippet({
1617
+ serviceNameTitle,
1618
+ apiName: apiGenName,
1619
+ snippetMethod,
1620
+ snippetApiArgs
1621
+ });
1385
1622
  const currentSnippetMap = {};
1386
1623
  snippetMap[pathWithBase][httpMethod] = currentSnippetMap;
1387
1624
  currentSnippetMap.web = resultSnippet;
@@ -1401,12 +1638,13 @@ class CodeGenerator {
1401
1638
  static srcFolder = () => CliParser.getOutputPath();
1402
1639
  static getGeneratedFolder = (isAdmin) => isAdmin ? `${CodeGenerator.srcFolder()}/generated-admin` : `${CodeGenerator.srcFolder()}/generated-public`;
1403
1640
  static getGeneratedSnippetsFolder = () => `${CliParser.getSnippetOutputPath()}/generated-snippets`;
1404
- static prepareDirs = (DIST_DEFINITION_DIR, DIST_DIR, DIST_DIR_ENDPOINTS) => {
1641
+ static prepareDirs = (DIST_DEFINITION_DIR, DIST_DIR, DIST_DIR_ENDPOINTS, DIST_DIR_QUERIES) => {
1405
1642
  ParserUtils.mkdirIfNotExist(DIST_DEFINITION_DIR);
1406
1643
  ParserUtils.mkdirIfNotExist(DIST_DIR(true));
1407
1644
  ParserUtils.mkdirIfNotExist(DIST_DIR(false));
1408
1645
  ParserUtils.mkdirIfNotExist(DIST_DIR_ENDPOINTS(true));
1409
1646
  ParserUtils.mkdirIfNotExist(DIST_DIR_ENDPOINTS(false));
1647
+ ParserUtils.mkdirIfNotExist(DIST_DIR_QUERIES(true));
1410
1648
  };
1411
1649
  static main = async (nameArray) => {
1412
1650
  const serviceName = nameArray[0];
@@ -1434,9 +1672,10 @@ class CodeGenerator {
1434
1672
  }
1435
1673
  const DIST_DIR = (isAdmin) => `${CodeGenerator.getGeneratedFolder(isAdmin)}`;
1436
1674
  const DIST_DIR_ENDPOINTS = (isAdmin) => path__default.join(DIST_DIR(isAdmin), "endpoints");
1675
+ const DIST_DIR_QUERIES = (isAdmin) => path__default.join(DIST_DIR(isAdmin), "queries");
1437
1676
  const DIST_DEFINITION_DIR = path__default.join(CodeGenerator.srcFolder(), "generated-definitions");
1438
1677
  const targetSrcFolder = `${CodeGenerator.srcFolder()}/`;
1439
- CodeGenerator.prepareDirs(DIST_DEFINITION_DIR, DIST_DIR, DIST_DIR_ENDPOINTS);
1678
+ CodeGenerator.prepareDirs(DIST_DEFINITION_DIR, DIST_DIR, DIST_DIR_ENDPOINTS, DIST_DIR_QUERIES);
1440
1679
  const mainApiList = [];
1441
1680
  const generatePublicOrAdmin = (isAdmin) => {
1442
1681
  const parsedInformationByType = isAdmin ? parsedInformation.admin : parsedInformation.public;
@@ -1446,7 +1685,8 @@ class CodeGenerator {
1446
1685
  tagToEndpointClassesRecord,
1447
1686
  tagToSdkClientRecord,
1448
1687
  tagToSdkFunctionNamesRecord,
1449
- tagToSdkImportsRecord
1688
+ tagToSdkImportsRecord,
1689
+ tagToEndpointQueryRecord
1450
1690
  } = parsedInformationByType;
1451
1691
  const writeApiEndpointFiles = (isAdminEndpoint) => {
1452
1692
  const apiList = [];
@@ -1457,12 +1697,15 @@ class CodeGenerator {
1457
1697
  const apiImports = [.../* @__PURE__ */ new Set([...tagToSdkImportsRecord[tag], ...Object.values(tagToClassImportsRecord[className])])];
1458
1698
  apiImports.push(`import { ${classGenName} } from './endpoints/${classGenName}.js'`);
1459
1699
  ParserUtils.writeClassFile(DIST_DIR_ENDPOINTS(isAdminEndpoint), classGenName, classBuffer, imports);
1460
- const apiBuffer = tagToSdkClientRecord[tag];
1461
1700
  const { apiGenName } = ParserUtils.generateApiName(tag, isAdminEndpoint);
1462
- ParserUtils.writeApiFile(DIST_DIR(isAdminEndpoint), apiGenName, apiBuffer, apiImports, tagToSdkFunctionNamesRecord[tag]);
1701
+ const queryBuffer = tagToEndpointQueryRecord[tag];
1702
+ const queryFileName = ParserUtils.writeQueryFile(DIST_DIR_QUERIES(isAdminEndpoint), apiGenName, queryBuffer, apiImports, serviceNameTitle, tagToSdkFunctionNamesRecord[tag], imports);
1703
+ const apiBuffer = tagToSdkClientRecord[tag];
1704
+ ParserUtils.writeApiFile(DIST_DIR(isAdminEndpoint), apiGenName, apiBuffer, imports, tagToSdkFunctionNamesRecord[tag]);
1463
1705
  apiList.push(apiGenName);
1464
1706
  indexImportsSet.add(ParserUtils.getRelativePathToWebSdkSrcFolder(path__default.join(DIST_DIR_ENDPOINTS(isAdminEndpoint), `${classGenName}`), targetSrcFolder));
1465
1707
  indexImportsSet.add(ParserUtils.getRelativePathToWebSdkSrcFolder(path__default.join(DIST_DIR(isAdminEndpoint), `${apiGenName}`), targetSrcFolder));
1708
+ queryFileName && indexImportsSet.add(ParserUtils.getRelativePathToWebSdkSrcFolder(path__default.join(DIST_DIR(isAdminEndpoint), "queries", `${queryFileName}`), targetSrcFolder));
1466
1709
  }
1467
1710
  mainApiList.push(...apiList);
1468
1711
  indexImportsSet.add(ParserUtils.getRelativePathToWebSdkSrcFolder(path__default.join(CodeGenerator.srcFolder(), serviceNameTitle), targetSrcFolder));
@@ -1574,7 +1817,7 @@ const generateSdk = async () => {
1574
1817
  }
1575
1818
  });
1576
1819
  }
1577
- const indexImportsArray = Array.from(indexImportsSet);
1820
+ const indexImportsArray = Array.from(indexImportsSet).sort();
1578
1821
  const filesToImport = indexImportsArray.map((fileToImport) => {
1579
1822
  return `export * from '${fileToImport.replace("\\", "/")}.js'`;
1580
1823
  });