@lensjs/core 1.0.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/README.md +1 -0
- package/copy-front-build.cjs +16 -0
- package/package.json +40 -0
- package/src/abstracts/adapter.ts +41 -0
- package/src/abstracts/store.ts +36 -0
- package/src/context/container.ts +67 -0
- package/src/context/context.ts +9 -0
- package/src/core/api_controller.ts +116 -0
- package/src/core/lens.ts +147 -0
- package/src/core/watcher.ts +6 -0
- package/src/index.ts +11 -0
- package/src/stores/better_sqlite.ts +176 -0
- package/src/stores/index.ts +1 -0
- package/src/types/index.ts +103 -0
- package/src/ui/README.md +69 -0
- package/src/ui/bun.lock +750 -0
- package/src/ui/eslint.config.js +27 -0
- package/src/ui/index.html +13 -0
- package/src/ui/package-lock.json +2953 -0
- package/src/ui/package.json +40 -0
- package/src/ui/public/favicon.ico +0 -0
- package/src/ui/src/App.tsx +40 -0
- package/src/ui/src/components/DetailPanel.tsx +70 -0
- package/src/ui/src/components/JsonViewer.tsx +232 -0
- package/src/ui/src/components/LoadMore.tsx +25 -0
- package/src/ui/src/components/MethodBadge.tsx +19 -0
- package/src/ui/src/components/Modal.tsx +48 -0
- package/src/ui/src/components/StatusCode.tsx +20 -0
- package/src/ui/src/components/Table.tsx +127 -0
- package/src/ui/src/components/layout/DeleteButton.tsx +60 -0
- package/src/ui/src/components/layout/Footer.tsx +12 -0
- package/src/ui/src/components/layout/Header.tsx +40 -0
- package/src/ui/src/components/layout/Layout.tsx +49 -0
- package/src/ui/src/components/layout/LoadingScreen.tsx +14 -0
- package/src/ui/src/components/layout/Sidebar.tsx +67 -0
- package/src/ui/src/components/queryFormatters/MongoViewer.tsx +92 -0
- package/src/ui/src/components/queryFormatters/QueryViewer.tsx +18 -0
- package/src/ui/src/components/queryFormatters/SqlViewer.tsx +105 -0
- package/src/ui/src/components/table/NoData.tsx +26 -0
- package/src/ui/src/components/tabs/TabbedDataViewer.tsx +77 -0
- package/src/ui/src/containers/queries/QueriesContainer.tsx +21 -0
- package/src/ui/src/containers/queries/QueryDetailsContainer.tsx +15 -0
- package/src/ui/src/containers/requests/RequestDetailsContainer.tsx +16 -0
- package/src/ui/src/containers/requests/RequestsContainer.tsx +22 -0
- package/src/ui/src/hooks/useLensApi.ts +92 -0
- package/src/ui/src/hooks/useLoadMore.ts +48 -0
- package/src/ui/src/hooks/useQueries.ts +58 -0
- package/src/ui/src/hooks/useRequests.ts +79 -0
- package/src/ui/src/hooks/useTanstackApi.ts +126 -0
- package/src/ui/src/index.css +78 -0
- package/src/ui/src/interfaces/index.ts +10 -0
- package/src/ui/src/main.tsx +33 -0
- package/src/ui/src/router/Router.ts +11 -0
- package/src/ui/src/router/routes/Loading.tsx +5 -0
- package/src/ui/src/router/routes/index.tsx +85 -0
- package/src/ui/src/types/index.ts +95 -0
- package/src/ui/src/utils/api.ts +7 -0
- package/src/ui/src/utils/context.ts +24 -0
- package/src/ui/src/utils/date.ts +36 -0
- package/src/ui/src/views/queries/QueryDetails.tsx +58 -0
- package/src/ui/src/views/queries/QueryTable.tsx +21 -0
- package/src/ui/src/views/queries/columns.tsx +83 -0
- package/src/ui/src/views/requests/BasicRequestDetails.tsx +82 -0
- package/src/ui/src/views/requests/RequestDetails.tsx +70 -0
- package/src/ui/src/views/requests/RequetsTable.tsx +19 -0
- package/src/ui/src/views/requests/columns.tsx +62 -0
- package/src/ui/src/vite-env.d.ts +1 -0
- package/src/ui/tsconfig.app.json +27 -0
- package/src/ui/tsconfig.json +7 -0
- package/src/ui/tsconfig.node.json +25 -0
- package/src/ui/vite.config.ts +9 -0
- package/src/utils/event_emitter.ts +13 -0
- package/src/utils/index.ts +176 -0
- package/src/watchers/index.ts +2 -0
- package/src/watchers/query_watcher.ts +15 -0
- package/src/watchers/request_watcher.ts +27 -0
- package/tests/core/lens.test.ts +89 -0
- package/tests/stores/better_sqlite.test.ts +168 -0
- package/tests/utils/index.test.ts +182 -0
- package/tests/watchers/query_watcher.test.ts +35 -0
- package/tests/watchers/request_watcher.test.ts +59 -0
- package/tsconfig.json +3 -0
- package/tsup.config.ts +15 -0
- package/vitest.config.ts +9 -0
|
@@ -0,0 +1,103 @@
|
|
|
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
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
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
|
+
```
|