@peers-app/peers-sdk 0.7.2 → 0.7.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.
Files changed (58) hide show
  1. package/dist/context/data-context.d.ts +1 -1
  2. package/dist/context/data-context.js +2 -3
  3. package/dist/context/user-context-singleton.js +13 -31
  4. package/dist/context/user-context.d.ts +2 -5
  5. package/dist/context/user-context.js +20 -15
  6. package/dist/data/assistants.d.ts +1 -1
  7. package/dist/data/change-tracking.d.ts +16 -16
  8. package/dist/data/channels.d.ts +1 -1
  9. package/dist/data/data-locks.d.ts +2 -2
  10. package/dist/data/data-locks.test.js +3 -0
  11. package/dist/data/devices.d.ts +4 -4
  12. package/dist/data/embeddings.d.ts +1 -1
  13. package/dist/data/group-members.d.ts +7 -4
  14. package/dist/data/group-members.js +98 -32
  15. package/dist/data/groups.d.ts +7 -3
  16. package/dist/data/groups.js +91 -30
  17. package/dist/data/index.d.ts +1 -0
  18. package/dist/data/index.js +1 -0
  19. package/dist/data/knowledge/knowledge-frames.d.ts +1 -1
  20. package/dist/data/knowledge/knowledge-links.d.ts +1 -1
  21. package/dist/data/knowledge/knowledge-values.d.ts +1 -1
  22. package/dist/data/knowledge/peer-types.d.ts +1 -1
  23. package/dist/data/knowledge/predicates.d.ts +1 -1
  24. package/dist/data/messages.d.ts +4 -4
  25. package/dist/data/orm/client-proxy.data-source.js +8 -18
  26. package/dist/data/orm/decorators.d.ts +1 -1
  27. package/dist/data/orm/decorators.js +7 -6
  28. package/dist/data/packages.d.ts +2 -1
  29. package/dist/data/packages.js +90 -40
  30. package/dist/data/peer-events/peer-event-handlers.d.ts +1 -1
  31. package/dist/data/peer-events/peer-event-types.d.ts +1 -1
  32. package/dist/data/persistent-vars.js +124 -119
  33. package/dist/data/tool-tests.d.ts +1 -1
  34. package/dist/data/tools.d.ts +1 -1
  35. package/dist/data/user-permissions.test.js +7 -10
  36. package/dist/data/user-trust-levels.d.ts +42 -0
  37. package/dist/data/user-trust-levels.js +60 -0
  38. package/dist/data/users.d.ts +7 -7
  39. package/dist/data/users.js +86 -27
  40. package/dist/data/workflow-logs.d.ts +1 -1
  41. package/dist/data/workflow-runs.js +1 -1
  42. package/dist/data/workflows.d.ts +1 -1
  43. package/dist/device/connection.js +2 -2
  44. package/dist/device/get-trust-level.js +10 -6
  45. package/dist/index.d.ts +1 -0
  46. package/dist/index.js +1 -0
  47. package/dist/logging/console-logger.d.ts +10 -0
  48. package/dist/logging/console-logger.js +206 -0
  49. package/dist/logging/console-logs.table.d.ts +48 -0
  50. package/dist/logging/console-logs.table.js +140 -0
  51. package/dist/logging/index.d.ts +2 -0
  52. package/dist/logging/index.js +18 -0
  53. package/dist/rpc-types.d.ts +0 -11
  54. package/dist/rpc-types.js +0 -8
  55. package/dist/types/peer-device.d.ts +10 -0
  56. package/dist/users.query.d.ts +3 -1
  57. package/dist/users.query.js +39 -11
  58. package/package.json +1 -1
@@ -10,8 +10,8 @@ export declare class DataContext {
10
10
  readonly tableContainer: TableContainer;
11
11
  readonly packageLoader: PackageLoader;
12
12
  readonly eventRegistry: EventRegistry;
13
+ readonly dataContextId: string;
13
14
  constructor(userContext: UserContext, groupId?: string | undefined);
14
- get dataContextId(): string;
15
15
  /**
16
16
  * Call this to indicate that this should be the current data context to be used unless otherwise specified
17
17
  */
@@ -10,9 +10,11 @@ class DataContext {
10
10
  tableContainer;
11
11
  packageLoader;
12
12
  eventRegistry;
13
+ dataContextId;
13
14
  constructor(userContext, groupId) {
14
15
  this.userContext = userContext;
15
16
  this.groupId = groupId;
17
+ this.dataContextId = groupId || userContext.userId;
16
18
  // Initialize dependencies in the correct order to avoid circular references
17
19
  this.eventRegistry = new orm_1.EventRegistry(this.dataContextId);
18
20
  this.packageLoader = new package_loader_1.PackageLoader(this);
@@ -23,9 +25,6 @@ class DataContext {
23
25
  const tableFactory = (metaData, schema, TableClass) => this.createTable(metaData, schema, TableClass);
24
26
  this.tableContainer = new orm_1.TableContainer(tableFactory, groupId);
25
27
  }
26
- get dataContextId() {
27
- return this.groupId || this.userContext.userId;
28
- }
29
28
  /**
30
29
  * Call this to indicate that this should be the current data context to be used unless otherwise specified
31
30
  */
@@ -55,7 +55,7 @@ function getTableContainer(dataContext) {
55
55
  }
56
56
  function setDefaultClientUserContext(userId) {
57
57
  const clientProxyDataSourceFactory = (metaData, schema, groupId) => {
58
- return new client_proxy_data_source_1.ClientProxyDataSource(metaData, schema, groupId ?? '');
58
+ return new client_proxy_data_source_1.ClientProxyDataSource(metaData, schema, groupId || userId);
59
59
  };
60
60
  const userContext = new user_context_1.UserContext(userId, clientProxyDataSourceFactory);
61
61
  (async () => {
@@ -86,38 +86,20 @@ if (!rpc_types_1.isClient) {
86
86
  .getTable(tableName);
87
87
  return table;
88
88
  }
89
- // TODO: add check that client has permission to do the operation to the table
90
- rpc_types_1.rpcServerCalls.tableGet = async (dataContextId, tableName, id) => {
91
- const table = await getTable(dataContextId, tableName);
92
- return table.get(id);
93
- };
94
- rpc_types_1.rpcServerCalls.tableList = async (dataContextId, tableName, filter, opts) => {
95
- const table = await getTable(dataContextId, tableName);
96
- return table.list(filter, opts);
97
- };
98
- rpc_types_1.rpcServerCalls.tableCount = async (dataContextId, tableName, filter) => {
99
- const table = await getTable(dataContextId, tableName);
100
- return table.count(filter);
101
- };
102
- rpc_types_1.rpcServerCalls.tableSave = async (dataContextId, tableName, data, opts) => {
103
- const table = await getTable(dataContextId, tableName);
104
- return table.save(data, opts);
105
- };
106
- rpc_types_1.rpcServerCalls.tableInsert = async (dataContextId, tableName, data) => {
107
- const table = await getTable(dataContextId, tableName);
108
- return table.insert(data);
109
- };
110
- rpc_types_1.rpcServerCalls.tableUpdate = async (dataContextId, tableName, data) => {
111
- const table = await getTable(dataContextId, tableName);
112
- return table.update(data);
113
- };
114
- rpc_types_1.rpcServerCalls.tableDelete = async (dataContextId, tableName, idOrRecord) => {
115
- const table = await getTable(dataContextId, tableName);
116
- return table.delete(idOrRecord);
117
- };
89
+ // TODO: add check that client has permission to make this call
118
90
  rpc_types_1.rpcServerCalls.tableMethodCall = async (dataContextId, tableName, methodName, ...args) => {
91
+ if (!tableName) {
92
+ throw new Error('tableName is required for tableMethodCall');
93
+ }
94
+ if (!dataContextId) {
95
+ console.warn('dataContextId not provided to tableMethodCall - defaulting to user context. This is discouraged. If userDataContext was intended then pass it in explicitly.');
96
+ }
119
97
  const table = await getTable(dataContextId, tableName);
120
- // @ts-ignore
98
+ const method = table[methodName];
99
+ if (typeof method !== 'function') {
100
+ throw new Error(`Method ${methodName} not found on table ${tableName}`);
101
+ }
102
+ // @ts-ignore - call this way to ensure 'this' is correct
121
103
  return table[methodName](...args);
122
104
  };
123
105
  }
@@ -1,7 +1,6 @@
1
1
  import { DataContext } from "../context/data-context";
2
2
  import { IUser } from "../data";
3
3
  import type { DataSourceFactory, IDataChangedEvent, Table } from "../data/orm";
4
- import { TrustLevel } from "../device/socket.type";
5
4
  import { IPublicPrivateKeys } from "../keys";
6
5
  import { Observable } from "../observable";
7
6
  export declare class UserContext {
@@ -9,7 +8,6 @@ export declare class UserContext {
9
8
  readonly dataSourceFactory: DataSourceFactory;
10
9
  readonly deviceId: Observable<string>;
11
10
  readonly currentlyActiveGroupId: Observable<string | undefined>;
12
- readonly packagesRootDir: Observable<string>;
13
11
  readonly reloadPackagesOnPageRefresh: Observable<boolean>;
14
12
  readonly groupIds: Observable<string[]>;
15
13
  readonly userDataContext: DataContext;
@@ -34,15 +32,14 @@ export declare class UserContext {
34
32
  getMe(): Promise<{
35
33
  name: string;
36
34
  publicKey: string;
37
- publicBoxKey: string;
38
35
  userId: string;
36
+ publicBoxKey: string;
39
37
  signature?: string | undefined;
40
- trustLevel?: TrustLevel | undefined;
41
38
  } | undefined>;
42
39
  syncUserAndGroupObjects(userId: string, keys: IPublicPrivateKeys, me?: IUser): Promise<void>;
43
40
  subscribeToDataChangedAcrossAllGroups<T extends {
44
41
  [key: string]: any;
45
- }>(table: Table<T>, handler: (evt: ICrossGroupSubscriptionHandlerArgs<T>) => any): import("../events").ISubscriptionResult;
42
+ }>(table: string | Table<T>, handler: (evt: ICrossGroupSubscriptionHandlerArgs<T>) => any): import("../events").ISubscriptionResult;
46
43
  }
47
44
  export interface ICrossGroupSubscriptionHandlerArgs<T> {
48
45
  name: string;
@@ -4,7 +4,6 @@ exports.UserContext = void 0;
4
4
  const lodash_1 = require("lodash");
5
5
  const data_context_1 = require("../context/data-context");
6
6
  const data_1 = require("../data");
7
- const socket_type_1 = require("../device/socket.type");
8
7
  const events_1 = require("../events");
9
8
  const keys_1 = require("../keys");
10
9
  const observable_1 = require("../observable");
@@ -14,7 +13,6 @@ class UserContext {
14
13
  dataSourceFactory;
15
14
  deviceId = (0, observable_1.observable)('');
16
15
  currentlyActiveGroupId = (0, observable_1.observable)();
17
- packagesRootDir = (0, observable_1.observable)('');
18
16
  reloadPackagesOnPageRefresh = (0, observable_1.observable)(false);
19
17
  groupIds = (0, observable_1.observable)([]);
20
18
  userDataContext;
@@ -30,7 +28,12 @@ class UserContext {
30
28
  this.loadingPromise = this.init();
31
29
  }
32
30
  async init() {
33
- await this.loadUserContextObservablesFromDB();
31
+ if (typeof process !== 'undefined' && process.env.NODE_ENV === 'test') {
32
+ console.log(`not setting up user-context pvars during tests because they will interfere with other UserContext instances`);
33
+ }
34
+ else {
35
+ await this.loadUserContextObservablesFromDB();
36
+ }
34
37
  await this.loadGroupContexts();
35
38
  await this.loadAllPackages();
36
39
  return this;
@@ -107,8 +110,9 @@ class UserContext {
107
110
  * for the user context to be fully loaded before proceeding with standard data access
108
111
  */
109
112
  async loadUserContextObservablesFromDB() {
110
- const persistentVars = await this.userDataContext.tableContainer.getTableByName(data_1.persistentVarsMetaData.name);
111
- const vars = await persistentVars.list({ name: { $in: ['myUserId', 'thisDeviceId', 'currentlyActiveGroupId', 'packagesRootDir', 'reloadPackagesOnPageRefresh'] } });
113
+ // const persistentVars: PersistentVarsTable = await this.userDataContext.tableContainer.getTableByName(persistentVarsMetaData.name) as PersistentVarsTable;
114
+ const persistentVars = (0, data_1.PersistentVars)(this.userDataContext);
115
+ const vars = await persistentVars.list({ name: { $in: ['thisDeviceId', 'currentlyActiveGroupId', 'reloadPackagesOnPageRefresh'] } });
112
116
  const varDbValues = vars.reduce((acc, curr) => {
113
117
  acc[curr.name] = curr.value?.value;
114
118
  return acc;
@@ -120,15 +124,11 @@ class UserContext {
120
124
  const currentlyActiveGroupIdPVar = (0, data_1.deviceVar)('currentlyActiveGroupId', { dbValue: varDbValues['currentlyActiveGroupId'], defaultValue: '', userContext: this });
121
125
  this.currentlyActiveGroupId(currentlyActiveGroupIdPVar());
122
126
  (0, observable_1.linkObservables)(currentlyActiveGroupIdPVar, this.currentlyActiveGroupId);
123
- const packagesRootDirPVar = (0, data_1.deviceVar)('packagesRootDir', { defaultValue: '~/peers-packages', dbValue: varDbValues['packagesRootDir'], userContext: this });
124
- this.packagesRootDir(packagesRootDirPVar());
125
- (0, observable_1.linkObservables)(packagesRootDirPVar, this.packagesRootDir);
126
127
  const reloadPackagesOnPageRefreshPVar = (0, data_1.deviceVar)('reloadPackagesOnPageRefresh', { defaultValue: false, dbValue: varDbValues['reloadPackagesOnPageRefresh'], userContext: this });
127
128
  this.reloadPackagesOnPageRefresh(reloadPackagesOnPageRefreshPVar());
128
129
  (0, observable_1.linkObservables)(reloadPackagesOnPageRefreshPVar, this.reloadPackagesOnPageRefresh);
129
130
  await Promise.all([
130
131
  deviceIdPVar.loadingPromise,
131
- packagesRootDirPVar.loadingPromise,
132
132
  reloadPackagesOnPageRefreshPVar.loadingPromise,
133
133
  ]);
134
134
  }
@@ -148,7 +148,6 @@ class UserContext {
148
148
  name: 'Unnamed_1',
149
149
  publicKey: '',
150
150
  publicBoxKey: '',
151
- trustLevel: socket_type_1.TrustLevel.Self,
152
151
  };
153
152
  }
154
153
  me.publicKey = keys.publicKey;
@@ -162,9 +161,8 @@ class UserContext {
162
161
  // sync my user to all all my groups
163
162
  for (const [, dataContext] of userContext.groupDataContexts) {
164
163
  let groupMe = await (0, data_1.Users)(dataContext).get(me.userId);
165
- if (!groupMe || groupMe.name !== me.name || groupMe.publicKey !== me.publicKey) {
166
- groupMe = (0, keys_1.addSignatureToObject)({ ...me, trustLevel: groupMe?.trustLevel || socket_type_1.TrustLevel.NewUser }, keys.secretKey);
167
- await (0, data_1.Users)(dataContext).save(groupMe);
164
+ if (!(0, lodash_1.isEqual)(groupMe, meSigned)) {
165
+ await (0, data_1.Users)(dataContext).save(meSigned);
168
166
  }
169
167
  }
170
168
  // sync group objects to my personal db
@@ -176,13 +174,20 @@ class UserContext {
176
174
  const groupObject = await (0, data_1.Groups)(dataContext).get(dataContext.groupId);
177
175
  const myGroupObject = await (0, data_1.Groups)(this.userDataContext).get(dataContext.groupId);
178
176
  if (groupObject && !(0, lodash_1.isEqual)(groupObject, myGroupObject)) {
179
- (0, keys_1.verifyObjectSignature)(groupObject);
177
+ try {
178
+ (0, keys_1.verifyObjectSignature)(groupObject);
179
+ }
180
+ catch (err) {
181
+ console.error(`Error verifying group object from group ${dataContext.groupId}:`, err);
182
+ continue;
183
+ }
180
184
  await (0, data_1.Groups)(this.userDataContext).save(groupObject);
181
185
  }
182
186
  }
183
187
  }
184
188
  subscribeToDataChangedAcrossAllGroups(table, handler) {
185
- const tableEventPrefix = `${table.tableName}_DataChanged_`;
189
+ const tableName = typeof table === 'string' ? table : table.tableName;
190
+ const tableEventPrefix = `${tableName}_DataChanged_`;
186
191
  const subscription = (0, events_1.subscribe)(evt => evt.name.startsWith(tableEventPrefix), async (evt) => {
187
192
  const dataContextId = evt.name.endsWith('_') ? this.userId : evt.name.split('_').pop();
188
193
  const dataContext = this.getDataContext(dataContextId);
@@ -39,7 +39,7 @@ export declare const assistantSchema: z.ZodObject<{
39
39
  toolInclusionStrategy?: ToolInclusionStrategy | undefined;
40
40
  }>;
41
41
  export type IAssistant = z.infer<typeof assistantSchema>;
42
- export declare function Assistants(dataContext?: DataContext): import("..").Table<{
42
+ export declare function Assistants(dataContext?: DataContext): import("./orm").Table<{
43
43
  name: string;
44
44
  createdAt: Date;
45
45
  assistantId: string;
@@ -10,22 +10,22 @@ declare const insertChange: z.ZodObject<{
10
10
  recordId: z.ZodString;
11
11
  newRecord: z.ZodObject<{}, "strip", z.ZodAny, z.objectOutputType<{}, z.ZodAny, "strip">, z.objectInputType<{}, z.ZodAny, "strip">>;
12
12
  }, "strip", z.ZodTypeAny, {
13
- recordId: string;
14
13
  changeId: string;
15
14
  changeType: "insert" | "snapshot" | "restore";
16
15
  timestamp: number;
17
16
  timestampApplied: number;
18
17
  tableName: string;
18
+ recordId: string;
19
19
  newRecord: {} & {
20
20
  [k: string]: any;
21
21
  };
22
22
  }, {
23
- recordId: string;
24
23
  changeId: string;
25
24
  changeType: "insert" | "snapshot" | "restore";
26
25
  timestamp: number;
27
26
  timestampApplied: number;
28
27
  tableName: string;
28
+ recordId: string;
29
29
  newRecord: {} & {
30
30
  [k: string]: any;
31
31
  };
@@ -40,20 +40,20 @@ declare const deleteChange: z.ZodObject<{
40
40
  recordId: z.ZodString;
41
41
  oldRecord: z.ZodOptional<z.ZodObject<{}, "strip", z.ZodAny, z.objectOutputType<{}, z.ZodAny, "strip">, z.objectInputType<{}, z.ZodAny, "strip">>>;
42
42
  }, "strip", z.ZodTypeAny, {
43
- recordId: string;
44
43
  changeId: string;
45
44
  changeType: "delete";
46
45
  timestamp: number;
47
46
  timestampApplied: number;
48
47
  tableName: string;
48
+ recordId: string;
49
49
  oldRecord?: z.objectOutputType<{}, z.ZodAny, "strip"> | undefined;
50
50
  }, {
51
- recordId: string;
52
51
  changeId: string;
53
52
  changeType: "delete";
54
53
  timestamp: number;
55
54
  timestampApplied: number;
56
55
  tableName: string;
56
+ recordId: string;
57
57
  oldRecord?: z.objectInputType<{}, z.ZodAny, "strip"> | undefined;
58
58
  }>;
59
59
  export type IChangeDelete = z.infer<typeof deleteChange>;
@@ -67,23 +67,23 @@ declare const updateChange: z.ZodObject<{
67
67
  newRecord: z.ZodObject<{}, "strip", z.ZodAny, z.objectOutputType<{}, z.ZodAny, "strip">, z.objectInputType<{}, z.ZodAny, "strip">>;
68
68
  jsonDiff: z.ZodArray<z.ZodAny, "many">;
69
69
  }, "strip", z.ZodTypeAny, {
70
- recordId: string;
71
70
  changeId: string;
72
71
  changeType: "update";
73
72
  timestamp: number;
74
73
  timestampApplied: number;
75
74
  tableName: string;
75
+ recordId: string;
76
76
  newRecord: {} & {
77
77
  [k: string]: any;
78
78
  };
79
79
  jsonDiff: any[];
80
80
  }, {
81
- recordId: string;
82
81
  changeId: string;
83
82
  changeType: "update";
84
83
  timestamp: number;
85
84
  timestampApplied: number;
86
85
  tableName: string;
86
+ recordId: string;
87
87
  newRecord: {} & {
88
88
  [k: string]: any;
89
89
  };
@@ -99,22 +99,22 @@ declare const changeSchema: z.ZodUnion<[z.ZodObject<{
99
99
  recordId: z.ZodString;
100
100
  newRecord: z.ZodObject<{}, "strip", z.ZodAny, z.objectOutputType<{}, z.ZodAny, "strip">, z.objectInputType<{}, z.ZodAny, "strip">>;
101
101
  }, "strip", z.ZodTypeAny, {
102
- recordId: string;
103
102
  changeId: string;
104
103
  changeType: "insert" | "snapshot" | "restore";
105
104
  timestamp: number;
106
105
  timestampApplied: number;
107
106
  tableName: string;
107
+ recordId: string;
108
108
  newRecord: {} & {
109
109
  [k: string]: any;
110
110
  };
111
111
  }, {
112
- recordId: string;
113
112
  changeId: string;
114
113
  changeType: "insert" | "snapshot" | "restore";
115
114
  timestamp: number;
116
115
  timestampApplied: number;
117
116
  tableName: string;
117
+ recordId: string;
118
118
  newRecord: {} & {
119
119
  [k: string]: any;
120
120
  };
@@ -127,20 +127,20 @@ declare const changeSchema: z.ZodUnion<[z.ZodObject<{
127
127
  recordId: z.ZodString;
128
128
  oldRecord: z.ZodOptional<z.ZodObject<{}, "strip", z.ZodAny, z.objectOutputType<{}, z.ZodAny, "strip">, z.objectInputType<{}, z.ZodAny, "strip">>>;
129
129
  }, "strip", z.ZodTypeAny, {
130
- recordId: string;
131
130
  changeId: string;
132
131
  changeType: "delete";
133
132
  timestamp: number;
134
133
  timestampApplied: number;
135
134
  tableName: string;
135
+ recordId: string;
136
136
  oldRecord?: z.objectOutputType<{}, z.ZodAny, "strip"> | undefined;
137
137
  }, {
138
- recordId: string;
139
138
  changeId: string;
140
139
  changeType: "delete";
141
140
  timestamp: number;
142
141
  timestampApplied: number;
143
142
  tableName: string;
143
+ recordId: string;
144
144
  oldRecord?: z.objectInputType<{}, z.ZodAny, "strip"> | undefined;
145
145
  }>, z.ZodObject<{
146
146
  changeId: z.ZodEffects<z.ZodString, string, string>;
@@ -152,23 +152,23 @@ declare const changeSchema: z.ZodUnion<[z.ZodObject<{
152
152
  newRecord: z.ZodObject<{}, "strip", z.ZodAny, z.objectOutputType<{}, z.ZodAny, "strip">, z.objectInputType<{}, z.ZodAny, "strip">>;
153
153
  jsonDiff: z.ZodArray<z.ZodAny, "many">;
154
154
  }, "strip", z.ZodTypeAny, {
155
- recordId: string;
156
155
  changeId: string;
157
156
  changeType: "update";
158
157
  timestamp: number;
159
158
  timestampApplied: number;
160
159
  tableName: string;
160
+ recordId: string;
161
161
  newRecord: {} & {
162
162
  [k: string]: any;
163
163
  };
164
164
  jsonDiff: any[];
165
165
  }, {
166
- recordId: string;
167
166
  changeId: string;
168
167
  changeType: "update";
169
168
  timestamp: number;
170
169
  timestampApplied: number;
171
170
  tableName: string;
171
+ recordId: string;
172
172
  newRecord: {} & {
173
173
  [k: string]: any;
174
174
  };
@@ -186,25 +186,25 @@ export declare const changeTrackingSchema: z.ZodObject<{
186
186
  newRecord: z.ZodOptional<z.ZodObject<{}, "strip", z.ZodAny, z.objectOutputType<{}, z.ZodAny, "strip">, z.objectInputType<{}, z.ZodAny, "strip">>>;
187
187
  jsonDiff: z.ZodOptional<z.ZodArray<z.ZodAny, "many">>;
188
188
  }, "strip", z.ZodTypeAny, {
189
- recordId: string;
190
189
  changeId: string;
191
190
  changeType: "update" | "insert" | "delete" | "snapshot" | "restore";
192
191
  timestamp: number;
193
192
  timestampApplied: number;
194
193
  tableName: string;
194
+ recordId: string;
195
195
  newRecord?: z.objectOutputType<{}, z.ZodAny, "strip"> | undefined;
196
- jsonDiff?: any[] | undefined;
197
196
  oldRecord?: z.objectOutputType<{}, z.ZodAny, "strip"> | undefined;
197
+ jsonDiff?: any[] | undefined;
198
198
  }, {
199
- recordId: string;
200
199
  changeId: string;
201
200
  changeType: "update" | "insert" | "delete" | "snapshot" | "restore";
202
201
  timestamp: number;
203
202
  timestampApplied: number;
204
203
  tableName: string;
204
+ recordId: string;
205
205
  newRecord?: z.objectInputType<{}, z.ZodAny, "strip"> | undefined;
206
- jsonDiff?: any[] | undefined;
207
206
  oldRecord?: z.objectInputType<{}, z.ZodAny, "strip"> | undefined;
207
+ jsonDiff?: any[] | undefined;
208
208
  }>;
209
209
  export type IChangeAny = z.infer<typeof changeTrackingSchema>;
210
210
  export declare class ChangeTrackingTable extends SQLDataSource<IChange> {
@@ -20,7 +20,7 @@ export declare const channelSchema: z.ZodObject<{
20
20
  owningGroupId: string;
21
21
  }>;
22
22
  export type IChannel = z.infer<typeof channelSchema>;
23
- export declare function Channels(dataContext?: DataContext): import("..").Table<{
23
+ export declare function Channels(dataContext?: DataContext): import("./orm").Table<{
24
24
  name: string;
25
25
  description: string;
26
26
  createdAt: Date;
@@ -7,13 +7,13 @@ export declare const dataLockSchema: z.ZodObject<{
7
7
  lockedUntil: z.ZodNumber;
8
8
  acknowledged: z.ZodOptional<z.ZodNumber>;
9
9
  }, "strip", z.ZodTypeAny, {
10
- dataLockId: string;
11
10
  recordId: string;
11
+ dataLockId: string;
12
12
  lockedUntil: number;
13
13
  acknowledged?: number | undefined;
14
14
  }, {
15
- dataLockId: string;
16
15
  recordId: string;
16
+ dataLockId: string;
17
17
  lockedUntil: number;
18
18
  acknowledged?: number | undefined;
19
19
  }>;
@@ -90,6 +90,9 @@ class MockPeerDevice {
90
90
  timestampLastApplied: Date.now()
91
91
  }));
92
92
  }
93
+ sendDeviceMessage(message) {
94
+ throw new Error('Method not implemented.');
95
+ }
93
96
  }
94
97
  describe('data-locks.ts', () => {
95
98
  const fiveMinutesMs = 5 * 60 * 1000;
@@ -11,18 +11,18 @@ export declare const deviceSchema: z.ZodObject<{
11
11
  trustLevel: z.ZodNativeEnum<typeof TrustLevel>;
12
12
  }, "strip", z.ZodTypeAny, {
13
13
  userId: string;
14
- trustLevel: TrustLevel;
15
14
  deviceId: string;
16
15
  firstSeen: Date;
17
16
  lastSeen: Date;
17
+ trustLevel: TrustLevel;
18
18
  name?: string | undefined;
19
19
  serverUrl?: string | undefined;
20
20
  }, {
21
21
  userId: string;
22
- trustLevel: TrustLevel;
23
22
  deviceId: string;
24
23
  firstSeen: Date;
25
24
  lastSeen: Date;
25
+ trustLevel: TrustLevel;
26
26
  name?: string | undefined;
27
27
  serverUrl?: string | undefined;
28
28
  }>;
@@ -38,12 +38,12 @@ export interface IDeviceHandshake extends IDeviceInfo {
38
38
  serverAddress: string;
39
39
  timestamp: number;
40
40
  }
41
- export declare function Devices(dataContext?: DataContext): import("..").Table<{
41
+ export declare function Devices(dataContext?: DataContext): import("./orm").Table<{
42
42
  userId: string;
43
- trustLevel: TrustLevel;
44
43
  deviceId: string;
45
44
  firstSeen: Date;
46
45
  lastSeen: Date;
46
+ trustLevel: TrustLevel;
47
47
  name?: string | undefined;
48
48
  serverUrl?: string | undefined;
49
49
  }>;
@@ -34,7 +34,7 @@ export declare const embeddingSchema: z.ZodObject<{
34
34
  embeddingType: string;
35
35
  }>;
36
36
  export type IEmbedding = z.infer<typeof embeddingSchema>;
37
- export declare function Embeddings(dataContext?: DataContext): import("..").Table<{
37
+ export declare function Embeddings(dataContext?: DataContext): import("./orm").Table<{
38
38
  metadata: {
39
39
  fkId?: string | undefined;
40
40
  } & {
@@ -1,8 +1,8 @@
1
1
  import { z } from "zod";
2
2
  import type { DataContext } from "../context/data-context";
3
- import { Table } from "./orm";
4
3
  import { GroupMemberRole } from './group-member-roles';
5
- import { ISaveOptions } from "..";
4
+ import type { ISaveOptions } from "./orm/data-query";
5
+ import { Table } from "./orm/table";
6
6
  export declare const groupMemberSchema: z.ZodObject<{
7
7
  groupMemberId: z.ZodEffects<z.ZodString, string, string>;
8
8
  groupId: z.ZodEffects<z.ZodString, string, string>;
@@ -13,16 +13,16 @@ export declare const groupMemberSchema: z.ZodObject<{
13
13
  }, "strip", z.ZodTypeAny, {
14
14
  role: GroupMemberRole;
15
15
  signature: string;
16
- groupId: string;
17
16
  userId: string;
18
17
  groupMemberId: string;
18
+ groupId: string;
19
19
  deleted?: boolean | undefined;
20
20
  }, {
21
21
  role: GroupMemberRole;
22
22
  signature: string;
23
- groupId: string;
24
23
  userId: string;
25
24
  groupMemberId: string;
25
+ groupId: string;
26
26
  deleted?: boolean | undefined;
27
27
  }>;
28
28
  export type IGroupMember = z.infer<typeof groupMemberSchema>;
@@ -30,7 +30,10 @@ export declare const groupMembersTableName = "GroupMembers";
30
30
  export declare class GroupMembersTable extends Table<IGroupMember> {
31
31
  static isPassthrough: boolean;
32
32
  save(groupMember: IGroupMember, opts?: ISaveOptions): Promise<IGroupMember>;
33
+ signAndSave(groupMember: IGroupMember, opts?: ISaveOptions): Promise<IGroupMember>;
33
34
  delete(groupMemberId: string): Promise<void>;
35
+ private static addSignatureToGroupMember;
36
+ static enableGroupMemberSigning(fn: (groupMember: IGroupMember) => IGroupMember): void;
34
37
  /** @deprecated Forbidden on GroupsTable; use save() */
35
38
  insert(..._args: Parameters<Table<IGroupMember>['insert']>): never;
36
39
  /** @deprecated Forbidden on GroupsTable; use save() */