squilo 0.4.1 → 0.6.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +2 -2
- package/dist/index.js +97 -74
- package/dist/index.js.map +11 -11
- package/dist/pipes/auth/strategies/index.d.ts +2 -2
- package/dist/pipes/auth/strategies/index.js +1 -1
- package/dist/pipes/output/strategies/index.d.ts +51 -5
- package/dist/pipes/output/strategies/index.js +132 -72
- package/dist/pipes/output/strategies/index.js.map +6 -6
- package/dist/shared/chunk-shrjzctv.js +56 -0
- package/dist/shared/{chunk-s3vw82k6.js.map → chunk-shrjzctv.js.map} +1 -1
- package/dist/shared/{chunk-ydmc6s5q.d.ts → chunk-t5frzhxr.d.ts} +4 -5
- package/dist/shared/chunk-vct19a11.d.ts +59 -0
- package/package.json +4 -4
- package/dist/shared/chunk-pmxhq7r6.d.ts +0 -35
- package/dist/shared/chunk-s3vw82k6.js +0 -23
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { ServerChain, ServerConfig } from "./shared/chunk-
|
|
2
|
-
import "./shared/chunk-
|
|
1
|
+
import { ServerChain, ServerConfig } from "./shared/chunk-t5frzhxr";
|
|
2
|
+
import "./shared/chunk-vct19a11";
|
|
3
3
|
declare const Server: (config: ServerConfig) => ServerChain;
|
|
4
4
|
import * as SQL from "mssql";
|
|
5
5
|
export { Server, SQL };
|
package/dist/index.js
CHANGED
|
@@ -1,8 +1,36 @@
|
|
|
1
1
|
// @bun
|
|
2
|
-
import
|
|
2
|
+
import {
|
|
3
|
+
__callDispose,
|
|
4
|
+
__using
|
|
5
|
+
} from "./shared/chunk-shrjzctv.js";
|
|
3
6
|
|
|
4
7
|
// src/pool/index.ts
|
|
5
8
|
import { ConnectionPool } from "mssql";
|
|
9
|
+
var TransactionWrapper = function(transaction) {
|
|
10
|
+
Object.setPrototypeOf(this, Object.getPrototypeOf(transaction));
|
|
11
|
+
Object.assign(this, transaction);
|
|
12
|
+
let committed = false;
|
|
13
|
+
this.commit$ = async function() {
|
|
14
|
+
committed = true;
|
|
15
|
+
return await this.commit();
|
|
16
|
+
};
|
|
17
|
+
this[Symbol.asyncDispose] = async function() {
|
|
18
|
+
if (!committed) {
|
|
19
|
+
return await this.rollback();
|
|
20
|
+
}
|
|
21
|
+
};
|
|
22
|
+
};
|
|
23
|
+
var ConnectionPoolWrapper = function(conn) {
|
|
24
|
+
Object.setPrototypeOf(this, Object.getPrototypeOf(conn));
|
|
25
|
+
Object.assign(this, conn);
|
|
26
|
+
this.transaction$ = async function() {
|
|
27
|
+
const transaction = await this.transaction().begin();
|
|
28
|
+
return new TransactionWrapper(transaction);
|
|
29
|
+
};
|
|
30
|
+
this[Symbol.asyncDispose] = async function() {
|
|
31
|
+
return await this.close();
|
|
32
|
+
};
|
|
33
|
+
};
|
|
6
34
|
function Pool(poolConfig) {
|
|
7
35
|
const POOL = {};
|
|
8
36
|
return {
|
|
@@ -23,16 +51,12 @@ function Pool(poolConfig) {
|
|
|
23
51
|
delete POOL[database];
|
|
24
52
|
throw err;
|
|
25
53
|
});
|
|
26
|
-
POOL[database] = pool.connect().catch((err) => {
|
|
54
|
+
POOL[database] = () => pool.connect().then(() => pool).catch((err) => {
|
|
27
55
|
delete POOL[database];
|
|
28
56
|
throw err;
|
|
29
57
|
});
|
|
30
58
|
}
|
|
31
59
|
return POOL[database];
|
|
32
|
-
},
|
|
33
|
-
closeAll: async () => {
|
|
34
|
-
const closes = Object.values(POOL).map((pool) => pool.then((p) => p.close()));
|
|
35
|
-
await Promise.all(closes);
|
|
36
60
|
}
|
|
37
61
|
};
|
|
38
62
|
}
|
|
@@ -58,7 +82,8 @@ class SafeGuardError extends Error {
|
|
|
58
82
|
// src/pipes/shared/runner/index.ts
|
|
59
83
|
var Runner = () => {
|
|
60
84
|
const singleBar = new SingleBar({
|
|
61
|
-
format: `{bar} {percentage}% | {value}/{total} | {database}
|
|
85
|
+
format: `{bar} {percentage}% | {value}/{total} | {database}`,
|
|
86
|
+
hideCursor: true
|
|
62
87
|
}, Presets.shades_classic);
|
|
63
88
|
const [guard, trackError] = (() => {
|
|
64
89
|
const limit = LoadEnv().SAFE_GUARD;
|
|
@@ -70,7 +95,7 @@ var Runner = () => {
|
|
|
70
95
|
};
|
|
71
96
|
const trackError2 = () => {
|
|
72
97
|
errorsCount++;
|
|
73
|
-
if (errorsCount >= limit) {
|
|
98
|
+
if (limit > 0 && errorsCount >= limit) {
|
|
74
99
|
open = true;
|
|
75
100
|
}
|
|
76
101
|
};
|
|
@@ -78,63 +103,76 @@ var Runner = () => {
|
|
|
78
103
|
})();
|
|
79
104
|
const runner = async ({
|
|
80
105
|
connection: dc,
|
|
81
|
-
input,
|
|
82
106
|
fn,
|
|
83
|
-
|
|
84
|
-
onError = () => {}
|
|
107
|
+
onResult = () => {}
|
|
85
108
|
}) => {
|
|
109
|
+
const databaseName = typeof dc.database === "string" ? dc.database : dc.database.Database;
|
|
86
110
|
return guard().then(() => {
|
|
87
111
|
if (singleBar && Bun.env.NODE_ENV !== "test") {
|
|
88
|
-
singleBar.update({ database:
|
|
112
|
+
singleBar.update({ database: databaseName });
|
|
113
|
+
}
|
|
114
|
+
}).then(() => dc.connection()).then(async (conn) => {
|
|
115
|
+
let __stack = [];
|
|
116
|
+
try {
|
|
117
|
+
const wrapped = __using(__stack, new ConnectionPoolWrapper(conn), 1);
|
|
118
|
+
return await fn(wrapped, dc.database);
|
|
119
|
+
} catch (_catch) {
|
|
120
|
+
var _err = _catch, _hasErr = 1;
|
|
121
|
+
} finally {
|
|
122
|
+
var _promise = __callDispose(__stack, _err, _hasErr);
|
|
123
|
+
_promise && await _promise;
|
|
89
124
|
}
|
|
90
|
-
}).then((
|
|
125
|
+
}).then((result) => onResult(result)).then(() => {
|
|
91
126
|
if (singleBar && Bun.env.NODE_ENV !== "test") {
|
|
92
|
-
singleBar.increment(1, { database:
|
|
127
|
+
singleBar.increment(1, { database: databaseName });
|
|
128
|
+
}
|
|
129
|
+
}).catch((error) => {
|
|
130
|
+
if (singleBar && Bun.env.NODE_ENV !== "test") {
|
|
131
|
+
singleBar.increment(1, { database: databaseName });
|
|
93
132
|
}
|
|
94
|
-
}).catch((error) => tran.rollback().then(() => {
|
|
95
|
-
throw error;
|
|
96
|
-
}))).catch(async (error) => {
|
|
97
133
|
if (error instanceof SafeGuardError) {
|
|
98
134
|
return;
|
|
99
135
|
}
|
|
100
136
|
trackError();
|
|
101
|
-
|
|
137
|
+
onResult(undefined, {
|
|
138
|
+
name: error.name,
|
|
139
|
+
message: error.message,
|
|
140
|
+
stack: error.stack,
|
|
141
|
+
code: error.code || undefined,
|
|
142
|
+
number: error.number || undefined,
|
|
143
|
+
state: error.state || undefined,
|
|
144
|
+
class: error.class || undefined,
|
|
145
|
+
serverName: error.serverName || undefined,
|
|
146
|
+
procName: error.procName || undefined,
|
|
147
|
+
lineNumber: error.lineNumber || undefined
|
|
148
|
+
});
|
|
102
149
|
});
|
|
103
150
|
};
|
|
104
151
|
return [runner, singleBar];
|
|
105
152
|
};
|
|
106
153
|
|
|
107
154
|
// src/pipes/execute/index.ts
|
|
108
|
-
var Execute = (connections$, databases
|
|
155
|
+
var Execute = (connections$, databases$) => {
|
|
109
156
|
return async (fn) => {
|
|
110
157
|
const errors = [];
|
|
111
158
|
const [runner, singleBar] = Runner();
|
|
112
159
|
const executeFn = (dc) => runner({
|
|
113
160
|
connection: dc,
|
|
114
|
-
input,
|
|
115
161
|
fn,
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
number: error.number || undefined,
|
|
124
|
-
state: error.state || undefined,
|
|
125
|
-
class: error.class || undefined,
|
|
126
|
-
serverName: error.serverName || undefined,
|
|
127
|
-
procName: error.procName || undefined,
|
|
128
|
-
lineNumber: error.lineNumber || undefined
|
|
129
|
-
}
|
|
130
|
-
});
|
|
162
|
+
onResult(_, error) {
|
|
163
|
+
if (error) {
|
|
164
|
+
errors.push({
|
|
165
|
+
database: dc.database,
|
|
166
|
+
error
|
|
167
|
+
});
|
|
168
|
+
}
|
|
131
169
|
}
|
|
132
170
|
});
|
|
133
171
|
const databases = await databases$;
|
|
134
172
|
if (Bun.env.NODE_ENV !== "test") {
|
|
135
173
|
singleBar.start(databases.length, 0);
|
|
136
174
|
}
|
|
137
|
-
for
|
|
175
|
+
for (const connectionBatch of connections$(databases)) {
|
|
138
176
|
const executions = connectionBatch.map(executeFn);
|
|
139
177
|
await Promise.allSettled(executions);
|
|
140
178
|
}
|
|
@@ -146,17 +184,10 @@ var Execute = (connections$, databases$, input) => {
|
|
|
146
184
|
};
|
|
147
185
|
|
|
148
186
|
// src/pipes/output/index.ts
|
|
149
|
-
var Output = (
|
|
150
|
-
const errors = [];
|
|
151
|
-
const output = await strategy(data);
|
|
152
|
-
for await (const item of error) {
|
|
153
|
-
errors.push(item);
|
|
154
|
-
}
|
|
155
|
-
return [errors, output];
|
|
156
|
-
};
|
|
187
|
+
var Output = (result) => async (strategy) => await strategy(result);
|
|
157
188
|
|
|
158
189
|
// src/pipes/transform/index.ts
|
|
159
|
-
var Transform = (
|
|
190
|
+
var Transform = (result) => {
|
|
160
191
|
return (transformFn) => {
|
|
161
192
|
class TransformDataStream extends TransformStream {
|
|
162
193
|
constructor() {
|
|
@@ -164,37 +195,32 @@ var Transform = (data, error) => {
|
|
|
164
195
|
async transform(chunk, controller) {
|
|
165
196
|
const transformedData2 = {
|
|
166
197
|
database: chunk.database,
|
|
167
|
-
data: await transformFn(chunk.data)
|
|
198
|
+
data: chunk.data ? await transformFn(chunk.data) : undefined,
|
|
199
|
+
error: chunk.error
|
|
168
200
|
};
|
|
169
201
|
controller.enqueue(transformedData2);
|
|
170
202
|
}
|
|
171
203
|
});
|
|
172
204
|
}
|
|
173
205
|
}
|
|
174
|
-
const transformedData =
|
|
206
|
+
const transformedData = result.pipeThrough(new TransformDataStream);
|
|
175
207
|
return {
|
|
176
|
-
Output: Output(transformedData
|
|
208
|
+
Output: Output(transformedData)
|
|
177
209
|
};
|
|
178
210
|
};
|
|
179
211
|
};
|
|
180
212
|
|
|
181
213
|
// src/pipes/retrieve/index.ts
|
|
182
|
-
var Retrieve = (connections$, databases
|
|
214
|
+
var Retrieve = (connections$, databases$) => {
|
|
183
215
|
return (fn) => {
|
|
184
|
-
const { readable:
|
|
185
|
-
const
|
|
186
|
-
const dataWriter = writableData.getWriter();
|
|
187
|
-
const errorWriter = writableError.getWriter();
|
|
216
|
+
const { readable: readableResult, writable: writableResult } = new TransformStream;
|
|
217
|
+
const resultWriter = writableResult.getWriter();
|
|
188
218
|
const [runner, singleBar] = Runner();
|
|
189
219
|
const executeFn = (dc) => runner({
|
|
190
220
|
connection: dc,
|
|
191
|
-
input,
|
|
192
221
|
fn,
|
|
193
|
-
|
|
194
|
-
await
|
|
195
|
-
},
|
|
196
|
-
onError: async (error) => {
|
|
197
|
-
await errorWriter.write({ [dc.database]: error });
|
|
222
|
+
onResult: async (data, error) => {
|
|
223
|
+
await resultWriter.write({ database: dc.database, data, error });
|
|
198
224
|
}
|
|
199
225
|
});
|
|
200
226
|
(async () => {
|
|
@@ -202,26 +228,24 @@ var Retrieve = (connections$, databases$, input) => {
|
|
|
202
228
|
if (Bun.env.NODE_ENV !== "test") {
|
|
203
229
|
singleBar.start(databases.length, 0);
|
|
204
230
|
}
|
|
205
|
-
for
|
|
231
|
+
for (const connectionBatch of connections$(databases)) {
|
|
206
232
|
const executions = connectionBatch.map(executeFn);
|
|
207
233
|
await Promise.allSettled(executions);
|
|
208
234
|
}
|
|
209
235
|
if (Bun.env.NODE_ENV !== "test") {
|
|
210
236
|
singleBar.stop();
|
|
211
237
|
}
|
|
212
|
-
await
|
|
213
|
-
await errorWriter.close();
|
|
238
|
+
await resultWriter.close().catch(() => {});
|
|
214
239
|
})();
|
|
215
240
|
return {
|
|
216
|
-
Transform: Transform(
|
|
217
|
-
Output: Output(
|
|
241
|
+
Transform: Transform(readableResult),
|
|
242
|
+
Output: Output(readableResult)
|
|
218
243
|
};
|
|
219
244
|
};
|
|
220
245
|
};
|
|
221
246
|
|
|
222
247
|
// src/pipes/connect/index.ts
|
|
223
248
|
var Connect = (pool) => (param, concurrent) => {
|
|
224
|
-
let connections$;
|
|
225
249
|
let databases$;
|
|
226
250
|
function connections(concurrent2 = Number.MAX_VALUE) {
|
|
227
251
|
return function* (databases) {
|
|
@@ -232,7 +256,7 @@ var Connect = (pool) => (param, concurrent) => {
|
|
|
232
256
|
for (const database of guard_test) {
|
|
233
257
|
yield [{
|
|
234
258
|
database,
|
|
235
|
-
connection: pool.connect({ database })
|
|
259
|
+
connection: pool.connect({ database: typeof database === "string" ? database : database.Database })
|
|
236
260
|
}];
|
|
237
261
|
}
|
|
238
262
|
}
|
|
@@ -240,7 +264,7 @@ var Connect = (pool) => (param, concurrent) => {
|
|
|
240
264
|
for (const databases_result_chunk of databases_result_chunks) {
|
|
241
265
|
yield databases_result_chunk.map((database) => ({
|
|
242
266
|
database,
|
|
243
|
-
connection: pool.connect({ database })
|
|
267
|
+
connection: pool.connect({ database: typeof database === "string" ? database : database.Database })
|
|
244
268
|
}));
|
|
245
269
|
}
|
|
246
270
|
};
|
|
@@ -250,14 +274,14 @@ var Connect = (pool) => (param, concurrent) => {
|
|
|
250
274
|
} else if (Array.isArray(param)) {
|
|
251
275
|
databases$ = Promise.resolve(param);
|
|
252
276
|
} else if (typeof param === "object" && "query" in param) {
|
|
253
|
-
databases$ = pool.connect({ database: param.database
|
|
277
|
+
databases$ = pool.connect({ database: param.database })().then((conn) => conn.request().query(param.query)).then((result) => result.recordset);
|
|
254
278
|
} else {
|
|
255
279
|
throw new Error("Invalid parameter");
|
|
256
280
|
}
|
|
257
|
-
connections$ = connections(concurrent);
|
|
281
|
+
const connections$ = connections(concurrent);
|
|
258
282
|
return {
|
|
259
|
-
Execute: Execute(connections$, databases
|
|
260
|
-
Retrieve: Retrieve(connections$, databases
|
|
283
|
+
Execute: Execute(connections$, databases$),
|
|
284
|
+
Retrieve: Retrieve(connections$, databases$)
|
|
261
285
|
};
|
|
262
286
|
};
|
|
263
287
|
|
|
@@ -266,8 +290,7 @@ var Auth = (config) => (strategy) => {
|
|
|
266
290
|
const configWithAuth = strategy(config);
|
|
267
291
|
const pool = Pool(configWithAuth);
|
|
268
292
|
return {
|
|
269
|
-
Connect: Connect(pool)
|
|
270
|
-
Close: () => pool.closeAll()
|
|
293
|
+
Connect: Connect(pool)
|
|
271
294
|
};
|
|
272
295
|
};
|
|
273
296
|
|
|
@@ -283,5 +306,5 @@ export {
|
|
|
283
306
|
SQL
|
|
284
307
|
};
|
|
285
308
|
|
|
286
|
-
//# debugId=
|
|
309
|
+
//# debugId=D159CA6ECD19CCD464756E2164756E21
|
|
287
310
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -2,20 +2,20 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["src/pool/index.ts", "src/pipes/shared/runner/index.ts", "src/utils/load-env.ts", "src/pipes/shared/runner/types.ts", "src/pipes/execute/index.ts", "src/pipes/output/index.ts", "src/pipes/transform/index.ts", "src/pipes/retrieve/index.ts", "src/pipes/connect/index.ts", "src/pipes/auth/index.ts", "src/pipes/server/index.ts", "src/index.ts"],
|
|
4
4
|
"sourcesContent": [
|
|
5
|
-
"import { type config, ConnectionPool } from 'mssql';\nexport type Pool = {\n connect: (partialConfig: Partial<config>) =>
|
|
6
|
-
"import { Presets, SingleBar } from 'cli-progress';\nimport { LoadEnv } from '../../../utils/load-env';\nimport { type ErrorType, type RunnerOptions, type TransactionRunner, SafeGuardError } from './types';\n\nexport const Runner = (): [TransactionRunner
|
|
5
|
+
"import { type config, ConnectionPool, Transaction } from 'mssql';\n\nexport interface TransactionWrapper extends Transaction, AsyncDisposable {\n commit$: () => Promise<void>;\n}\n\nexport const TransactionWrapper = function(this: TransactionWrapper, transaction: Transaction) {\n Object.setPrototypeOf(this, Object.getPrototypeOf(transaction));\n Object.assign(this, transaction);\n \n let committed: boolean = false;\n\n this.commit$ = async function() {\n committed = true;\n return await this.commit();\n };\n\n this[Symbol.asyncDispose] = async function() {\n if (!committed) {\n return await this.rollback();\n }\n };\n} as unknown as new (transaction: Transaction) => TransactionWrapper & Transaction;\n\nexport interface ConnectionPoolWrapper extends ConnectionPool, AsyncDisposable {\n transaction$: () => Promise<TransactionWrapper>;\n}\n\nexport const ConnectionPoolWrapper = function(this: ConnectionPoolWrapper, conn: ConnectionPool) {\n Object.setPrototypeOf(this, Object.getPrototypeOf(conn));\n Object.assign(this, conn);\n\n this.transaction$ = async function() {\n const transaction = await this.transaction().begin();\n return new TransactionWrapper(transaction);\n };\n\n this[Symbol.asyncDispose] = async function() {\n return await this.close();\n };\n} as unknown as new (conn: ConnectionPool) => ConnectionPoolWrapper & ConnectionPool;\n\nexport type Pool = {\n connect: (partialConfig: Partial<config>) => () => Promise<ConnectionPool>;\n}\n\nexport function Pool(poolConfig: config): Pool {\n const POOL: Record<string, () => Promise<ConnectionPool>> = {};\n\n return {\n connect: (partialConfig: Partial<config>) => {\n const config = { ...poolConfig, ...partialConfig };\n const database = config.database;\n\n if (!database) {\n throw new Error('Database name is required');\n }\n\n if (!(database in POOL)) {\n const pool = new ConnectionPool(config);\n const close = pool.close.bind(pool);\n\n pool.close = async () => {\n delete POOL[database];\n return await close();\n }\n\n pool.on('error', err => {\n delete POOL[database];\n throw err;\n });\n\n POOL[database] = () => pool\n .connect()\n .then(() => pool)\n .catch(err => {\n delete POOL[database];\n throw err;\n });\n }\n\n return POOL[database]!;\n },\n }\n}",
|
|
6
|
+
"import { Presets, SingleBar } from 'cli-progress';\nimport { LoadEnv } from '../../../utils/load-env';\nimport { type ErrorType, type RunnerOptions, type TransactionRunner, SafeGuardError } from './types';\nimport type { MSSQLError, RequestError } from 'mssql';\nimport type { DatabaseObject } from '../../connect/types';\nimport { ConnectionPoolWrapper } from '../../../pool';\n\nexport const Runner = <T extends string | DatabaseObject>(): [TransactionRunner<T>, SingleBar] => {\n\n const singleBar = new SingleBar({\n format: `{bar} {percentage}% | {value}/{total} | {database}`,\n hideCursor: true\n }, Presets.shades_classic);\n\n const [guard, trackError] = (() => { \n const limit = LoadEnv().SAFE_GUARD;\n let errorsCount = 0, open = false;\n\n const guard = async () => {\n if (open) {\n throw new SafeGuardError();\n }\n }\n\n const trackError = () => {\n errorsCount++;\n if (limit > 0 && errorsCount >= limit) {\n open = true;\n }\n }\n\n return [guard, trackError];\n })()\n\n const runner = async <TReturn>({\n connection: dc,\n fn,\n onResult = () => { }\n }: RunnerOptions<T, TReturn>): Promise<void> => {\n const databaseName = typeof dc.database === 'string' ? dc.database : dc.database.Database;\n return guard()\n .then(() => {\n if (singleBar && Bun.env.NODE_ENV !== 'test') {\n singleBar.update({ database: databaseName });\n }\n })\n .then(() => dc.connection())\n .then(async (conn) => {\n await using wrapped = new ConnectionPoolWrapper(conn);\n return await fn(wrapped, dc.database);\n })\n .then(result => onResult(result))\n .then(() => {\n if (singleBar && Bun.env.NODE_ENV !== 'test') {\n singleBar.increment(1, { database: databaseName });\n }\n })\n .catch(error => {\n if (singleBar && Bun.env.NODE_ENV !== 'test') {\n singleBar.increment(1, { database: databaseName });\n }\n\n if (error instanceof SafeGuardError) {\n return;\n }\n\n trackError();\n onResult(undefined, ({\n name: error.name,\n message: error.message,\n stack: error.stack,\n code: (error as MSSQLError).code || undefined,\n number: (error as RequestError).number || undefined,\n state: (error as RequestError).state || undefined,\n class: (error as RequestError).class || undefined,\n serverName: (error as RequestError).serverName || undefined,\n procName: (error as RequestError).procName || undefined,\n lineNumber: (error as RequestError).lineNumber || undefined\n }) as ErrorType);\n });\n };\n\n return [runner, singleBar];\n};\n",
|
|
7
7
|
"type Env = {\n SAFE_GUARD: number;\n}\n\ntype StringEnv = {\n [P in keyof Env]?: string\n}\n\ndeclare module \"bun\" {\n interface Env extends StringEnv { }\n}\n\nexport const LoadEnv = (): Env => {\n const SAFE_GUARD = Number.parseInt(Bun.env.SAFE_GUARD || '1', 10);\n return {\n SAFE_GUARD: SAFE_GUARD\n }\n}",
|
|
8
|
-
"import type { ConnectionError, TransactionError, RequestError, PreparedStatementError, Transaction } from \"mssql\";\nimport type { DatabaseConnection } from \"../../connect/types\";\n\nexport type ErrorType = Error | ConnectionError | TransactionError | RequestError | PreparedStatementError;\n\nexport interface RunnerOptions<
|
|
9
|
-
"import type {
|
|
10
|
-
"import type {
|
|
11
|
-
"import type {
|
|
12
|
-
"import type { Transaction } from \"mssql\";\nimport { Output } from \"../output\"\nimport { Transform } from \"../transform\"\nimport type { DatabaseConnection } from \"../connect/types\";\nimport type { RetrieveChain } from \"./types\";\nimport { Runner } from \"../shared/runner\";\nimport type {
|
|
13
|
-
"import type { Pool } from \"../../pool\";\nimport { Execute } from \"../execute\";\nimport { Retrieve } from \"../retrieve\";\n\nimport type {
|
|
14
|
-
"import type { ServerConfig } from \"../server/types\";\nimport { Pool } from \"../../pool\";\nimport { Connect } from \"../connect\";\nimport type { AuthenticationChain } from \"./types\";\nimport type { AuthStrategy } from \"./strategies/types\";\n\nexport const Auth = (config: ServerConfig) => (strategy: AuthStrategy): AuthenticationChain => {\n const configWithAuth = strategy(config);\n const pool = Pool(configWithAuth);\n\n return {\n Connect: Connect(pool)
|
|
8
|
+
"import type { ConnectionError, TransactionError, RequestError, PreparedStatementError, Transaction, ConnectionPool } from \"mssql\";\nimport type { DatabaseConnection } from \"../../connect/types\";\nimport type { ConnectionPoolWrapper } from \"../../../pool\";\n\nexport type ErrorType = Error | ConnectionError | TransactionError | RequestError | PreparedStatementError;\n\nexport interface RunnerOptions<T, TReturn> {\n connection: DatabaseConnection<T>;\n fn: (connection: ConnectionPoolWrapper, database: T) => Promise<TReturn>;\n onResult?: (data?: TReturn, error?: ErrorType) => Promise<void> | void\n}\n\nexport type TransactionRunner<T> = <TReturn>(options: RunnerOptions<T, TReturn>) => Promise<void>;\n\nexport type Execution<T> = { database: T }\nexport type ExecutionError<T> = Execution<T> & { error: ErrorType };\nexport type ExecutionData<T, TReturn> = Execution<T> & { data: TReturn }\nexport type ExecutionResult<T, TReturn> = Execution<T> & Partial<ExecutionData<T, TReturn>> & Partial<ExecutionError<T>>\n\nexport class SafeGuardError extends Error {\n constructor() {\n super(`Safe guard reached`);\n }\n}",
|
|
9
|
+
"import type { DatabaseConnection, DatabaseObject } from \"../connect/types\";\nimport { Runner } from '../shared/runner';\nimport type { ExecutionError } from '../shared/runner/types';\nimport type { ConnectionPoolWrapper } from '../../pool';\n\nexport const Execute = <T extends string | DatabaseObject>(\n connections$: (databases: T[]) => Generator<DatabaseConnection<T>[]>,\n databases$: Promise<T[]>\n) => {\n return async (\n fn: (conn: ConnectionPoolWrapper, database: T) => Promise<void>\n ): Promise<ExecutionError<T>[]> => {\n const errors: ExecutionError<T>[] = [];\n\n const [runner, singleBar] = Runner<T>();\n\n const executeFn = (dc: DatabaseConnection<T>) => runner({\n connection: dc,\n fn,\n onResult(_, error) {\n if (error) {\n errors.push({\n database: dc.database,\n error\n })\n }\n },\n });\n\n const databases = await databases$;\n\n if (Bun.env.NODE_ENV !== 'test') {\n singleBar.start(databases.length, 0);\n }\n\n for (const connectionBatch of connections$(databases)) {\n const executions = connectionBatch.map(executeFn);\n await Promise.allSettled(executions);\n }\n\n if (Bun.env.NODE_ENV !== 'test') {\n singleBar.stop();\n }\n\n return errors;\n };\n};",
|
|
10
|
+
"import type { ExecutionResult } from \"../shared/runner/types\";\nimport type { OutputStrategy } from \"./strategies/types\";\n\nexport const Output =\n <T, TReturn, TOutput = void>(\n result: ReadableStream<ExecutionResult<T, TReturn >>,\n ) =>\n async (strategy: OutputStrategy<T, TReturn, TOutput>): Promise<TOutput> => await strategy(result);\n",
|
|
11
|
+
"import type { ExecutionResult } from \"../shared/runner/types\";\nimport type { TransformChain, TransformFunction } from \"./types\";\nimport { Output } from \"../output\";\n\nexport const Transform = <T, TInput>(\n result: ReadableStream<ExecutionResult<T, TInput>>\n) => {\n return <TOutput>(transformFn: TransformFunction<TInput, TOutput>): TransformChain<T, TOutput> => {\n class TransformDataStream extends TransformStream<ExecutionResult<T, TInput>, ExecutionResult<T, TOutput>> {\n constructor() {\n super({\n async transform(chunk, controller) {\n const transformedData: ExecutionResult<T, TOutput> = {\n database: chunk.database,\n data: chunk.data ? await transformFn(chunk.data) : undefined,\n error: chunk.error,\n };\n controller.enqueue(transformedData);\n }\n })\n }\n }\n \n const transformedData = result.pipeThrough(new TransformDataStream());\n\n return {\n Output: Output(transformedData)\n };\n }\n}",
|
|
12
|
+
"import type { ConnectionPool, Transaction } from \"mssql\";\nimport { Output } from \"../output\"\nimport { Transform } from \"../transform\"\nimport type { DatabaseConnection, DatabaseObject } from \"../connect/types\";\nimport type { RetrieveChain } from \"./types\";\nimport { Runner } from \"../shared/runner\";\nimport type { ExecutionResult } from \"../shared/runner/types\";\nimport type { ConnectionPoolWrapper } from \"../../pool\";\n\nexport const Retrieve = <T extends string | DatabaseObject>(\n connections$: (databases: T[]) => Generator<DatabaseConnection<T>[]>,\n databases$: Promise<T[]>\n) => {\n return <TReturn>(fn: (conn: ConnectionPoolWrapper, database: T) => Promise<TReturn>): RetrieveChain<T, TReturn> => {\n const { readable: readableResult, writable: writableResult } = new TransformStream<ExecutionResult<T, TReturn>, ExecutionResult<T, TReturn>>();\n const resultWriter = writableResult.getWriter();\n\n const [runner, singleBar] = Runner<T>();\n\n const executeFn = (dc: DatabaseConnection<T>) => runner({\n connection: dc,\n fn,\n onResult: async (data, error) => {\n await resultWriter.write({ database: dc.database, data: data, error: error });\n }\n });\n\n // Process all connections and close the stream when done\n (async () => {\n const databases = await databases$;\n\n if (Bun.env.NODE_ENV !== 'test') {\n singleBar.start(databases.length, 0);\n }\n\n for (const connectionBatch of connections$(databases)) {\n const executions = connectionBatch.map(executeFn);\n await Promise.allSettled(executions);\n }\n\n if (Bun.env.NODE_ENV !== 'test') {\n singleBar.stop();\n }\n\n await resultWriter.close().catch(() => {});\n })();\n\n return {\n Transform: Transform(readableResult),\n Output: Output(readableResult)\n };\n }\n}",
|
|
13
|
+
"import type { Pool } from \"../../pool\";\nimport { Execute } from \"../execute\";\nimport { Retrieve } from \"../retrieve\";\n\nimport type { ConnectionOptions, ConnectionChain, DatabaseConnection, DatabaseObject } from \"./types\";\nimport { LoadEnv } from \"../../utils/load-env\";\n\nexport const Connect = (pool: Pool) => <T extends string | DatabaseObject>(param: string | string[] | ConnectionOptions, concurrent?: number): ConnectionChain<T> => {\n let databases$: Promise<T[]>;\n\n function connections(concurrent: number = Number.MAX_VALUE): (databases: T[]) => Generator<DatabaseConnection<T>[]> {\n return function* (databases: T[]) {\n const _databases = [...databases];\n const safe_guard = LoadEnv().SAFE_GUARD;\n\n if (safe_guard > 0) {\n const guard_test = _databases.splice(0, safe_guard);\n\n for (const database of guard_test) {\n yield [{\n database,\n connection: pool.connect({ database: typeof database === 'string' ? database : database.Database }) \n }];\n }\n }\n\n const databases_result_chunks = Array.from(\n { length: Math.ceil(_databases.length / concurrent) },\n (_, i) => _databases.slice(i * concurrent, (i + 1) * concurrent)\n );\n\n for (const databases_result_chunk of databases_result_chunks) {\n yield databases_result_chunk.map(database => ({\n database,\n connection: pool.connect({ database: typeof database === 'string' ? database : database.Database })\n }));\n }\n }\n }\n\n if (typeof param === 'string') {\n databases$ = Promise.resolve([param as T]);\n }\n\n else if (Array.isArray(param)) {\n databases$ = Promise.resolve(param as T[]);\n }\n\n else if (typeof param === 'object' && 'query' in param) {\n databases$ = pool\n .connect({ database: param.database })()\n .then(conn => conn\n .request()\n .query<T[]>(param.query)\n )\n .then(result => result.recordset)\n }\n\n else {\n throw new Error(\"Invalid parameter\");\n }\n\n const connections$ = connections(concurrent);\n\n return {\n Execute: Execute(connections$, databases$),\n Retrieve: Retrieve(connections$, databases$)\n }\n}",
|
|
14
|
+
"import type { ServerConfig } from \"../server/types\";\nimport { Pool } from \"../../pool\";\nimport { Connect } from \"../connect\";\nimport type { AuthenticationChain } from \"./types\";\nimport type { AuthStrategy } from \"./strategies/types\";\n\nexport const Auth = (config: ServerConfig) => (strategy: AuthStrategy): AuthenticationChain => {\n const configWithAuth = strategy(config);\n const pool = Pool(configWithAuth);\n\n return {\n Connect: Connect(pool)\n }\n}",
|
|
15
15
|
"import { Auth } from \"../auth\";\nimport type { ServerChain, ServerConfig } from \"./types\";\n\nexport const Server = (config: ServerConfig): ServerChain => ({\n Auth: Auth(config),\n});",
|
|
16
16
|
"export * from \"./pipes/server\"\nexport * as SQL from \"mssql\""
|
|
17
17
|
],
|
|
18
|
-
"mappings": "
|
|
19
|
-
"debugId": "
|
|
18
|
+
"mappings": ";;;;;;;AAAA;AAMO,IAAM,qBAAqB,QAAQ,CAA2B,aAA0B;AAAA,EAC3F,OAAO,eAAe,MAAM,OAAO,eAAe,WAAW,CAAC;AAAA,EAC9D,OAAO,OAAO,MAAM,WAAW;AAAA,EAE/B,IAAI,YAAqB;AAAA,EAEzB,KAAK,UAAU,cAAc,GAAG;AAAA,IAC5B,YAAY;AAAA,IACZ,OAAO,MAAM,KAAK,OAAO;AAAA;AAAA,EAG7B,KAAK,OAAO,gBAAgB,cAAc,GAAG;AAAA,IACzC,IAAI,CAAC,WAAW;AAAA,MACZ,OAAO,MAAM,KAAK,SAAS;AAAA,IAC/B;AAAA;AAAA;AAQD,IAAM,wBAAwB,QAAQ,CAA8B,MAAsB;AAAA,EAC7F,OAAO,eAAe,MAAM,OAAO,eAAe,IAAI,CAAC;AAAA,EACvD,OAAO,OAAO,MAAM,IAAI;AAAA,EAExB,KAAK,eAAe,cAAc,GAAG;AAAA,IACjC,MAAM,cAAc,MAAM,KAAK,YAAY,EAAE,MAAM;AAAA,IACnD,OAAO,IAAI,mBAAmB,WAAW;AAAA;AAAA,EAG7C,KAAK,OAAO,gBAAgB,cAAc,GAAG;AAAA,IACzC,OAAO,MAAM,KAAK,MAAM;AAAA;AAAA;AAQzB,SAAS,IAAI,CAAC,YAA0B;AAAA,EAC3C,MAAM,OAAsD,CAAC;AAAA,EAE7D,OAAO;AAAA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AI,OAAO,UAAU,YAAY,WAAW,OAAO;AAAA,IACpD,aAAa,KACR,QAAQ,EAAE,UAAU,MAAM,SAAS,CAAC,EAAE,EACtC,KAAK,UAAQ,KACT,QAAQ,EACR,MAAW,MAAM,KAAK,CAC3B,EACC,KAAK,YAAU,OAAO,SAAS;AAAA,EACxC,EAEK;AAAA,IACD,MAAM,IAAI,MAAM,mBAAmB;AAAA;AAAA,EAGvC,MAAM,eAAe,YAAY,UAAU;AAAA,EAE3C,OAAO;AAAA,IACH,SAAS,QAAQ,cAAc,UAAU;AAAA,IACzC,UAAU,SAAS,cAAc,UAAU;AAAA,EAC/C;AAAA;;;AC7DG,IAAM,OAAO,CAAC,WAAyB,CAAC,aAAgD;AAAA,EAC3F,MAAM,iBAAiB,SAAS,MAAM;AAAA,EACtC,MAAM,OAAO,KAAK,cAAc;AAAA,EAEhC,OAAO;AAAA,IACH,SAAS,QAAQ,IAAI;AAAA,EACzB;AAAA;;;ACTG,IAAM,SAAS,CAAC,YAAuC;AAAA,EAC1D,MAAM,KAAK,MAAM;AACrB;;;ACJA;",
|
|
19
|
+
"debugId": "D159CA6ECD19CCD464756E2164756E21",
|
|
20
20
|
"names": []
|
|
21
21
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { AuthStrategy } from "../../../shared/chunk-
|
|
2
|
-
import "../../../shared/chunk-
|
|
1
|
+
import { AuthStrategy } from "../../../shared/chunk-t5frzhxr";
|
|
2
|
+
import "../../../shared/chunk-vct19a11";
|
|
3
3
|
declare const UserAndPassword: (username: string, password: string) => AuthStrategy;
|
|
4
4
|
import { NodeAuthOptions } from "@azure/msal-node";
|
|
5
5
|
declare const ActiveDirectoryAccessToken: (config: NodeAuthOptions) => Promise<AuthStrategy>;
|
|
@@ -1,9 +1,55 @@
|
|
|
1
|
-
import { OutputStrategy } from "../../../shared/chunk-
|
|
1
|
+
import { DatabaseObject, ExecutionError, OutputStrategy } from "../../../shared/chunk-vct19a11";
|
|
2
2
|
declare const MergeOutputStrategy: <
|
|
3
|
+
T,
|
|
3
4
|
TData,
|
|
4
5
|
TMerged = TData extends Array<infer TItem> ? TItem : TData
|
|
5
|
-
>() => OutputStrategy<TData, TMerged[]>;
|
|
6
|
-
declare const ConsoleOutputStrategy: <
|
|
7
|
-
|
|
8
|
-
|
|
6
|
+
>() => OutputStrategy<T, TData, [ExecutionError<T>[], TMerged[]]>;
|
|
7
|
+
declare const ConsoleOutputStrategy: <
|
|
8
|
+
T,
|
|
9
|
+
TData
|
|
10
|
+
>() => OutputStrategy<T, TData, void>;
|
|
11
|
+
declare function JsonOutputStrategy<
|
|
12
|
+
T,
|
|
13
|
+
TData
|
|
14
|
+
>(): OutputStrategy<T, TData, [ExecutionError<T>[], string]>;
|
|
15
|
+
declare function JsonOutputStrategy<
|
|
16
|
+
T,
|
|
17
|
+
TData
|
|
18
|
+
>(includeEmpty: boolean): OutputStrategy<T, TData, [ExecutionError<T>[], string]>;
|
|
19
|
+
declare function JsonOutputStrategy<
|
|
20
|
+
T,
|
|
21
|
+
TData
|
|
22
|
+
>(includeEmpty: boolean, includeErrors: false): OutputStrategy<T, TData, [ExecutionError<T>[], string]>;
|
|
23
|
+
declare function JsonOutputStrategy<
|
|
24
|
+
T,
|
|
25
|
+
TData
|
|
26
|
+
>(includeEmpty: boolean, includeErrors: true): OutputStrategy<T, TData, string>;
|
|
27
|
+
declare function JsonOutputStrategy<
|
|
28
|
+
T,
|
|
29
|
+
TData
|
|
30
|
+
>(includeEmpty: boolean, includeErrors: boolean): OutputStrategy<T, TData, string | [ExecutionError<T>[], string]>;
|
|
31
|
+
declare function XlsOutputStrategy<
|
|
32
|
+
T extends string | DatabaseObject,
|
|
33
|
+
TData
|
|
34
|
+
>(): OutputStrategy<T, TData, [ExecutionError<T>[], string]>;
|
|
35
|
+
declare function XlsOutputStrategy<
|
|
36
|
+
T extends string | DatabaseObject,
|
|
37
|
+
TData
|
|
38
|
+
>(combineSheets: boolean): OutputStrategy<T, TData, [ExecutionError<T>[], string]>;
|
|
39
|
+
declare function XlsOutputStrategy<
|
|
40
|
+
T extends string | DatabaseObject,
|
|
41
|
+
TData
|
|
42
|
+
>(combineSheets: boolean, includeEmpty: boolean): OutputStrategy<T, TData, [ExecutionError<T>[], string]>;
|
|
43
|
+
declare function XlsOutputStrategy<
|
|
44
|
+
T extends string | DatabaseObject,
|
|
45
|
+
TData
|
|
46
|
+
>(combineSheets: boolean, includeEmpty: boolean, includeErrors: false): OutputStrategy<T, TData, [ExecutionError<T>[], string]>;
|
|
47
|
+
declare function XlsOutputStrategy<
|
|
48
|
+
T extends string | DatabaseObject,
|
|
49
|
+
TData
|
|
50
|
+
>(combineSheets: boolean, includeEmpty: boolean, includeErrors: true): OutputStrategy<T, TData, string>;
|
|
51
|
+
declare function XlsOutputStrategy<
|
|
52
|
+
T extends string | DatabaseObject,
|
|
53
|
+
TData
|
|
54
|
+
>(combineSheets: boolean, includeEmpty: boolean, includeErrors: boolean): OutputStrategy<T, TData, string | [ExecutionError<T>[], string]>;
|
|
9
55
|
export { XlsOutputStrategy, OutputStrategy, MergeOutputStrategy, JsonOutputStrategy, ConsoleOutputStrategy };
|
|
@@ -1,17 +1,22 @@
|
|
|
1
1
|
// @bun
|
|
2
|
-
import"../../../shared/chunk-
|
|
2
|
+
import"../../../shared/chunk-shrjzctv.js";
|
|
3
3
|
|
|
4
4
|
// src/pipes/output/strategies/merge.ts
|
|
5
5
|
var MergeOutputStrategy = () => async (result) => {
|
|
6
6
|
const data = [];
|
|
7
|
+
const errors = [];
|
|
7
8
|
for await (const item of result) {
|
|
9
|
+
if (item.error) {
|
|
10
|
+
errors.push({ database: item.database, error: item.error });
|
|
11
|
+
continue;
|
|
12
|
+
}
|
|
8
13
|
if (Array.isArray(item.data)) {
|
|
9
14
|
data.push(...item.data);
|
|
10
15
|
} else {
|
|
11
16
|
data.push(item.data);
|
|
12
17
|
}
|
|
13
18
|
}
|
|
14
|
-
return data;
|
|
19
|
+
return [errors, data];
|
|
15
20
|
};
|
|
16
21
|
// src/pipes/output/strategies/console.ts
|
|
17
22
|
var ConsoleOutputStrategy = () => async (result) => {
|
|
@@ -20,40 +25,78 @@ var ConsoleOutputStrategy = () => async (result) => {
|
|
|
20
25
|
}
|
|
21
26
|
};
|
|
22
27
|
// src/pipes/output/strategies/json.ts
|
|
23
|
-
var checkEmpty = (
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
28
|
+
var checkEmpty = ({ data }) => data === undefined || data === null || typeof data === "object" && Object.keys(data).length === 0;
|
|
29
|
+
function GetProcessingStream(includeEmpty, includeErrors, errors) {
|
|
30
|
+
return class DataProcessingStream extends TransformStream {
|
|
31
|
+
constructor() {
|
|
32
|
+
super({
|
|
33
|
+
async transform(chunk, controller) {
|
|
34
|
+
if (!includeErrors && chunk.error) {
|
|
35
|
+
errors.push({ database: chunk.database, error: chunk.error });
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
if (!chunk.error && !includeEmpty && checkEmpty(chunk)) {
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
controller.enqueue(chunk);
|
|
42
|
+
}
|
|
43
|
+
});
|
|
38
44
|
}
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
function JsonOutputStrategy(includeEmpty = true, includeErrors = false) {
|
|
48
|
+
return async (result) => {
|
|
49
|
+
const errors = [];
|
|
50
|
+
let filename = process.argv[1]?.replace(/\.(?:js|ts)/, "");
|
|
51
|
+
filename = `${filename}-${Date.now()}.json`;
|
|
52
|
+
|
|
53
|
+
class DataProcessingStream extends GetProcessingStream(includeEmpty, includeErrors, errors) {
|
|
54
|
+
}
|
|
55
|
+
try {
|
|
56
|
+
const file = Bun.file(filename);
|
|
57
|
+
const writer = file.writer();
|
|
58
|
+
writer.write("[");
|
|
59
|
+
let first = true;
|
|
60
|
+
for await (const chunk of result.pipeThrough(new DataProcessingStream)) {
|
|
61
|
+
if (!first) {
|
|
62
|
+
writer.write(`,
|
|
63
|
+
`);
|
|
64
|
+
}
|
|
65
|
+
writer.write(`${JSON.stringify(chunk, null, 2)}`);
|
|
66
|
+
first = false;
|
|
67
|
+
}
|
|
68
|
+
writer.write("]");
|
|
69
|
+
writer.end();
|
|
70
|
+
} catch (error) {
|
|
71
|
+
console.error("Error writing JSON file:", error);
|
|
72
|
+
}
|
|
73
|
+
if (!includeErrors) {
|
|
74
|
+
return [errors, filename];
|
|
75
|
+
}
|
|
76
|
+
return filename;
|
|
77
|
+
};
|
|
78
|
+
}
|
|
50
79
|
// src/pipes/output/strategies/xls.ts
|
|
51
80
|
import * as XLSX from "xlsx";
|
|
52
|
-
|
|
53
|
-
|
|
81
|
+
var checkEmpty2 = ({ data }) => data === undefined || data === null || typeof data === "object" && Object.keys(data).length === 0;
|
|
82
|
+
async function processSeparateSheets(result, workbook, includeEmpty = true) {
|
|
83
|
+
const errors = [];
|
|
54
84
|
for await (const dbResult of result) {
|
|
55
85
|
const database = dbResult.database;
|
|
56
86
|
const data = dbResult.data;
|
|
87
|
+
const error = dbResult.error;
|
|
88
|
+
const databaseName = typeof database === "string" ? database : database?.Database;
|
|
89
|
+
if (error) {
|
|
90
|
+
errors.push({ database, error });
|
|
91
|
+
continue;
|
|
92
|
+
}
|
|
93
|
+
if (checkEmpty2(dbResult)) {
|
|
94
|
+
if (includeEmpty) {
|
|
95
|
+
const emptyWorksheet = XLSX.utils.json_to_sheet([{ database: databaseName, message: "No data available" }]);
|
|
96
|
+
XLSX.utils.book_append_sheet(workbook, emptyWorksheet, databaseName.slice(0, 31));
|
|
97
|
+
}
|
|
98
|
+
continue;
|
|
99
|
+
}
|
|
57
100
|
let sheetData = [];
|
|
58
101
|
if (Array.isArray(data)) {
|
|
59
102
|
sheetData = data;
|
|
@@ -62,37 +105,44 @@ async function processSeparateSheets(result, workbook) {
|
|
|
62
105
|
} else {
|
|
63
106
|
sheetData = [{ value: data }];
|
|
64
107
|
}
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
XLSX.utils.book_append_sheet(workbook, worksheet, database);
|
|
68
|
-
hasData = true;
|
|
69
|
-
}
|
|
108
|
+
const worksheet = XLSX.utils.json_to_sheet(sheetData);
|
|
109
|
+
XLSX.utils.book_append_sheet(workbook, worksheet, databaseName.slice(0, 31));
|
|
70
110
|
}
|
|
71
|
-
return
|
|
111
|
+
return errors;
|
|
72
112
|
}
|
|
73
|
-
async function processCombinedSheet(result, workbook) {
|
|
113
|
+
async function processCombinedSheet(result, workbook, includeEmpty = true) {
|
|
74
114
|
const allData = [];
|
|
115
|
+
const errors = [];
|
|
75
116
|
const databaseGroups = {};
|
|
76
117
|
let currentRow = 1;
|
|
77
118
|
for await (const dbResult of result) {
|
|
78
119
|
const database = dbResult.database;
|
|
79
120
|
const data = dbResult.data;
|
|
121
|
+
const error = dbResult.error;
|
|
122
|
+
const databaseName = typeof database === "string" ? database : database?.Database;
|
|
123
|
+
if (error) {
|
|
124
|
+
errors.push({ database, error });
|
|
125
|
+
continue;
|
|
126
|
+
}
|
|
127
|
+
if (checkEmpty2(dbResult)) {
|
|
128
|
+
if (includeEmpty) {
|
|
129
|
+
allData.push({ database });
|
|
130
|
+
}
|
|
131
|
+
continue;
|
|
132
|
+
}
|
|
80
133
|
let sheetData = [];
|
|
81
134
|
if (Array.isArray(data)) {
|
|
82
|
-
sheetData = data.map((item) => ({ database, ...item }));
|
|
135
|
+
sheetData = data.map((item) => ({ database: databaseName, ...item }));
|
|
83
136
|
} else if (data && typeof data === "object") {
|
|
84
|
-
sheetData = [{ database, ...data }];
|
|
137
|
+
sheetData = [{ database: databaseName, ...data }];
|
|
85
138
|
} else {
|
|
86
|
-
sheetData = [{ database, value: data }];
|
|
139
|
+
sheetData = [{ database: databaseName, value: data }];
|
|
87
140
|
}
|
|
88
|
-
databaseGroups[
|
|
89
|
-
databaseGroups[
|
|
141
|
+
databaseGroups[databaseName] ??= { startRow: currentRow, endRow: currentRow };
|
|
142
|
+
databaseGroups[databaseName].endRow = currentRow + sheetData.length - 1;
|
|
90
143
|
currentRow += sheetData.length;
|
|
91
144
|
allData.push(...sheetData);
|
|
92
145
|
}
|
|
93
|
-
if (allData.length === 0) {
|
|
94
|
-
return false;
|
|
95
|
-
}
|
|
96
146
|
const worksheet = XLSX.utils.json_to_sheet(allData);
|
|
97
147
|
worksheet["!rows"] ??= [];
|
|
98
148
|
for (const [_, { startRow, endRow }] of Object.entries(databaseGroups)) {
|
|
@@ -102,34 +152,44 @@ async function processCombinedSheet(result, workbook) {
|
|
|
102
152
|
}
|
|
103
153
|
}
|
|
104
154
|
XLSX.utils.book_append_sheet(workbook, worksheet, "Combined");
|
|
105
|
-
return
|
|
155
|
+
return errors;
|
|
106
156
|
}
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
if (
|
|
118
|
-
|
|
119
|
-
|
|
157
|
+
function flattenErrors(errors) {
|
|
158
|
+
return errors.map((error) => {
|
|
159
|
+
const databaseName = typeof error.database === "string" ? error.database : error.database?.Database;
|
|
160
|
+
return { database: databaseName, ...error.error };
|
|
161
|
+
});
|
|
162
|
+
}
|
|
163
|
+
function XlsOutputStrategy(combineSheets = false, includeEmpty = true, includeErrors = false) {
|
|
164
|
+
return async (result) => {
|
|
165
|
+
const workbook = XLSX.utils.book_new();
|
|
166
|
+
let errors = [];
|
|
167
|
+
if (combineSheets) {
|
|
168
|
+
errors = await processCombinedSheet(result, workbook, includeEmpty);
|
|
169
|
+
} else {
|
|
170
|
+
errors = await processSeparateSheets(result, workbook, includeEmpty);
|
|
120
171
|
}
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
172
|
+
if (includeErrors) {
|
|
173
|
+
const errorWorksheet = XLSX.utils.json_to_sheet(flattenErrors(errors));
|
|
174
|
+
XLSX.utils.book_append_sheet(workbook, errorWorksheet, "Errors");
|
|
175
|
+
}
|
|
176
|
+
let filename = process.argv[1]?.replace(/\.(?:js|ts)/, "");
|
|
177
|
+
filename = `${filename}-${Date.now()}.xlsx`;
|
|
178
|
+
try {
|
|
179
|
+
if (workbook.SheetNames.length) {
|
|
180
|
+
const buffer = XLSX.write(workbook, { type: "buffer", bookType: "xlsx", cellStyles: true });
|
|
181
|
+
await Bun.write(filename, buffer);
|
|
182
|
+
}
|
|
183
|
+
if (!includeErrors) {
|
|
184
|
+
return [errors, filename];
|
|
185
|
+
}
|
|
186
|
+
return filename;
|
|
187
|
+
} catch (error) {
|
|
188
|
+
console.error("Error writing Excel file");
|
|
189
|
+
throw error;
|
|
190
|
+
}
|
|
191
|
+
};
|
|
192
|
+
}
|
|
133
193
|
export {
|
|
134
194
|
XlsOutputStrategy,
|
|
135
195
|
MergeOutputStrategy,
|
|
@@ -137,5 +197,5 @@ export {
|
|
|
137
197
|
ConsoleOutputStrategy
|
|
138
198
|
};
|
|
139
199
|
|
|
140
|
-
//# debugId=
|
|
200
|
+
//# debugId=C4ACE35E39E5C69064756E2164756E21
|
|
141
201
|
//# sourceMappingURL=index.js.map
|
|
@@ -2,12 +2,12 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["src/pipes/output/strategies/merge.ts", "src/pipes/output/strategies/console.ts", "src/pipes/output/strategies/json.ts", "src/pipes/output/strategies/xls.ts"],
|
|
4
4
|
"sourcesContent": [
|
|
5
|
-
"import type { OutputStrategy } from './types';\n\nexport const MergeOutputStrategy = <TData, TMerged = TData extends Array<infer TItem> ? TItem : TData>(): OutputStrategy<TData, TMerged[]> => async (result) => {\n const data: TMerged[] = [];\n for await (const item of result) {\n if (Array.isArray(item.data)) {\n data.push(...item.data);\n } else {\n data.push(item.data as unknown as TMerged);\n }\n }\n return data;\n};",
|
|
6
|
-
"import type { OutputStrategy } from './types';\n\nexport const ConsoleOutputStrategy = <TData>(): OutputStrategy<TData, void> => async (result) => {\n for await (const data of result) {\n console.log(data);\n }\n};",
|
|
7
|
-
"import type {
|
|
8
|
-
"import * as XLSX from 'xlsx';\nimport type { OutputStrategy } from './types';\nimport type {
|
|
5
|
+
"import type { ExecutionError } from '../../shared/runner/types';\nimport type { OutputStrategy } from './types';\n\nexport const MergeOutputStrategy = <T, TData, TMerged = TData extends Array<infer TItem> ? TItem : TData>(): OutputStrategy<T, TData, [ExecutionError<T>[], TMerged[]]> => async (result) => {\n const data: TMerged[] = [];\n const errors: ExecutionError<T>[] = [];\n\n for await (const item of result) {\n if (item.error) {\n errors.push({ database: item.database, error: item.error });\n continue;\n }\n if (Array.isArray(item.data)) {\n data.push(...item.data);\n } else {\n data.push(item.data as unknown as TMerged);\n }\n }\n return [errors, data];\n};",
|
|
6
|
+
"import type { OutputStrategy } from './types';\n\nexport const ConsoleOutputStrategy = <T, TData>(): OutputStrategy<T, TData, void> => async (result) => {\n for await (const data of result) {\n console.log(data);\n }\n};",
|
|
7
|
+
"import type { ExecutionError, ExecutionResult } from '../../shared/runner/types';\nimport type { OutputStrategy } from './types';\n\nconst checkEmpty = <T, TData>({ data }: ExecutionResult<T, TData>) =>\n (data === undefined || data === null) || (typeof data === 'object' && Object.keys(data).length === 0);\n\nfunction GetProcessingStream<T, TData>(includeEmpty: boolean, includeErrors: boolean, errors: ExecutionError<T>[]) {\n return class DataProcessingStream extends TransformStream<ExecutionResult<T, TData>, ExecutionResult<T, TData>> {\n constructor() {\n super({\n async transform(chunk, controller) {\n if (!includeErrors && chunk.error) {\n errors.push({ database: chunk.database, error: chunk.error});\n return;\n }\n\n if (!chunk.error && !includeEmpty && checkEmpty(chunk)) {\n return;\n }\n\n controller.enqueue(chunk);\n },\n });\n }\n }\n}\n\nexport function JsonOutputStrategy<T, TData>(): OutputStrategy<T, TData, [ExecutionError<T>[], string]>;\nexport function JsonOutputStrategy<T, TData>(includeEmpty: boolean): OutputStrategy<T, TData, [ExecutionError<T>[], string]>;\nexport function JsonOutputStrategy<T, TData>(includeEmpty: boolean, includeErrors: false): OutputStrategy<T, TData, [ExecutionError<T>[], string]>;\nexport function JsonOutputStrategy<T, TData>(includeEmpty: boolean, includeErrors: true): OutputStrategy<T, TData, string>;\nexport function JsonOutputStrategy<T, TData>(includeEmpty: boolean, includeErrors: boolean): OutputStrategy<T, TData, string | [ExecutionError<T>[], string]>;\nexport function JsonOutputStrategy<T, TData>(includeEmpty = true, includeErrors = false): OutputStrategy<T, TData, string | [ExecutionError<T>[], string]> {\n return async (result) => {\n const errors: ExecutionError<T>[] = [];\n\n let filename = process.argv[1]?.replace(/\\.(?:js|ts)/, '')\n filename = `${filename}-${Date.now()}.json`;\n\n class DataProcessingStream extends GetProcessingStream<T, TData>(includeEmpty, includeErrors, errors) {}\n\n try {\n const file = Bun.file(filename);\n const writer = file.writer();\n\n writer.write('[');\n let first = true;\n for await (const chunk of result.pipeThrough(new DataProcessingStream())) {\n if (!first) {\n writer.write(',\\n');\n }\n writer.write(`${JSON.stringify(chunk, null, 2)}`);\n first = false;\n }\n writer.write(']');\n writer.end();\n } catch (error) {\n console.error('Error writing JSON file:', error);\n }\n\n if (!includeErrors) {\n return [errors, filename];\n }\n\n return filename;\n }\n}",
|
|
8
|
+
"import * as XLSX from 'xlsx';\nimport type { OutputStrategy } from './types';\nimport type { ErrorType, ExecutionError, ExecutionResult } from '../../shared/runner/types';\nimport type { DatabaseObject } from '../../connect/types';\n\nconst checkEmpty = <T, TData>({ data }: ExecutionResult<T, TData>) =>\n (data === undefined || data === null) || (typeof data === 'object' && Object.keys(data).length === 0);\n\nasync function processSeparateSheets<T extends string | DatabaseObject, TData>(\n result: ReadableStream<ExecutionResult<T, TData>>,\n workbook: XLSX.WorkBook,\n includeEmpty = true\n): Promise<ExecutionError<T>[]> {\n const errors: ExecutionError<T>[] = [];\n\n for await (const dbResult of result) {\n const database = dbResult.database;\n const data = dbResult.data;\n const error = dbResult.error;\n\n const databaseName = typeof database === 'string' ? database : database?.Database;\n\n if (error) {\n errors.push({database, error});\n continue;\n }\n\n if (checkEmpty(dbResult)) {\n if (includeEmpty) {\n const emptyWorksheet = XLSX.utils.json_to_sheet([{ database: databaseName, message: \"No data available\" }]);\n XLSX.utils.book_append_sheet(workbook, emptyWorksheet, databaseName.slice(0, 31));\n }\n continue;\n }\n\n let sheetData: unknown[] = [];\n if (Array.isArray(data)) {\n sheetData = data;\n } else if (data && typeof data === 'object') {\n sheetData = [data];\n } else {\n sheetData = [{ value: data }];\n }\n\n const worksheet = XLSX.utils.json_to_sheet(sheetData);\n XLSX.utils.book_append_sheet(workbook, worksheet, databaseName.slice(0, 31));\n }\n\n return errors;\n}\n\nasync function processCombinedSheet<T extends string | DatabaseObject, TData>(\n result: ReadableStream<ExecutionResult<T, TData>>,\n workbook: XLSX.WorkBook,\n includeEmpty = true\n): Promise<ExecutionError<T>[]> {\n const allData: unknown[] = [];\n const errors: ExecutionError<T>[] = [];\n\n const databaseGroups: { [database: string]: { startRow: number, endRow: number } } = {};\n let currentRow = 1; // Start from row 1 (header is row 0)\n\n for await (const dbResult of result) {\n const database = dbResult.database;\n const data = dbResult.data;\n const error = dbResult.error;\n\n const databaseName = typeof database === 'string' ? database : database?.Database;\n\n if (error) {\n errors.push({database, error});\n continue;\n }\n\n if (checkEmpty(dbResult)) {\n if (includeEmpty) {\n allData.push({ database });\n }\n continue;\n }\n\n let sheetData: unknown[] = [];\n if (Array.isArray(data)) {\n sheetData = data.map(item => ({ database: databaseName, ...item }));\n } else if (data && typeof data === 'object') {\n sheetData = [{ database: databaseName, ...data }];\n } else {\n sheetData = [{ database: databaseName, value: data }];\n }\n\n // Track the start row for this database group\n databaseGroups[databaseName] ??= { startRow: currentRow, endRow: currentRow };\n\n // Update the end row for this database group\n databaseGroups[databaseName].endRow = currentRow + sheetData.length - 1;\n currentRow += sheetData.length;\n\n allData.push(...sheetData);\n }\n\n const worksheet = XLSX.utils.json_to_sheet(allData);\n\n worksheet['!rows'] ??= [];\n\n // Set row grouping for each database\n for (const [_, { startRow, endRow }] of Object.entries(databaseGroups)) {\n // Set level 1 for all rows in this database group\n for (let i = startRow; i <= endRow; i++) {\n worksheet['!rows'][i] ??= { hpx: 20 };\n worksheet['!rows'][i]!.level = i === endRow ? 0 : 1;\n }\n }\n\n XLSX.utils.book_append_sheet(workbook, worksheet, \"Combined\");\n return errors;\n}\n\nfunction flattenErrors<T extends string | DatabaseObject>(errors: ExecutionError<T>[]): ({ database: string } & ErrorType)[] {\n return errors.map(error => {\n const databaseName = typeof error.database === 'string' ? error.database : error.database?.Database;\n return { database: databaseName, ...error.error };\n })\n}\n\nexport function XlsOutputStrategy<T extends string | DatabaseObject, TData>(): OutputStrategy<T, TData, [ExecutionError<T>[], string]>\nexport function XlsOutputStrategy<T extends string | DatabaseObject, TData>(combineSheets: boolean): OutputStrategy<T, TData, [ExecutionError<T>[], string]>\nexport function XlsOutputStrategy<T extends string | DatabaseObject, TData>(combineSheets: boolean, includeEmpty: boolean): OutputStrategy<T, TData, [ExecutionError<T>[], string]>\nexport function XlsOutputStrategy<T extends string | DatabaseObject, TData>(combineSheets: boolean, includeEmpty: boolean, includeErrors: false): OutputStrategy<T, TData, [ExecutionError<T>[], string]>\nexport function XlsOutputStrategy<T extends string | DatabaseObject, TData>(combineSheets: boolean, includeEmpty: boolean, includeErrors: true): OutputStrategy<T, TData, string>\nexport function XlsOutputStrategy<T extends string | DatabaseObject, TData>(combineSheets: boolean, includeEmpty: boolean, includeErrors: boolean): OutputStrategy<T, TData, string | [ExecutionError<T>[], string]>\nexport function XlsOutputStrategy<T extends string | DatabaseObject, TData>(combineSheets = false, includeEmpty = true, includeErrors = false): OutputStrategy<T, TData, string | [ExecutionError<T>[], string]> {\n return async (result: ReadableStream<ExecutionResult<T, TData>>): Promise<string | [ExecutionError<T>[], string]> => {\n const workbook = XLSX.utils.book_new();\n let errors: ExecutionError<T>[] = [];\n\n if (combineSheets) {\n errors = await processCombinedSheet(result, workbook, includeEmpty);\n } else {\n errors = await processSeparateSheets(result, workbook, includeEmpty);\n }\n\n if (includeErrors) {\n const errorWorksheet = XLSX.utils.json_to_sheet(flattenErrors(errors));\n XLSX.utils.book_append_sheet(workbook, errorWorksheet, \"Errors\")\n }\n\n let filename = process.argv[1]?.replace(/\\.(?:js|ts)/, '');\n filename = `${filename}-${Date.now()}.xlsx`;\n\n try {\n if (workbook.SheetNames.length) {\n const buffer = XLSX.write(workbook, { type: 'buffer', bookType: 'xlsx', cellStyles: true });\n await Bun.write(filename, buffer);\n }\n\n if (!includeErrors) {\n return [errors, filename];\n }\n return filename;\n } catch (error) {\n console.error('Error writing Excel file');\n throw error;\n }\n };\n}"
|
|
9
9
|
],
|
|
10
|
-
"mappings": ";;;;
|
|
11
|
-
"debugId": "
|
|
10
|
+
"mappings": ";;;;AAGO,IAAM,sBAAsB,MAAwI,OAAO,WAAW;AAAA,EAC3L,MAAM,OAAkB,CAAC;AAAA,EACzB,MAAM,SAA8B,CAAC;AAAA,EAErC,iBAAiB,QAAQ,QAAQ;AAAA,IAC/B,IAAI,KAAK,OAAO;AAAA,MACd,OAAO,KAAK,EAAE,UAAU,KAAK,UAAU,OAAO,KAAK,MAAM,CAAC;AAAA,MAC1D;AAAA,IACF;AAAA,IACA,IAAI,MAAM,QAAQ,KAAK,IAAI,GAAG;AAAA,MAC5B,KAAK,KAAK,GAAG,KAAK,IAAI;AAAA,IACxB,EAAO;AAAA,MACL,KAAK,KAAK,KAAK,IAA0B;AAAA;AAAA,EAE7C;AAAA,EACA,OAAO,CAAC,QAAQ,IAAI;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EA,IAAI,WAAW,QAAQ,KAAK,IAAI,QAAQ,eAAe,EAAE;AAAA,IACzD,WAAW,GAAG,YAAY,KAAK,IAAI;AAAA,IAEnC,IAAI;AAAA,MACF,IAAI,SAAS,WAAW,QAAQ;AAAA,QAC9B,MAAM,SAAc,WAAM,UAAU,EAAE,MAAM,UAAU,UAAU,QAAQ,YAAY,KAAK,CAAC;AAAA,QAC1F,MAAM,IAAI,MAAM,UAAU,MAAM;AAAA,MAClC;AAAA,MAEA,IAAI,CAAC,eAAe;AAAA,QAClB,OAAO,CAAC,QAAQ,QAAQ;AAAA,MAC1B;AAAA,MACA,OAAO;AAAA,MACP,OAAO,OAAO;AAAA,MACd,QAAQ,MAAM,0BAA0B;AAAA,MACxC,MAAM;AAAA;AAAA;AAAA;",
|
|
11
|
+
"debugId": "C4ACE35E39E5C69064756E2164756E21",
|
|
12
12
|
"names": []
|
|
13
13
|
}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
// @bun
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
4
|
+
var __defProp = Object.defineProperty;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __toESM = (mod, isNodeMode, target) => {
|
|
8
|
+
target = mod != null ? __create(__getProtoOf(mod)) : {};
|
|
9
|
+
const to = isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target;
|
|
10
|
+
for (let key of __getOwnPropNames(mod))
|
|
11
|
+
if (!__hasOwnProp.call(to, key))
|
|
12
|
+
__defProp(to, key, {
|
|
13
|
+
get: () => mod[key],
|
|
14
|
+
enumerable: true
|
|
15
|
+
});
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __require = import.meta.require;
|
|
19
|
+
var __using = (stack, value, async) => {
|
|
20
|
+
if (value != null) {
|
|
21
|
+
if (typeof value !== "object" && typeof value !== "function")
|
|
22
|
+
throw TypeError('Object expected to be assigned to "using" declaration');
|
|
23
|
+
let dispose;
|
|
24
|
+
if (async)
|
|
25
|
+
dispose = value[Symbol.asyncDispose];
|
|
26
|
+
if (dispose === undefined)
|
|
27
|
+
dispose = value[Symbol.dispose];
|
|
28
|
+
if (typeof dispose !== "function")
|
|
29
|
+
throw TypeError("Object not disposable");
|
|
30
|
+
stack.push([async, dispose, value]);
|
|
31
|
+
} else if (async) {
|
|
32
|
+
stack.push([async]);
|
|
33
|
+
}
|
|
34
|
+
return value;
|
|
35
|
+
};
|
|
36
|
+
var __callDispose = (stack, error, hasError) => {
|
|
37
|
+
let fail = (e) => error = hasError ? new SuppressedError(e, error, "An error was suppressed during disposal") : (hasError = true, e), next = (it) => {
|
|
38
|
+
while (it = stack.pop()) {
|
|
39
|
+
try {
|
|
40
|
+
var result = it[1] && it[1].call(it[2]);
|
|
41
|
+
if (it[0])
|
|
42
|
+
return Promise.resolve(result).then(next, (e) => (fail(e), next()));
|
|
43
|
+
} catch (e) {
|
|
44
|
+
fail(e);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
if (hasError)
|
|
48
|
+
throw error;
|
|
49
|
+
};
|
|
50
|
+
return next();
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
export { __toESM, __require, __using, __callDispose };
|
|
54
|
+
|
|
55
|
+
//# debugId=C68FBD04759BFF3664756E2164756E21
|
|
56
|
+
//# sourceMappingURL=chunk-shrjzctv.js.map
|
|
@@ -1,10 +1,9 @@
|
|
|
1
|
-
import { ConnectionChain, ConnectionOptions } from "./chunk-
|
|
1
|
+
import { ConnectionChain, ConnectionOptions, DatabaseObject } from "./chunk-vct19a11";
|
|
2
2
|
import { config } from "mssql";
|
|
3
3
|
type AuthenticationChain = {
|
|
4
|
-
Connect(database: string): ConnectionChain
|
|
5
|
-
Connect(databases: string[], concurrent?: number): ConnectionChain
|
|
6
|
-
Connect(options: ConnectionOptions, concurrent?: number): ConnectionChain
|
|
7
|
-
Close(): Promise<void>;
|
|
4
|
+
Connect(database: string): ConnectionChain<string>;
|
|
5
|
+
Connect(databases: string[], concurrent?: number): ConnectionChain<string[]>;
|
|
6
|
+
Connect<T extends DatabaseObject>(options: ConnectionOptions, concurrent?: number): ConnectionChain<T>;
|
|
8
7
|
};
|
|
9
8
|
type ServerConfig = Omit<config, "authentication" | "user" | "password">;
|
|
10
9
|
type ServerChain = {
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { ConnectionError, TransactionError, RequestError, PreparedStatementError } from "mssql";
|
|
2
|
+
type TransformChain<
|
|
3
|
+
T,
|
|
4
|
+
TOutput
|
|
5
|
+
> = {
|
|
6
|
+
Output<TFinalOutput>(strategy: OutputStrategy<T, TOutput, TFinalOutput>): Promise<TFinalOutput>;
|
|
7
|
+
};
|
|
8
|
+
type TransformFunction<
|
|
9
|
+
TInput,
|
|
10
|
+
TOutput
|
|
11
|
+
> = (data: TInput) => TOutput | Promise<TOutput>;
|
|
12
|
+
type RetrieveChain<
|
|
13
|
+
T,
|
|
14
|
+
TReturn
|
|
15
|
+
> = {
|
|
16
|
+
Transform<TOutput>(transformFn: TransformFunction<TReturn, TOutput>): TransformChain<T, TOutput>;
|
|
17
|
+
Output<TOutput>(strategy: OutputStrategy<T, TReturn, TOutput>): Promise<TOutput>;
|
|
18
|
+
};
|
|
19
|
+
import { ConnectionPool, Transaction } from "mssql";
|
|
20
|
+
interface TransactionWrapper extends Transaction, AsyncDisposable {
|
|
21
|
+
commit$: () => Promise<void>;
|
|
22
|
+
}
|
|
23
|
+
interface ConnectionPoolWrapper extends ConnectionPool, AsyncDisposable {
|
|
24
|
+
transaction$: () => Promise<TransactionWrapper>;
|
|
25
|
+
}
|
|
26
|
+
type DatabaseObject = object & {
|
|
27
|
+
Database: string;
|
|
28
|
+
};
|
|
29
|
+
type ConnectionOptions = {
|
|
30
|
+
database: string;
|
|
31
|
+
query: `SELECT ${string}[Database]${string} FROM ${string}`;
|
|
32
|
+
};
|
|
33
|
+
type ConnectionChain<T> = {
|
|
34
|
+
Execute(fn: (connection: ConnectionPoolWrapper, database: T) => Promise<void>): Promise<ExecutionError<T>[]>;
|
|
35
|
+
Retrieve<TResult>(fn: (connection: ConnectionPoolWrapper, database: T) => Promise<TResult>): RetrieveChain<T, TResult>;
|
|
36
|
+
};
|
|
37
|
+
type ErrorType = Error | ConnectionError | TransactionError | RequestError | PreparedStatementError;
|
|
38
|
+
type Execution<T> = {
|
|
39
|
+
database: T;
|
|
40
|
+
};
|
|
41
|
+
type ExecutionError<T> = Execution<T> & {
|
|
42
|
+
error: ErrorType;
|
|
43
|
+
};
|
|
44
|
+
type ExecutionData<
|
|
45
|
+
T,
|
|
46
|
+
TReturn
|
|
47
|
+
> = Execution<T> & {
|
|
48
|
+
data: TReturn;
|
|
49
|
+
};
|
|
50
|
+
type ExecutionResult<
|
|
51
|
+
T,
|
|
52
|
+
TReturn
|
|
53
|
+
> = Execution<T> & Partial<ExecutionData<T, TReturn>> & Partial<ExecutionError<T>>;
|
|
54
|
+
type OutputStrategy<
|
|
55
|
+
T,
|
|
56
|
+
TReturn,
|
|
57
|
+
TOutput = void
|
|
58
|
+
> = (data: ReadableStream<ExecutionResult<T, TReturn>>) => Promise<TOutput>;
|
|
59
|
+
export { ExecutionError, OutputStrategy, DatabaseObject, ConnectionOptions, ConnectionChain };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "squilo",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.6.1",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"files": [
|
|
6
6
|
"dist"
|
|
@@ -47,10 +47,9 @@
|
|
|
47
47
|
"prepublishOnly": "bun run build"
|
|
48
48
|
},
|
|
49
49
|
"devDependencies": {
|
|
50
|
-
"@biomejs/biome": "2.
|
|
50
|
+
"@biomejs/biome": "2.3.11",
|
|
51
51
|
"@faker-js/faker": "^10.1.0",
|
|
52
52
|
"@types/bun": "latest",
|
|
53
|
-
"@types/mssql": "^9.1.8",
|
|
54
53
|
"@types/cli-progress": "^3.11.6",
|
|
55
54
|
"bunup": "^0.16.10",
|
|
56
55
|
"testcontainers": "^11.7.1"
|
|
@@ -61,7 +60,8 @@
|
|
|
61
60
|
"dependencies": {
|
|
62
61
|
"@azure/msal-node": "^3.8.0",
|
|
63
62
|
"cli-progress": "^3.12.0",
|
|
64
|
-
"mssql": "^
|
|
63
|
+
"mssql": "^12.2.0",
|
|
64
|
+
"@types/mssql": "^9.1.8",
|
|
65
65
|
"open": "^10.2.0",
|
|
66
66
|
"xlsx": "https://cdn.sheetjs.com/xlsx-0.20.3/xlsx-0.20.3.tgz"
|
|
67
67
|
},
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
import { ConnectionError, TransactionError, RequestError, PreparedStatementError } from "mssql";
|
|
2
|
-
import { Transaction } from "mssql";
|
|
3
|
-
type TransformChain<
|
|
4
|
-
TInput,
|
|
5
|
-
TOutput
|
|
6
|
-
> = {
|
|
7
|
-
Output<TFinalOutput>(strategy: OutputStrategy<TOutput, TFinalOutput>): Promise<[ExecutionError[], TFinalOutput]>;
|
|
8
|
-
};
|
|
9
|
-
type TransformFunction<
|
|
10
|
-
TInput,
|
|
11
|
-
TOutput
|
|
12
|
-
> = (data: TInput) => TOutput | Promise<TOutput>;
|
|
13
|
-
type RetrieveChain<TReturn> = {
|
|
14
|
-
Transform<TOutput>(transformFn: TransformFunction<TReturn, TOutput>): TransformChain<TReturn, TOutput>;
|
|
15
|
-
Output<TOutput>(strategy: OutputStrategy<TReturn, TOutput>): Promise<[ExecutionError[], TOutput]>;
|
|
16
|
-
};
|
|
17
|
-
type ConnectionOptions = {
|
|
18
|
-
database: string;
|
|
19
|
-
query: `SELECT${string}FROM${string}`;
|
|
20
|
-
};
|
|
21
|
-
type ConnectionChain = {
|
|
22
|
-
Execute(fn: (transaction: Transaction, database: string) => Promise<void>): Promise<ExecutionError[]>;
|
|
23
|
-
Retrieve<TResult>(fn: (transaction: Transaction, database: string) => Promise<TResult>): RetrieveChain<TResult>;
|
|
24
|
-
};
|
|
25
|
-
type ErrorType = Error | ConnectionError | TransactionError | RequestError | PreparedStatementError;
|
|
26
|
-
type ExecutionError = Record<string, ErrorType>;
|
|
27
|
-
type ExecutionData<TReturn> = {
|
|
28
|
-
database: string;
|
|
29
|
-
data: TReturn;
|
|
30
|
-
};
|
|
31
|
-
type OutputStrategy<
|
|
32
|
-
TReturn,
|
|
33
|
-
TOutput = void
|
|
34
|
-
> = (data: ReadableStream<ExecutionData<TReturn>>) => Promise<TOutput>;
|
|
35
|
-
export { OutputStrategy, ConnectionOptions, ConnectionChain };
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
// @bun
|
|
2
|
-
var __create = Object.create;
|
|
3
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
4
|
-
var __defProp = Object.defineProperty;
|
|
5
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
-
var __toESM = (mod, isNodeMode, target) => {
|
|
8
|
-
target = mod != null ? __create(__getProtoOf(mod)) : {};
|
|
9
|
-
const to = isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target;
|
|
10
|
-
for (let key of __getOwnPropNames(mod))
|
|
11
|
-
if (!__hasOwnProp.call(to, key))
|
|
12
|
-
__defProp(to, key, {
|
|
13
|
-
get: () => mod[key],
|
|
14
|
-
enumerable: true
|
|
15
|
-
});
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __require = import.meta.require;
|
|
19
|
-
|
|
20
|
-
export { __toESM, __require };
|
|
21
|
-
|
|
22
|
-
//# debugId=0E9B17E05FB65D0564756E2164756E21
|
|
23
|
-
//# sourceMappingURL=chunk-s3vw82k6.js.map
|