UNPKG

@eclipse-ditto/ditto-javascript-client-node

Version:

Node.js(r) implementation of Eclipse Ditto JavaScript API.

253 lines 6.5 kB
"use strict"; /*! * 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 */ Object.defineProperty(exports, "__esModule", { value: true }); exports.Resource = exports.AccessRight = exports.Subject = exports.SubjectId = exports.DittoSubjectIssuer = exports.Resources = exports.Subjects = exports.Entry = exports.Entries = exports.Policy = void 0; const model_1 = require("./model"); /** * Representation of a Policy */ class Policy extends model_1.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; } // @ts-ignore return new Policy(id, Entries.fromObject(o['entries'])); } toObject() { const entriesObj = Entries.toObject(this.entries); return model_1.EntityModel.buildObject(new Map([ ['entries', entriesObj] ])); } get id() { return this._id; } get entries() { return this._entries; } } exports.Policy = Policy; /** * Representation of Entries */ class Entries extends model_1.IndexedEntityModel { /** * Parses Entries. * * @param o - The object to parse. * @returns The Entries */ static fromObject(o) { if (o === undefined) { return o; } return model_1.IndexedEntityModel.fromPlainObject(o, Entry.fromObject); } } exports.Entries = Entries; /** * Representation of an Entry */ class Entry extends model_1.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; } // @ts-ignore 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 model_1.EntityModel.buildObject(new Map([ ['subjects', subjectsObj], ['resources', resourcesObj] ])); } get id() { return this._id; } get subjects() { return this._subjects; } get resources() { return this._resources; } } exports.Entry = Entry; /** * Representation of Subjects */ class Subjects extends model_1.IndexedEntityModel { /** * Parses Subjects. * * @param o - The object to parse. * @returns The Subjects */ static fromObject(o) { if (o === undefined) { return o; } return model_1.IndexedEntityModel.fromPlainObject(o, Subject.fromObject, key => key); } } exports.Subjects = Subjects; /** * Representation of Resources */ class Resources extends model_1.IndexedEntityModel { /** * Parses Resources. * * @param o - The object to parse. * @returns The Resources */ static fromObject(o) { if (o === undefined) { return o; } return model_1.IndexedEntityModel.fromPlainObject(o, Resource.fromObject); } } exports.Resources = Resources; var DittoSubjectIssuer; (function (DittoSubjectIssuer) { DittoSubjectIssuer["GOOGLE"] = "google"; DittoSubjectIssuer["NGINX"] = "nginx"; })(DittoSubjectIssuer = exports.DittoSubjectIssuer || (exports.DittoSubjectIssuer = {})); 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; } } exports.SubjectId = SubjectId; /** * Representation of a Subject */ class Subject extends model_1.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; } // @ts-ignore return new Subject(SubjectId.fromString(id), o['type']); } toObject() { return model_1.EntityModel.buildObject(new Map([ ['type', this.type] ])); } get id() { return this._id.toString(); } get type() { return this._type; } } exports.Subject = Subject; var AccessRight; (function (AccessRight) { AccessRight["Read"] = "READ"; AccessRight["Write"] = "WRITE"; })(AccessRight = exports.AccessRight || (exports.AccessRight = {})); /** * Representation of a Resource */ class Resource extends model_1.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; } // @ts-ignore return new Resource(id, o['grant'], o['revoke']); } toObject() { return model_1.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; } } exports.Resource = Resource; //# sourceMappingURL=policies.model.js.map