26 lines
746 B
TypeScript
26 lines
746 B
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;};
|
|
}
|
|
|