Prepare for Preserves schema; switch to yarn

This commit is contained in:
Tony Garnock-Jones 2021-03-10 23:49:34 +01:00
parent 1b120512a8
commit 8fa737ce85
18 changed files with 71 additions and 26 deletions

1
.gitignore vendored
View File

@ -1,3 +1,4 @@
package-lock.json
node_modules/
lib/
index.js

View File

@ -1,17 +1,19 @@
{
"devDependencies": {
"@types/node": "^14.14.31",
"esm": "^3.2.25",
"rollup": "^2.40.0",
"typescript": "^4.1.5"
"typescript": "^4.2.3"
},
"dependencies": {
"preserves": "^0.7.0"
"@preserves/core": "^0.8.0",
"@preserves/schema": "^0.0.0"
},
"scripts": {
"compile": "npx tsc",
"compile:watch": "npx tsc -w",
"rollup": "npx rollup -c",
"rollup:watch": "npx rollup -c -w",
"compile": "tsc",
"compile:watch": "tsc -w",
"rollup": "rollup -c",
"rollup:watch": "rollup -c -w",
"clean": "rm -rf lib index.js"
}
}

View File

@ -1,4 +1,4 @@
import { IdentitySet, Value } from 'preserves';
import { IdentitySet, Value } from '@preserves/core';
import { Attenuation, runRewrites } from './rewrite.js';
import { queueTask } from './task.js';

View File

@ -1,6 +1,6 @@
// Bags and Deltas (which are Bags where item-counts can be negative).
import { Value, Set, Dictionary, DefaultPointer } from 'preserves';
import { Value, Set, Dictionary, DefaultPointer } from '@preserves/core';
export enum ChangeDescription {
PRESENT_TO_ABSENT = -1,

View File

@ -1,5 +1,5 @@
import { Ref } from "actor";
import { Record } from "preserves";
import { Record } from "@preserves/core";
export const _BoxState = Symbol.for('BoxState');
export const BoxState = Record.makeConstructor<{value: number}, Ref>()(

View File

@ -1,4 +1,4 @@
import { Bytes, underlying } from 'preserves';
import { Bytes, underlying } from '@preserves/core';
import * as node_crypto from 'crypto';
export const KEY_LENGTH = 16; // 128 bits

View File

@ -1,5 +1,5 @@
import { Assertion, Entity, Handle, Ref, Turn } from 'actor';
import { Dictionary, IdentityMap, is, Record, Tuple } from 'preserves';
import { Dictionary, IdentityMap, is, Record, Tuple } from '@preserves/core';
import { Bag, ChangeDescription } from './bag';
// Q. Why keep "Observe"? Why not do the clever trick of asserting the
@ -33,7 +33,7 @@ export const Observe = Record.makeConstructor<{label: Assertion, observer: Ref},
export class Dataspace implements Partial<Entity> {
readonly handleMap: IdentityMap<Handle, Record<Assertion, any, Ref>> = new IdentityMap();
readonly assertions = new Bag<Ref>();
readonly subscriptions: Dictionary<Map<Ref, Dictionary<Handle>>> = new Dictionary();
readonly subscriptions = new Dictionary<Map<Ref, Dictionary<Handle, Ref>>, Ref>();
assert(turn: Turn, rec: Assertion, handle: Handle): void {
// console.log(preserves`ds ${turn.actor.id} assert ${rec} ${handle}`);
@ -42,8 +42,8 @@ export class Dataspace implements Partial<Entity> {
if (this.assertions.change(rec, +1) !== ChangeDescription.ABSENT_TO_PRESENT) return;
if (Observe.isClassOf(rec)) {
const label = Observe._.label(rec)!;
const observer = Observe._.observer(rec) as Ref;
const seen = new Dictionary<Handle>();
const observer = Observe._.observer(rec);
const seen = new Dictionary<Handle, Ref>();
if (!this.subscriptions.has(label)) this.subscriptions.set(label, new Map());
this.subscriptions.get(label)!.set(observer, seen);
this.assertions.forEach((_count, prev) =>

View File

@ -1,5 +1,5 @@
import { Actor, Assertion, Turn } from './actor.js';
import { Dictionary, Record } from 'preserves';
import { Dictionary, Record } from '@preserves/core';
import { Dataspace, Observe } from './dataspace.js';
import { Worker } from 'worker_threads';
import { Relay, spawnRelay } from './relay.js';

View File

@ -1,6 +1,6 @@
import { Handle, Ref } from './actor.js';
import { Attenuation, Pattern, Template } from './rewrite.js';
import { Record, Value } from 'preserves';
import { Record, Value } from '@preserves/core';
export const _Assert = Symbol.for('assert');
export const _Retract = Symbol.for('retract');

View File

@ -1,5 +1,5 @@
import { Actor, Assertion, Entity, Handle, Ref, Turn } from './actor.js';
import { BytesLike, canonicalString, Decoder, encode, FlexMap, IdentityMap, mapPointers, underlying, Value } from 'preserves';
import { BytesLike, canonicalString, Decoder, encode, FlexMap, IdentityMap, mapPointers, underlying, Value } from '@preserves/core';
import {
EncodedAttenuation,
EntityMessage,

View File

@ -1,5 +1,5 @@
import type { Assertion, Bindings, Handle, Ref, Turn } from "./actor.js";
import { Dictionary, IdentityMap, is, Record, Tuple, Value } from "preserves";
import { Dictionary, IdentityMap, is, Record, Tuple, Value } from "@preserves/core";
export type Attenuation = Array<RewriteStage>; // array of stages, each a list of alternatives
export type RewriteStage = Array<Rewrite>;
@ -150,9 +150,9 @@ export function instantiate(t: Template, b: Bindings): Assertion {
const members = TCompound._.members(t);
switch (ctor.label) {
case _CRec: {
const v = Record<Assertion, any, Ref>(
const v = Record(
CRec._.label(ctor) as Assertion,
[],
[] as Assertion[],
);
v.length = CRec._.arity(ctor);
for (const [key, tt] of members) {

View File

@ -4,7 +4,7 @@ import { sturdyDecode } from "./sturdy.js";
import { Observe } from "./dataspace.js";
import * as net from 'net';
import { Bytes } from "preserves";
import { Bytes } from "@preserves/core";
const [ moduleName, hexCap ] = process.argv.slice(2);
const cap = sturdyDecode(Bytes.fromHex(hexCap ?? ''));

View File

@ -6,7 +6,7 @@ import * as net from 'net';
import { Caveat, mint, Or, Rewrite, sturdyEncode, SturdyRef, validate, _Or, _Rewrite } from './sturdy.js';
import { KEY_LENGTH } from './cryptography.js';
import { attenuate, Attenuation } from './rewrite.js';
import { Bytes, IdentityMap } from 'preserves';
import { Bytes, IdentityMap } from '@preserves/core';
const secretKey = new Bytes(KEY_LENGTH);
mint('syndicate', secretKey).then(v => {

View File

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

View File

@ -7,7 +7,7 @@
// California: Internet Society, 2014.
import { mac } from './cryptography.js';
import { Bytes, decode, encode, is, Record, Value } from 'preserves';
import { Bytes, decode, encode, is, Record, Value } from '@preserves/core';
import type { Pattern, Template } from './rewrite.js';
export type EmbeddedRef = never;

View File

@ -1,4 +1,4 @@
import { Bytes, Reader } from 'preserves';
import { Bytes, Reader } from '@preserves/core';
import { attenuate, Caveat, sturdyDecode, sturdyEncode, SturdyRef } from '../sturdy.js';
const [ base, pat ] = process.argv.slice(2);

View File

@ -1,7 +1,7 @@
// Web Worker loader
import { Actor, Turn, Assertion, Ref, __setNextActorId } from './actor.js';
import { Record } from 'preserves';
import { Record } from '@preserves/core';
import { parentPort, threadId } from 'worker_threads';
import { Relay, spawnRelay } from './relay.js';

42
yarn.lock Normal file
View File

@ -0,0 +1,42 @@
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
# yarn lockfile v1
"@preserves/core@^0.8.0":
version "0.8.0"
resolved "https://registry.yarnpkg.com/@preserves/core/-/core-0.8.0.tgz#b5e32b9907f2ba27d6753da49231a979d36d9142"
integrity sha512-0DLz6SXH7y4P3z/6jUgUx63XvHPHgqj0U7xxVJMpBrGm/xb2ZMyzMhG53qkKClUo7VoXG3rvraKiM6TNudETYA==
"@preserves/schema@^0.0.0":
version "0.0.0"
resolved "https://registry.yarnpkg.com/@preserves/schema/-/schema-0.0.0.tgz#215192e699bcec922756081cf7be86622c35c5b0"
integrity sha512-34aAVtb3SBjK6xv5DvtzHiDW5s1IKP7CbhzUEvnm9LXTsTevX7ItBHJ3wtL2+JRfT3N2GTp75z6qk6dXHvZ2FA==
dependencies:
"@preserves/core" "^0.8.0"
"@types/node@^14.14.31":
version "14.14.33"
resolved "https://registry.yarnpkg.com/@types/node/-/node-14.14.33.tgz#9e4f8c64345522e4e8ce77b334a8aaa64e2b6c78"
integrity sha512-oJqcTrgPUF29oUP8AsUqbXGJNuPutsetaa9kTQAQce5Lx5dTYWV02ScBiT/k1BX/Z7pKeqedmvp39Wu4zR7N7g==
esm@^3.2.25:
version "3.2.25"
resolved "https://registry.yarnpkg.com/esm/-/esm-3.2.25.tgz#342c18c29d56157688ba5ce31f8431fbb795cc10"
integrity sha512-U1suiZ2oDVWv4zPO56S0NcR5QriEahGtdN2OR6FiOG4WJvcjBVFB0qI4+eKoWFH483PKGuLuu6V8Z4T5g63UVA==
fsevents@~2.3.1:
version "2.3.2"
resolved "https://registry.yarnpkg.com/fsevents/-/fsevents-2.3.2.tgz#8a526f78b8fdf4623b709e0b975c52c24c02fd1a"
integrity sha512-xiqMQR4xAeHTuB9uWm+fFRcIOgKBMiOBP+eXiyT7jsgVCq1bkVygt00oASowB7EdtpOHaaPgKt812P9ab+DDKA==
rollup@^2.40.0:
version "2.41.0"
resolved "https://registry.yarnpkg.com/rollup/-/rollup-2.41.0.tgz#b2a398bbabbf227738dedaef099e494aed468982"
integrity sha512-Gk76XHTggulWPH95q8V62bw6uqDH6UGvbD6LOa3QUyhuMF3eOuaeDHR7SLm1T9faitkpNrqzUAVYx47klcMnlA==
optionalDependencies:
fsevents "~2.3.1"
typescript@^4.2.3:
version "4.2.3"
resolved "https://registry.yarnpkg.com/typescript/-/typescript-4.2.3.tgz#39062d8019912d43726298f09493d598048c1ce3"
integrity sha512-qOcYwxaByStAWrBf4x0fibwZvMRG+r4cQoTjbPtUlrWjBHbmCAww1i448U0GJ+3cNNEtebDteo/cHOR3xJ4wEw==