@memberjunction/codegen-lib 5.41.0 → 5.43.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.
- package/README.md +1 -1
- package/dist/Config/config.d.ts +132 -7
- package/dist/Config/config.d.ts.map +1 -1
- package/dist/Config/config.js +193 -15
- package/dist/Config/config.js.map +1 -1
- package/dist/Config/db-connection.d.ts +49 -7
- package/dist/Config/db-connection.d.ts.map +1 -1
- package/dist/Config/db-connection.js +87 -37
- package/dist/Config/db-connection.js.map +1 -1
- package/dist/Config/pg-connection.d.ts +58 -0
- package/dist/Config/pg-connection.d.ts.map +1 -0
- package/dist/Config/pg-connection.js +100 -0
- package/dist/Config/pg-connection.js.map +1 -0
- package/dist/Database/codeGenDatabaseProvider.d.ts +81 -1
- package/dist/Database/codeGenDatabaseProvider.d.ts.map +1 -1
- package/dist/Database/codeGenDatabaseProvider.js +45 -0
- package/dist/Database/codeGenDatabaseProvider.js.map +1 -1
- package/dist/Database/manage-metadata.d.ts +26 -1
- package/dist/Database/manage-metadata.d.ts.map +1 -1
- package/dist/Database/manage-metadata.js +101 -2
- package/dist/Database/manage-metadata.js.map +1 -1
- package/dist/Database/providers/postgresql/PostgreSQLCodeGenProvider.d.ts +25 -1
- package/dist/Database/providers/postgresql/PostgreSQLCodeGenProvider.d.ts.map +1 -1
- package/dist/Database/providers/postgresql/PostgreSQLCodeGenProvider.js +80 -6
- package/dist/Database/providers/postgresql/PostgreSQLCodeGenProvider.js.map +1 -1
- package/dist/Database/providers/postgresql/metadataSupportObjects.d.ts +24 -0
- package/dist/Database/providers/postgresql/metadataSupportObjects.d.ts.map +1 -0
- package/dist/Database/providers/postgresql/metadataSupportObjects.js +650 -0
- package/dist/Database/providers/postgresql/metadataSupportObjects.js.map +1 -0
- package/dist/Database/providers/sqlserver/SQLServerCodeGenProvider.d.ts +13 -1
- package/dist/Database/providers/sqlserver/SQLServerCodeGenProvider.d.ts.map +1 -1
- package/dist/Database/providers/sqlserver/SQLServerCodeGenProvider.js +39 -3
- package/dist/Database/providers/sqlserver/SQLServerCodeGenProvider.js.map +1 -1
- package/dist/Database/sql_codegen.d.ts.map +1 -1
- package/dist/Database/sql_codegen.js +12 -8
- package/dist/Database/sql_codegen.js.map +1 -1
- package/dist/Misc/action_subclasses_codegen.d.ts.map +1 -1
- package/dist/Misc/action_subclasses_codegen.js +3 -1
- package/dist/Misc/action_subclasses_codegen.js.map +1 -1
- package/dist/Misc/remote_operations_codegen.d.ts +54 -0
- package/dist/Misc/remote_operations_codegen.d.ts.map +1 -0
- package/dist/Misc/remote_operations_codegen.js +186 -0
- package/dist/Misc/remote_operations_codegen.js.map +1 -0
- package/dist/Misc/runCommand.d.ts.map +1 -1
- package/dist/Misc/runCommand.js +8 -3
- package/dist/Misc/runCommand.js.map +1 -1
- package/dist/Misc/status_logging.d.ts +2 -0
- package/dist/Misc/status_logging.d.ts.map +1 -1
- package/dist/Misc/status_logging.js +12 -1
- package/dist/Misc/status_logging.js.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/plugins/index.d.ts +35 -0
- package/dist/plugins/index.d.ts.map +1 -0
- package/dist/plugins/index.js +100 -0
- package/dist/plugins/index.js.map +1 -0
- package/dist/runCodeGen.d.ts +42 -25
- package/dist/runCodeGen.d.ts.map +1 -1
- package/dist/runCodeGen.js +140 -86
- package/dist/runCodeGen.js.map +1 -1
- package/package.json +32 -19
|
@@ -1,21 +1,63 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
*
|
|
4
|
-
*
|
|
2
|
+
* SQL Server-specific connection configuration and management for
|
|
3
|
+
* MemberJunction CodeGen. Provides the lazy mssql pool used by the
|
|
4
|
+
* SQL Server codegen path (see `runCodeGen.ts` → `setupSQLServerDataSource`).
|
|
5
|
+
*
|
|
6
|
+
* **Scope** — this file is intentionally SQL-Server-only; it imports `mssql`
|
|
7
|
+
* directly. The PostgreSQL codegen path (`setupPostgreSQLDataSource` in
|
|
8
|
+
* `runCodeGen.ts`) creates its `pg.Pool` inline and does not touch
|
|
9
|
+
* `MSSQLConnection` or `getSqlConfig`. A future refactor may unify both
|
|
10
|
+
* paths behind the existing `CodeGenDatabaseProvider` factory; for now the
|
|
11
|
+
* SQL Server and PostgreSQL halves stay separate.
|
|
12
|
+
*
|
|
13
|
+
* **Lazy resolution** — the mssql config is built lazily on the first call
|
|
14
|
+
* to {@link MSSQLConnection} instead of at module load. The previous
|
|
15
|
+
* implementation destructured `configInfo` at module load time, capturing
|
|
16
|
+
* empty/default values *before* `initializeConfig()` had a chance to
|
|
17
|
+
* populate the live config (a real race when any caller does
|
|
18
|
+
* `await import('@memberjunction/codegen-lib')` and then `initializeConfig()`
|
|
19
|
+
* afterward). Lazy resolution fixes the race so `mj codegen` and `mj install`'s
|
|
20
|
+
* codegen phase pick up the actual `.env` and `mj.config.cjs` values.
|
|
5
21
|
*/
|
|
6
22
|
import mssql from 'mssql';
|
|
7
23
|
/**
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
24
|
+
* Build the mssql config object from the current `configInfo`. Called from
|
|
25
|
+
* {@link MSSQLConnection} on each cold-start so it reflects the values that
|
|
26
|
+
* are present *after* `initializeConfig()` has run, not the empty defaults
|
|
27
|
+
* that may have been visible at module load time.
|
|
28
|
+
*
|
|
29
|
+
* Exported for unit-test access to the `codegenPool.statementTimeoutMs` →
|
|
30
|
+
* `dbRequestTimeout` → 120000 precedence chain. Production code uses
|
|
31
|
+
* {@link MSSQLConnection} (which caches the resolved config + pool); this
|
|
32
|
+
* export gives tests a pure-function entry point without forcing them to
|
|
33
|
+
* mock `mssql.connect`.
|
|
11
34
|
*/
|
|
12
|
-
export declare
|
|
35
|
+
export declare function buildSqlConfig(): mssql.config;
|
|
13
36
|
/**
|
|
14
37
|
* Gets or creates a SQL Server connection pool for database operations.
|
|
15
38
|
* Uses singleton pattern to reuse the same connection pool across multiple
|
|
16
39
|
* code generation operations for better performance.
|
|
40
|
+
*
|
|
41
|
+
* The mssql config is built **at first connection time** so that
|
|
42
|
+
* `initializeConfig()` has had a chance to populate `configInfo` from the
|
|
43
|
+
* user's `.env` and `mj.config.cjs`. Building it at module load (the prior
|
|
44
|
+
* behavior) captured stale empty values and triggered
|
|
45
|
+
* `"config.server property is required"` at codegen time.
|
|
46
|
+
*
|
|
17
47
|
* @returns Promise resolving to the mssql ConnectionPool instance
|
|
18
48
|
* @throws Error if connection fails
|
|
19
49
|
*/
|
|
20
50
|
export declare function MSSQLConnection(): Promise<mssql.ConnectionPool>;
|
|
51
|
+
/**
|
|
52
|
+
* Returns the resolved mssql config used by the active connection pool, or
|
|
53
|
+
* `undefined` if {@link MSSQLConnection} has not been called yet. Use this
|
|
54
|
+
* when you need to read connection details (server, port, instance,
|
|
55
|
+
* database) for logging or diagnostics.
|
|
56
|
+
*
|
|
57
|
+
* Always call {@link MSSQLConnection} before relying on this accessor in
|
|
58
|
+
* the same code path — the config is populated as a side effect of opening
|
|
59
|
+
* the pool. (`await MSSQLConnection()` followed by `getSqlConfig()` is
|
|
60
|
+
* guaranteed to return the live config.)
|
|
61
|
+
*/
|
|
62
|
+
export declare function getSqlConfig(): mssql.config | undefined;
|
|
21
63
|
//# sourceMappingURL=db-connection.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"db-connection.d.ts","sourceRoot":"","sources":["../../src/Config/db-connection.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"db-connection.d.ts","sourceRoot":"","sources":["../../src/Config/db-connection.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAEH,OAAO,KAAK,MAAM,OAAO,CAAC;AAG1B;;;;;;;;;;;GAWG;AACH,wBAAgB,cAAc,IAAI,KAAK,CAAC,MAAM,CAwC7C;AAaD;;;;;;;;;;;;;GAaG;AACH,wBAAsB,eAAe,IAAI,OAAO,CAAC,KAAK,CAAC,cAAc,CAAC,CAMrE;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,YAAY,IAAI,KAAK,CAAC,MAAM,GAAG,SAAS,CAEvD"}
|
|
@@ -1,59 +1,109 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
*
|
|
4
|
-
*
|
|
2
|
+
* SQL Server-specific connection configuration and management for
|
|
3
|
+
* MemberJunction CodeGen. Provides the lazy mssql pool used by the
|
|
4
|
+
* SQL Server codegen path (see `runCodeGen.ts` → `setupSQLServerDataSource`).
|
|
5
|
+
*
|
|
6
|
+
* **Scope** — this file is intentionally SQL-Server-only; it imports `mssql`
|
|
7
|
+
* directly. The PostgreSQL codegen path (`setupPostgreSQLDataSource` in
|
|
8
|
+
* `runCodeGen.ts`) creates its `pg.Pool` inline and does not touch
|
|
9
|
+
* `MSSQLConnection` or `getSqlConfig`. A future refactor may unify both
|
|
10
|
+
* paths behind the existing `CodeGenDatabaseProvider` factory; for now the
|
|
11
|
+
* SQL Server and PostgreSQL halves stay separate.
|
|
12
|
+
*
|
|
13
|
+
* **Lazy resolution** — the mssql config is built lazily on the first call
|
|
14
|
+
* to {@link MSSQLConnection} instead of at module load. The previous
|
|
15
|
+
* implementation destructured `configInfo` at module load time, capturing
|
|
16
|
+
* empty/default values *before* `initializeConfig()` had a chance to
|
|
17
|
+
* populate the live config (a real race when any caller does
|
|
18
|
+
* `await import('@memberjunction/codegen-lib')` and then `initializeConfig()`
|
|
19
|
+
* afterward). Lazy resolution fixes the race so `mj codegen` and `mj install`'s
|
|
20
|
+
* codegen phase pick up the actual `.env` and `mj.config.cjs` values.
|
|
5
21
|
*/
|
|
6
22
|
import mssql from 'mssql';
|
|
7
23
|
import { configInfo } from './config.js';
|
|
8
|
-
/** Extract database connection parameters from configuration */
|
|
9
|
-
const { dbDatabase, dbHost, codeGenPassword, dbPort, codeGenLogin, dbInstanceName, dbTrustServerCertificate, dbRequestTimeout } = configInfo;
|
|
10
24
|
/**
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
25
|
+
* Build the mssql config object from the current `configInfo`. Called from
|
|
26
|
+
* {@link MSSQLConnection} on each cold-start so it reflects the values that
|
|
27
|
+
* are present *after* `initializeConfig()` has run, not the empty defaults
|
|
28
|
+
* that may have been visible at module load time.
|
|
29
|
+
*
|
|
30
|
+
* Exported for unit-test access to the `codegenPool.statementTimeoutMs` →
|
|
31
|
+
* `dbRequestTimeout` → 120000 precedence chain. Production code uses
|
|
32
|
+
* {@link MSSQLConnection} (which caches the resolved config + pool); this
|
|
33
|
+
* export gives tests a pure-function entry point without forcing them to
|
|
34
|
+
* mock `mssql.connect`.
|
|
14
35
|
*/
|
|
15
|
-
export
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
}
|
|
36
|
+
export function buildSqlConfig() {
|
|
37
|
+
const { dbDatabase, dbHost, codeGenPassword, dbPort, codeGenLogin, dbInstanceName, dbTrustServerCertificate, dbRequestTimeout, codegenPool, } = configInfo;
|
|
38
|
+
// Resolve the request timeout from the cross-platform knob first, then fall
|
|
39
|
+
// back to the legacy SQL-Server-only `dbRequestTimeout`, then to mssql's
|
|
40
|
+
// 120000ms default. Keeps existing configs working while the unified
|
|
41
|
+
// `codegenPool.statementTimeoutMs` becomes the canonical knob for both
|
|
42
|
+
// providers.
|
|
43
|
+
const requestTimeout = codegenPool?.statementTimeoutMs ?? dbRequestTimeout ?? 120000;
|
|
44
|
+
return {
|
|
45
|
+
user: codeGenLogin,
|
|
46
|
+
password: codeGenPassword,
|
|
47
|
+
server: dbHost,
|
|
48
|
+
database: dbDatabase,
|
|
49
|
+
port: dbPort,
|
|
50
|
+
options: {
|
|
51
|
+
/**
|
|
52
|
+
* Request timeout for long-running CodeGen queries. Resolved from
|
|
53
|
+
* `codegenPool.statementTimeoutMs` (cross-platform, preferred) → the legacy
|
|
54
|
+
* `dbRequestTimeout` (SQL Server only) / `MJ_CODEGEN_REQUEST_TIMEOUT` env
|
|
55
|
+
* var → mssql's 120000ms (2 min) default. Bump when steps like
|
|
56
|
+
* spUpdateExistingEntityFieldsFromSchema run beyond the default.
|
|
57
|
+
*/
|
|
58
|
+
requestTimeout,
|
|
59
|
+
encrypt: true,
|
|
60
|
+
instanceName: dbInstanceName && dbInstanceName.trim().length > 0 ? dbInstanceName : undefined,
|
|
61
|
+
trustServerCertificate: dbTrustServerCertificate === 'Y',
|
|
62
|
+
},
|
|
63
|
+
};
|
|
64
|
+
}
|
|
42
65
|
/**
|
|
43
|
-
*
|
|
66
|
+
* Module-internal cache for the resolved mssql config. Populated on first
|
|
67
|
+
* call to {@link MSSQLConnection}. Read via the {@link getSqlConfig}
|
|
68
|
+
* accessor — never exported directly so callers cannot observe (or depend
|
|
69
|
+
* on) the mutable-`let` shape.
|
|
44
70
|
*/
|
|
71
|
+
let _sqlConfig;
|
|
72
|
+
/** Cached connection pool instance for reuse across code generation operations */
|
|
45
73
|
let _pool;
|
|
46
74
|
/**
|
|
47
75
|
* Gets or creates a SQL Server connection pool for database operations.
|
|
48
76
|
* Uses singleton pattern to reuse the same connection pool across multiple
|
|
49
77
|
* code generation operations for better performance.
|
|
78
|
+
*
|
|
79
|
+
* The mssql config is built **at first connection time** so that
|
|
80
|
+
* `initializeConfig()` has had a chance to populate `configInfo` from the
|
|
81
|
+
* user's `.env` and `mj.config.cjs`. Building it at module load (the prior
|
|
82
|
+
* behavior) captured stale empty values and triggered
|
|
83
|
+
* `"config.server property is required"` at codegen time.
|
|
84
|
+
*
|
|
50
85
|
* @returns Promise resolving to the mssql ConnectionPool instance
|
|
51
86
|
* @throws Error if connection fails
|
|
52
87
|
*/
|
|
53
88
|
export async function MSSQLConnection() {
|
|
54
89
|
if (!_pool) {
|
|
55
|
-
|
|
90
|
+
_sqlConfig = buildSqlConfig();
|
|
91
|
+
_pool = await mssql.connect(_sqlConfig);
|
|
56
92
|
}
|
|
57
93
|
return _pool;
|
|
58
94
|
}
|
|
95
|
+
/**
|
|
96
|
+
* Returns the resolved mssql config used by the active connection pool, or
|
|
97
|
+
* `undefined` if {@link MSSQLConnection} has not been called yet. Use this
|
|
98
|
+
* when you need to read connection details (server, port, instance,
|
|
99
|
+
* database) for logging or diagnostics.
|
|
100
|
+
*
|
|
101
|
+
* Always call {@link MSSQLConnection} before relying on this accessor in
|
|
102
|
+
* the same code path — the config is populated as a side effect of opening
|
|
103
|
+
* the pool. (`await MSSQLConnection()` followed by `getSqlConfig()` is
|
|
104
|
+
* guaranteed to return the live config.)
|
|
105
|
+
*/
|
|
106
|
+
export function getSqlConfig() {
|
|
107
|
+
return _sqlConfig;
|
|
108
|
+
}
|
|
59
109
|
//# sourceMappingURL=db-connection.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"db-connection.js","sourceRoot":"","sources":["../../src/Config/db-connection.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"db-connection.js","sourceRoot":"","sources":["../../src/Config/db-connection.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAEH,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AAEtC;;;;;;;;;;;GAWG;AACH,MAAM,UAAU,cAAc;IAC5B,MAAM,EACJ,UAAU,EACV,MAAM,EACN,eAAe,EACf,MAAM,EACN,YAAY,EACZ,cAAc,EACd,wBAAwB,EACxB,gBAAgB,EAChB,WAAW,GACZ,GAAG,UAAU,CAAC;IAEf,4EAA4E;IAC5E,yEAAyE;IACzE,qEAAqE;IACrE,uEAAuE;IACvE,aAAa;IACb,MAAM,cAAc,GAAG,WAAW,EAAE,kBAAkB,IAAI,gBAAgB,IAAI,MAAM,CAAC;IAErF,OAAO;QACL,IAAI,EAAE,YAAY;QAClB,QAAQ,EAAE,eAAe;QACzB,MAAM,EAAE,MAAM;QACd,QAAQ,EAAE,UAAU;QACpB,IAAI,EAAE,MAAM;QACZ,OAAO,EAAE;YACP;;;;;;eAMG;YACH,cAAc;YACd,OAAO,EAAE,IAAI;YACb,YAAY,EAAE,cAAc,IAAI,cAAc,CAAC,IAAI,EAAE,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,cAAc,CAAC,CAAC,CAAC,SAAS;YAC7F,sBAAsB,EAAE,wBAAwB,KAAK,GAAG;SACzD;KACF,CAAC;AACJ,CAAC;AAED;;;;;GAKG;AACH,IAAI,UAAoC,CAAC;AAEzC,kFAAkF;AAClF,IAAI,KAA2B,CAAC;AAEhC;;;;;;;;;;;;;GAaG;AACH,MAAM,CAAC,KAAK,UAAU,eAAe;IACnC,IAAI,CAAC,KAAK,EAAE,CAAC;QACX,UAAU,GAAG,cAAc,EAAE,CAAC;QAC9B,KAAK,GAAG,MAAM,KAAK,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC;IAC1C,CAAC;IACD,OAAO,KAAK,CAAC;AACf,CAAC;AAED;;;;;;;;;;GAUG;AACH,MAAM,UAAU,YAAY;IAC1B,OAAO,UAAU,CAAC;AACpB,CAAC"}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* PostgreSQL-specific connection configuration and management for
|
|
3
|
+
* MemberJunction CodeGen. Provides the lazy `pg.Pool` used by the
|
|
4
|
+
* PostgreSQL codegen path (see `PostgreSQLCodeGenProvider.SetupDataSource()`).
|
|
5
|
+
*
|
|
6
|
+
* **Scope** — this file is intentionally PostgreSQL-only; it imports
|
|
7
|
+
* `@memberjunction/postgresql-dataprovider`'s {@link PGConnectionManager}
|
|
8
|
+
* for the actual pool lifecycle. The SQL Server codegen path lives in
|
|
9
|
+
* `db-connection.ts` and is independent.
|
|
10
|
+
*
|
|
11
|
+
* **Lazy resolution** — the pg config is built lazily on the first call
|
|
12
|
+
* to {@link PGConnection} instead of at module load. This matches the
|
|
13
|
+
* shape of `db-connection.ts`'s {@link MSSQLConnection} and allows
|
|
14
|
+
* `initializeConfig()` to populate {@link configInfo} before the pool
|
|
15
|
+
* is created. Building the config at module load would capture empty
|
|
16
|
+
* defaults whenever a caller does `await import('@memberjunction/codegen-lib')`
|
|
17
|
+
* before `initializeConfig()` runs.
|
|
18
|
+
*
|
|
19
|
+
* **Module-level cache** — the resolved pool + config are cached at the
|
|
20
|
+
* module level so repeated CodeGen operations reuse the same pool. This
|
|
21
|
+
* matches SQL Server's `_pool` caching and replaces the previous
|
|
22
|
+
* function-local pool in `runCodeGen.setupPostgreSQLDataSource()` that
|
|
23
|
+
* created a fresh pool on every `setupDataSource()` call.
|
|
24
|
+
*/
|
|
25
|
+
import pg from 'pg';
|
|
26
|
+
import { type PGConnectionConfig } from '@memberjunction/postgresql-dataprovider';
|
|
27
|
+
/**
|
|
28
|
+
* Get-or-create the PostgreSQL connection pool for CodeGen operations.
|
|
29
|
+
* Builds the config at first call so `initializeConfig()` has had a chance
|
|
30
|
+
* to populate `configInfo`. The optional `statement_timeout` GUC (via
|
|
31
|
+
* {@link configInfo.codegenPool.statementTimeoutMs}) is carried in the libpq
|
|
32
|
+
* startup options assembled by {@link buildPgConfig} — see its docstring for
|
|
33
|
+
* why the startup-option path is preferred over a runtime `connect` listener.
|
|
34
|
+
*
|
|
35
|
+
* @returns Promise resolving to the pg.Pool from the underlying manager.
|
|
36
|
+
* @throws Error if connection fails.
|
|
37
|
+
*/
|
|
38
|
+
export declare function PGConnection(): Promise<pg.Pool>;
|
|
39
|
+
/**
|
|
40
|
+
* Returns the resolved {@link PGConnectionConfig} used by the active pool,
|
|
41
|
+
* or `undefined` if {@link PGConnection} has not been called yet. Use this
|
|
42
|
+
* when you need to read connection details (host, port, database) for
|
|
43
|
+
* logging or diagnostics — the same pattern as `getSqlConfig()` for SQL
|
|
44
|
+
* Server.
|
|
45
|
+
*
|
|
46
|
+
* Always call {@link PGConnection} before relying on this accessor in the
|
|
47
|
+
* same code path — the config is populated as a side effect of opening the
|
|
48
|
+
* pool. (`await PGConnection()` followed by `getPgConfig()` is guaranteed
|
|
49
|
+
* to return the live config.)
|
|
50
|
+
*/
|
|
51
|
+
export declare function getPgConfig(): PGConnectionConfig | undefined;
|
|
52
|
+
/**
|
|
53
|
+
* Closes the underlying connection manager + pool. Safe to call multiple
|
|
54
|
+
* times. Used by tests and by long-running processes that need explicit
|
|
55
|
+
* cleanup; production CodeGen runs let the process exit handle teardown.
|
|
56
|
+
*/
|
|
57
|
+
export declare function ClosePGConnection(): Promise<void>;
|
|
58
|
+
//# sourceMappingURL=pg-connection.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pg-connection.d.ts","sourceRoot":"","sources":["../../src/Config/pg-connection.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,OAAO,EAAE,MAAM,IAAI,CAAC;AACpB,OAAO,EAAuB,KAAK,kBAAkB,EAAE,MAAM,yCAAyC,CAAC;AA4DvG;;;;;;;;;;GAUG;AACH,wBAAsB,YAAY,IAAI,OAAO,CAAC,EAAE,CAAC,IAAI,CAAC,CAOrD;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,WAAW,IAAI,kBAAkB,GAAG,SAAS,CAE5D;AAED;;;;GAIG;AACH,wBAAsB,iBAAiB,IAAI,OAAO,CAAC,IAAI,CAAC,CAMvD"}
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import { PGConnectionManager } from '@memberjunction/postgresql-dataprovider';
|
|
2
|
+
import { configInfo } from './config.js';
|
|
3
|
+
/**
|
|
4
|
+
* Build the {@link PGConnectionConfig} from the current `configInfo`. Called
|
|
5
|
+
* lazily from {@link PGConnection} so values are read AFTER `initializeConfig()`
|
|
6
|
+
* has run. {@link configInfo.codegenPool} supplies optional pool-size, timeout,
|
|
7
|
+
* and SSL knobs; when omitted, the pre-multi-provider-refactor inline `pg.Pool`
|
|
8
|
+
* behavior is preserved — no SSL by default (matches the historical local-codegen
|
|
9
|
+
* default), no startup options, and `PGConnectionManager`'s own pool-size defaults
|
|
10
|
+
* (20 max, 2 min).
|
|
11
|
+
*
|
|
12
|
+
* `statementTimeoutMs` is carried via the libpq `-c statement_timeout=<ms>`
|
|
13
|
+
* startup option rather than a runtime `SET` on the pool's `connect` event.
|
|
14
|
+
* The startup option is honored by every backend including the verify-SELECT-1
|
|
15
|
+
* connection that `PGConnectionManager.Initialize()` opens — a runtime listener
|
|
16
|
+
* would attach AFTER that connection had already been created and released back
|
|
17
|
+
* into the pool, leaving the first pool client without the GUC.
|
|
18
|
+
*/
|
|
19
|
+
function buildPgConfig() {
|
|
20
|
+
const pool = configInfo.codegenPool;
|
|
21
|
+
// SSL: default to false (preserves the pre-refactor inline `pg.Pool` behavior
|
|
22
|
+
// where no `ssl` key was set → pg default OFF). Without this explicit `false`,
|
|
23
|
+
// `PGConnectionManager.Initialize()` would default SSL ON in `NODE_ENV=production`,
|
|
24
|
+
// breaking codegen against non-SSL/locally-bridged Postgres in production shells.
|
|
25
|
+
const ssl = pool?.ssl ?? false;
|
|
26
|
+
// statement_timeout via libpq startup option — applied server-side from
|
|
27
|
+
// connection #1, including the verify-SELECT-1 connection.
|
|
28
|
+
const stmtTimeoutMs = pool?.statementTimeoutMs;
|
|
29
|
+
const options = stmtTimeoutMs && stmtTimeoutMs > 0 ? `-c statement_timeout=${stmtTimeoutMs}` : undefined;
|
|
30
|
+
return {
|
|
31
|
+
Host: configInfo.dbHost,
|
|
32
|
+
Port: configInfo.dbPort,
|
|
33
|
+
Database: configInfo.dbDatabase,
|
|
34
|
+
User: configInfo.codeGenLogin,
|
|
35
|
+
Password: configInfo.codeGenPassword,
|
|
36
|
+
MJCoreSchemaName: configInfo.mjCoreSchema,
|
|
37
|
+
MaxConnections: pool?.max,
|
|
38
|
+
MinConnections: pool?.min,
|
|
39
|
+
IdleTimeoutMillis: pool?.idleTimeoutMillis,
|
|
40
|
+
ConnectionTimeoutMillis: pool?.connectionTimeoutMillis,
|
|
41
|
+
SSL: ssl,
|
|
42
|
+
Options: options,
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Module-internal cache for the resolved {@link PGConnectionConfig}. Populated
|
|
47
|
+
* on first call to {@link PGConnection}. Read via the {@link getPgConfig}
|
|
48
|
+
* accessor — never exported directly so callers cannot observe (or depend on)
|
|
49
|
+
* a mutable storage cell.
|
|
50
|
+
*/
|
|
51
|
+
let _pgConfig;
|
|
52
|
+
/** Cached connection manager instance shared across CodeGen operations. */
|
|
53
|
+
let _manager;
|
|
54
|
+
/**
|
|
55
|
+
* Get-or-create the PostgreSQL connection pool for CodeGen operations.
|
|
56
|
+
* Builds the config at first call so `initializeConfig()` has had a chance
|
|
57
|
+
* to populate `configInfo`. The optional `statement_timeout` GUC (via
|
|
58
|
+
* {@link configInfo.codegenPool.statementTimeoutMs}) is carried in the libpq
|
|
59
|
+
* startup options assembled by {@link buildPgConfig} — see its docstring for
|
|
60
|
+
* why the startup-option path is preferred over a runtime `connect` listener.
|
|
61
|
+
*
|
|
62
|
+
* @returns Promise resolving to the pg.Pool from the underlying manager.
|
|
63
|
+
* @throws Error if connection fails.
|
|
64
|
+
*/
|
|
65
|
+
export async function PGConnection() {
|
|
66
|
+
if (!_manager) {
|
|
67
|
+
_pgConfig = buildPgConfig();
|
|
68
|
+
_manager = new PGConnectionManager();
|
|
69
|
+
await _manager.Initialize(_pgConfig);
|
|
70
|
+
}
|
|
71
|
+
return _manager.Pool;
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Returns the resolved {@link PGConnectionConfig} used by the active pool,
|
|
75
|
+
* or `undefined` if {@link PGConnection} has not been called yet. Use this
|
|
76
|
+
* when you need to read connection details (host, port, database) for
|
|
77
|
+
* logging or diagnostics — the same pattern as `getSqlConfig()` for SQL
|
|
78
|
+
* Server.
|
|
79
|
+
*
|
|
80
|
+
* Always call {@link PGConnection} before relying on this accessor in the
|
|
81
|
+
* same code path — the config is populated as a side effect of opening the
|
|
82
|
+
* pool. (`await PGConnection()` followed by `getPgConfig()` is guaranteed
|
|
83
|
+
* to return the live config.)
|
|
84
|
+
*/
|
|
85
|
+
export function getPgConfig() {
|
|
86
|
+
return _pgConfig;
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Closes the underlying connection manager + pool. Safe to call multiple
|
|
90
|
+
* times. Used by tests and by long-running processes that need explicit
|
|
91
|
+
* cleanup; production CodeGen runs let the process exit handle teardown.
|
|
92
|
+
*/
|
|
93
|
+
export async function ClosePGConnection() {
|
|
94
|
+
if (_manager) {
|
|
95
|
+
await _manager.Close();
|
|
96
|
+
_manager = undefined;
|
|
97
|
+
_pgConfig = undefined;
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
//# sourceMappingURL=pg-connection.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pg-connection.js","sourceRoot":"","sources":["../../src/Config/pg-connection.ts"],"names":[],"mappings":"AAyBA,OAAO,EAAE,mBAAmB,EAA2B,MAAM,yCAAyC,CAAC;AACvG,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAEzC;;;;;;;;;;;;;;;GAeG;AACH,SAAS,aAAa;IACpB,MAAM,IAAI,GAAG,UAAU,CAAC,WAAW,CAAC;IAEpC,8EAA8E;IAC9E,+EAA+E;IAC/E,oFAAoF;IACpF,kFAAkF;IAClF,MAAM,GAAG,GAAG,IAAI,EAAE,GAAG,IAAI,KAAK,CAAC;IAE/B,wEAAwE;IACxE,2DAA2D;IAC3D,MAAM,aAAa,GAAG,IAAI,EAAE,kBAAkB,CAAC;IAC/C,MAAM,OAA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AC"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { EntityInfo, EntityFieldInfo } from '@memberjunction/core';
|
|
1
|
+
import { EntityInfo, EntityFieldInfo, IMetadataProvider, UserInfo } from '@memberjunction/core';
|
|
2
2
|
import { DatabasePlatform, SQLDialect } from '@memberjunction/sql-dialect';
|
|
3
3
|
/**
|
|
4
4
|
* Represents a single row from a query result.
|
|
@@ -128,6 +128,23 @@ export interface CodeGenConnection {
|
|
|
128
128
|
*/
|
|
129
129
|
beginTransaction(): Promise<CodeGenTransaction>;
|
|
130
130
|
}
|
|
131
|
+
/**
|
|
132
|
+
* Bundle returned by {@link CodeGenDatabaseProvider.SetupDataSource} that
|
|
133
|
+
* gives the orchestrator everything it needs to begin a CodeGen run:
|
|
134
|
+
* the per-platform metadata provider, a dialect-aware connection, the
|
|
135
|
+
* "owner" user used as the audit principal for generated rows, and a
|
|
136
|
+
* human-readable connection-info string for log output.
|
|
137
|
+
*/
|
|
138
|
+
export interface DataSourceResult {
|
|
139
|
+
/** The configured per-platform metadata provider (SQL Server or PostgreSQL). */
|
|
140
|
+
provider: IMetadataProvider;
|
|
141
|
+
/** Database-agnostic connection used by all platform-neutral CodeGen code. */
|
|
142
|
+
connection: CodeGenConnection;
|
|
143
|
+
/** The "owner" user (or the first available user) used for audit fields. */
|
|
144
|
+
currentUser: UserInfo;
|
|
145
|
+
/** Display-only connection summary (e.g. `host:port/database`). */
|
|
146
|
+
connectionInfo: string;
|
|
147
|
+
}
|
|
131
148
|
/**
|
|
132
149
|
* Union type for stored procedure / function types (Create, Update, Delete).
|
|
133
150
|
*/
|
|
@@ -218,6 +235,34 @@ export declare abstract class CodeGenDatabaseProvider {
|
|
|
218
235
|
* The database platform key (e.g., 'sqlserver', 'postgresql').
|
|
219
236
|
*/
|
|
220
237
|
abstract get PlatformKey(): DatabasePlatform;
|
|
238
|
+
/**
|
|
239
|
+
* Set up the per-platform data source for a CodeGen run: open a
|
|
240
|
+
* connection pool, configure the metadata provider, build the
|
|
241
|
+
* {@link CodeGenConnection}, and resolve the audit user.
|
|
242
|
+
*
|
|
243
|
+
* **Where this lives and why** — the orchestrator (`RunCodeGenBase`)
|
|
244
|
+
* used to switch on `configInfo.dbPlatform` inline and call private
|
|
245
|
+
* `setupSQLServerDataSource()` / `setupPostgreSQLDataSource()` methods.
|
|
246
|
+
* That bypassed the existing factory pattern (see e.g.
|
|
247
|
+
* `manage-metadata.ts`'s `get dbProvider()`, which dispatches via
|
|
248
|
+
* `MJGlobal.Instance.ClassFactory.CreateInstance(CodeGenDatabaseProvider, platform)`)
|
|
249
|
+
* and meant adding a third platform would require touching the
|
|
250
|
+
* orchestrator. Moving the setup here puts it behind the same
|
|
251
|
+
* factory: subclasses register via `@RegisterClass(CodeGenDatabaseProvider, '<platform>')`
|
|
252
|
+
* and the orchestrator just resolves + calls.
|
|
253
|
+
*
|
|
254
|
+
* Subclasses are responsible for:
|
|
255
|
+
* - opening their pool (typically via a module-cached helper such as
|
|
256
|
+
* `MSSQLConnection()` / `PGConnection()` so multiple `setupDataSource()`
|
|
257
|
+
* calls reuse the same pool)
|
|
258
|
+
* - configuring + setting their metadata provider via `SetProvider(...)`
|
|
259
|
+
* when appropriate
|
|
260
|
+
* - loading the audit user (currently SQL Server uses `UserCache`,
|
|
261
|
+
* PostgreSQL hand-queries `vwUsers`/`vwUserRoles` — see implementations
|
|
262
|
+
* for the deliberate asymmetry note)
|
|
263
|
+
* - emitting spinner status via `status_logging` helpers when desired
|
|
264
|
+
*/
|
|
265
|
+
abstract SetupDataSource(): Promise<DataSourceResult>;
|
|
221
266
|
/**
|
|
222
267
|
* Whether this dialect can handle a base view that LEFT-JOINs itself to read
|
|
223
268
|
* a virtual computed column (e.g. `vwRecordChanges` joining to itself for the
|
|
@@ -733,6 +778,22 @@ export declare abstract class CodeGenDatabaseProvider {
|
|
|
733
778
|
* @param mjCoreSchema The MJ core schema name.
|
|
734
779
|
*/
|
|
735
780
|
abstract getFixVirtualFieldNullabilitySQL(mjCoreSchema: string): string;
|
|
781
|
+
/**
|
|
782
|
+
* Returns DDL that creates/replaces the platform's metadata-management
|
|
783
|
+
* support objects (introspection views and the routines manage-metadata
|
|
784
|
+
* invokes via {@link callRoutineSQL}), or `null` when the platform ships
|
|
785
|
+
* them through migrations instead.
|
|
786
|
+
*
|
|
787
|
+
* These objects are CodeGen's own machinery — only CodeGen calls them —
|
|
788
|
+
* so platforms that return DDL here get it executed (idempotently) at the
|
|
789
|
+
* start of every manageMetadata run. That guarantees the objects can
|
|
790
|
+
* never be missing or version-skewed relative to the CodeGenLib code that
|
|
791
|
+
* calls them.
|
|
792
|
+
*
|
|
793
|
+
* SQL Server: returns `null` (objects ship in the baseline migrations).
|
|
794
|
+
* PostgreSQL: returns the full support-object DDL.
|
|
795
|
+
*/
|
|
796
|
+
getMetadataSupportObjectsSQL(_mjCoreSchema: string): string | null;
|
|
736
797
|
/**
|
|
737
798
|
* Executes a SQL file using the platform's native CLI tool (sqlcmd/psql).
|
|
738
799
|
* The implementation is responsible for reading connection configuration
|
|
@@ -866,4 +927,23 @@ export interface PhasedExecutionResult {
|
|
|
866
927
|
/** Underlying error when `success` is false. */
|
|
867
928
|
error?: Error;
|
|
868
929
|
}
|
|
930
|
+
/**
|
|
931
|
+
* Resolve the concrete {@link CodeGenDatabaseProvider} registered for a given
|
|
932
|
+
* platform via `MJGlobal.Instance.ClassFactory`. This is the single source of
|
|
933
|
+
* truth for platform dispatch — the orchestrator (`RunCodeGenBase.setupDataSource()`)
|
|
934
|
+
* delegates to this function rather than re-implementing the lookup. Tests
|
|
935
|
+
* import this function directly so they exercise the real dispatch logic
|
|
936
|
+
* instead of a transcribed copy.
|
|
937
|
+
*
|
|
938
|
+
* `ClassFactory.CreateInstance` returns the abstract base class itself on a
|
|
939
|
+
* missed registration lookup (it does not throw). We disambiguate by checking
|
|
940
|
+
* `constructor === CodeGenDatabaseProvider` and throw a descriptive error so
|
|
941
|
+
* the failure mode reads as "no provider registered" instead of a cryptic
|
|
942
|
+
* "is not a constructor" / "is not a function" downstream.
|
|
943
|
+
*
|
|
944
|
+
* @param platform The `dbPlatform` key — typically `'sqlserver'` or `'postgresql'`.
|
|
945
|
+
* @returns The resolved provider subclass instance.
|
|
946
|
+
* @throws Error if no provider is registered for the given platform.
|
|
947
|
+
*/
|
|
948
|
+
export declare function resolveCodeGenDatabaseProvider(platform: DatabasePlatform): CodeGenDatabaseProvider;
|
|
869
949
|
//# sourceMappingURL=codeGenDatabaseProvider.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"codeGenDatabaseProvider.d.ts","sourceRoot":"","sources":["../../src/Database/codeGenDatabaseProvider.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,eAAe,EAAwB,MAAM,sBAAsB,CAAC;
|
|
1
|
+
{"version":3,"file":"codeGenDatabaseProvider.d.ts","sourceRoot":"","sources":["../../src/Database/codeGenDatabaseProvider.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,eAAe,EAAwB,iBAAiB,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAEtH,OAAO,EAAE,gBAAgB,EAAE,UAAU,EAAE,MAAM,6BAA6B,CAAC;AAI3E;;;;;;;;GAQG;AAEH,MAAM,MAAM,eAAe,GAAG,GAAG,CAAC;AAElC;;;;GAIG;AACH,MAAM,WAAW,kBAAkB;IAC/B,uEAAuE;IACvE,SAAS,EAAE,eAAe,EAAE,CAAC;CAChC;AAED;;;GAGG;AACH,MAAM,WAAW,kBAAkB;IAC/B;;;;OAIG;IACH,KAAK,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,kBAAkB,CAAC,CAAC;IAEhD;;OAEG;IACH,MAAM,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;IAExB;;OAEG;IACH,QAAQ,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;CAC7B;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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AACH,wBAAgB,8BAA8B,CAAC,QAAQ,EAAE,gBAAgB,GAAG,uBAAuB,CAYlG"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { MJGlobal } from '@memberjunction/global';
|
|
1
2
|
/**
|
|
2
3
|
* Union type for stored procedure / function types (Create, Update, Delete).
|
|
3
4
|
*/
|
|
@@ -340,6 +341,24 @@ export class CodeGenDatabaseProvider {
|
|
|
340
341
|
get BatchSeparator() {
|
|
341
342
|
return this.Dialect.BatchSeparator();
|
|
342
343
|
}
|
|
344
|
+
/**
|
|
345
|
+
* Returns DDL that creates/replaces the platform's metadata-management
|
|
346
|
+
* support objects (introspection views and the routines manage-metadata
|
|
347
|
+
* invokes via {@link callRoutineSQL}), or `null` when the platform ships
|
|
348
|
+
* them through migrations instead.
|
|
349
|
+
*
|
|
350
|
+
* These objects are CodeGen's own machinery — only CodeGen calls them —
|
|
351
|
+
* so platforms that return DDL here get it executed (idempotently) at the
|
|
352
|
+
* start of every manageMetadata run. That guarantees the objects can
|
|
353
|
+
* never be missing or version-skewed relative to the CodeGenLib code that
|
|
354
|
+
* calls them.
|
|
355
|
+
*
|
|
356
|
+
* SQL Server: returns `null` (objects ship in the baseline migrations).
|
|
357
|
+
* PostgreSQL: returns the full support-object DDL.
|
|
358
|
+
*/
|
|
359
|
+
getMetadataSupportObjectsSQL(_mjCoreSchema) {
|
|
360
|
+
return null;
|
|
361
|
+
}
|
|
343
362
|
// ─── POST-RUN VALIDATION ─────────────────────────────────────────────
|
|
344
363
|
/**
|
|
345
364
|
* Returns a SQL query that lists every stored procedure / function name in
|
|
@@ -445,4 +464,30 @@ export class CodeGenDatabaseProvider {
|
|
|
445
464
|
return expected.filter(e => !existing.has(`${e.schema.toLowerCase()}.${e.expectedRoutine.toLowerCase()}`));
|
|
446
465
|
}
|
|
447
466
|
}
|
|
467
|
+
/**
|
|
468
|
+
* Resolve the concrete {@link CodeGenDatabaseProvider} registered for a given
|
|
469
|
+
* platform via `MJGlobal.Instance.ClassFactory`. This is the single source of
|
|
470
|
+
* truth for platform dispatch — the orchestrator (`RunCodeGenBase.setupDataSource()`)
|
|
471
|
+
* delegates to this function rather than re-implementing the lookup. Tests
|
|
472
|
+
* import this function directly so they exercise the real dispatch logic
|
|
473
|
+
* instead of a transcribed copy.
|
|
474
|
+
*
|
|
475
|
+
* `ClassFactory.CreateInstance` returns the abstract base class itself on a
|
|
476
|
+
* missed registration lookup (it does not throw). We disambiguate by checking
|
|
477
|
+
* `constructor === CodeGenDatabaseProvider` and throw a descriptive error so
|
|
478
|
+
* the failure mode reads as "no provider registered" instead of a cryptic
|
|
479
|
+
* "is not a constructor" / "is not a function" downstream.
|
|
480
|
+
*
|
|
481
|
+
* @param platform The `dbPlatform` key — typically `'sqlserver'` or `'postgresql'`.
|
|
482
|
+
* @returns The resolved provider subclass instance.
|
|
483
|
+
* @throws Error if no provider is registered for the given platform.
|
|
484
|
+
*/
|
|
485
|
+
export function resolveCodeGenDatabaseProvider(platform) {
|
|
486
|
+
const provider = MJGlobal.Instance.ClassFactory.CreateInstance(CodeGenDatabaseProvider, platform);
|
|
487
|
+
if (!provider || provider.constructor === CodeGenDatabaseProvider) {
|
|
488
|
+
throw new Error(`CodeGen database provider for dbPlatform='${platform}' not found. Ensure the corresponding ` +
|
|
489
|
+
`provider class is registered via @RegisterClass(CodeGenDatabaseProvider, '${platform}').`);
|
|
490
|
+
}
|
|
491
|
+
return provider;
|
|
492
|
+
}
|
|
448
493
|
//# sourceMappingURL=codeGenDatabaseProvider.js.map
|