@api-client/core 0.18.30 → 0.18.32

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 (37) hide show
  1. package/build/src/browser.d.ts +1 -0
  2. package/build/src/browser.d.ts.map +1 -1
  3. package/build/src/browser.js +1 -0
  4. package/build/src/browser.js.map +1 -1
  5. package/build/src/index.d.ts +1 -0
  6. package/build/src/index.d.ts.map +1 -1
  7. package/build/src/index.js +1 -0
  8. package/build/src/index.js.map +1 -1
  9. package/build/src/modeling/ApiModel.d.ts +3 -2
  10. package/build/src/modeling/ApiModel.d.ts.map +1 -1
  11. package/build/src/modeling/ApiModel.js +23 -8
  12. package/build/src/modeling/ApiModel.js.map +1 -1
  13. package/build/src/modeling/ExposedEntity.d.ts +114 -0
  14. package/build/src/modeling/ExposedEntity.d.ts.map +1 -0
  15. package/build/src/modeling/ExposedEntity.js +300 -0
  16. package/build/src/modeling/ExposedEntity.js.map +1 -0
  17. package/build/src/modeling/helpers/endpointHelpers.d.ts +11 -0
  18. package/build/src/modeling/helpers/endpointHelpers.d.ts.map +1 -1
  19. package/build/src/modeling/helpers/endpointHelpers.js +21 -0
  20. package/build/src/modeling/helpers/endpointHelpers.js.map +1 -1
  21. package/build/src/modeling/types.d.ts +17 -4
  22. package/build/src/modeling/types.d.ts.map +1 -1
  23. package/build/src/modeling/types.js.map +1 -1
  24. package/build/src/models/kinds.d.ts +1 -0
  25. package/build/src/models/kinds.d.ts.map +1 -1
  26. package/build/src/models/kinds.js +1 -0
  27. package/build/src/models/kinds.js.map +1 -1
  28. package/build/tsconfig.tsbuildinfo +1 -1
  29. package/package.json +1 -1
  30. package/src/modeling/ApiModel.ts +28 -13
  31. package/src/modeling/ExposedEntity.ts +344 -0
  32. package/src/modeling/helpers/endpointHelpers.ts +22 -0
  33. package/src/modeling/types.ts +18 -3
  34. package/src/models/kinds.ts +1 -0
  35. package/tests/unit/modeling/api_model.spec.ts +49 -10
  36. package/tests/unit/modeling/api_model_expose_entity.spec.ts +1 -1
  37. package/tests/unit/modeling/exposed_entity.spec.ts +100 -0
@@ -0,0 +1,100 @@
1
+ import { test } from '@japa/runner'
2
+ import { ApiModel, ExposedEntity } from '../../../src/index.js'
3
+
4
+ test.group('ExposedEntity', () => {
5
+ test('setRelativeCollectionPath normalizes and preserves resource param', ({ assert }) => {
6
+ const model = new ApiModel()
7
+ const ex = new ExposedEntity(model, {
8
+ hasCollection: true,
9
+ relativeCollectionPath: '/items',
10
+ relativeResourcePath: '/items/{customId}',
11
+ })
12
+
13
+ ex.setRelativeCollectionPath('products')
14
+
15
+ assert.equal(ex.relativeCollectionPath, '/products')
16
+ assert.equal(ex.relativeResourcePath, '/products/{customId}')
17
+ }).tags(['@modeling', '@exposed-entity'])
18
+
19
+ test('setRelativeResourcePath with collection allows only parameter name change', ({ assert }) => {
20
+ const model = new ApiModel()
21
+ const ex = new ExposedEntity(model, {
22
+ hasCollection: true,
23
+ relativeCollectionPath: '/products',
24
+ relativeResourcePath: '/products/{id}',
25
+ })
26
+
27
+ // valid: same collection segment, different param name
28
+ ex.setRelativeResourcePath('/products/{productId}')
29
+ assert.equal(ex.relativeResourcePath, '/products/{productId}')
30
+
31
+ // invalid: different first segment
32
+ assert.throws(() => ex.setRelativeResourcePath('/wrong/{id}'))
33
+
34
+ // invalid: second segment not a parameter
35
+ assert.throws(() => ex.setRelativeResourcePath('/products/notParam'))
36
+ }).tags(['@modeling', '@exposed-entity'])
37
+
38
+ test('setRelativeResourcePath without collection must have exactly two segments', ({ assert }) => {
39
+ const model = new ApiModel()
40
+ const ex = new ExposedEntity(model, {
41
+ hasCollection: false,
42
+ relativeResourcePath: '/profile/{id}',
43
+ })
44
+
45
+ ex.setRelativeResourcePath('settings/secret')
46
+ assert.equal(ex.relativeResourcePath, '/settings/secret')
47
+
48
+ assert.throws(() => ex.setRelativeResourcePath('onlyone'))
49
+ }).tags(['@modeling', '@exposed-entity'])
50
+
51
+ test('computes absolute resource and collection paths along parent chain', ({ assert }) => {
52
+ const model = new ApiModel()
53
+
54
+ // Build exposure schemas
55
+ const rootSchema = {
56
+ key: 'root',
57
+ entity: { key: 'user' },
58
+ hasCollection: true,
59
+ relativeCollectionPath: '/users',
60
+ relativeResourcePath: '/users/{userId}',
61
+ isRoot: true,
62
+ actions: [],
63
+ }
64
+ const childSchema = {
65
+ key: 'child',
66
+ entity: { key: 'post' },
67
+ hasCollection: true,
68
+ relativeCollectionPath: '/posts',
69
+ relativeResourcePath: '/posts/{postId}',
70
+ parent: { key: 'root', association: { key: 'toPosts' } },
71
+ actions: [],
72
+ }
73
+ const grandSchema = {
74
+ key: 'grand',
75
+ entity: { key: 'details' },
76
+ hasCollection: false,
77
+ relativeResourcePath: '/details',
78
+ parent: { key: 'child', association: { key: 'toDetails' } },
79
+ actions: [],
80
+ }
81
+ // Instantiate instances bound to the model
82
+ const rootEx = new ExposedEntity(model, rootSchema)
83
+ const childEx = new ExposedEntity(model, childSchema)
84
+ const grandEx = new ExposedEntity(model, grandSchema)
85
+ // attach to model as instances
86
+ model.exposes = [rootEx, childEx, grandEx]
87
+
88
+ // root
89
+ assert.equal(rootEx.getAbsoluteCollectionPath(), '/users')
90
+ assert.equal(rootEx.getAbsoluteResourcePath(), '/users/{userId}')
91
+
92
+ // child
93
+ assert.equal(childEx.getAbsoluteCollectionPath(), '/users/{userId}/posts')
94
+ assert.equal(childEx.getAbsoluteResourcePath(), '/users/{userId}/posts/{postId}')
95
+
96
+ // grand (no collection)
97
+ assert.isUndefined(grandEx.getAbsoluteCollectionPath())
98
+ assert.equal(grandEx.getAbsoluteResourcePath(), '/users/{userId}/posts/{postId}/details')
99
+ }).tags(['@modeling', '@exposed-entity'])
100
+ })