preserves/implementations/javascript/packages/schema/src/gen/schema.ts

676 lines
27 KiB
TypeScript
Raw Normal View History

2021-03-10 22:15:53 +00:00
import * as _ from "@preserves/core";
export const $1 = 1;
export const $Boolean = Symbol.for("Boolean");
export const $ByteString = Symbol.for("ByteString");
export const $Double = Symbol.for("Double");
export const $Float = Symbol.for("Float");
export const $SignedInteger = Symbol.for("SignedInteger");
export const $String = Symbol.for("String");
export const $Symbol = Symbol.for("Symbol");
export const $and = Symbol.for("and");
export const $atom = Symbol.for("atom");
export const $definitions = Symbol.for("definitions");
export const $dict = Symbol.for("dict");
export const $dictof = Symbol.for("dictof");
export const $lit = Symbol.for("lit");
export const $named = Symbol.for("named");
export const $or = Symbol.for("or");
export const $pointer = Symbol.for("pointer");
export const $rec = Symbol.for("rec");
export const $ref = Symbol.for("ref");
export const $schema = Symbol.for("schema");
export const $setof = Symbol.for("setof");
2021-03-11 09:56:49 +00:00
export const $thisModule = Symbol.for("thisModule");
2021-03-10 22:15:53 +00:00
export const $tuple = Symbol.for("tuple");
export const $tuple_STAR_ = Symbol.for("tuple*");
export const $version = Symbol.for("version");
2021-03-11 16:59:40 +00:00
export const __lit5 = false;
2021-03-10 22:15:53 +00:00
export const Schema = _.Record.makeConstructor<{
"details": (
{
get(k: typeof $version): Version;
2021-03-11 16:59:40 +00:00
get(k: typeof $pointer): PointerName;
2021-03-12 10:14:39 +00:00
get(k: typeof $definitions): _.KeyedDictionary<symbol, Pattern, _ptr>;
2021-03-10 22:15:53 +00:00
has(k: typeof $version): true;
2021-03-11 16:59:40 +00:00
has(k: typeof $pointer): true;
2021-03-10 22:15:53 +00:00
has(k: typeof $definitions): true;
2021-03-11 16:59:40 +00:00
} & _.Dictionary<_val, _ptr>
2021-03-10 22:15:53 +00:00
)
2021-03-11 16:59:40 +00:00
}, _ptr>()($schema, ["details"]);
2021-03-10 22:15:53 +00:00
export type Schema = _.Record<
(typeof $schema),
[
(
{
get(k: typeof $version): Version;
2021-03-11 16:59:40 +00:00
get(k: typeof $pointer): PointerName;
2021-03-12 10:14:39 +00:00
get(k: typeof $definitions): _.KeyedDictionary<symbol, Pattern, _ptr>;
2021-03-10 22:15:53 +00:00
has(k: typeof $version): true;
2021-03-11 16:59:40 +00:00
has(k: typeof $pointer): true;
2021-03-10 22:15:53 +00:00
has(k: typeof $definitions): true;
2021-03-11 16:59:40 +00:00
} & _.Dictionary<_val, _ptr>
2021-03-10 22:15:53 +00:00
)
2021-03-11 16:59:40 +00:00
],
_ptr
2021-03-10 22:15:53 +00:00
>;
export type Version = (typeof $1);
2021-03-11 16:59:40 +00:00
export type PointerName = (Ref | (typeof __lit5));
2021-03-10 22:15:53 +00:00
export type Pattern = (
_.Record<
(typeof $atom),
[
(
(typeof $Boolean) |
(typeof $Float) |
(typeof $Double) |
(typeof $SignedInteger) |
(typeof $String) |
(typeof $ByteString) |
(typeof $Symbol)
)
2021-03-11 16:59:40 +00:00
],
_ptr
2021-03-10 22:15:53 +00:00
> |
2021-03-11 16:59:40 +00:00
_.Record<(typeof $pointer), [], _ptr> |
_.Record<(typeof $lit), [_val], _ptr> |
2021-03-11 09:56:49 +00:00
Ref |
2021-03-11 16:59:40 +00:00
_.Record<(typeof $or), [Array<Pattern>], _ptr> |
_.Record<(typeof $and), [Array<Pattern>], _ptr> |
_.Record<(typeof $rec), [Pattern, Pattern], _ptr> |
_.Record<(typeof $tuple), [Array<NamedPattern>], _ptr> |
_.Record<(typeof $tuple_STAR_), [Array<NamedPattern>, NamedPattern], _ptr> |
_.Record<(typeof $setof), [Pattern], _ptr> |
_.Record<(typeof $dictof), [Pattern, Pattern], _ptr> |
2021-03-12 10:14:39 +00:00
_.Record<(typeof $dict), [_.KeyedDictionary<_val, Pattern, _ptr>], _ptr>
2021-03-10 22:15:53 +00:00
);
2021-03-11 16:59:40 +00:00
export type NamedPattern = (_.Record<(typeof $named), [symbol, Pattern], _ptr> | Pattern);
2021-03-10 22:15:53 +00:00
2021-03-11 16:59:40 +00:00
export const Ref = _.Record.makeConstructor<{"module": ModuleRef, "name": symbol}, _ptr>()($ref, ["module","name"]);
2021-03-11 09:56:49 +00:00
2021-03-11 16:59:40 +00:00
export type Ref = _.Record<(typeof $ref), [ModuleRef, symbol], _ptr>;
2021-03-11 09:56:49 +00:00
export type ModuleRef = ((typeof $thisModule) | ModulePath);
export type ModulePath = Array<symbol>;
2021-03-12 10:14:39 +00:00
export type _ptr = never;
export type _val = _.Value<_ptr>;
2021-03-11 09:56:49 +00:00
2021-03-10 22:15:53 +00:00
export function isSchema(v: any): v is Schema {
2021-03-11 16:59:40 +00:00
let _tmp0, _tmp1, _tmp2: any;
2021-03-10 22:15:53 +00:00
return (
2021-03-11 16:59:40 +00:00
_.Record.isRecord<_val, _.Tuple<_val>, _ptr>(v) &&
2021-03-11 13:43:58 +00:00
_.is(v.label, $schema) &&
2021-03-10 22:15:53 +00:00
(
(v.length === 1) &&
(
2021-03-11 16:59:40 +00:00
_.Dictionary.isDictionary<_val, _ptr>(v[0]) &&
2021-03-10 22:15:53 +00:00
((_tmp0 = v[0].get($version)) !== void 0 && isVersion(_tmp0)) &&
2021-03-11 16:59:40 +00:00
((_tmp1 = v[0].get($pointer)) !== void 0 && isPointerName(_tmp1)) &&
2021-03-10 22:15:53 +00:00
(
2021-03-11 16:59:40 +00:00
(_tmp2 = v[0].get($definitions)) !== void 0 && (
_.Dictionary.isDictionary<_val, _ptr>(_tmp2) &&
2021-03-10 22:15:53 +00:00
((() => {
2021-03-11 16:59:40 +00:00
for (const e of _tmp2) {
2021-03-10 22:15:53 +00:00
if (!(typeof e[0] === 'symbol')) return false;
if (!(isPattern(e[1]))) return false;
};
return true;
})())
)
)
)
)
);
}
2021-03-11 16:59:40 +00:00
export function asSchema(v: any): Schema {
if (!isSchema(v)) {throw new TypeError(`Invalid Schema: ${_.stringify(v)}`);} else {return v;};
}
2021-03-11 08:25:17 +00:00
export function decodeSchema(d: _.TypedDecoder<_ptr>): Schema | undefined {
let _tmp0, _tmp1, _tmp2: any;
return ((() => {
const M = d.mark();
if (!d.openRecord()) return void 0;
const L = _.checkIs(d.nextSymbol(), $schema);
if (L === void 0) { d.restoreMark(M); return void 0; };
const Fs = (((() => {
const M = d.mark();
const v0 = ((() => {
const M = d.mark();
const r = d.next();
if (!((
_.Dictionary.isDictionary<_val, _ptr>(r) &&
((_tmp0 = r.get($version)) !== void 0 && isVersion(_tmp0)) &&
((_tmp1 = r.get($pointer)) !== void 0 && isPointerName(_tmp1)) &&
(
(_tmp2 = r.get($definitions)) !== void 0 && (
_.Dictionary.isDictionary<_val, _ptr>(_tmp2) &&
((() => {
for (const e of _tmp2) {
if (!(typeof e[0] === 'symbol')) return false;
if (!(isPattern(e[1]))) return false;
};
return true;
})())
)
)
))) { d.restoreMark(M); return void 0; };
return r;
})()); if (v0 === void 0) { d.restoreMark(M); return void 0; };
if (!d.closeCompound()) { d.restoreMark(M); return void 0; };
return [v0] as [
(
{
get(k: typeof $version): Version;
get(k: typeof $pointer): PointerName;
get(k: typeof $definitions): _.KeyedDictionary<symbol, Pattern, _ptr>;
has(k: typeof $version): true;
has(k: typeof $pointer): true;
has(k: typeof $definitions): true;
} & _.Dictionary<_val, _ptr>
)
];
})())) as any;
if (Fs === void 0) { d.restoreMark(M); return void 0; };
return _.Record<
(typeof $schema),
[
(
{
get(k: typeof $version): Version;
get(k: typeof $pointer): PointerName;
get(k: typeof $definitions): _.KeyedDictionary<symbol, Pattern, _ptr>;
has(k: typeof $version): true;
has(k: typeof $pointer): true;
has(k: typeof $definitions): true;
} & _.Dictionary<_val, _ptr>
)
]
>(L, Fs);
})());
}
2021-03-11 13:43:58 +00:00
export function isVersion(v: any): v is Version {return _.is(v, $1);}
2021-03-10 22:15:53 +00:00
2021-03-11 16:59:40 +00:00
export function asVersion(v: any): Version {
if (!isVersion(v)) {throw new TypeError(`Invalid Version: ${_.stringify(v)}`);} else {return v;};
}
export function decodeVersion(d: _.TypedDecoder<_ptr>): Version | undefined {return _.checkIs(d.nextSignedInteger(), $1);}
2021-03-11 16:59:40 +00:00
export function isPointerName(v: any): v is PointerName {return (isRef(v) || _.is(v, __lit5));}
export function asPointerName(v: any): PointerName {
if (!isPointerName(v)) {throw new TypeError(`Invalid PointerName: ${_.stringify(v)}`);} else {return v;};
}
2021-03-11 08:25:17 +00:00
export function decodePointerName(d: _.TypedDecoder<_ptr>): PointerName | undefined {return (decodeRef(d) ?? _.checkIs(d.nextBoolean(), __lit5));}
2021-03-10 22:15:53 +00:00
export function isPattern(v: any): v is Pattern {
return (
(
2021-03-11 16:59:40 +00:00
_.Record.isRecord<_val, _.Tuple<_val>, _ptr>(v) &&
2021-03-11 13:43:58 +00:00
_.is(v.label, $atom) &&
2021-03-10 22:15:53 +00:00
(
(v.length === 1) &&
(
2021-03-11 13:43:58 +00:00
_.is(v[0], $Boolean) ||
_.is(v[0], $Float) ||
_.is(v[0], $Double) ||
_.is(v[0], $SignedInteger) ||
_.is(v[0], $String) ||
_.is(v[0], $ByteString) ||
_.is(v[0], $Symbol)
2021-03-10 22:15:53 +00:00
)
)
) ||
2021-03-11 16:59:40 +00:00
(
_.Record.isRecord<_val, _.Tuple<_val>, _ptr>(v) &&
_.is(v.label, $pointer) &&
((v.length === 0))
) ||
(
_.Record.isRecord<_val, _.Tuple<_val>, _ptr>(v) &&
_.is(v.label, $lit) &&
((v.length === 1) && true)
) ||
2021-03-11 09:56:49 +00:00
isRef(v) ||
2021-03-10 22:15:53 +00:00
(
2021-03-11 16:59:40 +00:00
_.Record.isRecord<_val, _.Tuple<_val>, _ptr>(v) &&
2021-03-11 13:43:58 +00:00
_.is(v.label, $or) &&
2021-03-10 22:15:53 +00:00
(
(v.length === 1) &&
(
_.Array.isArray(v[0]) &&
2021-03-11 16:59:40 +00:00
!_.Record.isRecord<_val, _.Tuple<_val>, _ptr>(v[0]) &&
2021-03-10 22:15:53 +00:00
(v[0].length >= 0) &&
v[0].slice(0).every(v => (isPattern(v)))
)
)
) ||
(
2021-03-11 16:59:40 +00:00
_.Record.isRecord<_val, _.Tuple<_val>, _ptr>(v) &&
2021-03-11 13:43:58 +00:00
_.is(v.label, $and) &&
2021-03-10 22:15:53 +00:00
(
(v.length === 1) &&
(
_.Array.isArray(v[0]) &&
2021-03-11 16:59:40 +00:00
!_.Record.isRecord<_val, _.Tuple<_val>, _ptr>(v[0]) &&
2021-03-10 22:15:53 +00:00
(v[0].length >= 0) &&
v[0].slice(0).every(v => (isPattern(v)))
)
)
) ||
(
2021-03-11 16:59:40 +00:00
_.Record.isRecord<_val, _.Tuple<_val>, _ptr>(v) &&
2021-03-11 13:43:58 +00:00
_.is(v.label, $rec) &&
2021-03-10 22:15:53 +00:00
((v.length === 2) && isPattern(v[0]) && isPattern(v[1]))
) ||
(
2021-03-11 16:59:40 +00:00
_.Record.isRecord<_val, _.Tuple<_val>, _ptr>(v) &&
2021-03-11 13:43:58 +00:00
_.is(v.label, $tuple) &&
2021-03-10 22:15:53 +00:00
(
(v.length === 1) &&
(
_.Array.isArray(v[0]) &&
2021-03-11 16:59:40 +00:00
!_.Record.isRecord<_val, _.Tuple<_val>, _ptr>(v[0]) &&
2021-03-10 22:15:53 +00:00
(v[0].length >= 0) &&
v[0].slice(0).every(v => (isNamedPattern(v)))
)
)
) ||
(
2021-03-11 16:59:40 +00:00
_.Record.isRecord<_val, _.Tuple<_val>, _ptr>(v) &&
2021-03-11 13:43:58 +00:00
_.is(v.label, $tuple_STAR_) &&
2021-03-10 22:15:53 +00:00
(
(v.length === 2) &&
(
_.Array.isArray(v[0]) &&
2021-03-11 16:59:40 +00:00
!_.Record.isRecord<_val, _.Tuple<_val>, _ptr>(v[0]) &&
2021-03-10 22:15:53 +00:00
(v[0].length >= 0) &&
v[0].slice(0).every(v => (isNamedPattern(v)))
) &&
isNamedPattern(v[1])
)
) ||
(
2021-03-11 16:59:40 +00:00
_.Record.isRecord<_val, _.Tuple<_val>, _ptr>(v) &&
2021-03-11 13:43:58 +00:00
_.is(v.label, $setof) &&
2021-03-10 22:15:53 +00:00
((v.length === 1) && isPattern(v[0]))
) ||
(
2021-03-11 16:59:40 +00:00
_.Record.isRecord<_val, _.Tuple<_val>, _ptr>(v) &&
2021-03-11 13:43:58 +00:00
_.is(v.label, $dictof) &&
2021-03-10 22:15:53 +00:00
((v.length === 2) && isPattern(v[0]) && isPattern(v[1]))
) ||
(
2021-03-11 16:59:40 +00:00
_.Record.isRecord<_val, _.Tuple<_val>, _ptr>(v) &&
2021-03-11 13:43:58 +00:00
_.is(v.label, $dict) &&
2021-03-10 22:15:53 +00:00
(
(v.length === 1) &&
(
2021-03-11 16:59:40 +00:00
_.Dictionary.isDictionary<_val, _ptr>(v[0]) &&
2021-03-10 22:15:53 +00:00
((() => {
for (const e of v[0]) {if (!(true)) return false; if (!(isPattern(e[1]))) return false;};
return true;
})())
)
)
)
);
}
2021-03-11 16:59:40 +00:00
export function asPattern(v: any): Pattern {
if (!isPattern(v)) {throw new TypeError(`Invalid Pattern: ${_.stringify(v)}`);} else {return v;};
}
2021-03-11 08:25:17 +00:00
export function decodePattern(d: _.TypedDecoder<_ptr>): Pattern | undefined {
return (
((() => {
const M = d.mark();
if (!d.openRecord()) return void 0;
const L = _.checkIs(d.nextSymbol(), $atom);
if (L === void 0) { d.restoreMark(M); return void 0; };
const Fs = (((() => {
const M = d.mark();
const v0 = (
_.checkIs(d.nextSymbol(), $Boolean) ??
_.checkIs(d.nextSymbol(), $Float) ??
_.checkIs(d.nextSymbol(), $Double) ??
_.checkIs(d.nextSymbol(), $SignedInteger) ??
_.checkIs(d.nextSymbol(), $String) ??
_.checkIs(d.nextSymbol(), $ByteString) ??
_.checkIs(d.nextSymbol(), $Symbol)
); if (v0 === void 0) { d.restoreMark(M); return void 0; };
if (!d.closeCompound()) { d.restoreMark(M); return void 0; };
return [v0] as [
(
(typeof $Boolean) |
(typeof $Float) |
(typeof $Double) |
(typeof $SignedInteger) |
(typeof $String) |
(typeof $ByteString) |
(typeof $Symbol)
)
];
})())) as any;
if (Fs === void 0) { d.restoreMark(M); return void 0; };
return _.Record<
(typeof $atom),
[
(
(typeof $Boolean) |
(typeof $Float) |
(typeof $Double) |
(typeof $SignedInteger) |
(typeof $String) |
(typeof $ByteString) |
(typeof $Symbol)
)
]
>(L, Fs);
})()) ??
((() => {
const M = d.mark();
if (!d.openRecord()) return void 0;
const L = _.checkIs(d.nextSymbol(), $pointer);
if (L === void 0) { d.restoreMark(M); return void 0; };
const Fs = (((() => {
const M = d.mark();
if (!d.closeCompound()) { d.restoreMark(M); return void 0; };
return [] as [];
})())) as any;
if (Fs === void 0) { d.restoreMark(M); return void 0; };
return _.Record<(typeof $pointer), []>(L, Fs);
})()) ??
((() => {
const M = d.mark();
if (!d.openRecord()) return void 0;
const L = _.checkIs(d.nextSymbol(), $lit);
if (L === void 0) { d.restoreMark(M); return void 0; };
const Fs = (((() => {
const M = d.mark();
const v0 = d.next(); if (v0 === void 0) { d.restoreMark(M); return void 0; };
if (!d.closeCompound()) { d.restoreMark(M); return void 0; };
return [v0] as [_val];
})())) as any;
if (Fs === void 0) { d.restoreMark(M); return void 0; };
return _.Record<(typeof $lit), [_val]>(L, Fs);
})()) ??
decodeRef(d) ??
((() => {
const M = d.mark();
if (!d.openRecord()) return void 0;
const L = _.checkIs(d.nextSymbol(), $or);
if (L === void 0) { d.restoreMark(M); return void 0; };
const Fs = (((() => {
const M = d.mark();
const v0 = ((() => {
const M = d.mark();
if (!d.openSequence()) return void 0;
const vN: Array<Pattern> = [];
let tmp: undefined | Pattern;
while ((tmp = decodePattern(d)) !== void 0) vN.push(tmp);
if (!d.closeCompound()) { d.restoreMark(M); return void 0; };
return vN;
})()); if (v0 === void 0) { d.restoreMark(M); return void 0; };
if (!d.closeCompound()) { d.restoreMark(M); return void 0; };
return [v0] as [Array<Pattern>];
})())) as any;
if (Fs === void 0) { d.restoreMark(M); return void 0; };
return _.Record<(typeof $or), [Array<Pattern>]>(L, Fs);
})()) ??
((() => {
const M = d.mark();
if (!d.openRecord()) return void 0;
const L = _.checkIs(d.nextSymbol(), $and);
if (L === void 0) { d.restoreMark(M); return void 0; };
const Fs = (((() => {
const M = d.mark();
const v0 = ((() => {
const M = d.mark();
if (!d.openSequence()) return void 0;
const vN: Array<Pattern> = [];
let tmp: undefined | Pattern;
while ((tmp = decodePattern(d)) !== void 0) vN.push(tmp);
if (!d.closeCompound()) { d.restoreMark(M); return void 0; };
return vN;
})()); if (v0 === void 0) { d.restoreMark(M); return void 0; };
if (!d.closeCompound()) { d.restoreMark(M); return void 0; };
return [v0] as [Array<Pattern>];
})())) as any;
if (Fs === void 0) { d.restoreMark(M); return void 0; };
return _.Record<(typeof $and), [Array<Pattern>]>(L, Fs);
})()) ??
((() => {
const M = d.mark();
if (!d.openRecord()) return void 0;
const L = _.checkIs(d.nextSymbol(), $rec);
if (L === void 0) { d.restoreMark(M); return void 0; };
const Fs = (((() => {
const M = d.mark();
const v0 = decodePattern(d); if (v0 === void 0) { d.restoreMark(M); return void 0; };
const v1 = decodePattern(d); if (v1 === void 0) { d.restoreMark(M); return void 0; };
if (!d.closeCompound()) { d.restoreMark(M); return void 0; };
return [v0, v1] as [Pattern, Pattern];
})())) as any;
if (Fs === void 0) { d.restoreMark(M); return void 0; };
return _.Record<(typeof $rec), [Pattern, Pattern]>(L, Fs);
})()) ??
((() => {
const M = d.mark();
if (!d.openRecord()) return void 0;
const L = _.checkIs(d.nextSymbol(), $tuple);
if (L === void 0) { d.restoreMark(M); return void 0; };
const Fs = (((() => {
const M = d.mark();
const v0 = ((() => {
const M = d.mark();
if (!d.openSequence()) return void 0;
const vN: Array<NamedPattern> = [];
let tmp: undefined | NamedPattern;
while ((tmp = decodeNamedPattern(d)) !== void 0) vN.push(tmp);
if (!d.closeCompound()) { d.restoreMark(M); return void 0; };
return vN;
})()); if (v0 === void 0) { d.restoreMark(M); return void 0; };
if (!d.closeCompound()) { d.restoreMark(M); return void 0; };
return [v0] as [Array<NamedPattern>];
})())) as any;
if (Fs === void 0) { d.restoreMark(M); return void 0; };
return _.Record<(typeof $tuple), [Array<NamedPattern>]>(L, Fs);
})()) ??
((() => {
const M = d.mark();
if (!d.openRecord()) return void 0;
const L = _.checkIs(d.nextSymbol(), $tuple_STAR_);
if (L === void 0) { d.restoreMark(M); return void 0; };
const Fs = (((() => {
const M = d.mark();
const v0 = ((() => {
const M = d.mark();
if (!d.openSequence()) return void 0;
const vN: Array<NamedPattern> = [];
let tmp: undefined | NamedPattern;
while ((tmp = decodeNamedPattern(d)) !== void 0) vN.push(tmp);
if (!d.closeCompound()) { d.restoreMark(M); return void 0; };
return vN;
})()); if (v0 === void 0) { d.restoreMark(M); return void 0; };
const v1 = decodeNamedPattern(d); if (v1 === void 0) { d.restoreMark(M); return void 0; };
if (!d.closeCompound()) { d.restoreMark(M); return void 0; };
return [v0, v1] as [Array<NamedPattern>, NamedPattern];
})())) as any;
if (Fs === void 0) { d.restoreMark(M); return void 0; };
return _.Record<(typeof $tuple_STAR_), [Array<NamedPattern>, NamedPattern]>(L, Fs);
})()) ??
((() => {
const M = d.mark();
if (!d.openRecord()) return void 0;
const L = _.checkIs(d.nextSymbol(), $setof);
if (L === void 0) { d.restoreMark(M); return void 0; };
const Fs = (((() => {
const M = d.mark();
const v0 = decodePattern(d); if (v0 === void 0) { d.restoreMark(M); return void 0; };
if (!d.closeCompound()) { d.restoreMark(M); return void 0; };
return [v0] as [Pattern];
})())) as any;
if (Fs === void 0) { d.restoreMark(M); return void 0; };
return _.Record<(typeof $setof), [Pattern]>(L, Fs);
})()) ??
((() => {
const M = d.mark();
if (!d.openRecord()) return void 0;
const L = _.checkIs(d.nextSymbol(), $dictof);
if (L === void 0) { d.restoreMark(M); return void 0; };
const Fs = (((() => {
const M = d.mark();
const v0 = decodePattern(d); if (v0 === void 0) { d.restoreMark(M); return void 0; };
const v1 = decodePattern(d); if (v1 === void 0) { d.restoreMark(M); return void 0; };
if (!d.closeCompound()) { d.restoreMark(M); return void 0; };
return [v0, v1] as [Pattern, Pattern];
})())) as any;
if (Fs === void 0) { d.restoreMark(M); return void 0; };
return _.Record<(typeof $dictof), [Pattern, Pattern]>(L, Fs);
})()) ??
((() => {
const M = d.mark();
if (!d.openRecord()) return void 0;
const L = _.checkIs(d.nextSymbol(), $dict);
if (L === void 0) { d.restoreMark(M); return void 0; };
const Fs = (((() => {
const M = d.mark();
const v0 = ((() => {
const M = d.mark();
if (!d.openDictionary()) return void 0;
const r: _.KeyedDictionary<_val, Pattern, _ptr> = new _.KeyedDictionary();
let K: undefined | _val;
while ((K = d.next()) !== void 0) {
const V = decodePattern(d);
if (V === void 0) { d.restoreMark(M); return void 0; };
r.set(K, V);
};
if (!d.closeCompound()) { d.restoreMark(M); return void 0; };
return r;
})()); if (v0 === void 0) { d.restoreMark(M); return void 0; };
if (!d.closeCompound()) { d.restoreMark(M); return void 0; };
return [v0] as [_.KeyedDictionary<_val, Pattern, _ptr>];
})())) as any;
if (Fs === void 0) { d.restoreMark(M); return void 0; };
return _.Record<(typeof $dict), [_.KeyedDictionary<_val, Pattern, _ptr>]>(L, Fs);
})())
);
}
2021-03-10 22:15:53 +00:00
export function isNamedPattern(v: any): v is NamedPattern {
return (
(
2021-03-11 16:59:40 +00:00
_.Record.isRecord<_val, _.Tuple<_val>, _ptr>(v) &&
2021-03-11 13:43:58 +00:00
_.is(v.label, $named) &&
2021-03-10 22:15:53 +00:00
((v.length === 2) && typeof v[0] === 'symbol' && isPattern(v[1]))
) ||
isPattern(v)
);
}
2021-03-11 08:25:17 +00:00
export function asNamedPattern(v: any): NamedPattern {
2021-03-11 16:59:40 +00:00
if (!isNamedPattern(v)) {throw new TypeError(`Invalid NamedPattern: ${_.stringify(v)}`);} else {return v;};
2021-03-11 08:25:17 +00:00
}
export function decodeNamedPattern(d: _.TypedDecoder<_ptr>): NamedPattern | undefined {
return (
((() => {
const M = d.mark();
if (!d.openRecord()) return void 0;
const L = _.checkIs(d.nextSymbol(), $named);
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 = decodePattern(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, Pattern];
})())) as any;
if (Fs === void 0) { d.restoreMark(M); return void 0; };
return _.Record<(typeof $named), [symbol, Pattern]>(L, Fs);
})()) ??
decodePattern(d)
);
}
2021-03-11 09:56:49 +00:00
export function isRef(v: any): v is Ref {
return (
2021-03-11 16:59:40 +00:00
_.Record.isRecord<_val, _.Tuple<_val>, _ptr>(v) &&
2021-03-11 13:43:58 +00:00
_.is(v.label, $ref) &&
2021-03-11 09:56:49 +00:00
((v.length === 2) && isModuleRef(v[0]) && typeof v[1] === 'symbol')
);
}
2021-03-11 16:59:40 +00:00
export function asRef(v: any): Ref {
if (!isRef(v)) {throw new TypeError(`Invalid Ref: ${_.stringify(v)}`);} else {return v;};
}
2021-03-11 09:56:49 +00:00
export function decodeRef(d: _.TypedDecoder<_ptr>): Ref | undefined {
return ((() => {
const M = d.mark();
if (!d.openRecord()) return void 0;
const L = _.checkIs(d.nextSymbol(), $ref);
if (L === void 0) { d.restoreMark(M); return void 0; };
const Fs = (((() => {
const M = d.mark();
const v0 = decodeModuleRef(d); if (v0 === void 0) { d.restoreMark(M); return void 0; };
const v1 = d.nextSymbol(); if (v1 === void 0) { d.restoreMark(M); return void 0; };
if (!d.closeCompound()) { d.restoreMark(M); return void 0; };
return [v0, v1] as [ModuleRef, symbol];
})())) as any;
if (Fs === void 0) { d.restoreMark(M); return void 0; };
return _.Record<(typeof $ref), [ModuleRef, symbol]>(L, Fs);
})());
}
2021-03-11 13:43:58 +00:00
export function isModuleRef(v: any): v is ModuleRef {return (_.is(v, $thisModule) || isModulePath(v));}
2021-03-11 09:56:49 +00:00
2021-03-11 13:43:58 +00:00
export function asModuleRef(v: any): ModuleRef {
2021-03-11 16:59:40 +00:00
if (!isModuleRef(v)) {throw new TypeError(`Invalid ModuleRef: ${_.stringify(v)}`);} else {return v;};
2021-03-11 13:43:58 +00:00
}
2021-03-11 09:56:49 +00:00
export function decodeModuleRef(d: _.TypedDecoder<_ptr>): ModuleRef | undefined {return (_.checkIs(d.nextSymbol(), $thisModule) ?? decodeModulePath(d));}
2021-03-11 09:56:49 +00:00
export function isModulePath(v: any): v is ModulePath {
return (
_.Array.isArray(v) &&
2021-03-11 16:59:40 +00:00
!_.Record.isRecord<_val, _.Tuple<_val>, _ptr>(v) &&
2021-03-11 09:56:49 +00:00
(v.length >= 0) &&
v.slice(0).every(v => (typeof v === 'symbol'))
);
}
2021-03-11 13:43:58 +00:00
export function asModulePath(v: any): ModulePath {
2021-03-11 16:59:40 +00:00
if (!isModulePath(v)) {throw new TypeError(`Invalid ModulePath: ${_.stringify(v)}`);} else {return v;};
2021-03-11 13:43:58 +00:00
}
2021-03-10 22:15:53 +00:00
export function decodeModulePath(d: _.TypedDecoder<_ptr>): ModulePath | undefined {
return ((() => {
const M = d.mark();
if (!d.openSequence()) return void 0;
const vN: Array<symbol> = [];
let tmp: undefined | symbol;
while ((tmp = d.nextSymbol()) !== void 0) vN.push(tmp);
if (!d.closeCompound()) { d.restoreMark(M); return void 0; };
return vN;
})());
}
export const _decodePtr = () => { throw new _.DecodeError("Pointers forbidden"); };