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

276 lines
8.8 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");
export const Schema = _.Record.makeConstructor<{
"details": (
{
get(k: typeof $version): Version;
get(k: typeof $definitions): _.KeyedDictionary<symbol, Pattern>;
has(k: typeof $version): true;
has(k: typeof $definitions): true;
} & _.Dictionary<_.Value>
)
}>()($schema, ["details"]);
export type Schema = _.Record<
(typeof $schema),
[
(
{
get(k: typeof $version): Version;
get(k: typeof $definitions): _.KeyedDictionary<symbol, Pattern>;
has(k: typeof $version): true;
has(k: typeof $definitions): true;
} & _.Dictionary<_.Value>
)
]
>;
export type Version = (typeof $1);
export type Pattern = (
_.Record<
(typeof $atom),
[
(
(typeof $Boolean) |
(typeof $Float) |
(typeof $Double) |
(typeof $SignedInteger) |
(typeof $String) |
(typeof $ByteString) |
(typeof $Symbol)
)
]
> |
_.Record<(typeof $pointer), []> |
_.Record<(typeof $lit), [_.Value]> |
2021-03-11 09:56:49 +00:00
Ref |
2021-03-10 22:15:53 +00:00
_.Record<(typeof $or), [Array<Pattern>]> |
_.Record<(typeof $and), [Array<Pattern>]> |
_.Record<(typeof $rec), [Pattern, Pattern]> |
_.Record<(typeof $tuple), [Array<NamedPattern>]> |
_.Record<(typeof $tuple_STAR_), [Array<NamedPattern>, NamedPattern]> |
_.Record<(typeof $setof), [Pattern]> |
_.Record<(typeof $dictof), [Pattern, Pattern]> |
_.Record<(typeof $dict), [_.KeyedDictionary<_.Value, Pattern>]>
);
export type NamedPattern = (_.Record<(typeof $named), [symbol, Pattern]> | Pattern);
2021-03-11 09:56:49 +00:00
export const Ref = _.Record.makeConstructor<{"module": ModuleRef, "name": symbol}>()($ref, ["module","name"]);
export type Ref = _.Record<(typeof $ref), [ModuleRef, symbol]>;
export type ModuleRef = ((typeof $thisModule) | ModulePath);
export type ModulePath = Array<symbol>;
2021-03-10 22:15:53 +00:00
export function isSchema(v: any): v is Schema {
let _tmp0, _tmp1: any;
return (
_.Record.isRecord(v) &&
v.label === $schema &&
(
(v.length === 1) &&
(
_.Dictionary.isDictionary(v[0]) &&
((_tmp0 = v[0].get($version)) !== void 0 && isVersion(_tmp0)) &&
(
(_tmp1 = v[0].get($definitions)) !== void 0 && (
_.Dictionary.isDictionary(_tmp1) &&
((() => {
for (const e of _tmp1) {
if (!(typeof e[0] === 'symbol')) return false;
if (!(isPattern(e[1]))) return false;
};
return true;
})())
)
)
)
)
);
}
2021-03-11 08:25:17 +00:00
export function asSchema(v: any): Schema {if (!isSchema(v)) {throw new TypeError("Schema");} else {return v;};}
2021-03-10 22:15:53 +00:00
export function isVersion(v: any): v is Version {return v === $1;}
2021-03-11 08:25:17 +00:00
export function asVersion(v: any): Version {if (!isVersion(v)) {throw new TypeError("Version");} else {return v;};}
2021-03-10 22:15:53 +00:00
export function isPattern(v: any): v is Pattern {
return (
(
_.Record.isRecord(v) &&
v.label === $atom &&
(
(v.length === 1) &&
(
v[0] === $Boolean ||
v[0] === $Float ||
v[0] === $Double ||
v[0] === $SignedInteger ||
v[0] === $String ||
v[0] === $ByteString ||
v[0] === $Symbol
)
)
) ||
(_.Record.isRecord(v) && v.label === $pointer && ((v.length === 0))) ||
(_.Record.isRecord(v) && 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
(
_.Record.isRecord(v) &&
v.label === $or &&
(
(v.length === 1) &&
(
_.Array.isArray(v[0]) &&
!_.Record.isRecord(v[0]) &&
(v[0].length >= 0) &&
v[0].slice(0).every(v => (isPattern(v)))
)
)
) ||
(
_.Record.isRecord(v) &&
v.label === $and &&
(
(v.length === 1) &&
(
_.Array.isArray(v[0]) &&
!_.Record.isRecord(v[0]) &&
(v[0].length >= 0) &&
v[0].slice(0).every(v => (isPattern(v)))
)
)
) ||
(
_.Record.isRecord(v) &&
v.label === $rec &&
((v.length === 2) && isPattern(v[0]) && isPattern(v[1]))
) ||
(
_.Record.isRecord(v) &&
v.label === $tuple &&
(
(v.length === 1) &&
(
_.Array.isArray(v[0]) &&
!_.Record.isRecord(v[0]) &&
(v[0].length >= 0) &&
v[0].slice(0).every(v => (isNamedPattern(v)))
)
)
) ||
(
_.Record.isRecord(v) &&
v.label === $tuple_STAR_ &&
(
(v.length === 2) &&
(
_.Array.isArray(v[0]) &&
!_.Record.isRecord(v[0]) &&
(v[0].length >= 0) &&
v[0].slice(0).every(v => (isNamedPattern(v)))
) &&
isNamedPattern(v[1])
)
) ||
(
_.Record.isRecord(v) &&
v.label === $setof &&
((v.length === 1) && isPattern(v[0]))
) ||
(
_.Record.isRecord(v) &&
v.label === $dictof &&
((v.length === 2) && isPattern(v[0]) && isPattern(v[1]))
) ||
(
_.Record.isRecord(v) &&
v.label === $dict &&
(
(v.length === 1) &&
(
_.Dictionary.isDictionary(v[0]) &&
((() => {
for (const e of v[0]) {if (!(true)) return false; if (!(isPattern(e[1]))) return false;};
return true;
})())
)
)
)
);
}
2021-03-11 08:25:17 +00:00
export function asPattern(v: any): Pattern {if (!isPattern(v)) {throw new TypeError("Pattern");} else {return v;};}
2021-03-10 22:15:53 +00:00
export function isNamedPattern(v: any): v is NamedPattern {
return (
(
_.Record.isRecord(v) &&
v.label === $named &&
((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 {
if (!isNamedPattern(v)) {throw new TypeError("NamedPattern");} else {return v;};
}
2021-03-11 09:56:49 +00:00
export function isRef(v: any): v is Ref {
return (
_.Record.isRecord(v) &&
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("Ref");} else {return v;};}
export function isModuleRef(v: any): v is ModuleRef {return (v === $thisModule || isModulePath(v));}
export function asModuleRef(v: any): ModuleRef {if (!isModuleRef(v)) {throw new TypeError("ModuleRef");} else {return v;};}
export function isModulePath(v: any): v is ModulePath {
return (
_.Array.isArray(v) &&
!_.Record.isRecord(v) &&
(v.length >= 0) &&
v.slice(0).every(v => (typeof v === 'symbol'))
);
}
export function asModulePath(v: any): ModulePath {if (!isModulePath(v)) {throw new TypeError("ModulePath");} else {return v;};}
2021-03-10 22:15:53 +00:00