@decohere/data 0.0.1-dev.125 → 0.0.1-dev.5
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/package.json +5 -21
- package/src/connection-info.ts +55 -0
- package/src/data-provider.ts +17 -0
- package/{types/src/data.types.d.ts → src/data.types.ts} +5 -3
- package/src/database.config.ts +5 -0
- package/src/error.ts +2 -0
- package/src/inject-unit-of-work.ts +7 -0
- package/src/repository.ts +28 -0
- package/{types/src/transaction.d.ts → src/transaction.ts} +1 -1
- package/LICENSE +0 -15
- package/commonjs/src/connection-info.js +0 -4
- package/commonjs/src/data-provider.js +0 -4
- package/commonjs/src/data.types.js +0 -4
- package/commonjs/src/database.config.js +0 -13
- package/commonjs/src/error.js +0 -22
- package/commonjs/src/index.js +0 -25
- package/commonjs/src/inject-unit-of-work.js +0 -23
- package/commonjs/src/repository.js +0 -24
- package/commonjs/src/transaction.js +0 -4
- package/es6/src/connection-info.js +0 -9
- package/es6/src/data-provider.js +0 -1
- package/es6/src/data.types.js +0 -1
- package/es6/src/database.config.js +0 -3
- package/es6/src/error.js +0 -4
- package/es6/src/inject-unit-of-work.js +0 -5
- package/es6/src/repository.js +0 -14
- package/es6/src/transaction.js +0 -1
- package/types/src/connection-info.d.ts +0 -53
- package/types/src/data-provider.d.ts +0 -15
- package/types/src/database.config.d.ts +0 -4
- package/types/src/error.d.ts +0 -4
- package/types/src/index.d.ts +0 -8
- package/types/src/inject-unit-of-work.d.ts +0 -2
- package/types/src/repository.d.ts +0 -14
- /package/{es6/src/index.js → src/index.ts} +0 -0
package/package.json
CHANGED
|
@@ -1,25 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@decohere/data",
|
|
3
|
-
"version": "0.0.1-dev.
|
|
4
|
-
"description": "
|
|
5
|
-
"keywords": [
|
|
6
|
-
"typescript",
|
|
7
|
-
"data-access",
|
|
8
|
-
"repository",
|
|
9
|
-
"unit-of-work",
|
|
10
|
-
"decohere"
|
|
11
|
-
],
|
|
12
|
-
"homepage": "https://github.com/typesmiths/decohere/tree/main/projects/data/data#readme",
|
|
13
|
-
"bugs": {
|
|
14
|
-
"url": "https://github.com/typesmiths/decohere/issues"
|
|
15
|
-
},
|
|
16
|
-
"repository": {
|
|
17
|
-
"type": "git",
|
|
18
|
-
"url": "git+https://github.com/typesmiths/decohere.git",
|
|
19
|
-
"directory": "projects/data/data"
|
|
20
|
-
},
|
|
3
|
+
"version": "0.0.1-dev.5",
|
|
4
|
+
"description": "",
|
|
21
5
|
"license": "ISC",
|
|
22
|
-
"author": "
|
|
6
|
+
"author": "",
|
|
23
7
|
"type": "module",
|
|
24
8
|
"main": "index.js",
|
|
25
9
|
"exports": {
|
|
@@ -33,8 +17,8 @@
|
|
|
33
17
|
"test": "echo \"Error: no test specified\" && exit 1"
|
|
34
18
|
},
|
|
35
19
|
"dependencies": {
|
|
36
|
-
"@decohere/
|
|
37
|
-
"@decohere/
|
|
20
|
+
"@decohere/di": "0.0.1-dev.5",
|
|
21
|
+
"@decohere/core": "0.0.1-dev.5"
|
|
38
22
|
},
|
|
39
23
|
"devDependencies": {}
|
|
40
24
|
}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
export type Dialect = "postgresql" | "tsql";
|
|
2
|
+
export type Provider = "postgres" | "mssql";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* How the server checks who connects, named as in pg_hba.conf.
|
|
6
|
+
* - `password` (default): every role signs in with a password.
|
|
7
|
+
* - `trust`: the server lets every connection in, so no role has a password. For a local dev
|
|
8
|
+
* server only; refused outside development.
|
|
9
|
+
*/
|
|
10
|
+
export type DatabaseAuth = "password" | "trust";
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Datasource connection settings.
|
|
14
|
+
*
|
|
15
|
+
* Privilege model (three roles — see CU-869eh3065):
|
|
16
|
+
* - **username/password** — runtime app role (DML only in production).
|
|
17
|
+
* - **migrateUsername/migratePassword** — migration/DDL role (CI/deploy only; not on API pods).
|
|
18
|
+
* - **adminUser/adminPassword** — bootstrap role (`CREATEDB`/`CREATEROLE`, not superuser);
|
|
19
|
+
* used only when `bootstrap` is enabled (explicit or auto in development).
|
|
20
|
+
*/
|
|
21
|
+
export type ConnectionInfo = {
|
|
22
|
+
name: string;
|
|
23
|
+
provider: Provider;
|
|
24
|
+
dialect?: Dialect;
|
|
25
|
+
host: string;
|
|
26
|
+
database: string;
|
|
27
|
+
port: number;
|
|
28
|
+
synchronize: boolean;
|
|
29
|
+
seed: boolean;
|
|
30
|
+
/** Runtime app role (TypeORM connection). */
|
|
31
|
+
username: string;
|
|
32
|
+
/** Required unless `auth` is `trust`. */
|
|
33
|
+
password?: string;
|
|
34
|
+
/** Defaults to `password`. `trust` must be declared: a missing password never implies it. */
|
|
35
|
+
auth?: DatabaseAuth;
|
|
36
|
+
/**
|
|
37
|
+
* Schema this data source's tables live in (default `public`). Bootstrap creates it when
|
|
38
|
+
* missing and grants the app role access to it.
|
|
39
|
+
*/
|
|
40
|
+
schema?: string;
|
|
41
|
+
/**
|
|
42
|
+
* When true, run prepareDatabase (create DB + roles) at API startup.
|
|
43
|
+
* When false, never bootstrap (production default).
|
|
44
|
+
* When omitted, bootstrap only if NODE_ENV is development/dev and admin creds are set.
|
|
45
|
+
*/
|
|
46
|
+
bootstrap?: boolean;
|
|
47
|
+
/** Bootstrap / provisioner role — must not be the runtime app user. */
|
|
48
|
+
adminUser?: string;
|
|
49
|
+
/** Required to bootstrap unless `auth` is `trust`. */
|
|
50
|
+
adminPassword?: string;
|
|
51
|
+
/** Optional migration role for DDL; default privileges grant DML to the app user. */
|
|
52
|
+
migrateUsername?: string;
|
|
53
|
+
/** Required with `migrateUsername` when bootstrapping, unless `auth` is `trust`. */
|
|
54
|
+
migratePassword?: string;
|
|
55
|
+
};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { Constructable } from "@decohere/core/reflection";
|
|
2
|
+
import type { Entity } from "./data.types.js";
|
|
3
|
+
|
|
4
|
+
export interface IUnitOfWork {
|
|
5
|
+
commit(): unknown;
|
|
6
|
+
beginTransaction(): Promise<void>;
|
|
7
|
+
/** Roll back anything unfinished and release the connection; prefer this over sync dispose. */
|
|
8
|
+
[Symbol.asyncDispose](): Promise<void>;
|
|
9
|
+
[Symbol.dispose](): void;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export interface IDataProvider {
|
|
13
|
+
findById<T extends Entity>(entity: Constructable<T>, key: string | number): Promise<T>;
|
|
14
|
+
save<T>(entity: T): Promise<T>;
|
|
15
|
+
delete<T>(entity: T);
|
|
16
|
+
all<T>(entity: Constructable): Promise<T[]>;
|
|
17
|
+
}
|
package/src/error.ts
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { Constructable } from "@decohere/core/reflection";
|
|
2
|
+
import type { Entity } from "./data.types.js";
|
|
3
|
+
import type { IDataProvider } from "./data-provider.js";
|
|
4
|
+
|
|
5
|
+
export interface IRepository<T> {
|
|
6
|
+
find(key: string): Promise<T>;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export abstract class Repository<T extends Entity> implements IRepository<T> {
|
|
10
|
+
protected abstract readonly provider: IDataProvider;
|
|
11
|
+
protected abstract readonly type: Constructable<T>;
|
|
12
|
+
|
|
13
|
+
public find(key: string | number): Promise<T> {
|
|
14
|
+
return this.provider.findById(this.type, key);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
public save(entity: T): Promise<T> {
|
|
18
|
+
return this.provider.save(entity);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
public async delete(entity: T) {
|
|
22
|
+
await this.provider.delete(entity);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
public async all(): Promise<T[]> {
|
|
26
|
+
return this.provider.all(this.type);
|
|
27
|
+
}
|
|
28
|
+
}
|
package/LICENSE
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
ISC License
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2025-2026 Typesmiths
|
|
4
|
-
|
|
5
|
-
Permission to use, copy, modify, and/or distribute this software for any
|
|
6
|
-
purpose with or without fee is hereby granted, provided that the above
|
|
7
|
-
copyright notice and this permission notice appear in all copies.
|
|
8
|
-
|
|
9
|
-
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
|
10
|
-
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
11
|
-
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
|
12
|
-
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
13
|
-
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
|
14
|
-
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
|
15
|
-
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", {
|
|
3
|
-
value: true
|
|
4
|
-
});
|
|
5
|
-
Object.defineProperty(exports, "DatabaseConfig", {
|
|
6
|
-
enumerable: true,
|
|
7
|
-
get: function() {
|
|
8
|
-
return DatabaseConfig;
|
|
9
|
-
}
|
|
10
|
-
});
|
|
11
|
-
class DatabaseConfig {
|
|
12
|
-
dataSources = [];
|
|
13
|
-
}
|
package/commonjs/src/error.js
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", {
|
|
3
|
-
value: true
|
|
4
|
-
});
|
|
5
|
-
function _export(target, all) {
|
|
6
|
-
for(var name in all)Object.defineProperty(target, name, {
|
|
7
|
-
enumerable: true,
|
|
8
|
-
get: Object.getOwnPropertyDescriptor(all, name).get
|
|
9
|
-
});
|
|
10
|
-
}
|
|
11
|
-
_export(exports, {
|
|
12
|
-
get DataConfigurationError () {
|
|
13
|
-
return DataConfigurationError;
|
|
14
|
-
},
|
|
15
|
-
get DataError () {
|
|
16
|
-
return DataError;
|
|
17
|
-
}
|
|
18
|
-
});
|
|
19
|
-
class DataError extends Error {
|
|
20
|
-
}
|
|
21
|
-
class DataConfigurationError extends Error {
|
|
22
|
-
}
|
package/commonjs/src/index.js
DELETED
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", {
|
|
3
|
-
value: true
|
|
4
|
-
});
|
|
5
|
-
_export_star(require("./connection-info.js"), exports);
|
|
6
|
-
_export_star(require("./data.types.js"), exports);
|
|
7
|
-
_export_star(require("./data-provider.js"), exports);
|
|
8
|
-
_export_star(require("./database.config.js"), exports);
|
|
9
|
-
_export_star(require("./error.js"), exports);
|
|
10
|
-
_export_star(require("./inject-unit-of-work.js"), exports);
|
|
11
|
-
_export_star(require("./repository.js"), exports);
|
|
12
|
-
_export_star(require("./transaction.js"), exports);
|
|
13
|
-
function _export_star(from, to) {
|
|
14
|
-
Object.keys(from).forEach(function(k) {
|
|
15
|
-
if (k !== "default" && !Object.prototype.hasOwnProperty.call(to, k)) {
|
|
16
|
-
Object.defineProperty(to, k, {
|
|
17
|
-
enumerable: true,
|
|
18
|
-
get: function() {
|
|
19
|
-
return from[k];
|
|
20
|
-
}
|
|
21
|
-
});
|
|
22
|
-
}
|
|
23
|
-
});
|
|
24
|
-
return from;
|
|
25
|
-
}
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", {
|
|
3
|
-
value: true
|
|
4
|
-
});
|
|
5
|
-
function _export(target, all) {
|
|
6
|
-
for(var name in all)Object.defineProperty(target, name, {
|
|
7
|
-
enumerable: true,
|
|
8
|
-
get: Object.getOwnPropertyDescriptor(all, name).get
|
|
9
|
-
});
|
|
10
|
-
}
|
|
11
|
-
_export(exports, {
|
|
12
|
-
get DEFAULT_DATA_SOURCE () {
|
|
13
|
-
return DEFAULT_DATA_SOURCE;
|
|
14
|
-
},
|
|
15
|
-
get injectUnitOfWork () {
|
|
16
|
-
return injectUnitOfWork;
|
|
17
|
-
}
|
|
18
|
-
});
|
|
19
|
-
const _decorators = require("@decohere/crucible/decorators");
|
|
20
|
-
const DEFAULT_DATA_SOURCE = Symbol("DEFAULT_DATA_SOURCE");
|
|
21
|
-
function injectUnitOfWork(key) {
|
|
22
|
-
return (0, _decorators.inject)(key ?? DEFAULT_DATA_SOURCE);
|
|
23
|
-
}
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", {
|
|
3
|
-
value: true
|
|
4
|
-
});
|
|
5
|
-
Object.defineProperty(exports, "Repository", {
|
|
6
|
-
enumerable: true,
|
|
7
|
-
get: function() {
|
|
8
|
-
return Repository;
|
|
9
|
-
}
|
|
10
|
-
});
|
|
11
|
-
class Repository {
|
|
12
|
-
find(key) {
|
|
13
|
-
return this.provider.findById(this.type, key);
|
|
14
|
-
}
|
|
15
|
-
save(entity) {
|
|
16
|
-
return this.provider.save(entity);
|
|
17
|
-
}
|
|
18
|
-
async delete(entity) {
|
|
19
|
-
await this.provider.delete(entity);
|
|
20
|
-
}
|
|
21
|
-
async all() {
|
|
22
|
-
return this.provider.all(this.type);
|
|
23
|
-
}
|
|
24
|
-
}
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Datasource connection settings.
|
|
3
|
-
*
|
|
4
|
-
* Privilege model (three roles):
|
|
5
|
-
* - **username/password** — runtime app role (DML only in production).
|
|
6
|
-
* - **migrateUsername/migratePassword** — migration/DDL role (CI/deploy only; not on API pods).
|
|
7
|
-
* - **adminUser/adminPassword** — bootstrap role (`CREATEDB`/`CREATEROLE`, not superuser);
|
|
8
|
-
* used only when `bootstrap` is enabled (explicit or auto in development).
|
|
9
|
-
*/ export { };
|
package/es6/src/data-provider.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { };
|
package/es6/src/data.types.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { };
|
package/es6/src/error.js
DELETED
package/es6/src/repository.js
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
export class Repository {
|
|
2
|
-
find(key) {
|
|
3
|
-
return this.provider.findById(this.type, key);
|
|
4
|
-
}
|
|
5
|
-
save(entity) {
|
|
6
|
-
return this.provider.save(entity);
|
|
7
|
-
}
|
|
8
|
-
async delete(entity) {
|
|
9
|
-
await this.provider.delete(entity);
|
|
10
|
-
}
|
|
11
|
-
async all() {
|
|
12
|
-
return this.provider.all(this.type);
|
|
13
|
-
}
|
|
14
|
-
}
|
package/es6/src/transaction.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { };
|
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
export type Dialect = "postgresql" | "tsql";
|
|
2
|
-
export type Provider = "postgres" | "mssql";
|
|
3
|
-
/**
|
|
4
|
-
* How the server checks who connects, named as in pg_hba.conf.
|
|
5
|
-
* - `password` (default): every role signs in with a password.
|
|
6
|
-
* - `trust`: the server lets every connection in, so no role has a password. For a local dev
|
|
7
|
-
* server only; refused outside development.
|
|
8
|
-
*/
|
|
9
|
-
export type DatabaseAuth = "password" | "trust";
|
|
10
|
-
/**
|
|
11
|
-
* Datasource connection settings.
|
|
12
|
-
*
|
|
13
|
-
* Privilege model (three roles):
|
|
14
|
-
* - **username/password** — runtime app role (DML only in production).
|
|
15
|
-
* - **migrateUsername/migratePassword** — migration/DDL role (CI/deploy only; not on API pods).
|
|
16
|
-
* - **adminUser/adminPassword** — bootstrap role (`CREATEDB`/`CREATEROLE`, not superuser);
|
|
17
|
-
* used only when `bootstrap` is enabled (explicit or auto in development).
|
|
18
|
-
*/
|
|
19
|
-
export type ConnectionInfo = {
|
|
20
|
-
name: string;
|
|
21
|
-
provider: Provider;
|
|
22
|
-
dialect?: Dialect;
|
|
23
|
-
host: string;
|
|
24
|
-
database: string;
|
|
25
|
-
port: number;
|
|
26
|
-
synchronize: boolean;
|
|
27
|
-
seed: boolean;
|
|
28
|
-
/** Runtime app role (TypeORM connection). */
|
|
29
|
-
username: string;
|
|
30
|
-
/** Required unless `auth` is `trust`. */
|
|
31
|
-
password?: string;
|
|
32
|
-
/** Defaults to `password`. `trust` must be declared: a missing password never implies it. */
|
|
33
|
-
auth?: DatabaseAuth;
|
|
34
|
-
/**
|
|
35
|
-
* Schema this data source's tables live in (default `public`). Bootstrap creates it when
|
|
36
|
-
* missing and grants the app role access to it.
|
|
37
|
-
*/
|
|
38
|
-
schema?: string;
|
|
39
|
-
/**
|
|
40
|
-
* When true, run prepareDatabase (create DB + roles) at API startup.
|
|
41
|
-
* When false, never bootstrap (production default).
|
|
42
|
-
* When omitted, bootstrap only if NODE_ENV is development/dev and admin creds are set.
|
|
43
|
-
*/
|
|
44
|
-
bootstrap?: boolean;
|
|
45
|
-
/** Bootstrap / provisioner role — must not be the runtime app user. */
|
|
46
|
-
adminUser?: string;
|
|
47
|
-
/** Required to bootstrap unless `auth` is `trust`. */
|
|
48
|
-
adminPassword?: string;
|
|
49
|
-
/** Optional migration role for DDL; default privileges grant DML to the app user. */
|
|
50
|
-
migrateUsername?: string;
|
|
51
|
-
/** Required with `migrateUsername` when bootstrapping, unless `auth` is `trust`. */
|
|
52
|
-
migratePassword?: string;
|
|
53
|
-
};
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import type { Constructable } from "@decohere/core/reflection";
|
|
2
|
-
import type { Entity } from "./data.types.js";
|
|
3
|
-
export interface IUnitOfWork {
|
|
4
|
-
commit(): unknown;
|
|
5
|
-
beginTransaction(): Promise<void>;
|
|
6
|
-
/** Roll back anything unfinished and release the connection; prefer this over sync dispose. */
|
|
7
|
-
[Symbol.asyncDispose](): Promise<void>;
|
|
8
|
-
[Symbol.dispose](): void;
|
|
9
|
-
}
|
|
10
|
-
export interface IDataProvider {
|
|
11
|
-
findById<T extends Entity>(entity: Constructable<T>, key: string | number): Promise<T>;
|
|
12
|
-
save<T>(entity: T): Promise<T>;
|
|
13
|
-
delete<T>(entity: T): any;
|
|
14
|
-
all<T>(entity: Constructable): Promise<T[]>;
|
|
15
|
-
}
|
package/types/src/error.d.ts
DELETED
package/types/src/index.d.ts
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
export * from "./connection-info.js";
|
|
2
|
-
export * from "./data.types.js";
|
|
3
|
-
export * from "./data-provider.js";
|
|
4
|
-
export * from "./database.config.js";
|
|
5
|
-
export * from "./error.js";
|
|
6
|
-
export * from "./inject-unit-of-work.js";
|
|
7
|
-
export * from "./repository.js";
|
|
8
|
-
export * from "./transaction.js";
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import type { Constructable } from "@decohere/core/reflection";
|
|
2
|
-
import type { Entity } from "./data.types.js";
|
|
3
|
-
import type { IDataProvider } from "./data-provider.js";
|
|
4
|
-
export interface IRepository<T> {
|
|
5
|
-
find(key: string): Promise<T>;
|
|
6
|
-
}
|
|
7
|
-
export declare abstract class Repository<T extends Entity> implements IRepository<T> {
|
|
8
|
-
protected abstract readonly provider: IDataProvider;
|
|
9
|
-
protected abstract readonly type: Constructable<T>;
|
|
10
|
-
find(key: string | number): Promise<T>;
|
|
11
|
-
save(entity: T): Promise<T>;
|
|
12
|
-
delete(entity: T): Promise<void>;
|
|
13
|
-
all(): Promise<T[]>;
|
|
14
|
-
}
|
|
File without changes
|