@noormdev/sdk 1.4.1 → 1.5.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.
@@ -1,5 +1,6 @@
1
1
  import { createRequire } from 'module';
2
- import { attemptSync, observer, attempt } from './chunk-LY2F7ZFI.js';
2
+ import { observer } from './chunk-6LG4ENOJ.js';
3
+ import { attemptSync, attempt } from './chunk-TXDGFA44.js';
3
4
  import { dist_default } from './chunk-TBRUDUBQ.js';
4
5
  import { readFile as readFile$1, readdir, stat } from 'fs/promises';
5
6
  import * as fs from 'fs';
@@ -2505,7 +2506,7 @@ function createIncludeHelper(templateDir, projectRoot, options) {
2505
2506
  throw new Error(`Include path escapes project root: ${includePath}`);
2506
2507
  }
2507
2508
  if (resolved.endsWith(".tmpl")) {
2508
- const { processFile: processFile2 } = await import('./engine-MZQ364EH.js');
2509
+ const { processFile: processFile2 } = await import('./engine-P74UTJQO.js');
2509
2510
  const result = await processFile2(resolved, options);
2510
2511
  return result.sql;
2511
2512
  }
@@ -2587,5 +2588,5 @@ voca/es/index.js:
2587
2588
  */
2588
2589
 
2589
2590
  export { DT_EXTENSIONS, DtReader, ENCODED_TYPES, FORMAT_VERSION, encryptWithPassphrase, es_default, eta, isTemplate, processFile, processFiles, renderTemplate };
2590
- //# sourceMappingURL=chunk-G4B7EHL7.js.map
2591
- //# sourceMappingURL=chunk-G4B7EHL7.js.map
2591
+ //# sourceMappingURL=chunk-M7Q44VFJ.js.map
2592
+ //# sourceMappingURL=chunk-M7Q44VFJ.js.map
@@ -0,0 +1,188 @@
1
+ import { createRequire } from 'module';
2
+ import { attemptSync } from './chunk-TXDGFA44.js';
3
+ import { DEFAULT_PORTS, connectTimeoutFor } from './chunk-WE2JLJMT.js';
4
+ import { existsSync, constants, accessSync } from 'fs';
5
+ import { resolve, dirname } from 'path';
6
+
7
+ createRequire(import.meta.url);
8
+ var DatabaseConnectionError = class extends Error {
9
+ constructor(message, serverCode, serverMessage, options) {
10
+ super(message, options);
11
+ this.serverCode = serverCode;
12
+ this.serverMessage = serverMessage;
13
+ }
14
+ name = "DatabaseConnectionError";
15
+ };
16
+ var noPassword = ({ user }) => `No password was supplied for user '${user}', and the server requires one.`;
17
+ var timedOut = ({ where, config }) => `${where} did not answer within ${connectTimeoutFor(config)}ms. Check the host and port, and that no firewall is dropping the connection.`;
18
+ var SERVER_FULL = "The server has no free connections (max_connections reached). Try again later.";
19
+ var TRANSPORT_REASONS = [
20
+ [["ECONNREFUSED"], ({ where }) => `Connection refused at ${where}: nothing is listening there. Check the host and port, and that the server is running.`],
21
+ [["ENOTFOUND"], ({ host }) => `Host '${host}' could not be found. Check the host name.`],
22
+ [["EAI_AGAIN"], ({ host }) => `Host '${host}' could not be looked up: DNS did not answer. Check the network connection.`],
23
+ [["ETIMEDOUT", "ETIMEOUT"], timedOut],
24
+ [["EHOSTUNREACH", "ENETUNREACH"], ({ host }) => `${host} is unreachable from this machine: there is no network route to it.`],
25
+ [["ECONNRESET"], ({ where }) => `${where} closed the connection during the handshake. Check that the port belongs to this database server and that the ssl setting matches what it expects.`]
26
+ ];
27
+ var TLS_CERTIFICATE_CODES = /* @__PURE__ */ new Set([
28
+ "DEPTH_ZERO_SELF_SIGNED_CERT",
29
+ "SELF_SIGNED_CERT_IN_CHAIN",
30
+ "UNABLE_TO_VERIFY_LEAF_SIGNATURE",
31
+ "UNABLE_TO_GET_ISSUER_CERT_LOCALLY",
32
+ "CERT_HAS_EXPIRED",
33
+ "CERT_NOT_YET_VALID",
34
+ "ERR_TLS_CERT_ALTNAME_INVALID"
35
+ ]);
36
+ var MSSQL_REASONS = [
37
+ [4060, ({ database, where }) => `Cannot open database '${database}' on ${where}: it does not exist or this login has no access to it.`],
38
+ [40615, () => "The server's firewall does not allow this machine's IP address. Add it to the server's firewall rules."],
39
+ [18470, ({ user }) => `Login '${user}' is disabled. An administrator can enable it with ALTER LOGIN ... ENABLE.`],
40
+ [18486, ({ user }) => `Login '${user}' is locked out after too many failed attempts.`],
41
+ [18487, ({ user }) => `The password for login '${user}' has expired. Change it with a SQL Server client, then update this connection.`],
42
+ [18488, ({ user }) => `The password for login '${user}' must be changed before it can log in. Change it with a SQL Server client, then update this connection.`],
43
+ [18456, ({ user }) => `Login failed for user '${user}'. SQL Server does not tell clients why; the usual causes are a wrong password, an unknown login, a login denied CONNECT SQL, or a server that only accepts Windows authentication. The server's error log names the cause.`]
44
+ ];
45
+ var POSTGRES_REASONS = {
46
+ "28P01": ({ user }) => `Password authentication failed for user '${user}'. PostgreSQL does not tell clients why; the usual causes are a wrong password, an unknown role, or an expired password (VALID UNTIL). The server log names the cause.`,
47
+ "28000": ({ user, database, message }) => {
48
+ if (message.includes("is not permitted to log in")) return `Role '${user}' is not allowed to log in (NOLOGIN).`;
49
+ if (message.includes("pg_hba.conf")) {
50
+ return `The server's pg_hba.conf has no rule that lets user '${user}' connect to '${database}' from this machine.`;
51
+ }
52
+ return void 0;
53
+ },
54
+ "3D000": ({ database, where }) => `Database '${database}' does not exist on ${where}.`,
55
+ "42501": ({ user, database, message }) => message.startsWith("permission denied for database") ? `Role '${user}' may not connect to database '${database}': it lacks the CONNECT privilege.` : void 0,
56
+ "53300": ({ user, message }) => message.includes("for role") ? `Role '${user}' has used up its connection limit (CONNECTION LIMIT).` : SERVER_FULL,
57
+ "57P03": () => "The server is starting up or shutting down. Try again in a moment."
58
+ };
59
+ var POSTGRES_CLIENT_REASONS = [
60
+ // pg raises this itself when the server asks for a SCRAM password and the
61
+ // config has none.
62
+ ["client password must be a string", noPassword],
63
+ ["The server does not support SSL connections", () => "The server does not accept TLS connections. Turn ssl off for this connection."],
64
+ ["Connection terminated due to connection timeout", timedOut]
65
+ ];
66
+ var MYSQL_REASONS = {
67
+ ER_ACCESS_DENIED_ERROR: (failure) => failure.message.includes("(using password: NO)") ? noPassword(failure) : `Access denied for user '${failure.user}'. MySQL does not tell clients why; the usual causes are a wrong password, an unknown user, no account for this machine's host, or an account that requires TLS (REQUIRE SSL).`,
68
+ ER_DBACCESS_DENIED_ERROR: ({ user, database }) => `User '${user}' has no privileges on database '${database}'.`,
69
+ ER_BAD_DB_ERROR: ({ database, where }) => `Database '${database}' does not exist on ${where}.`,
70
+ ER_HOST_NOT_PRIVILEGED: () => "The server accepts no account from this machine's host.",
71
+ ER_ACCOUNT_HAS_BEEN_LOCKED: ({ user }) => `Account '${user}' is locked. An administrator can unlock it with ALTER USER ... ACCOUNT UNLOCK.`,
72
+ ER_MUST_CHANGE_PASSWORD_LOGIN: ({ user }) => `The password for '${user}' has expired. Change it with a MySQL client, then update this connection.`,
73
+ ER_CON_COUNT_ERROR: () => SERVER_FULL,
74
+ ER_USER_LIMIT_REACHED: ({ user }) => `User '${user}' has used up its connection limit (MAX_USER_CONNECTIONS).`,
75
+ ER_HOST_IS_BLOCKED: () => "The server blocked this machine after too many connection errors. An administrator can clear its host cache.",
76
+ ER_SECURE_TRANSPORT_REQUIRED: () => "The server only accepts TLS connections. Turn ssl on for this connection."
77
+ };
78
+ function explainConnectionError(err, config) {
79
+ if (err instanceof DatabaseConnectionError) return err;
80
+ const codes = errorCodes(err);
81
+ const failure = describeFailure(err, config);
82
+ const reason = explainTransport(codes, failure) ?? explainServer(codes, failure);
83
+ const serverMessage = serverMessages(err).join(" | ");
84
+ if (!reason && codes.length === 0) return err;
85
+ return new DatabaseConnectionError(
86
+ reason ?? (err.message || serverMessage),
87
+ codes.join(", ") || void 0,
88
+ serverMessage,
89
+ { cause: err }
90
+ );
91
+ }
92
+ function explainMssqlLoginFailure(serverErrors, err, config) {
93
+ if (serverErrors.length === 0) return err;
94
+ const failure = describeFailure(err, config);
95
+ const match = MSSQL_REASONS.find(([number]) => serverErrors.some((e) => e.number === number));
96
+ return new DatabaseConnectionError(
97
+ match?.[1](failure) ?? err.message,
98
+ serverErrors.map((e) => e.number).join(", "),
99
+ serverErrors.map((e) => e.message).join(" | "),
100
+ { cause: err }
101
+ );
102
+ }
103
+ function describeFailure(err, config) {
104
+ const host = config.host ?? "localhost";
105
+ return {
106
+ user: config.user ?? "",
107
+ database: config.database,
108
+ host,
109
+ where: `${host}:${config.port ?? DEFAULT_PORTS[config.dialect]}`,
110
+ config,
111
+ message: err.message
112
+ };
113
+ }
114
+ function walk(err, visit, seen = /* @__PURE__ */ new Set()) {
115
+ if (typeof err !== "object" || err === null || seen.has(err)) return;
116
+ const inner = Reflect.get(err, "errors");
117
+ seen.add(err);
118
+ visit(err);
119
+ walk(Reflect.get(err, "cause"), visit, seen);
120
+ if (Array.isArray(inner)) {
121
+ for (const each of inner) walk(each, visit, seen);
122
+ }
123
+ }
124
+ function errorCodes(err) {
125
+ const codes = /* @__PURE__ */ new Set();
126
+ walk(err, (error) => {
127
+ const code = Reflect.get(error, "code");
128
+ if (typeof code === "string") codes.add(code);
129
+ });
130
+ return [...codes];
131
+ }
132
+ function serverMessages(err) {
133
+ const messages = /* @__PURE__ */ new Set();
134
+ walk(err, (error) => {
135
+ const message = Reflect.get(error, "message");
136
+ if (typeof message === "string" && message) messages.add(message);
137
+ });
138
+ return [...messages];
139
+ }
140
+ function explainTransport(codes, failure) {
141
+ const transport = TRANSPORT_REASONS.find(([matches]) => matches.some((code) => codes.includes(code)));
142
+ if (transport) return transport[1](failure);
143
+ const certificateCode = codes.find((code) => TLS_CERTIFICATE_CODES.has(code));
144
+ if (!certificateCode) return void 0;
145
+ const withoutValidation = failure.config.dialect === "mssql" ? "turn ssl off to keep encryption without validating the certificate" : "turn ssl off, which also turns off encryption";
146
+ return `The server's TLS certificate was rejected (${certificateCode}). Trust the authority that issued it on this machine, or ${withoutValidation}.`;
147
+ }
148
+ function explainServer(codes, failure) {
149
+ const code = codes[0] ?? "";
150
+ switch (failure.config.dialect) {
151
+ case "postgres": {
152
+ const client = POSTGRES_CLIENT_REASONS.find(([text]) => failure.message.includes(text));
153
+ return POSTGRES_REASONS[code]?.(failure) ?? client?.[1](failure);
154
+ }
155
+ case "mysql":
156
+ return MYSQL_REASONS[code]?.(failure);
157
+ case "sqlite":
158
+ return explainSqlite(code, failure);
159
+ default:
160
+ return void 0;
161
+ }
162
+ }
163
+ function explainSqlite(code, failure) {
164
+ const file = resolve(failure.config.filename ?? failure.database);
165
+ const dir = dirname(file);
166
+ if (code === "SQLITE_NOTADB") {
167
+ return `'${file}' is not a SQLite database, or it is encrypted.`;
168
+ }
169
+ if (code !== "SQLITE_CANTOPEN") return void 0;
170
+ if (!existsSync(dir)) {
171
+ return `Cannot open SQLite database '${file}': directory '${dir}' is missing.`;
172
+ }
173
+ if (existsSync(file) && !canAccess(file, constants.R_OK | constants.W_OK)) {
174
+ return `Cannot open SQLite database '${file}': this process lacks read or write permission on the file.`;
175
+ }
176
+ if (!existsSync(file) && !canAccess(dir, constants.W_OK)) {
177
+ return `Cannot create SQLite database '${file}': this process lacks write permission on '${dir}'.`;
178
+ }
179
+ return void 0;
180
+ }
181
+ function canAccess(path, mode) {
182
+ const [, err] = attemptSync(() => accessSync(path, mode));
183
+ return !err;
184
+ }
185
+
186
+ export { DatabaseConnectionError, explainConnectionError, explainMssqlLoginFailure };
187
+ //# sourceMappingURL=chunk-OXTXFKWJ.js.map
188
+ //# sourceMappingURL=chunk-OXTXFKWJ.js.map