cojson 0.8.50 β 0.9.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.turbo/turbo-build.log +3 -3
- package/CHANGELOG.md +13 -0
- package/dist/native/coValue.js +6 -0
- package/dist/native/coValue.js.map +1 -1
- package/dist/native/coValueCore.js +3 -1
- package/dist/native/coValueCore.js.map +1 -1
- package/dist/native/coValues/coList.js +21 -25
- package/dist/native/coValues/coList.js.map +1 -1
- package/dist/native/coValues/coMap.js +11 -0
- package/dist/native/coValues/coMap.js.map +1 -1
- package/dist/native/coValues/coPlainText.js +86 -0
- package/dist/native/coValues/coPlainText.js.map +1 -0
- package/dist/native/coValues/group.js +26 -7
- package/dist/native/coValues/group.js.map +1 -1
- package/dist/native/coreToCoValue.js +5 -2
- package/dist/native/coreToCoValue.js.map +1 -1
- package/dist/native/crypto/WasmCrypto.js +130 -0
- package/dist/native/crypto/WasmCrypto.js.map +1 -0
- package/dist/native/crypto/export.js +3 -0
- package/dist/native/crypto/export.js.map +1 -0
- package/dist/native/exports.js +3 -3
- package/dist/native/exports.js.map +1 -1
- package/dist/web/coValue.js +6 -0
- package/dist/web/coValue.js.map +1 -1
- package/dist/web/coValueCore.js +3 -1
- package/dist/web/coValueCore.js.map +1 -1
- package/dist/web/coValues/coList.js +21 -25
- package/dist/web/coValues/coList.js.map +1 -1
- package/dist/web/coValues/coMap.js +11 -0
- package/dist/web/coValues/coMap.js.map +1 -1
- package/dist/web/coValues/coPlainText.js +86 -0
- package/dist/web/coValues/coPlainText.js.map +1 -0
- package/dist/web/coValues/group.js +26 -7
- package/dist/web/coValues/group.js.map +1 -1
- package/dist/web/coreToCoValue.js +5 -2
- package/dist/web/coreToCoValue.js.map +1 -1
- package/dist/web/crypto/export.js +3 -0
- package/dist/web/crypto/export.js.map +1 -0
- package/dist/web/exports.js +3 -3
- package/dist/web/exports.js.map +1 -1
- package/package.json +6 -1
- package/src/coValue.ts +10 -0
- package/src/coValueCore.ts +4 -1
- package/src/coValues/coList.ts +35 -35
- package/src/coValues/coMap.ts +20 -0
- package/src/coValues/coPlainText.ts +128 -0
- package/src/coValues/group.ts +34 -7
- package/src/coreToCoValue.ts +4 -2
- package/src/crypto/export.ts +2 -0
- package/src/exports.ts +7 -2
- package/src/tests/coList.test.ts +59 -0
- package/src/tests/coMap.test.ts +32 -0
- package/src/tests/coPlainText.test.ts +133 -0
package/src/exports.ts
CHANGED
|
@@ -6,14 +6,16 @@ import {
|
|
|
6
6
|
MAX_RECOMMENDED_TX_SIZE,
|
|
7
7
|
idforHeader,
|
|
8
8
|
} from "./coValueCore.js";
|
|
9
|
-
import { ControlledAgent, RawControlledAccount } from "./coValues/account.js";
|
|
10
9
|
import {
|
|
10
|
+
ControlledAgent,
|
|
11
11
|
RawAccount,
|
|
12
|
+
RawControlledAccount,
|
|
12
13
|
RawProfile,
|
|
13
14
|
accountHeaderForInitialAgentSecret,
|
|
14
15
|
} from "./coValues/account.js";
|
|
15
|
-
import { RawCoList } from "./coValues/coList.js";
|
|
16
|
+
import { OpID, RawCoList } from "./coValues/coList.js";
|
|
16
17
|
import { RawCoMap } from "./coValues/coMap.js";
|
|
18
|
+
import { RawCoPlainText, stringifyOpID } from "./coValues/coPlainText.js";
|
|
17
19
|
import {
|
|
18
20
|
CoStreamItem,
|
|
19
21
|
RawBinaryCoStream,
|
|
@@ -137,6 +139,8 @@ export {
|
|
|
137
139
|
isRawCoID,
|
|
138
140
|
LSMStorage,
|
|
139
141
|
emptyKnownState,
|
|
142
|
+
RawCoPlainText,
|
|
143
|
+
stringifyOpID,
|
|
140
144
|
};
|
|
141
145
|
|
|
142
146
|
export type {
|
|
@@ -151,6 +155,7 @@ export type {
|
|
|
151
155
|
CoValueUniqueness,
|
|
152
156
|
Stringified,
|
|
153
157
|
CoStreamItem,
|
|
158
|
+
OpID,
|
|
154
159
|
};
|
|
155
160
|
|
|
156
161
|
// eslint-disable-next-line @typescript-eslint/no-namespace
|
package/src/tests/coList.test.ts
CHANGED
|
@@ -75,6 +75,26 @@ test("Push is equivalent to append after last item", () => {
|
|
|
75
75
|
expect(content.toJSON()).toEqual(["hello", "world", "hooray"]);
|
|
76
76
|
});
|
|
77
77
|
|
|
78
|
+
test("appendItems add an array of items at the end of the list", () => {
|
|
79
|
+
const node = new LocalNode(...randomAnonymousAccountAndSessionID(), Crypto);
|
|
80
|
+
|
|
81
|
+
const coValue = node.createCoValue({
|
|
82
|
+
type: "colist",
|
|
83
|
+
ruleset: { type: "unsafeAllowAll" },
|
|
84
|
+
meta: null,
|
|
85
|
+
...Crypto.createdNowUnique(),
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
const content = expectList(coValue.getCurrentContent());
|
|
89
|
+
|
|
90
|
+
expect(content.type).toEqual("colist");
|
|
91
|
+
|
|
92
|
+
content.append("hello", 0, "trusting");
|
|
93
|
+
expect(content.toJSON()).toEqual(["hello"]);
|
|
94
|
+
content.appendItems(["world", "hooray", "universe"], undefined, "trusting");
|
|
95
|
+
expect(content.toJSON()).toEqual(["hello", "world", "hooray", "universe"]);
|
|
96
|
+
});
|
|
97
|
+
|
|
78
98
|
test("Can push into empty list", () => {
|
|
79
99
|
const node = new LocalNode(...randomAnonymousAccountAndSessionID(), Crypto);
|
|
80
100
|
|
|
@@ -92,3 +112,42 @@ test("Can push into empty list", () => {
|
|
|
92
112
|
content.append("hello", undefined, "trusting");
|
|
93
113
|
expect(content.toJSON()).toEqual(["hello"]);
|
|
94
114
|
});
|
|
115
|
+
|
|
116
|
+
test("init the list correctly", () => {
|
|
117
|
+
const node = new LocalNode(...randomAnonymousAccountAndSessionID(), Crypto);
|
|
118
|
+
|
|
119
|
+
const group = node.createGroup();
|
|
120
|
+
|
|
121
|
+
const content = group.createList(["hello", "world", "hooray", "universe"]);
|
|
122
|
+
|
|
123
|
+
expect(content.type).toEqual("colist");
|
|
124
|
+
expect(content.toJSON()).toEqual(["hello", "world", "hooray", "universe"]);
|
|
125
|
+
|
|
126
|
+
content.append("hello", content.toJSON().length - 1, "trusting");
|
|
127
|
+
expect(content.toJSON()).toEqual([
|
|
128
|
+
"hello",
|
|
129
|
+
"world",
|
|
130
|
+
"hooray",
|
|
131
|
+
"universe",
|
|
132
|
+
"hello",
|
|
133
|
+
]);
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
test("Items prepended to start appear with latest first", () => {
|
|
137
|
+
const node = new LocalNode(...randomAnonymousAccountAndSessionID(), Crypto);
|
|
138
|
+
|
|
139
|
+
const coValue = node.createCoValue({
|
|
140
|
+
type: "colist",
|
|
141
|
+
ruleset: { type: "unsafeAllowAll" },
|
|
142
|
+
meta: null,
|
|
143
|
+
...Crypto.createdNowUnique(),
|
|
144
|
+
});
|
|
145
|
+
|
|
146
|
+
const content = expectList(coValue.getCurrentContent());
|
|
147
|
+
|
|
148
|
+
content.prepend("first", 0, "trusting");
|
|
149
|
+
content.prepend("second", 0, "trusting");
|
|
150
|
+
content.prepend("third", 0, "trusting");
|
|
151
|
+
|
|
152
|
+
expect(content.toJSON()).toEqual(["third", "second", "first"]);
|
|
153
|
+
});
|
package/src/tests/coMap.test.ts
CHANGED
|
@@ -175,3 +175,35 @@ test("Can get last tx ID for a key in CoMap", () => {
|
|
|
175
175
|
content.set("hello", "C", "trusting");
|
|
176
176
|
expect(content.lastEditAt("hello")?.tx.txIndex).toEqual(2);
|
|
177
177
|
});
|
|
178
|
+
|
|
179
|
+
test("Can set items in bulk with assign", () => {
|
|
180
|
+
const node = new LocalNode(...randomAnonymousAccountAndSessionID(), Crypto);
|
|
181
|
+
|
|
182
|
+
const coValue = node.createCoValue({
|
|
183
|
+
type: "comap",
|
|
184
|
+
ruleset: { type: "unsafeAllowAll" },
|
|
185
|
+
meta: null,
|
|
186
|
+
...Crypto.createdNowUnique(),
|
|
187
|
+
});
|
|
188
|
+
|
|
189
|
+
const content = expectMap(coValue.getCurrentContent());
|
|
190
|
+
|
|
191
|
+
expect(content.type).toEqual("comap");
|
|
192
|
+
|
|
193
|
+
content.set("key1", "set1", "trusting");
|
|
194
|
+
|
|
195
|
+
content.assign(
|
|
196
|
+
{
|
|
197
|
+
key1: "assign1",
|
|
198
|
+
key2: "assign2",
|
|
199
|
+
key3: "assign3",
|
|
200
|
+
},
|
|
201
|
+
"trusting",
|
|
202
|
+
);
|
|
203
|
+
|
|
204
|
+
expect(content.toJSON()).toEqual({
|
|
205
|
+
key1: "assign1",
|
|
206
|
+
key2: "assign2",
|
|
207
|
+
key3: "assign3",
|
|
208
|
+
});
|
|
209
|
+
});
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
import { afterEach, expect, test, vi } from "vitest";
|
|
2
|
+
import { expectPlainText } from "../coValue.js";
|
|
3
|
+
import { WasmCrypto } from "../crypto/WasmCrypto.js";
|
|
4
|
+
import { LocalNode } from "../localNode.js";
|
|
5
|
+
import { randomAnonymousAccountAndSessionID } from "./testUtils.js";
|
|
6
|
+
|
|
7
|
+
const Crypto = await WasmCrypto.create();
|
|
8
|
+
|
|
9
|
+
afterEach(() => void vi.unstubAllGlobals());
|
|
10
|
+
|
|
11
|
+
test("should throw on creation if Intl.Segmenter is not available", () => {
|
|
12
|
+
vi.stubGlobal("Intl", {
|
|
13
|
+
Segmenter: undefined,
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
const node = new LocalNode(...randomAnonymousAccountAndSessionID(), Crypto);
|
|
17
|
+
const group = node.createGroup();
|
|
18
|
+
expect(() => group.createPlainText()).toThrow(
|
|
19
|
+
"Intl.Segmenter is not supported. Use a polyfill to get coPlainText support in Jazz. (eg. https://formatjs.github.io/docs/polyfills/intl-segmenter/)",
|
|
20
|
+
);
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
test("Empty CoPlainText works", () => {
|
|
24
|
+
const node = new LocalNode(...randomAnonymousAccountAndSessionID(), Crypto);
|
|
25
|
+
|
|
26
|
+
const coValue = node.createCoValue({
|
|
27
|
+
type: "coplaintext",
|
|
28
|
+
ruleset: { type: "unsafeAllowAll" },
|
|
29
|
+
meta: null,
|
|
30
|
+
...Crypto.createdNowUnique(),
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
const content = expectPlainText(coValue.getCurrentContent());
|
|
34
|
+
|
|
35
|
+
expect(content.type).toEqual("coplaintext");
|
|
36
|
+
expect(content.toString()).toEqual("");
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
test("Can insert into empty CoPlainText", () => {
|
|
40
|
+
const node = new LocalNode(...randomAnonymousAccountAndSessionID(), Crypto);
|
|
41
|
+
|
|
42
|
+
const coValue = node.createCoValue({
|
|
43
|
+
type: "coplaintext",
|
|
44
|
+
ruleset: { type: "unsafeAllowAll" },
|
|
45
|
+
meta: null,
|
|
46
|
+
...Crypto.createdNowUnique(),
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
const content = expectPlainText(coValue.getCurrentContent());
|
|
50
|
+
|
|
51
|
+
expect(content.type).toEqual("coplaintext");
|
|
52
|
+
|
|
53
|
+
content.insertAfter(0, "a", "trusting");
|
|
54
|
+
expect(content.toString()).toEqual("a");
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
test("Can insert and delete in CoPlainText", () => {
|
|
58
|
+
const node = new LocalNode(...randomAnonymousAccountAndSessionID(), Crypto);
|
|
59
|
+
|
|
60
|
+
const coValue = node.createCoValue({
|
|
61
|
+
type: "coplaintext",
|
|
62
|
+
ruleset: { type: "unsafeAllowAll" },
|
|
63
|
+
meta: null,
|
|
64
|
+
...Crypto.createdNowUnique(),
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
const content = expectPlainText(coValue.getCurrentContent());
|
|
68
|
+
|
|
69
|
+
expect(content.type).toEqual("coplaintext");
|
|
70
|
+
|
|
71
|
+
content.insertAfter(0, "hello", "trusting");
|
|
72
|
+
expect(content.toString()).toEqual("hello");
|
|
73
|
+
|
|
74
|
+
content.insertAfter(5, " world", "trusting");
|
|
75
|
+
expect(content.toString()).toEqual("hello world");
|
|
76
|
+
|
|
77
|
+
content.insertAfter(0, "Hello, ", "trusting");
|
|
78
|
+
expect(content.toString()).toEqual("Hello, hello world");
|
|
79
|
+
|
|
80
|
+
console.log("first delete");
|
|
81
|
+
content.deleteRange({ from: 6, to: 12 }, "trusting");
|
|
82
|
+
expect(content.toString()).toEqual("Hello, world");
|
|
83
|
+
|
|
84
|
+
content.insertAfter(2, "π", "trusting");
|
|
85
|
+
expect(content.toString()).toEqual("Heπllo, world");
|
|
86
|
+
|
|
87
|
+
console.log("second delete");
|
|
88
|
+
content.deleteRange({ from: 2, to: 4 }, "trusting");
|
|
89
|
+
expect(content.toString()).toEqual("Hello, world");
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
test("Multiple items appended after start appear in correct order", () => {
|
|
93
|
+
const node = new LocalNode(...randomAnonymousAccountAndSessionID(), Crypto);
|
|
94
|
+
|
|
95
|
+
const coValue = node.createCoValue({
|
|
96
|
+
type: "coplaintext",
|
|
97
|
+
ruleset: { type: "unsafeAllowAll" },
|
|
98
|
+
meta: null,
|
|
99
|
+
...Crypto.createdNowUnique(),
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
const content = expectPlainText(coValue.getCurrentContent());
|
|
103
|
+
|
|
104
|
+
// Add multiple items in a single transaction, all after start
|
|
105
|
+
content.insertAfter(0, "h", "trusting");
|
|
106
|
+
content.insertAfter(1, "e", "trusting");
|
|
107
|
+
content.insertAfter(2, "y", "trusting");
|
|
108
|
+
|
|
109
|
+
// They should appear in insertion order (hey), not reversed (yeh)
|
|
110
|
+
expect(content.toString()).toEqual("hey");
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
test("Items inserted at start appear with latest first", () => {
|
|
114
|
+
const node = new LocalNode(...randomAnonymousAccountAndSessionID(), Crypto);
|
|
115
|
+
|
|
116
|
+
const coValue = node.createCoValue({
|
|
117
|
+
type: "coplaintext",
|
|
118
|
+
ruleset: { type: "unsafeAllowAll" },
|
|
119
|
+
meta: null,
|
|
120
|
+
...Crypto.createdNowUnique(),
|
|
121
|
+
});
|
|
122
|
+
|
|
123
|
+
const content = expectPlainText(coValue.getCurrentContent());
|
|
124
|
+
|
|
125
|
+
// Insert multiple items at the start
|
|
126
|
+
content.insertAfter(0, "first", "trusting");
|
|
127
|
+
content.insertAfter(0, "second", "trusting");
|
|
128
|
+
content.insertAfter(0, "third", "trusting");
|
|
129
|
+
|
|
130
|
+
// They should appear in reverse chronological order
|
|
131
|
+
// because newer items should appear before older items
|
|
132
|
+
expect(content.toString()).toEqual("thirdsecondfirst");
|
|
133
|
+
});
|