Browse Source

Upgrade to latest schema language including embedded interfaces

main
Tony Garnock-Jones 4 months ago
parent
commit
594fe01067
  1. 4
      package.json
  2. 4
      schemas/dataspace.prs
  3. 4
      schemas/gatekeeper.prs
  4. 2
      schemas/protocol.prs
  5. 11
      schemas/secure-chat-protocol.prs
  6. 107
      src/gen/secure-chat-protocol.ts
  7. 30
      yarn.lock

4
package.json

@ -6,8 +6,8 @@
"typescript": "^4.2.3"
},
"dependencies": {
"@preserves/core": "^0.16.0",
"@preserves/schema": "^0.13.0"
"@preserves/core": "^0.17.0",
"@preserves/schema": "^0.16.0"
},
"scripts": {
"regenerate": "rm -rf ./src/gen && preserves-schema-ts --module Actor=./src/runtime/actor.ts --output ./src/gen './schemas/**/*.prs'",

4
schemas/dataspace.prs

@ -2,8 +2,8 @@ version 1 .
embeddedType Actor.Ref .
;As implemented
Observe = <Observe @label symbol @observer embedded>.
Observe = <Observe @label symbol @observer #!any>.
; ;As will be implemented soon
; Observe = <Observe @pattern Pattern @observer embedded>.
; Observe = <Observe @pattern Pattern @observer #!any>.
.

4
schemas/gatekeeper.prs

@ -1,5 +1,5 @@
version 1 .
embeddedType Actor.Ref .
Resolve = <resolve @sturdyref sturdy.SturdyRef @observer embedded>.
Bind = <bind @oid any @key bytes @target embedded>.
Resolve = <resolve @sturdyref sturdy.SturdyRef @observer #!#!any>.
Bind = <bind @oid any @key bytes @target #!any>.

2
schemas/protocol.prs

@ -11,4 +11,4 @@ TurnEvent = [@oid Oid @event Event].
Assert = <assert @assertion Assertion @handle Handle>.
Retract = <retract @handle Handle>.
Message = <message @body Assertion>.
Sync = <sync @peer embedded>.
Sync = <sync @peer #!#t>.

11
schemas/secure-chat-protocol.prs

@ -3,9 +3,16 @@ embeddedType Actor.Ref .
UserId = int .
Join = <joinedUser @uid UserId @handle embedded>.
Join = <joinedUser @uid UserId @handle #!Session>.
NickClaim = <claimNick @uid UserId @name string @k embedded>.
Session = @observeUsers <Observe =user @observer #!UserInfo>
/ @observeSpeech <Observe =says @observer #!Says>
/ NickClaim
/ Says
.
NickClaim = <claimNick @uid UserId @name string @k #!NickClaimResponse>.
NickClaimResponse = #t / NickConflict .
UserInfo = <user @uid UserId @name string>.

107
src/gen/secure-chat-protocol.ts

@ -1,11 +1,13 @@
import * as _ from "@preserves/core";
import * as _i_Actor from "../runtime/actor";
export const $Observe = Symbol.for("Observe");
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 const __lit5 = true;
export type _embedded = _i_Actor.Ref;
@ -15,8 +17,17 @@ export type UserId = number;
export type Join = {"uid": UserId, "handle": _embedded};
export type Session = (
{"_variant": "observeUsers", "observer": _embedded} |
{"_variant": "observeSpeech", "observer": _embedded} |
{"_variant": "NickClaim", "value": NickClaim} |
{"_variant": "Says", "value": Says}
);
export type NickClaim = {"uid": UserId, "name": string, "k": _embedded};
export type NickClaimResponse = ({"_variant": "true"} | {"_variant": "NickConflict", "value": NickConflict});
export type UserInfo = {"uid": UserId, "name": string};
export type Says = {"who": UserId, "what": string};
@ -28,8 +39,20 @@ export function UserId(value: number): UserId {return value;}
export function Join({uid, handle}: {uid: UserId, handle: _embedded}): Join {return {"uid": uid, "handle": handle};}
export namespace Session {
export function observeUsers(observer: _embedded): Session {return {"_variant": "observeUsers", "observer": observer};};
export function observeSpeech(observer: _embedded): Session {return {"_variant": "observeSpeech", "observer": observer};};
export function NickClaim(value: NickClaim): Session {return {"_variant": "NickClaim", "value": value};};
export function Says(value: Says): Session {return {"_variant": "Says", "value": value};};
}
export function NickClaim({uid, name, k}: {uid: UserId, name: string, k: _embedded}): NickClaim {return {"uid": uid, "name": name, "k": k};}
export namespace NickClaimResponse {
export function $true(): NickClaimResponse {return {"_variant": "true"};};
export function NickConflict(value: NickConflict): NickClaimResponse {return {"_variant": "NickConflict", "value": value};};
}
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};}
@ -78,6 +101,64 @@ export function toJoin(v: _val): undefined | Join {
export function fromJoin(_v: Join): _val {return _.Record($joinedUser, [fromUserId(_v["uid"]), _.embed(_v["handle"])]);}
export function asSession(v: _val): Session {
let result = toSession(v);
if (result === void 0) throw new TypeError(`Invalid Session: ${_.stringify(v)}`);
return result;
}
export function toSession(v: _val): undefined | Session {
let result: undefined | Session;
if (_.Record.isRecord<_val, _.Tuple<_val>, _embedded>(v)) {
let _tmp0: (null) | undefined;
_tmp0 = _.is(v.label, $Observe) ? null : void 0;
if (_tmp0 !== void 0) {
let _tmp1: (null) | undefined;
_tmp1 = _.is(v[0], $user) ? null : void 0;
if (_tmp1 !== void 0) {
let _tmp2: (_embedded) | undefined;
_tmp2 = _.isEmbedded<_embedded>(v[1]) ? v[1].embeddedValue : void 0;
if (_tmp2 !== void 0) {result = {"_variant": "observeUsers", "observer": _tmp2};};
};
};
};
if (result === void 0) {
if (_.Record.isRecord<_val, _.Tuple<_val>, _embedded>(v)) {
let _tmp3: (null) | undefined;
_tmp3 = _.is(v.label, $Observe) ? null : void 0;
if (_tmp3 !== void 0) {
let _tmp4: (null) | undefined;
_tmp4 = _.is(v[0], $says) ? null : void 0;
if (_tmp4 !== void 0) {
let _tmp5: (_embedded) | undefined;
_tmp5 = _.isEmbedded<_embedded>(v[1]) ? v[1].embeddedValue : void 0;
if (_tmp5 !== void 0) {result = {"_variant": "observeSpeech", "observer": _tmp5};};
};
};
};
if (result === void 0) {
let _tmp6: (NickClaim) | undefined;
_tmp6 = toNickClaim(v);
if (_tmp6 !== void 0) {result = {"_variant": "NickClaim", "value": _tmp6};};
if (result === void 0) {
let _tmp7: (Says) | undefined;
_tmp7 = toSays(v);
if (_tmp7 !== void 0) {result = {"_variant": "Says", "value": _tmp7};};
};
};
};
return result;
}
export function fromSession(_v: Session): _val {
switch (_v._variant) {
case "observeUsers": {return _.Record($Observe, [$user, _.embed(_v["observer"])]);};
case "observeSpeech": {return _.Record($Observe, [$says, _.embed(_v["observer"])]);};
case "NickClaim": {return fromNickClaim(_v.value);};
case "Says": {return fromSays(_v.value);};
};
}
export function asNickClaim(v: _val): NickClaim {
let result = toNickClaim(v);
if (result === void 0) throw new TypeError(`Invalid NickClaim: ${_.stringify(v)}`);
@ -110,6 +191,32 @@ export function fromNickClaim(_v: NickClaim): _val {
return _.Record($claimNick, [fromUserId(_v["uid"]), _v["name"], _.embed(_v["k"])]);
}
export function asNickClaimResponse(v: _val): NickClaimResponse {
let result = toNickClaimResponse(v);
if (result === void 0) throw new TypeError(`Invalid NickClaimResponse: ${_.stringify(v)}`);
return result;
}
export function toNickClaimResponse(v: _val): undefined | NickClaimResponse {
let _tmp0: (null) | undefined;
let result: undefined | NickClaimResponse;
_tmp0 = _.is(v, __lit5) ? null : void 0;
if (_tmp0 !== void 0) {result = {"_variant": "true"};};
if (result === void 0) {
let _tmp1: (NickConflict) | undefined;
_tmp1 = toNickConflict(v);
if (_tmp1 !== void 0) {result = {"_variant": "NickConflict", "value": _tmp1};};
};
return result;
}
export function fromNickClaimResponse(_v: NickClaimResponse): _val {
switch (_v._variant) {
case "true": {return __lit5;};
case "NickConflict": {return fromNickConflict(_v.value);};
};
}
export function asUserInfo(v: _val): UserInfo {
let result = toUserInfo(v);
if (result === void 0) throw new TypeError(`Invalid UserInfo: ${_.stringify(v)}`);

30
yarn.lock

@ -2,17 +2,17 @@
# yarn lockfile v1
"@preserves/core@^0.16.0":
version "0.16.0"
resolved "https://registry.yarnpkg.com/@preserves/core/-/core-0.16.0.tgz#4828ecd2445bb7ba6e6d80333653d3e8e7005fe9"
integrity sha512-tW5JKvv/CmC23q/NtDv7viPutKEPZqWuDoVOndqBQK4k3E3UfgTlVpbnM3wOG9OP3icl38aY8nMtvTlJ3IWaoA==
"@preserves/core@^0.17.0":
version "0.17.0"
resolved "https://registry.yarnpkg.com/@preserves/core/-/core-0.17.0.tgz#23e7edb0a1bf5e602d210ea2ae474113d0cc5b12"
integrity sha512-ZyqsC8f08yvOn9UjaBekIhKDY44k7sWwyW2xTLfVCffFHGCPidgq6uUGKcuKAbr3ibGB7kQ6KQr/xgVAUpDC0Q==
"@preserves/schema@^0.13.0":
version "0.13.0"
resolved "https://registry.yarnpkg.com/@preserves/schema/-/schema-0.13.0.tgz#6d054a6a70a4b3133ca0a20ca0cc71fe2f23a54f"
integrity sha512-EvHiGT40fx4mvX4salwKd5gmx3znUJKxJFY1hbFdoAxXOi13Zd2B71qBMsoMJNIHARcp978G8ZJKdWJNjHkzcA==
"@preserves/schema@^0.16.0":
version "0.16.0"
resolved "https://registry.yarnpkg.com/@preserves/schema/-/schema-0.16.0.tgz#93fa31486b5d614ad2203e188be311f834ddd7d7"
integrity sha512-fSCqybOlXTNJktTe+96RJiSBh8rStYJ7Hpm2DnuFAne6t5EjGaTnre15vBn/IDq92cBLS+LMOCDrc4IojAXTkw==
dependencies:
"@preserves/core" "^0.16.0"
"@preserves/core" "^0.17.0"
"@types/glob" "^7.1.3"
"@types/minimatch" "^3.0.3"
chalk "^4.1.0"
@ -35,9 +35,9 @@
integrity sha512-1z8k4wzFnNjVK/tlxvrWuK5WMt6mydWWP7+zvH5eFep4oj+UkrfiJTRtjCeBXNpwaA/FYqqtb4/QS4ianFpIRA==
"@types/node@*":
version "15.3.1"
resolved "https://registry.yarnpkg.com/@types/node/-/node-15.3.1.tgz#23a06b87eedb524016616e886b116b8fdcb180af"
integrity sha512-weaeiP4UF4XgF++3rpQhpIJWsCTS4QJw5gvBhQu6cFIxTwyxWIe3xbnrY/o2lTCQ0lsdb8YIUDUvLR4Vuz5rbw==
version "15.6.1"
resolved "https://registry.yarnpkg.com/@types/node/-/node-15.6.1.tgz#32d43390d5c62c5b6ec486a9bc9c59544de39a08"
integrity sha512-7EIraBEyRHEe7CH+Fm1XvgqU6uwZN8Q7jppJGcqjROMT29qhAuuOxYB1uEY5UMYQKEmA5D+5tBnhdaPXSsLONA==
"@types/node@^14.14.31":
version "14.14.33"
@ -237,9 +237,9 @@ path-is-absolute@^1.0.0:
integrity sha1-F0uSaHNVNP+8es5r9TpanhtcX18=
picomatch@^2.0.4, picomatch@^2.2.1:
version "2.2.3"
resolved "https://registry.yarnpkg.com/picomatch/-/picomatch-2.2.3.tgz#465547f359ccc206d3c48e46a1bcb89bf7ee619d"
integrity sha512-KpELjfwcCDUb9PeigTs2mBJzXUPzAuP2oPcA989He8Rte0+YUAjw1JVedDhuTKPkHjSYzMN3npC9luThGYEKdg==
version "2.3.0"
resolved "https://registry.yarnpkg.com/picomatch/-/picomatch-2.3.0.tgz#f1f061de8f6a4bf022892e2d128234fb98302972"
integrity sha512-lY1Q/PiJGC2zOv/z391WOTD+Z02bCgsFfvxoXXf6h7kv9o+WmsmzYqrAwY63sNgOxE4xEdq0WyUnXfKeBrSvYw==
readdirp@~3.5.0:
version "3.5.0"

Loading…
Cancel
Save