@aouda/client 0.1.6 → 0.1.8

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.
@@ -421,7 +421,7 @@ var import_node_url = require("url");
421
421
  // package.json
422
422
  var package_default = {
423
423
  name: "@aouda/client",
424
- version: "0.1.6",
424
+ version: "0.1.8",
425
425
  description: "Official TypeScript/JavaScript client library for Aouda",
426
426
  type: "module",
427
427
  main: "./dist/index.cjs",
@@ -1425,7 +1425,8 @@ var BulkLoadCoordinator = class {
1425
1425
  pkUniquenessOverride: options.pkUniquenessOverride,
1426
1426
  replicationMode: options.replicationMode,
1427
1427
  forceSingleNodeReplicationBypass: options.forceSingleNodeReplicationBypass,
1428
- postLoadMqBehavior: options.postLoadMqBehavior
1428
+ postLoadMqBehavior: options.postLoadMqBehavior,
1429
+ ...options.identityInsert === true ? { identityInsert: true } : {}
1429
1430
  }
1430
1431
  };
1431
1432
  const beginResp = await this.transport.post(
@@ -3435,6 +3436,8 @@ var TableQuery = class _TableQuery {
3435
3436
  * a Promise. It does not use query builder state (where, orderBy, etc.).
3436
3437
  *
3437
3438
  * @param row - The row data to insert. Keys are column names.
3439
+ * @param row - The row object to insert. Keys are column names.
3440
+ * @param options - Optional insert options (e.g. `identityInsert`).
3438
3441
  * @returns The insert result with row count, execution time, and optional generated values.
3439
3442
  * @throws Error if `row` is null or undefined.
3440
3443
  *
@@ -3445,9 +3448,12 @@ var TableQuery = class _TableQuery {
3445
3448
  *
3446
3449
  * console.log(result.rowsInserted); // 1
3447
3450
  * console.log(result.generatedValues); // { "0": { id: 42 } }
3451
+ *
3452
+ * // Identity-insert (Bond isAutoIncrementDisabled: true): store explicit IDs including 0
3453
+ * await client.table('orders').insert({ id: 1000, status: 'seeded' }, { identityInsert: true });
3448
3454
  * ```
3449
3455
  */
3450
- async insert(row) {
3456
+ async insert(row, options) {
3451
3457
  if (row == null) {
3452
3458
  throw new Error("insert() requires a non-null row object");
3453
3459
  }
@@ -3457,6 +3463,9 @@ var TableQuery = class _TableQuery {
3457
3463
  database: this.database,
3458
3464
  rows: [row]
3459
3465
  };
3466
+ if (options?.identityInsert === true) {
3467
+ body.identityInsert = true;
3468
+ }
3460
3469
  const response = await this.transport.post(path4, body);
3461
3470
  const result = {
3462
3471
  rowsInserted: response.rowsInserted,
@@ -3474,6 +3483,7 @@ var TableQuery = class _TableQuery {
3474
3483
  * a Promise. It does not use query builder state (where, orderBy, etc.).
3475
3484
  *
3476
3485
  * @param rows - Array of row objects to insert. Must contain at least one row.
3486
+ * @param options - Optional insert options (e.g. `identityInsert`).
3477
3487
  * @returns The insert result with total row count, execution time, and optional generated values.
3478
3488
  * @throws Error if `rows` is empty.
3479
3489
  *
@@ -3486,9 +3496,14 @@ var TableQuery = class _TableQuery {
3486
3496
  * ]);
3487
3497
  *
3488
3498
  * console.log(result.rowsInserted); // 2
3499
+ *
3500
+ * await client.table('orders').insertMany(
3501
+ * [{ id: 10 }, { id: 20 }],
3502
+ * { identityInsert: true },
3503
+ * );
3489
3504
  * ```
3490
3505
  */
3491
- async insertMany(rows) {
3506
+ async insertMany(rows, options) {
3492
3507
  if (!Array.isArray(rows) || rows.length === 0) {
3493
3508
  throw new Error("insertMany() requires a non-empty array of rows");
3494
3509
  }
@@ -3498,6 +3513,9 @@ var TableQuery = class _TableQuery {
3498
3513
  database: this.database,
3499
3514
  rows
3500
3515
  };
3516
+ if (options?.identityInsert === true) {
3517
+ body.identityInsert = true;
3518
+ }
3501
3519
  const response = await this.transport.post(path4, body);
3502
3520
  const result = {
3503
3521
  rowsInserted: response.rowsInserted,
@@ -3935,23 +3953,68 @@ var TablesApi = class {
3935
3953
  );
3936
3954
  }
3937
3955
  /**
3938
- * Renames a column.
3956
+ * Alters a column (type, nullable, encoder, autoIncrement, references, and/or rename).
3957
+ * PATCH /api/databases/{db}/tables/{t}/columns/{c}.
3958
+ * Omit a property to leave it unchanged. For `references`, omit unchanged; `""` or `null` clears.
3939
3959
  * @param tableName - Table name.
3940
3960
  * @param columnName - Current column name.
3941
- * @param body - Request body (database, newName).
3942
- * @returns 200 response body (column detail).
3943
- * @throws AoudaNotFoundError if table or column does not exist; AoudaApiError for WRITE_NOT_ALLOWED, etc.
3961
+ * @param body - Fields to change. `database` is injected from the client scope when omitted.
3962
+ * @returns Updated column detail.
3944
3963
  */
3945
- async renameColumn(tableName, columnName, body) {
3964
+ async alterColumn(tableName, columnName, body) {
3946
3965
  validateNonEmptyString(tableName, "Table name");
3947
3966
  validateNonEmptyString(columnName, "Column name");
3948
- validateNonEmptyString(body.newName, "New column name");
3967
+ const hasField = body.newName !== void 0 || body.type !== void 0 || body.nullable !== void 0 || body.encoder !== void 0 || body.autoIncrement !== void 0 || body.references !== void 0;
3968
+ if (!hasField) {
3969
+ throw new Error(
3970
+ "AlterColumnRequest must set at least one of: newName, type, nullable, encoder, autoIncrement, references"
3971
+ );
3972
+ }
3949
3973
  const prefix = databasePath2(this.database);
3950
3974
  const encodedTable = encodeURIComponent(tableName);
3951
3975
  const encodedColumn = encodeURIComponent(columnName);
3976
+ const requestBody = {
3977
+ database: this.database,
3978
+ ...body
3979
+ };
3952
3980
  return this.transport.patch(
3953
3981
  `${prefix}/tables/${encodedTable}/columns/${encodedColumn}`,
3954
- body
3982
+ requestBody
3983
+ );
3984
+ }
3985
+ /**
3986
+ * Renames a column (convenience wrapper over {@link alterColumn}).
3987
+ * @param tableName - Table name.
3988
+ * @param columnName - Current column name.
3989
+ * @param body - Request body with newName (database optional; injected when omitted).
3990
+ * @returns 200 response body (column detail).
3991
+ * @throws AoudaNotFoundError if table or column does not exist; AoudaApiError for WRITE_NOT_ALLOWED, etc.
3992
+ */
3993
+ async renameColumn(tableName, columnName, body) {
3994
+ validateNonEmptyString(body.newName ?? "", "New column name");
3995
+ return this.alterColumn(tableName, columnName, { newName: body.newName });
3996
+ }
3997
+ /**
3998
+ * Reorders columns in a table.
3999
+ * PUT /api/databases/{db}/tables/{t}/columns:order (204 No Content).
4000
+ * @param tableName - Table name.
4001
+ * @param columnsOrBody - Ordered column names, or a request body with `columns`.
4002
+ */
4003
+ async reorderColumns(tableName, columnsOrBody) {
4004
+ validateNonEmptyString(tableName, "Table name");
4005
+ const columns = Array.isArray(columnsOrBody) ? columnsOrBody : columnsOrBody.columns;
4006
+ if (!columns?.length) {
4007
+ throw new Error("columns array is required and must be non-empty");
4008
+ }
4009
+ const prefix = databasePath2(this.database);
4010
+ const encodedTable = encodeURIComponent(tableName);
4011
+ const requestBody = {
4012
+ database: this.database,
4013
+ columns
4014
+ };
4015
+ await this.transport.put(
4016
+ `${prefix}/tables/${encodedTable}/columns:order`,
4017
+ requestBody
3955
4018
  );
3956
4019
  }
3957
4020
  /**
@@ -4191,6 +4254,37 @@ var BranchesApi = class {
4191
4254
  }
4192
4255
  };
4193
4256
 
4257
+ // src/jobs.ts
4258
+ function validateNonEmptyString2(value, name) {
4259
+ if (typeof value !== "string" || value.trim().length === 0) {
4260
+ throw new Error(`${name} must be a non-empty string`);
4261
+ }
4262
+ }
4263
+ var JobsApi = class {
4264
+ constructor(transport, database) {
4265
+ this.transport = transport;
4266
+ this.database = database;
4267
+ }
4268
+ get prefix() {
4269
+ return `${databasePath2(this.database)}/jobs`;
4270
+ }
4271
+ /**
4272
+ * Lists jobs whose params target this database.
4273
+ */
4274
+ async list() {
4275
+ return this.transport.get(this.prefix);
4276
+ }
4277
+ /**
4278
+ * Gets a single job by id when it belongs to this database.
4279
+ * @param jobId - Job GUID string.
4280
+ */
4281
+ async get(jobId) {
4282
+ validateNonEmptyString2(jobId, "Job id");
4283
+ const encoded = encodeURIComponent(jobId);
4284
+ return this.transport.get(`${this.prefix}/${encoded}`);
4285
+ }
4286
+ };
4287
+
4194
4288
  // src/admin/server.ts
4195
4289
  var ServerAdminApi = class {
4196
4290
  constructor(transport) {
@@ -4700,6 +4794,35 @@ var NotificationsAdminApi = class {
4700
4794
  request
4701
4795
  );
4702
4796
  }
4797
+ /**
4798
+ * Get recent captured auth notifications (newest first).
4799
+ * GET /admin/notifications/outbox?channel=&limit=
4800
+ */
4801
+ async getOutbox(options) {
4802
+ return this.transport.get(
4803
+ this.buildOutboxPath(options)
4804
+ );
4805
+ }
4806
+ /**
4807
+ * Clear the in-memory notification outbox.
4808
+ * DELETE /admin/notifications/outbox
4809
+ */
4810
+ async clearOutbox() {
4811
+ return this.transport.delete(
4812
+ `${BASE_PATH7}/outbox`
4813
+ );
4814
+ }
4815
+ buildOutboxPath(options) {
4816
+ const params = new URLSearchParams();
4817
+ if (options?.channel !== void 0 && options.channel.trim().length > 0) {
4818
+ params.set("channel", options.channel);
4819
+ }
4820
+ if (options?.limit !== void 0) {
4821
+ params.set("limit", String(options.limit));
4822
+ }
4823
+ const query = params.toString();
4824
+ return query.length > 0 ? `${BASE_PATH7}/outbox?${query}` : `${BASE_PATH7}/outbox`;
4825
+ }
4703
4826
  };
4704
4827
 
4705
4828
  // src/admin/index.ts
@@ -5439,7 +5562,7 @@ var DEFAULT_TIMEOUT_MS = 3e4;
5439
5562
  function normalizeBaseUrl(url) {
5440
5563
  return url.replace(/\/+$/, "");
5441
5564
  }
5442
- function validateNonEmptyString2(value, name) {
5565
+ function validateNonEmptyString3(value, name) {
5443
5566
  if (typeof value !== "string" || value.trim().length === 0) {
5444
5567
  throw new Error(`${name} must be a non-empty string`);
5445
5568
  }
@@ -5454,8 +5577,8 @@ var AoudaClient = class {
5454
5577
  constructor(options) {
5455
5578
  this.connected = false;
5456
5579
  this._wsTransport = null;
5457
- validateNonEmptyString2(options.serverUrl, "serverUrl");
5458
- validateNonEmptyString2(options.database, "database");
5580
+ validateNonEmptyString3(options.serverUrl, "serverUrl");
5581
+ validateNonEmptyString3(options.database, "database");
5459
5582
  this.baseUrl = normalizeBaseUrl(options.serverUrl);
5460
5583
  this.timeout = options.timeout ?? DEFAULT_TIMEOUT_MS;
5461
5584
  this.database = options.database.trim();
@@ -5537,6 +5660,7 @@ var AoudaClient = class {
5537
5660
  this._authHandler = null;
5538
5661
  }
5539
5662
  this._tables = new TablesApi(this.transport, this.database);
5663
+ this._jobs = new JobsApi(this.transport, this.database);
5540
5664
  this._databases = new DatabasesApi(this.transport);
5541
5665
  this._schema = new SchemaApi(this.transport, this.database);
5542
5666
  this._branches = new BranchesApi(this.transport, this.database);
@@ -5630,7 +5754,7 @@ var AoudaClient = class {
5630
5754
  * ```
5631
5755
  */
5632
5756
  table(name) {
5633
- validateNonEmptyString2(name, "Table name");
5757
+ validateNonEmptyString3(name, "Table name");
5634
5758
  return new TableQuery(
5635
5759
  this.transport,
5636
5760
  name,
@@ -5646,6 +5770,13 @@ var AoudaClient = class {
5646
5770
  get tables() {
5647
5771
  return this._tables;
5648
5772
  }
5773
+ /**
5774
+ * Access pending/background jobs for the current database (e.g. ColumnRewrite).
5775
+ * @returns The jobs API.
5776
+ */
5777
+ get jobs() {
5778
+ return this._jobs;
5779
+ }
5649
5780
  /**
5650
5781
  * Access server-level database operations (list, create, get, drop).
5651
5782
  * @returns The databases API.
@@ -5742,7 +5873,7 @@ var AoudaClient = class {
5742
5873
  * ```
5743
5874
  */
5744
5875
  bulkLoad(tableName, rows, options) {
5745
- validateNonEmptyString2(tableName, "tableName");
5876
+ validateNonEmptyString3(tableName, "tableName");
5746
5877
  return new BulkLoadCoordinator(this.transport, this.database).run(
5747
5878
  [tableName],
5748
5879
  rows,