@api-client/core 0.3.1 → 0.3.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (183) hide show
  1. package/build/browser.d.ts +1 -1
  2. package/build/index.d.ts +2 -2
  3. package/build/index.js.map +1 -1
  4. package/build/src/models/Backend.d.ts +22 -0
  5. package/build/src/runtime/store/StoreSdk.d.ts +192 -12
  6. package/build/src/runtime/store/StoreSdk.js +592 -53
  7. package/build/src/runtime/store/StoreSdk.js.map +1 -1
  8. package/package.json +3 -1
  9. package/src/data/DataReader.ts +11 -0
  10. package/src/data/DataUtils.ts +108 -0
  11. package/src/data/JmesparthReader.ts +26 -0
  12. package/src/data/Json2Xml.ts +190 -0
  13. package/src/data/JsonReader.ts +41 -0
  14. package/src/data/PayloadPointer.ts +48 -0
  15. package/src/data/RequestDataExtractor.ts +133 -0
  16. package/src/data/UrlEncodedReader.ts +20 -0
  17. package/src/data/XmlReader.ts +103 -0
  18. package/src/events/BaseEvents.ts +259 -0
  19. package/src/events/CustomEvent.ts +27 -0
  20. package/src/events/EventTypes.ts +19 -0
  21. package/src/events/Events.ts +19 -0
  22. package/src/events/authorization/AuthorizationEventTypes.ts +22 -0
  23. package/src/events/authorization/AuthorizationEvents.ts +61 -0
  24. package/src/events/cookies/CookieEventTypes.ts +13 -0
  25. package/src/events/cookies/CookieEvents.ts +157 -0
  26. package/src/events/encryption/EncryptionEventTypes.ts +4 -0
  27. package/src/events/encryption/EncryptionEvents.ts +51 -0
  28. package/src/events/environment/EnvironmentEventTypes.ts +3 -0
  29. package/src/events/environment/EnvironmentEvents.ts +24 -0
  30. package/src/events/models/ClientCertificateEvents.ts +87 -0
  31. package/src/events/models/ModelEventTypes.ts +47 -0
  32. package/src/events/models/ModelEvents.ts +7 -0
  33. package/src/events/models/ProjectEvents.ts +331 -0
  34. package/src/events/process/ProcessEventTypes.ts +5 -0
  35. package/src/events/process/ProcessEvents.ts +76 -0
  36. package/src/events/readme.md +22 -0
  37. package/src/events/reporting/ReportingEventTypes.ts +3 -0
  38. package/src/events/reporting/ReportingEvents.ts +28 -0
  39. package/src/events/telemetry/TelemetryEventTypes.ts +10 -0
  40. package/src/events/telemetry/TelemetryEvents.ts +156 -0
  41. package/src/lib/cookies/Cookie.ts +312 -0
  42. package/src/lib/cookies/Cookies.ts +326 -0
  43. package/src/lib/cookies/Utils.ts +168 -0
  44. package/src/lib/headers/Headers.ts +219 -0
  45. package/src/lib/logging/DefaultLogger.ts +19 -0
  46. package/src/lib/logging/DummyLogger.ts +21 -0
  47. package/src/lib/logging/Logger.ts +16 -0
  48. package/src/lib/transformers/PayloadSerializer.ts +332 -0
  49. package/src/lib/transformers/Utils.ts +18 -0
  50. package/src/lib/uuid.ts +40 -0
  51. package/src/mocking/LegacyInterfaces.ts +52 -0
  52. package/src/mocking/LegacyMock.ts +37 -0
  53. package/src/mocking/legacy/Authorization.ts +39 -0
  54. package/src/mocking/legacy/Certificates.ts +145 -0
  55. package/src/mocking/legacy/Cookies.ts +51 -0
  56. package/src/mocking/legacy/HostRules.ts +43 -0
  57. package/src/mocking/legacy/Http.ts +236 -0
  58. package/src/mocking/legacy/HttpResponse.ts +106 -0
  59. package/src/mocking/legacy/RestApi.ts +68 -0
  60. package/src/mocking/legacy/Urls.ts +44 -0
  61. package/src/mocking/legacy/Variables.ts +53 -0
  62. package/src/models/ArcResponse.ts +166 -0
  63. package/src/models/Authorization.ts +481 -0
  64. package/src/models/AuthorizationData.ts +60 -0
  65. package/src/models/Backend.ts +107 -0
  66. package/src/models/ClientCertificate.ts +68 -0
  67. package/src/models/Environment.ts +279 -0
  68. package/src/models/ErrorResponse.ts +101 -0
  69. package/src/models/HistoryIndex.ts +76 -0
  70. package/src/models/HistoryRequest.ts +28 -0
  71. package/src/models/HostRule.ts +163 -0
  72. package/src/models/HttpCookie.ts +285 -0
  73. package/src/models/HttpProject.ts +1294 -0
  74. package/src/models/HttpProjectListItem.ts +23 -0
  75. package/src/models/HttpRequest.ts +124 -0
  76. package/src/models/HttpResponse.ts +143 -0
  77. package/src/models/License.ts +113 -0
  78. package/src/models/ProjectDefinitionProperty.ts +40 -0
  79. package/src/models/ProjectFolder.ts +439 -0
  80. package/src/models/ProjectItem.ts +135 -0
  81. package/src/models/ProjectParent.ts +113 -0
  82. package/src/models/ProjectRequest.ts +277 -0
  83. package/src/models/ProjectSchema.ts +202 -0
  84. package/src/models/Property.ts +423 -0
  85. package/src/models/Provider.ts +98 -0
  86. package/src/models/README.md +20 -0
  87. package/src/models/Request.ts +452 -0
  88. package/src/models/RequestActions.ts +163 -0
  89. package/src/models/RequestAuthorization.ts +115 -0
  90. package/src/models/RequestConfig.ts +317 -0
  91. package/src/models/RequestLog.ts +159 -0
  92. package/src/models/RequestTime.ts +108 -0
  93. package/src/models/RequestUiMeta.ts +258 -0
  94. package/src/models/RequestsSize.ts +65 -0
  95. package/src/models/ResponseAuthorization.ts +104 -0
  96. package/src/models/ResponseRedirect.ts +158 -0
  97. package/src/models/RevisionInfo.ts +37 -0
  98. package/src/models/SentRequest.ts +125 -0
  99. package/src/models/SerializablePayload.ts +68 -0
  100. package/src/models/Server.ts +153 -0
  101. package/src/models/Thing.ts +110 -0
  102. package/src/models/Url.ts +90 -0
  103. package/src/models/User.ts +120 -0
  104. package/src/models/WebApi.ts +234 -0
  105. package/src/models/WebApiIndex.ts +122 -0
  106. package/src/models/Workspace.ts +182 -0
  107. package/src/models/actions/Action.ts +213 -0
  108. package/src/models/actions/ActionView.ts +40 -0
  109. package/src/models/actions/Condition.ts +207 -0
  110. package/src/models/actions/ConditionView.ts +42 -0
  111. package/src/models/actions/Enums.ts +29 -0
  112. package/src/models/actions/RunnableAction.ts +144 -0
  113. package/src/models/actions/runnable/DeleteCookieAction.ts +113 -0
  114. package/src/models/actions/runnable/Runnable.ts +9 -0
  115. package/src/models/actions/runnable/SetCookieAction.ts +216 -0
  116. package/src/models/actions/runnable/SetVariableAction.ts +81 -0
  117. package/src/models/legacy/DataExport.ts +172 -0
  118. package/src/models/legacy/Normalizer.ts +110 -0
  119. package/src/models/legacy/actions/Actions.ts +269 -0
  120. package/src/models/legacy/authorization/Authorization.ts +572 -0
  121. package/src/models/legacy/models/ApiTypes.ts +202 -0
  122. package/src/models/legacy/models/ArcLegacyProject.ts +39 -0
  123. package/src/models/legacy/models/AuthData.ts +17 -0
  124. package/src/models/legacy/models/ClientCertificate.ts +95 -0
  125. package/src/models/legacy/models/Cookies.ts +52 -0
  126. package/src/models/legacy/models/HostRule.ts +35 -0
  127. package/src/models/legacy/models/RestApi.ts +49 -0
  128. package/src/models/legacy/models/UrlHistory.ts +37 -0
  129. package/src/models/legacy/models/Variable.ts +43 -0
  130. package/src/models/legacy/models/base.d.ts +95 -0
  131. package/src/models/legacy/request/ArcRequest.ts +405 -0
  132. package/src/models/legacy/request/ArcResponse.ts +177 -0
  133. package/src/models/legacy/request/HistoryData.ts +47 -0
  134. package/src/models/legacy/request/Legacy.ts +45 -0
  135. package/src/models/legacy/request/RequestBody.ts +87 -0
  136. package/src/models/transformers/ArcDexieTransformer.ts +323 -0
  137. package/src/models/transformers/ArcLegacyNormalizer.ts +85 -0
  138. package/src/models/transformers/ArcLegacyTransformer.ts +200 -0
  139. package/src/models/transformers/ArcPouchTransformer.ts +184 -0
  140. package/src/models/transformers/BaseTransformer.ts +116 -0
  141. package/src/models/transformers/ImportUtils.ts +141 -0
  142. package/src/models/transformers/LegacyDataExportToApiProject.ts +76 -0
  143. package/src/models/transformers/LegacyExportProcessor.ts +252 -0
  144. package/src/models/transformers/PostmanBackupTransformer.ts +306 -0
  145. package/src/models/transformers/PostmanDataTransformer.ts +50 -0
  146. package/src/models/transformers/PostmanTransformer.ts +106 -0
  147. package/src/models/transformers/PostmanV21Transformer.ts +311 -0
  148. package/src/models/transformers/PostmanV2Transformer.ts +308 -0
  149. package/src/models/transformers/har.ts +865 -0
  150. package/src/runtime/actions/ActionRunner.ts +83 -0
  151. package/src/runtime/actions/ConditionRunner.ts +194 -0
  152. package/src/runtime/actions/RunnableCondition.ts +57 -0
  153. package/src/runtime/actions/runnable/ActionRunnable.ts +19 -0
  154. package/src/runtime/actions/runnable/DeleteCookieRunnable.ts +39 -0
  155. package/src/runtime/actions/runnable/SetCookieRunnable.ts +92 -0
  156. package/src/runtime/actions/runnable/SetVariableRunnable.ts +53 -0
  157. package/src/runtime/http-engine/ArcEngine.ts +1064 -0
  158. package/src/runtime/http-engine/Errors.ts +13 -0
  159. package/src/runtime/http-engine/FormData.ts +85 -0
  160. package/src/runtime/http-engine/HttpEngine.ts +874 -0
  161. package/src/runtime/http-engine/HttpErrorCodes.ts +270 -0
  162. package/src/runtime/http-engine/NodeEngine.ts +787 -0
  163. package/src/runtime/http-engine/NodeEngineDirect.ts +476 -0
  164. package/src/runtime/http-engine/PayloadSupport.ts +84 -0
  165. package/src/runtime/http-engine/RequestUtils.ts +164 -0
  166. package/src/runtime/http-engine/ntlm/Des.ts +345 -0
  167. package/src/runtime/http-engine/ntlm/MD4.ts +135 -0
  168. package/src/runtime/http-engine/ntlm/NtlmAuth.ts +186 -0
  169. package/src/runtime/http-engine/ntlm/NtlmMessage.ts +57 -0
  170. package/src/runtime/modules/BasicAuthCache.ts +133 -0
  171. package/src/runtime/modules/ExecutionResponse.ts +4 -0
  172. package/src/runtime/modules/ModulesRegistry.ts +136 -0
  173. package/src/runtime/modules/RequestAuthorization.ts +110 -0
  174. package/src/runtime/modules/RequestCookies.ts +145 -0
  175. package/src/runtime/node/ProjectRunner.ts +275 -0
  176. package/src/runtime/node/RequestFactory.ts +422 -0
  177. package/src/runtime/node/VariablesStore.ts +25 -0
  178. package/src/runtime/store/StoreSdk.ts +838 -0
  179. package/src/runtime/variables/Cache.ts +53 -0
  180. package/src/runtime/variables/EvalFunctions.ts +132 -0
  181. package/src/runtime/variables/ProjectVariables.ts +6 -0
  182. package/src/runtime/variables/VariablesProcessor.ts +543 -0
  183. package/src/runtime/variables/VariablesTokenizer.ts +55 -0
@@ -0,0 +1,234 @@
1
+ export const Kind = 'ARC#WebApi';
2
+
3
+ /**
4
+ * @deprecated This was used in the old version of ARC.
5
+ */
6
+ export interface ILegacyRestApi {
7
+ /**
8
+ * The ID of the index item that this entry refers to.
9
+ */
10
+ indexId: string;
11
+ /**
12
+ * Version name of the API
13
+ */
14
+ version: string;
15
+ /**
16
+ * API data model. It is the output of the AMF parser run on the API.
17
+ */
18
+ data: string;
19
+ /**
20
+ * The AMF parser version used to parse this document.
21
+ */
22
+ amfVersion?: string;
23
+ }
24
+
25
+ export interface IWebApi {
26
+ kind: typeof Kind;
27
+ /**
28
+ * The ID of the index item that this entry refers to.
29
+ */
30
+ indexId: string;
31
+ /**
32
+ * Version name of the API
33
+ */
34
+ version: string;
35
+ /**
36
+ * API data model. It is the output of the AMF parser run on the API.
37
+ * This is left for compatibility.
38
+ * @deprecated This was used in the old version of ARC. v18 uses the `path` with the location of the API project.
39
+ */
40
+ data?: string;
41
+ /**
42
+ * The AMF parser version used to parse this document.
43
+ * This is left for compatibility.
44
+ * @deprecated This was used in the old version of ARC. v18 does not use this information.
45
+ */
46
+ amfVersion?: string;
47
+ /**
48
+ * The location of the API project. This can be any URI to get the sources of the API project.
49
+ */
50
+ path: string;
51
+ /**
52
+ * Optional information to point to the API's main file.
53
+ */
54
+ main?: string;
55
+ /**
56
+ * The API format's media type.
57
+ */
58
+ mime?: string;
59
+ /**
60
+ * The API vendor. E.g. RAML 1.0, OAS 3.0, ASYNC 2.0, ...
61
+ */
62
+ vendor?: string;
63
+ }
64
+
65
+ export class WebApi {
66
+ kind = Kind;
67
+ /**
68
+ * The ID of the index item that this entry refers to.
69
+ */
70
+ indexId = '';
71
+ /**
72
+ * Version name of the API
73
+ */
74
+ version = '';
75
+ /**
76
+ * API data model. It is the output of the AMF parser run on the API.
77
+ * This is left for compatibility.
78
+ * @deprecated This was used in the old version of ARC. v18 uses the `path` with the location of the API project.
79
+ */
80
+ data?: string;
81
+ /**
82
+ * The AMF parser version used to parse this document.
83
+ * This is left for compatibility.
84
+ * @deprecated This was used in the old version of ARC. v18 does not use this information.
85
+ */
86
+ amfVersion?: string;
87
+ /**
88
+ * The location of the API project. This can be any URI to get the sources of the API project.
89
+ */
90
+ path = '';
91
+ /**
92
+ * Optional information to point to the API's main file.
93
+ */
94
+ main?: string;
95
+ /**
96
+ * The API format's media type.
97
+ */
98
+ mime?: string;
99
+ /**
100
+ * The API vendor. E.g. RAML 1.0, OAS 3.0, ASYNC 2.0, ...
101
+ */
102
+ vendor?: string;
103
+
104
+ /**
105
+ * Checks whether the object represents a legacy way of storing the web API data.
106
+ */
107
+ get isLegacy(): boolean {
108
+ return !!this.data;
109
+ }
110
+
111
+ /**
112
+ * Checks whether the object is the legacy schema for web API (formally known as RestAPI)
113
+ */
114
+ static isLegacy(api: unknown): boolean {
115
+ const legacy = api as ILegacyRestApi;
116
+ if (legacy.data) {
117
+ return true;
118
+ }
119
+ return false;
120
+ }
121
+
122
+ static fromLegacy(api: ILegacyRestApi): WebApi {
123
+ const { version, amfVersion, data, indexId } = api;
124
+ const init: IWebApi = {
125
+ kind: Kind,
126
+ version,
127
+ path: '',
128
+ indexId,
129
+ };
130
+ if (amfVersion) {
131
+ init.amfVersion = amfVersion;
132
+ }
133
+ if (data) {
134
+ init.data = data;
135
+ }
136
+ return new WebApi(init);
137
+ }
138
+
139
+ /**
140
+ * Creates an identifier of this web API object.
141
+ * @param indexId The id of the corresponding index item. This is usually the base URI of the API.
142
+ * @param version The version name of this web API.
143
+ * @returns The unique and reversible identifier of this web API.
144
+ */
145
+ static createId(indexId: string, version: string): string {
146
+ return `${indexId}|${version}`;
147
+ }
148
+
149
+ constructor(input?: string|IWebApi) {
150
+ let init: IWebApi;
151
+ if (typeof input === 'string') {
152
+ init = JSON.parse(input);
153
+ } else if (typeof input === 'object') {
154
+ init = input;
155
+ } else {
156
+ init = {
157
+ kind: Kind,
158
+ version: '',
159
+ path: '',
160
+ indexId: '',
161
+ };
162
+ }
163
+ this.new(init);
164
+ }
165
+
166
+ new(init: IWebApi): void {
167
+ const { version, data, amfVersion, path, main, mime, vendor, indexId } = init;
168
+ if (indexId) {
169
+ this.indexId = indexId;
170
+ } else {
171
+ this.indexId = '';
172
+ }
173
+ if (version) {
174
+ this.version = version;
175
+ } else {
176
+ this.version = '';
177
+ }
178
+ if (data) {
179
+ this.data = data;
180
+ } else {
181
+ this.data = undefined;
182
+ }
183
+ if (amfVersion) {
184
+ this.amfVersion = amfVersion;
185
+ } else {
186
+ this.amfVersion = undefined;
187
+ }
188
+ if (path) {
189
+ this.path = path;
190
+ } else {
191
+ this.path = '';
192
+ }
193
+ if (main) {
194
+ this.main = main;
195
+ } else {
196
+ this.main = undefined
197
+ }
198
+ if (mime) {
199
+ this.mime = mime;
200
+ } else {
201
+ this.mime = mime;
202
+ }
203
+ if (vendor) {
204
+ this.vendor = vendor;
205
+ } else {
206
+ this.vendor = undefined;
207
+ }
208
+ }
209
+
210
+ toJSON(): IWebApi {
211
+ const result: IWebApi = {
212
+ kind: Kind,
213
+ version: this.version,
214
+ path: this.path,
215
+ indexId: this.indexId,
216
+ };
217
+ if (this.data) {
218
+ result.data = this.data;
219
+ }
220
+ if (this.amfVersion) {
221
+ result.amfVersion = this.amfVersion;
222
+ }
223
+ if (this.main) {
224
+ result.main = this.main;
225
+ }
226
+ if (this.mime) {
227
+ result.mime = this.mime;
228
+ }
229
+ if (this.vendor) {
230
+ result.vendor = this.vendor;
231
+ }
232
+ return result;
233
+ }
234
+ }
@@ -0,0 +1,122 @@
1
+ export const Kind = 'ARC#WebApiIndex';
2
+
3
+ /**
4
+ * @deprecated This was used in the old version of ARC.
5
+ */
6
+ export interface ILegacyWebApiIndex {
7
+ /**
8
+ * API title
9
+ */
10
+ title: string;
11
+ /**
12
+ * API media type
13
+ * @deprecated This has been renamed to `vendor`.
14
+ */
15
+ type: string;
16
+ /**
17
+ * API order on the list
18
+ */
19
+ order: number;
20
+ /**
21
+ * List of version names stored with this API.
22
+ */
23
+ versions: string[];
24
+ /**
25
+ * The latest added version name.
26
+ */
27
+ latest: string;
28
+ }
29
+
30
+ export interface IWebApiIndex {
31
+ kind: typeof Kind;
32
+ /**
33
+ * API title
34
+ */
35
+ title: string;
36
+ /**
37
+ * List of version names stored with this API.
38
+ */
39
+ versions: string[];
40
+ /**
41
+ * The latest added version name.
42
+ */
43
+ latest: string;
44
+ /**
45
+ * The API vendor. E.g. RAML 1.0, OAS 3.0, ASYNC 2.0, ...
46
+ */
47
+ vendor: string;
48
+ }
49
+
50
+ export class WebApiIndex {
51
+ kind = Kind;
52
+ /**
53
+ * API title
54
+ */
55
+ title = '';
56
+ /**
57
+ * List of version names stored with this API.
58
+ */
59
+ versions: string[] = [];
60
+ /**
61
+ * The latest added version name.
62
+ */
63
+ latest = '';
64
+ /**
65
+ * The API vendor. E.g. RAML 1.0, OAS 3.0, ASYNC 2.0, ...
66
+ */
67
+ vendor = '';
68
+
69
+ static isLegacy(api: unknown): boolean {
70
+ const legacy = api as ILegacyWebApiIndex;
71
+ return !!legacy.type;
72
+ }
73
+
74
+ static fromLegacy(api: ILegacyWebApiIndex): WebApiIndex {
75
+ const { title, type, versions=[], latest } = api;
76
+ const init: IWebApiIndex = {
77
+ kind: Kind,
78
+ title,
79
+ versions,
80
+ latest,
81
+ vendor: type,
82
+ };
83
+ return new WebApiIndex(init);
84
+ }
85
+
86
+ constructor(input?: string|IWebApiIndex) {
87
+ let init: IWebApiIndex;
88
+ if (typeof input === 'string') {
89
+ init = JSON.parse(input);
90
+ } else if (typeof input === 'object') {
91
+ init = input;
92
+ } else {
93
+ init = {
94
+ kind: Kind,
95
+ latest: '',
96
+ title: '',
97
+ vendor: '',
98
+ versions: [],
99
+ };
100
+ }
101
+ this.new(init);
102
+ }
103
+
104
+ new(init: IWebApiIndex): void {
105
+ const { latest='', title='', vendor='', versions=[] } = init;
106
+ this.latest = latest;
107
+ this.versions = versions;
108
+ this.title = title;
109
+ this.vendor = vendor;
110
+ }
111
+
112
+ toJSON(): IWebApiIndex {
113
+ const result: IWebApiIndex = {
114
+ kind: Kind,
115
+ latest: this.latest,
116
+ versions: this.versions,
117
+ title: this.title,
118
+ vendor: this.vendor,
119
+ };
120
+ return result;
121
+ }
122
+ }
@@ -0,0 +1,182 @@
1
+ import { AccessControlLevel } from "./User.js";
2
+ import { IThing, Thing, Kind as ThingKind } from './Thing.js';
3
+ import v4 from '../lib/uuid.js';
4
+
5
+ export const Kind = 'ARC#Space';
6
+ /**
7
+ * A definition of the working space for users.
8
+ *
9
+ * A working space is a logical container in the data store
10
+ * created by the system users, where they can store their projects and other data.
11
+ */
12
+ export interface IWorkspace {
13
+ kind: 'ARC#Space';
14
+ /**
15
+ * The space identifier.
16
+ */
17
+ key: string;
18
+ /**
19
+ * The environment's meta info.
20
+ */
21
+ info: IThing;
22
+ /**
23
+ * The list of users added to this space. May not be set when owner did not add anyone to the space.
24
+ */
25
+ users?: string[];
26
+ /**
27
+ * The owner of this space. The id of the User object.
28
+ * Set to `default` when there are no users in the system (no authentication).
29
+ */
30
+ owner: string;
31
+ /**
32
+ * The list of project keys added to the workspace.
33
+ * @deprecated This is not actually used.
34
+ */
35
+ projects: string[];
36
+ }
37
+
38
+ /**
39
+ * The workspace information set to a specific client what contains user specific data.
40
+ */
41
+ export interface IUserWorkspace extends IWorkspace {
42
+ access: AccessControlLevel;
43
+ }
44
+
45
+ export const DefaultOwner = 'default';
46
+
47
+ /**
48
+ * A definition of the working space for users.
49
+ *
50
+ * A working space is a logical container in the data store
51
+ * created by the system users, where they can store their projects and other data.
52
+ */
53
+ export class Workspace {
54
+ kind = Kind;
55
+ /**
56
+ * The space identifier.
57
+ */
58
+ key = '';
59
+ /**
60
+ * The name of the environment.
61
+ */
62
+ info: Thing = new Thing({ kind: ThingKind });
63
+ /**
64
+ * The list of users added to this space. May not be set when owner did not add anyone to the space.
65
+ */
66
+ users?: string[];
67
+ /**
68
+ * The owner of this space. The id of the User object.
69
+ * Set to `default` when there are no users in the system (no authentication).
70
+ */
71
+ owner = '';
72
+ /**
73
+ * The list of keys of projects added to the workspace.
74
+ * @deprecated This is not actually used.
75
+ */
76
+ projects: string[] = [];
77
+ /**
78
+ * Only set when the object was created from the data received by the ARC backend.
79
+ * Level access of the current user to the space.
80
+ * Note, this information is never serialized with the object.
81
+ */
82
+ access?: AccessControlLevel;
83
+
84
+ /**
85
+ * Creates a new Space object from a name.
86
+ *
87
+ * @param name The name to set.
88
+ * @param owner The user id that is the owner of the space.
89
+ */
90
+ static fromName(name: string, owner = DefaultOwner): Workspace {
91
+ const key = v4();
92
+ const info = new Thing({ kind: ThingKind, name });
93
+ const definition = new Workspace({
94
+ key,
95
+ kind: Kind,
96
+ info: info.toJSON(),
97
+ owner,
98
+ projects: [],
99
+ });
100
+ return definition;
101
+ }
102
+
103
+ /**
104
+ * @param input The environment definition used to restore the state.
105
+ */
106
+ constructor(input?: string | IWorkspace | IUserWorkspace) {
107
+ let init: IWorkspace;
108
+ if (typeof input === 'string') {
109
+ init = JSON.parse(input);
110
+ } else if (typeof input === 'object') {
111
+ init = input;
112
+ } else {
113
+ init = {
114
+ kind: Kind,
115
+ key: v4(),
116
+ info: {
117
+ kind: ThingKind,
118
+ name: '',
119
+ },
120
+ owner: DefaultOwner,
121
+ projects: [],
122
+ };
123
+ }
124
+ this.new(init);
125
+ }
126
+
127
+ /**
128
+ * Creates a new environment clearing anything that is so far defined.
129
+ *
130
+ * Note, this throws an error when the environment is not an ARC environment.
131
+ */
132
+ new(init: IWorkspace | IUserWorkspace): void {
133
+ if (!Workspace.isWorkspace(init)) {
134
+ throw new Error(`Not an ARC space.`);
135
+ }
136
+ const { key = v4(), projects = [], info, owner = DefaultOwner, users } = init;
137
+ this.kind = Kind;
138
+ this.key = key;
139
+ this.projects = projects;
140
+ this.owner = owner;
141
+ if (info) {
142
+ this.info = new Thing(info);
143
+ } else {
144
+ this.info = new Thing({ kind: ThingKind, name: '' });
145
+ }
146
+ if (Array.isArray(users)) {
147
+ this.users = users;
148
+ } else {
149
+ this.users = [];
150
+ }
151
+ const typed = init as IUserWorkspace;
152
+ if (typed.access) {
153
+ this.access = typed.access;
154
+ }
155
+ }
156
+
157
+ /**
158
+ * Checks whether the input is a definition of an user space.
159
+ */
160
+ static isWorkspace(input: unknown): boolean {
161
+ const typed = input as IWorkspace;
162
+ if (!input || typed.kind !== Kind) {
163
+ return false;
164
+ }
165
+ return true;
166
+ }
167
+
168
+ toJSON(): IWorkspace {
169
+ const { projects = [], owner = DefaultOwner, users } = this;
170
+ const result: IWorkspace = {
171
+ kind: Kind,
172
+ key: this.key,
173
+ info: this.info.toJSON(),
174
+ projects,
175
+ owner,
176
+ };
177
+ if (Array.isArray(users) && users.length) {
178
+ result.users = users;
179
+ }
180
+ return result;
181
+ }
182
+ }