@lossless.org/client 1.4.0 → 1.5.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.
Files changed (51) hide show
  1. package/dist_ts/00_commitinfo_data.js +1 -1
  2. package/dist_ts/core/interfaces.d.ts +7 -0
  3. package/dist_ts/index.d.ts +1 -1
  4. package/dist_ts/nosqldb/classes.collection.js +2 -3
  5. package/dist_ts/nosqldb/classes.connection.d.ts +8 -3
  6. package/dist_ts/nosqldb/classes.connection.js +11 -6
  7. package/dist_ts/nosqldb/classes.db.d.ts +13 -0
  8. package/dist_ts/nosqldb/classes.db.js +28 -1
  9. package/dist_ts/nosqldb/classes.doc.js +10 -2
  10. package/dist_ts/nosqldb/classes.easystore.d.ts +13 -0
  11. package/dist_ts/nosqldb/classes.easystore.js +16 -1
  12. package/dist_ts/nosqldb/engineidentity.d.ts +31 -0
  13. package/dist_ts/nosqldb/engineidentity.js +105 -0
  14. package/dist_ts/nosqldb/index.d.ts +2 -0
  15. package/dist_ts/nosqldb/index.js +1 -1
  16. package/dist_ts/nosqldb/lineage.js +3 -1
  17. package/dist_ts/objectstorage/classes.connection.js +2 -2
  18. package/dist_ts/sqldb/classes.clickhouseconnection.js +3 -2
  19. package/dist_ts/sqldb/classes.sqlconnection.d.ts +7 -5
  20. package/dist_ts/sqldb/classes.sqlconnection.js +3 -3
  21. package/dist_ts/sqldb/interfaces.d.ts +5 -0
  22. package/dist_ts/sqldb/interfaces.js +1 -1
  23. package/dist_ts/sqldb/internal.lease.d.ts +15 -0
  24. package/dist_ts/sqldb/internal.lease.js +2 -0
  25. package/dist_ts/sqldb/internal.sqlpool.d.ts +2 -1
  26. package/dist_ts/sqldb/internal.sqlpool.js +1 -1
  27. package/dist_ts/sqldb/plugins.d.ts +4 -0
  28. package/dist_ts/sqldb/plugins.js +7 -0
  29. package/dist_ts/sqldb/plugins.mariadb.d.ts +2 -3
  30. package/dist_ts/sqldb/plugins.mariadb.js +4 -4
  31. package/package.json +3 -3
  32. package/readme.md +24 -19
  33. package/ts/00_commitinfo_data.ts +1 -1
  34. package/ts/core/interfaces.ts +7 -0
  35. package/ts/index.ts +1 -1
  36. package/ts/nosqldb/classes.collection.ts +1 -2
  37. package/ts/nosqldb/classes.connection.ts +19 -7
  38. package/ts/nosqldb/classes.db.ts +38 -0
  39. package/ts/nosqldb/classes.doc.ts +14 -1
  40. package/ts/nosqldb/classes.easystore.ts +16 -0
  41. package/ts/nosqldb/engineidentity.ts +153 -0
  42. package/ts/nosqldb/index.ts +11 -0
  43. package/ts/nosqldb/lineage.ts +2 -0
  44. package/ts/objectstorage/classes.connection.ts +1 -1
  45. package/ts/sqldb/classes.clickhouseconnection.ts +2 -1
  46. package/ts/sqldb/classes.sqlconnection.ts +14 -11
  47. package/ts/sqldb/interfaces.ts +5 -0
  48. package/ts/sqldb/internal.lease.ts +16 -0
  49. package/ts/sqldb/internal.sqlpool.ts +2 -1
  50. package/ts/sqldb/plugins.mariadb.ts +3 -3
  51. package/ts/sqldb/plugins.ts +7 -0
@@ -11,7 +11,8 @@ export class ClickHouseConnection {
11
11
  public readonly backend = 'clickhouse' as const;
12
12
  public readonly metrics: SmartClickHouseDb;
13
13
  public readonly capabilities: ICapabilities = Object.freeze({ backend: 'clickhouse',
14
- transactions: 'unsupported', changeStreams: 'unsupported', objectMetrics: 'unsupported', diskResidentScans: 'available' });
14
+ transactions: 'unsupported', changeStreams: 'unsupported', compositeGrouping: 'unsupported',
15
+ objectMetrics: 'unsupported', diskResidentScans: 'available' });
15
16
  private client?: plugins.clickhouse.ClickHouseClient;
16
17
  private readonly operations = new Map<Operation, () => void>();
17
18
  private readonly tasks = new Set<Promise<unknown>>();
@@ -1,13 +1,15 @@
1
- import * as plugins from './plugins.mariadb.js';
1
+ import * as plugins from './plugins.js';
2
2
  import { SqlTable } from './classes.sqltable.js';
3
- import { SqlPool, type SqlPooledConnection } from './internal.sqlpool.js';
3
+ import { SqlPool } from './internal.sqlpool.js';
4
+ import type { ISqlLeaseConnection } from './internal.lease.js';
4
5
  import { Operation } from '../core/classes.operation.js';
5
6
  import { LosslessClientError, backendError } from '../core/classes.error.js';
6
7
  import type { ICapabilities, IOperationOptions, IReadiness } from '../core/interfaces.js';
7
8
  import { quoteIdentifier, resultLimits, valueBytes } from './interfaces.js';
8
- import type { IInsertOptions, IQueryOptions, ISqlMutationResult, ISqlStatement, TSqlValue } from './interfaces.js';
9
+ import type { IInsertOptions, IQueryOptions, ISqlMutationResult, ISqlStatement, ISqlWriteAcknowledgement,
10
+ TSqlValue } from './interfaces.js';
9
11
 
10
- /** Options of a MariaDB-protocol connection. `tls` is the driver's own TLS configuration. */
12
+ /** Options of a MariaDB-protocol connection. `tls` is this client's own TLS configuration, passed to the driver. */
11
13
  export interface ISqlConnectionOptions {
12
14
  backend: 'sqldb' | 'mariadb';
13
15
  host: string;
@@ -17,11 +19,11 @@ export interface ISqlConnectionOptions {
17
19
  database: string;
18
20
  connectionLimit?: number;
19
21
  timeoutMs?: number;
20
- tls?: plugins.mariadb.ConnectionConfig['ssl'];
22
+ tls?: boolean | (plugins.tls.SecureContextOptions & { rejectUnauthorized?: boolean });
21
23
  }
22
24
 
23
25
  interface ILease {
24
- connection: SqlPooledConnection;
26
+ connection: ISqlLeaseConnection;
25
27
  operation: Operation;
26
28
  close: () => Promise<void>;
27
29
  done: Promise<void>;
@@ -54,7 +56,7 @@ const boundValues = (statement: ISqlStatement): TSqlValue[] =>
54
56
  ? value.toISOString().replace('T', ' ').replace('Z', '')
55
57
  : value instanceof Uint8Array ? Buffer.from(value) : value);
56
58
 
57
- const mutationResult = (result: plugins.mariadb.UpsertResult): ISqlMutationResult => ({
59
+ const mutationResult = (result: ISqlWriteAcknowledgement): ISqlMutationResult => ({
58
60
  affectedRows: result.affectedRows,
59
61
  ...(result.insertId === undefined ? {} : { insertId: BigInt(result.insertId) }),
60
62
  completion: 'acknowledged',
@@ -81,7 +83,7 @@ export class SqlConnection {
81
83
  }
82
84
  this.backend = options.backend;
83
85
  this.capabilities = Object.freeze({ backend: this.backend, transactions: 'available',
84
- changeStreams: 'unsupported', objectMetrics: 'unsupported',
86
+ changeStreams: 'unsupported', compositeGrouping: 'unsupported', objectMetrics: 'unsupported',
85
87
  diskResidentScans: this.backend === 'sqldb' ? 'unsupported' : 'available' });
86
88
  }
87
89
 
@@ -130,7 +132,7 @@ export class SqlConnection {
130
132
  const operation = new Operation(options, this.options.timeoutMs);
131
133
  this.pendingOperations.add(operation);
132
134
  const acquisition = (async (): Promise<ILease> => {
133
- let connection: SqlPooledConnection | undefined;
135
+ let connection: ISqlLeaseConnection | undefined;
134
136
  try {
135
137
  operation.check();
136
138
  connection = await pool.getConnection(operation);
@@ -174,7 +176,7 @@ export class SqlConnection {
174
176
  try {
175
177
  lease.operation.check();
176
178
  dispatched = true;
177
- const result = await lease.connection.execute<plugins.mariadb.UpsertResult>(statement.sql, boundValues(statement));
179
+ const result = await lease.connection.execute<ISqlWriteAcknowledgement>(statement.sql, boundValues(statement));
178
180
  return mutationResult(result);
179
181
  } catch (error) {
180
182
  if (dispatched && (lease.operation.signal.aborted || !lease.connection.isValid())) {
@@ -328,7 +330,8 @@ export class SqlTransaction {
328
330
 
329
331
  public execute(statement: ISqlStatement): Promise<ISqlMutationResult> {
330
332
  validateStatement(statement);
331
- return this.run(async () => mutationResult(await this.lease.connection.execute(statement.sql, boundValues(statement))));
333
+ return this.run(async () => mutationResult(
334
+ await this.lease.connection.execute<ISqlWriteAcknowledgement>(statement.sql, boundValues(statement))));
332
335
  }
333
336
 
334
337
  public query<Row = Record<string, unknown>>(statement: ISqlStatement, options: Pick<IQueryOptions, 'maxRows' | 'maxBytes'> = {}): Promise<Row[]> {
@@ -9,6 +9,11 @@ export interface ISqlMutationResult {
9
9
  insertId?: bigint;
10
10
  completion: 'acknowledged';
11
11
  }
12
+ /** What a write acknowledgement carries on the wire; the driver's own result satisfies it. */
13
+ export interface ISqlWriteAcknowledgement {
14
+ affectedRows: number;
15
+ insertId?: number | bigint;
16
+ }
12
17
  export interface IInsertOptions extends IOperationOptions { batchSize?: number; maxBatchBytes?: number }
13
18
  export interface IClickHouseConnectionOptions {
14
19
  backend: 'clickhouse';
@@ -0,0 +1,16 @@
1
+ import * as plugins from './plugins.js';
2
+
3
+ /**
4
+ * What a pooled connection offers the holder of its lease. The pool speaks the driver's types;
5
+ * this seam is the client's own, so the connection and transaction declarations never name the driver.
6
+ */
7
+ export interface ISqlLeaseConnection {
8
+ execute<Result>(sql: string, values?: readonly unknown[]): Promise<Result>;
9
+ beginTransaction(): Promise<void>;
10
+ commit(): Promise<void>;
11
+ rollback(): Promise<void>;
12
+ queryStream(sql: string, values?: readonly unknown[]): plugins.stream.Readable;
13
+ isValid(): boolean;
14
+ destroy(): void;
15
+ release(): Promise<void>;
16
+ }
@@ -1,4 +1,5 @@
1
1
  import * as plugins from './plugins.mariadb.js';
2
+ import type { ISqlLeaseConnection } from './internal.lease.js';
2
3
  import type { Operation } from '../core/classes.operation.js';
3
4
  import { LosslessClientError } from '../core/classes.error.js';
4
5
 
@@ -112,7 +113,7 @@ export class SqlPool {
112
113
  }
113
114
 
114
115
  /** A lease can never affect a physical connection after returning ownership to the pool. */
115
- export class SqlPooledConnection {
116
+ export class SqlPooledConnection implements ISqlLeaseConnection {
116
117
  private readonly tasks = new Set<Promise<unknown>>();
117
118
  private readonly streams = new Set<plugins.stream.Readable>();
118
119
  private released = false;
@@ -1,4 +1,4 @@
1
+ // The MariaDB driver plus the shared Node built-ins. Only modules that speak to the driver import this.
1
2
  import * as mariadb from 'mariadb';
2
- import * as stream from 'node:stream';
3
- import * as net from 'node:net';
4
- export { mariadb, stream, net };
3
+ export * from './plugins.js';
4
+ export { mariadb };
@@ -0,0 +1,7 @@
1
+ // Node built-ins the relational families share. Driver packages stay in their own plugin modules,
2
+ // so a declaration that needs none of them never reaches an optional peer.
3
+ import * as net from 'node:net';
4
+ import * as stream from 'node:stream';
5
+ import * as tls from 'node:tls';
6
+
7
+ export { net, stream, tls };