emilsoftware-utilities 2.0.0-dev.3 → 2.0.0-dev.4
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/Orm.d.ts +5 -0
- package/dist/Orm.js +78 -13
- package/dist/Orm.js.map +1 -1
- package/dist/firebird-compat.d.ts +2 -0
- package/dist/firebird-compat.js +17 -11
- package/dist/firebird-compat.js.map +1 -1
- package/package.json +1 -1
package/dist/Orm.d.ts
CHANGED
|
@@ -1,9 +1,14 @@
|
|
|
1
1
|
import { Database, Options, Transaction } from "es-node-firebird";
|
|
2
2
|
export declare class Orm {
|
|
3
3
|
private static logger;
|
|
4
|
+
private static compatibilityProfileCache;
|
|
4
5
|
static quote(value: string): string;
|
|
5
6
|
private static getTimeoutMs;
|
|
6
7
|
private static createTimeoutError;
|
|
8
|
+
private static createCompatibilityCacheKey;
|
|
9
|
+
private static getProbeTimeoutMs;
|
|
10
|
+
private static reorderCandidatesWithCache;
|
|
11
|
+
private static createCompatibilitySummaryError;
|
|
7
12
|
private static detachQuietly;
|
|
8
13
|
private static attachOnceWithTimeout;
|
|
9
14
|
private static attachWithTimeout;
|
package/dist/Orm.js
CHANGED
|
@@ -53,8 +53,8 @@ class Orm {
|
|
|
53
53
|
return "\"" + value + "\"";
|
|
54
54
|
}
|
|
55
55
|
static getTimeoutMs(options) {
|
|
56
|
-
var _a, _b;
|
|
57
|
-
const candidate = (_b = (_a = options.connectTimeoutMs) !== null && _a !== void 0 ? _a : options.
|
|
56
|
+
var _a, _b, _c;
|
|
57
|
+
const candidate = (_c = (_b = (_a = options.connectTimeoutMs) !== null && _a !== void 0 ? _a : options.compatibilityTotalTimeoutMs) !== null && _b !== void 0 ? _b : options.connectTimeout) !== null && _c !== void 0 ? _c : 15000;
|
|
58
58
|
return Number.isFinite(candidate) && candidate > 0 ? Math.trunc(candidate) : 15000;
|
|
59
59
|
}
|
|
60
60
|
static createTimeoutError(stage, timeoutMs, options, query) {
|
|
@@ -63,6 +63,54 @@ class Orm {
|
|
|
63
63
|
const suffix = query ? ` | sql=${query.replace(/\s+/g, " ").trim()}` : "";
|
|
64
64
|
return new Error(`Timeout during Firebird ${stage} after ${timeoutMs} ms on ${target}${suffix}`);
|
|
65
65
|
}
|
|
66
|
+
static createCompatibilityCacheKey(options) {
|
|
67
|
+
var _a, _b, _c, _d;
|
|
68
|
+
return [
|
|
69
|
+
(_a = options.host) !== null && _a !== void 0 ? _a : "?",
|
|
70
|
+
(_b = options.port) !== null && _b !== void 0 ? _b : "?",
|
|
71
|
+
(_c = options.database) !== null && _c !== void 0 ? _c : "?",
|
|
72
|
+
(_d = options.user) !== null && _d !== void 0 ? _d : "?",
|
|
73
|
+
].join("|");
|
|
74
|
+
}
|
|
75
|
+
static getProbeTimeoutMs(options, candidateCount) {
|
|
76
|
+
const configured = options.compatibilityProbeTimeoutMs;
|
|
77
|
+
if (Number.isFinite(configured) && configured > 0) {
|
|
78
|
+
return Math.trunc(configured);
|
|
79
|
+
}
|
|
80
|
+
const totalTimeoutMs = this.getTimeoutMs(options);
|
|
81
|
+
if (candidateCount <= 1) {
|
|
82
|
+
return totalTimeoutMs;
|
|
83
|
+
}
|
|
84
|
+
return Math.max(2500, Math.min(5000, Math.trunc(totalTimeoutMs / candidateCount)));
|
|
85
|
+
}
|
|
86
|
+
static reorderCandidatesWithCache(options, candidates) {
|
|
87
|
+
const cacheKey = this.createCompatibilityCacheKey(options);
|
|
88
|
+
const cachedCandidate = this.compatibilityProfileCache.get(cacheKey);
|
|
89
|
+
if (!cachedCandidate) {
|
|
90
|
+
return candidates;
|
|
91
|
+
}
|
|
92
|
+
const ordered = [...candidates];
|
|
93
|
+
const cachedDescription = (0, firebird_compat_1.describeFirebirdCompatibilityOptions)(cachedCandidate);
|
|
94
|
+
const cachedIndex = ordered.findIndex((candidate) => (0, firebird_compat_1.describeFirebirdCompatibilityOptions)(candidate) === cachedDescription);
|
|
95
|
+
if (cachedIndex <= 0) {
|
|
96
|
+
return ordered;
|
|
97
|
+
}
|
|
98
|
+
const [matchedCandidate] = ordered.splice(cachedIndex, 1);
|
|
99
|
+
ordered.unshift(matchedCandidate);
|
|
100
|
+
return ordered;
|
|
101
|
+
}
|
|
102
|
+
static createCompatibilitySummaryError(options, attempts) {
|
|
103
|
+
var _a, _b, _c;
|
|
104
|
+
const target = `${(_a = options.host) !== null && _a !== void 0 ? _a : "?"}:${(_b = options.port) !== null && _b !== void 0 ? _b : "?"} -> ${(_c = options.database) !== null && _c !== void 0 ? _c : "?"}`;
|
|
105
|
+
const attemptsSummary = attempts
|
|
106
|
+
.map(({ candidate, error }) => {
|
|
107
|
+
var _a, _b;
|
|
108
|
+
const errorMessage = String((_b = (_a = error === null || error === void 0 ? void 0 : error.message) !== null && _a !== void 0 ? _a : error) !== null && _b !== void 0 ? _b : "Unknown error");
|
|
109
|
+
return `[${(0, firebird_compat_1.describeFirebirdCompatibilityOptions)(candidate)} => ${errorMessage}]`;
|
|
110
|
+
})
|
|
111
|
+
.join("; ");
|
|
112
|
+
return new Error(`Unable to attach Firebird database after compatibility probing on ${target}. Attempts: ${attemptsSummary}`);
|
|
113
|
+
}
|
|
66
114
|
static detachQuietly(db) {
|
|
67
115
|
return __awaiter(this, void 0, void 0, function* () {
|
|
68
116
|
if (!db) {
|
|
@@ -78,9 +126,8 @@ class Orm {
|
|
|
78
126
|
});
|
|
79
127
|
});
|
|
80
128
|
}
|
|
81
|
-
static attachOnceWithTimeout(options) {
|
|
129
|
+
static attachOnceWithTimeout(options, timeoutMs = this.getTimeoutMs(options)) {
|
|
82
130
|
return new Promise((resolve, reject) => {
|
|
83
|
-
const timeoutMs = this.getTimeoutMs(options);
|
|
84
131
|
let settled = false;
|
|
85
132
|
const timeoutId = setTimeout(() => {
|
|
86
133
|
if (settled) {
|
|
@@ -107,25 +154,42 @@ class Orm {
|
|
|
107
154
|
static attachWithTimeout(options) {
|
|
108
155
|
return __awaiter(this, void 0, void 0, function* () {
|
|
109
156
|
var _a;
|
|
110
|
-
const
|
|
111
|
-
|
|
157
|
+
const totalTimeoutMs = this.getTimeoutMs(options);
|
|
158
|
+
const candidates = this.reorderCandidatesWithCache(options, (0, firebird_compat_1.buildFirebirdCompatibilityCandidates)(options));
|
|
159
|
+
const probeTimeoutMs = this.getProbeTimeoutMs(options, candidates.length);
|
|
160
|
+
const startedAt = Date.now();
|
|
161
|
+
const attempts = [];
|
|
162
|
+
const cacheKey = this.createCompatibilityCacheKey(options);
|
|
112
163
|
for (let index = 0; index < candidates.length; index++) {
|
|
113
164
|
const candidate = candidates[index];
|
|
165
|
+
const elapsedMs = Date.now() - startedAt;
|
|
166
|
+
const remainingMs = totalTimeoutMs - elapsedMs;
|
|
167
|
+
if (remainingMs <= 0) {
|
|
168
|
+
break;
|
|
169
|
+
}
|
|
170
|
+
const attemptTimeoutMs = index === 0 && candidates.length === 1
|
|
171
|
+
? remainingMs
|
|
172
|
+
: Math.min(probeTimeoutMs, remainingMs);
|
|
114
173
|
try {
|
|
115
|
-
if (
|
|
116
|
-
this.logger.
|
|
174
|
+
if (candidates.length > 1) {
|
|
175
|
+
this.logger.info(`Firebird compatibility probe ${index + 1}/${candidates.length}: ${(0, firebird_compat_1.describeFirebirdCompatibilityOptions)(candidate)} (timeout ${attemptTimeoutMs} ms)`);
|
|
176
|
+
}
|
|
177
|
+
const db = yield this.attachOnceWithTimeout(candidate, attemptTimeoutMs);
|
|
178
|
+
this.compatibilityProfileCache.set(cacheKey, candidate);
|
|
179
|
+
if (candidates.length > 1) {
|
|
180
|
+
this.logger.info(`Firebird compatibility profile selected: ${(0, firebird_compat_1.describeFirebirdCompatibilityOptions)(candidate)}`);
|
|
117
181
|
}
|
|
118
|
-
return
|
|
182
|
+
return db;
|
|
119
183
|
}
|
|
120
184
|
catch (error) {
|
|
121
|
-
|
|
185
|
+
attempts.push({ candidate, error });
|
|
122
186
|
if (!(0, firebird_compat_1.shouldRetryFirebirdCompatibility)(error) || index === candidates.length - 1) {
|
|
123
|
-
throw
|
|
187
|
+
throw this.createCompatibilitySummaryError(options, attempts);
|
|
124
188
|
}
|
|
125
|
-
this.logger.warning(`Firebird attach failed with ${(0, firebird_compat_1.describeFirebirdCompatibilityOptions)(candidate)}.
|
|
189
|
+
this.logger.warning(`Firebird attach failed with ${(0, firebird_compat_1.describeFirebirdCompatibilityOptions)(candidate)}. Trying next compatibility profile. Error: ${String((_a = error === null || error === void 0 ? void 0 : error.message) !== null && _a !== void 0 ? _a : error)}`);
|
|
126
190
|
}
|
|
127
191
|
}
|
|
128
|
-
throw
|
|
192
|
+
throw this.createCompatibilitySummaryError(options, attempts);
|
|
129
193
|
});
|
|
130
194
|
}
|
|
131
195
|
static testConnection(options) {
|
|
@@ -333,4 +397,5 @@ class Orm {
|
|
|
333
397
|
}
|
|
334
398
|
exports.Orm = Orm;
|
|
335
399
|
Orm.logger = new Logger_1.Logger(Orm.name);
|
|
400
|
+
Orm.compatibilityProfileCache = new Map();
|
|
336
401
|
//# sourceMappingURL=Orm.js.map
|
package/dist/Orm.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Orm.js","sourceRoot":"","sources":["../src/Orm.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,2DAA6C;AAC7C,qCAAkC;AAElC,2CAA4C;AAC5C,uDAM2B;AAE3B,IAAA,wDAAsC,GAAE,CAAC;AAEzC,MAAa,GAAG;IAGL,MAAM,CAAC,KAAK,CAAC,KAAa;QAC7B,OAAO,IAAI,GAAG,KAAK,GAAG,IAAI,CAAC;IAC/B,CAAC;IAEO,MAAM,CAAC,YAAY,CAAC,OAAgB;;QACxC,MAAM,SAAS,GAAG,MAAA,MAAC,OAA2B,CAAC,gBAAgB,mCACvD,OAA2B,CAAC,cAAc,mCAC3C,KAAK,CAAC;QAEb,OAAO,MAAM,CAAC,QAAQ,CAAC,SAAS,CAAC,IAAI,SAAS,GAAG,CAAC,CAAC,CAAC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,CAAC,CAAC;YAC1B,CAAC;YAAC,OAAO,KAAK,EAAE,CAAC;gBACb,OAAO,MAAM,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;oBACzC,WAAW,CAAC,QAAQ,CAAC,CAAC,WAAgB,EAAQ,EAAE;wBAC5C,IAAI,WAAW,EAAE,CAAC;4BACd,OAAO,MAAM,CAAC,WAAW,CAAC,CAAC;wBAC/B,CAAC;6BAAM,CAAC;4BACJ,OAAO,MAAM,CAAC,KAAK,CAAC,CAAC;wBACzB,CAAC;oBACL,CAAC,CAAC,CAAC;gBACP,CAAC,CAAC,CAAC;YACP,CAAC;QACL,CAAC;KAAA;;AAlSL,kBAmSC;AAlSkB,UAAM,GAAW,IAAI,eAAM,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC","sourcesContent":["import * as Firebird from \"es-node-firebird\";\nimport { Logger } from \"./Logger\";\nimport { Database, Options, Transaction } from \"es-node-firebird\";\nimport { RestUtilities } from \"./Utilities\";\nimport {\n buildFirebirdCompatibilityCandidates,\n describeFirebirdCompatibilityOptions,\n ensureEsNodeFirebirdCompatibilityPatch,\n FirebirdOptions,\n shouldRetryFirebirdCompatibility,\n} from \"./firebird-compat\";\n\nensureEsNodeFirebirdCompatibilityPatch();\n\nexport class Orm {\n private static logger: Logger = new Logger(Orm.name);\n\n public static quote(value: string): string {\n return \"\\\"\" + value + \"\\\"\";\n }\n\n private static getTimeoutMs(options: Options): number {\n const candidate = (options as FirebirdOptions).connectTimeoutMs\n ?? (options as FirebirdOptions).connectTimeout\n ?? 15000;\n\n return Number.isFinite(candidate) && candidate > 0 ? Math.trunc(candidate) : 15000;\n }\n\n private static createTimeoutError(stage: string, timeoutMs: number, options: Options, query?: string): Error {\n const target = `${options.host ?? \"?\"}:${options.port ?? \"?\"} -> ${options.database ?? \"?\"}`;\n const suffix = query ? ` | sql=${query.replace(/\\s+/g, \" \").trim()}` : \"\";\n return new Error(`Timeout during Firebird ${stage} after ${timeoutMs} ms on ${target}${suffix}`);\n }\n\n private static async detachQuietly(db: Database | undefined): Promise<void> {\n if (!db) {\n return;\n }\n\n await new Promise<void>((resolve) => {\n try {\n db.detach(() => resolve());\n } catch {\n resolve();\n }\n });\n }\n\n private static attachOnceWithTimeout(options: Options): Promise<Database> {\n return new Promise((resolve, reject): void => {\n const timeoutMs = this.getTimeoutMs(options);\n let settled = false;\n const timeoutId = setTimeout(() => {\n if (settled) {\n return;\n }\n\n settled = true;\n reject(this.createTimeoutError(\"attach\", timeoutMs, options));\n }, timeoutMs);\n\n Firebird.attach(options, async (err: any, db: Database): Promise<void> => {\n if (settled) {\n await this.detachQuietly(db);\n return;\n }\n\n settled = true;\n clearTimeout(timeoutId);\n\n if (err) {\n this.logger.error(err);\n return reject(err);\n }\n\n return resolve(db);\n });\n });\n }\n\n private static async attachWithTimeout(options: Options): Promise<Database> {\n const candidates = buildFirebirdCompatibilityCandidates(options);\n let lastError: unknown;\n\n for (let index = 0; index < candidates.length; index++) {\n const candidate = candidates[index];\n\n try {\n if (index > 0) {\n this.logger.warning(\n `Retry Firebird attach with compatibility fallback ${index + 1}/${candidates.length}: ${describeFirebirdCompatibilityOptions(candidate)}`\n );\n }\n\n return await this.attachOnceWithTimeout(candidate);\n } catch (error) {\n lastError = error;\n\n if (!shouldRetryFirebirdCompatibility(error) || index === candidates.length - 1) {\n throw error;\n }\n\n this.logger.warning(\n `Firebird attach failed with ${describeFirebirdCompatibilityOptions(candidate)}. Retrying compatibility fallback. Error: ${String((error as { message?: unknown })?.message ?? error)}`\n );\n }\n }\n\n throw lastError;\n }\n\n public static async testConnection(options: Options): Promise<boolean> {\n return new Promise((resolve): void => {\n this.attachWithTimeout(options)\n .then(async (db: Database): Promise<void> => {\n this.logger.info(\"DATABASE connesso.\");\n await this.detachQuietly(db);\n resolve(true);\n })\n .catch((err: Error): void => {\n this.logger.error(\"La connessione con il DATABASE non e andata a buon fine.\");\n this.logger.error(err);\n resolve(false);\n });\n });\n }\n\n public static async query(options: Options, query: string, parameters: any[] = [], logQuery = true): Promise<any> {\n try {\n const db = await this.attachWithTimeout(options);\n\n return await new Promise((resolve, reject): void => {\n const timeoutMs = this.getTimeoutMs(options);\n let settled = false;\n const timeoutId = setTimeout(async () => {\n if (settled) {\n return;\n }\n\n settled = true;\n await this.detachQuietly(db);\n reject(this.createTimeoutError(\"query\", timeoutMs, options, query));\n }, timeoutMs);\n\n if (logQuery) {\n this.logger.info(RestUtilities.printQueryWithParams(query, parameters));\n }\n\n db.query(query, parameters, async (error: any, result: any) => {\n if (settled) {\n await this.detachQuietly(db);\n return;\n }\n\n settled = true;\n clearTimeout(timeoutId);\n await this.detachQuietly(db);\n\n if (error) {\n this.logger.error(error);\n return reject(error);\n }\n\n return resolve(result);\n });\n });\n } catch (error) {\n this.logger.error(error as object);\n throw error;\n }\n }\n\n public static async execute(options: Options, query: string, parameters: any = [], logQuery = true): Promise<any> {\n try {\n const db = await this.attachWithTimeout(options);\n\n return await new Promise((resolve, reject): void => {\n const timeoutMs = this.getTimeoutMs(options);\n let settled = false;\n const timeoutId = setTimeout(async () => {\n if (settled) {\n return;\n }\n\n settled = true;\n await this.detachQuietly(db);\n reject(this.createTimeoutError(\"execute\", timeoutMs, options, query));\n }, timeoutMs);\n\n if (logQuery) {\n this.logger.info(RestUtilities.printQueryWithParams(query, parameters));\n }\n\n db.execute(query, parameters, async (error: any, result: any) => {\n if (settled) {\n await this.detachQuietly(db);\n return;\n }\n\n settled = true;\n clearTimeout(timeoutId);\n await this.detachQuietly(db);\n\n if (error) {\n this.logger.error(error);\n return reject(error);\n }\n\n return resolve(result);\n });\n });\n } catch (error) {\n this.logger.error(error as object);\n throw error;\n }\n }\n\n public static trimParam(param: any): string {\n if (typeof param === \"string\" || param instanceof String) {\n return param.trim();\n }\n return param;\n }\n\n public static async connect(options: Options): Promise<Database> {\n return this.attachWithTimeout(options);\n }\n\n public static async startTransaction(db: Database): Promise<Transaction> {\n return new Promise((resolve, reject): void => {\n db.transaction(Firebird.ISOLATION_READ_COMMITTED, function (err: any, transaction: Transaction): void {\n if (err) return reject(err); else return resolve(transaction);\n });\n });\n }\n\n public static async commitTransaction(transaction: Transaction): Promise<string> {\n return new Promise((resolve, reject): void => {\n transaction.commit((err: any): void => {\n if (err) return reject(err); else return resolve(\"Transaction committed successfully.\");\n });\n });\n }\n\n public static async rollbackTransaction(transaction: Transaction): Promise<string> {\n return new Promise((resolve, reject): void => {\n transaction.rollback((err: any): void => {\n if (err) return reject(err); else return resolve(\"Transaction rolled back successfully.\");\n });\n });\n }\n\n public static async executeMultiple(options: Options, queriesWithParams: { query: string, params: any[] }[]): Promise<string> {\n let db: Database | undefined;\n let transaction: Transaction | undefined;\n\n try {\n db = await Orm.connect(options);\n transaction = await Orm.startTransaction(db);\n\n for (const qwp of queriesWithParams) {\n await new Promise((resolve, reject) => {\n transaction.query(qwp.query, qwp.params, (err: any, result: any): void => {\n if (err) return reject(err);\n else return resolve(result);\n });\n });\n }\n\n await Orm.commitTransaction(transaction);\n await Orm.detachQuietly(db);\n return \"OK\";\n\n } catch (error) {\n if (transaction) {\n await Orm.rollbackTransaction(transaction);\n }\n await Orm.detachQuietly(db);\n throw error;\n }\n }\n\n public static async executeQueries(transaction: Transaction, queries: string[], params: any[]): Promise<any> {\n try {\n return await queries.reduce((promiseChain: Promise<any>, currentQuery: string, index: number) => {\n return promiseChain.then(() => new Promise((resolve, reject) => {\n transaction.query(currentQuery, params[index], (err: any, result: any): void => {\n if (err) return reject(err);\n else return resolve(result);\n });\n }));\n }, Promise.resolve());\n } catch (error) {\n return await new Promise((resolve, reject) => {\n transaction.rollback((rollbackErr: any): void => {\n if (rollbackErr) {\n return reject(rollbackErr);\n } else {\n return reject(error);\n }\n });\n });\n }\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"Orm.js","sourceRoot":"","sources":["../src/Orm.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,2DAA6C;A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E,MAAW,EAAQ,EAAE;4BAC3E,IAAI,GAAG;gCAAE,OAAO,MAAM,CAAC,GAAG,CAAC,CAAC;;gCACvB,OAAO,OAAO,CAAC,MAAM,CAAC,CAAC;wBAChC,CAAC,CAAC,CAAC;oBACP,CAAC,CAAC,CAAC,CAAC;gBACR,CAAC,EAAE,OAAO,CAAC,OAAO,EAAE,CAAC,CAAC;YAC1B,CAAC;YAAC,OAAO,KAAK,EAAE,CAAC;gBACb,OAAO,MAAM,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;oBACzC,WAAW,CAAC,QAAQ,CAAC,CAAC,WAAgB,EAAQ,EAAE;wBAC5C,IAAI,WAAW,EAAE,CAAC;4BACd,OAAO,MAAM,CAAC,WAAW,CAAC,CAAC;wBAC/B,CAAC;6BAAM,CAAC;4BACJ,OAAO,MAAM,CAAC,KAAK,CAAC,CAAC;wBACzB,CAAC;oBACL,CAAC,CAAC,CAAC;gBACP,CAAC,CAAC,CAAC;YACP,CAAC;QACL,CAAC;KAAA;;AAjXL,kBAkXC;AAjXkB,UAAM,GAAW,IAAI,eAAM,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;AACtC,6BAAyB,GAAiC,IAAI,GAAG,EAA2B,CAAC","sourcesContent":["import * as Firebird from \"es-node-firebird\";\nimport { Logger } from \"./Logger\";\nimport { Database, Options, Transaction } from \"es-node-firebird\";\nimport { RestUtilities } from \"./Utilities\";\nimport {\n buildFirebirdCompatibilityCandidates,\n describeFirebirdCompatibilityOptions,\n ensureEsNodeFirebirdCompatibilityPatch,\n FirebirdOptions,\n shouldRetryFirebirdCompatibility,\n} from \"./firebird-compat\";\n\nensureEsNodeFirebirdCompatibilityPatch();\n\nexport class Orm {\n private static logger: Logger = new Logger(Orm.name);\n private static compatibilityProfileCache: Map<string, FirebirdOptions> = new Map<string, FirebirdOptions>();\n\n public static quote(value: string): string {\n return \"\\\"\" + value + \"\\\"\";\n }\n\n private static getTimeoutMs(options: Options): number {\n const candidate = (options as FirebirdOptions).connectTimeoutMs\n ?? (options as FirebirdOptions).compatibilityTotalTimeoutMs\n ?? (options as FirebirdOptions).connectTimeout\n ?? 15000;\n\n return Number.isFinite(candidate) && candidate > 0 ? Math.trunc(candidate) : 15000;\n }\n\n private static createTimeoutError(stage: string, timeoutMs: number, options: Options, query?: string): Error {\n const target = `${options.host ?? \"?\"}:${options.port ?? \"?\"} -> ${options.database ?? \"?\"}`;\n const suffix = query ? ` | sql=${query.replace(/\\s+/g, \" \").trim()}` : \"\";\n return new Error(`Timeout during Firebird ${stage} after ${timeoutMs} ms on ${target}${suffix}`);\n }\n\n private static createCompatibilityCacheKey(options: Options): string {\n return [\n options.host ?? \"?\",\n options.port ?? \"?\",\n options.database ?? \"?\",\n options.user ?? \"?\",\n ].join(\"|\");\n }\n\n private static getProbeTimeoutMs(options: Options, candidateCount: number): number {\n const configured = (options as FirebirdOptions).compatibilityProbeTimeoutMs;\n if (Number.isFinite(configured) && configured! > 0) {\n return Math.trunc(configured!);\n }\n\n const totalTimeoutMs = this.getTimeoutMs(options);\n if (candidateCount <= 1) {\n return totalTimeoutMs;\n }\n\n return Math.max(2500, Math.min(5000, Math.trunc(totalTimeoutMs / candidateCount)));\n }\n\n private static reorderCandidatesWithCache(options: Options, candidates: FirebirdOptions[]): FirebirdOptions[] {\n const cacheKey = this.createCompatibilityCacheKey(options);\n const cachedCandidate = this.compatibilityProfileCache.get(cacheKey);\n if (!cachedCandidate) {\n return candidates;\n }\n\n const ordered = [...candidates];\n const cachedDescription = describeFirebirdCompatibilityOptions(cachedCandidate);\n const cachedIndex = ordered.findIndex((candidate) => describeFirebirdCompatibilityOptions(candidate) === cachedDescription);\n\n if (cachedIndex <= 0) {\n return ordered;\n }\n\n const [matchedCandidate] = ordered.splice(cachedIndex, 1);\n ordered.unshift(matchedCandidate);\n return ordered;\n }\n\n private static createCompatibilitySummaryError(options: Options, attempts: { candidate: FirebirdOptions, error: unknown }[]): Error {\n const target = `${options.host ?? \"?\"}:${options.port ?? \"?\"} -> ${options.database ?? \"?\"}`;\n const attemptsSummary = attempts\n .map(({ candidate, error }) => {\n const errorMessage = String((error as { message?: unknown })?.message ?? error ?? \"Unknown error\");\n return `[${describeFirebirdCompatibilityOptions(candidate)} => ${errorMessage}]`;\n })\n .join(\"; \");\n\n return new Error(`Unable to attach Firebird database after compatibility probing on ${target}. Attempts: ${attemptsSummary}`);\n }\n\n private static async detachQuietly(db: Database | undefined): Promise<void> {\n if (!db) {\n return;\n }\n\n await new Promise<void>((resolve) => {\n try {\n db.detach(() => resolve());\n } catch {\n resolve();\n }\n });\n }\n\n private static attachOnceWithTimeout(options: Options, timeoutMs = this.getTimeoutMs(options)): Promise<Database> {\n return new Promise((resolve, reject): void => {\n let settled = false;\n const timeoutId = setTimeout(() => {\n if (settled) {\n return;\n }\n\n settled = true;\n reject(this.createTimeoutError(\"attach\", timeoutMs, options));\n }, timeoutMs);\n\n Firebird.attach(options, async (err: any, db: Database): Promise<void> => {\n if (settled) {\n await this.detachQuietly(db);\n return;\n }\n\n settled = true;\n clearTimeout(timeoutId);\n\n if (err) {\n this.logger.error(err);\n return reject(err);\n }\n\n return resolve(db);\n });\n });\n }\n\n private static async attachWithTimeout(options: Options): Promise<Database> {\n const totalTimeoutMs = this.getTimeoutMs(options);\n const candidates = this.reorderCandidatesWithCache(options, buildFirebirdCompatibilityCandidates(options));\n const probeTimeoutMs = this.getProbeTimeoutMs(options, candidates.length);\n const startedAt = Date.now();\n const attempts: { candidate: FirebirdOptions, error: unknown }[] = [];\n const cacheKey = this.createCompatibilityCacheKey(options);\n\n for (let index = 0; index < candidates.length; index++) {\n const candidate = candidates[index];\n const elapsedMs = Date.now() - startedAt;\n const remainingMs = totalTimeoutMs - elapsedMs;\n\n if (remainingMs <= 0) {\n break;\n }\n\n const attemptTimeoutMs = index === 0 && candidates.length === 1\n ? remainingMs\n : Math.min(probeTimeoutMs, remainingMs);\n\n try {\n if (candidates.length > 1) {\n this.logger.info(\n `Firebird compatibility probe ${index + 1}/${candidates.length}: ${describeFirebirdCompatibilityOptions(candidate)} (timeout ${attemptTimeoutMs} ms)`\n );\n }\n\n const db = await this.attachOnceWithTimeout(candidate, attemptTimeoutMs);\n this.compatibilityProfileCache.set(cacheKey, candidate);\n\n if (candidates.length > 1) {\n this.logger.info(\n `Firebird compatibility profile selected: ${describeFirebirdCompatibilityOptions(candidate)}`\n );\n }\n\n return db;\n } catch (error) {\n attempts.push({ candidate, error });\n\n if (!shouldRetryFirebirdCompatibility(error) || index === candidates.length - 1) {\n throw this.createCompatibilitySummaryError(options, attempts);\n }\n\n this.logger.warning(\n `Firebird attach failed with ${describeFirebirdCompatibilityOptions(candidate)}. Trying next compatibility profile. Error: ${String((error as { message?: unknown })?.message ?? error)}`\n );\n }\n }\n\n throw this.createCompatibilitySummaryError(options, attempts);\n }\n\n public static async testConnection(options: Options): Promise<boolean> {\n return new Promise((resolve): void => {\n this.attachWithTimeout(options)\n .then(async (db: Database): Promise<void> => {\n this.logger.info(\"DATABASE connesso.\");\n await this.detachQuietly(db);\n resolve(true);\n })\n .catch((err: Error): void => {\n this.logger.error(\"La connessione con il DATABASE non e andata a buon fine.\");\n this.logger.error(err);\n resolve(false);\n });\n });\n }\n\n public static async query(options: Options, query: string, parameters: any[] = [], logQuery = true): Promise<any> {\n try {\n const db = await this.attachWithTimeout(options);\n\n return await new Promise((resolve, reject): void => {\n const timeoutMs = this.getTimeoutMs(options);\n let settled = false;\n const timeoutId = setTimeout(async () => {\n if (settled) {\n return;\n }\n\n settled = true;\n await this.detachQuietly(db);\n reject(this.createTimeoutError(\"query\", timeoutMs, options, query));\n }, timeoutMs);\n\n if (logQuery) {\n this.logger.info(RestUtilities.printQueryWithParams(query, parameters));\n }\n\n db.query(query, parameters, async (error: any, result: any) => {\n if (settled) {\n await this.detachQuietly(db);\n return;\n }\n\n settled = true;\n clearTimeout(timeoutId);\n await this.detachQuietly(db);\n\n if (error) {\n this.logger.error(error);\n return reject(error);\n }\n\n return resolve(result);\n });\n });\n } catch (error) {\n this.logger.error(error as object);\n throw error;\n }\n }\n\n public static async execute(options: Options, query: string, parameters: any = [], logQuery = true): Promise<any> {\n try {\n const db = await this.attachWithTimeout(options);\n\n return await new Promise((resolve, reject): void => {\n const timeoutMs = this.getTimeoutMs(options);\n let settled = false;\n const timeoutId = setTimeout(async () => {\n if (settled) {\n return;\n }\n\n settled = true;\n await this.detachQuietly(db);\n reject(this.createTimeoutError(\"execute\", timeoutMs, options, query));\n }, timeoutMs);\n\n if (logQuery) {\n this.logger.info(RestUtilities.printQueryWithParams(query, parameters));\n }\n\n db.execute(query, parameters, async (error: any, result: any) => {\n if (settled) {\n await this.detachQuietly(db);\n return;\n }\n\n settled = true;\n clearTimeout(timeoutId);\n await this.detachQuietly(db);\n\n if (error) {\n this.logger.error(error);\n return reject(error);\n }\n\n return resolve(result);\n });\n });\n } catch (error) {\n this.logger.error(error as object);\n throw error;\n }\n }\n\n public static trimParam(param: any): string {\n if (typeof param === \"string\" || param instanceof String) {\n return param.trim();\n }\n return param;\n }\n\n public static async connect(options: Options): Promise<Database> {\n return this.attachWithTimeout(options);\n }\n\n public static async startTransaction(db: Database): Promise<Transaction> {\n return new Promise((resolve, reject): void => {\n db.transaction(Firebird.ISOLATION_READ_COMMITTED, function (err: any, transaction: Transaction): void {\n if (err) return reject(err); else return resolve(transaction);\n });\n });\n }\n\n public static async commitTransaction(transaction: Transaction): Promise<string> {\n return new Promise((resolve, reject): void => {\n transaction.commit((err: any): void => {\n if (err) return reject(err); else return resolve(\"Transaction committed successfully.\");\n });\n });\n }\n\n public static async rollbackTransaction(transaction: Transaction): Promise<string> {\n return new Promise((resolve, reject): void => {\n transaction.rollback((err: any): void => {\n if (err) return reject(err); else return resolve(\"Transaction rolled back successfully.\");\n });\n });\n }\n\n public static async executeMultiple(options: Options, queriesWithParams: { query: string, params: any[] }[]): Promise<string> {\n let db: Database | undefined;\n let transaction: Transaction | undefined;\n\n try {\n db = await Orm.connect(options);\n transaction = await Orm.startTransaction(db);\n\n for (const qwp of queriesWithParams) {\n await new Promise((resolve, reject) => {\n transaction.query(qwp.query, qwp.params, (err: any, result: any): void => {\n if (err) return reject(err);\n else return resolve(result);\n });\n });\n }\n\n await Orm.commitTransaction(transaction);\n await Orm.detachQuietly(db);\n return \"OK\";\n\n } catch (error) {\n if (transaction) {\n await Orm.rollbackTransaction(transaction);\n }\n await Orm.detachQuietly(db);\n throw error;\n }\n }\n\n public static async executeQueries(transaction: Transaction, queries: string[], params: any[]): Promise<any> {\n try {\n return await queries.reduce((promiseChain: Promise<any>, currentQuery: string, index: number) => {\n return promiseChain.then(() => new Promise((resolve, reject) => {\n transaction.query(currentQuery, params[index], (err: any, result: any): void => {\n if (err) return reject(err);\n else return resolve(result);\n });\n }));\n }, Promise.resolve());\n } catch (error) {\n return await new Promise((resolve, reject) => {\n transaction.rollback((rollbackErr: any): void => {\n if (rollbackErr) {\n return reject(rollbackErr);\n } else {\n return reject(error);\n }\n });\n });\n }\n }\n}\n"]}
|
|
@@ -7,6 +7,8 @@ export type FirebirdOptions = Options & {
|
|
|
7
7
|
authPlugins?: FirebirdAuthPlugin[];
|
|
8
8
|
connectTimeoutMs?: number;
|
|
9
9
|
connectTimeout?: number;
|
|
10
|
+
compatibilityProbeTimeoutMs?: number;
|
|
11
|
+
compatibilityTotalTimeoutMs?: number;
|
|
10
12
|
};
|
|
11
13
|
export declare function normalizeFirebirdOptions(options: Options): FirebirdOptions;
|
|
12
14
|
export declare function buildFirebirdCompatibilityCandidates(options: Options): FirebirdOptions[];
|
package/dist/firebird-compat.js
CHANGED
|
@@ -95,7 +95,8 @@ function isRetryableCompatibilityError(error) {
|
|
|
95
95
|
return message.includes("incompatible wire encryption")
|
|
96
96
|
|| message.includes("no matching plugins on server")
|
|
97
97
|
|| message.includes("unknown auth plugin")
|
|
98
|
-
|| message.includes("unknow auth plugin")
|
|
98
|
+
|| message.includes("unknow auth plugin")
|
|
99
|
+
|| message.includes("timeout during firebird attach");
|
|
99
100
|
}
|
|
100
101
|
function pushUniqueCandidate(target, candidate) {
|
|
101
102
|
var _a;
|
|
@@ -110,6 +111,11 @@ function pushUniqueCandidate(target, candidate) {
|
|
|
110
111
|
target.push(normalized);
|
|
111
112
|
}
|
|
112
113
|
}
|
|
114
|
+
function appendPluginCandidates(target, base, pluginName, wireCryptModes) {
|
|
115
|
+
wireCryptModes.forEach((wireCrypt) => {
|
|
116
|
+
pushUniqueCandidate(target, Object.assign(Object.assign({}, base), { pluginName, wireCrypt }));
|
|
117
|
+
});
|
|
118
|
+
}
|
|
113
119
|
function buildFirebirdCompatibilityCandidates(options) {
|
|
114
120
|
const normalized = normalizeFirebirdOptions(options);
|
|
115
121
|
const compatibilityOptions = options;
|
|
@@ -121,21 +127,21 @@ function buildFirebirdCompatibilityCandidates(options) {
|
|
|
121
127
|
return candidates;
|
|
122
128
|
}
|
|
123
129
|
if (hasExplicitPlugin) {
|
|
124
|
-
|
|
125
|
-
|
|
130
|
+
const wireCryptModes = normalized.pluginName === "Legacy_Auth"
|
|
131
|
+
? ["disabled", "enabled"]
|
|
132
|
+
: ["enabled", "required", "disabled"];
|
|
133
|
+
appendPluginCandidates(candidates, normalized, normalized.pluginName, wireCryptModes);
|
|
126
134
|
return candidates;
|
|
127
135
|
}
|
|
128
136
|
if (hasExplicitWireCrypt) {
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
137
|
+
appendPluginCandidates(candidates, normalized, "Srp256", [normalized.wireCrypt]);
|
|
138
|
+
appendPluginCandidates(candidates, normalized, "Srp", [normalized.wireCrypt]);
|
|
139
|
+
appendPluginCandidates(candidates, normalized, "Legacy_Auth", [normalized.wireCrypt]);
|
|
132
140
|
return candidates;
|
|
133
141
|
}
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
pushUniqueCandidate(candidates, Object.assign(Object.assign({}, normalized), { pluginName: "Srp", wireCrypt: "disabled" }));
|
|
138
|
-
pushUniqueCandidate(candidates, Object.assign(Object.assign({}, normalized), { pluginName: "Legacy_Auth", wireCrypt: "disabled" }));
|
|
142
|
+
appendPluginCandidates(candidates, normalized, "Srp256", ["enabled", "required", "disabled"]);
|
|
143
|
+
appendPluginCandidates(candidates, normalized, "Srp", ["enabled", "required", "disabled"]);
|
|
144
|
+
appendPluginCandidates(candidates, normalized, "Legacy_Auth", ["disabled", "enabled"]);
|
|
139
145
|
return candidates;
|
|
140
146
|
}
|
|
141
147
|
function shouldRetryFirebirdCompatibility(error) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"firebird-compat.js","sourceRoot":"","sources":["../src/firebird-compat.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA8FA,4DAQC;AAuBD,oFAgCC;AAED,4EAEC;AAED,oFAGC;AAED,wFA+DC;AAvOD,2DAA6C;AAc7C,MAAM,gBAAgB,GAAG,CAAC,CAAC;AAC3B,MAAM,gBAAgB,GAAG,EAAE,CAAC;AAC5B,MAAM,iBAAiB,GAAG,EAAE,CAAC;AAC7B,MAAM,kBAAkB,GAAG,CAAC,CAAC;AAC7B,MAAM,iBAAiB,GAAG,CAAC,CAAC;AAC5B,MAAM,mBAAmB,GAAG,CAAC,CAAC;AAC9B,MAAM,wBAAwB,GAAyB,CAAC,QAAQ,EAAE,KAAK,EAAE,aAAa,CAAC,CAAC;AAwBxF,SAAS,sBAAsB,CAAC,KAAc;IAC1C,MAAM,UAAU,GAAG,MAAM,CAAC,KAAK,aAAL,KAAK,cAAL,KAAK,GAAI,EAAE,CAAC,CAAC,IAAI,EAAE,CAAC,WAAW,EAAE,CAAC;IAC5D,IAAI,UAAU,KAAK,UAAU,EAAE,CAAC;QAC5B,OAAO,UAAU,CAAC;IACtB,CAAC;IAED,IAAI,UAAU,KAAK,UAAU,EAAE,CAAC;QAC5B,OAAO,UAAU,CAAC;IACtB,CAAC;IAED,OAAO,SAAS,CAAC;AACrB,CAAC;AAED,SAAS,mBAAmB,CAAC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,EAAE,GAAG,IAAI,CAAC,CAAC;QACvD,CAAC,CAAC;QAEF,GAAG,CAAC,SAAS,GAAG,SAAS,gBAAgB,CAAC,IAAY,EAAE,KAAa,EAAE,QAAiB;YACpF,IAAI,IAAI,KAAK,gBAAgB,EAAE,CAAC;gBAC5B,OAAO,iBAAiB,CAAC,IAAI,CAAC,IAAI,EAAE,IAAI,EAAE,UAAU,EAAE,QAAQ,CAAC,CAAC;YACpE,CAAC;YAED,IAAI,IAAI,KAAK,gBAAgB,EAAE,CAAC;gBAC5B,OAAO,iBAAiB,CAAC,IAAI,CAAC,IAAI,EAAE,IAAI,EAAE,WAAW,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,QAAQ,CAAC,CAAC;YAC/E,CAAC;YAED,OAAO,iBAAiB,CAAC,IAAI,CAAC,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,QAAQ,CAAC,CAAC;QAC/D,CAAC,CAAC;QAEF,IAAI,CAAC;YACD,OAAO,eAAe,CAAC,IAAI,CAAC,IAAI,EAAE,cAAc,EAAE,QAAQ,CAAC,CAAC;QAChE,CAAC;gBAAS,CAAC;YACP,GAAG,CAAC,QAAQ,GAAG,gBAAgB,CAAC;YAChC,GAAG,CAAC,SAAS,GAAG,iBAAiB,CAAC;QACtC,CAAC;IACL,CAAC,CAAC;IAEF,mBAAmB,CAAC,8BAA8B,GAAG,IAAI,CAAC;AAC9D,CAAC;AAED,sCAAsC,EAAE,CAAC","sourcesContent":["import * as Firebird from \"es-node-firebird\";\nimport { Options } from \"es-node-firebird\";\n\nexport type FirebirdWireCryptMode = \"disabled\" | \"enabled\" | \"required\";\nexport type FirebirdAuthPlugin = \"Legacy_Auth\" | \"Srp\" | \"Srp256\";\n\nexport type FirebirdOptions = Options & {\n wireCrypt?: FirebirdWireCryptMode;\n pluginName?: FirebirdAuthPlugin;\n authPlugins?: FirebirdAuthPlugin[];\n connectTimeoutMs?: number;\n connectTimeout?: number;\n};\n\nconst CNCT_PLUGIN_NAME = 8;\nconst CNCT_PLUGIN_LIST = 10;\nconst CNCT_CLIENT_CRYPT = 11;\nconst WIRE_CRYPT_DISABLE = 0;\nconst WIRE_CRYPT_ENABLE = 1;\nconst WIRE_CRYPT_REQUIRED = 2;\nconst DEFAULT_AUTH_PLUGIN_LIST: FirebirdAuthPlugin[] = [\"Srp256\", \"Srp\", \"Legacy_Auth\"];\n\ntype BlrWriterLike = {\n addBytes: (bytes: number[], ...args: unknown[]) => unknown;\n addString: (code: number, value: string, encoding?: string) => unknown;\n};\n\ntype ConnectionLike = {\n _blr?: BlrWriterLike;\n accept?: {\n protocolMinimumType?: number;\n pluginName?: string;\n };\n};\n\ntype FirebirdModuleLike = {\n Connection?: {\n prototype?: {\n connect?: (this: ConnectionLike, options: FirebirdOptions, callback: unknown) => unknown;\n __emilsoftwareWireCryptPatched?: boolean;\n };\n };\n};\n\nfunction normalizeWireCryptMode(value: unknown): FirebirdWireCryptMode {\n const normalized = String(value ?? \"\").trim().toLowerCase();\n if (normalized === \"required\") {\n return \"required\";\n }\n\n if (normalized === \"disabled\") {\n return \"disabled\";\n }\n\n return \"enabled\";\n}\n\nfunction normalizeAuthPlugin(value: unknown): FirebirdAuthPlugin {\n const normalized = String(value ?? \"\").trim().toLowerCase();\n\n if (normalized === \"legacy_auth\" || normalized === \"legacy\") {\n return \"Legacy_Auth\";\n }\n\n if (normalized === \"srp256\") {\n return \"Srp256\";\n }\n\n return \"Srp\";\n}\n\nfunction toWireCryptFlag(mode: FirebirdWireCryptMode): number {\n switch (mode) {\n case \"required\":\n return WIRE_CRYPT_REQUIRED;\n case \"disabled\":\n return WIRE_CRYPT_DISABLE;\n default:\n return WIRE_CRYPT_ENABLE;\n }\n}\n\nfunction normalizeAuthPluginList(value: unknown): FirebirdAuthPlugin[] {\n if (!Array.isArray(value) || value.length === 0) {\n return [...DEFAULT_AUTH_PLUGIN_LIST];\n }\n\n const normalized = value\n .map((entry: unknown) => normalizeAuthPlugin(entry))\n .filter((entry: FirebirdAuthPlugin, index: number, source: FirebirdAuthPlugin[]) => source.indexOf(entry) === index);\n\n return normalized.length > 0 ? normalized : [...DEFAULT_AUTH_PLUGIN_LIST];\n}\n\nexport function normalizeFirebirdOptions(options: Options): FirebirdOptions {\n const compatibilityOptions = options as FirebirdOptions;\n return {\n ...options,\n wireCrypt: normalizeWireCryptMode(compatibilityOptions.wireCrypt),\n pluginName: normalizeAuthPlugin(compatibilityOptions.pluginName),\n authPlugins: normalizeAuthPluginList(compatibilityOptions.authPlugins),\n };\n}\n\nfunction isRetryableCompatibilityError(error: unknown): boolean {\n const message = String((error as { message?: unknown })?.message ?? error ?? \"\").toLowerCase();\n return message.includes(\"incompatible wire encryption\")\n || message.includes(\"no matching plugins on server\")\n || message.includes(\"unknown auth plugin\")\n || message.includes(\"unknow auth plugin\");\n}\n\nfunction pushUniqueCandidate(target: FirebirdOptions[], candidate: FirebirdOptions): void {\n const normalized = normalizeFirebirdOptions(candidate);\n const key = `${normalized.pluginName}|${normalized.wireCrypt}|${(normalized.authPlugins ?? []).join(\",\")}`;\n const alreadyPresent = target.some((entry) => {\n const normalizedEntry = normalizeFirebirdOptions(entry);\n return `${normalizedEntry.pluginName}|${normalizedEntry.wireCrypt}|${(normalizedEntry.authPlugins ?? []).join(\",\")}` === key;\n });\n\n if (!alreadyPresent) {\n target.push(normalized);\n }\n}\n\nexport function buildFirebirdCompatibilityCandidates(options: Options): FirebirdOptions[] {\n const normalized = normalizeFirebirdOptions(options);\n const compatibilityOptions = options as FirebirdOptions;\n const hasExplicitPlugin = compatibilityOptions.pluginName !== undefined;\n const hasExplicitWireCrypt = compatibilityOptions.wireCrypt !== undefined;\n const candidates: FirebirdOptions[] = [];\n\n pushUniqueCandidate(candidates, normalized);\n\n if (hasExplicitPlugin && hasExplicitWireCrypt) {\n return candidates;\n }\n\n if (hasExplicitPlugin) {\n pushUniqueCandidate(candidates, { ...normalized, wireCrypt: \"disabled\" });\n pushUniqueCandidate(candidates, { ...normalized, wireCrypt: \"enabled\" });\n return candidates;\n }\n\n if (hasExplicitWireCrypt) {\n pushUniqueCandidate(candidates, { ...normalized, pluginName: \"Srp256\" });\n pushUniqueCandidate(candidates, { ...normalized, pluginName: \"Srp\" });\n pushUniqueCandidate(candidates, { ...normalized, pluginName: \"Legacy_Auth\" });\n return candidates;\n }\n\n pushUniqueCandidate(candidates, { ...normalized, pluginName: \"Srp256\", wireCrypt: \"enabled\" });\n pushUniqueCandidate(candidates, { ...normalized, pluginName: \"Srp\", wireCrypt: \"enabled\" });\n pushUniqueCandidate(candidates, { ...normalized, pluginName: \"Srp256\", wireCrypt: \"disabled\" });\n pushUniqueCandidate(candidates, { ...normalized, pluginName: \"Srp\", wireCrypt: \"disabled\" });\n pushUniqueCandidate(candidates, { ...normalized, pluginName: \"Legacy_Auth\", wireCrypt: \"disabled\" });\n return candidates;\n}\n\nexport function shouldRetryFirebirdCompatibility(error: unknown): boolean {\n return isRetryableCompatibilityError(error);\n}\n\nexport function describeFirebirdCompatibilityOptions(options: Options): string {\n const normalized = normalizeFirebirdOptions(options);\n return `plugin=${normalized.pluginName}, wireCrypt=${normalized.wireCrypt}, authPlugins=${(normalized.authPlugins ?? []).join(\"/\")}`;\n}\n\nexport function ensureEsNodeFirebirdCompatibilityPatch(): void {\n const firebird = Firebird as FirebirdModuleLike;\n const connectionPrototype = firebird.Connection?.prototype;\n\n if (!connectionPrototype?.connect || connectionPrototype.__emilsoftwareWireCryptPatched) {\n return;\n }\n\n const originalConnect = connectionPrototype.connect;\n\n connectionPrototype.connect = function patchedConnect(\n this: ConnectionLike,\n options: FirebirdOptions,\n callback: unknown,\n ) {\n const normalizedOptions = normalizeFirebirdOptions(options);\n const wireCryptFlag = toWireCryptFlag(normalizedOptions.wireCrypt);\n const authPlugin = normalizedOptions.pluginName;\n const authPlugins = normalizedOptions.authPlugins ?? DEFAULT_AUTH_PLUGIN_LIST;\n\n this.accept ??= { protocolMinimumType: 0, pluginName: authPlugin };\n\n const blr = this._blr;\n const originalAddBytes = blr?.addBytes;\n const originalAddString = blr?.addString;\n\n if (!blr || !originalAddBytes || !originalAddString) {\n return originalConnect.call(this, normalizedOptions, callback);\n }\n\n const patchedOptions = authPlugin === \"Srp256\"\n ? { ...normalizedOptions, pluginName: \"Srp\" as FirebirdAuthPlugin }\n : normalizedOptions;\n\n blr.addBytes = function patchedAddBytes(bytes: number[], ...args: unknown[]) {\n if (Array.isArray(bytes) && bytes.length === 6 && bytes[0] === CNCT_CLIENT_CRYPT && bytes[1] === 4) {\n return originalAddBytes.call(this, [bytes[0], bytes[1], wireCryptFlag, 0, 0, 0], ...args);\n }\n\n return originalAddBytes.call(this, bytes, ...args);\n };\n\n blr.addString = function patchedAddString(code: number, value: string, encoding?: string) {\n if (code === CNCT_PLUGIN_NAME) {\n return originalAddString.call(this, code, authPlugin, encoding);\n }\n\n if (code === CNCT_PLUGIN_LIST) {\n return originalAddString.call(this, code, authPlugins.join(\",\"), encoding);\n }\n\n return originalAddString.call(this, code, value, encoding);\n };\n\n try {\n return originalConnect.call(this, patchedOptions, callback);\n } finally {\n blr.addBytes = originalAddBytes;\n blr.addString = originalAddString;\n }\n };\n\n connectionPrototype.__emilsoftwareWireCryptPatched = true;\n}\n\nensureEsNodeFirebirdCompatibilityPatch();\n"]}
|
|
1
|
+
{"version":3,"file":"firebird-compat.js","sourceRoot":"","sources":["../src/firebird-compat.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAgGA,4DAQC;AAmCD,oFAiCC;AAED,4EAEC;AAED,oFAGC;AAED,wFA+DC;AAtPD,2DAA6C;AAgB7C,MAAM,gBAAgB,GAAG,CAAC,CAAC;AAC3B,MAAM,gBAAgB,GAAG,EAAE,CAAC;AAC5B,MAAM,iBAAiB,GAAG,EAAE,CAAC;AAC7B,MAAM,kBAAkB,GAAG,CAAC,CAAC;AAC7B,MAAM,iBAAiB,GAAG,CAAC,CAAC;AAC5B,MAAM,mBAAmB,GAAG,CAAC,CAAC;AAC9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CAAC,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,QAAQ,CAAC,CAAC;QAC/D,CAAC,CAAC;QAEF,IAAI,CAAC;YACD,OAAO,eAAe,CAAC,IAAI,CAAC,IAAI,EAAE,cAAc,EAAE,QAAQ,CAAC,CAAC;QAChE,CAAC;gBAAS,CAAC;YACP,GAAG,CAAC,QAAQ,GAAG,gBAAgB,CAAC;YAChC,GAAG,CAAC,SAAS,GAAG,iBAAiB,CAAC;QACtC,CAAC;IACL,CAAC,CAAC;IAEF,mBAAmB,CAAC,8BAA8B,GAAG,IAAI,CAAC;AAC9D,CAAC;AAED,sCAAsC,EAAE,CAAC","sourcesContent":["import * as Firebird from \"es-node-firebird\";\nimport { Options } from \"es-node-firebird\";\n\nexport type FirebirdWireCryptMode = \"disabled\" | \"enabled\" | \"required\";\nexport type FirebirdAuthPlugin = \"Legacy_Auth\" | \"Srp\" | \"Srp256\";\n\nexport type FirebirdOptions = Options & {\n wireCrypt?: FirebirdWireCryptMode;\n pluginName?: FirebirdAuthPlugin;\n authPlugins?: FirebirdAuthPlugin[];\n connectTimeoutMs?: number;\n connectTimeout?: number;\n compatibilityProbeTimeoutMs?: number;\n compatibilityTotalTimeoutMs?: number;\n};\n\nconst CNCT_PLUGIN_NAME = 8;\nconst CNCT_PLUGIN_LIST = 10;\nconst CNCT_CLIENT_CRYPT = 11;\nconst WIRE_CRYPT_DISABLE = 0;\nconst WIRE_CRYPT_ENABLE = 1;\nconst WIRE_CRYPT_REQUIRED = 2;\nconst DEFAULT_AUTH_PLUGIN_LIST: FirebirdAuthPlugin[] = [\"Srp256\", \"Srp\", \"Legacy_Auth\"];\n\ntype BlrWriterLike = {\n addBytes: (bytes: number[], ...args: unknown[]) => unknown;\n addString: (code: number, value: string, encoding?: string) => unknown;\n};\n\ntype ConnectionLike = {\n _blr?: BlrWriterLike;\n accept?: {\n protocolMinimumType?: number;\n pluginName?: string;\n };\n};\n\ntype FirebirdModuleLike = {\n Connection?: {\n prototype?: {\n connect?: (this: ConnectionLike, options: FirebirdOptions, callback: unknown) => unknown;\n __emilsoftwareWireCryptPatched?: boolean;\n };\n };\n};\n\nfunction normalizeWireCryptMode(value: unknown): FirebirdWireCryptMode {\n const normalized = String(value ?? \"\").trim().toLowerCase();\n if (normalized === \"required\") {\n return \"required\";\n }\n\n if (normalized === \"disabled\") {\n return \"disabled\";\n }\n\n return \"enabled\";\n}\n\nfunction normalizeAuthPlugin(value: unknown): FirebirdAuthPlugin {\n const normalized = String(value ?? \"\").trim().toLowerCase();\n\n if (normalized === \"legacy_auth\" || normalized === \"legacy\") {\n return \"Legacy_Auth\";\n }\n\n if (normalized === \"srp256\") {\n return \"Srp256\";\n }\n\n return \"Srp\";\n}\n\nfunction toWireCryptFlag(mode: FirebirdWireCryptMode): number {\n switch (mode) {\n case \"required\":\n return WIRE_CRYPT_REQUIRED;\n case \"disabled\":\n return WIRE_CRYPT_DISABLE;\n default:\n return WIRE_CRYPT_ENABLE;\n }\n}\n\nfunction normalizeAuthPluginList(value: unknown): FirebirdAuthPlugin[] {\n if (!Array.isArray(value) || value.length === 0) {\n return [...DEFAULT_AUTH_PLUGIN_LIST];\n }\n\n const normalized = value\n .map((entry: unknown) => normalizeAuthPlugin(entry))\n .filter((entry: FirebirdAuthPlugin, index: number, source: FirebirdAuthPlugin[]) => source.indexOf(entry) === index);\n\n return normalized.length > 0 ? normalized : [...DEFAULT_AUTH_PLUGIN_LIST];\n}\n\nexport function normalizeFirebirdOptions(options: Options): FirebirdOptions {\n const compatibilityOptions = options as FirebirdOptions;\n return {\n ...options,\n wireCrypt: normalizeWireCryptMode(compatibilityOptions.wireCrypt),\n pluginName: normalizeAuthPlugin(compatibilityOptions.pluginName),\n authPlugins: normalizeAuthPluginList(compatibilityOptions.authPlugins),\n };\n}\n\nfunction isRetryableCompatibilityError(error: unknown): boolean {\n const message = String((error as { message?: unknown })?.message ?? error ?? \"\").toLowerCase();\n return message.includes(\"incompatible wire encryption\")\n || message.includes(\"no matching plugins on server\")\n || message.includes(\"unknown auth plugin\")\n || message.includes(\"unknow auth plugin\")\n || message.includes(\"timeout during firebird attach\");\n}\n\nfunction pushUniqueCandidate(target: FirebirdOptions[], candidate: FirebirdOptions): void {\n const normalized = normalizeFirebirdOptions(candidate);\n const key = `${normalized.pluginName}|${normalized.wireCrypt}|${(normalized.authPlugins ?? []).join(\",\")}`;\n const alreadyPresent = target.some((entry) => {\n const normalizedEntry = normalizeFirebirdOptions(entry);\n return `${normalizedEntry.pluginName}|${normalizedEntry.wireCrypt}|${(normalizedEntry.authPlugins ?? []).join(\",\")}` === key;\n });\n\n if (!alreadyPresent) {\n target.push(normalized);\n }\n}\n\nfunction appendPluginCandidates(\n target: FirebirdOptions[],\n base: FirebirdOptions,\n pluginName: FirebirdAuthPlugin,\n wireCryptModes: FirebirdWireCryptMode[],\n): void {\n wireCryptModes.forEach((wireCrypt) => {\n pushUniqueCandidate(target, { ...base, pluginName, wireCrypt });\n });\n}\n\nexport function buildFirebirdCompatibilityCandidates(options: Options): FirebirdOptions[] {\n const normalized = normalizeFirebirdOptions(options);\n const compatibilityOptions = options as FirebirdOptions;\n const hasExplicitPlugin = compatibilityOptions.pluginName !== undefined;\n const hasExplicitWireCrypt = compatibilityOptions.wireCrypt !== undefined;\n const candidates: FirebirdOptions[] = [];\n\n pushUniqueCandidate(candidates, normalized);\n\n if (hasExplicitPlugin && hasExplicitWireCrypt) {\n return candidates;\n }\n\n if (hasExplicitPlugin) {\n const wireCryptModes = normalized.pluginName === \"Legacy_Auth\"\n ? [\"disabled\", \"enabled\"] as FirebirdWireCryptMode[]\n : [\"enabled\", \"required\", \"disabled\"] as FirebirdWireCryptMode[];\n\n appendPluginCandidates(candidates, normalized, normalized.pluginName!, wireCryptModes);\n return candidates;\n }\n\n if (hasExplicitWireCrypt) {\n appendPluginCandidates(candidates, normalized, \"Srp256\", [normalized.wireCrypt!]);\n appendPluginCandidates(candidates, normalized, \"Srp\", [normalized.wireCrypt!]);\n appendPluginCandidates(candidates, normalized, \"Legacy_Auth\", [normalized.wireCrypt!]);\n return candidates;\n }\n\n appendPluginCandidates(candidates, normalized, \"Srp256\", [\"enabled\", \"required\", \"disabled\"]);\n appendPluginCandidates(candidates, normalized, \"Srp\", [\"enabled\", \"required\", \"disabled\"]);\n appendPluginCandidates(candidates, normalized, \"Legacy_Auth\", [\"disabled\", \"enabled\"]);\n return candidates;\n}\n\nexport function shouldRetryFirebirdCompatibility(error: unknown): boolean {\n return isRetryableCompatibilityError(error);\n}\n\nexport function describeFirebirdCompatibilityOptions(options: Options): string {\n const normalized = normalizeFirebirdOptions(options);\n return `plugin=${normalized.pluginName}, wireCrypt=${normalized.wireCrypt}, authPlugins=${(normalized.authPlugins ?? []).join(\"/\")}`;\n}\n\nexport function ensureEsNodeFirebirdCompatibilityPatch(): void {\n const firebird = Firebird as FirebirdModuleLike;\n const connectionPrototype = firebird.Connection?.prototype;\n\n if (!connectionPrototype?.connect || connectionPrototype.__emilsoftwareWireCryptPatched) {\n return;\n }\n\n const originalConnect = connectionPrototype.connect;\n\n connectionPrototype.connect = function patchedConnect(\n this: ConnectionLike,\n options: FirebirdOptions,\n callback: unknown,\n ) {\n const normalizedOptions = normalizeFirebirdOptions(options);\n const wireCryptFlag = toWireCryptFlag(normalizedOptions.wireCrypt);\n const authPlugin = normalizedOptions.pluginName;\n const authPlugins = normalizedOptions.authPlugins ?? DEFAULT_AUTH_PLUGIN_LIST;\n\n this.accept ??= { protocolMinimumType: 0, pluginName: authPlugin };\n\n const blr = this._blr;\n const originalAddBytes = blr?.addBytes;\n const originalAddString = blr?.addString;\n\n if (!blr || !originalAddBytes || !originalAddString) {\n return originalConnect.call(this, normalizedOptions, callback);\n }\n\n const patchedOptions = authPlugin === \"Srp256\"\n ? { ...normalizedOptions, pluginName: \"Srp\" as FirebirdAuthPlugin }\n : normalizedOptions;\n\n blr.addBytes = function patchedAddBytes(bytes: number[], ...args: unknown[]) {\n if (Array.isArray(bytes) && bytes.length === 6 && bytes[0] === CNCT_CLIENT_CRYPT && bytes[1] === 4) {\n return originalAddBytes.call(this, [bytes[0], bytes[1], wireCryptFlag, 0, 0, 0], ...args);\n }\n\n return originalAddBytes.call(this, bytes, ...args);\n };\n\n blr.addString = function patchedAddString(code: number, value: string, encoding?: string) {\n if (code === CNCT_PLUGIN_NAME) {\n return originalAddString.call(this, code, authPlugin, encoding);\n }\n\n if (code === CNCT_PLUGIN_LIST) {\n return originalAddString.call(this, code, authPlugins.join(\",\"), encoding);\n }\n\n return originalAddString.call(this, code, value, encoding);\n };\n\n try {\n return originalConnect.call(this, patchedOptions, callback);\n } finally {\n blr.addBytes = originalAddBytes;\n blr.addString = originalAddString;\n }\n };\n\n connectionPrototype.__emilsoftwareWireCryptPatched = true;\n}\n\nensureEsNodeFirebirdCompatibilityPatch();\n"]}
|