@api-client/core 0.20.7 → 0.20.8

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/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@api-client/core",
3
3
  "description": "The API Client's core client library. Works in NodeJS and in a ES enabled browser.",
4
- "version": "0.20.7",
4
+ "version": "0.20.8",
5
5
  "license": "UNLICENSED",
6
6
  "exports": {
7
7
  "./browser.js": {
@@ -16,6 +16,7 @@ import { DependentModel, type DependentModelSchema, type DomainDependency } from
16
16
  import { observed, toRaw } from '../decorators/observed.js'
17
17
  import pluralize from '@jarrodek/pluralize'
18
18
  import { createDomainKey } from './helpers/keying.js'
19
+ import { paramNameFor } from './helpers/endpointHelpers.js'
19
20
  import { ExposedEntity } from './ExposedEntity.js'
20
21
  import { AccessRule, AccessRuleSchema } from './rules/AccessRule.js'
21
22
  import { RateLimitingConfiguration, RateLimitingConfigurationSchema } from './rules/RateLimitingConfiguration.js'
@@ -462,15 +463,16 @@ export class ApiModel extends DependentModel {
462
463
  }
463
464
  const name = domainEntity.info.name || ''
464
465
  const segment = pluralize(name.toLocaleLowerCase())
466
+ const paramName = paramNameFor(name)
465
467
  let relativeCollectionPath = `/${segment}`
466
- let relativeResourcePath = `/${segment}/{id}`
468
+ let relativeResourcePath = `/${segment}/{${paramName}}`
467
469
 
468
470
  // Check for root path collision and resolve by appending a number
469
471
  let counter = 1
470
472
  const originalCollectionPath = relativeCollectionPath
471
473
  while (this.findCollectionPathCollision(relativeCollectionPath)) {
472
474
  relativeCollectionPath = `${originalCollectionPath}-${counter}`
473
- relativeResourcePath = `${relativeCollectionPath}/{id}`
475
+ relativeResourcePath = `${relativeCollectionPath}/{${paramName}}`
474
476
  counter++
475
477
  }
476
478
 
@@ -552,14 +554,15 @@ export class ApiModel extends DependentModel {
552
554
  if (targetDomEntity) {
553
555
  const name = targetDomEntity.info.name || ''
554
556
  const segment = pluralize(name.toLocaleLowerCase())
557
+ const paramName = paramNameFor(name)
555
558
  let relativeCollectionPath = `/${segment}`
556
- let relativeResourcePath = `/${segment}/{id}`
559
+ let relativeResourcePath = `/${segment}/{${paramName}}`
557
560
 
558
561
  let counter = 1
559
562
  const originalCollectionPath = relativeCollectionPath
560
563
  while (this.findResourcePathCollision(relativeCollectionPath)) {
561
564
  relativeCollectionPath = `${originalCollectionPath}-${counter}`
562
- relativeResourcePath = `${relativeCollectionPath}/{id}`
565
+ relativeResourcePath = `${relativeCollectionPath}/{${paramName}}`
563
566
  counter++
564
567
  }
565
568
 
@@ -582,8 +585,9 @@ export class ApiModel extends DependentModel {
582
585
  const name = association.info.name || ''
583
586
  const segment = pluralize(name.toLocaleLowerCase())
584
587
  const isCollection = association.multiple !== false
588
+ const paramName = paramNameFor(targetDomainEntity.info.name || '')
585
589
  const relativeCollectionPath = isCollection ? `/${segment}` : undefined
586
- const relativeResourcePath = isCollection ? `/${segment}/{id}` : `/${segment}`
590
+ const relativeResourcePath = isCollection ? `/${segment}/{${paramName}}` : `/${segment}`
587
591
  // Create nested exposure
588
592
  const nestedExposure: ExposedEntitySchema = {
589
593
  kind: ExposedEntityKind,
@@ -87,6 +87,7 @@ test.group('ApiModel.exposeEntity()', () => {
87
87
  assert.isDefined(nestedB)
88
88
  assert.deepEqual(nestedB?.parent?.key, exposedA.key)
89
89
  assert.strictEqual(nestedB?.collectionPath, '/entitybs')
90
+ assert.strictEqual(nestedB?.resourcePath, '/entitybs/{bId}')
90
91
  })
91
92
 
92
93
  test('does not infinitely expose circular associations', ({ assert }) => {
@@ -216,7 +217,7 @@ test.group('ApiModel.exposeEntity()', () => {
216
217
  // Expose second entity -> should resolve collision to /items-1
217
218
  const exp2 = model.exposeEntity({ key: e2.key })
218
219
  assert.equal(exp2.collectionPath, '/items-1')
219
- assert.equal(exp2.resourcePath, '/items-1/{id}')
220
+ assert.equal(exp2.resourcePath, '/items-1/{itemId}')
220
221
 
221
222
  // Expose third entity -> /items-2
222
223
  const e3 = dm.addEntity({ info: { name: 'Item' } })
@@ -10,7 +10,7 @@ test.group('OasGenerator', (group) => {
10
10
  let api: ApiModel
11
11
 
12
12
  group.each.setup(() => {
13
- domain = new DataDomain({ info: { name: 'Test Domain', version: '1.0.0' } })
13
+ domain = new DataDomain({ info: { name: 'Test Domain', version: '1.0.0' } }, undefined, { readOnly: true })
14
14
  const model = domain.addModel({ info: { name: 'model1' } })
15
15
  const user = model.addEntity({ info: { name: 'user' } })
16
16
  user.addSemantic({ id: SemanticType.User })
@@ -232,17 +232,17 @@ test.group('OasGenerator', (group) => {
232
232
  // User endpoints (CRUD)
233
233
  assert.isObject(paths['/users'].get, 'User list')
234
234
  assert.isObject(paths['/users'].post, 'User create')
235
- assert.isObject(paths['/users/{id}'].get, 'User read')
236
- assert.isObject(paths['/users/{id}'].put, 'User put')
237
- assert.isObject(paths['/users/{id}'].delete, 'User delete')
235
+ assert.isObject(paths['/users/{userId}'].get, 'User read')
236
+ assert.isObject(paths['/users/{userId}'].put, 'User put')
237
+ assert.isObject(paths['/users/{userId}'].delete, 'User delete')
238
238
 
239
239
  // Post endpoints (list, update, delete)
240
240
  assert.isObject(paths['/posts'].get)
241
241
  assert.isUndefined(paths['/posts'].post) // no create Action
242
- assert.isUndefined(paths['/posts/{id}'].get) // no read action
243
- assert.isObject(paths['/posts/{id}'].patch)
244
- assert.isObject(paths['/posts/{id}'].put)
245
- assert.isObject(paths['/posts/{id}'].delete)
242
+ assert.isUndefined(paths['/posts/{postId}'].get) // no read action
243
+ assert.isObject(paths['/posts/{postId}'].patch)
244
+ assert.isObject(paths['/posts/{postId}'].put)
245
+ assert.isObject(paths['/posts/{postId}'].delete)
246
246
  })
247
247
 
248
248
  test('generates standard error responses', ({ assert }) => {