@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.
Files changed (84) hide show
  1. package/README.md +1 -0
  2. package/copy-front-build.cjs +16 -0
  3. package/package.json +40 -0
  4. package/src/abstracts/adapter.ts +41 -0
  5. package/src/abstracts/store.ts +36 -0
  6. package/src/context/container.ts +67 -0
  7. package/src/context/context.ts +9 -0
  8. package/src/core/api_controller.ts +116 -0
  9. package/src/core/lens.ts +147 -0
  10. package/src/core/watcher.ts +6 -0
  11. package/src/index.ts +11 -0
  12. package/src/stores/better_sqlite.ts +176 -0
  13. package/src/stores/index.ts +1 -0
  14. package/src/types/index.ts +103 -0
  15. package/src/ui/README.md +69 -0
  16. package/src/ui/bun.lock +750 -0
  17. package/src/ui/eslint.config.js +27 -0
  18. package/src/ui/index.html +13 -0
  19. package/src/ui/package-lock.json +2953 -0
  20. package/src/ui/package.json +40 -0
  21. package/src/ui/public/favicon.ico +0 -0
  22. package/src/ui/src/App.tsx +40 -0
  23. package/src/ui/src/components/DetailPanel.tsx +70 -0
  24. package/src/ui/src/components/JsonViewer.tsx +232 -0
  25. package/src/ui/src/components/LoadMore.tsx +25 -0
  26. package/src/ui/src/components/MethodBadge.tsx +19 -0
  27. package/src/ui/src/components/Modal.tsx +48 -0
  28. package/src/ui/src/components/StatusCode.tsx +20 -0
  29. package/src/ui/src/components/Table.tsx +127 -0
  30. package/src/ui/src/components/layout/DeleteButton.tsx +60 -0
  31. package/src/ui/src/components/layout/Footer.tsx +12 -0
  32. package/src/ui/src/components/layout/Header.tsx +40 -0
  33. package/src/ui/src/components/layout/Layout.tsx +49 -0
  34. package/src/ui/src/components/layout/LoadingScreen.tsx +14 -0
  35. package/src/ui/src/components/layout/Sidebar.tsx +67 -0
  36. package/src/ui/src/components/queryFormatters/MongoViewer.tsx +92 -0
  37. package/src/ui/src/components/queryFormatters/QueryViewer.tsx +18 -0
  38. package/src/ui/src/components/queryFormatters/SqlViewer.tsx +105 -0
  39. package/src/ui/src/components/table/NoData.tsx +26 -0
  40. package/src/ui/src/components/tabs/TabbedDataViewer.tsx +77 -0
  41. package/src/ui/src/containers/queries/QueriesContainer.tsx +21 -0
  42. package/src/ui/src/containers/queries/QueryDetailsContainer.tsx +15 -0
  43. package/src/ui/src/containers/requests/RequestDetailsContainer.tsx +16 -0
  44. package/src/ui/src/containers/requests/RequestsContainer.tsx +22 -0
  45. package/src/ui/src/hooks/useLensApi.ts +92 -0
  46. package/src/ui/src/hooks/useLoadMore.ts +48 -0
  47. package/src/ui/src/hooks/useQueries.ts +58 -0
  48. package/src/ui/src/hooks/useRequests.ts +79 -0
  49. package/src/ui/src/hooks/useTanstackApi.ts +126 -0
  50. package/src/ui/src/index.css +78 -0
  51. package/src/ui/src/interfaces/index.ts +10 -0
  52. package/src/ui/src/main.tsx +33 -0
  53. package/src/ui/src/router/Router.ts +11 -0
  54. package/src/ui/src/router/routes/Loading.tsx +5 -0
  55. package/src/ui/src/router/routes/index.tsx +85 -0
  56. package/src/ui/src/types/index.ts +95 -0
  57. package/src/ui/src/utils/api.ts +7 -0
  58. package/src/ui/src/utils/context.ts +24 -0
  59. package/src/ui/src/utils/date.ts +36 -0
  60. package/src/ui/src/views/queries/QueryDetails.tsx +58 -0
  61. package/src/ui/src/views/queries/QueryTable.tsx +21 -0
  62. package/src/ui/src/views/queries/columns.tsx +83 -0
  63. package/src/ui/src/views/requests/BasicRequestDetails.tsx +82 -0
  64. package/src/ui/src/views/requests/RequestDetails.tsx +70 -0
  65. package/src/ui/src/views/requests/RequetsTable.tsx +19 -0
  66. package/src/ui/src/views/requests/columns.tsx +62 -0
  67. package/src/ui/src/vite-env.d.ts +1 -0
  68. package/src/ui/tsconfig.app.json +27 -0
  69. package/src/ui/tsconfig.json +7 -0
  70. package/src/ui/tsconfig.node.json +25 -0
  71. package/src/ui/vite.config.ts +9 -0
  72. package/src/utils/event_emitter.ts +13 -0
  73. package/src/utils/index.ts +176 -0
  74. package/src/watchers/index.ts +2 -0
  75. package/src/watchers/query_watcher.ts +15 -0
  76. package/src/watchers/request_watcher.ts +27 -0
  77. package/tests/core/lens.test.ts +89 -0
  78. package/tests/stores/better_sqlite.test.ts +168 -0
  79. package/tests/utils/index.test.ts +182 -0
  80. package/tests/watchers/query_watcher.test.ts +35 -0
  81. package/tests/watchers/request_watcher.test.ts +59 -0
  82. package/tsconfig.json +3 -0
  83. package/tsup.config.ts +15 -0
  84. 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";
@@ -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
+ ```