46 lines
1.4 KiB
TypeScript
46 lines
1.4 KiB
TypeScript
import * as _ from "@preserves/core";
|
|
|
|
export const $Instance = Symbol.for("Instance");
|
|
|
|
export const Instance = _.Record.makeConstructor<{"_field0": string, "_field1": _val}, _ptr>()($Instance, ["_field0","_field1"]);
|
|
|
|
export type Instance = _.Record<(typeof $Instance), [string, _val], _ptr>;
|
|
|
|
export type _ptr = never;
|
|
|
|
export type _val = _.Value<_ptr>;
|
|
|
|
|
|
export function isInstance(v: any): v is Instance {
|
|
return (
|
|
_.Record.isRecord<_val, _.Tuple<_val>, _ptr>(v) &&
|
|
_.is(v.label, $Instance) &&
|
|
((v.length === 2) && typeof v[0] === 'string' && true)
|
|
);
|
|
}
|
|
|
|
export function asInstance(v: any): Instance {
|
|
if (!isInstance(v)) {throw new TypeError(`Invalid Instance: ${_.stringify(v)}`);} else {return v;};
|
|
}
|
|
|
|
export function decodeInstance(d: _.TypedDecoder<_ptr>): Instance | undefined {
|
|
let result;
|
|
if (d.openRecord()) {
|
|
let _tmp0: any;
|
|
_tmp0 = _.asLiteral(d.nextSymbol(), $Instance);
|
|
if (_tmp0 !== void 0) {
|
|
let _tmp1, _tmp2, _tmp3: any;
|
|
_tmp2 = d.nextString();
|
|
if (_tmp2 !== void 0) {
|
|
_tmp3 = d.next();
|
|
if (_tmp3 !== void 0) {if (d.closeCompound()) _tmp1 = [_tmp2, _tmp3];};
|
|
};
|
|
if (_tmp1 !== void 0) result = _.Record<(typeof $Instance), [string, _val]>(_tmp0 as any, _tmp1 as any);
|
|
};
|
|
};
|
|
return result;
|
|
}
|
|
|
|
export const _decodePtr = () => { throw new _.DecodeError("Pointers forbidden"); };
|
|
|