@peers-app/peers-sdk 0.7.0 → 0.7.3

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 (59) 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 +6 -30
  4. package/dist/context/user-context.d.ts +1 -6
  5. package/dist/context/user-context.js +10 -12
  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/devices.d.ts +4 -4
  11. package/dist/data/embeddings.d.ts +1 -1
  12. package/dist/data/files/files.d.ts +8 -6
  13. package/dist/data/files/files.js +16 -12
  14. package/dist/data/files/files.test.js +17 -17
  15. package/dist/data/group-members.d.ts +7 -4
  16. package/dist/data/group-members.js +98 -32
  17. package/dist/data/groups.d.ts +7 -3
  18. package/dist/data/groups.js +91 -30
  19. package/dist/data/index.d.ts +2 -0
  20. package/dist/data/index.js +2 -0
  21. package/dist/data/knowledge/knowledge-frames.d.ts +1 -1
  22. package/dist/data/knowledge/knowledge-links.d.ts +1 -1
  23. package/dist/data/knowledge/knowledge-values.d.ts +1 -1
  24. package/dist/data/knowledge/peer-types.d.ts +1 -1
  25. package/dist/data/knowledge/predicates.d.ts +1 -1
  26. package/dist/data/messages.d.ts +4 -4
  27. package/dist/data/orm/client-proxy.data-source.js +8 -18
  28. package/dist/data/orm/decorators.d.ts +1 -1
  29. package/dist/data/orm/decorators.js +7 -7
  30. package/dist/data/orm/table.js +3 -5
  31. package/dist/data/packages.d.ts +2 -1
  32. package/dist/data/packages.js +93 -44
  33. package/dist/data/packages.utils.d.ts +3 -0
  34. package/dist/data/packages.utils.js +41 -0
  35. package/dist/data/peer-events/peer-event-handlers.d.ts +1 -1
  36. package/dist/data/peer-events/peer-event-types.d.ts +1 -1
  37. package/dist/data/tool-tests.d.ts +1 -1
  38. package/dist/data/tools.d.ts +1 -1
  39. package/dist/data/user-permissions.test.js +7 -10
  40. package/dist/data/user-trust-levels.d.ts +42 -0
  41. package/dist/data/user-trust-levels.js +60 -0
  42. package/dist/data/users.d.ts +7 -7
  43. package/dist/data/users.js +86 -27
  44. package/dist/data/workflow-logs.d.ts +1 -1
  45. package/dist/data/workflow-runs.js +1 -1
  46. package/dist/data/workflows.d.ts +1 -1
  47. package/dist/device/get-trust-level.js +9 -5
  48. package/dist/keys.d.ts +1 -1
  49. package/dist/keys.js +2 -2
  50. package/dist/keys.test.js +1 -1
  51. package/dist/package-loader/package-loader.d.ts +1 -1
  52. package/dist/package-loader/package-loader.js +4 -4
  53. package/dist/rpc-types.d.ts +6 -20
  54. package/dist/rpc-types.js +5 -12
  55. package/dist/system-ids.d.ts +2 -0
  56. package/dist/system-ids.js +3 -1
  57. package/dist/users.query.d.ts +3 -1
  58. package/dist/users.query.js +39 -11
  59. 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
  */
@@ -86,38 +86,14 @@ 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) => {
119
91
  const table = await getTable(dataContextId, tableName);
120
- // @ts-ignore
92
+ const method = table[methodName];
93
+ if (typeof method !== 'function') {
94
+ throw new Error(`Method ${methodName} not found on table ${tableName}`);
95
+ }
96
+ // @ts-ignore - call this way to ensure 'this' is correct
121
97
  return table[methodName](...args);
122
98
  };
123
99
  }
@@ -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 {
@@ -11,9 +10,6 @@ export declare class UserContext {
11
10
  readonly currentlyActiveGroupId: Observable<string | undefined>;
12
11
  readonly packagesRootDir: Observable<string>;
13
12
  readonly reloadPackagesOnPageRefresh: Observable<boolean>;
14
- readonly packageLocalPathsResolved: Observable<{
15
- [packageId: string]: string;
16
- }>;
17
13
  readonly groupIds: Observable<string[]>;
18
14
  readonly userDataContext: DataContext;
19
15
  readonly groupDataContexts: Map<string, DataContext>;
@@ -37,10 +33,9 @@ export declare class UserContext {
37
33
  getMe(): Promise<{
38
34
  name: string;
39
35
  publicKey: string;
40
- publicBoxKey: string;
41
36
  userId: string;
37
+ publicBoxKey: string;
42
38
  signature?: string | undefined;
43
- trustLevel?: TrustLevel | undefined;
44
39
  } | undefined>;
45
40
  syncUserAndGroupObjects(userId: string, keys: IPublicPrivateKeys, me?: IUser): Promise<void>;
46
41
  subscribeToDataChangedAcrossAllGroups<T extends {
@@ -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");
@@ -16,7 +15,6 @@ class UserContext {
16
15
  currentlyActiveGroupId = (0, observable_1.observable)();
17
16
  packagesRootDir = (0, observable_1.observable)('');
18
17
  reloadPackagesOnPageRefresh = (0, observable_1.observable)(false);
19
- packageLocalPathsResolved = (0, observable_1.observable)({});
20
18
  groupIds = (0, observable_1.observable)([]);
21
19
  userDataContext;
22
20
  groupDataContexts = new Map();
@@ -109,7 +107,7 @@ class UserContext {
109
107
  */
110
108
  async loadUserContextObservablesFromDB() {
111
109
  const persistentVars = await this.userDataContext.tableContainer.getTableByName(data_1.persistentVarsMetaData.name);
112
- const vars = await persistentVars.list({ name: { $in: ['myUserId', 'thisDeviceId', 'currentlyActiveGroupId', 'packagesRootDir', 'reloadPackagesOnPageRefresh', 'packageLocalPathsResolved'] } });
110
+ const vars = await persistentVars.list({ name: { $in: ['myUserId', 'thisDeviceId', 'currentlyActiveGroupId', 'packagesRootDir', 'reloadPackagesOnPageRefresh'] } });
113
111
  const varDbValues = vars.reduce((acc, curr) => {
114
112
  acc[curr.name] = curr.value?.value;
115
113
  return acc;
@@ -127,14 +125,10 @@ class UserContext {
127
125
  const reloadPackagesOnPageRefreshPVar = (0, data_1.deviceVar)('reloadPackagesOnPageRefresh', { defaultValue: false, dbValue: varDbValues['reloadPackagesOnPageRefresh'], userContext: this });
128
126
  this.reloadPackagesOnPageRefresh(reloadPackagesOnPageRefreshPVar());
129
127
  (0, observable_1.linkObservables)(reloadPackagesOnPageRefreshPVar, this.reloadPackagesOnPageRefresh);
130
- const packageLocalPathsResolvedPVar = (0, data_1.deviceVar)('packageLocalPathsResolved', { defaultValue: {}, dbValue: varDbValues['packageLocalPathsResolved'], userContext: this });
131
- this.packageLocalPathsResolved(packageLocalPathsResolvedPVar());
132
- (0, observable_1.linkObservables)(packageLocalPathsResolvedPVar, this.packageLocalPathsResolved);
133
128
  await Promise.all([
134
129
  deviceIdPVar.loadingPromise,
135
130
  packagesRootDirPVar.loadingPromise,
136
131
  reloadPackagesOnPageRefreshPVar.loadingPromise,
137
- packageLocalPathsResolvedPVar.loadingPromise,
138
132
  ]);
139
133
  }
140
134
  async getMe() {
@@ -153,7 +147,6 @@ class UserContext {
153
147
  name: 'Unnamed_1',
154
148
  publicKey: '',
155
149
  publicBoxKey: '',
156
- trustLevel: socket_type_1.TrustLevel.Self,
157
150
  };
158
151
  }
159
152
  me.publicKey = keys.publicKey;
@@ -167,9 +160,8 @@ class UserContext {
167
160
  // sync my user to all all my groups
168
161
  for (const [, dataContext] of userContext.groupDataContexts) {
169
162
  let groupMe = await (0, data_1.Users)(dataContext).get(me.userId);
170
- if (!groupMe || groupMe.name !== me.name || groupMe.publicKey !== me.publicKey) {
171
- groupMe = (0, keys_1.addSignatureToObject)({ ...me, trustLevel: groupMe?.trustLevel || socket_type_1.TrustLevel.NewUser }, keys.secretKey);
172
- await (0, data_1.Users)(dataContext).save(groupMe);
163
+ if (!(0, lodash_1.isEqual)(groupMe, meSigned)) {
164
+ await (0, data_1.Users)(dataContext).save(meSigned);
173
165
  }
174
166
  }
175
167
  // sync group objects to my personal db
@@ -181,7 +173,13 @@ class UserContext {
181
173
  const groupObject = await (0, data_1.Groups)(dataContext).get(dataContext.groupId);
182
174
  const myGroupObject = await (0, data_1.Groups)(this.userDataContext).get(dataContext.groupId);
183
175
  if (groupObject && !(0, lodash_1.isEqual)(groupObject, myGroupObject)) {
184
- (0, keys_1.verifyObjectSignature)(groupObject);
176
+ try {
177
+ (0, keys_1.verifyObjectSignature)(groupObject);
178
+ }
179
+ catch (err) {
180
+ console.error(`Error verifying group object from group ${dataContext.groupId}:`, err);
181
+ continue;
182
+ }
185
183
  await (0, data_1.Groups)(this.userDataContext).save(groupObject);
186
184
  }
187
185
  }
@@ -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
  }>;
@@ -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
  } & {
@@ -4,23 +4,25 @@ import { FileWriteStream } from "./file-write-stream";
4
4
  import { IFile, IFileInput } from "./file.types";
5
5
  import type { DataContext } from "../../context/data-context";
6
6
  export declare class FilesTable extends Table<IFile> {
7
- /** @deprecated Direct inserts forbidden; use safeFile() or saveFileRecord() */
7
+ /** @deprecated Direct inserts forbidden; use saveFile() or saveFileRecord() */
8
8
  insert(..._args: Parameters<Table<any>['insert']>): never;
9
- /** @deprecated Direct updates forbidden; use safeFile() or saveFileRecord() */
9
+ /** @deprecated Direct updates forbidden; use saveFile() or saveFileRecord() */
10
10
  update(..._args: Parameters<Table<any>['update']>): never;
11
11
  /** @deprecated Direct deletes forbidden; use deleteFile() */
12
12
  delete(..._args: Parameters<Table<any>['delete']>): never;
13
+ /** @deprecated Direct save forbidden; use saveFile() or saveFileRecord() */
14
+ save(..._args: Parameters<Table<any>['save']>): never;
13
15
  createWriteStream(metadata: IFileInput): Promise<FileWriteStream>;
14
16
  /**
15
- * Note: Use `saveFile` instead for direct use. This method is intended for internal use
16
- * to insert a file record into the database as part of streaming operations.
17
- * @param fileRecord The file record to insert
17
+ * Note: Use `saveFile` to write a file to disk. This method is for managing
18
+ * the file metadata in the database which is done automatically by `saveFile`.
19
+ * @param fileRecord The file record to save to the database
18
20
  * @returns The inserted file record
19
21
  */
20
22
  saveFileRecord(fileRecord: IFile): Promise<IFile>;
21
23
  openReadStream(fileId: string, preloadChunksCount?: number): Promise<FileReadStream | null>;
22
24
  saveFile(metaData: IFileInput, data: Uint8Array | string): Promise<IFile>;
23
- getFile(fileId: string): Promise<Uint8Array | null>;
25
+ getFileContents(fileId: string): Promise<Uint8Array | null>;
24
26
  deleteFile(fileId: string): Promise<void>;
25
27
  createIndexFileRecursively(chunkHashes: string[]): Promise<string>;
26
28
  loadChunkHashesRecursively(indexFileId: string): Promise<string[]>;
@@ -11,25 +11,29 @@ const file_read_stream_1 = require("./file-read-stream");
11
11
  const file_write_stream_1 = require("./file-write-stream");
12
12
  const file_types_1 = require("./file.types");
13
13
  class FilesTable extends orm_1.Table {
14
- /** @deprecated Direct inserts forbidden; use safeFile() or saveFileRecord() */
14
+ /** @deprecated Direct inserts forbidden; use saveFile() or saveFileRecord() */
15
15
  insert(..._args) {
16
- throw new Error('Direct inserts forbidden; use safeFile() or saveFileRecord()');
16
+ throw new Error('Direct inserts forbidden; use saveFile() or saveFileRecord()');
17
17
  }
18
- /** @deprecated Direct updates forbidden; use safeFile() or saveFileRecord() */
18
+ /** @deprecated Direct updates forbidden; use saveFile() or saveFileRecord() */
19
19
  update(..._args) {
20
- throw new Error('Direct updates forbidden; use safeFile() or saveFileRecord()');
20
+ throw new Error('Direct updates forbidden; use saveFile() or saveFileRecord()');
21
21
  }
22
22
  /** @deprecated Direct deletes forbidden; use deleteFile() */
23
23
  delete(..._args) {
24
24
  throw new Error('Direct deletes forbidden; use deleteFile()');
25
25
  }
26
+ /** @deprecated Direct save forbidden; use saveFile() or saveFileRecord() */
27
+ save(..._args) {
28
+ throw new Error('Direct saves forbidden; use saveFile() or saveFileRecord()');
29
+ }
26
30
  async createWriteStream(metadata) {
27
31
  return new file_write_stream_1.FileWriteStream(metadata, this);
28
32
  }
29
33
  /**
30
- * Note: Use `saveFile` instead for direct use. This method is intended for internal use
31
- * to insert a file record into the database as part of streaming operations.
32
- * @param fileRecord The file record to insert
34
+ * Note: Use `saveFile` to write a file to disk. This method is for managing
35
+ * the file metadata in the database which is done automatically by `saveFile`.
36
+ * @param fileRecord The file record to save to the database
33
37
  * @returns The inserted file record
34
38
  */
35
39
  async saveFileRecord(fileRecord) {
@@ -56,7 +60,7 @@ class FilesTable extends orm_1.Table {
56
60
  // Finalize and return the result
57
61
  return await writeStream.finalize();
58
62
  }
59
- async getFile(fileId) {
63
+ async getFileContents(fileId) {
60
64
  // Use FileReadStream internally to ensure consistent chunk reading logic
61
65
  const readStream = await this.openReadStream(fileId);
62
66
  if (!readStream) {
@@ -76,9 +80,9 @@ class FilesTable extends orm_1.Table {
76
80
  await this.deleteFile(fileRecord.indexFileId);
77
81
  }
78
82
  // Note: We don't delete chunks since they may be shared with other files
79
- // Chunk cleanup could be implemented as a separate garbage collection process
83
+ // TODO Chunk cleanup needs to be implemented as a separate garbage collection process
80
84
  // that removes chunks not referenced by any files
81
- // Delete from database
85
+ // Delete file record from database
82
86
  await super.delete(fileId);
83
87
  }
84
88
  // Create an index file recursively for large files
@@ -103,7 +107,7 @@ class FilesTable extends orm_1.Table {
103
107
  // Load chunk hashes recursively from an index file
104
108
  async loadChunkHashesRecursively(indexFileId) {
105
109
  // Recursively load the index file
106
- const indexBuffer = await this.getFile(indexFileId);
110
+ const indexBuffer = await this.getFileContents(indexFileId);
107
111
  if (!indexBuffer) {
108
112
  throw new Error(`Index file not found: ${indexFileId}`);
109
113
  }
@@ -119,7 +123,7 @@ function Files(dataContext) {
119
123
  }
120
124
  // TODO implement permissions check for file access
121
125
  rpc_types_1.rpcServerCalls.getFileContents = async (fileId, encoding = 'utf8') => {
122
- const data = await Files().getFile(fileId);
126
+ const data = await Files().getFileContents(fileId);
123
127
  if (data === null) {
124
128
  throw new Error(`File not found: ${fileId}`);
125
129
  }