Browse Source

Bring up to date (untested)

main
Tony Garnock-Jones 12 months ago
parent
commit
2b5e5611b3
  1. 11
      Makefile
  2. 5
      package.json
  3. 2
      protocols/schemas/examples/boxProtocol.prs
  4. 9
      schemas/dataspace.prs
  5. 5
      schemas/gatekeeper.prs
  6. 14
      schemas/protocol.prs
  7. 21
      schemas/secure-chat-protocol.prs
  8. 5
      schemas/simple-chat-protocol.prs
  9. 44
      schemas/sturdy.prs
  10. 4
      schemas/worker.prs
  11. 34
      src/distributed/server.ts
  12. 6
      src/examples/box.ts
  13. 8
      src/examples/client.ts
  14. 2
      src/examples/main.ts
  15. 52
      src/examples/secure-chat-client.ts
  16. 85
      src/examples/secure-chat-moderator.ts
  17. 20
      src/examples/simple-chat.ts
  18. 37
      src/gen/dataspace.ts
  19. 392
      src/gen/dataspacePatterns.ts
  20. 22
      src/gen/examples/boxProtocol.ts
  21. 359
      src/gen/externalProtocol.ts
  22. 45
      src/gen/gatekeeper.ts
  23. 356
      src/gen/genericProtocol.ts
  24. 359
      src/gen/internalProtocol.ts
  25. 291
      src/gen/protocol.ts
  26. 35
      src/gen/racketEvent.ts
  27. 106
      src/gen/secureChatProtocol.ts
  28. 61
      src/gen/service.ts
  29. 22
      src/gen/simpleChatProtocol.ts
  30. 401
      src/gen/stream.ts
  31. 540
      src/gen/sturdy.ts
  32. 115
      src/gen/tcp.ts
  33. 147
      src/gen/timer.ts
  34. 22
      src/gen/worker.ts
  35. 2
      src/runtime/actor.ts
  36. 103
      src/runtime/dataspace.ts
  37. 8
      src/runtime/rewrite.ts
  38. 4
      src/transport/protocol.ts
  39. 2
      src/transport/relay.ts
  40. 4
      src/transport/sturdy.ts

11
Makefile

@ -0,0 +1,11 @@ @@ -0,0 +1,11 @@
all:
yarn run build
clean:
yarn run clean
pull-protocols:
git subtree pull -P protocols \
-m 'Merge latest changes from the syndicate-protocols repository' \
git@git.syndicate-lang.org:syndicate-lang/syndicate-protocols \
main

5
package.json

@ -10,14 +10,13 @@ @@ -10,14 +10,13 @@
"@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'",
"regenerate": "rm -rf ./src/gen && preserves-schema-ts --module EntityRef=./src/runtime/actor.ts --output ./src/gen './protocols/schemas/**/*.prs'",
"regenerate:watch": "yarn regenerate --watch",
"regenerate:bundle": "preserves-schemac './schemas/**/*.prs' > novy-syndicate.schema.bundle.bin",
"compile": "tsc",
"compile:watch": "tsc -w",
"rollup": "rollup -c",
"rollup:watch": "rollup -c -w",
"clean": "rm -rf lib index.js",
"build": "yarn regenerate && yarn regenerate:bundle && yarn compile && yarn rollup"
"build": "yarn regenerate && yarn compile && yarn rollup"
}
}

2
schemas/box-protocol.prs → protocols/schemas/examples/boxProtocol.prs

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
version 1 .
embeddedType Actor.Ref .
embeddedType EntityRef.Ref .
BoxState = <BoxState @value int>.
SetBox = <SetBox @value int>.

9
schemas/dataspace.prs

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

5
schemas/gatekeeper.prs

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

14
schemas/protocol.prs

@ -1,14 +0,0 @@ @@ -1,14 +0,0 @@
version 1 .
embeddedType sturdy.WireRef .
Assertion = any .
Handle = int .
Event = Assert / Retract / Message / Sync .
Oid = int .
Turn = [TurnEvent ...].
TurnEvent = [@oid Oid @event Event].
Assert = <assert @assertion Assertion @handle Handle>.
Retract = <retract @handle Handle>.
Message = <message @body Assertion>.
Sync = <sync @peer #!#t>.

21
schemas/secure-chat-protocol.prs

@ -1,21 +0,0 @@ @@ -1,21 +0,0 @@
version 1 .
embeddedType Actor.Ref .
UserId = int .
Join = <joinedUser @uid UserId @handle #!Session>.
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>.
Says = <says @who UserId @what string>.
NickConflict = <nickConflict>.

5
schemas/simple-chat-protocol.prs

@ -1,5 +0,0 @@ @@ -1,5 +0,0 @@
version 1 .
embeddedType Actor.Ref .
Present = <Present @username string>.
Says = <Says @who string @what string>.

44
schemas/sturdy.prs

@ -1,44 +0,0 @@ @@ -1,44 +0,0 @@
version 1 .
embeddedType Actor.Ref .
; Each Attenuation is a stage. The sequence of Attenuations is run RIGHT-TO-LEFT.
; That is, the newest Attenuations are at the right.
SturdyRef = <ref @oid any @caveatChain [Attenuation ...] @sig bytes>.
; An individual Attenuation is run RIGHT-TO-LEFT.
; That is, the newest Caveats are at the right.
Attenuation = [Caveat ...].
; embodies 1st-party caveats over assertion structure, but nothing else
; can add 3rd-party caveats and richer predicates later
Caveat = Rewrite / Alts .
Rewrite = <rewrite @pattern Pattern @template Template>.
Alts = <or @alternatives [Rewrite ...]>.
Oid = int .
WireRef = @mine [0 @oid Oid] / @yours [1 @oid Oid @attenuation Caveat ...].
;---------------------------------------------------------------------------
ConstructorSpec = CRec / CArr / CDict .
CRec = <rec @label any @arity int>.
CArr = <arr @arity int>.
CDict = <dict>.
Lit = <lit @value any>.
Pattern = PDiscard / PAtom / PEmbedded / PBind / PAnd / PNot / Lit / PCompound .
PDiscard = <_>.
PAtom = =Boolean / =Float / =Double / =SignedInteger / =String / =ByteString / =Symbol .
PEmbedded = =Embedded .
PBind = <bind @pattern Pattern>.
PAnd = <and @patterns [Pattern ...]>.
PNot = <not @pattern Pattern>.
PCompound = <compound @ctor ConstructorSpec @members PCompoundMembers>.
PCompoundMembers = { any: Pattern ...:... }.
Template = TAttenuate / TRef / Lit / TCompound .
TAttenuate = <attenuate @template Template @attenuation Attenuation>.
TRef = <ref @binding int>.
TCompound = <compound @ctor ConstructorSpec @members TCompoundMembers>.
TCompoundMembers = { any: Template ...:... }.

4
schemas/worker.prs

@ -1,4 +0,0 @@ @@ -1,4 +0,0 @@
version 1 .
embeddedType Actor.Ref .
Instance = <Instance @name string @argument any>.

34
src/distributed/server.ts

@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
import { Actor, Handle, Turn } from '../runtime/actor.js';
import { Dataspace, during, observe } from '../runtime/dataspace.js';
import { Actor, Handle, Ref, Turn } from '../runtime/actor.js';
import { Dataspace, during, observe, P } from '../runtime/dataspace.js';
import { Relay, spawnRelay } from '../transport/relay.js';
import * as net from 'net';
import { mint, sturdyEncode, validate } from '../transport/sturdy.js';
import { KEY_LENGTH } from '../transport/cryptography.js';
import { attenuate } from '../runtime/rewrite.js';
import { Bytes, embed, is } from '@preserves/core';
import { Attenuation, fromSturdyRef, _val } from '../gen/sturdy.js';
import { $bind, Bind, fromBind, toBind, toResolve } from '../gen/gatekeeper.js';
import { Bytes, embed, Embedded } from '@preserves/core';
import { Attenuation, fromSturdyRef } from '../gen/sturdy.js';
import { $bind, Bind, fromBind, toResolve } from '../gen/gatekeeper.js';
new Actor(t => {
t.activeFacet.preventInertCheck();
@ -44,18 +44,18 @@ new Actor(t => { @@ -44,18 +44,18 @@ new Actor(t => {
if (a === void 0) return null;
const r = a.sturdyref;
let facet = t.facet(t => {
observe(t, ds, $bind, during(async (t, b0) => {
const b = toBind(b0);
if (b === void 0) return null;
if (!is(r.oid, b.oid)) return null;
if (!await validate(r, b.key)) return null;
const cavs: Attenuation = [];
r.caveatChain.forEach(cs => cavs.push(... cs));
const attenuated_ds = attenuate(b.target, ... cavs);
let replyHandle: Handle | undefined;
t.freshen(t => replyHandle = t.assert(a.observer, embed(attenuated_ds)));
return t => t.retract(replyHandle);
}));
observe(t, ds, P.rec($bind, P.lit(r.oid), P.bind('key'), P.bind('target')),
during(async (t, bindings) => {
const [key, embeddedTarget] = bindings as [Bytes, Embedded<Ref>];
const target = embeddedTarget.embeddedValue;
if (!await validate(r, key)) return null;
const cavs: Attenuation = [];
r.caveatChain.forEach(cs => cavs.push(... cs));
const attenuated_ds = attenuate(target, ... cavs);
let replyHandle: Handle | undefined;
t.freshen(t => replyHandle = t.assert(a.observer, embed(attenuated_ds)));
return t => t.retract(replyHandle);
}));
});
return t => t.stop(facet);
})),

6
src/examples/box.ts

@ -1,6 +1,6 @@ @@ -1,6 +1,6 @@
import { Embedded } from "@preserves/core";
import { BoxState, $SetBox, fromBoxState } from "../gen/box-protocol.js";
import { fromObserve, Observe } from "../gen/dataspace.js";
import { BoxState, $SetBox, fromBoxState } from "../gen/examples/boxProtocol.js";
import { fromObserve, Observe, P } from "../runtime/dataspace.js";
import { Assertion, Handle, Ref, Turn } from "../runtime/actor.js";
let startTime = Date.now();
@ -18,7 +18,7 @@ export default function (t: Turn, arg: Assertion) { @@ -18,7 +18,7 @@ export default function (t: Turn, arg: Assertion) {
}
setValue(t, 0);
t.assert(ds, fromObserve(Observe({
label: $SetBox,
pattern: P.rec($SetBox, P.bind('newValue', P.discard())),
observer: t.ref({
message(t: Turn, [newValue]: [number]): void {
// console.log(`Box ${t.actor.id}: got ${newValue}`);

8
src/examples/client.ts

@ -1,6 +1,6 @@ @@ -1,6 +1,6 @@
import { Embedded } from "@preserves/core";
import { $BoxState, fromSetBox, SetBox } from "../gen/box-protocol.js";
import { fromObserve, Observe } from "../gen/dataspace.js";
import { $BoxState, fromSetBox, SetBox } from "../gen/examples/boxProtocol.js";
import { fromObserve, Observe, P } from "../runtime/dataspace.js";
import { Assertion, Ref, Turn } from "../runtime/actor.js";
export default function (t: Turn, ds_p: Embedded<Ref>) {
@ -8,7 +8,7 @@ export default function (t: Turn, ds_p: Embedded<Ref>) { @@ -8,7 +8,7 @@ export default function (t: Turn, ds_p: Embedded<Ref>) {
console.log('Spawning Client');
let count = 0;
t.assert(ds, fromObserve(Observe({
label: $BoxState,
pattern: P.rec($BoxState, P.bind('currentValue', P.discard())),
observer: t.ref({
assert(t: Turn, [currentValue]: [number]): void {
// console.log(`Client ${t.actor.id}: got ${currentValue}`);
@ -17,7 +17,7 @@ export default function (t: Turn, ds_p: Embedded<Ref>) { @@ -17,7 +17,7 @@ export default function (t: Turn, ds_p: Embedded<Ref>) {
})
})));
t.assert(ds, fromObserve(Observe({
label: $BoxState,
pattern: P.rec($BoxState, P.discard()),
observer: t.ref({
assert(_t: Turn, _assertion: Assertion): void {
count++;

2
src/examples/main.ts

@ -2,7 +2,7 @@ import { Actor, Assertion, Turn } from '../runtime/actor.js'; @@ -2,7 +2,7 @@ import { Actor, Assertion, Turn } from '../runtime/actor.js';
import { Dictionary, embed } from '@preserves/core';
import { Dataspace } from '../runtime/dataspace.js';
import { _embedded, attenuate, CRec, Lit, Pattern, PCompound, rfilter, ConstructorSpec } from '../runtime/rewrite.js';
import { $BoxState, $SetBox } from '../gen/box-protocol.js';
import { $BoxState, $SetBox } from '../gen/examples/boxProtocol.js';
import { $Observe } from '../gen/dataspace.js';
import { spawnWorker } from '../worker/index.js';
import path from 'path';

52
src/examples/secure-chat-client.ts

@ -1,16 +1,17 @@ @@ -1,16 +1,17 @@
import { $joinedUser, $says, $user, asJoin, asSays, asUserInfo, fromNickClaim, fromSays, NickClaim, Says, UserId } from "../gen/secure-chat-protocol.js";
import { during, observe } from "../runtime/dataspace.js";
import { $joinedUser, $says, $user, fromNickClaim, fromSays, NickClaim, Says, UserId } from "../gen/secureChatProtocol.js";
import { during, observe, P } from "../runtime/dataspace.js";
import { Assertion, Ref, Turn } from "../runtime/actor.js";
import { attachReadline } from './readline.js';
import { Embedded } from "@preserves/core";
export default function (t: Turn, ds_ptr: Embedded<Ref>) {
const ds = ds_ptr.embeddedValue;
observe(t, ds, $joinedUser, during(async (t, j0) => {
const j = asJoin(j0);
const facet = t.facet(t => runSession(t, j.uid, j.handle));
return t => t.stop(facet);
}));
observe(t, ds, P.rec($joinedUser, P.bind('uid', P.discard()), P.bind('handle', P.discard())),
during(async (t, bindings) => {
let [uid, handle] = bindings as [UserId, Ref];
const facet = t.facet(t => runSession(t, uid, handle));
return t => t.stop(facet);
}));
}
function runSession(t: Turn, uid: UserId, session: Ref) {
@ -39,25 +40,26 @@ function runSession(t: Turn, uid: UserId, session: Ref) { @@ -39,25 +40,26 @@ function runSession(t: Turn, uid: UserId, session: Ref) {
updateUsername(t, 'user' + process.pid);
const users = new Map<UserId, string>();
observe(t, session, $user, during(async (_t, ui0) => {
const ui = asUserInfo(ui0);
const oldName = users.get(ui.uid);
console.log(oldName === void 0
? `${ui.name} arrived`
: `${oldName} changed name to ${ui.name}`);
users.set(ui.uid, ui.name);
return (_t) => {
if (users.get(ui.uid) === ui.name) {
console.log(`${ui.name} departed`);
users.delete(ui.uid);
}
};
}));
observe(t, session, P.rec($user, P.bind('uid', P.discard()), P.bind('name', P.discard())),
during(async (_t, bindings) => {
let [uid, name] = bindings as [UserId, string];
const oldName = users.get(uid);
console.log(oldName === void 0
? `${name} arrived`
: `${oldName} changed name to ${name}`);
users.set(uid, name);
return (_t) => {
if (users.get(uid) === name) {
console.log(`${name} departed`);
users.delete(uid);
}
};
}));
observe(t, session, $says, {
message(_t: Turn, u0: Assertion): void {
const u = asSays(u0);
console.log(`${users.get(u.who) ?? `<unknown ${u.who}>`}: ${u.what}`);
observe(t, session, P.rec($says, P.bind('who', P.discard()), P.bind('what', P.discard())), {
message(_t: Turn, bindings: Assertion): void {
let [who, what] = bindings as [UserId, string];
console.log(`${users.get(who) ?? `<unknown ${who}>`}: ${what}`);
},
});

85
src/examples/secure-chat-moderator.ts

@ -7,14 +7,13 @@ import { @@ -7,14 +7,13 @@ import {
NickConflict,
UserId,
UserInfo,
asNickClaim,
fromJoin,
fromNickConflict,
fromUserInfo,
} from "../gen/secure-chat-protocol.js";
} from "../gen/secureChatProtocol.js";
import { Assertion, Handle, Ref, Turn } from "../runtime/actor.js";
import { observe, during, $Observe, asObserve, Dataspace } from "../runtime/dataspace.js";
import { attenuate, rfilter, pRec, pEmbedded, pString, pLit } from "../runtime/rewrite.js";
import { observe, during, $Observe, Dataspace, P, $rec, $compound } from "../runtime/dataspace.js";
import { attenuate, rfilter, pRec, pEmbedded, pString, pLit, pDiscard } from "../runtime/rewrite.js";
import { attenuate as sturdyAttenuate, KEY_LENGTH, sturdyEncode, fromSturdyRef, mint } from "../transport/sturdy.js";
import { Bind, fromBind } from "../gen/gatekeeper.js";
import { Bytes, Embedded } from "@preserves/core";
@ -28,7 +27,11 @@ export default function (t: Turn, gatekeeperDs_ptr: Embedded<Ref>) { @@ -28,7 +27,11 @@ export default function (t: Turn, gatekeeperDs_ptr: Embedded<Ref>) {
const chatKey = new Bytes(KEY_LENGTH);
t.assert(gatekeeperDs, fromBind(Bind({ oid: chatOid, key: chatKey, target: ds })));
mint(chatOid, chatKey).then(async r => {
r = await sturdyAttenuate(r, rfilter(pRec($Observe, pLit($joinedUser), pEmbedded())));
r = await sturdyAttenuate(r, rfilter(pRec($Observe,
pRec($compound,
pRec($rec, pLit($joinedUser), pLit(2)),
pDiscard()),
pEmbedded())));
console.log(fromSturdyRef(r).asPreservesText());
console.log(sturdyEncode(fromSturdyRef(r)).toHex());
});
@ -36,39 +39,45 @@ export default function (t: Turn, gatekeeperDs_ptr: Embedded<Ref>) { @@ -36,39 +39,45 @@ export default function (t: Turn, gatekeeperDs_ptr: Embedded<Ref>) {
const nicks = new Map<string, UserId>();
let nextUserId: UserId = 0;
observe(t, ds, $Observe, during(async (t, o0) => {
const o = asObserve(o0);
if (o.label !== $joinedUser) return null;
observe(t, ds, P.rec($Observe,
P.rec($compound,
P.rec($rec, P.lit($joinedUser), P.lit(2)),
P.discard()),
P.bind('observer', P.discard())),
during(async (t, bindings) => {
const [embeddedObserver] = bindings as [Embedded<Ref>];
const observer = embeddedObserver.embeddedValue;
const uid: UserId = nextUserId++;
const f = t.facet(t => {
t.assert(o.observer, fromJoin(Join({
uid,
handle: attenuate(ds, rfilter(
pRec($Observe, pLit($user), pEmbedded()),
pRec($Observe, pLit($says), pEmbedded()),
pRec($claimNick, pLit(uid), pString(), pEmbedded()),
pRec($says, pLit(uid), pString()))),
})));
let infoHandle: Handle | undefined;
let nick: string | undefined;
observe(t, ds, $claimNick, {
assert(t: Turn, c0: Assertion): void {
const c = asNickClaim(c0);
if (c.uid !== uid) return;
if (nicks.has(c.name)) {
t.message(c.k, fromNickConflict(NickConflict()));
} else {
t.message(c.k, true);
if (nick !== void 0) nicks.delete(nick);
infoHandle = t.replace(ds, infoHandle, fromUserInfo(UserInfo(c)));
nick = c.name;
nicks.set(nick, uid);
}
}
});
});
const uid: UserId = nextUserId++;
const f = t.facet(t => {
t.assert(observer, fromJoin(Join({
uid,
handle: attenuate(ds, rfilter(
pRec($Observe, pLit($user), pEmbedded()),
pRec($Observe, pLit($says), pEmbedded()),
pRec($claimNick, pLit(uid), pString(), pEmbedded()),
pRec($says, pLit(uid), pString()))),
})));
let infoHandle: Handle | undefined;
let nick: string | undefined;
observe(t, ds, P.rec($claimNick, P.lit(uid), P.bind('name'), P.bind('k')), {
assert(t: Turn, bindings: Assertion): void {
const [name, embeddedK] = bindings as [string, Embedded<Ref>];
const k = embeddedK.embeddedValue;
if (nicks.has(name)) {
t.message(k, fromNickConflict(NickConflict()));
} else {
t.message(k, true);
if (nick !== void 0) nicks.delete(nick);
infoHandle = t.replace(ds, infoHandle,
fromUserInfo(UserInfo({ uid, name })));
nick = name;
nicks.set(nick, uid);
}
}
});
});
return t => t.stop(f);
}));
return t => t.stop(f);
}));
}

20
src/examples/simple-chat.ts

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
import { $Present, $Says, asPresent, asSays, fromPresent, fromSays, Present, Says } from "../gen/simple-chat-protocol.js";
import { during, observe } from "../runtime/dataspace.js";
import { $Present, $Says, fromPresent, fromSays, Present, Says } from "../gen/simpleChatProtocol.js";
import { during, observe, P } from "../runtime/dataspace.js";
import { Assertion, Handle, Ref, Turn } from "../runtime/actor.js";
import { attachReadline } from './readline.js';
import { Embedded } from "@preserves/core";
@ -16,16 +16,16 @@ export default function (t: Turn, ds_ptr: Embedded<Ref>) { @@ -16,16 +16,16 @@ export default function (t: Turn, ds_ptr: Embedded<Ref>) {
}
updateUsername(t, 'user' + process.pid);
observe(t, ds, $Present, during(async (_t, e0) => {
const e = asPresent(e0);
console.log(`${e.username} arrived`);
return (_t) => console.log(`${e.username} departed`);
observe(t, ds, P.rec($Present, P.bind('username')), during(async (_t, bindings) => {
const [username] = bindings as [string];
console.log(`${username} arrived`);
return (_t) => console.log(`${username} departed`);
}));
observe(t, ds, $Says, {
message(_t: Turn, u0: Assertion): void {
const u = asSays(u0);
console.log(`${u.who}: ${u.what}`);
observe(t, ds, P.rec($Says, P.bind('who'), P.bind('what')), {
message(_t: Turn, bindings: Assertion): void {
const [who, what] = bindings as [string, string];
console.log(`${who}: ${what}`);
},
});

37
src/gen/dataspace.ts

@ -1,40 +1,49 @@ @@ -1,40 +1,49 @@
import * as _ from "@preserves/core";
import * as _i_Actor from "../runtime/actor";
import * as _i_EntityRef from "../runtime/actor";
import * as _i_dataspacePatterns from "./dataspacePatterns";
export const $Observe = Symbol.for("Observe");
export type _embedded = _i_Actor.Ref;
export type _embedded = _i_EntityRef.Ref;
export type _val = _.Value<_embedded>;
export type Observe<_embedded = _i_EntityRef.Ref> = {"pattern": _i_dataspacePatterns.Pattern<_embedded>, "observer": _embedded};
export type Observe = {"label": symbol, "observer": _embedded};
export function Observe<_embedded = _i_EntityRef.Ref>(
{pattern, observer}: {pattern: _i_dataspacePatterns.Pattern<_embedded>, observer: _embedded}
): Observe<_embedded> {return {"pattern": pattern, "observer": observer};}
export function Observe({label, observer}: {label: symbol, observer: _embedded}): Observe {return {"label": label, "observer": observer};}
export function asObserve(v: _val): Observe {
export function asObserve<_embedded = _i_EntityRef.Ref>(v: _.Value<_embedded>): Observe<_embedded> {
let result = toObserve(v);
if (result === void 0) throw new TypeError(`Invalid Observe: ${_.stringify(v)}`);
return result;
}
export function toObserve(v: _val): undefined | Observe {
let result: undefined | Observe;
if (_.Record.isRecord<_val, _.Tuple<_val>, _embedded>(v)) {
export function toObserve<_embedded = _i_EntityRef.Ref>(v: _.Value<_embedded>): undefined | Observe<_embedded> {
let result: undefined | Observe<_embedded>;
if (_.Record.isRecord<_.Value<_embedded>, _.Tuple<_.Value<_embedded>>, _embedded>(v)) {
let _tmp0: (null) | undefined;
_tmp0 = _.is(v.label, $Observe) ? null : void 0;
if (_tmp0 !== void 0) {
let _tmp1: (symbol) | undefined;
_tmp1 = typeof v[0] === 'symbol' ? v[0] : void 0;
let _tmp1: (_i_dataspacePatterns.Pattern<_embedded>) | undefined;
_tmp1 = _i_dataspacePatterns.toPattern(v[0]);
if (_tmp1 !== void 0) {
let _tmp2: (_embedded) | undefined;
_tmp2 = _.isEmbedded<_embedded>(v[1]) ? v[1].embeddedValue : void 0;
if (_tmp2 !== void 0) {result = {"label": _tmp1, "observer": _tmp2};};
if (_tmp2 !== void 0) {result = {"pattern": _tmp1, "observer": _tmp2};};
};
};
};
return result;
}
export function fromObserve(_v: Observe): _val {return _.Record($Observe, [_v["label"], _.embed(_v["observer"])]);}
export function fromObserve<_embedded = _i_EntityRef.Ref>(_v: Observe<_embedded>): _.Value<_embedded> {
return _.Record(
$Observe,
[
_i_dataspacePatterns.fromPattern<_embedded>(_v["pattern"]),
_.embed(_v["observer"])
]
);
}

392
src/gen/dataspacePatterns.ts

@ -0,0 +1,392 @@ @@ -0,0 +1,392 @@
import * as _ from "@preserves/core";
import * as _i_EntityRef from "../runtime/actor";
export const $_ = Symbol.for("_");
export const $arr = Symbol.for("arr");
export const $bind = Symbol.for("bind");
export const $compound = Symbol.for("compound");
export const $dict = Symbol.for("dict");
export const $lit = Symbol.for("lit");
export const $rec = Symbol.for("rec");
export type _embedded = _i_EntityRef.Ref;
export type Pattern<_embedded = _i_EntityRef.Ref> = (
{"_variant": "DDiscard", "value": DDiscard} |
{"_variant": "DBind", "value": DBind<_embedded>} |
{"_variant": "DLit", "value": DLit<_embedded>} |
{"_variant": "DCompound", "value": DCompound<_embedded>}
);
export type DDiscard = null;
export type DBind<_embedded = _i_EntityRef.Ref> = {"name": symbol, "pattern": Pattern<_embedded>};
export type DLit<_embedded = _i_EntityRef.Ref> = {"value": _.Value<_embedded>};
export type DCompound<_embedded = _i_EntityRef.Ref> = (
{
"_variant": "rec",
"ctor": CRec<_embedded>,
"members": _.KeyedDictionary<number, Pattern<_embedded>, _embedded>
} |
{
"_variant": "arr",
"ctor": CArr,
"members": _.KeyedDictionary<number, Pattern<_embedded>, _embedded>
} |
{
"_variant": "dict",
"ctor": CDict,
"members": _.KeyedDictionary<_.Value<_embedded>, Pattern<_embedded>, _embedded>
}
);
export type CRec<_embedded = _i_EntityRef.Ref> = {"label": _.Value<_embedded>, "arity": number};
export type CArr = {"arity": number};
export type CDict = null;
export namespace Pattern {
export function DDiscard<_embedded = _i_EntityRef.Ref>(value: DDiscard): Pattern<_embedded> {return {"_variant": "DDiscard", "value": value};};
export function DBind<_embedded = _i_EntityRef.Ref>(value: DBind<_embedded>): Pattern<_embedded> {return {"_variant": "DBind", "value": value};};
export function DLit<_embedded = _i_EntityRef.Ref>(value: DLit<_embedded>): Pattern<_embedded> {return {"_variant": "DLit", "value": value};};
export function DCompound<_embedded = _i_EntityRef.Ref>(value: DCompound<_embedded>): Pattern<_embedded> {return {"_variant": "DCompound", "value": value};};
}
export function DDiscard(): DDiscard {return null;}
export function DBind<_embedded = _i_EntityRef.Ref>({name, pattern}: {name: symbol, pattern: Pattern<_embedded>}): DBind<_embedded> {return {"name": name, "pattern": pattern};}
export function DLit<_embedded = _i_EntityRef.Ref>(value: _.Value<_embedded>): DLit<_embedded> {return {"value": value};}
export namespace DCompound {
export function rec<_embedded = _i_EntityRef.Ref>(
{ctor, members}: {
ctor: CRec<_embedded>,
members: _.KeyedDictionary<number, Pattern<_embedded>, _embedded>
}
): DCompound<_embedded> {return {"_variant": "rec", "ctor": ctor, "members": members};};
export function arr<_embedded = _i_EntityRef.Ref>(
{ctor, members}: {ctor: CArr, members: _.KeyedDictionary<number, Pattern<_embedded>, _embedded>}
): DCompound<_embedded> {return {"_variant": "arr", "ctor": ctor, "members": members};};
export function dict<_embedded = _i_EntityRef.Ref>(
{ctor, members}: {
ctor: CDict,
members: _.KeyedDictionary<_.Value<_embedded>, Pattern<_embedded>, _embedded>
}
): DCompound<_embedded> {return {"_variant": "dict", "ctor": ctor, "members": members};};
}
export function CRec<_embedded = _i_EntityRef.Ref>({label, arity}: {label: _.Value<_embedded>, arity: number}): CRec<_embedded> {return {"label": label, "arity": arity};}
export function CArr(arity: number): CArr {return {"arity": arity};}
export function CDict(): CDict {return null;}
export function asPattern<_embedded = _i_EntityRef.Ref>(v: _.Value<_embedded>): Pattern<_embedded> {
let result = toPattern(v);
if (result === void 0) throw new TypeError(`Invalid Pattern: ${_.stringify(v)}`);
return result;
}
export function toPattern<_embedded = _i_EntityRef.Ref>(v: _.Value<_embedded>): undefined | Pattern<_embedded> {
let _tmp0: (DDiscard) | undefined;
let result: undefined | Pattern<_embedded>;
_tmp0 = toDDiscard(v);
if (_tmp0 !== void 0) {result = {"_variant": "DDiscard", "value": _tmp0};};
if (result === void 0) {
let _tmp1: (DBind<_embedded>) | undefined;
_tmp1 = toDBind(v);
if (_tmp1 !== void 0) {result = {"_variant": "DBind", "value": _tmp1};};
if (result === void 0) {
let _tmp2: (DLit<_embedded>) | undefined;
_tmp2 = toDLit(v);
if (_tmp2 !== void 0) {result = {"_variant": "DLit", "value": _tmp2};};
if (result === void 0) {
let _tmp3: (DCompound<_embedded>) | undefined;
_tmp3 = toDCompound(v);
if (_tmp3 !== void 0) {result = {"_variant": "DCompound", "value": _tmp3};};
};
};
};
return result;
}
export function fromPattern<_embedded = _i_EntityRef.Ref>(_v: Pattern<_embedded>): _.Value<_embedded> {
switch (_v._variant) {
case "DDiscard": {return fromDDiscard<_embedded>(_v.value);};
case "DBind": {return fromDBind<_embedded>(_v.value);};
case "DLit": {return fromDLit<_embedded>(_v.value);};
case "DCompound": {return fromDCompound<_embedded>(_v.value);};
};
}
export function asDDiscard<_embedded = _i_EntityRef.Ref>(v: _.Value<_embedded>): DDiscard {
let result = toDDiscard(v);
if (result === void 0) throw new TypeError(`Invalid DDiscard: ${_.stringify(v)}`);
return result;
}
export function toDDiscard<_embedded = _i_EntityRef.Ref>(v: _.Value<_embedded>): undefined | DDiscard {
let result: undefined | DDiscard;
if (_.Record.isRecord<_.Value<_embedded>, _.Tuple<_.Value<_embedded>>, _embedded>(v)) {
let _tmp0: (null) | undefined;
_tmp0 = _.is(v.label, $_) ? null : void 0;
if (_tmp0 !== void 0) {result = null;};
};
return result;
}
export function fromDDiscard<_embedded = _i_EntityRef.Ref>(_v: DDiscard): _.Value<_embedded> {return _.Record($_, []);}
export function asDBind<_embedded = _i_EntityRef.Ref>(v: _.Value<_embedded>): DBind<_embedded> {
let result = toDBind(v);
if (result === void 0) throw new TypeError(`Invalid DBind: ${_.stringify(v)}`);
return result;
}
export function toDBind<_embedded = _i_EntityRef.Ref>(v: _.Value<_embedded>): undefined | DBind<_embedded> {
let result: undefined | DBind<_embedded>;
if (_.Record.isRecord<_.Value<_embedded>, _.Tuple<_.Value<_embedded>>, _embedded>(v)) {
let _tmp0: (null) | undefined;
_tmp0 = _.is(v.label, $bind) ? null : void 0;
if (_tmp0 !== void 0) {
let _tmp1: (symbol) | undefined;
_tmp1 = typeof v[0] === 'symbol' ? v[0] : void 0;
if (_tmp1 !== void 0) {
let _tmp2: (Pattern<_embedded>) | undefined;
_tmp2 = toPattern(v[1]);
if (_tmp2 !== void 0) {result = {"name": _tmp1, "pattern": _tmp2};};
};
};
};
return result;
}
export function fromDBind<_embedded = _i_EntityRef.Ref>(_v: DBind<_embedded>): _.Value<_embedded> {return _.Record($bind, [_v["name"], fromPattern<_embedded>(_v["pattern"])]);}
export function asDLit<_embedded = _i_EntityRef.Ref>(v: _.Value<_embedded>): DLit<_embedded> {
let result = toDLit(v);
if (result === void 0) throw new TypeError(`Invalid DLit: ${_.stringify(v)}`);
return result;
}
export function toDLit<_embedded = _i_EntityRef.Ref>(v: _.Value<_embedded>): undefined | DLit<_embedded> {
let result: undefined | DLit<_embedded>;
if (_.Record.isRecord<_.Value<_embedded>, _.Tuple<_.Value<_embedded>>, _embedded>(v)) {
let _tmp0: (null) | undefined;
_tmp0 = _.is(v.label, $lit) ? null : void 0;
if (_tmp0 !== void 0) {
let _tmp1: (_.Value<_embedded>) | undefined;
_tmp1 = v[0];
if (_tmp1 !== void 0) {result = {"value": _tmp1};};
};
};
return result;
}
export function fromDLit<_embedded = _i_EntityRef.Ref>(_v: DLit<_embedded>): _.Value<_embedded> {return _.Record($lit, [_v["value"]]);}
export function asDCompound<_embedded = _i_EntityRef.Ref>(v: _.Value<_embedded>): DCompound<_embedded> {
let result = toDCompound(v);
if (result === void 0) throw new TypeError(`Invalid DCompound: ${_.stringify(v)}`);
return result;
}
export function toDCompound<_embedded = _i_EntityRef.Ref>(v: _.Value<_embedded>): undefined | DCompound<_embedded> {
let result: undefined | DCompound<_embedded>;
if (_.Record.isRecord<_.Value<_embedded>, _.Tuple<_.Value<_embedded>>, _embedded>(v)) {
let _tmp0: (null) | undefined;
_tmp0 = _.is(v.label, $compound) ? null : void 0;
if (_tmp0 !== void 0) {
let _tmp1: (CRec<_embedded>) | undefined;
_tmp1 = toCRec(v[0]);
if (_tmp1 !== void 0) {
let _tmp2: (_.KeyedDictionary<number, Pattern<_embedded>, _embedded>) | undefined;
_tmp2 = void 0;
if (_.Dictionary.isDictionary<_embedded>(v[1])) {
_tmp2 = new _.KeyedDictionary();
for (const [_tmp4, _tmp3] of v[1]) {
let _tmp5: (number) | undefined;
_tmp5 = typeof _tmp4 === 'number' ? _tmp4 : void 0;
if (_tmp5 !== void 0) {
let _tmp6: (Pattern<_embedded>) | undefined;
_tmp6 = toPattern(_tmp3);
if (_tmp6 !== void 0) {_tmp2.set(_tmp5, _tmp6); continue;};
};
_tmp2 = void 0;
break;
};
};
if (_tmp2 !== void 0) {result = {"_variant": "rec", "ctor": _tmp1, "members": _tmp2};};
};
};
};
if (result === void 0) {
if (_.Record.isRecord<_.Value<_embedded>, _.Tuple<_.Value<_embedded>>, _embedded>(v)) {
let _tmp7: (null) | undefined;
_tmp7 = _.is(v.label, $compound) ? null : void 0;
if (_tmp7 !== void 0) {
let _tmp8: (CArr) | undefined;
_tmp8 = toCArr(v[0]);
if (_tmp8 !== void 0) {
let _tmp9: (_.KeyedDictionary<number, Pattern<_embedded>, _embedded>) | undefined;
_tmp9 = void 0;
if (_.Dictionary.isDictionary<_embedded>(v[1])) {
_tmp9 = new _.KeyedDictionary();
for (const [_tmp11, _tmp10] of v[1]) {
let _tmp12: (number) | undefined;
_tmp12 = typeof _tmp11 === 'number' ? _tmp11 : void 0;
if (_tmp12 !== void 0) {
let _tmp13: (Pattern<_embedded>) | undefined;
_tmp13 = toPattern(_tmp10);
if (_tmp13 !== void 0) {_tmp9.set(_tmp12, _tmp13); continue;};
};
_tmp9 = void 0;
break;
};
};
if (_tmp9 !== void 0) {result = {"_variant": "arr", "ctor": _tmp8, "members": _tmp9};};
};
};
};
if (result === void 0) {
if (_.Record.isRecord<_.Value<_embedded>, _.Tuple<_.Value<_embedded>>, _embedded>(v)) {
let _tmp14: (null) | undefined;
_tmp14 = _.is(v.label, $compound) ? null : void 0;
if (_tmp14 !== void 0) {
let _tmp15: (CDict) | undefined;
_tmp15 = toCDict(v[0]);
if (_tmp15 !== void 0) {
let _tmp16: (_.KeyedDictionary<_.Value<_embedded>, Pattern<_embedded>, _embedded>) | undefined;
_tmp16 = void 0;
if (_.Dictionary.isDictionary<_embedded>(v[1])) {
_tmp16 = new _.KeyedDictionary();
for (const [_tmp18, _tmp17] of v[1]) {
let _tmp19: (_.Value<_embedded>) | undefined;
_tmp19 = _tmp18;
if (_tmp19 !== void 0) {
let _tmp20: (Pattern<_embedded>) | undefined;
_tmp20 = toPattern(_tmp17);
if (_tmp20 !== void 0) {_tmp16.set(_tmp19, _tmp20); continue;};
};
_tmp16 = void 0;
break;
};
};
if (_tmp16 !== void 0) {result = {"_variant": "dict", "ctor": _tmp15, "members": _tmp16};};
};
};
};
};
};
return result;
}
export function fromDCompound<_embedded = _i_EntityRef.Ref>(_v: DCompound<_embedded>): _.Value<_embedded> {
switch (_v._variant) {
case "rec": {
return _.Record(
$compound,
[
fromCRec<_embedded>(_v["ctor"]),
new _.Dictionary<_embedded>(
_.Array.from(_v["members"].entries()).map(([k, v]) => [k, fromPattern<_embedded>(v)])
)
]
);
};
case "arr": {
return _.Record(
$compound,
[
fromCArr<_embedded>(_v["ctor"]),
new _.Dictionary<_embedded>(
_.Array.from(_v["members"].entries()).map(([k, v]) => [k, fromPattern<_embedded>(v)])
)
]
);
};
case "dict": {
return _.Record(
$compound,
[
fromCDict<_embedded>(_v["ctor"]),
new _.Dictionary<_embedded>(
_.Array.from(_v["members"].entries()).map(([k, v]) => [k, fromPattern<_embedded>(v)])
)
]
);
};
};
}
export function asCRec<_embedded = _i_EntityRef.Ref>(v: _.Value<_embedded>): CRec<_embedded> {
let result = toCRec(v);
if (result === void 0) throw new TypeError(`Invalid CRec: ${_.stringify(v)}`);
return result;
}
export function toCRec<_embedded = _i_EntityRef.Ref>(v: _.Value<_embedded>): undefined | CRec<_embedded> {
let result: undefined | CRec<_embedded>;
if (_.Record.isRecord<_.Value<_embedded>, _.Tuple<_.Value<_embedded>>, _embedded>(v)) {
let _tmp0: (null) | undefined;
_tmp0 = _.is(v.label, $rec) ? null : void 0;
if (_tmp0 !== void 0) {
let _tmp1: (_.Value<_embedded>) | undefined;
_tmp1 = v[0];
if (_tmp1 !== void 0) {
let _tmp2: (number) | undefined;
_tmp2 = typeof v[1] === 'number' ? v[1] : void 0;
if (_tmp2 !== void 0) {result = {"label": _tmp1, "arity": _tmp2};};
};
};
};
return result;
}
export function fromCRec<_embedded = _i_EntityRef.Ref>(_v: CRec<_embedded>): _.Value<_embedded> {return _.Record($rec, [_v["label"], _v["arity"]]);}
export function asCArr<_embedded = _i_EntityRef.Ref>(v: _.Value<_embedded>): CArr {
let result = toCArr(v);
if (result === void 0) throw new TypeError(`Invalid CArr: ${_.stringify(v)}`);
return result;
}
export function toCArr<_embedded = _i_EntityRef.Ref>(v: _.Value<_embedded>): undefined | CArr {
let result: undefined | CArr;
if (_.Record.isRecord<_.Value<_embedded>, _.Tuple<_.Value<_embedded>>, _embedded>(v)) {
let _tmp0: (null) | undefined;
_tmp0 = _.is(v.label, $arr) ? null : void 0;
if (_tmp0 !== void 0) {
let _tmp1: (number) | undefined;
_tmp1 = typeof v[0] === 'number' ? v[0] : void 0;
if (_tmp1 !== void 0) {result = {"arity": _tmp1};};
};
};
return result;
}
export function fromCArr<_embedded = _i_EntityRef.Ref>(_v: CArr): _.Value<_embedded> {return _.Record($arr, [_v["arity"]]);}
export function asCDict<_embedded = _i_EntityRef.Ref>(v: _.Value<_embedded>): CDict {
let result = toCDict(v);
if (result === void 0) throw new TypeError(`Invalid CDict: ${_.stringify(v)}`);
return result;
}
export function toCDict<_embedded = _i_EntityRef.Ref>(v: _.Value<_embedded>): undefined | CDict {
let result: undefined | CDict;
if (_.Record.isRecord<_.Value<_embedded>, _.Tuple<_.Value<_embedded>>, _embedded>(v)) {
let _tmp0: (null) | undefined;
_tmp0 = _.is(v.label, $dict) ? null : void 0;
if (_tmp0 !== void 0) {result = null;};
};
return result;
}
export function fromCDict<_embedded = _i_EntityRef.Ref>(_v: CDict): _.Value<_embedded> {return _.Record($dict, []);}

22
src/gen/box-protocol.ts → src/gen/examples/boxProtocol.ts

@ -1,12 +1,10 @@ @@ -1,12 +1,10 @@
import * as _ from "@preserves/core";
import * as _i_Actor from "../runtime/actor";
import * as _i_EntityRef from "../../runtime/actor";
export const $BoxState = Symbol.for("BoxState");
export const $SetBox = Symbol.for("SetBox");
export type _embedded = _i_Actor.Ref;
export type _val = _.Value<_embedded>;
export type _embedded = _i_EntityRef.Ref;
export type BoxState = {"value": number};
@ -17,15 +15,15 @@ export function BoxState(value: number): BoxState {return {"value": value};} @@ -17,15 +15,15 @@ export function BoxState(value: number): BoxState {return {"value": value};}
export function SetBox(value: number): SetBox {return {"value": value};}
export function asBoxState(v: _val): BoxState {
export function asBoxState<_embedded = _i_EntityRef.Ref>(v: _.Value<_embedded>): BoxState {
let result = toBoxState(v);
if (result === void 0) throw new TypeError(`Invalid BoxState: ${_.stringify(v)}`);
return result;
}
export function toBoxState(v: _val): undefined | BoxState {
export function toBoxState<_embedded = _i_EntityRef.Ref>(v: _.Value<_embedded>): undefined | BoxState {
let result: undefined | BoxState;
if (_.Record.isRecord<_val, _.Tuple<_val>, _embedded>(v)) {
if (_.Record.isRecord<_.Value<_embedded>, _.Tuple<_.Value<_embedded>>, _embedded>(v)) {
let _tmp0: (null) | undefined;
_tmp0 = _.is(v.label, $BoxState) ? null : void 0;
if (_tmp0 !== void 0) {
@ -37,17 +35,17 @@ export function toBoxState(v: _val): undefined | BoxState { @@ -37,17 +35,17 @@ export function toBoxState(v: _val): undefined | BoxState {
return result;
}
export function fromBoxState(_v: BoxState): _val {return _.Record($BoxState, [_v["value"]]);}
export function fromBoxState<_embedded = _i_EntityRef.Ref>(_v: BoxState): _.Value<_embedded> {return _.Record($BoxState, [_v["value"]]);}
export function asSetBox(v: _val): SetBox {
export function asSetBox<_embedded = _i_EntityRef.Ref>(v: _.Value<_embedded>): SetBox {
let result = toSetBox(v);
if (result === void 0) throw new TypeError(`Invalid SetBox: ${_.stringify(v)}`);
return result;
}
export function toSetBox(v: _val): undefined | SetBox {
export function toSetBox<_embedded = _i_EntityRef.Ref>(v: _.Value<_embedded>): undefined | SetBox {
let result: undefined | SetBox;
if (_.Record.isRecord<_val, _.Tuple<_val>, _embedded>(v)) {
if (_.Record.isRecord<_.Value<_embedded>, _.Tuple<_.Value<_embedded>>, _embedded>(v)) {
let _tmp0: (null) | undefined;
_tmp0 = _.is(v.label, $SetBox) ? null : void 0;
if (_tmp0 !== void 0) {
@ -59,5 +57,5 @@ export function toSetBox(v: _val): undefined | SetBox { @@ -59,5 +57,5 @@ export function toSetBox(v: _val): undefined | SetBox {
return result;
}
export function fromSetBox(_v: SetBox): _val {return _.Record($SetBox, [_v["value"]]);}
export function fromSetBox<_embedded = _i_EntityRef.Ref>(_v: SetBox): _.Value<_embedded> {return _.Record($SetBox, [_v["value"]]);}

359
src/gen/externalProtocol.ts

@ -0,0 +1,359 @@ @@ -0,0 +1,359 @@
import * as _ from "@preserves/core";
import * as _i_sturdy from "./sturdy";
export const $assert = Symbol.for("assert");
export const $error = Symbol.for("error");
export const $message = Symbol.for("message");
export const $retract = Symbol.for("retract");
export const $sync = Symbol.for("sync");
export type _embedded = _i_sturdy.WireRef;
export type Packet<_embedded = _i_sturdy.WireRef> = (
{"_variant": "Turn", "value": Turn<_embedded>} |
{"_variant": "Error", "value": Error<_embedded>}
);
export type Error<_embedded = _i_sturdy.WireRef> = {"message": string, "detail": _.Value<_embedded>};
export type Assertion<_embedded = _i_sturdy.WireRef> = _.Value<_embedded>;
export type Handle = number;
export type Event<_embedded = _i_sturdy.WireRef> = (
{"_variant": "Assert", "value": Assert<_embedded>} |
{"_variant": "Retract", "value": Retract} |
{"_variant": "Message", "value": Message<_embedded>} |
{"_variant": "Sync", "value": Sync<_embedded>}
);
export type Oid = number;
export type Turn<_embedded = _i_sturdy.WireRef> = Array<TurnEvent<_embedded>>;
export type TurnEvent<_embedded = _i_sturdy.WireRef> = {"oid": Oid, "event": Event<_embedded>};
export type Assert<_embedded = _i_sturdy.WireRef> = {"assertion": Assertion<_embedded>, "handle": Handle};
export type Retract = {"handle": Handle};
export type Message<_embedded = _i_sturdy.WireRef> = {"body": Assertion<_embedded>};
export type Sync<_embedded = _i_sturdy.WireRef> = {"peer": _embedded};
export namespace Packet {
export function Turn<_embedded = _i_sturdy.WireRef>(value: Turn<_embedded>): Packet<_embedded> {return {"_variant": "Turn", "value": value};};
export function Error<_embedded = _i_sturdy.WireRef>(value: Error<_embedded>): Packet<_embedded> {return {"_variant": "Error", "value": value};};
}
export function Error<_embedded = _i_sturdy.WireRef>({message, detail}: {message: string, detail: _.Value<_embedded>}): Error<_embedded> {return {"message": message, "detail": detail};}
export function Assertion<_embedded = _i_sturdy.WireRef>(value: _.Value<_embedded>): Assertion<_embedded> {return value;}
export function Handle(value: number): Handle {return value;}
export namespace Event {
export function Assert<_embedded = _i_sturdy.WireRef>(value: Assert<_embedded>): Event<_embedded> {return {"_variant": "Assert", "value": value};};
export function Retract<_embedded = _i_sturdy.WireRef>(value: Retract): Event<_embedded> {return {"_variant": "Retract", "value": value};};
export function Message<_embedded = _i_sturdy.WireRef>(value: Message<_embedded>): Event<_embedded> {return {"_variant": "Message", "value": value};};
export function Sync<_embedded = _i_sturdy.WireRef>(value: Sync<_embedded>): Event<_embedded> {return {"_variant": "Sync", "value": value};};
}
export function Oid(value: number): Oid {return value;}
export function Turn<_embedded = _i_sturdy.WireRef>(value: Array<TurnEvent<_embedded>>): Turn<_embedded> {return value;}
export function TurnEvent<_embedded = _i_sturdy.WireRef>({oid, event}: {oid: Oid, event: Event<_embedded>}): TurnEvent<_embedded> {return {"oid": oid, "event": event};}
export function Assert<_embedded = _i_sturdy.WireRef>({assertion, handle}: {assertion: Assertion<_embedded>, handle: Handle}): Assert<_embedded> {return {"assertion": assertion, "handle": handle};}
export function Retract(handle: Handle): Retract {return {"handle": handle};}
export function Message<_embedded = _i_sturdy.WireRef>(body: Assertion<_embedded>): Message<_embedded> {return {"body": body};}
export function Sync<_embedded = _i_sturdy.WireRef>(peer: _embedded): Sync<_embedded> {return {"peer": peer};}
export function asPacket<_embedded = _i_sturdy.WireRef>(v: _.Value<_embedded>): Packet<_embedded> {
let result = toPacket(v);
if (result === void 0) throw new TypeError(`Invalid Packet: ${_.stringify(v)}`);
return result;
}
export function toPacket<_embedded = _i_sturdy.WireRef>(v: _.Value<_embedded>): undefined | Packet<_embedded> {
let _tmp0: (Turn<_embedded>) | undefined;
let result: undefined | Packet<_embedded>;
_tmp0 = toTurn(v);
if (_tmp0 !== void 0) {result = {"_variant": "Turn", "value": _tmp0};};
if (result === void 0) {
let _tmp1: (Error<_embedded>) | undefined;
_tmp1 = toError(v);
if (_tmp1 !== void 0) {result = {"_variant": "Error", "value": _tmp1};};
};
return result;
}
export function fromPacket<_embedded = _i_sturdy.WireRef>(_v: Packet<_embedded>): _.Value<_embedded> {
switch (_v._variant) {
case "Turn": {return fromTurn<_embedded>(_v.value);};
case "Error": {return fromError<_embedded>(_v.value);};
};
}
export function asError<_embedded = _i_sturdy.WireRef>(v: _.Value<_embedded>): Error<_embedded> {
let result = toError(v);
if (result === void 0) throw new TypeError(`Invalid Error: ${_.stringify(v)}`);
return result;
}
export function toError<_embedded = _i_sturdy.WireRef>(v: _.Value<_embedded>): undefined | Error<_embedded> {
let result: undefined | Error<_embedded>;
if (_.Record.isRecord<_.Value<_embedded>, _.Tuple<_.Value<_embedded>>, _embedded>(v)) {
let _tmp0: (null) | undefined;
_tmp0 = _.is(v.label, $error) ? null : void 0;
if (_tmp0 !== void 0) {
let _tmp1: (string) | undefined;
_tmp1 = typeof v[0] === 'string' ? v[0] : void 0;
if (_tmp1 !== void 0) {
let _tmp2: (_.Value<_embedded>) | undefined;
_tmp2 = v[1];
if (_tmp2 !== void 0) {result = {"message": _tmp1, "detail": _tmp2};};
};
};
};
return result;
}
export function fromError<_embedded = _i_sturdy.WireRef>(_v: Error<_embedded>): _.Value<_embedded> {return _.Record($error, [_v["message"], _v["detail"]]);}
export function asAssertion<_embedded = _i_sturdy.WireRef>(v: _.Value<_embedded>): Assertion<_embedded> {
let result = toAssertion(v);
if (result === void 0) throw new TypeError(`Invalid Assertion: ${_.stringify(v)}`);
return result;
}
export function toAssertion<_embedded = _i_sturdy.WireRef>(v: _.Value<_embedded>): undefined | Assertion<_embedded> {
let _tmp0: (_.Value<_embedded>) | undefined;
let result: undefined | Assertion<_embedded>;
_tmp0 = v;
if (_tmp0 !== void 0) {result = _tmp0;};
return result;
}
export function fromAssertion<_embedded = _i_sturdy.WireRef>(_v: Assertion<_embedded>): _.Value<_embedded> {return _v;}
export function asHandle<_embedded = _i_sturdy.WireRef>(v: _.Value<_embedded>): Handle {
let result = toHandle(v);
if (result === void 0) throw new TypeError(`Invalid Handle: ${_.stringify(v)}`);
return result;
}
export function toHandle<_embedded = _i_sturdy.WireRef>(v: _.Value<_embedded>): undefined | Handle {
let _tmp0: (number) | undefined;
let result: undefined | Handle;
_tmp0 = typeof v === 'number' ? v : void 0;
if (_tmp0 !== void 0) {result = _tmp0;};
return result;
}
export function fromHandle<_embedded = _i_sturdy.WireRef>(_v: Handle): _.Value<_embedded> {return _v;}
export function asEvent<_embedded = _i_sturdy.WireRef>(v: _.Value<_embedded>): Event<_embedded> {
let result = toEvent(v);
if (result === void 0) throw new TypeError(`Invalid Event: ${_.stringify(v)}`);
return result;
}
export function toEvent<_embedded = _i_sturdy.WireRef>(v: _.Value<_embedded>): undefined | Event<_embedded> {
let _tmp0: (Assert<_embedded>) | undefined;
let result: undefined | Event<_embedded>;
_tmp0 = toAssert(v);
if (_tmp0 !== void 0) {result = {"_variant": "Assert", "value": _tmp0};};
if (result === void 0) {
let _tmp1: (Retract) | undefined;
_tmp1 = toRetract(v);
if (_tmp1 !== void 0) {result = {"_variant": "Retract", "value": _tmp1};};
if (result === void 0) {
let _tmp2: (Message<_embedded>) | undefined;
_tmp2 = toMessage(v);
if (_tmp2 !== void 0) {result = {"_variant": "Message", "value": _tmp2};};
if (result === void 0) {
let _tmp3: (Sync<_embedded>) | undefined;
_tmp3 = toSync(v);
if (_tmp3 !== void 0) {result = {"_variant": "Sync", "value": _tmp3};};
};
};
};
return result;
}
export function fromEvent<_embedded = _i_sturdy.WireRef>(_v: Event<_embedded>): _.Value<_embedded> {
switch (_v._variant) {
case "Assert": {return fromAssert<_embedded>(_v.value);};
case "Retract": {return fromRetract<_embedded>(_v.value);};
case "Message": {return fromMessage<_embedded>(_v.value);};
case "Sync": {return fromSync<_embedded>(_v.value);};
};
}
export function asOid<_embedded = _i_sturdy.WireRef>(v: _.Value<_embedded>): Oid {
let result = toOid(v);
if (result === void 0) throw new TypeError(`Invalid Oid: ${_.stringify(v)}`);
return result;
}
export function toOid<_embedded = _i_sturdy.WireRef>(v: _.Value<_embedded>): undefined | Oid {
let _tmp0: (number) | undefined;
let result: undefined | Oid;
_tmp0 = typeof v === 'number' ? v : void 0;
if (_tmp0 !== void 0) {result = _tmp0;};
return result;
}
export function fromOid<_embedded = _i_sturdy.WireRef>(_v: Oid): _.Value<_embedded> {return _v;}
export function asTurn<_embedded = _i_sturdy.WireRef>(v: _.Value<_embedded>): Turn<_embedded> {
let result = toTurn(v);
if (result === void 0) throw new TypeError(`Invalid Turn: ${_.stringify(v)}`);
return result;
}