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) &&
|
2021-03-11 13:43:58 +00:00
|
|
|
_.is(v.label, $schema) &&
|
2021-03-10 22:15:53 +00:00
|
|
|
(
|
|
|
|
(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 13:43:58 +00:00
|
|
|
export function asSchema(v: any): Schema {if (!isSchema(v)) {throw new TypeError("Invalid Schema");} else {return v;};}
|
2021-03-11 08:25:17 +00:00
|
|
|
|
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 13:43:58 +00:00
|
|
|
export function asVersion(v: any): Version {if (!isVersion(v)) {throw new TypeError("Invalid Version");} else {return v;};}
|
2021-03-11 08:25:17 +00:00
|
|
|
|
2021-03-10 22:15:53 +00:00
|
|
|
export function isPattern(v: any): v is Pattern {
|
|
|
|
return (
|
|
|
|
(
|
|
|
|
_.Record.isRecord(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 13:43:58 +00:00
|
|
|
(_.Record.isRecord(v) && _.is(v.label, $pointer) && ((v.length === 0))) ||
|
|
|
|
(_.Record.isRecord(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
|
|
|
(
|
|
|
|
_.Record.isRecord(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]) &&
|
|
|
|
!_.Record.isRecord(v[0]) &&
|
|
|
|
(v[0].length >= 0) &&
|
|
|
|
v[0].slice(0).every(v => (isPattern(v)))
|
|
|
|
)
|
|
|
|
)
|
|
|
|
) ||
|
|
|
|
(
|
|
|
|
_.Record.isRecord(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]) &&
|
|
|
|
!_.Record.isRecord(v[0]) &&
|
|
|
|
(v[0].length >= 0) &&
|
|
|
|
v[0].slice(0).every(v => (isPattern(v)))
|
|
|
|
)
|
|
|
|
)
|
|
|
|
) ||
|
|
|
|
(
|
|
|
|
_.Record.isRecord(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]))
|
|
|
|
) ||
|
|
|
|
(
|
|
|
|
_.Record.isRecord(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]) &&
|
|
|
|
!_.Record.isRecord(v[0]) &&
|
|
|
|
(v[0].length >= 0) &&
|
|
|
|
v[0].slice(0).every(v => (isNamedPattern(v)))
|
|
|
|
)
|
|
|
|
)
|
|
|
|
) ||
|
|
|
|
(
|
|
|
|
_.Record.isRecord(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]) &&
|
|
|
|
!_.Record.isRecord(v[0]) &&
|
|
|
|
(v[0].length >= 0) &&
|
|
|
|
v[0].slice(0).every(v => (isNamedPattern(v)))
|
|
|
|
) &&
|
|
|
|
isNamedPattern(v[1])
|
|
|
|
)
|
|
|
|
) ||
|
|
|
|
(
|
|
|
|
_.Record.isRecord(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]))
|
|
|
|
) ||
|
|
|
|
(
|
|
|
|
_.Record.isRecord(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]))
|
|
|
|
) ||
|
|
|
|
(
|
|
|
|
_.Record.isRecord(v) &&
|
2021-03-11 13:43:58 +00:00
|
|
|
_.is(v.label, $dict) &&
|
2021-03-10 22:15:53 +00:00
|
|
|
(
|
|
|
|
(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 13:43:58 +00:00
|
|
|
export function asPattern(v: any): Pattern {if (!isPattern(v)) {throw new TypeError("Invalid Pattern");} else {return v;};}
|
2021-03-11 08:25:17 +00:00
|
|
|
|
2021-03-10 22:15:53 +00:00
|
|
|
export function isNamedPattern(v: any): v is NamedPattern {
|
|
|
|
return (
|
|
|
|
(
|
|
|
|
_.Record.isRecord(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 13:43:58 +00:00
|
|
|
if (!isNamedPattern(v)) {throw new TypeError("Invalid NamedPattern");} else {return v;};
|
2021-03-11 08:25:17 +00:00
|
|
|
}
|
|
|
|
|
2021-03-11 09:56:49 +00:00
|
|
|
export function isRef(v: any): v is Ref {
|
|
|
|
return (
|
|
|
|
_.Record.isRecord(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 13:43:58 +00:00
|
|
|
export function asRef(v: any): Ref {if (!isRef(v)) {throw new TypeError("Invalid Ref");} else {return v;};}
|
2021-03-11 09:56:49 +00:00
|
|
|
|
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 {
|
|
|
|
if (!isModuleRef(v)) {throw new TypeError("Invalid ModuleRef");} else {return v;};
|
|
|
|
}
|
2021-03-11 09:56:49 +00:00
|
|
|
|
|
|
|
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'))
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2021-03-11 13:43:58 +00:00
|
|
|
export function asModulePath(v: any): ModulePath {
|
|
|
|
if (!isModulePath(v)) {throw new TypeError("Invalid ModulePath");} else {return v;};
|
|
|
|
}
|
2021-03-10 22:15:53 +00:00
|
|
|
|