Browse Source

Classify source files into subdirectories

main
Tony Garnock-Jones 6 months ago
parent
commit
fa47fa3e5e
  1. 2
      package.json
  2. 2
      rollup.config.js
  3. 1
      schemas/worker.prs
  4. 10
      src/distributed/sandbox.ts
  5. 14
      src/distributed/server.ts
  6. 6
      src/examples/box.ts
  7. 6
      src/examples/client.ts
  8. 42
      src/examples/main.ts
  9. 2
      src/examples/readline.ts
  10. 6
      src/examples/secure-chat-client.ts
  11. 10
      src/examples/secure-chat-moderator.ts
  12. 8
      src/examples/simple-chat.ts
  13. 8
      src/examples/sturdy-demo.ts
  14. 2
      src/gen/box-protocol.ts
  15. 2
      src/gen/dataspace.ts
  16. 2
      src/gen/protocol.ts
  17. 2
      src/gen/secure-chat-protocol.ts
  18. 2
      src/gen/simple-chat-protocol.ts
  19. 2
      src/gen/sturdy.ts
  20. 5
      src/gen/worker.ts
  21. 0
      src/runtime/actor.ts
  22. 0
      src/runtime/bag.ts
  23. 6
      src/runtime/dataspace.ts
  24. 4
      src/runtime/rewrite.ts
  25. 0
      src/runtime/task.ts
  26. 2
      src/tools/attenuate.ts
  27. 0
      src/transport/cryptography.ts
  28. 6
      src/transport/protocol.ts
  29. 10
      src/transport/relay.ts
  30. 4
      src/transport/sturdy.ts
  31. 31
      src/worker/index.ts
  32. 4
      src/worker/wload.ts

2
package.json

@ -10,7 +10,7 @@
"@preserves/schema": "^0.4.0"
},
"scripts": {
"regenerate": "rm -rf ./src/gen && preserves-schema-ts --module Actor=./src/actor.ts --module Protocol=./src/protocol.ts --output ./src/gen './schemas/**/*.prs'",
"regenerate": "rm -rf ./src/gen && preserves-schema-ts --module Actor=./src/runtime/actor.ts --module Protocol=./src/transport/protocol.ts --output ./src/gen './schemas/**/*.prs'",
"regenerate:watch": "yarn regenerate --watch",
"regenerate:bundle": "preserves-schemac './schemas/**/*.prs' > novy-syndicate.schema.bundle.bin",
"compile": "tsc",

2
rollup.config.js

@ -1,5 +1,5 @@
export default {
input: 'lib/sturdy-demo.js',
input: 'lib/examples/sturdy-demo.js',
output: {
file: 'index.js',
format: 'umd',

1
schemas/worker.prs

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

10
src/sandbox.ts → src/distributed/sandbox.ts

@ -1,8 +1,8 @@
import { Actor, Ref, Turn } from "./actor";
import { Relay, spawnRelay } from "./relay";
import { sturdyDecode } from "./sturdy";
import { Resolve, asSturdyRef, fromResolve } from "./gen/sturdy";
import { during } from "./dataspace";
import { Actor, Ref, Turn } from "../runtime/actor";
import { Relay, spawnRelay } from "../transport/relay";
import { sturdyDecode } from "../transport/sturdy";
import { Resolve, asSturdyRef, fromResolve } from "../gen/sturdy";
import { during } from "../runtime/dataspace";
import * as net from 'net';
import { Bytes } from "@preserves/core";

14
src/server.ts → src/distributed/server.ts

@ -1,13 +1,13 @@
import { Actor, Handle, Turn } from './actor.js';
import { Dataspace, during, observe } from './dataspace.js';
import { Relay, spawnRelay } from './relay.js';
import { Actor, Handle, Turn } from '../runtime/actor.js';
import { Dataspace, during, observe } from '../runtime/dataspace.js';
import { Relay, spawnRelay } from '../transport/relay.js';
import * as net from 'net';
import { mint, sturdyEncode, validate } from './sturdy.js';
import { KEY_LENGTH } from './cryptography.js';
import { attenuate } from './rewrite.js';
import { mint, sturdyEncode, validate } from '../transport/sturdy.js';
import { KEY_LENGTH } from '../transport/cryptography.js';
import { attenuate } from '../runtime/rewrite.js';
import { Bytes, is } from '@preserves/core';
import { $bind, Attenuation, Bind, fromBind, fromSturdyRef, toBind, toResolve, _val } from './gen/sturdy.js';
import { $bind, Attenuation, Bind, fromBind, fromSturdyRef, toBind, toResolve, _val } from '../gen/sturdy.js';
new Actor(t => {
t.activeFacet.preventInertCheck();

6
src/box.ts → src/examples/box.ts

@ -1,6 +1,6 @@
import { BoxState, $SetBox, fromBoxState } from "./gen/box-protocol.js";
import { fromObserve, Observe } from "./gen/dataspace.js";
import { Assertion, Handle, Ref, Turn } from "./actor.js";
import { BoxState, $SetBox, fromBoxState } from "../gen/box-protocol.js";
import { fromObserve, Observe } from "../gen/dataspace.js";
import { Assertion, Handle, Ref, Turn } from "../runtime/actor.js";
let startTime = Date.now();
let prevValue = 0;

6
src/client.ts → src/examples/client.ts

@ -1,6 +1,6 @@
import { $BoxState, fromSetBox, SetBox } from "./gen/box-protocol.js";
import { fromObserve, Observe } from "./gen/dataspace.js";
import { Assertion, Ref, Turn } from "./actor.js";
import { $BoxState, fromSetBox, SetBox } from "../gen/box-protocol.js";
import { fromObserve, Observe } from "../gen/dataspace.js";
import { Assertion, Ref, Turn } from "../runtime/actor.js";
export default function (t: Turn, ds: Ref) {
console.log('Spawning Client');

42
src/main.ts → src/examples/main.ts

@ -1,40 +1,12 @@
import { Actor, Assertion, Ref, Turn } from './actor.js';
import { Dictionary, Record } from '@preserves/core';
import { Dataspace } from './dataspace.js';
import { Worker } from 'worker_threads';
import { Relay, spawnRelay } from './relay.js';
import { Actor, Assertion, Ref, Turn } from '../runtime/actor.js';
import { Dictionary } from '@preserves/core';
import { Dataspace } from '../runtime/dataspace.js';
import { attenuate, CRec, Lit, Pattern, PCompound, rfilter, ConstructorSpec } from '../runtime/rewrite.js';
import { $BoxState, $SetBox } from '../gen/box-protocol.js';
import { $Observe } from '../gen/dataspace.js';
import { spawnWorker } from '../worker/index.js';
import path from 'path';
import { attenuate, CRec, Lit, Pattern, PCompound, rfilter, ConstructorSpec } from './rewrite.js';
import { $BoxState, $SetBox } from './gen/box-protocol.js';
import { $Observe } from './gen/dataspace.js';
const Instance = Record.makeConstructor<{moduleName: string, arg: Assertion}>()(
Symbol.for('Instance'), ['moduleName', 'arg']);
function spawnWorker(t: Turn, moduleName: string, arg: Assertion) {
const w = new Worker(path.join(__dirname, 'wload.js'));
const reenable = t.activeFacet.preventInertCheck();
spawnRelay(t, {
packetWriter: bs => w.postMessage(bs),
setup(t: Turn, r: Relay) {
w.on('message', bs => r.accept(bs));
w.on('error', err => Turn.for(t.activeFacet, t => t.crash(err)));
w.on('exit', code => Turn.for(t.activeFacet, t => {
if (code === 0) {
t.stopActor();
} else {
t.crash(new Error(`Worker crashed with code ${code}`));
}
}));
},
initialOid: 0,
}).then(factory => {
reenable();
new Actor(t => t.assert(factory, Instance(moduleName, arg)));
});
}
function spawnModule(t: Turn, moduleName: string, arg: Assertion) {
import(moduleName).then(m => t.freshen(t => t.spawn(t => m.default(t, arg))));
}

2
src/readline.ts → src/examples/readline.ts

@ -1,4 +1,4 @@
import { Turn, Entity, Facet } from './actor.js';
import { Turn, Entity, Facet } from '../runtime/actor.js';
import readline from 'readline';
export function attachReadline(t: Turn, entity: Partial<Entity>): Facet {

6
src/secure-chat-client.ts → src/examples/secure-chat-client.ts

@ -1,6 +1,6 @@
import { $joinedUser, $says, $user, asJoin, asSays, asUserInfo, fromNickClaim, fromSays, NickClaim, Says, UserId } from "./gen/secure-chat-protocol.js";
import { during, observe } from "./dataspace.js";
import { Assertion, Ref, Turn } from "./actor.js";
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 { Assertion, Ref, Turn } from "../runtime/actor.js";
import { attachReadline } from './readline.js';
export default function (t: Turn, ds: Ref) {

10
src/secure-chat-moderator.ts → src/examples/secure-chat-moderator.ts

@ -11,11 +11,11 @@ import {
fromJoin,
fromNickConflict,
fromUserInfo,
} from "./gen/secure-chat-protocol.js";
import { Assertion, Handle, Ref, Turn } from "./actor.js";
import { observe, during, $Observe, asObserve, Dataspace } from "./dataspace.js";
import { attenuate, rfilter, pRec, pPointer, pString, pLit } from "./rewrite.js";
import { attenuate as sturdyAttenuate, fromBind, Bind, KEY_LENGTH, sturdyEncode, fromSturdyRef, mint } from "./sturdy.js";
} from "../gen/secure-chat-protocol.js";
import { Assertion, Handle, Ref, Turn } from "../runtime/actor.js";
import { observe, during, $Observe, asObserve, Dataspace } from "../runtime/dataspace.js";
import { attenuate, rfilter, pRec, pPointer, pString, pLit } from "../runtime/rewrite.js";
import { attenuate as sturdyAttenuate, fromBind, Bind, KEY_LENGTH, sturdyEncode, fromSturdyRef, mint } from "../transport/sturdy.js";
import { Bytes } from "@preserves/core";
export default function (t: Turn, gatekeeperDs: Ref) {

8
src/simple-chat.ts → src/examples/simple-chat.ts

@ -1,6 +1,6 @@
import { $Present, $Says, asPresent, asSays, fromPresent, fromSays, Present, Says } from "./gen/simple-chat-protocol.js";
import { during, observe } from "./dataspace.js";
import { Assertion, Handle, Ref, Turn } from "./actor.js";
import { $Present, $Says, asPresent, asSays, fromPresent, fromSays, Present, Says } from "../gen/simple-chat-protocol.js";
import { during, observe } from "../runtime/dataspace.js";
import { Assertion, Handle, Ref, Turn } from "../runtime/actor.js";
import { attachReadline } from './readline.js';
export default function (t: Turn, ds: Ref) {
@ -27,7 +27,7 @@ export default function (t: Turn, ds: Ref) {
});
attachReadline(t, {
retract(t) { t.stop(); },
retract(t) { t.stopActor(); },
message(t, line: string) {
if (line.toLowerCase().startsWith('/nick ')) {
updateUsername(t, line.slice(5).trimLeft());

8
src/sturdy-demo.ts → src/examples/sturdy-demo.ts

@ -1,8 +1,8 @@
import { newKey } from './cryptography.js';
import { attenuate, KEY_LENGTH, mint, Caveat, Rewrite, sturdyEncode, validate } from './sturdy.js';
import * as RW from './rewrite.js';
import { newKey } from '../transport/cryptography.js';
import { attenuate, KEY_LENGTH, mint, Caveat, Rewrite, sturdyEncode, validate } from '../transport/sturdy.js';
import * as RW from '../runtime/rewrite.js';
import { Bytes, Dictionary } from '@preserves/core';
import { Ref } from 'actor.js';
import { Ref } from '../runtime/actor.js';
async function main() {
const m1 = await mint('hello world', new Bytes(KEY_LENGTH));

2
src/gen/box-protocol.ts

@ -1,5 +1,5 @@
import * as _ from "@preserves/core";
import * as _i_Actor from "../actor";
import * as _i_Actor from "../runtime/actor";
export const $BoxState = Symbol.for("BoxState");
export const $SetBox = Symbol.for("SetBox");

2
src/gen/dataspace.ts

@ -1,5 +1,5 @@
import * as _ from "@preserves/core";
import * as _i_Actor from "../actor";
import * as _i_Actor from "../runtime/actor";
export const $Observe = Symbol.for("Observe");

2
src/gen/protocol.ts

@ -1,5 +1,5 @@
import * as _ from "@preserves/core";
import * as _i_Protocol from "../protocol";
import * as _i_Protocol from "../transport/protocol";
export const $assert = Symbol.for("assert");
export const $message = Symbol.for("message");

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

@ -1,5 +1,5 @@
import * as _ from "@preserves/core";
import * as _i_Actor from "../actor";
import * as _i_Actor from "../runtime/actor";
export const $claimNick = Symbol.for("claimNick");
export const $joinedUser = Symbol.for("joinedUser");

2
src/gen/simple-chat-protocol.ts

@ -1,5 +1,5 @@
import * as _ from "@preserves/core";
import * as _i_Actor from "../actor";
import * as _i_Actor from "../runtime/actor";
export const $Present = Symbol.for("Present");
export const $Says = Symbol.for("Says");

2
src/gen/sturdy.ts

@ -1,5 +1,5 @@
import * as _ from "@preserves/core";
import * as _i_Actor from "../actor";
import * as _i_Actor from "../runtime/actor";
export const $Boolean = Symbol.for("Boolean");
export const $ByteString = Symbol.for("ByteString");

5
src/gen/worker.ts

@ -1,15 +1,16 @@
import * as _ from "@preserves/core";
import * as _i_Actor from "../runtime/actor";
export const $Instance = Symbol.for("Instance");
export type _ptr = never;
export type _ptr = _i_Actor.Ref;
export type _val = _.Value<_ptr>;
export type Instance = {"name": string, "argument": _val};
export const _toPtr = () => { throw new _.DecodeError("Pointers forbidden"); };
export const _toPtr = (v: _val) => {let result: undefined | _ptr; result = _i_Actor.toRef(v); return result;};
export function Instance({name, argument}: {name: string, argument: _val}): Instance {return {"name": name, "argument": argument};}

0
src/actor.ts → src/runtime/actor.ts

0
src/bag.ts → src/runtime/bag.ts

6
src/dataspace.ts → src/runtime/dataspace.ts

@ -1,9 +1,9 @@
import { Assertion, Entity, Handle, LocalAction, Ref, Turn } from 'actor';
import { Assertion, Entity, Handle, LocalAction, Ref, Turn } from 'runtime/actor';
import { Dictionary, IdentityMap, is, Record, Tuple } from '@preserves/core';
import { Bag, ChangeDescription } from './bag';
import { fromObserve, toObserve, Observe } from './gen/dataspace';
export * from './gen/dataspace';
import { fromObserve, toObserve, Observe } from '../gen/dataspace';
export * from '../gen/dataspace';
// Q. Why keep "Observe"? Why not do the clever trick of asserting the
// observer, and having the dataspace read the implicit pattern it's

4
src/rewrite.ts → src/runtime/rewrite.ts

@ -23,8 +23,8 @@ import {
TRef,
Template,
_val,
} from './gen/sturdy.js';
export * from './gen/sturdy.js';
} from '../gen/sturdy.js';
export * from '../gen/sturdy.js';
export type Bindings = { [name: string]: Assertion };

0
src/task.ts → src/runtime/task.ts

2
src/tools/attenuate.ts

@ -1,5 +1,5 @@
import { Bytes, Reader } from '@preserves/core';
import { fromSturdyRef, toSturdyRef, toCaveat, attenuate, sturdyDecode, sturdyEncode } from '../sturdy.js';
import { fromSturdyRef, toSturdyRef, toCaveat, attenuate, sturdyDecode, sturdyEncode } from '../transport/sturdy.js';
const [ base, pat ] = process.argv.slice(2);
const baseCap = toSturdyRef(sturdyDecode(Bytes.fromHex(base ?? '')));

0
src/cryptography.ts → src/transport/cryptography.ts

6
src/protocol.ts → src/transport/protocol.ts

@ -1,6 +1,6 @@
import { Attenuation, toAttenuation } from './gen/sturdy.js';
import * as IO from './gen/protocol.js';
import { Assertion, Ref } from './actor.js';
import { Attenuation, toAttenuation } from '../gen/sturdy.js';
import * as IO from '../gen/protocol.js';
import { Assertion, Ref } from '../runtime/actor.js';
import { mapPointers } from '@preserves/core';
import { pointerNotAllowed } from './sturdy.js';

10
src/relay.ts → src/transport/relay.ts

@ -1,10 +1,10 @@
import { Actor, Assertion, Entity, Facet, Handle, Ref, Turn } from './actor.js';
import { Actor, Assertion, Entity, Facet, Handle, Ref, Turn } from '../runtime/actor.js';
import { BytesLike, canonicalString, Decoder, encode, FlexMap, IdentityMap, mapPointers, underlying, Value } from '@preserves/core';
import * as IO from './gen/protocol.js';
import * as IO from '../gen/protocol.js';
import { myRef, toWireRef, WireRef, WireSymbol, yourRef } from './protocol.js';
import { queueTask } from './task.js';
import { attenuate } from './rewrite.js';
import { Attenuation, fromAttenuation } from './gen/sturdy.js';
import { queueTask } from '../runtime/task.js';
import { attenuate } from '../runtime/rewrite.js';
import { Attenuation, fromAttenuation } from '../gen/sturdy.js';
import { pointerNotAllowed } from './sturdy.js';
export class SyncPeerEntity implements Entity {

4
src/sturdy.ts → src/transport/sturdy.ts

@ -8,8 +8,8 @@
import { mac } from './cryptography.js';
import { Bytes, decode, encode, is } from '@preserves/core';
import * as S from './gen/sturdy.js';
export * from './gen/sturdy.js';
import * as S from '../gen/sturdy.js';
export * from '../gen/sturdy.js';
export type SturdyValue = S._val;

31
src/worker/index.ts

@ -0,0 +1,31 @@
import { Actor, Assertion, Turn } from '../runtime/actor.js';
import { Relay, spawnRelay } from '../transport/relay.js';
import { Worker } from 'worker_threads';
import { fromInstance, Instance } from '../gen/worker.js';
import path from 'path';
export function spawnWorker(t: Turn, moduleName: string, arg: Assertion) {
const w = new Worker(path.join(__dirname, 'wload.js'));
const reenable = t.activeFacet.preventInertCheck();
spawnRelay(t, {
packetWriter: bs => w.postMessage(bs),
setup(t: Turn, r: Relay) {
w.on('message', bs => r.accept(bs));
w.on('error', err => Turn.for(t.activeFacet, t => t.crash(err)));
w.on('exit', code => Turn.for(t.activeFacet, t => {
if (code === 0) {
t.stopActor();
} else {
t.crash(new Error(`Worker crashed with code ${code}`));
}
}));
},
initialOid: 0,
}).then(factory => {
reenable();
new Actor(t => t.assert(factory, fromInstance(Instance({
name: moduleName,
argument: arg,
}))));
});
}

4
src/wload.ts → src/worker/wload.ts

@ -1,9 +1,9 @@
// Web Worker loader
import { Actor, Turn, Assertion, Ref, __setNextActorId } from './actor.js';
import { Actor, Turn, Assertion, Ref, __setNextActorId } from '../runtime/actor.js';
import { Record } from '@preserves/core';
import { parentPort, threadId } from 'worker_threads';
import { Relay, spawnRelay } from './relay.js';
import { Relay, spawnRelay } from '../transport/relay.js';
const _Instance = Symbol.for('Instance');
const Instance = Record.makeConstructor<{moduleName: string, arg: Assertion}>()(
Loading…
Cancel
Save