@api-client/core 0.8.21 → 0.9.0
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 +12 -5
- package/build/browser.js +2 -3
- package/build/browser.js.map +1 -1
- package/build/index.d.ts +12 -5
- package/build/index.js +2 -4
- package/build/index.js.map +1 -1
- package/build/src/events/BaseEvents.d.ts +125 -18
- package/build/src/events/BaseEvents.js.map +1 -1
- package/build/src/events/EventTypes.d.ts +0 -14
- package/build/src/events/EventTypes.js +0 -2
- package/build/src/events/EventTypes.js.map +1 -1
- package/build/src/events/Events.d.ts +1 -5
- package/build/src/events/Events.js +0 -2
- package/build/src/events/Events.js.map +1 -1
- package/build/src/events/transport/TransportEventTypes.d.ts +0 -1
- package/build/src/events/transport/TransportEventTypes.js +0 -1
- package/build/src/events/transport/TransportEventTypes.js.map +1 -1
- package/build/src/events/transport/TransportEvents.d.ts +0 -8
- package/build/src/events/transport/TransportEvents.js +0 -11
- package/build/src/events/transport/TransportEvents.js.map +1 -1
- package/build/src/mocking/ProjectMock.d.ts +0 -3
- package/build/src/mocking/ProjectMock.js +0 -3
- package/build/src/mocking/ProjectMock.js.map +1 -1
- package/build/src/mocking/lib/History.js +5 -0
- package/build/src/mocking/lib/History.js.map +1 -1
- package/build/src/models/{Workspace.d.ts → Folder.d.ts} +7 -7
- package/build/src/models/{Workspace.js → Folder.js} +5 -5
- package/build/src/models/Folder.js.map +1 -0
- package/build/src/models/HttpHistory.d.ts +38 -43
- package/build/src/models/HttpHistory.js +27 -34
- package/build/src/models/HttpHistory.js.map +1 -1
- package/build/src/models/HttpProject.d.ts +0 -2
- package/build/src/models/HttpProject.js +0 -27
- package/build/src/models/HttpProject.js.map +1 -1
- package/build/src/models/Project.d.ts +0 -8
- package/build/src/models/Project.js +0 -4
- package/build/src/models/Project.js.map +1 -1
- package/build/src/models/ProjectFolder.d.ts +0 -2
- package/build/src/models/ProjectFolder.js +0 -14
- package/build/src/models/ProjectFolder.js.map +1 -1
- package/build/src/models/ProjectItem.d.ts +0 -2
- package/build/src/models/ProjectItem.js +0 -20
- package/build/src/models/ProjectItem.js.map +1 -1
- package/build/src/models/ProjectRequest.d.ts +2 -3
- package/build/src/models/ProjectRequest.js.map +1 -1
- package/build/src/models/RequestConfig.d.ts +1 -1
- package/build/src/models/Space.d.ts +42 -0
- package/build/src/models/Space.js +81 -0
- package/build/src/models/Space.js.map +1 -0
- package/build/src/models/TrashEntry.d.ts +27 -0
- package/build/src/models/TrashEntry.js +2 -0
- package/build/src/models/TrashEntry.js.map +1 -0
- package/build/src/models/data/DataAssociation.d.ts +22 -5
- package/build/src/models/data/DataAssociation.js +29 -11
- package/build/src/models/data/DataAssociation.js.map +1 -1
- package/build/src/models/data/DataEntity.d.ts +12 -1
- package/build/src/models/data/DataEntity.js +49 -10
- package/build/src/models/data/DataEntity.js.map +1 -1
- package/build/src/models/data/DataNamespace.d.ts +34 -1
- package/build/src/models/data/DataNamespace.js +75 -1
- package/build/src/models/data/DataNamespace.js.map +1 -1
- package/build/src/models/store/Backend.d.ts +0 -315
- package/build/src/models/store/Backend.js +0 -1
- package/build/src/models/store/Backend.js.map +1 -1
- package/build/src/models/store/File.d.ts +30 -0
- package/build/src/models/store/File.js +5 -5
- package/build/src/models/store/File.js.map +1 -1
- package/build/src/proxy/ProxyService.d.ts +0 -10
- package/build/src/proxy/ProxyService.js +0 -14
- package/build/src/proxy/ProxyService.js.map +1 -1
- package/build/src/runtime/node/InteropInterfaces.d.ts +1 -2
- package/build/src/runtime/node/ProjectParallelRunner.d.ts +2 -3
- package/build/src/runtime/node/ProjectParallelRunner.js.map +1 -1
- package/build/src/runtime/node/ProjectRequestRunner.d.ts +7 -8
- package/build/src/runtime/node/ProjectRequestRunner.js +2 -3
- package/build/src/runtime/node/ProjectRequestRunner.js.map +1 -1
- package/build/src/runtime/node/ProjectRunner.d.ts +3 -4
- package/build/src/runtime/node/ProjectRunner.js.map +1 -1
- package/build/src/runtime/node/ProjectRunnerWorker.js +0 -4
- package/build/src/runtime/node/ProjectRunnerWorker.js.map +1 -1
- package/build/src/runtime/store/CertificatesSdk.d.ts +46 -0
- package/build/src/runtime/store/CertificatesSdk.js +227 -0
- package/build/src/runtime/store/CertificatesSdk.js.map +1 -0
- package/build/src/runtime/store/FilesSdk.d.ts +14 -9
- package/build/src/runtime/store/FilesSdk.js +60 -16
- package/build/src/runtime/store/FilesSdk.js.map +1 -1
- package/build/src/runtime/store/HistorySdk.d.ts +11 -8
- package/build/src/runtime/store/HistorySdk.js +140 -17
- package/build/src/runtime/store/HistorySdk.js.map +1 -1
- package/build/src/runtime/store/RevisionsSdk.d.ts +12 -0
- package/build/src/runtime/store/RevisionsSdk.js +43 -0
- package/build/src/runtime/store/RevisionsSdk.js.map +1 -0
- package/build/src/runtime/store/RouteBuilder.d.ts +16 -18
- package/build/src/runtime/store/RouteBuilder.js +33 -60
- package/build/src/runtime/store/RouteBuilder.js.map +1 -1
- package/build/src/runtime/store/Sdk.d.ts +10 -7
- package/build/src/runtime/store/Sdk.js +12 -5
- package/build/src/runtime/store/Sdk.js.map +1 -1
- package/build/src/runtime/store/SdkBase.js.map +1 -1
- package/build/src/runtime/store/SharedSdk.d.ts +2 -2
- package/build/src/runtime/store/SharedSdk.js.map +1 -1
- package/build/src/runtime/store/SpacesSdk.d.ts +29 -0
- package/build/src/runtime/store/SpacesSdk.js +135 -0
- package/build/src/runtime/store/SpacesSdk.js.map +1 -0
- package/build/src/runtime/store/TrashSdk.d.ts +35 -0
- package/build/src/runtime/store/TrashSdk.js +155 -0
- package/build/src/runtime/store/TrashSdk.js.map +1 -0
- package/build/src/runtime/store/UsersSdk.d.ts +2 -2
- package/build/src/runtime/store/UsersSdk.js.map +1 -1
- package/build/src/runtime/store/interfaces/ApiClientStore.d.ts +30 -0
- package/build/src/runtime/store/interfaces/ApiClientStore.js +2 -0
- package/build/src/runtime/store/interfaces/ApiClientStore.js.map +1 -0
- package/build/src/runtime/store/interfaces/Certificates.d.ts +49 -0
- package/build/src/runtime/store/interfaces/Certificates.js +2 -0
- package/build/src/runtime/store/interfaces/Certificates.js.map +1 -0
- package/build/src/runtime/store/interfaces/Files.d.ts +63 -0
- package/build/src/runtime/store/interfaces/Files.js +2 -0
- package/build/src/runtime/store/interfaces/Files.js.map +1 -0
- package/build/src/runtime/store/interfaces/History.d.ts +63 -0
- package/build/src/runtime/store/interfaces/History.js +2 -0
- package/build/src/runtime/store/interfaces/History.js.map +1 -0
- package/build/src/runtime/store/interfaces/Media.d.ts +42 -0
- package/build/src/runtime/store/interfaces/Media.js +2 -0
- package/build/src/runtime/store/interfaces/Media.js.map +1 -0
- package/build/src/runtime/store/interfaces/Revisions.d.ts +25 -0
- package/build/src/runtime/store/interfaces/Revisions.js +2 -0
- package/build/src/runtime/store/interfaces/Revisions.js.map +1 -0
- package/build/src/runtime/store/interfaces/Spaces.d.ts +42 -0
- package/build/src/runtime/store/interfaces/Spaces.js +2 -0
- package/build/src/runtime/store/interfaces/Spaces.js.map +1 -0
- package/build/src/runtime/store/interfaces/Trash.d.ts +38 -0
- package/build/src/runtime/store/interfaces/Trash.js +2 -0
- package/build/src/runtime/store/interfaces/Trash.js.map +1 -0
- package/package.json +12 -12
- package/src/events/BaseEvents.ts +136 -18
- package/src/events/EventTypes.ts +0 -2
- package/src/events/Events.ts +0 -2
- package/src/events/transport/TransportEventTypes.ts +0 -1
- package/src/events/transport/TransportEvents.ts +0 -13
- package/src/mocking/ProjectMock.ts +0 -4
- package/src/mocking/lib/History.ts +5 -0
- package/src/models/{Workspace.ts → Folder.ts} +12 -12
- package/src/models/HttpHistory.ts +53 -63
- package/src/models/HttpProject.ts +0 -29
- package/src/models/Project.ts +0 -8
- package/src/models/ProjectFolder.ts +0 -16
- package/src/models/ProjectItem.ts +0 -18
- package/src/models/ProjectRequest.ts +3 -4
- package/src/models/RequestConfig.ts +1 -1
- package/src/models/Space.ts +105 -0
- package/src/models/TrashEntry.ts +29 -0
- package/src/models/data/DataAssociation.ts +50 -15
- package/src/models/data/DataEntity.ts +51 -10
- package/src/models/data/DataNamespace.ts +78 -2
- package/src/models/store/Backend.ts +0 -342
- package/src/models/store/File.ts +38 -5
- package/src/proxy/ProxyService.ts +0 -15
- package/src/proxy/readme.md +0 -1
- package/src/runtime/node/InteropInterfaces.ts +1 -2
- package/src/runtime/node/ProjectParallelRunner.ts +2 -3
- package/src/runtime/node/ProjectRequestRunner.ts +13 -14
- package/src/runtime/node/ProjectRunner.ts +3 -4
- package/src/runtime/node/ProjectRunnerWorker.ts +1 -4
- package/src/runtime/store/CertificatesSdk.ts +231 -0
- package/src/runtime/store/FilesSdk.ts +71 -26
- package/src/runtime/store/HistorySdk.ts +145 -33
- package/src/runtime/store/RevisionsSdk.ts +44 -0
- package/src/runtime/store/RouteBuilder.ts +37 -69
- package/src/runtime/store/Sdk.ts +17 -7
- package/src/runtime/store/SdkBase.ts +1 -1
- package/src/runtime/store/SharedSdk.ts +3 -3
- package/src/runtime/store/SpacesSdk.ts +136 -0
- package/src/runtime/store/TrashSdk.ts +159 -0
- package/src/runtime/store/UsersSdk.ts +3 -3
- package/src/runtime/store/interfaces/ApiClientStore.ts +39 -0
- package/src/runtime/store/interfaces/Certificates.ts +56 -0
- package/src/runtime/store/interfaces/Files.ts +70 -0
- package/src/runtime/store/interfaces/History.ts +64 -0
- package/src/runtime/store/interfaces/Media.ts +46 -0
- package/src/runtime/store/interfaces/Revisions.ts +27 -0
- package/src/runtime/store/interfaces/Spaces.ts +48 -0
- package/src/runtime/store/interfaces/Trash.ts +42 -0
- package/build/src/events/models/ClientCertificateEvents.d.ts +0 -54
- package/build/src/events/models/ClientCertificateEvents.js +0 -78
- package/build/src/events/models/ClientCertificateEvents.js.map +0 -1
- package/build/src/events/models/ModelEventTypes.d.ts +0 -13
- package/build/src/events/models/ModelEventTypes.js +0 -14
- package/build/src/events/models/ModelEventTypes.js.map +0 -1
- package/build/src/events/models/ModelEvents.d.ts +0 -4
- package/build/src/events/models/ModelEvents.js +0 -5
- package/build/src/events/models/ModelEvents.js.map +0 -1
- package/build/src/mocking/lib/App.d.ts +0 -36
- package/build/src/mocking/lib/App.js +0 -70
- package/build/src/mocking/lib/App.js.map +0 -1
- package/build/src/models/AppProject.d.ts +0 -817
- package/build/src/models/AppProject.js +0 -1721
- package/build/src/models/AppProject.js.map +0 -1
- package/build/src/models/AppRequest.d.ts +0 -69
- package/build/src/models/AppRequest.js +0 -150
- package/build/src/models/AppRequest.js.map +0 -1
- package/build/src/models/Workspace.js.map +0 -1
- package/build/src/proxy/AppProjectProxy.d.ts +0 -28
- package/build/src/proxy/AppProjectProxy.js +0 -107
- package/build/src/proxy/AppProjectProxy.js.map +0 -1
- package/build/src/runtime/store/AppSdk.d.ts +0 -213
- package/build/src/runtime/store/AppSdk.js +0 -836
- package/build/src/runtime/store/AppSdk.js.map +0 -1
- package/src/events/models/ClientCertificateEvents.ts +0 -85
- package/src/events/models/ModelEventTypes.ts +0 -13
- package/src/events/models/ModelEvents.ts +0 -5
- package/src/mocking/lib/App.ts +0 -101
- package/src/models/AppProject.ts +0 -2188
- package/src/models/AppRequest.ts +0 -176
- package/src/proxy/AppProjectProxy.ts +0 -126
- package/src/runtime/store/AppSdk.ts +0 -842
package/src/models/AppProject.ts
DELETED
|
@@ -1,2188 +0,0 @@
|
|
|
1
|
-
/* eslint-disable no-param-reassign */
|
|
2
|
-
/* eslint-disable class-methods-use-this */
|
|
3
|
-
/* eslint-disable @typescript-eslint/no-this-alias */
|
|
4
|
-
/* eslint-disable max-classes-per-file */
|
|
5
|
-
// import { ARCHistoryRequest, ARCSavedRequest } from "@api-client/core/build/legacy.js";
|
|
6
|
-
|
|
7
|
-
import v4 from "../lib/uuid.js";
|
|
8
|
-
import { HttpRequest, IHttpRequest } from "./HttpRequest.js";
|
|
9
|
-
import { IRequest, Request } from "./Request.js";
|
|
10
|
-
import { Environment, IEnvironment, Kind as EnvironmentKind } from './Environment.js';
|
|
11
|
-
import { IThing, Thing, Kind as ThingKind } from "./Thing.js";
|
|
12
|
-
import { ARCHistoryRequest, ARCSavedRequest } from "./legacy/request/ArcRequest.js";
|
|
13
|
-
import { ARCProject } from "./legacy/models/ArcLegacyProject.js";
|
|
14
|
-
import { Certificate, HttpCertificate } from "./ClientCertificate.js";
|
|
15
|
-
import { ICCAuthorization } from "./Authorization.js";
|
|
16
|
-
import { IProjectRequestIterator } from "./HttpProject.js";
|
|
17
|
-
import { IFile, File, DefaultOwner } from "./store/File.js";
|
|
18
|
-
|
|
19
|
-
export const AppProjectKind = 'Core#AppProject';
|
|
20
|
-
export const AppProjectFolderKind = 'Core#AppProjectFolder';
|
|
21
|
-
export const AppProjectRequestKind = 'Core#AppProjectRequest';
|
|
22
|
-
export const AppProjectFileKind = 'Core#AppProjectFile';
|
|
23
|
-
|
|
24
|
-
export interface IAppProjectItemOptions {
|
|
25
|
-
/**
|
|
26
|
-
* The parent folder to add the item to.
|
|
27
|
-
*/
|
|
28
|
-
parent?: string;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
export interface IAppProjectItemCreateOptions extends IAppProjectItemOptions {
|
|
32
|
-
/**
|
|
33
|
-
* The position at which to add the item.
|
|
34
|
-
*/
|
|
35
|
-
index?: number;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
export interface IAppProjectRequestCloneOptions {
|
|
39
|
-
/**
|
|
40
|
-
* By default it revalidates (re-creates) keys in the request.
|
|
41
|
-
* Set this to true to not make any changes to the keys.
|
|
42
|
-
*/
|
|
43
|
-
withoutRevalidate?: boolean;
|
|
44
|
-
/**
|
|
45
|
-
* By default it attaches the request to the same parent as the original request.
|
|
46
|
-
* Set this to `true` when moving a request between projects to prevent adding the request to the project.
|
|
47
|
-
* Note, the request still have a reference to the original project. You need to update the `project` property.
|
|
48
|
-
*/
|
|
49
|
-
withoutAttach?: boolean;
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
export interface IAppProjectFolderAddOptions {
|
|
53
|
-
/**
|
|
54
|
-
* Optionally the position at which to add the request into the list of items.
|
|
55
|
-
*/
|
|
56
|
-
index?: number;
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
export interface IAppProjectFolderCloneOptions {
|
|
60
|
-
/**
|
|
61
|
-
* By default it clones the folder with all requests in it.
|
|
62
|
-
* Set this to `true` to skip copying the requests along with the folder.
|
|
63
|
-
*/
|
|
64
|
-
withoutRequests?: boolean;
|
|
65
|
-
/**
|
|
66
|
-
* By default it clones the folder with all folders in it.
|
|
67
|
-
* Set this to `true` to skip copying the folders along with the folder.
|
|
68
|
-
*/
|
|
69
|
-
withoutFolders?: boolean;
|
|
70
|
-
/**
|
|
71
|
-
* The target project where to put the copied folder.
|
|
72
|
-
* When the target project is not the same as the source project then the folder
|
|
73
|
-
* is put into the project root rather than the parent folder (as it would when cloning
|
|
74
|
-
* a folder inside the same project).
|
|
75
|
-
*/
|
|
76
|
-
targetProject?: AppProject;
|
|
77
|
-
/**
|
|
78
|
-
* The **key** of the target folder.
|
|
79
|
-
*
|
|
80
|
-
* By default it clones the folder to its parent unless the clone is attached to another project.
|
|
81
|
-
* When the target folder is set then it places the clone under the passed target folder.
|
|
82
|
-
*/
|
|
83
|
-
targetFolder?: string;
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
export interface IAppProjectFolderCreateOptions extends IAppProjectItemOptions {
|
|
87
|
-
/**
|
|
88
|
-
* Ignores the operation when the folder with the same name already exists.
|
|
89
|
-
* This command can be used used to ensure that the folder exists.
|
|
90
|
-
*/
|
|
91
|
-
skipExisting?: boolean;
|
|
92
|
-
/**
|
|
93
|
-
* Optionally the position at which to add the folder into the list of items.
|
|
94
|
-
*/
|
|
95
|
-
index?: number;
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
export interface IAppProjectFolderSearchOptions {
|
|
99
|
-
/**
|
|
100
|
-
* When set it searches for a folder using keys only.
|
|
101
|
-
* By default it searches for a key and the name.
|
|
102
|
-
*/
|
|
103
|
-
keyOnly?: boolean;
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
export interface IAppProjectFolderDeleteOptions {
|
|
107
|
-
/**
|
|
108
|
-
* When set it won't throw an error when the folder is not found in the project.
|
|
109
|
-
*/
|
|
110
|
-
safe?: boolean;
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
export interface IAppProjectRequestAddOptions extends IAppProjectItemOptions {
|
|
114
|
-
/**
|
|
115
|
-
* Optionally the position at which to add the request into the list of items.
|
|
116
|
-
*/
|
|
117
|
-
index?: number;
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
export interface IAppProjectRequestSearchOptions {
|
|
121
|
-
/**
|
|
122
|
-
* When set it searches for a request using keys only.
|
|
123
|
-
* By default it searches for a key and the name.
|
|
124
|
-
*/
|
|
125
|
-
keyOnly?: boolean;
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
export interface IAppProjectRequestDeleteOptions {
|
|
129
|
-
/**
|
|
130
|
-
* When set it won't throw an error when the request is not found in the project.
|
|
131
|
-
*/
|
|
132
|
-
safe?: boolean;
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
export interface IAppProjectProjectMoveOptions extends IAppProjectItemOptions {
|
|
136
|
-
/**
|
|
137
|
-
* The position at which to insert the object in the destination. BY default it adds the object at the end.
|
|
138
|
-
*/
|
|
139
|
-
index?: number;
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
export interface IAppProjectFolderListOptions {
|
|
143
|
-
/**
|
|
144
|
-
* Folder name or key to list folders for.
|
|
145
|
-
*/
|
|
146
|
-
folder?: string;
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
export interface IAppProjectProjectCloneOptions {
|
|
150
|
-
/**
|
|
151
|
-
* By default it revalidates (re-creates) keys in the request.
|
|
152
|
-
* Set this to true to not make any changes to the keys.
|
|
153
|
-
*/
|
|
154
|
-
withoutRevalidate?: boolean;
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
export interface IAppProjectEnvironmentCreateOptions extends IAppProjectItemOptions {
|
|
158
|
-
/**
|
|
159
|
-
* The position at which to add the item.
|
|
160
|
-
*/
|
|
161
|
-
index?: number;
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
export interface IAppProjectReadEnvironmentOptions extends IAppProjectItemOptions {
|
|
165
|
-
/**
|
|
166
|
-
* The name or the key of the environment to select.
|
|
167
|
-
*
|
|
168
|
-
* When the name is not specified it selects:
|
|
169
|
-
* - the first environment from the project, if any
|
|
170
|
-
* - any parent folder's first environment to the requested folder, if any (if parent is set)
|
|
171
|
-
* - the requested folder's first environment, if any (if parent is set)
|
|
172
|
-
*/
|
|
173
|
-
nameOrKey?: string;
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
export interface IAppProjectRequest extends IRequest {
|
|
177
|
-
kind: typeof AppProjectRequestKind;
|
|
178
|
-
key: string;
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
export interface IAppProjectItem {
|
|
182
|
-
kind: typeof AppProjectFolderKind | typeof AppProjectRequestKind | typeof EnvironmentKind;
|
|
183
|
-
key: string;
|
|
184
|
-
}
|
|
185
|
-
|
|
186
|
-
export interface IAppProjectDefinitions {
|
|
187
|
-
/**
|
|
188
|
-
* The list of all folders defined in the project.
|
|
189
|
-
*/
|
|
190
|
-
folders?: IAppProjectParent[];
|
|
191
|
-
/**
|
|
192
|
-
* The list of all requests defined in the project.
|
|
193
|
-
*/
|
|
194
|
-
requests?: IAppProjectRequest[];
|
|
195
|
-
environments?: IEnvironment[];
|
|
196
|
-
certificates?: HttpCertificate[];
|
|
197
|
-
}
|
|
198
|
-
|
|
199
|
-
export interface AppProjectDefinitions {
|
|
200
|
-
/**
|
|
201
|
-
* The list of all folders defined in the project.
|
|
202
|
-
*/
|
|
203
|
-
folders: AppProjectFolder[];
|
|
204
|
-
/**
|
|
205
|
-
* The list of all requests defined in the project.
|
|
206
|
-
*/
|
|
207
|
-
requests: AppProjectRequest[];
|
|
208
|
-
environments: Environment[];
|
|
209
|
-
certificates: Certificate[];
|
|
210
|
-
}
|
|
211
|
-
|
|
212
|
-
/**
|
|
213
|
-
* An app project is similar to the HttpProject but stored for a single application
|
|
214
|
-
* and has no sharing options. The AppProject can be upgraded to an HttpProject.
|
|
215
|
-
*/
|
|
216
|
-
export interface IAppProject extends IAppProjectParent {
|
|
217
|
-
definitions: IAppProjectDefinitions;
|
|
218
|
-
}
|
|
219
|
-
|
|
220
|
-
export interface IAppProjectParent {
|
|
221
|
-
key: string;
|
|
222
|
-
kind: typeof AppProjectKind | typeof AppProjectFolderKind;
|
|
223
|
-
/**
|
|
224
|
-
* Folder meta
|
|
225
|
-
*/
|
|
226
|
-
info: IThing;
|
|
227
|
-
/**
|
|
228
|
-
* The list of items in the folder.
|
|
229
|
-
* It is an ordered list of requests and folders.
|
|
230
|
-
* The actual definition is kept in the root's `definitions`.
|
|
231
|
-
*/
|
|
232
|
-
items: IAppProjectItem[];
|
|
233
|
-
/**
|
|
234
|
-
* Timestamp when the project was last updated.
|
|
235
|
-
*/
|
|
236
|
-
updated?: number;
|
|
237
|
-
/**
|
|
238
|
-
* Timestamp when the project was created.
|
|
239
|
-
*/
|
|
240
|
-
created?: number;
|
|
241
|
-
}
|
|
242
|
-
|
|
243
|
-
export class AppProjectRequest extends Request {
|
|
244
|
-
override kind = AppProjectRequestKind;
|
|
245
|
-
|
|
246
|
-
/**
|
|
247
|
-
* The identifier of the request.
|
|
248
|
-
*/
|
|
249
|
-
key = '';
|
|
250
|
-
|
|
251
|
-
/**
|
|
252
|
-
* A reference to the top level project object.
|
|
253
|
-
*/
|
|
254
|
-
project: AppProject;
|
|
255
|
-
|
|
256
|
-
/**
|
|
257
|
-
* Creates a project request from an URL.
|
|
258
|
-
* This does not manipulate the project.
|
|
259
|
-
*
|
|
260
|
-
* @param url The Request URL. This is required.
|
|
261
|
-
* @param project The parent project.
|
|
262
|
-
*/
|
|
263
|
-
static override fromUrl(url: string, project?: AppProject): AppProjectRequest {
|
|
264
|
-
if (!project) {
|
|
265
|
-
throw new Error(`The project is required.`);
|
|
266
|
-
}
|
|
267
|
-
const now: number = Date.now();
|
|
268
|
-
const request = new AppProjectRequest(project, {
|
|
269
|
-
key: v4(),
|
|
270
|
-
kind: AppProjectRequestKind,
|
|
271
|
-
created: now,
|
|
272
|
-
updated: now,
|
|
273
|
-
expects: HttpRequest.fromBaseValues({ url, method: 'GET' }).toJSON(),
|
|
274
|
-
info: Thing.fromName(url).toJSON(),
|
|
275
|
-
});
|
|
276
|
-
return request;
|
|
277
|
-
}
|
|
278
|
-
|
|
279
|
-
/**
|
|
280
|
-
* Creates a project request from a name.
|
|
281
|
-
* This does not manipulate the project.
|
|
282
|
-
*
|
|
283
|
-
* @param name The Request name.
|
|
284
|
-
* @param project The parent project.This is required.
|
|
285
|
-
*/
|
|
286
|
-
static override fromName(name: string, project?: AppProject): AppProjectRequest {
|
|
287
|
-
if (!project) {
|
|
288
|
-
throw new Error(`The project is required.`);
|
|
289
|
-
}
|
|
290
|
-
const now: number = Date.now();
|
|
291
|
-
const request = new AppProjectRequest(project, {
|
|
292
|
-
key: v4(),
|
|
293
|
-
kind: AppProjectRequestKind,
|
|
294
|
-
created: now,
|
|
295
|
-
updated: now,
|
|
296
|
-
expects: new HttpRequest().toJSON(),
|
|
297
|
-
info: Thing.fromName(name).toJSON(),
|
|
298
|
-
});
|
|
299
|
-
return request;
|
|
300
|
-
}
|
|
301
|
-
|
|
302
|
-
/**
|
|
303
|
-
* Creates a project request from an HttpRequest definition.
|
|
304
|
-
* This does not manipulate the project.
|
|
305
|
-
*
|
|
306
|
-
* @param project The parent project This is required.
|
|
307
|
-
* @param info The request data.
|
|
308
|
-
*/
|
|
309
|
-
static override fromHttpRequest(info: IHttpRequest, project?: AppProject): AppProjectRequest {
|
|
310
|
-
if (!project) {
|
|
311
|
-
throw new Error(`The project is required.`);
|
|
312
|
-
}
|
|
313
|
-
const now: number = Date.now();
|
|
314
|
-
const request = new AppProjectRequest(project, {
|
|
315
|
-
key: v4(),
|
|
316
|
-
kind: AppProjectRequestKind,
|
|
317
|
-
created: now,
|
|
318
|
-
updated: now,
|
|
319
|
-
expects: HttpRequest.fromBaseValues({ method: info.method, url: info.url, headers: info.headers, payload: info.payload }).toJSON(),
|
|
320
|
-
info: Thing.fromName(info.url).toJSON(),
|
|
321
|
-
});
|
|
322
|
-
return request;
|
|
323
|
-
}
|
|
324
|
-
|
|
325
|
-
/**
|
|
326
|
-
* Creates a project request for a schema of a Request.
|
|
327
|
-
*/
|
|
328
|
-
static fromRequest(request: IRequest, project: AppProject): AppProjectRequest {
|
|
329
|
-
const key = v4();
|
|
330
|
-
const init: IAppProjectRequest = { ...request, key, kind: AppProjectRequestKind };
|
|
331
|
-
const result = new AppProjectRequest(project, init);
|
|
332
|
-
return result;
|
|
333
|
-
}
|
|
334
|
-
|
|
335
|
-
constructor(project: AppProject, input?: string | IAppProjectRequest) {
|
|
336
|
-
super(input);
|
|
337
|
-
this.project = project;
|
|
338
|
-
|
|
339
|
-
let init: IAppProjectRequest | undefined;
|
|
340
|
-
if (typeof input === 'string') {
|
|
341
|
-
init = JSON.parse(input);
|
|
342
|
-
} else if (typeof input === 'object') {
|
|
343
|
-
init = input;
|
|
344
|
-
}
|
|
345
|
-
if (init) {
|
|
346
|
-
this.key = init.key || v4();
|
|
347
|
-
}
|
|
348
|
-
this.kind = AppProjectRequestKind;
|
|
349
|
-
}
|
|
350
|
-
|
|
351
|
-
override new(init: IAppProjectRequest): void {
|
|
352
|
-
super.new(init);
|
|
353
|
-
|
|
354
|
-
const { key = v4() } = init;
|
|
355
|
-
this.key = key;
|
|
356
|
-
this.kind = AppProjectRequestKind;
|
|
357
|
-
}
|
|
358
|
-
|
|
359
|
-
override toJSON(): IAppProjectRequest {
|
|
360
|
-
const request = super.toJSON();
|
|
361
|
-
const result: IAppProjectRequest = { ...request, key: this.key, kind: AppProjectRequestKind };
|
|
362
|
-
return result;
|
|
363
|
-
}
|
|
364
|
-
|
|
365
|
-
/**
|
|
366
|
-
* @returns The instance of the ArcProject or a ArcProjectFolder that is a closes parent of this instance.
|
|
367
|
-
*/
|
|
368
|
-
getParent(): AppProjectFolder | AppProject | undefined {
|
|
369
|
-
const { project, key } = this;
|
|
370
|
-
return project.findParent(key);
|
|
371
|
-
}
|
|
372
|
-
|
|
373
|
-
/**
|
|
374
|
-
* @returns A reference to the parent folder or the top-level HTTP project.
|
|
375
|
-
*/
|
|
376
|
-
getProject(): AppProject {
|
|
377
|
-
return this.project;
|
|
378
|
-
}
|
|
379
|
-
|
|
380
|
-
/**
|
|
381
|
-
* Removes this request from the project.
|
|
382
|
-
*/
|
|
383
|
-
remove(): void {
|
|
384
|
-
this.project.removeRequest(this.key);
|
|
385
|
-
}
|
|
386
|
-
|
|
387
|
-
/**
|
|
388
|
-
* Makes a copy of this request.
|
|
389
|
-
* By default it attaches the copied request to the same parent.
|
|
390
|
-
* Use the options dictionary to control this behavior.
|
|
391
|
-
*/
|
|
392
|
-
clone(opts: IAppProjectRequestCloneOptions = {}): AppProjectRequest {
|
|
393
|
-
const copy = new AppProjectRequest(this.project, this.toJSON());
|
|
394
|
-
if (!opts.withoutRevalidate) {
|
|
395
|
-
copy.key = v4();
|
|
396
|
-
}
|
|
397
|
-
if (!opts.withoutAttach) {
|
|
398
|
-
// if the parent is the project then add the request to the project.
|
|
399
|
-
const parent = this.getParent();
|
|
400
|
-
if (parent) {
|
|
401
|
-
parent.addRequest(copy);
|
|
402
|
-
}
|
|
403
|
-
}
|
|
404
|
-
return copy;
|
|
405
|
-
}
|
|
406
|
-
|
|
407
|
-
/**
|
|
408
|
-
* The static version of the `clone()` method.
|
|
409
|
-
*
|
|
410
|
-
* @param request The request schema to clone.
|
|
411
|
-
* @param project The project to add the request to.
|
|
412
|
-
* @param opts Optional options.
|
|
413
|
-
* @returns The copied request.
|
|
414
|
-
*/
|
|
415
|
-
static clone(request: IAppProjectRequest, project: AppProject, opts: IAppProjectRequestCloneOptions = {}): AppProjectRequest {
|
|
416
|
-
const obj = new AppProjectRequest(project, request);
|
|
417
|
-
return obj.clone(opts);
|
|
418
|
-
}
|
|
419
|
-
}
|
|
420
|
-
|
|
421
|
-
export class AppProjectItem {
|
|
422
|
-
/**
|
|
423
|
-
* The kind of the item.
|
|
424
|
-
*/
|
|
425
|
-
kind: typeof AppProjectFolderKind | typeof AppProjectRequestKind | typeof EnvironmentKind = AppProjectRequestKind;
|
|
426
|
-
|
|
427
|
-
/**
|
|
428
|
-
* The identifier of the object in the `definitions` array of the project.
|
|
429
|
-
*/
|
|
430
|
-
key = '';
|
|
431
|
-
|
|
432
|
-
/**
|
|
433
|
-
* A reference to the top level project object.
|
|
434
|
-
*/
|
|
435
|
-
project: AppProject;
|
|
436
|
-
|
|
437
|
-
/**
|
|
438
|
-
* Checks whether the input is a definition of a project item.
|
|
439
|
-
*/
|
|
440
|
-
static isProjectItem(input: unknown): boolean {
|
|
441
|
-
const typed = input as IAppProjectItem;
|
|
442
|
-
if (!input || ![AppProjectFolderKind, AppProjectRequestKind, EnvironmentKind].includes(typed.kind)) {
|
|
443
|
-
return false;
|
|
444
|
-
}
|
|
445
|
-
return true;
|
|
446
|
-
}
|
|
447
|
-
|
|
448
|
-
/**
|
|
449
|
-
* @return An instance that represents a request item
|
|
450
|
-
*/
|
|
451
|
-
static projectRequest(project: AppProject, key: string): AppProjectItem {
|
|
452
|
-
const item = new AppProjectItem(project, {
|
|
453
|
-
kind: AppProjectRequestKind,
|
|
454
|
-
key,
|
|
455
|
-
});
|
|
456
|
-
return item;
|
|
457
|
-
}
|
|
458
|
-
|
|
459
|
-
/**
|
|
460
|
-
* @return An instance that represents a folder item
|
|
461
|
-
*/
|
|
462
|
-
static projectFolder(project: AppProject, key: string): AppProjectItem {
|
|
463
|
-
const item = new AppProjectItem(project, {
|
|
464
|
-
kind: AppProjectFolderKind,
|
|
465
|
-
key,
|
|
466
|
-
});
|
|
467
|
-
return item;
|
|
468
|
-
}
|
|
469
|
-
|
|
470
|
-
/**
|
|
471
|
-
* @return An instance that represents an environment item
|
|
472
|
-
*/
|
|
473
|
-
static projectEnvironment(project: AppProject, key: string): AppProjectItem {
|
|
474
|
-
const item = new AppProjectItem(project, {
|
|
475
|
-
kind: EnvironmentKind,
|
|
476
|
-
key,
|
|
477
|
-
});
|
|
478
|
-
return item;
|
|
479
|
-
}
|
|
480
|
-
|
|
481
|
-
/**
|
|
482
|
-
* @param project The top-most project.
|
|
483
|
-
* @param input The project item definition used to restore the state.
|
|
484
|
-
*/
|
|
485
|
-
constructor(project: AppProject, input: string | IAppProjectItem) {
|
|
486
|
-
this.project = project;
|
|
487
|
-
let init: IAppProjectItem;
|
|
488
|
-
if (typeof input === 'string') {
|
|
489
|
-
if (input === 'http-request') {
|
|
490
|
-
init = {
|
|
491
|
-
kind: AppProjectRequestKind,
|
|
492
|
-
key: '',
|
|
493
|
-
};
|
|
494
|
-
} else if (input === 'folder') {
|
|
495
|
-
init = {
|
|
496
|
-
kind: AppProjectFolderKind,
|
|
497
|
-
key: '',
|
|
498
|
-
};
|
|
499
|
-
} else if (input === 'environment') {
|
|
500
|
-
init = {
|
|
501
|
-
kind: EnvironmentKind,
|
|
502
|
-
key: '',
|
|
503
|
-
};
|
|
504
|
-
} else {
|
|
505
|
-
init = JSON.parse(input);
|
|
506
|
-
}
|
|
507
|
-
} else if (typeof input === 'object') {
|
|
508
|
-
init = input;
|
|
509
|
-
} else {
|
|
510
|
-
throw new Error('Specify the type of the item.');
|
|
511
|
-
}
|
|
512
|
-
this.new(init);
|
|
513
|
-
}
|
|
514
|
-
|
|
515
|
-
/**
|
|
516
|
-
* Creates a new project item clearing anything that is so far defined.
|
|
517
|
-
*
|
|
518
|
-
* Note, this throws an error when the project item is not a project item.
|
|
519
|
-
*/
|
|
520
|
-
new(init: IAppProjectItem): void {
|
|
521
|
-
if (!AppProjectItem.isProjectItem(init)) {
|
|
522
|
-
throw new Error(`Not a project item.`);
|
|
523
|
-
}
|
|
524
|
-
const { kind, key } = init;
|
|
525
|
-
this.kind = kind;
|
|
526
|
-
this.key = key;
|
|
527
|
-
}
|
|
528
|
-
|
|
529
|
-
toJSON(): IAppProjectItem {
|
|
530
|
-
const result: IAppProjectItem = {
|
|
531
|
-
kind: this.kind,
|
|
532
|
-
key: this.key,
|
|
533
|
-
};
|
|
534
|
-
return result;
|
|
535
|
-
}
|
|
536
|
-
|
|
537
|
-
/**
|
|
538
|
-
* @returns The instance of the definition associated with this item.
|
|
539
|
-
*/
|
|
540
|
-
getItem(): AppProjectFolder | AppProjectRequest | Environment | undefined {
|
|
541
|
-
const { project, key, kind } = this;
|
|
542
|
-
const { definitions } = project;
|
|
543
|
-
if (kind === AppProjectRequestKind) {
|
|
544
|
-
return definitions.requests.find(i => i.key === key);
|
|
545
|
-
}
|
|
546
|
-
if (kind === AppProjectFolderKind) {
|
|
547
|
-
return definitions.folders.find(i => i.key === key);
|
|
548
|
-
}
|
|
549
|
-
if (kind === EnvironmentKind) {
|
|
550
|
-
return definitions.environments.find(i => i.key === key);
|
|
551
|
-
}
|
|
552
|
-
return undefined;
|
|
553
|
-
}
|
|
554
|
-
|
|
555
|
-
/**
|
|
556
|
-
* @returns The instance of the ArcProject or a ArcProjectFolder that is a closest parent of this item.
|
|
557
|
-
*/
|
|
558
|
-
getParent(): AppProjectFolder | AppProject | undefined {
|
|
559
|
-
const { project, key } = this;
|
|
560
|
-
return project.findParent(key);
|
|
561
|
-
}
|
|
562
|
-
}
|
|
563
|
-
|
|
564
|
-
export abstract class AppProjectParent {
|
|
565
|
-
/**
|
|
566
|
-
* The auto-generated key for the folder object.
|
|
567
|
-
* For the project root this is the same as the `_id`.
|
|
568
|
-
*/
|
|
569
|
-
kind: typeof AppProjectKind | typeof AppProjectFolderKind;
|
|
570
|
-
|
|
571
|
-
/**
|
|
572
|
-
* The key of the project / folder.
|
|
573
|
-
*/
|
|
574
|
-
key = '';
|
|
575
|
-
|
|
576
|
-
/**
|
|
577
|
-
* The basic information about the project / folder.
|
|
578
|
-
*/
|
|
579
|
-
info: Thing = Thing.fromName('');
|
|
580
|
-
|
|
581
|
-
/**
|
|
582
|
-
* The list of items in the folder.
|
|
583
|
-
* It is an ordered list of requests and folders.
|
|
584
|
-
* The actual definition is kept in the root's `definitions`.
|
|
585
|
-
*/
|
|
586
|
-
items: AppProjectItem[] = [];
|
|
587
|
-
|
|
588
|
-
/**
|
|
589
|
-
* Timestamp when the project was last updated.
|
|
590
|
-
*/
|
|
591
|
-
updated: number = Date.now();
|
|
592
|
-
|
|
593
|
-
/**
|
|
594
|
-
* Timestamp when the project was created.
|
|
595
|
-
*/
|
|
596
|
-
created: number = Date.now();
|
|
597
|
-
|
|
598
|
-
constructor(kind: typeof AppProjectKind | typeof AppProjectFolderKind, input?: string | IAppProjectParent) {
|
|
599
|
-
this.kind = kind;
|
|
600
|
-
|
|
601
|
-
let init: IAppProjectParent;
|
|
602
|
-
if (typeof input === 'string') {
|
|
603
|
-
init = JSON.parse(input);
|
|
604
|
-
} else if (typeof input === 'object') {
|
|
605
|
-
init = input;
|
|
606
|
-
} else {
|
|
607
|
-
const now: number = Date.now();
|
|
608
|
-
init = {
|
|
609
|
-
kind,
|
|
610
|
-
created: now,
|
|
611
|
-
updated: now,
|
|
612
|
-
items: [],
|
|
613
|
-
key: v4(),
|
|
614
|
-
info: Thing.fromName('New folder').toJSON(),
|
|
615
|
-
};
|
|
616
|
-
}
|
|
617
|
-
this.new(init);
|
|
618
|
-
}
|
|
619
|
-
|
|
620
|
-
/**
|
|
621
|
-
* Creates a new project folder clearing anything that is so far defined.
|
|
622
|
-
*
|
|
623
|
-
* Note, this throws an error when the project folder is not a project folder.
|
|
624
|
-
*/
|
|
625
|
-
new(init: IAppProjectParent): void {
|
|
626
|
-
const { key = v4(), created = Date.now(), updated = Date.now(), items, info, kind } = init;
|
|
627
|
-
this.kind = kind;
|
|
628
|
-
this.key = key;
|
|
629
|
-
this.created = created;
|
|
630
|
-
this.updated = updated;
|
|
631
|
-
this.setItems(items);
|
|
632
|
-
if (info) {
|
|
633
|
-
this.info = new Thing(info);
|
|
634
|
-
} else {
|
|
635
|
-
this.info = Thing.fromName('New folder');
|
|
636
|
-
}
|
|
637
|
-
}
|
|
638
|
-
|
|
639
|
-
abstract setItems(items?: IAppProjectItem[]): void;
|
|
640
|
-
|
|
641
|
-
/**
|
|
642
|
-
* Lists items (not the actual definitions!) that are folders.
|
|
643
|
-
*/
|
|
644
|
-
listFolderItems(): AppProjectItem[] {
|
|
645
|
-
const { items = [] } = this;
|
|
646
|
-
return items.filter(i => i.kind === AppProjectFolderKind);
|
|
647
|
-
}
|
|
648
|
-
|
|
649
|
-
/**
|
|
650
|
-
* Lists items (not the actual definitions!) that are requests.
|
|
651
|
-
*/
|
|
652
|
-
listRequestItems(): AppProjectItem[] {
|
|
653
|
-
const { items = [] } = this;
|
|
654
|
-
return items.filter(i => i.kind === AppProjectRequestKind);
|
|
655
|
-
}
|
|
656
|
-
}
|
|
657
|
-
|
|
658
|
-
export class AppProjectFolder extends AppProjectParent {
|
|
659
|
-
|
|
660
|
-
project: AppProject;
|
|
661
|
-
|
|
662
|
-
/**
|
|
663
|
-
* Creates a new ArcProjectFolder object from a name.
|
|
664
|
-
* @param project The top-most project.
|
|
665
|
-
* @param name The name to set.
|
|
666
|
-
*/
|
|
667
|
-
static fromName(project: AppProject, name = 'New folder'): AppProjectFolder {
|
|
668
|
-
const now = Date.now();
|
|
669
|
-
const key = v4();
|
|
670
|
-
const info = Thing.fromName(name);
|
|
671
|
-
const definition = new AppProjectFolder(project, {
|
|
672
|
-
key,
|
|
673
|
-
created: now,
|
|
674
|
-
updated: now,
|
|
675
|
-
items: [],
|
|
676
|
-
kind: AppProjectFolderKind,
|
|
677
|
-
info: info.toJSON(),
|
|
678
|
-
});
|
|
679
|
-
return definition;
|
|
680
|
-
}
|
|
681
|
-
|
|
682
|
-
constructor(project: AppProject, input?: string | IAppProjectParent) {
|
|
683
|
-
super(AppProjectFolderKind, input);
|
|
684
|
-
this.project = project;
|
|
685
|
-
|
|
686
|
-
let init: IAppProjectParent | undefined;
|
|
687
|
-
if (typeof input === 'string') {
|
|
688
|
-
init = JSON.parse(input);
|
|
689
|
-
} else if (typeof input === 'object') {
|
|
690
|
-
init = input;
|
|
691
|
-
}
|
|
692
|
-
if (init) {
|
|
693
|
-
this.key = init.key || v4();
|
|
694
|
-
}
|
|
695
|
-
this.kind = AppProjectFolderKind;
|
|
696
|
-
}
|
|
697
|
-
|
|
698
|
-
toJSON(): IAppProjectParent {
|
|
699
|
-
const result: IAppProjectParent = {
|
|
700
|
-
kind: AppProjectFolderKind,
|
|
701
|
-
info: this.info.toJSON(),
|
|
702
|
-
key: this.key,
|
|
703
|
-
created: this.created,
|
|
704
|
-
updated: this.updated,
|
|
705
|
-
items: [],
|
|
706
|
-
};
|
|
707
|
-
if (Array.isArray(this.items)) {
|
|
708
|
-
result.items = this.items.map(i => i.toJSON());
|
|
709
|
-
}
|
|
710
|
-
return result;
|
|
711
|
-
}
|
|
712
|
-
|
|
713
|
-
setItems(items?: IAppProjectItem[]): void {
|
|
714
|
-
if (Array.isArray(items)) {
|
|
715
|
-
this.items = items.map(i => new AppProjectItem(this.project, i));
|
|
716
|
-
} else {
|
|
717
|
-
this.items = [];
|
|
718
|
-
}
|
|
719
|
-
}
|
|
720
|
-
|
|
721
|
-
/**
|
|
722
|
-
* Appends an instance of a folder to a project.
|
|
723
|
-
*
|
|
724
|
-
* @param folder The folder to add to this project.
|
|
725
|
-
* @returns The added folder.
|
|
726
|
-
*/
|
|
727
|
-
addFolder(folder: AppProjectFolder): AppProjectFolder;
|
|
728
|
-
|
|
729
|
-
/**
|
|
730
|
-
* Appends new folder to a project from a full folder schema.
|
|
731
|
-
* This is primarily used to insert a folder on the client side
|
|
732
|
-
* after a folder was created in the store.
|
|
733
|
-
*
|
|
734
|
-
* @param folder The folder schema to add to this project.
|
|
735
|
-
* @returns The added folder.
|
|
736
|
-
*/
|
|
737
|
-
addFolder(folder: IAppProjectParent): AppProjectFolder;
|
|
738
|
-
|
|
739
|
-
/**
|
|
740
|
-
* Appends a new folder to the project or a sub-folder.
|
|
741
|
-
*
|
|
742
|
-
* @param name The name to set. Optional.
|
|
743
|
-
* @returns The newly inserted folder. If the folder already existed it returns its instance.
|
|
744
|
-
*/
|
|
745
|
-
addFolder(name?: string): AppProjectFolder;
|
|
746
|
-
|
|
747
|
-
/**
|
|
748
|
-
* Appends a new folder to the folder. It updates the project to add the request definition.
|
|
749
|
-
* @param name The name to set. Optional.
|
|
750
|
-
* @returns The key of newly inserted folder.
|
|
751
|
-
*/
|
|
752
|
-
addFolder(name: string | IAppProjectParent | AppProjectFolder | undefined): AppProjectFolder {
|
|
753
|
-
return this.project.addFolder(name as AppProjectFolder, { parent: this.key });
|
|
754
|
-
}
|
|
755
|
-
|
|
756
|
-
/**
|
|
757
|
-
* Adds a request to the project or a sub-folder.
|
|
758
|
-
*
|
|
759
|
-
* @param url The URL of the request.
|
|
760
|
-
* @param opts The request add options.
|
|
761
|
-
* @returns The inserted into the definitions request.
|
|
762
|
-
*/
|
|
763
|
-
addRequest(url: string, opts?: IAppProjectFolderAddOptions): AppProjectRequest;
|
|
764
|
-
|
|
765
|
-
/**
|
|
766
|
-
* Adds a request to the project or a sub-folder.
|
|
767
|
-
*
|
|
768
|
-
* @param request The request to add.
|
|
769
|
-
* @param opts The request add options.
|
|
770
|
-
* @returns The inserted into the definitions request.
|
|
771
|
-
*/
|
|
772
|
-
addRequest(request: IAppProjectRequest | AppProjectRequest, opts?: IAppProjectFolderAddOptions): AppProjectRequest;
|
|
773
|
-
|
|
774
|
-
/**
|
|
775
|
-
* Appends a new request to the folder. It updates the project to add the request definition.
|
|
776
|
-
* @param request The request to append to the folder.
|
|
777
|
-
* @returns The key of newly inserted request.
|
|
778
|
-
*/
|
|
779
|
-
addRequest(request: IAppProjectRequest | AppProjectRequest | string, opts: IAppProjectFolderAddOptions = {}): AppProjectRequest {
|
|
780
|
-
const addOptions = { parent: this.key, ...opts };
|
|
781
|
-
if (typeof request === 'string') {
|
|
782
|
-
return this.project.addRequest(request, addOptions);
|
|
783
|
-
}
|
|
784
|
-
return this.project.addRequest(request, addOptions);
|
|
785
|
-
}
|
|
786
|
-
|
|
787
|
-
/**
|
|
788
|
-
* @returns The instance of the ArcProject or a ArcProjectFolder that is a closes parent of this instance.
|
|
789
|
-
*/
|
|
790
|
-
getParent(): AppProjectFolder | AppProject | undefined {
|
|
791
|
-
const { project, key } = this;
|
|
792
|
-
return project.findParent(key);
|
|
793
|
-
}
|
|
794
|
-
|
|
795
|
-
/**
|
|
796
|
-
* @returns A reference to the parent folder or the top-level HTTP project.
|
|
797
|
-
*/
|
|
798
|
-
getProject(): AppProject {
|
|
799
|
-
return this.project;
|
|
800
|
-
}
|
|
801
|
-
|
|
802
|
-
/**
|
|
803
|
-
* Removes this folder from the project.
|
|
804
|
-
*/
|
|
805
|
-
remove(): void {
|
|
806
|
-
this.project.removeFolder(this.key);
|
|
807
|
-
}
|
|
808
|
-
|
|
809
|
-
/**
|
|
810
|
-
* Makes a copy of this folder.
|
|
811
|
-
* By default it attaches the copied folder to the same parent.
|
|
812
|
-
* It also, by default, copies requests declared in this folder.
|
|
813
|
-
*
|
|
814
|
-
* Use the options dictionary to control these behaviors.
|
|
815
|
-
*
|
|
816
|
-
* @param opts Cloning options
|
|
817
|
-
*/
|
|
818
|
-
clone(opts: IAppProjectFolderCloneOptions = {}): AppProjectFolder {
|
|
819
|
-
const { targetProject = this.project, targetFolder } = opts;
|
|
820
|
-
const copy = new AppProjectFolder(targetProject, this.toJSON());
|
|
821
|
-
copy.key = v4();
|
|
822
|
-
|
|
823
|
-
const extProject = targetProject !== this.project;
|
|
824
|
-
if (extProject) {
|
|
825
|
-
if (targetFolder) {
|
|
826
|
-
const parent = targetProject.findFolder(targetFolder, { keyOnly: true });
|
|
827
|
-
if (!parent) {
|
|
828
|
-
throw new Error(`The target project does not contain the folder ${targetFolder}`);
|
|
829
|
-
}
|
|
830
|
-
parent.addFolder(copy);
|
|
831
|
-
} else {
|
|
832
|
-
targetProject.addFolder(copy);
|
|
833
|
-
}
|
|
834
|
-
} else {
|
|
835
|
-
const parent = targetFolder ? this.project.findFolder(targetFolder, { keyOnly: true }) : this.getParent();
|
|
836
|
-
if (parent) {
|
|
837
|
-
parent.addFolder(copy);
|
|
838
|
-
} else {
|
|
839
|
-
throw new Error(`Unable to locate a parent of the folder.`);
|
|
840
|
-
}
|
|
841
|
-
}
|
|
842
|
-
// removes all items. Depending on the passed option we re-add them next.
|
|
843
|
-
copy.items = [];
|
|
844
|
-
|
|
845
|
-
if (!opts.withoutRequests) {
|
|
846
|
-
this.cloneRequests(copy, this.project);
|
|
847
|
-
}
|
|
848
|
-
if (!opts.withoutFolders) {
|
|
849
|
-
this.cloneSubFolders(copy, this.project, !opts.withoutRequests);
|
|
850
|
-
}
|
|
851
|
-
return copy;
|
|
852
|
-
}
|
|
853
|
-
|
|
854
|
-
/**
|
|
855
|
-
* Clones the current requests to the target folder.
|
|
856
|
-
*
|
|
857
|
-
* @param folder The target folder into which to put the requests. The folder has to have the target project attached to it.
|
|
858
|
-
* @param project The originating project where the definitions are stored
|
|
859
|
-
*/
|
|
860
|
-
protected cloneRequests(folder: AppProjectFolder, project: AppProject): void {
|
|
861
|
-
const requests = this.items.filter(i => i.kind === AppProjectRequestKind);
|
|
862
|
-
requests.forEach(r => {
|
|
863
|
-
const request = project.findRequest(r.key, { keyOnly: true });
|
|
864
|
-
if (!request) {
|
|
865
|
-
// Should we throw an error here?
|
|
866
|
-
// CONS:
|
|
867
|
-
// - It's not really related to the operation. It means there is an inconsistency in the project. That's the role of the project class.
|
|
868
|
-
// - Ignoring this would allow us to make a copy that is error free.
|
|
869
|
-
// - The error may occur in a situation when the user does not expect it (giving the nature of the error)
|
|
870
|
-
// Pros:
|
|
871
|
-
// - There's an inconsistency in the project definition that should be reported back to the UI for the user to inspect
|
|
872
|
-
return;
|
|
873
|
-
}
|
|
874
|
-
const copy = request.clone({ withoutAttach: true });
|
|
875
|
-
copy.project = folder.getProject();
|
|
876
|
-
folder.addRequest(copy);
|
|
877
|
-
});
|
|
878
|
-
}
|
|
879
|
-
|
|
880
|
-
/**
|
|
881
|
-
* Clones the sub-folders to the target folder.
|
|
882
|
-
*
|
|
883
|
-
* @param folder The target folder into which to put the sub-folders. The folder has to have the target project attached to it.
|
|
884
|
-
* @param project The originating project where the definitions are stored
|
|
885
|
-
* @param withRequests Whether to clone requests with the folder.
|
|
886
|
-
*/
|
|
887
|
-
protected cloneSubFolders(folder: AppProjectFolder, project: AppProject, withRequests = true): void {
|
|
888
|
-
const folders = this.items.filter(i => i.kind === AppProjectFolderKind);
|
|
889
|
-
folders.forEach(f => {
|
|
890
|
-
const definition = project.findFolder(f.key, { keyOnly: true });
|
|
891
|
-
if (!definition) {
|
|
892
|
-
return;
|
|
893
|
-
}
|
|
894
|
-
const copy = new AppProjectFolder(folder.getProject(), definition.toJSON());
|
|
895
|
-
copy.key = v4();
|
|
896
|
-
copy.items = [];
|
|
897
|
-
folder.addFolder(copy);
|
|
898
|
-
if (withRequests) {
|
|
899
|
-
definition.cloneRequests(copy, project);
|
|
900
|
-
}
|
|
901
|
-
definition.cloneSubFolders(copy, project, withRequests);
|
|
902
|
-
});
|
|
903
|
-
}
|
|
904
|
-
|
|
905
|
-
/**
|
|
906
|
-
* Lists folders in this folder.
|
|
907
|
-
*/
|
|
908
|
-
listFolders(): AppProjectFolder[] {
|
|
909
|
-
return this.project.listFolders({ folder: this.key });
|
|
910
|
-
}
|
|
911
|
-
|
|
912
|
-
/**
|
|
913
|
-
* Lists requests in this folder.
|
|
914
|
-
*/
|
|
915
|
-
listRequests(): AppProjectRequest[] {
|
|
916
|
-
return this.project.listRequests(this.key);
|
|
917
|
-
}
|
|
918
|
-
|
|
919
|
-
/**
|
|
920
|
-
* Adds a request to the project that has been created for a previous version of ARC.
|
|
921
|
-
*
|
|
922
|
-
* @param legacy The legacy request definition.
|
|
923
|
-
* @returns The created project request.
|
|
924
|
-
*/
|
|
925
|
-
async addLegacyRequest(legacy: ARCSavedRequest | ARCHistoryRequest): Promise<AppProjectRequest> {
|
|
926
|
-
const request = await Request.fromLegacy(legacy);
|
|
927
|
-
const projectRequest = AppProjectRequest.fromRequest(request.toJSON(), this.project);
|
|
928
|
-
return this.addRequest(projectRequest);
|
|
929
|
-
}
|
|
930
|
-
|
|
931
|
-
/**
|
|
932
|
-
* Adds an environment to the project.
|
|
933
|
-
*
|
|
934
|
-
* @param env The definition of the environment to use to create the environment
|
|
935
|
-
* @returns The same or created environment.
|
|
936
|
-
*/
|
|
937
|
-
addEnvironment(env: IEnvironment, opts?: IAppProjectEnvironmentCreateOptions): Environment;
|
|
938
|
-
|
|
939
|
-
/**
|
|
940
|
-
* Adds an environment to the project.
|
|
941
|
-
*
|
|
942
|
-
* @param env The instance of the environment to add
|
|
943
|
-
* @returns The same or created environment.
|
|
944
|
-
*/
|
|
945
|
-
addEnvironment(env: Environment, opts?: IAppProjectEnvironmentCreateOptions): Environment;
|
|
946
|
-
|
|
947
|
-
/**
|
|
948
|
-
* Adds an environment to the project.
|
|
949
|
-
*
|
|
950
|
-
* @param env The name of the environment to create
|
|
951
|
-
* @returns The same or created environment.
|
|
952
|
-
*/
|
|
953
|
-
addEnvironment(env: string, opts?: IAppProjectEnvironmentCreateOptions): Environment;
|
|
954
|
-
|
|
955
|
-
/**
|
|
956
|
-
* Adds an environment to the project.
|
|
957
|
-
* @returns The same or created environment.
|
|
958
|
-
*/
|
|
959
|
-
addEnvironment(env: IEnvironment | Environment | string, opts: IAppProjectEnvironmentCreateOptions = {}): Environment {
|
|
960
|
-
const newOptions: IAppProjectEnvironmentCreateOptions = { ...opts, parent: this.key };
|
|
961
|
-
return this.project.addEnvironment(env as Environment, newOptions);
|
|
962
|
-
}
|
|
963
|
-
|
|
964
|
-
/**
|
|
965
|
-
* @param key The environment key to read.
|
|
966
|
-
*/
|
|
967
|
-
getEnvironment(key: string): Environment | undefined {
|
|
968
|
-
return this.project.getEnvironment(key, { parent: this.key });
|
|
969
|
-
}
|
|
970
|
-
|
|
971
|
-
/**
|
|
972
|
-
* Removes an environment from the folder or a sub-folder.
|
|
973
|
-
*
|
|
974
|
-
* @param key the key of the environment to remove
|
|
975
|
-
* @returns The removed environment, if any.
|
|
976
|
-
*/
|
|
977
|
-
removeEnvironment(key: string): Environment | undefined {
|
|
978
|
-
return this.project.removeEnvironment(key, { parent: this.key });
|
|
979
|
-
}
|
|
980
|
-
|
|
981
|
-
/**
|
|
982
|
-
* This is a link to the `getEnvironments()`. The difference is that on the
|
|
983
|
-
* project level it won't return environments defined with the class initialization.
|
|
984
|
-
*/
|
|
985
|
-
listEnvironments(): Environment[] {
|
|
986
|
-
return this.project.listEnvironments({ parent: this.key });
|
|
987
|
-
}
|
|
988
|
-
|
|
989
|
-
/**
|
|
990
|
-
* @returns The list of environments defined in this folder
|
|
991
|
-
*/
|
|
992
|
-
getEnvironments(): Environment[] {
|
|
993
|
-
return this.project.getEnvironments({ parent: this.key });
|
|
994
|
-
}
|
|
995
|
-
}
|
|
996
|
-
|
|
997
|
-
/**
|
|
998
|
-
* An app project is similar to the HttpProject but stored for a single application
|
|
999
|
-
* and has no sharing options. The AppProject can be upgraded to an HttpProject.
|
|
1000
|
-
*/
|
|
1001
|
-
export class AppProject extends AppProjectParent {
|
|
1002
|
-
/**
|
|
1003
|
-
* Timestamp when the project was last updated.
|
|
1004
|
-
*/
|
|
1005
|
-
override updated: number = Date.now();
|
|
1006
|
-
|
|
1007
|
-
/**
|
|
1008
|
-
* Timestamp when the project was created.
|
|
1009
|
-
*/
|
|
1010
|
-
override created: number = Date.now();
|
|
1011
|
-
|
|
1012
|
-
definitions: AppProjectDefinitions;
|
|
1013
|
-
|
|
1014
|
-
/**
|
|
1015
|
-
* Creates a new ARC project from a name.
|
|
1016
|
-
* @param name The name to set.
|
|
1017
|
-
*/
|
|
1018
|
-
static fromName(name: string): AppProject {
|
|
1019
|
-
const project = new AppProject();
|
|
1020
|
-
const info = Thing.fromName(name);
|
|
1021
|
-
project.info = info;
|
|
1022
|
-
return project;
|
|
1023
|
-
}
|
|
1024
|
-
|
|
1025
|
-
/**
|
|
1026
|
-
* Creates an HTTP project instance from ARC's legacy project definition.
|
|
1027
|
-
*
|
|
1028
|
-
* Note, the `requests` should be processed and the payload restored to it's original value.
|
|
1029
|
-
*/
|
|
1030
|
-
static async fromLegacyProject(project: ARCProject, requests: ARCSavedRequest[]): Promise<AppProject> {
|
|
1031
|
-
const { name = 'Unnamed project', description, requests: ids } = project;
|
|
1032
|
-
const result = AppProject.fromName(name);
|
|
1033
|
-
if (project._id) {
|
|
1034
|
-
result.key = project._id;
|
|
1035
|
-
}
|
|
1036
|
-
if (description) {
|
|
1037
|
-
result.info.description = description;
|
|
1038
|
-
}
|
|
1039
|
-
if (Array.isArray(ids) && ids.length) {
|
|
1040
|
-
const promises = ids.map(async (id) => {
|
|
1041
|
-
const old = requests.find((item) => item._id === id);
|
|
1042
|
-
if (!old) {
|
|
1043
|
-
return;
|
|
1044
|
-
}
|
|
1045
|
-
const request = await Request.fromLegacy(old);
|
|
1046
|
-
const projectRequest = AppProjectRequest.fromRequest(request.toJSON(), result);
|
|
1047
|
-
if (old._id) {
|
|
1048
|
-
projectRequest.key = old._id;
|
|
1049
|
-
}
|
|
1050
|
-
result.addRequest(projectRequest);
|
|
1051
|
-
});
|
|
1052
|
-
await Promise.allSettled(promises);
|
|
1053
|
-
}
|
|
1054
|
-
return result;
|
|
1055
|
-
}
|
|
1056
|
-
|
|
1057
|
-
constructor(input?: string | IAppProject) {
|
|
1058
|
-
super(AppProjectKind);
|
|
1059
|
-
this.definitions = {
|
|
1060
|
-
folders: [],
|
|
1061
|
-
requests: [],
|
|
1062
|
-
environments: [],
|
|
1063
|
-
certificates: [],
|
|
1064
|
-
};
|
|
1065
|
-
let init: IAppProject;
|
|
1066
|
-
if (typeof input === 'string') {
|
|
1067
|
-
init = JSON.parse(input);
|
|
1068
|
-
} else if (typeof input === 'object') {
|
|
1069
|
-
init = input;
|
|
1070
|
-
if (!init.kind) {
|
|
1071
|
-
init.kind = AppProjectKind;
|
|
1072
|
-
}
|
|
1073
|
-
} else {
|
|
1074
|
-
const now = Date.now();
|
|
1075
|
-
init = {
|
|
1076
|
-
kind: AppProjectKind,
|
|
1077
|
-
key: v4(),
|
|
1078
|
-
definitions: {},
|
|
1079
|
-
items: [],
|
|
1080
|
-
info: Thing.fromName('').toJSON(),
|
|
1081
|
-
created: now,
|
|
1082
|
-
updated: now,
|
|
1083
|
-
}
|
|
1084
|
-
}
|
|
1085
|
-
this.new(init);
|
|
1086
|
-
}
|
|
1087
|
-
|
|
1088
|
-
override new(init: IAppProject): void {
|
|
1089
|
-
if (!init || !init.items) {
|
|
1090
|
-
throw new Error(`Not a project.`);
|
|
1091
|
-
}
|
|
1092
|
-
const { key = v4(), definitions = {}, items, info, created = Date.now(), updated = Date.now() } = init;
|
|
1093
|
-
this.key = key;
|
|
1094
|
-
this.created = created;
|
|
1095
|
-
this.updated = updated;
|
|
1096
|
-
if (info) {
|
|
1097
|
-
this.info = new Thing(info);
|
|
1098
|
-
} else {
|
|
1099
|
-
this.info = Thing.fromName('');
|
|
1100
|
-
}
|
|
1101
|
-
this.setItems(items);
|
|
1102
|
-
this.definitions = {
|
|
1103
|
-
folders: [],
|
|
1104
|
-
requests: [],
|
|
1105
|
-
environments: [],
|
|
1106
|
-
certificates: [],
|
|
1107
|
-
};
|
|
1108
|
-
if (Array.isArray(definitions.requests)) {
|
|
1109
|
-
this.definitions.requests = definitions.requests.map(i => {
|
|
1110
|
-
const instance = new AppProjectRequest(this, i);
|
|
1111
|
-
return instance;
|
|
1112
|
-
});
|
|
1113
|
-
}
|
|
1114
|
-
if (Array.isArray(definitions.folders)) {
|
|
1115
|
-
this.definitions.folders = definitions.folders.map(i => {
|
|
1116
|
-
const instance = new AppProjectFolder(this, i);
|
|
1117
|
-
return instance;
|
|
1118
|
-
});
|
|
1119
|
-
}
|
|
1120
|
-
if (Array.isArray(definitions.environments)) {
|
|
1121
|
-
this.definitions.environments = definitions.environments.map(i => new Environment(i));
|
|
1122
|
-
}
|
|
1123
|
-
if (Array.isArray(definitions.certificates)) {
|
|
1124
|
-
this.definitions.certificates = definitions.certificates.map(i => new Certificate(i));
|
|
1125
|
-
}
|
|
1126
|
-
}
|
|
1127
|
-
|
|
1128
|
-
toJSON(): IAppProject {
|
|
1129
|
-
const result: IAppProject = {
|
|
1130
|
-
kind: AppProjectKind,
|
|
1131
|
-
key: this.key,
|
|
1132
|
-
definitions: {},
|
|
1133
|
-
items: [],
|
|
1134
|
-
info: this.info.toJSON(),
|
|
1135
|
-
created: this.created,
|
|
1136
|
-
updated: this.updated,
|
|
1137
|
-
};
|
|
1138
|
-
if (Array.isArray(this.definitions.requests) && this.definitions.requests.length) {
|
|
1139
|
-
result.definitions.requests = this.definitions.requests.map(i => i.toJSON());
|
|
1140
|
-
}
|
|
1141
|
-
if (Array.isArray(this.definitions.folders) && this.definitions.folders.length) {
|
|
1142
|
-
result.definitions.folders = this.definitions.folders.map(i => i.toJSON());
|
|
1143
|
-
}
|
|
1144
|
-
if (Array.isArray(this.definitions.environments) && this.definitions.environments.length) {
|
|
1145
|
-
result.definitions.environments = this.definitions.environments.map(i => i.toJSON());
|
|
1146
|
-
}
|
|
1147
|
-
if (Array.isArray(this.definitions.certificates) && this.definitions.certificates.length) {
|
|
1148
|
-
result.definitions.certificates = this.definitions.certificates.map(i => i.toJSON());
|
|
1149
|
-
}
|
|
1150
|
-
if (Array.isArray(this.items) && this.items.length) {
|
|
1151
|
-
result.items = this.items.map(i => i.toJSON());
|
|
1152
|
-
}
|
|
1153
|
-
return result;
|
|
1154
|
-
}
|
|
1155
|
-
|
|
1156
|
-
setItems(items?: IAppProjectItem[]): void {
|
|
1157
|
-
if (Array.isArray(items)) {
|
|
1158
|
-
this.items = items.map(i => new AppProjectItem(this, i));
|
|
1159
|
-
} else {
|
|
1160
|
-
this.items = [];
|
|
1161
|
-
}
|
|
1162
|
-
}
|
|
1163
|
-
|
|
1164
|
-
/**
|
|
1165
|
-
* Finds a parent of a definition.
|
|
1166
|
-
*
|
|
1167
|
-
* @param key The key of the definition.
|
|
1168
|
-
* @returns The parent or undefine when not found.
|
|
1169
|
-
*/
|
|
1170
|
-
findParent(key: string): AppProjectFolder | AppProject | undefined {
|
|
1171
|
-
const { definitions, items = [] } = this;
|
|
1172
|
-
const projectItemsIndex = items.findIndex(i => i.key === key);
|
|
1173
|
-
if (projectItemsIndex > -1) {
|
|
1174
|
-
return this;
|
|
1175
|
-
}
|
|
1176
|
-
const definition = definitions.folders.find(i => i.items.some(item => item.key === key));
|
|
1177
|
-
if (definition) {
|
|
1178
|
-
return definition;
|
|
1179
|
-
}
|
|
1180
|
-
return undefined;
|
|
1181
|
-
}
|
|
1182
|
-
|
|
1183
|
-
/**
|
|
1184
|
-
* Appends an instance of a folder to a project.
|
|
1185
|
-
*
|
|
1186
|
-
* @param folder The folder to add to this project.
|
|
1187
|
-
* @param opts Optional folder add options.
|
|
1188
|
-
* @returns The added folder.
|
|
1189
|
-
*/
|
|
1190
|
-
addFolder(folder: AppProjectFolder, opts?: IAppProjectFolderCreateOptions): AppProjectFolder;
|
|
1191
|
-
|
|
1192
|
-
/**
|
|
1193
|
-
* Appends new folder to a project from a full folder schema.
|
|
1194
|
-
* This is primarily used to insert a folder on the client side
|
|
1195
|
-
* after a folder was created in the store.
|
|
1196
|
-
*
|
|
1197
|
-
* @param folder The folder schema to add to this project.
|
|
1198
|
-
* @param opts Optional folder add options.
|
|
1199
|
-
* @returns The added folder.
|
|
1200
|
-
*/
|
|
1201
|
-
addFolder(folder: IAppProjectParent, opts?: IAppProjectFolderCreateOptions): AppProjectFolder;
|
|
1202
|
-
|
|
1203
|
-
/**
|
|
1204
|
-
* Appends a new folder to the project or a sub-folder.
|
|
1205
|
-
*
|
|
1206
|
-
* @param name The name to set. Optional.
|
|
1207
|
-
* @param opts Folder create options.
|
|
1208
|
-
* @returns The newly inserted folder. If the folder already existed it returns its instance.
|
|
1209
|
-
*/
|
|
1210
|
-
addFolder(name?: string, opts?: IAppProjectFolderCreateOptions): AppProjectFolder;
|
|
1211
|
-
|
|
1212
|
-
/**
|
|
1213
|
-
* Appends a new folder to the project or a sub-folder.
|
|
1214
|
-
*
|
|
1215
|
-
* Passing the folder schema as the fist argument is primarily used to insert a folder on the client side
|
|
1216
|
-
* after a folder was created in the store.
|
|
1217
|
-
*
|
|
1218
|
-
* @param init The name or a folder schema. When not set a default name is assumed.
|
|
1219
|
-
* @param opts Folder create options.
|
|
1220
|
-
* @returns The newly inserted folder. If the folder already existed it returns its instance.
|
|
1221
|
-
*/
|
|
1222
|
-
addFolder(init: string | IAppProjectParent | AppProjectFolder = 'New Folder', opts: IAppProjectFolderCreateOptions = {}): AppProjectFolder {
|
|
1223
|
-
if (!Array.isArray(this.items)) {
|
|
1224
|
-
this.items = [];
|
|
1225
|
-
}
|
|
1226
|
-
if (!Array.isArray(this.definitions.folders)) {
|
|
1227
|
-
this.definitions.folders = [];
|
|
1228
|
-
}
|
|
1229
|
-
const { skipExisting, parent } = opts;
|
|
1230
|
-
let root: AppProjectFolder | AppProject;
|
|
1231
|
-
if (parent) {
|
|
1232
|
-
const rootCandidate = this.findFolder(parent);
|
|
1233
|
-
if (!rootCandidate) {
|
|
1234
|
-
throw new Error(`Unable to find the parent folder ${parent}`);
|
|
1235
|
-
}
|
|
1236
|
-
root = rootCandidate;
|
|
1237
|
-
} else {
|
|
1238
|
-
root = this;
|
|
1239
|
-
}
|
|
1240
|
-
let definition: AppProjectFolder;
|
|
1241
|
-
if (typeof init === 'string') {
|
|
1242
|
-
definition = AppProjectFolder.fromName(this, init);
|
|
1243
|
-
} else if (init instanceof AppProjectFolder) {
|
|
1244
|
-
definition = init;
|
|
1245
|
-
} else {
|
|
1246
|
-
definition = new AppProjectFolder(this, init);
|
|
1247
|
-
}
|
|
1248
|
-
if (skipExisting) {
|
|
1249
|
-
const folders = root.listFolderItems();
|
|
1250
|
-
for (const item of folders) {
|
|
1251
|
-
const existing = this.findFolder(item.key, { keyOnly: true });
|
|
1252
|
-
if (existing && existing.info.name === definition.info.name) {
|
|
1253
|
-
return existing;
|
|
1254
|
-
}
|
|
1255
|
-
}
|
|
1256
|
-
}
|
|
1257
|
-
|
|
1258
|
-
this.definitions.folders.push(definition);
|
|
1259
|
-
const item = AppProjectItem.projectFolder(this, definition.key);
|
|
1260
|
-
if (!Array.isArray(root.items)) {
|
|
1261
|
-
root.items = [];
|
|
1262
|
-
}
|
|
1263
|
-
if (typeof opts.index === 'number') {
|
|
1264
|
-
root.items.splice(opts.index, 0, item);
|
|
1265
|
-
} else {
|
|
1266
|
-
root.items.push(item);
|
|
1267
|
-
}
|
|
1268
|
-
return definition;
|
|
1269
|
-
}
|
|
1270
|
-
|
|
1271
|
-
/**
|
|
1272
|
-
* Searches for a folder in the structure.
|
|
1273
|
-
*
|
|
1274
|
-
* @param nameOrKey The name or the key of the folder.
|
|
1275
|
-
* @param opts Optional search options.
|
|
1276
|
-
* @returns Found project folder or undefined.
|
|
1277
|
-
*/
|
|
1278
|
-
findFolder(nameOrKey: string, opts: IAppProjectFolderSearchOptions = {}): AppProjectFolder | undefined {
|
|
1279
|
-
const { definitions } = this;
|
|
1280
|
-
const item = definitions.folders.find((i) => {
|
|
1281
|
-
if (i.kind !== AppProjectFolderKind) {
|
|
1282
|
-
return false;
|
|
1283
|
-
}
|
|
1284
|
-
const folder = (i as AppProjectFolder);
|
|
1285
|
-
if (folder.key === nameOrKey) {
|
|
1286
|
-
return true;
|
|
1287
|
-
}
|
|
1288
|
-
if (opts.keyOnly) {
|
|
1289
|
-
return false;
|
|
1290
|
-
}
|
|
1291
|
-
return !!folder.info && folder.info.name === nameOrKey;
|
|
1292
|
-
});
|
|
1293
|
-
if (item) {
|
|
1294
|
-
return item as AppProjectFolder;
|
|
1295
|
-
}
|
|
1296
|
-
return undefined;
|
|
1297
|
-
}
|
|
1298
|
-
|
|
1299
|
-
/**
|
|
1300
|
-
* Removes a folder from the project.
|
|
1301
|
-
* @param key The folder key. It ignores the name when searching to the folder to avoid ambiguity.
|
|
1302
|
-
* @param opts Folder remove options.
|
|
1303
|
-
* @returns The removed folder definition or undefined when not removed.
|
|
1304
|
-
*/
|
|
1305
|
-
removeFolder(key: string, opts: IAppProjectFolderDeleteOptions = {}): AppProjectFolder | undefined {
|
|
1306
|
-
const { definitions } = this;
|
|
1307
|
-
const folder = this.findFolder(key, { keyOnly: true });
|
|
1308
|
-
if (!folder) {
|
|
1309
|
-
if (opts.safe) {
|
|
1310
|
-
return undefined;
|
|
1311
|
-
}
|
|
1312
|
-
throw new Error(`Unable to find the folder ${key}`);
|
|
1313
|
-
}
|
|
1314
|
-
const parent = this.findParent(key);
|
|
1315
|
-
if (!parent) {
|
|
1316
|
-
if (opts.safe) {
|
|
1317
|
-
return undefined;
|
|
1318
|
-
}
|
|
1319
|
-
throw new Error(`Unable to find a parent of the folder ${key}`);
|
|
1320
|
-
}
|
|
1321
|
-
|
|
1322
|
-
const requests = folder.listRequests();
|
|
1323
|
-
requests.forEach(r => r.remove());
|
|
1324
|
-
const folders = folder.listFolders();
|
|
1325
|
-
folders.forEach(f => f.remove());
|
|
1326
|
-
|
|
1327
|
-
const itemIndex = parent.items.findIndex(i => i.key === key);
|
|
1328
|
-
const definitionIndex = definitions.folders.findIndex(i => i.key === key);
|
|
1329
|
-
definitions.folders.splice(definitionIndex, 1);
|
|
1330
|
-
if (itemIndex >= 0) {
|
|
1331
|
-
parent.items.splice(itemIndex, 1);
|
|
1332
|
-
}
|
|
1333
|
-
return folder;
|
|
1334
|
-
}
|
|
1335
|
-
|
|
1336
|
-
/**
|
|
1337
|
-
* Moves a folder between folders and the project or between items inside a folder or a project
|
|
1338
|
-
*
|
|
1339
|
-
* Note, when the `parent` option is not specified it moved the folder to the project's root.
|
|
1340
|
-
*
|
|
1341
|
-
* @param key The key of the request to move.
|
|
1342
|
-
* @param opts The moving options.
|
|
1343
|
-
*/
|
|
1344
|
-
moveFolder(key: string, opts: IAppProjectProjectMoveOptions = {}): void {
|
|
1345
|
-
const { index, parent } = opts;
|
|
1346
|
-
const movedFolder = this.findFolder(key);
|
|
1347
|
-
if (!movedFolder) {
|
|
1348
|
-
throw new Error(`Unable to locate the folder ${key}`);
|
|
1349
|
-
}
|
|
1350
|
-
const parentFolder = this.findParent(key);
|
|
1351
|
-
if (!parentFolder) {
|
|
1352
|
-
throw new Error(`Unable to locate a parent of the folder ${key}`);
|
|
1353
|
-
}
|
|
1354
|
-
if (parent) {
|
|
1355
|
-
// check if moving a folder into another folder that is a child of the moved folder.
|
|
1356
|
-
if (this.hasChild(parent, key)) {
|
|
1357
|
-
throw new RangeError(`Unable to move a folder to its child.`);
|
|
1358
|
-
}
|
|
1359
|
-
}
|
|
1360
|
-
const target = parent ? this.findFolder(parent) : this;
|
|
1361
|
-
if (!target) {
|
|
1362
|
-
throw new Error(`Unable to locate the new parent folder ${parent}`);
|
|
1363
|
-
}
|
|
1364
|
-
const hasIndex = typeof index === 'number';
|
|
1365
|
-
if (hasIndex) {
|
|
1366
|
-
// comparing to the `.length` and not `.length - 1` in case we are adding at the end.
|
|
1367
|
-
const maxIndex = Math.max(target.items.length, 0);
|
|
1368
|
-
if (index > maxIndex) {
|
|
1369
|
-
throw new RangeError(`Index out of bounds. Maximum index is ${maxIndex}.`);
|
|
1370
|
-
}
|
|
1371
|
-
}
|
|
1372
|
-
|
|
1373
|
-
const itemIndex = parentFolder.items.findIndex(i => i.key === key);
|
|
1374
|
-
const item = parentFolder.items.splice(itemIndex, 1)[0];
|
|
1375
|
-
|
|
1376
|
-
if (hasIndex && target.items.length > index) {
|
|
1377
|
-
target.items.splice(index, 0, item);
|
|
1378
|
-
} else {
|
|
1379
|
-
target.items.push(item);
|
|
1380
|
-
}
|
|
1381
|
-
}
|
|
1382
|
-
|
|
1383
|
-
/**
|
|
1384
|
-
* Checks whether a folder has a child (anywhere down the structure).
|
|
1385
|
-
*
|
|
1386
|
-
* @param child The **key** of the child.
|
|
1387
|
-
* @param folder The **key** of the folder. When not set it searches from the project root.
|
|
1388
|
-
* @returns True when the child is located somewhere down the structure.
|
|
1389
|
-
*/
|
|
1390
|
-
hasChild(child: string, folder?: string): boolean {
|
|
1391
|
-
const target = folder ? this.findFolder(folder) : this;
|
|
1392
|
-
if (!target) {
|
|
1393
|
-
throw new Error(`Unable to locate the folder ${folder}`);
|
|
1394
|
-
}
|
|
1395
|
-
const { items = [] } = target;
|
|
1396
|
-
for (const item of items) {
|
|
1397
|
-
if (item.key === child) {
|
|
1398
|
-
return true;
|
|
1399
|
-
}
|
|
1400
|
-
if (item.kind === AppProjectFolderKind) {
|
|
1401
|
-
const hasChild = this.hasChild(child, item.key);
|
|
1402
|
-
if (hasChild) {
|
|
1403
|
-
return true;
|
|
1404
|
-
}
|
|
1405
|
-
}
|
|
1406
|
-
}
|
|
1407
|
-
return false;
|
|
1408
|
-
}
|
|
1409
|
-
|
|
1410
|
-
/**
|
|
1411
|
-
* Adds a request to the project or a sub-folder.
|
|
1412
|
-
*
|
|
1413
|
-
* @param url The URL of the request.
|
|
1414
|
-
* @param opts The request add options.
|
|
1415
|
-
* @returns The inserted into the definitions request.
|
|
1416
|
-
*/
|
|
1417
|
-
addRequest(url: string, opts?: IAppProjectRequestAddOptions): AppProjectRequest;
|
|
1418
|
-
|
|
1419
|
-
/**
|
|
1420
|
-
* Adds a request to the project or a sub-folder.
|
|
1421
|
-
*
|
|
1422
|
-
* @param request The request to add.
|
|
1423
|
-
* @param opts The request add options.
|
|
1424
|
-
* @returns The inserted into the definitions request.
|
|
1425
|
-
*/
|
|
1426
|
-
addRequest(request: IAppProjectRequest | AppProjectRequest, opts?: IAppProjectRequestAddOptions): AppProjectRequest;
|
|
1427
|
-
|
|
1428
|
-
/**
|
|
1429
|
-
* Adds a request to the project or a sub-folder.
|
|
1430
|
-
* @param request The request to add.
|
|
1431
|
-
* @param opts Thew request add options.
|
|
1432
|
-
* @returns The inserted into the definitions request.
|
|
1433
|
-
*/
|
|
1434
|
-
addRequest(request: IAppProjectRequest | AppProjectRequest | string, opts: IAppProjectRequestAddOptions = {}): AppProjectRequest {
|
|
1435
|
-
if (!Array.isArray(this.definitions.requests)) {
|
|
1436
|
-
this.definitions.requests = [];
|
|
1437
|
-
}
|
|
1438
|
-
|
|
1439
|
-
// the request can be already added to the project as the same method is used to refresh a request after
|
|
1440
|
-
// a store update. From the system perspective it is the same event.
|
|
1441
|
-
|
|
1442
|
-
if (typeof request === 'object' && request.key) {
|
|
1443
|
-
const existing = this.definitions.requests.find(i => i.key === request.key);
|
|
1444
|
-
if (existing) {
|
|
1445
|
-
existing.new(request as IAppProjectRequest);
|
|
1446
|
-
return existing;
|
|
1447
|
-
}
|
|
1448
|
-
}
|
|
1449
|
-
|
|
1450
|
-
// if we got here, it means that we are adding a new request object to the project.
|
|
1451
|
-
|
|
1452
|
-
let finalRequest;
|
|
1453
|
-
if (typeof request === 'string') {
|
|
1454
|
-
finalRequest = AppProjectRequest.fromUrl(request, this);
|
|
1455
|
-
} else if (request instanceof AppProjectRequest) {
|
|
1456
|
-
finalRequest = request;
|
|
1457
|
-
finalRequest.project = this;
|
|
1458
|
-
} else {
|
|
1459
|
-
finalRequest = new AppProjectRequest(this, request);
|
|
1460
|
-
}
|
|
1461
|
-
if (!finalRequest.key) {
|
|
1462
|
-
finalRequest.key = v4();
|
|
1463
|
-
}
|
|
1464
|
-
|
|
1465
|
-
let root: AppProjectFolder | AppProject;
|
|
1466
|
-
if (opts.parent) {
|
|
1467
|
-
const rootCandidate = this.findFolder(opts.parent);
|
|
1468
|
-
if (!rootCandidate) {
|
|
1469
|
-
throw new Error(`Unable to find the parent folder ${opts.parent}.`);
|
|
1470
|
-
}
|
|
1471
|
-
root = rootCandidate;
|
|
1472
|
-
} else {
|
|
1473
|
-
root = this;
|
|
1474
|
-
}
|
|
1475
|
-
|
|
1476
|
-
if (!Array.isArray(root.items)) {
|
|
1477
|
-
root.items = [];
|
|
1478
|
-
}
|
|
1479
|
-
|
|
1480
|
-
if (typeof opts.index === 'number') {
|
|
1481
|
-
const maxIndex = Math.max(root.items.length - 1, 0);
|
|
1482
|
-
if (opts.index > maxIndex) {
|
|
1483
|
-
throw new RangeError(`Index out of bounds. Maximum index is ${maxIndex}.`);
|
|
1484
|
-
}
|
|
1485
|
-
}
|
|
1486
|
-
|
|
1487
|
-
this.definitions.requests.push(finalRequest);
|
|
1488
|
-
const item = AppProjectItem.projectRequest(this, finalRequest.key);
|
|
1489
|
-
|
|
1490
|
-
if (typeof opts.index === 'number') {
|
|
1491
|
-
root.items.splice(opts.index, 0, item);
|
|
1492
|
-
} else {
|
|
1493
|
-
root.items.push(item);
|
|
1494
|
-
}
|
|
1495
|
-
return finalRequest;
|
|
1496
|
-
}
|
|
1497
|
-
|
|
1498
|
-
/**
|
|
1499
|
-
* Adds a request to the project that has been created for a previous version of ARC.
|
|
1500
|
-
*
|
|
1501
|
-
* @param legacy The legacy request definition.
|
|
1502
|
-
* @returns The created project request.
|
|
1503
|
-
*/
|
|
1504
|
-
async addLegacyRequest(legacy: ARCSavedRequest | ARCHistoryRequest): Promise<AppProjectRequest> {
|
|
1505
|
-
const request = await Request.fromLegacy(legacy);
|
|
1506
|
-
const projectRequest = AppProjectRequest.fromRequest(request.toJSON(), this);
|
|
1507
|
-
return this.addRequest(projectRequest);
|
|
1508
|
-
}
|
|
1509
|
-
|
|
1510
|
-
/**
|
|
1511
|
-
* Searches for a request in the project.
|
|
1512
|
-
*
|
|
1513
|
-
* @param nameOrKey The name or the key of the request.
|
|
1514
|
-
* @param opts Optional search options.
|
|
1515
|
-
* @returns Found project request or undefined.
|
|
1516
|
-
*/
|
|
1517
|
-
findRequest(nameOrKey: string, opts: IAppProjectRequestSearchOptions = {}): AppProjectRequest | undefined {
|
|
1518
|
-
const { definitions } = this;
|
|
1519
|
-
const item = definitions.requests.find((request) => {
|
|
1520
|
-
if (request.key === nameOrKey) {
|
|
1521
|
-
return true;
|
|
1522
|
-
}
|
|
1523
|
-
if (opts.keyOnly) {
|
|
1524
|
-
return false;
|
|
1525
|
-
}
|
|
1526
|
-
return !!request.info && request.info.name === nameOrKey;
|
|
1527
|
-
});
|
|
1528
|
-
if (item) {
|
|
1529
|
-
return item as AppProjectRequest;
|
|
1530
|
-
}
|
|
1531
|
-
return undefined;
|
|
1532
|
-
}
|
|
1533
|
-
|
|
1534
|
-
/**
|
|
1535
|
-
* Removes a request from the project.
|
|
1536
|
-
*
|
|
1537
|
-
* @param key The request key. It ignores the name when searching to the request to avoid ambiguity.
|
|
1538
|
-
* @param opts Request remove options.
|
|
1539
|
-
* @returns The removed request definition or undefined when not removed.
|
|
1540
|
-
*/
|
|
1541
|
-
removeRequest(key: string, opts: IAppProjectRequestDeleteOptions = {}): AppProjectRequest | undefined {
|
|
1542
|
-
const { definitions } = this;
|
|
1543
|
-
const request = this.findRequest(key, { keyOnly: true });
|
|
1544
|
-
if (!request) {
|
|
1545
|
-
if (opts.safe) {
|
|
1546
|
-
return undefined;
|
|
1547
|
-
}
|
|
1548
|
-
throw new Error(`Unable to find the request ${key}`);
|
|
1549
|
-
}
|
|
1550
|
-
const parent = this.findParent(key);
|
|
1551
|
-
if (!parent) {
|
|
1552
|
-
if (opts.safe) {
|
|
1553
|
-
return undefined;
|
|
1554
|
-
}
|
|
1555
|
-
throw new Error(`Unable to find a parent of the request ${key}`);
|
|
1556
|
-
}
|
|
1557
|
-
const itemIndex = parent.items.findIndex(i => i.key === key);
|
|
1558
|
-
const definitionIndex = definitions.requests.findIndex(i => i.key === key);
|
|
1559
|
-
definitions.requests.splice(definitionIndex, 1);
|
|
1560
|
-
if (itemIndex >= 0) {
|
|
1561
|
-
parent.items.splice(itemIndex, 1);
|
|
1562
|
-
}
|
|
1563
|
-
return request;
|
|
1564
|
-
}
|
|
1565
|
-
|
|
1566
|
-
/**
|
|
1567
|
-
* Moves a request between folders and the project or between items inside a folder or a project.
|
|
1568
|
-
*
|
|
1569
|
-
* Note, when the `parent` option is not specified it moved the request to the project's root.
|
|
1570
|
-
*
|
|
1571
|
-
* @param key The key of the request to move.
|
|
1572
|
-
* @param opts The moving options.
|
|
1573
|
-
*/
|
|
1574
|
-
moveRequest(key: string, opts: IAppProjectProjectMoveOptions = {}): void {
|
|
1575
|
-
const { index, parent } = opts;
|
|
1576
|
-
const request = this.findRequest(key);
|
|
1577
|
-
if (!request) {
|
|
1578
|
-
throw new Error(`Unable to locate the request ${key}`);
|
|
1579
|
-
}
|
|
1580
|
-
const parentFolder = this.findParent(key);
|
|
1581
|
-
if (!parentFolder) {
|
|
1582
|
-
throw new Error(`Unable to locate a parent of the request ${key}`);
|
|
1583
|
-
}
|
|
1584
|
-
const target = parent ? this.findFolder(parent) : this;
|
|
1585
|
-
if (!target) {
|
|
1586
|
-
throw new Error(`Unable to locate the new parent folder ${parent}`);
|
|
1587
|
-
}
|
|
1588
|
-
const hasIndex = typeof index === 'number';
|
|
1589
|
-
if (hasIndex) {
|
|
1590
|
-
// comparing to the `.length` and not `.length - 1` in case we are adding at the end.
|
|
1591
|
-
const maxIndex = Math.max(target.items.length, 0);
|
|
1592
|
-
if (index > maxIndex) {
|
|
1593
|
-
throw new RangeError(`Index out of bounds. Maximum index is ${maxIndex}.`);
|
|
1594
|
-
}
|
|
1595
|
-
}
|
|
1596
|
-
|
|
1597
|
-
const itemIndex = parentFolder.items.findIndex(i => i.key === key);
|
|
1598
|
-
const item = parentFolder.items.splice(itemIndex, 1)[0];
|
|
1599
|
-
|
|
1600
|
-
if (hasIndex && target.items.length > index) {
|
|
1601
|
-
target.items.splice(index, 0, item);
|
|
1602
|
-
} else {
|
|
1603
|
-
target.items.push(item);
|
|
1604
|
-
}
|
|
1605
|
-
}
|
|
1606
|
-
|
|
1607
|
-
/**
|
|
1608
|
-
* Lists items (not the actual definitions!) that are folders.
|
|
1609
|
-
*/
|
|
1610
|
-
override listFolderItems(): AppProjectItem[] {
|
|
1611
|
-
const { items = [] } = this;
|
|
1612
|
-
return items.filter(i => i.kind === AppProjectFolderKind);
|
|
1613
|
-
}
|
|
1614
|
-
|
|
1615
|
-
/**
|
|
1616
|
-
* Lists items (not the actual definitions!) that are requests.
|
|
1617
|
-
*/
|
|
1618
|
-
override listRequestItems(): AppProjectItem[] {
|
|
1619
|
-
const { items = [] } = this;
|
|
1620
|
-
return items.filter(i => i.kind === AppProjectRequestKind);
|
|
1621
|
-
}
|
|
1622
|
-
|
|
1623
|
-
/**
|
|
1624
|
-
* Lists folders from the project or a sub-folder.
|
|
1625
|
-
* @param opts Folder listing options.
|
|
1626
|
-
*/
|
|
1627
|
-
listFolders(opts: IAppProjectFolderListOptions = {}): AppProjectFolder[] {
|
|
1628
|
-
let root;
|
|
1629
|
-
if (opts.folder) {
|
|
1630
|
-
const parent = this.findFolder(opts.folder);
|
|
1631
|
-
if (!parent) {
|
|
1632
|
-
throw new Error(`Unable to find the folder ${opts.folder}.`);
|
|
1633
|
-
}
|
|
1634
|
-
root = parent;
|
|
1635
|
-
} else {
|
|
1636
|
-
root = this;
|
|
1637
|
-
}
|
|
1638
|
-
const items = root.listFolderItems();
|
|
1639
|
-
const result: AppProjectFolder[] = [];
|
|
1640
|
-
const { definitions } = this;
|
|
1641
|
-
items.forEach((i) => {
|
|
1642
|
-
const definition = definitions.folders.find(d => i.key === d.key);
|
|
1643
|
-
if (definition) {
|
|
1644
|
-
result.push(definition);
|
|
1645
|
-
}
|
|
1646
|
-
});
|
|
1647
|
-
return result;
|
|
1648
|
-
}
|
|
1649
|
-
|
|
1650
|
-
/**
|
|
1651
|
-
* Lists requests in this project or a sub-folder.
|
|
1652
|
-
* @param folder The optional folder name or the key to list requests for.
|
|
1653
|
-
*/
|
|
1654
|
-
listRequests(folder?: string): AppProjectRequest[] {
|
|
1655
|
-
let root;
|
|
1656
|
-
if (folder) {
|
|
1657
|
-
const parent = this.findFolder(folder);
|
|
1658
|
-
if (!parent) {
|
|
1659
|
-
throw new Error(`Unable to find the folder ${folder}.`);
|
|
1660
|
-
}
|
|
1661
|
-
root = parent;
|
|
1662
|
-
} else {
|
|
1663
|
-
root = this;
|
|
1664
|
-
}
|
|
1665
|
-
const items = root.listRequestItems();
|
|
1666
|
-
const result: AppProjectRequest[] = [];
|
|
1667
|
-
const { definitions } = this;
|
|
1668
|
-
items.forEach((i) => {
|
|
1669
|
-
const definition = definitions.requests.find(d => i.key === d.key);
|
|
1670
|
-
if (definition) {
|
|
1671
|
-
result.push(definition);
|
|
1672
|
-
}
|
|
1673
|
-
});
|
|
1674
|
-
return result;
|
|
1675
|
-
}
|
|
1676
|
-
|
|
1677
|
-
/**
|
|
1678
|
-
* Lists definitions for the `items` of the project or a folder.
|
|
1679
|
-
* @param folder Optionally the folder name to list the definitions for.
|
|
1680
|
-
*/
|
|
1681
|
-
listDefinitions(folder?: string): (AppProjectFolder | AppProjectRequest | Environment)[] {
|
|
1682
|
-
let root;
|
|
1683
|
-
if (folder) {
|
|
1684
|
-
const parent = this.findFolder(folder);
|
|
1685
|
-
if (!parent) {
|
|
1686
|
-
throw new Error(`Unable to find the folder ${folder}`);
|
|
1687
|
-
}
|
|
1688
|
-
root = parent;
|
|
1689
|
-
} else {
|
|
1690
|
-
root = this;
|
|
1691
|
-
}
|
|
1692
|
-
const result: (AppProjectFolder | AppProjectRequest | Environment)[] = [];
|
|
1693
|
-
const { items = [] } = root;
|
|
1694
|
-
const { definitions } = this;
|
|
1695
|
-
items.forEach((item) => {
|
|
1696
|
-
let definition: AppProjectFolder | AppProjectRequest | Environment | undefined;
|
|
1697
|
-
if (item.kind === AppProjectFolderKind) {
|
|
1698
|
-
definition = definitions.folders.find(d => item.key === d.key);
|
|
1699
|
-
} else if (item.kind === AppProjectRequestKind) {
|
|
1700
|
-
definition = definitions.requests.find(d => item.key === d.key);
|
|
1701
|
-
} else if (item.kind === EnvironmentKind) {
|
|
1702
|
-
definition = definitions.environments.find(d => item.key === d.key);
|
|
1703
|
-
}
|
|
1704
|
-
if (definition) {
|
|
1705
|
-
result.push(definition);
|
|
1706
|
-
}
|
|
1707
|
-
});
|
|
1708
|
-
return result;
|
|
1709
|
-
}
|
|
1710
|
-
|
|
1711
|
-
/**
|
|
1712
|
-
* @returns On the project level this always returns undefined.
|
|
1713
|
-
*/
|
|
1714
|
-
getParent(): AppProjectFolder | AppProject | undefined {
|
|
1715
|
-
return undefined;
|
|
1716
|
-
}
|
|
1717
|
-
|
|
1718
|
-
getProject(): AppProject {
|
|
1719
|
-
return this;
|
|
1720
|
-
}
|
|
1721
|
-
|
|
1722
|
-
/**
|
|
1723
|
-
* Makes a copy of this project.
|
|
1724
|
-
*/
|
|
1725
|
-
clone(opts: IAppProjectProjectCloneOptions = {}): AppProject {
|
|
1726
|
-
const copy = new AppProject(this.toJSON());
|
|
1727
|
-
if (!opts.withoutRevalidate) {
|
|
1728
|
-
copy.key = v4();
|
|
1729
|
-
AppProject.regenerateKeys(copy);
|
|
1730
|
-
}
|
|
1731
|
-
return copy;
|
|
1732
|
-
}
|
|
1733
|
-
|
|
1734
|
-
static clone(project: IAppProject, opts: IAppProjectProjectCloneOptions = {}): AppProject {
|
|
1735
|
-
const obj = new AppProject(project);
|
|
1736
|
-
return obj.clone(opts);
|
|
1737
|
-
}
|
|
1738
|
-
|
|
1739
|
-
/**
|
|
1740
|
-
* Re-generates keys in the project, taking care of the references.
|
|
1741
|
-
*
|
|
1742
|
-
* Note, this changes the project properties. Make a copy of the project before calling this.
|
|
1743
|
-
*
|
|
1744
|
-
* @param src The project instance to re-generate keys for.
|
|
1745
|
-
*/
|
|
1746
|
-
static regenerateKeys(src: AppProject): void {
|
|
1747
|
-
const { items = [], definitions } = src;
|
|
1748
|
-
// create a flat list of all "items" in the project and all folders.
|
|
1749
|
-
let flatItems = [...items];
|
|
1750
|
-
(definitions.folders || []).forEach((folder) => {
|
|
1751
|
-
if (Array.isArray(folder.items) && folder.items.length) {
|
|
1752
|
-
flatItems = flatItems.concat(folder.items);
|
|
1753
|
-
}
|
|
1754
|
-
});
|
|
1755
|
-
(definitions.folders || []).forEach((folder) => {
|
|
1756
|
-
// if (Array.isArray(folder.environments) && folder.environments.length) {
|
|
1757
|
-
// withEnvironments.push(folder);
|
|
1758
|
-
// }
|
|
1759
|
-
const oldKey = folder.key;
|
|
1760
|
-
const indexObject = flatItems.find(i => i.key === oldKey);
|
|
1761
|
-
if (!indexObject) {
|
|
1762
|
-
return;
|
|
1763
|
-
}
|
|
1764
|
-
const newKey = v4();
|
|
1765
|
-
indexObject.key = newKey;
|
|
1766
|
-
folder.key = newKey;
|
|
1767
|
-
});
|
|
1768
|
-
(definitions.requests || []).forEach((request) => {
|
|
1769
|
-
const oldKey = request.key;
|
|
1770
|
-
const indexObject = flatItems.find(i => i.key === oldKey);
|
|
1771
|
-
if (!indexObject) {
|
|
1772
|
-
return;
|
|
1773
|
-
}
|
|
1774
|
-
const newKey = v4();
|
|
1775
|
-
indexObject.key = newKey;
|
|
1776
|
-
request.key = newKey;
|
|
1777
|
-
});
|
|
1778
|
-
(definitions.environments || []).forEach((environment) => {
|
|
1779
|
-
const oldKey = environment.key;
|
|
1780
|
-
const indexObject = flatItems.find(i => i.key === oldKey);
|
|
1781
|
-
if (!indexObject) {
|
|
1782
|
-
return;
|
|
1783
|
-
}
|
|
1784
|
-
const newKey = v4();
|
|
1785
|
-
indexObject.key = newKey;
|
|
1786
|
-
environment.key = newKey;
|
|
1787
|
-
});
|
|
1788
|
-
(definitions.certificates || []).forEach((cert) => {
|
|
1789
|
-
cert.key = v4();
|
|
1790
|
-
});
|
|
1791
|
-
}
|
|
1792
|
-
|
|
1793
|
-
/**
|
|
1794
|
-
* Adds an environment to the project.
|
|
1795
|
-
*
|
|
1796
|
-
* @param env The definition of the environment to use to create the environment
|
|
1797
|
-
* @returns The same or created environment.
|
|
1798
|
-
*/
|
|
1799
|
-
addEnvironment(env: IEnvironment, opts?: IAppProjectEnvironmentCreateOptions): Environment;
|
|
1800
|
-
|
|
1801
|
-
/**
|
|
1802
|
-
* Adds an environment to the project.
|
|
1803
|
-
*
|
|
1804
|
-
* @param env The instance of the environment to add
|
|
1805
|
-
* @returns The same or created environment.
|
|
1806
|
-
*/
|
|
1807
|
-
addEnvironment(env: Environment, opts?: IAppProjectEnvironmentCreateOptions): Environment;
|
|
1808
|
-
|
|
1809
|
-
/**
|
|
1810
|
-
* Adds an environment to the project.
|
|
1811
|
-
*
|
|
1812
|
-
* @param env The name of the environment to create
|
|
1813
|
-
* @returns The same or created environment.
|
|
1814
|
-
*/
|
|
1815
|
-
addEnvironment(env: string, opts?: IAppProjectEnvironmentCreateOptions): Environment;
|
|
1816
|
-
|
|
1817
|
-
/**
|
|
1818
|
-
* Adds an environment to the project.
|
|
1819
|
-
* @returns The same or created environment.
|
|
1820
|
-
*/
|
|
1821
|
-
addEnvironment(env: IEnvironment | Environment | string, opts: IAppProjectEnvironmentCreateOptions = {}): Environment {
|
|
1822
|
-
const environment = this._createEnv(env);
|
|
1823
|
-
const root = this._getRoot(opts);
|
|
1824
|
-
const project = this.getProject();
|
|
1825
|
-
if (!project.definitions.environments) {
|
|
1826
|
-
project.definitions.environments = [];
|
|
1827
|
-
}
|
|
1828
|
-
project.definitions.environments.push(environment);
|
|
1829
|
-
const item = AppProjectItem.projectEnvironment(project, environment.key);
|
|
1830
|
-
this._insertItem(item, root, opts);
|
|
1831
|
-
return environment;
|
|
1832
|
-
}
|
|
1833
|
-
|
|
1834
|
-
protected _createEnv(env: IEnvironment | Environment | string): Environment {
|
|
1835
|
-
let finalEnv: Environment;
|
|
1836
|
-
if (env instanceof Environment) {
|
|
1837
|
-
finalEnv = env;
|
|
1838
|
-
} else if (typeof env === 'string') {
|
|
1839
|
-
finalEnv = Environment.fromName(env);
|
|
1840
|
-
} else {
|
|
1841
|
-
finalEnv = new Environment(env);
|
|
1842
|
-
}
|
|
1843
|
-
if (!finalEnv.key) {
|
|
1844
|
-
finalEnv.key = v4();
|
|
1845
|
-
}
|
|
1846
|
-
return finalEnv;
|
|
1847
|
-
}
|
|
1848
|
-
|
|
1849
|
-
/**
|
|
1850
|
-
* @param key The environment key to read.
|
|
1851
|
-
*/
|
|
1852
|
-
getEnvironment(key: string, opts: IAppProjectItemOptions = {}): Environment | undefined {
|
|
1853
|
-
const root = this._getRoot(opts);
|
|
1854
|
-
const item = root.items.find(i => i.key === key);
|
|
1855
|
-
if (!item) {
|
|
1856
|
-
return undefined;
|
|
1857
|
-
}
|
|
1858
|
-
const project = this.getProject();
|
|
1859
|
-
if (!Array.isArray(project.definitions.environments)) {
|
|
1860
|
-
project.definitions.environments = [];
|
|
1861
|
-
}
|
|
1862
|
-
return project.definitions.environments.find(e => e.key === key);
|
|
1863
|
-
}
|
|
1864
|
-
|
|
1865
|
-
/**
|
|
1866
|
-
* Removes an environment from the folder or a sub-folder.
|
|
1867
|
-
*
|
|
1868
|
-
* @param key the key of the environment to remove
|
|
1869
|
-
* @returns The removed environment, if any.
|
|
1870
|
-
*/
|
|
1871
|
-
removeEnvironment(key: string, opts: IAppProjectItemOptions = {}): Environment | undefined {
|
|
1872
|
-
const root = this._getRoot(opts);
|
|
1873
|
-
const itemIndex = root.items.findIndex(i => i.key === key);
|
|
1874
|
-
if (itemIndex < 0) {
|
|
1875
|
-
return undefined;
|
|
1876
|
-
}
|
|
1877
|
-
root.items.splice(itemIndex, 1);
|
|
1878
|
-
const project = this.getProject();
|
|
1879
|
-
if (!Array.isArray(project.definitions.environments)) {
|
|
1880
|
-
project.definitions.environments = [];
|
|
1881
|
-
}
|
|
1882
|
-
const defIndex = project.definitions.environments.findIndex(i => i.key === key);
|
|
1883
|
-
if (defIndex < 0) {
|
|
1884
|
-
return undefined;
|
|
1885
|
-
}
|
|
1886
|
-
const env = project.definitions.environments[defIndex];
|
|
1887
|
-
project.definitions.environments.splice(defIndex, 1);
|
|
1888
|
-
return env;
|
|
1889
|
-
}
|
|
1890
|
-
|
|
1891
|
-
/**
|
|
1892
|
-
* This method is a link to `listEnvironments()` to be compatible with the HttpProject.
|
|
1893
|
-
*
|
|
1894
|
-
* @returns The list of environments defined in this folder
|
|
1895
|
-
*/
|
|
1896
|
-
getEnvironments(opts?: IAppProjectItemOptions): Environment[] {
|
|
1897
|
-
return this.listEnvironments(opts);
|
|
1898
|
-
}
|
|
1899
|
-
|
|
1900
|
-
/**
|
|
1901
|
-
* This is a link to the `getEnvironments()`. The difference is that on the
|
|
1902
|
-
* project level it won't return environments defined with the class initialization.
|
|
1903
|
-
*/
|
|
1904
|
-
listEnvironments(opts: IAppProjectItemOptions = {}): Environment[] {
|
|
1905
|
-
const root = this._getRoot(opts);
|
|
1906
|
-
const items = root.items.filter(i => i.kind === EnvironmentKind).map(i => i.key);
|
|
1907
|
-
const project = this.getProject();
|
|
1908
|
-
if (!Array.isArray(project.definitions.environments)) {
|
|
1909
|
-
project.definitions.environments = [];
|
|
1910
|
-
}
|
|
1911
|
-
return project.definitions.environments.filter(e => items.includes(e.key));
|
|
1912
|
-
}
|
|
1913
|
-
|
|
1914
|
-
/**
|
|
1915
|
-
* Reads the list of environments from then selected folder up to the project root.
|
|
1916
|
-
* It stops going up in the project structure when selected environment has the `encapsulated`
|
|
1917
|
-
* property set to true.
|
|
1918
|
-
* The environments are ordered from the top-most level to the selected folder.
|
|
1919
|
-
*
|
|
1920
|
-
* @param opts The environment read options
|
|
1921
|
-
*/
|
|
1922
|
-
readEnvironments(opts: IAppProjectReadEnvironmentOptions = {}): Environment[] {
|
|
1923
|
-
const result: Environment[] = [];
|
|
1924
|
-
const { parent, nameOrKey } = opts;
|
|
1925
|
-
|
|
1926
|
-
const root = parent ? this.findFolder(parent, { keyOnly: true }) : this;
|
|
1927
|
-
if (!root) {
|
|
1928
|
-
return result;
|
|
1929
|
-
}
|
|
1930
|
-
|
|
1931
|
-
let current: AppProject | AppProjectFolder | undefined = root;
|
|
1932
|
-
while (current) {
|
|
1933
|
-
const environments = current.listEnvironments();
|
|
1934
|
-
if (environments.length) {
|
|
1935
|
-
const selected = nameOrKey ? environments.find(i => i.key === nameOrKey || i.info.name === nameOrKey) : environments[0];
|
|
1936
|
-
if (selected) {
|
|
1937
|
-
result.push(selected);
|
|
1938
|
-
if (selected.encapsulated) {
|
|
1939
|
-
break;
|
|
1940
|
-
}
|
|
1941
|
-
}
|
|
1942
|
-
}
|
|
1943
|
-
current = current.getParent();
|
|
1944
|
-
}
|
|
1945
|
-
|
|
1946
|
-
return result.reverse();
|
|
1947
|
-
}
|
|
1948
|
-
|
|
1949
|
-
/**
|
|
1950
|
-
* Finds a definition for an environment regardless of its parent.
|
|
1951
|
-
*
|
|
1952
|
-
* @param key The Key of the environment to find.
|
|
1953
|
-
* @returns The environment definition or undefined if not found.
|
|
1954
|
-
*/
|
|
1955
|
-
findEnvironment(key: string): Environment | undefined {
|
|
1956
|
-
return this.definitions.environments.find(i => i.key === key);
|
|
1957
|
-
}
|
|
1958
|
-
|
|
1959
|
-
/**
|
|
1960
|
-
* Depending on the options returns a project or a folder.
|
|
1961
|
-
* It throws when parent folder cannot ber found.
|
|
1962
|
-
*/
|
|
1963
|
-
protected _getRoot(opts: { parent?: string }): AppProjectFolder | AppProject {
|
|
1964
|
-
const project = this.getProject();
|
|
1965
|
-
if (opts.parent) {
|
|
1966
|
-
const parent = project.findFolder(opts.parent);
|
|
1967
|
-
if (!parent) {
|
|
1968
|
-
throw new Error(`Unable to find the parent folder ${opts.parent}.`);
|
|
1969
|
-
}
|
|
1970
|
-
return parent;
|
|
1971
|
-
}
|
|
1972
|
-
return project;
|
|
1973
|
-
}
|
|
1974
|
-
|
|
1975
|
-
protected _insertItem(item: AppProjectItem, root: AppProjectFolder | AppProject, opts: IAppProjectItemCreateOptions): void {
|
|
1976
|
-
if (!Array.isArray(root.items)) {
|
|
1977
|
-
root.items = [];
|
|
1978
|
-
}
|
|
1979
|
-
if (typeof opts.index === 'number') {
|
|
1980
|
-
root.items.splice(opts.index, 0, item);
|
|
1981
|
-
} else {
|
|
1982
|
-
root.items.push(item);
|
|
1983
|
-
}
|
|
1984
|
-
}
|
|
1985
|
-
|
|
1986
|
-
/**
|
|
1987
|
-
* Finds a definition for a certificate.
|
|
1988
|
-
*
|
|
1989
|
-
* @param key The key of the certificate to find.
|
|
1990
|
-
* @returns The certificate definition or undefined if not found.
|
|
1991
|
-
*/
|
|
1992
|
-
findCertificate(key: string): Certificate | undefined {
|
|
1993
|
-
return this.definitions.certificates.find(i => i.key === key);
|
|
1994
|
-
}
|
|
1995
|
-
|
|
1996
|
-
/**
|
|
1997
|
-
* Adds a certificate to the project.
|
|
1998
|
-
*
|
|
1999
|
-
* @param init Either an instance of a certificate or its definition.
|
|
2000
|
-
* @returns The inserted certificate.
|
|
2001
|
-
*/
|
|
2002
|
-
addCertificate(init: Certificate | HttpCertificate): Certificate {
|
|
2003
|
-
let finalCert: Certificate;
|
|
2004
|
-
if (init instanceof Certificate) {
|
|
2005
|
-
finalCert = init;
|
|
2006
|
-
} else {
|
|
2007
|
-
finalCert = new Certificate(init);
|
|
2008
|
-
}
|
|
2009
|
-
if (!this.definitions.certificates) {
|
|
2010
|
-
this.definitions.certificates = [];
|
|
2011
|
-
}
|
|
2012
|
-
this.definitions.certificates.push(finalCert);
|
|
2013
|
-
return finalCert;
|
|
2014
|
-
}
|
|
2015
|
-
|
|
2016
|
-
/**
|
|
2017
|
-
* Removes a certificate from the project.
|
|
2018
|
-
*
|
|
2019
|
-
* @param key the key of the certificate to remove
|
|
2020
|
-
* @returns The removed certificate, if any.
|
|
2021
|
-
*/
|
|
2022
|
-
removeCertificate(key: string): Certificate | undefined {
|
|
2023
|
-
if (!Array.isArray(this.definitions.certificates)) {
|
|
2024
|
-
return undefined
|
|
2025
|
-
}
|
|
2026
|
-
const defIndex = this.definitions.certificates.findIndex(i => i.key === key);
|
|
2027
|
-
if (defIndex < 0) {
|
|
2028
|
-
return undefined;
|
|
2029
|
-
}
|
|
2030
|
-
const cert = this.definitions.certificates[defIndex];
|
|
2031
|
-
this.definitions.certificates.splice(defIndex, 1);
|
|
2032
|
-
return cert;
|
|
2033
|
-
}
|
|
2034
|
-
|
|
2035
|
-
/**
|
|
2036
|
-
* Finds the requests that are using the certificate identified by the key.
|
|
2037
|
-
*
|
|
2038
|
-
* @param key The key of the certificate to find the usage for.
|
|
2039
|
-
* @returns The list of requests that use this certificate.
|
|
2040
|
-
*/
|
|
2041
|
-
findCertificateRequests(key: string): AppProjectRequest[] {
|
|
2042
|
-
return this.definitions.requests.filter((request) => {
|
|
2043
|
-
if (!Array.isArray(request.authorization)) {
|
|
2044
|
-
return false;
|
|
2045
|
-
}
|
|
2046
|
-
const ccAuth = request.authorization.find(auth => auth.type === 'client certificate');
|
|
2047
|
-
if (!ccAuth) {
|
|
2048
|
-
return false;
|
|
2049
|
-
}
|
|
2050
|
-
const cnf = ccAuth.config as ICCAuthorization;
|
|
2051
|
-
return !!cnf && !!cnf.certificate && cnf.certificate.key === key;
|
|
2052
|
-
});
|
|
2053
|
-
}
|
|
2054
|
-
|
|
2055
|
-
/**
|
|
2056
|
-
* Iterates over requests in the project.
|
|
2057
|
-
*/
|
|
2058
|
-
* requestIterator(opts: IProjectRequestIterator = {}): Generator<AppProjectRequest> {
|
|
2059
|
-
const { definitions } = this;
|
|
2060
|
-
const { ignore=[], parent, recursive, requests=[] } = opts;
|
|
2061
|
-
const root = parent ? this.findFolder(parent) : this;
|
|
2062
|
-
if (!root) {
|
|
2063
|
-
throw new Error(`The parent folder not found: ${parent}.`);
|
|
2064
|
-
}
|
|
2065
|
-
const items = root.items;
|
|
2066
|
-
if (!items || !items.length) {
|
|
2067
|
-
return;
|
|
2068
|
-
}
|
|
2069
|
-
for (const item of items) {
|
|
2070
|
-
if (ignore.includes(item.key)) {
|
|
2071
|
-
continue;
|
|
2072
|
-
}
|
|
2073
|
-
if (item.kind === AppProjectRequestKind) {
|
|
2074
|
-
const request = definitions.requests.find(i => i.key === item.key);
|
|
2075
|
-
if (!request) {
|
|
2076
|
-
continue;
|
|
2077
|
-
}
|
|
2078
|
-
const name = request.info.name || '';
|
|
2079
|
-
if (ignore.includes(name)) {
|
|
2080
|
-
continue;
|
|
2081
|
-
}
|
|
2082
|
-
if (requests.length && !requests.includes(item.key) && !requests.includes(name)) {
|
|
2083
|
-
continue;
|
|
2084
|
-
}
|
|
2085
|
-
yield request;
|
|
2086
|
-
} else if (recursive && item.kind === AppProjectFolderKind) {
|
|
2087
|
-
const folder = definitions.folders.find(i => i.key === item.key);
|
|
2088
|
-
if (!folder) {
|
|
2089
|
-
continue;
|
|
2090
|
-
}
|
|
2091
|
-
const name = folder.info.name || '';
|
|
2092
|
-
if (ignore.includes(name)) {
|
|
2093
|
-
continue;
|
|
2094
|
-
}
|
|
2095
|
-
const it = this.requestIterator({
|
|
2096
|
-
parent: item.key,
|
|
2097
|
-
recursive,
|
|
2098
|
-
ignore,
|
|
2099
|
-
requests,
|
|
2100
|
-
});
|
|
2101
|
-
for (const request of it) {
|
|
2102
|
-
yield request;
|
|
2103
|
-
}
|
|
2104
|
-
}
|
|
2105
|
-
}
|
|
2106
|
-
}
|
|
2107
|
-
}
|
|
2108
|
-
|
|
2109
|
-
/**
|
|
2110
|
-
* This model represents a meta data for an AppProject stored with the data store.
|
|
2111
|
-
* This does not include the AppProject entity, though, it is referenced through the same key.
|
|
2112
|
-
*/
|
|
2113
|
-
export interface IAppProjectFile extends IFile {
|
|
2114
|
-
kind: typeof AppProjectFileKind;
|
|
2115
|
-
}
|
|
2116
|
-
|
|
2117
|
-
export class AppProjectFile extends File {
|
|
2118
|
-
override kind = AppProjectFileKind;
|
|
2119
|
-
|
|
2120
|
-
static fromProject(project: AppProject | IAppProject): AppProjectFile {
|
|
2121
|
-
let final: IAppProject;
|
|
2122
|
-
if (typeof (project as AppProject).toJSON === 'function') {
|
|
2123
|
-
final = (project as AppProject).toJSON();
|
|
2124
|
-
} else {
|
|
2125
|
-
final = project as IAppProject;
|
|
2126
|
-
}
|
|
2127
|
-
const init: IAppProjectFile = {
|
|
2128
|
-
kind: AppProjectFileKind,
|
|
2129
|
-
key: final.key,
|
|
2130
|
-
info: { ...final.info },
|
|
2131
|
-
lastModified: { user: '', time: 0, byMe: false },
|
|
2132
|
-
owner: DefaultOwner,
|
|
2133
|
-
parents: [],
|
|
2134
|
-
permissionIds: [],
|
|
2135
|
-
permissions: [],
|
|
2136
|
-
};
|
|
2137
|
-
return new AppProjectFile(init);
|
|
2138
|
-
}
|
|
2139
|
-
|
|
2140
|
-
constructor(input?: string | IAppProjectFile) {
|
|
2141
|
-
super();
|
|
2142
|
-
let init: IAppProjectFile;
|
|
2143
|
-
if (typeof input === 'string') {
|
|
2144
|
-
init = JSON.parse(input);
|
|
2145
|
-
} else if (typeof input === 'object') {
|
|
2146
|
-
init = input;
|
|
2147
|
-
} else {
|
|
2148
|
-
init = {
|
|
2149
|
-
kind: AppProjectFileKind,
|
|
2150
|
-
key: v4(),
|
|
2151
|
-
info: {
|
|
2152
|
-
kind: ThingKind,
|
|
2153
|
-
name: '',
|
|
2154
|
-
},
|
|
2155
|
-
owner: DefaultOwner,
|
|
2156
|
-
parents: [],
|
|
2157
|
-
permissionIds: [],
|
|
2158
|
-
permissions: [],
|
|
2159
|
-
lastModified: { user: '', time: 0, byMe: false },
|
|
2160
|
-
};
|
|
2161
|
-
}
|
|
2162
|
-
this.new(init);
|
|
2163
|
-
}
|
|
2164
|
-
|
|
2165
|
-
override new(init: IAppProjectFile): void {
|
|
2166
|
-
if (!AppProjectFile.isProject(init)) {
|
|
2167
|
-
throw new Error(`Not a project file.`);
|
|
2168
|
-
}
|
|
2169
|
-
super.new(init);
|
|
2170
|
-
this.kind = AppProjectFileKind;
|
|
2171
|
-
}
|
|
2172
|
-
|
|
2173
|
-
static isProject(input: unknown): boolean {
|
|
2174
|
-
const typed = input as IAppProjectFile;
|
|
2175
|
-
if (!input || typed.kind !== AppProjectFileKind) {
|
|
2176
|
-
return false;
|
|
2177
|
-
}
|
|
2178
|
-
return true;
|
|
2179
|
-
}
|
|
2180
|
-
|
|
2181
|
-
override toJSON(): IAppProjectFile {
|
|
2182
|
-
const result: IAppProjectFile = {
|
|
2183
|
-
...super.toJSON(),
|
|
2184
|
-
kind: AppProjectFileKind,
|
|
2185
|
-
};
|
|
2186
|
-
return result;
|
|
2187
|
-
}
|
|
2188
|
-
}
|