Global Dataspace and ActorSpace available
This commit is contained in:
parent
1979a439f8
commit
ed605718e5
|
@ -182,7 +182,7 @@ ${joinItems(sa.captureBinders.map(binderTypeGuard(t)), '\n')}
|
||||||
: ``;
|
: ``;
|
||||||
*/
|
*/
|
||||||
const n = spawn.name === void 0 ? '' : t` __SYNDICATE__.Turn.activeFacet.actor.name = ${walk(spawn.name)};`;
|
const n = spawn.name === void 0 ? '' : t` __SYNDICATE__.Turn.activeFacet.actor.name = ${walk(spawn.name)};`;
|
||||||
return t`__SYNDICATE__.Turn.active._spawn${spawn.linkedToken ? 'Link': ''}(() => {${n} ${inject} ${walk(spawn.body)} });`;
|
return t`__SYNDICATE__.Dataspace._spawn${spawn.linkedToken ? 'Link': ''}(() => {${n} ${inject} ${walk(spawn.body)} });`;
|
||||||
}
|
}
|
||||||
|
|
||||||
x(ctx.parser.spawn, expandSpawn);
|
x(ctx.parser.spawn, expandSpawn);
|
||||||
|
|
|
@ -29,6 +29,7 @@
|
||||||
"types": "lib/index.d.ts",
|
"types": "lib/index.d.ts",
|
||||||
"author": "Tony Garnock-Jones <tonyg@leastfixedpoint.com>",
|
"author": "Tony Garnock-Jones <tonyg@leastfixedpoint.com>",
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
|
"@preserves/core": "0.992",
|
||||||
"@preserves/schema-cli": "0.992"
|
"@preserves/schema-cli": "0.992"
|
||||||
},
|
},
|
||||||
"peerDependencies": {
|
"peerDependencies": {
|
||||||
|
|
|
@ -8,6 +8,7 @@ import { ActorSpace } from './space.js';
|
||||||
import { ActionDescription, StructuredTask, TaskAction } from './task.js';
|
import { ActionDescription, StructuredTask, TaskAction } from './task.js';
|
||||||
import { randomId } from './randomid.js';
|
import { randomId } from './randomid.js';
|
||||||
import * as Q from '../gen/queuedTasks.js';
|
import * as Q from '../gen/queuedTasks.js';
|
||||||
|
import { Dataspace } from './dataspace.js';
|
||||||
|
|
||||||
export type AnyValue = Value<Ref>;
|
export type AnyValue = Value<Ref>;
|
||||||
|
|
||||||
|
@ -101,15 +102,11 @@ export class Actor {
|
||||||
exitReason: ExitReason = null;
|
exitReason: ExitReason = null;
|
||||||
readonly exitHooks: Array<LocalAction> = [];
|
readonly exitHooks: Array<LocalAction> = [];
|
||||||
|
|
||||||
static boot(bootProc: LocalAction, space: ActorSpace, initialAssertions?: OutboundMap): Actor;
|
static boot(
|
||||||
static boot(bootProc: LocalAction, initialAssertions?: OutboundMap): Actor;
|
bootProc: LocalAction,
|
||||||
static boot(bootProc: LocalAction, spaceOrInitialAssertions?: ActorSpace | OutboundMap, initialAssertions0?: OutboundMap): Actor {
|
initialAssertions: OutboundMap = new Map(),
|
||||||
const space: ActorSpace = (spaceOrInitialAssertions && !Map.isMap(spaceOrInitialAssertions))
|
space = new ActorSpace(),
|
||||||
? spaceOrInitialAssertions
|
): Actor {
|
||||||
: new ActorSpace();
|
|
||||||
const initialAssertions: OutboundMap | undefined = (spaceOrInitialAssertions && Map.isMap(spaceOrInitialAssertions))
|
|
||||||
? spaceOrInitialAssertions
|
|
||||||
: (spaceOrInitialAssertions ? initialAssertions0 : void 0);
|
|
||||||
const newActor = new Actor(space, initialAssertions);
|
const newActor = new Actor(space, initialAssertions);
|
||||||
newActor._boot(bootProc);
|
newActor._boot(bootProc);
|
||||||
return newActor;
|
return newActor;
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
|
|
||||||
import { IdentityMap, KeyedDictionary, stringify } from '@preserves/core';
|
import { IdentityMap, KeyedDictionary, stringify } from '@preserves/core';
|
||||||
import { Index, IndexObserver } from './skeleton.js';
|
import { Index, IndexObserver } from './skeleton.js';
|
||||||
import { Actor, AnyValue, Assertion, Entity, Facet, Handle, LocalAction, Ref, Turn } from './actor.js';
|
import { Actor, AnyValue, Assertion, DetailedAction, Entity, Facet, Handle, LocalAction, Ref, Turn } from './actor.js';
|
||||||
import { Observe, toObserve } from '../gen/dataspace.js';
|
import { Observe, toObserve } from '../gen/dataspace.js';
|
||||||
import * as P from '../gen/dataspacePatterns.js';
|
import * as P from '../gen/dataspacePatterns.js';
|
||||||
|
|
||||||
|
@ -46,6 +46,36 @@ export class DataspaceObserver implements IndexObserver<Turn> {
|
||||||
}
|
}
|
||||||
|
|
||||||
export class Dataspace implements Partial<Entity> {
|
export class Dataspace implements Partial<Entity> {
|
||||||
|
private static _global: Ref | undefined = void 0;
|
||||||
|
|
||||||
|
static get global(): Ref {
|
||||||
|
if (Dataspace._global === void 0) {
|
||||||
|
Dataspace.boot(ds => {
|
||||||
|
// Cast to any because `global` is otherwise readonly (!)
|
||||||
|
Dataspace._global = ds;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
return Dataspace._global!;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Alias for syndicatec code generator to use, plus hook for fallback use outside a Turn
|
||||||
|
static _spawnLink(bootProc: LocalAction | DetailedAction): Actor | null {
|
||||||
|
if (Turn.active) {
|
||||||
|
return Turn.active._spawnLink(bootProc);
|
||||||
|
} else {
|
||||||
|
throw new Error("Cannot spawnLink outside an active Turn");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Alias for syndicatec code generator to use, plus hook for fallback use outside a Turn
|
||||||
|
static _spawn(bootProc: LocalAction | DetailedAction): Actor {
|
||||||
|
if (Turn.active) {
|
||||||
|
return Turn.active._spawn(bootProc);
|
||||||
|
} else {
|
||||||
|
return Actor.boot(bootProc, void 0, Dataspace.global.relay.actor.space);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
readonly options: DataspaceOptions;
|
readonly options: DataspaceOptions;
|
||||||
readonly index = new Index();
|
readonly index = new Index();
|
||||||
readonly handleMap = new IdentityMap<Handle, Assertion>();
|
readonly handleMap = new IdentityMap<Handle, Assertion>();
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
/// SPDX-License-Identifier: GPL-3.0-or-later
|
/// SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
/// SPDX-FileCopyrightText: Copyright © 2016-2023 Tony Garnock-Jones <tonyg@leastfixedpoint.com>
|
/// SPDX-FileCopyrightText: Copyright © 2016-2023 Tony Garnock-Jones <tonyg@leastfixedpoint.com>
|
||||||
|
|
||||||
import { randomId, Observe, FlexMap, embed, Embedded, Ref, Turn, AnyValue } from "@syndicate-lang/core";
|
import { randomId, Observe, FlexMap, embed, Embedded, Ref, Turn, AnyValue, Dataspace } from "@syndicate-lang/core";
|
||||||
import { QuasiValue as Q } from "@syndicate-lang/core";
|
import { QuasiValue as Q } from "@syndicate-lang/core";
|
||||||
|
|
||||||
import * as P from "./protocol";
|
import * as P from "./protocol";
|
||||||
|
@ -11,7 +11,7 @@ export type UIFragmentRecord = ReturnType<typeof P.UIFragment>;
|
||||||
import { HtmlFragments } from "./html";
|
import { HtmlFragments } from "./html";
|
||||||
export * from "./html";
|
export * from "./html";
|
||||||
|
|
||||||
export function boot(ds: Ref) {
|
export function boot(ds = Dataspace.global) {
|
||||||
spawnGlobalEventFactory(ds);
|
spawnGlobalEventFactory(ds);
|
||||||
spawnWindowEventFactory(ds);
|
spawnWindowEventFactory(ds);
|
||||||
spawnUIFragmentFactory(ds);
|
spawnUIFragmentFactory(ds);
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
/// SPDX-License-Identifier: GPL-3.0-or-later
|
/// SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
/// SPDX-FileCopyrightText: Copyright © 2016-2023 Tony Garnock-Jones <tonyg@leastfixedpoint.com>
|
/// SPDX-FileCopyrightText: Copyright © 2016-2023 Tony Garnock-Jones <tonyg@leastfixedpoint.com>
|
||||||
|
|
||||||
import { preserves, DoubleFloat, Observe, floatValue, Turn, Ref, Schemas } from "@syndicate-lang/core";
|
import { preserves, DoubleFloat, Observe, floatValue, Turn, Ref, Schemas, Dataspace } from "@syndicate-lang/core";
|
||||||
import { QuasiValue as Q } from "@syndicate-lang/core";
|
import { QuasiValue as Q } from "@syndicate-lang/core";
|
||||||
|
|
||||||
export message type PeriodicTick(interval: DoubleFloat);
|
export message type PeriodicTick(interval: DoubleFloat);
|
||||||
|
@ -20,7 +20,7 @@ export function sleep(ds: Ref, seconds: number, cb: () => void): void {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export function boot(ds: Ref) {
|
export function boot(ds = Dataspace.global) {
|
||||||
spawn named 'timer/PeriodicTick' {
|
spawn named 'timer/PeriodicTick' {
|
||||||
at ds {
|
at ds {
|
||||||
during Observe({
|
during Observe({
|
||||||
|
|
|
@ -4,6 +4,7 @@
|
||||||
import {
|
import {
|
||||||
Assertion,
|
Assertion,
|
||||||
Bytes,
|
Bytes,
|
||||||
|
Dataspace,
|
||||||
Embedded,
|
Embedded,
|
||||||
IdentitySet,
|
IdentitySet,
|
||||||
Observe,
|
Observe,
|
||||||
|
@ -31,7 +32,7 @@ type TransportState = {
|
||||||
peer: Ref,
|
peer: Ref,
|
||||||
};
|
};
|
||||||
|
|
||||||
export function boot(ds: Ref, debug: boolean = false, WebSocketConstructor?: typeof WebSocket) {
|
export function boot(ds = Dataspace.global, debug: boolean = false, WebSocketConstructor?: typeof WebSocket) {
|
||||||
spawn named 'transportConnector' {
|
spawn named 'transportConnector' {
|
||||||
at ds {
|
at ds {
|
||||||
during Observe({ "pattern": :pattern G.TransportConnection({
|
during Observe({ "pattern": :pattern G.TransportConnection({
|
||||||
|
|
|
@ -1403,7 +1403,7 @@
|
||||||
dependencies:
|
dependencies:
|
||||||
"@octokit/openapi-types" "^12.11.0"
|
"@octokit/openapi-types" "^12.11.0"
|
||||||
|
|
||||||
"@preserves/core@*", "@preserves/core@^0.992.3":
|
"@preserves/core@*", "@preserves/core@0.992", "@preserves/core@^0.992.3":
|
||||||
version "0.992.3"
|
version "0.992.3"
|
||||||
resolved "https://registry.yarnpkg.com/@preserves/core/-/core-0.992.3.tgz#776a43db71c95cc4d1c276ebe85aef39587a6f4c"
|
resolved "https://registry.yarnpkg.com/@preserves/core/-/core-0.992.3.tgz#776a43db71c95cc4d1c276ebe85aef39587a6f4c"
|
||||||
integrity sha512-thDNEIAvD1j4OZqAItXEdKSR/wklKp/lCY2Lxdmj8oLRM82jaTzvlvkQwUIK08zcV3QVBaIed/UeG4J1W4Jlrw==
|
integrity sha512-thDNEIAvD1j4OZqAItXEdKSR/wklKp/lCY2Lxdmj8oLRM82jaTzvlvkQwUIK08zcV3QVBaIed/UeG4J1W4Jlrw==
|
||||||
|
|
Loading…
Reference in New Issue