@api-client/core 0.5.15 → 0.5.16
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/src/models/HttpProject.d.ts +85 -32
- package/build/src/models/HttpProject.js +181 -80
- package/build/src/models/HttpProject.js.map +1 -1
- package/build/src/models/ProjectFolder.d.ts +43 -6
- package/build/src/models/ProjectFolder.js +37 -12
- package/build/src/models/ProjectFolder.js.map +1 -1
- package/build/src/models/ProjectItem.d.ts +13 -6
- package/build/src/models/ProjectItem.js +24 -4
- package/build/src/models/ProjectItem.js.map +1 -1
- package/build/src/models/ProjectParent.d.ts +1 -42
- package/build/src/models/ProjectParent.js +1 -84
- package/build/src/models/ProjectParent.js.map +1 -1
- package/build/src/models/transformers/PostmanBackupTransformer.js +0 -1
- package/build/src/models/transformers/PostmanBackupTransformer.js.map +1 -1
- package/build/src/models/transformers/PostmanV21Transformer.js +0 -1
- package/build/src/models/transformers/PostmanV21Transformer.js.map +1 -1
- package/build/src/models/transformers/PostmanV2Transformer.js +0 -1
- package/build/src/models/transformers/PostmanV2Transformer.js.map +1 -1
- package/build/src/runtime/node/ProjectRequestRunner.js +1 -1
- package/build/src/runtime/node/ProjectRequestRunner.js.map +1 -1
- package/package.json +1 -1
- package/src/models/HttpProject.ts +236 -99
- package/src/models/ProjectFolder.ts +68 -17
- package/src/models/ProjectItem.ts +33 -11
- package/src/models/ProjectParent.ts +1 -110
- package/src/models/transformers/PostmanBackupTransformer.ts +0 -1
- package/src/models/transformers/PostmanV21Transformer.ts +0 -1
- package/src/models/transformers/PostmanV2Transformer.ts +0 -1
- package/src/runtime/node/ProjectRequestRunner.ts +1 -1
|
@@ -1,12 +1,15 @@
|
|
|
1
1
|
import { Kind as ProjectFolderKind, ProjectFolder } from './ProjectFolder.js';
|
|
2
2
|
import { Kind as ProjectRequestKind, ProjectRequest } from './ProjectRequest.js';
|
|
3
|
+
import { Kind as EnvironmentKind, Environment } from './Environment.js';
|
|
3
4
|
import { HttpProject } from './HttpProject.js';
|
|
4
5
|
|
|
6
|
+
type Kind = typeof ProjectFolderKind | typeof ProjectRequestKind | typeof EnvironmentKind;
|
|
7
|
+
|
|
5
8
|
export interface IProjectItem {
|
|
6
9
|
/**
|
|
7
10
|
* The kind of the item.
|
|
8
11
|
*/
|
|
9
|
-
kind:
|
|
12
|
+
kind: Kind;
|
|
10
13
|
/**
|
|
11
14
|
* The identifier in the `definitions` array of the project.
|
|
12
15
|
*/
|
|
@@ -17,7 +20,7 @@ export class ProjectItem {
|
|
|
17
20
|
/**
|
|
18
21
|
* The kind of the item.
|
|
19
22
|
*/
|
|
20
|
-
kind:
|
|
23
|
+
kind: Kind = ProjectRequestKind;
|
|
21
24
|
/**
|
|
22
25
|
* The identifier of the object in the `definitions` array of the project.
|
|
23
26
|
*/
|
|
@@ -32,16 +35,16 @@ export class ProjectItem {
|
|
|
32
35
|
*/
|
|
33
36
|
static isProjectItem(input: unknown): boolean {
|
|
34
37
|
const typed = input as IProjectItem;
|
|
35
|
-
if (!input || ![ProjectFolderKind, ProjectRequestKind].includes(typed.kind)) {
|
|
38
|
+
if (!input || ![ProjectFolderKind, ProjectRequestKind, EnvironmentKind].includes(typed.kind)) {
|
|
36
39
|
return false;
|
|
37
40
|
}
|
|
38
41
|
return true;
|
|
39
42
|
}
|
|
40
43
|
|
|
41
44
|
/**
|
|
42
|
-
* @return An instance that represents a request
|
|
45
|
+
* @return An instance that represents a request item
|
|
43
46
|
*/
|
|
44
|
-
static projectRequest(project: HttpProject, key: string)
|
|
47
|
+
static projectRequest(project: HttpProject, key: string): ProjectItem {
|
|
45
48
|
const item = new ProjectItem(project, {
|
|
46
49
|
kind: ProjectRequestKind,
|
|
47
50
|
key,
|
|
@@ -50,9 +53,9 @@ export class ProjectItem {
|
|
|
50
53
|
}
|
|
51
54
|
|
|
52
55
|
/**
|
|
53
|
-
* @return An instance that represents a folder
|
|
56
|
+
* @return An instance that represents a folder item
|
|
54
57
|
*/
|
|
55
|
-
static projectFolder(project: HttpProject, key: string)
|
|
58
|
+
static projectFolder(project: HttpProject, key: string): ProjectItem {
|
|
56
59
|
const item = new ProjectItem(project, {
|
|
57
60
|
kind: ProjectFolderKind,
|
|
58
61
|
key,
|
|
@@ -60,11 +63,22 @@ export class ProjectItem {
|
|
|
60
63
|
return item;
|
|
61
64
|
}
|
|
62
65
|
|
|
66
|
+
/**
|
|
67
|
+
* @return An instance that represents an environment item
|
|
68
|
+
*/
|
|
69
|
+
static projectEnvironment(project: HttpProject, key: string): ProjectItem {
|
|
70
|
+
const item = new ProjectItem(project, {
|
|
71
|
+
kind: EnvironmentKind,
|
|
72
|
+
key,
|
|
73
|
+
});
|
|
74
|
+
return item;
|
|
75
|
+
}
|
|
76
|
+
|
|
63
77
|
/**
|
|
64
78
|
* @param project The top-most project.
|
|
65
79
|
* @param input The project item definition used to restore the state.
|
|
66
80
|
*/
|
|
67
|
-
constructor(project: HttpProject, input: string|IProjectItem) {
|
|
81
|
+
constructor(project: HttpProject, input: string | IProjectItem) {
|
|
68
82
|
this.project = project;
|
|
69
83
|
let init: IProjectItem;
|
|
70
84
|
if (typeof input === 'string') {
|
|
@@ -78,6 +92,11 @@ export class ProjectItem {
|
|
|
78
92
|
kind: ProjectFolderKind,
|
|
79
93
|
key: '',
|
|
80
94
|
};
|
|
95
|
+
} else if (input === 'environment') {
|
|
96
|
+
init = {
|
|
97
|
+
kind: EnvironmentKind,
|
|
98
|
+
key: '',
|
|
99
|
+
};
|
|
81
100
|
} else {
|
|
82
101
|
init = JSON.parse(input);
|
|
83
102
|
}
|
|
@@ -114,7 +133,7 @@ export class ProjectItem {
|
|
|
114
133
|
/**
|
|
115
134
|
* @returns The instance of the definition associated with this item.
|
|
116
135
|
*/
|
|
117
|
-
getItem(): ProjectFolder | ProjectRequest| undefined {
|
|
136
|
+
getItem(): ProjectFolder | ProjectRequest | Environment | undefined {
|
|
118
137
|
const { project, key, kind } = this;
|
|
119
138
|
const { definitions } = project;
|
|
120
139
|
if (kind === ProjectRequestKind) {
|
|
@@ -123,12 +142,15 @@ export class ProjectItem {
|
|
|
123
142
|
if (kind === ProjectFolderKind) {
|
|
124
143
|
return definitions.folders.find(i => i.key === key);
|
|
125
144
|
}
|
|
145
|
+
if (kind === EnvironmentKind) {
|
|
146
|
+
return definitions.environments.find(i => i.key === key);
|
|
147
|
+
}
|
|
126
148
|
}
|
|
127
149
|
|
|
128
150
|
/**
|
|
129
|
-
* @returns The instance of the HttpProject or a ProjectFolder that is a
|
|
151
|
+
* @returns The instance of the HttpProject or a ProjectFolder that is a closest parent of this item.
|
|
130
152
|
*/
|
|
131
|
-
getParent(): ProjectFolder|HttpProject|undefined {
|
|
153
|
+
getParent(): ProjectFolder | HttpProject | undefined {
|
|
132
154
|
const { project, key } = this;
|
|
133
155
|
return project.findParent(key);
|
|
134
156
|
}
|
|
@@ -3,8 +3,6 @@ import { ProjectFolder } from "./ProjectFolder.js";
|
|
|
3
3
|
import { ProjectItem } from "./ProjectItem.js";
|
|
4
4
|
import { Thing, Kind as ThingKind } from "./Thing.js";
|
|
5
5
|
import { ProjectDefinitionProperty } from "./ProjectDefinitionProperty.js";
|
|
6
|
-
import { Environment, IEnvironment } from "./Environment.js";
|
|
7
|
-
import v4 from '../lib/uuid.js';
|
|
8
6
|
|
|
9
7
|
/**
|
|
10
8
|
* A class that contains a common properties and methods of an `HttpProject` and
|
|
@@ -14,12 +12,7 @@ export abstract class ProjectParent implements ProjectDefinitionProperty {
|
|
|
14
12
|
kind: unknown;
|
|
15
13
|
key: string = '';
|
|
16
14
|
/**
|
|
17
|
-
* The environments
|
|
18
|
-
* If not set it is inherited from the parent.
|
|
19
|
-
*/
|
|
20
|
-
environments: string[] = [];
|
|
21
|
-
/**
|
|
22
|
-
* The ordered list of HTTP requests / folders in the projects.
|
|
15
|
+
* The ordered list of HTTP requests, folders, or environments in the projects.
|
|
23
16
|
* The UI uses this to manipulate the view without changing the definitions.
|
|
24
17
|
*/
|
|
25
18
|
items: ProjectItem[] = [];
|
|
@@ -35,106 +28,4 @@ export abstract class ProjectParent implements ProjectDefinitionProperty {
|
|
|
35
28
|
abstract getParent(): HttpProject | ProjectFolder | undefined;
|
|
36
29
|
|
|
37
30
|
abstract getProject(): HttpProject;
|
|
38
|
-
|
|
39
|
-
/**
|
|
40
|
-
* Adds an environment to the project.
|
|
41
|
-
*
|
|
42
|
-
* @param env The definition of the environment to use to create the environment
|
|
43
|
-
* @returns The same or created environment.
|
|
44
|
-
*/
|
|
45
|
-
addEnvironment(env: IEnvironment): Environment;
|
|
46
|
-
|
|
47
|
-
/**
|
|
48
|
-
* Adds an environment to the project.
|
|
49
|
-
*
|
|
50
|
-
* @param env The instance of the environment to add
|
|
51
|
-
* @returns The same or created environment.
|
|
52
|
-
*/
|
|
53
|
-
addEnvironment(env: Environment): Environment;
|
|
54
|
-
|
|
55
|
-
/**
|
|
56
|
-
* Adds an environment to the project.
|
|
57
|
-
*
|
|
58
|
-
* @param env The name of the environment to create
|
|
59
|
-
* @returns The same or created environment.
|
|
60
|
-
*/
|
|
61
|
-
addEnvironment(env: string): Environment;
|
|
62
|
-
|
|
63
|
-
/**
|
|
64
|
-
* Adds an environment to the project.
|
|
65
|
-
* @returns The same or created environment.
|
|
66
|
-
*/
|
|
67
|
-
addEnvironment(env: IEnvironment | Environment | string): Environment {
|
|
68
|
-
if (!Array.isArray(this.environments)) {
|
|
69
|
-
this.environments = [];
|
|
70
|
-
}
|
|
71
|
-
let finalEnv;
|
|
72
|
-
if (env instanceof Environment) {
|
|
73
|
-
finalEnv = env;
|
|
74
|
-
} else if (typeof env === 'string') {
|
|
75
|
-
finalEnv = Environment.fromName(env);
|
|
76
|
-
} else {
|
|
77
|
-
finalEnv = new Environment(env);
|
|
78
|
-
}
|
|
79
|
-
if (!finalEnv.key) {
|
|
80
|
-
finalEnv.key = v4();
|
|
81
|
-
}
|
|
82
|
-
const project = this.getProject();
|
|
83
|
-
if (!project.definitions.environments) {
|
|
84
|
-
project.definitions.environments = [];
|
|
85
|
-
}
|
|
86
|
-
project.definitions.environments.push(finalEnv);
|
|
87
|
-
this.environments.push(finalEnv.key);
|
|
88
|
-
return finalEnv;
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
/**
|
|
92
|
-
*
|
|
93
|
-
* @returns The list of environments defined in this folder.
|
|
94
|
-
*/
|
|
95
|
-
getEnvironments(): Environment[] {
|
|
96
|
-
const { environments } = this;
|
|
97
|
-
if (!environments.length) {
|
|
98
|
-
return [];
|
|
99
|
-
}
|
|
100
|
-
const project = this.getProject();
|
|
101
|
-
if (!project.definitions.environments) {
|
|
102
|
-
return [];
|
|
103
|
-
}
|
|
104
|
-
const result: Environment[] = [];
|
|
105
|
-
environments.forEach((key) => {
|
|
106
|
-
const env = project.definitions.environments.find(i => i.key === key);
|
|
107
|
-
if (env) {
|
|
108
|
-
result.push(env);
|
|
109
|
-
}
|
|
110
|
-
});
|
|
111
|
-
return result;
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
/**
|
|
115
|
-
* @param key The environment key to read.
|
|
116
|
-
*/
|
|
117
|
-
getEnvironment(key: string): Environment | undefined {
|
|
118
|
-
const { environments } = this;
|
|
119
|
-
if (!environments.length) {
|
|
120
|
-
return undefined;
|
|
121
|
-
}
|
|
122
|
-
const has = environments.includes(key);
|
|
123
|
-
if (!has) {
|
|
124
|
-
return undefined;
|
|
125
|
-
}
|
|
126
|
-
const project = this.getProject();
|
|
127
|
-
if (!project.definitions.environments) {
|
|
128
|
-
return undefined;
|
|
129
|
-
}
|
|
130
|
-
return project.definitions.environments.find(i => i.key === key);
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
/**
|
|
134
|
-
* This is a link to the `getEnvironments()`. The difference is that on the
|
|
135
|
-
* project level it won't return environments defined with the class initialization.
|
|
136
|
-
*/
|
|
137
|
-
listEnvironments(): Environment[] {
|
|
138
|
-
return this.getEnvironments();
|
|
139
|
-
}
|
|
140
31
|
}
|
|
@@ -205,7 +205,7 @@ export class ProjectRequestRunner extends EventEmitter {
|
|
|
205
205
|
*/
|
|
206
206
|
protected async readEnvironments(parent: HttpProject | ProjectFolder): Promise<Environment[]> {
|
|
207
207
|
const folderKey = parent.kind === ProjectFolderKind ? (parent as ProjectFolder).key : undefined;
|
|
208
|
-
return this.project.readEnvironments({ folderKey });
|
|
208
|
+
return this.project.readEnvironments({ parent: folderKey });
|
|
209
209
|
}
|
|
210
210
|
|
|
211
211
|
/**
|