@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,29 @@
1
+ export interface AccessRuleSchema {
2
+ /**
3
+ * The unique identifier for the access rule.
4
+ * This is used to reference the rule in the API configuration.
5
+ */
6
+ type: string
7
+ }
8
+
9
+ /**
10
+ * Base class for all access rules.
11
+ */
12
+ export class AccessRule extends EventTarget implements AccessRuleSchema {
13
+ readonly type: string
14
+
15
+ constructor(state: Partial<AccessRuleSchema> = {}) {
16
+ super()
17
+ this.type = state.type ?? ''
18
+ }
19
+
20
+ toJSON(): AccessRuleSchema {
21
+ return {
22
+ type: this.type,
23
+ }
24
+ }
25
+
26
+ notifyChange() {
27
+ this.dispatchEvent(new Event('change'))
28
+ }
29
+ }
@@ -0,0 +1,24 @@
1
+ import { AccessRule, type AccessRuleSchema } from './AccessRule.js'
2
+
3
+ /**
4
+ * The action is allowed for any authenticated user.
5
+ * This rule does not impose any additional restrictions based on user properties or resource ownership.
6
+ * It is used for resources that should be accessible to all logged-in users.
7
+ */
8
+ export interface AllowAuthenticatedAccessRuleSchema extends AccessRuleSchema {
9
+ type: 'authenticated'
10
+ }
11
+
12
+ /**
13
+ * The action is allowed for any authenticated user.
14
+ * This rule does not impose any additional restrictions based on user properties or resource ownership.
15
+ * It is used for resources that should be accessible to all logged-in users.
16
+ */
17
+ export class AllowAuthenticatedAccessRule extends AccessRule implements AllowAuthenticatedAccessRuleSchema {
18
+ override readonly type: 'authenticated'
19
+
20
+ constructor(state: Partial<AllowAuthenticatedAccessRuleSchema> = {}) {
21
+ super(state)
22
+ this.type = 'authenticated'
23
+ }
24
+ }
@@ -0,0 +1,24 @@
1
+ import { AccessRule, type AccessRuleSchema } from './AccessRule.js'
2
+
3
+ /**
4
+ * The action is allowed for all users, including unauthenticated ones.
5
+ * This is typically used for public APIs or resources that do not require authentication.
6
+ * It is the most permissive rule and should be used with caution.
7
+ */
8
+ export interface AllowPublicAccessRuleSchema extends AccessRuleSchema {
9
+ type: 'public'
10
+ }
11
+
12
+ /**
13
+ * The action is allowed for all users, including unauthenticated ones.
14
+ * This is typically used for public APIs or resources that do not require authentication.
15
+ * It is the most permissive rule and should be used with caution.
16
+ */
17
+ export class AllowPublicAccessRule extends AccessRule implements AllowPublicAccessRuleSchema {
18
+ override readonly type: 'public'
19
+
20
+ constructor(state: Partial<AllowPublicAccessRuleSchema> = {}) {
21
+ super(state)
22
+ this.type = 'public'
23
+ }
24
+ }
@@ -0,0 +1,39 @@
1
+ import { AccessRule, type AccessRuleSchema } from './AccessRule.js'
2
+ import { observed, toRaw } from '../../decorators/observed.js'
3
+
4
+ /**
5
+ * The action is allowed if the authenticated user's email domain matches a specific domain.
6
+ * This is used to restrict access based on the user's email address.
7
+ * For example, only users with an email address from "my-company.com" can access certain resources.
8
+ */
9
+ export interface MatchEmailDomainAccessRuleSchema extends AccessRuleSchema {
10
+ type: 'matchEmailDomain'
11
+ /**
12
+ * The email domains that the authenticated user's email must match.
13
+ */
14
+ domains: string[]
15
+ }
16
+
17
+ /**
18
+ * The action is allowed if the authenticated user's email domain matches a specific domain.
19
+ * This is used to restrict access based on the user's email address.
20
+ * For example, only users with an email address from "my-company.com" can access certain resources.
21
+ */
22
+ export class MatchEmailDomainAccessRule extends AccessRule implements MatchEmailDomainAccessRuleSchema {
23
+ override readonly type: 'matchEmailDomain'
24
+
25
+ @observed({ deep: true }) accessor domains: string[]
26
+
27
+ constructor(state: Partial<MatchEmailDomainAccessRuleSchema> = {}) {
28
+ super(state)
29
+ this.type = 'matchEmailDomain'
30
+ this.domains = state.domains ? [...state.domains] : []
31
+ }
32
+
33
+ override toJSON(): MatchEmailDomainAccessRuleSchema {
34
+ return {
35
+ ...(super.toJSON() as MatchEmailDomainAccessRuleSchema),
36
+ domains: structuredClone(toRaw(this, this.domains)) as string[],
37
+ }
38
+ }
39
+ }
@@ -0,0 +1,43 @@
1
+ import { AccessRule, type AccessRuleSchema } from './AccessRule.js'
2
+ import { observed } from '../../decorators/observed.js'
3
+
4
+ /**
5
+ * The action is allowed if the authenticated user's ID matches a specific property on the resource.
6
+ * This is typically used to restrict access to resources owned by the user.
7
+ * For example, a user can only access their own profile or documents.
8
+ */
9
+ export interface MatchResourceOwnerAccessRuleSchema extends AccessRuleSchema {
10
+ type: 'resourceOwner'
11
+ /**
12
+ * The property on the resource that should match the authenticated user's ID.
13
+ * This is typically the ID of the user who owns the resource.
14
+ *
15
+ * The domain model should annotate this property with the "ResourceOwnerIdentifier" semantic
16
+ * to indicate that it is used for ownership checks.
17
+ */
18
+ property: string
19
+ }
20
+
21
+ /**
22
+ * The action is allowed if the authenticated user's ID matches a specific property on the resource.
23
+ * This is typically used to restrict access to resources owned by the user.
24
+ * For example, a user can only access their own profile or documents.
25
+ */
26
+ export class MatchResourceOwnerAccessRule extends AccessRule implements MatchResourceOwnerAccessRuleSchema {
27
+ override readonly type: 'resourceOwner'
28
+
29
+ @observed() accessor property: string
30
+
31
+ constructor(state: Partial<MatchResourceOwnerAccessRuleSchema> = {}) {
32
+ super(state)
33
+ this.type = 'resourceOwner'
34
+ this.property = state.property ?? ''
35
+ }
36
+
37
+ override toJSON(): MatchResourceOwnerAccessRuleSchema {
38
+ return {
39
+ ...(super.toJSON() as MatchResourceOwnerAccessRuleSchema),
40
+ property: this.property,
41
+ }
42
+ }
43
+ }
@@ -0,0 +1,44 @@
1
+ import { AccessRule, type AccessRuleSchema } from './AccessRule.js'
2
+ import { observed } from '../../decorators/observed.js'
3
+
4
+ /**
5
+ * The action is allowed if a specific property on the authenticated user matches an expected value.
6
+ * This is used to enforce other user-specific restrictions.
7
+ */
8
+ export interface MatchUserPropertyAccessRuleSchema extends AccessRuleSchema {
9
+ type: 'matchUserProperty'
10
+ /**
11
+ * The property on the authenticated user that should match the expected value.
12
+ */
13
+ property: string
14
+ /**
15
+ * The expected value for the user property.
16
+ */
17
+ value: string
18
+ }
19
+
20
+ /**
21
+ * The action is allowed if a specific property on the authenticated user matches an expected value.
22
+ * This is used to enforce other user-specific restrictions.
23
+ */
24
+ export class MatchUserPropertyAccessRule extends AccessRule implements MatchUserPropertyAccessRuleSchema {
25
+ override readonly type: 'matchUserProperty'
26
+
27
+ @observed() accessor property: string
28
+ @observed() accessor value: string
29
+
30
+ constructor(state: Partial<MatchUserPropertyAccessRuleSchema> = {}) {
31
+ super(state)
32
+ this.type = 'matchUserProperty'
33
+ this.property = state.property ?? ''
34
+ this.value = state.value ?? ''
35
+ }
36
+
37
+ override toJSON(): MatchUserPropertyAccessRuleSchema {
38
+ return {
39
+ ...(super.toJSON() as MatchUserPropertyAccessRuleSchema),
40
+ property: this.property,
41
+ value: this.value,
42
+ }
43
+ }
44
+ }
@@ -0,0 +1,43 @@
1
+ import { AccessRule, type AccessRuleSchema } from './AccessRule.js'
2
+ import { observed, toRaw } from '../../decorators/observed.js'
3
+
4
+ /**
5
+ * The action is allowed if the authenticated user has a specific role.
6
+ * This is used to enforce role-based access control (RBAC).
7
+ * For example, only users with the "admin" role can perform certain actions.
8
+ */
9
+ export interface MatchUserRoleAccessRuleSchema extends AccessRuleSchema {
10
+ type: 'matchUserRole'
11
+ /**
12
+ * The role that the authenticated user must have to access the resource.
13
+ * This is typically a property on the user entity that defines their role.
14
+ *
15
+ * The domain model should annotate this property with the "UserRole" semantic
16
+ * to indicate that it is used for role-based access control.
17
+ */
18
+ role: string[]
19
+ }
20
+
21
+ /**
22
+ * The action is allowed if the authenticated user has a specific role.
23
+ * This is used to enforce role-based access control (RBAC).
24
+ * For example, only users with the "admin" role can perform certain actions.
25
+ */
26
+ export class MatchUserRoleAccessRule extends AccessRule implements MatchUserRoleAccessRuleSchema {
27
+ override readonly type: 'matchUserRole'
28
+
29
+ @observed({ deep: true }) accessor role: string[]
30
+
31
+ constructor(state: Partial<MatchUserRoleAccessRuleSchema> = {}) {
32
+ super(state)
33
+ this.type = 'matchUserRole'
34
+ this.role = state.role ? [...state.role] : []
35
+ }
36
+
37
+ override toJSON(): MatchUserRoleAccessRuleSchema {
38
+ return {
39
+ ...(super.toJSON() as MatchUserRoleAccessRuleSchema),
40
+ role: structuredClone(toRaw(this, this.role)) as string[],
41
+ }
42
+ }
43
+ }
@@ -0,0 +1,104 @@
1
+ import { observed, toRaw } from '../../decorators/observed.js'
2
+
3
+ export type RateLimitRuleKey = { type: 'ip' } | { type: 'userId' } | { type: 'role'; value: string }
4
+ export type RateLimitRuleInterval = 'second' | 'minute' | 'hour' | 'day'
5
+
6
+ /**
7
+ * Represents a single rate limiting rule that applies to a specific
8
+ * type of client, using a token bucket algorithm.
9
+ */
10
+ export interface RateLimitRuleSchema {
11
+ /**
12
+ * A human-readable description of what this rule is for.
13
+ * e.g., "Limit anonymous users to 60 requests per hour."
14
+ */
15
+ description?: string
16
+
17
+ /**
18
+ * Defines how to group requests for rate limiting. This determines
19
+ * who the limit applies to.
20
+ *
21
+ * - 'ip': Keys on the client's IP address. Best for anonymous traffic.
22
+ * - 'userId': Keys on the authenticated user's ID. Best for logged-in users.
23
+ * - 'role': Applies a shared limit to all users of a specific role.
24
+ */
25
+ key?: RateLimitRuleKey
26
+
27
+ /**
28
+ * The number of requests allowed over the defined interval.
29
+ * This is the rate at which tokens are added to the bucket.
30
+ */
31
+ rate?: number
32
+
33
+ /**
34
+ * The time interval for the rate.
35
+ */
36
+ interval?: RateLimitRuleInterval
37
+
38
+ /**
39
+ * The maximum number of requests that can be made in a burst.
40
+ * This represents the "bucket size." A larger burst allows for
41
+ * more requests to be made in a short period before throttling begins.
42
+ */
43
+ burst?: number
44
+ }
45
+
46
+ /**
47
+ * Represents a single rate limiting rule that applies to a specific
48
+ * type of client, using a token bucket algorithm.
49
+ */
50
+ export class RateLimitRule extends EventTarget implements RateLimitRuleSchema {
51
+ @observed() accessor description: string | undefined
52
+ @observed({ deep: true }) accessor key: RateLimitRuleKey | undefined
53
+ @observed() accessor rate: number | undefined
54
+ @observed() accessor interval: RateLimitRuleInterval | undefined
55
+ @observed() accessor burst: number | undefined
56
+
57
+ constructor(state: Partial<RateLimitRuleSchema> = {}) {
58
+ super()
59
+ this.description = state.description
60
+ this.key = RateLimitRule.isRateLimitRuleKey(state.key) ? structuredClone(state.key) : undefined
61
+ this.rate = typeof state.rate === 'number' ? state.rate : undefined
62
+ this.interval = RateLimitRule.isRateLimitRuleInterval(state.interval) ? state.interval : undefined
63
+ this.burst = typeof state.burst === 'number' ? state.burst : undefined
64
+ }
65
+
66
+ toJSON(): RateLimitRuleSchema {
67
+ const result: RateLimitRuleSchema = {}
68
+ if (this.description) {
69
+ result.description = this.description
70
+ }
71
+ if (RateLimitRule.isRateLimitRuleKey(this.key)) {
72
+ result.key = structuredClone(toRaw(this, this.key))
73
+ }
74
+ if (typeof this.rate === 'number') {
75
+ result.rate = this.rate
76
+ }
77
+ if (RateLimitRule.isRateLimitRuleInterval(this.interval)) {
78
+ result.interval = this.interval
79
+ }
80
+ if (typeof this.burst === 'number') {
81
+ result.burst = this.burst
82
+ }
83
+ return result
84
+ }
85
+
86
+ notifyChange() {
87
+ this.dispatchEvent(new Event('change'))
88
+ }
89
+
90
+ static isRateLimitRuleInterval(value: unknown): value is RateLimitRuleInterval {
91
+ if (typeof value !== 'string') {
92
+ return false
93
+ }
94
+ return ['second', 'minute', 'hour', 'day'].includes(value)
95
+ }
96
+
97
+ static isRateLimitRuleKey(value: unknown): value is RateLimitRuleKey {
98
+ if (typeof value !== 'object' || value === null) {
99
+ return false
100
+ }
101
+ const key = value as Record<string, unknown>
102
+ return 'type' in key && (key.type === 'ip' || key.type === 'userId' || key.type === 'role')
103
+ }
104
+ }
@@ -0,0 +1,32 @@
1
+ import { RateLimitRule, type RateLimitRuleSchema } from './RateLimitRule.js'
2
+ import { observed } from '../../decorators/observed.js'
3
+
4
+ /**
5
+ * Defines the rate limiting and throttling policies for the entire API.
6
+ */
7
+ export interface RateLimitingConfigurationSchema {
8
+ /**
9
+ * An ordered list of rules. The first rule that matches an incoming
10
+ * request will be applied.
11
+ */
12
+ rules: RateLimitRuleSchema[]
13
+ }
14
+
15
+ export class RateLimitingConfiguration extends EventTarget implements RateLimitingConfigurationSchema {
16
+ @observed({ deep: true }) accessor rules: RateLimitRule[]
17
+
18
+ constructor(state: Partial<RateLimitingConfigurationSchema> = {}) {
19
+ super()
20
+ this.rules = state.rules?.map((rule) => new RateLimitRule(rule)) || []
21
+ }
22
+
23
+ toJSON(): RateLimitingConfigurationSchema {
24
+ return {
25
+ rules: this.rules.map((rule) => rule.toJSON()),
26
+ }
27
+ }
28
+
29
+ notifyChange() {
30
+ this.dispatchEvent(new Event('change'))
31
+ }
32
+ }