From 8a145941dbbfa8e979e894ca84d75ef220b917dc Mon Sep 17 00:00:00 2001 From: Anselm Date: Wed, 2 Aug 2023 16:27:59 +0100 Subject: [PATCH] Rename CoValueContent to ContentType --- README.md | 2 +- src/{coValue.test.ts => contentType.test.ts} | 0 src/{coValue.ts => contentType.ts} | 16 ++++++++-------- src/index.ts | 6 +++--- src/jsonValue.ts | 4 ++-- src/multilog.test.ts | 6 +++--- src/multilog.ts | 12 ++++++------ src/node.ts | 2 +- src/permissions.test.ts | 2 +- src/permissions.ts | 4 ++-- src/sync.test.ts | 2 +- 11 files changed, 28 insertions(+), 28 deletions(-) rename src/{coValue.test.ts => contentType.test.ts} (100%) rename src/{coValue.ts => contentType.ts} (93%) diff --git a/README.md b/README.md index 23145acbc..6b38c12ad 100644 --- a/README.md +++ b/README.md @@ -30,7 +30,7 @@ THIS IS WORK IN PROGRESS - Team (`AgentID` → `Role`) - CoList (`Immutable[]`, addressable positions, insertAfter semantics) - Agent (`{signatoryID, recipientID}[]`) -- MultiStream (independent per-session streams of `Immutable`s) +- CoStream (independent per-session streams of `Immutable`s) - Static (single addressable `Immutable`) ## Implementation Abstractions diff --git a/src/coValue.test.ts b/src/contentType.test.ts similarity index 100% rename from src/coValue.test.ts rename to src/contentType.test.ts diff --git a/src/coValue.ts b/src/contentType.ts similarity index 93% rename from src/coValue.ts rename to src/contentType.ts index ebe9e9808..c936dc950 100644 --- a/src/coValue.ts +++ b/src/contentType.ts @@ -1,14 +1,14 @@ import { JsonAtom, JsonObject, JsonValue } from "./jsonValue"; import { MultiLog, MultiLogID, TransactionID } from "./multilog"; -export type CoValueID = MultiLogID & { +export type CoValueID = MultiLogID & { readonly __type: T; }; -export type CoValueContent = +export type ContentType = | CoMap<{[key: string]: JsonValue}, JsonValue> | CoList - | MultiStream + | CoStream | Static; type MapOp = { @@ -204,12 +204,12 @@ export class CoList { } } -export class MultiStream { - id: CoValueID>; - type: "multistream" = "multistream"; +export class CoStream { + id: CoValueID>; + type: "costream" = "costream"; constructor(multilog: MultiLog) { - this.id = multilog.id as CoValueID>; + this.id = multilog.id as CoValueID>; } toJSON(): JsonObject { @@ -230,7 +230,7 @@ export class Static { } } -export function expectMap(content: CoValueContent): CoMap<{ [key: string]: string }, {}> { +export function expectMap(content: ContentType): CoMap<{ [key: string]: string }, {}> { if (content.type !== "comap") { throw new Error("Expected map"); } diff --git a/src/index.ts b/src/index.ts index 453614bc3..cc2ad60c9 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,13 +1,13 @@ -import { CoValueContent } from "./coValue"; +import { ContentType } from "./contentType"; import { JsonValue } from "./jsonValue"; import { MultiLog } from "./multilog"; import { LocalNode } from "./node"; -type Value = JsonValue | CoValueContent; +type Value = JsonValue | ContentType; export { JsonValue, - CoValueContent as CoValue, + ContentType as CoValue, Value, LocalNode, MultiLog diff --git a/src/jsonValue.ts b/src/jsonValue.ts index 9a535263c..67bc29e0c 100644 --- a/src/jsonValue.ts +++ b/src/jsonValue.ts @@ -1,6 +1,6 @@ -import { CoValueID, CoValueContent } from "./coValue"; +import { CoValueID, ContentType } from "./contentType"; export type JsonAtom = string | number | boolean | null; -export type JsonValue = JsonAtom | JsonArray | JsonObject | CoValueID; +export type JsonValue = JsonAtom | JsonArray | JsonObject | CoValueID; export type JsonArray = JsonValue[]; export type JsonObject = { [key: string]: JsonValue; }; diff --git a/src/multilog.test.ts b/src/multilog.test.ts index 09fa2aa0f..66aad04bf 100644 --- a/src/multilog.test.ts +++ b/src/multilog.test.ts @@ -18,7 +18,7 @@ test("Can create multilog with new agent credentials and add transaction to it", ); const multilog = node.createMultiLog({ - type: "multistream", + type: "costream", ruleset: { type: "unsafeAllowAll" }, meta: null, }); @@ -58,7 +58,7 @@ test("transactions with wrong signature are rejected", () => { ); const multilog = node.createMultiLog({ - type: "multistream", + type: "costream", ruleset: { type: "unsafeAllowAll" }, meta: null, }); @@ -97,7 +97,7 @@ test("transactions with correctly signed, but wrong hash are rejected", () => { ); const multilog = node.createMultiLog({ - type: "multistream", + type: "costream", ruleset: { type: "unsafeAllowAll" }, meta: null, }); diff --git a/src/multilog.ts b/src/multilog.ts index 105017178..f6a2aaf60 100644 --- a/src/multilog.ts +++ b/src/multilog.ts @@ -1,5 +1,5 @@ import { randomBytes } from "@noble/hashes/utils"; -import { CoList, CoMap, CoValueContent, Static, MultiStream } from "./coValue"; +import { CoList, CoMap, ContentType, Static, CoStream } from "./contentType"; import { Encrypted, Hash, @@ -36,7 +36,7 @@ import { MultiLogKnownState, NewContentMessage } from "./sync"; export type MultiLogID = `coval_${string}`; export type MultiLogHeader = { - type: CoValueContent["type"]; + type: ContentType["type"]; ruleset: RulesetDef; meta: JsonValue; }; @@ -94,7 +94,7 @@ export class MultiLog { node: LocalNode; header: MultiLogHeader; sessions: { [key: SessionID]: SessionLog }; - content?: CoValueContent; + content?: ContentType; constructor(header: MultiLogHeader, node: LocalNode) { this.id = multilogIDforHeader(header); @@ -260,7 +260,7 @@ export class MultiLog { ); } - getCurrentContent(): CoValueContent { + getCurrentContent(): ContentType { if (this.content) { return this.content; } @@ -269,8 +269,8 @@ export class MultiLog { this.content = new CoMap(this); } else if (this.header.type === "colist") { this.content = new CoList(this); - } else if (this.header.type === "multistream") { - this.content = new MultiStream(this); + } else if (this.header.type === "costream") { + this.content = new CoStream(this); } else if (this.header.type === "static") { this.content = new Static(this); } else { diff --git a/src/node.ts b/src/node.ts index c824702c5..db0b4649e 100644 --- a/src/node.ts +++ b/src/node.ts @@ -1,4 +1,4 @@ -import { CoMap } from "./coValue"; +import { CoMap } from "./contentType"; import { newRandomKeySecret, seal } from "./crypto"; import { MultiLogID, diff --git a/src/permissions.test.ts b/src/permissions.test.ts index 041e5a0ac..0f21679a2 100644 --- a/src/permissions.test.ts +++ b/src/permissions.test.ts @@ -6,7 +6,7 @@ import { newRandomSessionID, } from "./multilog"; import { LocalNode } from "./node"; -import { expectMap } from "./coValue"; +import { expectMap } from "./contentType"; import { expectTeamContent } from "./permissions"; import { getRecipientID, diff --git a/src/permissions.ts b/src/permissions.ts index 85ab519bc..9dc10cef0 100644 --- a/src/permissions.ts +++ b/src/permissions.ts @@ -1,4 +1,4 @@ -import { CoMap, CoValueContent, MapOpPayload } from "./coValue"; +import { CoMap, ContentType, MapOpPayload } from "./contentType"; import { JsonValue } from "./jsonValue"; import { Encrypted, @@ -215,7 +215,7 @@ export type TeamContent = { [key: AgentID]: Role } & { }; }; -export function expectTeamContent(content: CoValueContent): CoMap { +export function expectTeamContent(content: ContentType): CoMap { if (content.type !== "comap") { throw new Error("Expected map"); } diff --git a/src/sync.test.ts b/src/sync.test.ts index 1c7edbea3..56f2c758a 100644 --- a/src/sync.test.ts +++ b/src/sync.test.ts @@ -7,7 +7,7 @@ import { } from "./multilog"; import { LocalNode } from "./node"; import { Peer, SyncMessage } from "./sync"; -import { MapOpPayload, expectMap } from "./coValue"; +import { MapOpPayload, expectMap } from "./contentType"; test( "Node replies with initial tx and header to empty subscribe",