@alevnyacow/nzmt 0.28.0 → 0.29.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.
Files changed (2) hide show
  1. package/bin/cli.js +25 -5
  2. package/package.json +1 -1
package/bin/cli.js CHANGED
@@ -367,8 +367,28 @@ function initClientUtils() {
367
367
  "\t}"
368
368
  ].join('\n'))
369
369
 
370
+ fs.writeFileSync(path.resolve(folder, 'normalize-query-key-payload.ts'), [
371
+ 'export const normalizeObjectKeysOrder = (input: any): any => {',
372
+ '\tif (Array.isArray(input)) {',
373
+ '\t\treturn input.map(item => normalizeObjectKeysOrder(item))',
374
+ '\t}',
375
+ '',
376
+ '\tif (input !== null && typeof input === "object") {',
377
+ '\t\tconst sortedKeys = Object.keys(input).sort((a, b) => a.localeCompare(b))',
378
+ '\t\tconst result: Record<string, any> = {}',
379
+ '\t\tfor (const key of sortedKeys) {',
380
+ '\t\t\tresult[key] = normalizeObjectKeysOrder(input[key])',
381
+ '\t\t}',
382
+ '\t\treturn result',
383
+ '\t}',
384
+ '',
385
+ '\treturn input',
386
+ '}'
387
+ ].join('\n'))
388
+
370
389
  fs.writeFileSync(path.resolve(folder, 'index.ts'), [
371
- `export * from './api-request'`
390
+ `export * from './api-request'`,
391
+ `export * from './normalize-query-key-payload'`
372
392
  ].join('\n'))
373
393
  }
374
394
 
@@ -1249,7 +1269,7 @@ function generateQueries(lowerCase, upperCase, entity) {
1249
1269
  fs.writeFileSync(fileName, [
1250
1270
  `import { ${rootMethod === 'GET' ? 'useQuery' : 'useMutation, useQueryClient'} } from '@tanstack/react-query'`,
1251
1271
  `import type { ${upperCase}API } from '@${config.paths.controllers}/${requiredEntity}'`,
1252
- `import { apiRequest } from '@${config.paths.clientUtils}'`,
1272
+ `import { apiRequest, normalizeObjectKeysOrder } from '@${config.paths.clientUtils}'`,
1253
1273
  '',
1254
1274
  `type Method = ${upperCase}API['endpoints']['${rootMethod}']`,
1255
1275
  ``,
@@ -1259,7 +1279,7 @@ function generateQueries(lowerCase, upperCase, entity) {
1259
1279
  ? [
1260
1280
  `export const use${rootMethod} = (payload: Method['payload']) => {`,
1261
1281
  `\treturn useQuery<Method['response'], Method['error']>({`,
1262
- `\t\tqueryKey: ['${requiredEntity}', '${rootMethod}', payload],`,
1282
+ `\t\tqueryKey: ['${requiredEntity}', '${rootMethod}', normalizeObjectKeysOrder(payload)],`,
1263
1283
  `\t\tqueryFn: () => apiRequest(endpoint, 'GET')(payload)`,
1264
1284
  `\t})`,
1265
1285
  `}`
@@ -1291,7 +1311,7 @@ function generateQueries(lowerCase, upperCase, entity) {
1291
1311
  fs.writeFileSync(fileName, [
1292
1312
  `import { ${method === 'GET' ? 'useQuery' : 'useMutation, useQueryClient' } } from '@tanstack/react-query'`,
1293
1313
  `import type { ${upperCase}API } from '@${config.paths.controllers}/${requiredEntity}'`,
1294
- `import { apiRequest } from '@${config.paths.clientUtils}'`,
1314
+ `import { apiRequest, normalizeObjectKeysOrder } from '@${config.paths.clientUtils}'`,
1295
1315
  '',
1296
1316
  `type Method = ${upperCase}API['endpoints']['${fullMethodName}']`,
1297
1317
  ``,
@@ -1301,7 +1321,7 @@ function generateQueries(lowerCase, upperCase, entity) {
1301
1321
  ? [
1302
1322
  `export const use${nameForHook} = (payload: Method['payload']) => {`,
1303
1323
  `\treturn useQuery<Method['response'], Method['error']>({`,
1304
- `\t\tqueryKey: ['${requiredEntity}', ${currentPath.split('/').map(x => `'${x}'`).join(', ')}, payload],`,
1324
+ `\t\tqueryKey: ['${requiredEntity}', ${currentPath.split('/').map(x => `'${x}'`).join(', ')}, normalizeObjectKeysOrder(payload)],`,
1305
1325
  `\t\tqueryFn: () => apiRequest(endpoint, 'GET')(payload)`,
1306
1326
  `\t})`,
1307
1327
  `}`
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@alevnyacow/nzmt",
3
- "version": "0.28.0",
3
+ "version": "0.29.0",
4
4
  "description": "Next Zod Modules Toolkit",
5
5
  "keywords": ["next", "full-stack", "server", "backend", "cli", "scaffolding", "zod", "rest", "contract programming", "contract-first", "react-query", "ddd", "domain-driven"],
6
6
  "repository": {