Rename CoValueContent to ContentType
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
import { JsonAtom, JsonObject, JsonValue } from "./jsonValue";
|
||||
import { MultiLog, MultiLogID, TransactionID } from "./multilog";
|
||||
|
||||
export type CoValueID<T extends CoValueContent> = MultiLogID & {
|
||||
export type CoValueID<T extends ContentType> = MultiLogID & {
|
||||
readonly __type: T;
|
||||
};
|
||||
|
||||
export type CoValueContent =
|
||||
export type ContentType =
|
||||
| CoMap<{[key: string]: JsonValue}, JsonValue>
|
||||
| CoList<JsonValue, JsonValue>
|
||||
| MultiStream<JsonValue, JsonValue>
|
||||
| CoStream<JsonValue, JsonValue>
|
||||
| Static<JsonValue>;
|
||||
|
||||
type MapOp<K extends string, V extends JsonValue> = {
|
||||
@@ -204,12 +204,12 @@ export class CoList<T extends JsonValue, Meta extends JsonValue> {
|
||||
}
|
||||
}
|
||||
|
||||
export class MultiStream<T extends JsonValue, Meta extends JsonValue> {
|
||||
id: CoValueID<MultiStream<T, Meta>>;
|
||||
type: "multistream" = "multistream";
|
||||
export class CoStream<T extends JsonValue, Meta extends JsonValue> {
|
||||
id: CoValueID<CoStream<T, Meta>>;
|
||||
type: "costream" = "costream";
|
||||
|
||||
constructor(multilog: MultiLog) {
|
||||
this.id = multilog.id as CoValueID<MultiStream<T, Meta>>;
|
||||
this.id = multilog.id as CoValueID<CoStream<T, Meta>>;
|
||||
}
|
||||
|
||||
toJSON(): JsonObject {
|
||||
@@ -230,7 +230,7 @@ export class Static<T extends JsonValue> {
|
||||
}
|
||||
}
|
||||
|
||||
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");
|
||||
}
|
||||
@@ -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
|
||||
|
||||
@@ -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<CoValueContent>;
|
||||
export type JsonValue = JsonAtom | JsonArray | JsonObject | CoValueID<ContentType>;
|
||||
export type JsonArray = JsonValue[];
|
||||
export type JsonObject = { [key: string]: JsonValue; };
|
||||
|
||||
@@ -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,
|
||||
});
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { CoMap } from "./coValue";
|
||||
import { CoMap } from "./contentType";
|
||||
import { newRandomKeySecret, seal } from "./crypto";
|
||||
import {
|
||||
MultiLogID,
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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<TeamContent, {}> {
|
||||
export function expectTeamContent(content: ContentType): CoMap<TeamContent, {}> {
|
||||
if (content.type !== "comap") {
|
||||
throw new Error("Expected map");
|
||||
}
|
||||
|
||||
@@ -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",
|
||||
|
||||
Reference in New Issue
Block a user