UNPKG

@eclipse-ditto/ditto-javascript-client-dom

Version:

DOM implementation of Eclipse Ditto JavaScript API to be used in browsers.

238 lines 5.83 kB
/*! * Copyright (c) 2019 Contributors to the Eclipse Foundation * * See the NOTICE file(s) distributed with this work for additional * information regarding copyright ownership. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License 2.0 which is available at * http://www.eclipse.org/legal/epl-2.0 * * SPDX-License-Identifier: EPL-2.0 */ import { EntityModel, EntityWithId, IndexedEntityModel } from './model'; /** * Representation of a Policy */ export class Policy extends EntityWithId { constructor(_id, _entries) { super(); this._id = _id; this._entries = _entries; } /** * Parses a Policy. * * @param o - The object to parse. * @param id - The id of the new Policy. * @returns The Policy */ static fromObject(o, id) { if (o === undefined) { return o; } return new Policy(id, Entries.fromObject(o['entries'])); } toObject() { const entriesObj = Entries.toObject(this.entries); return EntityModel.buildObject(new Map([ ['entries', entriesObj] ])); } get id() { return this._id; } get entries() { return this._entries; } } /** * Representation of Entries */ export class Entries extends IndexedEntityModel { /** * Parses Entries. * * @param o - The object to parse. * @returns The Entries */ static fromObject(o) { if (o === undefined) { return o; } return IndexedEntityModel.fromPlainObject(o, Entry.fromObject); } } /** * Representation of an Entry */ export class Entry extends EntityWithId { constructor(_id, _subjects, _resources) { super(); this._id = _id; this._subjects = _subjects; this._resources = _resources; } /** * Parses an Entry. * * @param o - The object to parse. * @param label - The label of the new Entry. * @returns The Entry */ static fromObject(o, label) { if (o === undefined) { return o; } return new Entry(label, Subjects.fromObject(o['subjects']), Resources.fromObject(o['resources'])); } toObject() { const subjectsObj = Subjects.toObject(this.subjects); const resourcesObj = Resources.toObject(this.resources); return EntityModel.buildObject(new Map([ ['subjects', subjectsObj], ['resources', resourcesObj] ])); } get id() { return this._id; } get subjects() { return this._subjects; } get resources() { return this._resources; } } /** * Representation of Subjects */ export class Subjects extends IndexedEntityModel { /** * Parses Subjects. * * @param o - The object to parse. * @returns The Subjects */ static fromObject(o) { if (o === undefined) { return o; } return IndexedEntityModel.fromPlainObject(o, Subject.fromObject, key => key); } } /** * Representation of Resources */ export class Resources extends IndexedEntityModel { /** * Parses Resources. * * @param o - The object to parse. * @returns The Resources */ static fromObject(o) { if (o === undefined) { return o; } return IndexedEntityModel.fromPlainObject(o, Resource.fromObject); } } export var DittoSubjectIssuer; (function (DittoSubjectIssuer) { DittoSubjectIssuer["GOOGLE"] = "google"; DittoSubjectIssuer["NGINX"] = "nginx"; })(DittoSubjectIssuer || (DittoSubjectIssuer = {})); export class SubjectId { constructor(_id) { this._id = _id; } static fromIssuerAndId(issuer, subjectId) { return new SubjectId(`${issuer}:${subjectId}`); } static fromString(subjectId) { return new SubjectId(subjectId); } toString() { return this._id; } } /** * Representation of a Subject */ export class Subject extends EntityWithId { constructor(_id, _type) { super(); this._id = _id; this._type = _type; } /** * Parses a Subject. * * @param o - The object to parse. * @param id - The id of the new Subject. * @returns The Subject */ static fromObject(o, id) { if (o === undefined) { return o; } return new Subject(SubjectId.fromString(id), o['type']); } toObject() { return EntityModel.buildObject(new Map([ ['type', this.type] ])); } get id() { return this._id.toString(); } get type() { return this._type; } } export var AccessRight; (function (AccessRight) { AccessRight["Read"] = "READ"; AccessRight["Write"] = "WRITE"; })(AccessRight || (AccessRight = {})); /** * Representation of a Resource */ export class Resource extends EntityWithId { constructor(_id, _grant, _revoke) { super(); this._id = _id; this._grant = _grant; this._revoke = _revoke; } /** * Parses a Resource. * * @param o - The object to parse. * @param id - The id of the new Resource. * @returns The Resource */ static fromObject(o, id) { if (o === undefined) { return o; } return new Resource(id, o['grant'], o['revoke']); } toObject() { return EntityModel.buildObject(new Map([ ['revoke', this.revoke], ['grant', this.grant] ])); } get id() { return this._id; } get grant() { return this._grant; } get revoke() { return this._revoke; } } //# sourceMappingURL=policies.model.js.map