UNPKG

diffusion

Version:

Diffusion JavaScript client

286 lines (285 loc) 9.49 kB
"use strict"; /** * @module TopicUpdate */ var __extends = (this && this.__extends) || (function () { var extendStatics = function (d, b) { extendStatics = Object.setPrototypeOf || ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; return extendStatics(d, b); }; return function (d, b) { if (typeof b !== "function" && b !== null) throw new TypeError("Class extends value " + String(b) + " is not a constructor or null"); extendStatics(d, b); function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; })(); Object.defineProperty(exports, "__esModule", { value: true }); exports.Locked = exports.Disjunction = exports.Conjunction = exports.NoValueConstraint = exports.TopicConstraint = exports.CompoundConstraint = exports.Unconstrained = exports.UpdateConstraintImpl = exports.ConstraintValueType = exports.ConstraintType = void 0; var errors_1 = require("./../../errors/errors"); /** * Enum mapping the different constraint types to their protocol code */ var ConstraintType; (function (ConstraintType) { ConstraintType[ConstraintType["UNCONSTRAINED"] = 0] = "UNCONSTRAINED"; ConstraintType[ConstraintType["CONJUNCTION"] = 1] = "CONJUNCTION"; ConstraintType[ConstraintType["TOPIC_VALUE"] = 2] = "TOPIC_VALUE"; ConstraintType[ConstraintType["NO_VALUE"] = 3] = "NO_VALUE"; ConstraintType[ConstraintType["LOCKED"] = 4] = "LOCKED"; ConstraintType[ConstraintType["NO_TOPIC"] = 5] = "NO_TOPIC"; ConstraintType[ConstraintType["PARTIAL_JSON"] = 6] = "PARTIAL_JSON"; ConstraintType[ConstraintType["DISJUNCTION"] = 7] = "DISJUNCTION"; })(ConstraintType = exports.ConstraintType || (exports.ConstraintType = {})); /** * Represents the type of value specified in a constraint. * * All but null map directly by name to DataTypes. * * @since 6.10 */ var ConstraintValueType; (function (ConstraintValueType) { /** * Indicates a null value. */ ConstraintValueType[ConstraintValueType["NULL"] = 0] = "NULL"; /** * See {@link DataTypes.string}. */ ConstraintValueType[ConstraintValueType["STRING"] = 1] = "STRING"; /** * See {@link DataTypes.int64}. */ ConstraintValueType[ConstraintValueType["INT64"] = 2] = "INT64"; /** * See {@link DataTypes.double}. */ ConstraintValueType[ConstraintValueType["DOUBLE"] = 3] = "DOUBLE"; /** * See {@link DataTypes.binary}. */ ConstraintValueType[ConstraintValueType["BINARY"] = 4] = "BINARY"; /** * See {@link DataTypes.json}. */ ConstraintValueType[ConstraintValueType["JSON"] = 5] = "JSON"; /** * See {@link DataTypes.recordv2}. */ ConstraintValueType[ConstraintValueType["RECORD_V2"] = 6] = "RECORD_V2"; /** * Indicates a boolean value. */ ConstraintValueType[ConstraintValueType["BOOLEAN"] = 7] = "BOOLEAN"; })(ConstraintValueType = exports.ConstraintValueType || (exports.ConstraintValueType = {})); /** * Base implementation of {@link UpdateConstraint} that implements only * the {@link UpdateConstraint.and and} method but no other functionality */ var UpdateConstraintImpl = /** @class */ (function () { /** * Constructor */ function UpdateConstraintImpl(id) { this.id = id; } /** * @inheritdoc */ UpdateConstraintImpl.prototype.and = function (other) { if (this === other) { throw new errors_1.IllegalArgumentError("Cannot 'and' a constraint with itself"); } if (this.andBlockedFor(other)) { throw new errors_1.IllegalArgumentError('Constraint could not be satisfied'); } /* tslint:disable-next-line:no-use-before-declare */ return new Conjunction(this, other); }; UpdateConstraintImpl.prototype.or = function (other) { if (this === other) { throw new errors_1.IllegalArgumentError("Cannot 'or' a constraint with itself"); } /* tslint:disable-next-line:no-use-before-declare */ return new Disjunction(this, other); }; /** * Get the constraint type * * @return `'UNCONSTRAINED'` */ UpdateConstraintImpl.prototype.getConstraintType = function () { return this.id; }; /** * Indicates whether anding with the specified constraint is disallowed. */ UpdateConstraintImpl.prototype.andBlockedFor = function (other) { return false; }; return UpdateConstraintImpl; }()); exports.UpdateConstraintImpl = UpdateConstraintImpl; /** * Unconstrained update constraint */ var Unconstrained = /** @class */ (function (_super) { __extends(Unconstrained, _super); /** * Constructor */ function Unconstrained() { return _super.call(this, ConstraintType.UNCONSTRAINED) || this; } return Unconstrained; }(UpdateConstraintImpl)); exports.Unconstrained = Unconstrained; /** * Base class for compound constraints. * * @since 6.10 */ var CompoundConstraint = /** @class */ (function (_super) { __extends(CompoundConstraint, _super); /** * Constructor. */ function CompoundConstraint(id, left, right) { var _this = _super.call(this, id) || this; _this.left = left; _this.right = right; return _this; } return CompoundConstraint; }(UpdateConstraintImpl)); exports.CompoundConstraint = CompoundConstraint; /** * Represents a constraint on the topic. * * @since 6.10 */ var TopicConstraint = /** @class */ (function (_super) { __extends(TopicConstraint, _super); /** * Constructor */ function TopicConstraint(id) { return _super.call(this, id) || this; } return TopicConstraint; }(UpdateConstraintImpl)); exports.TopicConstraint = TopicConstraint; /** * A general no-value or no-topic constraint. */ var NoValueConstraint = /** @class */ (function (_super) { __extends(NoValueConstraint, _super); /** * Constructor */ function NoValueConstraint(id) { return _super.call(this, id) || this; } /** * @inheritdoc */ NoValueConstraint.prototype.andBlockedFor = function (other) { return other instanceof TopicConstraint || other instanceof CompoundConstraint && other.andBlockedFor(this); }; return NoValueConstraint; }(TopicConstraint)); exports.NoValueConstraint = NoValueConstraint; /** * A conjunction update constraint that is fulfilled only when all of its * member constraints are fulfilled */ var Conjunction = /** @class */ (function (_super) { __extends(Conjunction, _super); /** * Create a new Conjunction instance * * @param constraints the member constraints which are ANDed together */ function Conjunction(left, right) { return _super.call(this, ConstraintType.CONJUNCTION, left, right) || this; } /** * @inheritdoc */ Conjunction.prototype.andBlockedFor = function (other) { return (other instanceof TopicConstraint || other instanceof Conjunction && other.hasNoValueConstraint()) && this.hasNoValueConstraint(); }; /** * Indicates whether the conjunction has no value constraint operands or * descendant conjunctions which have no value constraint operands. */ Conjunction.prototype.hasNoValueConstraint = function () { if (this.left instanceof NoValueConstraint || this.right instanceof NoValueConstraint) { return true; } return this.left instanceof Conjunction && this.left.hasNoValueConstraint() || this.right instanceof Conjunction && this.right.hasNoValueConstraint(); }; return Conjunction; }(CompoundConstraint)); exports.Conjunction = Conjunction; /** * A conjunction update constraint that is fulfilled when any one of its * member constraints are fulfilled */ var Disjunction = /** @class */ (function (_super) { __extends(Disjunction, _super); /** * Create a new Conjunction instance * * @param constraints the member constraints which are ANDed together */ function Disjunction(left, right) { return _super.call(this, ConstraintType.DISJUNCTION, left, right) || this; } return Disjunction; }(CompoundConstraint)); exports.Disjunction = Disjunction; /** * A constraint requiring a lock to be held by the session. */ var Locked = /** @class */ (function (_super) { __extends(Locked, _super); /** * Create a new Locked instance * * @param lock the lock that need to be held */ function Locked(lock) { var _this = _super.call(this, ConstraintType.LOCKED) || this; _this.lock = lock; _this.lockName = lock.getName(); _this.sequence = lock.getSequence(); return _this; } /** * Get the lock name * * @return the lock name */ Locked.prototype.getLockName = function () { return this.lockName; }; /** * Get the lock sequence number * * @return the lock sequence number */ Locked.prototype.getSequence = function () { return this.sequence; }; return Locked; }(UpdateConstraintImpl)); exports.Locked = Locked;