@lobb-js/lobb-ext-reports 0.15.0 → 0.15.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/lib/components/pages/reports/components/report.svelte +1 -1
- package/extensions/reports/studio/lib/components/pages/reports/components/report.svelte +1 -1
- package/package.json +5 -5
- package/extensions/reports/tests/configs/simple.ts +0 -49
- package/extensions/reports/tests/reports.test.ts +0 -105
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lobb-js/lobb-ext-reports",
|
|
3
|
-
"version": "0.15.
|
|
3
|
+
"version": "0.15.1",
|
|
4
4
|
"license": "UNLICENSED",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"publishConfig": {
|
|
@@ -18,8 +18,8 @@
|
|
|
18
18
|
}
|
|
19
19
|
},
|
|
20
20
|
"scripts": {
|
|
21
|
-
"test": "bun test
|
|
22
|
-
"test:lobb": "bun test
|
|
21
|
+
"test": "bun test tests",
|
|
22
|
+
"test:lobb": "bun test tests",
|
|
23
23
|
"dev": "bun run --watch lobb.ts",
|
|
24
24
|
"dev:studio": "vite dev",
|
|
25
25
|
"build": "vite build",
|
|
@@ -32,7 +32,7 @@
|
|
|
32
32
|
"package": "svelte-package --input extensions/reports/studio"
|
|
33
33
|
},
|
|
34
34
|
"dependencies": {
|
|
35
|
-
"@lobb-js/core": "^0.
|
|
35
|
+
"@lobb-js/core": "^0.37.0",
|
|
36
36
|
"chart.js": "^4.4.8",
|
|
37
37
|
"gridstack": "^12.6.0",
|
|
38
38
|
"hono": "^4.7.0",
|
|
@@ -43,7 +43,7 @@
|
|
|
43
43
|
},
|
|
44
44
|
"devDependencies": {
|
|
45
45
|
"@faker-js/faker": "^9.6.0",
|
|
46
|
-
"@lobb-js/studio": "^0.
|
|
46
|
+
"@lobb-js/studio": "^0.37.1",
|
|
47
47
|
"@lucide/svelte": "^0.563.1",
|
|
48
48
|
"@sveltejs/adapter-node": "^5.5.4",
|
|
49
49
|
"@sveltejs/kit": "^2.60.1",
|
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
import type { Config } from "@lobb-js/core";
|
|
2
|
-
import extension from "../../index.ts";
|
|
3
|
-
|
|
4
|
-
export const simpleConfig: Config = {
|
|
5
|
-
project: {
|
|
6
|
-
name: "Lobb",
|
|
7
|
-
force_sync: true,
|
|
8
|
-
},
|
|
9
|
-
database: {
|
|
10
|
-
host: "localhost",
|
|
11
|
-
port: 5432,
|
|
12
|
-
username: "test",
|
|
13
|
-
password: "test",
|
|
14
|
-
database: "*",
|
|
15
|
-
},
|
|
16
|
-
web_server: {
|
|
17
|
-
host: "0.0.0.0",
|
|
18
|
-
port: 0,
|
|
19
|
-
cors: {
|
|
20
|
-
origin: "*",
|
|
21
|
-
},
|
|
22
|
-
},
|
|
23
|
-
extensions: [
|
|
24
|
-
extension(),
|
|
25
|
-
],
|
|
26
|
-
collections: {
|
|
27
|
-
donations: {
|
|
28
|
-
indexes: {},
|
|
29
|
-
fields: {
|
|
30
|
-
id: {
|
|
31
|
-
type: "integer",
|
|
32
|
-
},
|
|
33
|
-
donor_name: {
|
|
34
|
-
type: "string",
|
|
35
|
-
length: 255,
|
|
36
|
-
required: true,
|
|
37
|
-
},
|
|
38
|
-
amount: {
|
|
39
|
-
type: "decimal",
|
|
40
|
-
required: true,
|
|
41
|
-
},
|
|
42
|
-
created_at: {
|
|
43
|
-
type: "date",
|
|
44
|
-
default: "{{ now }}",
|
|
45
|
-
},
|
|
46
|
-
},
|
|
47
|
-
},
|
|
48
|
-
},
|
|
49
|
-
};
|
|
@@ -1,105 +0,0 @@
|
|
|
1
|
-
import { Lobb } from "@lobb-js/core";
|
|
2
|
-
import { afterAll, beforeAll, describe, expect, it } from "bun:test";
|
|
3
|
-
import { faker } from "@faker-js/faker";
|
|
4
|
-
import { simpleConfig } from "./configs/simple.ts";
|
|
5
|
-
|
|
6
|
-
describe("Reports operations", () => {
|
|
7
|
-
let lobb: Lobb;
|
|
8
|
-
let baseUrl: string;
|
|
9
|
-
|
|
10
|
-
beforeAll(async () => {
|
|
11
|
-
lobb = await Lobb.init(simpleConfig);
|
|
12
|
-
baseUrl = `http://127.0.0.1:${lobb.webServer.port}`;
|
|
13
|
-
});
|
|
14
|
-
|
|
15
|
-
afterAll(async () => {
|
|
16
|
-
await lobb.close();
|
|
17
|
-
});
|
|
18
|
-
|
|
19
|
-
it("should execute the query of the Report successfully", async () => {
|
|
20
|
-
const response1 = await fetch(
|
|
21
|
-
`${baseUrl}/api/collections/reports_dashboards`,
|
|
22
|
-
{
|
|
23
|
-
method: "POST",
|
|
24
|
-
body: JSON.stringify({
|
|
25
|
-
data: {
|
|
26
|
-
name: "test report",
|
|
27
|
-
description: "test description",
|
|
28
|
-
},
|
|
29
|
-
}),
|
|
30
|
-
},
|
|
31
|
-
);
|
|
32
|
-
const result2 = await response1.json();
|
|
33
|
-
const reportId = result2.data.id;
|
|
34
|
-
|
|
35
|
-
// creating a chart
|
|
36
|
-
const response = await fetch(
|
|
37
|
-
`${baseUrl}/api/collections/reports_charts`,
|
|
38
|
-
{
|
|
39
|
-
method: "POST",
|
|
40
|
-
body: JSON.stringify({
|
|
41
|
-
data: {
|
|
42
|
-
report_id: reportId,
|
|
43
|
-
title: "test report",
|
|
44
|
-
description: "test description",
|
|
45
|
-
chart: `async function chart(query: QueryFn) {
|
|
46
|
-
const entries = await query("SELECT EXTRACT(MONTH FROM created_at) AS month, CAST(SUM(amount) AS DECIMAL) AS totalDonations FROM donations GROUP BY EXTRACT(MONTH FROM created_at) ORDER BY month ASC");
|
|
47
|
-
return {
|
|
48
|
-
type: 'table',
|
|
49
|
-
input: {
|
|
50
|
-
data: entries
|
|
51
|
-
}
|
|
52
|
-
};
|
|
53
|
-
}`,
|
|
54
|
-
},
|
|
55
|
-
}),
|
|
56
|
-
},
|
|
57
|
-
);
|
|
58
|
-
const result1 = await response.json();
|
|
59
|
-
const chartId = result1.data.id;
|
|
60
|
-
|
|
61
|
-
// create donations
|
|
62
|
-
faker.seed(1);
|
|
63
|
-
const donations = Array.from({ length: 50 }, () => ({
|
|
64
|
-
donor_name: faker.person.fullName(),
|
|
65
|
-
amount: faker.finance.amount({
|
|
66
|
-
min: 10,
|
|
67
|
-
max: 1000,
|
|
68
|
-
}),
|
|
69
|
-
created_at: faker.date.between({
|
|
70
|
-
from: "2023-01-01",
|
|
71
|
-
to: "2023-12-31",
|
|
72
|
-
}).toISOString(),
|
|
73
|
-
}));
|
|
74
|
-
await lobb.collectionService.createMany({
|
|
75
|
-
collectionName: "donations",
|
|
76
|
-
data: donations,
|
|
77
|
-
});
|
|
78
|
-
|
|
79
|
-
// execute the query and get the results
|
|
80
|
-
const response2 = await fetch(
|
|
81
|
-
`${baseUrl}/api/collections/reports_charts/${chartId}?action=run_query`,
|
|
82
|
-
);
|
|
83
|
-
const result = await response2.json();
|
|
84
|
-
|
|
85
|
-
expect(result).toEqual({
|
|
86
|
-
type: "table",
|
|
87
|
-
input: {
|
|
88
|
-
data: [
|
|
89
|
-
{ month: "1", totaldonations: "755.23" },
|
|
90
|
-
{ month: "2", totaldonations: "1629.79" },
|
|
91
|
-
{ month: "3", totaldonations: "3286.90" },
|
|
92
|
-
{ month: "4", totaldonations: "2506.34" },
|
|
93
|
-
{ month: "5", totaldonations: "471.05" },
|
|
94
|
-
{ month: "6", totaldonations: "396.11" },
|
|
95
|
-
{ month: "7", totaldonations: "3451.62" },
|
|
96
|
-
{ month: "8", totaldonations: "3245.77" },
|
|
97
|
-
{ month: "9", totaldonations: "1641.96" },
|
|
98
|
-
{ month: "10", totaldonations: "703.91" },
|
|
99
|
-
{ month: "11", totaldonations: "4452.67" },
|
|
100
|
-
{ month: "12", totaldonations: "2028.52" },
|
|
101
|
-
],
|
|
102
|
-
},
|
|
103
|
-
});
|
|
104
|
-
});
|
|
105
|
-
});
|