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"); export const $tuple = Symbol.for("tuple"); export const $tuple_STAR_ = Symbol.for("tuple*"); export const $version = Symbol.for("version"); export const __lit5 = false; export const Schema = _.Record.makeConstructor<{ "details": ( { get(k: typeof $version): Version; get(k: typeof $pointer): PointerName; get(k: typeof $definitions): _.KeyedDictionary; has(k: typeof $version): true; has(k: typeof $pointer): true; has(k: typeof $definitions): true; } & _.Dictionary<_ptr> ) }, _ptr>()($schema, ["details"]); export type Schema = _.Record< (typeof $schema), [ ( { get(k: typeof $version): Version; get(k: typeof $pointer): PointerName; get(k: typeof $definitions): _.KeyedDictionary; has(k: typeof $version): true; has(k: typeof $pointer): true; has(k: typeof $definitions): true; } & _.Dictionary<_ptr> ) ], _ptr >; export type Version = (typeof $1); export type PointerName = (Ref | (typeof __lit5)); export type Definition = (_.Record<(typeof $or), [Array<[symbol, Alternative]>], _ptr> | Alternative); export type Alternative = (_.Record<(typeof $and), [Array], _ptr> | Pattern); export type Pattern = ( _.Record<(typeof $atom), [AtomKind], _ptr> | _.Record<(typeof $pointer), [], _ptr> | _.Record<(typeof $lit), [_val], _ptr> | Ref | _.Record<(typeof $rec), [Pattern, Pattern], _ptr> | _.Record<(typeof $tuple), [Array], _ptr> | _.Record<(typeof $tuple_STAR_), [Array, NamedPattern], _ptr> | _.Record<(typeof $setof), [Pattern], _ptr> | _.Record<(typeof $dictof), [Pattern, Pattern], _ptr> | _.Record<(typeof $dict), [_.KeyedDictionary<_val, Pattern, _ptr>], _ptr> ); export type AtomKind = ( (typeof $Boolean) | (typeof $Float) | (typeof $Double) | (typeof $SignedInteger) | (typeof $String) | (typeof $ByteString) | (typeof $Symbol) ); export type NamedPattern = (_.Record<(typeof $named), [symbol, Pattern], _ptr> | Pattern); export const Ref = _.Record.makeConstructor<{"module": ModulePath, "name": symbol}, _ptr>()($ref, ["module","name"]); export type Ref = _.Record<(typeof $ref), [ModulePath, symbol], _ptr>; export type ModulePath = Array; export type _ptr = never; export type _val = _.Value<_ptr>; export function isSchema(v: any): v is Schema { let _tmp0, _tmp1, _tmp2: any; return ( _.Record.isRecord<_val, _.Tuple<_val>, _ptr>(v) && _.is(v.label, $schema) && ( (v.length === 1) && ( _.Dictionary.isDictionary<_ptr>(v[0]) && ((_tmp0 = v[0].get($version)) !== void 0 && isVersion(_tmp0)) && ((_tmp1 = v[0].get($pointer)) !== void 0 && isPointerName(_tmp1)) && ( (_tmp2 = v[0].get($definitions)) !== void 0 && ( _.Dictionary.isDictionary<_ptr>(_tmp2) && ((() => { for (const e of _tmp2) { if (!(typeof e[0] === 'symbol')) return false; if (!(isDefinition(e[1]))) return false; }; return true; })()) ) ) ) ) ); } export function asSchema(v: any): Schema { if (!isSchema(v)) {throw new TypeError(`Invalid Schema: ${_.stringify(v)}`);} else {return v;}; } export function decodeSchema(d: _.TypedDecoder<_ptr>): Schema | undefined { let result; if (d.openRecord()) { let _tmp3: any; _tmp3 = _.asLiteral(d.nextSymbol(), $schema); if (_tmp3 !== void 0) { let _tmp4, _tmp5, _tmp6, _tmp7, _tmp8: any; _tmp5 = d.next(); if (_tmp5 !== void 0 && !(( _.Dictionary.isDictionary<_ptr>(_tmp5) && ((_tmp6 = _tmp5.get($version)) !== void 0 && isVersion(_tmp6)) && ((_tmp7 = _tmp5.get($pointer)) !== void 0 && isPointerName(_tmp7)) && ( (_tmp8 = _tmp5.get($definitions)) !== void 0 && ( _.Dictionary.isDictionary<_ptr>(_tmp8) && ((() => { for (const e of _tmp8) { if (!(typeof e[0] === 'symbol')) return false; if (!(isDefinition(e[1]))) return false; }; return true; })()) ) ) ))) _tmp5 = void 0; if (_tmp5 !== void 0) {if (d.closeCompound()) _tmp4 = [_tmp5];}; if (_tmp4 !== void 0) result = _.Record< (typeof $schema), [ ( { get(k: typeof $version): Version; get(k: typeof $pointer): PointerName; get(k: typeof $definitions): _.KeyedDictionary; has(k: typeof $version): true; has(k: typeof $pointer): true; has(k: typeof $definitions): true; } & _.Dictionary<_ptr> ) ] >(_tmp3 as any, _tmp4 as any); }; }; return result; } export function isVersion(v: any): v is Version {return _.is(v, $1);} 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 {let result; result = _.asLiteral(d.nextSignedInteger(), $1); return result;} 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;}; } export function decodePointerName(d: _.TypedDecoder<_ptr>): PointerName | undefined { let _tmp9: any; let result; _tmp9 = d.mark(); result = decodeRef(d); if (result === void 0) {d.restoreMark(_tmp9); result = _.asLiteral(d.nextBoolean(), __lit5);}; return result; } export function isDefinition(v: any): v is Definition { return ( ( _.Record.isRecord<_val, _.Tuple<_val>, _ptr>(v) && _.is(v.label, $or) && ( (v.length === 1) && ( _.Array.isArray(v[0]) && !_.Record.isRecord<_val, _.Tuple<_val>, _ptr>(v[0]) && (v[0].length >= 0) && v[0].every(v => ( ( _.Array.isArray(v) && !_.Record.isRecord<_val, _.Tuple<_val>, _ptr>(v) && (v.length === 2) && typeof v[0] === 'symbol' && isAlternative(v[1]) ) )) ) ) ) || isAlternative(v) ); } export function asDefinition(v: any): Definition { if (!isDefinition(v)) {throw new TypeError(`Invalid Definition: ${_.stringify(v)}`);} else {return v;}; } export function decodeDefinition(d: _.TypedDecoder<_ptr>): Definition | undefined { let _tmp10: any; let result; _tmp10 = d.mark(); if (d.openRecord()) { let _tmp11: any; _tmp11 = _.asLiteral(d.nextSymbol(), $or); if (_tmp11 !== void 0) { let _tmp12, _tmp13: any; if (d.openSequence()) { let _tmp14: any; { let vN: Array<[symbol, Alternative]> | undefined = []; while (!d.closeCompound()) { let _tmp15, _tmp16: any; _tmp14 = void 0; if (d.openSequence()) { _tmp15 = d.nextSymbol(); if (_tmp15 !== void 0) { _tmp16 = decodeAlternative(d); if (_tmp16 !== void 0) {if (d.closeCompound()) _tmp14 = [_tmp15, _tmp16];}; }; }; if (_tmp14 === void 0) {vN = void 0; break;}; vN.push(_tmp14); }; _tmp13 = vN; }; }; if (_tmp13 !== void 0) {if (d.closeCompound()) _tmp12 = [_tmp13];}; if (_tmp12 !== void 0) result = _.Record<(typeof $or), [Array<[symbol, Alternative]>]>(_tmp11 as any, _tmp12 as any); }; }; if (result === void 0) {d.restoreMark(_tmp10); result = decodeAlternative(d);}; return result; } export function isAlternative(v: any): v is Alternative { return ( ( _.Record.isRecord<_val, _.Tuple<_val>, _ptr>(v) && _.is(v.label, $and) && ( (v.length === 1) && ( _.Array.isArray(v[0]) && !_.Record.isRecord<_val, _.Tuple<_val>, _ptr>(v[0]) && (v[0].length >= 0) && v[0].every(v => (isPattern(v))) ) ) ) || isPattern(v) ); } export function asAlternative(v: any): Alternative { if (!isAlternative(v)) {throw new TypeError(`Invalid Alternative: ${_.stringify(v)}`);} else {return v;}; } export function decodeAlternative(d: _.TypedDecoder<_ptr>): Alternative | undefined { let _tmp17: any; let result; _tmp17 = d.mark(); if (d.openRecord()) { let _tmp18: any; _tmp18 = _.asLiteral(d.nextSymbol(), $and); if (_tmp18 !== void 0) { let _tmp19, _tmp20: any; if (d.openSequence()) { let _tmp21: any; { let vN: Array | undefined = []; while (!d.closeCompound()) { _tmp21 = void 0; _tmp21 = decodePattern(d); if (_tmp21 === void 0) {vN = void 0; break;}; vN.push(_tmp21); }; _tmp20 = vN; }; }; if (_tmp20 !== void 0) {if (d.closeCompound()) _tmp19 = [_tmp20];}; if (_tmp19 !== void 0) result = _.Record<(typeof $and), [Array]>(_tmp18 as any, _tmp19 as any); }; }; if (result === void 0) {d.restoreMark(_tmp17); result = decodePattern(d);}; return result; } export function isPattern(v: any): v is Pattern { return _.Record.isRecord<_val, _.Tuple<_val>, _ptr>(v) && ( ( (_.is(v.label, $atom) && ((v.length === 1) && isAtomKind(v[0]))) || (_.is(v.label, $pointer) && ((v.length === 0))) || (_.is(v.label, $lit) && ((v.length === 1) && true)) || ( _.is(v.label, $ref) && ((v.length === 2) && isModulePath(v[0]) && typeof v[1] === 'symbol') ) || ( _.is(v.label, $rec) && ((v.length === 2) && isPattern(v[0]) && isPattern(v[1])) ) || ( _.is(v.label, $tuple) && ( (v.length === 1) && ( _.Array.isArray(v[0]) && !_.Record.isRecord<_val, _.Tuple<_val>, _ptr>(v[0]) && (v[0].length >= 0) && v[0].every(v => (isNamedPattern(v))) ) ) ) || ( _.is(v.label, $tuple_STAR_) && ( (v.length === 2) && ( _.Array.isArray(v[0]) && !_.Record.isRecord<_val, _.Tuple<_val>, _ptr>(v[0]) && (v[0].length >= 0) && v[0].every(v => (isNamedPattern(v))) ) && isNamedPattern(v[1]) ) ) || (_.is(v.label, $setof) && ((v.length === 1) && isPattern(v[0]))) || ( _.is(v.label, $dictof) && ((v.length === 2) && isPattern(v[0]) && isPattern(v[1])) ) || ( _.is(v.label, $dict) && ( (v.length === 1) && ( _.Dictionary.isDictionary<_ptr>(v[0]) && ((() => { for (const e of v[0]) {if (!(true)) return false; if (!(isPattern(e[1]))) return false;}; return true; })()) ) ) ) ) ); } export function asPattern(v: any): Pattern { if (!isPattern(v)) {throw new TypeError(`Invalid Pattern: ${_.stringify(v)}`);} else {return v;}; } export function decodePattern(d: _.TypedDecoder<_ptr>): Pattern | undefined { let result; if (d.openRecord()) { let _tmp22, _tmp23: any; _tmp22 = d.next(); _tmp23 = d.mark(); if (_.is(_tmp22, $atom)) { let _tmp24, _tmp25: any; _tmp25 = decodeAtomKind(d); if (_tmp25 !== void 0) {if (d.closeCompound()) _tmp24 = [_tmp25];}; if (_tmp24 !== void 0) result = _.Record<(typeof $atom), [AtomKind]>(_tmp22 as any, _tmp24 as any); }; if (result === void 0) { d.restoreMark(_tmp23); if (_.is(_tmp22, $pointer)) { let _tmp26: any; if (d.closeCompound()) _tmp26 = []; if (_tmp26 !== void 0) result = _.Record<(typeof $pointer), []>(_tmp22 as any, _tmp26 as any); }; if (result === void 0) { d.restoreMark(_tmp23); if (_.is(_tmp22, $lit)) { let _tmp27, _tmp28: any; _tmp28 = d.next(); if (_tmp28 !== void 0) {if (d.closeCompound()) _tmp27 = [_tmp28];}; if (_tmp27 !== void 0) result = _.Record<(typeof $lit), [_val]>(_tmp22 as any, _tmp27 as any); }; if (result === void 0) { d.restoreMark(_tmp23); if (_.is(_tmp22, $ref)) { let _tmp29, _tmp30, _tmp31: any; _tmp30 = decodeModulePath(d); if (_tmp30 !== void 0) { _tmp31 = d.nextSymbol(); if (_tmp31 !== void 0) {if (d.closeCompound()) _tmp29 = [_tmp30, _tmp31];}; }; if (_tmp29 !== void 0) result = _.Record<(typeof $ref), [ModulePath, symbol]>(_tmp22 as any, _tmp29 as any); }; if (result === void 0) { d.restoreMark(_tmp23); if (_.is(_tmp22, $rec)) { let _tmp32, _tmp33, _tmp34: any; _tmp33 = decodePattern(d); if (_tmp33 !== void 0) { _tmp34 = decodePattern(d); if (_tmp34 !== void 0) {if (d.closeCompound()) _tmp32 = [_tmp33, _tmp34];}; }; if (_tmp32 !== void 0) result = _.Record<(typeof $rec), [Pattern, Pattern]>(_tmp22 as any, _tmp32 as any); }; if (result === void 0) { d.restoreMark(_tmp23); if (_.is(_tmp22, $tuple)) { let _tmp35, _tmp36: any; if (d.openSequence()) { let _tmp37: any; { let vN: Array | undefined = []; while (!d.closeCompound()) { _tmp37 = void 0; _tmp37 = decodeNamedPattern(d); if (_tmp37 === void 0) {vN = void 0; break;}; vN.push(_tmp37); }; _tmp36 = vN; }; }; if (_tmp36 !== void 0) {if (d.closeCompound()) _tmp35 = [_tmp36];}; if (_tmp35 !== void 0) result = _.Record<(typeof $tuple), [Array]>(_tmp22 as any, _tmp35 as any); }; if (result === void 0) { d.restoreMark(_tmp23); if (_.is(_tmp22, $tuple_STAR_)) { let _tmp38, _tmp39, _tmp40: any; if (d.openSequence()) { let _tmp41: any; { let vN: Array | undefined = []; while (!d.closeCompound()) { _tmp41 = void 0; _tmp41 = decodeNamedPattern(d); if (_tmp41 === void 0) {vN = void 0; break;}; vN.push(_tmp41); }; _tmp39 = vN; }; }; if (_tmp39 !== void 0) { _tmp40 = decodeNamedPattern(d); if (_tmp40 !== void 0) {if (d.closeCompound()) _tmp38 = [_tmp39, _tmp40];}; }; if (_tmp38 !== void 0) result = _.Record<(typeof $tuple_STAR_), [Array, NamedPattern]>(_tmp22 as any, _tmp38 as any); }; if (result === void 0) { d.restoreMark(_tmp23); if (_.is(_tmp22, $setof)) { let _tmp42, _tmp43: any; _tmp43 = decodePattern(d); if (_tmp43 !== void 0) {if (d.closeCompound()) _tmp42 = [_tmp43];}; if (_tmp42 !== void 0) result = _.Record<(typeof $setof), [Pattern]>(_tmp22 as any, _tmp42 as any); }; if (result === void 0) { d.restoreMark(_tmp23); if (_.is(_tmp22, $dictof)) { let _tmp44, _tmp45, _tmp46: any; _tmp45 = decodePattern(d); if (_tmp45 !== void 0) { _tmp46 = decodePattern(d); if (_tmp46 !== void 0) {if (d.closeCompound()) _tmp44 = [_tmp45, _tmp46];}; }; if (_tmp44 !== void 0) result = _.Record<(typeof $dictof), [Pattern, Pattern]>(_tmp22 as any, _tmp44 as any); }; if (result === void 0) { d.restoreMark(_tmp23); if (_.is(_tmp22, $dict)) { let _tmp47, _tmp48: any; if (d.openDictionary()) { let r: _.KeyedDictionary<_val, Pattern, _ptr> | undefined = new _.KeyedDictionary(); while (!d.closeCompound()) { let K: undefined | _val = void 0; K = d.next(); if (K === void 0) { r = void 0; break; }; let V: undefined | Pattern = void 0; V = decodePattern(d); if (V === void 0) { r = void 0; break; }; r.set(K, V); }; _tmp48 = r; }; if (_tmp48 !== void 0) {if (d.closeCompound()) _tmp47 = [_tmp48];}; if (_tmp47 !== void 0) result = _.Record<(typeof $dict), [_.KeyedDictionary<_val, Pattern, _ptr>]>(_tmp22 as any, _tmp47 as any); }; }; }; }; }; }; }; }; }; }; }; return result; } export function isAtomKind(v: any): v is AtomKind { return ( _.is(v, $Boolean) || _.is(v, $Float) || _.is(v, $Double) || _.is(v, $SignedInteger) || _.is(v, $String) || _.is(v, $ByteString) || _.is(v, $Symbol) ); } export function asAtomKind(v: any): AtomKind { if (!isAtomKind(v)) {throw new TypeError(`Invalid AtomKind: ${_.stringify(v)}`);} else {return v;}; } export function decodeAtomKind(d: _.TypedDecoder<_ptr>): AtomKind | undefined { let _tmp49: any; let result; _tmp49 = d.mark(); result = _.asLiteral(d.nextSymbol(), $Boolean); if (result === void 0) { d.restoreMark(_tmp49); result = _.asLiteral(d.nextSymbol(), $Float); if (result === void 0) { d.restoreMark(_tmp49); result = _.asLiteral(d.nextSymbol(), $Double); if (result === void 0) { d.restoreMark(_tmp49); result = _.asLiteral(d.nextSymbol(), $SignedInteger); if (result === void 0) { d.restoreMark(_tmp49); result = _.asLiteral(d.nextSymbol(), $String); if (result === void 0) { d.restoreMark(_tmp49); result = _.asLiteral(d.nextSymbol(), $ByteString); if (result === void 0) {d.restoreMark(_tmp49); result = _.asLiteral(d.nextSymbol(), $Symbol);}; }; }; }; }; }; return result; } export function isNamedPattern(v: any): v is NamedPattern { return ( ( _.Record.isRecord<_val, _.Tuple<_val>, _ptr>(v) && _.is(v.label, $named) && ((v.length === 2) && typeof v[0] === 'symbol' && isPattern(v[1])) ) || isPattern(v) ); } export function asNamedPattern(v: any): NamedPattern { if (!isNamedPattern(v)) {throw new TypeError(`Invalid NamedPattern: ${_.stringify(v)}`);} else {return v;}; } export function decodeNamedPattern(d: _.TypedDecoder<_ptr>): NamedPattern | undefined { let _tmp50: any; let result; _tmp50 = d.mark(); if (d.openRecord()) { let _tmp51: any; _tmp51 = _.asLiteral(d.nextSymbol(), $named); if (_tmp51 !== void 0) { let _tmp52, _tmp53, _tmp54: any; _tmp53 = d.nextSymbol(); if (_tmp53 !== void 0) { _tmp54 = decodePattern(d); if (_tmp54 !== void 0) {if (d.closeCompound()) _tmp52 = [_tmp53, _tmp54];}; }; if (_tmp52 !== void 0) result = _.Record<(typeof $named), [symbol, Pattern]>(_tmp51 as any, _tmp52 as any); }; }; if (result === void 0) {d.restoreMark(_tmp50); result = decodePattern(d);}; return result; } export function isRef(v: any): v is Ref { return ( _.Record.isRecord<_val, _.Tuple<_val>, _ptr>(v) && _.is(v.label, $ref) && ((v.length === 2) && isModulePath(v[0]) && typeof v[1] === 'symbol') ); } export function asRef(v: any): Ref { if (!isRef(v)) {throw new TypeError(`Invalid Ref: ${_.stringify(v)}`);} else {return v;}; } export function decodeRef(d: _.TypedDecoder<_ptr>): Ref | undefined { let result; if (d.openRecord()) { let _tmp55: any; _tmp55 = _.asLiteral(d.nextSymbol(), $ref); if (_tmp55 !== void 0) { let _tmp56, _tmp57, _tmp58: any; _tmp57 = decodeModulePath(d); if (_tmp57 !== void 0) { _tmp58 = d.nextSymbol(); if (_tmp58 !== void 0) {if (d.closeCompound()) _tmp56 = [_tmp57, _tmp58];}; }; if (_tmp56 !== void 0) result = _.Record<(typeof $ref), [ModulePath, symbol]>(_tmp55 as any, _tmp56 as any); }; }; return result; } export function isModulePath(v: any): v is ModulePath { return ( _.Array.isArray(v) && !_.Record.isRecord<_val, _.Tuple<_val>, _ptr>(v) && (v.length >= 0) && v.every(v => (typeof v === 'symbol')) ); } export function asModulePath(v: any): ModulePath { if (!isModulePath(v)) {throw new TypeError(`Invalid ModulePath: ${_.stringify(v)}`);} else {return v;}; } export function decodeModulePath(d: _.TypedDecoder<_ptr>): ModulePath | undefined { let result; if (d.openSequence()) { let _tmp59: any; { let vN: Array | undefined = []; while (!d.closeCompound()) { _tmp59 = void 0; _tmp59 = d.nextSymbol(); if (_tmp59 === void 0) {vN = void 0; break;}; vN.push(_tmp59); }; result = vN; }; }; return result; } export const _decodePtr = () => { throw new _.DecodeError("Pointers forbidden"); };