@lensjs/core 1.0.1 → 1.0.2
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/abstracts/adapter.cjs +8 -0
- package/dist/abstracts/adapter.d.cts +19 -0
- package/dist/abstracts/adapter.d.ts +19 -0
- package/dist/abstracts/adapter.js +8 -0
- package/dist/abstracts/store.cjs +7 -0
- package/dist/abstracts/store.d.cts +23 -0
- package/dist/abstracts/store.d.ts +23 -0
- package/dist/abstracts/store.js +7 -0
- package/dist/chunk-2HRVJRKV.cjs +10 -0
- package/dist/chunk-3R5QARPT.cjs +14 -0
- package/{src/watchers/request_watcher.ts → dist/chunk-4HLDYZJA.js} +18 -11
- package/dist/chunk-5PYQWLAZ.js +129 -0
- package/dist/chunk-75ZPJI57.cjs +9 -0
- package/dist/chunk-7EKM5HB5.cjs +1 -0
- package/dist/chunk-AUDSBNLF.cjs +122 -0
- package/dist/chunk-BFFOUTTE.cjs +32 -0
- package/dist/chunk-BL4Z6JFH.cjs +34 -0
- package/dist/chunk-CQ2Z4TCR.js +7 -0
- package/dist/chunk-EHOWCXZV.cjs +7 -0
- package/{src/utils/index.ts → dist/chunk-EJ5BW35V.js} +69 -86
- package/dist/chunk-EKG3FVLV.cjs +7 -0
- package/dist/chunk-FCMQ3WE3.cjs +129 -0
- package/dist/chunk-FKMBNWX4.js +7 -0
- package/dist/chunk-FLOVBBFU.js +10 -0
- package/dist/chunk-GI7SJDNQ.cjs +38 -0
- package/dist/chunk-IPMTMCFP.js +122 -0
- package/dist/chunk-JZ2JLQXL.cjs +87 -0
- package/dist/chunk-MLKGABMK.js +9 -0
- package/dist/chunk-QRZUNYF6.cjs +16 -0
- package/dist/chunk-RMZ4UAQ2.js +14 -0
- package/dist/chunk-SJXZARBJ.cjs +22 -0
- package/dist/chunk-TJDE6AZM.js +87 -0
- package/dist/chunk-TPUVRGYT.js +32 -0
- package/dist/chunk-UF5HFNMI.js +22 -0
- package/dist/chunk-VD5IMUWL.js +0 -0
- package/dist/chunk-WU6IZUEV.cjs +159 -0
- package/dist/chunk-XXYRWHSQ.js +0 -0
- package/dist/chunk-XYXPHWEI.js +16 -0
- package/dist/chunk-XZFXXD3A.cjs +1 -0
- package/dist/chunk-YC6T4XWI.js +38 -0
- package/dist/context/container.cjs +7 -0
- package/dist/context/container.d.cts +28 -0
- package/dist/context/container.d.ts +28 -0
- package/dist/context/container.js +7 -0
- package/dist/context/context.cjs +10 -0
- package/dist/context/context.d.cts +15 -0
- package/dist/context/context.d.ts +15 -0
- package/dist/context/context.js +10 -0
- package/dist/core/api_controller.cjs +10 -0
- package/dist/core/api_controller.d.cts +25 -0
- package/dist/core/api_controller.d.ts +25 -0
- package/dist/core/api_controller.js +10 -0
- package/dist/core/lens.cjs +15 -0
- package/dist/core/lens.d.cts +24 -0
- package/dist/core/lens.d.ts +24 -0
- package/dist/core/lens.js +15 -0
- package/dist/core/watcher.cjs +7 -0
- package/dist/core/watcher.d.cts +9 -0
- package/dist/core/watcher.d.ts +9 -0
- package/dist/core/watcher.js +7 -0
- package/dist/index-D0Vszdac.d.cts +49 -0
- package/dist/index-D0Vszdac.d.ts +49 -0
- package/dist/index.cjs +55 -0
- package/dist/index.d.cts +16 -0
- package/dist/index.d.ts +16 -0
- package/dist/index.js +55 -0
- package/dist/stores/better_sqlite.cjs +10 -0
- package/dist/stores/better_sqlite.d.cts +51 -0
- package/dist/stores/better_sqlite.d.ts +51 -0
- package/dist/stores/better_sqlite.js +10 -0
- package/dist/stores/index.cjs +11 -0
- package/dist/stores/index.d.cts +5 -0
- package/dist/stores/index.d.ts +5 -0
- package/dist/stores/index.js +11 -0
- package/dist/types/index.cjs +7 -0
- package/dist/types/index.d.cts +91 -0
- package/dist/types/index.d.ts +91 -0
- package/dist/types/index.js +7 -0
- package/dist/ui/assets/QueriesContainer-Bxr99HkT.js +2 -0
- package/dist/ui/assets/QueryDetailsContainer-BcbxQyxT.js +48 -0
- package/dist/ui/assets/QueryTable-Dx1MyXwe.js +1 -0
- package/dist/ui/assets/RequestDetails-B9rQn1tY.js +1 -0
- package/dist/ui/assets/RequestDetailsContainer-C0sOvaO2.js +2 -0
- package/dist/ui/assets/RequestsContainer-DYNNLt6S.js +2 -0
- package/dist/ui/assets/RequetsTable-BN-1fud-.js +1 -0
- package/dist/ui/assets/StatusCode-ByIHR7Pe.js +1 -0
- package/dist/ui/assets/TabbedDataViewer-CoLeLuBm.js +1 -0
- package/dist/ui/assets/Table-CXg4Wfwf.js +6 -0
- package/dist/ui/assets/date-BXZFS9Wq.js +1 -0
- package/dist/ui/assets/index-BPTSPdZM.css +1 -0
- package/dist/ui/assets/index-C3XpMOuU.js +114 -0
- package/dist/ui/assets/useLensApi-BlL4RwJa.js +1 -0
- package/dist/ui/assets/useLoadMore-BqF649Mm.js +1 -0
- package/dist/ui/assets/useQueries-Iwl8o-Xk.js +1 -0
- package/dist/ui/favicon.ico +0 -0
- package/dist/ui/index.html +14 -0
- package/dist/utils/event_emitter.cjs +11 -0
- package/dist/utils/event_emitter.d.cts +16 -0
- package/dist/utils/event_emitter.d.ts +16 -0
- package/dist/utils/event_emitter.js +11 -0
- package/dist/utils/index.cjs +31 -0
- package/dist/utils/index.d.cts +3 -0
- package/dist/utils/index.d.ts +3 -0
- package/dist/utils/index.js +31 -0
- package/dist/watchers/index.cjs +16 -0
- package/dist/watchers/index.d.cts +5 -0
- package/dist/watchers/index.d.ts +5 -0
- package/dist/watchers/index.js +16 -0
- package/dist/watchers/query_watcher.cjs +11 -0
- package/dist/watchers/query_watcher.d.cts +10 -0
- package/dist/watchers/query_watcher.d.ts +10 -0
- package/dist/watchers/query_watcher.js +11 -0
- package/dist/watchers/request_watcher.cjs +11 -0
- package/dist/watchers/request_watcher.d.cts +10 -0
- package/dist/watchers/request_watcher.d.ts +10 -0
- package/dist/watchers/request_watcher.js +11 -0
- package/package.json +4 -1
- package/copy-front-build.cjs +0 -16
- package/src/abstracts/adapter.ts +0 -41
- package/src/abstracts/store.ts +0 -36
- package/src/context/container.ts +0 -67
- package/src/context/context.ts +0 -9
- package/src/core/api_controller.ts +0 -116
- package/src/core/lens.ts +0 -147
- package/src/core/watcher.ts +0 -6
- package/src/index.ts +0 -11
- package/src/stores/better_sqlite.ts +0 -176
- package/src/stores/index.ts +0 -1
- package/src/types/index.ts +0 -103
- package/src/ui/README.md +0 -69
- package/src/ui/bun.lock +0 -750
- package/src/ui/eslint.config.js +0 -27
- package/src/ui/index.html +0 -13
- package/src/ui/package-lock.json +0 -2953
- package/src/ui/package.json +0 -40
- package/src/ui/src/App.tsx +0 -40
- package/src/ui/src/components/DetailPanel.tsx +0 -70
- package/src/ui/src/components/JsonViewer.tsx +0 -232
- package/src/ui/src/components/LoadMore.tsx +0 -25
- package/src/ui/src/components/MethodBadge.tsx +0 -19
- package/src/ui/src/components/Modal.tsx +0 -48
- package/src/ui/src/components/StatusCode.tsx +0 -20
- package/src/ui/src/components/Table.tsx +0 -127
- package/src/ui/src/components/layout/DeleteButton.tsx +0 -60
- package/src/ui/src/components/layout/Footer.tsx +0 -12
- package/src/ui/src/components/layout/Header.tsx +0 -40
- package/src/ui/src/components/layout/Layout.tsx +0 -49
- package/src/ui/src/components/layout/LoadingScreen.tsx +0 -14
- package/src/ui/src/components/layout/Sidebar.tsx +0 -67
- package/src/ui/src/components/queryFormatters/MongoViewer.tsx +0 -92
- package/src/ui/src/components/queryFormatters/QueryViewer.tsx +0 -18
- package/src/ui/src/components/queryFormatters/SqlViewer.tsx +0 -105
- package/src/ui/src/components/table/NoData.tsx +0 -26
- package/src/ui/src/components/tabs/TabbedDataViewer.tsx +0 -77
- package/src/ui/src/containers/queries/QueriesContainer.tsx +0 -21
- package/src/ui/src/containers/queries/QueryDetailsContainer.tsx +0 -15
- package/src/ui/src/containers/requests/RequestDetailsContainer.tsx +0 -16
- package/src/ui/src/containers/requests/RequestsContainer.tsx +0 -22
- package/src/ui/src/hooks/useLensApi.ts +0 -92
- package/src/ui/src/hooks/useLoadMore.ts +0 -48
- package/src/ui/src/hooks/useQueries.ts +0 -58
- package/src/ui/src/hooks/useRequests.ts +0 -79
- package/src/ui/src/hooks/useTanstackApi.ts +0 -126
- package/src/ui/src/index.css +0 -78
- package/src/ui/src/interfaces/index.ts +0 -10
- package/src/ui/src/main.tsx +0 -33
- package/src/ui/src/router/Router.ts +0 -11
- package/src/ui/src/router/routes/Loading.tsx +0 -5
- package/src/ui/src/router/routes/index.tsx +0 -85
- package/src/ui/src/types/index.ts +0 -95
- package/src/ui/src/utils/api.ts +0 -7
- package/src/ui/src/utils/context.ts +0 -24
- package/src/ui/src/utils/date.ts +0 -36
- package/src/ui/src/views/queries/QueryDetails.tsx +0 -58
- package/src/ui/src/views/queries/QueryTable.tsx +0 -21
- package/src/ui/src/views/queries/columns.tsx +0 -83
- package/src/ui/src/views/requests/BasicRequestDetails.tsx +0 -82
- package/src/ui/src/views/requests/RequestDetails.tsx +0 -70
- package/src/ui/src/views/requests/RequetsTable.tsx +0 -19
- package/src/ui/src/views/requests/columns.tsx +0 -62
- package/src/ui/src/vite-env.d.ts +0 -1
- package/src/ui/tsconfig.app.json +0 -27
- package/src/ui/tsconfig.json +0 -7
- package/src/ui/tsconfig.node.json +0 -25
- package/src/ui/vite.config.ts +0 -9
- package/src/utils/event_emitter.ts +0 -13
- package/src/watchers/index.ts +0 -2
- package/src/watchers/query_watcher.ts +0 -15
- package/tests/core/lens.test.ts +0 -89
- package/tests/stores/better_sqlite.test.ts +0 -168
- package/tests/utils/index.test.ts +0 -182
- package/tests/watchers/query_watcher.test.ts +0 -35
- package/tests/watchers/request_watcher.test.ts +0 -59
- package/tsconfig.json +0 -3
- package/tsup.config.ts +0 -15
- package/vitest.config.ts +0 -9
- /package/{src/ui/public/favicon.ico → dist/ui/assets/favicon-D0UnoCWN.ico} +0 -0
package/src/core/lens.ts
DELETED
|
@@ -1,147 +0,0 @@
|
|
|
1
|
-
import type Store from "../abstracts/store";
|
|
2
|
-
import type Adapter from "../abstracts/adapter";
|
|
3
|
-
import Watcher from "./watcher";
|
|
4
|
-
import { ApiController } from "./api_controller";
|
|
5
|
-
import * as path from "node:path";
|
|
6
|
-
import type {
|
|
7
|
-
LensConfig,
|
|
8
|
-
RouteDefinitionHandler,
|
|
9
|
-
WatcherTypeEnum,
|
|
10
|
-
} from "../types/index.ts";
|
|
11
|
-
import { getUiConfig } from "../context/context";
|
|
12
|
-
import Container from "../context/container";
|
|
13
|
-
import { BetterSqliteStore } from "../stores/index";
|
|
14
|
-
import { getMeta } from "../utils/index";
|
|
15
|
-
|
|
16
|
-
export default class Lens {
|
|
17
|
-
private static watchers: Map<WatcherTypeEnum, Watcher> = new Map();
|
|
18
|
-
private static store: Store;
|
|
19
|
-
private static adapter: Adapter;
|
|
20
|
-
|
|
21
|
-
static watch(watcher: Watcher): typeof Lens {
|
|
22
|
-
this.watchers.set(watcher.name, watcher);
|
|
23
|
-
return this;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
static setWatchers(watchers: Watcher[]): typeof Lens {
|
|
27
|
-
this.watchers = new Map(watchers.map((watcher) => [watcher.name, watcher]));
|
|
28
|
-
return this;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
static async start(
|
|
32
|
-
config: LensConfig = {
|
|
33
|
-
basePath: "lens",
|
|
34
|
-
appName: "Lens",
|
|
35
|
-
enabled: true,
|
|
36
|
-
},
|
|
37
|
-
) {
|
|
38
|
-
if (!config.enabled) {
|
|
39
|
-
return;
|
|
40
|
-
}
|
|
41
|
-
await this.bindContainerDeps(config);
|
|
42
|
-
|
|
43
|
-
let adapter = this.getAdapter();
|
|
44
|
-
|
|
45
|
-
adapter.setWatchers(Array.from(this.watchers.values())).setup();
|
|
46
|
-
|
|
47
|
-
const { apiRoutes } = this.getRoutes({
|
|
48
|
-
basePath: config.basePath,
|
|
49
|
-
});
|
|
50
|
-
|
|
51
|
-
adapter.registerRoutes(apiRoutes);
|
|
52
|
-
|
|
53
|
-
const { __dirname } = getMeta(import.meta.url);
|
|
54
|
-
const uiPath = path.resolve(this.normalizeDirName(__dirname), "ui");
|
|
55
|
-
adapter.serveUI(uiPath, config.basePath, getUiConfig());
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
static setStore(store: Store): typeof Lens {
|
|
59
|
-
this.store = store;
|
|
60
|
-
return this;
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
static async getStore(): Promise<Store> {
|
|
64
|
-
return this.store ?? (await this.getDefaultStore());
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
static setAdapter(adapter: Adapter): typeof Lens {
|
|
68
|
-
this.adapter = adapter;
|
|
69
|
-
return this;
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
static getAdapter(): Adapter {
|
|
73
|
-
if (!this.adapter) {
|
|
74
|
-
throw new Error("No adapter has been set");
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
return this.adapter;
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
private static async bindContainerDeps(config: LensConfig) {
|
|
81
|
-
const dbStore = await this.getStore();
|
|
82
|
-
Container.singleton("store", () => dbStore);
|
|
83
|
-
Container.singleton("uiConfig", () => {
|
|
84
|
-
return {
|
|
85
|
-
appName: config.appName,
|
|
86
|
-
path: `/${config.basePath}`,
|
|
87
|
-
api: {
|
|
88
|
-
requests: `/${config.basePath}/api/requests`,
|
|
89
|
-
queries: `/${config.basePath}/api/queries`,
|
|
90
|
-
truncate: `/${config.basePath}/api/truncate`,
|
|
91
|
-
},
|
|
92
|
-
};
|
|
93
|
-
});
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
private static getRoutes({ basePath }: { basePath: string }) {
|
|
97
|
-
const apiRoutes = [
|
|
98
|
-
{
|
|
99
|
-
method: "GET" as const,
|
|
100
|
-
path: `/lens-config`,
|
|
101
|
-
handler: () => ApiController.fetchUiConfig(),
|
|
102
|
-
},
|
|
103
|
-
{
|
|
104
|
-
method: "GET" as const,
|
|
105
|
-
path: `${basePath}/api/requests`,
|
|
106
|
-
handler: async (data: RouteDefinitionHandler) =>
|
|
107
|
-
await ApiController.getRequests(data),
|
|
108
|
-
},
|
|
109
|
-
{
|
|
110
|
-
method: "GET" as const,
|
|
111
|
-
path: `${basePath}/api/requests/:id`,
|
|
112
|
-
handler: async (data: RouteDefinitionHandler) =>
|
|
113
|
-
await ApiController.getRequest(data),
|
|
114
|
-
},
|
|
115
|
-
{
|
|
116
|
-
method: "GET" as const,
|
|
117
|
-
path: `${basePath}/api/queries`,
|
|
118
|
-
handler: async (data: RouteDefinitionHandler) =>
|
|
119
|
-
await ApiController.getQueries(data),
|
|
120
|
-
},
|
|
121
|
-
{
|
|
122
|
-
method: "GET" as const,
|
|
123
|
-
path: `${basePath}/api/queries/:id`,
|
|
124
|
-
handler: async (data: RouteDefinitionHandler) =>
|
|
125
|
-
await ApiController.getQuery(data),
|
|
126
|
-
},
|
|
127
|
-
{
|
|
128
|
-
method: "DELETE" as const,
|
|
129
|
-
path: `${basePath}/api/truncate`,
|
|
130
|
-
handler: async () => await ApiController.truncate(),
|
|
131
|
-
},
|
|
132
|
-
];
|
|
133
|
-
|
|
134
|
-
return { apiRoutes };
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
private static async getDefaultStore(): Promise<Store> {
|
|
138
|
-
const store = new BetterSqliteStore();
|
|
139
|
-
await store.initialize();
|
|
140
|
-
|
|
141
|
-
return store;
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
private static normalizeDirName(path: string) {
|
|
145
|
-
return path.replace(/(\/packages\/)[^/]+(?=\/dist)/, "$1core");
|
|
146
|
-
}
|
|
147
|
-
}
|
package/src/core/watcher.ts
DELETED
package/src/index.ts
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
export { default as Lens } from "./core/lens";
|
|
2
|
-
|
|
3
|
-
export * from "./stores";
|
|
4
|
-
export * from "./watchers";
|
|
5
|
-
export * from "./types/index";
|
|
6
|
-
export { default as LensAdapter } from "./abstracts/adapter";
|
|
7
|
-
export { default as LensStore } from "./abstracts/store";
|
|
8
|
-
export { default as LensWatcher } from "./core/watcher";
|
|
9
|
-
export { getStore as getLensStore } from "./context/context";
|
|
10
|
-
export * as lensUtils from "./utils/index";
|
|
11
|
-
export { lensEmitter, lensResource, createEmittery} from "./utils/event_emitter";
|
|
@@ -1,176 +0,0 @@
|
|
|
1
|
-
import Store from "../abstracts/store";
|
|
2
|
-
import { randomUUID } from "crypto";
|
|
3
|
-
import {
|
|
4
|
-
WatcherTypeEnum,
|
|
5
|
-
type PaginationParams,
|
|
6
|
-
type LensEntry,
|
|
7
|
-
} from "../types/index";
|
|
8
|
-
import Database from "libsql";
|
|
9
|
-
import { sqlDateTime } from "../utils";
|
|
10
|
-
|
|
11
|
-
const TABLE_NAME = "lens_entries";
|
|
12
|
-
|
|
13
|
-
export default class BetterSqliteStore extends Store {
|
|
14
|
-
protected connection!: Database.Database;
|
|
15
|
-
|
|
16
|
-
public async initialize() {
|
|
17
|
-
this.connection = new Database("lens.db");
|
|
18
|
-
|
|
19
|
-
this.setupSchema();
|
|
20
|
-
console.log("Connected to Lens (SQLite) database.");
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
public async truncate() {
|
|
24
|
-
this.connection.prepare(`DELETE FROM ${TABLE_NAME};`).run();
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
public async save(entry: {
|
|
28
|
-
id?: string;
|
|
29
|
-
data: Record<string, any>;
|
|
30
|
-
minimal_data?: Record<string, any>;
|
|
31
|
-
type: WatcherTypeEnum;
|
|
32
|
-
timestamp?: string;
|
|
33
|
-
requestId?: string;
|
|
34
|
-
}) {
|
|
35
|
-
this.connection
|
|
36
|
-
.prepare(
|
|
37
|
-
`INSERT INTO ${TABLE_NAME} (id, data, type, created_at, lens_entry_id, minimal_data) values($id, $data, $type, $created_at, $lens_entry_id, $minimalData)`
|
|
38
|
-
)
|
|
39
|
-
.run({
|
|
40
|
-
id: entry.id ?? randomUUID(),
|
|
41
|
-
data: JSON.stringify(entry.data),
|
|
42
|
-
type: entry.type,
|
|
43
|
-
created_at: entry.timestamp ?? sqlDateTime(),
|
|
44
|
-
lens_entry_id: entry.requestId || null,
|
|
45
|
-
minimalData: JSON.stringify(entry.minimal_data ?? {}),
|
|
46
|
-
});
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
override async getAllQueries<T extends LensEntry[]>(
|
|
50
|
-
pagination: PaginationParams
|
|
51
|
-
) {
|
|
52
|
-
return await this.paginate<T>(WatcherTypeEnum.QUERY, pagination);
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
override async getAllRequests<T extends Omit<LensEntry, "data">[]>(
|
|
56
|
-
pagination: PaginationParams
|
|
57
|
-
) {
|
|
58
|
-
return await this.paginate<T>(WatcherTypeEnum.REQUEST, pagination, false);
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
public async allByRequestId(requestId: string, type: WatcherTypeEnum) {
|
|
62
|
-
const rows = this.connection
|
|
63
|
-
.prepare(
|
|
64
|
-
`${this.getSelectedColumns()} FROM ${TABLE_NAME} WHERE type = $type AND lens_entry_id = $requestId ORDER BY created_at DESC`
|
|
65
|
-
)
|
|
66
|
-
.all({ type, requestId });
|
|
67
|
-
|
|
68
|
-
return this.mapRows(rows);
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
public async paginate<T>(
|
|
72
|
-
type: WatcherTypeEnum,
|
|
73
|
-
{ page, perPage }: PaginationParams,
|
|
74
|
-
includeFullData: boolean = true
|
|
75
|
-
): Promise<{
|
|
76
|
-
meta: {
|
|
77
|
-
total: number;
|
|
78
|
-
lastPage: number;
|
|
79
|
-
currentPage: number;
|
|
80
|
-
};
|
|
81
|
-
data: T;
|
|
82
|
-
}> {
|
|
83
|
-
const offset = (page - 1) * perPage;
|
|
84
|
-
const query = `${this.getSelectedColumns(
|
|
85
|
-
includeFullData
|
|
86
|
-
)} FROM ${TABLE_NAME} WHERE type = ? ORDER BY created_at DESC LIMIT ? OFFSET ?`;
|
|
87
|
-
const count = await this.count(type);
|
|
88
|
-
const rows = this.connection.prepare(query).all(type, perPage, offset);
|
|
89
|
-
const mappedRows = this.mapRows(rows, includeFullData);
|
|
90
|
-
|
|
91
|
-
return {
|
|
92
|
-
meta: {
|
|
93
|
-
total: count,
|
|
94
|
-
lastPage: Math.ceil(count / perPage),
|
|
95
|
-
currentPage: page,
|
|
96
|
-
},
|
|
97
|
-
data: mappedRows as T,
|
|
98
|
-
};
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
override async count(type: WatcherTypeEnum): Promise<number> {
|
|
102
|
-
const result = this.connection
|
|
103
|
-
.prepare(`SELECT count(*) as count FROM ${TABLE_NAME} WHERE type = ?`)
|
|
104
|
-
.get(type) as { count: number };
|
|
105
|
-
|
|
106
|
-
return Number(result.count);
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
public async find(type: WatcherTypeEnum, id: string) {
|
|
110
|
-
const row = this.connection
|
|
111
|
-
.prepare(
|
|
112
|
-
`${this.getSelectedColumns()} FROM ${TABLE_NAME} WHERE id = ? AND type = ? LIMIT 1`
|
|
113
|
-
)
|
|
114
|
-
.get(id, type);
|
|
115
|
-
|
|
116
|
-
if (!row) {
|
|
117
|
-
return null;
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
return this.mapRow(row, true);
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
private setupSchema() {
|
|
124
|
-
const createTable = `
|
|
125
|
-
CREATE TABLE IF NOT EXISTS ${TABLE_NAME} (
|
|
126
|
-
id TEXT PRIMARY KEY,
|
|
127
|
-
minimal_data TEXT,
|
|
128
|
-
data TEXT NOT NULL,
|
|
129
|
-
type TEXT NOT NULL,
|
|
130
|
-
created_at TEXT NOT NULL,
|
|
131
|
-
updated_at TEXT,
|
|
132
|
-
lens_entry_id TEXT NULL
|
|
133
|
-
);
|
|
134
|
-
`;
|
|
135
|
-
|
|
136
|
-
const createIndex = `
|
|
137
|
-
CREATE INDEX IF NOT EXISTS lens_entries_id_type_index
|
|
138
|
-
ON ${TABLE_NAME} (id, type);
|
|
139
|
-
`;
|
|
140
|
-
|
|
141
|
-
this.connection.exec(createTable);
|
|
142
|
-
this.connection.exec(createIndex);
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
protected mapRow(row: any, includeFullData = true): LensEntry {
|
|
146
|
-
let data = includeFullData ? JSON.parse(row.data) : {};
|
|
147
|
-
|
|
148
|
-
if (!includeFullData) {
|
|
149
|
-
data = JSON.parse(row.minimal_data);
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
return {
|
|
153
|
-
id: row.id,
|
|
154
|
-
type: row.type,
|
|
155
|
-
created_at: row.created_at,
|
|
156
|
-
lens_entry_id: row.lens_entry_id,
|
|
157
|
-
data: data,
|
|
158
|
-
};
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
protected mapRows(rows: any[], includeFullData = true) {
|
|
162
|
-
let mappedRows: LensEntry[] = [];
|
|
163
|
-
|
|
164
|
-
for (const row of rows) {
|
|
165
|
-
mappedRows.push(this.mapRow(row, includeFullData));
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
return mappedRows;
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
protected getSelectedColumns(includeFullData: boolean = true) {
|
|
172
|
-
return `SELECT id, minimal_data, type, created_at, lens_entry_id ${
|
|
173
|
-
includeFullData ? ",data" : ""
|
|
174
|
-
}`;
|
|
175
|
-
}
|
|
176
|
-
}
|
package/src/stores/index.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { default as BetterSqliteStore } from "./better_sqlite";
|
package/src/types/index.ts
DELETED
|
@@ -1,103 +0,0 @@
|
|
|
1
|
-
import { SqlLanguage } from "sql-formatter";
|
|
2
|
-
|
|
3
|
-
export type QueryType = Required<SqlLanguage | "mongodb">;
|
|
4
|
-
export type SqlQueryType = Exclude<QueryType, "mongodb">;
|
|
5
|
-
export type QueryEntry = {
|
|
6
|
-
data: {
|
|
7
|
-
query: string;
|
|
8
|
-
duration: string;
|
|
9
|
-
createdAt: string;
|
|
10
|
-
type: QueryType;
|
|
11
|
-
};
|
|
12
|
-
requestId?: string;
|
|
13
|
-
};
|
|
14
|
-
|
|
15
|
-
export type UserEntry = {
|
|
16
|
-
id: number | string;
|
|
17
|
-
name: string;
|
|
18
|
-
email: string;
|
|
19
|
-
};
|
|
20
|
-
|
|
21
|
-
export type RequestEntry = {
|
|
22
|
-
request: {
|
|
23
|
-
id: string;
|
|
24
|
-
method: HttpMethod;
|
|
25
|
-
duration: string;
|
|
26
|
-
path: string;
|
|
27
|
-
headers: Record<string, any>;
|
|
28
|
-
body: Record<string, any>;
|
|
29
|
-
status: number;
|
|
30
|
-
ip: string;
|
|
31
|
-
createdAt: string;
|
|
32
|
-
};
|
|
33
|
-
response: {
|
|
34
|
-
json: Record<string, any>;
|
|
35
|
-
headers: Record<string, string>;
|
|
36
|
-
};
|
|
37
|
-
user?: UserEntry | null;
|
|
38
|
-
};
|
|
39
|
-
|
|
40
|
-
export type Entry =
|
|
41
|
-
| { type: "query"; data: QueryEntry }
|
|
42
|
-
| { type: "request"; data: RequestEntry };
|
|
43
|
-
|
|
44
|
-
export enum WatcherTypeEnum {
|
|
45
|
-
REQUEST = "request",
|
|
46
|
-
QUERY = "query",
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
export type LensConfig = {
|
|
50
|
-
basePath: string;
|
|
51
|
-
appName: string;
|
|
52
|
-
enabled: boolean;
|
|
53
|
-
};
|
|
54
|
-
|
|
55
|
-
export type LensEntry = {
|
|
56
|
-
id: string;
|
|
57
|
-
minimal_data?: Record<string, any>;
|
|
58
|
-
data: Record<string, any>;
|
|
59
|
-
type: WatcherTypeEnum;
|
|
60
|
-
created_at: string;
|
|
61
|
-
lens_entry_id: string | null;
|
|
62
|
-
};
|
|
63
|
-
|
|
64
|
-
export type RouteDefinitionHandler = {
|
|
65
|
-
params: Record<string, any>;
|
|
66
|
-
qs?: Record<string, any>;
|
|
67
|
-
};
|
|
68
|
-
export type RouteDefinition = {
|
|
69
|
-
method: "GET" | "POST" | "DELETE";
|
|
70
|
-
path: string;
|
|
71
|
-
handler: (data: RouteDefinitionHandler) => any;
|
|
72
|
-
};
|
|
73
|
-
|
|
74
|
-
export type PaginationParams = {
|
|
75
|
-
page: number;
|
|
76
|
-
perPage: number;
|
|
77
|
-
};
|
|
78
|
-
|
|
79
|
-
export type Paginator<T> = {
|
|
80
|
-
meta: {
|
|
81
|
-
total: number;
|
|
82
|
-
lastPage: number;
|
|
83
|
-
currentPage: number;
|
|
84
|
-
};
|
|
85
|
-
data: T;
|
|
86
|
-
};
|
|
87
|
-
|
|
88
|
-
export type ApiResponse<T> = {
|
|
89
|
-
status: number;
|
|
90
|
-
message: string;
|
|
91
|
-
data: T | null;
|
|
92
|
-
meta?: Paginator<T>["meta"];
|
|
93
|
-
};
|
|
94
|
-
|
|
95
|
-
export type HttpMethod =
|
|
96
|
-
| "GET"
|
|
97
|
-
| "POST"
|
|
98
|
-
| "PUT"
|
|
99
|
-
| "DELETE"
|
|
100
|
-
| "PATCH"
|
|
101
|
-
| "HEAD"
|
|
102
|
-
| "OPTIONS";
|
|
103
|
-
export type RouteHttpMethod = "get" | "post" | "put" | "delete" | "patch";
|
package/src/ui/README.md
DELETED
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
# React + TypeScript + Vite
|
|
2
|
-
|
|
3
|
-
This template provides a minimal setup to get React working in Vite with HMR and some ESLint rules.
|
|
4
|
-
|
|
5
|
-
Currently, two official plugins are available:
|
|
6
|
-
|
|
7
|
-
- [@vitejs/plugin-react](https://github.com/vitejs/vite-plugin-react/blob/main/packages/plugin-react) uses [Babel](https://babeljs.io/) for Fast Refresh
|
|
8
|
-
- [@vitejs/plugin-react-swc](https://github.com/vitejs/vite-plugin-react/blob/main/packages/plugin-react-swc) uses [SWC](https://swc.rs/) for Fast Refresh
|
|
9
|
-
|
|
10
|
-
## Expanding the ESLint configuration
|
|
11
|
-
|
|
12
|
-
If you are developing a production application, we recommend updating the configuration to enable type-aware lint rules:
|
|
13
|
-
|
|
14
|
-
```js
|
|
15
|
-
export default tseslint.config([
|
|
16
|
-
globalIgnores(['dist']),
|
|
17
|
-
{
|
|
18
|
-
files: ['**/*.{ts,tsx}'],
|
|
19
|
-
extends: [
|
|
20
|
-
// Other configs...
|
|
21
|
-
|
|
22
|
-
// Remove tseslint.configs.recommended and replace with this
|
|
23
|
-
...tseslint.configs.recommendedTypeChecked,
|
|
24
|
-
// Alternatively, use this for stricter rules
|
|
25
|
-
...tseslint.configs.strictTypeChecked,
|
|
26
|
-
// Optionally, add this for stylistic rules
|
|
27
|
-
...tseslint.configs.stylisticTypeChecked,
|
|
28
|
-
|
|
29
|
-
// Other configs...
|
|
30
|
-
],
|
|
31
|
-
languageOptions: {
|
|
32
|
-
parserOptions: {
|
|
33
|
-
project: ['./tsconfig.node.json', './tsconfig.app.json'],
|
|
34
|
-
tsconfigRootDir: import.meta.dirname,
|
|
35
|
-
},
|
|
36
|
-
// other options...
|
|
37
|
-
},
|
|
38
|
-
},
|
|
39
|
-
])
|
|
40
|
-
```
|
|
41
|
-
|
|
42
|
-
You can also install [eslint-plugin-react-x](https://github.com/Rel1cx/eslint-react/tree/main/packages/plugins/eslint-plugin-react-x) and [eslint-plugin-react-dom](https://github.com/Rel1cx/eslint-react/tree/main/packages/plugins/eslint-plugin-react-dom) for React-specific lint rules:
|
|
43
|
-
|
|
44
|
-
```js
|
|
45
|
-
// eslint.config.js
|
|
46
|
-
import reactX from 'eslint-plugin-react-x'
|
|
47
|
-
import reactDom from 'eslint-plugin-react-dom'
|
|
48
|
-
|
|
49
|
-
export default tseslint.config([
|
|
50
|
-
globalIgnores(['dist']),
|
|
51
|
-
{
|
|
52
|
-
files: ['**/*.{ts,tsx}'],
|
|
53
|
-
extends: [
|
|
54
|
-
// Other configs...
|
|
55
|
-
// Enable lint rules for React
|
|
56
|
-
reactX.configs['recommended-typescript'],
|
|
57
|
-
// Enable lint rules for React DOM
|
|
58
|
-
reactDom.configs.recommended,
|
|
59
|
-
],
|
|
60
|
-
languageOptions: {
|
|
61
|
-
parserOptions: {
|
|
62
|
-
project: ['./tsconfig.node.json', './tsconfig.app.json'],
|
|
63
|
-
tsconfigRootDir: import.meta.dirname,
|
|
64
|
-
},
|
|
65
|
-
// other options...
|
|
66
|
-
},
|
|
67
|
-
},
|
|
68
|
-
])
|
|
69
|
-
```
|