@peers-app/peers-sdk 0.15.4 → 0.16.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.
@@ -1,7 +1,6 @@
1
1
  export * from "./assistants";
2
2
  export * from "./change-tracking";
3
3
  export * from "./channels";
4
- export * from "./data-locks";
5
4
  export * from "./device-sync-info";
6
5
  export * from "./devices";
7
6
  export * from "./embeddings";
@@ -17,7 +17,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
17
17
  __exportStar(require("./assistants"), exports);
18
18
  __exportStar(require("./change-tracking"), exports);
19
19
  __exportStar(require("./channels"), exports);
20
- __exportStar(require("./data-locks"), exports);
21
20
  __exportStar(require("./device-sync-info"), exports);
22
21
  __exportStar(require("./devices"), exports);
23
22
  __exportStar(require("./embeddings"), exports);
@@ -1,4 +1,5 @@
1
1
  import type { z } from "zod";
2
+ import type { ITableDefinitionRecord } from "../table-definitions-table";
2
3
  import { Table } from "./table";
3
4
  import type { ITableDefinition, TableConstructor, TableFactory } from "./table-definitions.type";
4
5
  import { type ITableMetaData } from "./types";
@@ -52,6 +53,27 @@ export declare class TableContainer {
52
53
  * Returns the table instance if found, or null if no definition exists.
53
54
  */
54
55
  getFallbackTable(tableName: string): Promise<Table<any> | null>;
56
+ /**
57
+ * Return the names of all tables whose TableDefinitions record has `deleted` set.
58
+ * Used by sync to exclude change records for deleted tables.
59
+ *
60
+ * @returns Array of table names (as stored in the `name` column of TableDefinitions).
61
+ */
62
+ getDeletedTableNames(): Promise<string[]>;
63
+ /**
64
+ * Return all TableDefinitions records that have been marked as deleted.
65
+ * Used by the Data Explorer UI to display deleted tables.
66
+ *
67
+ * @returns Full {@link ITableDefinitionRecord} objects with populated `deleted` timestamps.
68
+ */
69
+ getDeletedTableDefinitions(): Promise<ITableDefinitionRecord[]>;
70
+ /**
71
+ * Return the names of all tables whose metadata marks them as local-only.
72
+ * Used by sync to exclude local-only change records from remote exchange.
73
+ *
74
+ * @returns Array of full table names for local-only table definitions.
75
+ */
76
+ getLocalOnlyTableNames(): string[];
55
77
  /**
56
78
  * Register a table definition from a synced TableDefinitions record.
57
79
  * These go into the fallback tier (no custom constructor) so they never
@@ -158,6 +158,15 @@ class TableContainer {
158
158
  .get(metaData.tableId)
159
159
  .then((existing) => {
160
160
  if (existing) {
161
+ // Code-registration is authoritative: if the table was marked deleted,
162
+ // clear the flag and force an update so sync propagates the revival.
163
+ if (existing.deleted) {
164
+ record.deleted = undefined;
165
+ return tableDefsTable.save(record, {
166
+ restoreIfDeleted: true,
167
+ saveAsSnapshot: true,
168
+ });
169
+ }
161
170
  const result = checkVersionedUpdate(existing.versionNumber, record.versionNumber, existing.metaData, record.metaData);
162
171
  if (result === "skip") {
163
172
  return;
@@ -225,7 +234,7 @@ class TableContainer {
225
234
  if (!this.fallbackSubscribed) {
226
235
  this.fallbackSubscribed = true;
227
236
  tableDefsTable.dataChanged.subscribe((event) => {
228
- if (event.op === "delete") {
237
+ if (event.op === "delete" || event.dataObject?.deleted) {
229
238
  const md = event.dataObject?.metaData;
230
239
  if (md) {
231
240
  const name = (0, utils_1.getFullTableName)(md);
@@ -239,12 +248,63 @@ class TableContainer {
239
248
  }
240
249
  // Query for this specific table definition
241
250
  const record = await tableDefsTable.findOne({ name: tableName });
242
- if (!record)
251
+ if (!record || record.deleted)
243
252
  return null;
244
253
  this.registerFromTableDefinitionRecord(record);
245
254
  // Now instantiate via getTableByName which checks fallbackDefinitions
246
255
  return this.getTableByName(tableName);
247
256
  }
257
+ /**
258
+ * Return the names of all tables whose TableDefinitions record has `deleted` set.
259
+ * Used by sync to exclude change records for deleted tables.
260
+ *
261
+ * @returns Array of table names (as stored in the `name` column of TableDefinitions).
262
+ */
263
+ async getDeletedTableNames() {
264
+ const tableDefsTable = this.tableInstances.TableDefinitions;
265
+ if (!tableDefsTable)
266
+ return [];
267
+ const deletedRecords = await tableDefsTable.list({
268
+ deleted: { $exists: true },
269
+ });
270
+ return deletedRecords.map((r) => r.name);
271
+ }
272
+ /**
273
+ * Return all TableDefinitions records that have been marked as deleted.
274
+ * Used by the Data Explorer UI to display deleted tables.
275
+ *
276
+ * @returns Full {@link ITableDefinitionRecord} objects with populated `deleted` timestamps.
277
+ */
278
+ async getDeletedTableDefinitions() {
279
+ const tableDefsTable = this.tableInstances.TableDefinitions;
280
+ if (!tableDefsTable)
281
+ return [];
282
+ return tableDefsTable.list({ deleted: { $exists: true } });
283
+ }
284
+ /**
285
+ * Return the names of all tables whose metadata marks them as local-only.
286
+ * Used by sync to exclude local-only change records from remote exchange.
287
+ *
288
+ * @returns Array of full table names for local-only table definitions.
289
+ */
290
+ getLocalOnlyTableNames() {
291
+ const names = [];
292
+ const fullDefinitions = [
293
+ ...Object.values(table_definitions_system_1.systemTableDefinitions),
294
+ ...Object.values(this.tableDefinitions),
295
+ ];
296
+ for (const tableDefinition of fullDefinitions) {
297
+ if (tableDefinition.metaData.localOnly) {
298
+ names.push((0, utils_1.getFullTableName)(tableDefinition.metaData));
299
+ }
300
+ }
301
+ for (const [tableName, fallbackDefinition] of Object.entries(this.fallbackDefinitions)) {
302
+ if (fallbackDefinition.metaData.localOnly && !names.includes(tableName)) {
303
+ names.push(tableName);
304
+ }
305
+ }
306
+ return names;
307
+ }
248
308
  /**
249
309
  * Register a table definition from a synced TableDefinitions record.
250
310
  * These go into the fallback tier (no custom constructor) so they never
@@ -260,6 +320,12 @@ class TableContainer {
260
320
  return;
261
321
  }
262
322
  const tableName = (0, utils_1.getFullTableName)(metaData);
323
+ // Deleted tables should not be registered as fallbacks
324
+ if (record.deleted) {
325
+ delete this.fallbackDefinitions[tableName];
326
+ delete this.fallbackInstances[tableName];
327
+ return;
328
+ }
263
329
  // Don't overwrite a full (code-registered) definition -- that always takes precedence
264
330
  const fullDef = this.tableDefinitions[tableName] || table_definitions_system_1.systemTableDefinitions[tableName];
265
331
  if (fullDef) {
@@ -67,7 +67,7 @@ function createTestHarness() {
67
67
  .fn()
68
68
  .mockImplementation((metaData, schema, TableClass) => {
69
69
  const deps = {
70
- dataSource: new client_proxy_data_source_1.ClientProxyDataSource(metaData, schema, "test-context"),
70
+ dataSource: new client_proxy_data_source_1.ClientProxyDataSource(metaData, schema ?? zod_1.z.object({}), "test-context"),
71
71
  eventRegistry,
72
72
  };
73
73
  return new (TableClass || table_1.Table)(metaData, deps);
@@ -134,7 +134,7 @@ describe("Tiered table instances", () => {
134
134
  expect(table).not.toBeInstanceOf(CustomTestTable);
135
135
  });
136
136
  it("getAllTables should prefer full instances over fallback instances", () => {
137
- const { container, testMetaData, testSchema, defRecord, tableFactory } = createTestHarness();
137
+ const { container, testMetaData, testSchema, defRecord } = createTestHarness();
138
138
  // Create a second table that will only have a fallback definition
139
139
  const tableId2 = (0, utils_1.newid)();
140
140
  const metaData2 = {
@@ -172,3 +172,58 @@ describe("Tiered table instances", () => {
172
172
  expect(secondTable).not.toBeInstanceOf(CustomTestTable);
173
173
  });
174
174
  });
175
+ describe("getLocalOnlyTableNames", () => {
176
+ it("returns localOnly code-registered table names and excludes non-local tables", () => {
177
+ const { container, testSchema } = createTestHarness();
178
+ const localOnlyMetaData = {
179
+ tableId: (0, utils_1.newid)(),
180
+ name: "LocalOnlyTable",
181
+ description: "A local-only table",
182
+ primaryKeyName: "id",
183
+ fields: [
184
+ { name: "id", type: field_type_1.FieldType.id },
185
+ { name: "title", type: field_type_1.FieldType.string },
186
+ ],
187
+ localOnly: true,
188
+ };
189
+ const syncedMetaData = {
190
+ tableId: (0, utils_1.newid)(),
191
+ name: "SyncedTable",
192
+ description: "A synced table",
193
+ primaryKeyName: "id",
194
+ fields: [
195
+ { name: "id", type: field_type_1.FieldType.id },
196
+ { name: "title", type: field_type_1.FieldType.string },
197
+ ],
198
+ };
199
+ container.registerTableDefinition({
200
+ metaData: localOnlyMetaData,
201
+ schema: testSchema,
202
+ });
203
+ container.registerTableDefinition({
204
+ metaData: syncedMetaData,
205
+ schema: testSchema,
206
+ });
207
+ const localOnlyNames = container.getLocalOnlyTableNames();
208
+ expect(localOnlyNames).toContain((0, utils_1.getFullTableName)(localOnlyMetaData));
209
+ expect(localOnlyNames).not.toContain((0, utils_1.getFullTableName)(syncedMetaData));
210
+ });
211
+ it("returns localOnly fallback table names without duplicates", () => {
212
+ const { container, testMetaData, testSchema, defRecord } = createTestHarness();
213
+ const localOnlyMetaData = {
214
+ ...testMetaData,
215
+ localOnly: true,
216
+ };
217
+ const localOnlyDefRecord = {
218
+ ...defRecord,
219
+ metaData: localOnlyMetaData,
220
+ };
221
+ container.registerFromTableDefinitionRecord(localOnlyDefRecord);
222
+ container.registerTableDefinition({
223
+ metaData: localOnlyMetaData,
224
+ schema: testSchema,
225
+ });
226
+ const localOnlyNames = container.getLocalOnlyTableNames();
227
+ expect(localOnlyNames.filter((name) => name === defRecord.name)).toHaveLength(1);
228
+ });
229
+ });
@@ -1,10 +1,12 @@
1
1
  import { z } from "zod";
2
2
  import type { DataContext } from "../context/data-context";
3
+ /** Zod schema for rows in the {@link TableDefinitions} system table. */
3
4
  export declare const tableDefinitionRecordSchema: z.ZodObject<{
4
5
  tableId: z.ZodString;
5
6
  name: z.ZodString;
6
7
  metaData: z.ZodObject<{}, "strip", z.ZodAny, z.objectOutputType<{}, z.ZodAny, "strip">, z.objectInputType<{}, z.ZodAny, "strip">>;
7
8
  versionNumber: z.ZodDefault<z.ZodNumber>;
9
+ deleted: z.ZodOptional<z.ZodDate>;
8
10
  }, "strip", z.ZodTypeAny, {
9
11
  name: string;
10
12
  metaData: {} & {
@@ -12,15 +14,26 @@ export declare const tableDefinitionRecordSchema: z.ZodObject<{
12
14
  };
13
15
  tableId: string;
14
16
  versionNumber: number;
17
+ deleted?: Date | undefined;
15
18
  }, {
16
19
  name: string;
17
20
  metaData: {} & {
18
21
  [k: string]: any;
19
22
  };
20
23
  tableId: string;
24
+ deleted?: Date | undefined;
21
25
  versionNumber?: number | undefined;
22
26
  }>;
27
+ /** A single row in the {@link TableDefinitions} system table. */
23
28
  export type ITableDefinitionRecord = z.infer<typeof tableDefinitionRecordSchema>;
29
+ /**
30
+ * Accessor for the TableDefinitions system table.
31
+ *
32
+ * This table stores table schemas as tracked, synced data so that peers can
33
+ * learn about table definitions without needing the originating package installed.
34
+ *
35
+ * @param dataContext - Optional data context; when omitted the singleton context is used.
36
+ */
24
37
  export declare function TableDefinitions(dataContext?: DataContext): import("./orm").Table<{
25
38
  name: string;
26
39
  metaData: {} & {
@@ -28,4 +41,5 @@ export declare function TableDefinitions(dataContext?: DataContext): import("./o
28
41
  };
29
42
  tableId: string;
30
43
  versionNumber: number;
44
+ deleted?: Date | undefined;
31
45
  }>;
@@ -7,6 +7,7 @@ const user_context_singleton_1 = require("../context/user-context-singleton");
7
7
  const zod_types_1 = require("../types/zod-types");
8
8
  const table_definitions_system_1 = require("./orm/table-definitions.system");
9
9
  const types_1 = require("./orm/types");
10
+ /** Zod schema for rows in the {@link TableDefinitions} system table. */
10
11
  exports.tableDefinitionRecordSchema = zod_1.z.object({
11
12
  tableId: zod_1.z.string().describe("Primary key - same as ITableMetaData.tableId"),
12
13
  name: zod_1.z.string().describe("Table name"),
@@ -15,6 +16,10 @@ exports.tableDefinitionRecordSchema = zod_1.z.object({
15
16
  .number()
16
17
  .default(0)
17
18
  .describe("Version number set by the developer in the table definition; higher value wins during sync"),
19
+ deleted: zod_1.z
20
+ .date()
21
+ .optional()
22
+ .describe("When set, the table was deleted at this time. Changes for this table should be ignored during sync."),
18
23
  });
19
24
  const metaData = {
20
25
  name: "TableDefinitions",
@@ -24,6 +29,14 @@ const metaData = {
24
29
  indexes: [{ fields: ["name"] }],
25
30
  };
26
31
  (0, table_definitions_system_1.registerSystemTableDefinition)(metaData, exports.tableDefinitionRecordSchema);
32
+ /**
33
+ * Accessor for the TableDefinitions system table.
34
+ *
35
+ * This table stores table schemas as tracked, synced data so that peers can
36
+ * learn about table definitions without needing the originating package installed.
37
+ *
38
+ * @param dataContext - Optional data context; when omitted the singleton context is used.
39
+ */
27
40
  function TableDefinitions(dataContext) {
28
41
  return (0, user_context_singleton_1.getTableContainer)(dataContext).getTable(metaData, exports.tableDefinitionRecordSchema);
29
42
  }
@@ -36,6 +36,7 @@ const metaData = {
36
36
  description: "The log entries for workflow runs.",
37
37
  primaryKeyName: "workflowLogId",
38
38
  fields: (0, types_1.schemaToFields)(exports.workflowLogSchema),
39
+ localOnly: true,
39
40
  };
40
41
  (0, table_definitions_system_1.registerSystemTableDefinition)(metaData, exports.workflowLogSchema);
41
42
  function WorkflowLogs(dataContext) {
@@ -1,6 +1,5 @@
1
1
  import { z } from "zod";
2
2
  import type { DataContext } from "../context/data-context";
3
- import { type IDataLock } from "./data-locks";
4
3
  import { Table } from "./orm/table";
5
4
  export declare const workflowRunSchema: z.ZodObject<{
6
5
  workflowRunId: z.ZodEffects<z.ZodString, string, string>;
@@ -77,19 +76,9 @@ export declare const workflowRunSchema: z.ZodObject<{
77
76
  }>;
78
77
  export type IWorkflowRun = z.infer<typeof workflowRunSchema>;
79
78
  declare class WorkflowRunTable extends Table<IWorkflowRun> {
80
- /** @deprecated Direct calls to save forbidden; use insert or saveWithLock */
81
- save(..._args: Parameters<Table<any>["insert"]>): never;
82
- /** @deprecated Direct calls to update forbidden; use saveWithLock() */
83
- update(..._args: Parameters<Table<any>["update"]>): never;
84
- saveWithLock(workflowRun: IWorkflowRun, lock?: IDataLock): Promise<IWorkflowRun>;
85
- acquireLock(workflowRunId: string, timeoutMs?: number, lockTimeMs?: number): Promise<IDataLock | undefined>;
86
- saveAndRelease(workflowRun: IWorkflowRun, lock: IDataLock): Promise<void>;
87
79
  haltRun(workflowRunId: string): Promise<void>;
88
- /**
89
- * Removes the error state from a workflow run and locks it so
90
- * additional editing can be done before it is re-run.
91
- */
92
- clearErrorState(workflowRunId: string): Promise<IDataLock | false>;
80
+ /** Removes the error state from a workflow run so it can be re-run. */
81
+ clearErrorState(workflowRunId: string): Promise<boolean>;
93
82
  }
94
83
  export declare function WorkflowRuns(dataContext?: DataContext): WorkflowRunTable;
95
84
  export interface IRunWorkflowOptions {
@@ -47,7 +47,6 @@ const zod_types_1 = require("../types/zod-types");
47
47
  const utils_1 = require("../utils");
48
48
  const assistants_1 = require("./assistants");
49
49
  const channels_1 = require("./channels");
50
- const data_locks_1 = require("./data-locks");
51
50
  const groups_1 = require("./groups");
52
51
  const messages_1 = require("./messages");
53
52
  const orm_1 = require("./orm");
@@ -104,6 +103,7 @@ const metaData = {
104
103
  description: "workflows instances that have been run manually, from messages, or from events",
105
104
  primaryKeyName: "workflowRunId",
106
105
  fields: (0, types_1.schemaToFields)(exports.workflowRunSchema),
106
+ localOnly: true,
107
107
  indexes: [
108
108
  { fields: ["workflowId"] },
109
109
  { fields: ["parentMessageId"] },
@@ -123,83 +123,6 @@ let WorkflowRunTable = (() => {
123
123
  __esDecorate(this, null, _haltRun_decorators, { kind: "method", name: "haltRun", static: false, private: false, access: { has: obj => "haltRun" in obj, get: obj => obj.haltRun }, metadata: _metadata }, null, _instanceExtraInitializers);
124
124
  if (_metadata) Object.defineProperty(this, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
125
125
  }
126
- /** @deprecated Direct calls to save forbidden; use insert or saveWithLock */
127
- save(..._args) {
128
- throw new Error("Direct inserts forbidden; use insert() or saveWithLock()");
129
- }
130
- /** @deprecated Direct calls to update forbidden; use saveWithLock() */
131
- update(..._args) {
132
- throw new Error("Direct updates forbidden; use saveWithLock()");
133
- }
134
- async saveWithLock(workflowRun, lock) {
135
- if (!workflowRun.workflowRunId) {
136
- workflowRun.workflowRunId = (0, utils_1.newid)();
137
- return super.insert(workflowRun);
138
- }
139
- let lockedForThisSave = false;
140
- if (!lock) {
141
- lock = await (0, data_locks_1.DataLocks)().acquireLock(workflowRun.workflowRunId);
142
- lockedForThisSave = true;
143
- }
144
- else {
145
- const currentLock = await (0, data_locks_1.DataLocks)().getCurrentLock(workflowRun.workflowRunId);
146
- if (currentLock?.dataLockId !== lock.dataLockId) {
147
- throw new Error(`Provided lock is not the current lock for workflowRunId ${workflowRun.workflowRunId} - aborting save`);
148
- }
149
- }
150
- if (!lock) {
151
- throw new Error(`Could not acquire lock for workflow run ${workflowRun.workflowRunId}`);
152
- }
153
- if (lock.recordId !== workflowRun.workflowRunId) {
154
- throw new Error(`Provided lock recordId ${lock?.recordId} does not match workflowRunId ${workflowRun.workflowRunId}`);
155
- }
156
- let dbData = await this.get(workflowRun.workflowRunId);
157
- if (dbData && !lock) {
158
- const currentLock = await (0, data_locks_1.DataLocks)().getCurrentLock(workflowRun.workflowRunId);
159
- if (currentLock) {
160
- throw new Error(`Workflow run ${workflowRun.workflowRunId} is locked by ${currentLock.dataLockId} - the lock will timeout at ${new Date(currentLock.lockedUntil)}`);
161
- }
162
- }
163
- if (dbData?.inErrorState) {
164
- throw new Error(`Workflow run ${workflowRun.workflowRunId} is in an error state - use clearErrorState to continue the run`);
165
- }
166
- if (dbData) {
167
- dbData = await super.update(workflowRun);
168
- }
169
- else {
170
- dbData = await super.insert(workflowRun);
171
- }
172
- if (lockedForThisSave) {
173
- await (0, data_locks_1.DataLocks)().releaseLock(lock);
174
- }
175
- return dbData;
176
- }
177
- async acquireLock(workflowRunId, timeoutMs, lockTimeMs) {
178
- const workflowDbData = await this.get(workflowRunId);
179
- if (!workflowDbData)
180
- return undefined;
181
- if (workflowDbData.inErrorState) {
182
- console.warn(`Workflow run ${workflowRunId} is in an error state - not acquiring lock`);
183
- return undefined;
184
- }
185
- return await (0, data_locks_1.DataLocks)().acquireLock(workflowRunId, timeoutMs, lockTimeMs);
186
- }
187
- async saveAndRelease(workflowRun, lock) {
188
- const workflowDbData = await this.get(workflowRun.workflowRunId);
189
- if (!workflowDbData)
190
- return;
191
- const currentLock = await (0, data_locks_1.DataLocks)().getCurrentLock(workflowRun.workflowRunId);
192
- if (!currentLock || currentLock.dataLockId !== lock.dataLockId) {
193
- console.warn(`Workflow run ${workflowRun.workflowRunId} is not locked by ${lock.dataLockId} - aborting save`);
194
- return;
195
- }
196
- if (workflowDbData.inErrorState) {
197
- console.warn(`Workflow run ${workflowRun.workflowRunId} is in an error state - aborting save`);
198
- return;
199
- }
200
- await super.update(workflowRun);
201
- await (0, data_locks_1.DataLocks)().releaseLock(lock);
202
- }
203
126
  async haltRun(workflowRunId) {
204
127
  const run = await super.get(workflowRunId);
205
128
  if (!run) {
@@ -212,16 +135,6 @@ let WorkflowRunTable = (() => {
212
135
  if (!run.completedAt) {
213
136
  run.inErrorState = true;
214
137
  await super.update(run);
215
- // Release any existing lock
216
- while (true) {
217
- const currentLock = await (0, data_locks_1.DataLocks)().getCurrentLock(workflowRunId);
218
- if (currentLock) {
219
- await (0, data_locks_1.DataLocks)().releaseLock(currentLock);
220
- }
221
- else {
222
- break; // No lock to release
223
- }
224
- }
225
138
  // also halt any child runs
226
139
  this.list({ parentWorkflowRunId: workflowRunId })
227
140
  .then(async (childRuns) => {
@@ -241,10 +154,7 @@ let WorkflowRunTable = (() => {
241
154
  logger(runHaltMessage);
242
155
  }
243
156
  }
244
- /**
245
- * Removes the error state from a workflow run and locks it so
246
- * additional editing can be done before it is re-run.
247
- */
157
+ /** Removes the error state from a workflow run so it can be re-run. */
248
158
  async clearErrorState(workflowRunId) {
249
159
  const run = await super.get(workflowRunId);
250
160
  if (!run) {
@@ -254,14 +164,9 @@ let WorkflowRunTable = (() => {
254
164
  console.warn(`Workflow run ${workflowRunId} is not in an error state - not clearing`);
255
165
  return false;
256
166
  }
257
- const lock = await (0, data_locks_1.DataLocks)().acquireLock(workflowRunId);
258
- if (!lock) {
259
- console.warn(`Could not acquire lock for workflow run ${workflowRunId}`);
260
- return false;
261
- }
262
167
  run.inErrorState = false;
263
168
  await super.update(run);
264
- return lock;
169
+ return true;
265
170
  }
266
171
  constructor() {
267
172
  super(...arguments);
@@ -11,6 +11,7 @@ const metaData = {
11
11
  primaryKeyName: "workflowId",
12
12
  fields: (0, types_1.schemaToFields)(workflow_1.workflowSchema),
13
13
  iconClassName: "bi bi-database-fill-gear",
14
+ localOnly: true,
14
15
  indexes: [{ fields: ["name"] }],
15
16
  };
16
17
  (0, table_definitions_system_1.registerSystemTableDefinition)(metaData, workflow_1.workflowSchema);
package/dist/index.d.ts CHANGED
@@ -1,9 +1,9 @@
1
1
  export * from "./context";
2
2
  export * from "./data";
3
- export { WorkflowLogs, getLogger, workflowLogSchema, type IWorkflowLog, } from "./data/workflow-logs";
4
3
  export * as data from "./data";
5
4
  export * from "./data/orm";
6
5
  export * as orm from "./data/orm";
6
+ export { getLogger, type IWorkflowLog, WorkflowLogs, workflowLogSchema, } from "./data/workflow-logs";
7
7
  export * from "./device/binary-peer-connection-v2";
8
8
  export * from "./device/connection";
9
9
  export * from "./device/device";
package/dist/index.js CHANGED
@@ -14,17 +14,17 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
- exports.tools = exports.orm = exports.data = exports.workflowLogSchema = exports.getLogger = exports.WorkflowLogs = void 0;
17
+ exports.tools = exports.workflowLogSchema = exports.WorkflowLogs = exports.getLogger = exports.orm = exports.data = void 0;
18
18
  __exportStar(require("./context"), exports);
19
19
  __exportStar(require("./data"), exports);
20
+ exports.data = require("./data");
21
+ __exportStar(require("./data/orm"), exports);
22
+ exports.orm = require("./data/orm");
20
23
  // Root `.d.ts` lists these explicitly so IDEs see them (not only via `export *`).
21
24
  var workflow_logs_1 = require("./data/workflow-logs");
22
- Object.defineProperty(exports, "WorkflowLogs", { enumerable: true, get: function () { return workflow_logs_1.WorkflowLogs; } });
23
25
  Object.defineProperty(exports, "getLogger", { enumerable: true, get: function () { return workflow_logs_1.getLogger; } });
26
+ Object.defineProperty(exports, "WorkflowLogs", { enumerable: true, get: function () { return workflow_logs_1.WorkflowLogs; } });
24
27
  Object.defineProperty(exports, "workflowLogSchema", { enumerable: true, get: function () { return workflow_logs_1.workflowLogSchema; } });
25
- exports.data = require("./data");
26
- __exportStar(require("./data/orm"), exports);
27
- exports.orm = require("./data/orm");
28
28
  __exportStar(require("./device/binary-peer-connection-v2"), exports);
29
29
  __exportStar(require("./device/connection"), exports);
30
30
  __exportStar(require("./device/device"), exports);
package/dist/keys.d.ts CHANGED
@@ -1,52 +1,103 @@
1
+ /** Replaces tweetnacl’s default PRNG (required on some runtimes, e.g. tests or constrained environments). */
1
2
  export declare function setPRNG(fn: (x: Uint8Array, n: number) => void): void;
3
+ /** SHA-256 of UTF-8 `str`, returned as base64url (no padding). */
2
4
  export declare function hashValue(str: string): string;
5
+ /** SHA-256 of raw bytes, returned as base64url (no padding). */
3
6
  export declare function hashBytes(buffer: Uint8Array): string;
7
+ /** Deterministic JSON string via `fast-json-stable-stringify` (key order stable). */
4
8
  export declare function stableStringify(obj: any): string;
9
+ /** {@link hashValue} of the stable JSON for `obj` (for content-addressing object payloads). */
5
10
  export declare function hashObject(obj: {
6
11
  [key: string]: any;
7
12
  }): string;
13
+ /** Base64 with URL-safe alphabet and no `=` padding (used throughout keys and wire formats). */
8
14
  export declare function encodeBase64(data: Uint8Array): string;
15
+ /**
16
+ * Inverse of {@link encodeBase64}; accepts standard or URL-safe base64 and repads as needed.
17
+ * @throws TypeError if `data` is not a string
18
+ */
9
19
  export declare function decodeBase64(data: string): Uint8Array;
20
+ /** Random token as base64url string (`size` raw bytes, default 32). */
10
21
  export declare function newToken(size?: number): string;
22
+ /** Ed25519 signing key and derived X25519 box public key, both base64url. */
11
23
  export interface IPublicKeys {
12
24
  publicKey: string;
13
25
  publicBoxKey: string;
14
26
  }
27
+ /** {@link IPublicKeys} plus Ed25519 secret key material (64-byte encoding as stored by this module). */
15
28
  export interface IPublicPrivateKeys extends IPublicKeys {
16
29
  secretKey: string;
17
30
  }
31
+ /** Detached Ed25519 signature over JSON-serialized `contents` with signer’s public key. */
18
32
  export interface ISignedObject<T> {
19
33
  contents: T;
20
34
  signature: string;
21
35
  publicKey: string;
22
36
  }
37
+ /** NaCl box ciphertext + nonce + sender box public key (all base64url). */
23
38
  export interface IDataBox {
24
39
  contents: string;
25
40
  nonce: string;
26
41
  fromPublicKey: string;
27
42
  }
43
+ /** Generates a new Ed25519 keypair and derived X25519 box keys; all keys are base64url. */
28
44
  export declare function newKeys(): IPublicPrivateKeys;
45
+ /** Re-derives public and box keys from an Ed25519 `secretKey` (same encoding as {@link newKeys}). */
29
46
  export declare function hydrateKeys(secretKey: string): IPublicPrivateKeys;
47
+ /** Signs a UTF-8 message with Ed25519; returns base64url signed message (NaCl `sign` combined format). */
30
48
  export declare function signMessageWithSecretKey(msg: string, secretKey: string): string;
49
+ /**
50
+ * Verifies and strips an Ed25519 signed message; returns the original UTF-8 string.
51
+ * @throws If verification fails
52
+ */
31
53
  export declare function openMessageWithPublicKey(msg: string, publicKey: string): string;
54
+ /**
55
+ * Detached sign over stable JSON: `undefined` / `null` are encoded with sentinel fields for round-trip.
56
+ * @returns Payload with original `contents`, `signature`, and signer's Ed25519 public key (32-byte slice, base64url)
57
+ */
32
58
  export declare function signObjectWithSecretKey<T>(obj: T, secretKey: string): ISignedObject<T>;
59
+ /**
60
+ * Verifies a detached signature and returns `contents` after undoing the undefined/null sentinels.
61
+ * @throws If the signature is invalid
62
+ */
33
63
  export declare function openSignedObject<T>(signedObj: ISignedObject<T>): T;
64
+ /**
65
+ * X25519 box encrypts `data` (msgpack via {@link txEncode}) to `toPublicBoxKey` from keys derived from `mySecretKey`.
66
+ * @param toPublicBoxKey Recipient’s X25519 public key (base64url)
67
+ */
34
68
  export declare function boxDataWithKeys(data: any, toPublicBoxKey: string, mySecretKey: string): IDataBox;
69
+ /** Narrowing guard: value looks like an {@link IDataBox} envelope. */
35
70
  export declare function isBoxedData(data: any): boolean;
71
+ /**
72
+ * Decrypts a box from {@link boxDataWithKeys} using the recipient’s Ed25519 secret (same format as {@link newKeys}).
73
+ * @throws If decryption or authentication fails
74
+ */
36
75
  export declare function openBoxWithSecretKey(box: IDataBox, mySecretKey: string): any;
76
+ /** JSON-serializes `data` then NaCl `secretbox` with a random nonce; returns base64 payload `~` base64 nonce. */
37
77
  export declare function encryptData<T>(data: T, secretKey: string): string;
78
+ /** Inverse of {@link encryptData}. Returns `null` if secretbox open fails. */
38
79
  export declare function decryptData<T>(encryptedData: string, secretKey: string): T | null;
80
+ /** Object plus a `signature` field in the `publicKey:detachedSig` form produced by this module. */
39
81
  export type IObjectWithSignature<T> = T & {
40
82
  signature: string;
41
83
  };
42
84
  type IMaybeSignature = {
43
85
  signature?: string;
44
86
  };
87
+ /**
88
+ * Strips any existing `signature`, signs a shallow copy of `obj`, and sets `signature` to `publicKey:detachedSig`.
89
+ * @returns Same shape as `obj` with string `signature` suitable for {@link verifyObjectSignature}
90
+ */
45
91
  export declare function addSignatureToObject<T extends Record<string, any>>(obj: T, secretKey: string): IObjectWithSignature<T>;
46
92
  /**
47
- * Will throw if the signature is invalid
93
+ * Ensures `signature` matches the rest of the object via {@link openSignedObject}.
94
+ * @throws If there is no signature or verification fails
48
95
  */
49
96
  export declare function verifyObjectSignature<T extends IMaybeSignature>(objectWithSignature: T): void;
97
+ /** True if {@link verifyObjectSignature} would succeed. */
50
98
  export declare function isObjectSignatureValid<T extends IMaybeSignature>(objectWithSignature: T): boolean;
99
+ /**
100
+ * Parses the Ed25519 public key prefix from a `publicKey:signature` field, or `undefined` if malformed.
101
+ */
51
102
  export declare function getPublicKeyFromObjectSignature<T extends IMaybeSignature>(objectWithSignature: T): string | undefined;
52
103
  export {};