@api-client/core 0.19.17 → 0.19.18
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/browser.d.ts +12 -12
- package/build/src/browser.d.ts.map +1 -1
- package/build/src/browser.js +3 -3
- package/build/src/browser.js.map +1 -1
- package/build/src/index.d.ts +12 -12
- package/build/src/index.d.ts.map +1 -1
- package/build/src/index.js +3 -3
- package/build/src/index.js.map +1 -1
- package/build/src/mocking/ProjectMock.d.ts +1 -1
- package/build/src/mocking/ProjectMock.d.ts.map +1 -1
- package/build/src/mocking/ProjectMock.js.map +1 -1
- package/build/src/mocking/lib/File.d.ts +5 -5
- package/build/src/mocking/lib/File.d.ts.map +1 -1
- package/build/src/mocking/lib/File.js.map +1 -1
- package/build/src/mocking/lib/Organization.d.ts +3 -3
- package/build/src/mocking/lib/Organization.d.ts.map +1 -1
- package/build/src/mocking/lib/Organization.js +2 -1
- package/build/src/mocking/lib/Organization.js.map +1 -1
- package/build/src/mocking/lib/Permission.d.ts +6 -6
- package/build/src/mocking/lib/Permission.d.ts.map +1 -1
- package/build/src/mocking/lib/Permission.js.map +1 -1
- package/build/src/mocking/lib/User.d.ts +8 -4
- package/build/src/mocking/lib/User.d.ts.map +1 -1
- package/build/src/mocking/lib/User.js.map +1 -1
- package/build/src/modeling/ApiFile.d.ts +8 -4
- package/build/src/modeling/ApiFile.d.ts.map +1 -1
- package/build/src/modeling/ApiFile.js.map +1 -1
- package/build/src/modeling/ApiModel.d.ts +2 -2
- package/build/src/modeling/ApiModel.d.ts.map +1 -1
- package/build/src/modeling/ApiModel.js.map +1 -1
- package/build/src/modeling/DataDomain.d.ts +2 -2
- package/build/src/modeling/DataDomain.d.ts.map +1 -1
- package/build/src/modeling/DataDomain.js.map +1 -1
- package/build/src/modeling/DomainAssociation.d.ts +2 -2
- package/build/src/modeling/DomainAssociation.d.ts.map +1 -1
- package/build/src/modeling/DomainAssociation.js.map +1 -1
- package/build/src/modeling/DomainEntity.d.ts +2 -2
- package/build/src/modeling/DomainEntity.d.ts.map +1 -1
- package/build/src/modeling/DomainEntity.js.map +1 -1
- package/build/src/modeling/DomainFile.d.ts +8 -4
- package/build/src/modeling/DomainFile.d.ts.map +1 -1
- package/build/src/modeling/DomainFile.js.map +1 -1
- package/build/src/modeling/DomainModel.d.ts +2 -2
- package/build/src/modeling/DomainModel.d.ts.map +1 -1
- package/build/src/modeling/DomainModel.js.map +1 -1
- package/build/src/modeling/DomainNamespace.d.ts +2 -2
- package/build/src/modeling/DomainNamespace.d.ts.map +1 -1
- package/build/src/modeling/DomainNamespace.js.map +1 -1
- package/build/src/modeling/DomainProperty.d.ts +2 -2
- package/build/src/modeling/DomainProperty.d.ts.map +1 -1
- package/build/src/modeling/DomainProperty.js.map +1 -1
- package/build/src/modeling/helpers/Intelisense.d.ts +38 -38
- package/build/src/modeling/helpers/Intelisense.d.ts.map +1 -1
- package/build/src/modeling/helpers/Intelisense.js.map +1 -1
- package/build/src/models/AiMessage.d.ts +3 -3
- package/build/src/models/AiMessage.d.ts.map +1 -1
- package/build/src/models/AiMessage.js.map +1 -1
- package/build/src/models/AiSession.d.ts +3 -3
- package/build/src/models/AiSession.d.ts.map +1 -1
- package/build/src/models/AiSession.js.map +1 -1
- package/build/src/models/CertificateFile.d.ts +2 -2
- package/build/src/models/CertificateFile.d.ts.map +1 -1
- package/build/src/models/CertificateFile.js.map +1 -1
- package/build/src/models/Environment.d.ts +2 -2
- package/build/src/models/Environment.d.ts.map +1 -1
- package/build/src/models/Environment.js.map +1 -1
- package/build/src/models/Folder.d.ts +9 -5
- package/build/src/models/Folder.d.ts.map +1 -1
- package/build/src/models/Folder.js.map +1 -1
- package/build/src/models/HttpProject.d.ts +2 -2
- package/build/src/models/HttpProject.d.ts.map +1 -1
- package/build/src/models/HttpProject.js.map +1 -1
- package/build/src/models/ProjectFolder.d.ts +2 -2
- package/build/src/models/ProjectFolder.d.ts.map +1 -1
- package/build/src/models/ProjectFolder.js.map +1 -1
- package/build/src/models/Request.d.ts +3 -3
- package/build/src/models/Request.d.ts.map +1 -1
- package/build/src/models/Request.js.map +1 -1
- package/build/src/models/Thing.d.ts +9 -5
- package/build/src/models/Thing.d.ts.map +1 -1
- package/build/src/models/Thing.js.map +1 -1
- package/build/src/models/TrashEntry.d.ts +2 -2
- package/build/src/models/TrashEntry.d.ts.map +1 -1
- package/build/src/models/TrashEntry.js.map +1 -1
- package/build/src/models/store/Capabilities.d.ts +5 -1
- package/build/src/models/store/Capabilities.d.ts.map +1 -1
- package/build/src/models/store/Capabilities.js.map +1 -1
- package/build/src/models/store/Deletion.d.ts +5 -1
- package/build/src/models/store/Deletion.d.ts.map +1 -1
- package/build/src/models/store/Deletion.js.map +1 -1
- package/build/src/models/store/File.d.ts +45 -37
- package/build/src/models/store/File.d.ts.map +1 -1
- package/build/src/models/store/File.js +1 -1
- package/build/src/models/store/File.js.map +1 -1
- package/build/src/models/store/Group.d.ts +3 -3
- package/build/src/models/store/Group.d.ts.map +1 -1
- package/build/src/models/store/Group.js.map +1 -1
- package/build/src/models/store/Invitation.d.ts +3 -3
- package/build/src/models/store/Invitation.d.ts.map +1 -1
- package/build/src/models/store/Invitation.js.map +1 -1
- package/build/src/models/store/Modification.d.ts +5 -1
- package/build/src/models/store/Modification.d.ts.map +1 -1
- package/build/src/models/store/Modification.js.map +1 -1
- package/build/src/models/store/Organization.d.ts +18 -13
- package/build/src/models/store/Organization.d.ts.map +1 -1
- package/build/src/models/store/Organization.js +29 -47
- package/build/src/models/store/Organization.js.map +1 -1
- package/build/src/models/store/Permission.d.ts +9 -5
- package/build/src/models/store/Permission.d.ts.map +1 -1
- package/build/src/models/store/Permission.js.map +1 -1
- package/build/src/models/store/User.d.ts +18 -6
- package/build/src/models/store/User.d.ts.map +1 -1
- package/build/src/models/store/User.js.map +1 -1
- package/build/src/models/store/UserIdentity.d.ts +9 -5
- package/build/src/models/store/UserIdentity.d.ts.map +1 -1
- package/build/src/models/store/UserIdentity.js.map +1 -1
- package/build/src/sdk/FilesSdk.d.ts +15 -15
- package/build/src/sdk/FilesSdk.d.ts.map +1 -1
- package/build/src/sdk/FilesSdk.js +1 -1
- package/build/src/sdk/FilesSdk.js.map +1 -1
- package/build/src/sdk/OrganizationsSdk.d.ts +9 -9
- package/build/src/sdk/OrganizationsSdk.d.ts.map +1 -1
- package/build/src/sdk/OrganizationsSdk.js.map +1 -1
- package/build/src/sdk/SdkMock.js +6 -6
- package/build/src/sdk/SdkMock.js.map +1 -1
- package/build/src/sdk/SharedSdk.d.ts +2 -2
- package/build/src/sdk/SharedSdk.d.ts.map +1 -1
- package/build/src/sdk/SharedSdk.js.map +1 -1
- package/build/src/sdk/StoreSdkNode.d.ts +1 -1
- package/build/src/sdk/StoreSdkNode.d.ts.map +1 -1
- package/build/src/sdk/StoreSdkNode.js.map +1 -1
- package/build/src/sdk/StoreSdkWeb.d.ts +1 -1
- package/build/src/sdk/StoreSdkWeb.d.ts.map +1 -1
- package/build/src/sdk/StoreSdkWeb.js.map +1 -1
- package/build/src/sdk/UsersSdk.d.ts +5 -5
- package/build/src/sdk/UsersSdk.d.ts.map +1 -1
- package/build/src/sdk/UsersSdk.js.map +1 -1
- package/build/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/src/mocking/ProjectMock.ts +1 -1
- package/src/mocking/lib/File.ts +5 -5
- package/src/mocking/lib/Organization.ts +5 -3
- package/src/mocking/lib/Permission.ts +8 -8
- package/src/mocking/lib/User.ts +11 -6
- package/src/modeling/ApiFile.ts +11 -6
- package/src/modeling/ApiModel.ts +2 -2
- package/src/modeling/DataDomain.ts +2 -2
- package/src/modeling/DomainAssociation.ts +2 -2
- package/src/modeling/DomainEntity.ts +2 -2
- package/src/modeling/DomainFile.ts +11 -6
- package/src/modeling/DomainModel.ts +2 -2
- package/src/modeling/DomainNamespace.ts +2 -2
- package/src/modeling/DomainProperty.ts +2 -2
- package/src/modeling/helpers/Intelisense.ts +41 -38
- package/src/models/AiMessage.ts +3 -3
- package/src/models/AiSession.ts +3 -3
- package/src/models/CertificateFile.ts +2 -2
- package/src/models/Environment.ts +2 -2
- package/src/models/Folder.ts +13 -8
- package/src/models/HttpProject.ts +2 -2
- package/src/models/ProjectFolder.ts +2 -2
- package/src/models/Request.ts +3 -3
- package/src/models/Thing.ts +14 -9
- package/src/models/TrashEntry.ts +2 -2
- package/src/models/store/Capabilities.ts +6 -1
- package/src/models/store/Deletion.ts +6 -1
- package/src/models/store/File.ts +53 -43
- package/src/models/store/Group.ts +3 -3
- package/src/models/store/Invitation.ts +3 -3
- package/src/models/store/Modification.ts +6 -1
- package/src/models/store/Organization.ts +45 -60
- package/src/models/store/Permission.ts +17 -12
- package/src/models/store/User.ts +21 -6
- package/src/models/store/UserIdentity.ts +13 -8
- package/src/sdk/FilesSdk.ts +29 -25
- package/src/sdk/OrganizationsSdk.ts +20 -16
- package/src/sdk/SdkMock.ts +16 -16
- package/src/sdk/SharedSdk.ts +3 -3
- package/src/sdk/StoreSdkNode.ts +3 -3
- package/src/sdk/StoreSdkWeb.ts +3 -3
- package/src/sdk/UsersSdk.ts +6 -6
- package/tests/unit/mocking/current/File.spec.ts +5 -5
- package/tests/unit/mocking/current/Organization.spec.ts +4 -3
- package/tests/unit/mocking/current/Permission.spec.ts +2 -2
- package/tests/unit/mocking/current/User.spec.ts +2 -2
- package/tests/unit/modeling/domain_file.spec.ts +3 -3
- package/tests/unit/models/File/createFileCapabilities.spec.ts +3 -3
- package/tests/unit/models/File/new.spec.ts +2 -2
- package/tests/unit/models/File/setDeleted.spec.ts +3 -3
- package/tests/unit/models/File/setLastModified.spec.ts +3 -3
- package/tests/unit/models/File/toJSON.spec.ts +2 -2
- package/tests/unit/models/Folder/create.spec.ts +3 -3
- package/tests/unit/models/Permission/all.spec.ts +3 -3
- package/tests/unit/models/store/Invitation.spec.ts +2 -2
- package/tests/unit/models/store/Organization.spec.ts +100 -0
- package/tests/unit/models/store/Permission.spec.ts +16 -6
- package/tests/unit/models/thing.spec.ts +3 -3
package/src/models/store/File.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { nanoid } from '../../nanoid.js'
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
2
|
+
import { PermissionSchema, Permission, PermissionRole } from './Permission.js'
|
|
3
|
+
import { ModificationSchema } from './Modification.js'
|
|
4
|
+
import { DeletionSchema } from './Deletion.js'
|
|
5
|
+
import { UserSchema, Kind as UserKind } from './User.js'
|
|
6
|
+
import { ThingSchema, Thing } from '../Thing.js'
|
|
7
|
+
import { CapabilitiesSchema } from './Capabilities.js'
|
|
8
8
|
import { FolderKind } from '../kinds.js'
|
|
9
9
|
// this causes error
|
|
10
10
|
// import { Kind as FolderKind } from '../Folder.js';
|
|
@@ -42,7 +42,7 @@ export interface FileBreadcrumb {
|
|
|
42
42
|
name: string
|
|
43
43
|
}
|
|
44
44
|
|
|
45
|
-
export interface
|
|
45
|
+
export interface StoredFileSchema {
|
|
46
46
|
/**
|
|
47
47
|
* The kind of the File
|
|
48
48
|
*/
|
|
@@ -54,7 +54,7 @@ export interface IStoredFile {
|
|
|
54
54
|
/**
|
|
55
55
|
* The file's meta info.
|
|
56
56
|
*/
|
|
57
|
-
info:
|
|
57
|
+
info: ThingSchema
|
|
58
58
|
/**
|
|
59
59
|
* The color of the icon to render for this file in the file explorer.
|
|
60
60
|
* This should be a hex format, e.g.: #c00 for red.
|
|
@@ -71,11 +71,16 @@ export interface IStoredFile {
|
|
|
71
71
|
shortcutTarget?: string
|
|
72
72
|
}
|
|
73
73
|
|
|
74
|
+
/**
|
|
75
|
+
* @deprecated Use {@link StoredFileSchema} instead.
|
|
76
|
+
*/
|
|
77
|
+
export type IStoredFile = StoredFileSchema
|
|
78
|
+
|
|
74
79
|
/**
|
|
75
80
|
* An interface describing an object in the data store that
|
|
76
81
|
* describes a file or an object that can be treated as a file or a folder.
|
|
77
82
|
*/
|
|
78
|
-
export interface
|
|
83
|
+
export interface FileSchema extends StoredFileSchema {
|
|
79
84
|
/**
|
|
80
85
|
* The list of parents of the object. It is an ordered list of parents
|
|
81
86
|
* from the top (first element) to the lowest parent in the tree (last element).
|
|
@@ -99,11 +104,11 @@ export interface IFile extends IStoredFile {
|
|
|
99
104
|
* The information about the delete information.
|
|
100
105
|
* Always set when the `delete` is true.
|
|
101
106
|
*/
|
|
102
|
-
deletedInfo?:
|
|
107
|
+
deletedInfo?: DeletionSchema
|
|
103
108
|
/**
|
|
104
109
|
* The last modification made to this file.
|
|
105
110
|
*/
|
|
106
|
-
lastModified:
|
|
111
|
+
lastModified: ModificationSchema
|
|
107
112
|
/**
|
|
108
113
|
* An arbitrary list of labels applied to the file.
|
|
109
114
|
*/
|
|
@@ -114,7 +119,7 @@ export interface IFile extends IStoredFile {
|
|
|
114
119
|
*
|
|
115
120
|
* This is a readonly field and it is ignored when creating / updating the file.
|
|
116
121
|
*/
|
|
117
|
-
capabilities?:
|
|
122
|
+
capabilities?: CapabilitiesSchema
|
|
118
123
|
/**
|
|
119
124
|
* Populated by the server when reading the file. The list of permissions to the object.
|
|
120
125
|
*
|
|
@@ -124,7 +129,7 @@ export interface IFile extends IStoredFile {
|
|
|
124
129
|
* Data store implementation note, this is not stored in the store but it is populated
|
|
125
130
|
* when reading the object.
|
|
126
131
|
*/
|
|
127
|
-
permissions:
|
|
132
|
+
permissions: PermissionSchema[]
|
|
128
133
|
/**
|
|
129
134
|
* Populated by the store in some situations. If it's missing then you should request
|
|
130
135
|
* breadcrumbs from the store.
|
|
@@ -132,6 +137,11 @@ export interface IFile extends IStoredFile {
|
|
|
132
137
|
breadcrumb?: FileBreadcrumb[]
|
|
133
138
|
}
|
|
134
139
|
|
|
140
|
+
/**
|
|
141
|
+
* @deprecated Use {@link FileSchema} instead.
|
|
142
|
+
*/
|
|
143
|
+
export type IFile = FileSchema
|
|
144
|
+
|
|
135
145
|
const parentsSymbol = Symbol('parents')
|
|
136
146
|
const deletedSymbol = Symbol('deleted')
|
|
137
147
|
const deletedInfoSymbol = Symbol('deletedInfo')
|
|
@@ -188,9 +198,9 @@ export class StoredFile {
|
|
|
188
198
|
* @param input The input to create the file schema.
|
|
189
199
|
* @returns The file schema object.
|
|
190
200
|
*/
|
|
191
|
-
static createSchema(input: Partial<
|
|
201
|
+
static createSchema(input: Partial<StoredFileSchema> = {}): StoredFileSchema {
|
|
192
202
|
const { key = nanoid(), kind, iconColor, shortcutTarget } = input
|
|
193
|
-
const result:
|
|
203
|
+
const result: StoredFileSchema = {
|
|
194
204
|
key,
|
|
195
205
|
kind: kind || '',
|
|
196
206
|
info: Thing.fromJSON(input.info, { name: 'Unnamed file' }).toJSON(),
|
|
@@ -205,7 +215,7 @@ export class StoredFile {
|
|
|
205
215
|
return result
|
|
206
216
|
}
|
|
207
217
|
|
|
208
|
-
constructor(state:
|
|
218
|
+
constructor(state: StoredFileSchema) {
|
|
209
219
|
this.kind = state.kind
|
|
210
220
|
this.key = state.key
|
|
211
221
|
this.info = new Thing(state.info)
|
|
@@ -220,7 +230,7 @@ export class StoredFile {
|
|
|
220
230
|
/**
|
|
221
231
|
* @deprecated Use `createSchema()` and setup values in the constructor instead.
|
|
222
232
|
*/
|
|
223
|
-
new(init:
|
|
233
|
+
new(init: StoredFileSchema): this {
|
|
224
234
|
const { key = nanoid(), info, kind, iconColor, shortcutTarget } = init
|
|
225
235
|
this.key = key
|
|
226
236
|
this.kind = kind
|
|
@@ -242,8 +252,8 @@ export class StoredFile {
|
|
|
242
252
|
return this
|
|
243
253
|
}
|
|
244
254
|
|
|
245
|
-
toJSON():
|
|
246
|
-
const result:
|
|
255
|
+
toJSON(): StoredFileSchema {
|
|
256
|
+
const result: StoredFileSchema = {
|
|
247
257
|
key: this.key,
|
|
248
258
|
kind: this.kind,
|
|
249
259
|
info: this.info.toJSON(),
|
|
@@ -264,13 +274,13 @@ export class StoredFile {
|
|
|
264
274
|
* @param file The file object to create the capabilities to. The object is not mutated.
|
|
265
275
|
* @param role The user role to the file.
|
|
266
276
|
*/
|
|
267
|
-
static createFileCapabilities(file:
|
|
277
|
+
static createFileCapabilities(file: StoredFileSchema | StoredFile, role?: PermissionRole): CapabilitiesSchema {
|
|
268
278
|
const isCommenter = Permission.hasRole('commenter', role)
|
|
269
279
|
const isOwner = Permission.hasRole('owner', role)
|
|
270
280
|
const isReader = Permission.hasRole('reader', role)
|
|
271
281
|
const isWriter = Permission.hasRole('writer', role)
|
|
272
282
|
const isFolder = file.kind === FolderKind
|
|
273
|
-
const result:
|
|
283
|
+
const result: CapabilitiesSchema = {
|
|
274
284
|
canReadMedia: !isFolder && isReader,
|
|
275
285
|
canListChildren: isFolder && isReader,
|
|
276
286
|
canComment: !isFolder && isCommenter,
|
|
@@ -287,20 +297,20 @@ export class StoredFile {
|
|
|
287
297
|
return result
|
|
288
298
|
}
|
|
289
299
|
|
|
290
|
-
createFileCapabilities(role: PermissionRole):
|
|
300
|
+
createFileCapabilities(role: PermissionRole): CapabilitiesSchema {
|
|
291
301
|
return File.createFileCapabilities(this, role)
|
|
292
302
|
}
|
|
293
303
|
|
|
294
304
|
/**
|
|
295
305
|
* Mutates the file object by setting the `byMe` properties (on deleted and modified info)
|
|
296
306
|
*
|
|
297
|
-
* Note, this can be done only on file schema (
|
|
307
|
+
* Note, this can be done only on file schema (FileSchema). The `File` object has
|
|
298
308
|
* this properties frozen.
|
|
299
309
|
*
|
|
300
310
|
* @param file The file to mutate
|
|
301
311
|
* @param user The user key to compare.
|
|
302
312
|
*/
|
|
303
|
-
static updateByMeMeta(file:
|
|
313
|
+
static updateByMeMeta(file: FileSchema, user: string): void {
|
|
304
314
|
if (file.deletedInfo) {
|
|
305
315
|
file.deletedInfo.byMe = file.deletedInfo.user === user
|
|
306
316
|
}
|
|
@@ -317,7 +327,7 @@ export class StoredFile {
|
|
|
317
327
|
* @param user The user that modifies the file.
|
|
318
328
|
* @returns The same file.
|
|
319
329
|
*/
|
|
320
|
-
static setLastModified(file:
|
|
330
|
+
static setLastModified(file: FileSchema, user: UserSchema): FileSchema {
|
|
321
331
|
if (!file) {
|
|
322
332
|
throw new Error(`The file is required.`)
|
|
323
333
|
}
|
|
@@ -344,7 +354,7 @@ export class StoredFile {
|
|
|
344
354
|
* @param user The deleting user
|
|
345
355
|
* @returns The same file reference.
|
|
346
356
|
*/
|
|
347
|
-
static setDeleted(file:
|
|
357
|
+
static setDeleted(file: FileSchema, user: UserSchema): FileSchema {
|
|
348
358
|
if (!file) {
|
|
349
359
|
throw new Error(`The file is required.`)
|
|
350
360
|
}
|
|
@@ -400,22 +410,22 @@ export class File extends StoredFile {
|
|
|
400
410
|
return this[deletedSymbol] || false
|
|
401
411
|
}
|
|
402
412
|
|
|
403
|
-
[deletedInfoSymbol]?: Readonly<
|
|
413
|
+
[deletedInfoSymbol]?: Readonly<DeletionSchema>
|
|
404
414
|
|
|
405
415
|
/**
|
|
406
416
|
* The information about the delete information.
|
|
407
417
|
* Always set when the `delete` is true.
|
|
408
418
|
*/
|
|
409
|
-
get deletedInfo(): Readonly<
|
|
419
|
+
get deletedInfo(): Readonly<DeletionSchema> | undefined {
|
|
410
420
|
return this[deletedInfoSymbol]
|
|
411
421
|
}
|
|
412
422
|
|
|
413
|
-
[lastModifiedSymbol]: Readonly<
|
|
423
|
+
[lastModifiedSymbol]: Readonly<ModificationSchema> = { user: '', time: 0, byMe: false }
|
|
414
424
|
|
|
415
425
|
/**
|
|
416
426
|
* The last modification made to this file.
|
|
417
427
|
*/
|
|
418
|
-
get lastModified(): Readonly<
|
|
428
|
+
get lastModified(): Readonly<ModificationSchema> {
|
|
419
429
|
return this[lastModifiedSymbol]
|
|
420
430
|
}
|
|
421
431
|
|
|
@@ -424,7 +434,7 @@ export class File extends StoredFile {
|
|
|
424
434
|
*/
|
|
425
435
|
labels?: string[];
|
|
426
436
|
|
|
427
|
-
[capabilitiesSymbol]?: Readonly<
|
|
437
|
+
[capabilitiesSymbol]?: Readonly<CapabilitiesSchema>
|
|
428
438
|
|
|
429
439
|
/**
|
|
430
440
|
* This is populated when reading a file from the store.
|
|
@@ -432,11 +442,11 @@ export class File extends StoredFile {
|
|
|
432
442
|
*
|
|
433
443
|
* This is a readonly field and it is ignored when creating / updating the file.
|
|
434
444
|
*/
|
|
435
|
-
get capabilities(): Readonly<
|
|
445
|
+
get capabilities(): Readonly<CapabilitiesSchema> | undefined {
|
|
436
446
|
return this[capabilitiesSymbol]
|
|
437
447
|
}
|
|
438
448
|
|
|
439
|
-
[permissionsSymbol]: readonly
|
|
449
|
+
[permissionsSymbol]: readonly PermissionSchema[] = []
|
|
440
450
|
|
|
441
451
|
/**
|
|
442
452
|
* Populated by the server when reading the file. The list of permissions to the object.
|
|
@@ -444,12 +454,12 @@ export class File extends StoredFile {
|
|
|
444
454
|
* This property cannot be manipulated directly by the client. Should be treated as
|
|
445
455
|
* opaque value.
|
|
446
456
|
*/
|
|
447
|
-
get permissions(): readonly
|
|
457
|
+
get permissions(): readonly PermissionSchema[] {
|
|
448
458
|
return this[permissionsSymbol]
|
|
449
459
|
}
|
|
450
460
|
|
|
451
|
-
static override createSchema(input: Partial<
|
|
452
|
-
const result = StoredFile.createSchema(input) as
|
|
461
|
+
static override createSchema(input: Partial<FileSchema> = {}): FileSchema {
|
|
462
|
+
const result = StoredFile.createSchema(input) as FileSchema
|
|
453
463
|
if (Array.isArray(input.parents)) {
|
|
454
464
|
result.parents = [...input.parents]
|
|
455
465
|
} else {
|
|
@@ -486,7 +496,7 @@ export class File extends StoredFile {
|
|
|
486
496
|
return result
|
|
487
497
|
}
|
|
488
498
|
|
|
489
|
-
constructor(state?: Partial<
|
|
499
|
+
constructor(state?: Partial<FileSchema>) {
|
|
490
500
|
const init = File.createSchema(state)
|
|
491
501
|
super(init)
|
|
492
502
|
this[parentsSymbol] = [...init.parents]
|
|
@@ -506,7 +516,7 @@ export class File extends StoredFile {
|
|
|
506
516
|
/**
|
|
507
517
|
* @deprecated Use `createSchema()` and setup values in the constructor instead.
|
|
508
518
|
*/
|
|
509
|
-
override new(init:
|
|
519
|
+
override new(init: FileSchema): this {
|
|
510
520
|
super.new(init)
|
|
511
521
|
const { permissions = [], parents = [], permissionIds = [], deleted, deletedInfo, lastModified, labels } = init
|
|
512
522
|
this[permissionsSymbol] = permissions.map((i) => ({ ...i }))
|
|
@@ -530,8 +540,8 @@ export class File extends StoredFile {
|
|
|
530
540
|
return this
|
|
531
541
|
}
|
|
532
542
|
|
|
533
|
-
override toJSON():
|
|
534
|
-
const result:
|
|
543
|
+
override toJSON(): FileSchema {
|
|
544
|
+
const result: FileSchema = {
|
|
535
545
|
...super.toJSON(),
|
|
536
546
|
parents: [...this.parents],
|
|
537
547
|
permissionIds: [...this.permissionIds],
|
|
@@ -540,7 +550,7 @@ export class File extends StoredFile {
|
|
|
540
550
|
}
|
|
541
551
|
if (this.deleted) {
|
|
542
552
|
result.deleted = this.deleted
|
|
543
|
-
result.deletedInfo = { ...this.deletedInfo } as
|
|
553
|
+
result.deletedInfo = { ...this.deletedInfo } as DeletionSchema
|
|
544
554
|
}
|
|
545
555
|
if (Array.isArray(this.labels)) {
|
|
546
556
|
result.labels = [...this.labels]
|
|
@@ -568,7 +578,7 @@ export class File extends StoredFile {
|
|
|
568
578
|
*
|
|
569
579
|
* @param user The user that modifies the entity.
|
|
570
580
|
*/
|
|
571
|
-
setLastModified(user:
|
|
581
|
+
setLastModified(user: UserSchema): void {
|
|
572
582
|
if (!user) {
|
|
573
583
|
throw new Error(`The user is required.`)
|
|
574
584
|
}
|
|
@@ -615,7 +625,7 @@ export class File extends StoredFile {
|
|
|
615
625
|
*
|
|
616
626
|
* @param user The user that deletes the entity.
|
|
617
627
|
*/
|
|
618
|
-
setDeleted(user:
|
|
628
|
+
setDeleted(user: UserSchema): void {
|
|
619
629
|
if (!user) {
|
|
620
630
|
throw new Error(`The user is required.`)
|
|
621
631
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { GroupKind } from '../kinds.js'
|
|
2
|
-
import type {
|
|
2
|
+
import type { DeletionSchema } from './Deletion.js'
|
|
3
3
|
import { nanoid } from '../../nanoid.js'
|
|
4
4
|
|
|
5
5
|
/**
|
|
@@ -76,7 +76,7 @@ export interface GroupSchema {
|
|
|
76
76
|
* This field is ignored by the API and is set automatically.
|
|
77
77
|
* @readonly
|
|
78
78
|
*/
|
|
79
|
-
deleteInfo?:
|
|
79
|
+
deleteInfo?: DeletionSchema
|
|
80
80
|
}
|
|
81
81
|
|
|
82
82
|
export class Group implements GroupSchema {
|
|
@@ -91,7 +91,7 @@ export class Group implements GroupSchema {
|
|
|
91
91
|
users: string[] = []
|
|
92
92
|
createdAt = 0
|
|
93
93
|
updatedAt = 0
|
|
94
|
-
deleteInfo?:
|
|
94
|
+
deleteInfo?: DeletionSchema
|
|
95
95
|
|
|
96
96
|
static createSchema(input: Partial<GroupSchema> = {}): GroupSchema {
|
|
97
97
|
const { key = nanoid() } = input
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { nanoid } from '../../nanoid.js'
|
|
2
2
|
import { InvitationKind } from '../kinds.js'
|
|
3
|
-
import type {
|
|
3
|
+
import type { DeletionSchema } from './Deletion.js'
|
|
4
4
|
import type { UserOrganizationGrantType } from './Organization.js'
|
|
5
5
|
import type { Operation } from '@api-client/json/types.js'
|
|
6
6
|
import { Builder } from '@api-client/json/patch/builder.js'
|
|
@@ -73,7 +73,7 @@ export interface InvitationSchema {
|
|
|
73
73
|
* The information about the delete information.
|
|
74
74
|
* Always set when the `delete` is true.
|
|
75
75
|
*/
|
|
76
|
-
deletedInfo?:
|
|
76
|
+
deletedInfo?: DeletionSchema
|
|
77
77
|
/**
|
|
78
78
|
* The timestamp when the invitation was created.
|
|
79
79
|
*/
|
|
@@ -110,7 +110,7 @@ export class Invitation implements InvitationSchema {
|
|
|
110
110
|
status: InvitationStatus
|
|
111
111
|
grantType: UserOrganizationGrantType
|
|
112
112
|
deleted: boolean
|
|
113
|
-
deletedInfo:
|
|
113
|
+
deletedInfo: DeletionSchema | undefined
|
|
114
114
|
createdAt: number
|
|
115
115
|
updatedAt: number
|
|
116
116
|
resent: number
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Information about a modification of a File.
|
|
3
3
|
*/
|
|
4
|
-
export interface
|
|
4
|
+
export interface ModificationSchema {
|
|
5
5
|
/**
|
|
6
6
|
* The key of the user modifying the record.
|
|
7
7
|
*/
|
|
@@ -22,3 +22,8 @@ export interface IModification {
|
|
|
22
22
|
*/
|
|
23
23
|
time: number
|
|
24
24
|
}
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* @deprecated Use {@link ModificationSchema} instead.
|
|
28
|
+
*/
|
|
29
|
+
export type IModification = ModificationSchema
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { nanoid } from '../../nanoid.js'
|
|
2
|
-
import type {
|
|
2
|
+
import type { DeletionSchema } from './Deletion.js'
|
|
3
3
|
import { OrganizationKind } from '../kinds.js'
|
|
4
4
|
|
|
5
5
|
export type UserOrganizationGrantType = 'owner' | 'manager' | 'editor' | 'viewer'
|
|
@@ -9,7 +9,7 @@ export type UserOrganizationGrantType = 'owner' | 'manager' | 'editor' | 'viewer
|
|
|
9
9
|
* This association allows the user to use different identity providers that map to the same user, as long as the
|
|
10
10
|
* email stays consistent.
|
|
11
11
|
*/
|
|
12
|
-
export interface
|
|
12
|
+
export interface OrganizationSchema {
|
|
13
13
|
kind: typeof OrganizationKind
|
|
14
14
|
/**
|
|
15
15
|
* The database ID
|
|
@@ -19,6 +19,10 @@ export interface IOrganization {
|
|
|
19
19
|
* The organization name
|
|
20
20
|
*/
|
|
21
21
|
name: string
|
|
22
|
+
/**
|
|
23
|
+
* The organization slug. It is used to identify the organization in the URL.
|
|
24
|
+
*/
|
|
25
|
+
slug: string
|
|
22
26
|
/**
|
|
23
27
|
* The key of the user that created the organization.
|
|
24
28
|
*/
|
|
@@ -35,7 +39,7 @@ export interface IOrganization {
|
|
|
35
39
|
* The information about the delete information.
|
|
36
40
|
* Always set when the `delete` is true.
|
|
37
41
|
*/
|
|
38
|
-
deletedInfo?:
|
|
42
|
+
deletedInfo?: DeletionSchema
|
|
39
43
|
/**
|
|
40
44
|
* The grant type to the organization the **current user** has.
|
|
41
45
|
* By nature, it's a dynamic field populated by the data store.
|
|
@@ -43,86 +47,67 @@ export interface IOrganization {
|
|
|
43
47
|
grantType: UserOrganizationGrantType
|
|
44
48
|
}
|
|
45
49
|
|
|
46
|
-
|
|
47
|
-
|
|
50
|
+
/**
|
|
51
|
+
* @deprecated use OrganizationSchema instead.
|
|
52
|
+
*/
|
|
53
|
+
export type IOrganization = OrganizationSchema
|
|
54
|
+
|
|
55
|
+
export class Organization implements OrganizationSchema {
|
|
56
|
+
readonly kind: typeof OrganizationKind = OrganizationKind
|
|
48
57
|
key = ''
|
|
49
58
|
name = ''
|
|
59
|
+
slug = ''
|
|
50
60
|
createdBy = ''
|
|
51
61
|
createdDate = 0
|
|
52
62
|
deleted = false
|
|
53
|
-
deletedInfo?:
|
|
63
|
+
deletedInfo?: DeletionSchema
|
|
54
64
|
grantType: UserOrganizationGrantType = 'viewer'
|
|
55
65
|
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
createdBy: '',
|
|
68
|
-
createdDate: Date.now(),
|
|
69
|
-
deleted: false,
|
|
70
|
-
grantType: 'viewer',
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
this.new(init)
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
new(init: IOrganization): void {
|
|
77
|
-
if (!Organization.isOrganization(init)) {
|
|
78
|
-
throw new Error(`Not an Organization.`)
|
|
66
|
+
static createSchema(input: Partial<OrganizationSchema> = {}): OrganizationSchema {
|
|
67
|
+
const { key = nanoid() } = input
|
|
68
|
+
const result: OrganizationSchema = {
|
|
69
|
+
kind: OrganizationKind,
|
|
70
|
+
key,
|
|
71
|
+
name: input.name || 'Unnamed organization',
|
|
72
|
+
slug: input.slug || '',
|
|
73
|
+
createdBy: input.createdBy || '',
|
|
74
|
+
createdDate: input.createdDate || Date.now(),
|
|
75
|
+
deleted: input.deleted || false,
|
|
76
|
+
grantType: input.grantType || 'viewer',
|
|
79
77
|
}
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
name,
|
|
83
|
-
createdBy,
|
|
84
|
-
createdDate = Date.now(),
|
|
85
|
-
deleted = false,
|
|
86
|
-
deletedInfo,
|
|
87
|
-
grantType = 'viewer',
|
|
88
|
-
} = init
|
|
89
|
-
this.kind = OrganizationKind
|
|
90
|
-
this.key = key
|
|
91
|
-
this.name = name
|
|
92
|
-
this.createdBy = createdBy
|
|
93
|
-
this.createdDate = createdDate
|
|
94
|
-
this.deleted = deleted
|
|
95
|
-
this.grantType = grantType
|
|
96
|
-
if (deletedInfo) {
|
|
97
|
-
this.deletedInfo = deletedInfo
|
|
98
|
-
} else {
|
|
99
|
-
this.deletedInfo = undefined
|
|
78
|
+
if (input.deletedInfo) {
|
|
79
|
+
result.deletedInfo = input.deletedInfo
|
|
100
80
|
}
|
|
81
|
+
return result
|
|
101
82
|
}
|
|
102
83
|
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
84
|
+
constructor(state?: Partial<OrganizationSchema>) {
|
|
85
|
+
const init = Organization.createSchema(state)
|
|
86
|
+
this.key = init.key
|
|
87
|
+
this.name = init.name
|
|
88
|
+
this.slug = init.slug
|
|
89
|
+
this.createdBy = init.createdBy
|
|
90
|
+
this.createdDate = init.createdDate
|
|
91
|
+
this.deleted = init.deleted ?? false
|
|
92
|
+
this.grantType = init.grantType
|
|
93
|
+
if (init.deletedInfo) {
|
|
94
|
+
this.deletedInfo = { ...init.deletedInfo }
|
|
110
95
|
}
|
|
111
|
-
return true
|
|
112
96
|
}
|
|
113
97
|
|
|
114
|
-
toJSON():
|
|
115
|
-
const result:
|
|
98
|
+
toJSON(): OrganizationSchema {
|
|
99
|
+
const result: OrganizationSchema = {
|
|
116
100
|
kind: OrganizationKind,
|
|
117
101
|
key: this.key,
|
|
118
102
|
name: this.name,
|
|
103
|
+
slug: this.slug,
|
|
119
104
|
createdBy: this.createdBy,
|
|
120
105
|
createdDate: this.createdDate,
|
|
121
106
|
deleted: this.deleted,
|
|
122
107
|
grantType: this.grantType,
|
|
123
108
|
}
|
|
124
109
|
if (this.deletedInfo) {
|
|
125
|
-
result.deletedInfo = this.deletedInfo
|
|
110
|
+
result.deletedInfo = { ...this.deletedInfo }
|
|
126
111
|
}
|
|
127
112
|
return result
|
|
128
113
|
}
|
|
@@ -81,7 +81,7 @@ interface IBasePermission {
|
|
|
81
81
|
/**
|
|
82
82
|
* A schema describing a permission to a store object.
|
|
83
83
|
*/
|
|
84
|
-
export interface
|
|
84
|
+
export interface PermissionSchema extends IBasePermission {
|
|
85
85
|
kind: typeof Kind
|
|
86
86
|
/**
|
|
87
87
|
* The data store key of the permission.
|
|
@@ -90,6 +90,11 @@ export interface IPermission extends IBasePermission {
|
|
|
90
90
|
key: string
|
|
91
91
|
}
|
|
92
92
|
|
|
93
|
+
/**
|
|
94
|
+
* @deprecated Use {@link PermissionSchema} instead.
|
|
95
|
+
*/
|
|
96
|
+
export type IPermission = PermissionSchema
|
|
97
|
+
|
|
93
98
|
export class Permission {
|
|
94
99
|
kind = Kind
|
|
95
100
|
/**
|
|
@@ -164,7 +169,7 @@ export class Permission {
|
|
|
164
169
|
* @param addingUser The key of the user that created this permission
|
|
165
170
|
*/
|
|
166
171
|
static fromUserRole(role: PermissionRole, itemId: string, user: string, addingUser: string): Permission {
|
|
167
|
-
const init:
|
|
172
|
+
const init: PermissionSchema = {
|
|
168
173
|
key: nanoid(),
|
|
169
174
|
kind: Kind,
|
|
170
175
|
itemId,
|
|
@@ -187,7 +192,7 @@ export class Permission {
|
|
|
187
192
|
* @param addingUser The key of the user that created this permission
|
|
188
193
|
*/
|
|
189
194
|
static fromGroupRole(role: PermissionRole, itemId: string, group: string, addingUser: string): Permission {
|
|
190
|
-
const init:
|
|
195
|
+
const init: PermissionSchema = {
|
|
191
196
|
key: nanoid(),
|
|
192
197
|
kind: Kind,
|
|
193
198
|
itemId,
|
|
@@ -214,7 +219,7 @@ export class Permission {
|
|
|
214
219
|
organizationId: string,
|
|
215
220
|
addingUser: string
|
|
216
221
|
): Permission {
|
|
217
|
-
const init:
|
|
222
|
+
const init: PermissionSchema = {
|
|
218
223
|
key: nanoid(),
|
|
219
224
|
kind: Kind,
|
|
220
225
|
itemId,
|
|
@@ -239,8 +244,8 @@ export class Permission {
|
|
|
239
244
|
})
|
|
240
245
|
}
|
|
241
246
|
|
|
242
|
-
constructor(input?: string |
|
|
243
|
-
let init:
|
|
247
|
+
constructor(input?: string | PermissionSchema) {
|
|
248
|
+
let init: PermissionSchema
|
|
244
249
|
if (typeof input === 'string') {
|
|
245
250
|
init = JSON.parse(input)
|
|
246
251
|
} else if (typeof input === 'object') {
|
|
@@ -261,7 +266,7 @@ export class Permission {
|
|
|
261
266
|
this.new(init)
|
|
262
267
|
}
|
|
263
268
|
|
|
264
|
-
new(init:
|
|
269
|
+
new(init: PermissionSchema): void {
|
|
265
270
|
if (!Permission.isPermission(init)) {
|
|
266
271
|
throw new Error(`Not a permission.`)
|
|
267
272
|
}
|
|
@@ -299,7 +304,7 @@ export class Permission {
|
|
|
299
304
|
}
|
|
300
305
|
|
|
301
306
|
static isPermission(input: unknown): boolean {
|
|
302
|
-
const typed = input as
|
|
307
|
+
const typed = input as PermissionSchema
|
|
303
308
|
if (!input || typed.kind !== Kind) {
|
|
304
309
|
return false
|
|
305
310
|
}
|
|
@@ -352,7 +357,7 @@ export class Permission {
|
|
|
352
357
|
* @param permissions The list of permissions to check.
|
|
353
358
|
* @returns True if the user has the required role.
|
|
354
359
|
*/
|
|
355
|
-
static hasRoleIn(minimumLevel: PermissionRole, permissions:
|
|
360
|
+
static hasRoleIn(minimumLevel: PermissionRole, permissions: PermissionSchema[]): boolean {
|
|
356
361
|
if (!permissions || !permissions.length) {
|
|
357
362
|
return false
|
|
358
363
|
}
|
|
@@ -363,7 +368,7 @@ export class Permission {
|
|
|
363
368
|
const closestPermissions = sorted.filter((p) => p.depth === closestDepth)
|
|
364
369
|
|
|
365
370
|
// 2. Specificity: User > Group > Organization
|
|
366
|
-
let effectivePermission:
|
|
371
|
+
let effectivePermission: PermissionSchema | undefined
|
|
367
372
|
|
|
368
373
|
// Check for user permissions
|
|
369
374
|
const userPermissions = closestPermissions.filter((p) => p.type === 'user')
|
|
@@ -397,8 +402,8 @@ export class Permission {
|
|
|
397
402
|
return Permission.hasRole(minimumLevel, effectivePermission.role)
|
|
398
403
|
}
|
|
399
404
|
|
|
400
|
-
toJSON():
|
|
401
|
-
const result:
|
|
405
|
+
toJSON(): PermissionSchema {
|
|
406
|
+
const result: PermissionSchema = {
|
|
402
407
|
kind: Kind,
|
|
403
408
|
key: this.key,
|
|
404
409
|
role: this.role,
|