@api-client/core 0.18.57 → 0.18.59

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 (132) hide show
  1. package/build/src/decorators/observed.d.ts.map +1 -1
  2. package/build/src/decorators/observed.js +15 -1
  3. package/build/src/decorators/observed.js.map +1 -1
  4. package/build/src/modeling/ApiModel.d.ts +7 -5
  5. package/build/src/modeling/ApiModel.d.ts.map +1 -1
  6. package/build/src/modeling/ApiModel.js +35 -16
  7. package/build/src/modeling/ApiModel.js.map +1 -1
  8. package/build/src/modeling/ExposedEntity.d.ts +5 -2
  9. package/build/src/modeling/ExposedEntity.d.ts.map +1 -1
  10. package/build/src/modeling/ExposedEntity.js +11 -8
  11. package/build/src/modeling/ExposedEntity.js.map +1 -1
  12. package/build/src/modeling/actions/Action.d.ts +41 -0
  13. package/build/src/modeling/actions/Action.d.ts.map +1 -0
  14. package/build/src/modeling/actions/Action.js +64 -0
  15. package/build/src/modeling/actions/Action.js.map +1 -0
  16. package/build/src/modeling/actions/CreateAction.d.ts +20 -0
  17. package/build/src/modeling/actions/CreateAction.d.ts.map +1 -0
  18. package/build/src/modeling/actions/CreateAction.js +43 -0
  19. package/build/src/modeling/actions/CreateAction.js.map +1 -0
  20. package/build/src/modeling/actions/DeleteAction.d.ts +36 -0
  21. package/build/src/modeling/actions/DeleteAction.d.ts.map +1 -0
  22. package/build/src/modeling/actions/DeleteAction.js +63 -0
  23. package/build/src/modeling/actions/DeleteAction.js.map +1 -0
  24. package/build/src/modeling/actions/ListAction.d.ts +39 -0
  25. package/build/src/modeling/actions/ListAction.d.ts.map +1 -0
  26. package/build/src/modeling/actions/ListAction.js +76 -0
  27. package/build/src/modeling/actions/ListAction.js.map +1 -0
  28. package/build/src/modeling/actions/ReadAction.d.ts +20 -0
  29. package/build/src/modeling/actions/ReadAction.d.ts.map +1 -0
  30. package/build/src/modeling/actions/ReadAction.js +43 -0
  31. package/build/src/modeling/actions/ReadAction.js.map +1 -0
  32. package/build/src/modeling/actions/SearchAction.d.ts +26 -0
  33. package/build/src/modeling/actions/SearchAction.d.ts.map +1 -0
  34. package/build/src/modeling/actions/SearchAction.js +53 -0
  35. package/build/src/modeling/actions/SearchAction.js.map +1 -0
  36. package/build/src/modeling/actions/UpdateAction.d.ts +29 -0
  37. package/build/src/modeling/actions/UpdateAction.d.ts.map +1 -0
  38. package/build/src/modeling/actions/UpdateAction.js +53 -0
  39. package/build/src/modeling/actions/UpdateAction.js.map +1 -0
  40. package/build/src/modeling/actions/index.d.ts +24 -0
  41. package/build/src/modeling/actions/index.d.ts.map +1 -0
  42. package/build/src/modeling/actions/index.js +9 -0
  43. package/build/src/modeling/actions/index.js.map +1 -0
  44. package/build/src/modeling/index.d.ts +12 -0
  45. package/build/src/modeling/index.d.ts.map +1 -0
  46. package/build/src/modeling/index.js +12 -0
  47. package/build/src/modeling/index.js.map +1 -0
  48. package/build/src/modeling/rules/AccessRule.d.ts +17 -0
  49. package/build/src/modeling/rules/AccessRule.d.ts.map +1 -0
  50. package/build/src/modeling/rules/AccessRule.js +19 -0
  51. package/build/src/modeling/rules/AccessRule.js.map +1 -0
  52. package/build/src/modeling/rules/AllowAuthenticated.d.ts +19 -0
  53. package/build/src/modeling/rules/AllowAuthenticated.d.ts.map +1 -0
  54. package/build/src/modeling/rules/AllowAuthenticated.js +14 -0
  55. package/build/src/modeling/rules/AllowAuthenticated.js.map +1 -0
  56. package/build/src/modeling/rules/AllowPublic.d.ts +19 -0
  57. package/build/src/modeling/rules/AllowPublic.d.ts.map +1 -0
  58. package/build/src/modeling/rules/AllowPublic.js +14 -0
  59. package/build/src/modeling/rules/AllowPublic.js.map +1 -0
  60. package/build/src/modeling/rules/MatchEmailDomain.d.ts +25 -0
  61. package/build/src/modeling/rules/MatchEmailDomain.d.ts.map +1 -0
  62. package/build/src/modeling/rules/MatchEmailDomain.js +40 -0
  63. package/build/src/modeling/rules/MatchEmailDomain.js.map +1 -0
  64. package/build/src/modeling/rules/MatchResourceOwner.d.ts +29 -0
  65. package/build/src/modeling/rules/MatchResourceOwner.d.ts.map +1 -0
  66. package/build/src/modeling/rules/MatchResourceOwner.js +40 -0
  67. package/build/src/modeling/rules/MatchResourceOwner.js.map +1 -0
  68. package/build/src/modeling/rules/MatchUserProperty.d.ts +28 -0
  69. package/build/src/modeling/rules/MatchUserProperty.d.ts.map +1 -0
  70. package/build/src/modeling/rules/MatchUserProperty.js +49 -0
  71. package/build/src/modeling/rules/MatchUserProperty.js.map +1 -0
  72. package/build/src/modeling/rules/MatchUserRole.d.ts +29 -0
  73. package/build/src/modeling/rules/MatchUserRole.d.ts.map +1 -0
  74. package/build/src/modeling/rules/MatchUserRole.js +40 -0
  75. package/build/src/modeling/rules/MatchUserRole.js.map +1 -0
  76. package/build/src/modeling/rules/RateLimitRule.d.ts +61 -0
  77. package/build/src/modeling/rules/RateLimitRule.d.ts.map +1 -0
  78. package/build/src/modeling/rules/RateLimitRule.js +101 -0
  79. package/build/src/modeling/rules/RateLimitRule.js.map +1 -0
  80. package/build/src/modeling/rules/RateLimitingConfiguration.d.ts +18 -0
  81. package/build/src/modeling/rules/RateLimitingConfiguration.d.ts.map +1 -0
  82. package/build/src/modeling/rules/RateLimitingConfiguration.js +35 -0
  83. package/build/src/modeling/rules/RateLimitingConfiguration.js.map +1 -0
  84. package/build/src/modeling/rules/index.d.ts +14 -0
  85. package/build/src/modeling/rules/index.d.ts.map +1 -0
  86. package/build/src/modeling/rules/index.js +11 -0
  87. package/build/src/modeling/rules/index.js.map +1 -0
  88. package/build/src/modeling/types.d.ts +6 -257
  89. package/build/src/modeling/types.d.ts.map +1 -1
  90. package/build/src/modeling/types.js.map +1 -1
  91. package/build/tsconfig.tsbuildinfo +1 -1
  92. package/data/models/example-generator-api.json +6 -6
  93. package/package.json +1 -1
  94. package/src/decorators/observed.ts +15 -1
  95. package/src/modeling/ApiModel.ts +21 -19
  96. package/src/modeling/ExposedEntity.ts +13 -18
  97. package/src/modeling/actions/Action.ts +64 -0
  98. package/src/modeling/actions/CreateAction.ts +38 -0
  99. package/src/modeling/actions/DeleteAction.ts +59 -0
  100. package/src/modeling/actions/ListAction.ts +66 -0
  101. package/src/modeling/actions/ReadAction.ts +40 -0
  102. package/src/modeling/actions/SearchAction.ts +46 -0
  103. package/src/modeling/actions/UpdateAction.ts +49 -0
  104. package/src/modeling/rules/AccessRule.ts +29 -0
  105. package/src/modeling/rules/AllowAuthenticated.ts +24 -0
  106. package/src/modeling/rules/AllowPublic.ts +24 -0
  107. package/src/modeling/rules/MatchEmailDomain.ts +39 -0
  108. package/src/modeling/rules/MatchResourceOwner.ts +43 -0
  109. package/src/modeling/rules/MatchUserProperty.ts +44 -0
  110. package/src/modeling/rules/MatchUserRole.ts +43 -0
  111. package/src/modeling/rules/RateLimitRule.ts +104 -0
  112. package/src/modeling/rules/RateLimitingConfiguration.ts +32 -0
  113. package/src/modeling/types.ts +6 -276
  114. package/tests/unit/decorators/observed.spec.ts +42 -0
  115. package/tests/unit/modeling/actions/Action.spec.ts +109 -0
  116. package/tests/unit/modeling/actions/CreateAction.spec.ts +65 -0
  117. package/tests/unit/modeling/actions/DeleteAction.spec.ts +78 -0
  118. package/tests/unit/modeling/actions/ListAction.spec.ts +106 -0
  119. package/tests/unit/modeling/actions/ReadAction.spec.ts +77 -0
  120. package/tests/unit/modeling/actions/SearchAction.spec.ts +73 -0
  121. package/tests/unit/modeling/actions/UpdateAction.spec.ts +73 -0
  122. package/tests/unit/modeling/api_model.spec.ts +48 -3
  123. package/tests/unit/modeling/exposed_entity.spec.ts +73 -0
  124. package/tests/unit/modeling/rules/AccessRule.spec.ts +42 -0
  125. package/tests/unit/modeling/rules/AllowAuthenticated.spec.ts +28 -0
  126. package/tests/unit/modeling/rules/AllowPublic.spec.ts +28 -0
  127. package/tests/unit/modeling/rules/MatchEmailDomain.spec.ts +52 -0
  128. package/tests/unit/modeling/rules/MatchResourceOwner.spec.ts +37 -0
  129. package/tests/unit/modeling/rules/MatchUserProperty.spec.ts +58 -0
  130. package/tests/unit/modeling/rules/MatchUserRole.spec.ts +52 -0
  131. package/tests/unit/modeling/rules/RateLimitRule.spec.ts +70 -0
  132. package/tests/unit/modeling/rules/RateLimitingConfiguration.spec.ts +61 -0
@@ -0,0 +1,37 @@
1
+ import { test } from '@japa/runner'
2
+ import { MatchResourceOwnerAccessRule } from '../../../../src/modeling/rules/MatchResourceOwner.js'
3
+
4
+ test.group('MatchResourceOwnerAccessRule', () => {
5
+ test('initializes with default values', ({ assert }) => {
6
+ const rule = new MatchResourceOwnerAccessRule()
7
+ assert.equal(rule.type, 'resourceOwner')
8
+ assert.equal(rule.property, '')
9
+ }).tags(['@modeling', '@rule', '@match-resource-owner'])
10
+
11
+ test('initializes with provided values', ({ assert }) => {
12
+ const rule = new MatchResourceOwnerAccessRule({ property: 'creatorId' })
13
+
14
+ assert.equal(rule.type, 'resourceOwner')
15
+ assert.equal(rule.property, 'creatorId')
16
+ }).tags(['@modeling', '@rule', '@match-resource-owner'])
17
+
18
+ test('toJSON returns valid schema', ({ assert }) => {
19
+ const rule = new MatchResourceOwnerAccessRule({ property: 'creatorId' })
20
+ const json = rule.toJSON()
21
+
22
+ assert.equal(json.type, 'resourceOwner')
23
+ assert.equal(json.property, 'creatorId')
24
+ }).tags(['@modeling', '@rule', '@match-resource-owner', '@serialization'])
25
+
26
+ test('notifies change when property changes', async ({ assert }) => {
27
+ const rule = new MatchResourceOwnerAccessRule()
28
+ let notified = false
29
+ rule.addEventListener('change', () => {
30
+ notified = true
31
+ })
32
+
33
+ rule.property = 'ownerId'
34
+ await Promise.resolve()
35
+ assert.isTrue(notified)
36
+ }).tags(['@modeling', '@rule', '@match-resource-owner', '@observed'])
37
+ })
@@ -0,0 +1,58 @@
1
+ import { test } from '@japa/runner'
2
+ import { MatchUserPropertyAccessRule } from '../../../../src/modeling/rules/MatchUserProperty.js'
3
+
4
+ test.group('MatchUserPropertyAccessRule', () => {
5
+ test('initializes with default values', ({ assert }) => {
6
+ const rule = new MatchUserPropertyAccessRule()
7
+ assert.equal(rule.type, 'matchUserProperty')
8
+ assert.equal(rule.property, '')
9
+ assert.equal(rule.value, '')
10
+ }).tags(['@modeling', '@rule', '@match-user-property'])
11
+
12
+ test('initializes with provided values', ({ assert }) => {
13
+ const rule = new MatchUserPropertyAccessRule({
14
+ property: 'department',
15
+ value: 'engineering',
16
+ })
17
+
18
+ assert.equal(rule.type, 'matchUserProperty')
19
+ assert.equal(rule.property, 'department')
20
+ assert.equal(rule.value, 'engineering')
21
+ }).tags(['@modeling', '@rule', '@match-user-property'])
22
+
23
+ test('toJSON returns valid schema', ({ assert }) => {
24
+ const rule = new MatchUserPropertyAccessRule({
25
+ property: 'department',
26
+ value: 'engineering',
27
+ })
28
+ const json = rule.toJSON()
29
+
30
+ assert.equal(json.type, 'matchUserProperty')
31
+ assert.equal(json.property, 'department')
32
+ assert.equal(json.value, 'engineering')
33
+ }).tags(['@modeling', '@rule', '@match-user-property', '@serialization'])
34
+
35
+ test('notifies change when property changes', async ({ assert }) => {
36
+ const rule = new MatchUserPropertyAccessRule()
37
+ let notified = false
38
+ rule.addEventListener('change', () => {
39
+ notified = true
40
+ })
41
+
42
+ rule.property = 'dept'
43
+ await Promise.resolve()
44
+ assert.isTrue(notified)
45
+ }).tags(['@modeling', '@rule', '@match-user-property', '@observed'])
46
+
47
+ test('notifies change when value changes', async ({ assert }) => {
48
+ const rule = new MatchUserPropertyAccessRule()
49
+ let notified = false
50
+ rule.addEventListener('change', () => {
51
+ notified = true
52
+ })
53
+
54
+ rule.value = 'sales'
55
+ await Promise.resolve()
56
+ assert.isTrue(notified)
57
+ }).tags(['@modeling', '@rule', '@match-user-property', '@observed'])
58
+ })
@@ -0,0 +1,52 @@
1
+ import { test } from '@japa/runner'
2
+ import { MatchUserRoleAccessRule } from '../../../../src/modeling/rules/MatchUserRole.js'
3
+
4
+ test.group('MatchUserRoleAccessRule', () => {
5
+ test('initializes with default values', ({ assert }) => {
6
+ const rule = new MatchUserRoleAccessRule()
7
+ assert.equal(rule.type, 'matchUserRole')
8
+ assert.deepEqual(rule.role, [])
9
+ }).tags(['@modeling', '@rule', '@match-user-role'])
10
+
11
+ test('initializes with provided values', ({ assert }) => {
12
+ const role = ['admin', 'manager']
13
+ const rule = new MatchUserRoleAccessRule({ role })
14
+
15
+ assert.equal(rule.type, 'matchUserRole')
16
+ assert.deepEqual(rule.role, role)
17
+ }).tags(['@modeling', '@rule', '@match-user-role'])
18
+
19
+ test('constructor copies arrays (immutability)', ({ assert }) => {
20
+ const role = ['admin']
21
+ const rule = new MatchUserRoleAccessRule({ role })
22
+
23
+ // Modify original source
24
+ role.push('guest')
25
+
26
+ assert.deepEqual(rule.role, ['admin'])
27
+ }).tags(['@modeling', '@rule', '@match-user-role', '@immutability'])
28
+
29
+ test('toJSON returns valid schema', ({ assert }) => {
30
+ const rule = new MatchUserRoleAccessRule({ role: ['admin'] })
31
+ const json = rule.toJSON()
32
+
33
+ // Modify JSON
34
+ json.role.push('guest')
35
+
36
+ assert.equal(json.type, 'matchUserRole')
37
+ assert.lengthOf(rule.role, 1) // Ensure immutability
38
+ assert.equal(rule.role[0], 'admin')
39
+ }).tags(['@modeling', '@rule', '@match-user-role', '@serialization', '@immutability'])
40
+
41
+ test('notifies change when role changes', async ({ assert }) => {
42
+ const rule = new MatchUserRoleAccessRule()
43
+ let notified = false
44
+ rule.addEventListener('change', () => {
45
+ notified = true
46
+ })
47
+
48
+ rule.role = ['admin']
49
+ await Promise.resolve()
50
+ assert.isTrue(notified)
51
+ }).tags(['@modeling', '@rule', '@match-user-role', '@observed'])
52
+ })
@@ -0,0 +1,70 @@
1
+ import { test } from '@japa/runner'
2
+ import { RateLimitRule } from '../../../../src/modeling/rules/RateLimitRule.js'
3
+
4
+ test.group('RateLimitRule', () => {
5
+ test('initializes with default values', ({ assert }) => {
6
+ const rule = new RateLimitRule()
7
+ assert.isUndefined(rule.description)
8
+ assert.isUndefined(rule.key)
9
+ assert.isUndefined(rule.rate)
10
+ assert.isUndefined(rule.interval)
11
+ assert.isUndefined(rule.burst)
12
+ }).tags(['@modeling', '@rule', '@rate-limit'])
13
+
14
+ test('initializes with provided values', ({ assert }) => {
15
+ const rule = new RateLimitRule({
16
+ description: 'Test Rule',
17
+ key: { type: 'ip' },
18
+ rate: 100,
19
+ interval: 'minute',
20
+ burst: 10,
21
+ })
22
+
23
+ assert.equal(rule.description, 'Test Rule')
24
+ assert.deepEqual(rule.key, { type: 'ip' })
25
+ assert.equal(rule.rate, 100)
26
+ assert.equal(rule.interval, 'minute')
27
+ assert.equal(rule.burst, 10)
28
+ }).tags(['@modeling', '@rule', '@rate-limit'])
29
+
30
+ test('constructor copies objects (immutability)', ({ assert }) => {
31
+ const key = { type: 'role', value: 'admin' } as const
32
+ const rule = new RateLimitRule({ key })
33
+
34
+ // Modify original source
35
+ // @ts-expect-error: modifying readonly property for test
36
+ key.value = 'guest'
37
+
38
+ assert.deepEqual(rule.key, { type: 'role', value: 'admin' })
39
+ }).tags(['@modeling', '@rule', '@rate-limit', '@immutability'])
40
+
41
+ test('toJSON returns valid schema', ({ assert }) => {
42
+ const rule = new RateLimitRule({
43
+ description: 'Test Rule',
44
+ key: { type: 'userId' },
45
+ rate: 60,
46
+ interval: 'hour',
47
+ burst: 5,
48
+ })
49
+
50
+ const json = rule.toJSON()
51
+
52
+ assert.equal(json.description, 'Test Rule')
53
+ assert.deepEqual(json.key, { type: 'userId' })
54
+ assert.equal(json.rate, 60)
55
+ assert.equal(json.interval, 'hour')
56
+ assert.equal(json.burst, 5)
57
+ }).tags(['@modeling', '@rule', '@rate-limit', '@serialization'])
58
+
59
+ test('notifies change when properties change', async ({ assert }) => {
60
+ const rule = new RateLimitRule()
61
+ let notified = false
62
+ rule.addEventListener('change', () => {
63
+ notified = true
64
+ })
65
+
66
+ rule.rate = 50
67
+ await Promise.resolve()
68
+ assert.isTrue(notified)
69
+ }).tags(['@modeling', '@rule', '@rate-limit', '@observed'])
70
+ })
@@ -0,0 +1,61 @@
1
+ import { test } from '@japa/runner'
2
+ import { RateLimitingConfiguration } from '../../../../src/modeling/rules/RateLimitingConfiguration.js'
3
+ import { RateLimitRule } from '../../../../src/modeling/rules/RateLimitRule.js'
4
+
5
+ test.group('RateLimitingConfiguration', () => {
6
+ test('initializes with default values', ({ assert }) => {
7
+ const config = new RateLimitingConfiguration()
8
+ assert.deepEqual(config.rules, [])
9
+ }).tags(['@modeling', '@rule', '@rate-limiting-config'])
10
+
11
+ test('initializes with provided rules', ({ assert }) => {
12
+ const rule = { rate: 100, interval: 'minute' } as const
13
+ const config = new RateLimitingConfiguration({
14
+ rules: [rule],
15
+ })
16
+
17
+ assert.lengthOf(config.rules, 1)
18
+ assert.instanceOf(config.rules[0], RateLimitRule)
19
+ assert.equal(config.rules[0].rate, 100)
20
+ }).tags(['@modeling', '@rule', '@rate-limiting-config'])
21
+
22
+ test('toJSON returns valid schema', ({ assert }) => {
23
+ const config = new RateLimitingConfiguration({
24
+ rules: [{ rate: 100, interval: 'minute' }],
25
+ })
26
+
27
+ const json = config.toJSON()
28
+
29
+ assert.lengthOf(json.rules, 1)
30
+ assert.equal(json.rules[0].rate, 100)
31
+ assert.equal(json.rules[0].interval, 'minute')
32
+ }).tags(['@modeling', '@rule', '@rate-limiting-config', '@serialization'])
33
+
34
+ test('notifies change when rules are added', async ({ assert }) => {
35
+ const config = new RateLimitingConfiguration()
36
+ let notified = false
37
+ config.addEventListener('change', () => {
38
+ notified = true
39
+ })
40
+
41
+ config.rules.push(new RateLimitRule({ rate: 10 }))
42
+ await Promise.resolve()
43
+ assert.isTrue(notified)
44
+ }).tags(['@modeling', '@rule', '@rate-limiting-config', '@observed'])
45
+
46
+ test('notifies change when nested rule changes', async ({ assert }) => {
47
+ const rule = new RateLimitRule({ rate: 10 })
48
+ const config = new RateLimitingConfiguration()
49
+ config.rules.push(rule)
50
+ await Promise.resolve() // Wait for push notification to settle
51
+
52
+ let notified = false
53
+ config.addEventListener('change', () => {
54
+ notified = true
55
+ })
56
+
57
+ config.rules[0].rate = 20
58
+ await Promise.resolve()
59
+ assert.isTrue(notified)
60
+ }).tags(['@modeling', '@rule', '@rate-limiting-config', '@observed'])
61
+ })