@api-client/core 0.14.2 → 0.14.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 (86) hide show
  1. package/build/src/browser.d.ts +1 -1
  2. package/build/src/browser.d.ts.map +1 -1
  3. package/build/src/browser.js +1 -0
  4. package/build/src/browser.js.map +1 -1
  5. package/build/src/events/BaseEvents.d.ts +4 -0
  6. package/build/src/events/BaseEvents.d.ts.map +1 -1
  7. package/build/src/events/BaseEvents.js.map +1 -1
  8. package/build/src/index.d.ts +2 -1
  9. package/build/src/index.d.ts.map +1 -1
  10. package/build/src/index.js +2 -0
  11. package/build/src/index.js.map +1 -1
  12. package/build/src/modeling/ApiFile.d.ts +23 -0
  13. package/build/src/modeling/ApiFile.d.ts.map +1 -0
  14. package/build/src/modeling/ApiFile.js +44 -0
  15. package/build/src/modeling/ApiFile.js.map +1 -0
  16. package/build/src/modeling/ApiModel.d.ts +159 -0
  17. package/build/src/modeling/ApiModel.d.ts.map +1 -0
  18. package/build/src/modeling/ApiModel.js +237 -0
  19. package/build/src/modeling/ApiModel.js.map +1 -0
  20. package/build/src/modeling/DataDomain.d.ts +1 -1
  21. package/build/src/modeling/DataDomain.d.ts.map +1 -1
  22. package/build/src/modeling/DataDomain.js +1 -3
  23. package/build/src/modeling/DataDomain.js.map +1 -1
  24. package/build/src/modeling/DomainEntity.js +1 -1
  25. package/build/src/modeling/DomainEntity.js.map +1 -1
  26. package/build/src/modeling/DomainFile.d.ts +1 -2
  27. package/build/src/modeling/DomainFile.d.ts.map +1 -1
  28. package/build/src/modeling/DomainFile.js +3 -41
  29. package/build/src/modeling/DomainFile.js.map +1 -1
  30. package/build/src/modeling/Semantics.d.ts +55 -8
  31. package/build/src/modeling/Semantics.d.ts.map +1 -1
  32. package/build/src/modeling/Semantics.js +62 -8
  33. package/build/src/modeling/Semantics.js.map +1 -1
  34. package/build/src/modeling/amf/ShapeGenerator.d.ts.map +1 -1
  35. package/build/src/modeling/amf/ShapeGenerator.js.map +1 -1
  36. package/build/src/modeling/types.d.ts +491 -0
  37. package/build/src/modeling/types.d.ts.map +1 -1
  38. package/build/src/modeling/types.js.map +1 -1
  39. package/build/src/models/kinds.d.ts +3 -0
  40. package/build/src/models/kinds.d.ts.map +1 -1
  41. package/build/src/models/kinds.js +3 -0
  42. package/build/src/models/kinds.js.map +1 -1
  43. package/build/src/models/store/File.d.ts +19 -2
  44. package/build/src/models/store/File.d.ts.map +1 -1
  45. package/build/src/models/store/File.js +100 -13
  46. package/build/src/models/store/File.js.map +1 -1
  47. package/build/src/models/store/Group.d.ts +76 -2
  48. package/build/src/models/store/Group.d.ts.map +1 -1
  49. package/build/src/models/store/Group.js +84 -1
  50. package/build/src/models/store/Group.js.map +1 -1
  51. package/build/src/sdk/GroupsSdk.d.ts +41 -0
  52. package/build/src/sdk/GroupsSdk.d.ts.map +1 -0
  53. package/build/src/sdk/GroupsSdk.js +135 -0
  54. package/build/src/sdk/GroupsSdk.js.map +1 -0
  55. package/build/src/sdk/RouteBuilder.d.ts +2 -0
  56. package/build/src/sdk/RouteBuilder.d.ts.map +1 -1
  57. package/build/src/sdk/RouteBuilder.js +6 -0
  58. package/build/src/sdk/RouteBuilder.js.map +1 -1
  59. package/build/src/sdk/Sdk.d.ts +2 -0
  60. package/build/src/sdk/Sdk.d.ts.map +1 -1
  61. package/build/src/sdk/Sdk.js +5 -0
  62. package/build/src/sdk/Sdk.js.map +1 -1
  63. package/build/tsconfig.tsbuildinfo +1 -1
  64. package/package.json +2 -3
  65. package/src/events/BaseEvents.ts +4 -0
  66. package/src/modeling/ApiFile.ts +53 -0
  67. package/src/modeling/ApiModel.ts +327 -0
  68. package/src/modeling/DataDomain.ts +1 -1
  69. package/src/modeling/DomainEntity.ts +1 -1
  70. package/src/modeling/DomainFile.ts +3 -40
  71. package/src/modeling/Semantics.ts +63 -8
  72. package/src/modeling/amf/ShapeGenerator.ts +1 -1
  73. package/src/modeling/types.ts +545 -0
  74. package/src/models/kinds.ts +3 -0
  75. package/src/models/store/File.ts +100 -13
  76. package/src/models/store/Group.ts +148 -2
  77. package/src/sdk/GroupsSdk.ts +150 -0
  78. package/src/sdk/RouteBuilder.ts +8 -0
  79. package/src/sdk/Sdk.ts +6 -0
  80. package/tests/unit/modeling/api_model.spec.ts +291 -0
  81. package/tests/unit/modeling/domain_entity.spec.ts +15 -15
  82. package/tests/unit/modeling/domain_file.spec.ts +1 -11
  83. package/tests/unit/modeling/domain_model_entities.spec.ts +2 -2
  84. package/tests/unit/modeling/semantics.spec.ts +8 -11
  85. package/tests/unit/models/File/constructor.spec.ts +3 -2
  86. package/tests/unit/models/File/shortcutTo.spec.ts +1 -1
@@ -1 +1 @@
1
- {"version":3,"file":"File.d.ts","sourceRoot":"","sources":["../../../../src/models/store/File.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAc,cAAc,EAAE,MAAM,iBAAiB,CAAA;AACzE,OAAO,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAA;AACjD,OAAO,EAAE,SAAS,EAAE,MAAM,eAAe,CAAA;AACzC,OAAO,EAAE,KAAK,EAAoB,MAAM,WAAW,CAAA;AACnD,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,aAAa,CAAA;AAC3C,OAAO,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAA;AAKjD,MAAM,WAAW,cAAc;IAC7B;;;OAGG;IACH,MAAM,CAAC,EAAE,MAAM,CAAA;CAChB;AAED,MAAM,WAAW,gBAAgB;IAC/B;;OAEG;IACH,OAAO,CAAC,EAAE,OAAO,CAAA;CAClB;AAED;;GAEG;AACH,MAAM,WAAW,cAAc;IAC7B;;OAEG;IACH,GAAG,EAAE,MAAM,CAAA;IACX;;OAEG;IACH,IAAI,EAAE,MAAM,CAAA;IACZ;;OAEG;IACH,IAAI,EAAE,MAAM,CAAA;CACb;AAED,MAAM,WAAW,WAAW;IAC1B;;OAEG;IACH,IAAI,EAAE,MAAM,CAAA;I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AAW,EAAE,CAExC;WAEe,YAAY,CAAC,KAAK,GAAE,OAAO,CAAC,KAAK,CAAM,GAAG,KAAK;gBAsCnD,KAAK,CAAC,EAAE,OAAO,CAAC,KAAK,CAAC;IAiBlC;;OAEG;IACM,GAAG,CAAC,IAAI,EAAE,KAAK,GAAG,IAAI;IAwBtB,MAAM,IAAI,KAAK;IAkBxB;;;OAGG;IACH,MAAM,CAAC,QAAQ,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,IAAI;IAKjD,UAAU,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI;IAKhC;;;;;OAKG;IACH,eAAe,CAAC,IAAI,EAAE,KAAK,GAAG,IAAI;IAelC;;;;;;;;OAQG;IACH,QAAQ,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI;IAgB7B;;;;;;OAMG;IACH,UAAU,CAAC,IAAI,EAAE,KAAK,GAAG,IAAI;IAgB7B,MAAM,IAAI,OAAO;IAIjB,QAAQ,IAAI,OAAO;CAGpB"}
@@ -45,6 +45,43 @@ export class StoredFile {
45
45
  set shortcutTarget(value) {
46
46
  this[shortcutTargetSymbol] = value;
47
47
  }
48
+ /**
49
+ * Creates a file schema object with the given properties.
50
+ * The `key` is generated if not set.
51
+ *
52
+ * @param input The input to create the file schema.
53
+ * @returns The file schema object.
54
+ */
55
+ static createSchema(input = {}) {
56
+ const { key = nanoid(), kind, iconColor, shortcutTarget } = input;
57
+ const result = {
58
+ key,
59
+ kind: kind || '',
60
+ info: Thing.fromJSON(input.info, { name: 'Unnamed file' }).toJSON(),
61
+ };
62
+ if (iconColor) {
63
+ result.iconColor = iconColor;
64
+ }
65
+ if (shortcutTarget) {
66
+ result.isShortcut = true;
67
+ result.shortcutTarget = shortcutTarget;
68
+ }
69
+ return result;
70
+ }
71
+ constructor(state) {
72
+ this.kind = state.kind;
73
+ this.key = state.key;
74
+ this.info = new Thing(state.info);
75
+ if (state.iconColor) {
76
+ this.iconColor = state.iconColor;
77
+ }
78
+ if (state.shortcutTarget) {
79
+ this.shortcutTarget = state.shortcutTarget;
80
+ }
81
+ }
82
+ /**
83
+ * @deprecated Use `createSchema()` and setup values in the constructor instead.
84
+ */
48
85
  new(init) {
49
86
  const { key = nanoid(), info, kind, iconColor, shortcutTarget } = init;
50
87
  this.key = key;
@@ -254,6 +291,66 @@ export class File extends StoredFile {
254
291
  get permissions() {
255
292
  return this[permissionsSymbol];
256
293
  }
294
+ static createSchema(input = {}) {
295
+ const result = StoredFile.createSchema(input);
296
+ if (Array.isArray(input.parents)) {
297
+ result.parents = [...input.parents];
298
+ }
299
+ else {
300
+ result.parents = [];
301
+ }
302
+ if (Array.isArray(input.permissionIds)) {
303
+ result.permissionIds = [...input.permissionIds];
304
+ }
305
+ else {
306
+ result.permissionIds = [];
307
+ }
308
+ if (Array.isArray(input.permissions)) {
309
+ result.permissions = input.permissions.map((i) => ({ ...i }));
310
+ }
311
+ else {
312
+ result.permissions = [];
313
+ }
314
+ if (input.capabilities) {
315
+ result.capabilities = { ...input.capabilities };
316
+ }
317
+ if (input.lastModified) {
318
+ result.lastModified = { ...input.lastModified };
319
+ }
320
+ else {
321
+ result.lastModified = { user: '', time: 0, byMe: false };
322
+ }
323
+ if (typeof input.deleted === 'boolean') {
324
+ result.deleted = input.deleted;
325
+ result.deletedInfo = input.deletedInfo ? { ...input.deletedInfo } : undefined;
326
+ }
327
+ if (Array.isArray(input.labels)) {
328
+ result.labels = [...input.labels];
329
+ }
330
+ if (typeof input.shortcutTarget === 'string') {
331
+ result.shortcutTarget = input.shortcutTarget;
332
+ }
333
+ return result;
334
+ }
335
+ constructor(state) {
336
+ const init = File.createSchema(state);
337
+ super(init);
338
+ this[parentsSymbol] = [...init.parents];
339
+ this[permissionIdsSymbol] = [...init.permissionIds];
340
+ this[permissionsSymbol] = init.permissions.map((i) => ({ ...i }));
341
+ this[capabilitiesSymbol] = init.capabilities ? { ...init.capabilities } : undefined;
342
+ this[lastModifiedSymbol] = Object.freeze({ ...init.lastModified });
343
+ if (typeof init.deleted === 'boolean') {
344
+ this[deletedSymbol] = init.deleted;
345
+ this[deletedInfoSymbol] = init.deletedInfo ? Object.freeze({ ...init.deletedInfo }) : undefined;
346
+ }
347
+ if (Array.isArray(init.labels)) {
348
+ this.labels = [...init.labels];
349
+ }
350
+ }
351
+ /**
352
+ * @deprecated Use `createSchema()` and setup values in the constructor instead.
353
+ */
257
354
  new(init) {
258
355
  super.new(init);
259
356
  const { permissions = [], parents = [], permissionIds = [], deleted, deletedInfo, lastModified, labels } = init;
@@ -298,20 +395,10 @@ export class File extends StoredFile {
298
395
  }
299
396
  /**
300
397
  * @param name The name to set.
301
- * @param owner The user id that is the owner of the file.
398
+ * @param kind The kind of the file to create.
302
399
  */
303
- static fromName(name, kind = '') {
304
- const key = nanoid();
305
- const definition = new File();
306
- definition.new({
307
- key,
308
- kind,
309
- info: Thing.fromName(name).toJSON(),
310
- parents: [],
311
- permissionIds: [],
312
- permissions: [],
313
- lastModified: { user: '', time: 0, byMe: false },
314
- });
400
+ static fromName(name, kind) {
401
+ const definition = new File({ kind, info: { name } });
315
402
  return definition;
316
403
  }
317
404
  shortcutTo(fileId) {
@@ -1 +1 @@
1
- {"version":3,"file":"File.js","sourceRoot":"","sources":["../../../../src/models/store/File.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAA;AACxC,OAAO,EAAe,UAAU,EAAkB,MAAM,iBAAiB,CAAA;AAGzE,OAAO,EAAS,IAAI,IAAI,QAAQ,EAAE,MAAM,WAAW,CAAA;AACnD,OAAO,EAAU,KAAK,EAAE,MAAM,aAAa,CAAA;AAE3C,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAA;AA+HxC,MAAM,aAAa,GAAG,MAAM,CAAC,SAAS,CAAC,CAAA;AACvC,MAAM,aAAa,GAAG,MAAM,CAAC,SAAS,CAAC,CAAA;AACvC,MAAM,iBAAiB,GAAG,MAAM,CAAC,aAAa,CAAC,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;IAED,MAAM;QACJ,OAAO,IAAI,CAAC,IAAI,KAAK,UAAU,CAAA;IACjC,CAAC;IAED,QAAQ;QACN,OAAO,IAAI,CAAC,IAAI,KAAK,UAAU,CAAA;IACjC,CAAC;CACF","sourcesContent":["import { nanoid } from '../../nanoid.js'\nimport { IPermission, Permission, PermissionRole } from './Permission.js'\nimport { IModification } from './Modification.js'\nimport { IDeletion } from './Deletion.js'\nimport { IUser, Kind as UserKind } from './User.js'\nimport { IThing, Thing } from '../Thing.js'\nimport { ICapabilities } from './Capabilities.js'\nimport { FolderKind } from '../kinds.js'\n// this causes error\n// import { Kind as FolderKind } from '../Folder.js';\n\nexport interface FileAddOptions {\n /**\n * The parent folder where to put the file.\n * The `parents` array is always cleared from the file object before adding it to the store.\n */\n parent?: string\n}\n\nexport interface MediaReadOptions {\n /**\n * When set it reads the file that was marked as `_deleted`. By default it throws when file was deleted.\n */\n deleted?: boolean\n}\n\n/**\n * A breadcrumb when creating the breadcrumb list for a file.\n */\nexport interface FileBreadcrumb {\n /**\n * The datastore key of the object.\n */\n key: string\n /**\n * THe kind of the object.\n */\n kind: string\n /**\n * The name of the object.\n */\n name: string\n}\n\nexport interface IStoredFile {\n /**\n * The kind of the File\n */\n kind: string\n /**\n * The identifier of the entity\n */\n key: string\n /**\n * The file's meta info.\n */\n info: IThing\n /**\n * The color of the icon to render for this file in the file explorer.\n * This should be a hex format, e.g.: #c00 for red.\n */\n iconColor?: string\n /**\n * Whether the file is a shortcut to another file.\n * Many properties cannot be changed of a shortcut, like, shortcuts cannot be shared.\n */\n isShortcut?: boolean\n /**\n * The ID of the target file.\n */\n shortcutTarget?: string\n}\n\n/**\n * An interface describing an object in the data store that\n * describes a file or an object that can be treated as a file or a folder.\n */\nexport interface IFile extends IStoredFile {\n /**\n * The list of parents of the object. It is an ordered list of parents\n * from the top (first element) to the lowest parent in the tree (last element).\n *\n * After creating the object, this property cannot be manipulated directly by the client.\n * Should be treated as opaque value.\n */\n parents: string[]\n /**\n * The list of permissions to this file object.\n *\n * This property cannot be manipulated directly by the client. Should be treated as\n * opaque value.\n */\n permissionIds: string[]\n /**\n * Whether the file object is deleted.\n */\n deleted?: boolean\n /**\n * The information about the delete information.\n * Always set when the `delete` is true.\n */\n deletedInfo?: IDeletion\n /**\n * The last modification made to this file.\n */\n lastModified: IModification\n /**\n * An arbitrary list of labels applied to the file.\n */\n labels?: string[]\n /**\n * This is populated when reading a file from the store.\n * A list of actions the user can perform on the file.\n *\n * This is a readonly field and it is ignored when creating / updating the file.\n */\n capabilities?: ICapabilities\n /**\n * Populated by the server when reading the file. The list of permissions to the object.\n *\n * This property cannot be manipulated directly by the client. Should be treated as\n * opaque value.\n *\n * Data store implementation note, this is not stored in the store but it is populated\n * when reading the object.\n */\n permissions: IPermission[]\n /**\n * Populated by the store in some situations. If it's missing then you should request\n * breadcrumbs from the store.\n */\n breadcrumb?: FileBreadcrumb[]\n}\n\nconst parentsSymbol = Symbol('parents')\nconst deletedSymbol = Symbol('deleted')\nconst deletedInfoSymbol = Symbol('deletedInfo')\nconst lastModifiedSymbol = Symbol('lastModified')\nconst capabilitiesSymbol = Symbol('capabilities')\nconst permissionsSymbol = Symbol('permissions')\nconst permissionIdsSymbol = Symbol('permissionIds')\nconst shortcutTargetSymbol = Symbol('shortcutTarget')\n\nexport class StoredFile {\n /**\n * The kind of the File\n */\n kind = ''\n /**\n * The identifier of the entity\n */\n key = ''\n /**\n * The name of the environment.\n */\n info: Thing = Thing.fromName('')\n\n /**\n * The color of the icon to render for this file in the file explorer.\n */\n iconColor?: string\n\n /**\n * Whether the file is a shortcut to another file.\n * Many properties cannot be changed of a shortcut, like, shortcuts cannot be shared.\n */\n get isShortcut(): boolean {\n return !!this.shortcutTarget\n }\n\n [shortcutTargetSymbol]?: string\n\n /**\n * The ID of the target file.\n */\n get shortcutTarget(): string | undefined {\n return this[shortcutTargetSymbol]\n }\n\n set shortcutTarget(value: string | undefined) {\n this[shortcutTargetSymbol] = value\n }\n\n new(init: IStoredFile): this {\n const { key = nanoid(), info, kind, iconColor, shortcutTarget } = init\n this.key = key\n this.kind = kind\n if (info) {\n this.info = new Thing(info)\n } else {\n this.info = Thing.fromName('')\n }\n if (iconColor) {\n this.iconColor = iconColor\n } else {\n this.iconColor = undefined\n }\n if (shortcutTarget) {\n this.shortcutTarget = shortcutTarget\n } else {\n this.shortcutTarget = undefined\n }\n return this\n }\n\n toJSON(): IStoredFile {\n const result: IStoredFile = {\n key: this.key,\n kind: this.kind,\n info: this.info.toJSON(),\n }\n if (this.iconColor) {\n result.iconColor = this.iconColor\n }\n if (this.shortcutTarget) {\n result.isShortcut = true\n result.shortcutTarget = this.shortcutTarget\n }\n return result\n }\n\n /**\n * Creates the Capabilities object for a file giving user level.\n *\n * @param file The file object to create the capabilities to. The object is not mutated.\n * @param role The user role to the file.\n */\n static createFileCapabilities(file: IStoredFile | StoredFile, role?: PermissionRole): ICapabilities {\n const isCommenter = Permission.hasRole('commenter', role)\n const isOwner = Permission.hasRole('owner', role)\n const isReader = Permission.hasRole('reader', role)\n const isWriter = Permission.hasRole('writer', role)\n const isFolder = file.kind === FolderKind\n const result: ICapabilities = {\n canReadMedia: !isFolder && isReader,\n canListChildren: isFolder && isReader,\n canComment: !isFolder && isCommenter,\n canEditMedia: !isFolder && isWriter,\n canEditMeta: isWriter,\n canReadRevisions: isWriter,\n canAddChildren: isFolder && isWriter,\n canDelete: isOwner,\n canTrash: isOwner,\n canUntrash: isOwner,\n canShare: isWriter,\n canMove: isWriter,\n }\n return result\n }\n\n createFileCapabilities(role: PermissionRole): ICapabilities {\n return File.createFileCapabilities(this, role)\n }\n\n /**\n * Mutates the file object by setting the `byMe` properties (on deleted and modified info)\n *\n * Note, this can be done only on file schema (IFile). The `File` object has\n * this properties frozen.\n *\n * @param file The file to mutate\n * @param user The user key to compare.\n */\n static updateByMeMeta(file: IFile, user: string): void {\n if (file.deletedInfo) {\n file.deletedInfo.byMe = file.deletedInfo.user === user\n }\n if (file.lastModified) {\n file.lastModified.byMe = file.lastModified.user === user\n }\n }\n\n /**\n * Static method to set the `lastModified` property on a file without creating an instance of a file meta.\n * Useful when the meta kind is unknown.\n *\n * @param file The file to update. Note, this method mutates the file.\n * @param user The user that modifies the file.\n * @returns The same file.\n */\n static setLastModified(file: IFile, user: IUser): IFile {\n if (!file) {\n throw new Error(`The file is required.`)\n }\n if (!user) {\n throw new Error(`The user is required.`)\n }\n if (user.kind !== UserKind) {\n throw new Error(`Invalid value for the user when setting \"lastModified\".`)\n }\n file.lastModified = {\n byMe: false,\n time: Date.now(),\n user: user.key,\n name: user.name,\n }\n return file\n }\n\n /**\n * Similar to the instance method `setDeleted()` but without creating\n * an instance of the file when the type is unknown.\n *\n * @param file The file to change. Note, this operation mutates the file.\n * @param user The deleting user\n * @returns The same file reference.\n */\n static setDeleted(file: IFile, user: IUser): IFile {\n if (!file) {\n throw new Error(`The file is required.`)\n }\n if (!user) {\n throw new Error(`The user is required.`)\n }\n if (user.kind !== UserKind) {\n throw new Error(`Invalid value for the user when setting \"deletedInfo\".`)\n }\n file.deleted = true\n file.deletedInfo = {\n byMe: false,\n time: Date.now(),\n user: user.key,\n name: user.name,\n }\n return file\n }\n}\n\nexport class File extends StoredFile {\n [parentsSymbol]: string[] = []\n\n /**\n * The list of parents of the object. It is an ordered list of parents\n * from the top (first element) to the lowest parent in the tree (last element).\n *\n * This property cannot be manipulated directly by the client. Should be treated as\n * opaque value.\n */\n get parents(): string[] {\n return this[parentsSymbol]\n }\n\n [permissionIdsSymbol]: readonly string[] = []\n\n /**\n * The list of permissions to this file object.\n *\n * This property cannot be manipulated directly by the client. Should be treated as\n * opaque value.\n */\n get permissionIds(): readonly string[] {\n return this[permissionIdsSymbol]\n }\n\n [deletedSymbol]?: boolean\n\n /**\n * Whether the file object is deleted.\n */\n get deleted(): boolean {\n return this[deletedSymbol] || false\n }\n\n [deletedInfoSymbol]?: Readonly<IDeletion>\n\n /**\n * The information about the delete information.\n * Always set when the `delete` is true.\n */\n get deletedInfo(): Readonly<IDeletion> | undefined {\n return this[deletedInfoSymbol]\n }\n\n [lastModifiedSymbol]: Readonly<IModification> = { user: '', time: 0, byMe: false }\n\n /**\n * The last modification made to this file.\n */\n get lastModified(): Readonly<IModification> {\n return this[lastModifiedSymbol]\n }\n\n /**\n * An arbitrary list of labels applied to the file.\n */\n labels?: string[];\n\n [capabilitiesSymbol]?: Readonly<ICapabilities>\n\n /**\n * This is populated when reading a file from the store.\n * A list of actions the user can perform on the file.\n *\n * This is a readonly field and it is ignored when creating / updating the file.\n */\n get capabilities(): Readonly<ICapabilities> | undefined {\n return this[capabilitiesSymbol]\n }\n\n [permissionsSymbol]: readonly IPermission[] = []\n\n /**\n * Populated by the server when reading the file. The list of permissions to the object.\n *\n * This property cannot be manipulated directly by the client. Should be treated as\n * opaque value.\n */\n get permissions(): readonly IPermission[] {\n return this[permissionsSymbol]\n }\n\n override new(init: IFile): this {\n super.new(init)\n const { permissions = [], parents = [], permissionIds = [], deleted, deletedInfo, lastModified, labels } = init\n this[permissionsSymbol] = permissions.map((i) => ({ ...i }))\n this[parentsSymbol] = [...parents]\n this[permissionIdsSymbol] = [...permissionIds]\n this[lastModifiedSymbol] = lastModified\n ? Object.freeze({ ...lastModified })\n : Object.freeze({ user: '', time: 0, byMe: false })\n if (typeof deleted === 'boolean') {\n this[deletedSymbol] = deleted\n this[deletedInfoSymbol] = deletedInfo ? Object.freeze({ ...deletedInfo }) : undefined\n } else {\n this[deletedSymbol] = undefined\n this[deletedInfoSymbol] = undefined\n }\n if (Array.isArray(labels)) {\n this.labels = [...labels]\n } else {\n this.labels = undefined\n }\n return this\n }\n\n override toJSON(): IFile {\n const result: IFile = {\n ...super.toJSON(),\n parents: [...this.parents],\n permissionIds: [...this.permissionIds],\n lastModified: { ...this.lastModified },\n permissions: [...this.permissions],\n }\n if (this.deleted) {\n result.deleted = this.deleted\n result.deletedInfo = { ...this.deletedInfo } as IDeletion\n }\n if (Array.isArray(this.labels)) {\n result.labels = [...this.labels]\n }\n return result\n }\n\n /**\n * @param name The name to set.\n * @param owner The user id that is the owner of the file.\n */\n static fromName(name: string, kind = ''): File {\n const key = nanoid()\n const definition = new File()\n definition.new({\n key,\n kind,\n info: Thing.fromName(name).toJSON(),\n parents: [],\n permissionIds: [],\n permissions: [],\n lastModified: { user: '', time: 0, byMe: false },\n })\n return definition\n }\n\n shortcutTo(fileId: string): this {\n this.shortcutTarget = fileId\n return this\n }\n\n /**\n * Updates the \"lastModified\" value.\n * A helper method for a common task.\n *\n * @param user The user that modifies the entity.\n */\n setLastModified(user: IUser): void {\n if (!user) {\n throw new Error(`The user is required.`)\n }\n if (user.kind !== UserKind) {\n throw new Error(`Invalid value for the user when setting \"lastModified\".`)\n }\n this[lastModifiedSymbol] = {\n byMe: false,\n time: Date.now(),\n user: user.key,\n name: user.name,\n }\n }\n\n /**\n * Adds a label to the list of labels.\n *\n * It makes sure the value is a valid, non-empty string and the `labels` array is set.\n *\n * It does nothing when the label already exists.\n *\n * @param label The label to set.\n */\n addLabel(label: string): void {\n if (typeof label !== 'string') {\n throw new Error(`The label must be a string.`)\n }\n if (!label.trim()) {\n throw new Error(`The label is required.`)\n }\n if (!Array.isArray(this.labels)) {\n this.labels = []\n }\n if (this.labels.includes(label)) {\n return\n }\n this.labels.push(label)\n }\n\n /**\n * Marks the entity as deleted.\n *\n * A helper method for a common task.\n *\n * @param user The user that deletes the entity.\n */\n setDeleted(user: IUser): void {\n if (!user) {\n throw new Error(`The user is required.`)\n }\n if (user.kind !== UserKind) {\n throw new Error(`Invalid value for the user when setting \"deletedInfo\".`)\n }\n this[deletedSymbol] = true\n this[deletedInfoSymbol] = {\n byMe: false,\n time: Date.now(),\n user: user.key,\n name: user.name,\n }\n }\n\n isFile(): boolean {\n return this.kind !== FolderKind\n }\n\n isFolder(): boolean {\n return this.kind === FolderKind\n }\n}\n"]}
1
+ {"version":3,"file":"File.js","sourceRoot":"","sources":["../../../../src/models/store/File.ts"],"names":[],"mappings":"AAAA,OAAO,EAA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AAE,CAAC;YACV,MAAM,IAAI,KAAK,CAAC,uBAAuB,CAAC,CAAA;QAC1C,CAAC;QACD,IAAI,IAAI,CAAC,IAAI,KAAK,QAAQ,EAAE,CAAC;YAC3B,MAAM,IAAI,KAAK,CAAC,wDAAwD,CAAC,CAAA;QAC3E,CAAC;QACD,IAAI,CAAC,aAAa,CAAC,GAAG,IAAI,CAAA;QAC1B,IAAI,CAAC,iBAAiB,CAAC,GAAG;YACxB,IAAI,EAAE,KAAK;YACX,IAAI,EAAE,IAAI,CAAC,GAAG,EAAE;YAChB,IAAI,EAAE,IAAI,CAAC,GAAG;YACd,IAAI,EAAE,IAAI,CAAC,IAAI;SAChB,CAAA;IACH,CAAC;IAED,MAAM;QACJ,OAAO,IAAI,CAAC,IAAI,KAAK,UAAU,CAAA;IACjC,CAAC;IAED,QAAQ;QACN,OAAO,IAAI,CAAC,IAAI,KAAK,UAAU,CAAA;IACjC,CAAC;CACF","sourcesContent":["import { nanoid } from '../../nanoid.js'\nimport { IPermission, Permission, PermissionRole } from './Permission.js'\nimport { IModification } from './Modification.js'\nimport { IDeletion } from './Deletion.js'\nimport { IUser, Kind as UserKind } from './User.js'\nimport { IThing, Thing } from '../Thing.js'\nimport { ICapabilities } from './Capabilities.js'\nimport { FolderKind } from '../kinds.js'\n// this causes error\n// import { Kind as FolderKind } from '../Folder.js';\n\nexport interface FileAddOptions {\n /**\n * The parent folder where to put the file.\n * The `parents` array is always cleared from the file object before adding it to the store.\n */\n parent?: string\n}\n\nexport interface MediaReadOptions {\n /**\n * When set it reads the file that was marked as `_deleted`. By default it throws when file was deleted.\n */\n deleted?: boolean\n}\n\n/**\n * A breadcrumb when creating the breadcrumb list for a file.\n */\nexport interface FileBreadcrumb {\n /**\n * The datastore key of the object.\n */\n key: string\n /**\n * THe kind of the object.\n */\n kind: string\n /**\n * The name of the object.\n */\n name: string\n}\n\nexport interface IStoredFile {\n /**\n * The kind of the File\n */\n kind: string\n /**\n * The identifier of the entity\n */\n key: string\n /**\n * The file's meta info.\n */\n info: IThing\n /**\n * The color of the icon to render for this file in the file explorer.\n * This should be a hex format, e.g.: #c00 for red.\n */\n iconColor?: string\n /**\n * Whether the file is a shortcut to another file.\n * Many properties cannot be changed of a shortcut, like, shortcuts cannot be shared.\n */\n isShortcut?: boolean\n /**\n * The ID of the target file.\n */\n shortcutTarget?: string\n}\n\n/**\n * An interface describing an object in the data store that\n * describes a file or an object that can be treated as a file or a folder.\n */\nexport interface IFile extends IStoredFile {\n /**\n * The list of parents of the object. It is an ordered list of parents\n * from the top (first element) to the lowest parent in the tree (last element).\n *\n * After creating the object, this property cannot be manipulated directly by the client.\n * Should be treated as opaque value.\n */\n parents: string[]\n /**\n * The list of permissions to this file object.\n *\n * This property cannot be manipulated directly by the client. Should be treated as\n * opaque value.\n */\n permissionIds: string[]\n /**\n * Whether the file object is deleted.\n */\n deleted?: boolean\n /**\n * The information about the delete information.\n * Always set when the `delete` is true.\n */\n deletedInfo?: IDeletion\n /**\n * The last modification made to this file.\n */\n lastModified: IModification\n /**\n * An arbitrary list of labels applied to the file.\n */\n labels?: string[]\n /**\n * This is populated when reading a file from the store.\n * A list of actions the user can perform on the file.\n *\n * This is a readonly field and it is ignored when creating / updating the file.\n */\n capabilities?: ICapabilities\n /**\n * Populated by the server when reading the file. The list of permissions to the object.\n *\n * This property cannot be manipulated directly by the client. Should be treated as\n * opaque value.\n *\n * Data store implementation note, this is not stored in the store but it is populated\n * when reading the object.\n */\n permissions: IPermission[]\n /**\n * Populated by the store in some situations. If it's missing then you should request\n * breadcrumbs from the store.\n */\n breadcrumb?: FileBreadcrumb[]\n}\n\nconst parentsSymbol = Symbol('parents')\nconst deletedSymbol = Symbol('deleted')\nconst deletedInfoSymbol = Symbol('deletedInfo')\nconst lastModifiedSymbol = Symbol('lastModified')\nconst capabilitiesSymbol = Symbol('capabilities')\nconst permissionsSymbol = Symbol('permissions')\nconst permissionIdsSymbol = Symbol('permissionIds')\nconst shortcutTargetSymbol = Symbol('shortcutTarget')\n\nexport class StoredFile {\n /**\n * The kind of the File\n */\n kind = ''\n /**\n * The identifier of the entity\n */\n key = ''\n /**\n * The name of the environment.\n */\n info: Thing = Thing.fromName('')\n\n /**\n * The color of the icon to render for this file in the file explorer.\n */\n iconColor?: string\n\n /**\n * Whether the file is a shortcut to another file.\n * Many properties cannot be changed of a shortcut, like, shortcuts cannot be shared.\n */\n get isShortcut(): boolean {\n return !!this.shortcutTarget\n }\n\n [shortcutTargetSymbol]?: string\n\n /**\n * The ID of the target file.\n */\n get shortcutTarget(): string | undefined {\n return this[shortcutTargetSymbol]\n }\n\n set shortcutTarget(value: string | undefined) {\n this[shortcutTargetSymbol] = value\n }\n\n /**\n * Creates a file schema object with the given properties.\n * The `key` is generated if not set.\n *\n * @param input The input to create the file schema.\n * @returns The file schema object.\n */\n static createSchema(input: Partial<IStoredFile> = {}): IStoredFile {\n const { key = nanoid(), kind, iconColor, shortcutTarget } = input\n const result: IStoredFile = {\n key,\n kind: kind || '',\n info: Thing.fromJSON(input.info, { name: 'Unnamed file' }).toJSON(),\n }\n if (iconColor) {\n result.iconColor = iconColor\n }\n if (shortcutTarget) {\n result.isShortcut = true\n result.shortcutTarget = shortcutTarget\n }\n return result\n }\n\n constructor(state: IStoredFile) {\n this.kind = state.kind\n this.key = state.key\n this.info = new Thing(state.info)\n if (state.iconColor) {\n this.iconColor = state.iconColor\n }\n if (state.shortcutTarget) {\n this.shortcutTarget = state.shortcutTarget\n }\n }\n\n /**\n * @deprecated Use `createSchema()` and setup values in the constructor instead.\n */\n new(init: IStoredFile): this {\n const { key = nanoid(), info, kind, iconColor, shortcutTarget } = init\n this.key = key\n this.kind = kind\n if (info) {\n this.info = new Thing(info)\n } else {\n this.info = Thing.fromName('')\n }\n if (iconColor) {\n this.iconColor = iconColor\n } else {\n this.iconColor = undefined\n }\n if (shortcutTarget) {\n this.shortcutTarget = shortcutTarget\n } else {\n this.shortcutTarget = undefined\n }\n return this\n }\n\n toJSON(): IStoredFile {\n const result: IStoredFile = {\n key: this.key,\n kind: this.kind,\n info: this.info.toJSON(),\n }\n if (this.iconColor) {\n result.iconColor = this.iconColor\n }\n if (this.shortcutTarget) {\n result.isShortcut = true\n result.shortcutTarget = this.shortcutTarget\n }\n return result\n }\n\n /**\n * Creates the Capabilities object for a file giving user level.\n *\n * @param file The file object to create the capabilities to. The object is not mutated.\n * @param role The user role to the file.\n */\n static createFileCapabilities(file: IStoredFile | StoredFile, role?: PermissionRole): ICapabilities {\n const isCommenter = Permission.hasRole('commenter', role)\n const isOwner = Permission.hasRole('owner', role)\n const isReader = Permission.hasRole('reader', role)\n const isWriter = Permission.hasRole('writer', role)\n const isFolder = file.kind === FolderKind\n const result: ICapabilities = {\n canReadMedia: !isFolder && isReader,\n canListChildren: isFolder && isReader,\n canComment: !isFolder && isCommenter,\n canEditMedia: !isFolder && isWriter,\n canEditMeta: isWriter,\n canReadRevisions: isWriter,\n canAddChildren: isFolder && isWriter,\n canDelete: isOwner,\n canTrash: isOwner,\n canUntrash: isOwner,\n canShare: isWriter,\n canMove: isWriter,\n }\n return result\n }\n\n createFileCapabilities(role: PermissionRole): ICapabilities {\n return File.createFileCapabilities(this, role)\n }\n\n /**\n * Mutates the file object by setting the `byMe` properties (on deleted and modified info)\n *\n * Note, this can be done only on file schema (IFile). The `File` object has\n * this properties frozen.\n *\n * @param file The file to mutate\n * @param user The user key to compare.\n */\n static updateByMeMeta(file: IFile, user: string): void {\n if (file.deletedInfo) {\n file.deletedInfo.byMe = file.deletedInfo.user === user\n }\n if (file.lastModified) {\n file.lastModified.byMe = file.lastModified.user === user\n }\n }\n\n /**\n * Static method to set the `lastModified` property on a file without creating an instance of a file meta.\n * Useful when the meta kind is unknown.\n *\n * @param file The file to update. Note, this method mutates the file.\n * @param user The user that modifies the file.\n * @returns The same file.\n */\n static setLastModified(file: IFile, user: IUser): IFile {\n if (!file) {\n throw new Error(`The file is required.`)\n }\n if (!user) {\n throw new Error(`The user is required.`)\n }\n if (user.kind !== UserKind) {\n throw new Error(`Invalid value for the user when setting \"lastModified\".`)\n }\n file.lastModified = {\n byMe: false,\n time: Date.now(),\n user: user.key,\n name: user.name,\n }\n return file\n }\n\n /**\n * Similar to the instance method `setDeleted()` but without creating\n * an instance of the file when the type is unknown.\n *\n * @param file The file to change. Note, this operation mutates the file.\n * @param user The deleting user\n * @returns The same file reference.\n */\n static setDeleted(file: IFile, user: IUser): IFile {\n if (!file) {\n throw new Error(`The file is required.`)\n }\n if (!user) {\n throw new Error(`The user is required.`)\n }\n if (user.kind !== UserKind) {\n throw new Error(`Invalid value for the user when setting \"deletedInfo\".`)\n }\n file.deleted = true\n file.deletedInfo = {\n byMe: false,\n time: Date.now(),\n user: user.key,\n name: user.name,\n }\n return file\n }\n}\n\nexport class File extends StoredFile {\n [parentsSymbol]: string[] = []\n\n /**\n * The list of parents of the object. It is an ordered list of parents\n * from the top (first element) to the lowest parent in the tree (last element).\n *\n * This property cannot be manipulated directly by the client. Should be treated as\n * opaque value.\n */\n get parents(): string[] {\n return this[parentsSymbol]\n }\n\n [permissionIdsSymbol]: readonly string[] = []\n\n /**\n * The list of permissions to this file object.\n *\n * This property cannot be manipulated directly by the client. Should be treated as\n * opaque value.\n */\n get permissionIds(): readonly string[] {\n return this[permissionIdsSymbol]\n }\n\n [deletedSymbol]?: boolean\n\n /**\n * Whether the file object is deleted.\n */\n get deleted(): boolean {\n return this[deletedSymbol] || false\n }\n\n [deletedInfoSymbol]?: Readonly<IDeletion>\n\n /**\n * The information about the delete information.\n * Always set when the `delete` is true.\n */\n get deletedInfo(): Readonly<IDeletion> | undefined {\n return this[deletedInfoSymbol]\n }\n\n [lastModifiedSymbol]: Readonly<IModification> = { user: '', time: 0, byMe: false }\n\n /**\n * The last modification made to this file.\n */\n get lastModified(): Readonly<IModification> {\n return this[lastModifiedSymbol]\n }\n\n /**\n * An arbitrary list of labels applied to the file.\n */\n labels?: string[];\n\n [capabilitiesSymbol]?: Readonly<ICapabilities>\n\n /**\n * This is populated when reading a file from the store.\n * A list of actions the user can perform on the file.\n *\n * This is a readonly field and it is ignored when creating / updating the file.\n */\n get capabilities(): Readonly<ICapabilities> | undefined {\n return this[capabilitiesSymbol]\n }\n\n [permissionsSymbol]: readonly IPermission[] = []\n\n /**\n * Populated by the server when reading the file. The list of permissions to the object.\n *\n * This property cannot be manipulated directly by the client. Should be treated as\n * opaque value.\n */\n get permissions(): readonly IPermission[] {\n return this[permissionsSymbol]\n }\n\n static override createSchema(input: Partial<IFile> = {}): IFile {\n const result = StoredFile.createSchema(input) as IFile\n if (Array.isArray(input.parents)) {\n result.parents = [...input.parents]\n } else {\n result.parents = []\n }\n if (Array.isArray(input.permissionIds)) {\n result.permissionIds = [...input.permissionIds]\n } else {\n result.permissionIds = []\n }\n if (Array.isArray(input.permissions)) {\n result.permissions = input.permissions.map((i) => ({ ...i }))\n } else {\n result.permissions = []\n }\n if (input.capabilities) {\n result.capabilities = { ...input.capabilities }\n }\n if (input.lastModified) {\n result.lastModified = { ...input.lastModified }\n } else {\n result.lastModified = { user: '', time: 0, byMe: false }\n }\n if (typeof input.deleted === 'boolean') {\n result.deleted = input.deleted\n result.deletedInfo = input.deletedInfo ? { ...input.deletedInfo } : undefined\n }\n if (Array.isArray(input.labels)) {\n result.labels = [...input.labels]\n }\n if (typeof input.shortcutTarget === 'string') {\n result.shortcutTarget = input.shortcutTarget\n }\n return result\n }\n\n constructor(state?: Partial<IFile>) {\n const init = File.createSchema(state)\n super(init)\n this[parentsSymbol] = [...init.parents]\n this[permissionIdsSymbol] = [...init.permissionIds]\n this[permissionsSymbol] = init.permissions.map((i) => ({ ...i }))\n this[capabilitiesSymbol] = init.capabilities ? { ...init.capabilities } : undefined\n this[lastModifiedSymbol] = Object.freeze({ ...init.lastModified })\n if (typeof init.deleted === 'boolean') {\n this[deletedSymbol] = init.deleted\n this[deletedInfoSymbol] = init.deletedInfo ? Object.freeze({ ...init.deletedInfo }) : undefined\n }\n if (Array.isArray(init.labels)) {\n this.labels = [...init.labels]\n }\n }\n\n /**\n * @deprecated Use `createSchema()` and setup values in the constructor instead.\n */\n override new(init: IFile): this {\n super.new(init)\n const { permissions = [], parents = [], permissionIds = [], deleted, deletedInfo, lastModified, labels } = init\n this[permissionsSymbol] = permissions.map((i) => ({ ...i }))\n this[parentsSymbol] = [...parents]\n this[permissionIdsSymbol] = [...permissionIds]\n this[lastModifiedSymbol] = lastModified\n ? Object.freeze({ ...lastModified })\n : Object.freeze({ user: '', time: 0, byMe: false })\n if (typeof deleted === 'boolean') {\n this[deletedSymbol] = deleted\n this[deletedInfoSymbol] = deletedInfo ? Object.freeze({ ...deletedInfo }) : undefined\n } else {\n this[deletedSymbol] = undefined\n this[deletedInfoSymbol] = undefined\n }\n if (Array.isArray(labels)) {\n this.labels = [...labels]\n } else {\n this.labels = undefined\n }\n return this\n }\n\n override toJSON(): IFile {\n const result: IFile = {\n ...super.toJSON(),\n parents: [...this.parents],\n permissionIds: [...this.permissionIds],\n lastModified: { ...this.lastModified },\n permissions: [...this.permissions],\n }\n if (this.deleted) {\n result.deleted = this.deleted\n result.deletedInfo = { ...this.deletedInfo } as IDeletion\n }\n if (Array.isArray(this.labels)) {\n result.labels = [...this.labels]\n }\n return result\n }\n\n /**\n * @param name The name to set.\n * @param kind The kind of the file to create.\n */\n static fromName(name: string, kind: string): File {\n const definition = new File({ kind, info: { name } })\n return definition\n }\n\n shortcutTo(fileId: string): this {\n this.shortcutTarget = fileId\n return this\n }\n\n /**\n * Updates the \"lastModified\" value.\n * A helper method for a common task.\n *\n * @param user The user that modifies the entity.\n */\n setLastModified(user: IUser): void {\n if (!user) {\n throw new Error(`The user is required.`)\n }\n if (user.kind !== UserKind) {\n throw new Error(`Invalid value for the user when setting \"lastModified\".`)\n }\n this[lastModifiedSymbol] = {\n byMe: false,\n time: Date.now(),\n user: user.key,\n name: user.name,\n }\n }\n\n /**\n * Adds a label to the list of labels.\n *\n * It makes sure the value is a valid, non-empty string and the `labels` array is set.\n *\n * It does nothing when the label already exists.\n *\n * @param label The label to set.\n */\n addLabel(label: string): void {\n if (typeof label !== 'string') {\n throw new Error(`The label must be a string.`)\n }\n if (!label.trim()) {\n throw new Error(`The label is required.`)\n }\n if (!Array.isArray(this.labels)) {\n this.labels = []\n }\n if (this.labels.includes(label)) {\n return\n }\n this.labels.push(label)\n }\n\n /**\n * Marks the entity as deleted.\n *\n * A helper method for a common task.\n *\n * @param user The user that deletes the entity.\n */\n setDeleted(user: IUser): void {\n if (!user) {\n throw new Error(`The user is required.`)\n }\n if (user.kind !== UserKind) {\n throw new Error(`Invalid value for the user when setting \"deletedInfo\".`)\n }\n this[deletedSymbol] = true\n this[deletedInfoSymbol] = {\n byMe: false,\n time: Date.now(),\n user: user.key,\n name: user.name,\n }\n }\n\n isFile(): boolean {\n return this.kind !== FolderKind\n }\n\n isFolder(): boolean {\n return this.kind === FolderKind\n }\n}\n"]}
@@ -1,22 +1,96 @@
1
+ import { GroupKind } from '../kinds.js';
2
+ import type { IDeletion } from './Deletion.js';
3
+ /**
4
+ * @deprecated Use `GroupSchema` instead.
5
+ * This interface is kept for backward compatibility.
6
+ */
7
+ export interface IGroup extends GroupSchema {
8
+ }
1
9
  /**
2
10
  * An object representing a user group.
3
11
  */
4
- export interface IGroup {
12
+ export interface GroupSchema {
13
+ kind: typeof GroupKind;
5
14
  /**
6
15
  * The key of the group.
16
+ * If not provided, it will be generated automatically by the API
7
17
  */
8
18
  key: string;
9
19
  /**
10
- * The name of the group
20
+ * The name of the group.
21
+ * This is a required field and must be unique within the organization.
22
+ * @required
11
23
  */
12
24
  name: string;
25
+ /**
26
+ * The description of the group.
27
+ */
28
+ description?: string;
13
29
  /**
14
30
  * The id of the user that created this group.
31
+ * This field is ignored by the API and is set automatically.
32
+ * @readonly
15
33
  */
16
34
  owner: string;
35
+ /**
36
+ * The icon of the group, if any.
37
+ * An optional icon for the group, stored as a URL or path.
38
+ * Max 255 characters.
39
+ */
40
+ icon?: string;
41
+ /**
42
+ * The color of the group, if any.
43
+ * An optional color for the group, stored as a hex code.
44
+ * Max 50 characters (including the #).
45
+ */
46
+ color?: string;
47
+ /**
48
+ * The organization ID this group belongs to.
49
+ * This field is ignored by the API and is set automatically.
50
+ * @readonly
51
+ */
52
+ oid: string;
17
53
  /**
18
54
  * The list of users in this group.
55
+ * This field is ignored by the API and is set automatically.
56
+ * @readonly
19
57
  */
20
58
  users: string[];
59
+ /**
60
+ * Describes when this group was created
61
+ * This field is ignored by the API and is set automatically.
62
+ * @readonly
63
+ */
64
+ createdAt: number;
65
+ /**
66
+ * Describes when this group was updated
67
+ * This field is ignored by the API and is set automatically.
68
+ * @readonly
69
+ */
70
+ updatedAt: number;
71
+ /**
72
+ * Optional deletion information if the group has been deleted.
73
+ * This field is ignored by the API and is set automatically.
74
+ * @readonly
75
+ */
76
+ deleteInfo?: IDeletion;
77
+ }
78
+ export declare class Group implements GroupSchema {
79
+ kind: typeof GroupKind;
80
+ key: string;
81
+ name: string;
82
+ description?: string;
83
+ owner: string;
84
+ icon?: string;
85
+ color?: string;
86
+ oid: string;
87
+ users: string[];
88
+ createdAt: number;
89
+ updatedAt: number;
90
+ deleteInfo?: IDeletion;
91
+ static createSchema(input?: Partial<GroupSchema>): GroupSchema;
92
+ static fromName(name: string, oid: string): Group;
93
+ constructor(state?: Partial<GroupSchema>);
94
+ toJSON(): GroupSchema;
21
95
  }
22
96
  //# sourceMappingURL=Group.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"Group.d.ts","sourceRoot":"","sources":["../../../../src/models/store/Group.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,WAAW,MAAM;IACrB;;OAEG;IACH,GAAG,EAAE,MAAM,CAAA;IACX;;OAEG;IACH,IAAI,EAAE,MAAM,CAAA;IACZ;;OAEG;IACH,KAAK,EAAE,MAAM,CAAA;IACb;;OAEG;IACH,KAAK,EAAE,MAAM,EAAE,CAAA;CAChB"}
1
+ {"version":3,"file":"Group.d.ts","sourceRoot":"","sources":["../../../../src/models/store/Group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I,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,KAAK;gBAIrC,KAAK,CAAC,EAAE,OAAO,CAAC,WAAW,CAAC;IAexC,MAAM,IAAI,WAAW;CAyBtB"}
@@ -1,2 +1,85 @@
1
- export {};
1
+ import { GroupKind } from '../kinds.js';
2
+ import { nanoid } from '../../nanoid.js';
3
+ export class Group {
4
+ kind = GroupKind;
5
+ key = '';
6
+ name = '';
7
+ description;
8
+ owner = '';
9
+ icon;
10
+ color;
11
+ oid = '';
12
+ users = [];
13
+ createdAt = 0;
14
+ updatedAt = 0;
15
+ deleteInfo;
16
+ static createSchema(input = {}) {
17
+ const { key = nanoid() } = input;
18
+ const result = {
19
+ kind: GroupKind,
20
+ key,
21
+ name: input.name || 'Unnamed group',
22
+ oid: input.oid || '',
23
+ owner: input.owner || '',
24
+ users: input.users || [],
25
+ createdAt: input.createdAt || Date.now(),
26
+ updatedAt: input.updatedAt || Date.now(),
27
+ };
28
+ if (input.description) {
29
+ result.description = input.description;
30
+ }
31
+ if (input.icon) {
32
+ result.icon = input.icon;
33
+ }
34
+ if (input.color) {
35
+ result.color = input.color;
36
+ }
37
+ if (input.deleteInfo) {
38
+ result.deleteInfo = input.deleteInfo;
39
+ }
40
+ return result;
41
+ }
42
+ static fromName(name, oid) {
43
+ return new Group({ name, oid });
44
+ }
45
+ constructor(state) {
46
+ const init = Group.createSchema(state);
47
+ this.key = init.key;
48
+ this.name = init.name;
49
+ this.description = init.description;
50
+ this.owner = init.owner;
51
+ this.icon = init.icon;
52
+ this.color = init.color;
53
+ this.oid = init.oid;
54
+ this.users = init.users;
55
+ this.createdAt = init.createdAt;
56
+ this.updatedAt = init.updatedAt;
57
+ this.deleteInfo = init.deleteInfo;
58
+ }
59
+ toJSON() {
60
+ const result = {
61
+ kind: this.kind,
62
+ key: GroupKind,
63
+ name: this.name,
64
+ oid: this.oid,
65
+ owner: this.owner,
66
+ users: [...this.users],
67
+ createdAt: this.createdAt,
68
+ updatedAt: this.updatedAt,
69
+ };
70
+ if (this.description) {
71
+ result.description = this.description;
72
+ }
73
+ if (this.icon) {
74
+ result.icon = this.icon;
75
+ }
76
+ if (this.color) {
77
+ result.color = this.color;
78
+ }
79
+ if (this.deleteInfo) {
80
+ result.deleteInfo = { ...this.deleteInfo };
81
+ }
82
+ return result;
83
+ }
84
+ }
2
85
  //# sourceMappingURL=Group.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"Group.js","sourceRoot":"","sources":["../../../../src/models/store/Group.ts"],"names":[],"mappings":"","sourcesContent":["/**\n * An object representing a user group.\n */\nexport interface IGroup {\n /**\n * The key of the group.\n */\n key: string\n /**\n * The name of the group\n */\n name: string\n /**\n * The id of the user that created this group.\n */\n owner: string\n /**\n * The list of users in this group.\n */\n users: string[]\n}\n"]}
1
+ {"version":3,"file":"Group.js","sourceRoot":"","sources":["../../../../src/models/store/Group.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAA;AAEvC,OAAO,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAA;AA+ExC,MAAM,OAAO,KAAK;IAChB,IAAI,GAAqB,SAAS,CAAA;IAClC,GAAG,GAAG,EAAE,CAAA;IACR,IAAI,GAAG,EAAE,CAAA;IACT,WAAW,CAAS;IACpB,KAAK,GAAG,EAAE,CAAA;IACV,IAAI,CAAS;IACb,KAAK,CAAS;IACd,GAAG,GAAG,EAAE,CAAA;IACR,KAAK,GAAa,EAAE,CAAA;IACpB,SAAS,GAAG,CAAC,CAAA;IACb,SAAS,GAAG,CAAC,CAAA;IACb,UAAU,CAAY;IAEtB,MAAM,CAAC,YAAY,CAAC,QAA8B,EAAE;QAClD,MAAM,EAAE,GAAG,GAAG,MAAM,EAAE,EAAE,GAAG,KAAK,CAAA;QAChC,MAAM,MAAM,GAAgB;YAC1B,IAAI,EAAE,SAAS;YACf,GAAG;YACH,IAAI,EAAE,KAAK,CAAC,IAAI,IAAI,eAAe;YACnC,GAAG,EAAE,K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CAAC,KAAK,GAAG,IAAI,CAAC,KAAK,CAAA;QACvB,IAAI,CAAC,GAAG,GAAG,IAAI,CAAC,GAAG,CAAA;QACnB,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC,KAAK,CAAA;QACvB,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC,SAAS,CAAA;QAC/B,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC,SAAS,CAAA;QAC/B,IAAI,CAAC,UAAU,GAAG,IAAI,CAAC,UAAU,CAAA;IACnC,CAAC;IAED,MAAM;QACJ,MAAM,MAAM,GAAgB;YAC1B,IAAI,EAAE,IAAI,CAAC,IAAI;YACf,GAAG,EAAE,SAAS;YACd,IAAI,EAAE,IAAI,CAAC,IAAI;YACf,GAAG,EAAE,IAAI,CAAC,GAAG;YACb,KAAK,EAAE,IAAI,CAAC,KAAK;YACjB,KAAK,EAAE,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC;YACtB,SAAS,EAAE,IAAI,CAAC,SAAS;YACzB,SAAS,EAAE,IAAI,CAAC,SAAS;SAC1B,CAAA;QACD,IAAI,IAAI,CAAC,WAAW,EAAE,CAAC;YACrB,MAAM,CAAC,WAAW,GAAG,IAAI,CAAC,WAAW,CAAA;QACvC,CAAC;QACD,IAAI,IAAI,CAAC,IAAI,EAAE,CAAC;YACd,MAAM,CAAC,IAAI,GAAG,IAAI,CAAC,IAAI,CAAA;QACzB,CAAC;QACD,IAAI,IAAI,CAAC,KAAK,EAAE,CAAC;YACf,MAAM,CAAC,KAAK,GAAG,IAAI,CAAC,KAAK,CAAA;QAC3B,CAAC;QACD,IAAI,IAAI,CAAC,UAAU,EAAE,CAAC;YACpB,MAAM,CAAC,UAAU,GAAG,EAAE,GAAG,IAAI,CAAC,UAAU,EAAE,CAAA;QAC5C,CAAC;QACD,OAAO,MAAM,CAAA;IACf,CAAC;CACF","sourcesContent":["import { GroupKind } from '../kinds.js'\nimport type { IDeletion } from './Deletion.js'\nimport { nanoid } from '../../nanoid.js'\n\n/**\n * @deprecated Use `GroupSchema` instead.\n * This interface is kept for backward compatibility.\n */\n// eslint-disable-next-line @typescript-eslint/no-empty-object-type\nexport interface IGroup extends GroupSchema {}\n\n/**\n * An object representing a user group.\n */\nexport interface GroupSchema {\n kind: typeof GroupKind\n /**\n * The key of the group.\n * If not provided, it will be generated automatically by the API\n */\n key: string\n /**\n * The name of the group.\n * This is a required field and must be unique within the organization.\n * @required\n */\n name: string\n /**\n * The description of the group.\n */\n description?: string\n /**\n * The id of the user that created this group.\n * This field is ignored by the API and is set automatically.\n * @readonly\n */\n owner: string\n /**\n * The icon of the group, if any.\n * An optional icon for the group, stored as a URL or path.\n * Max 255 characters.\n */\n icon?: string\n /**\n * The color of the group, if any.\n * An optional color for the group, stored as a hex code.\n * Max 50 characters (including the #).\n */\n color?: string\n /**\n * The organization ID this group belongs to.\n * This field is ignored by the API and is set automatically.\n * @readonly\n */\n oid: string\n /**\n * The list of users in this group.\n * This field is ignored by the API and is set automatically.\n * @readonly\n */\n users: string[]\n /**\n * Describes when this group was created\n * This field is ignored by the API and is set automatically.\n * @readonly\n */\n createdAt: number\n /**\n * Describes when this group was updated\n * This field is ignored by the API and is set automatically.\n * @readonly\n */\n updatedAt: number\n /**\n * Optional deletion information if the group has been deleted.\n * This field is ignored by the API and is set automatically.\n * @readonly\n */\n deleteInfo?: IDeletion\n}\n\nexport class Group implements GroupSchema {\n kind: typeof GroupKind = GroupKind\n key = ''\n name = ''\n description?: string\n owner = ''\n icon?: string\n color?: string\n oid = ''\n users: string[] = []\n createdAt = 0\n updatedAt = 0\n deleteInfo?: IDeletion\n\n static createSchema(input: Partial<GroupSchema> = {}): GroupSchema {\n const { key = nanoid() } = input\n const result: GroupSchema = {\n kind: GroupKind,\n key,\n name: input.name || 'Unnamed group',\n oid: input.oid || '',\n owner: input.owner || '',\n users: input.users || [],\n createdAt: input.createdAt || Date.now(),\n updatedAt: input.updatedAt || Date.now(),\n }\n if (input.description) {\n result.description = input.description\n }\n if (input.icon) {\n result.icon = input.icon\n }\n if (input.color) {\n result.color = input.color\n }\n if (input.deleteInfo) {\n result.deleteInfo = input.deleteInfo\n }\n return result\n }\n\n static fromName(name: string, oid: string): Group {\n return new Group({ name, oid })\n }\n\n constructor(state?: Partial<GroupSchema>) {\n const init = Group.createSchema(state)\n this.key = init.key\n this.name = init.name\n this.description = init.description\n this.owner = init.owner\n this.icon = init.icon\n this.color = init.color\n this.oid = init.oid\n this.users = init.users\n this.createdAt = init.createdAt\n this.updatedAt = init.updatedAt\n this.deleteInfo = init.deleteInfo\n }\n\n toJSON(): GroupSchema {\n const result: GroupSchema = {\n kind: this.kind,\n key: GroupKind,\n name: this.name,\n oid: this.oid,\n owner: this.owner,\n users: [...this.users],\n createdAt: this.createdAt,\n updatedAt: this.updatedAt,\n }\n if (this.description) {\n result.description = this.description\n }\n if (this.icon) {\n result.icon = this.icon\n }\n if (this.color) {\n result.color = this.color\n }\n if (this.deleteInfo) {\n result.deleteInfo = { ...this.deleteInfo }\n }\n return result\n }\n}\n"]}
@@ -0,0 +1,41 @@
1
+ import { ContextListOptions, ContextListResult } from '../browser.js';
2
+ import type { GroupSchema } from '../models/store/Group.js';
3
+ import { SdkBase, type SdkOptions } from './SdkBase.js';
4
+ export declare class GroupsSdk extends SdkBase {
5
+ /**
6
+ * Creates a new group in the specified organization.
7
+ * @param oid The organization ID where the group will be created.
8
+ * @param info The information about the group to create. See the `GroupSchema` interface for required fields.
9
+ * @param request Optional SDK options, including authentication token.
10
+ * @returns A promise that resolves to the created group.
11
+ */
12
+ create(oid: string, info: Partial<GroupSchema>, request?: SdkOptions): Promise<GroupSchema>;
13
+ /**
14
+ * Lists user groups in the specified organization.
15
+ * If you want to list specific user groups, you can use the `uid` option to filter by user ID.
16
+ * @param oid The organization ID to list groups from.
17
+ * @param options Optional parameters for filtering, sorting, and pagination.
18
+ * @param request Optional SDK options, including authentication token.
19
+ * @returns A promise that resolves to a list of groups in the organization.
20
+ */
21
+ list(oid: string, options?: ContextListOptions, request?: SdkOptions): Promise<ContextListResult<GroupSchema>>;
22
+ /**
23
+ * Updates an existing group in the specified organization.
24
+ * Note that this method support PUT requests only. Some fields are ignored by the API and are set automatically.
25
+ * @param oid The organization ID where the group exists.
26
+ * @param updated The updated information for the group. Must include the `key` of the group to update.
27
+ * @param request Optional SDK options, including authentication token.
28
+ * @returns A promise that resolves to the updated group.
29
+ */
30
+ update(oid: string, updated: GroupSchema, request?: SdkOptions): Promise<GroupSchema>;
31
+ /**
32
+ * Deletes a group in the specified organization.
33
+ * The groups support soft deletion, meaning that the group is not immediately removed from the database.
34
+ * @param oid The organization ID where the group exists.
35
+ * @param gid The group ID to delete.
36
+ * @param request Optional SDK options, including authentication token.
37
+ * @returns A promise that resolves when the group is deleted.
38
+ */
39
+ delete(oid: string, gid: string, request?: SdkOptions): Promise<void>;
40
+ }
41
+ //# sourceMappingURL=GroupsSdk.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"GroupsSdk.d.ts","sourceRoot":"","sources":["../../../src/sdk/GroupsSdk.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAA;AAErE,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAA;AAE3D,OAAO,EAKL,OAAO,EACP,KAAK,UAAU,EAChB,MAAM,cAAc,CAAA;AAErB,qBAAa,SAAU,SAAQ,OAAO;IACpC;;;;;;OAMG;IACG,MAAM,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,OAAO,CAAC,WAAW,CAAC,EAAE,OAAO,GAAE,UAAe,GAAG,OAAO,CAAC,WAAW,CAAC;IAiCrG;;;;;;;OAOG;IACG,IAAI,CACR,GAAG,EAAE,MAAM,EACX,OAAO,GAAE,kBAAuB,EAChC,OAAO,GAAE,UAAe,GACvB,OAAO,CAAC,iBAAiB,CAAC,WAAW,CAAC,CAAC;IAuB1C;;;;;;;OAOG;IACG,MAAM,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,EAAE,WAAW,EAAE,OAAO,GAAE,UAAe,GAAG,OAAO,CAAC,WAAW,CAAC;IAiC/F;;;;;;;OAOG;IACG,MAAM,CAAC,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,OAAO,GAAE,UAAe,GAAG,OAAO,CAAC,IAAI,CAAC;CAWhF"}