jazz-tools 0.13.31 → 0.14.1
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 +8 -8
- package/CHANGELOG.md +22 -3
- package/dist/auth/DemoAuth.d.ts.map +1 -1
- package/dist/auth/PassphraseAuth.d.ts +1 -3
- package/dist/auth/PassphraseAuth.d.ts.map +1 -1
- package/dist/{chunk-IJU4XPFS.js → chunk-WLOZKDOH.js} +3536 -3291
- package/dist/chunk-WLOZKDOH.js.map +1 -0
- package/dist/coValues/CoValueBase.d.ts +22 -0
- package/dist/coValues/CoValueBase.d.ts.map +1 -0
- package/dist/coValues/account.d.ts +12 -12
- package/dist/coValues/account.d.ts.map +1 -1
- package/dist/coValues/coFeed.d.ts +24 -25
- package/dist/coValues/coFeed.d.ts.map +1 -1
- package/dist/coValues/coList.d.ts +10 -13
- package/dist/coValues/coList.d.ts.map +1 -1
- package/dist/coValues/coMap.d.ts +32 -35
- package/dist/coValues/coMap.d.ts.map +1 -1
- package/dist/coValues/coPlainText.d.ts.map +1 -1
- package/dist/coValues/deepLoading.d.ts +17 -21
- package/dist/coValues/deepLoading.d.ts.map +1 -1
- package/dist/coValues/extensions/imageDef.d.ts +12 -11
- package/dist/coValues/extensions/imageDef.d.ts.map +1 -1
- package/dist/coValues/group.d.ts +5 -9
- package/dist/coValues/group.d.ts.map +1 -1
- package/dist/coValues/inbox.d.ts +2 -3
- package/dist/coValues/inbox.d.ts.map +1 -1
- package/dist/coValues/interfaces.d.ts +8 -34
- package/dist/coValues/interfaces.d.ts.map +1 -1
- package/dist/coValues/profile.d.ts +4 -14
- package/dist/coValues/profile.d.ts.map +1 -1
- package/dist/coValues/registeredSchemas.d.ts +1 -3
- package/dist/coValues/registeredSchemas.d.ts.map +1 -1
- package/dist/coValues/schemaUnion.d.ts +6 -6
- package/dist/exports.d.ts +12 -16
- package/dist/exports.d.ts.map +1 -1
- package/dist/implementation/ContextManager.d.ts +1 -1
- package/dist/implementation/ContextManager.d.ts.map +1 -1
- package/dist/implementation/activeAccountContext.d.ts +1 -1
- package/dist/implementation/activeAccountContext.d.ts.map +1 -1
- package/dist/implementation/createContext.d.ts +10 -10
- package/dist/implementation/createContext.d.ts.map +1 -1
- package/dist/implementation/invites.d.ts +6 -6
- package/dist/implementation/invites.d.ts.map +1 -1
- package/dist/implementation/refs.d.ts +2 -2
- package/dist/implementation/refs.d.ts.map +1 -1
- package/dist/implementation/schema.d.ts +21 -28
- package/dist/implementation/schema.d.ts.map +1 -1
- package/dist/implementation/zodSchema/runtimeConverters/zodFieldToCoFieldDef.d.ts +9 -0
- package/dist/implementation/zodSchema/runtimeConverters/zodFieldToCoFieldDef.d.ts.map +1 -0
- package/dist/implementation/zodSchema/runtimeConverters/zodSchemaToCoSchema.d.ts +28 -0
- package/dist/implementation/zodSchema/runtimeConverters/zodSchemaToCoSchema.d.ts.map +1 -0
- package/dist/implementation/zodSchema/schemaTypes/AccountSchema.d.ts +65 -0
- package/dist/implementation/zodSchema/schemaTypes/AccountSchema.d.ts.map +1 -0
- package/dist/implementation/zodSchema/schemaTypes/CoFeedSchema.d.ts +28 -0
- package/dist/implementation/zodSchema/schemaTypes/CoFeedSchema.d.ts.map +1 -0
- package/dist/implementation/zodSchema/schemaTypes/CoListSchema.d.ts +24 -0
- package/dist/implementation/zodSchema/schemaTypes/CoListSchema.d.ts.map +1 -0
- package/dist/implementation/zodSchema/schemaTypes/CoMapSchema.d.ts +41 -0
- package/dist/implementation/zodSchema/schemaTypes/CoMapSchema.d.ts.map +1 -0
- package/dist/implementation/zodSchema/schemaTypes/CoRecordSchema.d.ts +35 -0
- package/dist/implementation/zodSchema/schemaTypes/CoRecordSchema.d.ts.map +1 -0
- package/dist/implementation/zodSchema/schemaTypes/FileStreamSchema.d.ts +9 -0
- package/dist/implementation/zodSchema/schemaTypes/FileStreamSchema.d.ts.map +1 -0
- package/dist/implementation/zodSchema/schemaTypes/PlainTextSchema.d.ts +20 -0
- package/dist/implementation/zodSchema/schemaTypes/PlainTextSchema.d.ts.map +1 -0
- package/dist/implementation/zodSchema/schemaTypes/RichTextSchema.d.ts +18 -0
- package/dist/implementation/zodSchema/schemaTypes/RichTextSchema.d.ts.map +1 -0
- package/dist/implementation/zodSchema/typeConverters/InstanceOfSchema.d.ts +24 -0
- package/dist/implementation/zodSchema/typeConverters/InstanceOfSchema.d.ts.map +1 -0
- package/dist/implementation/zodSchema/typeConverters/InstanceOfSchemaCoValuesNullable.d.ts +21 -0
- package/dist/implementation/zodSchema/typeConverters/InstanceOfSchemaCoValuesNullable.d.ts.map +1 -0
- package/dist/implementation/zodSchema/typeConverters/InstanceOrPrimitiveOfSchema.d.ts +29 -0
- package/dist/implementation/zodSchema/typeConverters/InstanceOrPrimitiveOfSchema.d.ts.map +1 -0
- package/dist/implementation/zodSchema/typeConverters/InstanceOrPrimitiveOfSchemaCoValuesNullable.d.ts +29 -0
- package/dist/implementation/zodSchema/typeConverters/InstanceOrPrimitiveOfSchemaCoValuesNullable.d.ts.map +1 -0
- package/dist/implementation/zodSchema/unionUtils.d.ts +6 -0
- package/dist/implementation/zodSchema/unionUtils.d.ts.map +1 -0
- package/dist/implementation/zodSchema/zodCo.d.ts +35 -0
- package/dist/implementation/zodSchema/zodCo.d.ts.map +1 -0
- package/dist/implementation/zodSchema/zodSchema.d.ts +38 -0
- package/dist/implementation/zodSchema/zodSchema.d.ts.map +1 -0
- package/dist/index.js +295 -10
- package/dist/index.js.map +1 -1
- package/dist/internal.d.ts +34 -0
- package/dist/internal.d.ts.map +1 -1
- package/dist/subscribe/SubscriptionScope.d.ts +1 -2
- package/dist/subscribe/SubscriptionScope.d.ts.map +1 -1
- package/dist/subscribe/utils.d.ts +2 -2
- package/dist/subscribe/utils.d.ts.map +1 -1
- package/dist/testing.d.ts +10 -8
- package/dist/testing.d.ts.map +1 -1
- package/dist/testing.js +1 -1
- package/dist/testing.js.map +1 -1
- package/dist/tests/utils.d.ts +6 -2
- package/dist/tests/utils.d.ts.map +1 -1
- package/dist/types.d.ts +1 -7
- package/dist/types.d.ts.map +1 -1
- package/package.json +3 -2
- package/src/auth/DemoAuth.ts +1 -2
- package/src/auth/PassphraseAuth.ts +1 -1
- package/src/coValues/CoValueBase.ts +88 -0
- package/src/coValues/account.ts +53 -43
- package/src/coValues/coFeed.ts +65 -83
- package/src/coValues/coList.ts +28 -21
- package/src/coValues/coMap.ts +54 -38
- package/src/coValues/coPlainText.ts +4 -1
- package/src/coValues/deepLoading.ts +35 -43
- package/src/coValues/extensions/imageDef.ts +21 -19
- package/src/coValues/group.ts +37 -38
- package/src/coValues/inbox.ts +24 -11
- package/src/coValues/interfaces.ts +29 -93
- package/src/coValues/profile.ts +12 -13
- package/src/coValues/registeredSchemas.ts +1 -3
- package/src/coValues/schemaUnion.ts +6 -6
- package/src/exports.ts +47 -25
- package/src/implementation/activeAccountContext.ts +1 -1
- package/src/implementation/createContext.ts +39 -24
- package/src/implementation/invites.ts +15 -12
- package/src/implementation/refs.ts +6 -4
- package/src/implementation/schema.ts +22 -34
- package/src/implementation/zodSchema/runtimeConverters/zodFieldToCoFieldDef.ts +101 -0
- package/src/implementation/zodSchema/runtimeConverters/zodSchemaToCoSchema.ts +191 -0
- package/src/implementation/zodSchema/schemaTypes/AccountSchema.ts +102 -0
- package/src/implementation/zodSchema/schemaTypes/CoFeedSchema.ts +70 -0
- package/src/implementation/zodSchema/schemaTypes/CoListSchema.ts +59 -0
- package/src/implementation/zodSchema/schemaTypes/CoMapSchema.ts +126 -0
- package/src/implementation/zodSchema/schemaTypes/CoRecordSchema.ts +98 -0
- package/src/implementation/zodSchema/schemaTypes/FileStreamSchema.ts +9 -0
- package/src/implementation/zodSchema/schemaTypes/PlainTextSchema.ts +27 -0
- package/src/implementation/zodSchema/schemaTypes/RichTextSchema.ts +25 -0
- package/src/implementation/zodSchema/typeConverters/InstanceOfSchema.ts +61 -0
- package/src/implementation/zodSchema/typeConverters/InstanceOfSchemaCoValuesNullable.ts +77 -0
- package/src/implementation/zodSchema/typeConverters/InstanceOrPrimitiveOfSchema.ts +90 -0
- package/src/implementation/zodSchema/typeConverters/InstanceOrPrimitiveOfSchemaCoValuesNullable.ts +103 -0
- package/src/implementation/zodSchema/unionUtils.ts +139 -0
- package/src/implementation/zodSchema/zodCo.ts +409 -0
- package/src/implementation/zodSchema/zodSchema.ts +116 -0
- package/src/internal.ts +38 -0
- package/src/subscribe/SubscriptionScope.ts +3 -1
- package/src/subscribe/utils.ts +7 -2
- package/src/testing.ts +14 -16
- package/src/tests/ContextManager.test.ts +73 -47
- package/src/tests/DemoAuth.test.ts +1 -1
- package/src/tests/account.test.ts +6 -9
- package/src/tests/coFeed.test.ts +102 -63
- package/src/tests/coList.test.ts +82 -95
- package/src/tests/coMap.record.test.ts +53 -87
- package/src/tests/coMap.test.ts +297 -312
- package/src/tests/coPlainText.test.ts +19 -39
- package/src/tests/createContext.test.ts +33 -15
- package/src/tests/deepLoading.test.ts +196 -179
- package/src/tests/groupsAndAccounts.test.ts +81 -72
- package/src/tests/imageDef.test.ts +22 -13
- package/src/tests/inbox.test.ts +36 -29
- package/src/tests/load.test.ts +10 -10
- package/src/tests/patterns/requestToJoin.test.ts +31 -31
- package/src/tests/schema.test.ts +37 -38
- package/src/tests/schemaUnion.test.ts +54 -64
- package/src/tests/subscribe.test.ts +118 -116
- package/src/tests/testing.test.ts +33 -33
- package/src/tests/utils.ts +3 -2
- package/src/types.ts +1 -8
- package/dist/chunk-IJU4XPFS.js.map +0 -1
- package/dist/tests/deepLoading.test-d.d.ts +0 -2
- package/dist/tests/deepLoading.test-d.d.ts.map +0 -1
- package/src/tests/deepLoading.test-d.ts +0 -393
@@ -14,6 +14,7 @@ import {
|
|
14
14
|
Resolved,
|
15
15
|
SubscribeListenerOptions,
|
16
16
|
SubscribeRestArgs,
|
17
|
+
anySchemaToCoSchema,
|
17
18
|
parseCoValueCreateOptions,
|
18
19
|
} from "../internal.js";
|
19
20
|
import {
|
@@ -46,7 +47,9 @@ export class CoPlainText extends String implements CoValue {
|
|
46
47
|
|
47
48
|
if (agent instanceof ControlledAccount) {
|
48
49
|
return coValuesCache.get(agent.account, () =>
|
49
|
-
RegisteredSchemas["Account"].fromRaw(
|
50
|
+
anySchemaToCoSchema(RegisteredSchemas["Account"]).fromRaw(
|
51
|
+
agent.account,
|
52
|
+
),
|
50
53
|
);
|
51
54
|
}
|
52
55
|
|
@@ -1,12 +1,11 @@
|
|
1
1
|
import { SessionID } from "cojson";
|
2
|
-
import { ItemsSym
|
2
|
+
import { ItemsSym } from "../internal.js";
|
3
3
|
import { type Account } from "./account.js";
|
4
4
|
import { CoFeedEntry } from "./coFeed.js";
|
5
5
|
import { type CoKeys, type CoMap } from "./coMap.js";
|
6
6
|
import { type CoValue, type ID } from "./interfaces.js";
|
7
7
|
|
8
|
-
type
|
9
|
-
export type Clean<T> = UnCo<NonNullable<T>>;
|
8
|
+
type NotNull<T> = Exclude<T, null>;
|
10
9
|
|
11
10
|
export type RefsToResolve<
|
12
11
|
V,
|
@@ -22,7 +21,7 @@ export type RefsToResolve<
|
|
22
21
|
?
|
23
22
|
| {
|
24
23
|
$each: RefsToResolve<
|
25
|
-
|
24
|
+
NotNull<Item>,
|
26
25
|
DepthLimit,
|
27
26
|
[0, ...CurrentDepth]
|
28
27
|
>;
|
@@ -33,10 +32,10 @@ export type RefsToResolve<
|
|
33
32
|
V extends { _type: "CoMap" | "Group" | "Account" }
|
34
33
|
?
|
35
34
|
| ({
|
36
|
-
[Key in CoKeys<V> as
|
35
|
+
[Key in CoKeys<V> as NonNullable<V[Key]> extends CoValue
|
37
36
|
? Key
|
38
37
|
: never]?: RefsToResolve<
|
39
|
-
|
38
|
+
NonNullable<V[Key]>,
|
40
39
|
DepthLimit,
|
41
40
|
[0, ...CurrentDepth]
|
42
41
|
>;
|
@@ -44,7 +43,7 @@ export type RefsToResolve<
|
|
44
43
|
| (ItemsSym extends keyof V
|
45
44
|
? {
|
46
45
|
$each: RefsToResolve<
|
47
|
-
|
46
|
+
NonNullable<V[ItemsSym]>,
|
48
47
|
DepthLimit,
|
49
48
|
[0, ...CurrentDepth]
|
50
49
|
>;
|
@@ -59,7 +58,7 @@ export type RefsToResolve<
|
|
59
58
|
?
|
60
59
|
| {
|
61
60
|
$each: RefsToResolve<
|
62
|
-
|
61
|
+
NotNull<Item>,
|
63
62
|
DepthLimit,
|
64
63
|
[0, ...CurrentDepth]
|
65
64
|
>;
|
@@ -72,12 +71,10 @@ export type RefsToResolveStrict<T, V> = V extends RefsToResolve<T>
|
|
72
71
|
? RefsToResolve<T>
|
73
72
|
: V;
|
74
73
|
|
75
|
-
export type Resolved<
|
74
|
+
export type Resolved<
|
76
75
|
T,
|
77
|
-
R,
|
78
|
-
|
79
|
-
[]
|
80
|
-
>;
|
76
|
+
R extends RefsToResolve<T> | undefined = true,
|
77
|
+
> = DeeplyLoaded<T, R, 10, []>;
|
81
78
|
|
82
79
|
type onErrorNullEnabled<Depth> = Depth extends { $onError: null }
|
83
80
|
? null
|
@@ -94,13 +91,13 @@ export type DeeplyLoaded<
|
|
94
91
|
? V
|
95
92
|
: // Basically V extends CoList - but if we used that we'd introduce circularity into the definition of CoList itself
|
96
93
|
[V] extends [Array<infer Item>]
|
97
|
-
?
|
94
|
+
? NotNull<Item> extends CoValue
|
98
95
|
? Depth extends { $each: infer ItemDepth }
|
99
96
|
? // Deeply loaded CoList
|
100
97
|
(
|
101
|
-
| (
|
98
|
+
| (NotNull<Item> &
|
102
99
|
DeeplyLoaded<
|
103
|
-
|
100
|
+
NotNull<Item>,
|
104
101
|
ItemDepth,
|
105
102
|
DepthLimit,
|
106
103
|
[0, ...CurrentDepth]
|
@@ -118,37 +115,32 @@ export type DeeplyLoaded<
|
|
118
115
|
{
|
119
116
|
[key: string]:
|
120
117
|
| DeeplyLoaded<
|
121
|
-
|
118
|
+
NonNullable<V[ItemsSym]>,
|
122
119
|
ItemDepth,
|
123
120
|
DepthLimit,
|
124
121
|
[0, ...CurrentDepth]
|
125
122
|
>
|
126
|
-
| onErrorNullEnabled<
|
123
|
+
| onErrorNullEnabled<Depth["$each"]>;
|
127
124
|
} & V // same reason as in CoList
|
128
125
|
: never
|
129
126
|
: keyof Depth extends never // Depth = {}
|
130
127
|
? V
|
131
|
-
:
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
| (undefined extends V[Key] ? undefined : never)
|
148
|
-
| onErrorNullEnabled<Depth[Key]>
|
149
|
-
: never
|
150
|
-
: never;
|
151
|
-
} & V // same reason as in CoList
|
128
|
+
: // Deeply loaded CoMap
|
129
|
+
{
|
130
|
+
-readonly [Key in keyof Depth]-?: Key extends CoKeys<V>
|
131
|
+
? NonNullable<V[Key]> extends CoValue
|
132
|
+
?
|
133
|
+
| DeeplyLoaded<
|
134
|
+
NonNullable<V[Key]>,
|
135
|
+
Depth[Key],
|
136
|
+
DepthLimit,
|
137
|
+
[0, ...CurrentDepth]
|
138
|
+
>
|
139
|
+
| (undefined extends V[Key] ? undefined : never)
|
140
|
+
| onErrorNullEnabled<Depth[Key]>
|
141
|
+
: never
|
142
|
+
: never;
|
143
|
+
} & V // same reason as in CoList
|
152
144
|
: [V] extends [
|
153
145
|
{
|
154
146
|
_type: "CoStream";
|
@@ -157,12 +149,12 @@ export type DeeplyLoaded<
|
|
157
149
|
]
|
158
150
|
? // Deeply loaded CoStream
|
159
151
|
{
|
160
|
-
byMe?: { value:
|
161
|
-
inCurrentSession?: { value:
|
152
|
+
byMe?: { value: NotNull<Item> };
|
153
|
+
inCurrentSession?: { value: NotNull<Item> };
|
162
154
|
perSession: {
|
163
|
-
[key: SessionID]: { value:
|
155
|
+
[key: SessionID]: { value: NotNull<Item> };
|
164
156
|
};
|
165
|
-
} & { [key: ID<Account>]: { value:
|
157
|
+
} & { [key: ID<Account>]: { value: NotNull<Item> } } & V // same reason as in CoList
|
166
158
|
: [V] extends [
|
167
159
|
{
|
168
160
|
_type: "BinaryCoStream";
|
@@ -1,20 +1,22 @@
|
|
1
|
-
import
|
2
|
-
import {
|
3
|
-
|
1
|
+
import z from "zod/v4";
|
2
|
+
import { Loaded, coFileStreamDefiner, coMapDefiner } from "../../internal.js";
|
3
|
+
|
4
|
+
// avoiding circularity by using the standalone definers instead of `co`
|
5
|
+
const ImageDefinitionBase = coMapDefiner({
|
6
|
+
originalSize: z.tuple([z.number(), z.number()]),
|
7
|
+
placeholderDataURL: z.string().optional(),
|
8
|
+
}).catchall(coFileStreamDefiner());
|
4
9
|
|
5
10
|
/** @category Media */
|
6
|
-
export
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
targetWidth?: number;
|
16
|
-
}): { res: `${number}x${number}`; stream: FileStream } | undefined {
|
17
|
-
const resolutions = Object.keys(this).filter((key) =>
|
11
|
+
export const ImageDefinition = ImageDefinitionBase.withHelpers((Self) => ({
|
12
|
+
highestResAvailable(
|
13
|
+
imageDef: Loaded<typeof Self>,
|
14
|
+
options?: {
|
15
|
+
maxWidth?: number;
|
16
|
+
targetWidth?: number;
|
17
|
+
},
|
18
|
+
) {
|
19
|
+
const resolutions = Object.keys(imageDef).filter((key) =>
|
18
20
|
key.match(/^\d+x\d+$/),
|
19
21
|
) as `${number}x${number}`[];
|
20
22
|
|
@@ -41,7 +43,7 @@ export class ImageDefinition extends CoMap {
|
|
41
43
|
let highestAvailableResolution: `${number}x${number}` | undefined;
|
42
44
|
|
43
45
|
for (const resolution of validResolutions) {
|
44
|
-
if (
|
46
|
+
if (imageDef[resolution] && imageDef[resolution]?.getChunks()) {
|
45
47
|
highestAvailableResolution = resolution;
|
46
48
|
}
|
47
49
|
}
|
@@ -50,8 +52,8 @@ export class ImageDefinition extends CoMap {
|
|
50
52
|
return (
|
51
53
|
highestAvailableResolution && {
|
52
54
|
res: highestAvailableResolution,
|
53
|
-
stream:
|
55
|
+
stream: imageDef[highestAvailableResolution]!,
|
54
56
|
}
|
55
57
|
);
|
56
|
-
}
|
57
|
-
}
|
58
|
+
},
|
59
|
+
}));
|
package/src/coValues/group.ts
CHANGED
@@ -6,11 +6,13 @@ import type {
|
|
6
6
|
RawGroup,
|
7
7
|
Role,
|
8
8
|
} from "cojson";
|
9
|
-
import { activeAccountContext } from "../implementation/activeAccountContext.js";
|
10
9
|
import type {
|
10
|
+
AnyAccountSchema,
|
11
|
+
CoMap,
|
11
12
|
CoValue,
|
12
13
|
CoValueClass,
|
13
14
|
ID,
|
15
|
+
InstanceOfSchema,
|
14
16
|
RefEncoded,
|
15
17
|
RefsToResolve,
|
16
18
|
RefsToResolveStrict,
|
@@ -20,23 +22,23 @@ import type {
|
|
20
22
|
SubscribeRestArgs,
|
21
23
|
} from "../internal.js";
|
22
24
|
import {
|
25
|
+
Account,
|
26
|
+
AccountAndGroupProxyHandler,
|
23
27
|
CoValueBase,
|
28
|
+
Profile,
|
24
29
|
Ref,
|
30
|
+
RegisteredSchemas,
|
25
31
|
accessChildById,
|
26
|
-
|
32
|
+
activeAccountContext,
|
33
|
+
anySchemaToCoSchema,
|
27
34
|
ensureCoValueLoaded,
|
35
|
+
isControlledAccount,
|
28
36
|
loadCoValueWithoutMe,
|
29
37
|
parseGroupCreateOptions,
|
30
38
|
parseSubscribeRestArgs,
|
31
39
|
subscribeToCoValueWithoutMe,
|
32
40
|
subscribeToExistingCoValue,
|
33
41
|
} from "../internal.js";
|
34
|
-
import { RegisteredAccount } from "../types.js";
|
35
|
-
import { AccountAndGroupProxyHandler, isControlledAccount } from "./account.js";
|
36
|
-
import { type Account } from "./account.js";
|
37
|
-
import { type CoMap } from "./coMap.js";
|
38
|
-
import { type Profile } from "./profile.js";
|
39
|
-
import { RegisteredSchemas } from "./registeredSchemas.js";
|
40
42
|
|
41
43
|
/** @category Identity & Permissions */
|
42
44
|
export class Group extends CoValueBase implements CoValue {
|
@@ -80,26 +82,26 @@ export class Group extends CoValueBase implements CoValue {
|
|
80
82
|
| ID<NonNullable<this["root"]>>
|
81
83
|
| undefined;
|
82
84
|
return {
|
83
|
-
profile:
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
root:
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
85
|
+
profile: profileID
|
86
|
+
? (new Ref(
|
87
|
+
profileID,
|
88
|
+
this._loadedAs,
|
89
|
+
this._schema.profile as RefEncoded<NonNullable<this["profile"]>>,
|
90
|
+
this,
|
91
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
92
|
+
) as any as this["profile"] extends Profile
|
93
|
+
? Ref<this["profile"]>
|
94
|
+
: never)
|
95
|
+
: undefined,
|
96
|
+
root: rootID
|
97
|
+
? (new Ref(
|
98
|
+
rootID,
|
99
|
+
this._loadedAs,
|
100
|
+
this._schema.root as RefEncoded<NonNullable<this["root"]>>,
|
101
|
+
this,
|
102
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
103
|
+
) as any as this["root"] extends CoMap ? Ref<this["root"]> : never)
|
104
|
+
: undefined,
|
103
105
|
};
|
104
106
|
}
|
105
107
|
|
@@ -154,20 +156,17 @@ export class Group extends CoValueBase implements CoValue {
|
|
154
156
|
}
|
155
157
|
|
156
158
|
get members(): Array<{
|
157
|
-
id:
|
159
|
+
id: string;
|
158
160
|
role: AccountRole;
|
159
|
-
ref: Ref<
|
160
|
-
account:
|
161
|
+
ref: Ref<Account>;
|
162
|
+
account: Account;
|
161
163
|
}> {
|
162
164
|
const members = [];
|
163
165
|
|
164
|
-
const BaseAccountSchema =
|
165
|
-
(activeAccountContext.maybeGet()?.constructor as typeof Account) ||
|
166
|
-
RegisteredSchemas["Account"];
|
167
166
|
const refEncodedAccountSchema = {
|
168
|
-
ref: () =>
|
167
|
+
ref: () => Account,
|
169
168
|
optional: false,
|
170
|
-
} satisfies RefEncoded<
|
169
|
+
} satisfies RefEncoded<Account>;
|
171
170
|
|
172
171
|
for (const accountID of this._raw.getAllMemberKeysSet()) {
|
173
172
|
if (!isAccountID(accountID)) continue;
|
@@ -180,8 +179,8 @@ export class Group extends CoValueBase implements CoValue {
|
|
180
179
|
role === "reader" ||
|
181
180
|
role === "writeOnly"
|
182
181
|
) {
|
183
|
-
const ref = new Ref<
|
184
|
-
accountID
|
182
|
+
const ref = new Ref<Account>(
|
183
|
+
accountID,
|
185
184
|
this._loadedAs,
|
186
185
|
refEncodedAccountSchema,
|
187
186
|
this,
|
package/src/coValues/inbox.ts
CHANGED
@@ -1,8 +1,17 @@
|
|
1
1
|
import { CoID, InviteSecret, RawAccount, RawCoMap, SessionID } from "cojson";
|
2
2
|
import { CoStreamItem, RawCoStream } from "cojson";
|
3
|
-
import {
|
4
|
-
|
5
|
-
|
3
|
+
import {
|
4
|
+
type Account,
|
5
|
+
CoValue,
|
6
|
+
CoValueClass,
|
7
|
+
CoValueOrZodSchema,
|
8
|
+
ID,
|
9
|
+
InstanceOfSchema,
|
10
|
+
activeAccountContext,
|
11
|
+
anySchemaToCoSchema,
|
12
|
+
loadCoValue,
|
13
|
+
zodSchemaToCoSchema,
|
14
|
+
} from "../internal.js";
|
6
15
|
|
7
16
|
export type InboxInvite = `${CoID<MessagesStream>}/${InviteSecret}`;
|
8
17
|
type TxKey = `${SessionID}/${number}`;
|
@@ -101,10 +110,10 @@ export class Inbox {
|
|
101
110
|
this.failed = failed;
|
102
111
|
}
|
103
112
|
|
104
|
-
subscribe<
|
105
|
-
Schema:
|
113
|
+
subscribe<M extends CoValueOrZodSchema, O extends CoValue | undefined>(
|
114
|
+
Schema: M,
|
106
115
|
callback: (
|
107
|
-
message:
|
116
|
+
message: InstanceOfSchema<M>,
|
108
117
|
senderAccountID: ID<Account>,
|
109
118
|
) => Promise<O | undefined | void>,
|
110
119
|
options: { retries?: number } = {},
|
@@ -137,7 +146,7 @@ export class Inbox {
|
|
137
146
|
|
138
147
|
for (const [sessionID, items] of Object.entries(stream.items) as [
|
139
148
|
SessionID,
|
140
|
-
CoStreamItem<CoID<InboxMessage<
|
149
|
+
CoStreamItem<CoID<InboxMessage<InstanceOfSchema<M>, O>>>[],
|
141
150
|
][]) {
|
142
151
|
const accountID = getAccountIDfromSessionID(sessionID);
|
143
152
|
|
@@ -163,9 +172,13 @@ export class Inbox {
|
|
163
172
|
);
|
164
173
|
}
|
165
174
|
|
166
|
-
return loadCoValue(
|
167
|
-
|
168
|
-
|
175
|
+
return loadCoValue(
|
176
|
+
anySchemaToCoSchema(Schema),
|
177
|
+
message.get("payload")!,
|
178
|
+
{
|
179
|
+
loadAs: account,
|
180
|
+
},
|
181
|
+
);
|
169
182
|
})
|
170
183
|
.then((value) => {
|
171
184
|
if (!value) {
|
@@ -174,7 +187,7 @@ export class Inbox {
|
|
174
187
|
);
|
175
188
|
}
|
176
189
|
|
177
|
-
return callback(value
|
190
|
+
return callback(value as InstanceOfSchema<M>, accountID);
|
178
191
|
})
|
179
192
|
.then((result) => {
|
180
193
|
const inboxMessage = node
|
@@ -1,19 +1,22 @@
|
|
1
|
-
import type {
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
1
|
+
import type { CoValueUniqueness, RawCoValue } from "cojson";
|
2
|
+
import {
|
3
|
+
type Account,
|
4
|
+
AnonymousJazzAgent,
|
5
|
+
CoValueOrZodSchema,
|
6
|
+
type Group,
|
7
|
+
Loaded,
|
8
|
+
RefsToResolve,
|
9
|
+
RefsToResolveStrict,
|
10
|
+
RegisteredSchemas,
|
11
|
+
ResolveQuery,
|
12
|
+
ResolveQueryStrict,
|
13
|
+
Resolved,
|
14
|
+
SubscriptionScope,
|
15
|
+
type SubscriptionValue,
|
16
|
+
activeAccountContext,
|
17
|
+
anySchemaToCoSchema,
|
18
|
+
inspect,
|
19
|
+
} from "../internal.js";
|
17
20
|
|
18
21
|
/** @category Abstract interfaces */
|
19
22
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
@@ -76,74 +79,7 @@ export function isCoValueClass<V extends CoValue>(
|
|
76
79
|
*
|
77
80
|
* @category CoValues
|
78
81
|
*/
|
79
|
-
export type ID<T> =
|
80
|
-
|
81
|
-
type IDMarker<out T> = { __type(_: never): T };
|
82
|
-
|
83
|
-
/** @internal */
|
84
|
-
export class CoValueBase implements CoValue {
|
85
|
-
declare id: ID<this>;
|
86
|
-
declare _type: string;
|
87
|
-
declare _raw: RawCoValue;
|
88
|
-
/** @category Internals */
|
89
|
-
declare _instanceID: string;
|
90
|
-
|
91
|
-
get _owner(): Account | Group {
|
92
|
-
const owner = coValuesCache.get(this._raw.group, () =>
|
93
|
-
this._raw.group instanceof RawAccount
|
94
|
-
? RegisteredSchemas["Account"].fromRaw(this._raw.group)
|
95
|
-
: RegisteredSchemas["Group"].fromRaw(this._raw.group),
|
96
|
-
);
|
97
|
-
|
98
|
-
return owner;
|
99
|
-
}
|
100
|
-
|
101
|
-
/** @private */
|
102
|
-
get _loadedAs() {
|
103
|
-
const agent = this._raw.core.node.getCurrentAgent();
|
104
|
-
|
105
|
-
if (agent instanceof ControlledAccount) {
|
106
|
-
return coValuesCache.get(agent.account, () =>
|
107
|
-
RegisteredSchemas["Account"].fromRaw(agent.account),
|
108
|
-
);
|
109
|
-
}
|
110
|
-
|
111
|
-
return new AnonymousJazzAgent(this._raw.core.node);
|
112
|
-
}
|
113
|
-
|
114
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
115
|
-
constructor(..._args: any) {
|
116
|
-
Object.defineProperty(this, "_instanceID", {
|
117
|
-
value: `instance-${Math.random().toString(36).slice(2)}`,
|
118
|
-
enumerable: false,
|
119
|
-
});
|
120
|
-
}
|
121
|
-
|
122
|
-
/** @category Internals */
|
123
|
-
static fromRaw<V extends CoValue>(this: CoValueClass<V>, raw: RawCoValue): V {
|
124
|
-
return new this({ fromRaw: raw });
|
125
|
-
}
|
126
|
-
|
127
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
128
|
-
toJSON(): object | any[] | string {
|
129
|
-
return {
|
130
|
-
id: this.id,
|
131
|
-
type: this._type,
|
132
|
-
error: "unknown CoValue class",
|
133
|
-
};
|
134
|
-
}
|
135
|
-
|
136
|
-
[inspect]() {
|
137
|
-
return this.toJSON();
|
138
|
-
}
|
139
|
-
|
140
|
-
/** @category Type Helpers */
|
141
|
-
castAs<Cl extends CoValueClass & CoValueFromRaw<CoValue>>(
|
142
|
-
cl: Cl,
|
143
|
-
): InstanceType<Cl> {
|
144
|
-
return cl.fromRaw(this._raw) as InstanceType<Cl>;
|
145
|
-
}
|
146
|
-
}
|
82
|
+
export type ID<T> = string;
|
147
83
|
|
148
84
|
export function loadCoValueWithoutMe<
|
149
85
|
V extends CoValue,
|
@@ -359,18 +295,18 @@ export function subscribeToCoValue<
|
|
359
295
|
}
|
360
296
|
|
361
297
|
export function createCoValueObservable<
|
362
|
-
|
363
|
-
const R extends
|
298
|
+
S extends CoValueOrZodSchema,
|
299
|
+
const R extends ResolveQuery<S>,
|
364
300
|
>(initialValue: undefined | null = undefined) {
|
365
|
-
let currentValue:
|
301
|
+
let currentValue: Loaded<S, R> | undefined | null = initialValue;
|
366
302
|
let subscriberCount = 0;
|
367
303
|
|
368
304
|
function subscribe(
|
369
|
-
cls:
|
370
|
-
id:
|
305
|
+
cls: S,
|
306
|
+
id: string,
|
371
307
|
options: {
|
372
308
|
loadAs: Account | AnonymousJazzAgent;
|
373
|
-
resolve?:
|
309
|
+
resolve?: ResolveQueryStrict<S, R>;
|
374
310
|
onUnavailable?: () => void;
|
375
311
|
onUnauthorized?: () => void;
|
376
312
|
syncResolution?: boolean;
|
@@ -380,11 +316,11 @@ export function createCoValueObservable<
|
|
380
316
|
subscriberCount++;
|
381
317
|
|
382
318
|
const unsubscribe = subscribeToCoValue(
|
383
|
-
cls,
|
319
|
+
anySchemaToCoSchema(cls),
|
384
320
|
id,
|
385
321
|
{
|
386
322
|
loadAs: options.loadAs,
|
387
|
-
resolve: options.resolve,
|
323
|
+
resolve: options.resolve as any,
|
388
324
|
onUnavailable: () => {
|
389
325
|
currentValue = null;
|
390
326
|
options.onUnavailable?.();
|
@@ -396,7 +332,7 @@ export function createCoValueObservable<
|
|
396
332
|
syncResolution: options.syncResolution,
|
397
333
|
},
|
398
334
|
(value) => {
|
399
|
-
currentValue = value
|
335
|
+
currentValue = value as Loaded<S, R>;
|
400
336
|
listener();
|
401
337
|
},
|
402
338
|
);
|
package/src/coValues/profile.ts
CHANGED
@@ -1,19 +1,18 @@
|
|
1
|
-
import {
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
1
|
+
import {
|
2
|
+
Account,
|
3
|
+
CoMap,
|
4
|
+
CoMapInit,
|
5
|
+
CoValueClass,
|
6
|
+
Group,
|
7
|
+
Simplify,
|
8
|
+
coField,
|
9
|
+
} from "../internal.js";
|
7
10
|
|
8
11
|
/** @category Identity & Permissions */
|
9
12
|
export class Profile extends CoMap {
|
10
|
-
name =
|
11
|
-
inbox =
|
12
|
-
inboxInvite =
|
13
|
-
|
14
|
-
override get _owner(): Group {
|
15
|
-
return super._owner as Group;
|
16
|
-
}
|
13
|
+
name = coField.string;
|
14
|
+
inbox? = coField.optional.string;
|
15
|
+
inboxInvite? = coField.optional.string;
|
17
16
|
|
18
17
|
/**
|
19
18
|
* Creates a new profile with the given initial values and owner.
|
@@ -1,6 +1,4 @@
|
|
1
|
-
import type { Account } from "
|
2
|
-
import type { CoMap } from "./coMap.js";
|
3
|
-
import type { Group } from "./group.js";
|
1
|
+
import type { Account, CoMap, Group } from "../internal.js";
|
4
2
|
|
5
3
|
/**
|
6
4
|
* Regisering schemas into this Record to avoid circular dependencies.
|
@@ -15,18 +15,18 @@ import {
|
|
15
15
|
* import { SchemaUnion, CoMap } from "jazz-tools";
|
16
16
|
*
|
17
17
|
* class BaseWidget extends CoMap {
|
18
|
-
* type =
|
18
|
+
* type = coField.string;
|
19
19
|
* }
|
20
20
|
*
|
21
21
|
* class ButtonWidget extends BaseWidget {
|
22
|
-
* type =
|
23
|
-
* label =
|
22
|
+
* type = coField.literal("button");
|
23
|
+
* label = coField.string;
|
24
24
|
* }
|
25
25
|
*
|
26
26
|
* class SliderWidget extends BaseWidget {
|
27
|
-
* type =
|
28
|
-
* min =
|
29
|
-
* max =
|
27
|
+
* type = coField.literal("slider");
|
28
|
+
* min = coField.number;
|
29
|
+
* max = coField.number;
|
30
30
|
* }
|
31
31
|
*
|
32
32
|
* const WidgetUnion = SchemaUnion.Of<BaseWidget>((raw) => {
|