squilo 0.3.3 → 0.4.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 -38
- package/dist/index.js +26 -14
- package/dist/index.js.map +8 -8
- package/dist/pipes/auth/strategies/index.d.ts +2 -4
- package/dist/pipes/output/strategies/index.d.ts +3 -6
- package/dist/pipes/output/strategies/index.js +35 -33
- package/dist/pipes/output/strategies/index.js.map +5 -5
- package/dist/shared/chunk-pmxhq7r6.d.ts +35 -0
- package/dist/shared/chunk-ydmc6s5q.d.ts +15 -0
- package/package.json +3 -2
package/dist/index.d.ts
CHANGED
|
@@ -1,41 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import
|
|
3
|
-
import { Transaction } from "mssql";
|
|
4
|
-
type OutputStrategy<
|
|
5
|
-
TReturn,
|
|
6
|
-
TOutput = void
|
|
7
|
-
> = (data: ReadableStream<Record<string, TReturn>>) => Promise<TOutput>;
|
|
8
|
-
import { ExecutionError } from "../execute/types";
|
|
9
|
-
type RetrieveChain<TReturn> = {
|
|
10
|
-
Output<TOutput>(strategy: OutputStrategy<TReturn, TOutput>): Promise<[ExecutionError[], TOutput]>;
|
|
11
|
-
};
|
|
12
|
-
import { ExecutionError as ExecutionError2 } from "../execute/types";
|
|
13
|
-
type InputChain<TParam> = {
|
|
14
|
-
Execute(fn: (transaction: Transaction, database: string, params: TParam) => Promise<void>): Promise<ExecutionError2[]>;
|
|
15
|
-
Retrieve<TResult>(fn: (transaction: Transaction, database: string, params: TParam) => Promise<TResult>): RetrieveChain<TResult>;
|
|
16
|
-
};
|
|
17
|
-
import { ExecutionError as ExecutionError3 } from "../execute/types";
|
|
18
|
-
type ConnectionOptions = {
|
|
19
|
-
database: string;
|
|
20
|
-
query: `SELECT${string}FROM${string}`;
|
|
21
|
-
};
|
|
22
|
-
type ConnectionChain = {
|
|
23
|
-
Execute(fn: (transaction: Transaction2, database: string) => Promise<void>): Promise<ExecutionError3[]>;
|
|
24
|
-
Retrieve<TResult>(fn: (transaction: Transaction2, database: string) => Promise<TResult>): RetrieveChain<TResult>;
|
|
25
|
-
Input<TParam>(fn: () => TParam): InputChain<TParam>;
|
|
26
|
-
};
|
|
27
|
-
type AuthenticationChain = {
|
|
28
|
-
Connect(database: string): ConnectionChain;
|
|
29
|
-
Connect(databases: string[], concurrent?: number): ConnectionChain;
|
|
30
|
-
Connect(options: ConnectionOptions, concurrent?: number): ConnectionChain;
|
|
31
|
-
Close(): Promise<void>;
|
|
32
|
-
};
|
|
33
|
-
import { config } from "mssql";
|
|
34
|
-
type AuthStrategy = (config: ServerConfig) => config;
|
|
35
|
-
type ServerConfig = Omit<config2, "authentication" | "user" | "password">;
|
|
36
|
-
type ServerChain = {
|
|
37
|
-
Auth(strategy: AuthStrategy): AuthenticationChain;
|
|
38
|
-
};
|
|
1
|
+
import { ServerChain, ServerConfig } from "./shared/chunk-ydmc6s5q";
|
|
2
|
+
import "./shared/chunk-pmxhq7r6";
|
|
39
3
|
declare const Server: (config: ServerConfig) => ServerChain;
|
|
40
4
|
import * as SQL from "mssql";
|
|
41
5
|
export { Server, SQL };
|
package/dist/index.js
CHANGED
|
@@ -155,6 +155,29 @@ var Output = (data, error) => async (strategy) => {
|
|
|
155
155
|
return [errors, output];
|
|
156
156
|
};
|
|
157
157
|
|
|
158
|
+
// src/pipes/transform/index.ts
|
|
159
|
+
var Transform = (data, error) => {
|
|
160
|
+
return (transformFn) => {
|
|
161
|
+
class TransformDataStream extends TransformStream {
|
|
162
|
+
constructor() {
|
|
163
|
+
super({
|
|
164
|
+
async transform(chunk, controller) {
|
|
165
|
+
const transformedData2 = {
|
|
166
|
+
database: chunk.database,
|
|
167
|
+
data: await transformFn(chunk.data)
|
|
168
|
+
};
|
|
169
|
+
controller.enqueue(transformedData2);
|
|
170
|
+
}
|
|
171
|
+
});
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
const transformedData = data.pipeThrough(new TransformDataStream);
|
|
175
|
+
return {
|
|
176
|
+
Output: Output(transformedData, error)
|
|
177
|
+
};
|
|
178
|
+
};
|
|
179
|
+
};
|
|
180
|
+
|
|
158
181
|
// src/pipes/retrieve/index.ts
|
|
159
182
|
var Retrieve = (connections$, databases$, input) => {
|
|
160
183
|
return (fn) => {
|
|
@@ -168,7 +191,7 @@ var Retrieve = (connections$, databases$, input) => {
|
|
|
168
191
|
input,
|
|
169
192
|
fn,
|
|
170
193
|
onSuccess: async (result) => {
|
|
171
|
-
await dataWriter.write({
|
|
194
|
+
await dataWriter.write({ database: dc.database, data: result });
|
|
172
195
|
},
|
|
173
196
|
onError: async (error) => {
|
|
174
197
|
await errorWriter.write({ [dc.database]: error });
|
|
@@ -190,22 +213,12 @@ var Retrieve = (connections$, databases$, input) => {
|
|
|
190
213
|
await errorWriter.close();
|
|
191
214
|
})();
|
|
192
215
|
return {
|
|
216
|
+
Transform: Transform(readableData, readableError),
|
|
193
217
|
Output: Output(readableData, readableError)
|
|
194
218
|
};
|
|
195
219
|
};
|
|
196
220
|
};
|
|
197
221
|
|
|
198
|
-
// src/pipes/input/index.ts
|
|
199
|
-
var Input = (connections$, databases$) => {
|
|
200
|
-
return (fn) => {
|
|
201
|
-
const params = fn();
|
|
202
|
-
return {
|
|
203
|
-
Execute: Execute(connections$, databases$, params),
|
|
204
|
-
Retrieve: Retrieve(connections$, databases$, params)
|
|
205
|
-
};
|
|
206
|
-
};
|
|
207
|
-
};
|
|
208
|
-
|
|
209
222
|
// src/pipes/connect/index.ts
|
|
210
223
|
var Connect = (pool) => (param, concurrent) => {
|
|
211
224
|
let connections$;
|
|
@@ -243,7 +256,6 @@ var Connect = (pool) => (param, concurrent) => {
|
|
|
243
256
|
}
|
|
244
257
|
connections$ = connections(concurrent);
|
|
245
258
|
return {
|
|
246
|
-
Input: Input(connections$, databases$),
|
|
247
259
|
Execute: Execute(connections$, databases$, null),
|
|
248
260
|
Retrieve: Retrieve(connections$, databases$, null)
|
|
249
261
|
};
|
|
@@ -271,5 +283,5 @@ export {
|
|
|
271
283
|
SQL
|
|
272
284
|
};
|
|
273
285
|
|
|
274
|
-
//# debugId=
|
|
286
|
+
//# debugId=1C73627F80ABB76C64756E2164756E21
|
|
275
287
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1,21 +1,21 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 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/
|
|
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
5
|
"import { type config, ConnectionPool } from 'mssql';\nexport type Pool = {\n connect: (partialConfig: Partial<config>) => Promise<ConnectionPool>;\n closeAll: () => Promise<void>;\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 .catch(err => {\n delete POOL[database];\n throw err;\n });\n }\n\n return POOL[database]!;\n },\n closeAll: async () => {\n const closes = Object.values(POOL).map(pool => pool.then(p => p.close()));\n await Promise.all(closes);\n }\n\n }\n}",
|
|
6
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, SingleBar] => {\n const singleBar = new SingleBar({\n format: `{bar} {percentage}% | {value}/{total} | {database}`\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 (errorsCount >= limit) {\n open = true;\n }\n }\n\n return [guard, trackError];\n })()\n\n const runner = async <TParam, TReturn>({\n connection: dc,\n input,\n fn,\n onSuccess = () => { },\n onError = () => { }\n }: RunnerOptions<TParam, TReturn>): Promise<void> => {\n return guard()\n .then(() => {\n if (singleBar && Bun.env.NODE_ENV !== 'test') {\n singleBar.update({ database: dc.database });\n }\n })\n .then(() => dc.connection)\n .then(opened => opened.transaction())\n .then(tran => tran.begin()\n .then(() => fn(tran, dc.database, input))\n .then(result => onSuccess(result))\n .then(() => tran.commit())\n .then(() => {\n if (singleBar && Bun.env.NODE_ENV !== 'test') {\n singleBar.increment(1, { database: dc.database });\n }\n })\n .catch(error => tran.rollback().then(() => { throw error }))\n )\n .catch(async error => {\n if (error instanceof SafeGuardError) {\n return;\n }\n\n trackError();\n onError(error 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<TParam, TReturn> {\n connection: DatabaseConnection;\n input: TParam;\n fn: (transaction: Transaction, database: string, params: TParam) => Promise<TReturn>;\n onSuccess?: (result: TReturn) => Promise<void> | void;\n onError?: (error: ErrorType) => Promise<void> | void;\n}\n\nexport type TransactionRunner = <TParam, TReturn>(options: RunnerOptions<TParam, TReturn>) => Promise<void>;\n\nexport type ExecutionError = Record<string, ErrorType>;\n\nexport class SafeGuardError extends Error {\n constructor() {\n super(`Safe guard reached`);\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<TParam, TReturn> {\n connection: DatabaseConnection;\n input: TParam;\n fn: (transaction: Transaction, database: string, params: TParam) => Promise<TReturn>;\n onSuccess?: (result: TReturn) => Promise<void> | void;\n onError?: (error: ErrorType) => Promise<void> | void;\n}\n\nexport type TransactionRunner = <TParam, TReturn>(options: RunnerOptions<TParam, TReturn>) => Promise<void>;\n\nexport type ExecutionError = Record<string, ErrorType>;\nexport type ExecutionData<TReturn> = { database: string, data: TReturn }\n\nexport class SafeGuardError extends Error {\n constructor() {\n super(`Safe guard reached`);\n }\n}",
|
|
9
9
|
"import type { Transaction } from 'mssql';\nimport type { DatabaseConnection } from \"../connect/types\";\nimport { Runner } from '../shared/runner';\nimport type { ExecutionError } from '../shared/runner/types';\n\nexport const Execute = <TParam>(\n connections$: (databases: string[]) => Generator<DatabaseConnection[]>,\n databases$: Promise<string[]>,\n input: TParam\n) => {\n return async (\n fn: (transaction: Transaction, database: string, params: TParam) => Promise<void>\n ): Promise<ExecutionError[]> => {\n const errors: ExecutionError[] = [];\n\n const [runner, singleBar] = Runner();\n\n const executeFn = (dc: DatabaseConnection) => runner({\n connection: dc,\n input,\n fn,\n onError: async (error) => {\n errors.push({\n [dc.database]: {\n name: error.name,\n message: error.message,\n stack: error.stack,\n code: (error as any).code || undefined,\n number: (error as any).number || undefined,\n state: (error as any).state || undefined,\n class: (error as any).class || undefined,\n serverName: (error as any).serverName || undefined,\n procName: (error as any).procName || undefined,\n lineNumber: (error as any).lineNumber || undefined\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 await (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 { ExecutionError } from \"../
|
|
11
|
-
"import type {
|
|
12
|
-
"import {
|
|
13
|
-
"import type { Pool } from \"../../pool\";\nimport {
|
|
10
|
+
"import type { ExecutionData, ExecutionError } from \"../shared/runner/types\";\nimport type { OutputStrategy } from \"./strategies/types\";\n\nexport const Output =\n <TReturn, TOutput = void>(\n data: ReadableStream<ExecutionData<TReturn >>,\n error: ReadableStream<ExecutionError>\n ) =>\n async (strategy: OutputStrategy<TReturn, TOutput>): Promise<[ExecutionError[], TOutput]> => {\n const errors: ExecutionError[] = [];\n const output = await strategy(data);\n for await (const item of error) {\n errors.push(item);\n }\n return [errors, output];\n };\n",
|
|
11
|
+
"import type { ExecutionData, ExecutionError } from \"../shared/runner/types\";\nimport type { TransformChain, TransformFunction } from \"./types\";\nimport { Output } from \"../output\";\n\nexport const Transform = <TInput>(\n data: ReadableStream<ExecutionData<TInput>>,\n error: ReadableStream<ExecutionError>\n) => {\n return <TOutput>(transformFn: TransformFunction<TInput, TOutput>): TransformChain<TInput, TOutput> => {\n class TransformDataStream extends TransformStream<ExecutionData<TInput>, ExecutionData<TOutput>> {\n constructor() {\n super({\n async transform(chunk, controller) {\n const transformedData: ExecutionData<TOutput> = {\n database: chunk.database,\n data: await transformFn(chunk.data)\n };\n controller.enqueue(transformedData);\n }\n })\n }\n }\n \n const transformedData = data.pipeThrough(new TransformDataStream());\n\n return {\n Output: Output(transformedData, error)\n };\n }\n}",
|
|
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 { ExecutionData, ExecutionError } from \"../shared/runner/types\";\n\nexport const Retrieve = <TParam>(\n connections$: (databases: string[]) => Generator<DatabaseConnection[]>,\n databases$: Promise<string[]>,\n input: TParam\n) => {\n return <TReturn>(fn: (transaction: Transaction, database: string, params: TParam) => Promise<TReturn>): RetrieveChain<TReturn> => {\n const { readable: readableData, writable: writableData } = new TransformStream<ExecutionData<TReturn>, ExecutionData<TReturn>>();\n const { readable: readableError, writable: writableError } = new TransformStream<ExecutionError, ExecutionError>();\n const dataWriter = writableData.getWriter();\n const errorWriter = writableError.getWriter();\n\n const [runner, singleBar] = Runner();\n\n const executeFn = (dc: DatabaseConnection) => runner({\n connection: dc,\n input,\n fn,\n onSuccess: async (result) => {\n await dataWriter.write({ database: dc.database, data: result });\n },\n onError: async (error) => {\n await errorWriter.write({ [dc.database]: 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 await (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 dataWriter.close();\n await errorWriter.close();\n })();\n\n return {\n Transform: Transform(readableData, readableError),\n Output: Output(readableData, readableError)\n };\n }\n}",
|
|
13
|
+
"import type { Pool } from \"../../pool\";\nimport { Execute } from \"../execute\";\nimport { Retrieve } from \"../retrieve\";\n\nimport type { ConnectOverloads, ConnectionOptions, ConnectionChain, DatabaseConnection } from \"./types\";\nimport { LoadEnv } from \"../../utils/load-env\";\n\nexport const Connect = (pool: Pool): ConnectOverloads => (param: string | string[] | ConnectionOptions, concurrent?: number): ConnectionChain => {\n let connections$: (databases: string[]) => Generator<DatabaseConnection[]>;\n let databases$: Promise<string[]>;\n\n function connections(concurrent: number = Number.MAX_VALUE): (databases: string[]) => Generator<DatabaseConnection[]> {\n return function* (databases: string[]) {\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 })\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 })\n }));\n }\n }\n }\n\n if (typeof param === 'string') {\n databases$ = Promise.resolve([param]);\n }\n\n else if (Array.isArray(param)) {\n databases$ = Promise.resolve(param);\n }\n\n else if (typeof param === 'object' && 'query' in param) {\n databases$ = pool\n .connect({ database: param.database, arrayRowMode: true })\n .then(conn => conn\n .request()\n .query<string[]>(param.query)\n )\n .then(result => result.recordset.flat())\n }\n\n else {\n throw new Error(\"Invalid parameter\");\n }\n\n connections$ = connections(concurrent);\n\n return {\n Execute: Execute(connections$, databases$, null),\n Retrieve: Retrieve(connections$, databases$, null)\n }\n}",
|
|
14
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 Close: () => pool.closeAll(),\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": ";;;;AAAA;AAMO,SAAS,IAAI,CAAC,YAA0B;AAAA,EAC3C,MAAM,OAAgD,CAAC;AAAA,EAEvD,OAAO;AAAA,IACH,SAAS,CAAC,kBAAmC;AAAA,MACzC,MAAM,SAAS,KAAK,eAAe,cAAc;AAAA,MACjD,MAAM,WAAW,OAAO;AAAA,MAExB,IAAI,CAAC,UAAU;AAAA,QACX,MAAM,IAAI,MAAM,2BAA2B;AAAA,MAC/C;AAAA,MAEA,IAAI,EAAE,YAAY,OAAO;AAAA,QACrB,MAAM,OAAO,IAAI,eAAe,MAAM;AAAA,QACtC,MAAM,QAAQ,KAAK,MAAM,KAAK,IAAI;AAAA,QAElC,KAAK,QAAQ,YAAY;AAAA,UACrB,OAAO,KAAK;AAAA,UACZ,OAAO,MAAM,MAAM;AAAA;AAAA,QAGvB,KAAK,GAAG,SAAS,SAAO;AAAA,UACpB,OAAO,KAAK;AAAA,UACZ,MAAM;AAAA,SACT;AAAA,QAED,KAAK,YAAY,KACZ,QAAQ,EACR,MAAM,SAAO;AAAA,UACV,OAAO,KAAK;AAAA,UACZ,MAAM;AAAA,SACT;AAAA,MACT;AAAA,MAEA,OAAO,KAAK;AAAA;AAAA,IAEhB,UAAU,YAAY;AAAA,MAClB,MAAM,SAAS,OAAO,OAAO,IAAI,EAAE,IAAI,UAAQ,KAAK,KAAK,OAAK,EAAE,MAAM,CAAC,CAAC;AAAA,MACxE,MAAM,QAAQ,IAAI,MAAM;AAAA;AAAA,EAGhC;AAAA;;;AC/CJ;;;ACYO,IAAM,UAAU,MAAW;AAAA,EAC9B,MAAM,aAAa,OAAO,SAAS,IAAI,IAAI,cAAc,KAAK,EAAE;AAAA,EAChE,OAAO;AAAA,IAC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
|
|
21
21
|
}
|
|
@@ -1,7 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
import { config as config2 } from "mssql";
|
|
4
|
-
type AuthStrategy = (config2: ServerConfig) => config2;
|
|
1
|
+
import { AuthStrategy } from "../../../shared/chunk-ydmc6s5q";
|
|
2
|
+
import "../../../shared/chunk-pmxhq7r6";
|
|
5
3
|
declare const UserAndPassword: (username: string, password: string) => AuthStrategy;
|
|
6
4
|
import { NodeAuthOptions } from "@azure/msal-node";
|
|
7
5
|
declare const ActiveDirectoryAccessToken: (config: NodeAuthOptions) => Promise<AuthStrategy>;
|
|
@@ -1,12 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
TReturn,
|
|
3
|
-
TOutput = void
|
|
4
|
-
> = (data: ReadableStream<Record<string, TReturn>>) => Promise<TOutput>;
|
|
1
|
+
import { OutputStrategy } from "../../../shared/chunk-pmxhq7r6";
|
|
5
2
|
declare const MergeOutputStrategy: <
|
|
6
|
-
TData
|
|
3
|
+
TData,
|
|
7
4
|
TMerged = TData extends Array<infer TItem> ? TItem : TData
|
|
8
5
|
>() => OutputStrategy<TData, TMerged[]>;
|
|
9
6
|
declare const ConsoleOutputStrategy: <TData>() => OutputStrategy<TData, void>;
|
|
10
7
|
declare const JsonOutputStrategy: <TData>(allowEmpty?: boolean) => OutputStrategy<TData, string>;
|
|
11
|
-
declare const XlsOutputStrategy: <TData>(unique?: boolean) => OutputStrategy<TData, string>;
|
|
8
|
+
declare const XlsOutputStrategy: <TData extends []>(unique?: boolean) => OutputStrategy<TData, string>;
|
|
12
9
|
export { XlsOutputStrategy, OutputStrategy, MergeOutputStrategy, JsonOutputStrategy, ConsoleOutputStrategy };
|
|
@@ -5,9 +5,11 @@ import"../../../shared/chunk-s3vw82k6.js";
|
|
|
5
5
|
var MergeOutputStrategy = () => async (result) => {
|
|
6
6
|
const data = [];
|
|
7
7
|
for await (const item of result) {
|
|
8
|
-
|
|
9
|
-
data.push(...
|
|
10
|
-
}
|
|
8
|
+
if (Array.isArray(item.data)) {
|
|
9
|
+
data.push(...item.data);
|
|
10
|
+
} else {
|
|
11
|
+
data.push(item.data);
|
|
12
|
+
}
|
|
11
13
|
}
|
|
12
14
|
return data;
|
|
13
15
|
};
|
|
@@ -19,7 +21,7 @@ var ConsoleOutputStrategy = () => async (result) => {
|
|
|
19
21
|
};
|
|
20
22
|
// src/pipes/output/strategies/json.ts
|
|
21
23
|
var checkEmpty = (item) => {
|
|
22
|
-
const value =
|
|
24
|
+
const value = item.data;
|
|
23
25
|
if (value instanceof Array) {
|
|
24
26
|
return value.length === 0;
|
|
25
27
|
}
|
|
@@ -34,7 +36,7 @@ var JsonOutputStrategy = (allowEmpty = true) => async (result) => {
|
|
|
34
36
|
if (!allowEmpty && checkEmpty(item)) {
|
|
35
37
|
continue;
|
|
36
38
|
}
|
|
37
|
-
|
|
39
|
+
data[item.database] = item.data;
|
|
38
40
|
}
|
|
39
41
|
let filename = process.argv[1]?.replace(/\.(?:js|ts)/, "");
|
|
40
42
|
filename = `${filename}-${Date.now()}.json`;
|
|
@@ -50,20 +52,20 @@ import * as XLSX from "xlsx";
|
|
|
50
52
|
async function processSeparateSheets(result, workbook) {
|
|
51
53
|
let hasData = false;
|
|
52
54
|
for await (const dbResult of result) {
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
55
|
+
const database = dbResult.database;
|
|
56
|
+
const data = dbResult.data;
|
|
57
|
+
let sheetData = [];
|
|
58
|
+
if (Array.isArray(data)) {
|
|
59
|
+
sheetData = data;
|
|
60
|
+
} else if (data && typeof data === "object") {
|
|
61
|
+
sheetData = [data];
|
|
62
|
+
} else {
|
|
63
|
+
sheetData = [{ value: data }];
|
|
64
|
+
}
|
|
65
|
+
if (sheetData.length > 0) {
|
|
66
|
+
const worksheet = XLSX.utils.json_to_sheet(sheetData);
|
|
67
|
+
XLSX.utils.book_append_sheet(workbook, worksheet, database);
|
|
68
|
+
hasData = true;
|
|
67
69
|
}
|
|
68
70
|
}
|
|
69
71
|
return hasData;
|
|
@@ -73,20 +75,20 @@ async function processCombinedSheet(result, workbook) {
|
|
|
73
75
|
const databaseGroups = {};
|
|
74
76
|
let currentRow = 1;
|
|
75
77
|
for await (const dbResult of result) {
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
}
|
|
85
|
-
databaseGroups[database] ??= { startRow: currentRow, endRow: currentRow };
|
|
86
|
-
databaseGroups[database].endRow = currentRow + sheetData.length - 1;
|
|
87
|
-
currentRow += sheetData.length;
|
|
88
|
-
allData.push(...sheetData);
|
|
78
|
+
const database = dbResult.database;
|
|
79
|
+
const data = dbResult.data;
|
|
80
|
+
let sheetData = [];
|
|
81
|
+
if (Array.isArray(data)) {
|
|
82
|
+
sheetData = data.map((item) => ({ database, ...item }));
|
|
83
|
+
} else if (data && typeof data === "object") {
|
|
84
|
+
sheetData = [{ database, ...data }];
|
|
85
|
+
} else {
|
|
86
|
+
sheetData = [{ database, value: data }];
|
|
89
87
|
}
|
|
88
|
+
databaseGroups[database] ??= { startRow: currentRow, endRow: currentRow };
|
|
89
|
+
databaseGroups[database].endRow = currentRow + sheetData.length - 1;
|
|
90
|
+
currentRow += sheetData.length;
|
|
91
|
+
allData.push(...sheetData);
|
|
90
92
|
}
|
|
91
93
|
if (allData.length === 0) {
|
|
92
94
|
return false;
|
|
@@ -135,5 +137,5 @@ export {
|
|
|
135
137
|
ConsoleOutputStrategy
|
|
136
138
|
};
|
|
137
139
|
|
|
138
|
-
//# debugId=
|
|
140
|
+
//# debugId=02912BE6658738F764756E2164756E21
|
|
139
141
|
//# 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
|
|
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
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 { OutputStrategy } from './types';\n\nconst checkEmpty = (item:
|
|
8
|
-
"import * as XLSX from 'xlsx';\nimport type { OutputStrategy } from './types';\n\nasync function processSeparateSheets<TData>(\n result: ReadableStream<
|
|
7
|
+
"import type { ExecutionData } from '../../shared/runner/types';\nimport type { OutputStrategy } from './types';\n\nconst checkEmpty = (item: ExecutionData<unknown>) => {\n const value = item.data;\n if (value instanceof Array) {\n return value.length === 0;\n }\n\n if (value instanceof Object) {\n return Object.values(value).length === 0;\n }\n\n return value === null || value === undefined;\n}\n\nexport const JsonOutputStrategy = <TData>(allowEmpty: boolean = true): OutputStrategy<TData, string> => async (result) => {\n const data: Record<string, TData> = {};\n\n for await (const item of result) {\n if (!allowEmpty && checkEmpty(item)) {\n continue;\n }\n data[item.database] = item.data;\n }\n\n let filename = process.argv[1]?.replace(/\\.(?:js|ts)/, '')\n filename = `${filename}-${Date.now()}.json`;\n\n try {\n await Bun.write(filename, JSON.stringify(data, null, 2));\n } catch (error) {\n console.error('Error writing JSON file:', error);\n }\n\n return filename;\n};",
|
|
8
|
+
"import * as XLSX from 'xlsx';\nimport type { OutputStrategy } from './types';\nimport type { ExecutionData } from '../../shared/runner/types';\n\nasync function processSeparateSheets<TData>(\n result: ReadableStream<ExecutionData<TData>>,\n workbook: XLSX.WorkBook\n): Promise<boolean> {\n let hasData = false;\n\n for await (const dbResult of result) {\n const database = dbResult.database;\n const data = dbResult.data;\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 if (sheetData.length > 0) {\n const worksheet = XLSX.utils.json_to_sheet(sheetData);\n XLSX.utils.book_append_sheet(workbook, worksheet, database);\n hasData = true;\n }\n }\n\n return hasData;\n}\n\nasync function processCombinedSheet<TData>(\n result: ReadableStream<ExecutionData<TData>>,\n workbook: XLSX.WorkBook\n): Promise<boolean> {\n const allData: unknown[] = [];\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\n let sheetData: unknown[] = [];\n if (Array.isArray(data)) {\n sheetData = data.map(item => ({ database, ...item }));\n } else if (data && typeof data === 'object') {\n sheetData = [{ database, ...data }];\n } else {\n sheetData = [{ database, value: data }];\n }\n\n // Track the start row for this database group\n databaseGroups[database] ??= { startRow: currentRow, endRow: currentRow };\n\n // Update the end row for this database group\n databaseGroups[database].endRow = currentRow + sheetData.length - 1;\n currentRow += sheetData.length;\n\n allData.push(...sheetData);\n }\n\n if (allData.length === 0) {\n return false;\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 true;\n}\n\nexport const XlsOutputStrategy = <TData extends []>(unique: boolean = false): OutputStrategy<TData, string> => async (result) => {\n const workbook = XLSX.utils.book_new();\n\n if (unique) {\n const hasData = await processCombinedSheet(result, workbook);\n if (!hasData) {\n const emptyWorksheet = XLSX.utils.json_to_sheet([{ message: \"No data available\" }]);\n XLSX.utils.book_append_sheet(workbook, emptyWorksheet, \"Empty\");\n }\n } else {\n const hasData = await processSeparateSheets(result, workbook);\n if (!hasData) {\n const emptyWorksheet = XLSX.utils.json_to_sheet([{ message: \"No data available\" }]);\n XLSX.utils.book_append_sheet(workbook, emptyWorksheet, \"Empty\");\n }\n }\n\n let filename = process.argv[1]?.replace(/\\.(?:js|ts)/, '');\n filename = `${filename}-${Date.now()}.xlsx`;\n\n try {\n const buffer = XLSX.write(workbook, { type: 'buffer', bookType: 'xlsx', cellStyles: true });\n await Bun.write(filename, buffer);\n return filename;\n } catch (error) {\n console.error('Error writing Excel file');\n throw error;\n }\n};"
|
|
9
9
|
],
|
|
10
|
-
"mappings": ";;;;AAEO,IAAM,sBAAsB,
|
|
11
|
-
"debugId": "
|
|
10
|
+
"mappings": ";;;;AAEO,IAAM,sBAAsB,MAA2G,OAAO,WAAW;AAAA,EAC9J,MAAM,OAAkB,CAAC;AAAA,EACzB,iBAAiB,QAAQ,QAAQ;AAAA,IAC/B,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;AAAA;;ACTF,IAAM,wBAAwB,MAA0C,OAAO,WAAW;AAAA,EAC/F,iBAAiB,QAAQ,QAAQ;AAAA,IAC/B,QAAQ,IAAI,IAAI;AAAA,EAClB;AAAA;;ACFF,IAAM,aAAa,CAAC,SAAiC;AAAA,EACnD,MAAM,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EAEK,WAAM,kBAAkB,UAAU,WAAW,UAAU;AAAA,EAC5D,OAAO;AAAA;AAGF,IAAM,oBAAoB,CAAmB,SAAkB,UAAyC,OAAO,WAAW;AAAA,EAC/H,MAAM,WAAgB,WAAM,SAAS;AAAA,EAErC,IAAI,QAAQ;AAAA,IACV,MAAM,UAAU,MAAM,qBAAqB,QAAQ,QAAQ;AAAA,IAC3D,IAAI,CAAC,SAAS;AAAA,MACZ,MAAM,iBAAsB,WAAM,cAAc,CAAC,EAAE,SAAS,oBAAoB,CAAC,CAAC;AAAA,MAC7E,WAAM,kBAAkB,UAAU,gBAAgB,OAAO;AAAA,IAChE;AAAA,EACF,EAAO;AAAA,IACL,MAAM,UAAU,MAAM,sBAAsB,QAAQ,QAAQ;AAAA,IAC5D,IAAI,CAAC,SAAS;AAAA,MACZ,MAAM,iBAAsB,WAAM,cAAc,CAAC,EAAE,SAAS,oBAAoB,CAAC,CAAC;AAAA,MAC7E,WAAM,kBAAkB,UAAU,gBAAgB,OAAO;AAAA,IAChE;AAAA;AAAA,EAGF,IAAI,WAAW,QAAQ,KAAK,IAAI,QAAQ,eAAe,EAAE;AAAA,EACzD,WAAW,GAAG,YAAY,KAAK,IAAI;AAAA,EAEnC,IAAI;AAAA,IACF,MAAM,SAAc,WAAM,UAAU,EAAE,MAAM,UAAU,UAAU,QAAQ,YAAY,KAAK,CAAC;AAAA,IAC1F,MAAM,IAAI,MAAM,UAAU,MAAM;AAAA,IAChC,OAAO;AAAA,IACP,OAAO,OAAO;AAAA,IACd,QAAQ,MAAM,0BAA0B;AAAA,IACxC,MAAM;AAAA;AAAA;",
|
|
11
|
+
"debugId": "02912BE6658738F764756E2164756E21",
|
|
12
12
|
"names": []
|
|
13
13
|
}
|
|
@@ -0,0 +1,35 @@
|
|
|
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 };
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { ConnectionChain, ConnectionOptions } from "./chunk-pmxhq7r6";
|
|
2
|
+
import { config } from "mssql";
|
|
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>;
|
|
8
|
+
};
|
|
9
|
+
type ServerConfig = Omit<config, "authentication" | "user" | "password">;
|
|
10
|
+
type ServerChain = {
|
|
11
|
+
Auth(strategy: AuthStrategy): AuthenticationChain;
|
|
12
|
+
};
|
|
13
|
+
import { config as config2 } from "mssql";
|
|
14
|
+
type AuthStrategy = (config2: ServerConfig) => config2;
|
|
15
|
+
export { AuthStrategy, ServerConfig, ServerChain };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "squilo",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.1",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"files": [
|
|
6
6
|
"dist"
|
|
@@ -43,7 +43,8 @@
|
|
|
43
43
|
"test": "bun test",
|
|
44
44
|
"test:watch": "bun test --watch",
|
|
45
45
|
"test:debug": "bun test --inspect",
|
|
46
|
-
"build": "bunup"
|
|
46
|
+
"build": "bunup",
|
|
47
|
+
"prepublishOnly": "bun run build"
|
|
47
48
|
},
|
|
48
49
|
"devDependencies": {
|
|
49
50
|
"@biomejs/biome": "2.2.6",
|