UNPKG

@k8ts/instruments

Version:

A collection of utilities and core components for k8ts.

115 lines 4.1 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.FutureExports = void 0; const doddle_1 = require("doddle"); const error_1 = require("../error"); const reference_1 = require("../reference"); var FutureExports; (function (FutureExports) { function make(props) { const handler = new Handler(props); return new Proxy(props.actual, handler); } FutureExports.make = make; class Handler { _props; constructor(_props) { this._props = _props; } #createImmutableError(action) { return new error_1.ProxyOperationError(`Tried to ${action} an the exports constructs of ${this._props.origin}, but it is immutable.`); } defineProperty(_, property, __) { throw this.#createImmutableError(`define property ${String(property)} on`); } deleteProperty(_, property) { throw this.#createImmutableError(`delete property ${String(property)} from`); } getPrototypeOf(_) { return Reflect.getPrototypeOf(this._target); } get seq() { return (0, doddle_1.seq)(this._props.exports); } #isValidReferant(prop) { return this._props.origin.resourceKinds.tryParse(prop) != null; } get _target() { return this._props.actual; } get(target, property) { const key = property; if (Reflect.has(this._target, key)) { const x = Reflect.get(this._target, property); if (typeof x === "function") { return x.bind(this._target); } return x; } const refKey = this._props.origin.resourceKinds.tryParse(key); if (refKey == null) { return undefined; } const cls = this._props.origin.resourceKinds.getClass(refKey); return reference_1.ForwardRef.make({ class: cls, key: refKey, origin: this._props.origin, namespace: this._props.origin.meta.tryGet("namespace"), resolver: this.seq .as() .first(exp => exp.node.key.equals(refKey)) .map(x => { if (x == null) { throw new error_1.ProxyOperationError(`Failed to resolve forward reference to ${refKey} in ${this._props.origin}.`); } return x; }) }); } has(_, p) { if (Reflect.has(this._target, p)) { return true; } if (!this.#isValidReferant(p)) { return false; } return true; } isExtensible(target) { return false; } preventExtensions(target) { return true; } ownKeys(target) { throw new error_1.ProxyOperationError(`Cannot list all keys of a dynamic exports construct for ${this._props.origin}.`); } set(target, p, newValue, receiver) { throw this.#createImmutableError(`set property ${String(p)} on`); } setPrototypeOf(target, v) { throw this.#createImmutableError(`set prototype of`); } _tryTargetDescriptor(p) { return Object.getOwnPropertyDescriptor(this._target, p); } getOwnPropertyDescriptor(target, p) { const desc = this._tryTargetDescriptor(p); if (desc) { return desc; } const value = this.get(this._target, p); if (value == null) { return undefined; } return { configurable: false, enumerable: true, value, writable: false }; } } })(FutureExports || (exports.FutureExports = FutureExports = {})); //# sourceMappingURL=delayed-exports.js.map