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

315 lines
10 KiB
TypeScript

import * as _ from "@preserves/core";
export type _ptr = never;
export type _val = _.Value<_ptr>;
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 $thisModule = Symbol.for("thisModule");
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<symbol, Pattern>;
has(k: typeof $version): true;
has(k: typeof $pointer): true;
has(k: typeof $definitions): true;
} & _.Dictionary<_val, _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<symbol, Pattern>;
has(k: typeof $version): true;
has(k: typeof $pointer): true;
has(k: typeof $definitions): true;
} & _.Dictionary<_val, _ptr>
)
],
_ptr
>;
export type Version = (typeof $1);
export type PointerName = (Ref | (typeof __lit5));
export type Pattern = (
_.Record<
(typeof $atom),
[
(
(typeof $Boolean) |
(typeof $Float) |
(typeof $Double) |
(typeof $SignedInteger) |
(typeof $String) |
(typeof $ByteString) |
(typeof $Symbol)
)
],
_ptr
> |
_.Record<(typeof $pointer), [], _ptr> |
_.Record<(typeof $lit), [_val], _ptr> |
Ref |
_.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> |
_.Record<(typeof $dict), [_.KeyedDictionary<_val, Pattern>], _ptr>
);
export type NamedPattern = (_.Record<(typeof $named), [symbol, Pattern], _ptr> | Pattern);
export const Ref = _.Record.makeConstructor<{"module": ModuleRef, "name": symbol}, _ptr>()($ref, ["module","name"]);
export type Ref = _.Record<(typeof $ref), [ModuleRef, symbol], _ptr>;
export type ModuleRef = ((typeof $thisModule) | ModulePath);
export type ModulePath = Array<symbol>;
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<_val, _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<_val, _ptr>(_tmp2) &&
((() => {
for (const e of _tmp2) {
if (!(typeof e[0] === 'symbol')) return false;
if (!(isPattern(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 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 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 isPattern(v: any): v is Pattern {
return (
(
_.Record.isRecord<_val, _.Tuple<_val>, _ptr>(v) &&
_.is(v.label, $atom) &&
(
(v.length === 1) &&
(
_.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)
)
)
) ||
(
_.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)
) ||
isRef(v) ||
(
_.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].slice(0).every(v => (isPattern(v)))
)
)
) ||
(
_.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].slice(0).every(v => (isPattern(v)))
)
)
) ||
(
_.Record.isRecord<_val, _.Tuple<_val>, _ptr>(v) &&
_.is(v.label, $rec) &&
((v.length === 2) && isPattern(v[0]) && isPattern(v[1]))
) ||
(
_.Record.isRecord<_val, _.Tuple<_val>, _ptr>(v) &&
_.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].slice(0).every(v => (isNamedPattern(v)))
)
)
) ||
(
_.Record.isRecord<_val, _.Tuple<_val>, _ptr>(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].slice(0).every(v => (isNamedPattern(v)))
) &&
isNamedPattern(v[1])
)
) ||
(
_.Record.isRecord<_val, _.Tuple<_val>, _ptr>(v) &&
_.is(v.label, $setof) &&
((v.length === 1) && isPattern(v[0]))
) ||
(
_.Record.isRecord<_val, _.Tuple<_val>, _ptr>(v) &&
_.is(v.label, $dictof) &&
((v.length === 2) && isPattern(v[0]) && isPattern(v[1]))
) ||
(
_.Record.isRecord<_val, _.Tuple<_val>, _ptr>(v) &&
_.is(v.label, $dict) &&
(
(v.length === 1) &&
(
_.Dictionary.isDictionary<_val, _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 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 isRef(v: any): v is Ref {
return (
_.Record.isRecord<_val, _.Tuple<_val>, _ptr>(v) &&
_.is(v.label, $ref) &&
((v.length === 2) && isModuleRef(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 isModuleRef(v: any): v is ModuleRef {return (_.is(v, $thisModule) || isModulePath(v));}
export function asModuleRef(v: any): ModuleRef {
if (!isModuleRef(v)) {throw new TypeError(`Invalid ModuleRef: ${_.stringify(v)}`);} else {return v;};
}
export function isModulePath(v: any): v is ModulePath {
return (
_.Array.isArray(v) &&
!_.Record.isRecord<_val, _.Tuple<_val>, _ptr>(v) &&
(v.length >= 0) &&
v.slice(0).every(v => (typeof v === 'symbol'))
);
}
export function asModulePath(v: any): ModulePath {
if (!isModulePath(v)) {throw new TypeError(`Invalid ModulePath: ${_.stringify(v)}`);} else {return v;};
}