@api-client/core 0.5.2 → 0.5.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/browser.d.ts +1 -1
- package/build/browser.js +1 -1
- package/build/browser.js.map +1 -1
- package/build/index.d.ts +1 -1
- package/build/index.js +1 -1
- package/build/index.js.map +1 -1
- package/build/src/models/Project.d.ts +41 -0
- package/build/src/models/Project.js +94 -0
- package/build/src/models/Project.js.map +1 -0
- package/build/src/models/RevisionInfo.d.ts +5 -0
- package/build/src/models/RevisionInfo.js.map +1 -1
- package/build/src/models/Thing.js +1 -1
- package/build/src/models/Thing.js.map +1 -1
- package/build/src/models/Workspace.d.ts +0 -17
- package/build/src/models/Workspace.js +3 -19
- package/build/src/models/Workspace.js.map +1 -1
- package/build/src/models/store/Deletion.d.ts +24 -0
- package/build/src/models/store/Deletion.js +2 -0
- package/build/src/models/store/Deletion.js.map +1 -0
- package/build/src/models/store/File.d.ts +75 -12
- package/build/src/models/store/File.js +120 -19
- package/build/src/models/store/File.js.map +1 -1
- package/build/src/models/store/Modification.d.ts +24 -0
- package/build/src/models/store/Modification.js +2 -0
- package/build/src/models/store/Modification.js.map +1 -0
- package/package.json +1 -1
- package/src/models/Project.ts +110 -0
- package/src/models/RevisionInfo.ts +6 -0
- package/src/models/Thing.ts +1 -1
- package/src/models/Workspace.ts +4 -29
- package/src/models/store/Deletion.ts +24 -0
- package/src/models/store/File.ts +146 -26
- package/src/models/store/Modification.ts +24 -0
- package/build/src/models/HttpProjectListItem.d.ts +0 -23
- package/build/src/models/HttpProjectListItem.js +0 -2
- package/build/src/models/HttpProjectListItem.js.map +0 -1
- package/src/models/HttpProjectListItem.ts +0 -23
package/src/models/store/File.ts
CHANGED
|
@@ -1,8 +1,25 @@
|
|
|
1
1
|
import { IPermission } from './Permission.js';
|
|
2
|
+
import { IModification } from './Modification.js';
|
|
3
|
+
import { IDeletion } from './Deletion.js';
|
|
4
|
+
import { IUser, Kind as UserKind } from './User.js';
|
|
5
|
+
import { IThing, Thing } from '../Thing.js';
|
|
6
|
+
import v4 from '../../lib/uuid.js';
|
|
2
7
|
|
|
3
8
|
export const DefaultOwner = 'default';
|
|
4
9
|
|
|
5
10
|
export interface IStoredFile {
|
|
11
|
+
/**
|
|
12
|
+
* The kind of the File
|
|
13
|
+
*/
|
|
14
|
+
kind: string;
|
|
15
|
+
/**
|
|
16
|
+
* The identifier of the entity
|
|
17
|
+
*/
|
|
18
|
+
key: string;
|
|
19
|
+
/**
|
|
20
|
+
* The projects's meta info.
|
|
21
|
+
*/
|
|
22
|
+
info: IThing;
|
|
6
23
|
/**
|
|
7
24
|
* The list of parents of the object. It is an ordered list of parents
|
|
8
25
|
* from the top (first element) to the lowest parent in the tree (last element).
|
|
@@ -23,17 +40,22 @@ export interface IStoredFile {
|
|
|
23
40
|
*/
|
|
24
41
|
deleted?: boolean;
|
|
25
42
|
/**
|
|
26
|
-
* The
|
|
27
|
-
|
|
28
|
-
deletedTime?: number;
|
|
29
|
-
/**
|
|
30
|
-
* The id of the user that has deleted the file.
|
|
43
|
+
* The information about the delete information.
|
|
44
|
+
* Always set when the `delete` is true.
|
|
31
45
|
*/
|
|
32
|
-
|
|
46
|
+
deletedInfo?: IDeletion;
|
|
33
47
|
/**
|
|
34
48
|
* The owner of this object. The id of the User object.
|
|
35
49
|
*/
|
|
36
50
|
owner: string;
|
|
51
|
+
/**
|
|
52
|
+
* The last modification made to this file.
|
|
53
|
+
*/
|
|
54
|
+
lastModified: IModification;
|
|
55
|
+
/**
|
|
56
|
+
* An arbitrary list of labels applied to the file.
|
|
57
|
+
*/
|
|
58
|
+
labels?: string[];
|
|
37
59
|
}
|
|
38
60
|
|
|
39
61
|
/**
|
|
@@ -54,6 +76,18 @@ export interface IFile extends IStoredFile {
|
|
|
54
76
|
}
|
|
55
77
|
|
|
56
78
|
export class StoredFile {
|
|
79
|
+
/**
|
|
80
|
+
* The kind of the File
|
|
81
|
+
*/
|
|
82
|
+
kind = '';
|
|
83
|
+
/**
|
|
84
|
+
* The identifier of the entity
|
|
85
|
+
*/
|
|
86
|
+
key = '';
|
|
87
|
+
/**
|
|
88
|
+
* The name of the environment.
|
|
89
|
+
*/
|
|
90
|
+
info: Thing = Thing.fromName('');
|
|
57
91
|
/**
|
|
58
92
|
* The list of parents of the object. It is an ordered list of parents
|
|
59
93
|
* from the top (first element) to the lowest parent in the tree (last element).
|
|
@@ -74,54 +108,140 @@ export class StoredFile {
|
|
|
74
108
|
*/
|
|
75
109
|
deleted?: boolean;
|
|
76
110
|
/**
|
|
77
|
-
* The
|
|
111
|
+
* The information about the delete information.
|
|
112
|
+
* Always set when the `delete` is true.
|
|
78
113
|
*/
|
|
79
|
-
|
|
80
|
-
/**
|
|
81
|
-
* The id of the user that has deleted the file.
|
|
82
|
-
*/
|
|
83
|
-
deletingUser?: string;
|
|
114
|
+
deletedInfo?: IDeletion;
|
|
84
115
|
/**
|
|
85
116
|
* The owner of this space. The id of the User object.
|
|
86
117
|
* Set to `default` when there are no users in the system (no authentication).
|
|
87
118
|
*/
|
|
88
|
-
owner =
|
|
119
|
+
owner = DefaultOwner;
|
|
120
|
+
/**
|
|
121
|
+
* The last modification made to this file.
|
|
122
|
+
*/
|
|
123
|
+
lastModified: IModification = { user: '', time: 0, byMe: false };
|
|
124
|
+
/**
|
|
125
|
+
* An arbitrary list of labels applied to the file.
|
|
126
|
+
*/
|
|
127
|
+
labels?: string[];
|
|
89
128
|
|
|
90
129
|
new(init: IStoredFile): void {
|
|
91
|
-
const { parents=[], permissionIds=[], deleted,
|
|
130
|
+
const { key = v4(), info, kind, parents=[], permissionIds=[], deleted, deletedInfo, owner = DefaultOwner, lastModified, labels } = init;
|
|
131
|
+
this.key = key;
|
|
132
|
+
this.kind = kind;
|
|
133
|
+
if (info) {
|
|
134
|
+
this.info = new Thing(info);
|
|
135
|
+
} else {
|
|
136
|
+
this.info = Thing.fromName('');
|
|
137
|
+
}
|
|
92
138
|
this.parents = parents;
|
|
93
139
|
this.permissionIds = permissionIds;
|
|
94
140
|
this.owner = owner;
|
|
141
|
+
this.lastModified = lastModified || { user: '', time: 0, byMe: false };
|
|
95
142
|
if (typeof deleted === 'boolean') {
|
|
96
143
|
this.deleted = deleted;
|
|
97
|
-
this.
|
|
98
|
-
this.deletingUser = deletingUser;
|
|
144
|
+
this.deletedInfo = deletedInfo;
|
|
99
145
|
} else {
|
|
100
146
|
this.deleted = undefined;
|
|
101
|
-
this.
|
|
102
|
-
|
|
147
|
+
this.deletedInfo = undefined;
|
|
148
|
+
}
|
|
149
|
+
if (Array.isArray(labels)) {
|
|
150
|
+
this.labels = labels;
|
|
151
|
+
} else {
|
|
152
|
+
this.labels = undefined;
|
|
103
153
|
}
|
|
104
154
|
}
|
|
105
155
|
|
|
106
156
|
toJSON(): IStoredFile {
|
|
107
157
|
const { owner = DefaultOwner } = this;
|
|
108
158
|
const result: IStoredFile = {
|
|
159
|
+
key: this.key,
|
|
160
|
+
kind: this.kind,
|
|
161
|
+
info: this.info.toJSON(),
|
|
109
162
|
parents: this.parents,
|
|
110
163
|
permissionIds: this.permissionIds,
|
|
164
|
+
lastModified: this.lastModified,
|
|
111
165
|
owner,
|
|
112
166
|
};
|
|
113
|
-
if (
|
|
167
|
+
if (this.deleted) {
|
|
114
168
|
result.deleted = this.deleted;
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
if (this.deletingUser) {
|
|
120
|
-
result.deletingUser = this.deletingUser;
|
|
121
|
-
}
|
|
169
|
+
result.deletedInfo = this.deletedInfo;
|
|
170
|
+
}
|
|
171
|
+
if (Array.isArray(this.labels)) {
|
|
172
|
+
result.labels = this.labels;
|
|
122
173
|
}
|
|
123
174
|
return result;
|
|
124
175
|
}
|
|
176
|
+
|
|
177
|
+
/**
|
|
178
|
+
* Updates the "lastModified" value.
|
|
179
|
+
* A helper method for a common task.
|
|
180
|
+
*
|
|
181
|
+
* @param user The user that modifies the entity.
|
|
182
|
+
*/
|
|
183
|
+
setLastModified(user: IUser): void {
|
|
184
|
+
if (!user) {
|
|
185
|
+
throw new Error(`The user is required.`);
|
|
186
|
+
}
|
|
187
|
+
if (user.kind !== UserKind) {
|
|
188
|
+
throw new Error(`Invalid value for the user when setting "lastModified".`);
|
|
189
|
+
}
|
|
190
|
+
this.lastModified = {
|
|
191
|
+
byMe: false,
|
|
192
|
+
time: Date.now(),
|
|
193
|
+
user: user.key,
|
|
194
|
+
name: user.name,
|
|
195
|
+
};
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
/**
|
|
199
|
+
* Adds a label to the list of labels.
|
|
200
|
+
*
|
|
201
|
+
* It makes sure the value is a valid, non-empty string and the `labels` array is set.
|
|
202
|
+
*
|
|
203
|
+
* It does nothing when the label already exists.
|
|
204
|
+
*
|
|
205
|
+
* @param label The label to set.
|
|
206
|
+
*/
|
|
207
|
+
addLabel(label: string): void {
|
|
208
|
+
if (typeof label !== 'string') {
|
|
209
|
+
throw new Error(`The label must be a string.`);
|
|
210
|
+
}
|
|
211
|
+
if (!label.trim()) {
|
|
212
|
+
throw new Error(`The label is required.`);
|
|
213
|
+
}
|
|
214
|
+
if (!Array.isArray(this.labels)) {
|
|
215
|
+
this.labels = [];
|
|
216
|
+
}
|
|
217
|
+
if (this.labels.includes(label)) {
|
|
218
|
+
return;
|
|
219
|
+
}
|
|
220
|
+
this.labels.push(label);
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
/**
|
|
224
|
+
* Marks the entity as deleted.
|
|
225
|
+
*
|
|
226
|
+
* A helper method for a common task.
|
|
227
|
+
*
|
|
228
|
+
* @param user The user that deletes the entity.
|
|
229
|
+
*/
|
|
230
|
+
setDeleted(user: IUser): void {
|
|
231
|
+
if (!user) {
|
|
232
|
+
throw new Error(`The user is required.`);
|
|
233
|
+
}
|
|
234
|
+
if (user.kind !== UserKind) {
|
|
235
|
+
throw new Error(`Invalid value for the user when setting "lastModified".`);
|
|
236
|
+
}
|
|
237
|
+
this.deleted = true;
|
|
238
|
+
this.deletedInfo = {
|
|
239
|
+
byMe: false,
|
|
240
|
+
time: Date.now(),
|
|
241
|
+
user: user.key,
|
|
242
|
+
name: user.name,
|
|
243
|
+
};
|
|
244
|
+
}
|
|
125
245
|
}
|
|
126
246
|
|
|
127
247
|
export class File extends StoredFile {
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Information about a modification of a File.
|
|
3
|
+
*/
|
|
4
|
+
export interface IModification {
|
|
5
|
+
/**
|
|
6
|
+
* The key of the user modifying the record.
|
|
7
|
+
*/
|
|
8
|
+
user: string;
|
|
9
|
+
/**
|
|
10
|
+
* User name modifying the record. May not be set when there's no actual user.
|
|
11
|
+
*/
|
|
12
|
+
name?: string;
|
|
13
|
+
/**
|
|
14
|
+
* Whether the modification was performed by the requesting the data user.
|
|
15
|
+
*
|
|
16
|
+
* Note for store implementers, this field should not be stored and populated every time the
|
|
17
|
+
* record is requested.
|
|
18
|
+
*/
|
|
19
|
+
byMe: boolean;
|
|
20
|
+
/**
|
|
21
|
+
* A timestamp when the object was modified.
|
|
22
|
+
*/
|
|
23
|
+
time: number;
|
|
24
|
+
}
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
export declare const Kind = "Core#HttpProjectListItem";
|
|
2
|
-
/**
|
|
3
|
-
* The HTTP Project definition to be used in lists.
|
|
4
|
-
*/
|
|
5
|
-
export interface IHttpProjectListItem {
|
|
6
|
-
/**
|
|
7
|
-
* The data store key of the project.
|
|
8
|
-
*/
|
|
9
|
-
key: string;
|
|
10
|
-
/**
|
|
11
|
-
* Project's name
|
|
12
|
-
*/
|
|
13
|
-
name: string;
|
|
14
|
-
/**
|
|
15
|
-
* Whether the project is one of the favourites.
|
|
16
|
-
* May be used by an UI to add projects to favourites.
|
|
17
|
-
*/
|
|
18
|
-
favourite?: boolean;
|
|
19
|
-
/**
|
|
20
|
-
* The timestamp when the project was last updated.
|
|
21
|
-
*/
|
|
22
|
-
updated: number;
|
|
23
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"HttpProjectListItem.js","sourceRoot":"","sources":["../../../src/models/HttpProjectListItem.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,IAAI,GAAG,0BAA0B,CAAC"}
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
export const Kind = 'Core#HttpProjectListItem';
|
|
2
|
-
/**
|
|
3
|
-
* The HTTP Project definition to be used in lists.
|
|
4
|
-
*/
|
|
5
|
-
export interface IHttpProjectListItem {
|
|
6
|
-
/**
|
|
7
|
-
* The data store key of the project.
|
|
8
|
-
*/
|
|
9
|
-
key: string;
|
|
10
|
-
/**
|
|
11
|
-
* Project's name
|
|
12
|
-
*/
|
|
13
|
-
name: string;
|
|
14
|
-
/**
|
|
15
|
-
* Whether the project is one of the favourites.
|
|
16
|
-
* May be used by an UI to add projects to favourites.
|
|
17
|
-
*/
|
|
18
|
-
favourite?: boolean;
|
|
19
|
-
/**
|
|
20
|
-
* The timestamp when the project was last updated.
|
|
21
|
-
*/
|
|
22
|
-
updated: number;
|
|
23
|
-
}
|