squilo 0.1.2 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +265 -36
- package/package.json +17 -12
- package/src/.DS_Store +0 -0
- package/src/index.ts +3 -1
- package/src/pipes/auth/index.ts +2 -12
- package/src/pipes/auth/strategies/msal.ts +14 -7
- package/src/pipes/auth/strategies/userAndPassword.ts +1 -1
- package/src/pipes/auth/types.ts +12 -0
- package/src/pipes/connect/index.ts +25 -42
- package/src/pipes/connect/types.ts +25 -0
- package/src/pipes/execute/index.ts +36 -4
- package/src/pipes/index.ts +1 -1
- package/src/pipes/input/index.ts +6 -11
- package/src/pipes/input/types.ts +7 -0
- package/src/pipes/output/index.ts +4 -3
- package/src/pipes/output/strategies/console.ts +1 -1
- package/src/pipes/output/strategies/json.spec.ts +16 -6
- package/src/pipes/output/strategies/json.ts +14 -3
- package/src/pipes/output/strategies/merge.ts +1 -1
- package/src/pipes/output/strategies/xls.spec.ts +44 -15
- package/src/pipes/output/strategies/xls.ts +42 -10
- package/src/pipes/output/types.ts +1 -0
- package/src/pipes/retrieve/index.ts +48 -19
- package/src/pipes/retrieve/types.ts +5 -0
- package/src/pipes/server/index.ts +2 -6
- package/src/pipes/server/types.ts +5 -0
- package/src/pipes/types.ts +1 -0
- package/src/utils/append-error.ts +42 -0
- package/src/utils/load-env.ts +18 -0
- package/biome.json +0 -34
- package/test/connect.spec.ts +0 -119
- package/test/container/container.spec.ts +0 -33
- package/test/container/container.ts +0 -22
- package/test/container/setup/databases.spec.ts +0 -24
- package/test/container/setup/databases.ts +0 -77
- package/test/container/setup/users.spec.ts +0 -25
- package/test/container/setup/users.ts +0 -54
- package/test/index.spec.ts +0 -68
- package/test/input.spec.ts +0 -64
- package/tsconfig.json +0 -28
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
import { afterAll, beforeAll, describe, expect, it, test } from 'bun:test'
|
|
2
|
-
import { connect, ConnectionPool } from 'mssql'
|
|
3
|
-
import type { StartedTestContainer } from 'testcontainers'
|
|
4
|
-
import { AzureSqlEdge, SQL_PASSWORD } from './container';
|
|
5
|
-
|
|
6
|
-
describe('SQL Server', async () => {
|
|
7
|
-
let container: StartedTestContainer
|
|
8
|
-
let sqlClient: ConnectionPool
|
|
9
|
-
|
|
10
|
-
beforeAll(async () => {
|
|
11
|
-
container = await AzureSqlEdge()
|
|
12
|
-
sqlClient = await connect({
|
|
13
|
-
server: container.getHost(),
|
|
14
|
-
port: container.getMappedPort(1433),
|
|
15
|
-
database: 'master',
|
|
16
|
-
user: 'sa',
|
|
17
|
-
password: SQL_PASSWORD,
|
|
18
|
-
options: {
|
|
19
|
-
encrypt: false
|
|
20
|
-
}
|
|
21
|
-
});
|
|
22
|
-
})
|
|
23
|
-
|
|
24
|
-
afterAll(async () => {
|
|
25
|
-
await sqlClient.close();
|
|
26
|
-
await container.stop();
|
|
27
|
-
})
|
|
28
|
-
|
|
29
|
-
it('should connect to the database', async () => {
|
|
30
|
-
const result = await sqlClient.query`SELECT 'Hello'`;
|
|
31
|
-
expect(result.recordset[0]['']).toBe('Hello');
|
|
32
|
-
})
|
|
33
|
-
})
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import { GenericContainer, type StartedTestContainer, Wait } from "testcontainers";
|
|
2
|
-
|
|
3
|
-
export const SQL_PASSWORD = "YourStrong@Passw0rd";
|
|
4
|
-
|
|
5
|
-
export const AzureSqlEdge = () => new GenericContainer('mcr.microsoft.com/azure-sql-edge')
|
|
6
|
-
.withEnvironment({
|
|
7
|
-
'ACCEPT_EULA': 'Y',
|
|
8
|
-
'MSSQL_SA_PASSWORD': SQL_PASSWORD
|
|
9
|
-
})
|
|
10
|
-
.withExposedPorts(1433)
|
|
11
|
-
.withWaitStrategy(Wait.forLogMessage('Recovery is complete'))
|
|
12
|
-
.start();
|
|
13
|
-
|
|
14
|
-
export const CONFIG = (container: StartedTestContainer) => ({
|
|
15
|
-
server: container.getHost(),
|
|
16
|
-
port: container.getMappedPort(1433),
|
|
17
|
-
user: "sa",
|
|
18
|
-
password: SQL_PASSWORD,
|
|
19
|
-
options: {
|
|
20
|
-
encrypt: false
|
|
21
|
-
}
|
|
22
|
-
})
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import { beforeAll, describe, expect, it } from "bun:test"
|
|
2
|
-
import { SetupDatabases } from "./databases"
|
|
3
|
-
import { AzureSqlEdge, CONFIG } from "../container"
|
|
4
|
-
import { connect } from "mssql"
|
|
5
|
-
|
|
6
|
-
describe('Database creation', async () => {
|
|
7
|
-
const container = await AzureSqlEdge();
|
|
8
|
-
|
|
9
|
-
beforeAll(async () => {
|
|
10
|
-
await SetupDatabases(container);
|
|
11
|
-
})
|
|
12
|
-
|
|
13
|
-
it('Should create 5 databases', async () => {
|
|
14
|
-
const conn = await connect({
|
|
15
|
-
...CONFIG(container),
|
|
16
|
-
database: "master"
|
|
17
|
-
});
|
|
18
|
-
|
|
19
|
-
const result = await conn.query`SELECT * FROM sys.databases WHERE name like 'TestDB%'`
|
|
20
|
-
expect(result.recordset).toHaveLength(5);
|
|
21
|
-
|
|
22
|
-
await conn.close();
|
|
23
|
-
})
|
|
24
|
-
})
|
|
@@ -1,77 +0,0 @@
|
|
|
1
|
-
import { Bit, connect, NVarChar, Table } from "mssql";
|
|
2
|
-
import { CONFIG } from "../container";
|
|
3
|
-
import type { StartedTestContainer } from "testcontainers";
|
|
4
|
-
|
|
5
|
-
export const CLIENTS_MANAGER_DATABASE = 'ClientsManager';
|
|
6
|
-
|
|
7
|
-
export const DATABASES = [
|
|
8
|
-
"TestDB1",
|
|
9
|
-
"TestDB2",
|
|
10
|
-
"TestDB3",
|
|
11
|
-
"TestDB4",
|
|
12
|
-
"TestDB5",
|
|
13
|
-
];
|
|
14
|
-
|
|
15
|
-
export const SetupClientManager = async (container: StartedTestContainer) => {
|
|
16
|
-
const masterConn = await connect({
|
|
17
|
-
...CONFIG(container),
|
|
18
|
-
database: "master"
|
|
19
|
-
});
|
|
20
|
-
|
|
21
|
-
await masterConn.query(`
|
|
22
|
-
IF NOT EXISTS (SELECT * FROM sys.databases WHERE name = '${CLIENTS_MANAGER_DATABASE}')
|
|
23
|
-
BEGIN
|
|
24
|
-
CREATE DATABASE ${CLIENTS_MANAGER_DATABASE};
|
|
25
|
-
END
|
|
26
|
-
`);
|
|
27
|
-
|
|
28
|
-
await masterConn.close();
|
|
29
|
-
|
|
30
|
-
const clientManagerConn = await connect({
|
|
31
|
-
...CONFIG(container),
|
|
32
|
-
database: CLIENTS_MANAGER_DATABASE
|
|
33
|
-
});
|
|
34
|
-
|
|
35
|
-
await clientManagerConn.query(`
|
|
36
|
-
IF NOT EXISTS (SELECT * FROM sys.tables WHERE name = 'Clients')
|
|
37
|
-
BEGIN
|
|
38
|
-
CREATE TABLE Clients (
|
|
39
|
-
Id INT PRIMARY KEY IDENTITY(1,1),
|
|
40
|
-
Name NVARCHAR(255) UNIQUE NOT NULL,
|
|
41
|
-
DatabaseName NVARCHAR(255) UNIQUE NOT NULL,
|
|
42
|
-
Active BIT NOT NULL
|
|
43
|
-
);
|
|
44
|
-
END
|
|
45
|
-
`);
|
|
46
|
-
|
|
47
|
-
const table = new Table("Clients");
|
|
48
|
-
table.columns.add("Name", NVarChar(255), { nullable: false});
|
|
49
|
-
table.columns.add("DatabaseName", NVarChar(255), { nullable: false});
|
|
50
|
-
table.columns.add("Active", Bit(), { nullable: false});
|
|
51
|
-
|
|
52
|
-
for (const database of DATABASES) {
|
|
53
|
-
table.rows.add(database, database, 1);
|
|
54
|
-
}
|
|
55
|
-
table.rows.add("TestDB6", "TestDB6", 0);
|
|
56
|
-
|
|
57
|
-
await clientManagerConn.request().bulk(table);
|
|
58
|
-
await clientManagerConn.close();
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
export const SetupDatabases = async (container: StartedTestContainer) => {
|
|
62
|
-
const conn = await connect({
|
|
63
|
-
...CONFIG(container),
|
|
64
|
-
database: "master"
|
|
65
|
-
});
|
|
66
|
-
|
|
67
|
-
for (const dbName of DATABASES) {
|
|
68
|
-
await conn.query(`
|
|
69
|
-
IF NOT EXISTS (SELECT * FROM sys.databases WHERE name = '${dbName}')
|
|
70
|
-
BEGIN
|
|
71
|
-
CREATE DATABASE ${dbName};
|
|
72
|
-
END
|
|
73
|
-
`);
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
await conn.close();
|
|
77
|
-
}
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import { beforeAll, describe, expect, test } from "bun:test";
|
|
2
|
-
import { AzureSqlEdge, CONFIG } from "../container";
|
|
3
|
-
import { DATABASES, SetupDatabases } from "./databases";
|
|
4
|
-
import { SetupUsers } from "./users";
|
|
5
|
-
import { connect } from "mssql";
|
|
6
|
-
|
|
7
|
-
describe('Users table', async () => {
|
|
8
|
-
const container = await AzureSqlEdge();
|
|
9
|
-
|
|
10
|
-
beforeAll(async () => {
|
|
11
|
-
await SetupDatabases(container);
|
|
12
|
-
await SetupUsers(container);
|
|
13
|
-
})
|
|
14
|
-
|
|
15
|
-
test.each(DATABASES)('Should create 10 users in %s', async (database) => {
|
|
16
|
-
const conn = await connect({
|
|
17
|
-
...CONFIG(container),
|
|
18
|
-
database
|
|
19
|
-
});
|
|
20
|
-
const result = await conn.query`SELECT * FROM Users`
|
|
21
|
-
expect(result.recordset).toHaveLength(10);
|
|
22
|
-
|
|
23
|
-
await conn.close();
|
|
24
|
-
})
|
|
25
|
-
})
|
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
import { DATABASES } from "./databases";
|
|
2
|
-
import { connect, NVarChar, Table } from "mssql";
|
|
3
|
-
import { CONFIG } from "../container";
|
|
4
|
-
import { faker } from "@faker-js/faker";
|
|
5
|
-
import type { StartedTestContainer } from "testcontainers";
|
|
6
|
-
|
|
7
|
-
export type User = {
|
|
8
|
-
Id: number;
|
|
9
|
-
Name: string;
|
|
10
|
-
Email: string;
|
|
11
|
-
};
|
|
12
|
-
|
|
13
|
-
export const SetupUsers = async (container: StartedTestContainer, options: {
|
|
14
|
-
populate: boolean;
|
|
15
|
-
} = {
|
|
16
|
-
populate: true
|
|
17
|
-
}) => {
|
|
18
|
-
for (const database of DATABASES) {
|
|
19
|
-
const conn = await connect({
|
|
20
|
-
...CONFIG(container),
|
|
21
|
-
database
|
|
22
|
-
});
|
|
23
|
-
|
|
24
|
-
await conn.request().query`
|
|
25
|
-
IF NOT EXISTS (SELECT * FROM sys.tables WHERE name = 'Users')
|
|
26
|
-
BEGIN
|
|
27
|
-
CREATE TABLE Users (
|
|
28
|
-
Id INT PRIMARY KEY IDENTITY(1,1),
|
|
29
|
-
Name NVARCHAR(100) NOT NULL,
|
|
30
|
-
Email NVARCHAR(100) NOT NULL
|
|
31
|
-
);
|
|
32
|
-
END
|
|
33
|
-
`;
|
|
34
|
-
|
|
35
|
-
if (options.populate) {
|
|
36
|
-
await conn.request().query(`DELETE FROM Users`);
|
|
37
|
-
|
|
38
|
-
const usersTable = new Table("Users");
|
|
39
|
-
usersTable.columns.add("Name", NVarChar(100), { nullable: false });
|
|
40
|
-
usersTable.columns.add("Email", NVarChar(100), { nullable: false });
|
|
41
|
-
|
|
42
|
-
for (let i = 0; i < 10; i++) {
|
|
43
|
-
const name = faker.person.fullName({ firstName: "Joe"});
|
|
44
|
-
const email = faker.internet.email({ firstName: "Joe" }) + " ";
|
|
45
|
-
|
|
46
|
-
usersTable.rows.add(name, email);
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
await conn.request().bulk(usersTable);
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
await conn.close();
|
|
53
|
-
}
|
|
54
|
-
}
|
package/test/index.spec.ts
DELETED
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
import { expect, beforeAll, describe, it, afterAll, test } from "bun:test";
|
|
2
|
-
import { Server } from "../src/pipes/server";
|
|
3
|
-
import { UserAndPassword } from "../src/pipes/auth/strategies";
|
|
4
|
-
import { MergeOutputStrategy } from "../src/pipes/output/strategies";
|
|
5
|
-
import { AzureSqlEdge, SQL_PASSWORD } from "./container/container";
|
|
6
|
-
import { DATABASES, SetupDatabases } from "./container/setup/databases";
|
|
7
|
-
import { SetupUsers, type User } from "./container/setup/users";
|
|
8
|
-
|
|
9
|
-
describe('Squilo test', async () => {
|
|
10
|
-
const container = await AzureSqlEdge();
|
|
11
|
-
|
|
12
|
-
const LocalServer = Server({
|
|
13
|
-
server: container.getHost(),
|
|
14
|
-
port: container.getMappedPort(1433),
|
|
15
|
-
options: {
|
|
16
|
-
encrypt: false
|
|
17
|
-
},
|
|
18
|
-
})
|
|
19
|
-
.Auth(UserAndPassword("sa", SQL_PASSWORD));
|
|
20
|
-
|
|
21
|
-
beforeAll(async () => {
|
|
22
|
-
await SetupDatabases(container);
|
|
23
|
-
await SetupUsers(container);
|
|
24
|
-
})
|
|
25
|
-
|
|
26
|
-
afterAll(async () => {
|
|
27
|
-
await LocalServer.Close();
|
|
28
|
-
})
|
|
29
|
-
|
|
30
|
-
it("Get one from each database", async () => {
|
|
31
|
-
|
|
32
|
-
const users = await LocalServer
|
|
33
|
-
.Connect(DATABASES)
|
|
34
|
-
.Retrieve(async (transaction) => {
|
|
35
|
-
const result = await transaction.request().query<User>`
|
|
36
|
-
SELECT TOP 1 * FROM Users
|
|
37
|
-
`;
|
|
38
|
-
|
|
39
|
-
return result.recordset;
|
|
40
|
-
})
|
|
41
|
-
.Output(MergeOutputStrategy());
|
|
42
|
-
|
|
43
|
-
expect(users).toHaveLength(5);
|
|
44
|
-
});
|
|
45
|
-
|
|
46
|
-
test('Should fix user\'s email that are ending with extra space', async () => {
|
|
47
|
-
await LocalServer
|
|
48
|
-
.Connect(DATABASES)
|
|
49
|
-
.Execute(async (transaction) => {
|
|
50
|
-
await transaction.request().query`
|
|
51
|
-
UPDATE Users SET Email = RTRIM(Email)
|
|
52
|
-
`;
|
|
53
|
-
})
|
|
54
|
-
|
|
55
|
-
const users = await LocalServer
|
|
56
|
-
.Connect(DATABASES)
|
|
57
|
-
.Retrieve(async (transaction) => {
|
|
58
|
-
const result = await transaction.request().query<User>`
|
|
59
|
-
SELECT * FROM Users
|
|
60
|
-
`;
|
|
61
|
-
|
|
62
|
-
return result.recordset;
|
|
63
|
-
})
|
|
64
|
-
.Output(MergeOutputStrategy());
|
|
65
|
-
|
|
66
|
-
expect(users.every((user) => user.Email.endsWith(" ") === false)).toBe(true);
|
|
67
|
-
})
|
|
68
|
-
});
|
package/test/input.spec.ts
DELETED
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
import { afterAll, beforeAll, describe, expect, test } from "bun:test";
|
|
2
|
-
import { AzureSqlEdge, SQL_PASSWORD } from "./container/container";
|
|
3
|
-
import { Server } from "../src/pipes/server";
|
|
4
|
-
import { UserAndPassword } from "../src/pipes/auth/strategies";
|
|
5
|
-
import { DATABASES, SetupDatabases } from "./container/setup/databases";
|
|
6
|
-
import { SetupUsers, type User } from "./container/setup/users";
|
|
7
|
-
import { MergeOutputStrategy } from "../src/pipes/output/strategies";
|
|
8
|
-
|
|
9
|
-
describe('Squilo input test', async () => {
|
|
10
|
-
const container = await AzureSqlEdge();
|
|
11
|
-
const localServer = Server({
|
|
12
|
-
server: container.getHost(),
|
|
13
|
-
port: container.getMappedPort(1433),
|
|
14
|
-
options: {
|
|
15
|
-
encrypt: false
|
|
16
|
-
},
|
|
17
|
-
})
|
|
18
|
-
.Auth(UserAndPassword("sa", SQL_PASSWORD));
|
|
19
|
-
|
|
20
|
-
beforeAll(async () => {
|
|
21
|
-
await SetupDatabases(container);
|
|
22
|
-
await SetupUsers(container, { populate: false })
|
|
23
|
-
})
|
|
24
|
-
|
|
25
|
-
afterAll(async () => {
|
|
26
|
-
await localServer.Close();
|
|
27
|
-
})
|
|
28
|
-
|
|
29
|
-
test('Should add a user using console input', async () => {
|
|
30
|
-
let name: string | null = "joe";
|
|
31
|
-
let email: string | null = "joe.doe@example.com";
|
|
32
|
-
|
|
33
|
-
await localServer
|
|
34
|
-
.Connect(DATABASES)
|
|
35
|
-
.Input<Omit<User, "Id">>(() => {
|
|
36
|
-
return {
|
|
37
|
-
Name: name!,
|
|
38
|
-
Email: email!,
|
|
39
|
-
}
|
|
40
|
-
})
|
|
41
|
-
.Execute(async (transaction, _, user) => {
|
|
42
|
-
await transaction.request().query`
|
|
43
|
-
INSERT INTO Users (Name, Email)
|
|
44
|
-
VALUES (${user.Name}, ${user.Email})
|
|
45
|
-
`;
|
|
46
|
-
});
|
|
47
|
-
|
|
48
|
-
const users = await localServer
|
|
49
|
-
.Connect(DATABASES)
|
|
50
|
-
.Retrieve(async (transaction) => {
|
|
51
|
-
const result = await transaction.request().query<User>`
|
|
52
|
-
SELECT * FROM Users
|
|
53
|
-
`;
|
|
54
|
-
|
|
55
|
-
return result.recordset;
|
|
56
|
-
})
|
|
57
|
-
.Output(MergeOutputStrategy());
|
|
58
|
-
|
|
59
|
-
expect(users).toHaveLength(5);
|
|
60
|
-
|
|
61
|
-
const everyUserIsJoe = users.every(user => user.Name === name && user.Email === email);
|
|
62
|
-
expect(everyUserIsJoe).toBe(true);
|
|
63
|
-
})
|
|
64
|
-
})
|
package/tsconfig.json
DELETED
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"compilerOptions": {
|
|
3
|
-
// Environment setup & latest features
|
|
4
|
-
"lib": ["ESNext"],
|
|
5
|
-
"target": "ESNext",
|
|
6
|
-
"module": "Preserve",
|
|
7
|
-
"moduleDetection": "force",
|
|
8
|
-
"allowJs": true,
|
|
9
|
-
|
|
10
|
-
// Bundler mode
|
|
11
|
-
"moduleResolution": "bundler",
|
|
12
|
-
"allowImportingTsExtensions": true,
|
|
13
|
-
"verbatimModuleSyntax": true,
|
|
14
|
-
"noEmit": true,
|
|
15
|
-
|
|
16
|
-
// Best practices
|
|
17
|
-
"strict": true,
|
|
18
|
-
"skipLibCheck": true,
|
|
19
|
-
"noFallthroughCasesInSwitch": true,
|
|
20
|
-
"noUncheckedIndexedAccess": true,
|
|
21
|
-
"noImplicitOverride": true,
|
|
22
|
-
|
|
23
|
-
// Some stricter flags (disabled by default)
|
|
24
|
-
"noUnusedLocals": false,
|
|
25
|
-
"noUnusedParameters": false,
|
|
26
|
-
"noPropertyAccessFromIndexSignature": false
|
|
27
|
-
}
|
|
28
|
-
}
|