jazz-tools 0.10.14 → 0.11.0
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 +11 -7
- package/CHANGELOG.md +31 -0
- package/dist/auth/AuthSecretStorage.d.ts +25 -0
- package/dist/auth/AuthSecretStorage.d.ts.map +1 -0
- package/dist/auth/DemoAuth.d.ts +27 -0
- package/dist/auth/DemoAuth.d.ts.map +1 -0
- package/dist/auth/InMemoryKVStore.d.ts +9 -0
- package/dist/auth/InMemoryKVStore.d.ts.map +1 -0
- package/dist/auth/KvStoreContext.d.ts +17 -0
- package/dist/auth/KvStoreContext.d.ts.map +1 -0
- package/dist/auth/PassphraseAuth.d.ts +35 -0
- package/dist/auth/PassphraseAuth.d.ts.map +1 -0
- package/dist/{chunk-5YDDEUNX.js → chunk-RTRX7HIO.js} +193 -81
- package/dist/chunk-RTRX7HIO.js.map +1 -0
- package/dist/coValues/account.d.ts +120 -0
- package/dist/coValues/account.d.ts.map +1 -0
- package/dist/coValues/coFeed.d.ts +361 -0
- package/dist/coValues/coFeed.d.ts.map +1 -0
- package/dist/coValues/coList.d.ts +221 -0
- package/dist/coValues/coList.d.ts.map +1 -0
- package/dist/coValues/coMap.d.ts +500 -0
- package/dist/coValues/coMap.d.ts.map +1 -0
- package/dist/coValues/coPlainText.d.ts +69 -0
- package/dist/coValues/coPlainText.d.ts.map +1 -0
- package/dist/coValues/coRichText.d.ts +259 -0
- package/dist/coValues/coRichText.d.ts.map +1 -0
- package/dist/coValues/deepLoading.d.ts +81 -0
- package/dist/coValues/deepLoading.d.ts.map +1 -0
- package/dist/coValues/extensions/imageDef.d.ts +17 -0
- package/dist/coValues/extensions/imageDef.d.ts.map +1 -0
- package/dist/coValues/group.d.ts +67 -0
- package/dist/coValues/group.d.ts.map +1 -0
- package/dist/coValues/inbox.d.ts +52 -0
- package/dist/coValues/inbox.d.ts.map +1 -0
- package/dist/coValues/interfaces.d.ts +97 -0
- package/dist/coValues/interfaces.d.ts.map +1 -0
- package/dist/coValues/profile.d.ts +28 -0
- package/dist/coValues/profile.d.ts.map +1 -0
- package/dist/coValues/registeredSchemas.d.ts +12 -0
- package/dist/coValues/registeredSchemas.d.ts.map +1 -0
- package/dist/coValues/schemaUnion.d.ts +79 -0
- package/dist/coValues/schemaUnion.d.ts.map +1 -0
- package/dist/exports.d.ts +27 -0
- package/dist/exports.d.ts.map +1 -0
- package/dist/implementation/ContextManager.d.ts +65 -0
- package/dist/implementation/ContextManager.d.ts.map +1 -0
- package/dist/implementation/activeAccountContext.d.ts +12 -0
- package/dist/implementation/activeAccountContext.d.ts.map +1 -0
- package/dist/implementation/anonymousJazzAgent.d.ts +7 -0
- package/dist/implementation/anonymousJazzAgent.d.ts.map +1 -0
- package/dist/implementation/createContext.d.ts +91 -0
- package/dist/implementation/createContext.d.ts.map +1 -0
- package/dist/implementation/devtoolsFormatters.d.ts +2 -0
- package/dist/implementation/devtoolsFormatters.d.ts.map +1 -0
- package/dist/implementation/errors.d.ts +2 -0
- package/dist/implementation/errors.d.ts.map +1 -0
- package/dist/implementation/inspect.d.ts +3 -0
- package/dist/implementation/inspect.d.ts.map +1 -0
- package/dist/implementation/invites.d.ts +23 -0
- package/dist/implementation/invites.d.ts.map +1 -0
- package/dist/implementation/refs.d.ts +21 -0
- package/dist/implementation/refs.d.ts.map +1 -0
- package/dist/implementation/schema.d.ts +72 -0
- package/dist/implementation/schema.d.ts.map +1 -0
- package/dist/implementation/subscriptionScope.d.ts +33 -0
- package/dist/implementation/subscriptionScope.d.ts.map +1 -0
- package/dist/implementation/symbols.d.ts +8 -0
- package/dist/implementation/symbols.d.ts.map +1 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +1 -1
- package/dist/internal.d.ts +12 -0
- package/dist/internal.d.ts.map +1 -0
- package/dist/lib/cache.d.ts +6 -0
- package/dist/lib/cache.d.ts.map +1 -0
- package/dist/lib/cache.test.d.ts +2 -0
- package/dist/lib/cache.test.d.ts.map +1 -0
- package/dist/testing.d.ts +41 -0
- package/dist/testing.d.ts.map +1 -0
- package/dist/testing.js +11 -16
- package/dist/testing.js.map +1 -1
- package/dist/tests/AuthSecretStorage.test.d.ts +2 -0
- package/dist/tests/AuthSecretStorage.test.d.ts.map +1 -0
- package/dist/tests/ContextManager.test.d.ts +2 -0
- package/dist/tests/ContextManager.test.d.ts.map +1 -0
- package/dist/tests/DemoAuth.test.d.ts +2 -0
- package/dist/tests/DemoAuth.test.d.ts.map +1 -0
- package/dist/tests/PassphraseAuth.test.d.ts +2 -0
- package/dist/tests/PassphraseAuth.test.d.ts.map +1 -0
- package/dist/tests/account.test.d.ts +2 -0
- package/dist/tests/account.test.d.ts.map +1 -0
- package/dist/tests/coFeed.test.d.ts +2 -0
- package/dist/tests/coFeed.test.d.ts.map +1 -0
- package/dist/tests/coList.test.d.ts +2 -0
- package/dist/tests/coList.test.d.ts.map +1 -0
- package/dist/tests/coMap.test.d.ts +2 -0
- package/dist/tests/coMap.test.d.ts.map +1 -0
- package/dist/tests/coPlainText.test.d.ts +2 -0
- package/dist/tests/coPlainText.test.d.ts.map +1 -0
- package/dist/tests/coRichText.test.d.ts +2 -0
- package/dist/tests/coRichText.test.d.ts.map +1 -0
- package/dist/tests/createContext.test.d.ts +2 -0
- package/dist/tests/createContext.test.d.ts.map +1 -0
- package/dist/tests/deepLoading.test.d.ts +2 -0
- package/dist/tests/deepLoading.test.d.ts.map +1 -0
- package/dist/tests/fixtures.d.ts +2 -0
- package/dist/tests/fixtures.d.ts.map +1 -0
- package/dist/tests/groupsAndAccounts.test.d.ts +2 -0
- package/dist/tests/groupsAndAccounts.test.d.ts.map +1 -0
- package/dist/tests/inbox.test.d.ts +2 -0
- package/dist/tests/inbox.test.d.ts.map +1 -0
- package/dist/tests/interfaces.test.d.ts +2 -0
- package/dist/tests/interfaces.test.d.ts.map +1 -0
- package/dist/tests/invites.test.d.ts +2 -0
- package/dist/tests/invites.test.d.ts.map +1 -0
- package/dist/tests/schema.test.d.ts +2 -0
- package/dist/tests/schema.test.d.ts.map +1 -0
- package/dist/tests/schemaUnion.test.d.ts +2 -0
- package/dist/tests/schemaUnion.test.d.ts.map +1 -0
- package/dist/tests/subscribe.test.d.ts +2 -0
- package/dist/tests/subscribe.test.d.ts.map +1 -0
- package/dist/tests/testing.test.d.ts +2 -0
- package/dist/tests/testing.test.d.ts.map +1 -0
- package/dist/tests/utils.d.ts +21 -0
- package/dist/tests/utils.d.ts.map +1 -0
- package/dist/types.d.ts +52 -0
- package/dist/types.d.ts.map +1 -0
- package/package.json +8 -7
- package/src/coValues/account.ts +69 -11
- package/src/coValues/coMap.ts +2 -2
- package/src/coValues/coRichText.ts +42 -17
- package/src/coValues/group.ts +76 -31
- package/src/coValues/inbox.ts +10 -0
- package/src/coValues/interfaces.ts +1 -1
- package/src/coValues/profile.ts +35 -2
- package/src/implementation/ContextManager.ts +63 -15
- package/src/implementation/schema.ts +1 -3
- package/src/testing.ts +10 -16
- package/src/tests/AuthSecretStorage.test.ts +1 -2
- package/src/tests/ContextManager.test.ts +27 -14
- package/src/tests/PassphraseAuth.test.ts +7 -3
- package/src/tests/coMap.test.ts +20 -21
- package/src/tests/deepLoading.test.ts +8 -17
- package/src/tests/groupsAndAccounts.test.ts +429 -89
- package/src/tests/inbox.test.ts +24 -0
- package/src/tests/schema.test.ts +45 -5
- package/src/tests/utils.ts +7 -3
- package/src/types.ts +6 -0
- package/tsconfig.json +4 -1
- package/dist/chunk-5YDDEUNX.js.map +0 -1
@@ -0,0 +1,500 @@
|
|
1
|
+
import { AgentID, type CoValueUniqueness, CojsonInternalTypes, type JsonValue, RawAccountID, type RawCoMap } from "cojson";
|
2
|
+
import type { AnonymousJazzAgent, CoValue, CoValueClass, DeeplyLoaded, DepthsIn, ID, IfCo, RefIfCoValue, Schema, co } from "../internal.js";
|
3
|
+
import { CoValueBase, ItemsSym, Ref, inspect } from "../internal.js";
|
4
|
+
import { type Account } from "./account.js";
|
5
|
+
import { type Group } from "./group.js";
|
6
|
+
type CoMapEdit<V> = {
|
7
|
+
value?: V;
|
8
|
+
ref?: RefIfCoValue<V>;
|
9
|
+
by?: Account;
|
10
|
+
madeAt: Date;
|
11
|
+
key?: string;
|
12
|
+
};
|
13
|
+
type LastAndAllCoMapEdits<V> = CoMapEdit<V> & {
|
14
|
+
all: CoMapEdit<V>[];
|
15
|
+
};
|
16
|
+
export type Simplify<A> = {
|
17
|
+
[K in keyof A]: A[K];
|
18
|
+
} extends infer B ? B : never;
|
19
|
+
/**
|
20
|
+
* CoMaps are collaborative versions of plain objects, mapping string-like keys to values.
|
21
|
+
*
|
22
|
+
* @categoryDescription Declaration
|
23
|
+
* Declare your own CoMap schemas by subclassing `CoMap` and assigning field schemas with `co`.
|
24
|
+
*
|
25
|
+
* Optional `co.ref(...)` fields must be marked with `{ optional: true }`.
|
26
|
+
*
|
27
|
+
* ```ts
|
28
|
+
* import { co, CoMap } from "jazz-tools";
|
29
|
+
*
|
30
|
+
* class Person extends CoMap {
|
31
|
+
* name = co.string;
|
32
|
+
* age = co.number;
|
33
|
+
* pet = co.ref(Animal);
|
34
|
+
* car = co.ref(Car, { optional: true });
|
35
|
+
* }
|
36
|
+
* ```
|
37
|
+
*
|
38
|
+
* @categoryDescription Content
|
39
|
+
* You can access properties you declare on a `CoMap` (using `co`) as if they were normal properties on a plain object, using dot notation, `Object.keys()`, etc.
|
40
|
+
*
|
41
|
+
* ```ts
|
42
|
+
* person.name;
|
43
|
+
* person["age"];
|
44
|
+
* person.age = 42;
|
45
|
+
* person.pet?.name;
|
46
|
+
* Object.keys(person);
|
47
|
+
* // => ["name", "age", "pet"]
|
48
|
+
* ```
|
49
|
+
*
|
50
|
+
* @category CoValues
|
51
|
+
* */
|
52
|
+
export declare class CoMap extends CoValueBase implements CoValue {
|
53
|
+
/**
|
54
|
+
* The ID of this `CoMap`
|
55
|
+
* @category Content */
|
56
|
+
id: ID<this>;
|
57
|
+
/** @category Type Helpers */
|
58
|
+
_type: "CoMap";
|
59
|
+
/** @category Internals */
|
60
|
+
_raw: RawCoMap;
|
61
|
+
/** @internal */
|
62
|
+
static _schema: any;
|
63
|
+
/** @internal */
|
64
|
+
get _schema(): {
|
65
|
+
[key: string]: Schema;
|
66
|
+
} & {
|
67
|
+
[ItemsSym]?: Schema;
|
68
|
+
};
|
69
|
+
/**
|
70
|
+
* If property `prop` is a `co.ref(...)`, you can use `coMaps._refs.prop` to access
|
71
|
+
* the `Ref` instead of the potentially loaded/null value.
|
72
|
+
*
|
73
|
+
* This allows you to always get the ID or load the value manually.
|
74
|
+
*
|
75
|
+
* @example
|
76
|
+
* ```ts
|
77
|
+
* person._refs.pet.id; // => ID<Animal>
|
78
|
+
* person._refs.pet.value;
|
79
|
+
* // => Animal | null
|
80
|
+
* const pet = await person._refs.pet.load();
|
81
|
+
* ```
|
82
|
+
*
|
83
|
+
* @category Content
|
84
|
+
**/
|
85
|
+
get _refs(): {
|
86
|
+
[Key in CoKeys<this>]: IfCo<this[Key], RefIfCoValue<this[Key]>>;
|
87
|
+
};
|
88
|
+
/** @internal */
|
89
|
+
getEditFromRaw(target: CoMap, rawEdit: {
|
90
|
+
by: RawAccountID | AgentID;
|
91
|
+
tx: CojsonInternalTypes.TransactionID;
|
92
|
+
at: Date;
|
93
|
+
value?: JsonValue | undefined;
|
94
|
+
}, descriptor: Schema, key: string): {
|
95
|
+
value: any;
|
96
|
+
ref: Ref<CoValue> | undefined;
|
97
|
+
by: Account | null;
|
98
|
+
madeAt: Date;
|
99
|
+
key: string;
|
100
|
+
};
|
101
|
+
/** @category Collaboration */
|
102
|
+
get _edits(): { [Key in CoKeys<this>]: IfCo<this[Key], LastAndAllCoMapEdits<this[Key]>>; };
|
103
|
+
/** @internal */
|
104
|
+
constructor(options: {
|
105
|
+
fromRaw: RawCoMap;
|
106
|
+
} | undefined);
|
107
|
+
/**
|
108
|
+
* Create a new CoMap with the given initial values and owner.
|
109
|
+
*
|
110
|
+
* The owner (a Group or Account) determines access rights to the CoMap.
|
111
|
+
*
|
112
|
+
* The CoMap will immediately be persisted and synced to connected peers.
|
113
|
+
*
|
114
|
+
* @example
|
115
|
+
* ```ts
|
116
|
+
* const person = Person.create({
|
117
|
+
* name: "Alice",
|
118
|
+
* age: 42,
|
119
|
+
* pet: cat,
|
120
|
+
* }, { owner: friendGroup });
|
121
|
+
* ```
|
122
|
+
*
|
123
|
+
* @category Creation
|
124
|
+
**/
|
125
|
+
static create<M extends CoMap>(this: CoValueClass<M>, init: Simplify<CoMapInit<M>>, options?: {
|
126
|
+
owner: Account | Group;
|
127
|
+
unique?: CoValueUniqueness["uniqueness"];
|
128
|
+
} | Account | Group): M;
|
129
|
+
/**
|
130
|
+
* Return a JSON representation of the `CoMap`
|
131
|
+
* @category Content
|
132
|
+
*/
|
133
|
+
toJSON(_key?: string, seenAbove?: ID<CoValue>[]): any[];
|
134
|
+
[inspect](): any[];
|
135
|
+
/**
|
136
|
+
* Create a new `RawCoMap` from an initialization object
|
137
|
+
* @internal
|
138
|
+
*/
|
139
|
+
rawFromInit<Fields extends object = Record<string, any>>(init: Simplify<CoMapInit<Fields>> | undefined, owner: Account | Group, uniqueness?: CoValueUniqueness): RawCoMap<{
|
140
|
+
[key: string]: JsonValue | undefined;
|
141
|
+
}, import("cojson").JsonObject | null>;
|
142
|
+
/**
|
143
|
+
* Declare a Record-like CoMap schema, by extending `CoMap.Record(...)` and passing the value schema using `co`. Keys are always `string`.
|
144
|
+
*
|
145
|
+
* @example
|
146
|
+
* ```ts
|
147
|
+
* import { co, CoMap } from "jazz-tools";
|
148
|
+
*
|
149
|
+
* class ColorToFruitMap extends CoMap.Record(
|
150
|
+
* co.ref(Fruit)
|
151
|
+
* ) {}
|
152
|
+
*
|
153
|
+
* // assume we have map: ColorToFruitMap
|
154
|
+
* // and strawberry: Fruit
|
155
|
+
* map["red"] = strawberry;
|
156
|
+
* ```
|
157
|
+
*
|
158
|
+
* @category Declaration
|
159
|
+
*/
|
160
|
+
static Record<Value>(value: IfCo<Value, Value>): {
|
161
|
+
new (options: {
|
162
|
+
fromRaw: RawCoMap;
|
163
|
+
} | undefined): {
|
164
|
+
[x: string]: Value;
|
165
|
+
$items$: IfCo<Value, Value>;
|
166
|
+
/**
|
167
|
+
* The ID of this `CoMap`
|
168
|
+
* @category Content */
|
169
|
+
id: ID<any>;
|
170
|
+
/** @category Type Helpers */
|
171
|
+
_type: "CoMap";
|
172
|
+
/** @category Internals */
|
173
|
+
_raw: RawCoMap;
|
174
|
+
/** @internal */
|
175
|
+
readonly _schema: {
|
176
|
+
[key: string]: Schema;
|
177
|
+
} & {
|
178
|
+
$items$?: Schema;
|
179
|
+
};
|
180
|
+
/**
|
181
|
+
* If property `prop` is a `co.ref(...)`, you can use `coMaps._refs.prop` to access
|
182
|
+
* the `Ref` instead of the potentially loaded/null value.
|
183
|
+
*
|
184
|
+
* This allows you to always get the ID or load the value manually.
|
185
|
+
*
|
186
|
+
* @example
|
187
|
+
* ```ts
|
188
|
+
* person._refs.pet.id; // => ID<Animal>
|
189
|
+
* person._refs.pet.value;
|
190
|
+
* // => Animal | null
|
191
|
+
* const pet = await person._refs.pet.load();
|
192
|
+
* ```
|
193
|
+
*
|
194
|
+
* @category Content
|
195
|
+
**/
|
196
|
+
readonly _refs: {
|
197
|
+
[x: string]: IfCo<Value, RefIfCoValue<Value>>;
|
198
|
+
};
|
199
|
+
/** @internal */
|
200
|
+
getEditFromRaw(target: CoMap, rawEdit: {
|
201
|
+
by: RawAccountID | AgentID;
|
202
|
+
tx: CojsonInternalTypes.TransactionID;
|
203
|
+
at: Date;
|
204
|
+
value?: JsonValue | undefined;
|
205
|
+
}, descriptor: Schema, key: string): {
|
206
|
+
value: any;
|
207
|
+
ref: Ref<CoValue> | undefined;
|
208
|
+
by: Account | null;
|
209
|
+
madeAt: Date;
|
210
|
+
key: string;
|
211
|
+
};
|
212
|
+
/** @category Collaboration */
|
213
|
+
readonly _edits: {
|
214
|
+
[x: string]: IfCo<Value, LastAndAllCoMapEdits<Value>>;
|
215
|
+
};
|
216
|
+
/**
|
217
|
+
* Return a JSON representation of the `CoMap`
|
218
|
+
* @category Content
|
219
|
+
*/
|
220
|
+
toJSON(_key?: string, seenAbove?: ID<CoValue>[]): any[];
|
221
|
+
/**
|
222
|
+
* Create a new `RawCoMap` from an initialization object
|
223
|
+
* @internal
|
224
|
+
*/
|
225
|
+
rawFromInit<Fields extends object = Record<string, any>>(init: Simplify<CoMapInit<Fields>> | undefined, owner: Account | Group, uniqueness?: CoValueUniqueness): RawCoMap<{
|
226
|
+
[key: string]: JsonValue | undefined;
|
227
|
+
}, import("cojson").JsonObject | null>;
|
228
|
+
/**
|
229
|
+
* Given an already loaded `CoMap`, ensure that the specified fields are loaded to the specified depth.
|
230
|
+
*
|
231
|
+
* Works like `CoMap.load()`, but you don't need to pass the ID or the account to load as again.
|
232
|
+
*
|
233
|
+
* @category Subscription & Loading
|
234
|
+
*/
|
235
|
+
ensureLoaded<M extends CoMap, Depth>(this: M, depth: Depth & DepthsIn<M>): Promise<DeeplyLoaded<M, Depth>>;
|
236
|
+
/**
|
237
|
+
* Given an already loaded `CoMap`, subscribe to updates to the `CoMap` and ensure that the specified fields are loaded to the specified depth.
|
238
|
+
*
|
239
|
+
* Works like `CoMap.subscribe()`, but you don't need to pass the ID or the account to load as again.
|
240
|
+
*
|
241
|
+
* Returns an unsubscribe function that you should call when you no longer need updates.
|
242
|
+
*
|
243
|
+
* @category Subscription & Loading
|
244
|
+
**/
|
245
|
+
subscribe<M extends CoMap, Depth>(this: M, depth: Depth & DepthsIn<M>, listener: (value: DeeplyLoaded<M, Depth>) => void): () => void;
|
246
|
+
applyDiff<N extends Partial<CoMapInit<any>>>(newValues: N): any;
|
247
|
+
/**
|
248
|
+
* Wait for the `CoMap` to be uploaded to the other peers.
|
249
|
+
*
|
250
|
+
* @category Subscription & Loading
|
251
|
+
*/
|
252
|
+
waitForSync(options?: {
|
253
|
+
timeout?: number;
|
254
|
+
}): Promise<unknown[]>;
|
255
|
+
[inspect](): any[];
|
256
|
+
_instanceID: string;
|
257
|
+
readonly _owner: Account | Group;
|
258
|
+
readonly _loadedAs: Account | AnonymousJazzAgent;
|
259
|
+
castAs<Cl extends CoValueClass & import("./interfaces.js").CoValueFromRaw<CoValue>>(cl: Cl): InstanceType<Cl>;
|
260
|
+
};
|
261
|
+
/** @internal */
|
262
|
+
_schema: any;
|
263
|
+
/**
|
264
|
+
* Create a new CoMap with the given initial values and owner.
|
265
|
+
*
|
266
|
+
* The owner (a Group or Account) determines access rights to the CoMap.
|
267
|
+
*
|
268
|
+
* The CoMap will immediately be persisted and synced to connected peers.
|
269
|
+
*
|
270
|
+
* @example
|
271
|
+
* ```ts
|
272
|
+
* const person = Person.create({
|
273
|
+
* name: "Alice",
|
274
|
+
* age: 42,
|
275
|
+
* pet: cat,
|
276
|
+
* }, { owner: friendGroup });
|
277
|
+
* ```
|
278
|
+
*
|
279
|
+
* @category Creation
|
280
|
+
**/
|
281
|
+
create<M extends CoMap>(this: CoValueClass<M>, init: Simplify<CoMapInit<M>>, options?: {
|
282
|
+
owner: Account | Group;
|
283
|
+
unique?: CoValueUniqueness["uniqueness"];
|
284
|
+
} | Account | Group): M;
|
285
|
+
Record<Value>(value: IfCo<Value, Value>): any;
|
286
|
+
/**
|
287
|
+
* Load a `CoMap` with a given ID, as a given account.
|
288
|
+
*
|
289
|
+
* `depth` specifies which (if any) fields that reference other CoValues to load as well before resolving.
|
290
|
+
* The `DeeplyLoaded` return type guarantees that corresponding referenced CoValues are loaded to the specified depth.
|
291
|
+
*
|
292
|
+
* You can pass `[]` or `{}` for shallowly loading only this CoMap, or `{ fieldA: depthA, fieldB: depthB }` for recursively loading referenced CoValues.
|
293
|
+
*
|
294
|
+
* Check out the `load` methods on `CoMap`/`CoList`/`CoFeed`/`Group`/`Account` to see which depth structures are valid to nest.
|
295
|
+
*
|
296
|
+
* @example
|
297
|
+
* ```ts
|
298
|
+
* const person = await Person.load(
|
299
|
+
* "co_zdsMhHtfG6VNKt7RqPUPvUtN2Ax",
|
300
|
+
* { pet: {} }
|
301
|
+
* );
|
302
|
+
* ```
|
303
|
+
*
|
304
|
+
* @category Subscription & Loading
|
305
|
+
*/
|
306
|
+
load<C extends CoMap, Depth>(this: CoValueClass<C>, id: ID<C>, depth: Depth & DepthsIn<C>): Promise<DeeplyLoaded<C, Depth> | undefined>;
|
307
|
+
/**
|
308
|
+
* Load a `CoMap` with a given ID, as a given account.
|
309
|
+
*
|
310
|
+
* `depth` specifies which (if any) fields that reference other CoValues to load as well before resolving.
|
311
|
+
* The `DeeplyLoaded` return type guarantees that corresponding referenced CoValues are loaded to the specified depth.
|
312
|
+
*
|
313
|
+
* You can pass `[]` or `{}` for shallowly loading only this CoMap, or `{ fieldA: depthA, fieldB: depthB }` for recursively loading referenced CoValues.
|
314
|
+
*
|
315
|
+
* Check out the `load` methods on `CoMap`/`CoList`/`CoFeed`/`Group`/`Account` to see which depth structures are valid to nest.
|
316
|
+
*
|
317
|
+
* @example
|
318
|
+
* ```ts
|
319
|
+
* const person = await Person.load(
|
320
|
+
* "co_zdsMhHtfG6VNKt7RqPUPvUtN2Ax",
|
321
|
+
* { pet: {} }
|
322
|
+
* );
|
323
|
+
* ```
|
324
|
+
*
|
325
|
+
* @category Subscription & Loading
|
326
|
+
*/
|
327
|
+
load<C extends CoMap, Depth>(this: CoValueClass<C>, id: ID<C>, as: Account, depth: Depth & DepthsIn<C>): Promise<DeeplyLoaded<C, Depth> | undefined>;
|
328
|
+
/**
|
329
|
+
* Load and subscribe to a `CoMap` with a given ID, as a given account.
|
330
|
+
*
|
331
|
+
* Automatically also subscribes to updates to all referenced/nested CoValues as soon as they are accessed in the listener.
|
332
|
+
*
|
333
|
+
* `depth` specifies which (if any) fields that reference other CoValues to load as well before calling `listener` for the first time.
|
334
|
+
* The `DeeplyLoaded` return type guarantees that corresponding referenced CoValues are loaded to the specified depth.
|
335
|
+
*
|
336
|
+
* You can pass `[]` or `{}` for shallowly loading only this CoMap, or `{ fieldA: depthA, fieldB: depthB }` for recursively loading referenced CoValues.
|
337
|
+
*
|
338
|
+
* Check out the `load` methods on `CoMap`/`CoList`/`CoFeed`/`Group`/`Account` to see which depth structures are valid to nest.
|
339
|
+
*
|
340
|
+
* Returns an unsubscribe function that you should call when you no longer need updates.
|
341
|
+
*
|
342
|
+
* Also see the `useCoState` hook to reactively subscribe to a CoValue in a React component.
|
343
|
+
*
|
344
|
+
* @example
|
345
|
+
* ```ts
|
346
|
+
* const unsub = Person.subscribe(
|
347
|
+
* "co_zdsMhHtfG6VNKt7RqPUPvUtN2Ax",
|
348
|
+
* { pet: {} },
|
349
|
+
* (person) => console.log(person)
|
350
|
+
* );
|
351
|
+
* ```
|
352
|
+
*
|
353
|
+
* @category Subscription & Loading
|
354
|
+
*/
|
355
|
+
subscribe<C extends CoMap, Depth>(this: CoValueClass<C>, id: ID<C>, depth: Depth & DepthsIn<C>, listener: (value: DeeplyLoaded<C, Depth>) => void): () => void;
|
356
|
+
/**
|
357
|
+
* Load and subscribe to a `CoMap` with a given ID, as a given account.
|
358
|
+
*
|
359
|
+
* Automatically also subscribes to updates to all referenced/nested CoValues as soon as they are accessed in the listener.
|
360
|
+
*
|
361
|
+
* `depth` specifies which (if any) fields that reference other CoValues to load as well before calling `listener` for the first time.
|
362
|
+
* The `DeeplyLoaded` return type guarantees that corresponding referenced CoValues are loaded to the specified depth.
|
363
|
+
*
|
364
|
+
* You can pass `[]` or `{}` for shallowly loading only this CoMap, or `{ fieldA: depthA, fieldB: depthB }` for recursively loading referenced CoValues.
|
365
|
+
*
|
366
|
+
* Check out the `load` methods on `CoMap`/`CoList`/`CoFeed`/`Group`/`Account` to see which depth structures are valid to nest.
|
367
|
+
*
|
368
|
+
* Returns an unsubscribe function that you should call when you no longer need updates.
|
369
|
+
*
|
370
|
+
* Also see the `useCoState` hook to reactively subscribe to a CoValue in a React component.
|
371
|
+
*
|
372
|
+
* @example
|
373
|
+
* ```ts
|
374
|
+
* const unsub = Person.subscribe(
|
375
|
+
* "co_zdsMhHtfG6VNKt7RqPUPvUtN2Ax",
|
376
|
+
* { pet: {} },
|
377
|
+
* (person) => console.log(person)
|
378
|
+
* );
|
379
|
+
* ```
|
380
|
+
*
|
381
|
+
* @category Subscription & Loading
|
382
|
+
*/
|
383
|
+
subscribe<C extends CoMap, Depth>(this: CoValueClass<C>, id: ID<C>, as: Account, depth: Depth & DepthsIn<C>, listener: (value: DeeplyLoaded<C, Depth>) => void): () => void;
|
384
|
+
findUnique<M extends CoMap>(this: CoValueClass<M>, unique: CoValueUniqueness["uniqueness"], ownerID: ID<Account> | ID<Group>, as?: Account | Group | AnonymousJazzAgent): ID<M>;
|
385
|
+
fromRaw<V extends CoValue>(this: CoValueClass<V>, raw: import("cojson").RawCoValue): V;
|
386
|
+
};
|
387
|
+
/**
|
388
|
+
* Load a `CoMap` with a given ID, as a given account.
|
389
|
+
*
|
390
|
+
* `depth` specifies which (if any) fields that reference other CoValues to load as well before resolving.
|
391
|
+
* The `DeeplyLoaded` return type guarantees that corresponding referenced CoValues are loaded to the specified depth.
|
392
|
+
*
|
393
|
+
* You can pass `[]` or `{}` for shallowly loading only this CoMap, or `{ fieldA: depthA, fieldB: depthB }` for recursively loading referenced CoValues.
|
394
|
+
*
|
395
|
+
* Check out the `load` methods on `CoMap`/`CoList`/`CoFeed`/`Group`/`Account` to see which depth structures are valid to nest.
|
396
|
+
*
|
397
|
+
* @example
|
398
|
+
* ```ts
|
399
|
+
* const person = await Person.load(
|
400
|
+
* "co_zdsMhHtfG6VNKt7RqPUPvUtN2Ax",
|
401
|
+
* { pet: {} }
|
402
|
+
* );
|
403
|
+
* ```
|
404
|
+
*
|
405
|
+
* @category Subscription & Loading
|
406
|
+
*/
|
407
|
+
static load<C extends CoMap, Depth>(this: CoValueClass<C>, id: ID<C>, depth: Depth & DepthsIn<C>): Promise<DeeplyLoaded<C, Depth> | undefined>;
|
408
|
+
static load<C extends CoMap, Depth>(this: CoValueClass<C>, id: ID<C>, as: Account, depth: Depth & DepthsIn<C>): Promise<DeeplyLoaded<C, Depth> | undefined>;
|
409
|
+
/**
|
410
|
+
* Load and subscribe to a `CoMap` with a given ID, as a given account.
|
411
|
+
*
|
412
|
+
* Automatically also subscribes to updates to all referenced/nested CoValues as soon as they are accessed in the listener.
|
413
|
+
*
|
414
|
+
* `depth` specifies which (if any) fields that reference other CoValues to load as well before calling `listener` for the first time.
|
415
|
+
* The `DeeplyLoaded` return type guarantees that corresponding referenced CoValues are loaded to the specified depth.
|
416
|
+
*
|
417
|
+
* You can pass `[]` or `{}` for shallowly loading only this CoMap, or `{ fieldA: depthA, fieldB: depthB }` for recursively loading referenced CoValues.
|
418
|
+
*
|
419
|
+
* Check out the `load` methods on `CoMap`/`CoList`/`CoFeed`/`Group`/`Account` to see which depth structures are valid to nest.
|
420
|
+
*
|
421
|
+
* Returns an unsubscribe function that you should call when you no longer need updates.
|
422
|
+
*
|
423
|
+
* Also see the `useCoState` hook to reactively subscribe to a CoValue in a React component.
|
424
|
+
*
|
425
|
+
* @example
|
426
|
+
* ```ts
|
427
|
+
* const unsub = Person.subscribe(
|
428
|
+
* "co_zdsMhHtfG6VNKt7RqPUPvUtN2Ax",
|
429
|
+
* { pet: {} },
|
430
|
+
* (person) => console.log(person)
|
431
|
+
* );
|
432
|
+
* ```
|
433
|
+
*
|
434
|
+
* @category Subscription & Loading
|
435
|
+
*/
|
436
|
+
static subscribe<C extends CoMap, Depth>(this: CoValueClass<C>, id: ID<C>, depth: Depth & DepthsIn<C>, listener: (value: DeeplyLoaded<C, Depth>) => void): () => void;
|
437
|
+
static subscribe<C extends CoMap, Depth>(this: CoValueClass<C>, id: ID<C>, as: Account, depth: Depth & DepthsIn<C>, listener: (value: DeeplyLoaded<C, Depth>) => void): () => void;
|
438
|
+
static findUnique<M extends CoMap>(this: CoValueClass<M>, unique: CoValueUniqueness["uniqueness"], ownerID: ID<Account> | ID<Group>, as?: Account | Group | AnonymousJazzAgent): ID<M>;
|
439
|
+
/**
|
440
|
+
* Given an already loaded `CoMap`, ensure that the specified fields are loaded to the specified depth.
|
441
|
+
*
|
442
|
+
* Works like `CoMap.load()`, but you don't need to pass the ID or the account to load as again.
|
443
|
+
*
|
444
|
+
* @category Subscription & Loading
|
445
|
+
*/
|
446
|
+
ensureLoaded<M extends CoMap, Depth>(this: M, depth: Depth & DepthsIn<M>): Promise<DeeplyLoaded<M, Depth>>;
|
447
|
+
/**
|
448
|
+
* Given an already loaded `CoMap`, subscribe to updates to the `CoMap` and ensure that the specified fields are loaded to the specified depth.
|
449
|
+
*
|
450
|
+
* Works like `CoMap.subscribe()`, but you don't need to pass the ID or the account to load as again.
|
451
|
+
*
|
452
|
+
* Returns an unsubscribe function that you should call when you no longer need updates.
|
453
|
+
*
|
454
|
+
* @category Subscription & Loading
|
455
|
+
**/
|
456
|
+
subscribe<M extends CoMap, Depth>(this: M, depth: Depth & DepthsIn<M>, listener: (value: DeeplyLoaded<M, Depth>) => void): () => void;
|
457
|
+
applyDiff<N extends Partial<CoMapInit<this>>>(newValues: N): this;
|
458
|
+
/**
|
459
|
+
* Wait for the `CoMap` to be uploaded to the other peers.
|
460
|
+
*
|
461
|
+
* @category Subscription & Loading
|
462
|
+
*/
|
463
|
+
waitForSync(options?: {
|
464
|
+
timeout?: number;
|
465
|
+
}): Promise<unknown[]>;
|
466
|
+
}
|
467
|
+
export type CoKeys<Map extends object> = Exclude<keyof Map & string, keyof CoMap>;
|
468
|
+
/**
|
469
|
+
* Force required ref fields to be non nullable
|
470
|
+
*
|
471
|
+
* Considering that:
|
472
|
+
* - Optional refs are typed as co<InstanceType<CoValueClass> | null | undefined>
|
473
|
+
* - Required refs are typed as co<InstanceType<CoValueClass> | null>
|
474
|
+
*
|
475
|
+
* This type works in two steps:
|
476
|
+
* - Remove the null from both types
|
477
|
+
* - Then we check if the input type accepts undefined, if positive we put the null union back
|
478
|
+
*
|
479
|
+
* So the optional refs stays unchanged while we safely remove the null union
|
480
|
+
* from required refs
|
481
|
+
*
|
482
|
+
* This way required refs can be marked as required in the CoMapInit while
|
483
|
+
* staying a nullable property for value access.
|
484
|
+
*
|
485
|
+
* Example:
|
486
|
+
*
|
487
|
+
* const map = MyCoMap.create({
|
488
|
+
* requiredRef: NestedMap.create({}) // null is not valid here
|
489
|
+
* })
|
490
|
+
*
|
491
|
+
* map.requiredRef // this value is still nullable
|
492
|
+
*/
|
493
|
+
type ForceRequiredRef<V> = V extends co<InstanceType<CoValueClass> | null> ? NonNullable<V> : V extends co<InstanceType<CoValueClass> | undefined> ? V | null : V;
|
494
|
+
export type CoMapInit<Map extends object> = {
|
495
|
+
[Key in CoKeys<Map> as undefined extends Map[Key] ? never : IfCo<Map[Key], Key>]: ForceRequiredRef<Map[Key]>;
|
496
|
+
} & {
|
497
|
+
[Key in CoKeys<Map> as IfCo<Map[Key], Key>]?: ForceRequiredRef<Map[Key]>;
|
498
|
+
};
|
499
|
+
export {};
|
500
|
+
//# sourceMappingURL=coMap.d.ts.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"coMap.d.ts","sourceRoot":"","sources":["../../src/coValues/coMap.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,OAAO,EACP,KAAK,iBAAiB,EACtB,mBAAmB,EACnB,KAAK,SAAS,EACd,YAAY,EACZ,KAAK,QAAQ,EAEd,MAAM,QAAQ,CAAC;AAEhB,OAAO,KAAK,EACV,kBAAkB,EAClB,OAAO,EACP,YAAY,EACZ,YAAY,EACZ,QAAQ,EACR,EAAE,EACF,IAAI,EAEJ,YAAY,EACZ,MAAM,EACN,EAAE,EACH,MAAM,gBAAgB,CAAC;AACxB,OAAO,EACL,WAAW,EACX,QAAQ,EACR,GAAG,EAGH,OAAO,EAQR,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,KAAK,OAAO,EAAE,MAAM,cAAc,CAAC;AAC5C,OAAO,EAAE,KAAK,KAAK,EAAE,MAAM,YAAY,CAAC;AAGxC,KAAK,SAAS,CAAC,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,OAAO,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC,EAAE,SAAS,EAAE,CAAC;IA8B1D;;;;OAIG;IACH,WAAW,CAAC,OAAO,CAAC,EAAE;QAAE,OAAO,CAAC,EAAE,MAAM,CAAA;KAAE;CAG3C;AAED,MAAM,MAAM,MAAM,CAAC,GAAG,SAAS,MAAM,IAAI,OAAO,CAC9C,MAAM,GAAG,GAAG,MAAM,EAClB,MAAM,KAAK,CACZ,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,KAAK,gBAAgB,CAAC,CAAC,IAAI,CAAC,SAAS,EAAE,CAAC,YAAY,CAAC,YAAY,CAAC,GAAG,IAAI,CAAC,GACtE,WAAW,CAAC,CAAC,CAAC,GACd,CAAC,SAAS,EAAE,CAAC,YAAY,CAAC,YAAY,CAAC,GAAG,SAAS,CAAC,GAClD,CAAC,GAAG,IAAI,GACR,CAAC,CAAC;AAER,MAAM,MAAM,SAAS,CAAC,GAAG,SAAS,MAAM,IAAI;KACzC,GAAG,IAAI,MAAM,CAAC,GAAG,CAAC,IAAI,SAAS,SAAS,GAAG,CAAC,GAAG,CAAC,GAC7C,KAAK,GACL,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,GAAG,CAAC,GAAG,gBAAgB,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;CACrD,GAAG;KACD,GAAG,IAAI,MAAM,CAAC,GAAG,CAAC,IAAI,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,GAAG,CAAC,CAAC,CAAC,EAAE,gBAAgB,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;CACzE,CAAC"}
|
@@ -0,0 +1,69 @@
|
|
1
|
+
import { type OpID, type RawCoPlainText } from "cojson";
|
2
|
+
import type { CoValue, CoValueClass, ID } from "../internal.js";
|
3
|
+
import { inspect } from "../internal.js";
|
4
|
+
import { Account } from "./account.js";
|
5
|
+
import { Group } from "./group.js";
|
6
|
+
export type TextPos = OpID;
|
7
|
+
export declare class CoPlainText extends String implements CoValue {
|
8
|
+
id: ID<this>;
|
9
|
+
_type: "CoPlainText";
|
10
|
+
_raw: RawCoPlainText;
|
11
|
+
get _owner(): Account | Group;
|
12
|
+
get _loadedAs(): Account;
|
13
|
+
constructor(options: {
|
14
|
+
fromRaw: RawCoPlainText;
|
15
|
+
} | {
|
16
|
+
text: string;
|
17
|
+
owner: Account | Group;
|
18
|
+
});
|
19
|
+
static create<T extends CoPlainText>(this: CoValueClass<T>, text: string, options: {
|
20
|
+
owner: Account | Group;
|
21
|
+
}): T;
|
22
|
+
get length(): number;
|
23
|
+
toString(): string;
|
24
|
+
valueOf(): string;
|
25
|
+
toJSON(): string;
|
26
|
+
[inspect](): string;
|
27
|
+
insertAfter(idx: number, text: string): void;
|
28
|
+
deleteRange(range: {
|
29
|
+
from: number;
|
30
|
+
to: number;
|
31
|
+
}): void;
|
32
|
+
posBefore(idx: number): TextPos | undefined;
|
33
|
+
posAfter(idx: number): TextPos | undefined;
|
34
|
+
idxBefore(pos: TextPos): number | undefined;
|
35
|
+
idxAfter(pos: TextPos): number | undefined;
|
36
|
+
static fromRaw<V extends CoPlainText>(this: CoValueClass<V> & typeof CoPlainText, raw: RawCoPlainText): V & CoPlainText;
|
37
|
+
/**
|
38
|
+
* Load a `CoPlainText` with a given ID, as a given account.
|
39
|
+
*
|
40
|
+
* @category Subscription & Loading
|
41
|
+
*/
|
42
|
+
static load<T extends CoPlainText>(this: CoValueClass<T>, id: ID<T>, as?: Account): Promise<T | undefined>;
|
43
|
+
/**
|
44
|
+
* Load and subscribe to a `CoPlainText` with a given ID, as a given account.
|
45
|
+
*
|
46
|
+
* Automatically also subscribes to updates to all referenced/nested CoValues as soon as they are accessed in the listener.
|
47
|
+
*
|
48
|
+
* Check out the `load` methods on `CoMap`/`CoList`/`CoStream`/`Group`/`Account` to see which depth structures are valid to nest.
|
49
|
+
*
|
50
|
+
* Returns an unsubscribe function that you should call when you no longer need updates.
|
51
|
+
*
|
52
|
+
* Also see the `useCoState` hook to reactively subscribe to a CoValue in a React component.
|
53
|
+
*
|
54
|
+
* @category Subscription & Loading
|
55
|
+
*/
|
56
|
+
static subscribe<T extends CoPlainText>(this: CoValueClass<T>, id: ID<T>, listener: (value: T) => void): () => void;
|
57
|
+
static subscribe<T extends CoPlainText>(this: CoValueClass<T>, id: ID<T>, as: Account, listener: (value: T) => void): () => void;
|
58
|
+
/**
|
59
|
+
* Given an already loaded `CoPlainText`, subscribe to updates to the `CoPlainText` and ensure that the specified fields are loaded to the specified depth.
|
60
|
+
*
|
61
|
+
* Works like `CoPlainText.subscribe()`, but you don't need to pass the ID or the account to load as again.
|
62
|
+
*
|
63
|
+
* Returns an unsubscribe function that you should call when you no longer need updates.
|
64
|
+
*
|
65
|
+
* @category Subscription & Loading
|
66
|
+
**/
|
67
|
+
subscribe<T extends CoPlainText>(this: T, listener: (value: T) => void): () => void;
|
68
|
+
}
|
69
|
+
//# sourceMappingURL=coPlainText.d.ts.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"coPlainText.d.ts","sourceRoot":"","sources":["../../src/coValues/coPlainText.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,IAAI,EAET,KAAK,cAAc,EAEpB,MAAM,QAAQ,CAAC;AAEhB,OAAO,KAAK,EAAE,OAAO,EAAE,YAAY,EAAE,EAAE,EAAE,MAAM,gBAAgB,CAAC;AAChE,OAAO,EACL,OAAO,EAKR,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AACvC,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AAEnC,MAAM,MAAM,OAAO,GAAG,IAAI,CAAC;AAE3B,qBAAa,WAAY,SAAQ,MAAO,YAAW,OAAO;IAChD,EAAE,EAAE,EAAE,CAAC,IAAI,CAAC,CAAC;IACb,KAAK,EAAE,aAAa,CAAC;IACrB,IAAI,EAAE,cAAc,CAAC;IAE7B,IAAI,M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