@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.
Files changed (37) hide show
  1. package/build/browser.d.ts +1 -1
  2. package/build/browser.js +1 -1
  3. package/build/browser.js.map +1 -1
  4. package/build/index.d.ts +1 -1
  5. package/build/index.js +1 -1
  6. package/build/index.js.map +1 -1
  7. package/build/src/models/Project.d.ts +41 -0
  8. package/build/src/models/Project.js +94 -0
  9. package/build/src/models/Project.js.map +1 -0
  10. package/build/src/models/RevisionInfo.d.ts +5 -0
  11. package/build/src/models/RevisionInfo.js.map +1 -1
  12. package/build/src/models/Thing.js +1 -1
  13. package/build/src/models/Thing.js.map +1 -1
  14. package/build/src/models/Workspace.d.ts +0 -17
  15. package/build/src/models/Workspace.js +3 -19
  16. package/build/src/models/Workspace.js.map +1 -1
  17. package/build/src/models/store/Deletion.d.ts +24 -0
  18. package/build/src/models/store/Deletion.js +2 -0
  19. package/build/src/models/store/Deletion.js.map +1 -0
  20. package/build/src/models/store/File.d.ts +75 -12
  21. package/build/src/models/store/File.js +120 -19
  22. package/build/src/models/store/File.js.map +1 -1
  23. package/build/src/models/store/Modification.d.ts +24 -0
  24. package/build/src/models/store/Modification.js +2 -0
  25. package/build/src/models/store/Modification.js.map +1 -0
  26. package/package.json +1 -1
  27. package/src/models/Project.ts +110 -0
  28. package/src/models/RevisionInfo.ts +6 -0
  29. package/src/models/Thing.ts +1 -1
  30. package/src/models/Workspace.ts +4 -29
  31. package/src/models/store/Deletion.ts +24 -0
  32. package/src/models/store/File.ts +146 -26
  33. package/src/models/store/Modification.ts +24 -0
  34. package/build/src/models/HttpProjectListItem.d.ts +0 -23
  35. package/build/src/models/HttpProjectListItem.js +0 -2
  36. package/build/src/models/HttpProjectListItem.js.map +0 -1
  37. package/src/models/HttpProjectListItem.ts +0 -23
@@ -1,5 +1,20 @@
1
+ import { Kind as UserKind } from './User.js';
2
+ import { Thing } from '../Thing.js';
3
+ import v4 from '../../lib/uuid.js';
1
4
  export const DefaultOwner = 'default';
2
5
  export class StoredFile {
6
+ /**
7
+ * The kind of the File
8
+ */
9
+ kind = '';
10
+ /**
11
+ * The identifier of the entity
12
+ */
13
+ key = '';
14
+ /**
15
+ * The name of the environment.
16
+ */
17
+ info = Thing.fromName('');
3
18
  /**
4
19
  * The list of parents of the object. It is an ordered list of parents
5
20
  * from the top (first element) to the lowest parent in the tree (last element).
@@ -20,52 +35,138 @@ export class StoredFile {
20
35
  */
21
36
  deleted;
22
37
  /**
23
- * The timestamp of when the file was deleted.
38
+ * The information about the delete information.
39
+ * Always set when the `delete` is true.
24
40
  */
25
- deletedTime;
26
- /**
27
- * The id of the user that has deleted the file.
28
- */
29
- deletingUser;
41
+ deletedInfo;
30
42
  /**
31
43
  * The owner of this space. The id of the User object.
32
44
  * Set to `default` when there are no users in the system (no authentication).
33
45
  */
34
- owner = '';
46
+ owner = DefaultOwner;
47
+ /**
48
+ * The last modification made to this file.
49
+ */
50
+ lastModified = { user: '', time: 0, byMe: false };
51
+ /**
52
+ * An arbitrary list of labels applied to the file.
53
+ */
54
+ labels;
35
55
  new(init) {
36
- const { parents = [], permissionIds = [], deleted, deletedTime, deletingUser, owner = DefaultOwner } = init;
56
+ const { key = v4(), info, kind, parents = [], permissionIds = [], deleted, deletedInfo, owner = DefaultOwner, lastModified, labels } = init;
57
+ this.key = key;
58
+ this.kind = kind;
59
+ if (info) {
60
+ this.info = new Thing(info);
61
+ }
62
+ else {
63
+ this.info = Thing.fromName('');
64
+ }
37
65
  this.parents = parents;
38
66
  this.permissionIds = permissionIds;
39
67
  this.owner = owner;
68
+ this.lastModified = lastModified || { user: '', time: 0, byMe: false };
40
69
  if (typeof deleted === 'boolean') {
41
70
  this.deleted = deleted;
42
- this.deletedTime = deletedTime;
43
- this.deletingUser = deletingUser;
71
+ this.deletedInfo = deletedInfo;
44
72
  }
45
73
  else {
46
74
  this.deleted = undefined;
47
- this.deletedTime = undefined;
48
- this.deletingUser = undefined;
75
+ this.deletedInfo = undefined;
76
+ }
77
+ if (Array.isArray(labels)) {
78
+ this.labels = labels;
79
+ }
80
+ else {
81
+ this.labels = undefined;
49
82
  }
50
83
  }
51
84
  toJSON() {
52
85
  const { owner = DefaultOwner } = this;
53
86
  const result = {
87
+ key: this.key,
88
+ kind: this.kind,
89
+ info: this.info.toJSON(),
54
90
  parents: this.parents,
55
91
  permissionIds: this.permissionIds,
92
+ lastModified: this.lastModified,
56
93
  owner,
57
94
  };
58
- if (typeof this.deleted === 'boolean') {
95
+ if (this.deleted) {
59
96
  result.deleted = this.deleted;
60
- if (this.deletedTime) {
61
- result.deletedTime = this.deletedTime;
62
- }
63
- if (this.deletingUser) {
64
- result.deletingUser = this.deletingUser;
65
- }
97
+ result.deletedInfo = this.deletedInfo;
98
+ }
99
+ if (Array.isArray(this.labels)) {
100
+ result.labels = this.labels;
66
101
  }
67
102
  return result;
68
103
  }
104
+ /**
105
+ * Updates the "lastModified" value.
106
+ * A helper method for a common task.
107
+ *
108
+ * @param user The user that modifies the entity.
109
+ */
110
+ setLastModified(user) {
111
+ if (!user) {
112
+ throw new Error(`The user is required.`);
113
+ }
114
+ if (user.kind !== UserKind) {
115
+ throw new Error(`Invalid value for the user when setting "lastModified".`);
116
+ }
117
+ this.lastModified = {
118
+ byMe: false,
119
+ time: Date.now(),
120
+ user: user.key,
121
+ name: user.name,
122
+ };
123
+ }
124
+ /**
125
+ * Adds a label to the list of labels.
126
+ *
127
+ * It makes sure the value is a valid, non-empty string and the `labels` array is set.
128
+ *
129
+ * It does nothing when the label already exists.
130
+ *
131
+ * @param label The label to set.
132
+ */
133
+ addLabel(label) {
134
+ if (typeof label !== 'string') {
135
+ throw new Error(`The label must be a string.`);
136
+ }
137
+ if (!label.trim()) {
138
+ throw new Error(`The label is required.`);
139
+ }
140
+ if (!Array.isArray(this.labels)) {
141
+ this.labels = [];
142
+ }
143
+ if (this.labels.includes(label)) {
144
+ return;
145
+ }
146
+ this.labels.push(label);
147
+ }
148
+ /**
149
+ * Marks the entity as deleted.
150
+ *
151
+ * A helper method for a common task.
152
+ *
153
+ * @param user The user that deletes the entity.
154
+ */
155
+ setDeleted(user) {
156
+ if (!user) {
157
+ throw new Error(`The user is required.`);
158
+ }
159
+ if (user.kind !== UserKind) {
160
+ throw new Error(`Invalid value for the user when setting "lastModified".`);
161
+ }
162
+ this.deleted = true;
163
+ this.deletedInfo = {
164
+ byMe: false,
165
+ time: Date.now(),
166
+ user: user.key,
167
+ name: user.name,
168
+ };
169
+ }
69
170
  }
70
171
  export class File extends StoredFile {
71
172
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"File.js","sourceRoot":"","sources":["../../../../src/models/store/File.ts"],"names":[],"mappings":"AAEA,MAAM,CAAC,MAAM,YAAY,GAAG,SAAS,CAAC;AAqDtC,MAAM,OAAO,UAAU;IACrB;;;;;;OAMG;IACH,OAAO,GAAa,EAAE,CAAC;IACvB;;;;;OAKG;IACH,aAAa,GAAa,EAAE,CAAC;IAC7B;;OAEG;IACH,OAAO,CAAW;IAClB;;OAEG;IACH,WAAW,CAAU;IACrB;;OAEG;IACH,YAAY,CAAU;IACtB;;;OAGG;IACH,KAAK,GAAG,EAAE,CAAC;IAEX,GAAG,CAAC,IAAiB;QACnB,MAAM,EAAE,OAAO,GAAC,EAAE,EAAE,aAAa,GAAC,EAAE,EAAE,OAAO,EAAE,WAAW,EAAE,YAAY,EAAE,KAAK,GAAG,YAAY,EAAE,GAAG,IAAI,CAAC;QACxG,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;QACvB,IAAI,CAAC,aAAa,GAAG,aAAa,CAAC;QACnC,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;QACnB,IAAI,OAAO,OAAO,KAAK,SAAS,EAAE;YAChC,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;YACvB,IAAI,CAAC,WAAW,GAAG,WAAW,CAAC;YAC/B,IAAI,CAAC,YAAY,GAAG,YAAY,CAAC;SACl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AO,GAAG,IAAI,CAAC;QACpB,IAAI,CAAC,WAAW,GAAG;YACjB,IAAI,EAAE,KAAK;YACX,IAAI,EAAE,IAAI,CAAC,GAAG,EAAE;YAChB,IAAI,EAAE,IAAI,CAAC,GAAG;YACd,IAAI,EAAE,IAAI,CAAC,IAAI;SAChB,CAAC;IACJ,CAAC;CACF;AAED,MAAM,OAAO,IAAK,SAAQ,UAAU;IAClC;;;;;OAKG;IACH,WAAW,GAAkB,EAAE,CAAC;IAEhC,GAAG,CAAC,IAAW;QACb,KAAK,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;QAChB,MAAM,EAAE,WAAW,GAAC,EAAE,EAAE,GAAG,IAAI,CAAC;QAChC,IAAI,CAAC,WAAW,GAAG,WAAW,CAAC;IACjC,CAAC;IAED,MAAM;QACJ,MAAM,MAAM,GAAU;YACpB,GAAG,KAAK,CAAC,MAAM,EAAE;YACjB,WAAW,EAAE,IAAI,CAAC,WAAW;SAC9B,CAAC;QACF,OAAO,MAAM,CAAC;IAChB,CAAC;CACF"}
@@ -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
+ }
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=Modification.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Modification.js","sourceRoot":"","sources":["../../../../src/models/store/Modification.ts"],"names":[],"mappings":""}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@api-client/core",
3
3
  "description": "The API Client's core client library. Works in NodeJS and in a ES enabled browser.",
4
- "version": "0.5.2",
4
+ "version": "0.5.3",
5
5
  "license": "Apache-2.0",
6
6
  "main": "build/index.js",
7
7
  "module": "build/index.js",
@@ -0,0 +1,110 @@
1
+ import { IFile, File, DefaultOwner } from "./store/File.js";
2
+ import { Kind as ThingKind } from './Thing.js';
3
+ import { HttpProject, IHttpProject } from './HttpProject.js';
4
+ import v4 from '../lib/uuid.js';
5
+
6
+ export const Kind = 'Core#Project';
7
+
8
+ /**
9
+ * This model represents a meta data for an HTTP project stored with the data store.
10
+ * This does not include the HTTP project entity, though, it is referenced through the same key.
11
+ *
12
+ * A concept of a project is similar to a Workspace. It is an object that is rendered in the UIs
13
+ * like a workspace but has a different meaning. On the store side, when listing workspace items,
14
+ * both spaces and projects are returned in a single query.
15
+ */
16
+ export interface IProject extends IFile {
17
+ kind: typeof Kind;
18
+ }
19
+
20
+ /**
21
+ * This model represents a meta data for an HTTP project stored with the data store.
22
+ * This does not include the HTTP project entity, though, it is referenced through the same key.
23
+ *
24
+ * A concept of a project is similar to a Workspace. It is an object that is rendered in the UIs
25
+ * like a workspace but has a different meaning. On the store side, when listing workspace items,
26
+ * both spaces and projects are returned in a single query.
27
+ */
28
+ export class Project extends File {
29
+ kind = Kind;
30
+
31
+ static fromProject(project: HttpProject | IHttpProject): Project {
32
+ let final: IHttpProject;
33
+ if (typeof (project as HttpProject).toJSON === 'function') {
34
+ final = (project as HttpProject).toJSON();
35
+ } else {
36
+ final = project as IHttpProject;
37
+ }
38
+ const init: IProject = {
39
+ kind: Kind,
40
+ key: final.key,
41
+ info: { ...final.info },
42
+ lastModified: { user: '', time: 0, byMe: false },
43
+ owner: DefaultOwner,
44
+ parents: [],
45
+ permissionIds: [],
46
+ permissions: [],
47
+ };
48
+ return new Project(init);
49
+ }
50
+
51
+ /**
52
+ * @param input The environment definition used to restore the state.
53
+ */
54
+ constructor(input?: string | IProject) {
55
+ super();
56
+ let init: IProject;
57
+ if (typeof input === 'string') {
58
+ init = JSON.parse(input);
59
+ } else if (typeof input === 'object') {
60
+ init = input;
61
+ } else {
62
+ init = {
63
+ kind: Kind,
64
+ key: v4(),
65
+ info: {
66
+ kind: ThingKind,
67
+ name: '',
68
+ },
69
+ owner: DefaultOwner,
70
+ parents: [],
71
+ permissionIds: [],
72
+ permissions: [],
73
+ lastModified: { user: '', time: 0, byMe: false },
74
+ };
75
+ }
76
+ this.new(init);
77
+ }
78
+
79
+ /**
80
+ * Creates a new environment clearing anything that is so far defined.
81
+ *
82
+ * Note, this throws an error when the environment is not a space.
83
+ */
84
+ new(init: IProject): void {
85
+ if (!Project.isWorkspace(init)) {
86
+ throw new Error(`Not a space.`);
87
+ }
88
+ super.new(init);
89
+ this.kind = Kind;
90
+ }
91
+
92
+ /**
93
+ * Checks whether the input is a definition of an user space.
94
+ */
95
+ static isWorkspace(input: unknown): boolean {
96
+ const typed = input as IProject;
97
+ if (!input || typed.kind !== Kind) {
98
+ return false;
99
+ }
100
+ return true;
101
+ }
102
+
103
+ toJSON(): IProject {
104
+ const result: IProject = {
105
+ ...super.toJSON(),
106
+ kind: Kind,
107
+ };
108
+ return result;
109
+ }
110
+ }
@@ -1,3 +1,5 @@
1
+ import { IModification } from './store/Modification.js';
2
+
1
3
  export const Kind = 'Core#Revision';
2
4
 
3
5
  /**
@@ -34,4 +36,8 @@ export interface IRevisionInfo {
34
36
  * The `json8-patch` revisions object used to restore the previous state.
35
37
  */
36
38
  patch: any[];
39
+ /**
40
+ * The modification record for this revision.
41
+ */
42
+ modification: IModification;
37
43
  }
@@ -96,7 +96,7 @@ export class Thing {
96
96
  const result: IThing = {
97
97
  kind: Kind,
98
98
  };
99
- if (this.name) {
99
+ if (typeof this.name === 'string') {
100
100
  result.name = this.name;
101
101
  }
102
102
  if (this.description) {
@@ -1,5 +1,5 @@
1
1
  import { IFile, File, DefaultOwner } from "./store/File.js";
2
- import { IThing, Thing, Kind as ThingKind } from './Thing.js';
2
+ import { Thing, Kind as ThingKind } from './Thing.js';
3
3
  import v4 from '../lib/uuid.js';
4
4
 
5
5
  export const Kind = 'Core#Space';
@@ -11,18 +11,8 @@ export const Kind = 'Core#Space';
11
11
  */
12
12
  export interface IWorkspace extends IFile {
13
13
  kind: typeof Kind;
14
- /**
15
- * The space identifier.
16
- */
17
- key: string;
18
- /**
19
- * The environment's meta info.
20
- */
21
- info: IThing;
22
14
  }
23
15
 
24
-
25
-
26
16
  /**
27
17
  * A definition of the working space for users.
28
18
  *
@@ -31,14 +21,6 @@ export interface IWorkspace extends IFile {
31
21
  */
32
22
  export class Workspace extends File {
33
23
  kind = Kind;
34
- /**
35
- * The space identifier.
36
- */
37
- key = '';
38
- /**
39
- * The name of the environment.
40
- */
41
- info: Thing = new Thing({ kind: ThingKind });
42
24
 
43
25
  /**
44
26
  * Creates a new Space object from a name.
@@ -57,6 +39,7 @@ export class Workspace extends File {
57
39
  parents: [],
58
40
  permissionIds: [],
59
41
  permissions: [],
42
+ lastModified: { user: '', time: 0, byMe: false },
60
43
  });
61
44
  return definition;
62
45
  }
@@ -83,6 +66,7 @@ export class Workspace extends File {
83
66
  parents: [],
84
67
  permissionIds: [],
85
68
  permissions: [],
69
+ lastModified: { user: '', time: 0, byMe: false },
86
70
  };
87
71
  }
88
72
  this.new(init);
@@ -98,14 +82,7 @@ export class Workspace extends File {
98
82
  throw new Error(`Not a space.`);
99
83
  }
100
84
  super.new(init);
101
- const { key = v4(), info } = init;
102
85
  this.kind = Kind;
103
- this.key = key;
104
- if (info) {
105
- this.info = new Thing(info);
106
- } else {
107
- this.info = new Thing({ kind: ThingKind, name: '' });
108
- }
109
86
  }
110
87
 
111
88
  /**
@@ -121,10 +98,8 @@ export class Workspace extends File {
121
98
 
122
99
  toJSON(): IWorkspace {
123
100
  const result: IWorkspace = {
124
- kind: Kind,
125
- key: this.key,
126
- info: this.info.toJSON(),
127
101
  ...super.toJSON(),
102
+ kind: Kind,
128
103
  };
129
104
  return result;
130
105
  }
@@ -0,0 +1,24 @@
1
+ /**
2
+ * A schema describing the delete action performed on an entity.
3
+ */
4
+ export interface IDeletion {
5
+ /**
6
+ * The timestamp of when the entity was deleted.
7
+ */
8
+ time: number;
9
+ /**
10
+ * The id of the user that has deleted the entity.
11
+ */
12
+ user?: string;
13
+ /**
14
+ * User name deleting the entity. May not be set when there's no actual user.
15
+ */
16
+ name?: string;
17
+ /**
18
+ * Whether the deletion was performed by the requesting the data user.
19
+ *
20
+ * Note for store implementers, this field should not be stored and populated every time the
21
+ * record is requested.
22
+ */
23
+ byMe: boolean;
24
+ }