cojson 0.4.1 → 0.4.6

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.
Files changed (76) hide show
  1. package/dist/coValue.js +0 -9
  2. package/dist/coValue.js.map +1 -1
  3. package/dist/coValueCore.js +4 -34
  4. package/dist/coValueCore.js.map +1 -1
  5. package/dist/coValues/coList.js +2 -2
  6. package/dist/coValues/coList.js.map +1 -1
  7. package/dist/coValues/coMap.js +2 -2
  8. package/dist/coValues/coMap.js.map +1 -1
  9. package/dist/coValues/coStream.js +2 -2
  10. package/dist/coValues/coStream.js.map +1 -1
  11. package/dist/coValues/group.js.map +1 -1
  12. package/dist/coreToCoValue.js +37 -0
  13. package/dist/coreToCoValue.js.map +1 -0
  14. package/dist/index.js +2 -4
  15. package/dist/index.js.map +1 -1
  16. package/dist/isCoValue.js +10 -0
  17. package/dist/isCoValue.js.map +1 -0
  18. package/dist/localNode.js +1 -14
  19. package/dist/localNode.js.map +1 -1
  20. package/package.json +4 -4
  21. package/src/coValue.ts +11 -19
  22. package/src/coValueCore.ts +2 -25
  23. package/src/coValues/coList.ts +3 -2
  24. package/src/coValues/coMap.ts +3 -2
  25. package/src/coValues/coStream.ts +3 -4
  26. package/src/coValues/group.ts +4 -4
  27. package/src/coreToCoValue.ts +37 -0
  28. package/src/index.ts +16 -16
  29. package/src/isCoValue.ts +16 -0
  30. package/src/localNode.ts +6 -47
  31. package/src/tests/coValue.test.ts +5 -5
  32. package/src/tests/group.test.ts +1 -1
  33. package/dist/base64url.d.ts +0 -2
  34. package/dist/coValue.d.ts +0 -38
  35. package/dist/coValueCore.d.ts +0 -103
  36. package/dist/coValues/account.d.ts +0 -62
  37. package/dist/coValues/coList.d.ts +0 -179
  38. package/dist/coValues/coMap.d.ts +0 -149
  39. package/dist/coValues/coStream.d.ts +0 -123
  40. package/dist/coValues/group.d.ts +0 -111
  41. package/dist/crypto.d.ts +0 -120
  42. package/dist/ids.d.ts +0 -11
  43. package/dist/index.d.ts +0 -67
  44. package/dist/jsonStringify.d.ts +0 -6
  45. package/dist/jsonValue.d.ts +0 -7
  46. package/dist/localNode.d.ts +0 -101
  47. package/dist/media.d.ts +0 -7
  48. package/dist/permissions.d.ts +0 -20
  49. package/dist/queriedCoValues/queriedAccount.d.ts +0 -13
  50. package/dist/queriedCoValues/queriedAccount.js +0 -24
  51. package/dist/queriedCoValues/queriedAccount.js.map +0 -1
  52. package/dist/queriedCoValues/queriedCoList.d.ts +0 -66
  53. package/dist/queriedCoValues/queriedCoList.js +0 -116
  54. package/dist/queriedCoValues/queriedCoList.js.map +0 -1
  55. package/dist/queriedCoValues/queriedCoMap.d.ts +0 -40
  56. package/dist/queriedCoValues/queriedCoMap.js +0 -82
  57. package/dist/queriedCoValues/queriedCoMap.js.map +0 -1
  58. package/dist/queriedCoValues/queriedCoStream.d.ts +0 -36
  59. package/dist/queriedCoValues/queriedCoStream.js +0 -97
  60. package/dist/queriedCoValues/queriedCoStream.js.map +0 -1
  61. package/dist/queriedCoValues/queriedGroup.d.ts +0 -29
  62. package/dist/queriedCoValues/queriedGroup.js +0 -54
  63. package/dist/queriedCoValues/queriedGroup.js.map +0 -1
  64. package/dist/queries.d.ts +0 -62
  65. package/dist/queries.js +0 -142
  66. package/dist/queries.js.map +0 -1
  67. package/dist/streamUtils.d.ts +0 -8
  68. package/dist/sync.d.ts +0 -80
  69. package/dist/tests/testUtils.d.ts +0 -37
  70. package/src/queriedCoValues/queriedAccount.ts +0 -40
  71. package/src/queriedCoValues/queriedCoList.ts +0 -240
  72. package/src/queriedCoValues/queriedCoMap.ts +0 -168
  73. package/src/queriedCoValues/queriedCoStream.ts +0 -151
  74. package/src/queriedCoValues/queriedGroup.ts +0 -90
  75. package/src/queries.ts +0 -263
  76. package/src/tests/queries.test.ts +0 -398
@@ -1,40 +0,0 @@
1
- import { Account } from "../coValues/account.js";
2
- import { CoID, CoValue, ControlledAccount, InviteSecret } from "../index.js";
3
- import { QueryContext } from "../queries.js";
4
- import { QueriedGroup } from "./queriedGroup.js";
5
-
6
- export class QueriedAccount<A extends Account = Account> extends QueriedGroup<A> {
7
- id!: CoID<A>;
8
- isMe!: boolean;
9
-
10
- constructor(account: A, queryContext: QueryContext) {
11
- super(account, queryContext);
12
- Object.defineProperties(this, {
13
- id: { value: account.id, enumerable: false },
14
- isMe: {
15
- value: account.core.node.account.id === account.id,
16
- enumerable: false,
17
- },
18
- });
19
- }
20
-
21
- createGroup() {
22
- if (!this.isMe)
23
- throw new Error("Only the current user can create a group");
24
- return (
25
- this.group.core.node.account as ControlledAccount
26
- ).createGroup();
27
- }
28
-
29
- acceptInvite<T extends CoValue>(
30
- groupOrOwnedValueID: CoID<T>,
31
- inviteSecret: InviteSecret
32
- ) {
33
- if (!this.isMe)
34
- throw new Error("Only the current user can accept an invite");
35
- return (this.group.core.node.account as ControlledAccount).acceptInvite(
36
- groupOrOwnedValueID,
37
- inviteSecret
38
- );
39
- }
40
- }
@@ -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,151 +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 QueriedCoStreamEntry<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 = coStream.sessions().map((sessionID) => {
39
- const items = [...coStream.itemsIn(sessionID)].map((item) =>
40
- queryContext.defineSubqueryPropertiesIn(
41
- {
42
- tx: item.tx,
43
- at: new Date(item.at),
44
- },
45
- {
46
- by: {
47
- value: isAccountID(item.by)
48
- ? item.by
49
- : (undefined as never),
50
- enumerable: true,
51
- },
52
- value: {
53
- value: item.value as S["_item"],
54
- enumerable: true,
55
- },
56
- },
57
- [coStream.id]
58
- )
59
- );
60
-
61
- const lastItem = items[items.length - 1];
62
-
63
- return [
64
- sessionID,
65
- {
66
- get last() {
67
- return lastItem?.value;
68
- },
69
- get by() {
70
- return lastItem?.by;
71
- },
72
- tx: lastItem?.tx,
73
- at: lastItem?.at,
74
- all: items,
75
- } satisfies QueriedCoStreamEntry<S["_item"]>,
76
- ];
77
- });
78
-
79
- this.perAccount = [...coStream.accounts()].map((accountID) => {
80
- const items = [...coStream.itemsBy(accountID)].map((item) =>
81
- queryContext.defineSubqueryPropertiesIn(
82
- {
83
- tx: item.tx,
84
- at: new Date(item.at),
85
- },
86
- {
87
- by: {
88
- value: isAccountID(item.by)
89
- ? item.by
90
- : (undefined as never),
91
- enumerable: true,
92
- },
93
- value: {
94
- value: item.value as S["_item"],
95
- enumerable: true,
96
- },
97
- },
98
- [coStream.id]
99
- )
100
- );
101
-
102
- const lastItem = items[items.length - 1];
103
-
104
- const entry = {
105
- get last() {
106
- return lastItem?.value;
107
- },
108
- get by() {
109
- return lastItem?.by;
110
- },
111
- tx: lastItem?.tx,
112
- at: lastItem?.at,
113
- all: items,
114
- } satisfies QueriedCoStreamEntry<S["_item"]>;
115
-
116
- if (accountID === queryContext.node.account.id) {
117
- this.me = entry;
118
- }
119
-
120
- return [
121
- accountID,
122
- entry
123
- ];
124
- });
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?: QueriedCoStreamEntry<S["_item"]>;
140
- perAccount: [account: AccountID, items: QueriedCoStreamEntry<S["_item"]>][];
141
- perSession: [session: SessionID, items: QueriedCoStreamEntry<S["_item"]>][];
142
-
143
- push(item: S["_item"], privacy?: "private" | "trusting"): S {
144
- return this.coStream.push(item, privacy);
145
- }
146
- mutate(
147
- mutator: (mutable: MutableCoStream<S["_item"], S["meta"]>) => void
148
- ): S {
149
- return this.coStream.mutate(mutator);
150
- }
151
- }
@@ -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
- }