taurusdb-core 0.1.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.
Files changed (170) hide show
  1. package/README.md +21 -0
  2. package/dist/auth/secret-resolver.d.ts +16 -0
  3. package/dist/auth/secret-resolver.js +64 -0
  4. package/dist/auth/sql-profile-loader/env-source.d.ts +3 -0
  5. package/dist/auth/sql-profile-loader/env-source.js +94 -0
  6. package/dist/auth/sql-profile-loader/file-source.d.ts +6 -0
  7. package/dist/auth/sql-profile-loader/file-source.js +40 -0
  8. package/dist/auth/sql-profile-loader/loader.d.ts +16 -0
  9. package/dist/auth/sql-profile-loader/loader.js +81 -0
  10. package/dist/auth/sql-profile-loader/parsing.d.ts +14 -0
  11. package/dist/auth/sql-profile-loader/parsing.js +216 -0
  12. package/dist/auth/sql-profile-loader/runtime-override.d.ts +14 -0
  13. package/dist/auth/sql-profile-loader/runtime-override.js +52 -0
  14. package/dist/auth/sql-profile-loader/types.d.ts +64 -0
  15. package/dist/auth/sql-profile-loader/types.js +1 -0
  16. package/dist/auth/sql-profile-loader.d.ts +4 -0
  17. package/dist/auth/sql-profile-loader.js +3 -0
  18. package/dist/capability/feature-matrix.d.ts +5 -0
  19. package/dist/capability/feature-matrix.js +237 -0
  20. package/dist/capability/probe.d.ts +19 -0
  21. package/dist/capability/probe.js +139 -0
  22. package/dist/capability/types.d.ts +49 -0
  23. package/dist/capability/types.js +16 -0
  24. package/dist/capability/version.d.ts +3 -0
  25. package/dist/capability/version.js +47 -0
  26. package/dist/cloud/auth.d.ts +26 -0
  27. package/dist/cloud/auth.js +198 -0
  28. package/dist/cloud/instances.d.ts +46 -0
  29. package/dist/cloud/instances.js +224 -0
  30. package/dist/config/env.d.ts +1 -0
  31. package/dist/config/env.js +194 -0
  32. package/dist/config/index.d.ts +6 -0
  33. package/dist/config/index.js +21 -0
  34. package/dist/config/redaction.d.ts +2 -0
  35. package/dist/config/redaction.js +19 -0
  36. package/dist/config/schema.d.ts +417 -0
  37. package/dist/config/schema.js +100 -0
  38. package/dist/context/datasource-resolver.d.ts +19 -0
  39. package/dist/context/datasource-resolver.js +71 -0
  40. package/dist/context/session-context.d.ts +26 -0
  41. package/dist/context/session-context.js +1 -0
  42. package/dist/diagnostics/metrics-source.d.ts +65 -0
  43. package/dist/diagnostics/metrics-source.js +280 -0
  44. package/dist/diagnostics/slow-sql-source/das-source.d.ts +43 -0
  45. package/dist/diagnostics/slow-sql-source/das-source.js +170 -0
  46. package/dist/diagnostics/slow-sql-source/factory.d.ts +5 -0
  47. package/dist/diagnostics/slow-sql-source/factory.js +87 -0
  48. package/dist/diagnostics/slow-sql-source/parsers.d.ts +7 -0
  49. package/dist/diagnostics/slow-sql-source/parsers.js +125 -0
  50. package/dist/diagnostics/slow-sql-source/taurus-api-source.d.ts +42 -0
  51. package/dist/diagnostics/slow-sql-source/taurus-api-source.js +149 -0
  52. package/dist/diagnostics/slow-sql-source/types.d.ts +40 -0
  53. package/dist/diagnostics/slow-sql-source/types.js +1 -0
  54. package/dist/diagnostics/slow-sql-source/utils.d.ts +20 -0
  55. package/dist/diagnostics/slow-sql-source/utils.js +170 -0
  56. package/dist/diagnostics/slow-sql-source.d.ts +4 -0
  57. package/dist/diagnostics/slow-sql-source.js +3 -0
  58. package/dist/diagnostics/types.d.ts +189 -0
  59. package/dist/diagnostics/types.js +39 -0
  60. package/dist/engine/data-access/locks.d.ts +8 -0
  61. package/dist/engine/data-access/locks.js +146 -0
  62. package/dist/engine/data-access/processlist.d.ts +4 -0
  63. package/dist/engine/data-access/processlist.js +56 -0
  64. package/dist/engine/data-access/statements.d.ts +10 -0
  65. package/dist/engine/data-access/statements.js +203 -0
  66. package/dist/engine/data-access/storage.d.ts +6 -0
  67. package/dist/engine/data-access/storage.js +96 -0
  68. package/dist/engine/data-access.d.ts +4 -0
  69. package/dist/engine/data-access.js +4 -0
  70. package/dist/engine/diagnostics.d.ts +7 -0
  71. package/dist/engine/diagnostics.js +7 -0
  72. package/dist/engine/helper-modules/diagnostics.d.ts +57 -0
  73. package/dist/engine/helper-modules/diagnostics.js +322 -0
  74. package/dist/engine/helper-modules/parsers.d.ts +13 -0
  75. package/dist/engine/helper-modules/parsers.js +283 -0
  76. package/dist/engine/helper-modules/sql.d.ts +12 -0
  77. package/dist/engine/helper-modules/sql.js +119 -0
  78. package/dist/engine/helper-modules/types.d.ts +103 -0
  79. package/dist/engine/helper-modules/types.js +1 -0
  80. package/dist/engine/helpers.d.ts +4 -0
  81. package/dist/engine/helpers.js +4 -0
  82. package/dist/engine/runtime.d.ts +20 -0
  83. package/dist/engine/runtime.js +385 -0
  84. package/dist/engine/types.d.ts +125 -0
  85. package/dist/engine/types.js +1 -0
  86. package/dist/engine/workflows/connection-spike.d.ts +4 -0
  87. package/dist/engine/workflows/connection-spike.js +316 -0
  88. package/dist/engine/workflows/db-hotspot.d.ts +4 -0
  89. package/dist/engine/workflows/db-hotspot.js +182 -0
  90. package/dist/engine/workflows/lock-contention-helpers/entities.d.ts +9 -0
  91. package/dist/engine/workflows/lock-contention-helpers/entities.js +58 -0
  92. package/dist/engine/workflows/lock-contention-helpers/no-match.d.ts +3 -0
  93. package/dist/engine/workflows/lock-contention-helpers/no-match.js +65 -0
  94. package/dist/engine/workflows/lock-contention-helpers/report.d.ts +21 -0
  95. package/dist/engine/workflows/lock-contention-helpers/report.js +104 -0
  96. package/dist/engine/workflows/lock-contention-helpers/root-cause.d.ts +4 -0
  97. package/dist/engine/workflows/lock-contention-helpers/root-cause.js +79 -0
  98. package/dist/engine/workflows/lock-contention-helpers/signals.d.ts +22 -0
  99. package/dist/engine/workflows/lock-contention-helpers/signals.js +34 -0
  100. package/dist/engine/workflows/lock-contention-helpers.d.ts +5 -0
  101. package/dist/engine/workflows/lock-contention-helpers.js +5 -0
  102. package/dist/engine/workflows/lock-contention.d.ts +4 -0
  103. package/dist/engine/workflows/lock-contention.js +67 -0
  104. package/dist/engine/workflows/service-latency.d.ts +4 -0
  105. package/dist/engine/workflows/service-latency.js +262 -0
  106. package/dist/engine/workflows/slow-query-helpers.d.ts +41 -0
  107. package/dist/engine/workflows/slow-query-helpers.js +253 -0
  108. package/dist/engine/workflows/slow-query.d.ts +4 -0
  109. package/dist/engine/workflows/slow-query.js +156 -0
  110. package/dist/engine/workflows/storage-pressure-helpers.d.ts +12 -0
  111. package/dist/engine/workflows/storage-pressure-helpers.js +281 -0
  112. package/dist/engine/workflows/storage-pressure.d.ts +4 -0
  113. package/dist/engine/workflows/storage-pressure.js +27 -0
  114. package/dist/engine/workflows/top-slow-sql.d.ts +4 -0
  115. package/dist/engine/workflows/top-slow-sql.js +222 -0
  116. package/dist/engine.d.ts +77 -0
  117. package/dist/engine.js +240 -0
  118. package/dist/executor/adapters/mysql.d.ts +2 -0
  119. package/dist/executor/adapters/mysql.js +114 -0
  120. package/dist/executor/connection-pool.d.ts +105 -0
  121. package/dist/executor/connection-pool.js +236 -0
  122. package/dist/executor/explain.d.ts +5 -0
  123. package/dist/executor/explain.js +119 -0
  124. package/dist/executor/query-tracker.d.ts +45 -0
  125. package/dist/executor/query-tracker.js +83 -0
  126. package/dist/executor/result-normalizer.d.ts +6 -0
  127. package/dist/executor/result-normalizer.js +47 -0
  128. package/dist/executor/sql-executor.d.ts +32 -0
  129. package/dist/executor/sql-executor.js +250 -0
  130. package/dist/executor/types.d.ts +70 -0
  131. package/dist/executor/types.js +1 -0
  132. package/dist/index.d.ts +40 -0
  133. package/dist/index.js +21 -0
  134. package/dist/safety/confirmation-store.d.ts +44 -0
  135. package/dist/safety/confirmation-store.js +130 -0
  136. package/dist/safety/guardrail.d.ts +39 -0
  137. package/dist/safety/guardrail.js +99 -0
  138. package/dist/safety/parser/adapter.d.ts +10 -0
  139. package/dist/safety/parser/adapter.js +72 -0
  140. package/dist/safety/parser/ast-utils.d.ts +10 -0
  141. package/dist/safety/parser/ast-utils.js +167 -0
  142. package/dist/safety/parser/features.d.ts +12 -0
  143. package/dist/safety/parser/features.js +113 -0
  144. package/dist/safety/parser/index.d.ts +2 -0
  145. package/dist/safety/parser/index.js +1 -0
  146. package/dist/safety/parser/types.d.ts +76 -0
  147. package/dist/safety/parser/types.js +1 -0
  148. package/dist/safety/redaction.d.ts +34 -0
  149. package/dist/safety/redaction.js +186 -0
  150. package/dist/safety/sql-classifier.d.ts +19 -0
  151. package/dist/safety/sql-classifier.js +43 -0
  152. package/dist/safety/sql-validator.d.ts +19 -0
  153. package/dist/safety/sql-validator.js +143 -0
  154. package/dist/schema/adapters/mysql.d.ts +16 -0
  155. package/dist/schema/adapters/mysql.js +287 -0
  156. package/dist/schema/introspector.d.ts +70 -0
  157. package/dist/schema/introspector.js +40 -0
  158. package/dist/taurus/flashback.d.ts +36 -0
  159. package/dist/taurus/flashback.js +149 -0
  160. package/dist/taurus/recycle-bin.d.ts +14 -0
  161. package/dist/taurus/recycle-bin.js +61 -0
  162. package/dist/utils/formatter.d.ts +70 -0
  163. package/dist/utils/formatter.js +60 -0
  164. package/dist/utils/hash.d.ts +2 -0
  165. package/dist/utils/hash.js +247 -0
  166. package/dist/utils/id.d.ts +2 -0
  167. package/dist/utils/id.js +11 -0
  168. package/dist/utils/logger.d.ts +9 -0
  169. package/dist/utils/logger.js +39 -0
  170. package/package.json +46 -0
@@ -0,0 +1,70 @@
1
+ export type StatementType = "select" | "show" | "explain" | "describe" | "insert" | "update" | "delete" | "alter" | "drop" | "create" | "grant" | "revoke" | "unknown";
2
+ export declare const ErrorCode: {
3
+ readonly DATASOURCE_NOT_FOUND: "DATASOURCE_NOT_FOUND";
4
+ readonly CREDENTIAL_MISSING: "CREDENTIAL_MISSING";
5
+ readonly BLOCKED_SQL: "BLOCKED_SQL";
6
+ readonly CONFIRMATION_REQUIRED: "CONFIRMATION_REQUIRED";
7
+ readonly CONFIRMATION_INVALID: "CONFIRMATION_INVALID";
8
+ readonly INVALID_INPUT: "INVALID_INPUT";
9
+ readonly SQL_SYNTAX_ERROR: "SQL_SYNTAX_ERROR";
10
+ readonly QUERY_TIMEOUT: "QUERY_TIMEOUT";
11
+ readonly QUERY_CANCELLED: "QUERY_CANCELLED";
12
+ readonly CONNECTION_FAILED: "CONNECTION_FAILED";
13
+ readonly RESULT_TOO_LARGE: "RESULT_TOO_LARGE";
14
+ readonly UNSUPPORTED_FEATURE: "UNSUPPORTED_FEATURE";
15
+ };
16
+ export type ErrorCode = (typeof ErrorCode)[keyof typeof ErrorCode];
17
+ export type ToolError = {
18
+ code: ErrorCode;
19
+ message: string;
20
+ retryable?: boolean;
21
+ details?: Record<string, unknown>;
22
+ };
23
+ export type ResponseMetadata = {
24
+ task_id: string;
25
+ sql_hash?: string;
26
+ statement_type?: StatementType;
27
+ duration_ms?: number;
28
+ };
29
+ export type ToolResponse<T = unknown> = {
30
+ ok: boolean;
31
+ summary: string;
32
+ data?: T;
33
+ error?: ToolError;
34
+ metadata: ResponseMetadata;
35
+ };
36
+ export type FormatSuccessOptions = {
37
+ summary: string;
38
+ metadata: ResponseMetadata;
39
+ };
40
+ export type FormatErrorOptions<T = unknown> = {
41
+ code: ErrorCode;
42
+ message: string;
43
+ summary: string;
44
+ metadata: ResponseMetadata;
45
+ retryable?: boolean;
46
+ details?: Record<string, unknown>;
47
+ data?: T;
48
+ };
49
+ export type FormatBlockedOptions = {
50
+ reason: string;
51
+ metadata: ResponseMetadata;
52
+ summary?: string;
53
+ details?: Record<string, unknown>;
54
+ };
55
+ export type FormatConfirmationRequiredOptions = {
56
+ confirmationToken: string;
57
+ metadata: ResponseMetadata;
58
+ summary?: string;
59
+ message?: string;
60
+ riskLevel?: string;
61
+ sqlHash?: string;
62
+ };
63
+ export declare function formatSuccess<T>(data: T, options: FormatSuccessOptions): ToolResponse<T>;
64
+ export declare function formatError<T = unknown>(options: FormatErrorOptions<T>): ToolResponse<T>;
65
+ export declare function formatBlocked(options: FormatBlockedOptions): ToolResponse;
66
+ export declare function formatConfirmationRequired(options: FormatConfirmationRequiredOptions): ToolResponse<{
67
+ confirmation_token: string;
68
+ risk_level?: string;
69
+ sql_hash?: string;
70
+ }>;
@@ -0,0 +1,60 @@
1
+ export const ErrorCode = {
2
+ DATASOURCE_NOT_FOUND: "DATASOURCE_NOT_FOUND",
3
+ CREDENTIAL_MISSING: "CREDENTIAL_MISSING",
4
+ BLOCKED_SQL: "BLOCKED_SQL",
5
+ CONFIRMATION_REQUIRED: "CONFIRMATION_REQUIRED",
6
+ CONFIRMATION_INVALID: "CONFIRMATION_INVALID",
7
+ INVALID_INPUT: "INVALID_INPUT",
8
+ SQL_SYNTAX_ERROR: "SQL_SYNTAX_ERROR",
9
+ QUERY_TIMEOUT: "QUERY_TIMEOUT",
10
+ QUERY_CANCELLED: "QUERY_CANCELLED",
11
+ CONNECTION_FAILED: "CONNECTION_FAILED",
12
+ RESULT_TOO_LARGE: "RESULT_TOO_LARGE",
13
+ UNSUPPORTED_FEATURE: "UNSUPPORTED_FEATURE",
14
+ };
15
+ export function formatSuccess(data, options) {
16
+ return {
17
+ ok: true,
18
+ summary: options.summary,
19
+ data,
20
+ metadata: options.metadata,
21
+ };
22
+ }
23
+ export function formatError(options) {
24
+ return {
25
+ ok: false,
26
+ summary: options.summary,
27
+ data: options.data,
28
+ error: {
29
+ code: options.code,
30
+ message: options.message,
31
+ retryable: options.retryable,
32
+ details: options.details,
33
+ },
34
+ metadata: options.metadata,
35
+ };
36
+ }
37
+ export function formatBlocked(options) {
38
+ return formatError({
39
+ code: ErrorCode.BLOCKED_SQL,
40
+ message: options.reason,
41
+ summary: options.summary ?? "The SQL statement is blocked by safety policy.",
42
+ retryable: false,
43
+ details: options.details,
44
+ metadata: options.metadata,
45
+ });
46
+ }
47
+ export function formatConfirmationRequired(options) {
48
+ return formatError({
49
+ code: ErrorCode.CONFIRMATION_REQUIRED,
50
+ message: options.message ?? "Re-run the same SQL with confirmation_token to continue.",
51
+ summary: options.summary ?? "This SQL will modify data and requires explicit confirmation.",
52
+ retryable: true,
53
+ metadata: options.metadata,
54
+ data: {
55
+ confirmation_token: options.confirmationToken,
56
+ risk_level: options.riskLevel,
57
+ sql_hash: options.sqlHash,
58
+ },
59
+ });
60
+ }
@@ -0,0 +1,2 @@
1
+ export declare function normalizeSql(sql: string): string;
2
+ export declare function sqlHash(normalized: string): string;
@@ -0,0 +1,247 @@
1
+ import { createHash } from "node:crypto";
2
+ const SQL_KEYWORDS = new Set([
3
+ "select",
4
+ "show",
5
+ "describe",
6
+ "desc",
7
+ "explain",
8
+ "from",
9
+ "where",
10
+ "group",
11
+ "by",
12
+ "order",
13
+ "having",
14
+ "limit",
15
+ "offset",
16
+ "join",
17
+ "left",
18
+ "right",
19
+ "inner",
20
+ "outer",
21
+ "cross",
22
+ "on",
23
+ "as",
24
+ "distinct",
25
+ "union",
26
+ "all",
27
+ "insert",
28
+ "into",
29
+ "values",
30
+ "update",
31
+ "set",
32
+ "delete",
33
+ "create",
34
+ "alter",
35
+ "drop",
36
+ "truncate",
37
+ "table",
38
+ "database",
39
+ "schema",
40
+ "if",
41
+ "exists",
42
+ "not",
43
+ "null",
44
+ "and",
45
+ "or",
46
+ "in",
47
+ "is",
48
+ "like",
49
+ "between",
50
+ "case",
51
+ "when",
52
+ "then",
53
+ "else",
54
+ "end",
55
+ "asc",
56
+ "desc",
57
+ "with",
58
+ "recursive",
59
+ "grant",
60
+ "revoke",
61
+ "begin",
62
+ "commit",
63
+ "rollback",
64
+ ].map((keyword) => keyword.toLowerCase()));
65
+ function isWhitespace(char) {
66
+ return char === " " || char === "\t" || char === "\n" || char === "\r" || char === "\f";
67
+ }
68
+ function isWordChar(char) {
69
+ return /[A-Za-z0-9_$]/.test(char);
70
+ }
71
+ function stripSqlComments(sql) {
72
+ let result = "";
73
+ let quoteState = "none";
74
+ let index = 0;
75
+ while (index < sql.length) {
76
+ const char = sql[index];
77
+ const next = sql[index + 1];
78
+ if (quoteState === "none") {
79
+ if (char === "'" || char === '"' || char === "`") {
80
+ quoteState = char;
81
+ result += char;
82
+ index += 1;
83
+ continue;
84
+ }
85
+ if (char === "/" && next === "*") {
86
+ if (result.length > 0 && !isWhitespace(result[result.length - 1])) {
87
+ result += " ";
88
+ }
89
+ index += 2;
90
+ while (index < sql.length && !(sql[index] === "*" && sql[index + 1] === "/")) {
91
+ index += 1;
92
+ }
93
+ if (index < sql.length) {
94
+ index += 2;
95
+ }
96
+ continue;
97
+ }
98
+ if (char === "-" && next === "-") {
99
+ if (result.length > 0 && !isWhitespace(result[result.length - 1])) {
100
+ result += " ";
101
+ }
102
+ index += 2;
103
+ while (index < sql.length && sql[index] !== "\n") {
104
+ index += 1;
105
+ }
106
+ continue;
107
+ }
108
+ if (char === "#") {
109
+ if (result.length > 0 && !isWhitespace(result[result.length - 1])) {
110
+ result += " ";
111
+ }
112
+ index += 1;
113
+ while (index < sql.length && sql[index] !== "\n") {
114
+ index += 1;
115
+ }
116
+ continue;
117
+ }
118
+ }
119
+ else if (char === quoteState) {
120
+ if (sql[index + 1] === quoteState) {
121
+ result += char;
122
+ result += sql[index + 1];
123
+ index += 2;
124
+ continue;
125
+ }
126
+ quoteState = "none";
127
+ result += char;
128
+ index += 1;
129
+ continue;
130
+ }
131
+ result += char;
132
+ index += 1;
133
+ }
134
+ return result;
135
+ }
136
+ function trimLineEndWhitespace(sql) {
137
+ return sql
138
+ .replace(/\r\n/g, "\n")
139
+ .split("\n")
140
+ .map((line) => line.replace(/[ \t]+$/g, ""))
141
+ .join("\n");
142
+ }
143
+ function collapseWhitespaceOutsideLiterals(sql) {
144
+ let result = "";
145
+ let quoteState = "none";
146
+ let pendingSpace = false;
147
+ let index = 0;
148
+ while (index < sql.length) {
149
+ const char = sql[index];
150
+ if (quoteState === "none") {
151
+ if (char === "'" || char === '"' || char === "`") {
152
+ if (pendingSpace && result.length > 0) {
153
+ result += " ";
154
+ }
155
+ pendingSpace = false;
156
+ quoteState = char;
157
+ result += char;
158
+ index += 1;
159
+ continue;
160
+ }
161
+ if (isWhitespace(char)) {
162
+ pendingSpace = true;
163
+ index += 1;
164
+ continue;
165
+ }
166
+ if (pendingSpace && result.length > 0) {
167
+ result += " ";
168
+ }
169
+ pendingSpace = false;
170
+ result += char;
171
+ index += 1;
172
+ continue;
173
+ }
174
+ result += char;
175
+ if (char === quoteState) {
176
+ if (sql[index + 1] === quoteState) {
177
+ result += sql[index + 1];
178
+ index += 2;
179
+ continue;
180
+ }
181
+ quoteState = "none";
182
+ }
183
+ index += 1;
184
+ }
185
+ return result.trim();
186
+ }
187
+ function uppercaseKeywordsOutsideLiterals(sql) {
188
+ let result = "";
189
+ let quoteState = "none";
190
+ let index = 0;
191
+ let currentWord = "";
192
+ const flushWord = () => {
193
+ if (currentWord.length === 0) {
194
+ return;
195
+ }
196
+ const lower = currentWord.toLowerCase();
197
+ result += SQL_KEYWORDS.has(lower) ? lower.toUpperCase() : currentWord;
198
+ currentWord = "";
199
+ };
200
+ while (index < sql.length) {
201
+ const char = sql[index];
202
+ if (quoteState === "none") {
203
+ if (char === "'" || char === '"' || char === "`") {
204
+ flushWord();
205
+ quoteState = char;
206
+ result += char;
207
+ index += 1;
208
+ continue;
209
+ }
210
+ if (isWordChar(char)) {
211
+ currentWord += char;
212
+ }
213
+ else {
214
+ flushWord();
215
+ result += char;
216
+ }
217
+ index += 1;
218
+ continue;
219
+ }
220
+ flushWord();
221
+ result += char;
222
+ if (char === quoteState) {
223
+ if (sql[index + 1] === quoteState) {
224
+ result += sql[index + 1];
225
+ index += 2;
226
+ continue;
227
+ }
228
+ quoteState = "none";
229
+ }
230
+ index += 1;
231
+ }
232
+ flushWord();
233
+ return result;
234
+ }
235
+ function stripTrailingSemicolon(sql) {
236
+ return sql.replace(/\s*;\s*$/, "").trim();
237
+ }
238
+ export function normalizeSql(sql) {
239
+ const withoutComments = stripSqlComments(sql);
240
+ const lineTrimmed = trimLineEndWhitespace(withoutComments);
241
+ const collapsed = collapseWhitespaceOutsideLiterals(lineTrimmed);
242
+ const keywordUppercased = uppercaseKeywordsOutsideLiterals(collapsed);
243
+ return stripTrailingSemicolon(keywordUppercased);
244
+ }
245
+ export function sqlHash(normalized) {
246
+ return createHash("sha256").update(normalized).digest("hex").slice(0, 16);
247
+ }
@@ -0,0 +1,2 @@
1
+ export declare function generateTaskId(now?: number): string;
2
+ export declare function generateQueryId(now?: number): string;
@@ -0,0 +1,11 @@
1
+ import { monotonicFactory } from "ulid";
2
+ const monotonicUlid = monotonicFactory();
3
+ function generatePrefixedId(prefix, now = Date.now()) {
4
+ return `${prefix}${monotonicUlid(now).toLowerCase()}`;
5
+ }
6
+ export function generateTaskId(now) {
7
+ return generatePrefixedId("task_", now);
8
+ }
9
+ export function generateQueryId(now) {
10
+ return generatePrefixedId("qry_", now);
11
+ }
@@ -0,0 +1,9 @@
1
+ import pino, { type DestinationStream, type Logger } from "pino";
2
+ type TaskContext = {
3
+ task_id: string;
4
+ };
5
+ export declare function createLogger(destination?: DestinationStream | NodeJS.WritableStream): Logger;
6
+ export declare const logger: pino.Logger;
7
+ export declare function withTaskContext<T>(task_id: string, fn: () => Promise<T>): Promise<T>;
8
+ export declare function getTaskContext(): TaskContext | undefined;
9
+ export {};
@@ -0,0 +1,39 @@
1
+ import { AsyncLocalStorage } from "node:async_hooks";
2
+ import pino from "pino";
3
+ const taskContextStorage = new AsyncLocalStorage();
4
+ const REDACT_PATHS = [
5
+ "password",
6
+ "*.password",
7
+ "credentials.*",
8
+ "secret",
9
+ "token",
10
+ "*.token",
11
+ ];
12
+ function createDefaultDestination() {
13
+ return pino.destination({ fd: 2, sync: false });
14
+ }
15
+ function createLoggerOptions() {
16
+ return {
17
+ level: process.env.TAURUSDB_MCP_LOG_LEVEL ?? "info",
18
+ base: undefined,
19
+ redact: {
20
+ paths: REDACT_PATHS,
21
+ censor: "[REDACTED]",
22
+ },
23
+ mixin: () => {
24
+ const taskId = taskContextStorage.getStore()?.task_id;
25
+ return taskId ? { task_id: taskId } : {};
26
+ },
27
+ timestamp: pino.stdTimeFunctions.isoTime,
28
+ };
29
+ }
30
+ export function createLogger(destination) {
31
+ return pino(createLoggerOptions(), destination ?? createDefaultDestination());
32
+ }
33
+ export const logger = createLogger();
34
+ export function withTaskContext(task_id, fn) {
35
+ return taskContextStorage.run({ task_id }, fn);
36
+ }
37
+ export function getTaskContext() {
38
+ return taskContextStorage.getStore();
39
+ }
package/package.json ADDED
@@ -0,0 +1,46 @@
1
+ {
2
+ "name": "taurusdb-core",
3
+ "version": "0.1.0",
4
+ "description": "Shared TaurusDB data-plane engine for schema, SQL execution, guardrails, and diagnostics.",
5
+ "type": "module",
6
+ "main": "dist/index.js",
7
+ "types": "dist/index.d.ts",
8
+ "engines": {
9
+ "node": ">=20.0.0"
10
+ },
11
+ "keywords": [
12
+ "taurusdb",
13
+ "mysql",
14
+ "database",
15
+ "diagnostics",
16
+ "guardrails"
17
+ ],
18
+ "publishConfig": {
19
+ "access": "public"
20
+ },
21
+ "files": [
22
+ "dist"
23
+ ],
24
+ "exports": {
25
+ ".": {
26
+ "types": "./dist/index.d.ts",
27
+ "default": "./dist/index.js"
28
+ },
29
+ "./*": {
30
+ "types": "./dist/*.d.ts",
31
+ "default": "./dist/*.js"
32
+ }
33
+ },
34
+ "scripts": {
35
+ "build": "tsc -p tsconfig.json",
36
+ "check": "tsc --noEmit -p tsconfig.json",
37
+ "test": "node --test tests/*.test.mjs"
38
+ },
39
+ "dependencies": {
40
+ "mysql2": "^3.22.1",
41
+ "node-sql-parser": "^5.4.0",
42
+ "pino": "^9.11.0",
43
+ "ulid": "^3.0.1",
44
+ "zod": "^3.24.1"
45
+ }
46
+ }