@deterministic-code/datasources 0.1.16 → 0.1.17
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.
- package/dist/Datasource.d.ts +2 -0
- package/dist/Datasource.js +6 -0
- package/dist/IDatasource.d.ts +2 -0
- package/dist/mocks/mock-datasource.d.ts +2 -0
- package/dist/mocks/mock-datasource.js +2 -0
- package/dist/stubs/StubDatasource.d.ts +2 -0
- package/dist/stubs/StubDatasource.js +6 -0
- package/package.json +1 -1
package/dist/Datasource.d.ts
CHANGED
|
@@ -17,6 +17,8 @@ export declare class Datasource implements IDatasource {
|
|
|
17
17
|
readonly repositories: RepositoryFactory;
|
|
18
18
|
constructor(provider: string, driver: IDriver, options?: DatasourceOptions | undefined);
|
|
19
19
|
private defaultConnection;
|
|
20
|
+
close: () => Promise<void>;
|
|
21
|
+
[Symbol.asyncDispose]: () => Promise<void>;
|
|
20
22
|
createConnection: () => Promise<IConnection>;
|
|
21
23
|
createCommand: (connection?: IConnection) => Promise<ICommand>;
|
|
22
24
|
private applyCrud;
|
package/dist/Datasource.js
CHANGED
|
@@ -29,6 +29,12 @@ export class Datasource {
|
|
|
29
29
|
});
|
|
30
30
|
}
|
|
31
31
|
defaultConnection = () => (this.connection ??= this.driver.connection(this.options));
|
|
32
|
+
close = async () => {
|
|
33
|
+
const connection = this.connection;
|
|
34
|
+
this.connection = undefined;
|
|
35
|
+
await connection?.close();
|
|
36
|
+
};
|
|
37
|
+
[Symbol.asyncDispose] = () => this.close();
|
|
32
38
|
createConnection = () => Promise.resolve(this.defaultConnection());
|
|
33
39
|
createCommand = async (connection) => {
|
|
34
40
|
if (!connection) {
|
package/dist/IDatasource.d.ts
CHANGED
|
@@ -9,6 +9,8 @@ import type { RepositoryFactory } from "./RepositoryFactory.js";
|
|
|
9
9
|
export interface IDatasource {
|
|
10
10
|
readonly provider: string;
|
|
11
11
|
readonly repositories: RepositoryFactory;
|
|
12
|
+
close(): Promise<void>;
|
|
13
|
+
[Symbol.asyncDispose](): Promise<void>;
|
|
12
14
|
createConnection(): Promise<IConnection>;
|
|
13
15
|
createCommand(connection?: IConnection): Promise<ICommand>;
|
|
14
16
|
createRepository<T>(type: Constructable<T>, connection?: IConnection, options?: CRUDRepositoryOptions<T>): ICRUDRepository<T>;
|
|
@@ -15,6 +15,8 @@ export declare class MockDatasource implements IDatasource {
|
|
|
15
15
|
repository?: ICRUDRepository;
|
|
16
16
|
readonly repositories: RepositoryFactory;
|
|
17
17
|
constructor(provider?: string);
|
|
18
|
+
close: () => Promise<void>;
|
|
19
|
+
[Symbol.asyncDispose]: () => Promise<void>;
|
|
18
20
|
createConnection(): Promise<IConnection>;
|
|
19
21
|
createCommand(connection?: IConnection): Promise<ICommand>;
|
|
20
22
|
createRepository<T>(type: Constructable<T>, connection?: IConnection): ICRUDRepository<T>;
|
|
@@ -16,6 +16,8 @@ export class MockDatasource {
|
|
|
16
16
|
this.provider = provider;
|
|
17
17
|
this.connection = new MockConnection();
|
|
18
18
|
}
|
|
19
|
+
close = () => this.connection.close();
|
|
20
|
+
[Symbol.asyncDispose] = () => this.close();
|
|
19
21
|
createConnection() {
|
|
20
22
|
this.createConnectionCalls += 1;
|
|
21
23
|
return Promise.resolve(this.connection);
|
|
@@ -11,6 +11,8 @@ export declare class StubDatasource implements IDatasource {
|
|
|
11
11
|
readonly repositories: RepositoryFactory;
|
|
12
12
|
constructor(provider: string);
|
|
13
13
|
private defaultConnection;
|
|
14
|
+
close: () => Promise<void>;
|
|
15
|
+
[Symbol.asyncDispose]: () => Promise<void>;
|
|
14
16
|
createConnection: () => Promise<IConnection>;
|
|
15
17
|
createCommand: (connection?: IConnection) => Promise<ICommand>;
|
|
16
18
|
createRepository<T>(type: Constructable<T>, connection?: IConnection): ICRUDRepository<T>;
|
|
@@ -11,6 +11,12 @@ export class StubDatasource {
|
|
|
11
11
|
this.provider = provider;
|
|
12
12
|
}
|
|
13
13
|
defaultConnection = () => (this.connection ??= new StubConnection(this.provider));
|
|
14
|
+
close = async () => {
|
|
15
|
+
const connection = this.connection;
|
|
16
|
+
this.connection = undefined;
|
|
17
|
+
await connection?.close();
|
|
18
|
+
};
|
|
19
|
+
[Symbol.asyncDispose] = () => this.close();
|
|
14
20
|
createConnection = () => Promise.resolve(this.defaultConnection());
|
|
15
21
|
createCommand = async (connection) => {
|
|
16
22
|
if (!connection) {
|