jazz-tools 0.8.49 → 0.8.51
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 +4 -4
- package/CHANGELOG.md +14 -0
- package/dist/{chunk-6OHBW32Q.js → chunk-MUJIKQFH.js} +23 -16
- package/dist/chunk-MUJIKQFH.js.map +1 -0
- package/dist/index.native.js +1 -1
- package/dist/index.web.js +1 -1
- package/package.json +2 -2
- package/src/coValues/coFeed.ts +18 -12
- package/src/coValues/coList.ts +5 -3
- package/src/coValues/coMap.ts +14 -9
- package/src/coValues/group.ts +3 -2
- package/src/coValues/interfaces.ts +23 -1
- package/src/tests/coFeed.test.ts +16 -0
- package/src/tests/coList.test.ts +14 -0
- package/src/tests/coMap.test.ts +19 -0
- package/dist/chunk-6OHBW32Q.js.map +0 -1
package/src/coValues/coMap.ts
CHANGED
@@ -30,6 +30,7 @@ import {
|
|
30
30
|
isRefEncoded,
|
31
31
|
loadCoValue,
|
32
32
|
makeRefs,
|
33
|
+
parseCoValueCreateOptions,
|
33
34
|
subscribeToCoValue,
|
34
35
|
subscribeToExistingCoValue,
|
35
36
|
subscriptionsScopes,
|
@@ -43,6 +44,7 @@ type CoMapEdit<V> = {
|
|
43
44
|
ref?: RefIfCoValue<V>;
|
44
45
|
by?: Account;
|
45
46
|
madeAt: Date;
|
47
|
+
key?: string;
|
46
48
|
};
|
47
49
|
|
48
50
|
type LastAndAllCoMapEdits<V> = CoMapEdit<V> & { all: CoMapEdit<V>[] };
|
@@ -183,6 +185,7 @@ export class CoMap extends CoValueBase implements CoValue {
|
|
183
185
|
optional: false,
|
184
186
|
}).accessFrom(target, "_edits." + key + ".by"),
|
185
187
|
madeAt: rawEdit.at,
|
188
|
+
key,
|
186
189
|
};
|
187
190
|
}
|
188
191
|
|
@@ -271,17 +274,19 @@ export class CoMap extends CoValueBase implements CoValue {
|
|
271
274
|
static create<M extends CoMap>(
|
272
275
|
this: CoValueClass<M>,
|
273
276
|
init: Simplify<CoMapInit<M>>,
|
274
|
-
options:
|
275
|
-
|
276
|
-
|
277
|
-
|
277
|
+
options:
|
278
|
+
| {
|
279
|
+
owner: Account | Group;
|
280
|
+
unique?: CoValueUniqueness["uniqueness"];
|
281
|
+
}
|
282
|
+
| Account
|
283
|
+
| Group,
|
278
284
|
) {
|
279
285
|
const instance = new this();
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
);
|
286
|
+
|
287
|
+
const { owner, uniqueness } = parseCoValueCreateOptions(options);
|
288
|
+
const raw = instance.rawFromInit(init, owner, uniqueness);
|
289
|
+
|
285
290
|
Object.defineProperties(instance, {
|
286
291
|
id: {
|
287
292
|
value: raw.id,
|
package/src/coValues/group.ts
CHANGED
@@ -14,6 +14,7 @@ import {
|
|
14
14
|
Ref,
|
15
15
|
ensureCoValueLoaded,
|
16
16
|
loadCoValue,
|
17
|
+
parseCoValueCreateOptions,
|
17
18
|
subscribeToCoValue,
|
18
19
|
subscribeToExistingCoValue,
|
19
20
|
} from "../internal.js";
|
@@ -123,9 +124,9 @@ export class Group extends CoValueBase implements CoValue {
|
|
123
124
|
|
124
125
|
static create<G extends Group>(
|
125
126
|
this: CoValueClass<G>,
|
126
|
-
options: { owner: Account },
|
127
|
+
options: { owner: Account } | Account,
|
127
128
|
) {
|
128
|
-
return new this(options);
|
129
|
+
return new this(parseCoValueCreateOptions(options));
|
129
130
|
}
|
130
131
|
|
131
132
|
myRole(): Role | undefined {
|
@@ -1,4 +1,8 @@
|
|
1
|
-
import type {
|
1
|
+
import type {
|
2
|
+
CoValueUniqueness,
|
3
|
+
CojsonInternalTypes,
|
4
|
+
RawCoValue,
|
5
|
+
} from "cojson";
|
2
6
|
import { RawAccount } from "cojson";
|
3
7
|
import { AnonymousJazzAgent } from "../implementation/anonymousJazzAgent.js";
|
4
8
|
import type { DeeplyLoaded, DepthsIn } from "../internal.js";
|
@@ -285,3 +289,21 @@ export function subscribeToExistingCoValue<V extends CoValue, Depth>(
|
|
285
289
|
listener,
|
286
290
|
);
|
287
291
|
}
|
292
|
+
|
293
|
+
export function parseCoValueCreateOptions(
|
294
|
+
options:
|
295
|
+
| {
|
296
|
+
owner: Account | Group;
|
297
|
+
unique?: CoValueUniqueness["uniqueness"];
|
298
|
+
}
|
299
|
+
| Account
|
300
|
+
| Group,
|
301
|
+
) {
|
302
|
+
return "_type" in options &&
|
303
|
+
(options._type === "Account" || options._type === "Group")
|
304
|
+
? { owner: options, uniqueness: undefined }
|
305
|
+
: {
|
306
|
+
owner: options.owner,
|
307
|
+
uniqueness: options.unique ? { uniqueness: options.unique } : undefined,
|
308
|
+
};
|
309
|
+
}
|
package/src/tests/coFeed.test.ts
CHANGED
@@ -4,6 +4,7 @@ import {
|
|
4
4
|
Account,
|
5
5
|
CoFeed,
|
6
6
|
FileStream,
|
7
|
+
Group,
|
7
8
|
ID,
|
8
9
|
WasmCrypto,
|
9
10
|
co,
|
@@ -34,6 +35,21 @@ describe("Simple CoFeed operations", async () => {
|
|
34
35
|
expect(stream.perSession[me.sessionID]?.value).toEqual("milk");
|
35
36
|
});
|
36
37
|
|
38
|
+
test("Construction with an Account", () => {
|
39
|
+
const stream = TestStream.create(["milk"], me);
|
40
|
+
|
41
|
+
expect(stream[me.id]?.value).toEqual("milk");
|
42
|
+
expect(stream.perSession[me.sessionID]?.value).toEqual("milk");
|
43
|
+
});
|
44
|
+
|
45
|
+
test("Construction with a Group", () => {
|
46
|
+
const group = Group.create(me);
|
47
|
+
const stream = TestStream.create(["milk"], group);
|
48
|
+
|
49
|
+
expect(stream[me.id]?.value).toEqual("milk");
|
50
|
+
expect(stream.perSession[me.sessionID]?.value).toEqual("milk");
|
51
|
+
});
|
52
|
+
|
37
53
|
describe("Mutation", () => {
|
38
54
|
test("pushing", () => {
|
39
55
|
stream.push("bread");
|
package/src/tests/coList.test.ts
CHANGED
@@ -3,6 +3,7 @@ import { describe, expect, test } from "vitest";
|
|
3
3
|
import {
|
4
4
|
Account,
|
5
5
|
CoList,
|
6
|
+
Group,
|
6
7
|
WasmCrypto,
|
7
8
|
co,
|
8
9
|
cojsonInternals,
|
@@ -37,6 +38,19 @@ describe("Simple CoList operations", async () => {
|
|
37
38
|
]);
|
38
39
|
});
|
39
40
|
|
41
|
+
test("Construction with an Account", () => {
|
42
|
+
const list = TestList.create(["milk"], me);
|
43
|
+
|
44
|
+
expect(list[0]).toEqual("milk");
|
45
|
+
});
|
46
|
+
|
47
|
+
test("Construction with a Group", () => {
|
48
|
+
const group = Group.create(me);
|
49
|
+
const list = TestList.create(["milk"], group);
|
50
|
+
|
51
|
+
expect(list[0]).toEqual("milk");
|
52
|
+
});
|
53
|
+
|
40
54
|
describe("Mutation", () => {
|
41
55
|
test("assignment", () => {
|
42
56
|
const list = TestList.create(["bread", "butter", "onion"], {
|
package/src/tests/coMap.test.ts
CHANGED
@@ -64,6 +64,25 @@ describe("Simple CoMap operations", async () => {
|
|
64
64
|
]);
|
65
65
|
});
|
66
66
|
|
67
|
+
test("Construction with an Account", () => {
|
68
|
+
const map = TestMap.create(
|
69
|
+
{ color: "red", _height: 10, birthday: birthday },
|
70
|
+
me,
|
71
|
+
);
|
72
|
+
|
73
|
+
expect(map.color).toEqual("red");
|
74
|
+
});
|
75
|
+
|
76
|
+
test("Construction with a Group", () => {
|
77
|
+
const group = Group.create(me);
|
78
|
+
const map = TestMap.create(
|
79
|
+
{ color: "red", _height: 10, birthday: birthday },
|
80
|
+
group,
|
81
|
+
);
|
82
|
+
|
83
|
+
expect(map.color).toEqual("red");
|
84
|
+
});
|
85
|
+
|
67
86
|
test("Construction with too many things provided", () => {
|
68
87
|
const mapWithExtra = TestMap.create(
|
69
88
|
{
|