cojson 0.4.0 → 0.4.5
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/dist/coValue.js +1 -1
- package/dist/coValue.js.map +1 -1
- package/dist/coValues/coList.js +1 -1
- package/dist/coValues/coList.js.map +1 -1
- package/dist/coValues/coMap.js +1 -1
- package/dist/coValues/coMap.js.map +1 -1
- package/dist/coValues/coStream.js +3 -2
- package/dist/coValues/coStream.js.map +1 -1
- package/dist/coValues/group.js.map +1 -1
- package/dist/index.js +2 -4
- package/dist/index.js.map +1 -1
- package/dist/localNode.js +1 -14
- package/dist/localNode.js.map +1 -1
- package/package.json +4 -4
- package/src/coValue.ts +10 -7
- package/src/coValues/coList.ts +1 -1
- package/src/coValues/coMap.ts +1 -1
- package/src/coValues/coStream.ts +4 -6
- package/src/coValues/group.ts +4 -4
- package/src/index.ts +16 -16
- package/src/localNode.ts +6 -47
- package/src/tests/coValue.test.ts +5 -5
- package/src/tests/group.test.ts +1 -1
- package/dist/base64url.d.ts +0 -2
- package/dist/coValue.d.ts +0 -38
- package/dist/coValueCore.d.ts +0 -103
- package/dist/coValues/account.d.ts +0 -62
- package/dist/coValues/coList.d.ts +0 -179
- package/dist/coValues/coMap.d.ts +0 -149
- package/dist/coValues/coStream.d.ts +0 -123
- package/dist/coValues/group.d.ts +0 -111
- package/dist/crypto.d.ts +0 -120
- package/dist/ids.d.ts +0 -11
- package/dist/index.d.ts +0 -67
- package/dist/jsonStringify.d.ts +0 -6
- package/dist/jsonValue.d.ts +0 -7
- package/dist/localNode.d.ts +0 -101
- package/dist/media.d.ts +0 -7
- package/dist/permissions.d.ts +0 -20
- package/dist/queriedCoValues/queriedAccount.d.ts +0 -13
- package/dist/queriedCoValues/queriedAccount.js +0 -24
- package/dist/queriedCoValues/queriedAccount.js.map +0 -1
- package/dist/queriedCoValues/queriedCoList.d.ts +0 -66
- package/dist/queriedCoValues/queriedCoList.js +0 -116
- package/dist/queriedCoValues/queriedCoList.js.map +0 -1
- package/dist/queriedCoValues/queriedCoMap.d.ts +0 -40
- package/dist/queriedCoValues/queriedCoMap.js +0 -82
- package/dist/queriedCoValues/queriedCoMap.js.map +0 -1
- package/dist/queriedCoValues/queriedCoStream.d.ts +0 -40
- package/dist/queriedCoValues/queriedCoStream.js +0 -96
- package/dist/queriedCoValues/queriedCoStream.js.map +0 -1
- package/dist/queriedCoValues/queriedGroup.d.ts +0 -29
- package/dist/queriedCoValues/queriedGroup.js +0 -54
- package/dist/queriedCoValues/queriedGroup.js.map +0 -1
- package/dist/queries.d.ts +0 -62
- package/dist/queries.js +0 -142
- package/dist/queries.js.map +0 -1
- package/dist/streamUtils.d.ts +0 -8
- package/dist/sync.d.ts +0 -80
- package/dist/tests/testUtils.d.ts +0 -37
- package/src/queriedCoValues/queriedAccount.ts +0 -40
- package/src/queriedCoValues/queriedCoList.ts +0 -240
- package/src/queriedCoValues/queriedCoMap.ts +0 -168
- package/src/queriedCoValues/queriedCoStream.ts +0 -155
- package/src/queriedCoValues/queriedGroup.ts +0 -90
- package/src/queries.ts +0 -263
- package/src/tests/queries.test.ts +0 -337
|
@@ -1,240 +0,0 @@
|
|
|
1
|
-
import { CoList, MutableCoList } from "../coValues/coList.js";
|
|
2
|
-
import { CoValueCore } from "../coValueCore.js";
|
|
3
|
-
import { Group } from "../coValues/group.js";
|
|
4
|
-
import { CoID, CoValue } from "../coValue.js";
|
|
5
|
-
import { TransactionID } from "../ids.js";
|
|
6
|
-
import { ValueOrSubQueried, QueryContext } from "../queries.js";
|
|
7
|
-
import { QueriedAccount } from "./queriedAccount.js";
|
|
8
|
-
|
|
9
|
-
export class QueriedCoList<L extends CoList> extends Array<
|
|
10
|
-
ValueOrSubQueried<L["_item"]>
|
|
11
|
-
> {
|
|
12
|
-
coList!: L;
|
|
13
|
-
id!: CoID<L>;
|
|
14
|
-
type!: "colist";
|
|
15
|
-
|
|
16
|
-
/** @internal */
|
|
17
|
-
constructor(coList: L, queryContext: QueryContext) {
|
|
18
|
-
if (!(coList instanceof CoList)) {
|
|
19
|
-
// this might be called from an intrinsic, like map, trying to create an empty array
|
|
20
|
-
// passing `0` as the only parameter
|
|
21
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
22
|
-
return new Array(coList) as any;
|
|
23
|
-
}
|
|
24
|
-
super(
|
|
25
|
-
...coList
|
|
26
|
-
.asArray()
|
|
27
|
-
.map(
|
|
28
|
-
(item) =>
|
|
29
|
-
queryContext.queryIfCoID(item, [coList.id]) as ValueOrSubQueried<
|
|
30
|
-
L["_item"]
|
|
31
|
-
>
|
|
32
|
-
)
|
|
33
|
-
);
|
|
34
|
-
|
|
35
|
-
Object.defineProperties(this, {
|
|
36
|
-
coList: { get() {return coList} },
|
|
37
|
-
id: { value: coList.id },
|
|
38
|
-
type: { value: "colist" },
|
|
39
|
-
edits: {
|
|
40
|
-
value: [...this.keys()].map((i) => {
|
|
41
|
-
const edit = coList.editAt(i)!;
|
|
42
|
-
return queryContext.defineSubqueryPropertiesIn({
|
|
43
|
-
|
|
44
|
-
tx: edit.tx,
|
|
45
|
-
at: new Date(edit.at),
|
|
46
|
-
}, {
|
|
47
|
-
by: {value: edit.by, enumerable: true},
|
|
48
|
-
value: {value: edit.value, enumerable: true},
|
|
49
|
-
}, [coList.id]);
|
|
50
|
-
}),
|
|
51
|
-
},
|
|
52
|
-
deletions: {
|
|
53
|
-
value: coList.deletionEdits().map((deletion) => queryContext.defineSubqueryPropertiesIn({
|
|
54
|
-
|
|
55
|
-
tx: deletion.tx,
|
|
56
|
-
at: new Date(deletion.at),
|
|
57
|
-
}, {
|
|
58
|
-
by: {value: deletion.by, enumerable: true},
|
|
59
|
-
}, [coList.id])),
|
|
60
|
-
},
|
|
61
|
-
});
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
get meta(): L["meta"] {
|
|
65
|
-
return this.coList.meta;
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
get group(): Group {
|
|
69
|
-
return this.coList.group;
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
get core(): CoValueCore {
|
|
73
|
-
return this.coList.core;
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
append(
|
|
77
|
-
item: L["_item"],
|
|
78
|
-
after?: number,
|
|
79
|
-
privacy?: "private" | "trusting"
|
|
80
|
-
): L {
|
|
81
|
-
return this.coList.append(item, after, privacy);
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
prepend(
|
|
85
|
-
item: L["_item"],
|
|
86
|
-
before?: number,
|
|
87
|
-
privacy?: "private" | "trusting"
|
|
88
|
-
): L {
|
|
89
|
-
return this.coList.prepend(item, before, privacy);
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
delete(at: number, privacy?: "private" | "trusting"): L {
|
|
93
|
-
return this.coList.delete(at, privacy);
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
mutate(
|
|
97
|
-
mutator: (mutable: MutableCoList<L["_item"], L["meta"]>) => void
|
|
98
|
-
): L {
|
|
99
|
-
return this.coList.mutate(mutator);
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
edits!: {
|
|
103
|
-
by?: QueriedAccount;
|
|
104
|
-
tx: TransactionID;
|
|
105
|
-
at: Date;
|
|
106
|
-
value: L["_item"] extends CoValue
|
|
107
|
-
? CoID<L["_item"]>
|
|
108
|
-
: Exclude<L["_item"], CoValue>;
|
|
109
|
-
}[];
|
|
110
|
-
|
|
111
|
-
deletions!: {
|
|
112
|
-
by?: QueriedAccount;
|
|
113
|
-
tx: TransactionID;
|
|
114
|
-
at: Date;
|
|
115
|
-
}[];
|
|
116
|
-
|
|
117
|
-
/** @internal */
|
|
118
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
119
|
-
static isArray(arg: any): arg is any[] {
|
|
120
|
-
return Array.isArray(arg);
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
/** @internal */
|
|
124
|
-
static from<T>(arrayLike: ArrayLike<T>): T[];
|
|
125
|
-
/** @internal */
|
|
126
|
-
static from<T, U>(
|
|
127
|
-
arrayLike: ArrayLike<T>,
|
|
128
|
-
mapfn: (v: T, k: number) => U,
|
|
129
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
130
|
-
thisArg?: any
|
|
131
|
-
): U[];
|
|
132
|
-
/** @internal */
|
|
133
|
-
static from<T>(iterable: Iterable<T> | ArrayLike<T>): T[];
|
|
134
|
-
/** @internal */
|
|
135
|
-
static from<T, U>(
|
|
136
|
-
iterable: Iterable<T> | ArrayLike<T>,
|
|
137
|
-
mapfn: (v: T, k: number) => U,
|
|
138
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
139
|
-
thisArg?: any
|
|
140
|
-
): U[];
|
|
141
|
-
/** @internal */
|
|
142
|
-
static from<T, U>(
|
|
143
|
-
_iterable: unknown,
|
|
144
|
-
_mapfn?: unknown,
|
|
145
|
-
_thisArg?: unknown
|
|
146
|
-
): T[] | U[] | T[] | U[] {
|
|
147
|
-
throw new Error("Array method 'from' not supported on QueriedCoList");
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
/** @internal */
|
|
151
|
-
static of<T>(..._items: T[]): T[] {
|
|
152
|
-
throw new Error("Array method 'of' not supported on QueriedCoList");
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
/** @internal */
|
|
156
|
-
pop(): ValueOrSubQueried<L["_item"]> | undefined {
|
|
157
|
-
throw new Error("Array method 'pop' not supported on QueriedCoList");
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
/** @internal */
|
|
161
|
-
push(..._items: ValueOrSubQueried<L["_item"]>[]): number {
|
|
162
|
-
throw new Error("Array method 'push' not supported on QueriedCoList");
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
/** @internal */
|
|
166
|
-
concat(
|
|
167
|
-
..._items: ConcatArray<ValueOrSubQueried<L["_item"]>>[]
|
|
168
|
-
): ValueOrSubQueried<L["_item"]>[];
|
|
169
|
-
/** @internal */
|
|
170
|
-
concat(
|
|
171
|
-
..._items: (
|
|
172
|
-
| ValueOrSubQueried<L["_item"]>
|
|
173
|
-
| ConcatArray<ValueOrSubQueried<L["_item"]>>
|
|
174
|
-
)[]
|
|
175
|
-
): ValueOrSubQueried<L["_item"]>[];
|
|
176
|
-
/** @internal */
|
|
177
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
178
|
-
concat(..._items: any[]): ValueOrSubQueried<L["_item"]>[] {
|
|
179
|
-
throw new Error("Array method 'concat' not supported on QueriedCoList");
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
/** @internal */
|
|
183
|
-
reverse(): ValueOrSubQueried<L["_item"]>[] {
|
|
184
|
-
throw new Error(
|
|
185
|
-
"Array method 'reverse' not supported on QueriedCoList"
|
|
186
|
-
);
|
|
187
|
-
}
|
|
188
|
-
|
|
189
|
-
/** @internal */
|
|
190
|
-
shift(): ValueOrSubQueried<L["_item"]> | undefined {
|
|
191
|
-
throw new Error("Array method 'shift' not supported on QueriedCoList");
|
|
192
|
-
}
|
|
193
|
-
|
|
194
|
-
/** @internal */
|
|
195
|
-
sort(
|
|
196
|
-
_compareFn?:
|
|
197
|
-
| ((
|
|
198
|
-
a: ValueOrSubQueried<L["_item"]>,
|
|
199
|
-
b: ValueOrSubQueried<L["_item"]>
|
|
200
|
-
) => number)
|
|
201
|
-
| undefined
|
|
202
|
-
): this {
|
|
203
|
-
throw new Error("Array method 'sort' not supported on QueriedCoList");
|
|
204
|
-
}
|
|
205
|
-
|
|
206
|
-
/** @internal */
|
|
207
|
-
splice(
|
|
208
|
-
_start: number,
|
|
209
|
-
_deleteCount?: number | undefined
|
|
210
|
-
): ValueOrSubQueried<L["_item"]>[] {
|
|
211
|
-
throw new Error("Array method 'splice' not supported on QueriedCoList");
|
|
212
|
-
}
|
|
213
|
-
|
|
214
|
-
/** @internal */
|
|
215
|
-
unshift(..._items: ValueOrSubQueried<L["_item"]>[]): number {
|
|
216
|
-
throw new Error(
|
|
217
|
-
"Array method 'unshift' not supported on QueriedCoList"
|
|
218
|
-
);
|
|
219
|
-
}
|
|
220
|
-
|
|
221
|
-
/** @internal */
|
|
222
|
-
fill(
|
|
223
|
-
_value: ValueOrSubQueried<L["_item"]>,
|
|
224
|
-
_start?: number | undefined,
|
|
225
|
-
_end?: number | undefined
|
|
226
|
-
): this {
|
|
227
|
-
throw new Error("Array method 'fill' not supported on QueriedCoList");
|
|
228
|
-
}
|
|
229
|
-
|
|
230
|
-
/** @internal */
|
|
231
|
-
copyWithin(
|
|
232
|
-
_target: number,
|
|
233
|
-
_start: number,
|
|
234
|
-
_end?: number | undefined
|
|
235
|
-
): this {
|
|
236
|
-
throw new Error(
|
|
237
|
-
"Array method 'copyWithin' not supported on QueriedCoList"
|
|
238
|
-
);
|
|
239
|
-
}
|
|
240
|
-
}
|
|
@@ -1,168 +0,0 @@
|
|
|
1
|
-
import { CoMap, MutableCoMap } from "../coValues/coMap.js";
|
|
2
|
-
import { CoValueCore } from "../coValueCore.js";
|
|
3
|
-
import { Group } from "../coValues/group.js";
|
|
4
|
-
import { CoID } from "../coValue.js";
|
|
5
|
-
import { TransactionID } from "../ids.js";
|
|
6
|
-
import { ValueOrSubQueried, QueryContext, QueryExtension } from "../queries.js";
|
|
7
|
-
import { QueriedAccount } from "./queriedAccount.js";
|
|
8
|
-
|
|
9
|
-
export type QueriedCoMap<M extends CoMap> = {
|
|
10
|
-
[K in keyof M["_shape"] & string]: ValueOrSubQueried<M["_shape"][K]>;
|
|
11
|
-
} & QueriedCoMapBase<M>;
|
|
12
|
-
|
|
13
|
-
export type QueriedCoMapEdit<M extends CoMap, K extends keyof M["_shape"]> = {
|
|
14
|
-
by?: QueriedAccount;
|
|
15
|
-
tx: TransactionID;
|
|
16
|
-
at: Date;
|
|
17
|
-
value: M["_shape"][K];
|
|
18
|
-
};
|
|
19
|
-
|
|
20
|
-
export class QueriedCoMapBase<M extends CoMap> {
|
|
21
|
-
coMap!: M;
|
|
22
|
-
id!: CoID<M>;
|
|
23
|
-
type!: "comap";
|
|
24
|
-
|
|
25
|
-
/** @internal */
|
|
26
|
-
static newWithKVPairs<M extends CoMap>(
|
|
27
|
-
coMap: M,
|
|
28
|
-
queryContext: QueryContext
|
|
29
|
-
): QueriedCoMap<M> {
|
|
30
|
-
const kv = {} as {
|
|
31
|
-
[K in keyof M["_shape"] & string]: ValueOrSubQueried<
|
|
32
|
-
M["_shape"][K]
|
|
33
|
-
>;
|
|
34
|
-
};
|
|
35
|
-
for (const key of coMap.keys()) {
|
|
36
|
-
const value = coMap.get(key);
|
|
37
|
-
|
|
38
|
-
if (value === undefined) continue;
|
|
39
|
-
|
|
40
|
-
queryContext.defineSubqueryPropertiesIn(
|
|
41
|
-
kv,
|
|
42
|
-
{
|
|
43
|
-
[key]: { value, enumerable: true },
|
|
44
|
-
},
|
|
45
|
-
[coMap.id]
|
|
46
|
-
);
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
return Object.assign(new QueriedCoMapBase(coMap, queryContext), kv);
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
/** @internal */
|
|
53
|
-
constructor(coMap: M, queryContext: QueryContext) {
|
|
54
|
-
Object.defineProperties(this, {
|
|
55
|
-
coMap: {
|
|
56
|
-
get() {
|
|
57
|
-
return coMap;
|
|
58
|
-
},
|
|
59
|
-
enumerable: false,
|
|
60
|
-
},
|
|
61
|
-
id: { value: coMap.id, enumerable: false },
|
|
62
|
-
type: { value: "comap", enumerable: false },
|
|
63
|
-
edits: {
|
|
64
|
-
value: Object.fromEntries(
|
|
65
|
-
coMap.keys().flatMap((key) => {
|
|
66
|
-
const edits = [...coMap.editsAt(key)].map((edit) =>
|
|
67
|
-
queryContext.defineSubqueryPropertiesIn(
|
|
68
|
-
{
|
|
69
|
-
tx: edit.tx,
|
|
70
|
-
at: new Date(edit.at),
|
|
71
|
-
},
|
|
72
|
-
{
|
|
73
|
-
by: { value: edit.by, enumerable: true },
|
|
74
|
-
value: {
|
|
75
|
-
value: edit.value,
|
|
76
|
-
enumerable: true,
|
|
77
|
-
},
|
|
78
|
-
},
|
|
79
|
-
[coMap.id]
|
|
80
|
-
)
|
|
81
|
-
);
|
|
82
|
-
const lastEdit = edits[edits.length - 1];
|
|
83
|
-
if (!lastEdit) return [];
|
|
84
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
85
|
-
const editsAtKey = {
|
|
86
|
-
by: lastEdit.by,
|
|
87
|
-
tx: lastEdit.tx,
|
|
88
|
-
at: lastEdit.at,
|
|
89
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
90
|
-
value: lastEdit.value as any,
|
|
91
|
-
all: edits,
|
|
92
|
-
};
|
|
93
|
-
|
|
94
|
-
return [[key, editsAtKey]];
|
|
95
|
-
})
|
|
96
|
-
),
|
|
97
|
-
enumerable: false,
|
|
98
|
-
},
|
|
99
|
-
as: {
|
|
100
|
-
value: <O>(extension: QueryExtension<M, O>) => {
|
|
101
|
-
return queryContext.getOrCreateExtension(
|
|
102
|
-
coMap.id,
|
|
103
|
-
extension
|
|
104
|
-
);
|
|
105
|
-
},
|
|
106
|
-
enumerable: false,
|
|
107
|
-
},
|
|
108
|
-
});
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
edits!: {
|
|
112
|
-
[K in keyof M["_shape"] & string]:
|
|
113
|
-
| (QueriedCoMapEdit<M, K> & {
|
|
114
|
-
all: QueriedCoMapEdit<M, K>[];
|
|
115
|
-
})
|
|
116
|
-
| undefined;
|
|
117
|
-
};
|
|
118
|
-
|
|
119
|
-
get meta(): M["meta"] {
|
|
120
|
-
return this.coMap.meta;
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
get group(): Group {
|
|
124
|
-
return this.coMap.group;
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
get core(): CoValueCore {
|
|
128
|
-
return this.coMap.core;
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
set<K extends keyof M["_shape"] & string>(
|
|
132
|
-
key: K,
|
|
133
|
-
value: M["_shape"][K],
|
|
134
|
-
privacy?: "private" | "trusting"
|
|
135
|
-
): M;
|
|
136
|
-
set(
|
|
137
|
-
kv: {
|
|
138
|
-
[K in keyof M["_shape"] & string]?: M["_shape"][K];
|
|
139
|
-
},
|
|
140
|
-
privacy?: "private" | "trusting"
|
|
141
|
-
): M;
|
|
142
|
-
set<K extends keyof M["_shape"] & string>(
|
|
143
|
-
...args:
|
|
144
|
-
| [
|
|
145
|
-
{
|
|
146
|
-
[K in keyof M["_shape"] & string]?: M["_shape"][K];
|
|
147
|
-
},
|
|
148
|
-
("private" | "trusting")?
|
|
149
|
-
]
|
|
150
|
-
| [K, M["_shape"][K], ("private" | "trusting")?]
|
|
151
|
-
): M {
|
|
152
|
-
// eslint-disable-next-line @typescript-eslint/ban-types
|
|
153
|
-
return (this.coMap.set as Function)(...args);
|
|
154
|
-
}
|
|
155
|
-
delete(
|
|
156
|
-
key: keyof M["_shape"] & string,
|
|
157
|
-
privacy?: "private" | "trusting"
|
|
158
|
-
): M {
|
|
159
|
-
return this.coMap.delete(key, privacy);
|
|
160
|
-
}
|
|
161
|
-
mutate(
|
|
162
|
-
mutator: (mutable: MutableCoMap<M["_shape"], M["meta"]>) => void
|
|
163
|
-
): M {
|
|
164
|
-
return this.coMap.mutate(mutator);
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
as!: <O>(extension: QueryExtension<M, O>) => O | undefined;
|
|
168
|
-
}
|
|
@@ -1,155 +0,0 @@
|
|
|
1
|
-
import { JsonValue } from "../jsonValue.js";
|
|
2
|
-
import { CoStream, MutableCoStream } from "../coValues/coStream.js";
|
|
3
|
-
import { CoValueCore } from "../coValueCore.js";
|
|
4
|
-
import { Group } from "../coValues/group.js";
|
|
5
|
-
import { AccountID, isAccountID } from "../coValues/account.js";
|
|
6
|
-
import { CoID, CoValue } from "../coValue.js";
|
|
7
|
-
import { SessionID, TransactionID } from "../ids.js";
|
|
8
|
-
import { ValueOrSubQueried, QueryContext } from "../queries.js";
|
|
9
|
-
import { QueriedAccount } from "./queriedAccount.js";
|
|
10
|
-
|
|
11
|
-
export type QueriedCoStreamItems<Item extends JsonValue | CoValue> = {
|
|
12
|
-
last?: ValueOrSubQueried<Item>;
|
|
13
|
-
by?: QueriedAccount;
|
|
14
|
-
tx?: TransactionID;
|
|
15
|
-
at?: Date;
|
|
16
|
-
all: {
|
|
17
|
-
value: ValueOrSubQueried<Item>;
|
|
18
|
-
by?: QueriedAccount;
|
|
19
|
-
tx: TransactionID;
|
|
20
|
-
at: Date;
|
|
21
|
-
}[];
|
|
22
|
-
};
|
|
23
|
-
|
|
24
|
-
export class QueriedCoStream<S extends CoStream> {
|
|
25
|
-
coStream!: S;
|
|
26
|
-
id: CoID<S>;
|
|
27
|
-
type = "costream" as const;
|
|
28
|
-
|
|
29
|
-
/** @internal */
|
|
30
|
-
constructor(coStream: S, queryContext: QueryContext) {
|
|
31
|
-
Object.defineProperty(this, "coStream", {
|
|
32
|
-
get() {
|
|
33
|
-
return coStream;
|
|
34
|
-
},
|
|
35
|
-
});
|
|
36
|
-
this.id = coStream.id;
|
|
37
|
-
|
|
38
|
-
this.perSession = Object.fromEntries(
|
|
39
|
-
coStream.sessions().map((sessionID) => {
|
|
40
|
-
const items = [...coStream.itemsIn(sessionID)].map((item) =>
|
|
41
|
-
queryContext.defineSubqueryPropertiesIn(
|
|
42
|
-
{
|
|
43
|
-
tx: item.tx,
|
|
44
|
-
at: new Date(item.at),
|
|
45
|
-
},
|
|
46
|
-
{
|
|
47
|
-
by: {
|
|
48
|
-
value: isAccountID(item.by)
|
|
49
|
-
? item.by
|
|
50
|
-
: (undefined as never),
|
|
51
|
-
enumerable: true,
|
|
52
|
-
},
|
|
53
|
-
value: {
|
|
54
|
-
value: item.value as S["_item"],
|
|
55
|
-
enumerable: true,
|
|
56
|
-
},
|
|
57
|
-
},
|
|
58
|
-
[coStream.id]
|
|
59
|
-
)
|
|
60
|
-
);
|
|
61
|
-
|
|
62
|
-
const lastItem = items[items.length - 1];
|
|
63
|
-
|
|
64
|
-
return [
|
|
65
|
-
sessionID,
|
|
66
|
-
{
|
|
67
|
-
get last() {
|
|
68
|
-
return lastItem?.value;
|
|
69
|
-
},
|
|
70
|
-
get by() {
|
|
71
|
-
return lastItem?.by;
|
|
72
|
-
},
|
|
73
|
-
tx: lastItem?.tx,
|
|
74
|
-
at: lastItem?.at,
|
|
75
|
-
all: items,
|
|
76
|
-
} satisfies QueriedCoStreamItems<S["_item"]>,
|
|
77
|
-
];
|
|
78
|
-
})
|
|
79
|
-
);
|
|
80
|
-
|
|
81
|
-
this.perAccount = Object.fromEntries(
|
|
82
|
-
[...coStream.accounts()].map((accountID) => {
|
|
83
|
-
const items = [...coStream.itemsBy(accountID)].map((item) => queryContext.defineSubqueryPropertiesIn(
|
|
84
|
-
{
|
|
85
|
-
tx: item.tx,
|
|
86
|
-
at: new Date(item.at),
|
|
87
|
-
},
|
|
88
|
-
{
|
|
89
|
-
by: {
|
|
90
|
-
value: isAccountID(item.by)
|
|
91
|
-
? item.by
|
|
92
|
-
: (undefined as never),
|
|
93
|
-
enumerable: true,
|
|
94
|
-
},
|
|
95
|
-
value: {
|
|
96
|
-
value: item.value as S["_item"],
|
|
97
|
-
enumerable: true,
|
|
98
|
-
},
|
|
99
|
-
},
|
|
100
|
-
[coStream.id]
|
|
101
|
-
));
|
|
102
|
-
|
|
103
|
-
const lastItem = items[items.length - 1];
|
|
104
|
-
|
|
105
|
-
return [
|
|
106
|
-
accountID,
|
|
107
|
-
{
|
|
108
|
-
get last() {
|
|
109
|
-
return lastItem?.value;
|
|
110
|
-
},
|
|
111
|
-
get by() {
|
|
112
|
-
return lastItem?.by;
|
|
113
|
-
},
|
|
114
|
-
tx: lastItem?.tx,
|
|
115
|
-
at: lastItem?.at,
|
|
116
|
-
all: items,
|
|
117
|
-
} satisfies QueriedCoStreamItems<S["_item"]>,
|
|
118
|
-
];
|
|
119
|
-
})
|
|
120
|
-
);
|
|
121
|
-
|
|
122
|
-
this.me = isAccountID(queryContext.node.account.id)
|
|
123
|
-
? this.perAccount[queryContext.node.account.id]
|
|
124
|
-
: undefined;
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
get meta(): S["meta"] {
|
|
128
|
-
return this.coStream.meta;
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
get group(): Group {
|
|
132
|
-
return this.coStream.group;
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
get core(): CoValueCore {
|
|
136
|
-
return this.coStream.core;
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
me?: QueriedCoStreamItems<S["_item"]>;
|
|
140
|
-
perAccount: {
|
|
141
|
-
[account: AccountID]: QueriedCoStreamItems<S["_item"]>;
|
|
142
|
-
};
|
|
143
|
-
perSession: {
|
|
144
|
-
[session: SessionID]: QueriedCoStreamItems<S["_item"]>;
|
|
145
|
-
};
|
|
146
|
-
|
|
147
|
-
push(item: S["_item"], privacy?: "private" | "trusting"): S {
|
|
148
|
-
return this.coStream.push(item, privacy);
|
|
149
|
-
}
|
|
150
|
-
mutate(
|
|
151
|
-
mutator: (mutable: MutableCoStream<S["_item"], S["meta"]>) => void
|
|
152
|
-
): S {
|
|
153
|
-
return this.coStream.mutate(mutator);
|
|
154
|
-
}
|
|
155
|
-
}
|
|
@@ -1,90 +0,0 @@
|
|
|
1
|
-
import { Everyone, Group, InviteSecret } from "../coValues/group.js";
|
|
2
|
-
import { CoID } from "../coValue.js";
|
|
3
|
-
import { QueryContext, ValueOrSubQueried } from "../queries.js";
|
|
4
|
-
import { CoValueCore } from "../coValueCore.js";
|
|
5
|
-
import { Role } from "../permissions.js";
|
|
6
|
-
import { AccountID } from "../coValues/account.js";
|
|
7
|
-
import { CoMap } from "../coValues/coMap.js";
|
|
8
|
-
import { CoList } from "../coValues/coList.js";
|
|
9
|
-
import { CoStream } from "../coValues/coStream.js";
|
|
10
|
-
import { BinaryCoStream } from "../coValues/coStream.js";
|
|
11
|
-
|
|
12
|
-
export class QueriedGroup<G extends Group = Group> {
|
|
13
|
-
group!: G;
|
|
14
|
-
id!: CoID<G>;
|
|
15
|
-
type = "group" as const;
|
|
16
|
-
profile?: ValueOrSubQueried<G["_shape"]["profile"]>;
|
|
17
|
-
root?: ValueOrSubQueried<G["_shape"]["root"]>;
|
|
18
|
-
|
|
19
|
-
constructor(group: G, queryContext: QueryContext) {
|
|
20
|
-
const profileID = group.get("profile");
|
|
21
|
-
const rootID = group.get("root");
|
|
22
|
-
queryContext.defineSubqueryPropertiesIn(Object.defineProperties(this, {
|
|
23
|
-
group: {
|
|
24
|
-
get() {
|
|
25
|
-
return group;
|
|
26
|
-
},
|
|
27
|
-
enumerable: false,
|
|
28
|
-
},
|
|
29
|
-
id: { value: group.id, enumerable: false },
|
|
30
|
-
type: { value: "group", enumerable: false },
|
|
31
|
-
}), {
|
|
32
|
-
profile: {
|
|
33
|
-
value: profileID,
|
|
34
|
-
enumerable: false,
|
|
35
|
-
},
|
|
36
|
-
root: {
|
|
37
|
-
value: rootID,
|
|
38
|
-
enumerable: false,
|
|
39
|
-
},
|
|
40
|
-
}, [group.id]);
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
get meta(): G["meta"] {
|
|
44
|
-
return this.group.meta;
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
get core(): CoValueCore {
|
|
48
|
-
return this.group.core;
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
addMember(accountID: AccountID | Everyone, role: Role): G {
|
|
52
|
-
return this.group.addMember(accountID, role);
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
removeMember(accountID: AccountID): G {
|
|
56
|
-
return this.group.removeMember(accountID);
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
createInvite(role: "reader" | "writer" | "admin"): InviteSecret {
|
|
60
|
-
return this.group.createInvite(role);
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
createMap<M extends CoMap>(
|
|
64
|
-
init?: {
|
|
65
|
-
[K in keyof M["_shape"]]: M["_shape"][K];
|
|
66
|
-
},
|
|
67
|
-
meta?: M["meta"],
|
|
68
|
-
initPrivacy: "trusting" | "private" = "private"
|
|
69
|
-
): M {
|
|
70
|
-
return this.group.createMap(init, meta, initPrivacy);
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
createList<L extends CoList>(
|
|
74
|
-
init?: L["_item"][],
|
|
75
|
-
meta?: L["meta"],
|
|
76
|
-
initPrivacy: "trusting" | "private" = "private"
|
|
77
|
-
): L {
|
|
78
|
-
return this.group.createList(init, meta, initPrivacy);
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
createStream<C extends CoStream>(meta?: C["meta"]): C {
|
|
82
|
-
return this.group.createStream(meta);
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
createBinaryStream<C extends BinaryCoStream>(
|
|
86
|
-
meta: C["meta"] = { type: "binary" }
|
|
87
|
-
): C {
|
|
88
|
-
return this.group.createBinaryStream(meta);
|
|
89
|
-
}
|
|
90
|
-
}
|