Schema Bundles
This commit is contained in:
parent
4d8618ce63
commit
55fab35073
|
@ -11,6 +11,7 @@ export const $Symbol = Symbol.for("Symbol");
|
||||||
export const $and = Symbol.for("and");
|
export const $and = Symbol.for("and");
|
||||||
export const $any = Symbol.for("any");
|
export const $any = Symbol.for("any");
|
||||||
export const $atom = Symbol.for("atom");
|
export const $atom = Symbol.for("atom");
|
||||||
|
export const $bundle = Symbol.for("bundle");
|
||||||
export const $definitions = Symbol.for("definitions");
|
export const $definitions = Symbol.for("definitions");
|
||||||
export const $dict = Symbol.for("dict");
|
export const $dict = Symbol.for("dict");
|
||||||
export const $dictof = Symbol.for("dictof");
|
export const $dictof = Symbol.for("dictof");
|
||||||
|
@ -25,12 +26,16 @@ export const $setof = Symbol.for("setof");
|
||||||
export const $tuple = Symbol.for("tuple");
|
export const $tuple = Symbol.for("tuple");
|
||||||
export const $tuple$STAR$ = Symbol.for("tuple*");
|
export const $tuple$STAR$ = Symbol.for("tuple*");
|
||||||
export const $version = Symbol.for("version");
|
export const $version = Symbol.for("version");
|
||||||
export const __lit5 = false;
|
export const __lit6 = false;
|
||||||
|
|
||||||
export type _ptr = never;
|
export type _ptr = never;
|
||||||
|
|
||||||
export type _val = _.Value<_ptr>;
|
export type _val = _.Value<_ptr>;
|
||||||
|
|
||||||
|
export type Bundle = {"modules": Modules};
|
||||||
|
|
||||||
|
export type Modules = _.KeyedDictionary<ModulePath, Schema, _ptr>;
|
||||||
|
|
||||||
export type Schema = {"version": Version, "pointer": PointerName, "definitions": Definitions};
|
export type Schema = {"version": Version, "pointer": PointerName, "definitions": Definitions};
|
||||||
|
|
||||||
export type Version = null;
|
export type Version = null;
|
||||||
|
@ -112,6 +117,10 @@ export type ModulePath = Array<symbol>;
|
||||||
|
|
||||||
export const _toPtr = () => { throw new _.DecodeError("Pointers forbidden"); };
|
export const _toPtr = () => { throw new _.DecodeError("Pointers forbidden"); };
|
||||||
|
|
||||||
|
export function Bundle(modules: Modules): Bundle {return {"modules": modules};}
|
||||||
|
|
||||||
|
export function Modules(value: _.KeyedDictionary<ModulePath, Schema, _ptr>): Modules {return value;}
|
||||||
|
|
||||||
export function Schema(
|
export function Schema(
|
||||||
{version, pointer, definitions}: {version: Version, pointer: PointerName, definitions: Definitions}
|
{version, pointer, definitions}: {version: Version, pointer: PointerName, definitions: Definitions}
|
||||||
): Schema {return {"version": version, "pointer": pointer, "definitions": definitions};}
|
): Schema {return {"version": version, "pointer": pointer, "definitions": definitions};}
|
||||||
|
@ -189,6 +198,59 @@ export function Ref({module, name}: {module: ModulePath, name: symbol}): Ref {re
|
||||||
|
|
||||||
export function ModulePath(value: Array<symbol>): ModulePath {return value;}
|
export function ModulePath(value: Array<symbol>): ModulePath {return value;}
|
||||||
|
|
||||||
|
export function asBundle(v: _val): Bundle {
|
||||||
|
let result = toBundle(v);
|
||||||
|
if (result === void 0) throw new TypeError(`Invalid Bundle: ${_.stringify(v)}`);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function toBundle(v: _val): undefined | Bundle {
|
||||||
|
let result: undefined | Bundle;
|
||||||
|
if (_.Record.isRecord<_val, _.Tuple<_val>, _ptr>(v)) {
|
||||||
|
let _tmp0: (null) | undefined;
|
||||||
|
_tmp0 = _.is(v.label, $bundle) ? null : void 0;
|
||||||
|
if (_tmp0 !== void 0) {
|
||||||
|
let _tmp1: (Modules) | undefined;
|
||||||
|
_tmp1 = toModules(v[0]);
|
||||||
|
if (_tmp1 !== void 0) {result = {"modules": _tmp1};};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function fromBundle(_v: Bundle): _val {return _.Record($bundle, [fromModules(_v["modules"])]);}
|
||||||
|
|
||||||
|
export function asModules(v: _val): Modules {
|
||||||
|
let result = toModules(v);
|
||||||
|
if (result === void 0) throw new TypeError(`Invalid Modules: ${_.stringify(v)}`);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function toModules(v: _val): undefined | Modules {
|
||||||
|
let _tmp0: (_.KeyedDictionary<ModulePath, Schema, _ptr>) | undefined;
|
||||||
|
let result: undefined | Modules;
|
||||||
|
if (_.Dictionary.isDictionary<_ptr>(v)) {
|
||||||
|
_tmp0 = new _.KeyedDictionary();
|
||||||
|
for (const [_tmp2, _tmp1] of v) {
|
||||||
|
let _tmp3: (ModulePath) | undefined;
|
||||||
|
_tmp3 = toModulePath(_tmp2);
|
||||||
|
if (_tmp3 !== void 0) {
|
||||||
|
let _tmp4: (Schema) | undefined;
|
||||||
|
_tmp4 = toSchema(_tmp1);
|
||||||
|
if (_tmp4 !== void 0) {_tmp0.set(_tmp3, _tmp4); continue;};
|
||||||
|
};
|
||||||
|
_tmp0 = void 0;
|
||||||
|
break;
|
||||||
|
};
|
||||||
|
if (_tmp0 !== void 0) {result = _tmp0;};
|
||||||
|
};
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function fromModules(_v: Modules): _val {
|
||||||
|
return new _.Dictionary<_ptr>(_.Array.from(_v.entries()).map(([k, v]) => [fromModulePath(k), fromSchema(v)]));
|
||||||
|
}
|
||||||
|
|
||||||
export function asSchema(v: _val): Schema {
|
export function asSchema(v: _val): Schema {
|
||||||
let result = toSchema(v);
|
let result = toSchema(v);
|
||||||
if (result === void 0) throw new TypeError(`Invalid Schema: ${_.stringify(v)}`);
|
if (result === void 0) throw new TypeError(`Invalid Schema: ${_.stringify(v)}`);
|
||||||
|
@ -272,14 +334,14 @@ export function toPointerName(v: _val): undefined | PointerName {
|
||||||
if (_tmp0 !== void 0) {result = {"_variant": "Ref", "value": _tmp0};};
|
if (_tmp0 !== void 0) {result = {"_variant": "Ref", "value": _tmp0};};
|
||||||
if (result === void 0) {
|
if (result === void 0) {
|
||||||
let _tmp1: (null) | undefined;
|
let _tmp1: (null) | undefined;
|
||||||
_tmp1 = _.is(v, __lit5) ? null : void 0;
|
_tmp1 = _.is(v, __lit6) ? null : void 0;
|
||||||
if (_tmp1 !== void 0) {result = {"_variant": "false"};};
|
if (_tmp1 !== void 0) {result = {"_variant": "false"};};
|
||||||
};
|
};
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function fromPointerName(_v: PointerName): _val {
|
export function fromPointerName(_v: PointerName): _val {
|
||||||
switch (_v._variant) {case "Ref": {return fromRef(_v.value);}; case "false": {return __lit5;};};
|
switch (_v._variant) {case "Ref": {return fromRef(_v.value);}; case "false": {return __lit6;};};
|
||||||
}
|
}
|
||||||
|
|
||||||
export function asDefinitions(v: _val): Definitions {
|
export function asDefinitions(v: _val): Definitions {
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
´³schema·³pointer€³version‘³definitions·³Ref´³rec´³lit³ref„´³tupleµ´³named³module´³refµ„³
|
´³schema·³pointer€³version‘³definitions·³Ref´³rec´³lit³ref„´³tupleµ´³named³module´³refµ„³
|
||||||
ModulePath„„´³named³name´³atom³Symbol„„„„„³Schema´³rec´³lit³schema„´³tupleµ´³dict·³pointer´³refµ„³PointerName„³version´³refµ„³Version„³definitions´³refµ„³Definitions„„„„„„³Pattern´³orµµ±
SimplePattern´³refµ„³
SimplePattern„„µ±CompoundPattern´³refµ„³CompoundPattern„„„„³Version´³lit‘„³AtomKind´³orµµ±Boolean´³lit³Boolean„„µ±Float´³lit³Float„„µ±Double´³lit³Double„„µ±
SignedInteger´³lit³
SignedInteger„„µ±String´³lit³String„„µ±
|
ModulePath„„´³named³name´³atom³Symbol„„„„„³Bundle´³rec´³lit³bundle„´³tupleµ´³named³modules´³refµ„³Modules„„„„„³Schema´³rec´³lit³schema„´³tupleµ´³dict·³pointer´³refµ„³PointerName„³version´³refµ„³Version„³definitions´³refµ„³Definitions„„„„„„³Modules´³dictof´³refµ„³
|
||||||
|
ModulePath„´³refµ„³Schema„„³Pattern´³orµµ±
SimplePattern´³refµ„³
SimplePattern„„µ±CompoundPattern´³refµ„³CompoundPattern„„„„³Version´³lit‘„³AtomKind´³orµµ±Boolean´³lit³Boolean„„µ±Float´³lit³Float„„µ±Double´³lit³Double„„µ±
SignedInteger´³lit³
SignedInteger„„µ±String´³lit³String„„µ±
|
||||||
ByteString´³lit³
|
ByteString´³lit³
|
||||||
ByteString„„µ±Symbol´³lit³Symbol„„„„³
|
ByteString„„µ±Symbol´³lit³Symbol„„„„³
|
||||||
Definition´³orµµ±or´³rec´³lit³or„´³tupleµ´³tuple*µ´³named³pattern´³refµ„³NamedAlternative„„„´³named³patterns´³refµ„³NamedAlternative„„„„„„„µ±Alternative´³refµ„³Alternative„„„„³
|
Definition´³orµµ±or´³rec´³lit³or„´³tupleµ´³tuple*µ´³named³pattern´³refµ„³NamedAlternative„„„´³named³patterns´³refµ„³NamedAlternative„„„„„„„µ±Alternative´³refµ„³Alternative„„„„³
|
||||||
|
|
|
@ -2,6 +2,9 @@
|
||||||
|
|
||||||
version 1 .
|
version 1 .
|
||||||
|
|
||||||
|
Bundle = <bundle @modules Modules>.
|
||||||
|
Modules = { ModulePath: Schema ...:... }.
|
||||||
|
|
||||||
Schema = <schema {
|
Schema = <schema {
|
||||||
version: Version
|
version: Version
|
||||||
pointer: PointerName
|
pointer: PointerName
|
||||||
|
|
Loading…
Reference in New Issue