@api-client/core 0.13.5 → 0.13.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/src/amf/AmfShapeGenerator.js +1 -1
- package/build/src/amf/AmfShapeGenerator.js.map +1 -1
- package/build/src/amf/DataValueGenerator.js +1 -1
- package/build/src/amf/DataValueGenerator.js.map +1 -1
- package/build/src/amf/models/AmfDataNode.js +1 -1
- package/build/src/amf/models/AmfDataNode.js.map +1 -1
- package/build/src/browser.d.ts +1 -1
- package/build/src/browser.d.ts.map +1 -1
- package/build/src/browser.js.map +1 -1
- package/build/src/index.d.ts +2 -1
- package/build/src/index.d.ts.map +1 -1
- package/build/src/index.js +1 -0
- package/build/src/index.js.map +1 -1
- package/build/src/modeling/DataDomain.js +1 -1
- package/build/src/modeling/DataDomain.js.map +1 -1
- package/build/src/modeling/DomainAssociation.js +1 -1
- package/build/src/modeling/DomainAssociation.js.map +1 -1
- package/build/src/modeling/DomainEntity.js +1 -1
- package/build/src/modeling/DomainEntity.js.map +1 -1
- package/build/src/modeling/DomainFile.js +1 -1
- package/build/src/modeling/DomainFile.js.map +1 -1
- package/build/src/modeling/DomainModel.js +1 -1
- package/build/src/modeling/DomainModel.js.map +1 -1
- package/build/src/modeling/DomainNamespace.js +1 -1
- package/build/src/modeling/DomainNamespace.js.map +1 -1
- package/build/src/modeling/DomainProperty.js +1 -1
- package/build/src/modeling/DomainProperty.js.map +1 -1
- package/build/src/modeling/amf/ShapeGenerator.js +1 -1
- package/build/src/modeling/amf/ShapeGenerator.js.map +1 -1
- package/build/src/modeling/legacy/DataAssociation.js +1 -1
- package/build/src/modeling/legacy/DataAssociation.js.map +1 -1
- package/build/src/modeling/legacy/DataEntity.js +1 -1
- package/build/src/modeling/legacy/DataEntity.js.map +1 -1
- package/build/src/modeling/legacy/DataEntityBuilder.js +1 -1
- package/build/src/modeling/legacy/DataEntityBuilder.js.map +1 -1
- package/build/src/modeling/legacy/DataModel.js +1 -1
- package/build/src/modeling/legacy/DataModel.js.map +1 -1
- package/build/src/modeling/legacy/DataNamespace.js +1 -1
- package/build/src/modeling/legacy/DataNamespace.js.map +1 -1
- package/build/src/modeling/legacy/DataProperty.js +1 -1
- package/build/src/modeling/legacy/DataProperty.js.map +1 -1
- package/build/src/models/AuthorizationData.js +1 -1
- package/build/src/models/AuthorizationData.js.map +1 -1
- package/build/src/models/CertificateFile.js +1 -1
- package/build/src/models/CertificateFile.js.map +1 -1
- package/build/src/models/ClientCertificate.js +1 -1
- package/build/src/models/ClientCertificate.js.map +1 -1
- package/build/src/models/Environment.js +1 -1
- package/build/src/models/Environment.js.map +1 -1
- package/build/src/models/Folder.js +1 -1
- package/build/src/models/Folder.js.map +1 -1
- package/build/src/models/HostRule.js +1 -1
- package/build/src/models/HostRule.js.map +1 -1
- package/build/src/models/HttpProject.js +1 -1
- package/build/src/models/HttpProject.js.map +1 -1
- package/build/src/models/Project.js +1 -1
- package/build/src/models/Project.js.map +1 -1
- package/build/src/models/ProjectFolder.js +1 -1
- package/build/src/models/ProjectFolder.js.map +1 -1
- package/build/src/models/ProjectRequest.js +1 -1
- package/build/src/models/ProjectRequest.js.map +1 -1
- package/build/src/models/ProjectSchema.js +1 -1
- package/build/src/models/ProjectSchema.js.map +1 -1
- package/build/src/models/store/DataFile.js +1 -1
- package/build/src/models/store/DataFile.js.map +1 -1
- package/build/src/models/store/File.js +1 -1
- package/build/src/models/store/File.js.map +1 -1
- package/build/src/models/store/Invitation.js +1 -1
- package/build/src/models/store/Invitation.js.map +1 -1
- package/build/src/models/store/Organization.js +1 -1
- package/build/src/models/store/Organization.js.map +1 -1
- package/build/src/models/store/Permission.d.ts +34 -0
- package/build/src/models/store/Permission.d.ts.map +1 -1
- package/build/src/models/store/Permission.js +28 -2
- package/build/src/models/store/Permission.js.map +1 -1
- package/build/src/models/store/UserIdentity.js +1 -1
- package/build/src/models/store/UserIdentity.js.map +1 -1
- package/build/src/models/transformers/ArcDexieTransformer.js +1 -1
- package/build/src/models/transformers/ArcDexieTransformer.js.map +1 -1
- package/build/src/models/transformers/ArcLegacyTransformer.js +1 -1
- package/build/src/models/transformers/ArcLegacyTransformer.js.map +1 -1
- package/build/src/models/transformers/ArcPouchTransformer.js +1 -1
- package/build/src/models/transformers/ArcPouchTransformer.js.map +1 -1
- package/build/src/models/transformers/PostmanV21Transformer.js +1 -1
- package/build/src/models/transformers/PostmanV21Transformer.js.map +1 -1
- package/build/src/models/transformers/PostmanV2Transformer.js +1 -1
- package/build/src/models/transformers/PostmanV2Transformer.js.map +1 -1
- package/build/src/nanoid.d.ts +10 -0
- package/build/src/nanoid.d.ts.map +1 -0
- package/build/src/nanoid.js +11 -0
- package/build/src/nanoid.js.map +1 -0
- package/build/src/patch/PatchClient.js +1 -1
- package/build/src/patch/PatchClient.js.map +1 -1
- package/build/src/sdk/FilesSdk.js +1 -1
- package/build/src/sdk/FilesSdk.js.map +1 -1
- package/build/tsconfig.tsbuildinfo +1 -1
- package/data/models/example-generator-api.json +14 -14
- package/package.json +2 -1
- package/src/amf/AmfShapeGenerator.ts +1 -1
- package/src/amf/DataValueGenerator.ts +1 -1
- package/src/amf/models/AmfDataNode.ts +1 -1
- package/src/modeling/DataDomain.ts +1 -1
- package/src/modeling/DomainAssociation.ts +1 -1
- package/src/modeling/DomainEntity.ts +1 -1
- package/src/modeling/DomainFile.ts +1 -1
- package/src/modeling/DomainModel.ts +1 -1
- package/src/modeling/DomainNamespace.ts +1 -1
- package/src/modeling/DomainProperty.ts +1 -1
- package/src/modeling/amf/ShapeGenerator.ts +1 -1
- package/src/modeling/legacy/DataAssociation.ts +1 -1
- package/src/modeling/legacy/DataEntity.ts +1 -1
- package/src/modeling/legacy/DataEntityBuilder.ts +1 -1
- package/src/modeling/legacy/DataModel.ts +1 -1
- package/src/modeling/legacy/DataNamespace.ts +1 -1
- package/src/modeling/legacy/DataProperty.ts +1 -1
- package/src/models/AuthorizationData.ts +1 -1
- package/src/models/CertificateFile.ts +1 -1
- package/src/models/ClientCertificate.ts +1 -1
- package/src/models/Environment.ts +1 -1
- package/src/models/Folder.ts +1 -1
- package/src/models/HostRule.ts +1 -1
- package/src/models/HttpProject.ts +1 -1
- package/src/models/Project.ts +1 -1
- package/src/models/ProjectFolder.ts +1 -1
- package/src/models/ProjectRequest.ts +1 -1
- package/src/models/ProjectSchema.ts +1 -1
- package/src/models/store/DataFile.ts +1 -1
- package/src/models/store/File.ts +1 -1
- package/src/models/store/Invitation.ts +1 -1
- package/src/models/store/Organization.ts +1 -1
- package/src/models/store/Permission.ts +59 -2
- package/src/models/store/UserIdentity.ts +1 -1
- package/src/models/transformers/ArcDexieTransformer.ts +1 -1
- package/src/models/transformers/ArcLegacyTransformer.ts +1 -1
- package/src/models/transformers/ArcPouchTransformer.ts +1 -1
- package/src/models/transformers/PostmanV21Transformer.ts +1 -1
- package/src/models/transformers/PostmanV2Transformer.ts +1 -1
- package/src/nanoid.ts +10 -0
- package/src/patch/PatchClient.ts +1 -1
- package/src/sdk/FilesSdk.ts +1 -1
- package/tests/unit/modeling/domain_file.spec.ts +4 -0
- package/tests/unit/models/File/new.spec.ts +2 -0
- package/tests/unit/models/File/toJSON.spec.ts +2 -0
- package/tests/unit/models/Folder/create.spec.ts +4 -0
- package/tests/unit/models/Permission/all.spec.ts +88 -0
- package/tests/unit/models/Project/create.spec.ts +4 -0
- package/tests/unit/runtime/proxy/HttpProjectProxy.spec.ts +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Project.js","sourceRoot":"","sources":["../../../src/models/Project.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"Project.js","sourceRoot":"","sources":["../../../src/models/Project.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAA;AACrC,OAAO,EAAS,IAAI,EAAE,MAAM,iBAAiB,CAAA;AAC7C,OAAO,EAAE,KAAK,EAAE,MAAM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EAAE,CAAC;YACrC,IAAI,GAAG,KAAK,CAAA;QACd,CAAC;aAAM,CAAC;YACN,IAAI,GAAG;gBACL,IAAI,EAAE,WAAW;gBACjB,GAAG,EAAE,MAAM,EAAE;gBACb,YAAY,EAAE,EAAE;gBAChB,IAAI,EAAE,KAAK,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,MAAM,EAAE;gBACjC,OAAO,EAAE,EAAE;gBACX,aAAa,EAAE,EAAE;gBACjB,WAAW,EAAE,EAAE;gBACf,YAAY,EAAE,EAAE,IAAI,EAAE,EAAE,EAAE,IAAI,EAAE,CAAC,EAAE,IAAI,EAAE,KAAK,EAAE;aACjD,CAAA;QACH,CAAC;QACD,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,CAAA;IAChB,CAAC;IAEQ,GAAG,CAAC,IAAc;QACzB,IAAI,CAAC,OAAO,CAAC,SAAS,CAAC,IAAI,CAAC,EAAE,CAAC;YAC7B,MAAM,IAAI,KAAK,CAAC,qBAAqB,CAAC,CAAA;QACxC,CAAC;QACD,KAAK,CAAC,GAAG,CAAC,IAAI,CAAC,CAAA;QACf,IAAI,CAAC,IAAI,GAAG,WAAW,CAAA;QACvB,OAAO,IAAI,CAAA;IACb,CAAC;IAED,MAAM,CAAC,SAAS,CAAC,KAAc;QAC7B,MAAM,KAAK,GAAG,KAAiB,CAAA;QAC/B,IAAI,CAAC,KAAK,IAAI,KAAK,CAAC,IAAI,KAAK,WAAW,EAAE,CAAC;YACzC,OAAO,KAAK,CAAA;QACd,CAAC;QACD,OAAO,IAAI,CAAA;IACb,CAAC;IAEQ,MAAM;QACb,MAAM,MAAM,GAAa;YACvB,GAAG,KAAK,CAAC,MAAM,EAAE;YACjB,IAAI,EAAE,WAAW;SAClB,CAAA;QACD,OAAO,MAAM,CAAA;IACf,CAAC;CACF","sourcesContent":["import { nanoid } from '../nanoid.js'\nimport { IFile, File } from './store/File.js'\nimport { Thing } from './Thing.js'\nimport { HttpProject, IHttpProject } from './HttpProject.js'\nimport { ProjectKind } from './kinds.js'\n\n/**\n * This model represents a meta data for an HTTP project stored with the data store.\n * This does not include the HTTP project entity, though, it is referenced through the same key.\n */\nexport interface IProject extends IFile {\n kind: typeof ProjectKind\n}\n\n/**\n * This model represents a meta data for an HTTP project stored with the data store.\n * This does not include the HTTP project entity, though, it is referenced through the same key.\n */\nexport class Project extends File {\n override kind = ProjectKind\n\n static fromProject(project: HttpProject | IHttpProject, organization: string, owner?: string): Project {\n let final: IHttpProject\n if (typeof (project as HttpProject).toJSON === 'function') {\n final = (project as HttpProject).toJSON()\n } else {\n final = project as IHttpProject\n }\n const init: IProject = {\n kind: ProjectKind,\n key: project.key,\n organization,\n info: { ...final.info },\n lastModified: { user: owner || '', time: 0, byMe: false },\n owner,\n parents: [],\n permissionIds: [],\n permissions: [],\n }\n return new Project(init)\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 override fromName(name: string, organization: string, owner?: string): Project {\n return super.fromName(name, organization, owner, ProjectKind) as Project\n }\n\n constructor(input?: string | IProject) {\n super()\n let init: IProject\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: ProjectKind,\n key: nanoid(),\n organization: '',\n info: Thing.fromName('').toJSON(),\n parents: [],\n permissionIds: [],\n permissions: [],\n lastModified: { user: '', time: 0, byMe: false },\n }\n }\n this.new(init)\n }\n\n override new(init: IProject): this {\n if (!Project.isProject(init)) {\n throw new Error(`Not a project file.`)\n }\n super.new(init)\n this.kind = ProjectKind\n return this\n }\n\n static isProject(input: unknown): boolean {\n const typed = input as IProject\n if (!input || typed.kind !== ProjectKind) {\n return false\n }\n return true\n }\n\n override toJSON(): IProject {\n const result: IProject = {\n ...super.toJSON(),\n kind: ProjectKind,\n }\n return result\n }\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ProjectFolder.js","sourceRoot":"","sources":["../../../src/models/ProjectFolder.ts"],"names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iB,CAAC,CAAA;QACtE,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,EAAE;YACpB,MAAM,UAAU,GAAG,OAAO,CAAC,UAAU,CAAC,CAAC,CAAC,GAAG,EAAE,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC,CAAA;YAC/D,IAAI,CAAC,UAAU,EAAE,CAAC;gBAChB,OAAM;YACR,CAAC;YACD,MAAM,IAAI,GAAG,IAAI,aAAa,CAAC,MAAM,CAAC,UAAU,EAAE,EAAE,UAAU,CAAC,MAAM,EAAE,CAAC,CAAA;YACxE,IAAI,CAAC,GAAG,GAAG,MAAM,EAAE,CAAA;YACnB,IAAI,CAAC,KAAK,GAAG,EAAE,CAAA;YACf,MAAM,CAAC,SAAS,CAAC,IAAI,CAAC,CAAA;YACtB,IAAI,YAAY,EAAE,CAAC;gBACjB,UAAU,CAAC,aAAa,CAAC,IAAI,EAAE,OAAO,CAAC,CAAA;YACzC,CAAC;YACD,UAAU,CAAC,eAAe,CAAC,IAAI,EAAE,OAAO,EAAE,YAAY,CAAC,CAAA;QACzD,CAAC,CAAC,CAAA;IACJ,CAAC;CACF","sourcesContent":["import { nanoid } from 'nanoid'\nimport { ProjectParent } from './ProjectParent.js'\nimport { type IProjectDefinitionProperty } from './ProjectDefinitionProperty.js'\nimport { ProjectItem, type IProjectItem } from './ProjectItem.js'\nimport { type ProjectRequest, Kind as ProjectRequestKind, type IProjectRequest } from './ProjectRequest.js'\nimport { type HttpProject, type IEnvironmentCreateOptions } from './HttpProject.js'\nimport { type IThing, Thing } from './Thing.js'\nimport { Environment, type IEnvironment } from './Environment.js'\nimport { ProjectFolderKind } from './kinds.js'\n\nexport const DefaultFolderName = 'New folder'\n\nexport interface IFolderAddOptions {\n /**\n * Optionally the position at which to add the request into the list of items.\n */\n index?: number\n}\n\nexport interface IFolderCloneOptions {\n /**\n * By default it clones the folder with all requests in it.\n * Set this to `true` to skip copying the requests along with the folder.\n */\n withoutRequests?: boolean\n /**\n * By default it clones the folder with all folders in it.\n * Set this to `true` to skip copying the folders along with the folder.\n */\n withoutFolders?: boolean\n /**\n * The target project where to put the copied folder.\n * When the target project is not the same as the source project then the folder\n * is put into the project root rather than the parent folder (as it would when cloning\n * a folder inside the same project).\n */\n targetProject?: HttpProject\n /**\n * The **key** of the target folder.\n *\n * By default it clones the folder to its parent unless the clone is attached to another project.\n * When the target folder is set then it places the clone under the passed target folder.\n */\n targetFolder?: string\n}\n\nexport interface IProjectFolder extends IProjectDefinitionProperty {\n kind: typeof ProjectFolderKind\n /**\n * The identifier of the folder.\n */\n key: string\n /**\n * Folder meta\n */\n info: IThing\n /**\n * The ordered list of HTTP requests / folders in the projects.\n * The UI uses this to manipulate the view without changing the definitions.\n */\n items: IProjectItem[]\n /**\n * Timestamp when the folder was last updated.\n */\n updated: number\n /**\n * Timestamp when the folder was created.\n */\n created: number\n}\n\n/**\n * Represents a folder, a group of requests or other folders, in a folder.\n */\nexport class ProjectFolder extends ProjectParent {\n /**\n * The default name of the folder.\n */\n static get defaultName(): string {\n return DefaultFolderName\n }\n\n override kind = ProjectFolderKind\n /**\n * A reference to the top level project object.\n */\n project: HttpProject\n /**\n * Timestamp when the folder was last updated.\n */\n updated = 0\n /**\n * Timestamp when the folder was created.\n */\n created = 0\n\n constructor(project: HttpProject, input?: string | IProjectFolder) {\n super()\n this.project = project\n let init: IProjectFolder\n if (typeof input === 'string') {\n init = JSON.parse(input)\n } else if (typeof input === 'object') {\n init = input\n } else {\n const now: number = Date.now()\n init = {\n kind: ProjectFolderKind,\n info: Thing.fromName(DefaultFolderName).toJSON(),\n created: now,\n updated: now,\n items: [],\n key: nanoid(),\n }\n }\n this.new(init)\n }\n\n /**\n * Creates a new project folder clearing anything that is so far defined.\n *\n * Note, this throws an error when the project folder is not a project folder.\n */\n new(init: IProjectFolder): void {\n if (!ProjectFolder.isProjectFolder(init)) {\n throw new Error(`Not a project folder.`)\n }\n const { key = nanoid(), created = Date.now(), updated = Date.now(), items, info } = init\n this.kind = ProjectFolderKind\n this.key = key\n this.created = created\n this.updated = updated\n if (Array.isArray(items)) {\n this.items = items.map((i) => new ProjectItem(this.project, i))\n } else {\n this.items = []\n }\n if (info) {\n this.info = new Thing(info)\n } else {\n this.info = Thing.fromName(DefaultFolderName)\n }\n }\n\n /**\n * Checks whether the input is a definition of a project folder.\n */\n static isProjectFolder(input: unknown): boolean {\n const typed = input as IProjectFolder\n if (!input || typed.kind !== ProjectFolderKind) {\n return false\n }\n return true\n }\n\n toJSON(): IProjectFolder {\n const result: IProjectFolder = {\n kind: ProjectFolderKind,\n info: this.info.toJSON(),\n key: this.key,\n created: this.created,\n updated: this.updated,\n items: [],\n }\n if (Array.isArray(this.items)) {\n result.items = this.items.map((i) => i.toJSON())\n }\n return result\n }\n\n /**\n * Creates a new ProjectFolder object from a name.\n * @param project The top-most project.\n * @param name The name to set.\n */\n static fromName(project: HttpProject, name = DefaultFolderName): ProjectFolder {\n const now = Date.now()\n const key = nanoid()\n const info = Thing.fromName(name)\n const definition = new ProjectFolder(project, {\n key,\n created: now,\n updated: now,\n items: [],\n kind: ProjectFolderKind,\n info: info.toJSON(),\n })\n return definition\n }\n\n /**\n * Appends an instance of a folder to a project.\n *\n * @param folder The folder to add to this project.\n * @returns The added folder.\n */\n addFolder(folder: ProjectFolder | IProjectFolder): ProjectFolder\n\n /**\n * Appends a new folder to the project or a sub-folder.\n *\n * @param name The name to set. Optional.\n * @returns The newly inserted folder. If the folder already existed it returns its instance.\n */\n addFolder(name?: string): ProjectFolder\n\n /**\n * Appends a new folder to the folder. It updates the project to add the request definition.\n * @param name The name to set. Optional.\n * @returns The key of newly inserted folder.\n */\n addFolder(name: string | IProjectFolder | ProjectFolder | undefined): ProjectFolder {\n return this.project.addFolder(name as ProjectFolder, { parent: this.key })\n }\n\n /**\n * Appends a new request to the folder. It updates the project to add the request definition.\n * @param request The request to append to the folder.\n * @returns The key of newly inserted request.\n */\n addRequest(request: IProjectRequest | ProjectRequest | string, opts: IFolderAddOptions = {}): ProjectRequest {\n const addOptions = { parent: this.key, ...opts }\n if (typeof request === 'string') {\n return this.project.addRequest(request, addOptions)\n }\n return this.project.addRequest(request, addOptions)\n }\n\n /**\n * Adds an environment to the project.\n * @param env The definition of the environment to use to create the environment or it's name\n * @returns The same or created environment.\n */\n addEnvironment(env: IEnvironment | Environment | string, opts: IEnvironmentCreateOptions = {}): Environment {\n const newOptions: IEnvironmentCreateOptions = { ...opts, parent: this.key }\n return this.project.addEnvironment(env, newOptions)\n }\n\n /**\n * Lists items (not the actual definitions!) that are folders.\n */\n listFolderItems(): ProjectItem[] {\n const { items = [] } = this\n return items.filter((i) => i.kind === ProjectFolderKind)\n }\n\n /**\n * Lists items (not the actual definitions!) that are requests.\n */\n listRequestItems(): ProjectItem[] {\n const { items = [] } = this\n return items.filter((i) => i.kind === ProjectRequestKind)\n }\n\n /**\n * Lists folders in this folder.\n */\n listFolders(): ProjectFolder[] {\n return this.project.listFolders({ folder: this.key })\n }\n\n /**\n * Lists requests in this folder.\n */\n listRequests(): ProjectRequest[] {\n return this.project.listRequests(this.key)\n }\n\n /**\n * The callback called when the object is attached to a parent.\n * This is called when the object is created and inserted to a project or a folder\n * and when the object is moved between folders.\n */\n attachedCallback(): void {\n // ...\n }\n\n /**\n * The callback called when the object is detached from its parent.\n * This callback is called when the item is deleted from a folder or a project,\n * or when the item is about to be moved to another folder.\n */\n detachedCallback(): void {\n // ...\n }\n\n /**\n * @returns The instance of the HttpProject or a ProjectFolder that is a closes parent of this instance.\n */\n getParent(): ProjectFolder | HttpProject | undefined {\n const { project, key } = this\n return project.findParent(key)\n }\n\n /**\n * @returns A reference to the parent folder or the top-level HTTP project.\n */\n getProject(): HttpProject {\n return this.project\n }\n\n /**\n * Removes this folder from the project.\n */\n remove(): void {\n this.project.removeFolder(this.key)\n }\n\n /**\n * @returns The list of environments defined in this folder\n */\n getEnvironments(): Environment[] {\n return this.project.getEnvironments({ parent: this.key })\n }\n\n /**\n * @param key The environment key to read.\n */\n getEnvironment(key: string): Environment | undefined {\n return this.project.getEnvironment(key, { parent: this.key })\n }\n\n /**\n * Removes an environment from the folder or a sub-folder.\n *\n * @param key the key of the environment to remove\n * @returns The removed environment, if any.\n */\n removeEnvironment(key: string): Environment | undefined {\n return this.project.removeEnvironment(key, { parent: this.key })\n }\n\n /**\n * This is a link to the `getEnvironments()`. The difference is that on the\n * project level it won't return environments defined with the class initialization.\n */\n listEnvironments(): Environment[] {\n return this.project.listEnvironments({ parent: this.key })\n }\n\n /**\n * Makes a copy of this folder.\n * By default it attaches the copied folder to the same parent.\n * It also, by default, copies requests declared in this folder.\n *\n * Use the options dictionary to control these behaviors.\n *\n * @param opts Cloning options\n */\n clone(opts: IFolderCloneOptions = {}): ProjectFolder {\n const { targetProject = this.project, targetFolder } = opts\n const copy = new ProjectFolder(targetProject, this.toJSON())\n copy.key = nanoid()\n\n const extProject = targetProject !== this.project\n if (extProject) {\n if (targetFolder) {\n const parent = targetProject.findFolder(targetFolder, { keyOnly: true })\n if (!parent) {\n throw new Error(`The target project does not contain the folder ${targetFolder}`)\n }\n parent.addFolder(copy)\n } else {\n targetProject.addFolder(copy)\n }\n } else {\n const parent = targetFolder ? this.project.findFolder(targetFolder, { keyOnly: true }) : this.getParent()\n if (parent) {\n parent.addFolder(copy)\n } else {\n throw new Error(`Unable to locate a parent of the folder.`)\n }\n }\n // removes all items. Depending on the passed option we re-add them next.\n copy.items = []\n\n if (!opts.withoutRequests) {\n this.cloneRequests(copy, this.project)\n }\n if (!opts.withoutFolders) {\n this.cloneSubFolders(copy, this.project, !opts.withoutRequests)\n }\n return copy\n }\n\n /**\n * Clones the current requests to the target folder.\n *\n * @param folder The target folder into which to put the requests. The folder has to have\n * the target project attached to it.\n * @param project The originating project where the definitions are stored\n */\n protected cloneRequests(folder: ProjectFolder, project: HttpProject): void {\n const requests = this.items.filter((i) => i.kind === ProjectRequestKind)\n requests.forEach((r) => {\n const request = project.findRequest(r.key, { keyOnly: true })\n if (!request) {\n // Should we throw an error here?\n // CONS:\n // - It's not really related to the operation. It means there is an inconsistency in the project.\n // That's the role of the project class.\n // - Ignoring this would allow us to make a copy that is error free.\n // - The error may occur in a situation when the user does not expect it (giving the nature of the error)\n // Pros:\n // - There's an inconsistency in the project definition that should be reported back to the UI\n // for the user to inspect\n return\n }\n const copy = request.clone({ withoutAttach: true })\n copy.project = folder.getProject()\n folder.addRequest(copy)\n })\n }\n\n /**\n * Clones the sub-folders to the target folder.\n *\n * @param folder The target folder into which to put the sub-folders. The folder has to have the target project\n * attached to it.\n * @param project The originating project where the definitions are stored\n * @param withRequests Whether to clone requests with the folder.\n */\n protected cloneSubFolders(folder: ProjectFolder, project: HttpProject, withRequests = true): void {\n const folders = this.items.filter((i) => i.kind === ProjectFolderKind)\n folders.forEach((f) => {\n const definition = project.findFolder(f.key, { keyOnly: true })\n if (!definition) {\n return\n }\n const copy = new ProjectFolder(folder.getProject(), definition.toJSON())\n copy.key = nanoid()\n copy.items = []\n folder.addFolder(copy)\n if (withRequests) {\n definition.cloneRequests(copy, project)\n }\n definition.cloneSubFolders(copy, project, withRequests)\n })\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"ProjectFolder.js","sourceRoot":"","sources":["../../../src/models/ProjectFolder.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAA;AACrC,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAA;AAElD,OAAO,EAAE,WAAW,EAAqB,MAAM,kBAAkB,CAAA;AACjE,OAAO,EAAuB,IAAI,IAAI,kBAAkB,EAAwB,MAAM,qBAAqB,CAAA;AAE3G,OAAO,EAAe,KAAK,EAAE,MAAM,YAAY,CAAA;AAE/C,OAAO,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAA;AAE9C,MAAM,CAAC,MAAM,iBAAiB,GAAG,YAAY,CAAA;AA6D7C;;GAEG;AACH,MAAM,OAAO,aAAc,SAAQ,aAAa;IAC9C;;OAEG;IACH,MAAM,KA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S,CAAC,IAAI,CAAC,CAAA;YACtB,IAAI,YAAY,EAAE,CAAC;gBACjB,UAAU,CAAC,aAAa,CAAC,IAAI,EAAE,OAAO,CAAC,CAAA;YACzC,CAAC;YACD,UAAU,CAAC,eAAe,CAAC,IAAI,EAAE,OAAO,EAAE,YAAY,CAAC,CAAA;QACzD,CAAC,CAAC,CAAA;IACJ,CAAC;CACF","sourcesContent":["import { nanoid } from '../nanoid.js'\nimport { ProjectParent } from './ProjectParent.js'\nimport { type IProjectDefinitionProperty } from './ProjectDefinitionProperty.js'\nimport { ProjectItem, type IProjectItem } from './ProjectItem.js'\nimport { type ProjectRequest, Kind as ProjectRequestKind, type IProjectRequest } from './ProjectRequest.js'\nimport { type HttpProject, type IEnvironmentCreateOptions } from './HttpProject.js'\nimport { type IThing, Thing } from './Thing.js'\nimport { Environment, type IEnvironment } from './Environment.js'\nimport { ProjectFolderKind } from './kinds.js'\n\nexport const DefaultFolderName = 'New folder'\n\nexport interface IFolderAddOptions {\n /**\n * Optionally the position at which to add the request into the list of items.\n */\n index?: number\n}\n\nexport interface IFolderCloneOptions {\n /**\n * By default it clones the folder with all requests in it.\n * Set this to `true` to skip copying the requests along with the folder.\n */\n withoutRequests?: boolean\n /**\n * By default it clones the folder with all folders in it.\n * Set this to `true` to skip copying the folders along with the folder.\n */\n withoutFolders?: boolean\n /**\n * The target project where to put the copied folder.\n * When the target project is not the same as the source project then the folder\n * is put into the project root rather than the parent folder (as it would when cloning\n * a folder inside the same project).\n */\n targetProject?: HttpProject\n /**\n * The **key** of the target folder.\n *\n * By default it clones the folder to its parent unless the clone is attached to another project.\n * When the target folder is set then it places the clone under the passed target folder.\n */\n targetFolder?: string\n}\n\nexport interface IProjectFolder extends IProjectDefinitionProperty {\n kind: typeof ProjectFolderKind\n /**\n * The identifier of the folder.\n */\n key: string\n /**\n * Folder meta\n */\n info: IThing\n /**\n * The ordered list of HTTP requests / folders in the projects.\n * The UI uses this to manipulate the view without changing the definitions.\n */\n items: IProjectItem[]\n /**\n * Timestamp when the folder was last updated.\n */\n updated: number\n /**\n * Timestamp when the folder was created.\n */\n created: number\n}\n\n/**\n * Represents a folder, a group of requests or other folders, in a folder.\n */\nexport class ProjectFolder extends ProjectParent {\n /**\n * The default name of the folder.\n */\n static get defaultName(): string {\n return DefaultFolderName\n }\n\n override kind = ProjectFolderKind\n /**\n * A reference to the top level project object.\n */\n project: HttpProject\n /**\n * Timestamp when the folder was last updated.\n */\n updated = 0\n /**\n * Timestamp when the folder was created.\n */\n created = 0\n\n constructor(project: HttpProject, input?: string | IProjectFolder) {\n super()\n this.project = project\n let init: IProjectFolder\n if (typeof input === 'string') {\n init = JSON.parse(input)\n } else if (typeof input === 'object') {\n init = input\n } else {\n const now: number = Date.now()\n init = {\n kind: ProjectFolderKind,\n info: Thing.fromName(DefaultFolderName).toJSON(),\n created: now,\n updated: now,\n items: [],\n key: nanoid(),\n }\n }\n this.new(init)\n }\n\n /**\n * Creates a new project folder clearing anything that is so far defined.\n *\n * Note, this throws an error when the project folder is not a project folder.\n */\n new(init: IProjectFolder): void {\n if (!ProjectFolder.isProjectFolder(init)) {\n throw new Error(`Not a project folder.`)\n }\n const { key = nanoid(), created = Date.now(), updated = Date.now(), items, info } = init\n this.kind = ProjectFolderKind\n this.key = key\n this.created = created\n this.updated = updated\n if (Array.isArray(items)) {\n this.items = items.map((i) => new ProjectItem(this.project, i))\n } else {\n this.items = []\n }\n if (info) {\n this.info = new Thing(info)\n } else {\n this.info = Thing.fromName(DefaultFolderName)\n }\n }\n\n /**\n * Checks whether the input is a definition of a project folder.\n */\n static isProjectFolder(input: unknown): boolean {\n const typed = input as IProjectFolder\n if (!input || typed.kind !== ProjectFolderKind) {\n return false\n }\n return true\n }\n\n toJSON(): IProjectFolder {\n const result: IProjectFolder = {\n kind: ProjectFolderKind,\n info: this.info.toJSON(),\n key: this.key,\n created: this.created,\n updated: this.updated,\n items: [],\n }\n if (Array.isArray(this.items)) {\n result.items = this.items.map((i) => i.toJSON())\n }\n return result\n }\n\n /**\n * Creates a new ProjectFolder object from a name.\n * @param project The top-most project.\n * @param name The name to set.\n */\n static fromName(project: HttpProject, name = DefaultFolderName): ProjectFolder {\n const now = Date.now()\n const key = nanoid()\n const info = Thing.fromName(name)\n const definition = new ProjectFolder(project, {\n key,\n created: now,\n updated: now,\n items: [],\n kind: ProjectFolderKind,\n info: info.toJSON(),\n })\n return definition\n }\n\n /**\n * Appends an instance of a folder to a project.\n *\n * @param folder The folder to add to this project.\n * @returns The added folder.\n */\n addFolder(folder: ProjectFolder | IProjectFolder): ProjectFolder\n\n /**\n * Appends a new folder to the project or a sub-folder.\n *\n * @param name The name to set. Optional.\n * @returns The newly inserted folder. If the folder already existed it returns its instance.\n */\n addFolder(name?: string): ProjectFolder\n\n /**\n * Appends a new folder to the folder. It updates the project to add the request definition.\n * @param name The name to set. Optional.\n * @returns The key of newly inserted folder.\n */\n addFolder(name: string | IProjectFolder | ProjectFolder | undefined): ProjectFolder {\n return this.project.addFolder(name as ProjectFolder, { parent: this.key })\n }\n\n /**\n * Appends a new request to the folder. It updates the project to add the request definition.\n * @param request The request to append to the folder.\n * @returns The key of newly inserted request.\n */\n addRequest(request: IProjectRequest | ProjectRequest | string, opts: IFolderAddOptions = {}): ProjectRequest {\n const addOptions = { parent: this.key, ...opts }\n if (typeof request === 'string') {\n return this.project.addRequest(request, addOptions)\n }\n return this.project.addRequest(request, addOptions)\n }\n\n /**\n * Adds an environment to the project.\n * @param env The definition of the environment to use to create the environment or it's name\n * @returns The same or created environment.\n */\n addEnvironment(env: IEnvironment | Environment | string, opts: IEnvironmentCreateOptions = {}): Environment {\n const newOptions: IEnvironmentCreateOptions = { ...opts, parent: this.key }\n return this.project.addEnvironment(env, newOptions)\n }\n\n /**\n * Lists items (not the actual definitions!) that are folders.\n */\n listFolderItems(): ProjectItem[] {\n const { items = [] } = this\n return items.filter((i) => i.kind === ProjectFolderKind)\n }\n\n /**\n * Lists items (not the actual definitions!) that are requests.\n */\n listRequestItems(): ProjectItem[] {\n const { items = [] } = this\n return items.filter((i) => i.kind === ProjectRequestKind)\n }\n\n /**\n * Lists folders in this folder.\n */\n listFolders(): ProjectFolder[] {\n return this.project.listFolders({ folder: this.key })\n }\n\n /**\n * Lists requests in this folder.\n */\n listRequests(): ProjectRequest[] {\n return this.project.listRequests(this.key)\n }\n\n /**\n * The callback called when the object is attached to a parent.\n * This is called when the object is created and inserted to a project or a folder\n * and when the object is moved between folders.\n */\n attachedCallback(): void {\n // ...\n }\n\n /**\n * The callback called when the object is detached from its parent.\n * This callback is called when the item is deleted from a folder or a project,\n * or when the item is about to be moved to another folder.\n */\n detachedCallback(): void {\n // ...\n }\n\n /**\n * @returns The instance of the HttpProject or a ProjectFolder that is a closes parent of this instance.\n */\n getParent(): ProjectFolder | HttpProject | undefined {\n const { project, key } = this\n return project.findParent(key)\n }\n\n /**\n * @returns A reference to the parent folder or the top-level HTTP project.\n */\n getProject(): HttpProject {\n return this.project\n }\n\n /**\n * Removes this folder from the project.\n */\n remove(): void {\n this.project.removeFolder(this.key)\n }\n\n /**\n * @returns The list of environments defined in this folder\n */\n getEnvironments(): Environment[] {\n return this.project.getEnvironments({ parent: this.key })\n }\n\n /**\n * @param key The environment key to read.\n */\n getEnvironment(key: string): Environment | undefined {\n return this.project.getEnvironment(key, { parent: this.key })\n }\n\n /**\n * Removes an environment from the folder or a sub-folder.\n *\n * @param key the key of the environment to remove\n * @returns The removed environment, if any.\n */\n removeEnvironment(key: string): Environment | undefined {\n return this.project.removeEnvironment(key, { parent: this.key })\n }\n\n /**\n * This is a link to the `getEnvironments()`. The difference is that on the\n * project level it won't return environments defined with the class initialization.\n */\n listEnvironments(): Environment[] {\n return this.project.listEnvironments({ parent: this.key })\n }\n\n /**\n * Makes a copy of this folder.\n * By default it attaches the copied folder to the same parent.\n * It also, by default, copies requests declared in this folder.\n *\n * Use the options dictionary to control these behaviors.\n *\n * @param opts Cloning options\n */\n clone(opts: IFolderCloneOptions = {}): ProjectFolder {\n const { targetProject = this.project, targetFolder } = opts\n const copy = new ProjectFolder(targetProject, this.toJSON())\n copy.key = nanoid()\n\n const extProject = targetProject !== this.project\n if (extProject) {\n if (targetFolder) {\n const parent = targetProject.findFolder(targetFolder, { keyOnly: true })\n if (!parent) {\n throw new Error(`The target project does not contain the folder ${targetFolder}`)\n }\n parent.addFolder(copy)\n } else {\n targetProject.addFolder(copy)\n }\n } else {\n const parent = targetFolder ? this.project.findFolder(targetFolder, { keyOnly: true }) : this.getParent()\n if (parent) {\n parent.addFolder(copy)\n } else {\n throw new Error(`Unable to locate a parent of the folder.`)\n }\n }\n // removes all items. Depending on the passed option we re-add them next.\n copy.items = []\n\n if (!opts.withoutRequests) {\n this.cloneRequests(copy, this.project)\n }\n if (!opts.withoutFolders) {\n this.cloneSubFolders(copy, this.project, !opts.withoutRequests)\n }\n return copy\n }\n\n /**\n * Clones the current requests to the target folder.\n *\n * @param folder The target folder into which to put the requests. The folder has to have\n * the target project attached to it.\n * @param project The originating project where the definitions are stored\n */\n protected cloneRequests(folder: ProjectFolder, project: HttpProject): void {\n const requests = this.items.filter((i) => i.kind === ProjectRequestKind)\n requests.forEach((r) => {\n const request = project.findRequest(r.key, { keyOnly: true })\n if (!request) {\n // Should we throw an error here?\n // CONS:\n // - It's not really related to the operation. It means there is an inconsistency in the project.\n // That's the role of the project class.\n // - Ignoring this would allow us to make a copy that is error free.\n // - The error may occur in a situation when the user does not expect it (giving the nature of the error)\n // Pros:\n // - There's an inconsistency in the project definition that should be reported back to the UI\n // for the user to inspect\n return\n }\n const copy = request.clone({ withoutAttach: true })\n copy.project = folder.getProject()\n folder.addRequest(copy)\n })\n }\n\n /**\n * Clones the sub-folders to the target folder.\n *\n * @param folder The target folder into which to put the sub-folders. The folder has to have the target project\n * attached to it.\n * @param project The originating project where the definitions are stored\n * @param withRequests Whether to clone requests with the folder.\n */\n protected cloneSubFolders(folder: ProjectFolder, project: HttpProject, withRequests = true): void {\n const folders = this.items.filter((i) => i.kind === ProjectFolderKind)\n folders.forEach((f) => {\n const definition = project.findFolder(f.key, { keyOnly: true })\n if (!definition) {\n return\n }\n const copy = new ProjectFolder(folder.getProject(), definition.toJSON())\n copy.key = nanoid()\n copy.items = []\n folder.addFolder(copy)\n if (withRequests) {\n definition.cloneRequests(copy, project)\n }\n definition.cloneSubFolders(copy, project, withRequests)\n })\n }\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ProjectRequest.js","sourceRoot":"","sources":["../../../src/models/ProjectRequest.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAA;AAG/B,OAAO,EAAgB,IAAI,IAAI,eAAe,EAAE,MAAM,kBAAkB,CAAA;AAExE,OAAO,EAAY,OAAO,EAAE,MAAM,cAAc,CAAA;AAEhD,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAA;AAExC,OAAO,EAAE,WAAW,EAAE,MAAM,+BAA+B,CAAA;AAE3D,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAA;AAElC,MAAM,CAAC,MAAM,IAAI,GAAG,qBAAqB,CAAA;AA+CzC;;;;;;GAMG;AACH,MAAM,OAAO,cAAe,SAAQ,OAAO;IAChC,IAAI,GAAG,IAAI,CAAA;IAEpB;;OAEG;IACH,GAAG,GAAG,EAAE,CAAA;IAER;;OAEG;IACH,OAAO,CAAa;IAEpB;;;;OAIG;IACH,WAAW,CAAS;IAEpB;;OAEG;IACH,MAAM,CAAC,gBAAgB,CAAC,KAAc;QACpC,MAAM,KAAK,GAAG,KAAwB,CAAA;QACtC,IAAI,CAAC,KAAK,IAAI,KAAK,CAAC,IAAI,KAAK,IAAI,EAAE,CAAC;YAClC,OAAO,KAAK,CAAA;QACd,CAAC;QACD,OAAO,IAAI,CAAA;IACb,CAAC;IAED;;;;;;OAMG;IACH,MAAM,CAAU,OAAO,CAAC,GAAW,EAAE,OAAqB;QACxD,IAAI,CAAC,OAAO,EAAE,CAAC;YAC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,IAAI,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC,aAAa,CAAC,IAAI,OAAO,CAAC,aAAa,CAAC,MAAM,EAAE,CAAC;YACzE,OAAO,OAAO,CAAC,aAAa,CAAA;QAC9B,CAAC;QACD,OAAO,SAAS,CAAA;IAClB,CAAC;IAED;;OAEG;IACO,6BAA6B;QACrC,MAAM,IAAI,GAAG,IAAI,CAAC,gBAAgB,EAAE,CAAA;QACpC,MAAM,OAAO,GAAG,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,aAAa,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,aAAa,CAAC,MAAM,CAAC,CAAA;QAC5F,IAAI,OAAO,EAAE,CAAC;YACZ,OAAO,OAAO,CAAC,aAAuC,CAAA;QACxD,CAAC;QACD,OAAO,SAAS,CAAA;IAClB,CAAC;CACF","sourcesContent":["import { nanoid } from 'nanoid'\nimport { ProjectDefinitionProperty, IProjectDefinitionProperty } from './ProjectDefinitionProperty.js'\nimport { ProjectFolder } from './ProjectFolder.js'\nimport { IHttpRequest, Kind as HttpRequestKind } from './HttpRequest.js'\nimport { HttpProject } from './HttpProject.js'\nimport { IRequest, Request } from './Request.js'\nimport { Environment } from './Environment.js'\nimport { Property } from './Property.js'\nimport { Server } from './Server.js'\nimport { UriTemplate } from '../lib/parsers/UriTemplate.js'\nimport { RequestAuthorization } from './RequestAuthorization.js'\nimport { Thing } from './Thing.js'\n\nexport const Kind = 'Core#ProjectRequest'\n\nexport interface RequestUrlReadOptions {\n /**\n * When set it won't apply variables to the URL.\n */\n noVariables?: boolean\n /**\n * When set is returns the only the base URL defined in the environment without\n * adding the `url` defined on the request object. *\n */\n baseUrl?: boolean\n /**\n * When set it uses these variables instead one the onces defined on the project.\n * When this is defined then `noVariables` has no effect.\n */\n variables?: Record<string, string>\n}\n\nexport interface IProjectRequest extends IProjectDefinitionProperty, IRequest {\n kind: typeof Kind\n /**\n * The identifier of the request.\n */\n key: string\n /**\n * The key of an environment defined on the project to apply to this request.\n * When not set it inherits environments from parents.\n * However, when this is set, it makes sure that server/variables from this environment are always applied.\n */\n environment?: string\n}\n\nexport interface IRequestCloneOptions {\n /**\n * By default it revalidates (re-creates) keys in the request.\n * Set this to true to not make any changes to the keys.\n */\n withoutRevalidate?: boolean\n /**\n * By default it attaches the request to the same parent as the original request.\n * Set this to `true` when moving a request between projects to prevent adding the request to the project.\n * Note, the request still have a reference to the original project. You need to update the `project` property.\n */\n withoutAttach?: boolean\n}\n\n/**\n * **Note about the payload.**\n *\n * The payload is **always** stored in the request object in its serialized form.\n * Use the `readPayload()` to read the correct data type and the `writePayload()` to\n * safely store the payload.\n */\nexport class ProjectRequest extends Request implements ProjectDefinitionProperty {\n override kind = Kind\n\n /**\n * The identifier of the request.\n */\n key = ''\n\n /**\n * A reference to the top level project object.\n */\n project: HttpProject\n\n /**\n * The key of an environment defined on the project to apply to this request.\n * When not set it inherits environments from parents.\n * However, when this is set, it makes sure that server/variables from this environment are always applied.\n */\n environment?: string\n\n /**\n * Checks whether the input is a definition of a project folder.\n */\n static isProjectRequest(input: unknown): boolean {\n const typed = input as IProjectRequest\n if (!input || typed.kind !== Kind) {\n return false\n }\n return true\n }\n\n /**\n * Creates a project request from an URL.\n * This does not manipulate the project.\n *\n * @param url The Request URL. This is required.\n * @param project The parent project.\n */\n static override fromUrl(url: string, project?: HttpProject): ProjectRequest {\n if (!project) {\n throw new Error(`The project is required.`)\n }\n const now: number = Date.now()\n const request = new ProjectRequest(project, {\n key: nanoid(),\n kind: Kind,\n created: now,\n updated: now,\n expects: {\n kind: HttpRequestKind,\n method: 'GET',\n url,\n },\n info: Thing.fromName(url).toJSON(),\n })\n return request\n }\n\n /**\n * Creates a project request from a name.\n * This does not manipulate the project.\n *\n * @param name The Request name.\n * @param project The parent project.This is required.\n */\n static override fromName(name: string, project?: HttpProject): ProjectRequest {\n if (!project) {\n throw new Error(`The project is required.`)\n }\n const now: number = Date.now()\n const request = new ProjectRequest(project, {\n key: nanoid(),\n kind: Kind,\n created: now,\n updated: now,\n expects: {\n kind: HttpRequestKind,\n method: 'GET',\n url: '',\n },\n info: Thing.fromName(name).toJSON(),\n })\n return request\n }\n\n /**\n * Creates a project request from an HttpRequest definition.\n * This does not manipulate the project.\n *\n * @param project The parent project This is required.\n * @param info The request data.\n */\n static override fromHttpRequest(info: IHttpRequest, project?: HttpProject): ProjectRequest {\n if (!project) {\n throw new Error(`The project is required.`)\n }\n const now: number = Date.now()\n const request = new ProjectRequest(project, {\n key: nanoid(),\n kind: Kind,\n created: now,\n updated: now,\n expects: {\n kind: HttpRequestKind,\n method: info.method,\n url: info.url,\n headers: info.headers,\n payload: info.payload,\n },\n info: Thing.fromName(info.url).toJSON(),\n })\n return request\n }\n\n /**\n * Creates a project request for a schema of a Request.\n */\n static fromRequest(request: IRequest, project: HttpProject): ProjectRequest {\n const key = nanoid()\n const init: IProjectRequest = { ...request, key, kind: Kind }\n const result = new ProjectRequest(project, init)\n return result\n }\n\n constructor(project: HttpProject, input?: string | IProjectRequest) {\n super(input)\n this.project = project\n let init: IProjectRequest\n if (typeof input === 'string') {\n init = JSON.parse(input)\n } else if (typeof input === 'object') {\n init = input\n } else {\n const now: number = Date.now()\n init = {\n key: nanoid(),\n kind: Kind,\n created: now,\n updated: now,\n expects: {\n kind: HttpRequestKind,\n method: 'GET',\n url: '',\n },\n info: Thing.fromName('').toJSON(),\n }\n }\n this.new(init)\n }\n\n override new(init: IProjectRequest): void {\n super.new(init)\n\n const { key, environment } = init as IProjectRequest\n this.key = key || nanoid()\n if (environment) {\n this.environment = environment\n }\n }\n\n override toJSON(): IProjectRequest {\n const request = super.toJSON()\n const result: IProjectRequest = { ...request, key: this.key, kind: Kind }\n if (this.environment) {\n result.environment = this.environment\n }\n return result\n }\n\n /**\n * The callback called when the object is attached to a parent.\n * This is called when the object is created and inserted to a project or a folder\n * and when the object is moved between folders.\n */\n attachedCallback(): void {\n // ...\n }\n\n /**\n * The callback called when the object is detached from its parent.\n * This callback is called when the item is deleted from a folder or a project,\n * or when the item is about to be moved to another folder.\n */\n detachedCallback(): void {\n // ...\n }\n\n /**\n * @returns The instance of the HttpProject or a ProjectFolder that is a closes parent of this instance.\n */\n getParent(): ProjectFolder | HttpProject | undefined {\n const { project, key } = this\n return project.findParent(key)\n }\n\n /**\n * @returns A reference to the parent folder or the top-level HTTP project.\n */\n getProject(): HttpProject {\n return this.project\n }\n\n /**\n * Removes this request from the project.\n */\n remove(): void {\n this.project.removeRequest(this.key)\n }\n\n /**\n * Makes a copy of this request.\n * By default it attaches the copied request to the same parent.\n * Use the options dictionary to control this behavior.\n */\n clone(opts: IRequestCloneOptions = {}): ProjectRequest {\n const copy = new ProjectRequest(this.project, this.toJSON())\n if (!opts.withoutRevalidate) {\n copy.key = nanoid()\n }\n if (!opts.withoutAttach) {\n // if the parent is the project then add the request to the project.\n const parent = this.getParent()\n if (parent) {\n parent.addRequest(copy)\n }\n }\n return copy\n }\n\n /**\n * The static version of the `clone()` method.\n *\n * @param request The request schema to clone.\n * @param project The project to add the request to.\n * @param opts Optional options.\n * @returns The copied request.\n */\n static clone(request: IProjectRequest, project: HttpProject, opts: IRequestCloneOptions = {}): ProjectRequest {\n const obj = new ProjectRequest(project, request)\n return obj.clone(opts)\n }\n\n /**\n * @returns The environment that should be applied to the request, if any.\n */\n getEnvironment(): Environment | undefined {\n const { environment, project } = this\n if (!environment) {\n return undefined\n }\n let parent = this.getParent()\n if (parent === project) {\n parent = undefined\n }\n return project.findEnvironment(environment)\n }\n\n /**\n * @returns All environments that can be applied to this request.\n */\n readEnvironments(): Environment[] {\n let parent = this.getParent()\n if (parent === this.project) {\n parent = undefined\n }\n return this.project.readEnvironments({ parent: parent?.key })\n }\n\n /**\n * It reads the URL from an environment defined for the request..\n * The environment servers and variables are applies for all environments defined on each folder down to this request.\n * This respects the `encapsulate` flag defined on an environment.\n *\n * By default it applies variables collected from the environments to the url. You can configure this behavior\n * by passing a configuration option.\n *\n * Note on performance.\n * This is a heave computing operation so use it sparingly. For best performance only compute the URL when\n * environments, environment selection or variables change.\n *\n * @param opts Read URL options\n * @returns the read URL or undefined when the URL/environments are not defined.\n */\n readUrl(opts: RequestUrlReadOptions = {}): string | undefined {\n const { environment } = this\n const expects = this.getExpects()\n // note, this list respects the `encapsulate` flag.\n const environments = this.readEnvironments()\n\n let requestUrl = opts.baseUrl ? undefined : expects.url\n if (!environments) {\n if (requestUrl && opts.variables) {\n return this.evaluateUri(requestUrl, opts.variables)\n }\n return requestUrl || undefined\n }\n\n // we assume that absolute URL has a scheme with a delimiter (://). However, the scheme value can be an URL.\n // When the request starts with `/` is obviously a relative (no domain) URL\n // The edge case is `{` because it may mean a variable with a domain or a path to be appended to the base URI\n // defined in an environment. However, we choose to use `/` as the indicator of being a \"relative\" URL.\n const isAbsolute = !!requestUrl && !requestUrl.startsWith('/') && requestUrl.includes('://')\n if (isAbsolute && opts.noVariables) {\n // we know the URL exists, it is absolute (server wouldn't be applied anyway), and we don't\n // want to apply variables. We return what we have so far.\n return requestUrl\n }\n\n const flatProperties: Property[] = []\n let effectiveServer: Server | undefined\n for (const env of environments) {\n if (env.server && env.server.uri) {\n effectiveServer = env.server\n }\n if (!opts.noVariables && !opts.variables && env.variables) {\n for (const prop of env.variables) {\n // environments are listed from the project's root down to the folder where the request\n // exists. When a folder has a variable that was already defined it is replaced.\n this.addProperty(prop, flatProperties)\n }\n }\n if (env.key === environment) {\n break\n }\n }\n\n if (!requestUrl) {\n // we return whatever we have in the server.\n if (effectiveServer) {\n // flatProperties is be empty if `noVariables` option is passed.\n const uri = effectiveServer.readUri()\n if (opts.variables) {\n return this.evaluateUri(uri, opts.variables)\n }\n return this.evaluateUri(uri, flatProperties)\n }\n return undefined\n }\n\n if (isAbsolute) {\n // ignore server reading and just apply variables to the request URL\n if (opts.variables) {\n return this.evaluateUri(requestUrl, opts.variables)\n }\n return this.evaluateUri(requestUrl, flatProperties)\n }\n\n let serverUrl = ''\n if (effectiveServer) {\n serverUrl = effectiveServer.readUri()\n }\n if (!serverUrl.endsWith('/')) {\n serverUrl += '/'\n }\n if (requestUrl.startsWith('/')) {\n requestUrl = requestUrl.substring(1)\n }\n const url = serverUrl + requestUrl\n if (opts.variables) {\n return this.evaluateUri(url, opts.variables)\n }\n return this.evaluateUri(url, flatProperties)\n }\n\n protected addProperty(item: Property, list: Property[]): void {\n const index = list.findIndex((i) => i.name === item.name)\n if (index >= 0) {\n list.splice(index, 1)\n }\n list.push(item)\n }\n\n /**\n * Evaluates the URI against variables.\n *\n * Note, this doesn't throw errors. When error occurs it returns the input string.\n *\n * @param uri The URI to process\n * @param variables The list of variables to use\n * @returns Expanded URI.\n */\n protected evaluateUri(uri: string, variables?: Property[] | Record<string, string>): string {\n if (!variables) {\n return uri\n }\n\n let vars: Record<string, string> | undefined\n if (Array.isArray(variables)) {\n if (variables.length) {\n vars = Property.toMap(variables) as Record<string, string>\n }\n } else {\n vars = variables\n }\n if (!vars) {\n return uri\n }\n let result = uri\n try {\n result = new UriTemplate(uri).expand(vars, { ignoreMissing: true })\n } catch {\n //\n }\n return result\n }\n\n /**\n * Reads the authorization that should be applied to the request.\n *\n * 1) First it returns the locally (on the request) defined authorization.\n * 2) Then it returns authorization defined on the selected environment.\n * 3) If has defined environment but no authorization on it, then it returns empty array.\n * 4) Only if the request has no selected environment then it reads first environment\n * that has authorization (from the request up to the project's root).\n */\n readAuthorization(): RequestAuthorization[] {\n if (Array.isArray(this.authorization) && this.authorization.length) {\n return this.authorization\n }\n const envAuth = this.readEnvironmentAuthorization()\n if (envAuth) {\n return envAuth\n }\n if (this.environment) {\n return []\n }\n const inherited = this.readEnvironmentsAuthorization()\n if (inherited) {\n return inherited\n }\n return []\n }\n\n /**\n * @returns Authorization defined on the selected environment or undefined.\n */\n protected readEnvironmentAuthorization(): RequestAuthorization[] | undefined {\n const selfEnv = this.getEnvironment()\n if (!selfEnv) {\n return undefined\n }\n if (Array.isArray(selfEnv.authorization) && selfEnv.authorization.length) {\n return selfEnv.authorization\n }\n return undefined\n }\n\n /**\n * @returns Authorization defined on any inherited environment or undefined.\n */\n protected readEnvironmentsAuthorization(): RequestAuthorization[] | undefined {\n const envs = this.readEnvironments()\n const authEnv = envs.find((i) => Array.isArray(i.authorization) && !!i.authorization.length)\n if (authEnv) {\n return authEnv.authorization as RequestAuthorization[]\n }\n return undefined\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"ProjectRequest.js","sourceRoot":"","sources":["../../../src/models/ProjectRequest.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAA;AAGrC,OAAO,EAAgB,IAAI,IAAI,eAAe,EAAE,MAAM,kBAAkB,CAAA;AAExE,OAAO,EAAY,OAAO,EAAE,MAAM,cAAc,CAAA;AAEhD,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAA;AAExC,OAAO,EAAE,WAAW,EAAE,MAAM,+BAA+B,CAAA;AAE3D,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAA;AAElC,MAAM,CAAC,MAAM,IAAI,GAAG,qBAAqB,CAAA;AA+CzC;;;;;;GAMG;AACH,MAAM,OAAO,cAAe,SAAQ,OAAO;IAChC,IAAI,GAAG,IAAI,CAAA;IAEpB;;OAEG;IACH,GAAG,GAAG,EAAE,CAAA;IAER;;OAEG;IACH,OAAO,CAAa;IAEpB;;;;OAIG;IACH,WAAW,CAAS;IAEpB;;OAEG;IACH,MAAM,CAAC,gBAAgB,CAAC,KAAc;QACpC,MAAM,KAAK,GAAG,KAAwB,CAAA;QACtC,IAAI,CAAC,KAAK,IAAI,KAAK,CAAC,IAAI,KAAK,IAAI,EAAE,CAAC;YAClC,OAAO,KAAK,CAAA;QACd,CAAC;QACD,OAAO,IAAI,CAAA;IACb,CAAC;IAED;;;;;;OAMG;IACH,MAAM,CAAU,OAAO,CAAC,GAAW,EAAE,OAAqB;QACxD,IAAI,CAAC,OAAO,EAAE,C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AC;QACD,IAAI,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC,aAAa,CAAC,IAAI,OAAO,CAAC,aAAa,CAAC,MAAM,EAAE,CAAC;YACzE,OAAO,OAAO,CAAC,aAAa,CAAA;QAC9B,CAAC;QACD,OAAO,SAAS,CAAA;IAClB,CAAC;IAED;;OAEG;IACO,6BAA6B;QACrC,MAAM,IAAI,GAAG,IAAI,CAAC,gBAAgB,EAAE,CAAA;QACpC,MAAM,OAAO,GAAG,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,aAAa,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,aAAa,CAAC,MAAM,CAAC,CAAA;QAC5F,IAAI,OAAO,EAAE,CAAC;YACZ,OAAO,OAAO,CAAC,aAAuC,CAAA;QACxD,CAAC;QACD,OAAO,SAAS,CAAA;IAClB,CAAC;CACF","sourcesContent":["import { nanoid } from '../nanoid.js'\nimport { ProjectDefinitionProperty, IProjectDefinitionProperty } from './ProjectDefinitionProperty.js'\nimport { ProjectFolder } from './ProjectFolder.js'\nimport { IHttpRequest, Kind as HttpRequestKind } from './HttpRequest.js'\nimport { HttpProject } from './HttpProject.js'\nimport { IRequest, Request } from './Request.js'\nimport { Environment } from './Environment.js'\nimport { Property } from './Property.js'\nimport { Server } from './Server.js'\nimport { UriTemplate } from '../lib/parsers/UriTemplate.js'\nimport { RequestAuthorization } from './RequestAuthorization.js'\nimport { Thing } from './Thing.js'\n\nexport const Kind = 'Core#ProjectRequest'\n\nexport interface RequestUrlReadOptions {\n /**\n * When set it won't apply variables to the URL.\n */\n noVariables?: boolean\n /**\n * When set is returns the only the base URL defined in the environment without\n * adding the `url` defined on the request object. *\n */\n baseUrl?: boolean\n /**\n * When set it uses these variables instead one the onces defined on the project.\n * When this is defined then `noVariables` has no effect.\n */\n variables?: Record<string, string>\n}\n\nexport interface IProjectRequest extends IProjectDefinitionProperty, IRequest {\n kind: typeof Kind\n /**\n * The identifier of the request.\n */\n key: string\n /**\n * The key of an environment defined on the project to apply to this request.\n * When not set it inherits environments from parents.\n * However, when this is set, it makes sure that server/variables from this environment are always applied.\n */\n environment?: string\n}\n\nexport interface IRequestCloneOptions {\n /**\n * By default it revalidates (re-creates) keys in the request.\n * Set this to true to not make any changes to the keys.\n */\n withoutRevalidate?: boolean\n /**\n * By default it attaches the request to the same parent as the original request.\n * Set this to `true` when moving a request between projects to prevent adding the request to the project.\n * Note, the request still have a reference to the original project. You need to update the `project` property.\n */\n withoutAttach?: boolean\n}\n\n/**\n * **Note about the payload.**\n *\n * The payload is **always** stored in the request object in its serialized form.\n * Use the `readPayload()` to read the correct data type and the `writePayload()` to\n * safely store the payload.\n */\nexport class ProjectRequest extends Request implements ProjectDefinitionProperty {\n override kind = Kind\n\n /**\n * The identifier of the request.\n */\n key = ''\n\n /**\n * A reference to the top level project object.\n */\n project: HttpProject\n\n /**\n * The key of an environment defined on the project to apply to this request.\n * When not set it inherits environments from parents.\n * However, when this is set, it makes sure that server/variables from this environment are always applied.\n */\n environment?: string\n\n /**\n * Checks whether the input is a definition of a project folder.\n */\n static isProjectRequest(input: unknown): boolean {\n const typed = input as IProjectRequest\n if (!input || typed.kind !== Kind) {\n return false\n }\n return true\n }\n\n /**\n * Creates a project request from an URL.\n * This does not manipulate the project.\n *\n * @param url The Request URL. This is required.\n * @param project The parent project.\n */\n static override fromUrl(url: string, project?: HttpProject): ProjectRequest {\n if (!project) {\n throw new Error(`The project is required.`)\n }\n const now: number = Date.now()\n const request = new ProjectRequest(project, {\n key: nanoid(),\n kind: Kind,\n created: now,\n updated: now,\n expects: {\n kind: HttpRequestKind,\n method: 'GET',\n url,\n },\n info: Thing.fromName(url).toJSON(),\n })\n return request\n }\n\n /**\n * Creates a project request from a name.\n * This does not manipulate the project.\n *\n * @param name The Request name.\n * @param project The parent project.This is required.\n */\n static override fromName(name: string, project?: HttpProject): ProjectRequest {\n if (!project) {\n throw new Error(`The project is required.`)\n }\n const now: number = Date.now()\n const request = new ProjectRequest(project, {\n key: nanoid(),\n kind: Kind,\n created: now,\n updated: now,\n expects: {\n kind: HttpRequestKind,\n method: 'GET',\n url: '',\n },\n info: Thing.fromName(name).toJSON(),\n })\n return request\n }\n\n /**\n * Creates a project request from an HttpRequest definition.\n * This does not manipulate the project.\n *\n * @param project The parent project This is required.\n * @param info The request data.\n */\n static override fromHttpRequest(info: IHttpRequest, project?: HttpProject): ProjectRequest {\n if (!project) {\n throw new Error(`The project is required.`)\n }\n const now: number = Date.now()\n const request = new ProjectRequest(project, {\n key: nanoid(),\n kind: Kind,\n created: now,\n updated: now,\n expects: {\n kind: HttpRequestKind,\n method: info.method,\n url: info.url,\n headers: info.headers,\n payload: info.payload,\n },\n info: Thing.fromName(info.url).toJSON(),\n })\n return request\n }\n\n /**\n * Creates a project request for a schema of a Request.\n */\n static fromRequest(request: IRequest, project: HttpProject): ProjectRequest {\n const key = nanoid()\n const init: IProjectRequest = { ...request, key, kind: Kind }\n const result = new ProjectRequest(project, init)\n return result\n }\n\n constructor(project: HttpProject, input?: string | IProjectRequest) {\n super(input)\n this.project = project\n let init: IProjectRequest\n if (typeof input === 'string') {\n init = JSON.parse(input)\n } else if (typeof input === 'object') {\n init = input\n } else {\n const now: number = Date.now()\n init = {\n key: nanoid(),\n kind: Kind,\n created: now,\n updated: now,\n expects: {\n kind: HttpRequestKind,\n method: 'GET',\n url: '',\n },\n info: Thing.fromName('').toJSON(),\n }\n }\n this.new(init)\n }\n\n override new(init: IProjectRequest): void {\n super.new(init)\n\n const { key, environment } = init as IProjectRequest\n this.key = key || nanoid()\n if (environment) {\n this.environment = environment\n }\n }\n\n override toJSON(): IProjectRequest {\n const request = super.toJSON()\n const result: IProjectRequest = { ...request, key: this.key, kind: Kind }\n if (this.environment) {\n result.environment = this.environment\n }\n return result\n }\n\n /**\n * The callback called when the object is attached to a parent.\n * This is called when the object is created and inserted to a project or a folder\n * and when the object is moved between folders.\n */\n attachedCallback(): void {\n // ...\n }\n\n /**\n * The callback called when the object is detached from its parent.\n * This callback is called when the item is deleted from a folder or a project,\n * or when the item is about to be moved to another folder.\n */\n detachedCallback(): void {\n // ...\n }\n\n /**\n * @returns The instance of the HttpProject or a ProjectFolder that is a closes parent of this instance.\n */\n getParent(): ProjectFolder | HttpProject | undefined {\n const { project, key } = this\n return project.findParent(key)\n }\n\n /**\n * @returns A reference to the parent folder or the top-level HTTP project.\n */\n getProject(): HttpProject {\n return this.project\n }\n\n /**\n * Removes this request from the project.\n */\n remove(): void {\n this.project.removeRequest(this.key)\n }\n\n /**\n * Makes a copy of this request.\n * By default it attaches the copied request to the same parent.\n * Use the options dictionary to control this behavior.\n */\n clone(opts: IRequestCloneOptions = {}): ProjectRequest {\n const copy = new ProjectRequest(this.project, this.toJSON())\n if (!opts.withoutRevalidate) {\n copy.key = nanoid()\n }\n if (!opts.withoutAttach) {\n // if the parent is the project then add the request to the project.\n const parent = this.getParent()\n if (parent) {\n parent.addRequest(copy)\n }\n }\n return copy\n }\n\n /**\n * The static version of the `clone()` method.\n *\n * @param request The request schema to clone.\n * @param project The project to add the request to.\n * @param opts Optional options.\n * @returns The copied request.\n */\n static clone(request: IProjectRequest, project: HttpProject, opts: IRequestCloneOptions = {}): ProjectRequest {\n const obj = new ProjectRequest(project, request)\n return obj.clone(opts)\n }\n\n /**\n * @returns The environment that should be applied to the request, if any.\n */\n getEnvironment(): Environment | undefined {\n const { environment, project } = this\n if (!environment) {\n return undefined\n }\n let parent = this.getParent()\n if (parent === project) {\n parent = undefined\n }\n return project.findEnvironment(environment)\n }\n\n /**\n * @returns All environments that can be applied to this request.\n */\n readEnvironments(): Environment[] {\n let parent = this.getParent()\n if (parent === this.project) {\n parent = undefined\n }\n return this.project.readEnvironments({ parent: parent?.key })\n }\n\n /**\n * It reads the URL from an environment defined for the request..\n * The environment servers and variables are applies for all environments defined on each folder down to this request.\n * This respects the `encapsulate` flag defined on an environment.\n *\n * By default it applies variables collected from the environments to the url. You can configure this behavior\n * by passing a configuration option.\n *\n * Note on performance.\n * This is a heave computing operation so use it sparingly. For best performance only compute the URL when\n * environments, environment selection or variables change.\n *\n * @param opts Read URL options\n * @returns the read URL or undefined when the URL/environments are not defined.\n */\n readUrl(opts: RequestUrlReadOptions = {}): string | undefined {\n const { environment } = this\n const expects = this.getExpects()\n // note, this list respects the `encapsulate` flag.\n const environments = this.readEnvironments()\n\n let requestUrl = opts.baseUrl ? undefined : expects.url\n if (!environments) {\n if (requestUrl && opts.variables) {\n return this.evaluateUri(requestUrl, opts.variables)\n }\n return requestUrl || undefined\n }\n\n // we assume that absolute URL has a scheme with a delimiter (://). However, the scheme value can be an URL.\n // When the request starts with `/` is obviously a relative (no domain) URL\n // The edge case is `{` because it may mean a variable with a domain or a path to be appended to the base URI\n // defined in an environment. However, we choose to use `/` as the indicator of being a \"relative\" URL.\n const isAbsolute = !!requestUrl && !requestUrl.startsWith('/') && requestUrl.includes('://')\n if (isAbsolute && opts.noVariables) {\n // we know the URL exists, it is absolute (server wouldn't be applied anyway), and we don't\n // want to apply variables. We return what we have so far.\n return requestUrl\n }\n\n const flatProperties: Property[] = []\n let effectiveServer: Server | undefined\n for (const env of environments) {\n if (env.server && env.server.uri) {\n effectiveServer = env.server\n }\n if (!opts.noVariables && !opts.variables && env.variables) {\n for (const prop of env.variables) {\n // environments are listed from the project's root down to the folder where the request\n // exists. When a folder has a variable that was already defined it is replaced.\n this.addProperty(prop, flatProperties)\n }\n }\n if (env.key === environment) {\n break\n }\n }\n\n if (!requestUrl) {\n // we return whatever we have in the server.\n if (effectiveServer) {\n // flatProperties is be empty if `noVariables` option is passed.\n const uri = effectiveServer.readUri()\n if (opts.variables) {\n return this.evaluateUri(uri, opts.variables)\n }\n return this.evaluateUri(uri, flatProperties)\n }\n return undefined\n }\n\n if (isAbsolute) {\n // ignore server reading and just apply variables to the request URL\n if (opts.variables) {\n return this.evaluateUri(requestUrl, opts.variables)\n }\n return this.evaluateUri(requestUrl, flatProperties)\n }\n\n let serverUrl = ''\n if (effectiveServer) {\n serverUrl = effectiveServer.readUri()\n }\n if (!serverUrl.endsWith('/')) {\n serverUrl += '/'\n }\n if (requestUrl.startsWith('/')) {\n requestUrl = requestUrl.substring(1)\n }\n const url = serverUrl + requestUrl\n if (opts.variables) {\n return this.evaluateUri(url, opts.variables)\n }\n return this.evaluateUri(url, flatProperties)\n }\n\n protected addProperty(item: Property, list: Property[]): void {\n const index = list.findIndex((i) => i.name === item.name)\n if (index >= 0) {\n list.splice(index, 1)\n }\n list.push(item)\n }\n\n /**\n * Evaluates the URI against variables.\n *\n * Note, this doesn't throw errors. When error occurs it returns the input string.\n *\n * @param uri The URI to process\n * @param variables The list of variables to use\n * @returns Expanded URI.\n */\n protected evaluateUri(uri: string, variables?: Property[] | Record<string, string>): string {\n if (!variables) {\n return uri\n }\n\n let vars: Record<string, string> | undefined\n if (Array.isArray(variables)) {\n if (variables.length) {\n vars = Property.toMap(variables) as Record<string, string>\n }\n } else {\n vars = variables\n }\n if (!vars) {\n return uri\n }\n let result = uri\n try {\n result = new UriTemplate(uri).expand(vars, { ignoreMissing: true })\n } catch {\n //\n }\n return result\n }\n\n /**\n * Reads the authorization that should be applied to the request.\n *\n * 1) First it returns the locally (on the request) defined authorization.\n * 2) Then it returns authorization defined on the selected environment.\n * 3) If has defined environment but no authorization on it, then it returns empty array.\n * 4) Only if the request has no selected environment then it reads first environment\n * that has authorization (from the request up to the project's root).\n */\n readAuthorization(): RequestAuthorization[] {\n if (Array.isArray(this.authorization) && this.authorization.length) {\n return this.authorization\n }\n const envAuth = this.readEnvironmentAuthorization()\n if (envAuth) {\n return envAuth\n }\n if (this.environment) {\n return []\n }\n const inherited = this.readEnvironmentsAuthorization()\n if (inherited) {\n return inherited\n }\n return []\n }\n\n /**\n * @returns Authorization defined on the selected environment or undefined.\n */\n protected readEnvironmentAuthorization(): RequestAuthorization[] | undefined {\n const selfEnv = this.getEnvironment()\n if (!selfEnv) {\n return undefined\n }\n if (Array.isArray(selfEnv.authorization) && selfEnv.authorization.length) {\n return selfEnv.authorization\n }\n return undefined\n }\n\n /**\n * @returns Authorization defined on any inherited environment or undefined.\n */\n protected readEnvironmentsAuthorization(): RequestAuthorization[] | undefined {\n const envs = this.readEnvironments()\n const authEnv = envs.find((i) => Array.isArray(i.authorization) && !!i.authorization.length)\n if (authEnv) {\n return authEnv.authorization as RequestAuthorization[]\n }\n return undefined\n }\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ProjectSchema.js","sourceRoot":"","sources":["../../../src/models/ProjectSchema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"ProjectSchema.js","sourceRoot":"","sources":["../../../src/models/ProjectSchema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAA;AACrC,OAAO,EAAE,QAAQ,EAA2B,IAAI,IAAI,YAAY,EAAE,MAAM,eAAe,CAAA;AACvF,MAAM,CAAC,MAAM,IAAI,GAAG,oBAAoB,CAAA;AAgCxC;;;;;;;;GAQG;AACH,MAAM,OAAO,aAAa;IACxB,IAAI,GAAG,IAAI,CAAA;IACX;;OAEG;IACH,GAAG,GAAG,EAAE,CAAA;IACR;;;;;;OAMG;IACH,UAAU,CAAa;IACvB;;;OAGG;IACH,OAAO,CAAS;IAChB;;;OAGG;IACH,IAAI,CAAS;IACb;;OAEG;IACH,IAAI,GAAG,EAAE,CAAA;IAET;;;OAGG;IACH,MAAM,CAAC,QAAQ,CAAC,IAAY;QAC1B,MAAM,IAAI,GAAmB;YAC3B,IAAI,EAAE,IAAI;YACV,IAAI;YACJ,GAAG,EAAE,MAAM,EAAE;SACd,CAAA;QACD,OAAO,IAAI,aAAa,CAAC,IAAI,CAAC,CAAA;IAChC,CAAC;IAED;;;;;;OAMG;IACH,MAAM,CAAC,WAAW,CAAC,IAAY,EAAE,OAAe,EAAE,IAAY;QAC5D,MA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AE,IAAoB,CAAC,CAAA;QACjF,CAAC;aAAM,CAAC;YACN,MAAM,IAAI,GAAG,UAAuB,CAAA;YACpC,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC;gBACf,IAAI,CAAC,IAAI,GAAG,YAAY,CAAA;YAC1B,CAAC;YACD,QAAQ,GAAG,IAAI,QAAQ,CAAC,IAAI,CAAC,CAAA;QAC/B,CAAC;QACD,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,UAAU,CAAC,EAAE,CAAC;YACpC,IAAI,CAAC,UAAU,GAAG,EAAE,CAAA;QACtB,CAAC;QACD,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAA;QAC9B,OAAO,QAAQ,CAAA;IACjB,CAAC;CACF","sourcesContent":["import { nanoid } from '../nanoid.js'\nimport { Property, IProperty, PropertyType, Kind as PropertyKind } from './Property.js'\nexport const Kind = 'Core#ProjectSchema'\n\nexport interface IProjectSchema {\n kind?: typeof Kind\n /**\n * The identifier of the environment.\n */\n key: string\n /**\n * The name of the schema.\n */\n name: string\n /**\n * The optional list of properties in this schema.\n * Because this is a list instead of a map it is possible to duplicate the property name. In this\n * case the last set value is the final value.\n *\n * When both the `properties` and the `content` is defined, `content` is used instead of properties.\n */\n properties?: IProperty[]\n /**\n * The \"raw\" content of the schema.\n * This value goes unchanged to the request.\n */\n content?: string\n /**\n * When content is used, it informs about the content type of the\n * schema. The schema is invalid when `content` is set and the `mime` is not.\n */\n mime?: string\n}\n\n/**\n * A project can contain schema definitions that can be reused in project requests.\n * The schema consists of:\n *\n * - content: the \"raw\" schema value in any format. This goes unprocessed into the request body.\n * - properties: a map of properties description that can be manipulated at runtime\n *\n * Scalar values are not supported as a schema definition. It always represents an object.\n */\nexport class ProjectSchema {\n kind = Kind\n /**\n * The identifier of the environment.\n */\n key = ''\n /**\n * The optional list of properties in this schema.\n * Because this is a list instead of a map it is possible to duplicate the property name. In this\n * case the last set value is the final value.\n *\n * When both the `properties` and the `content` is defined, `content` is used instead of properties.\n */\n properties?: Property[]\n /**\n * The \"raw\" content of the schema.\n * This value goes unchanged to the request.\n */\n content?: string\n /**\n * When content is used, it informs about the content type of the\n * schema. The schema is invalid when `content` is set and the `mime` is not.\n */\n mime?: string\n /**\n * The name of the schema.\n */\n name = ''\n\n /**\n * Creates a new schema instance from the passed name.\n * @param name The name of the schema.\n */\n static fromName(name: string): ProjectSchema {\n const init: IProjectSchema = {\n kind: Kind,\n name,\n key: nanoid(),\n }\n return new ProjectSchema(init)\n }\n\n /**\n * Creates a new schema instance from the content definition\n * @param name The name of the schema.\n * @param content The \"raw\" content of the schema\n * @param mime The mime type associated with the schema.\n * @returns The instance of the created schema\n */\n static fromContent(name: string, content: string, mime: string): ProjectSchema {\n const init: IProjectSchema = {\n kind: Kind,\n name,\n key: nanoid(),\n content,\n mime,\n }\n return new ProjectSchema(init)\n }\n\n /**\n * @param input The schema definition used to restore the state.\n */\n constructor(input?: string | IProjectSchema) {\n let init: IProjectSchema\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 name: '',\n key: nanoid(),\n }\n }\n this.new(init)\n }\n\n /**\n * Creates a new schema definition clearing anything that is so far defined.\n */\n new(init: IProjectSchema): void {\n const { key = nanoid(), content, properties, mime, name = '' } = init\n this.name = name\n this.key = key\n if (content) {\n this.content = content\n } else {\n this.content = undefined\n }\n if (Array.isArray(properties)) {\n this.properties = properties.map((i) => new Property(i))\n } else {\n this.properties = undefined\n }\n if (mime) {\n this.mime = mime\n } else {\n this.mime = undefined\n }\n }\n\n toJSON(): IProjectSchema {\n const result: IProjectSchema = {\n kind: Kind,\n name: this.name || '',\n key: this.key || nanoid(),\n }\n if (this.content) {\n result.content = this.content\n }\n if (this.mime) {\n result.mime = this.mime\n }\n if (Array.isArray(this.properties) && this.properties.length) {\n result.properties = this.properties.map((i) => i.toJSON())\n }\n return result\n }\n\n /**\n * Creates a schema property from a definition.\n * @param info The property definition.\n * @returns The same property definition\n */\n addProperty(info: IProperty): Property\n\n /**\n * Creates a schema property from a definition.\n *\n * @param name The property name\n * @param type The property data type\n * @returns The created schema definition.\n */\n addProperty(name: string, type: PropertyType): Property\n\n addProperty(infoOrName: string | IProperty, type?: PropertyType): Property {\n const infoType = typeof infoOrName\n if (infoType === 'string' && !type) {\n throw new Error('The type is required.')\n }\n let instance: Property\n if (infoType === 'string') {\n instance = Property.fromTypeDefault(infoOrName as string, type as PropertyType)\n } else {\n const init = infoOrName as IProperty\n if (!init.kind) {\n init.kind = PropertyKind\n }\n instance = new Property(init)\n }\n if (!Array.isArray(this.properties)) {\n this.properties = []\n }\n this.properties.push(instance)\n return instance\n }\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DataFile.js","sourceRoot":"","sources":["../../../../src/models/store/DataFile.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"DataFile.js","sourceRoot":"","sources":["../../../../src/models/store/DataFile.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAA;AACxC,OAAO,EAAE,IAAI,EAAS,MAAM,WAAW,CAAA;AACvC,OAAO,EAAE,KAAK,EAAE,MAAM,aAAa,CAAA;AAEnC,OAAO,EAAE,YAAY,IAAI,IAAI,EAAE,MAAM,aAAa,CAAA;AAMlD;;;GAGG;AACH,MAAM,OAAO,QAAS,SAAQ,IAAI;IACvB,IAAI,GAAG,IAAI,CAAA;IAEpB;;;;;;OAMG;IACH,MAAM,CAAC,iBAAiB,CAAC,KAAqC,EAAE,YAAoB,EAAE,KAAc;QAClG,IAAI,KAAqB,CAAA;QACzB,IAAI,OAAQ,KAAuB,CAAC,MAAM,KAAK,UAAU,EAAE,CAAC;YAC1D,KAAK,GAAI,KAAuB,CAAC,MAAM,EAAE,CAAA;QAC3C,CAAC;aAAM,CAAC;YACN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E,IAAI,EAAE,KAAK,EAAE;aACjD,CAAA;QACH,CAAC;QACD,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,CAAA;IAChB,CAAC;IAEQ,GAAG,CAAC,IAAe;QAC1B,IAAI,CAAC,QAAQ,CAAC,UAAU,CAAC,IAAI,CAAC,EAAE,CAAC;YAC/B,MAAM,IAAI,KAAK,CAAC,kBAAkB,CAAC,CAAA;QACrC,CAAC;QACD,KAAK,CAAC,GAAG,CAAC,IAAI,CAAC,CAAA;QACf,IAAI,CAAC,IAAI,GAAG,IAAI,CAAA;QAChB,OAAO,IAAI,CAAA;IACb,CAAC;IAED,MAAM,CAAC,UAAU,CAAC,KAAc;QAC9B,MAAM,KAAK,GAAG,KAAkB,CAAA;QAChC,IAAI,CAAC,KAAK,IAAI,KAAK,CAAC,IAAI,KAAK,IAAI,EAAE,CAAC;YAClC,OAAO,KAAK,CAAA;QACd,CAAC;QACD,OAAO,IAAI,CAAA;IACb,CAAC;IAEQ,MAAM;QACb,MAAM,MAAM,GAAc;YACxB,GAAG,KAAK,CAAC,MAAM,EAAE;YACjB,IAAI,EAAE,IAAI;SACX,CAAA;QACD,OAAO,MAAM,CAAA;IACf,CAAC;CACF","sourcesContent":["import { nanoid } from '../../nanoid.js'\nimport { File, IFile } from './File.js'\nimport { Thing } from '../Thing.js'\nimport { DataNamespace, IDataNamespace } from '../../modeling/legacy/DataNamespace.js'\nimport { DataFileKind as Kind } from '../kinds.js'\n\nexport interface IDataFile extends IFile {\n kind: typeof Kind\n}\n\n/**\n * Used by the store. A file definition for the DataNamespace\n * @deprecated Use DomainFile instead.\n */\nexport class DataFile extends File {\n override kind = Kind\n\n /**\n * Creates the file definition for a DataNamespace contents.\n *\n * @param input The data namespace instance or schema.\n * @param owner Optional owner to set.\n * @deprecated Use DomainFile instead.\n */\n static fromDataNamespace(input: DataNamespace | IDataNamespace, organization: string, owner?: string): DataFile {\n let final: IDataNamespace\n if (typeof (input as DataNamespace).toJSON === 'function') {\n final = (input as DataNamespace).toJSON()\n } else {\n final = input as IDataNamespace\n }\n const init: IDataFile = {\n kind: Kind,\n key: final.key,\n organization,\n info: { ...final.info },\n lastModified: { user: owner || '', time: 0, byMe: false },\n owner,\n parents: [],\n permissionIds: [],\n permissions: [],\n }\n return new DataFile(init)\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 override fromName(name: string, organization: string, owner?: string): DataFile {\n return super.fromName(name, organization, owner, Kind) as DataFile\n }\n\n constructor(input?: string | IDataFile) {\n super()\n let init: IDataFile\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 organization: '',\n info: Thing.fromName('').toJSON(),\n parents: [],\n permissionIds: [],\n permissions: [],\n lastModified: { user: '', time: 0, byMe: false },\n }\n }\n this.new(init)\n }\n\n override new(init: IDataFile): this {\n if (!DataFile.isDataFile(init)) {\n throw new Error(`Not a data file.`)\n }\n super.new(init)\n this.kind = Kind\n return this\n }\n\n static isDataFile(input: unknown): boolean {\n const typed = input as IDataFile\n if (!input || typed.kind !== Kind) {\n return false\n }\n return true\n }\n\n override toJSON(): IDataFile {\n const result: IDataFile = {\n ...super.toJSON(),\n kind: Kind,\n }\n return result\n }\n}\n"]}
|
|
@@ -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,MAA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R,CAAC;QACD,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAA;IACzB,CAAC;IAED;;;;;;OAMG;IACH,UAAU,CAAC,IAAW;QACpB,IAAI,CAAC,IAAI,EAAE,CAAC;YACV,MAAM,IAAI,KAAK,CAAC,uBAAuB,CAAC,CAAA;QAC1C,CAAC;QACD,IAAI,IAAI,CAAC,IAAI,KAAK,QAAQ,EAAE,CAAC;YAC3B,MAAM,IAAI,KAAK,CAAC,wDAAwD,CAAC,CAAA;QAC3E,CAAC;QACD,IAAI,CAAC,aAAa,CAAC,GAAG,IAAI,CAAA;QAC1B,IAAI,CAAC,iBAAiB,CAAC,GAAG;YACxB,IAAI,EAAE,KAAK;YACX,IAAI,EAAE,IAAI,CAAC,GAAG,EAAE;YAChB,IAAI,EAAE,IAAI,CAAC,GAAG;YACd,IAAI,EAAE,IAAI,CAAC,IAAI;SAChB,CAAA;IACH,CAAC;IAED,MAAM;QACJ,OAAO,IAAI,CAAC,IAAI,KAAK,UAAU,CAAA;IACjC,CAAC;IAED,QAAQ;QACN,OAAO,IAAI,CAAC,IAAI,KAAK,UAAU,CAAA;IACjC,CAAC;CACF","sourcesContent":["import { nanoid } from 'nanoid'\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;AAwIxC,MAAM,aAAa,GAAG,MAAM,CAAC,SAAS,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,CAAC;YAChC,OAAM;QACR,CAAC;QACD,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAA;IACzB,CAAC;IAED;;;;;;OAMG;IACH,UAAU,CAAC,IAAW;QACpB,IAAI,CAAC,IAAI,EAAE,CAAC;YACV,MAAM,IAAI,KAAK,CAAC,uBAAuB,CAAC,CAAA;QAC1C,CAAC;QACD,IAAI,IAAI,CAAC,IAAI,KAAK,QAAQ,EAAE,CAAC;YAC3B,MAAM,IAAI,KAAK,CAAC,wDAAwD,CAAC,CAAA;QAC3E,CAAC;QACD,IAAI,CAAC,aAAa,CAAC,GAAG,IAAI,CAAA;QAC1B,IAAI,CAAC,iBAAiB,CAAC,GAAG;YACxB,IAAI,EAAE,KAAK;YACX,IAAI,EAAE,IAAI,CAAC,GAAG,EAAE;YAChB,IAAI,EAAE,IAAI,CAAC,GAAG;YACd,IAAI,EAAE,IAAI,CAAC,IAAI;SAChB,CAAA;IACH,CAAC;IAED,MAAM;QACJ,OAAO,IAAI,CAAC,IAAI,KAAK,UAAU,CAAA;IACjC,CAAC;IAED,QAAQ;QACN,OAAO,IAAI,CAAC,IAAI,KAAK,UAAU,CAAA;IACjC,CAAC;CACF","sourcesContent":["import { nanoid } from '../../nanoid.js'\nimport { IPermission, Permission, PermissionRole } from './Permission.js'\nimport { IModification } from './Modification.js'\nimport { IDeletion } from './Deletion.js'\nimport { IUser, Kind as UserKind } from './User.js'\nimport { IThing, Thing } from '../Thing.js'\nimport { ICapabilities } from './Capabilities.js'\nimport { FolderKind } from '../kinds.js'\n// this causes error\n// import { Kind as FolderKind } from '../Folder.js';\n\nexport interface FileAddOptions {\n /**\n * The parent folder where to put the file.\n * The `parents` array is always cleared from the file object before adding it to the store.\n */\n parent?: string\n}\n\nexport interface MediaReadOptions {\n /**\n * When set it reads the file that was marked as `_deleted`. By default it throws when file was deleted.\n */\n deleted?: boolean\n}\n\n/**\n * A breadcrumb when creating the breadcrumb list for a file.\n */\nexport interface FileBreadcrumb {\n /**\n * The datastore key of the object.\n */\n key: string\n /**\n * THe kind of the object.\n */\n kind: string\n /**\n * The name of the object.\n */\n name: string\n}\n\nexport interface IStoredFile {\n /**\n * The kind of the File\n */\n kind: string\n /**\n * The identifier of the entity\n */\n key: string\n /**\n * The 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 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Invitation.js","sourceRoot":"","sources":["../../../../src/models/store/Invitation.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAA;AAC/B,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,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AAI,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,IAAI,CAAC,QAAQ,GAAG,IAAI,OAAO,CAAC,IAAI,CAAC,MAAM,EAAE,CAAC,CAAA;QAC5C,CAAC;QACD,OAAO,IAAI,CAAC,QAAQ,CAAA;IACtB,CAAC;IAED;;;;;OAKG;IACH,MAAM,CAAC,YAAY,CAAC,QAAmC,EAAE;QACvD,MAAM,EACJ,GAAG,GAAG,MAAM,EAAE,EACd,KAAK,EACL,GAAG,EACH,SAAS,EACT,GAA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AAI,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"]}
|