cojson 0.3.6 → 0.4.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.
Files changed (81) hide show
  1. package/dist/coValue.d.ts +7 -12
  2. package/dist/coValue.js.map +1 -1
  3. package/dist/coValueCore.d.ts +9 -4
  4. package/dist/coValueCore.js +69 -33
  5. package/dist/coValueCore.js.map +1 -1
  6. package/dist/coValues/account.d.ts +62 -0
  7. package/dist/{account.js → coValues/account.js} +19 -11
  8. package/dist/coValues/account.js.map +1 -0
  9. package/dist/coValues/coList.d.ts +19 -19
  10. package/dist/coValues/coList.js.map +1 -1
  11. package/dist/coValues/coMap.d.ts +31 -23
  12. package/dist/coValues/coMap.js +4 -6
  13. package/dist/coValues/coMap.js.map +1 -1
  14. package/dist/coValues/coStream.d.ts +19 -19
  15. package/dist/coValues/coStream.js.map +1 -1
  16. package/dist/{group.d.ts → coValues/group.d.ts} +27 -38
  17. package/dist/{group.js → coValues/group.js} +69 -73
  18. package/dist/coValues/group.js.map +1 -0
  19. package/dist/ids.d.ts +1 -1
  20. package/dist/index.d.ts +15 -11
  21. package/dist/index.js +10 -5
  22. package/dist/index.js.map +1 -1
  23. package/dist/localNode.d.ts +20 -7
  24. package/dist/localNode.js +74 -39
  25. package/dist/localNode.js.map +1 -1
  26. package/dist/media.d.ts +1 -1
  27. package/dist/permissions.d.ts +1 -1
  28. package/dist/permissions.js +43 -22
  29. package/dist/permissions.js.map +1 -1
  30. package/dist/queriedCoValues/queriedAccount.d.ts +13 -0
  31. package/dist/queriedCoValues/queriedAccount.js +24 -0
  32. package/dist/queriedCoValues/queriedAccount.js.map +1 -0
  33. package/dist/queriedCoValues/queriedCoList.d.ts +10 -10
  34. package/dist/queriedCoValues/queriedCoList.js +11 -15
  35. package/dist/queriedCoValues/queriedCoList.js.map +1 -1
  36. package/dist/queriedCoValues/queriedCoMap.d.ts +14 -21
  37. package/dist/queriedCoValues/queriedCoMap.js +27 -28
  38. package/dist/queriedCoValues/queriedCoMap.js.map +1 -1
  39. package/dist/queriedCoValues/queriedCoStream.d.ts +9 -9
  40. package/dist/queriedCoValues/queriedCoStream.js +44 -20
  41. package/dist/queriedCoValues/queriedCoStream.js.map +1 -1
  42. package/dist/queriedCoValues/queriedGroup.d.ts +29 -0
  43. package/dist/queriedCoValues/queriedGroup.js +54 -0
  44. package/dist/queriedCoValues/queriedGroup.js.map +1 -0
  45. package/dist/queries.d.ts +40 -9
  46. package/dist/queries.js +104 -39
  47. package/dist/queries.js.map +1 -1
  48. package/dist/sync.js +1 -0
  49. package/dist/sync.js.map +1 -1
  50. package/dist/tests/testUtils.d.ts +15 -7
  51. package/dist/tests/testUtils.js +16 -17
  52. package/dist/tests/testUtils.js.map +1 -1
  53. package/package.json +2 -2
  54. package/src/coValue.ts +12 -31
  55. package/src/coValueCore.ts +100 -40
  56. package/src/{account.ts → coValues/account.ts} +46 -27
  57. package/src/coValues/coList.ts +24 -28
  58. package/src/coValues/coMap.ts +42 -68
  59. package/src/coValues/coStream.ts +20 -26
  60. package/src/{group.ts → coValues/group.ts} +121 -141
  61. package/src/ids.ts +1 -1
  62. package/src/index.ts +25 -10
  63. package/src/localNode.ts +180 -77
  64. package/src/media.ts +1 -1
  65. package/src/permissions.ts +67 -36
  66. package/src/queriedCoValues/queriedAccount.ts +40 -0
  67. package/src/queriedCoValues/queriedCoList.ts +22 -30
  68. package/src/queriedCoValues/queriedCoMap.ts +60 -72
  69. package/src/queriedCoValues/queriedCoStream.ts +67 -37
  70. package/src/queriedCoValues/queriedGroup.ts +90 -0
  71. package/src/queries.ts +181 -60
  72. package/src/sync.ts +1 -0
  73. package/src/tests/account.test.ts +14 -9
  74. package/src/tests/coValueCore.test.ts +2 -2
  75. package/src/tests/permissions.test.ts +351 -242
  76. package/src/tests/queries.test.ts +98 -79
  77. package/src/tests/sync.test.ts +11 -11
  78. package/src/tests/testUtils.ts +16 -18
  79. package/dist/account.d.ts +0 -58
  80. package/dist/account.js.map +0 -1
  81. package/dist/group.js.map +0 -1
@@ -1,13 +1,12 @@
1
1
  import { CoList, MutableCoList } from "../coValues/coList.js";
2
2
  import { CoValueCore } from "../coValueCore.js";
3
- import { Group } from "../group.js";
4
- import { isAccountID } from "../account.js";
5
- import { AnyCoList, CoID, CoValue } from "../coValue.js";
3
+ import { Group } from "../coValues/group.js";
4
+ import { CoID, CoValue } from "../coValue.js";
6
5
  import { TransactionID } from "../ids.js";
7
- import { QueriedAccountAndProfile } from "./queriedCoMap.js";
8
6
  import { ValueOrSubQueried, QueryContext } from "../queries.js";
7
+ import { QueriedAccount } from "./queriedAccount.js";
9
8
 
10
- export class QueriedCoList<L extends AnyCoList> extends Array<
9
+ export class QueriedCoList<L extends CoList> extends Array<
11
10
  ValueOrSubQueried<L["_item"]>
12
11
  > {
13
12
  coList!: L;
@@ -27,40 +26,37 @@ export class QueriedCoList<L extends AnyCoList> extends Array<
27
26
  .asArray()
28
27
  .map(
29
28
  (item) =>
30
- queryContext.resolveValue(item) as ValueOrSubQueried<
29
+ queryContext.queryIfCoID(item, [coList.id]) as ValueOrSubQueried<
31
30
  L["_item"]
32
31
  >
33
32
  )
34
33
  );
35
34
 
36
35
  Object.defineProperties(this, {
37
- coList: { value: coList },
36
+ coList: { get() {return coList} },
38
37
  id: { value: coList.id },
39
38
  type: { value: "colist" },
40
39
  edits: {
41
40
  value: [...this.keys()].map((i) => {
42
41
  const edit = coList.editAt(i)!;
43
- return {
44
- by:
45
- edit.by && isAccountID(edit.by)
46
- ? queryContext.resolveAccount(edit.by)
47
- : undefined,
42
+ return queryContext.defineSubqueryPropertiesIn({
43
+
48
44
  tx: edit.tx,
49
45
  at: new Date(edit.at),
50
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
51
- value: queryContext.resolveValue(edit.value) as any,
52
- };
46
+ }, {
47
+ by: {value: edit.by, enumerable: true},
48
+ value: {value: edit.value, enumerable: true},
49
+ }, [coList.id]);
53
50
  }),
54
51
  },
55
52
  deletions: {
56
- value: coList.deletionEdits().map((deletion) => ({
57
- by:
58
- deletion.by && isAccountID(deletion.by)
59
- ? queryContext.resolveAccount(deletion.by)
60
- : undefined,
53
+ value: coList.deletionEdits().map((deletion) => queryContext.defineSubqueryPropertiesIn({
54
+
61
55
  tx: deletion.tx,
62
56
  at: new Date(deletion.at),
63
- })),
57
+ }, {
58
+ by: {value: deletion.by, enumerable: true},
59
+ }, [coList.id])),
64
60
  },
65
61
  });
66
62
  }
@@ -78,9 +74,7 @@ export class QueriedCoList<L extends AnyCoList> extends Array<
78
74
  }
79
75
 
80
76
  append(
81
- item: L["_item"] extends CoValue
82
- ? L["_item"] | CoID<L["_item"]>
83
- : L["_item"],
77
+ item: L["_item"],
84
78
  after?: number,
85
79
  privacy?: "private" | "trusting"
86
80
  ): L {
@@ -88,16 +82,14 @@ export class QueriedCoList<L extends AnyCoList> extends Array<
88
82
  }
89
83
 
90
84
  prepend(
91
- item: L["_item"] extends CoValue
92
- ? L["_item"] | CoID<L["_item"]>
93
- : L["_item"],
85
+ item: L["_item"],
94
86
  before?: number,
95
87
  privacy?: "private" | "trusting"
96
88
  ): L {
97
89
  return this.coList.prepend(item, before, privacy);
98
90
  }
99
91
 
100
- delete(at: number, privacy: "private" | "trusting"): L {
92
+ delete(at: number, privacy?: "private" | "trusting"): L {
101
93
  return this.coList.delete(at, privacy);
102
94
  }
103
95
 
@@ -108,7 +100,7 @@ export class QueriedCoList<L extends AnyCoList> extends Array<
108
100
  }
109
101
 
110
102
  edits!: {
111
- by?: QueriedAccountAndProfile;
103
+ by?: QueriedAccount;
112
104
  tx: TransactionID;
113
105
  at: Date;
114
106
  value: L["_item"] extends CoValue
@@ -117,7 +109,7 @@ export class QueriedCoList<L extends AnyCoList> extends Array<
117
109
  }[];
118
110
 
119
111
  deletions!: {
120
- by?: QueriedAccountAndProfile;
112
+ by?: QueriedAccount;
121
113
  tx: TransactionID;
122
114
  at: Date;
123
115
  }[];
@@ -1,34 +1,29 @@
1
- import { MutableCoMap } from "../coValues/coMap.js";
1
+ import { CoMap, MutableCoMap } from "../coValues/coMap.js";
2
2
  import { CoValueCore } from "../coValueCore.js";
3
- import { Group } from "../group.js";
4
- import { Account, AccountID, Profile, isAccountID } from "../account.js";
5
- import { AnyCoMap, CoID, CoValue } from "../coValue.js";
3
+ import { Group } from "../coValues/group.js";
4
+ import { CoID } from "../coValue.js";
6
5
  import { TransactionID } from "../ids.js";
7
- import { ValueOrSubQueried, QueryContext } from "../queries.js";
6
+ import { ValueOrSubQueried, QueryContext, QueryExtension } from "../queries.js";
7
+ import { QueriedAccount } from "./queriedAccount.js";
8
8
 
9
- export type QueriedCoMap<M extends AnyCoMap> = {
9
+ export type QueriedCoMap<M extends CoMap> = {
10
10
  [K in keyof M["_shape"] & string]: ValueOrSubQueried<M["_shape"][K]>;
11
11
  } & QueriedCoMapBase<M>;
12
12
 
13
- export type QueriedCoMapEdit<
14
- M extends AnyCoMap,
15
- K extends keyof M["_shape"]
16
- > = {
17
- by?: QueriedAccountAndProfile;
13
+ export type QueriedCoMapEdit<M extends CoMap, K extends keyof M["_shape"]> = {
14
+ by?: QueriedAccount;
18
15
  tx: TransactionID;
19
16
  at: Date;
20
- value: M["_shape"][K] extends CoValue
21
- ? CoID<M["_shape"][K]>
22
- : Exclude<M["_shape"][K], CoValue>;
17
+ value: M["_shape"][K];
23
18
  };
24
19
 
25
- export class QueriedCoMapBase<M extends AnyCoMap> {
20
+ export class QueriedCoMapBase<M extends CoMap> {
26
21
  coMap!: M;
27
22
  id!: CoID<M>;
28
23
  type!: "comap";
29
24
 
30
25
  /** @internal */
31
- static newWithKVPairs<M extends AnyCoMap>(
26
+ static newWithKVPairs<M extends CoMap>(
32
27
  coMap: M,
33
28
  queryContext: QueryContext
34
29
  ): QueriedCoMap<M> {
@@ -37,27 +32,18 @@ export class QueriedCoMapBase<M extends AnyCoMap> {
37
32
  M["_shape"][K]
38
33
  >;
39
34
  };
40
-
41
- if (coMap.meta?.type === "account") {
42
- const profileID = coMap.get("profile");
43
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
44
- (kv as any).profile =
45
- profileID && queryContext.resolveValue(profileID);
46
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
47
- (kv as any).isMe =
48
- (coMap as unknown as Account).id ===
49
- queryContext.node.account.id;
50
- } else {
51
- for (const key of coMap.keys()) {
52
- const value = coMap.get(key);
53
-
54
- if (value === undefined) continue;
55
-
56
- kv[key as keyof typeof kv] = queryContext.resolveValue(
57
- value
58
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
59
- ) as any;
60
- }
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
+ );
61
47
  }
62
48
 
63
49
  return Object.assign(new QueriedCoMapBase(coMap, queryContext), kv);
@@ -66,23 +52,33 @@ export class QueriedCoMapBase<M extends AnyCoMap> {
66
52
  /** @internal */
67
53
  constructor(coMap: M, queryContext: QueryContext) {
68
54
  Object.defineProperties(this, {
69
- coMap: { value: coMap, enumerable: false },
55
+ coMap: {
56
+ get() {
57
+ return coMap;
58
+ },
59
+ enumerable: false,
60
+ },
70
61
  id: { value: coMap.id, enumerable: false },
71
62
  type: { value: "comap", enumerable: false },
72
63
  edits: {
73
64
  value: Object.fromEntries(
74
65
  coMap.keys().flatMap((key) => {
75
- const edits = [...coMap.editsAt(key)].map((edit) => ({
76
- by:
77
- edit.by && isAccountID(edit.by)
78
- ? queryContext.resolveAccount(edit.by)
79
- : undefined,
80
- tx: edit.tx,
81
- at: new Date(edit.at),
82
- value:
83
- edit.value &&
84
- queryContext.resolveValue(edit.value),
85
- }));
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
+ );
86
82
  const lastEdit = edits[edits.length - 1];
87
83
  if (!lastEdit) return [];
88
84
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
@@ -100,6 +96,15 @@ export class QueriedCoMapBase<M extends AnyCoMap> {
100
96
  ),
101
97
  enumerable: false,
102
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
+ },
103
108
  });
104
109
  }
105
110
 
@@ -125,16 +130,12 @@ export class QueriedCoMapBase<M extends AnyCoMap> {
125
130
 
126
131
  set<K extends keyof M["_shape"] & string>(
127
132
  key: K,
128
- value: M["_shape"][K] extends CoValue
129
- ? M["_shape"][K] | CoID<M["_shape"][K]>
130
- : M["_shape"][K],
133
+ value: M["_shape"][K],
131
134
  privacy?: "private" | "trusting"
132
135
  ): M;
133
136
  set(
134
137
  kv: {
135
- [K in keyof M["_shape"] & string]?: M["_shape"][K] extends CoValue
136
- ? M["_shape"][K] | CoID<M["_shape"][K]>
137
- : M["_shape"][K];
138
+ [K in keyof M["_shape"] & string]?: M["_shape"][K];
138
139
  },
139
140
  privacy?: "private" | "trusting"
140
141
  ): M;
@@ -142,20 +143,11 @@ export class QueriedCoMapBase<M extends AnyCoMap> {
142
143
  ...args:
143
144
  | [
144
145
  {
145
- [K in keyof M["_shape"] &
146
- string]?: M["_shape"][K] extends CoValue
147
- ? M["_shape"][K] | CoID<M["_shape"][K]>
148
- : M["_shape"][K];
146
+ [K in keyof M["_shape"] & string]?: M["_shape"][K];
149
147
  },
150
148
  ("private" | "trusting")?
151
149
  ]
152
- | [
153
- K,
154
- M["_shape"][K] extends CoValue
155
- ? M["_shape"][K] | CoID<M["_shape"][K]>
156
- : M["_shape"][K],
157
- ("private" | "trusting")?
158
- ]
150
+ | [K, M["_shape"][K], ("private" | "trusting")?]
159
151
  ): M {
160
152
  // eslint-disable-next-line @typescript-eslint/ban-types
161
153
  return (this.coMap.set as Function)(...args);
@@ -171,10 +163,6 @@ export class QueriedCoMapBase<M extends AnyCoMap> {
171
163
  ): M {
172
164
  return this.coMap.mutate(mutator);
173
165
  }
174
- }
175
166
 
176
- export type QueriedAccountAndProfile = {
177
- profile?: { name?: string; id: CoID<Profile> };
178
- isMe?: boolean;
179
- id: AccountID;
180
- };
167
+ as!: <O>(extension: QueryExtension<M, O>) => O | undefined;
168
+ }
@@ -1,56 +1,75 @@
1
1
  import { JsonValue } from "../jsonValue.js";
2
- import { MutableCoStream } from "../coValues/coStream.js";
2
+ import { CoStream, MutableCoStream } from "../coValues/coStream.js";
3
3
  import { CoValueCore } from "../coValueCore.js";
4
- import { Group } from "../group.js";
5
- import { AccountID, isAccountID } from "../account.js";
6
- import { AnyCoStream, CoID, CoValue } from "../coValue.js";
4
+ import { Group } from "../coValues/group.js";
5
+ import { AccountID, isAccountID } from "../coValues/account.js";
6
+ import { CoID, CoValue } from "../coValue.js";
7
7
  import { SessionID, TransactionID } from "../ids.js";
8
- import { QueriedAccountAndProfile } from "./queriedCoMap.js";
9
8
  import { ValueOrSubQueried, QueryContext } from "../queries.js";
10
-
9
+ import { QueriedAccount } from "./queriedAccount.js";
11
10
 
12
11
  export type QueriedCoStreamItems<Item extends JsonValue | CoValue> = {
13
12
  last?: ValueOrSubQueried<Item>;
14
- by?: QueriedAccountAndProfile;
13
+ by?: QueriedAccount;
15
14
  tx?: TransactionID;
16
15
  at?: Date;
17
16
  all: {
18
17
  value: ValueOrSubQueried<Item>;
19
- by?: QueriedAccountAndProfile;
18
+ by?: QueriedAccount;
20
19
  tx: TransactionID;
21
20
  at: Date;
22
21
  }[];
23
22
  };
24
23
 
25
- export class QueriedCoStream<S extends AnyCoStream> {
26
- coStream: S;
24
+ export class QueriedCoStream<S extends CoStream> {
25
+ coStream!: S;
27
26
  id: CoID<S>;
28
27
  type = "costream" as const;
29
28
 
30
29
  /** @internal */
31
30
  constructor(coStream: S, queryContext: QueryContext) {
32
- this.coStream = coStream;
31
+ Object.defineProperty(this, "coStream", {
32
+ get() {
33
+ return coStream;
34
+ },
35
+ });
33
36
  this.id = coStream.id;
34
37
 
35
38
  this.perSession = Object.fromEntries(
36
39
  coStream.sessions().map((sessionID) => {
37
- const items = [...coStream.itemsIn(sessionID)].map((item) => ({
38
- by: item.by && isAccountID(item.by)
39
- ? queryContext.resolveAccount(item.by)
40
- : undefined,
41
- tx: item.tx,
42
- at: new Date(item.at),
43
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
44
- value: queryContext.resolveValue(item.value) as any,
45
- }));
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
+ );
46
61
 
47
62
  const lastItem = items[items.length - 1];
48
63
 
49
64
  return [
50
65
  sessionID,
51
66
  {
52
- last: lastItem?.value,
53
- by: lastItem?.by,
67
+ get last() {
68
+ return lastItem?.value;
69
+ },
70
+ get by() {
71
+ return lastItem?.by;
72
+ },
54
73
  tx: lastItem?.tx,
55
74
  at: lastItem?.at,
56
75
  all: items,
@@ -61,23 +80,37 @@ export class QueriedCoStream<S extends AnyCoStream> {
61
80
 
62
81
  this.perAccount = Object.fromEntries(
63
82
  [...coStream.accounts()].map((accountID) => {
64
- const items = [...coStream.itemsBy(accountID)].map((item) => ({
65
- by: item.by && isAccountID(item.by)
66
- ? queryContext.resolveAccount(item.by)
67
- : undefined,
68
- tx: item.tx,
69
- at: new Date(item.at),
70
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
71
- value: queryContext.resolveValue(item.value) as any,
72
- }));
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
+ ));
73
102
 
74
103
  const lastItem = items[items.length - 1];
75
104
 
76
105
  return [
77
106
  accountID,
78
107
  {
79
- last: lastItem?.value,
80
- by: lastItem?.by,
108
+ get last() {
109
+ return lastItem?.value;
110
+ },
111
+ get by() {
112
+ return lastItem?.by;
113
+ },
81
114
  tx: lastItem?.tx,
82
115
  at: lastItem?.at,
83
116
  all: items,
@@ -111,10 +144,7 @@ export class QueriedCoStream<S extends AnyCoStream> {
111
144
  [session: SessionID]: QueriedCoStreamItems<S["_item"]>;
112
145
  };
113
146
 
114
- push(
115
- item: S["_item"] extends CoValue ? S["_item"] | CoID<S["_item"]> : S["_item"],
116
- privacy?: "private" | "trusting"
117
- ): S {
147
+ push(item: S["_item"], privacy?: "private" | "trusting"): S {
118
148
  return this.coStream.push(item, privacy);
119
149
  }
120
150
  mutate(
@@ -0,0 +1,90 @@
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
+ }