@api-client/core 0.13.5 → 0.14.0

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 (164) hide show
  1. package/build/src/amf/AmfShapeGenerator.js +1 -1
  2. package/build/src/amf/AmfShapeGenerator.js.map +1 -1
  3. package/build/src/amf/DataValueGenerator.js +1 -1
  4. package/build/src/amf/DataValueGenerator.js.map +1 -1
  5. package/build/src/amf/models/AmfDataNode.js +1 -1
  6. package/build/src/amf/models/AmfDataNode.js.map +1 -1
  7. package/build/src/browser.d.ts +1 -1
  8. package/build/src/browser.d.ts.map +1 -1
  9. package/build/src/browser.js.map +1 -1
  10. package/build/src/index.d.ts +2 -1
  11. package/build/src/index.d.ts.map +1 -1
  12. package/build/src/index.js +1 -0
  13. package/build/src/index.js.map +1 -1
  14. package/build/src/modeling/DataDomain.js +1 -1
  15. package/build/src/modeling/DataDomain.js.map +1 -1
  16. package/build/src/modeling/DomainAssociation.js +1 -1
  17. package/build/src/modeling/DomainAssociation.js.map +1 -1
  18. package/build/src/modeling/DomainEntity.js +1 -1
  19. package/build/src/modeling/DomainEntity.js.map +1 -1
  20. package/build/src/modeling/DomainFile.d.ts +2 -3
  21. package/build/src/modeling/DomainFile.d.ts.map +1 -1
  22. package/build/src/modeling/DomainFile.js +5 -9
  23. package/build/src/modeling/DomainFile.js.map +1 -1
  24. package/build/src/modeling/DomainModel.js +1 -1
  25. package/build/src/modeling/DomainModel.js.map +1 -1
  26. package/build/src/modeling/DomainNamespace.js +1 -1
  27. package/build/src/modeling/DomainNamespace.js.map +1 -1
  28. package/build/src/modeling/DomainProperty.js +1 -1
  29. package/build/src/modeling/DomainProperty.js.map +1 -1
  30. package/build/src/modeling/amf/ShapeGenerator.js +1 -1
  31. package/build/src/modeling/amf/ShapeGenerator.js.map +1 -1
  32. package/build/src/modeling/legacy/DataAssociation.js +1 -1
  33. package/build/src/modeling/legacy/DataAssociation.js.map +1 -1
  34. package/build/src/modeling/legacy/DataEntity.js +1 -1
  35. package/build/src/modeling/legacy/DataEntity.js.map +1 -1
  36. package/build/src/modeling/legacy/DataEntityBuilder.js +1 -1
  37. package/build/src/modeling/legacy/DataEntityBuilder.js.map +1 -1
  38. package/build/src/modeling/legacy/DataModel.js +1 -1
  39. package/build/src/modeling/legacy/DataModel.js.map +1 -1
  40. package/build/src/modeling/legacy/DataNamespace.js +1 -1
  41. package/build/src/modeling/legacy/DataNamespace.js.map +1 -1
  42. package/build/src/modeling/legacy/DataProperty.js +1 -1
  43. package/build/src/modeling/legacy/DataProperty.js.map +1 -1
  44. package/build/src/models/AuthorizationData.js +1 -1
  45. package/build/src/models/AuthorizationData.js.map +1 -1
  46. package/build/src/models/CertificateFile.d.ts +2 -3
  47. package/build/src/models/CertificateFile.d.ts.map +1 -1
  48. package/build/src/models/CertificateFile.js +5 -9
  49. package/build/src/models/CertificateFile.js.map +1 -1
  50. package/build/src/models/ClientCertificate.js +1 -1
  51. package/build/src/models/ClientCertificate.js.map +1 -1
  52. package/build/src/models/Environment.js +1 -1
  53. package/build/src/models/Environment.js.map +1 -1
  54. package/build/src/models/Folder.d.ts +1 -2
  55. package/build/src/models/Folder.d.ts.map +1 -1
  56. package/build/src/models/Folder.js +3 -5
  57. package/build/src/models/Folder.js.map +1 -1
  58. package/build/src/models/HostRule.js +1 -1
  59. package/build/src/models/HostRule.js.map +1 -1
  60. package/build/src/models/HttpProject.js +1 -1
  61. package/build/src/models/HttpProject.js.map +1 -1
  62. package/build/src/models/Project.d.ts +2 -3
  63. package/build/src/models/Project.d.ts.map +1 -1
  64. package/build/src/models/Project.js +5 -9
  65. package/build/src/models/Project.js.map +1 -1
  66. package/build/src/models/ProjectFolder.js +1 -1
  67. package/build/src/models/ProjectFolder.js.map +1 -1
  68. package/build/src/models/ProjectRequest.js +1 -1
  69. package/build/src/models/ProjectRequest.js.map +1 -1
  70. package/build/src/models/ProjectSchema.js +1 -1
  71. package/build/src/models/ProjectSchema.js.map +1 -1
  72. package/build/src/models/store/DataFile.d.ts +2 -4
  73. package/build/src/models/store/DataFile.d.ts.map +1 -1
  74. package/build/src/models/store/DataFile.js +5 -10
  75. package/build/src/models/store/DataFile.js.map +1 -1
  76. package/build/src/models/store/File.d.ts +1 -21
  77. package/build/src/models/store/File.d.ts.map +1 -1
  78. package/build/src/models/store/File.js +4 -24
  79. package/build/src/models/store/File.js.map +1 -1
  80. package/build/src/models/store/Invitation.js +1 -1
  81. package/build/src/models/store/Invitation.js.map +1 -1
  82. package/build/src/models/store/Organization.js +1 -1
  83. package/build/src/models/store/Organization.js.map +1 -1
  84. package/build/src/models/store/Permission.d.ts +34 -0
  85. package/build/src/models/store/Permission.d.ts.map +1 -1
  86. package/build/src/models/store/Permission.js +28 -2
  87. package/build/src/models/store/Permission.js.map +1 -1
  88. package/build/src/models/store/UserIdentity.js +1 -1
  89. package/build/src/models/store/UserIdentity.js.map +1 -1
  90. package/build/src/models/transformers/ArcDexieTransformer.js +1 -1
  91. package/build/src/models/transformers/ArcDexieTransformer.js.map +1 -1
  92. package/build/src/models/transformers/ArcLegacyTransformer.js +1 -1
  93. package/build/src/models/transformers/ArcLegacyTransformer.js.map +1 -1
  94. package/build/src/models/transformers/ArcPouchTransformer.js +1 -1
  95. package/build/src/models/transformers/ArcPouchTransformer.js.map +1 -1
  96. package/build/src/models/transformers/PostmanV21Transformer.js +1 -1
  97. package/build/src/models/transformers/PostmanV21Transformer.js.map +1 -1
  98. package/build/src/models/transformers/PostmanV2Transformer.js +1 -1
  99. package/build/src/models/transformers/PostmanV2Transformer.js.map +1 -1
  100. package/build/src/nanoid.d.ts +10 -0
  101. package/build/src/nanoid.d.ts.map +1 -0
  102. package/build/src/nanoid.js +11 -0
  103. package/build/src/nanoid.js.map +1 -0
  104. package/build/src/patch/PatchClient.js +1 -1
  105. package/build/src/patch/PatchClient.js.map +1 -1
  106. package/build/src/sdk/FilesSdk.js +2 -2
  107. package/build/src/sdk/FilesSdk.js.map +1 -1
  108. package/build/tsconfig.tsbuildinfo +1 -1
  109. package/data/models/example-generator-api.json +15 -15
  110. package/eslint.config.js +1 -0
  111. package/package.json +6 -5
  112. package/src/amf/AmfShapeGenerator.ts +1 -1
  113. package/src/amf/DataValueGenerator.ts +1 -1
  114. package/src/amf/models/AmfDataNode.ts +1 -1
  115. package/src/modeling/DataDomain.ts +1 -1
  116. package/src/modeling/DomainAssociation.ts +1 -1
  117. package/src/modeling/DomainEntity.ts +1 -1
  118. package/src/modeling/DomainFile.ts +5 -9
  119. package/src/modeling/DomainModel.ts +1 -1
  120. package/src/modeling/DomainNamespace.ts +1 -1
  121. package/src/modeling/DomainProperty.ts +1 -1
  122. package/src/modeling/amf/ShapeGenerator.ts +1 -1
  123. package/src/modeling/legacy/DataAssociation.ts +1 -1
  124. package/src/modeling/legacy/DataEntity.ts +1 -1
  125. package/src/modeling/legacy/DataEntityBuilder.ts +1 -1
  126. package/src/modeling/legacy/DataModel.ts +1 -1
  127. package/src/modeling/legacy/DataNamespace.ts +1 -1
  128. package/src/modeling/legacy/DataProperty.ts +1 -1
  129. package/src/models/AuthorizationData.ts +1 -1
  130. package/src/models/CertificateFile.ts +5 -13
  131. package/src/models/ClientCertificate.ts +1 -1
  132. package/src/models/Environment.ts +1 -1
  133. package/src/models/Folder.ts +3 -5
  134. package/src/models/HostRule.ts +1 -1
  135. package/src/models/HttpProject.ts +1 -1
  136. package/src/models/Project.ts +5 -9
  137. package/src/models/ProjectFolder.ts +1 -1
  138. package/src/models/ProjectRequest.ts +1 -1
  139. package/src/models/ProjectSchema.ts +1 -1
  140. package/src/models/store/DataFile.ts +5 -10
  141. package/src/models/store/File.ts +5 -36
  142. package/src/models/store/Invitation.ts +1 -1
  143. package/src/models/store/Organization.ts +1 -1
  144. package/src/models/store/Permission.ts +59 -2
  145. package/src/models/store/UserIdentity.ts +1 -1
  146. package/src/models/transformers/ArcDexieTransformer.ts +1 -1
  147. package/src/models/transformers/ArcLegacyTransformer.ts +1 -1
  148. package/src/models/transformers/ArcPouchTransformer.ts +1 -1
  149. package/src/models/transformers/PostmanV21Transformer.ts +1 -1
  150. package/src/models/transformers/PostmanV2Transformer.ts +1 -1
  151. package/src/nanoid.ts +10 -0
  152. package/src/patch/PatchClient.ts +1 -1
  153. package/src/sdk/FilesSdk.ts +2 -2
  154. package/tests/unit/modeling/domain_file.spec.ts +8 -27
  155. package/tests/unit/models/Certificate/from_name.spec.ts +3 -15
  156. package/tests/unit/models/File/constructor.spec.ts +0 -1
  157. package/tests/unit/models/File/new.spec.ts +2 -13
  158. package/tests/unit/models/File/shortcutTo.spec.ts +1 -2
  159. package/tests/unit/models/File/toJSON.spec.ts +2 -13
  160. package/tests/unit/models/File/updateByMeMeta.spec.ts +4 -6
  161. package/tests/unit/models/Folder/create.spec.ts +6 -23
  162. package/tests/unit/models/Permission/all.spec.ts +88 -0
  163. package/tests/unit/models/Project/create.spec.ts +10 -32
  164. package/tests/unit/runtime/proxy/HttpProjectProxy.spec.ts +1 -1
@@ -1 +1 @@
1
- {"version":3,"file":"File.js","sourceRoot":"","sources":["../../../../src/models/store/File.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAA;AAC/B,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;AAwIxC,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,CAAA;AAC/C,MAAM,WAAW,GAAG,MAAM,CAAC,OAAO,CAAC,CAAA;AACnC,MAAM,kBAAkB,GAAG,MAAM,CAAC,cAAc,CAAC,CAAA;AACjD,M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D,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'\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 parent organization of the file.\n */\n organization: string\n /**\n * The file's meta info.\n */\n info: IThing\n /**\n * The owner of this object. The id of the User object.\n * Once the File is persistent by the API this is always populated.\n */\n owner?: string\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 ownerSymbol = Symbol('owner')\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 parent organization of the file.\n */\n organization = ''\n /**\n * The name of the environment.\n */\n info: Thing = Thing.fromName('');\n\n [ownerSymbol]?: string\n\n /**\n * The owner of this file. This is the id of the User object.\n * Set to `default` when there are no users in the system (no authentication).\n */\n get owner(): string | undefined {\n return this[ownerSymbol]\n }\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, owner, iconColor, organization, shortcutTarget } = init\n this.key = key\n this.organization = organization\n this.kind = kind\n this[ownerSymbol] = owner\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 { owner } = this\n const result: IStoredFile = {\n key: this.key,\n organization: this.organization,\n kind: this.kind,\n info: this.info.toJSON(),\n owner,\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, organization: string, owner?: string, kind = ''): File {\n const key = nanoid()\n const definition = new File()\n definition.new({\n key,\n kind,\n organization,\n info: Thing.fromName(name).toJSON(),\n owner,\n parents: [],\n permissionIds: [],\n permissions: [],\n lastModified: { user: owner || '', 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,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,CAAA;AAC/C,MAAM,kBAAkB,GAAG,MAAM,CAAC,cAAc,CAAC,CAAA;AACjD,MAAM,kBAAkB,GAAG,MAAM,CAAC,cAAc,CA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I,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,4 +1,4 @@
1
- import { nanoid } from 'nanoid';
1
+ import { nanoid } from '../../nanoid.js';
2
2
  import { InvitationKind } from '../kinds.js';
3
3
  import { Builder } from '@api-client/json/patch/builder.js';
4
4
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"Invitation.js","sourceRoot":"","sources":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IAClB,CAAC;IAED;;;;OAIG;IACH,YAAY,CAAC,SAAiB;QAC5B,IAAI,IAAI,CAAC,SAAS,KAAK,SAAS,EAAE,CAAC;YACjC,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,YAAY,EAAE,SAAS,CAAC,CAAA;YAC7C,IAAI,CAAC,SAAS,GAAG,SAAS,CAAA;QAC5B,CAAC;IACH,CAAC;IAED;;OAEG;IACH,YAAY,CAAC,SAAoC;QAC/C,IAAI,IAAI,CAAC,SAAS,KAAK,SAAS,EAAE,CAAC;YACjC,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,YAAY,EAAE,SAAS,CAAC,CAAA;YAC7C,IAAI,CAAC,SAAS,GAAG,SAAS,CAAA;QAC5B,CAAC;IACH,CAAC;CACF","sourcesContent":["import { nanoid } from 'nanoid'\nimport { InvitationKind } from '../kinds.js'\nimport type { IDeletion } from './Deletion.js'\nimport type { UserOrganizationGrantType } from './Organization.js'\nimport type { Operation } from '@api-client/json/types.js'\nimport { Builder } from '@api-client/json/patch/builder.js'\n\n/**\n * The status of an invitation.\n * - `pending`: The invitation has been sent but not yet responded to.\n * - `accepted`: The invitation has been accepted by the user.\n * - `declined`: The invitation has been declined by the user.\n */\nexport type InvitationStatus = 'pending' | 'accepted' | 'declined'\n\n/**\n * The schema for an invitation.\n * This defines the structure of an invitation object in the system.\n */\nexport interface InvitationSchema {\n /**\n * The kind of the invitation.\n */\n kind: typeof InvitationKind\n /**\n * The database ID of the invitation.\n */\n key: string\n /**\n * The user ID of the user who sent the invitation.\n */\n uid: string\n /**\n * The organization ID to which the invitation belongs.\n */\n oid: string\n /**\n * The email address of the user to whom the invitation is sent.\n */\n email: string\n /**\n * The name of the user to whom the invitation is sent.\n * This is optional and can be empty if the user is not known.\n */\n name?: string\n /**\n * The token used to respond to the invitation.\n */\n token: string\n /**\n * The timestamp when the invitation expires.\n * This is used to determine if the invitation is still valid.\n */\n expiresAt: number\n /**\n * The timestamp when the invitation was responded to.\n * This is set when the user accepts or declines the invitation.\n */\n respondedAt?: number\n /**\n * The status of the invitation.\n */\n status: InvitationStatus\n /**\n * The grant type the user will have in the organization if they accept the invitation.\n */\n grantType: UserOrganizationGrantType\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 timestamp when the invitation was created.\n */\n createdAt: number\n /**\n * The timestamp when the invitation was last updated.\n */\n updatedAt: number\n /**\n * Number of times the invitation was resent to the user.\n */\n resent: number\n /**\n * The timestamp when the invitation was last sent.\n * This is used to track when the invitation was last communicated to the user.\n */\n lastSentAt: number\n}\n\n/**\n * Represents an invitation to join an organization.\n * This class implements the `InvitationSchema` interface and provides methods to create and manipulate invitations.\n */\nexport class Invitation implements InvitationSchema {\n kind: typeof InvitationKind\n key: string\n uid: string\n oid: string\n email: string\n name: string | undefined\n token: string\n expiresAt: number\n respondedAt: number | undefined\n status: InvitationStatus\n grantType: UserOrganizationGrantType\n deleted: boolean\n deletedInfo: IDeletion | undefined\n createdAt: number\n updatedAt: number\n resent: number\n lastSentAt: number\n\n #builder?: Builder<InvitationSchema>\n\n /**\n * The patch builder for this invitation.\n */\n get builder(): Builder<InvitationSchema> {\n if (!this.#builder) {\n this.#builder = new Builder(this.toJSON())\n }\n return this.#builder\n }\n\n /**\n * Creates a full invitation schema with defaults.\n *\n * @param input The partial invitation schema.\n * @returns The invitation schema.\n */\n static createSchema(input: Partial<InvitationSchema> = {}): InvitationSchema {\n const {\n key = nanoid(),\n email,\n oid,\n grantType,\n uid = '',\n updatedAt = 0,\n createdAt = 0,\n expiresAt = 0,\n resent = 0,\n lastSentAt = 0,\n status = 'pending',\n token = '',\n } = input\n if (!email) {\n throw new Error('Email is required to create an invitation schema.')\n }\n if (!oid) {\n throw new Error('Organization ID is required to create an invitation schema.')\n }\n if (!grantType) {\n throw new Error('Grant type is required to create an invitation schema.')\n }\n const result: InvitationSchema = {\n kind: InvitationKind,\n key,\n uid,\n oid,\n email,\n grantType,\n token,\n expiresAt,\n status,\n createdAt,\n updatedAt,\n resent,\n lastSentAt,\n }\n if (input.name) {\n result.name = input.name\n }\n if (input.token) {\n result.token = input.token\n }\n if (input.expiresAt) {\n result.expiresAt = input.expiresAt\n }\n if (input.respondedAt) {\n result.respondedAt = input.respondedAt\n }\n if (input.status) {\n result.status = input.status\n }\n if (input.deleted) {\n result.deleted = input.deleted\n result.deletedInfo = input.deletedInfo\n }\n return result\n }\n\n constructor(input?: Partial<InvitationSchema>) {\n const init: InvitationSchema = Invitation.createSchema(input)\n this.kind = InvitationKind\n this.key = init.key\n this.uid = init.uid\n this.oid = init.oid\n this.email = init.email\n this.name = init.name\n this.token = init.token\n this.expiresAt = init.expiresAt\n this.respondedAt = init.respondedAt\n this.status = init.status\n this.grantType = init.grantType\n this.deleted = init.deleted || false\n this.deletedInfo = init.deletedInfo\n this.createdAt = init.createdAt\n this.updatedAt = init.updatedAt\n this.resent = init.resent\n this.lastSentAt = init.lastSentAt\n }\n\n toJSON(): InvitationSchema {\n const result: InvitationSchema = {\n kind: this.kind,\n key: this.key,\n uid: this.uid,\n oid: this.oid,\n email: this.email,\n token: this.token,\n expiresAt: this.expiresAt,\n status: this.status,\n grantType: this.grantType,\n deleted: this.deleted,\n createdAt: this.createdAt,\n updatedAt: this.updatedAt,\n resent: this.resent,\n lastSentAt: this.lastSentAt,\n }\n if (this.name) {\n result.name = this.name\n }\n if (this.respondedAt) {\n result.respondedAt = this.respondedAt\n }\n if (this.deletedInfo) {\n result.deletedInfo = { ...this.deletedInfo }\n }\n return result\n }\n\n /**\n * Retrieves the patch operations for this invitation.\n * This method builds a JSON Patch representation of the invitation,\n * which can be used to update the invitation in a database or API.\n *\n * Use one of the `set*` methods to modify the invitation before calling this method.\n *\n * @returns An array of patch operations.\n * If no changes have been made, it returns an empty array.\n */\n getPatch(): Operation[] {\n if (!this.#builder) {\n return []\n }\n return this.builder.build()\n }\n\n /**\n * Sets the name of the user to whom the invitation is sent.\n * If the name is the same as the current name, no operation is performed.\n *\n * @param name The name to set. If undefined, it will be removed.\n */\n setName(name?: string): void {\n if (name === this.name) {\n return\n }\n const hasName = !!this.name\n if (hasName && !name) {\n this.builder.remove('/name')\n } else {\n // The add method handles both adding and replacing\n this.builder.add('/name', name)\n }\n this.name = name\n }\n\n /**\n * Sets the expiration timestamp of the invitation.\n * @param expiresAt The timestamp when the invitation expires.\n * If the expiresAt is the same as the current expiresAt, no operation is performed.\n */\n setExpiresAt(expiresAt: number): void {\n if (this.expiresAt !== expiresAt) {\n this.builder.replace('/expiresAt', expiresAt)\n this.expiresAt = expiresAt\n }\n }\n\n /**\n * Sets the grant type of the user in the organization.\n */\n setGrantType(grantType: UserOrganizationGrantType): void {\n if (this.grantType !== grantType) {\n this.builder.replace('/grantType', grantType)\n this.grantType = grantType\n }\n }\n}\n"]}
1
+ {"version":3,"file":"Invitation.js","sourceRoot":"","sources":["../../../../src/models/store/Invitation.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAA;AACxC,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAA;AAI5C,OAAO,EAAE,OAAO,EAAE,MAAM,mCAAmC,CAAA;AA0F3D;;;GAGG;AACH,MAAM,OAAO,UAAU;IACrB,IAAI,CAAuB;IAC3B,GAAG,CAAQ;IACX,GAAG,CAAQ;IACX,GAAG,CAAQ;IACX,KAAK,CAAQ;IACb,IAAI,CAAoB;IACxB,KAAK,CAAQ;IACb,SAAS,CAAQ;IACjB,WAAW,CAAoB;IAC/B,MAAM,CAAkB;IACxB,SAAS,CAA2B;IACpC,OAAO,CAAS;IAChB,WAAW,CAAuB;IAClC,SAAS,CAAQ;IACjB,SAAS,CAAQ;IACjB,MAAM,CAAQ;IACd,UAAU,CAAQ;IAElB,QAAQ,CAA4B;IAEpC;;OAEG;IACH,IAAI,OAAO;QACT,IAAI,CAAC,IAAI,CAAC,QAAQ,EAAE,CAAC;YACnB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AAI,CAAC,QAAQ,EAAE,CAAC;YACnB,OAAO,EAAE,CAAA;QACX,CAAC;QACD,OAAO,IAAI,CAAC,OAAO,CAAC,KAAK,EAAE,CAAA;IAC7B,CAAC;IAED;;;;;OAKG;IACH,OAAO,CAAC,IAAa;QACnB,IAAI,IAAI,KAAK,IAAI,CAAC,IAAI,EAAE,CAAC;YACvB,OAAM;QACR,CAAC;QACD,MAAM,OAAO,GAAG,CAAC,CAAC,IAAI,CAAC,IAAI,CAAA;QAC3B,IAAI,OAAO,IAAI,CAAC,IAAI,EAAE,CAAC;YACrB,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,OAAO,CAAC,CAAA;QAC9B,CAAC;aAAM,CAAC;YACN,mDAAmD;YACnD,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,OAAO,EAAE,IAAI,CAAC,CAAA;QACjC,CAAC;QACD,IAAI,CAAC,IAAI,GAAG,IAAI,CAAA;IAClB,CAAC;IAED;;;;OAIG;IACH,YAAY,CAAC,SAAiB;QAC5B,IAAI,IAAI,CAAC,SAAS,KAAK,SAAS,EAAE,CAAC;YACjC,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,YAAY,EAAE,SAAS,CAAC,CAAA;YAC7C,IAAI,CAAC,SAAS,GAAG,SAAS,CAAA;QAC5B,CAAC;IACH,CAAC;IAED;;OAEG;IACH,YAAY,CAAC,SAAoC;QAC/C,IAAI,IAAI,CAAC,SAAS,KAAK,SAAS,EAAE,CAAC;YACjC,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,YAAY,EAAE,SAAS,CAAC,CAAA;YAC7C,IAAI,CAAC,SAAS,GAAG,SAAS,CAAA;QAC5B,CAAC;IACH,CAAC;CACF","sourcesContent":["import { nanoid } from '../../nanoid.js'\nimport { InvitationKind } from '../kinds.js'\nimport type { IDeletion } from './Deletion.js'\nimport type { UserOrganizationGrantType } from './Organization.js'\nimport type { Operation } from '@api-client/json/types.js'\nimport { Builder } from '@api-client/json/patch/builder.js'\n\n/**\n * The status of an invitation.\n * - `pending`: The invitation has been sent but not yet responded to.\n * - `accepted`: The invitation has been accepted by the user.\n * - `declined`: The invitation has been declined by the user.\n */\nexport type InvitationStatus = 'pending' | 'accepted' | 'declined'\n\n/**\n * The schema for an invitation.\n * This defines the structure of an invitation object in the system.\n */\nexport interface InvitationSchema {\n /**\n * The kind of the invitation.\n */\n kind: typeof InvitationKind\n /**\n * The database ID of the invitation.\n */\n key: string\n /**\n * The user ID of the user who sent the invitation.\n */\n uid: string\n /**\n * The organization ID to which the invitation belongs.\n */\n oid: string\n /**\n * The email address of the user to whom the invitation is sent.\n */\n email: string\n /**\n * The name of the user to whom the invitation is sent.\n * This is optional and can be empty if the user is not known.\n */\n name?: string\n /**\n * The token used to respond to the invitation.\n */\n token: string\n /**\n * The timestamp when the invitation expires.\n * This is used to determine if the invitation is still valid.\n */\n expiresAt: number\n /**\n * The timestamp when the invitation was responded to.\n * This is set when the user accepts or declines the invitation.\n */\n respondedAt?: number\n /**\n * The status of the invitation.\n */\n status: InvitationStatus\n /**\n * The grant type the user will have in the organization if they accept the invitation.\n */\n grantType: UserOrganizationGrantType\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 timestamp when the invitation was created.\n */\n createdAt: number\n /**\n * The timestamp when the invitation was last updated.\n */\n updatedAt: number\n /**\n * Number of times the invitation was resent to the user.\n */\n resent: number\n /**\n * The timestamp when the invitation was last sent.\n * This is used to track when the invitation was last communicated to the user.\n */\n lastSentAt: number\n}\n\n/**\n * Represents an invitation to join an organization.\n * This class implements the `InvitationSchema` interface and provides methods to create and manipulate invitations.\n */\nexport class Invitation implements InvitationSchema {\n kind: typeof InvitationKind\n key: string\n uid: string\n oid: string\n email: string\n name: string | undefined\n token: string\n expiresAt: number\n respondedAt: number | undefined\n status: InvitationStatus\n grantType: UserOrganizationGrantType\n deleted: boolean\n deletedInfo: IDeletion | undefined\n createdAt: number\n updatedAt: number\n resent: number\n lastSentAt: number\n\n #builder?: Builder<InvitationSchema>\n\n /**\n * The patch builder for this invitation.\n */\n get builder(): Builder<InvitationSchema> {\n if (!this.#builder) {\n this.#builder = new Builder(this.toJSON())\n }\n return this.#builder\n }\n\n /**\n * Creates a full invitation schema with defaults.\n *\n * @param input The partial invitation schema.\n * @returns The invitation schema.\n */\n static createSchema(input: Partial<InvitationSchema> = {}): InvitationSchema {\n const {\n key = nanoid(),\n email,\n oid,\n grantType,\n uid = '',\n updatedAt = 0,\n createdAt = 0,\n expiresAt = 0,\n resent = 0,\n lastSentAt = 0,\n status = 'pending',\n token = '',\n } = input\n if (!email) {\n throw new Error('Email is required to create an invitation schema.')\n }\n if (!oid) {\n throw new Error('Organization ID is required to create an invitation schema.')\n }\n if (!grantType) {\n throw new Error('Grant type is required to create an invitation schema.')\n }\n const result: InvitationSchema = {\n kind: InvitationKind,\n key,\n uid,\n oid,\n email,\n grantType,\n token,\n expiresAt,\n status,\n createdAt,\n updatedAt,\n resent,\n lastSentAt,\n }\n if (input.name) {\n result.name = input.name\n }\n if (input.token) {\n result.token = input.token\n }\n if (input.expiresAt) {\n result.expiresAt = input.expiresAt\n }\n if (input.respondedAt) {\n result.respondedAt = input.respondedAt\n }\n if (input.status) {\n result.status = input.status\n }\n if (input.deleted) {\n result.deleted = input.deleted\n result.deletedInfo = input.deletedInfo\n }\n return result\n }\n\n constructor(input?: Partial<InvitationSchema>) {\n const init: InvitationSchema = Invitation.createSchema(input)\n this.kind = InvitationKind\n this.key = init.key\n this.uid = init.uid\n this.oid = init.oid\n this.email = init.email\n this.name = init.name\n this.token = init.token\n this.expiresAt = init.expiresAt\n this.respondedAt = init.respondedAt\n this.status = init.status\n this.grantType = init.grantType\n this.deleted = init.deleted || false\n this.deletedInfo = init.deletedInfo\n this.createdAt = init.createdAt\n this.updatedAt = init.updatedAt\n this.resent = init.resent\n this.lastSentAt = init.lastSentAt\n }\n\n toJSON(): InvitationSchema {\n const result: InvitationSchema = {\n kind: this.kind,\n key: this.key,\n uid: this.uid,\n oid: this.oid,\n email: this.email,\n token: this.token,\n expiresAt: this.expiresAt,\n status: this.status,\n grantType: this.grantType,\n deleted: this.deleted,\n createdAt: this.createdAt,\n updatedAt: this.updatedAt,\n resent: this.resent,\n lastSentAt: this.lastSentAt,\n }\n if (this.name) {\n result.name = this.name\n }\n if (this.respondedAt) {\n result.respondedAt = this.respondedAt\n }\n if (this.deletedInfo) {\n result.deletedInfo = { ...this.deletedInfo }\n }\n return result\n }\n\n /**\n * Retrieves the patch operations for this invitation.\n * This method builds a JSON Patch representation of the invitation,\n * which can be used to update the invitation in a database or API.\n *\n * Use one of the `set*` methods to modify the invitation before calling this method.\n *\n * @returns An array of patch operations.\n * If no changes have been made, it returns an empty array.\n */\n getPatch(): Operation[] {\n if (!this.#builder) {\n return []\n }\n return this.builder.build()\n }\n\n /**\n * Sets the name of the user to whom the invitation is sent.\n * If the name is the same as the current name, no operation is performed.\n *\n * @param name The name to set. If undefined, it will be removed.\n */\n setName(name?: string): void {\n if (name === this.name) {\n return\n }\n const hasName = !!this.name\n if (hasName && !name) {\n this.builder.remove('/name')\n } else {\n // The add method handles both adding and replacing\n this.builder.add('/name', name)\n }\n this.name = name\n }\n\n /**\n * Sets the expiration timestamp of the invitation.\n * @param expiresAt The timestamp when the invitation expires.\n * If the expiresAt is the same as the current expiresAt, no operation is performed.\n */\n setExpiresAt(expiresAt: number): void {\n if (this.expiresAt !== expiresAt) {\n this.builder.replace('/expiresAt', expiresAt)\n this.expiresAt = expiresAt\n }\n }\n\n /**\n * Sets the grant type of the user in the organization.\n */\n setGrantType(grantType: UserOrganizationGrantType): void {\n if (this.grantType !== grantType) {\n this.builder.replace('/grantType', grantType)\n this.grantType = grantType\n }\n }\n}\n"]}
@@ -1,4 +1,4 @@
1
- import { nanoid } from 'nanoid';
1
+ import { nanoid } from '../../nanoid.js';
2
2
  import { OrganizationKind } from '../kinds.js';
3
3
  export class Organization {
4
4
  kind = OrganizationKind;
@@ -1 +1 @@
1
- {"version":3,"file":"Organization.js","sourceRoot":"","sources":["../../../../src/models/store/Organization.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAA;AAE/B,OAAO,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAA;AA2C9C,MAAM,OAAO,YAAY;IACvB,IAAI,GAA4B,gBAAgB,CAAA;IAChD,GAAG,GAAG,EAAE,CAAA;IACR,IAAI,GAAG,EAAE,CAAA;IACT,SAAS,GAAG,EAAE,CAAA;IACd,WAAW,GAAG,CAAC,CAAA;IACf,OAAO,GAAG,KAAK,CAAA;IACf,WAAW,CAAY;IACvB,SAAS,GAA8B,QAAQ,CAAA;IAE/C,YAAY,KAA8B;QACxC,IAAI,IAAmB,CAAA;QACvB,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;YAC9B,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,CAAA;QAC1B,CAAC;aAAM,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;YACrC,IAAI,GAAG,KAAK,CAAA;QACd,CAAC;aAAM,CAAC;YACN,IAAI,GAAG;gBACL,IAAI,EAAE,gBAAgB;gBACtB,GAAG,EAAE,MAAM,EAAE;gBACb,IAAI,EAAE,EAAE;gBACR,SAAS,EAAE,EAAE;gBACb,WAAW,EAAE,IAAI,CAAC,GAAG,EAAE;gBACvB,OAAO,EAAE,KAAK;gBACd,SAAS,EAAE,QAAQ;aACpB,CAAA;QACH,CAAC;QACD,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,CAAA;IAChB,CAAC;IAED,GAAG,CAAC,IAAmB;QACrB,IAAI,CAAC,YAAY,CAAC,cAAc,CAAC,IAAI,CAAC,EAAE,CAAC;YACvC,MAAM,IAAI,KAAK,CAAC,sBAAsB,CAAC,CAAA;QACzC,CAAC;QACD,MAAM,EACJ,GAAG,GAAG,MAAM,EAAE,E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C;QACD,OAAO,MAAM,CAAA;IACf,CAAC;CACF","sourcesContent":["import { nanoid } from 'nanoid'\nimport type { IDeletion } from './Deletion.js'\nimport { OrganizationKind } from '../kinds.js'\n\nexport type UserOrganizationGrantType = 'owner' | 'manager' | 'editor' | 'viewer'\n\n/**\n * In the system the user identity represents registration information associated with a specific identity provider.\n * This association allows the user to use different identity providers that map to the same user, as long as the\n * email stays consistent.\n */\nexport interface IOrganization {\n kind: typeof OrganizationKind\n /**\n * The database ID\n */\n key: string\n /**\n * The organization name\n */\n name: string\n /**\n * The key of the user that created the organization.\n */\n createdBy: string\n /**\n * The timestamp when the organization was created.\n */\n createdDate: number\n /**\n * Whether the organization 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 grant type to the organization the **current user** has.\n * By nature, it's a dynamic field populated by the data store.\n */\n grantType: UserOrganizationGrantType\n}\n\nexport class Organization implements IOrganization {\n kind: typeof OrganizationKind = OrganizationKind\n key = ''\n name = ''\n createdBy = ''\n createdDate = 0\n deleted = false\n deletedInfo?: IDeletion\n grantType: UserOrganizationGrantType = 'viewer'\n\n constructor(input?: string | IOrganization) {\n let init: IOrganization\n if (typeof input === 'string') {\n init = JSON.parse(input)\n } else if (typeof input === 'object') {\n init = input\n } else {\n init = {\n kind: OrganizationKind,\n key: nanoid(),\n name: '',\n createdBy: '',\n createdDate: Date.now(),\n deleted: false,\n grantType: 'viewer',\n }\n }\n this.new(init)\n }\n\n new(init: IOrganization): void {\n if (!Organization.isOrganization(init)) {\n throw new Error(`Not an Organization.`)\n }\n const {\n key = nanoid(),\n name,\n createdBy,\n createdDate = Date.now(),\n deleted = false,\n deletedInfo,\n grantType = 'viewer',\n } = init\n this.kind = OrganizationKind\n this.key = key\n this.name = name\n this.createdBy = createdBy\n this.createdDate = createdDate\n this.deleted = deleted\n this.grantType = grantType\n if (deletedInfo) {\n this.deletedInfo = deletedInfo\n } else {\n this.deletedInfo = undefined\n }\n }\n\n /**\n * Checks whether the input is a definition of an user organization.\n */\n static isOrganization(input: unknown): boolean {\n const typed = input as IOrganization\n if (!input || typed.kind !== OrganizationKind) {\n return false\n }\n return true\n }\n\n toJSON(): IOrganization {\n const result: IOrganization = {\n kind: OrganizationKind,\n key: this.key,\n name: this.name,\n createdBy: this.createdBy,\n createdDate: this.createdDate,\n deleted: this.deleted,\n grantType: this.grantType,\n }\n if (this.deletedInfo) {\n result.deletedInfo = this.deletedInfo\n }\n return result\n }\n}\n"]}
1
+ {"version":3,"file":"Organization.js","sourceRoot":"","sources":["../../../../src/models/store/Organization.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAA;AAExC,OAAO,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAA;AA2C9C,MAAM,OAAO,YAAY;IACvB,IAAI,GAA4B,gBAAgB,CAAA;IAChD,GAAG,GAAG,EAAE,CAAA;IACR,IAAI,GAAG,EAAE,CAAA;IACT,SAAS,GAAG,EAAE,CAAA;IACd,WAAW,GAAG,CAAC,CAAA;IACf,OAAO,GAAG,KAAK,CAAA;IACf,WAAW,CAAY;IACvB,SAAS,GAA8B,QAAQ,CAAA;IAE/C,YAAY,KAA8B;QACxC,IAAI,IAAmB,CAAA;QACvB,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;YAC9B,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,CAAA;QAC1B,CAAC;aAAM,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;YACrC,IAAI,GAAG,KAAK,CAAA;QACd,CAAC;aAAM,CAAC;YACN,IAAI,GAAG;gBACL,IAAI,EAAE,gBAAgB;gBACtB,GAAG,EAAE,MAAM,EAAE;gBACb,IAAI,EAAE,EAAE;gBACR,SAAS,EAAE,EAAE;gBACb,WAAW,EAAE,IAAI,CAAC,GAAG,EAAE;gBACvB,OAAO,EAAE,KAAK;gBACd,SA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,IAAI,EAAE,IAAI,CAAC,IAAI;YACf,SAAS,EAAE,IAAI,CAAC,SAAS;YACzB,WAAW,EAAE,IAAI,CAAC,WAAW;YAC7B,OAAO,EAAE,IAAI,CAAC,OAAO;YACrB,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,OAAO,MAAM,CAAA;IACf,CAAC;CACF","sourcesContent":["import { nanoid } from '../../nanoid.js'\nimport type { IDeletion } from './Deletion.js'\nimport { OrganizationKind } from '../kinds.js'\n\nexport type UserOrganizationGrantType = 'owner' | 'manager' | 'editor' | 'viewer'\n\n/**\n * In the system the user identity represents registration information associated with a specific identity provider.\n * This association allows the user to use different identity providers that map to the same user, as long as the\n * email stays consistent.\n */\nexport interface IOrganization {\n kind: typeof OrganizationKind\n /**\n * The database ID\n */\n key: string\n /**\n * The organization name\n */\n name: string\n /**\n * The key of the user that created the organization.\n */\n createdBy: string\n /**\n * The timestamp when the organization was created.\n */\n createdDate: number\n /**\n * Whether the organization 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 grant type to the organization the **current user** has.\n * By nature, it's a dynamic field populated by the data store.\n */\n grantType: UserOrganizationGrantType\n}\n\nexport class Organization implements IOrganization {\n kind: typeof OrganizationKind = OrganizationKind\n key = ''\n name = ''\n createdBy = ''\n createdDate = 0\n deleted = false\n deletedInfo?: IDeletion\n grantType: UserOrganizationGrantType = 'viewer'\n\n constructor(input?: string | IOrganization) {\n let init: IOrganization\n if (typeof input === 'string') {\n init = JSON.parse(input)\n } else if (typeof input === 'object') {\n init = input\n } else {\n init = {\n kind: OrganizationKind,\n key: nanoid(),\n name: '',\n createdBy: '',\n createdDate: Date.now(),\n deleted: false,\n grantType: 'viewer',\n }\n }\n this.new(init)\n }\n\n new(init: IOrganization): void {\n if (!Organization.isOrganization(init)) {\n throw new Error(`Not an Organization.`)\n }\n const {\n key = nanoid(),\n name,\n createdBy,\n createdDate = Date.now(),\n deleted = false,\n deletedInfo,\n grantType = 'viewer',\n } = init\n this.kind = OrganizationKind\n this.key = key\n this.name = name\n this.createdBy = createdBy\n this.createdDate = createdDate\n this.deleted = deleted\n this.grantType = grantType\n if (deletedInfo) {\n this.deletedInfo = deletedInfo\n } else {\n this.deletedInfo = undefined\n }\n }\n\n /**\n * Checks whether the input is a definition of an user organization.\n */\n static isOrganization(input: unknown): boolean {\n const typed = input as IOrganization\n if (!input || typed.kind !== OrganizationKind) {\n return false\n }\n return true\n }\n\n toJSON(): IOrganization {\n const result: IOrganization = {\n kind: OrganizationKind,\n key: this.key,\n name: this.name,\n createdBy: this.createdBy,\n createdDate: this.createdDate,\n deleted: this.deleted,\n grantType: this.grantType,\n }\n if (this.deletedInfo) {\n result.deletedInfo = this.deletedInfo\n }\n return result\n }\n}\n"]}
@@ -7,6 +7,12 @@ export type PermissionType = 'user' | 'group' | 'organization';
7
7
  * - `reader`: Can only view the item.
8
8
  */
9
9
  export type PermissionRole = 'owner' | 'reader' | 'commenter' | 'writer';
10
+ /**
11
+ * A predefined set of rules that can be used to determine the source of the permission.
12
+ * - `direct_user_grant`: The permission is granted directly to the user.
13
+ * - `creator_default_owner`: The permission is granted to the creator of the item as the default owner.
14
+ */
15
+ export type PermissionSourceRule = 'direct_user_grant' | 'creator_default_owner' | 'parent_owner_editor_rule';
10
16
  interface IBasePermission {
11
17
  /**
12
18
  * The type of the permission.
@@ -49,6 +55,20 @@ interface IBasePermission {
49
55
  * The store id of the user that added this permission.
50
56
  */
51
57
  addingUser: string;
58
+ /**
59
+ * The depth of the permission in the hierarchy.
60
+ * When `0` it means that the permissions do not use inheritance.
61
+ * When `1` it means the permission is set on the item itself.
62
+ * When `2` it means the permission is set on the parent item.
63
+ * When `3` it means the permission is set on the grandparent item, and so on.
64
+ * This is used to determine the depth of the permission in the hierarchy.
65
+ */
66
+ depth: number;
67
+ /**
68
+ * The source rule of the permission.
69
+ * This is used to determine how the permission was granted.
70
+ */
71
+ sourceRule: PermissionSourceRule;
52
72
  }
53
73
  /**
54
74
  * A schema describing a permission to a store object.
@@ -109,6 +129,20 @@ export declare class Permission {
109
129
  * The store id of the entity that is being granted the permission.
110
130
  */
111
131
  itemId: string;
132
+ /**
133
+ * The depth of the permission in the hierarchy.
134
+ * When `0` it means that the permissions do not use inheritance.
135
+ * When `1` it means the permission is set on the item itself.
136
+ * When `2` it means the permission is set on the parent item.
137
+ * When `3` it means the permission is set on the grandparent item, and so on.
138
+ * This is used to determine the depth of the permission in the hierarchy.
139
+ */
140
+ depth: number;
141
+ /**
142
+ * The source rule of the permission.
143
+ * This is used to determine how the permission was granted.
144
+ */
145
+ sourceRule: PermissionSourceRule;
112
146
  /**
113
147
  * Creates a Permission object for a user.
114
148
  *
@@ -1 +1 @@
1
- {"version":3,"file":"Permission.d.ts","sourceRoot":"","sources":["../../../../src/models/store/Permission.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,IAAI,oBAAoB,CAAA;AAErC,MAAM,MAAM,cAAc,GAAG,MAAM,GAAG,OAAO,GAAG,cAAc,CAAA;AAC9D;;;;;GAKG;AACH,MAAM,MAAM,cAAc,GAAG,OAAO,GAAG,QAAQ,GAAG,WAAW,GAAG,QAAQ,CAAA;AAGxE,UAAU,eAAe;IACvB;;;;;;OAMG;IACH,IAAI,EAAE,cAAc,CAAA;IACpB;;;OAGG;IACH,SAAS,EAAE,MAAM,CAAA;IACjB;;OAEG;IACH,MAAM,EAAE,MAAM,CAAA;IACd;;OAEG;IACH,IAAI,EAAE,cAAc,CAAA;IACpB;;;;;;OAMG;IACH,WAAW,CAAC,EAAE,MAAM,CAAA;IACpB;;;;;;OAMG;IACH,cAAc,CAAC,EAAE,MAAM,CAAA;IACvB;;OAEG;IACH,UAAU,EAAE,MAAM,CAAA;CACnB;AAED;;GAEG;A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MAAM,WAAW,sBAAuB,SAAQ,gBAAgB,EAAE,kBAAkB;IAClF,EAAE,EAAE,QAAQ,CAAA;IACZ;;OAEG;IACH,EAAE,EAAE,MAAM,CAAA;CACX;AAED,MAAM,MAAM,eAAe,GAAG,mBAAmB,GAAG,sBAAsB,GAAG,sBAAsB,CAAA"}
@@ -1,4 +1,4 @@
1
- import { nanoid } from 'nanoid';
1
+ import { nanoid } from '../../nanoid.js';
2
2
  export const Kind = 'Core#Permission';
3
3
  const orderedRoles = ['reader', 'commenter', 'writer', 'owner'];
4
4
  export class Permission {
@@ -49,6 +49,20 @@ export class Permission {
49
49
  * The store id of the entity that is being granted the permission.
50
50
  */
51
51
  itemId = '';
52
+ /**
53
+ * The depth of the permission in the hierarchy.
54
+ * When `0` it means that the permissions do not use inheritance.
55
+ * When `1` it means the permission is set on the item itself.
56
+ * When `2` it means the permission is set on the parent item.
57
+ * When `3` it means the permission is set on the grandparent item, and so on.
58
+ * This is used to determine the depth of the permission in the hierarchy.
59
+ */
60
+ depth = 0;
61
+ /**
62
+ * The source rule of the permission.
63
+ * This is used to determine how the permission was granted.
64
+ */
65
+ sourceRule = 'direct_user_grant';
52
66
  /**
53
67
  * Creates a Permission object for a user.
54
68
  *
@@ -66,6 +80,8 @@ export class Permission {
66
80
  role,
67
81
  type: 'user',
68
82
  addingUser,
83
+ depth: 0,
84
+ sourceRule: 'direct_user_grant',
69
85
  };
70
86
  return new Permission(init);
71
87
  }
@@ -86,6 +102,8 @@ export class Permission {
86
102
  role,
87
103
  type: 'group',
88
104
  addingUser,
105
+ depth: 0,
106
+ sourceRule: 'direct_user_grant',
89
107
  };
90
108
  return new Permission(init);
91
109
  }
@@ -105,6 +123,8 @@ export class Permission {
105
123
  role,
106
124
  type: 'organization',
107
125
  addingUser,
126
+ depth: 0,
127
+ sourceRule: 'direct_user_grant',
108
128
  };
109
129
  return new Permission(init);
110
130
  }
@@ -135,6 +155,8 @@ export class Permission {
135
155
  role: 'reader',
136
156
  type: 'user',
137
157
  addingUser: '',
158
+ depth: 0,
159
+ sourceRule: 'direct_user_grant',
138
160
  };
139
161
  }
140
162
  this.new(init);
@@ -143,7 +165,7 @@ export class Permission {
143
165
  if (!Permission.isPermission(init)) {
144
166
  throw new Error(`Not a permission.`);
145
167
  }
146
- const { key = nanoid(), granteeId, role, type, displayName, expirationTime, addingUser, itemId } = init;
168
+ const { key = nanoid(), granteeId, role, type, displayName, expirationTime, addingUser, itemId, depth, sourceRule, } = init;
147
169
  this.kind = Kind;
148
170
  this.key = key;
149
171
  this.granteeId = granteeId;
@@ -151,6 +173,8 @@ export class Permission {
151
173
  this.role = role;
152
174
  this.type = type;
153
175
  this.addingUser = addingUser;
176
+ this.depth = depth || 0;
177
+ this.sourceRule = sourceRule || 'direct_user_grant';
154
178
  if (displayName) {
155
179
  this.displayName = displayName;
156
180
  }
@@ -215,6 +239,8 @@ export class Permission {
215
239
  addingUser: this.addingUser,
216
240
  granteeId: this.granteeId,
217
241
  itemId: this.itemId,
242
+ depth: this.depth,
243
+ sourceRule: this.sourceRule,
218
244
  };
219
245
  if (this.displayName) {
220
246
  result.displayName = this.displayName;
@@ -1 +1 @@
1
- {"version":3,"file":"Permission.js","sourceRoot":"","sources":["../../../../src/models/store/Permission.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAA;AAE/B,MAAM,CAAC,MAAM,IAAI,GAAG,iBAAiB,CAAA;AAUrC,MAAM,YAAY,GAAqB,CAAC,QAAQ,EAAE,WAAW,EAAE,QAAQ,EAAE,OAAO,CAAC,CAAA;AA0DjF,MAAM,OAAO,UAAU;IACrB,IAAI,GAAG,IAAI,CAAA;IACX;;;OAGG;IACH,GAAG,GAAG,EAAE,CAAA;IACR;;;;;;OAMG;IACH,IAAI,GAAmB,MAAM,CAAA;IAC7B;;;OAGG;IACH,SAAS,GAAG,EAAE,CAAA;IACd;;OAEG;IACH,IAAI,GAAmB,QAAQ,CAAA;IAC/B;;;;;;OA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ED,MAAM;QACJ,MAAM,MAAM,GAAgB;YAC1B,IAAI,EAAE,IAAI;YACV,GAAG,EAAE,IAAI,CAAC,GAAG;YACb,IAAI,EAAE,IAAI,CAAC,IAAI;YACf,IAAI,EAAE,IAAI,CAAC,IAAI;YACf,UAAU,EAAE,IAAI,CAAC,UAAU;YAC3B,SAAS,EAAE,IAAI,CAAC,SAAS;YACzB,MAAM,EAAE,IAAI,CAAC,MAAM;SACpB,CAAA;QACD,IAAI,IAAI,CAAC,WAAW,EAAE,CAAC;YACrB,MAAM,CAAC,WAAW,GAAG,IAAI,CAAC,WAAW,CAAA;QACvC,CAAC;QACD,IAAI,IAAI,CAAC,cAAc,EAAE,CAAC;YACxB,MAAM,CAAC,cAAc,GAAG,IAAI,CAAC,cAAc,CAAA;QAC7C,CAAC;QACD,OAAO,MAAM,CAAA;IACf,CAAC;CACF","sourcesContent":["import { nanoid } from 'nanoid'\n\nexport const Kind = 'Core#Permission'\n\nexport type PermissionType = 'user' | 'group' | 'organization'\n/**\n * - `owner`: Full control over the item.\n * - `writer`: Can view, comment, and edit the item.\n * - `commenter`: Can view and comment on the item.\n * - `reader`: Can only view the item.\n */\nexport type PermissionRole = 'owner' | 'reader' | 'commenter' | 'writer'\nconst orderedRoles: PermissionRole[] = ['reader', 'commenter', 'writer', 'owner']\n\ninterface IBasePermission {\n /**\n * The type of the permission.\n *\n * - `user` can access the file by a specific user\n * - `group` can access the file by a group of users\n * - `organization` the object can be searched by anyone within the organization.\n */\n type: PermissionType\n /**\n * It represents the ID of the entity (user, group,or organization)\n * that is being granted the permission on a file or folder.\n */\n granteeId: string\n /**\n * The store id of the entity that is being granted the permission.\n */\n itemId: string\n /**\n * The role granted by this permission.\n */\n role: PermissionRole\n /**\n * The \"pretty\" name to render with the permission.\n *\n * - `user` type - user's full name\n * - `group` type - the name of the group\n * - `organization` type - no render name\n */\n displayName?: string\n /**\n * Optional expiration date of the permission. This is the timestamp when the permission expires.\n * When creating / updating the permission the expiration date must:\n *\n * - be used on a user or a group\n * - the time must be in the future\n */\n expirationTime?: number\n /**\n * The store id of the user that added this permission.\n */\n addingUser: string\n}\n\n/**\n * A schema describing a permission to a store object.\n */\nexport interface IPermission extends IBasePermission {\n kind: typeof Kind\n /**\n * The data store key of the permission.\n * This property is generated by the store and is not writable.\n */\n key: string\n}\n\nexport class Permission {\n kind = Kind\n /**\n * The data store key of the permission.\n * This property is generated by the store and is not writable.\n */\n key = ''\n /**\n * The type of the permission.\n *\n * - `user` can access the file by a specific user\n * - `group` can access the file by a group of users\n * - - `organization` the object can be searched by anyone within the organization.\n */\n type: PermissionType = 'user'\n /**\n * It represents the ID of the entity (user, group, or organization)\n * that is being granted the permission on a file or folder.\n */\n granteeId = ''\n /**\n * The role granted by this permission.\n */\n role: PermissionRole = 'reader'\n /**\n * The \"pretty\" name to render with the permission.\n *\n * - `user` type - user's full name\n * - `group` type - the name of the group\n * - `organization` type - the organization name.\n */\n displayName?: string\n /**\n * Optional expiration date of the permission. This is the timestamp when the permission expires.\n * When creating / updating the permission the expiration date must:\n *\n * - be used on a user or a group\n * - the time must be in the future\n */\n expirationTime?: number\n\n /**\n * The store id of the user that added this permission.\n */\n addingUser = ''\n\n /**\n * The store id of the entity that is being granted the permission.\n */\n itemId = ''\n\n /**\n * Creates a Permission object for a user.\n *\n * @param role The user role to set.\n * @param itemId The store id of the entity that is being granted the permission.\n * @param user The user id that has the role.\n * @param addingUser The key of the user that created this permission\n */\n static fromUserRole(role: PermissionRole, itemId: string, user: string, addingUser: string): Permission {\n const init: IPermission = {\n key: nanoid(),\n kind: Kind,\n itemId,\n granteeId: user,\n role,\n type: 'user',\n addingUser,\n }\n return new Permission(init)\n }\n\n /**\n * Creates a Permission object for a group.\n *\n * @param role The group role to set.\n * @param itemId The store id of the entity that is being granted the permission.\n * @param group The group id that has the role.\n * @param addingUser The key of the user that created this permission\n */\n static fromGroupRole(role: PermissionRole, itemId: string, group: string, addingUser: string): Permission {\n const init: IPermission = {\n key: nanoid(),\n kind: Kind,\n itemId,\n granteeId: group,\n role,\n type: 'group',\n addingUser,\n }\n return new Permission(init)\n }\n\n /**\n * Creates a Permission object for a group.\n *\n * @param role The group role to set.\n * @param itemId The store id of the entity that is being granted the permission.\n * @param addingUser The key of the user that created this permission\n */\n static fromOrganizationRole(\n role: PermissionRole,\n itemId: string,\n organizationId: string,\n addingUser: string\n ): Permission {\n const init: IPermission = {\n key: nanoid(),\n kind: Kind,\n itemId,\n granteeId: organizationId,\n role,\n type: 'organization',\n addingUser,\n }\n return new Permission(init)\n }\n\n /**\n * Creates a permission object from other than key and kind values.\n */\n static fromValues(init: IBasePermission): Permission {\n return new Permission({\n ...init,\n key: nanoid(),\n kind: Kind,\n })\n }\n\n constructor(input?: string | IPermission) {\n let init: IPermission\n if (typeof input === 'string') {\n init = JSON.parse(input)\n } else if (typeof input === 'object') {\n init = input\n } else {\n init = {\n kind: Kind,\n key: nanoid(),\n granteeId: '',\n itemId: '',\n role: 'reader',\n type: 'user',\n addingUser: '',\n }\n }\n this.new(init)\n }\n\n new(init: IPermission): void {\n if (!Permission.isPermission(init)) {\n throw new Error(`Not a permission.`)\n }\n const { key = nanoid(), granteeId, role, type, displayName, expirationTime, addingUser, itemId } = init\n this.kind = Kind\n this.key = key\n this.granteeId = granteeId\n this.itemId = itemId\n this.role = role\n this.type = type\n this.addingUser = addingUser\n if (displayName) {\n this.displayName = displayName\n } else {\n this.displayName = undefined\n }\n if (typeof expirationTime === 'number') {\n this.expirationTime = expirationTime\n } else {\n this.expirationTime = undefined\n }\n }\n\n static isPermission(input: unknown): boolean {\n const typed = input as IPermission\n if (!input || typed.kind !== Kind) {\n return false\n }\n return true\n }\n\n /**\n * Checks whether the current user role meets the minimum required role.\n *\n * @param minimumLevel The minimum requested role\n * @param currentRole The user role. When not set it always returns false.\n * @returns True if the `currentRole` is at least the `minimumRole`\n */\n static hasRole(minimumLevel: PermissionRole, currentRole?: PermissionRole): boolean {\n if (!currentRole) {\n return false\n }\n const currentAccessIndex = orderedRoles.indexOf(currentRole)\n const requestedAccessIndex = orderedRoles.indexOf(minimumLevel)\n // the current must be at least at the index of requested.\n return currentAccessIndex >= requestedAccessIndex\n }\n\n /**\n * Checks if role1 is higher than role2 in the permission hierarchy.\n *\n * @param role1 The first role to compare.\n * @param role2 The second role to compare.\n * @returns `true` if `role1` is higher than `role2`, `false` otherwise.\n */\n static isHigherRole(role1: PermissionRole, role2: PermissionRole): boolean {\n const role1Index = orderedRoles.indexOf(role1)\n const role2Index = orderedRoles.indexOf(role2)\n return role1Index > role2Index\n }\n\n /**\n * Link to the `Permission.hasRole(minimumLevel, currentRole)`.\n * @see {@link Permission.hasRole}\n */\n hasRole(minimumLevel: PermissionRole, currentRole: PermissionRole): boolean {\n return Permission.hasRole(minimumLevel, currentRole)\n }\n\n toJSON(): IPermission {\n const result: IPermission = {\n kind: Kind,\n key: this.key,\n role: this.role,\n type: this.type,\n addingUser: this.addingUser,\n granteeId: this.granteeId,\n itemId: this.itemId,\n }\n if (this.displayName) {\n result.displayName = this.displayName\n }\n if (this.expirationTime) {\n result.expirationTime = this.expirationTime\n }\n return result\n }\n}\n\n/**\n * This is used in the communication with the backend to add/change user's access to the resource.\n */\nexport interface IAccessOperation {\n /**\n * The user, group, or organization id that this permission affects.\n */\n id: string\n /**\n * The permission type: user, group, or organization\n */\n type: PermissionType\n}\n\ninterface IUpdatingOperation {\n /**\n * The level that the user or the group has access to:\n * - owner\n * - reader\n * - commenter\n * - writer\n */\n value: PermissionRole\n /**\n * The timestamp when the permission expires.\n */\n expirationTime?: number\n}\n\nexport interface IAccessAddOperation extends IAccessOperation, IUpdatingOperation {\n op: 'add'\n}\n\nexport interface IAccessRemoveOperation extends IAccessOperation {\n op: 'remove'\n}\n\nexport interface IAccessUpdateOperation extends IAccessOperation, IUpdatingOperation {\n op: 'update'\n /**\n * The ID of the permission to update.\n */\n id: string\n}\n\nexport type AccessOperation = IAccessAddOperation | IAccessRemoveOperation | IAccessUpdateOperation\n"]}
1
+ {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;YACjB,UAAU,EAAE,IAAI,CAAC,UAAU;SAC5B,CAAA;QACD,IAAI,IAAI,CAAC,WAAW,EAAE,CAAC;YACrB,MAAM,CAAC,WAAW,GAAG,IAAI,CAAC,WAAW,CAAA;QACvC,CAAC;QACD,IAAI,IAAI,CAAC,cAAc,EAAE,CAAC;YACxB,MAAM,CAAC,cAAc,GAAG,IAAI,CAAC,cAAc,CAAA;QAC7C,CAAC;QACD,OAAO,MAAM,CAAA;IACf,CAAC;CACF","sourcesContent":["import { nanoid } from '../../nanoid.js'\n\nexport const Kind = 'Core#Permission'\n\nexport type PermissionType = 'user' | 'group' | 'organization'\n/**\n * - `owner`: Full control over the item.\n * - `writer`: Can view, comment, and edit the item.\n * - `commenter`: Can view and comment on the item.\n * - `reader`: Can only view the item.\n */\nexport type PermissionRole = 'owner' | 'reader' | 'commenter' | 'writer'\nconst orderedRoles: PermissionRole[] = ['reader', 'commenter', 'writer', 'owner']\n/**\n * A predefined set of rules that can be used to determine the source of the permission.\n * - `direct_user_grant`: The permission is granted directly to the user.\n * - `creator_default_owner`: The permission is granted to the creator of the item as the default owner.\n */\nexport type PermissionSourceRule = 'direct_user_grant' | 'creator_default_owner' | 'parent_owner_editor_rule'\n\ninterface IBasePermission {\n /**\n * The type of the permission.\n *\n * - `user` can access the file by a specific user\n * - `group` can access the file by a group of users\n * - `organization` the object can be searched by anyone within the organization.\n */\n type: PermissionType\n /**\n * It represents the ID of the entity (user, group,or organization)\n * that is being granted the permission on a file or folder.\n */\n granteeId: string\n /**\n * The store id of the entity that is being granted the permission.\n */\n itemId: string\n /**\n * The role granted by this permission.\n */\n role: PermissionRole\n /**\n * The \"pretty\" name to render with the permission.\n *\n * - `user` type - user's full name\n * - `group` type - the name of the group\n * - `organization` type - no render name\n */\n displayName?: string\n /**\n * Optional expiration date of the permission. This is the timestamp when the permission expires.\n * When creating / updating the permission the expiration date must:\n *\n * - be used on a user or a group\n * - the time must be in the future\n */\n expirationTime?: number\n /**\n * The store id of the user that added this permission.\n */\n addingUser: string\n /**\n * The depth of the permission in the hierarchy.\n * When `0` it means that the permissions do not use inheritance.\n * When `1` it means the permission is set on the item itself.\n * When `2` it means the permission is set on the parent item.\n * When `3` it means the permission is set on the grandparent item, and so on.\n * This is used to determine the depth of the permission in the hierarchy.\n */\n depth: number\n /**\n * The source rule of the permission.\n * This is used to determine how the permission was granted.\n */\n sourceRule: PermissionSourceRule\n}\n\n/**\n * A schema describing a permission to a store object.\n */\nexport interface IPermission extends IBasePermission {\n kind: typeof Kind\n /**\n * The data store key of the permission.\n * This property is generated by the store and is not writable.\n */\n key: string\n}\n\nexport class Permission {\n kind = Kind\n /**\n * The data store key of the permission.\n * This property is generated by the store and is not writable.\n */\n key = ''\n /**\n * The type of the permission.\n *\n * - `user` can access the file by a specific user\n * - `group` can access the file by a group of users\n * - - `organization` the object can be searched by anyone within the organization.\n */\n type: PermissionType = 'user'\n /**\n * It represents the ID of the entity (user, group, or organization)\n * that is being granted the permission on a file or folder.\n */\n granteeId = ''\n /**\n * The role granted by this permission.\n */\n role: PermissionRole = 'reader'\n /**\n * The \"pretty\" name to render with the permission.\n *\n * - `user` type - user's full name\n * - `group` type - the name of the group\n * - `organization` type - the organization name.\n */\n displayName?: string\n /**\n * Optional expiration date of the permission. This is the timestamp when the permission expires.\n * When creating / updating the permission the expiration date must:\n *\n * - be used on a user or a group\n * - the time must be in the future\n */\n expirationTime?: number\n\n /**\n * The store id of the user that added this permission.\n */\n addingUser = ''\n\n /**\n * The store id of the entity that is being granted the permission.\n */\n itemId = ''\n /**\n * The depth of the permission in the hierarchy.\n * When `0` it means that the permissions do not use inheritance.\n * When `1` it means the permission is set on the item itself.\n * When `2` it means the permission is set on the parent item.\n * When `3` it means the permission is set on the grandparent item, and so on.\n * This is used to determine the depth of the permission in the hierarchy.\n */\n depth = 0\n /**\n * The source rule of the permission.\n * This is used to determine how the permission was granted.\n */\n sourceRule: PermissionSourceRule = 'direct_user_grant'\n\n /**\n * Creates a Permission object for a user.\n *\n * @param role The user role to set.\n * @param itemId The store id of the entity that is being granted the permission.\n * @param user The user id that has the role.\n * @param addingUser The key of the user that created this permission\n */\n static fromUserRole(role: PermissionRole, itemId: string, user: string, addingUser: string): Permission {\n const init: IPermission = {\n key: nanoid(),\n kind: Kind,\n itemId,\n granteeId: user,\n role,\n type: 'user',\n addingUser,\n depth: 0,\n sourceRule: 'direct_user_grant',\n }\n return new Permission(init)\n }\n\n /**\n * Creates a Permission object for a group.\n *\n * @param role The group role to set.\n * @param itemId The store id of the entity that is being granted the permission.\n * @param group The group id that has the role.\n * @param addingUser The key of the user that created this permission\n */\n static fromGroupRole(role: PermissionRole, itemId: string, group: string, addingUser: string): Permission {\n const init: IPermission = {\n key: nanoid(),\n kind: Kind,\n itemId,\n granteeId: group,\n role,\n type: 'group',\n addingUser,\n depth: 0,\n sourceRule: 'direct_user_grant',\n }\n return new Permission(init)\n }\n\n /**\n * Creates a Permission object for a group.\n *\n * @param role The group role to set.\n * @param itemId The store id of the entity that is being granted the permission.\n * @param addingUser The key of the user that created this permission\n */\n static fromOrganizationRole(\n role: PermissionRole,\n itemId: string,\n organizationId: string,\n addingUser: string\n ): Permission {\n const init: IPermission = {\n key: nanoid(),\n kind: Kind,\n itemId,\n granteeId: organizationId,\n role,\n type: 'organization',\n addingUser,\n depth: 0,\n sourceRule: 'direct_user_grant',\n }\n return new Permission(init)\n }\n\n /**\n * Creates a permission object from other than key and kind values.\n */\n static fromValues(init: IBasePermission): Permission {\n return new Permission({\n ...init,\n key: nanoid(),\n kind: Kind,\n })\n }\n\n constructor(input?: string | IPermission) {\n let init: IPermission\n if (typeof input === 'string') {\n init = JSON.parse(input)\n } else if (typeof input === 'object') {\n init = input\n } else {\n init = {\n kind: Kind,\n key: nanoid(),\n granteeId: '',\n itemId: '',\n role: 'reader',\n type: 'user',\n addingUser: '',\n depth: 0,\n sourceRule: 'direct_user_grant',\n }\n }\n this.new(init)\n }\n\n new(init: IPermission): void {\n if (!Permission.isPermission(init)) {\n throw new Error(`Not a permission.`)\n }\n const {\n key = nanoid(),\n granteeId,\n role,\n type,\n displayName,\n expirationTime,\n addingUser,\n itemId,\n depth,\n sourceRule,\n } = init\n this.kind = Kind\n this.key = key\n this.granteeId = granteeId\n this.itemId = itemId\n this.role = role\n this.type = type\n this.addingUser = addingUser\n this.depth = depth || 0\n this.sourceRule = sourceRule || 'direct_user_grant'\n if (displayName) {\n this.displayName = displayName\n } else {\n this.displayName = undefined\n }\n if (typeof expirationTime === 'number') {\n this.expirationTime = expirationTime\n } else {\n this.expirationTime = undefined\n }\n }\n\n static isPermission(input: unknown): boolean {\n const typed = input as IPermission\n if (!input || typed.kind !== Kind) {\n return false\n }\n return true\n }\n\n /**\n * Checks whether the current user role meets the minimum required role.\n *\n * @param minimumLevel The minimum requested role\n * @param currentRole The user role. When not set it always returns false.\n * @returns True if the `currentRole` is at least the `minimumRole`\n */\n static hasRole(minimumLevel: PermissionRole, currentRole?: PermissionRole): boolean {\n if (!currentRole) {\n return false\n }\n const currentAccessIndex = orderedRoles.indexOf(currentRole)\n const requestedAccessIndex = orderedRoles.indexOf(minimumLevel)\n // the current must be at least at the index of requested.\n return currentAccessIndex >= requestedAccessIndex\n }\n\n /**\n * Checks if role1 is higher than role2 in the permission hierarchy.\n *\n * @param role1 The first role to compare.\n * @param role2 The second role to compare.\n * @returns `true` if `role1` is higher than `role2`, `false` otherwise.\n */\n static isHigherRole(role1: PermissionRole, role2: PermissionRole): boolean {\n const role1Index = orderedRoles.indexOf(role1)\n const role2Index = orderedRoles.indexOf(role2)\n return role1Index > role2Index\n }\n\n /**\n * Link to the `Permission.hasRole(minimumLevel, currentRole)`.\n * @see {@link Permission.hasRole}\n */\n hasRole(minimumLevel: PermissionRole, currentRole: PermissionRole): boolean {\n return Permission.hasRole(minimumLevel, currentRole)\n }\n\n toJSON(): IPermission {\n const result: IPermission = {\n kind: Kind,\n key: this.key,\n role: this.role,\n type: this.type,\n addingUser: this.addingUser,\n granteeId: this.granteeId,\n itemId: this.itemId,\n depth: this.depth,\n sourceRule: this.sourceRule,\n }\n if (this.displayName) {\n result.displayName = this.displayName\n }\n if (this.expirationTime) {\n result.expirationTime = this.expirationTime\n }\n return result\n }\n}\n\n/**\n * This is used in the communication with the backend to add/change user's access to the resource.\n */\nexport interface IAccessOperation {\n /**\n * The user, group, or organization id that this permission affects.\n */\n id: string\n /**\n * The permission type: user, group, or organization\n */\n type: PermissionType\n}\n\ninterface IUpdatingOperation {\n /**\n * The level that the user or the group has access to:\n * - owner\n * - reader\n * - commenter\n * - writer\n */\n value: PermissionRole\n /**\n * The timestamp when the permission expires.\n */\n expirationTime?: number\n}\n\nexport interface IAccessAddOperation extends IAccessOperation, IUpdatingOperation {\n op: 'add'\n}\n\nexport interface IAccessRemoveOperation extends IAccessOperation {\n op: 'remove'\n}\n\nexport interface IAccessUpdateOperation extends IAccessOperation, IUpdatingOperation {\n op: 'update'\n /**\n * The ID of the permission to update.\n */\n id: string\n}\n\nexport type AccessOperation = IAccessAddOperation | IAccessRemoveOperation | IAccessUpdateOperation\n"]}
@@ -1,4 +1,4 @@
1
- import { nanoid } from 'nanoid';
1
+ import { nanoid } from '../../nanoid.js';
2
2
  export const Kind = 'Core#UserIdentity';
3
3
  export class UserIdentity {
4
4
  kind = Kind;
@@ -1 +1 @@
1
- {"version":3,"file":"UserIdentity.js","sourceRoot":"","sources":["../../../../src/models/store/UserIdentity.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAA;AAE/B,MAAM,CAAC,MAAM,IAAI,GAAG,mBAAmB,CAAA;AAuCvC,MAAM,OAAO,YAAY;IACvB,IAAI,GAAgB,IAAI,CAAA;IACxB,GAAG,GAAG,EAAE,CAAA;IACR,MAAM,GAAG,EAAE,CAAA;IACX,QAAQ,GAAa,QAAQ,CAAA;IAC7B,UAAU,GAAG,EAAE,CAAA;IACf,aAAa,GAAG,KAAK,CAAA;IACrB,UAAU,CAAS;IAEnB,YAAY,KA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,KAAc;QAClC,MAAM,KAAK,GAAG,KAAsB,CAAA;QACpC,IAAI,CAAC,KAAK,IAAI,KAAK,CAAC,IAAI,KAAK,IAAI,EAAE,CAAC;YAClC,OAAO,KAAK,CAAA;QACd,CAAC;QACD,OAAO,IAAI,CAAA;IACb,CAAC;IAED,MAAM;QACJ,MAAM,MAAM,GAAkB;YAC5B,IAAI,EAAE,IAAI;YACV,GAAG,EAAE,IAAI,CAAC,GAAG;YACb,QAAQ,EAAE,IAAI,CAAC,QAAQ;YACvB,UAAU,EAAE,IAAI,CAAC,UAAU;YAC3B,MAAM,EAAE,IAAI,CAAC,MAAM;YACnB,aAAa,EAAE,IAAI,CAAC,aAAa;SAClC,CAAA;QACD,IAAI,IAAI,CAAC,UAAU,EAAE,CAAC;YACpB,MAAM,CAAC,UAAU,GAAG,IAAI,CAAC,UAAU,CAAA;QACrC,CAAC;QACD,OAAO,MAAM,CAAA;IACf,CAAC;CACF","sourcesContent":["import { nanoid } from 'nanoid'\n\nexport const Kind = 'Core#UserIdentity'\n\ntype Provider = 'google'\n\n/**\n * In the system the user identity represents registration information associated with a specific identity provider.\n * This association allows the user to use different identity providers that map to the same user, as long as the\n * email stays consistent.\n */\nexport interface IUserIdentity {\n kind: typeof Kind\n /**\n * The database ID\n */\n key: string\n /**\n * The related user id.\n */\n userId: string\n /**\n * The identity provider.\n */\n provider: Provider\n /**\n * The provider's unique ID.\n * This allows to recognize a returning user.\n */\n providerId: string\n /**\n * `true`, if the provider has verified the email address.\n */\n emailVerified: boolean\n /**\n * If present, the host domain of the user's GSuite email address.\n * Google specific.\n */\n hostDomain?: string\n}\n\nexport class UserIdentity implements IUserIdentity {\n kind: typeof Kind = Kind\n key = ''\n userId = ''\n provider: Provider = 'google'\n providerId = ''\n emailVerified = false\n hostDomain?: string\n\n constructor(input?: string | IUserIdentity) {\n let init: IUserIdentity\n if (typeof input === 'string') {\n init = JSON.parse(input)\n } else if (typeof input === 'object') {\n init = input\n } else {\n init = {\n kind: Kind,\n key: nanoid(),\n userId: '',\n provider: 'google',\n providerId: '',\n emailVerified: false,\n }\n }\n this.new(init)\n }\n\n new(init: IUserIdentity): void {\n if (!UserIdentity.isUserIdentity(init)) {\n throw new Error(`Not a UserIdentity.`)\n }\n const { key = nanoid(), emailVerified, provider, providerId, userId, hostDomain } = init\n this.kind = Kind\n this.key = key\n this.provider = provider\n this.providerId = providerId\n this.userId = userId\n this.emailVerified = emailVerified\n if (hostDomain) {\n this.hostDomain = hostDomain\n } else {\n this.hostDomain = undefined\n }\n }\n\n static isUserIdentity(input: unknown): boolean {\n const typed = input as IUserIdentity\n if (!input || typed.kind !== Kind) {\n return false\n }\n return true\n }\n\n toJSON(): IUserIdentity {\n const result: IUserIdentity = {\n kind: Kind,\n key: this.key,\n provider: this.provider,\n providerId: this.providerId,\n userId: this.userId,\n emailVerified: this.emailVerified,\n }\n if (this.hostDomain) {\n result.hostDomain = this.hostDomain\n }\n return result\n }\n}\n"]}
1
+ {"version":3,"file":"UserIdentity.js","sourceRoot":"","sources":["../../../../src/models/store/UserIdentity.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAA;AAExC,MAAM,CAAC,MAAM,IAAI,GAAG,mBAAmB,CAAA;AAuCvC,MAAM,OAAO,YAAY;IACvB,IAAI,GAAgB,IAAI,CAAA;IACxB,GAAG,GAAG,EAAE,CAAA;IACR,MAAM,GAAG,EAAE,CAAA;IACX,QAAQ,GAAa,QAAQ,CAAA;IAC7B,UAAU,GAAG,EAAE,CAAA;IACf,aAAa,GAAG,KAAK,CAAA;IACrB,UAAU,CAAS;IAEnB,YAAY,KAA8B;QACxC,IAAI,IAAmB,CAAA;QACvB,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;YAC9B,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,CAAA;QAC1B,CAAC;aAAM,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;YACrC,I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AM,GAAkB;YAC5B,IAAI,EAAE,IAAI;YACV,GAAG,EAAE,IAAI,CAAC,GAAG;YACb,QAAQ,EAAE,IAAI,CAAC,QAAQ;YACvB,UAAU,EAAE,IAAI,CAAC,UAAU;YAC3B,MAAM,EAAE,IAAI,CAAC,MAAM;YACnB,aAAa,EAAE,IAAI,CAAC,aAAa;SAClC,CAAA;QACD,IAAI,IAAI,CAAC,UAAU,EAAE,CAAC;YACpB,MAAM,CAAC,UAAU,GAAG,IAAI,CAAC,UAAU,CAAA;QACrC,CAAC;QACD,OAAO,MAAM,CAAA;IACf,CAAC;CACF","sourcesContent":["import { nanoid } from '../../nanoid.js'\n\nexport const Kind = 'Core#UserIdentity'\n\ntype Provider = 'google'\n\n/**\n * In the system the user identity represents registration information associated with a specific identity provider.\n * This association allows the user to use different identity providers that map to the same user, as long as the\n * email stays consistent.\n */\nexport interface IUserIdentity {\n kind: typeof Kind\n /**\n * The database ID\n */\n key: string\n /**\n * The related user id.\n */\n userId: string\n /**\n * The identity provider.\n */\n provider: Provider\n /**\n * The provider's unique ID.\n * This allows to recognize a returning user.\n */\n providerId: string\n /**\n * `true`, if the provider has verified the email address.\n */\n emailVerified: boolean\n /**\n * If present, the host domain of the user's GSuite email address.\n * Google specific.\n */\n hostDomain?: string\n}\n\nexport class UserIdentity implements IUserIdentity {\n kind: typeof Kind = Kind\n key = ''\n userId = ''\n provider: Provider = 'google'\n providerId = ''\n emailVerified = false\n hostDomain?: string\n\n constructor(input?: string | IUserIdentity) {\n let init: IUserIdentity\n if (typeof input === 'string') {\n init = JSON.parse(input)\n } else if (typeof input === 'object') {\n init = input\n } else {\n init = {\n kind: Kind,\n key: nanoid(),\n userId: '',\n provider: 'google',\n providerId: '',\n emailVerified: false,\n }\n }\n this.new(init)\n }\n\n new(init: IUserIdentity): void {\n if (!UserIdentity.isUserIdentity(init)) {\n throw new Error(`Not a UserIdentity.`)\n }\n const { key = nanoid(), emailVerified, provider, providerId, userId, hostDomain } = init\n this.kind = Kind\n this.key = key\n this.provider = provider\n this.providerId = providerId\n this.userId = userId\n this.emailVerified = emailVerified\n if (hostDomain) {\n this.hostDomain = hostDomain\n } else {\n this.hostDomain = undefined\n }\n }\n\n static isUserIdentity(input: unknown): boolean {\n const typed = input as IUserIdentity\n if (!input || typed.kind !== Kind) {\n return false\n }\n return true\n }\n\n toJSON(): IUserIdentity {\n const result: IUserIdentity = {\n kind: Kind,\n key: this.key,\n provider: this.provider,\n providerId: this.providerId,\n userId: this.userId,\n emailVerified: this.emailVerified,\n }\n if (this.hostDomain) {\n result.hostDomain = this.hostDomain\n }\n return result\n }\n}\n"]}
@@ -1,4 +1,4 @@
1
- import { nanoid } from 'nanoid';
1
+ import { nanoid } from '../../nanoid.js';
2
2
  import { BaseTransformer, dataValue } from './BaseTransformer.js';
3
3
  /**
4
4
  * Transforms Dexie system (legacy system) into the legacy PouchDB system.
@@ -1 +1 @@
1
- {"version":3,"file":"ArcDexieTransformer.js","sourceRoot":"","sources":["../../../../src/models/transformers/ArcDexieTransformer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAA;AAC/B,OAAO,EAAE,eAAe,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAA;AAkEjE;;GAEG;AACH,MAAM,OAAO,mBAAoB,SAAQ,eAAe;IACtD;;;;;OAKG;IACH,KAAK,CAAC,SAAS;QACb,MAAM,GAAG,GAAG,IAAI,CAAC,SAAS,CAAgB,CAAA;QAE1C,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,aAAa,CAAC,GAAG,CAAC,QAAQ,IAAI,EAAE,CAAC,CAAA;QAC7D,MAAM,KAAK,GAAG,IAAI,CAAC,eAAe,CAAC,GAAG,CAAC,QAAQ,IAAI,EAAE,CAAC,CAAA;QACtD,MAAM,IAAI,GAAG,IAAI,CAAC,iBAAiB,CAAC,QAAQ,EAAE,KAAK,CAAC,CAAA;QACpD,MAAM,MAAM,GAAG;YACb,SAAS,EAAE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AC,UAAU,CAAC,MAAM,EAAE,CAAC,GAAG,IAAI,EAAE,CAAC,EAAE,EAAE,CAAC;gBAChE,MAAM,GAAG,GAAG,OAAO,CAAC,UAAU,CAAC,CAAC,CAAC,CAAA;gBACjC,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,QAAQ,EAAE,CAAC,EAAE,EAAE,CAAC;oBAClC,IAAI,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,MAAM,KAAK,GAAG,EAAE,CAAC;wBACjC,MAAM,EAAE,OAAO,EAAE,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAA;wBACjC,OAAO,CAAC,GAAG,IAAI,IAAI,YAAY,EAAE,CAAA;wBACjC,IAAI,CAAC,mBAAmB,CAAC,OAAgC,EAAE,YAAY,CAAC,CAAA;wBACxE,IAAI,CAAC,mBAAmB,CAAC,OAAO,CAAC,aAAa,EAAE,OAAO,CAAC,GAAG,CAAC,CAAA;wBAC5D,MAAK;oBACP,CAAC;gBACH,CAAC;YACH,CAAC;QACH,CAAC;QACD,OAAO,IAAI,CAAA;IACb,CAAC;CACF","sourcesContent":["import { nanoid } from 'nanoid'\nimport { BaseTransformer, dataValue } from './BaseTransformer.js'\nimport { Creator, Browser, Page, Entry, Header } from './har.js'\nimport {\n ArcExportObject,\n ExportArcProjects,\n ExportArcSavedRequest,\n ExportArcHistoryRequest,\n} from '../legacy/DataExport.js'\n\ninterface DexieExport {\n kind: string\n createdAt: string\n version: string\n requests?: DexieRequest[]\n projects?: DexieProject[]\n}\ninterface DexieRequest {\n order: number\n url: string\n method: string\n type: string\n updateTime: number\n id: string\n kind: string\n har: DexieHar\n _har?: DexieHar\n name?: string\n _name?: string\n referenceEntry?: number\n driveId?: string\n}\n\ninterface DexieHar {\n comment: string\n version: string\n creator: Creator\n browser: Browser\n pages: Page[]\n entries: Entry[]\n}\n\ninterface DexieProject {\n order: number\n created: number\n updateTime: number\n requestIds: string[]\n name: string\n kind: string\n id: number\n}\n\ninterface ProjectItem {\n updateData: string[]\n legacyProject: ExportArcProjects\n}\n\ninterface RequestProcessItem {\n origin: string\n request: ExportArcSavedRequest | ExportArcHistoryRequest\n}\n\ninterface ProcessedRequests {\n saved: RequestProcessItem[]\n history: RequestProcessItem[]\n}\n\n/**\n * Transforms Dexie system (legacy system) into the legacy PouchDB system.\n */\nexport class ArcDexieTransformer extends BaseTransformer {\n /**\n * Transforms legacy ARC export object based on Dexie data store\n * into current export data model.\n *\n * @returns New data model object.\n */\n async transform(): Promise<ArcExportObject> {\n const raw = this[dataValue] as DexieExport\n\n const requests = await this.parseRequests(raw.requests || [])\n const pData = this.processProjects(raw.projects || [])\n const data = this.associateProjects(requests, pData)\n const result = {\n createdAt: new Date().toISOString(),\n version: 'unknown',\n kind: 'ARC#Import',\n requests: data.saved ? data.saved.map((item) => item.request as ExportArcSavedRequest) : [],\n projects: pData ? pData.map((item) => item.legacyProject as ExportArcProjects) : [],\n history: data.history ? data.history.map((item) => item.request as ExportArcHistoryRequest) : [],\n }\n // TODO: handle history data.\n return result\n }\n\n /**\n * In new structure projects do not have a reference to request ids. It's\n * the other way around in previous system.\n * It's a bad pattern for object stores but it must suffice for now.\n *\n * @param projects List of projects in the import.\n * @returns Preprocessed projects array\n */\n processProjects(projects: DexieProject[]): ProjectItem[] {\n if (!projects || !projects.length) {\n return []\n }\n const list: ProjectItem[] = []\n projects.forEach((item) => {\n const result = this.processProjectItem(item)\n if (result) {\n list.push(result)\n }\n })\n return list\n }\n\n /**\n * Creates a pre-processed project data.\n *\n * @param item Project object from the Dexie import.\n * @return Pre-processed project object with project store data\n * under the `legacyProject` property and list of requests IDs under\n * the `updateData` property.\n */\n processProjectItem(item: DexieProject): ProjectItem | undefined {\n if (!item.requestIds || !item.requestIds.length) {\n return undefined\n }\n return {\n updateData: item.requestIds,\n legacyProject: {\n kind: 'ARC#Project',\n key: nanoid(),\n name: item.name,\n order: item.order,\n updated: item.updateTime,\n created: item.created,\n },\n }\n }\n\n /**\n * History is placed in its own store, saved items has own store.\n * Har data are not imported this way as user cannot actually use it.\n *\n * @param requests List of requests objects from the import file.\n * @returns A promise resolved when import is ready.\n */\n async parseRequests(requests: DexieRequest[]): Promise<ProcessedRequests> {\n const data = await this.parseRequestsDeffered(requests)\n // remove duplicates from the history.\n const ids: string[] = []\n data.history = data.history.filter((item) => {\n if (ids.indexOf(item.request.key) === -1) {\n ids[ids.length] = item.request.key\n return true\n }\n return false\n })\n return data\n }\n\n /**\n * Parses the request data.\n * It takes only portion of the data to parse so the script release the\n * event loop and ANR screen won't appear.\n *\n * @param requests List of requests from the import.\n * @param saved Final list of saved requests\n * @param history Final list of history items.\n */\n async parseRequestsDeffered(\n requests: DexieRequest[],\n saved: RequestProcessItem[] = [],\n history: RequestProcessItem[] = []\n ): Promise<ProcessedRequests> {\n if (requests.length === 0) {\n return {\n saved,\n history,\n }\n }\n const len = Math.min(requests.length, 200)\n // Up to 200 loop iteration at once.\n // Then the function return and release main loop.\n for (let i = 0; i < len; i++) {\n const item = requests[i]\n if (item.type === 'history') {\n const result = this.parseHistoryItem(item)\n history.push(result)\n } else if (item.type === 'saved') {\n const result = this.parseSavedItem(item)\n saved.push(result)\n } else if (item.type === 'drive') {\n const result = this.parseDriveItem(item)\n saved.push(result)\n }\n }\n requests.splice(0, len)\n return this.parseRequestsDeffered(requests, saved, history)\n }\n\n parseHistoryItem(item: DexieRequest): RequestProcessItem {\n const updated = { ...item }\n updated.updateTime = updated.updateTime || Date.now()\n const obj: ExportArcHistoryRequest = {\n key: nanoid(),\n method: updated.method,\n url: updated.url,\n updated: new Date(updated.updateTime).getTime(),\n }\n // payload and headers\n const har = updated._har || updated.har\n const { entries } = har\n const entry = entries[entries.length - 1]\n if (entry) {\n const harRequest = entry.request\n obj.headers = this.parseHarHeaders(harRequest.headers)\n obj.payload = harRequest.postData?.text\n let t = new Date(entry.startedDateTime).getTime()\n if (Number.isNaN(t)) {\n t = Date.now()\n }\n obj.created = t\n } else {\n obj.created = obj.updated\n }\n obj.updated = Date.now()\n return {\n origin: updated.id,\n request: obj,\n }\n }\n\n parseSavedItem(item: DexieRequest): RequestProcessItem {\n const requestName = item.name || item._name\n let keyName = requestName\n if (keyName && keyName[0] === '_') {\n keyName = keyName.substr(1)\n }\n const obj: ExportArcSavedRequest = {\n name: requestName || '',\n method: item.method,\n url: item.url,\n type: 'saved',\n kind: 'ARC#HttpRequest',\n key: nanoid(),\n }\n // payload and headers\n const harIndex = item.referenceEntry || 0\n const har = item._har || item.har\n if (har) {\n const { entries } = har\n let entry\n if (harIndex || harIndex === 0) {\n entry = entries[harIndex]\n } else {\n ;[entry] = entries\n }\n if (entry) {\n const harRequest = entry.request\n obj.headers = this.parseHarHeaders(harRequest.headers)\n obj.payload = harRequest.postData?.text\n let t = new Date(entry.startedDateTime).getTime()\n if (Number.isNaN(t)) {\n t = Date.now()\n }\n obj.created = t\n }\n }\n obj.updated = Date.now()\n\n return {\n origin: item.id,\n request: obj,\n }\n }\n\n parseDriveItem(item: DexieRequest): RequestProcessItem {\n const result = this.parseSavedItem(item)\n result.request.driveId = item.driveId\n return result\n }\n\n parseHarHeaders(arr: Header[]): string {\n if (!arr || !arr.length) {\n return ''\n }\n return arr.map((item) => `${item.name}: ${item.value}`).join('\\n')\n }\n\n /**\n * Associate requests with project data.\n *\n * @param {ProcessedRequests} data Parsed requests object\n * @param {ProjectItem[]} projects List of projects\n * @return {ProcessedRequests} Parsed requests object\n */\n associateProjects(data: ProcessedRequests, projects: ProjectItem[]): ProcessedRequests {\n if (!projects || !projects.length) {\n return data\n }\n if (!data.saved) {\n data.saved = []\n }\n const savedLen = data.saved.length\n const projectsLen = projects.length\n for (let i = 0; i < projectsLen; i++) {\n const project = projects[i]\n const newProjectId = project.legacyProject.key\n for (let j = 0, rLen = project.updateData.length; j < rLen; j++) {\n const rId = project.updateData[j]\n for (let k = 0; k < savedLen; k++) {\n if (data.saved[k].origin === rId) {\n const { request } = data.saved[k]\n request.key += `/${newProjectId}`\n this.addProjectReference(request as ExportArcSavedRequest, newProjectId)\n this.addRequestReference(project.legacyProject, request.key)\n break\n }\n }\n }\n }\n return data\n }\n}\n"]}
1
+ {"version":3,"file":"ArcDexieTransformer.js","sourceRoot":"","sources":["../../../../src/models/transformers/ArcDexieTransformer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAA;AACxC,OAAO,EAAE,eAAe,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAA;AAkEjE;;GAEG;AACH,MAAM,OAAO,mBAAoB,SAAQ,eAAe;IACtD;;;;;OAKG;IACH,KAAK,CAAC,SAAS;QACb,MAAM,GAAG,GAAG,IAAI,CAAC,SAAS,CAAgB,CAAA;QAE1C,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,aAAa,CAAC,GAAG,CAAC,QAAQ,IAAI,EAAE,CAAC,CAAA;QAC7D,MAAM,KAAK,GAAG,IAAI,CAAC,eAAe,CAAC,GAAG,CAAC,QAAQ,IAAI,EAAE,CAAC,CAAA;QACtD,MAAM,IAAI,GAAG,IAAI,CAAC,iBAAiB,CAAC,QAAQ,EAAE,KAAK,CAAC,CAAA;QACpD,MAAM,MAAM,GAAG;YACb,SAAS,EAAE,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE;YACnC,OAAO,EAAE,SAAS;YAClB,IAAI,EAAE,YAAY;YAClB,QAAQ,EAAE,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,OAAgC,CAAC,CAAC,CAAC,CAAC,EAAE;YAC3F,QAAQ,EAAE,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,aAAkC,CAAC,CAAC,CAAC,CAAC,EAAE;YACnF,OAAO,EAAE,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC,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ACjC,IAAI,CAAC,mBAAmB,CAAC,OAAgC,EAAE,YAAY,CAAC,CAAA;wBACxE,IAAI,CAAC,mBAAmB,CAAC,OAAO,CAAC,aAAa,EAAE,OAAO,CAAC,GAAG,CAAC,CAAA;wBAC5D,MAAK;oBACP,CAAC;gBACH,CAAC;YACH,CAAC;QACH,CAAC;QACD,OAAO,IAAI,CAAA;IACb,CAAC;CACF","sourcesContent":["import { nanoid } from '../../nanoid.js'\nimport { BaseTransformer, dataValue } from './BaseTransformer.js'\nimport { Creator, Browser, Page, Entry, Header } from './har.js'\nimport {\n ArcExportObject,\n ExportArcProjects,\n ExportArcSavedRequest,\n ExportArcHistoryRequest,\n} from '../legacy/DataExport.js'\n\ninterface DexieExport {\n kind: string\n createdAt: string\n version: string\n requests?: DexieRequest[]\n projects?: DexieProject[]\n}\ninterface DexieRequest {\n order: number\n url: string\n method: string\n type: string\n updateTime: number\n id: string\n kind: string\n har: DexieHar\n _har?: DexieHar\n name?: string\n _name?: string\n referenceEntry?: number\n driveId?: string\n}\n\ninterface DexieHar {\n comment: string\n version: string\n creator: Creator\n browser: Browser\n pages: Page[]\n entries: Entry[]\n}\n\ninterface DexieProject {\n order: number\n created: number\n updateTime: number\n requestIds: string[]\n name: string\n kind: string\n id: number\n}\n\ninterface ProjectItem {\n updateData: string[]\n legacyProject: ExportArcProjects\n}\n\ninterface RequestProcessItem {\n origin: string\n request: ExportArcSavedRequest | ExportArcHistoryRequest\n}\n\ninterface ProcessedRequests {\n saved: RequestProcessItem[]\n history: RequestProcessItem[]\n}\n\n/**\n * Transforms Dexie system (legacy system) into the legacy PouchDB system.\n */\nexport class ArcDexieTransformer extends BaseTransformer {\n /**\n * Transforms legacy ARC export object based on Dexie data store\n * into current export data model.\n *\n * @returns New data model object.\n */\n async transform(): Promise<ArcExportObject> {\n const raw = this[dataValue] as DexieExport\n\n const requests = await this.parseRequests(raw.requests || [])\n const pData = this.processProjects(raw.projects || [])\n const data = this.associateProjects(requests, pData)\n const result = {\n createdAt: new Date().toISOString(),\n version: 'unknown',\n kind: 'ARC#Import',\n requests: data.saved ? data.saved.map((item) => item.request as ExportArcSavedRequest) : [],\n projects: pData ? pData.map((item) => item.legacyProject as ExportArcProjects) : [],\n history: data.history ? data.history.map((item) => item.request as ExportArcHistoryRequest) : [],\n }\n // TODO: handle history data.\n return result\n }\n\n /**\n * In new structure projects do not have a reference to request ids. It's\n * the other way around in previous system.\n * It's a bad pattern for object stores but it must suffice for now.\n *\n * @param projects List of projects in the import.\n * @returns Preprocessed projects array\n */\n processProjects(projects: DexieProject[]): ProjectItem[] {\n if (!projects || !projects.length) {\n return []\n }\n const list: ProjectItem[] = []\n projects.forEach((item) => {\n const result = this.processProjectItem(item)\n if (result) {\n list.push(result)\n }\n })\n return list\n }\n\n /**\n * Creates a pre-processed project data.\n *\n * @param item Project object from the Dexie import.\n * @return Pre-processed project object with project store data\n * under the `legacyProject` property and list of requests IDs under\n * the `updateData` property.\n */\n processProjectItem(item: DexieProject): ProjectItem | undefined {\n if (!item.requestIds || !item.requestIds.length) {\n return undefined\n }\n return {\n updateData: item.requestIds,\n legacyProject: {\n kind: 'ARC#Project',\n key: nanoid(),\n name: item.name,\n order: item.order,\n updated: item.updateTime,\n created: item.created,\n },\n }\n }\n\n /**\n * History is placed in its own store, saved items has own store.\n * Har data are not imported this way as user cannot actually use it.\n *\n * @param requests List of requests objects from the import file.\n * @returns A promise resolved when import is ready.\n */\n async parseRequests(requests: DexieRequest[]): Promise<ProcessedRequests> {\n const data = await this.parseRequestsDeffered(requests)\n // remove duplicates from the history.\n const ids: string[] = []\n data.history = data.history.filter((item) => {\n if (ids.indexOf(item.request.key) === -1) {\n ids[ids.length] = item.request.key\n return true\n }\n return false\n })\n return data\n }\n\n /**\n * Parses the request data.\n * It takes only portion of the data to parse so the script release the\n * event loop and ANR screen won't appear.\n *\n * @param requests List of requests from the import.\n * @param saved Final list of saved requests\n * @param history Final list of history items.\n */\n async parseRequestsDeffered(\n requests: DexieRequest[],\n saved: RequestProcessItem[] = [],\n history: RequestProcessItem[] = []\n ): Promise<ProcessedRequests> {\n if (requests.length === 0) {\n return {\n saved,\n history,\n }\n }\n const len = Math.min(requests.length, 200)\n // Up to 200 loop iteration at once.\n // Then the function return and release main loop.\n for (let i = 0; i < len; i++) {\n const item = requests[i]\n if (item.type === 'history') {\n const result = this.parseHistoryItem(item)\n history.push(result)\n } else if (item.type === 'saved') {\n const result = this.parseSavedItem(item)\n saved.push(result)\n } else if (item.type === 'drive') {\n const result = this.parseDriveItem(item)\n saved.push(result)\n }\n }\n requests.splice(0, len)\n return this.parseRequestsDeffered(requests, saved, history)\n }\n\n parseHistoryItem(item: DexieRequest): RequestProcessItem {\n const updated = { ...item }\n updated.updateTime = updated.updateTime || Date.now()\n const obj: ExportArcHistoryRequest = {\n key: nanoid(),\n method: updated.method,\n url: updated.url,\n updated: new Date(updated.updateTime).getTime(),\n }\n // payload and headers\n const har = updated._har || updated.har\n const { entries } = har\n const entry = entries[entries.length - 1]\n if (entry) {\n const harRequest = entry.request\n obj.headers = this.parseHarHeaders(harRequest.headers)\n obj.payload = harRequest.postData?.text\n let t = new Date(entry.startedDateTime).getTime()\n if (Number.isNaN(t)) {\n t = Date.now()\n }\n obj.created = t\n } else {\n obj.created = obj.updated\n }\n obj.updated = Date.now()\n return {\n origin: updated.id,\n request: obj,\n }\n }\n\n parseSavedItem(item: DexieRequest): RequestProcessItem {\n const requestName = item.name || item._name\n let keyName = requestName\n if (keyName && keyName[0] === '_') {\n keyName = keyName.substr(1)\n }\n const obj: ExportArcSavedRequest = {\n name: requestName || '',\n method: item.method,\n url: item.url,\n type: 'saved',\n kind: 'ARC#HttpRequest',\n key: nanoid(),\n }\n // payload and headers\n const harIndex = item.referenceEntry || 0\n const har = item._har || item.har\n if (har) {\n const { entries } = har\n let entry\n if (harIndex || harIndex === 0) {\n entry = entries[harIndex]\n } else {\n ;[entry] = entries\n }\n if (entry) {\n const harRequest = entry.request\n obj.headers = this.parseHarHeaders(harRequest.headers)\n obj.payload = harRequest.postData?.text\n let t = new Date(entry.startedDateTime).getTime()\n if (Number.isNaN(t)) {\n t = Date.now()\n }\n obj.created = t\n }\n }\n obj.updated = Date.now()\n\n return {\n origin: item.id,\n request: obj,\n }\n }\n\n parseDriveItem(item: DexieRequest): RequestProcessItem {\n const result = this.parseSavedItem(item)\n result.request.driveId = item.driveId\n return result\n }\n\n parseHarHeaders(arr: Header[]): string {\n if (!arr || !arr.length) {\n return ''\n }\n return arr.map((item) => `${item.name}: ${item.value}`).join('\\n')\n }\n\n /**\n * Associate requests with project data.\n *\n * @param {ProcessedRequests} data Parsed requests object\n * @param {ProjectItem[]} projects List of projects\n * @return {ProcessedRequests} Parsed requests object\n */\n associateProjects(data: ProcessedRequests, projects: ProjectItem[]): ProcessedRequests {\n if (!projects || !projects.length) {\n return data\n }\n if (!data.saved) {\n data.saved = []\n }\n const savedLen = data.saved.length\n const projectsLen = projects.length\n for (let i = 0; i < projectsLen; i++) {\n const project = projects[i]\n const newProjectId = project.legacyProject.key\n for (let j = 0, rLen = project.updateData.length; j < rLen; j++) {\n const rId = project.updateData[j]\n for (let k = 0; k < savedLen; k++) {\n if (data.saved[k].origin === rId) {\n const { request } = data.saved[k]\n request.key += `/${newProjectId}`\n this.addProjectReference(request as ExportArcSavedRequest, newProjectId)\n this.addRequestReference(project.legacyProject, request.key)\n break\n }\n }\n }\n }\n return data\n }\n}\n"]}
@@ -1,5 +1,5 @@
1
1
  /* eslint-disable @typescript-eslint/no-explicit-any */
2
- import { nanoid } from 'nanoid';
2
+ import { nanoid } from '../../nanoid.js';
3
3
  import { BaseTransformer, dataValue } from './BaseTransformer.js';
4
4
  /**
5
5
  * Tests if the data import is a single request export.