tina4-nodejs 3.13.150 → 3.13.152

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 (71) hide show
  1. package/CLAUDE.md +2 -2
  2. package/package.json +5 -9
  3. package/packages/cli/dist/bin.js +1326 -586
  4. package/packages/cli/src/bin.ts +179 -7
  5. package/packages/cli/src/commands/generate.ts +36 -17
  6. package/packages/cli/src/commands/migrateCreate.ts +15 -3
  7. package/packages/cli/src/commands/queue.ts +8 -0
  8. package/packages/cli/src/util.ts +25 -15
  9. package/packages/core/dist/index.js +1172 -574
  10. package/packages/core/src/aiClient.ts +2 -1
  11. package/packages/core/src/api.ts +2 -1
  12. package/packages/core/src/auth.ts +1 -1
  13. package/packages/core/src/authGate.ts +3 -4
  14. package/packages/core/src/cache.ts +6 -1
  15. package/packages/core/src/devAdmin.ts +180 -123
  16. package/packages/core/src/dispatchPipeline.ts +4 -0
  17. package/packages/core/src/docs.ts +5 -3
  18. package/packages/core/src/errorOverlay.ts +18 -9
  19. package/packages/core/src/index.ts +2 -1
  20. package/packages/core/src/mcp.ts +53 -16
  21. package/packages/core/src/messenger.ts +22 -30
  22. package/packages/core/src/middleware.ts +8 -1
  23. package/packages/core/src/optionalPackage.ts +2 -2
  24. package/packages/core/src/plan.ts +3 -3
  25. package/packages/core/src/push.ts +1 -1
  26. package/packages/core/src/request.ts +185 -25
  27. package/packages/core/src/router.ts +3 -2
  28. package/packages/core/src/server.ts +36 -12
  29. package/packages/core/src/session.ts +44 -0
  30. package/packages/core/src/slashTrim.ts +39 -0
  31. package/packages/core/src/wsdl.ts +66 -48
  32. package/packages/core/templates/crud/form.twig +5 -5
  33. package/packages/core/templates/crud/table.twig +2 -2
  34. package/packages/core/templates/errors/302.twig +4 -3
  35. package/packages/frond/dist/index.js +206 -64
  36. package/packages/frond/src/engine.ts +278 -69
  37. package/packages/frond/src/index.ts +1 -1
  38. package/packages/orm/dist/index.js +1156 -560
  39. package/packages/orm/src/adapters/postgres.ts +79 -19
  40. package/packages/orm/src/crudRender.ts +5 -5
  41. package/packages/orm/src/crudTable.ts +1 -1
  42. package/packages/orm/src/database.ts +15 -29
  43. package/packages/orm/src/databaseResult.ts +11 -1
  44. package/packages/orm/src/docstore.ts +24 -8
  45. package/packages/orm/src/realtime/index.ts +1 -0
  46. package/packages/orm/src/realtime/realtime.ts +2 -1
  47. package/packages/orm/src/realtime/s3Client.ts +276 -0
  48. package/packages/orm/src/realtime/storage.ts +19 -60
  49. package/packages/orm/src/sqlTranslator.ts +58 -42
  50. package/packages/swagger/dist/index.js +25 -4
  51. package/packages/swagger/src/generator.ts +7 -4
  52. package/packages/swagger/src/ui.ts +2 -1
  53. package/types/cli/src/bin.d.ts +16 -0
  54. package/types/cli/src/commands/generate.d.ts +11 -0
  55. package/types/cli/src/commands/migrateCreate.d.ts +2 -0
  56. package/types/cli/src/commands/queue.d.ts +2 -0
  57. package/types/cli/src/util.d.ts +2 -1
  58. package/types/core/src/authGate.d.ts +3 -3
  59. package/types/core/src/devAdmin.d.ts +40 -0
  60. package/types/core/src/index.d.ts +2 -1
  61. package/types/core/src/middleware.d.ts +1 -0
  62. package/types/core/src/optionalPackage.d.ts +2 -2
  63. package/types/core/src/request.d.ts +5 -1
  64. package/types/core/src/session.d.ts +25 -0
  65. package/types/core/src/slashTrim.d.ts +6 -0
  66. package/types/frond/src/engine.d.ts +11 -0
  67. package/types/frond/src/index.d.ts +1 -1
  68. package/types/orm/src/adapters/postgres.d.ts +6 -0
  69. package/types/orm/src/realtime/index.d.ts +1 -0
  70. package/types/orm/src/realtime/s3Client.d.ts +48 -0
  71. package/types/orm/src/realtime/storage.d.ts +9 -7
@@ -136,6 +136,11 @@ export class PostgresAdapter implements DatabaseAdapter {
136
136
  this.client = typeof this.config === "string"
137
137
  ? new Client({ connectionString: this.config, ...timeoutOption })
138
138
  : new Client({ ...this.config, ...timeoutOption });
139
+ // pg emits an async 'error' event when the server drops the link
140
+ // (failover, idle reap, pg_terminate_backend). With no listener Node
141
+ // throws it as an uncaught exception and crashes the process, so absorb
142
+ // it and mark the link dead - the next statement rebuilds it (#236/#242).
143
+ (this.client as unknown as NodeJS.EventEmitter).on("error", () => { this.connectionIsDead = true; });
139
144
  return this.client!.connect();
140
145
  },
141
146
  budgetMs,
@@ -158,6 +163,59 @@ export class PostgresAdapter implements DatabaseAdapter {
158
163
  }
159
164
  }
160
165
 
166
+ // ── Reconnect after a dropped link (parity with the Python master, #236/#242) ──
167
+ // pg's Client does not reconnect itself: once the server drops the link it must
168
+ // be rebuilt. A statement that hits a dropped link reconnects and retries once
169
+ // when nothing uncommitted went down with it; inside an explicit transaction the
170
+ // error surfaces. A reconnect that itself fails leaves the link dead (not null-
171
+ // guarded away), so the NEXT statement retries and recovers once a server returns.
172
+ private connectionIsDead = false;
173
+
174
+ private isConnectionError(e: unknown): boolean {
175
+ const msg = e instanceof Error ? e.message : String(e);
176
+ return /connection terminated|terminating connection|server closed the connection|encountered a connection error|connection closed|not queryable|ECONNRESET|EPIPE|socket hang up/i.test(msg);
177
+ }
178
+
179
+ private async reconnect(): Promise<void> {
180
+ // end() on a dropped socket can HANG, so fire-and-forget it (the same
181
+ // pattern connect() uses for its own timeout cleanup) rather than await it.
182
+ void Promise.resolve(this.client?.end()).catch(() => { /* already gone */ });
183
+ this.client = null;
184
+ this.connectionIsDead = false;
185
+ await this.connect(); // rebuilds this.client from the stored config
186
+ }
187
+
188
+ private async ensureLiveConnection(): Promise<void> {
189
+ if (!this._inTransaction && (this.client === null || this.connectionIsDead)) {
190
+ await this.reconnect();
191
+ }
192
+ }
193
+
194
+ private async runQuery(sql: string, params?: unknown[]): Promise<import("pg").QueryResult> {
195
+ await this.ensureLiveConnection();
196
+ this.ensureConnected();
197
+ try {
198
+ return await this.client!.query(sql, params);
199
+ } catch (e) {
200
+ if (!this.isConnectionError(e)) throw e; // a genuine SQL error
201
+ this.connectionIsDead = true; // a later statement rebuilds the link
202
+ if (this._inTransaction) throw e; // the caller owns the open transaction
203
+ await this.reconnect(); // nothing uncommitted: heal and retry once
204
+ return await this.client!.query(sql, params);
205
+ }
206
+ }
207
+
208
+ // Transaction control (BEGIN/COMMIT/ROLLBACK) runs RAW - no reconnect, no
209
+ // pre-heal. A failed BEGIN/COMMIT/ROLLBACK must surface so the connection-pool
210
+ // layer can discard the connection and restore capacity; reconnecting or
211
+ // retrying here would mask that failure (databasePoolIsolation contract).
212
+ // Dropped-link recovery stays on the DATA path (runQuery): the next data
213
+ // statement heals the link.
214
+ private async rawQuery(sql: string): Promise<void> {
215
+ this.ensureConnected();
216
+ await this.client!.query(sql);
217
+ }
218
+
161
219
  /** Convert ? placeholders to $1, $2, ... for pg. */
162
220
  /** Ensure bytea columns are Buffer (already the case with pg). No-op guard. */
163
221
  private decodeBlobs<T>(row: T): T {
@@ -212,7 +270,6 @@ export class PostgresAdapter implements DatabaseAdapter {
212
270
  }
213
271
 
214
272
  execute(sql: string, params?: unknown[]): unknown {
215
- this.ensureConnected();
216
273
  const convertedSql = this.convertPlaceholders(sql);
217
274
  // pg client methods are async — we store a promise-based wrapper
218
275
  // Since the interface is sync, we provide executeAsync for real usage
@@ -255,9 +312,8 @@ export class PostgresAdapter implements DatabaseAdapter {
255
312
 
256
313
  /** Async execute for real usage. */
257
314
  async executeAsync(sql: string, params?: unknown[]): Promise<unknown> {
258
- this.ensureConnected();
259
315
  const convertedSql = this.bindable(sql, params);
260
- const result = await this.client!.query(convertedSql, params);
316
+ const result = await this.runQuery(convertedSql, params);
261
317
  if (result.rows?.[0]?.id !== undefined) {
262
318
  this._lastInsertId = this.normalizeId(result.rows[0].id);
263
319
  }
@@ -270,9 +326,8 @@ export class PostgresAdapter implements DatabaseAdapter {
270
326
 
271
327
  /** Async query for real usage. */
272
328
  async queryAsync<T = Record<string, unknown>>(sql: string, params?: unknown[]): Promise<T[]> {
273
- this.ensureConnected();
274
329
  const convertedSql = this.bindable(sql, params);
275
- const result = await this.client!.query(convertedSql, params);
330
+ const result = await this.runQuery(convertedSql, params);
276
331
  return (result.rows as T[]).map(row => this.decodeBlobs(row));
277
332
  }
278
333
 
@@ -308,7 +363,6 @@ export class PostgresAdapter implements DatabaseAdapter {
308
363
  }
309
364
 
310
365
  async insertAsync(table: string, data: Record<string, unknown> | Record<string, unknown>[]): Promise<DatabaseResult> {
311
- this.ensureConnected();
312
366
  // A list of dicts is a batch insert — build one parameterised INSERT and run
313
367
  // it once per row via executeManyAsync (ONE connection, wrapped in a single
314
368
  // transaction). Database.insert / the docs advertise `data: object | object[]`;
@@ -331,7 +385,7 @@ export class PostgresAdapter implements DatabaseAdapter {
331
385
  const { sql, values } = buildInsertRow(POSTGRES_DIALECT, table, data, " RETURNING *");
332
386
 
333
387
  try {
334
- const result = await this.client!.query(sql, values);
388
+ const result = await this.runQuery(sql, values);
335
389
  const insertedRow = result.rows[0];
336
390
  const id = this.normalizeId(insertedRow?.id);
337
391
  if (id !== null) this._lastInsertId = id;
@@ -350,7 +404,6 @@ export class PostgresAdapter implements DatabaseAdapter {
350
404
  }
351
405
 
352
406
  async updateAsync(table: string, data: Record<string, unknown>, filter: Record<string, unknown> | string, params?: unknown[]): Promise<DatabaseResult> {
353
- this.ensureConnected();
354
407
  // The composer numbers the SET markers from $1 and continues the WHERE
355
408
  // markers past them; a raw string filter's `?` are rewritten to $N via
356
409
  // convertPlaceholders (identity would leave `?`, which pg rejects).
@@ -360,7 +413,7 @@ export class PostgresAdapter implements DatabaseAdapter {
360
413
  });
361
414
 
362
415
  try {
363
- const result = await this.client!.query(sql, values);
416
+ const result = await this.runQuery(sql, values);
364
417
  return { success: true, affectedRows: result.rowCount ?? 0 };
365
418
  } catch (e) {
366
419
  return { success: false, affectedRows: 0, error: (e as Error).message };
@@ -372,7 +425,6 @@ export class PostgresAdapter implements DatabaseAdapter {
372
425
  }
373
426
 
374
427
  async deleteAsync(table: string, filter: Record<string, unknown> | string, params?: unknown[]): Promise<DatabaseResult> {
375
- this.ensureConnected();
376
428
  // bindable() rewrites a raw fragment's `?` to $N only when params are bound
377
429
  // (truncate() passes "1 = 1" with none — no rewrite, no error). A hash filter
378
430
  // numbers its `$N` from 1.
@@ -382,7 +434,7 @@ export class PostgresAdapter implements DatabaseAdapter {
382
434
  });
383
435
 
384
436
  try {
385
- const result = await this.client!.query(sql, values);
437
+ const result = await this.runQuery(sql, values);
386
438
  return { success: true, affectedRows: result.rowCount ?? 0 };
387
439
  } catch (e) {
388
440
  return { success: false, affectedRows: 0, error: (e as Error).message };
@@ -394,7 +446,7 @@ export class PostgresAdapter implements DatabaseAdapter {
394
446
  }
395
447
 
396
448
  async startTransactionAsync(): Promise<void> {
397
- await this.executeAsync("BEGIN");
449
+ await this.rawQuery("BEGIN");
398
450
  // Mark the connection as inside an explicit transaction so executeManyAsync's
399
451
  // owns-guard (owns = !_inTransaction) joins THIS transaction instead of
400
452
  // opening its own inner BEGIN/COMMIT (which would commit this outer
@@ -408,10 +460,14 @@ export class PostgresAdapter implements DatabaseAdapter {
408
460
  }
409
461
 
410
462
  async commitAsync(): Promise<void> {
411
- await this.executeAsync("COMMIT");
412
- // Transaction closed — clear the flag so subsequent standalone batches own
413
- // their own transaction again (parity with Python master commit()).
414
- this._inTransaction = false;
463
+ // The transaction ends whether or not COMMIT succeeds, so clear the flag in
464
+ // finally - a COMMIT that fails on a dropped link would otherwise leave
465
+ // _inTransaction set and wedge every later reconnect (#244).
466
+ try {
467
+ await this.rawQuery("COMMIT");
468
+ } finally {
469
+ this._inTransaction = false;
470
+ }
415
471
  }
416
472
 
417
473
  rollback(): void {
@@ -419,9 +475,13 @@ export class PostgresAdapter implements DatabaseAdapter {
419
475
  }
420
476
 
421
477
  async rollbackAsync(): Promise<void> {
422
- await this.executeAsync("ROLLBACK");
423
- // Transaction closed — clear the flag (parity with Python master rollback()).
424
- this._inTransaction = false;
478
+ // Clear the flag even if ROLLBACK fails on a dropped link - the transaction
479
+ // is over either way, and leaving it set would wedge every later reconnect (#244).
480
+ try {
481
+ await this.rawQuery("ROLLBACK");
482
+ } finally {
483
+ this._inTransaction = false;
484
+ }
425
485
  }
426
486
 
427
487
  getTables(): string[] {
@@ -73,13 +73,13 @@ function renderModalForm(mode: string, columns: string[], pk: string, edit: bool
73
73
  value: "",
74
74
  placeholder: h(`Enter ${label.toLowerCase()}`),
75
75
  type: "text",
76
- required_attr: "",
76
+ required: false,
77
77
  input: true,
78
78
  };
79
79
  });
80
80
  return renderCrudTemplate("form", {
81
81
  wrap: true,
82
- form_id_attr: ` id="form-${mode}"`,
82
+ form_id: `form-${mode}`,
83
83
  action: "",
84
84
  form_method: "POST",
85
85
  method_override: null,
@@ -150,7 +150,7 @@ function fieldInputShape(field: FormFieldDef, base: Record<string, unknown>): Re
150
150
  case "text":
151
151
  return { ...base, textarea: true };
152
152
  case "boolean":
153
- return { ...base, checkbox: true, checked_attr: value ? " checked" : "" };
153
+ return { ...base, checkbox: true, checked: !!value };
154
154
  case "select":
155
155
  return { ...base, select: true, options_html: buildOptions(field.options, value) };
156
156
  case "date":
@@ -174,7 +174,7 @@ function buildCustomField(field: FormFieldDef): Record<string, unknown> {
174
174
  label: h(String(label)),
175
175
  value: h(field.value ?? ""),
176
176
  placeholder: "",
177
- required_attr: field.required ? " required" : "",
177
+ required: !!field.required,
178
178
  };
179
179
  return fieldInputShape(field, base);
180
180
  }
@@ -190,7 +190,7 @@ export function generateForm(
190
190
  const verb = String(options.method ?? "POST").toUpperCase();
191
191
  return renderCrudTemplate("form", {
192
192
  wrap: true,
193
- form_id_attr: "",
193
+ form_id: "",
194
194
  action: h(options.action ?? "/"),
195
195
  form_method: h(verb),
196
196
  method_override: ["PUT", "PATCH", "DELETE"].includes(verb) ? verb : null,
@@ -165,7 +165,7 @@ export function tableData(opts: TableDataOpts): Record<string, unknown> {
165
165
  readonly: !opts.editable,
166
166
  inline_script: opts.inlineScript,
167
167
  table_name: h(opts.tableName),
168
- table_id_attr: opts.tableId ? ` id="${h(opts.tableId)}"` : "",
168
+ table_id: opts.tableId ? String(opts.tableId) : "",
169
169
  };
170
170
  }
171
171
 
@@ -27,7 +27,7 @@ import { quoteIdentifierAnsi, assertColumnNames } from "./adapters/sqlDialect.js
27
27
  */
28
28
  export function stripTrailingSemicolons(sql: string): string {
29
29
  if (!sql) return sql;
30
- let stripped = sql.replace(/\s+$/, "");
30
+ let stripped = sql.trimEnd();
31
31
  while (stripped.endsWith(";")) {
32
32
  stripped = stripped.slice(0, -1).replace(/\s+$/, "");
33
33
  }
@@ -1800,6 +1800,16 @@ export async function createAdapterFromUrl(url: string, username?: string, passw
1800
1800
  async function buildAdapterFromUrl(url: string, username?: string, password?: string): Promise<DatabaseAdapter> {
1801
1801
  const parsed = parseDatabaseUrl(url, username, password);
1802
1802
 
1803
+ // The four TCP engines (postgres/mysql/mssql/firebird) take the identical
1804
+ // connection shape from the parsed URL; build it once instead of per case.
1805
+ const serverConfig = {
1806
+ host: parsed.host ?? undefined,
1807
+ port: parsed.port ?? undefined,
1808
+ user: parsed.username ?? undefined,
1809
+ password: parsed.password ?? undefined,
1810
+ database: parsed.database || undefined,
1811
+ };
1812
+
1803
1813
  switch (parsed.engine) {
1804
1814
  case "sqlite": {
1805
1815
  const { SQLiteAdapter } = await import("./adapters/sqlite.js");
@@ -1807,49 +1817,25 @@ async function buildAdapterFromUrl(url: string, username?: string, password?: st
1807
1817
  }
1808
1818
  case "postgres": {
1809
1819
  const { PostgresAdapter } = await import("./adapters/postgres.js");
1810
- const adapter = new PostgresAdapter({
1811
- host: parsed.host ?? undefined,
1812
- port: parsed.port ?? undefined,
1813
- user: parsed.username ?? undefined,
1814
- password: parsed.password ?? undefined,
1815
- database: parsed.database || undefined,
1816
- });
1820
+ const adapter = new PostgresAdapter(serverConfig);
1817
1821
  await adapter.connect();
1818
1822
  return adapter;
1819
1823
  }
1820
1824
  case "mysql": {
1821
1825
  const { MysqlAdapter } = await import("./adapters/mysql.js");
1822
- const adapter = new MysqlAdapter({
1823
- host: parsed.host ?? undefined,
1824
- port: parsed.port ?? undefined,
1825
- user: parsed.username ?? undefined,
1826
- password: parsed.password ?? undefined,
1827
- database: parsed.database || undefined,
1828
- });
1826
+ const adapter = new MysqlAdapter(serverConfig);
1829
1827
  await adapter.connect();
1830
1828
  return adapter;
1831
1829
  }
1832
1830
  case "mssql": {
1833
1831
  const { MssqlAdapter } = await import("./adapters/mssql.js");
1834
- const adapter = new MssqlAdapter({
1835
- host: parsed.host ?? undefined,
1836
- port: parsed.port ?? undefined,
1837
- user: parsed.username ?? undefined,
1838
- password: parsed.password ?? undefined,
1839
- database: parsed.database || undefined,
1840
- });
1832
+ const adapter = new MssqlAdapter(serverConfig);
1841
1833
  await adapter.connect();
1842
1834
  return adapter;
1843
1835
  }
1844
1836
  case "firebird": {
1845
1837
  const { FirebirdAdapter } = await import("./adapters/firebird.js");
1846
- const adapter = new FirebirdAdapter({
1847
- host: parsed.host ?? undefined,
1848
- port: parsed.port ?? undefined,
1849
- user: parsed.username ?? undefined,
1850
- password: parsed.password ?? undefined,
1851
- database: parsed.database || undefined,
1852
- });
1838
+ const adapter = new FirebirdAdapter(serverConfig);
1853
1839
  await adapter.connect();
1854
1840
  return adapter;
1855
1841
  }
@@ -8,6 +8,16 @@ file, You can obtain one at https://mozilla.org/MPL/2.0/.
8
8
 
9
9
  import type { DatabaseAdapter, ColumnInfo } from "./types.js";
10
10
 
11
+ // Strip the "(args)" from a column type ("VARCHAR(255)" -> "VARCHAR",
12
+ // "INT(11) UNSIGNED" -> "INT UNSIGNED"). ReDoS-safe: indexOf/slice, not the old
13
+ // /\([^)]*\)/ which backtracks O(n^2) across many '(' (js/polynomial-redos).
14
+ function stripTypeArgs(colType: string): string {
15
+ const open = colType.indexOf("(");
16
+ if (open < 0) return colType;
17
+ const close = colType.indexOf(")", open);
18
+ return close < 0 ? colType : colType.slice(0, open) + colType.slice(close + 1);
19
+ }
20
+
11
21
  /** Column metadata returned by columnInfo(). */
12
22
  export interface ColumnInfoResult {
13
23
  name: string;
@@ -261,7 +271,7 @@ export class DatabaseResult implements Iterable<Record<string, unknown>> {
261
271
  const [size, decimals] = this._parseTypeSize(colType);
262
272
  return {
263
273
  name: col.name,
264
- type: colType.replace(/\(.*\)/, ""),
274
+ type: stripTypeArgs(colType),
265
275
  size,
266
276
  decimals,
267
277
  nullable: col.nullable ?? true,
@@ -155,6 +155,21 @@ function iso(d: Date): string {
155
155
  return d.toISOString();
156
156
  }
157
157
 
158
+ /**
159
+ * Write `key` as an own data property. A plain `obj[key] = value` with the key
160
+ * `__proto__` re-points the object's prototype instead of storing a field, and a
161
+ * path walked that way reaches Object.prototype itself. MongoDB stores
162
+ * `__proto__` as an ordinary field name, so the fallback does the same.
163
+ */
164
+ function setOwn(obj: Record<string, unknown>, key: string, value: unknown): void {
165
+ Object.defineProperty(obj, key, { value, writable: true, enumerable: true, configurable: true });
166
+ }
167
+
168
+ /** The own property `key`, never one inherited through the prototype chain. */
169
+ function getOwn(obj: Record<string, unknown>, key: string): unknown {
170
+ return Object.hasOwn(obj, key) ? obj[key] : undefined;
171
+ }
172
+
158
173
  /** Value -> JSON-serialisable, sortable scalar form (for storage/queries). */
159
174
  export function encodeValue(value: unknown): unknown {
160
175
  if (value instanceof ObjectId) return value.toString();
@@ -163,7 +178,7 @@ export function encodeValue(value: unknown): unknown {
163
178
  if (value !== null && typeof value === "object") {
164
179
  const out: Record<string, unknown> = {};
165
180
  for (const [k, v] of Object.entries(value as Record<string, unknown>)) {
166
- out[k] = encodeValue(v);
181
+ setOwn(out, k, encodeValue(v));
167
182
  }
168
183
  return out;
169
184
  }
@@ -184,7 +199,7 @@ export function decodeValue(value: unknown): unknown {
184
199
  if (value !== null && typeof value === "object") {
185
200
  const out: Record<string, unknown> = {};
186
201
  for (const [k, v] of Object.entries(value as Record<string, unknown>)) {
187
- out[k] = decodeValue(v);
202
+ setOwn(out, k, decodeValue(v));
188
203
  }
189
204
  return out;
190
205
  }
@@ -417,14 +432,14 @@ function project(doc: Record<string, unknown>, projection?: Record<string, unkno
417
432
  const exclude = new Set(Object.entries(projection).filter(([, v]) => !v).map(([k]) => k));
418
433
  if (include.size > 0) {
419
434
  const out: Record<string, unknown> = {};
420
- for (const k of include) if (k in doc) out[k] = doc[k];
435
+ for (const k of include) if (Object.hasOwn(doc, k)) setOwn(out, k, doc[k]);
421
436
  const idVal = projection._id;
422
437
  if ((idVal === undefined || idVal) && "_id" in doc) out._id = doc._id;
423
438
  return out;
424
439
  }
425
440
  // exclusion projection
426
441
  const out: Record<string, unknown> = {};
427
- for (const [k, v] of Object.entries(doc)) if (!exclude.has(k)) out[k] = v;
442
+ for (const [k, v] of Object.entries(doc)) if (!exclude.has(k)) setOwn(out, k, v);
428
443
  return out;
429
444
  }
430
445
 
@@ -432,19 +447,20 @@ function setPath(doc: Record<string, unknown>, dotted: string, value: unknown):
432
447
  const parts = dotted.split(".");
433
448
  let node = doc;
434
449
  for (const p of parts.slice(0, -1)) {
435
- if (node[p] === undefined || node[p] === null || typeof node[p] !== "object") {
436
- node[p] = {};
450
+ const child = getOwn(node, p);
451
+ if (child === undefined || child === null || typeof child !== "object") {
452
+ setOwn(node, p, {});
437
453
  }
438
454
  node = node[p] as Record<string, unknown>;
439
455
  }
440
- node[parts[parts.length - 1]] = value;
456
+ setOwn(node, parts[parts.length - 1], value);
441
457
  }
442
458
 
443
459
  function unsetPath(doc: Record<string, unknown>, dotted: string): void {
444
460
  const parts = dotted.split(".");
445
461
  let node: Record<string, unknown> | undefined = doc;
446
462
  for (const p of parts.slice(0, -1)) {
447
- const next = node[p];
463
+ const next = getOwn(node, p);
448
464
  if (next === null || typeof next !== "object") return;
449
465
  node = next as Record<string, unknown>;
450
466
  }
@@ -14,6 +14,7 @@ export {
14
14
  storageKey,
15
15
  type StorageBackend,
16
16
  } from "./storage.js";
17
+ export { S3Client, S3Error, S3ConfigError, uriEncode } from "./s3Client.js";
17
18
  export { default as Workspace } from "./models/workspace.js";
18
19
  export { default as Channel } from "./models/channel.js";
19
20
  export { default as ChannelMember } from "./models/channelMember.js";
@@ -7,6 +7,7 @@ file, You can obtain one at https://mozilla.org/MPL/2.0/.
7
7
  */
8
8
 
9
9
  import { createHmac } from "node:crypto";
10
+ import { trimSlashes } from "../../../core/src/slashTrim.js";
10
11
  import {
11
12
  Router,
12
13
  HTTP_OK,
@@ -87,7 +88,7 @@ let _authorize: RealtimeOptions["authorize"] | undefined;
87
88
  */
88
89
  export async function realtime(options: RealtimeOptions = {}): Promise<Record<string, string>> {
89
90
  const features = options.features ?? ["calls"];
90
- const raw = (options.prefix ?? "").replace(/^\/+|\/+$/g, "");
91
+ const raw = trimSlashes(options.prefix ?? "");
91
92
  const p = raw ? `/${raw}` : "";
92
93
  _authorize = options.authorize;
93
94