rev-dal 0.0.0-stage → 0.2.1
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/AGENTS.md +234 -0
- package/CONTRIBUTING.md +83 -0
- package/LICENSE +121 -0
- package/README.md +67 -2
- package/dist/index.d.ts +48 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +26 -0
- package/dist/index.js.map +1 -0
- package/dist/lib/clone.d.ts +24 -0
- package/dist/lib/clone.d.ts.map +1 -0
- package/dist/lib/clone.js +83 -0
- package/dist/lib/clone.js.map +1 -0
- package/dist/lib/create-model.d.ts +207 -0
- package/dist/lib/create-model.d.ts.map +1 -0
- package/dist/lib/create-model.js +230 -0
- package/dist/lib/create-model.js.map +1 -0
- package/dist/lib/data-access-layer.d.ts +140 -0
- package/dist/lib/data-access-layer.d.ts.map +1 -0
- package/dist/lib/data-access-layer.js +389 -0
- package/dist/lib/data-access-layer.js.map +1 -0
- package/dist/lib/errors.d.ts +139 -0
- package/dist/lib/errors.d.ts.map +1 -0
- package/dist/lib/errors.js +206 -0
- package/dist/lib/errors.js.map +1 -0
- package/dist/lib/filter-where.d.ts +199 -0
- package/dist/lib/filter-where.d.ts.map +1 -0
- package/dist/lib/filter-where.js +563 -0
- package/dist/lib/filter-where.js.map +1 -0
- package/dist/lib/ml-string.d.ts +63 -0
- package/dist/lib/ml-string.d.ts.map +1 -0
- package/dist/lib/ml-string.js +331 -0
- package/dist/lib/ml-string.js.map +1 -0
- package/dist/lib/model-factory.d.ts +25 -0
- package/dist/lib/model-factory.d.ts.map +1 -0
- package/dist/lib/model-factory.js +57 -0
- package/dist/lib/model-factory.js.map +1 -0
- package/dist/lib/model-handle.d.ts +67 -0
- package/dist/lib/model-handle.d.ts.map +1 -0
- package/dist/lib/model-handle.js +182 -0
- package/dist/lib/model-handle.js.map +1 -0
- package/dist/lib/model-initializer.d.ts +96 -0
- package/dist/lib/model-initializer.d.ts.map +1 -0
- package/dist/lib/model-initializer.js +182 -0
- package/dist/lib/model-initializer.js.map +1 -0
- package/dist/lib/model-manifest.d.ts +112 -0
- package/dist/lib/model-manifest.d.ts.map +1 -0
- package/dist/lib/model-manifest.js +2 -0
- package/dist/lib/model-manifest.js.map +1 -0
- package/dist/lib/model-registry.d.ts +81 -0
- package/dist/lib/model-registry.d.ts.map +1 -0
- package/dist/lib/model-registry.js +139 -0
- package/dist/lib/model-registry.js.map +1 -0
- package/dist/lib/model-types.d.ts +380 -0
- package/dist/lib/model-types.d.ts.map +1 -0
- package/dist/lib/model-types.js +2 -0
- package/dist/lib/model-types.js.map +1 -0
- package/dist/lib/model.d.ts +503 -0
- package/dist/lib/model.d.ts.map +1 -0
- package/dist/lib/model.js +1423 -0
- package/dist/lib/model.js.map +1 -0
- package/dist/lib/postgres-config.d.ts +3 -0
- package/dist/lib/postgres-config.d.ts.map +1 -0
- package/dist/lib/postgres-config.js +2 -0
- package/dist/lib/postgres-config.js.map +1 -0
- package/dist/lib/query-builder.d.ts +607 -0
- package/dist/lib/query-builder.d.ts.map +1 -0
- package/dist/lib/query-builder.js +1734 -0
- package/dist/lib/query-builder.js.map +1 -0
- package/dist/lib/revision.d.ts +55 -0
- package/dist/lib/revision.d.ts.map +1 -0
- package/dist/lib/revision.js +307 -0
- package/dist/lib/revision.js.map +1 -0
- package/dist/lib/runtime.d.ts +18 -0
- package/dist/lib/runtime.d.ts.map +1 -0
- package/dist/lib/runtime.js +134 -0
- package/dist/lib/runtime.js.map +1 -0
- package/dist/lib/transaction.d.ts +17 -0
- package/dist/lib/transaction.d.ts.map +1 -0
- package/dist/lib/transaction.js +30 -0
- package/dist/lib/transaction.js.map +1 -0
- package/dist/lib/type.d.ts +130 -0
- package/dist/lib/type.d.ts.map +1 -0
- package/dist/lib/type.js +376 -0
- package/dist/lib/type.js.map +1 -0
- package/docs/models.md +406 -0
- package/docs/multilingual-text.md +142 -0
- package/docs/queries.md +374 -0
- package/docs/revisions.md +61 -0
- package/package.json +60 -4
- package/releases/0.2.0.md +18 -0
- package/releases/0.2.1.md +22 -0
- package/releases/README.md +7 -0
- package/setup-db-grants.sql +51 -0
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
import type { PoolClient, PoolConfig, QueryResult } from 'pg';
|
|
2
|
+
import { Pool } from 'pg';
|
|
3
|
+
import type { ModelSchema } from './model.js';
|
|
4
|
+
import type { InferConstructor, ModelManifest } from './model-manifest.js';
|
|
5
|
+
import ModelRegistry from './model-registry.js';
|
|
6
|
+
import type { DataAccessLayer as DataAccessLayerContract, JsonObject, ModelConstructor } from './model-types.js';
|
|
7
|
+
import type { PostgresConfig } from './postgres-config.js';
|
|
8
|
+
type PoolLike = Pool | PoolClient;
|
|
9
|
+
type DataAccessLayerConfig = (PoolConfig & JsonObject) & Partial<PostgresConfig>;
|
|
10
|
+
/**
|
|
11
|
+
* Main Data Access Layer class for PostgreSQL
|
|
12
|
+
*
|
|
13
|
+
* Provides connection management, transaction support, and model creation
|
|
14
|
+
* functionality. This class serves as the main interface between the
|
|
15
|
+
* application and the PostgreSQL database.
|
|
16
|
+
*/
|
|
17
|
+
declare class DataAccessLayer implements DataAccessLayerContract {
|
|
18
|
+
config: DataAccessLayerConfig;
|
|
19
|
+
pool: Pool | null;
|
|
20
|
+
modelRegistry: ModelRegistry;
|
|
21
|
+
schemaNamespace?: string;
|
|
22
|
+
private _connected;
|
|
23
|
+
private _connecting;
|
|
24
|
+
mlString: import("./ml-string.js").MlStringVariants;
|
|
25
|
+
revision: import("./revision.js").RevisionHelpers;
|
|
26
|
+
types: {
|
|
27
|
+
readonly string: (options?: Record<string, unknown>) => import("./type.js").StringType<false>;
|
|
28
|
+
readonly number: (options?: Record<string, unknown>) => import("./type.js").NumberType<false>;
|
|
29
|
+
readonly boolean: (options?: Record<string, unknown>) => import("./type.js").BooleanType<false>;
|
|
30
|
+
readonly date: (options?: Record<string, unknown>) => import("./type.js").DateType<false>;
|
|
31
|
+
readonly array: <TElementField extends {
|
|
32
|
+
validate(value: unknown, fieldName?: string): unknown;
|
|
33
|
+
} = import("./type.js").Type<unknown, false>>(elementType?: TElementField | null, options?: Record<string, unknown>) => import("./type.js").ArrayType<TElementField, false>;
|
|
34
|
+
readonly object: (options?: Record<string, unknown>) => import("./type.js").ObjectType<unknown, false>;
|
|
35
|
+
readonly virtual: <TValue = unknown>(options?: Record<string, unknown>) => import("./type.js").VirtualType<TValue, false>;
|
|
36
|
+
readonly any: (options?: Record<string, unknown>) => import("./type.js").Type<unknown, false>;
|
|
37
|
+
};
|
|
38
|
+
constructor(config?: Partial<PostgresConfig> & JsonObject);
|
|
39
|
+
/**
|
|
40
|
+
* Initialize the connection pool and connect to PostgreSQL
|
|
41
|
+
* @returns This instance for chaining
|
|
42
|
+
*/
|
|
43
|
+
connect(): Promise<this>;
|
|
44
|
+
/**
|
|
45
|
+
* Create the pool, expose it on `this.pool` right away, and verify it.
|
|
46
|
+
* @private
|
|
47
|
+
*/
|
|
48
|
+
private _openPool;
|
|
49
|
+
/**
|
|
50
|
+
* Close all connections and clean up
|
|
51
|
+
*/
|
|
52
|
+
disconnect(): Promise<void>;
|
|
53
|
+
/**
|
|
54
|
+
* Get a connection from the pool
|
|
55
|
+
* @returns PostgreSQL client connection
|
|
56
|
+
*/
|
|
57
|
+
getConnection(): Promise<PoolClient>;
|
|
58
|
+
/**
|
|
59
|
+
* Execute a query with optional parameters
|
|
60
|
+
* @param text - SQL query text
|
|
61
|
+
* @param params - Query parameters
|
|
62
|
+
* @param client - Optional client connection (for transactions)
|
|
63
|
+
* @returns Query result
|
|
64
|
+
*/
|
|
65
|
+
query<TRecord extends JsonObject = JsonObject>(text: string, params?: unknown[], client?: PoolLike | null): Promise<QueryResult<TRecord>>;
|
|
66
|
+
/**
|
|
67
|
+
* Execute a transaction with automatic rollback on error
|
|
68
|
+
* @param callback - Function to execute within transaction
|
|
69
|
+
* @returns Result of the callback function
|
|
70
|
+
*/
|
|
71
|
+
transaction<T>(callback: (client: PoolClient) => Promise<T>): Promise<T>;
|
|
72
|
+
/**
|
|
73
|
+
* Create a new model class
|
|
74
|
+
* @param name - Model name (table name)
|
|
75
|
+
* @param schema - Model schema definition
|
|
76
|
+
* @param options - Model options
|
|
77
|
+
* @returns Model constructor
|
|
78
|
+
*/
|
|
79
|
+
createModel<TData extends JsonObject, TVirtual extends JsonObject = JsonObject>(name: string, schema: ModelSchema<TData, TVirtual>, options?: JsonObject): ModelConstructor<TData, TVirtual>;
|
|
80
|
+
/**
|
|
81
|
+
* Get a model registered on this DAL instance.
|
|
82
|
+
*
|
|
83
|
+
* Pass a table name or registry key for an untyped lookup. Pass a
|
|
84
|
+
* `defineModel()`/`referenceModel()` handle, or a constructor registered on
|
|
85
|
+
* another DAL, to get this DAL's constructor for the same model typed like
|
|
86
|
+
* the argument. Pass a model manifest to get it typed from the manifest.
|
|
87
|
+
*
|
|
88
|
+
* Handle types include `statics` passed to `defineModel()` and fallback
|
|
89
|
+
* methods passed to `referenceModel()`; those exist only on the handle, not
|
|
90
|
+
* on the returned constructor.
|
|
91
|
+
*
|
|
92
|
+
* Every form reads only this instance's registry: it never consults the
|
|
93
|
+
* bootstrap resolver, queries the database or registers models. Handles and
|
|
94
|
+
* manifests resolve by their manifest `tableName`; constructors by the
|
|
95
|
+
* registry key they were registered under.
|
|
96
|
+
*
|
|
97
|
+
* The non-string forms are typing hints; they do not check that the
|
|
98
|
+
* argument matches the registered model's schema.
|
|
99
|
+
*
|
|
100
|
+
* @param nameOrModel - Table name, registry key, model handle, constructor or manifest
|
|
101
|
+
* @returns The constructor registered on this DAL
|
|
102
|
+
* @throws Error when no model is registered under that name
|
|
103
|
+
* @throws TypeError when the argument is not a name, handle, registered constructor or manifest
|
|
104
|
+
*/
|
|
105
|
+
getModel<TData extends JsonObject = JsonObject, TVirtual extends JsonObject = JsonObject>(name: string): ModelConstructor<TData, TVirtual>;
|
|
106
|
+
getModel<Model extends ModelConstructor>(model: Model): Model;
|
|
107
|
+
getModel<Manifest extends ModelManifest>(manifest: Manifest): InferConstructor<Manifest>;
|
|
108
|
+
/**
|
|
109
|
+
* Return a map of registered models keyed by canonical name
|
|
110
|
+
*/
|
|
111
|
+
getRegisteredModels(): Map<string, ModelConstructor<JsonObject, JsonObject>>;
|
|
112
|
+
/**
|
|
113
|
+
* Expose the registry instance for advanced consumers
|
|
114
|
+
*/
|
|
115
|
+
getModelRegistry(): ModelRegistry;
|
|
116
|
+
/**
|
|
117
|
+
* Run database migrations
|
|
118
|
+
* @param migrationsPath - Path to migration files
|
|
119
|
+
*/
|
|
120
|
+
migrate(migrationsPath?: string): Promise<void>;
|
|
121
|
+
/**
|
|
122
|
+
* Rollback the last migration (if supported)
|
|
123
|
+
*/
|
|
124
|
+
rollback(migrationsPath?: string): Promise<void>;
|
|
125
|
+
/**
|
|
126
|
+
* Check if the DAL is connected
|
|
127
|
+
*/
|
|
128
|
+
isConnected(): boolean;
|
|
129
|
+
/**
|
|
130
|
+
* Get pool statistics
|
|
131
|
+
*/
|
|
132
|
+
getPoolStats(): {
|
|
133
|
+
totalCount: number;
|
|
134
|
+
idleCount: number;
|
|
135
|
+
waitingCount: number;
|
|
136
|
+
} | null;
|
|
137
|
+
}
|
|
138
|
+
export { DataAccessLayer };
|
|
139
|
+
export default DataAccessLayer;
|
|
140
|
+
//# sourceMappingURL=data-access-layer.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"data-access-layer.d.ts","sourceRoot":"","sources":["../../src/lib/data-access-layer.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,UAAU,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,IAAI,CAAC;AAC9D,OAAO,EAAE,IAAI,EAAE,MAAM,IAAI,CAAC;AAE1B,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAG9C,OAAO,KAAK,EAAE,gBAAgB,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAC3E,OAAO,aAAwC,MAAM,qBAAqB,CAAC;AAC3E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';
|
|
3
|
+
import { Pool } from 'pg';
|
|
4
|
+
import mlString from './ml-string.js';
|
|
5
|
+
import Model from './model.js';
|
|
6
|
+
import { getModelHandleTableName } from './model-handle.js';
|
|
7
|
+
import ModelRegistry, { getRegisteredModelKey } from './model-registry.js';
|
|
8
|
+
import revision from './revision.js';
|
|
9
|
+
import { debug } from './runtime.js';
|
|
10
|
+
import types from './type.js';
|
|
11
|
+
/**
|
|
12
|
+
* Turn a `getModel()` argument into a registry lookup key. Handles are
|
|
13
|
+
* checked first so their proxies' resolver-backed traps are never triggered.
|
|
14
|
+
*/
|
|
15
|
+
function resolveModelLookupName(value) {
|
|
16
|
+
if (typeof value === 'string') {
|
|
17
|
+
return value;
|
|
18
|
+
}
|
|
19
|
+
const handleTableName = getModelHandleTableName(value);
|
|
20
|
+
if (handleTableName !== undefined) {
|
|
21
|
+
return handleTableName;
|
|
22
|
+
}
|
|
23
|
+
const registryKey = getRegisteredModelKey(value);
|
|
24
|
+
if (registryKey !== undefined) {
|
|
25
|
+
return registryKey;
|
|
26
|
+
}
|
|
27
|
+
if (typeof value === 'object' && value !== null && !Array.isArray(value)) {
|
|
28
|
+
const { tableName } = value;
|
|
29
|
+
if (typeof tableName === 'string' && tableName.length > 0) {
|
|
30
|
+
return tableName;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
throw new TypeError('getModel() expects a model name, a defineModel()/referenceModel() handle, a registered model constructor, or a model manifest with a non-empty tableName.');
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Summarize query parameters for logs without revealing their values, which
|
|
37
|
+
* can include password hashes, tokens and personal data.
|
|
38
|
+
*
|
|
39
|
+
* @param params Query parameters
|
|
40
|
+
* @returns e.g. `3 (string, number, null)`
|
|
41
|
+
*/
|
|
42
|
+
function describeQueryParams(params) {
|
|
43
|
+
if (params.length === 0) {
|
|
44
|
+
return '0';
|
|
45
|
+
}
|
|
46
|
+
const kinds = params.map(param => {
|
|
47
|
+
if (param === null)
|
|
48
|
+
return 'null';
|
|
49
|
+
if (Array.isArray(param))
|
|
50
|
+
return 'array';
|
|
51
|
+
if (param instanceof Date)
|
|
52
|
+
return 'date';
|
|
53
|
+
return typeof param;
|
|
54
|
+
});
|
|
55
|
+
return `${params.length} (${kinds.join(', ')})`;
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Main Data Access Layer class for PostgreSQL
|
|
59
|
+
*
|
|
60
|
+
* Provides connection management, transaction support, and model creation
|
|
61
|
+
* functionality. This class serves as the main interface between the
|
|
62
|
+
* application and the PostgreSQL database.
|
|
63
|
+
*/
|
|
64
|
+
class DataAccessLayer {
|
|
65
|
+
config;
|
|
66
|
+
pool;
|
|
67
|
+
modelRegistry;
|
|
68
|
+
schemaNamespace;
|
|
69
|
+
_connected;
|
|
70
|
+
_connecting = null;
|
|
71
|
+
// Helper namespaces exposed for model manifests
|
|
72
|
+
mlString = mlString;
|
|
73
|
+
revision = revision;
|
|
74
|
+
types = types;
|
|
75
|
+
constructor(config = {}) {
|
|
76
|
+
const defaultConfig = {
|
|
77
|
+
host: 'localhost',
|
|
78
|
+
port: 5432,
|
|
79
|
+
database: 'libreviews',
|
|
80
|
+
user: 'postgres',
|
|
81
|
+
password: '',
|
|
82
|
+
max: 20,
|
|
83
|
+
idleTimeoutMillis: 30000,
|
|
84
|
+
connectionTimeoutMillis: 2000,
|
|
85
|
+
};
|
|
86
|
+
this.config = {
|
|
87
|
+
...defaultConfig,
|
|
88
|
+
...config,
|
|
89
|
+
};
|
|
90
|
+
this.pool = null;
|
|
91
|
+
this._connected = false;
|
|
92
|
+
this.modelRegistry = new ModelRegistry(this);
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Initialize the connection pool and connect to PostgreSQL
|
|
96
|
+
* @returns This instance for chaining
|
|
97
|
+
*/
|
|
98
|
+
async connect() {
|
|
99
|
+
if (this._connected) {
|
|
100
|
+
return this;
|
|
101
|
+
}
|
|
102
|
+
// Concurrent callers share one connection attempt (and one pool)
|
|
103
|
+
if (!this._connecting) {
|
|
104
|
+
this._connecting = this._openPool().finally(() => {
|
|
105
|
+
this._connecting = null;
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
await this._connecting;
|
|
109
|
+
return this;
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* Create the pool, expose it on `this.pool` right away, and verify it.
|
|
113
|
+
* @private
|
|
114
|
+
*/
|
|
115
|
+
async _openPool() {
|
|
116
|
+
// Expose the pool before the first await: callers may read `pool` while
|
|
117
|
+
// connect() is still in flight (pg pools connect lazily), as they could
|
|
118
|
+
// before the connection test was added. `isConnected()` only turns true
|
|
119
|
+
// once the test succeeds.
|
|
120
|
+
const pool = new Pool(this.config);
|
|
121
|
+
this.pool = pool;
|
|
122
|
+
// Attach handlers before any client exists: an 'error' event without a
|
|
123
|
+
// listener would crash the process.
|
|
124
|
+
pool.on('connect', () => {
|
|
125
|
+
debug.db('New PostgreSQL client connected');
|
|
126
|
+
});
|
|
127
|
+
pool.on('error', (err) => {
|
|
128
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
129
|
+
debug.error(`PostgreSQL pool error: ${message}`);
|
|
130
|
+
debug.error({ error: err instanceof Error ? err : new Error(message) });
|
|
131
|
+
});
|
|
132
|
+
try {
|
|
133
|
+
// Test the connection; always hand the client back, discarding it on error
|
|
134
|
+
const client = await pool.connect();
|
|
135
|
+
try {
|
|
136
|
+
await client.query('SELECT NOW()');
|
|
137
|
+
}
|
|
138
|
+
catch (queryError) {
|
|
139
|
+
client.release(queryError instanceof Error ? queryError : true);
|
|
140
|
+
throw queryError;
|
|
141
|
+
}
|
|
142
|
+
client.release();
|
|
143
|
+
this._connected = true;
|
|
144
|
+
debug.db('PostgreSQL connection pool established');
|
|
145
|
+
}
|
|
146
|
+
catch (error) {
|
|
147
|
+
// Don't leave a half-initialized pool behind
|
|
148
|
+
if (this.pool === pool) {
|
|
149
|
+
this.pool = null;
|
|
150
|
+
}
|
|
151
|
+
await pool.end().catch(() => undefined);
|
|
152
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
153
|
+
debug.error(`Failed to connect to PostgreSQL: ${message}`);
|
|
154
|
+
debug.error({ error: error instanceof Error ? error : new Error(message) });
|
|
155
|
+
throw error;
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
/**
|
|
159
|
+
* Close all connections and clean up
|
|
160
|
+
*/
|
|
161
|
+
async disconnect() {
|
|
162
|
+
if (this.pool) {
|
|
163
|
+
await this.pool.end();
|
|
164
|
+
this.pool = null;
|
|
165
|
+
this._connected = false;
|
|
166
|
+
this.modelRegistry.clear();
|
|
167
|
+
debug.db('PostgreSQL connection pool closed');
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
/**
|
|
171
|
+
* Get a connection from the pool
|
|
172
|
+
* @returns PostgreSQL client connection
|
|
173
|
+
*/
|
|
174
|
+
async getConnection() {
|
|
175
|
+
if (!this._connected || !this.pool) {
|
|
176
|
+
throw new Error('DAL not connected. Call connect() first.');
|
|
177
|
+
}
|
|
178
|
+
return this.pool.connect();
|
|
179
|
+
}
|
|
180
|
+
/**
|
|
181
|
+
* Execute a query with optional parameters
|
|
182
|
+
* @param text - SQL query text
|
|
183
|
+
* @param params - Query parameters
|
|
184
|
+
* @param client - Optional client connection (for transactions)
|
|
185
|
+
* @returns Query result
|
|
186
|
+
*/
|
|
187
|
+
async query(text, params = [], client = null) {
|
|
188
|
+
const queryClient = client ?? this.pool;
|
|
189
|
+
if (!queryClient) {
|
|
190
|
+
throw new Error('DAL not connected. Call connect() first.');
|
|
191
|
+
}
|
|
192
|
+
try {
|
|
193
|
+
const start = Date.now();
|
|
194
|
+
const result = await queryClient.query(text, params);
|
|
195
|
+
const duration = Date.now() - start;
|
|
196
|
+
debug.db(`Query executed in ${duration}ms: ${text.substring(0, 100)}...`);
|
|
197
|
+
return result;
|
|
198
|
+
}
|
|
199
|
+
catch (error) {
|
|
200
|
+
// Attach the SQL text (values are bound separately) but never the
|
|
201
|
+
// parameter values, since errors are often logged or reported upstream
|
|
202
|
+
if (typeof error === 'object' && error) {
|
|
203
|
+
error.query = text;
|
|
204
|
+
}
|
|
205
|
+
debug.error(`Query error: ${error.message}`);
|
|
206
|
+
debug.error(`Query text: ${text}`);
|
|
207
|
+
debug.error(`Query params: ${describeQueryParams(params)}`);
|
|
208
|
+
throw error;
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
/**
|
|
212
|
+
* Execute a transaction with automatic rollback on error
|
|
213
|
+
* @param callback - Function to execute within transaction
|
|
214
|
+
* @returns Result of the callback function
|
|
215
|
+
*/
|
|
216
|
+
async transaction(callback) {
|
|
217
|
+
const client = await this.getConnection();
|
|
218
|
+
// Set when the client can no longer be trusted, so the pool discards it
|
|
219
|
+
let releaseError;
|
|
220
|
+
try {
|
|
221
|
+
await client.query('BEGIN');
|
|
222
|
+
debug.db('Transaction started');
|
|
223
|
+
const result = await callback(client);
|
|
224
|
+
await client.query('COMMIT');
|
|
225
|
+
debug.db('Transaction committed');
|
|
226
|
+
return result;
|
|
227
|
+
}
|
|
228
|
+
catch (error) {
|
|
229
|
+
try {
|
|
230
|
+
await client.query('ROLLBACK');
|
|
231
|
+
}
|
|
232
|
+
catch (rollbackError) {
|
|
233
|
+
// Report the original failure, not the rollback's
|
|
234
|
+
releaseError =
|
|
235
|
+
rollbackError instanceof Error ? rollbackError : new Error(String(rollbackError));
|
|
236
|
+
debug.error(`Transaction rollback failed: ${releaseError.message}`);
|
|
237
|
+
}
|
|
238
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
239
|
+
debug.db(`Transaction rolled back due to error: ${message}`);
|
|
240
|
+
throw error;
|
|
241
|
+
}
|
|
242
|
+
finally {
|
|
243
|
+
client.release(releaseError);
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
/**
|
|
247
|
+
* Create a new model class
|
|
248
|
+
* @param name - Model name (table name)
|
|
249
|
+
* @param schema - Model schema definition
|
|
250
|
+
* @param options - Model options
|
|
251
|
+
* @returns Model constructor
|
|
252
|
+
*/
|
|
253
|
+
createModel(name, schema, options = {}) {
|
|
254
|
+
const { registryKey, ...modelOptions } = options || {};
|
|
255
|
+
const canonicalKey = typeof registryKey === 'string' ? registryKey : name;
|
|
256
|
+
const existing = this.modelRegistry.get(name) ||
|
|
257
|
+
(canonicalKey !== name ? this.modelRegistry.get(canonicalKey) : null);
|
|
258
|
+
if (existing) {
|
|
259
|
+
throw new Error(`Model '${canonicalKey}' already exists`);
|
|
260
|
+
}
|
|
261
|
+
const ModelClass = Model.createModel(name, schema, modelOptions, this);
|
|
262
|
+
this.modelRegistry.register(name, ModelClass, { key: canonicalKey });
|
|
263
|
+
debug.db(`Model '${name}' created`);
|
|
264
|
+
return ModelClass;
|
|
265
|
+
}
|
|
266
|
+
getModel(nameOrModel) {
|
|
267
|
+
const name = resolveModelLookupName(nameOrModel);
|
|
268
|
+
const model = this.modelRegistry.get(name);
|
|
269
|
+
if (!model) {
|
|
270
|
+
throw new Error(`Model '${name}' not found`);
|
|
271
|
+
}
|
|
272
|
+
return model;
|
|
273
|
+
}
|
|
274
|
+
/**
|
|
275
|
+
* Return a map of registered models keyed by canonical name
|
|
276
|
+
*/
|
|
277
|
+
getRegisteredModels() {
|
|
278
|
+
return this.modelRegistry.listByKey();
|
|
279
|
+
}
|
|
280
|
+
/**
|
|
281
|
+
* Expose the registry instance for advanced consumers
|
|
282
|
+
*/
|
|
283
|
+
getModelRegistry() {
|
|
284
|
+
return this.modelRegistry;
|
|
285
|
+
}
|
|
286
|
+
/**
|
|
287
|
+
* Run database migrations
|
|
288
|
+
* @param migrationsPath - Path to migration files
|
|
289
|
+
*/
|
|
290
|
+
async migrate(migrationsPath = 'migrations') {
|
|
291
|
+
debug.db('Running database migrations...');
|
|
292
|
+
try {
|
|
293
|
+
// Create migrations table if it doesn't exist
|
|
294
|
+
await this.query(`
|
|
295
|
+
CREATE TABLE IF NOT EXISTS migrations (
|
|
296
|
+
id SERIAL PRIMARY KEY,
|
|
297
|
+
filename VARCHAR(255) NOT NULL UNIQUE,
|
|
298
|
+
executed_at TIMESTAMP WITH TIME ZONE DEFAULT NOW()
|
|
299
|
+
)
|
|
300
|
+
`);
|
|
301
|
+
// Get list of migration files
|
|
302
|
+
const migrationFiles = await fs.readdir(migrationsPath);
|
|
303
|
+
const sqlFiles = migrationFiles.filter(file => file.endsWith('.sql')).sort();
|
|
304
|
+
// Get already executed migrations
|
|
305
|
+
const executedResult = await this.query('SELECT filename FROM migrations');
|
|
306
|
+
const executedMigrations = new Set(executedResult.rows.map(row => row.filename));
|
|
307
|
+
// Execute pending migrations
|
|
308
|
+
for (const filename of sqlFiles) {
|
|
309
|
+
if (!executedMigrations.has(filename)) {
|
|
310
|
+
debug.db(`Executing migration: ${filename}`);
|
|
311
|
+
const migrationPath = path.join(migrationsPath, filename);
|
|
312
|
+
const migrationSQL = await fs.readFile(migrationPath, 'utf8');
|
|
313
|
+
await this.transaction(async (client) => {
|
|
314
|
+
// Execute the migration
|
|
315
|
+
await client.query(migrationSQL);
|
|
316
|
+
// Record the migration as executed
|
|
317
|
+
await client.query('INSERT INTO migrations (filename) VALUES ($1)', [filename]);
|
|
318
|
+
});
|
|
319
|
+
debug.db(`Migration completed: ${filename}`);
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
debug.db('All migrations completed');
|
|
323
|
+
}
|
|
324
|
+
catch (error) {
|
|
325
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
326
|
+
debug.error(`Migration failed: ${message}`);
|
|
327
|
+
debug.error({ error: error instanceof Error ? error : new Error(message) });
|
|
328
|
+
throw error;
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
/**
|
|
332
|
+
* Rollback the last migration (if supported)
|
|
333
|
+
*/
|
|
334
|
+
async rollback(migrationsPath = 'migrations') {
|
|
335
|
+
debug.db('Rolling back last migration...');
|
|
336
|
+
const downDir = path.join(migrationsPath, 'down');
|
|
337
|
+
try {
|
|
338
|
+
const result = await this.query('SELECT filename FROM migrations ORDER BY executed_at DESC, id DESC LIMIT 1');
|
|
339
|
+
const lastMigration = result.rows[0]?.filename;
|
|
340
|
+
if (!lastMigration) {
|
|
341
|
+
debug.db('No migrations to roll back');
|
|
342
|
+
return;
|
|
343
|
+
}
|
|
344
|
+
const downPath = path.join(downDir, lastMigration);
|
|
345
|
+
let downSQL;
|
|
346
|
+
try {
|
|
347
|
+
downSQL = await fs.readFile(downPath, 'utf8');
|
|
348
|
+
}
|
|
349
|
+
catch (_error) {
|
|
350
|
+
const message = `Down migration not found for ${lastMigration} at ${downPath}`;
|
|
351
|
+
debug.error(message);
|
|
352
|
+
throw new Error(message);
|
|
353
|
+
}
|
|
354
|
+
await this.transaction(async (client) => {
|
|
355
|
+
await client.query(downSQL);
|
|
356
|
+
await client.query('DELETE FROM migrations WHERE filename = $1', [lastMigration]);
|
|
357
|
+
});
|
|
358
|
+
debug.db(`Rolled back migration: ${lastMigration}`);
|
|
359
|
+
}
|
|
360
|
+
catch (error) {
|
|
361
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
362
|
+
debug.error(`Rollback failed: ${message}`);
|
|
363
|
+
debug.error({ error: error instanceof Error ? error : new Error(message) });
|
|
364
|
+
throw error;
|
|
365
|
+
}
|
|
366
|
+
}
|
|
367
|
+
/**
|
|
368
|
+
* Check if the DAL is connected
|
|
369
|
+
*/
|
|
370
|
+
isConnected() {
|
|
371
|
+
return Boolean(this._connected && this.pool && !this.pool.ended);
|
|
372
|
+
}
|
|
373
|
+
/**
|
|
374
|
+
* Get pool statistics
|
|
375
|
+
*/
|
|
376
|
+
getPoolStats() {
|
|
377
|
+
if (!this.pool) {
|
|
378
|
+
return null;
|
|
379
|
+
}
|
|
380
|
+
return {
|
|
381
|
+
totalCount: this.pool.totalCount,
|
|
382
|
+
idleCount: this.pool.idleCount,
|
|
383
|
+
waitingCount: this.pool.waitingCount,
|
|
384
|
+
};
|
|
385
|
+
}
|
|
386
|
+
}
|
|
387
|
+
export { DataAccessLayer };
|
|
388
|
+
export default DataAccessLayer;
|
|
389
|
+
//# sourceMappingURL=data-access-layer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"data-access-layer.js","sourceRoot":"","sources":["../../src/lib/data-access-layer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,IAAI,EAAE,EAAE,MAAM,SAAS,CAAC;AACzC,OAAO,IAAI,MAAM,WAAW,CAAC;AAE7B,OAAO,EAAE,IAAI,EAAE,MAAM,IAAI,CAAC;AAC1B,OAAO,QAAQ,MAAM,gBAAgB,CAAC;AAEtC,OAAO,KAAK,MAAM,YAAY,CAAC;AAC/B,OAAO,EAAE,uBAAuB,EAAE,MAAM,mBAAmB,CAAC;AAE5D,OAAO,aAAa,EAAE,EAAE,qBAAqB,EAAE,MAAM,qBAAqB,CAAC;AAO3E,OAAO,QAAQ,MAAM,eAAe,CAAC;AACrC,OAAO,EAAE,KAAK,EAAE,MAAM,cAAc,CAAC;AACrC,OAAO,KAAK,MAAM,WAAW,CAAC;AAI9B;;;GAGG;AACH,SAAS,sBAAsB,CAAC,KAAc;IAC5C,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;QAC9B,OAAO,KAAK,CAAC;IACf,CAAC;IAED,MAAM,eAAe,GAAG,uBAAuB,CAAC,KAAK,CAAC,CAAC;IACvD,IAAI,eAAe,KAAK,SAAS,EAAE,CAAC;QAClC,OAAO,eAAe,CAAC;IACzB,CAAC;IAED,MAAM,WAAW,GAAG,qBAAqB,CAAC,KAAK,CAAC,CAAC;IACjD,IAAI,WAAW,KAAK,SAAS,EAAE,CAAC;QAC9B,OAAO,WAAW,CAAC;IACrB,CAAC;IAED,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC;QACzE,MAAM,EAAE,SAAS,EAAE,GAAG,KAAgC,CAAC;QACvD,IAAI,OA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