@api-client/core 0.18.1 → 0.18.3
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/build/src/browser.d.ts +1 -0
- package/build/src/browser.d.ts.map +1 -1
- package/build/src/browser.js +1 -0
- package/build/src/browser.js.map +1 -1
- package/build/src/index.d.ts +1 -1
- package/build/src/index.d.ts.map +1 -1
- package/build/src/index.js.map +1 -1
- package/build/src/modeling/ApiModel.d.ts +60 -6
- package/build/src/modeling/ApiModel.d.ts.map +1 -1
- package/build/src/modeling/ApiModel.js +347 -277
- package/build/src/modeling/ApiModel.js.map +1 -1
- package/build/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/src/modeling/ApiModel.ts +96 -11
- package/tests/unit/modeling/api_model.spec.ts +38 -9
|
@@ -1,286 +1,356 @@
|
|
|
1
|
+
import { __esDecorate, __runInitializers } from "tslib";
|
|
1
2
|
import { nanoid } from '../nanoid.js';
|
|
2
3
|
import { ApiModelKind, DataDomainKind } from '../models/kinds.js';
|
|
3
4
|
import { Thing } from '../models/Thing.js';
|
|
4
5
|
import { DataDomain } from './DataDomain.js';
|
|
5
6
|
import { DependentModel } from './DependentModel.js';
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
7
|
+
import { observed, toRaw } from './observed.js';
|
|
8
|
+
let ApiModel = (() => {
|
|
9
|
+
let _classSuper = DependentModel;
|
|
10
|
+
let _termsOfService_decorators;
|
|
11
|
+
let _termsOfService_initializers = [];
|
|
12
|
+
let _termsOfService_extraInitializers = [];
|
|
13
|
+
let _contact_decorators;
|
|
14
|
+
let _contact_initializers = [];
|
|
15
|
+
let _contact_extraInitializers = [];
|
|
16
|
+
let _license_decorators;
|
|
17
|
+
let _license_initializers = [];
|
|
18
|
+
let _license_extraInitializers = [];
|
|
19
|
+
return class ApiModel extends _classSuper {
|
|
20
|
+
static {
|
|
21
|
+
const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(_classSuper[Symbol.metadata] ?? null) : void 0;
|
|
22
|
+
_termsOfService_decorators = [observed()];
|
|
23
|
+
_contact_decorators = [observed({ deep: true })];
|
|
24
|
+
_license_decorators = [observed({ deep: true })];
|
|
25
|
+
__esDecorate(this, null, _termsOfService_decorators, { kind: "accessor", name: "termsOfService", static: false, private: false, access: { has: obj => "termsOfService" in obj, get: obj => obj.termsOfService, set: (obj, value) => { obj.termsOfService = value; } }, metadata: _metadata }, _termsOfService_initializers, _termsOfService_extraInitializers);
|
|
26
|
+
__esDecorate(this, null, _contact_decorators, { kind: "accessor", name: "contact", static: false, private: false, access: { has: obj => "contact" in obj, get: obj => obj.contact, set: (obj, value) => { obj.contact = value; } }, metadata: _metadata }, _contact_initializers, _contact_extraInitializers);
|
|
27
|
+
__esDecorate(this, null, _license_decorators, { kind: "accessor", name: "license", static: false, private: false, access: { has: obj => "license" in obj, get: obj => obj.license, set: (obj, value) => { obj.license = value; } }, metadata: _metadata }, _license_initializers, _license_extraInitializers);
|
|
28
|
+
if (_metadata) Object.defineProperty(this, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* The data domain kind recognizable by the ecosystem.
|
|
32
|
+
*/
|
|
33
|
+
kind;
|
|
34
|
+
/**
|
|
35
|
+
* The unique key of the data domain schema.
|
|
36
|
+
* This is a stable identifier that does not change across versions.
|
|
37
|
+
*/
|
|
38
|
+
key;
|
|
39
|
+
/**
|
|
40
|
+
* The description of the domain property.
|
|
41
|
+
*/
|
|
42
|
+
info;
|
|
43
|
+
/**
|
|
44
|
+
* The designated Data Entity that represents a "User".
|
|
45
|
+
* This entity must be marked with the "User" semantic in the Data Modeler.
|
|
46
|
+
*
|
|
47
|
+
* This property is required to publish the API.
|
|
48
|
+
*/
|
|
49
|
+
user;
|
|
50
|
+
/**
|
|
51
|
+
* Configuration for how users prove their identity.
|
|
52
|
+
* The API model is invalid if this is not set.
|
|
53
|
+
*/
|
|
54
|
+
authentication;
|
|
55
|
+
/**
|
|
56
|
+
* Configuration for what authenticated users are allowed to do.
|
|
57
|
+
* The API model is invalid if this is not set.
|
|
58
|
+
*/
|
|
59
|
+
authorization;
|
|
60
|
+
/**
|
|
61
|
+
* Configuration for the transport and payload of the user session.
|
|
62
|
+
* The API model is invalid if this is not set.
|
|
63
|
+
*/
|
|
64
|
+
session;
|
|
65
|
+
/**
|
|
66
|
+
* The specific subset of Data Entities to be exposed by this API.
|
|
67
|
+
* These are the entities that are included in the data domain schema.
|
|
68
|
+
*/
|
|
69
|
+
exposes;
|
|
70
|
+
/**
|
|
71
|
+
* Optional array of access rules that define the access control policies
|
|
72
|
+
* for the API. These rules are used to enforce security and permissions
|
|
73
|
+
* on the exposed entities.
|
|
74
|
+
*
|
|
75
|
+
* These rules apply to all exposed entities and actions. An API action
|
|
76
|
+
* can declare its own access rules, which will override these.
|
|
77
|
+
*/
|
|
78
|
+
accessRule;
|
|
79
|
+
/**
|
|
80
|
+
* Optional configuration for API-wide rate limiting and throttling.
|
|
81
|
+
* Defines rules to protect the API from overuse.
|
|
82
|
+
*/
|
|
83
|
+
rateLimiting;
|
|
84
|
+
#termsOfService_accessor_storage = __runInitializers(this, _termsOfService_initializers, void 0);
|
|
85
|
+
/**
|
|
86
|
+
* A URL to the Terms of Service for the API.
|
|
87
|
+
*/
|
|
88
|
+
get termsOfService() { return this.#termsOfService_accessor_storage; }
|
|
89
|
+
set termsOfService(value) { this.#termsOfService_accessor_storage = value; }
|
|
90
|
+
#contact_accessor_storage = (__runInitializers(this, _termsOfService_extraInitializers), __runInitializers(this, _contact_initializers, void 0));
|
|
91
|
+
/**
|
|
92
|
+
* The contact information for the exposed API.
|
|
93
|
+
*/
|
|
94
|
+
get contact() { return this.#contact_accessor_storage; }
|
|
95
|
+
set contact(value) { this.#contact_accessor_storage = value; }
|
|
96
|
+
#license_accessor_storage = (__runInitializers(this, _contact_extraInitializers), __runInitializers(this, _license_initializers, void 0));
|
|
97
|
+
/**
|
|
98
|
+
* The license information for the API.
|
|
99
|
+
*/
|
|
100
|
+
get license() { return this.#license_accessor_storage; }
|
|
101
|
+
set license(value) { this.#license_accessor_storage = value; }
|
|
102
|
+
/**
|
|
103
|
+
* When the initializing flag is set to true,
|
|
104
|
+
* the domain is not notified of changes.
|
|
105
|
+
*/
|
|
106
|
+
#initializing = (__runInitializers(this, _license_extraInitializers), true);
|
|
107
|
+
/**
|
|
108
|
+
* When the notifying flag is set to true,
|
|
109
|
+
* the domain is pending a notification.
|
|
110
|
+
* No other notifications will be sent until
|
|
111
|
+
* the current notification is sent.
|
|
112
|
+
*/
|
|
113
|
+
#notifying = false;
|
|
114
|
+
/**
|
|
115
|
+
* A convenience getter that returns the DataDomain associated with this API model.
|
|
116
|
+
* Since the API model can have only one DataDomain,
|
|
117
|
+
* this getter returns the first dependency in the list.
|
|
118
|
+
*
|
|
119
|
+
* The parent interface `DependentModel` allows for multiple dependencies,
|
|
120
|
+
* to unify the dependency management across different models.
|
|
121
|
+
*/
|
|
122
|
+
get domain() {
|
|
123
|
+
if (this.dependencyList.length === 0) {
|
|
124
|
+
return undefined;
|
|
125
|
+
}
|
|
126
|
+
const domain = this.dependencyList[0];
|
|
127
|
+
return this.dependencies.get(domain.key);
|
|
128
|
+
}
|
|
129
|
+
static createSchema(input = {}) {
|
|
130
|
+
const { key = nanoid(), exposes = [] } = input;
|
|
131
|
+
const info = Thing.fromJSON(input.info, { name: 'Unnamed API' }).toJSON();
|
|
132
|
+
const result = {
|
|
133
|
+
kind: ApiModelKind,
|
|
134
|
+
key,
|
|
135
|
+
info,
|
|
136
|
+
exposes,
|
|
137
|
+
};
|
|
138
|
+
if (input.user) {
|
|
139
|
+
result.user = { ...input.user };
|
|
140
|
+
}
|
|
141
|
+
if (input.dependencyList) {
|
|
142
|
+
result.dependencyList = structuredClone(input.dependencyList);
|
|
143
|
+
}
|
|
144
|
+
if (input.authentication) {
|
|
145
|
+
result.authentication = input.authentication;
|
|
146
|
+
}
|
|
147
|
+
if (input.authorization) {
|
|
148
|
+
result.authorization = input.authorization;
|
|
149
|
+
}
|
|
150
|
+
if (input.session) {
|
|
151
|
+
result.session = input.session;
|
|
152
|
+
}
|
|
153
|
+
if (input.accessRule) {
|
|
154
|
+
result.accessRule = input.accessRule;
|
|
155
|
+
}
|
|
156
|
+
if (input.rateLimiting) {
|
|
157
|
+
result.rateLimiting = input.rateLimiting;
|
|
158
|
+
}
|
|
159
|
+
if (input.termsOfService) {
|
|
160
|
+
result.termsOfService = input.termsOfService;
|
|
161
|
+
}
|
|
162
|
+
if (input.contact) {
|
|
163
|
+
result.contact = structuredClone(input.contact);
|
|
164
|
+
}
|
|
165
|
+
if (input.license) {
|
|
166
|
+
result.license = structuredClone(input.license);
|
|
167
|
+
}
|
|
168
|
+
return result;
|
|
169
|
+
}
|
|
170
|
+
constructor(state, domain) {
|
|
171
|
+
const init = ApiModel.createSchema(state);
|
|
172
|
+
const instances = [];
|
|
173
|
+
if (domain instanceof DataDomain) {
|
|
174
|
+
instances.push(domain);
|
|
175
|
+
}
|
|
176
|
+
else if (typeof domain === 'object' && domain.kind === DataDomainKind) {
|
|
177
|
+
instances.push(new DataDomain(domain));
|
|
178
|
+
}
|
|
179
|
+
else if (domain) {
|
|
180
|
+
throw new Error(`Invalid domain provided. Expected a DataDomain instance or schema.`);
|
|
181
|
+
}
|
|
182
|
+
super(init.dependencyList, instances);
|
|
183
|
+
this.kind = init.kind;
|
|
184
|
+
this.key = init.key;
|
|
185
|
+
this.info = new Thing(init.info);
|
|
186
|
+
this.user = init.user;
|
|
187
|
+
if (init.authentication) {
|
|
188
|
+
this.authentication = structuredClone(init.authentication);
|
|
189
|
+
}
|
|
190
|
+
if (init.authorization) {
|
|
191
|
+
this.authorization = structuredClone(init.authorization);
|
|
192
|
+
}
|
|
193
|
+
if (init.session) {
|
|
194
|
+
this.session = structuredClone(init.session);
|
|
195
|
+
}
|
|
196
|
+
if (Array.isArray(init.exposes)) {
|
|
197
|
+
this.exposes = structuredClone(init.exposes);
|
|
198
|
+
}
|
|
199
|
+
else {
|
|
200
|
+
this.exposes = [];
|
|
201
|
+
}
|
|
202
|
+
if (init.accessRule) {
|
|
203
|
+
this.accessRule = structuredClone(init.accessRule);
|
|
204
|
+
}
|
|
205
|
+
if (init.rateLimiting) {
|
|
206
|
+
this.rateLimiting = structuredClone(init.rateLimiting);
|
|
207
|
+
}
|
|
208
|
+
if (init.termsOfService) {
|
|
209
|
+
this.termsOfService = init.termsOfService;
|
|
210
|
+
}
|
|
211
|
+
if (init.contact) {
|
|
212
|
+
this.contact = init.contact;
|
|
213
|
+
}
|
|
214
|
+
if (init.license) {
|
|
215
|
+
this.license = init.license;
|
|
216
|
+
}
|
|
217
|
+
this.#initializing = false;
|
|
218
|
+
this.info.addEventListener('change', () => {
|
|
219
|
+
this.notifyChange();
|
|
220
|
+
});
|
|
221
|
+
}
|
|
222
|
+
toJSON() {
|
|
223
|
+
const result = {
|
|
224
|
+
kind: this.kind,
|
|
225
|
+
key: this.key,
|
|
226
|
+
info: this.info.toJSON(),
|
|
227
|
+
exposes: structuredClone(this.exposes),
|
|
228
|
+
};
|
|
229
|
+
if (this.user) {
|
|
230
|
+
result.user = { ...this.user };
|
|
231
|
+
}
|
|
232
|
+
if (this.dependencyList.length > 0) {
|
|
233
|
+
result.dependencyList = structuredClone(this.dependencyList);
|
|
234
|
+
}
|
|
235
|
+
if (this.authentication) {
|
|
236
|
+
result.authentication = structuredClone(this.authentication);
|
|
237
|
+
}
|
|
238
|
+
if (this.authorization) {
|
|
239
|
+
result.authorization = structuredClone(this.authorization);
|
|
240
|
+
}
|
|
241
|
+
if (this.session) {
|
|
242
|
+
result.session = structuredClone(this.session);
|
|
243
|
+
}
|
|
244
|
+
if (this.accessRule) {
|
|
245
|
+
result.accessRule = structuredClone(this.accessRule);
|
|
246
|
+
}
|
|
247
|
+
if (this.rateLimiting) {
|
|
248
|
+
result.rateLimiting = structuredClone(this.rateLimiting);
|
|
249
|
+
}
|
|
250
|
+
if (this.termsOfService) {
|
|
251
|
+
result.termsOfService = this.termsOfService;
|
|
252
|
+
}
|
|
253
|
+
if (this.contact) {
|
|
254
|
+
result.contact = structuredClone(toRaw(this, this.contact));
|
|
255
|
+
}
|
|
256
|
+
if (this.license) {
|
|
257
|
+
result.license = structuredClone(toRaw(this, this.license));
|
|
258
|
+
}
|
|
259
|
+
return result;
|
|
260
|
+
}
|
|
261
|
+
/**
|
|
262
|
+
* This function is used internally by all domain elements to notify that something has changed.
|
|
263
|
+
* Since we want to notify listeners after the operation commits, we use microtask
|
|
264
|
+
* to ensure that the event is dispatched after the current operation.
|
|
265
|
+
*/
|
|
266
|
+
notifyChange() {
|
|
267
|
+
if (this.#notifying || this.#initializing) {
|
|
268
|
+
return;
|
|
269
|
+
}
|
|
270
|
+
this.#notifying = true;
|
|
271
|
+
queueMicrotask(() => {
|
|
272
|
+
this.#notifying = false;
|
|
273
|
+
const event = new Event('change');
|
|
274
|
+
this.dispatchEvent(event);
|
|
275
|
+
});
|
|
276
|
+
}
|
|
277
|
+
/**
|
|
278
|
+
* Exposes a new entity in the API model.
|
|
279
|
+
* If the entity already exists, it returns the existing one.
|
|
280
|
+
* @param entityKey The key of the entity to expose.
|
|
281
|
+
* @returns The exposed entity.
|
|
282
|
+
*/
|
|
283
|
+
exposeEntity(entityKey) {
|
|
284
|
+
const existing = this.exposes.find((e) => e.key === entityKey);
|
|
285
|
+
if (existing) {
|
|
286
|
+
return existing;
|
|
287
|
+
}
|
|
288
|
+
const newEntity = {
|
|
289
|
+
key: entityKey,
|
|
290
|
+
actions: [],
|
|
291
|
+
};
|
|
292
|
+
this.exposes.push(newEntity);
|
|
160
293
|
this.notifyChange();
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
return existing;
|
|
219
|
-
}
|
|
220
|
-
const newEntity = {
|
|
221
|
-
key: entityKey,
|
|
222
|
-
actions: [],
|
|
223
|
-
};
|
|
224
|
-
this.exposes.push(newEntity);
|
|
225
|
-
this.notifyChange();
|
|
226
|
-
return newEntity;
|
|
227
|
-
}
|
|
228
|
-
/**
|
|
229
|
-
* Removes an entity from the API model.
|
|
230
|
-
* @param entityKey The key of the entity to remove.
|
|
231
|
-
*/
|
|
232
|
-
removeEntity(entityKey) {
|
|
233
|
-
const index = this.exposes.findIndex((e) => e.key === entityKey);
|
|
234
|
-
if (index !== -1) {
|
|
235
|
-
this.exposes.splice(index, 1);
|
|
294
|
+
return newEntity;
|
|
295
|
+
}
|
|
296
|
+
/**
|
|
297
|
+
* Removes an entity from the API model.
|
|
298
|
+
* @param entityKey The key of the entity to remove.
|
|
299
|
+
*/
|
|
300
|
+
removeEntity(entityKey) {
|
|
301
|
+
const index = this.exposes.findIndex((e) => e.key === entityKey);
|
|
302
|
+
if (index !== -1) {
|
|
303
|
+
this.exposes.splice(index, 1);
|
|
304
|
+
this.notifyChange();
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
/**
|
|
308
|
+
* Returns the exposed entity by its key.
|
|
309
|
+
* @param entityKey The key of the entity to find.
|
|
310
|
+
* @returns The exposed entity or undefined if not found.
|
|
311
|
+
*/
|
|
312
|
+
getExposedEntity(entityKey) {
|
|
313
|
+
return this.exposes.find((e) => e.key === entityKey);
|
|
314
|
+
}
|
|
315
|
+
/**
|
|
316
|
+
* Clears the API model for a new entity change.
|
|
317
|
+
* This method resets the dependencies, exposes, user,
|
|
318
|
+
* authentication, authorization, and session properties.
|
|
319
|
+
*/
|
|
320
|
+
cleanForEntityChange() {
|
|
321
|
+
this.dependencies.clear();
|
|
322
|
+
this.dependencyList = [];
|
|
323
|
+
this.exposes = [];
|
|
324
|
+
this.user = undefined;
|
|
325
|
+
if (this.session) {
|
|
326
|
+
this.session.properties = [];
|
|
327
|
+
}
|
|
328
|
+
if (this.authentication && this.authentication.strategy === 'UsernamePassword') {
|
|
329
|
+
const typed = this.authentication;
|
|
330
|
+
typed.passwordKey = undefined;
|
|
331
|
+
}
|
|
332
|
+
if (this.authorization && this.authorization.strategy == 'RBAC') {
|
|
333
|
+
const typed = this.authorization;
|
|
334
|
+
typed.roleKey = '';
|
|
335
|
+
}
|
|
336
|
+
}
|
|
337
|
+
/**
|
|
338
|
+
* Attaches a DataDomain to this API model.
|
|
339
|
+
* This method clears any existing dependencies and sets the new domain.
|
|
340
|
+
*
|
|
341
|
+
* @param domain The DataDomain to attach to this API model.
|
|
342
|
+
* @throws Error if the domain does not have a version set in its info.
|
|
343
|
+
*/
|
|
344
|
+
attachDataDomain(domain) {
|
|
345
|
+
if (!domain.info.version) {
|
|
346
|
+
throw new Error(`Cannot attach DataDomain without a version. Please set the version in the domain info.`);
|
|
347
|
+
}
|
|
348
|
+
this.cleanForEntityChange();
|
|
349
|
+
this.dependencies.set(domain.key, domain);
|
|
350
|
+
this.dependencyList = [{ key: domain.key, version: domain.info.version }];
|
|
236
351
|
this.notifyChange();
|
|
237
352
|
}
|
|
238
|
-
}
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
* @param entityKey The key of the entity to find.
|
|
242
|
-
* @returns The exposed entity or undefined if not found.
|
|
243
|
-
*/
|
|
244
|
-
getExposedEntity(entityKey) {
|
|
245
|
-
return this.exposes.find((e) => e.key === entityKey);
|
|
246
|
-
}
|
|
247
|
-
/**
|
|
248
|
-
* Clears the API model for a new entity change.
|
|
249
|
-
* This method resets the dependencies, exposes, userKey,
|
|
250
|
-
* authentication, authorization, and session properties.
|
|
251
|
-
*/
|
|
252
|
-
cleanForEntityChange() {
|
|
253
|
-
this.dependencies.clear();
|
|
254
|
-
this.dependencyList = [];
|
|
255
|
-
this.exposes = [];
|
|
256
|
-
this.userKey = undefined;
|
|
257
|
-
if (this.session) {
|
|
258
|
-
this.session.properties = [];
|
|
259
|
-
}
|
|
260
|
-
if (this.authentication && this.authentication.strategy === 'UsernamePassword') {
|
|
261
|
-
const typed = this.authentication;
|
|
262
|
-
typed.passwordKey = undefined;
|
|
263
|
-
}
|
|
264
|
-
if (this.authorization && this.authorization.strategy == 'RBAC') {
|
|
265
|
-
const typed = this.authorization;
|
|
266
|
-
typed.roleKey = '';
|
|
267
|
-
}
|
|
268
|
-
}
|
|
269
|
-
/**
|
|
270
|
-
* Attaches a DataDomain to this API model.
|
|
271
|
-
* This method clears any existing dependencies and sets the new domain.
|
|
272
|
-
*
|
|
273
|
-
* @param domain The DataDomain to attach to this API model.
|
|
274
|
-
* @throws Error if the domain does not have a version set in its info.
|
|
275
|
-
*/
|
|
276
|
-
attachDataDomain(domain) {
|
|
277
|
-
if (!domain.info.version) {
|
|
278
|
-
throw new Error(`Cannot attach DataDomain without a version. Please set the version in the domain info.`);
|
|
279
|
-
}
|
|
280
|
-
this.cleanForEntityChange();
|
|
281
|
-
this.dependencies.set(domain.key, domain);
|
|
282
|
-
this.dependencyList = [{ key: domain.key, version: domain.info.version }];
|
|
283
|
-
this.notifyChange();
|
|
284
|
-
}
|
|
285
|
-
}
|
|
353
|
+
};
|
|
354
|
+
})();
|
|
355
|
+
export { ApiModel };
|
|
286
356
|
//# sourceMappingURL=ApiModel.js.map
|