@api-client/core 0.3.1 → 0.3.4
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/browser.d.ts +1 -1
- package/build/index.d.ts +2 -2
- package/build/index.js.map +1 -1
- package/build/src/models/Backend.d.ts +22 -0
- package/build/src/runtime/store/StoreSdk.d.ts +192 -12
- package/build/src/runtime/store/StoreSdk.js +592 -53
- package/build/src/runtime/store/StoreSdk.js.map +1 -1
- package/package.json +3 -1
- package/src/data/DataReader.ts +11 -0
- package/src/data/DataUtils.ts +108 -0
- package/src/data/JmesparthReader.ts +26 -0
- package/src/data/Json2Xml.ts +190 -0
- package/src/data/JsonReader.ts +41 -0
- package/src/data/PayloadPointer.ts +48 -0
- package/src/data/RequestDataExtractor.ts +133 -0
- package/src/data/UrlEncodedReader.ts +20 -0
- package/src/data/XmlReader.ts +103 -0
- package/src/events/BaseEvents.ts +259 -0
- package/src/events/CustomEvent.ts +27 -0
- package/src/events/EventTypes.ts +19 -0
- package/src/events/Events.ts +19 -0
- package/src/events/authorization/AuthorizationEventTypes.ts +22 -0
- package/src/events/authorization/AuthorizationEvents.ts +61 -0
- package/src/events/cookies/CookieEventTypes.ts +13 -0
- package/src/events/cookies/CookieEvents.ts +157 -0
- package/src/events/encryption/EncryptionEventTypes.ts +4 -0
- package/src/events/encryption/EncryptionEvents.ts +51 -0
- package/src/events/environment/EnvironmentEventTypes.ts +3 -0
- package/src/events/environment/EnvironmentEvents.ts +24 -0
- package/src/events/models/ClientCertificateEvents.ts +87 -0
- package/src/events/models/ModelEventTypes.ts +47 -0
- package/src/events/models/ModelEvents.ts +7 -0
- package/src/events/models/ProjectEvents.ts +331 -0
- package/src/events/process/ProcessEventTypes.ts +5 -0
- package/src/events/process/ProcessEvents.ts +76 -0
- package/src/events/readme.md +22 -0
- package/src/events/reporting/ReportingEventTypes.ts +3 -0
- package/src/events/reporting/ReportingEvents.ts +28 -0
- package/src/events/telemetry/TelemetryEventTypes.ts +10 -0
- package/src/events/telemetry/TelemetryEvents.ts +156 -0
- package/src/lib/cookies/Cookie.ts +312 -0
- package/src/lib/cookies/Cookies.ts +326 -0
- package/src/lib/cookies/Utils.ts +168 -0
- package/src/lib/headers/Headers.ts +219 -0
- package/src/lib/logging/DefaultLogger.ts +19 -0
- package/src/lib/logging/DummyLogger.ts +21 -0
- package/src/lib/logging/Logger.ts +16 -0
- package/src/lib/transformers/PayloadSerializer.ts +332 -0
- package/src/lib/transformers/Utils.ts +18 -0
- package/src/lib/uuid.ts +40 -0
- package/src/mocking/LegacyInterfaces.ts +52 -0
- package/src/mocking/LegacyMock.ts +37 -0
- package/src/mocking/legacy/Authorization.ts +39 -0
- package/src/mocking/legacy/Certificates.ts +145 -0
- package/src/mocking/legacy/Cookies.ts +51 -0
- package/src/mocking/legacy/HostRules.ts +43 -0
- package/src/mocking/legacy/Http.ts +236 -0
- package/src/mocking/legacy/HttpResponse.ts +106 -0
- package/src/mocking/legacy/RestApi.ts +68 -0
- package/src/mocking/legacy/Urls.ts +44 -0
- package/src/mocking/legacy/Variables.ts +53 -0
- package/src/models/ArcResponse.ts +166 -0
- package/src/models/Authorization.ts +481 -0
- package/src/models/AuthorizationData.ts +60 -0
- package/src/models/Backend.ts +107 -0
- package/src/models/ClientCertificate.ts +68 -0
- package/src/models/Environment.ts +279 -0
- package/src/models/ErrorResponse.ts +101 -0
- package/src/models/HistoryIndex.ts +76 -0
- package/src/models/HistoryRequest.ts +28 -0
- package/src/models/HostRule.ts +163 -0
- package/src/models/HttpCookie.ts +285 -0
- package/src/models/HttpProject.ts +1294 -0
- package/src/models/HttpProjectListItem.ts +23 -0
- package/src/models/HttpRequest.ts +124 -0
- package/src/models/HttpResponse.ts +143 -0
- package/src/models/License.ts +113 -0
- package/src/models/ProjectDefinitionProperty.ts +40 -0
- package/src/models/ProjectFolder.ts +439 -0
- package/src/models/ProjectItem.ts +135 -0
- package/src/models/ProjectParent.ts +113 -0
- package/src/models/ProjectRequest.ts +277 -0
- package/src/models/ProjectSchema.ts +202 -0
- package/src/models/Property.ts +423 -0
- package/src/models/Provider.ts +98 -0
- package/src/models/README.md +20 -0
- package/src/models/Request.ts +452 -0
- package/src/models/RequestActions.ts +163 -0
- package/src/models/RequestAuthorization.ts +115 -0
- package/src/models/RequestConfig.ts +317 -0
- package/src/models/RequestLog.ts +159 -0
- package/src/models/RequestTime.ts +108 -0
- package/src/models/RequestUiMeta.ts +258 -0
- package/src/models/RequestsSize.ts +65 -0
- package/src/models/ResponseAuthorization.ts +104 -0
- package/src/models/ResponseRedirect.ts +158 -0
- package/src/models/RevisionInfo.ts +37 -0
- package/src/models/SentRequest.ts +125 -0
- package/src/models/SerializablePayload.ts +68 -0
- package/src/models/Server.ts +153 -0
- package/src/models/Thing.ts +110 -0
- package/src/models/Url.ts +90 -0
- package/src/models/User.ts +120 -0
- package/src/models/WebApi.ts +234 -0
- package/src/models/WebApiIndex.ts +122 -0
- package/src/models/Workspace.ts +182 -0
- package/src/models/actions/Action.ts +213 -0
- package/src/models/actions/ActionView.ts +40 -0
- package/src/models/actions/Condition.ts +207 -0
- package/src/models/actions/ConditionView.ts +42 -0
- package/src/models/actions/Enums.ts +29 -0
- package/src/models/actions/RunnableAction.ts +144 -0
- package/src/models/actions/runnable/DeleteCookieAction.ts +113 -0
- package/src/models/actions/runnable/Runnable.ts +9 -0
- package/src/models/actions/runnable/SetCookieAction.ts +216 -0
- package/src/models/actions/runnable/SetVariableAction.ts +81 -0
- package/src/models/legacy/DataExport.ts +172 -0
- package/src/models/legacy/Normalizer.ts +110 -0
- package/src/models/legacy/actions/Actions.ts +269 -0
- package/src/models/legacy/authorization/Authorization.ts +572 -0
- package/src/models/legacy/models/ApiTypes.ts +202 -0
- package/src/models/legacy/models/ArcLegacyProject.ts +39 -0
- package/src/models/legacy/models/AuthData.ts +17 -0
- package/src/models/legacy/models/ClientCertificate.ts +95 -0
- package/src/models/legacy/models/Cookies.ts +52 -0
- package/src/models/legacy/models/HostRule.ts +35 -0
- package/src/models/legacy/models/RestApi.ts +49 -0
- package/src/models/legacy/models/UrlHistory.ts +37 -0
- package/src/models/legacy/models/Variable.ts +43 -0
- package/src/models/legacy/models/base.d.ts +95 -0
- package/src/models/legacy/request/ArcRequest.ts +405 -0
- package/src/models/legacy/request/ArcResponse.ts +177 -0
- package/src/models/legacy/request/HistoryData.ts +47 -0
- package/src/models/legacy/request/Legacy.ts +45 -0
- package/src/models/legacy/request/RequestBody.ts +87 -0
- package/src/models/transformers/ArcDexieTransformer.ts +323 -0
- package/src/models/transformers/ArcLegacyNormalizer.ts +85 -0
- package/src/models/transformers/ArcLegacyTransformer.ts +200 -0
- package/src/models/transformers/ArcPouchTransformer.ts +184 -0
- package/src/models/transformers/BaseTransformer.ts +116 -0
- package/src/models/transformers/ImportUtils.ts +141 -0
- package/src/models/transformers/LegacyDataExportToApiProject.ts +76 -0
- package/src/models/transformers/LegacyExportProcessor.ts +252 -0
- package/src/models/transformers/PostmanBackupTransformer.ts +306 -0
- package/src/models/transformers/PostmanDataTransformer.ts +50 -0
- package/src/models/transformers/PostmanTransformer.ts +106 -0
- package/src/models/transformers/PostmanV21Transformer.ts +311 -0
- package/src/models/transformers/PostmanV2Transformer.ts +308 -0
- package/src/models/transformers/har.ts +865 -0
- package/src/runtime/actions/ActionRunner.ts +83 -0
- package/src/runtime/actions/ConditionRunner.ts +194 -0
- package/src/runtime/actions/RunnableCondition.ts +57 -0
- package/src/runtime/actions/runnable/ActionRunnable.ts +19 -0
- package/src/runtime/actions/runnable/DeleteCookieRunnable.ts +39 -0
- package/src/runtime/actions/runnable/SetCookieRunnable.ts +92 -0
- package/src/runtime/actions/runnable/SetVariableRunnable.ts +53 -0
- package/src/runtime/http-engine/ArcEngine.ts +1064 -0
- package/src/runtime/http-engine/Errors.ts +13 -0
- package/src/runtime/http-engine/FormData.ts +85 -0
- package/src/runtime/http-engine/HttpEngine.ts +874 -0
- package/src/runtime/http-engine/HttpErrorCodes.ts +270 -0
- package/src/runtime/http-engine/NodeEngine.ts +787 -0
- package/src/runtime/http-engine/NodeEngineDirect.ts +476 -0
- package/src/runtime/http-engine/PayloadSupport.ts +84 -0
- package/src/runtime/http-engine/RequestUtils.ts +164 -0
- package/src/runtime/http-engine/ntlm/Des.ts +345 -0
- package/src/runtime/http-engine/ntlm/MD4.ts +135 -0
- package/src/runtime/http-engine/ntlm/NtlmAuth.ts +186 -0
- package/src/runtime/http-engine/ntlm/NtlmMessage.ts +57 -0
- package/src/runtime/modules/BasicAuthCache.ts +133 -0
- package/src/runtime/modules/ExecutionResponse.ts +4 -0
- package/src/runtime/modules/ModulesRegistry.ts +136 -0
- package/src/runtime/modules/RequestAuthorization.ts +110 -0
- package/src/runtime/modules/RequestCookies.ts +145 -0
- package/src/runtime/node/ProjectRunner.ts +275 -0
- package/src/runtime/node/RequestFactory.ts +422 -0
- package/src/runtime/node/VariablesStore.ts +25 -0
- package/src/runtime/store/StoreSdk.ts +838 -0
- package/src/runtime/variables/Cache.ts +53 -0
- package/src/runtime/variables/EvalFunctions.ts +132 -0
- package/src/runtime/variables/ProjectVariables.ts +6 -0
- package/src/runtime/variables/VariablesProcessor.ts +543 -0
- package/src/runtime/variables/VariablesTokenizer.ts +55 -0
|
@@ -0,0 +1,277 @@
|
|
|
1
|
+
import { Kind as ThingKind } from './Thing.js';
|
|
2
|
+
import { ProjectDefinitionProperty, IProjectDefinitionProperty } from './ProjectDefinitionProperty.js';
|
|
3
|
+
import { ProjectFolder } from './ProjectFolder.js';
|
|
4
|
+
import { IHttpRequest, Kind as HttpRequestKind } from './HttpRequest.js';
|
|
5
|
+
import { HttpProject } from './HttpProject.js';
|
|
6
|
+
import v4 from '../lib/uuid.js';
|
|
7
|
+
import { IRequest, Request } from './Request.js';
|
|
8
|
+
|
|
9
|
+
export const Kind = 'ARC#ProjectRequest';
|
|
10
|
+
|
|
11
|
+
export interface IProjectRequest extends IProjectDefinitionProperty, IRequest {
|
|
12
|
+
kind: 'ARC#ProjectRequest';
|
|
13
|
+
/**
|
|
14
|
+
* The identifier of the request.
|
|
15
|
+
*/
|
|
16
|
+
key: string;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export interface IRequestCloneOptions {
|
|
20
|
+
/**
|
|
21
|
+
* By default it revalidates (re-creates) keys in the request.
|
|
22
|
+
* Set this to true to not make any changes to the keys.
|
|
23
|
+
*/
|
|
24
|
+
withoutRevalidate?: boolean;
|
|
25
|
+
/**
|
|
26
|
+
* By default it attaches the request to the same parent as the original request.
|
|
27
|
+
* Set this to `true` when moving a request between projects to prevent adding the request to the project.
|
|
28
|
+
* Note, the request still have a reference to the original project. You need to update the `project` property.
|
|
29
|
+
*/
|
|
30
|
+
withoutAttach?: boolean;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* **Note about the payload.**
|
|
35
|
+
*
|
|
36
|
+
* The payload is **always** stored in the request object in its serialized form.
|
|
37
|
+
* Use the `readPayload()` to read the correct data type and the `writePayload()` to
|
|
38
|
+
* safely store the payload.
|
|
39
|
+
*/
|
|
40
|
+
export class ProjectRequest extends Request implements ProjectDefinitionProperty {
|
|
41
|
+
kind = Kind;
|
|
42
|
+
/**
|
|
43
|
+
* The identifier of the request.
|
|
44
|
+
*/
|
|
45
|
+
key = '';
|
|
46
|
+
/**
|
|
47
|
+
* A reference to the top level project object.
|
|
48
|
+
*/
|
|
49
|
+
project: HttpProject;
|
|
50
|
+
/**
|
|
51
|
+
* Checks whether the input is a definition of a project folder.
|
|
52
|
+
*/
|
|
53
|
+
static isProjectRequest(input: unknown): boolean {
|
|
54
|
+
const typed = input as IProjectRequest;
|
|
55
|
+
if (!input || typed.kind !== Kind) {
|
|
56
|
+
return false;
|
|
57
|
+
}
|
|
58
|
+
return true;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Creates a project request from an URL.
|
|
63
|
+
* This does not manipulate the project.
|
|
64
|
+
*
|
|
65
|
+
* @param url The Request URL. This is required.
|
|
66
|
+
* @param project The parent project.
|
|
67
|
+
*/
|
|
68
|
+
static fromUrl(url: string, project?: HttpProject): ProjectRequest {
|
|
69
|
+
if (!project) {
|
|
70
|
+
throw new Error(`The project is required.`);
|
|
71
|
+
}
|
|
72
|
+
const now:number = Date.now();
|
|
73
|
+
const request = new ProjectRequest(project, {
|
|
74
|
+
key: v4(),
|
|
75
|
+
kind: Kind,
|
|
76
|
+
created: now,
|
|
77
|
+
updated: now,
|
|
78
|
+
expects: {
|
|
79
|
+
kind: HttpRequestKind,
|
|
80
|
+
method: 'GET',
|
|
81
|
+
url,
|
|
82
|
+
},
|
|
83
|
+
info: {
|
|
84
|
+
kind: ThingKind,
|
|
85
|
+
name: url,
|
|
86
|
+
},
|
|
87
|
+
});
|
|
88
|
+
return request;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* Creates a project request from a name.
|
|
93
|
+
* This does not manipulate the project.
|
|
94
|
+
*
|
|
95
|
+
* @param name The Request name.
|
|
96
|
+
* @param project The parent project.This is required.
|
|
97
|
+
*/
|
|
98
|
+
static fromName(name: string, project?: HttpProject): ProjectRequest {
|
|
99
|
+
if (!project) {
|
|
100
|
+
throw new Error(`The project is required.`);
|
|
101
|
+
}
|
|
102
|
+
const now:number = Date.now();
|
|
103
|
+
const request = new ProjectRequest(project, {
|
|
104
|
+
key: v4(),
|
|
105
|
+
kind: Kind,
|
|
106
|
+
created: now,
|
|
107
|
+
updated: now,
|
|
108
|
+
expects: {
|
|
109
|
+
kind: HttpRequestKind,
|
|
110
|
+
method: 'GET',
|
|
111
|
+
url: '',
|
|
112
|
+
},
|
|
113
|
+
info: {
|
|
114
|
+
kind: ThingKind,
|
|
115
|
+
name,
|
|
116
|
+
},
|
|
117
|
+
});
|
|
118
|
+
return request;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
/**
|
|
122
|
+
* Creates a project request from an HttpRequest definition.
|
|
123
|
+
* This does not manipulate the project.
|
|
124
|
+
*
|
|
125
|
+
* @param project The parent project This is required.
|
|
126
|
+
* @param info The request data.
|
|
127
|
+
*/
|
|
128
|
+
static fromHttpRequest(info: IHttpRequest, project?: HttpProject): ProjectRequest {
|
|
129
|
+
if (!project) {
|
|
130
|
+
throw new Error(`The project is required.`);
|
|
131
|
+
}
|
|
132
|
+
const now:number = Date.now();
|
|
133
|
+
const request = new ProjectRequest(project, {
|
|
134
|
+
key: v4(),
|
|
135
|
+
kind: Kind,
|
|
136
|
+
created: now,
|
|
137
|
+
updated: now,
|
|
138
|
+
expects: {
|
|
139
|
+
kind: HttpRequestKind,
|
|
140
|
+
method: info.method,
|
|
141
|
+
url: info.url,
|
|
142
|
+
headers: info.headers,
|
|
143
|
+
payload: info.payload,
|
|
144
|
+
},
|
|
145
|
+
info: {
|
|
146
|
+
kind: ThingKind,
|
|
147
|
+
name: info.url,
|
|
148
|
+
},
|
|
149
|
+
});
|
|
150
|
+
return request;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
/**
|
|
154
|
+
* Creates a project request for a schema of a Request.
|
|
155
|
+
*/
|
|
156
|
+
static fromRequest(request: IRequest, project: HttpProject): ProjectRequest {
|
|
157
|
+
const key = v4();
|
|
158
|
+
const init: IProjectRequest = { ...request, key, kind: Kind };
|
|
159
|
+
const result = new ProjectRequest(project, init);
|
|
160
|
+
return result;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
constructor(project: HttpProject, input?: string|IProjectRequest) {
|
|
164
|
+
super(input);
|
|
165
|
+
this.project = project;
|
|
166
|
+
let init: IProjectRequest;
|
|
167
|
+
if (typeof input === 'string') {
|
|
168
|
+
init = JSON.parse(input);
|
|
169
|
+
} else if (typeof input === 'object') {
|
|
170
|
+
init = input;
|
|
171
|
+
} else {
|
|
172
|
+
const now:number = Date.now();
|
|
173
|
+
init = {
|
|
174
|
+
key: v4(),
|
|
175
|
+
kind: Kind,
|
|
176
|
+
created: now,
|
|
177
|
+
updated: now,
|
|
178
|
+
expects: {
|
|
179
|
+
kind: HttpRequestKind,
|
|
180
|
+
method: 'GET',
|
|
181
|
+
url: '',
|
|
182
|
+
},
|
|
183
|
+
info: {
|
|
184
|
+
kind: ThingKind,
|
|
185
|
+
name: '',
|
|
186
|
+
},
|
|
187
|
+
};
|
|
188
|
+
}
|
|
189
|
+
this.new(init);
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
new(init: IProjectRequest): void {
|
|
193
|
+
super.new(init);
|
|
194
|
+
|
|
195
|
+
const { key } = init;
|
|
196
|
+
this.key = key || v4();
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
toJSON(): IProjectRequest {
|
|
200
|
+
const request = super.toJSON();
|
|
201
|
+
const result: IProjectRequest = { ...request, key: this.key, kind: Kind };
|
|
202
|
+
return result;
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
/**
|
|
206
|
+
* The callback called when the object is attached to a parent.
|
|
207
|
+
* This is called when the object is created and inserted to a project or a folder
|
|
208
|
+
* and when the object is moved between folders.
|
|
209
|
+
*/
|
|
210
|
+
attachedCallback(): void {
|
|
211
|
+
// ...
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
/**
|
|
215
|
+
* The callback called when the object is detached from its parent.
|
|
216
|
+
* This callback is called when the item is deleted from a folder or a project,
|
|
217
|
+
* or when the item is about to be moved to another folder.
|
|
218
|
+
*/
|
|
219
|
+
detachedCallback(): void {
|
|
220
|
+
// ...
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
/**
|
|
224
|
+
* @returns The instance of the HttpProject or a ProjectFolder that is a closes parent of this instance.
|
|
225
|
+
*/
|
|
226
|
+
getParent(): ProjectFolder|HttpProject|undefined {
|
|
227
|
+
const { project, key } = this;
|
|
228
|
+
return project.findParent(key);
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
/**
|
|
232
|
+
* @returns A reference to the parent folder or the top-level HTTP project.
|
|
233
|
+
*/
|
|
234
|
+
getProject(): HttpProject {
|
|
235
|
+
return this.project;
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
/**
|
|
239
|
+
* Removes this request from the project.
|
|
240
|
+
*/
|
|
241
|
+
remove(): void {
|
|
242
|
+
this.project.removeRequest(this.key);
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
/**
|
|
246
|
+
* Makes a copy of this request.
|
|
247
|
+
* By default it attaches the copied request to the same parent.
|
|
248
|
+
* Use the options dictionary to control this behavior.
|
|
249
|
+
*/
|
|
250
|
+
clone(opts: IRequestCloneOptions = {}): ProjectRequest {
|
|
251
|
+
const copy = new ProjectRequest(this.project, this.toJSON());
|
|
252
|
+
if (!opts.withoutRevalidate) {
|
|
253
|
+
copy.key = v4();
|
|
254
|
+
}
|
|
255
|
+
if (!opts.withoutAttach) {
|
|
256
|
+
// if the parent is the project then add the request to the project.
|
|
257
|
+
const parent = this.getParent();
|
|
258
|
+
if (parent) {
|
|
259
|
+
parent.addRequest(copy);
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
return copy;
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
/**
|
|
266
|
+
* The static version of the `clone()` method.
|
|
267
|
+
*
|
|
268
|
+
* @param request The request schema to clone.
|
|
269
|
+
* @param project The project to add the request to.
|
|
270
|
+
* @param opts Optional options.
|
|
271
|
+
* @returns The copied request.
|
|
272
|
+
*/
|
|
273
|
+
static clone(request: IProjectRequest, project: HttpProject, opts: IRequestCloneOptions = {}): ProjectRequest {
|
|
274
|
+
const obj = new ProjectRequest(project, request);
|
|
275
|
+
return obj.clone(opts);
|
|
276
|
+
}
|
|
277
|
+
}
|
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
import v4 from '../lib/uuid.js';
|
|
2
|
+
import { Property, IProperty, PropertyType, Kind as PropertyKind } from './Property.js';
|
|
3
|
+
export const Kind = 'ARC#ProjectSchema';
|
|
4
|
+
|
|
5
|
+
export interface IProjectSchema {
|
|
6
|
+
kind?: 'ARC#ProjectSchema';
|
|
7
|
+
/**
|
|
8
|
+
* The identifier of the environment.
|
|
9
|
+
*/
|
|
10
|
+
key: string;
|
|
11
|
+
/**
|
|
12
|
+
* The name of the schema.
|
|
13
|
+
*/
|
|
14
|
+
name: string;
|
|
15
|
+
/**
|
|
16
|
+
* The optional list of properties in this schema.
|
|
17
|
+
* Because this is a list instead of a map it is possible to duplicate the property name. In this
|
|
18
|
+
* case the last set value is the final value.
|
|
19
|
+
*
|
|
20
|
+
* When both the `properties` and the `content` is defined, `content` is used instead of properties.
|
|
21
|
+
*/
|
|
22
|
+
properties?: IProperty[];
|
|
23
|
+
/**
|
|
24
|
+
* The "raw" content of the schema.
|
|
25
|
+
* This value goes unchanged to the request.
|
|
26
|
+
*/
|
|
27
|
+
content?: string;
|
|
28
|
+
/**
|
|
29
|
+
* When content is used, it informs about the content type of the
|
|
30
|
+
* schema. The schema is invalid when `content` is set and the `mime` is not.
|
|
31
|
+
*/
|
|
32
|
+
mime?: string;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* A project can contain schema definitions that can be reused in project requests.
|
|
37
|
+
* The schema consists of:
|
|
38
|
+
*
|
|
39
|
+
* - content: the "raw" schema value in any format. This goes unprocessed into the request body.
|
|
40
|
+
* - properties: a map of properties description that can be manipulated at runtime
|
|
41
|
+
*
|
|
42
|
+
* Scalar values are not supported as a schema definition. It always represents an object.
|
|
43
|
+
*/
|
|
44
|
+
export class ProjectSchema {
|
|
45
|
+
kind = Kind;
|
|
46
|
+
/**
|
|
47
|
+
* The identifier of the environment.
|
|
48
|
+
*/
|
|
49
|
+
key = '';
|
|
50
|
+
/**
|
|
51
|
+
* The optional list of properties in this schema.
|
|
52
|
+
* Because this is a list instead of a map it is possible to duplicate the property name. In this
|
|
53
|
+
* case the last set value is the final value.
|
|
54
|
+
*
|
|
55
|
+
* When both the `properties` and the `content` is defined, `content` is used instead of properties.
|
|
56
|
+
*/
|
|
57
|
+
properties?: Property[];
|
|
58
|
+
/**
|
|
59
|
+
* The "raw" content of the schema.
|
|
60
|
+
* This value goes unchanged to the request.
|
|
61
|
+
*/
|
|
62
|
+
content?: string;
|
|
63
|
+
/**
|
|
64
|
+
* When content is used, it informs about the content type of the
|
|
65
|
+
* schema. The schema is invalid when `content` is set and the `mime` is not.
|
|
66
|
+
*/
|
|
67
|
+
mime?: string;
|
|
68
|
+
/**
|
|
69
|
+
* The name of the schema.
|
|
70
|
+
*/
|
|
71
|
+
name= '';
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* Creates a new schema instance from the passed name.
|
|
75
|
+
* @param name The name of the schema.
|
|
76
|
+
*/
|
|
77
|
+
static fromName(name: string): ProjectSchema {
|
|
78
|
+
const init: IProjectSchema = {
|
|
79
|
+
kind: Kind,
|
|
80
|
+
name,
|
|
81
|
+
key: v4(),
|
|
82
|
+
};
|
|
83
|
+
return new ProjectSchema(init);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* Creates a new schema instance from the content definition
|
|
88
|
+
* @param name The name of the schema.
|
|
89
|
+
* @param content The "raw" content of the schema
|
|
90
|
+
* @param mime The mime type associated with the schema.
|
|
91
|
+
* @returns The instance of the created schema
|
|
92
|
+
*/
|
|
93
|
+
static fromContent(name: string, content: string, mime: string): ProjectSchema {
|
|
94
|
+
const init: IProjectSchema = {
|
|
95
|
+
kind: Kind,
|
|
96
|
+
name,
|
|
97
|
+
key: v4(),
|
|
98
|
+
content,
|
|
99
|
+
mime,
|
|
100
|
+
};
|
|
101
|
+
return new ProjectSchema(init);
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* @param input The schema definition used to restore the state.
|
|
106
|
+
*/
|
|
107
|
+
constructor(input?: string | IProjectSchema) {
|
|
108
|
+
let init: IProjectSchema;
|
|
109
|
+
if (typeof input === 'string') {
|
|
110
|
+
init = JSON.parse(input);
|
|
111
|
+
} else if (typeof input === 'object') {
|
|
112
|
+
init = input;
|
|
113
|
+
} else {
|
|
114
|
+
init = {
|
|
115
|
+
kind: Kind,
|
|
116
|
+
name: '',
|
|
117
|
+
key: v4(),
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
this.new(init);
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
/**
|
|
124
|
+
* Creates a new schema definition clearing anything that is so far defined.
|
|
125
|
+
*/
|
|
126
|
+
new(init: IProjectSchema): void {
|
|
127
|
+
const { key=v4(), content, properties, mime, name='' } = init;
|
|
128
|
+
this.name = name;
|
|
129
|
+
this.key = key;
|
|
130
|
+
if (content) {
|
|
131
|
+
this.content = content;
|
|
132
|
+
} else {
|
|
133
|
+
this.content = undefined;
|
|
134
|
+
}
|
|
135
|
+
if (Array.isArray(properties)) {
|
|
136
|
+
this.properties = properties.map(i => new Property(i));
|
|
137
|
+
} else {
|
|
138
|
+
this.properties = undefined;
|
|
139
|
+
}
|
|
140
|
+
if (mime) {
|
|
141
|
+
this.mime = mime;
|
|
142
|
+
} else {
|
|
143
|
+
this.mime = undefined;
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
toJSON(): IProjectSchema {
|
|
148
|
+
const result:IProjectSchema = {
|
|
149
|
+
kind: Kind,
|
|
150
|
+
name: this.name || '',
|
|
151
|
+
key: this.key || v4(),
|
|
152
|
+
};
|
|
153
|
+
if (this.content) {
|
|
154
|
+
result.content = this.content;
|
|
155
|
+
}
|
|
156
|
+
if (this.mime) {
|
|
157
|
+
result.mime = this.mime;
|
|
158
|
+
}
|
|
159
|
+
if (Array.isArray(this.properties) && this.properties.length) {
|
|
160
|
+
result.properties = this.properties.map(i => i.toJSON());
|
|
161
|
+
}
|
|
162
|
+
return result;
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
/**
|
|
166
|
+
* Creates a schema property from a definition.
|
|
167
|
+
* @param info The property definition.
|
|
168
|
+
* @returns The same property definition
|
|
169
|
+
*/
|
|
170
|
+
addProperty(info: IProperty): Property;
|
|
171
|
+
|
|
172
|
+
/**
|
|
173
|
+
* Creates a schema property from a definition.
|
|
174
|
+
*
|
|
175
|
+
* @param name The property name
|
|
176
|
+
* @param type The property data type
|
|
177
|
+
* @returns The created schema definition.
|
|
178
|
+
*/
|
|
179
|
+
addProperty(name: string, type: PropertyType): Property;
|
|
180
|
+
|
|
181
|
+
addProperty(infoOrName: string | IProperty, type?: PropertyType): Property {
|
|
182
|
+
const infoType = typeof infoOrName;
|
|
183
|
+
if (infoType === 'string' && !type) {
|
|
184
|
+
throw new Error('The type is required.');
|
|
185
|
+
}
|
|
186
|
+
let instance: Property;
|
|
187
|
+
if (infoType === 'string') {
|
|
188
|
+
instance = Property.fromTypeDefault(infoOrName as string, type as PropertyType);
|
|
189
|
+
} else {
|
|
190
|
+
const init = infoOrName as IProperty;
|
|
191
|
+
if (!init.kind) {
|
|
192
|
+
init.kind = PropertyKind;
|
|
193
|
+
}
|
|
194
|
+
instance = new Property(init);
|
|
195
|
+
}
|
|
196
|
+
if (!Array.isArray(this.properties)) {
|
|
197
|
+
this.properties = [];
|
|
198
|
+
}
|
|
199
|
+
this.properties.push(instance);
|
|
200
|
+
return instance;
|
|
201
|
+
}
|
|
202
|
+
}
|