novy-syndicate/src/gen/dataspace.ts

47 lines
1.7 KiB
TypeScript
Raw Normal View History

2021-03-11 17:00:45 +00:00
import * as _ from "@preserves/core";
import * as _i_Actor from "../actor";
2021-03-11 17:00:45 +00:00
export const $Observe = Symbol.for("Observe");
export const Observe = _.Record.makeConstructor<{"label": symbol, "observer": _ptr}, _ptr>()($Observe, ["label","observer"]);
2021-03-11 17:00:45 +00:00
export type Observe = _.Record<(typeof $Observe), [symbol, _ptr], _ptr>;
export type _ptr = _i_Actor.Ref;
2021-03-11 17:00:45 +00:00
export type _val = _.Value<_ptr>;
export function isObserve(v: any): v is Observe {
return (
_.Record.isRecord<_val, _.Tuple<_val>, _ptr>(v) &&
_.is(v.label, $Observe) &&
((v.length === 2) && typeof v[0] === 'symbol' && _.isPointer(v[1]))
);
}
export function asObserve(v: any): Observe {
if (!isObserve(v)) {throw new TypeError(`Invalid Observe: ${_.stringify(v)}`);} else {return v;};
}
2021-03-12 19:49:18 +00:00
export function decodeObserve(d: _.TypedDecoder<_ptr>): Observe | undefined {
return ((() => {
const M = d.mark();
if (!d.openRecord()) return void 0;
const L = _.checkIs(d.nextSymbol(), $Observe);
if (L === void 0) { d.restoreMark(M); return void 0; };
const Fs = (((() => {
const M = d.mark();
const v0 = d.nextSymbol(); if (v0 === void 0) { d.restoreMark(M); return void 0; };
const v1 = _decodePtr(d); if (v1 === void 0) { d.restoreMark(M); return void 0; };
if (!d.closeCompound()) { d.restoreMark(M); return void 0; };
return [v0, v1] as [symbol, _ptr];
})())) as any;
if (Fs === void 0) { d.restoreMark(M); return void 0; };
return _.Record<(typeof $Observe), [symbol, _ptr]>(L, Fs);
})());
}
export const _decodePtr = (d: _.TypedDecoder<_ptr>) => _i_Actor.decodeRef(d);