183 lines
6.3 KiB
TypeScript
183 lines
6.3 KiB
TypeScript
|
import * as _ from "@preserves/core";
|
||
|
import * as _i_Actor from "../actor";
|
||
|
|
||
|
export const $claimNick = Symbol.for("claimNick");
|
||
|
export const $joinedUser = Symbol.for("joinedUser");
|
||
|
export const $nickConflict = Symbol.for("nickConflict");
|
||
|
export const $says = Symbol.for("says");
|
||
|
export const $user = Symbol.for("user");
|
||
|
|
||
|
export type _ptr = _i_Actor.Ref;
|
||
|
|
||
|
export type _val = _.Value<_ptr>;
|
||
|
|
||
|
export type UserId = number;
|
||
|
|
||
|
export type Join = {"uid": UserId, "handle": _ptr};
|
||
|
|
||
|
export type NickClaim = {"uid": UserId, "name": string, "k": _ptr};
|
||
|
|
||
|
export type UserInfo = {"uid": UserId, "name": string};
|
||
|
|
||
|
export type Says = {"who": UserId, "what": string};
|
||
|
|
||
|
export type NickConflict = null;
|
||
|
|
||
|
|
||
|
export const _toPtr = (v: _val) => {let result: undefined | _ptr; result = _i_Actor.toRef(v); return result;};
|
||
|
|
||
|
export function UserId(value: number): UserId {return value;}
|
||
|
|
||
|
export function Join({uid, handle}: {uid: UserId, handle: _ptr}): Join {return {"uid": uid, "handle": handle};}
|
||
|
|
||
|
export function NickClaim({uid, name, k}: {uid: UserId, name: string, k: _ptr}): NickClaim {return {"uid": uid, "name": name, "k": k};}
|
||
|
|
||
|
export function UserInfo({uid, name}: {uid: UserId, name: string}): UserInfo {return {"uid": uid, "name": name};}
|
||
|
|
||
|
export function Says({who, what}: {who: UserId, what: string}): Says {return {"who": who, "what": what};}
|
||
|
|
||
|
export function NickConflict(): NickConflict {return null;}
|
||
|
|
||
|
export function asUserId(v: _val): UserId {
|
||
|
let result = toUserId(v);
|
||
|
if (result === void 0) throw new TypeError(`Invalid UserId: ${_.stringify(v)}`);
|
||
|
return result;
|
||
|
}
|
||
|
|
||
|
export function toUserId(v: _val): undefined | UserId {
|
||
|
let _tmp0: (number) | undefined;
|
||
|
let result: undefined | UserId;
|
||
|
_tmp0 = typeof v === 'number' ? v : void 0;
|
||
|
if (_tmp0 !== void 0) {result = _tmp0;};
|
||
|
return result;
|
||
|
}
|
||
|
|
||
|
export function fromUserId(_v: UserId): _val {return _v;}
|
||
|
|
||
|
export function asJoin(v: _val): Join {
|
||
|
let result = toJoin(v);
|
||
|
if (result === void 0) throw new TypeError(`Invalid Join: ${_.stringify(v)}`);
|
||
|
return result;
|
||
|
}
|
||
|
|
||
|
export function toJoin(v: _val): undefined | Join {
|
||
|
let result: undefined | Join;
|
||
|
if (_.Record.isRecord<_val, _.Tuple<_val>, _ptr>(v)) {
|
||
|
let _tmp0: (null) | undefined;
|
||
|
_tmp0 = _.is(v.label, $joinedUser) ? null : void 0;
|
||
|
if (_tmp0 !== void 0) {
|
||
|
let _tmp1: (UserId) | undefined;
|
||
|
_tmp1 = toUserId(v[0]);
|
||
|
if (_tmp1 !== void 0) {
|
||
|
let _tmp2: (_ptr) | undefined;
|
||
|
_tmp2 = _toPtr(v[1]);
|
||
|
if (_tmp2 !== void 0) {result = {"uid": _tmp1, "handle": _tmp2};};
|
||
|
};
|
||
|
};
|
||
|
};
|
||
|
return result;
|
||
|
}
|
||
|
|
||
|
export function fromJoin(_v: Join): _val {return _.Record($joinedUser, [fromUserId(_v["uid"]), _v["handle"]]);}
|
||
|
|
||
|
export function asNickClaim(v: _val): NickClaim {
|
||
|
let result = toNickClaim(v);
|
||
|
if (result === void 0) throw new TypeError(`Invalid NickClaim: ${_.stringify(v)}`);
|
||
|
return result;
|
||
|
}
|
||
|
|
||
|
export function toNickClaim(v: _val): undefined | NickClaim {
|
||
|
let result: undefined | NickClaim;
|
||
|
if (_.Record.isRecord<_val, _.Tuple<_val>, _ptr>(v)) {
|
||
|
let _tmp0: (null) | undefined;
|
||
|
_tmp0 = _.is(v.label, $claimNick) ? null : void 0;
|
||
|
if (_tmp0 !== void 0) {
|
||
|
let _tmp1: (UserId) | undefined;
|
||
|
_tmp1 = toUserId(v[0]);
|
||
|
if (_tmp1 !== void 0) {
|
||
|
let _tmp2: (string) | undefined;
|
||
|
_tmp2 = typeof v[1] === 'string' ? v[1] : void 0;
|
||
|
if (_tmp2 !== void 0) {
|
||
|
let _tmp3: (_ptr) | undefined;
|
||
|
_tmp3 = _toPtr(v[2]);
|
||
|
if (_tmp3 !== void 0) {result = {"uid": _tmp1, "name": _tmp2, "k": _tmp3};};
|
||
|
};
|
||
|
};
|
||
|
};
|
||
|
};
|
||
|
return result;
|
||
|
}
|
||
|
|
||
|
export function fromNickClaim(_v: NickClaim): _val {return _.Record($claimNick, [fromUserId(_v["uid"]), _v["name"], _v["k"]]);}
|
||
|
|
||
|
export function asUserInfo(v: _val): UserInfo {
|
||
|
let result = toUserInfo(v);
|
||
|
if (result === void 0) throw new TypeError(`Invalid UserInfo: ${_.stringify(v)}`);
|
||
|
return result;
|
||
|
}
|
||
|
|
||
|
export function toUserInfo(v: _val): undefined | UserInfo {
|
||
|
let result: undefined | UserInfo;
|
||
|
if (_.Record.isRecord<_val, _.Tuple<_val>, _ptr>(v)) {
|
||
|
let _tmp0: (null) | undefined;
|
||
|
_tmp0 = _.is(v.label, $user) ? null : void 0;
|
||
|
if (_tmp0 !== void 0) {
|
||
|
let _tmp1: (UserId) | undefined;
|
||
|
_tmp1 = toUserId(v[0]);
|
||
|
if (_tmp1 !== void 0) {
|
||
|
let _tmp2: (string) | undefined;
|
||
|
_tmp2 = typeof v[1] === 'string' ? v[1] : void 0;
|
||
|
if (_tmp2 !== void 0) {result = {"uid": _tmp1, "name": _tmp2};};
|
||
|
};
|
||
|
};
|
||
|
};
|
||
|
return result;
|
||
|
}
|
||
|
|
||
|
export function fromUserInfo(_v: UserInfo): _val {return _.Record($user, [fromUserId(_v["uid"]), _v["name"]]);}
|
||
|
|
||
|
export function asSays(v: _val): Says {
|
||
|
let result = toSays(v);
|
||
|
if (result === void 0) throw new TypeError(`Invalid Says: ${_.stringify(v)}`);
|
||
|
return result;
|
||
|
}
|
||
|
|
||
|
export function toSays(v: _val): undefined | Says {
|
||
|
let result: undefined | Says;
|
||
|
if (_.Record.isRecord<_val, _.Tuple<_val>, _ptr>(v)) {
|
||
|
let _tmp0: (null) | undefined;
|
||
|
_tmp0 = _.is(v.label, $says) ? null : void 0;
|
||
|
if (_tmp0 !== void 0) {
|
||
|
let _tmp1: (UserId) | undefined;
|
||
|
_tmp1 = toUserId(v[0]);
|
||
|
if (_tmp1 !== void 0) {
|
||
|
let _tmp2: (string) | undefined;
|
||
|
_tmp2 = typeof v[1] === 'string' ? v[1] : void 0;
|
||
|
if (_tmp2 !== void 0) {result = {"who": _tmp1, "what": _tmp2};};
|
||
|
};
|
||
|
};
|
||
|
};
|
||
|
return result;
|
||
|
}
|
||
|
|
||
|
export function fromSays(_v: Says): _val {return _.Record($says, [fromUserId(_v["who"]), _v["what"]]);}
|
||
|
|
||
|
export function asNickConflict(v: _val): NickConflict {
|
||
|
let result = toNickConflict(v);
|
||
|
if (result === void 0) throw new TypeError(`Invalid NickConflict: ${_.stringify(v)}`);
|
||
|
return result;
|
||
|
}
|
||
|
|
||
|
export function toNickConflict(v: _val): undefined | NickConflict {
|
||
|
let result: undefined | NickConflict;
|
||
|
if (_.Record.isRecord<_val, _.Tuple<_val>, _ptr>(v)) {
|
||
|
let _tmp0: (null) | undefined;
|
||
|
_tmp0 = _.is(v.label, $nickConflict) ? null : void 0;
|
||
|
if (_tmp0 !== void 0) {result = null;};
|
||
|
};
|
||
|
return result;
|
||
|
}
|
||
|
|
||
|
export function fromNickConflict(_v: NickConflict): _val {return _.Record($nickConflict, []);}
|
||
|
|