@codewithagents/openapi-react-query 3.4.0 → 3.5.1

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.
@@ -18,7 +18,16 @@ const arbQueryParam = fc.record({
18
18
  })
19
19
 
20
20
  /** Realistic resource names */
21
- const RESOURCES = ['items', 'tasks', 'users', 'projects', 'orders', 'reports', 'documents', 'records']
21
+ const RESOURCES = [
22
+ 'items',
23
+ 'tasks',
24
+ 'users',
25
+ 'projects',
26
+ 'orders',
27
+ 'reports',
28
+ 'documents',
29
+ 'records',
30
+ ]
22
31
 
23
32
  /** Generates realistic path strings */
24
33
  const arbPath: fc.Arbitrary<string> = fc.oneof(
@@ -27,14 +36,20 @@ const arbPath: fc.Arbitrary<string> = fc.oneof(
27
36
  // /resources/{id} (1 path param)
28
37
  fc.tuple(fc.constantFrom(...RESOURCES), arbPathParam).map(([r, p]) => `/${r}/{${p}}`),
29
38
  // /resources/{p1}/sub/{p2} (2 path params)
30
- fc.tuple(fc.constantFrom(...RESOURCES), arbPathParam, fc.constantFrom(...RESOURCES), arbPathParam).map(
31
- ([r, p1, sub, p2]) => `/${r}/{${p1}}/${sub}/{${p2}}`,
32
- ),
39
+ fc
40
+ .tuple(fc.constantFrom(...RESOURCES), arbPathParam, fc.constantFrom(...RESOURCES), arbPathParam)
41
+ .map(([r, p1, sub, p2]) => `/${r}/{${p1}}/${sub}/{${p2}}`)
33
42
  )
34
43
 
35
44
  type HttpMethod = 'get' | 'post' | 'put' | 'patch' | 'delete'
36
45
 
37
- const arbHttpMethod: fc.Arbitrary<HttpMethod> = fc.constantFrom('get', 'post', 'put', 'patch', 'delete')
46
+ const arbHttpMethod: fc.Arbitrary<HttpMethod> = fc.constantFrom(
47
+ 'get',
48
+ 'post',
49
+ 'put',
50
+ 'patch',
51
+ 'delete'
52
+ )
38
53
 
39
54
  function extractPathParams(path: string): string[] {
40
55
  const matches = path.match(/\{([^}]+)\}/g)
@@ -53,7 +68,12 @@ interface ArbOp {
53
68
 
54
69
  /** Generates a single operation object */
55
70
  const arbOperation: fc.Arbitrary<ArbOp> = fc
56
- .tuple(arbOperationId, arbHttpMethod, arbPath, fc.array(arbQueryParam, { minLength: 0, maxLength: 3 }))
71
+ .tuple(
72
+ arbOperationId,
73
+ arbHttpMethod,
74
+ arbPath,
75
+ fc.array(arbQueryParam, { minLength: 0, maxLength: 3 })
76
+ )
57
77
  .map(([operationId, method, path, queryParams]) => {
58
78
  const pathParams = extractPathParams(path)
59
79
  const hasBody = method === 'post' || method === 'put' || method === 'patch'
@@ -124,7 +144,7 @@ describe('property-based tests — generateHooks invariants', () => {
124
144
  fc.property(arbSpec, (spec) => {
125
145
  expect(() => generateHooks(spec, { staleTime: 0, gcTime: 0 })).not.toThrow()
126
146
  }),
127
- { numRuns: 500 },
147
+ { numRuns: 500 }
128
148
  )
129
149
  })
130
150
 
@@ -142,7 +162,7 @@ describe('property-based tests — generateHooks invariants', () => {
142
162
  expect(content).toContain(`export function ${hookName}(`)
143
163
  }
144
164
  }),
145
- { numRuns: 300 },
165
+ { numRuns: 300 }
146
166
  )
147
167
  })
148
168
 
@@ -162,7 +182,7 @@ describe('property-based tests — generateHooks invariants', () => {
162
182
  }
163
183
  }
164
184
  }),
165
- { numRuns: 300 },
185
+ { numRuns: 300 }
166
186
  )
167
187
  })
168
188
 
@@ -174,14 +194,14 @@ describe('property-based tests — generateHooks invariants', () => {
174
194
  fc.assert(
175
195
  fc.property(arbSpec, (spec) => {
176
196
  const hasGet = Object.values(spec.paths ?? {}).some(
177
- (p) => (p as Record<string, unknown>)?.['get'] !== undefined,
197
+ (p) => (p as Record<string, unknown>)?.['get'] !== undefined
178
198
  )
179
199
  if (!hasGet) return // skip specs with no GET
180
200
  const { content } = generateHooks(spec, { staleTime: 0, gcTime: 0 })
181
201
  // The key factory always includes an `all:` method definition
182
202
  expect(content).toContain('all:')
183
203
  }),
184
- { numRuns: 300 },
204
+ { numRuns: 300 }
185
205
  )
186
206
  })
187
207
 
@@ -190,7 +210,7 @@ describe('property-based tests — generateHooks invariants', () => {
190
210
  fc.assert(
191
211
  fc.property(arbSpec, (spec) => {
192
212
  const { content } = generateHooks(spec, { staleTime: 0, gcTime: 0 })
193
- for (const [path, pathItem] of Object.entries(spec.paths ?? {})) {
213
+ for (const [_path, pathItem] of Object.entries(spec.paths ?? {})) {
194
214
  const op = (pathItem as Record<string, unknown>)['get'] as
195
215
  | { operationId?: string; parameters?: Array<{ in: string }> }
196
216
  | undefined
@@ -201,7 +221,7 @@ describe('property-based tests — generateHooks invariants', () => {
201
221
  expect(content).toContain('&&')
202
222
  }
203
223
  }),
204
- { numRuns: 200 },
224
+ { numRuns: 200 }
205
225
  )
206
226
  })
207
227
 
@@ -240,8 +260,7 @@ describe('property-based tests — generateHooks invariants', () => {
240
260
  if (!resourcesWithGets.has(firstSegment)) {
241
261
  // This mutation is on a resource with no GET → generator will still emit
242
262
  // `${factoryName}.all()` in the mutation hook, but the factory is never defined
243
- const hookName =
244
- 'use' + op.operationId[0]!.toUpperCase() + op.operationId.slice(1)
263
+ const hookName = 'use' + op.operationId[0]!.toUpperCase() + op.operationId.slice(1)
245
264
  const hookStart = content.indexOf(`export function ${hookName}(`)
246
265
  if (hookStart === -1) continue
247
266
  const hookEnd = content.indexOf('\n}', hookStart) + 2
@@ -249,7 +268,9 @@ describe('property-based tests — generateHooks invariants', () => {
249
268
 
250
269
  // The generated hook will reference factoryName (e.g. itemKeys)
251
270
  // but that factory is never exported — check if the factory is defined
252
- const camel = firstSegment.replace(/[-_](.)/g, (_: string, c: string) => c.toUpperCase())
271
+ const camel = firstSegment.replace(/[-_](.)/g, (_: string, c: string) =>
272
+ c.toUpperCase()
273
+ )
253
274
  const singular = camel.endsWith('s') ? camel.slice(0, -1) : camel
254
275
  const factoryName = `${singular}Keys`
255
276
 
@@ -261,7 +282,7 @@ describe('property-based tests — generateHooks invariants', () => {
261
282
  }
262
283
  }
263
284
  }),
264
- { numRuns: 200 },
285
+ { numRuns: 200 }
265
286
  )
266
287
  })
267
288
 
@@ -272,7 +293,7 @@ describe('property-based tests — generateHooks invariants', () => {
272
293
  const { content } = generateHooks(spec, { staleTime: 0, gcTime: 0 })
273
294
  expect(content).toMatch(/^\/\/ (This file is auto-generated|Generated)/)
274
295
  }),
275
- { numRuns: 200 },
296
+ { numRuns: 200 }
276
297
  )
277
298
  })
278
299
 
@@ -283,7 +304,7 @@ describe('property-based tests — generateHooks invariants', () => {
283
304
  const { filename } = generateHooks(spec, { staleTime: 0, gcTime: 0 })
284
305
  expect(filename).toBe('hooks.ts')
285
306
  }),
286
- { numRuns: 100 },
307
+ { numRuns: 100 }
287
308
  )
288
309
  })
289
310
  })