@lensjs/core 1.0.7 → 1.0.10

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 (100) hide show
  1. package/dist/abstracts/adapter.cjs +70 -5
  2. package/dist/abstracts/adapter.js +37 -5
  3. package/dist/abstracts/store.cjs +26 -6
  4. package/dist/abstracts/store.js +3 -4
  5. package/dist/context/container.cjs +57 -6
  6. package/dist/context/container.js +34 -4
  7. package/dist/context/context.cjs +71 -7
  8. package/dist/context/context.js +42 -6
  9. package/dist/core/api_controller.cjs +148 -7
  10. package/dist/core/api_controller.js +121 -7
  11. package/dist/core/lens.cjs +404 -12
  12. package/dist/core/lens.js +370 -12
  13. package/dist/core/watcher.cjs +26 -6
  14. package/dist/core/watcher.js +3 -4
  15. package/dist/{index-D0Vszdac.d.ts → index-DiLfwsvc.d.cts} +2 -11
  16. package/dist/{index-D0Vszdac.d.cts → index-DiLfwsvc.d.ts} +2 -11
  17. package/dist/index.cjs +611 -55
  18. package/dist/index.d.cts +2 -4
  19. package/dist/index.d.ts +2 -4
  20. package/dist/index.js +556 -42
  21. package/dist/stores/better_sqlite.cjs +149 -7
  22. package/dist/stores/better_sqlite.js +116 -7
  23. package/dist/stores/index.cjs +153 -8
  24. package/dist/stores/index.js +116 -8
  25. package/dist/types/index.cjs +33 -6
  26. package/dist/types/index.js +6 -4
  27. package/dist/ui/assets/QueriesContainer-CAAsjjW5.js +2 -0
  28. package/dist/ui/assets/{QueryDetailsContainer-BkaktbOw.js → QueryDetailsContainer-E7P-IO7f.js} +19 -19
  29. package/dist/ui/assets/QueryTable-BcrtUssT.js +1 -0
  30. package/dist/ui/assets/RequestDetails-C2DZBu5H.js +1 -0
  31. package/dist/ui/assets/RequestDetailsContainer-DuDo-IqS.js +2 -0
  32. package/dist/ui/assets/{RequestsContainer-zoWMoB7o.js → RequestsContainer-DK3hQVz9.js} +2 -2
  33. package/dist/ui/assets/RequetsTable-DgP8p60b.js +1 -0
  34. package/dist/ui/assets/{StatusCode-DH20lQ6a.js → StatusCode-FQEjz7gK.js} +1 -1
  35. package/dist/ui/assets/TabbedDataViewer-cBDdPwIz.js +1 -0
  36. package/dist/ui/assets/{Table-HwlddLhp.js → Table-DYaXk80S.js} +2 -2
  37. package/dist/ui/assets/index-BS8XxorB.js +114 -0
  38. package/dist/ui/assets/index-CpP2Ap5X.js +1 -0
  39. package/dist/ui/assets/index-DzNHqeKh.css +1 -0
  40. package/dist/ui/assets/{useLensApi-Bmk2bGb0.js → useLensApi-DG6atd6d.js} +1 -1
  41. package/dist/ui/assets/{useLoadMore-CvIajdjM.js → useLoadMore-CJltToLI.js} +1 -1
  42. package/dist/ui/assets/{useQueries-DuyhGJyf.js → useQueries-C8mDDDc6.js} +1 -1
  43. package/dist/ui/index.html +2 -2
  44. package/dist/utils/event_emitter.cjs +42 -10
  45. package/dist/utils/event_emitter.d.cts +1 -11
  46. package/dist/utils/event_emitter.d.ts +1 -11
  47. package/dist/utils/event_emitter.js +6 -9
  48. package/dist/utils/index.cjs +163 -31
  49. package/dist/utils/index.d.cts +1 -2
  50. package/dist/utils/index.d.ts +1 -2
  51. package/dist/utils/index.js +109 -20
  52. package/dist/watchers/index.cjs +105 -10
  53. package/dist/watchers/index.js +79 -12
  54. package/dist/watchers/query_watcher.cjs +78 -8
  55. package/dist/watchers/query_watcher.js +55 -8
  56. package/dist/watchers/request_watcher.cjs +90 -8
  57. package/dist/watchers/request_watcher.js +67 -8
  58. package/package.json +18 -18
  59. package/README.md +0 -1
  60. package/dist/chunk-2HRVJRKV.cjs +0 -10
  61. package/dist/chunk-3R5QARPT.cjs +0 -14
  62. package/dist/chunk-4HLDYZJA.js +0 -34
  63. package/dist/chunk-5PYQWLAZ.js +0 -129
  64. package/dist/chunk-75ZPJI57.cjs +0 -9
  65. package/dist/chunk-7EKM5HB5.cjs +0 -1
  66. package/dist/chunk-AUDSBNLF.cjs +0 -122
  67. package/dist/chunk-BFFOUTTE.cjs +0 -32
  68. package/dist/chunk-BL4Z6JFH.cjs +0 -34
  69. package/dist/chunk-CQ2Z4TCR.js +0 -7
  70. package/dist/chunk-EHOWCXZV.cjs +0 -7
  71. package/dist/chunk-EJ5BW35V.js +0 -159
  72. package/dist/chunk-EKG3FVLV.cjs +0 -7
  73. package/dist/chunk-FCMQ3WE3.cjs +0 -129
  74. package/dist/chunk-FKMBNWX4.js +0 -7
  75. package/dist/chunk-FLOVBBFU.js +0 -10
  76. package/dist/chunk-GI7SJDNQ.cjs +0 -38
  77. package/dist/chunk-IPMTMCFP.js +0 -122
  78. package/dist/chunk-JZ2JLQXL.cjs +0 -87
  79. package/dist/chunk-MLKGABMK.js +0 -9
  80. package/dist/chunk-QRZUNYF6.cjs +0 -16
  81. package/dist/chunk-RMZ4UAQ2.js +0 -14
  82. package/dist/chunk-SJXZARBJ.cjs +0 -22
  83. package/dist/chunk-TJDE6AZM.js +0 -87
  84. package/dist/chunk-TPUVRGYT.js +0 -32
  85. package/dist/chunk-UF5HFNMI.js +0 -22
  86. package/dist/chunk-VD5IMUWL.js +0 -0
  87. package/dist/chunk-WU6IZUEV.cjs +0 -159
  88. package/dist/chunk-XXYRWHSQ.js +0 -0
  89. package/dist/chunk-XYXPHWEI.js +0 -16
  90. package/dist/chunk-XZFXXD3A.cjs +0 -1
  91. package/dist/chunk-YC6T4XWI.js +0 -38
  92. package/dist/ui/assets/QueriesContainer-DHnHEGG1.js +0 -2
  93. package/dist/ui/assets/QueryTable-DegVNDkJ.js +0 -1
  94. package/dist/ui/assets/RequestDetails-zrL0n6gL.js +0 -1
  95. package/dist/ui/assets/RequestDetailsContainer-CsHWDxn7.js +0 -2
  96. package/dist/ui/assets/RequetsTable-1K9hhs0W.js +0 -1
  97. package/dist/ui/assets/TabbedDataViewer-DDVxzZiW.js +0 -1
  98. package/dist/ui/assets/date-CZdBf-JH.js +0 -1
  99. package/dist/ui/assets/index-C-9tn0L6.js +0 -114
  100. package/dist/ui/assets/index-DaNx3ROH.css +0 -1
@@ -1,129 +0,0 @@
1
- "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { newObj[key] = obj[key]; } } } newObj.default = obj; return newObj; } } async function _asyncNullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return await rhsFn(); } } var _class;
2
-
3
- var _chunkAUDSBNLFcjs = require('./chunk-AUDSBNLF.cjs');
4
-
5
-
6
- var _chunkWU6IZUEVcjs = require('./chunk-WU6IZUEV.cjs');
7
-
8
-
9
- var _chunkJZ2JLQXLcjs = require('./chunk-JZ2JLQXL.cjs');
10
-
11
-
12
- var _chunkQRZUNYF6cjs = require('./chunk-QRZUNYF6.cjs');
13
-
14
-
15
- var _chunkGI7SJDNQcjs = require('./chunk-GI7SJDNQ.cjs');
16
-
17
- // src/core/lens.ts
18
- var _path = require('path'); var path = _interopRequireWildcard(_path);
19
- var Lens = (_class = class {
20
- static __initStatic() {this.watchers = /* @__PURE__ */ new Map()}
21
-
22
-
23
- static watch(watcher) {
24
- this.watchers.set(watcher.name, watcher);
25
- return this;
26
- }
27
- static setWatchers(watchers) {
28
- this.watchers = new Map(watchers.map((watcher) => [watcher.name, watcher]));
29
- return this;
30
- }
31
- static async start(config = {
32
- basePath: "lens",
33
- appName: "Lens",
34
- enabled: true
35
- }) {
36
- if (!config.enabled) {
37
- return;
38
- }
39
- await this.bindContainerDeps(config);
40
- let adapter = this.getAdapter();
41
- adapter.setWatchers(Array.from(this.watchers.values())).setup();
42
- const { apiRoutes } = this.getRoutes({
43
- basePath: config.basePath
44
- });
45
- adapter.registerRoutes(apiRoutes);
46
- const { __dirname } = _chunkWU6IZUEVcjs.getMeta.call(void 0, import.meta.url);
47
- const uiPath = path.resolve(this.normalizeDirName(__dirname), "ui");
48
- adapter.serveUI(uiPath, config.basePath, _chunkQRZUNYF6cjs.getUiConfig.call(void 0, ));
49
- }
50
- static setStore(store) {
51
- this.store = store;
52
- return this;
53
- }
54
- static async getStore() {
55
- return await _asyncNullishCoalesce(this.store, async () => ( await this.getDefaultStore()));
56
- }
57
- static setAdapter(adapter) {
58
- this.adapter = adapter;
59
- return this;
60
- }
61
- static getAdapter() {
62
- if (!this.adapter) {
63
- throw new Error("No adapter has been set");
64
- }
65
- return this.adapter;
66
- }
67
- static async bindContainerDeps(config) {
68
- const dbStore = await this.getStore();
69
- _chunkGI7SJDNQcjs.Container.singleton("store", () => dbStore);
70
- _chunkGI7SJDNQcjs.Container.singleton("uiConfig", () => {
71
- return {
72
- appName: config.appName,
73
- path: `/${config.basePath}`,
74
- api: {
75
- requests: `/${config.basePath}/api/requests`,
76
- queries: `/${config.basePath}/api/queries`,
77
- truncate: `/${config.basePath}/api/truncate`
78
- }
79
- };
80
- });
81
- }
82
- static getRoutes({ basePath }) {
83
- const apiRoutes = [
84
- {
85
- method: "GET",
86
- path: `/lens-config`,
87
- handler: () => _chunkJZ2JLQXLcjs.ApiController.fetchUiConfig()
88
- },
89
- {
90
- method: "GET",
91
- path: `${basePath}/api/requests`,
92
- handler: async (data) => await _chunkJZ2JLQXLcjs.ApiController.getRequests(data)
93
- },
94
- {
95
- method: "GET",
96
- path: `${basePath}/api/requests/:id`,
97
- handler: async (data) => await _chunkJZ2JLQXLcjs.ApiController.getRequest(data)
98
- },
99
- {
100
- method: "GET",
101
- path: `${basePath}/api/queries`,
102
- handler: async (data) => await _chunkJZ2JLQXLcjs.ApiController.getQueries(data)
103
- },
104
- {
105
- method: "GET",
106
- path: `${basePath}/api/queries/:id`,
107
- handler: async (data) => await _chunkJZ2JLQXLcjs.ApiController.getQuery(data)
108
- },
109
- {
110
- method: "DELETE",
111
- path: `${basePath}/api/truncate`,
112
- handler: async () => await _chunkJZ2JLQXLcjs.ApiController.truncate()
113
- }
114
- ];
115
- return { apiRoutes };
116
- }
117
- static async getDefaultStore() {
118
- const store = new (0, _chunkAUDSBNLFcjs.BetterSqliteStore)();
119
- await store.initialize();
120
- return store;
121
- }
122
- static normalizeDirName(path2) {
123
- return path2.replace(/(\/packages\/)[^/]+(?=\/dist)/, "$1core");
124
- }
125
- }, _class.__initStatic(), _class);
126
-
127
-
128
-
129
- exports.Lens = Lens;
@@ -1,7 +0,0 @@
1
- // src/abstracts/store.ts
2
- var Store = class {
3
- };
4
-
5
- export {
6
- Store
7
- };
@@ -1,10 +0,0 @@
1
- // src/types/index.ts
2
- var WatcherTypeEnum = /* @__PURE__ */ ((WatcherTypeEnum2) => {
3
- WatcherTypeEnum2["REQUEST"] = "request";
4
- WatcherTypeEnum2["QUERY"] = "query";
5
- return WatcherTypeEnum2;
6
- })(WatcherTypeEnum || {});
7
-
8
- export {
9
- WatcherTypeEnum
10
- };
@@ -1,38 +0,0 @@
1
- "use strict";Object.defineProperty(exports, "__esModule", {value: true}); var _class;// src/context/container.ts
2
- var Container = (_class = class {
3
- static __initStatic() {this.bindings = /* @__PURE__ */ new Map()}
4
- static __initStatic2() {this.singletons = /* @__PURE__ */ new Map()}
5
- static __initStatic3() {this.instances = /* @__PURE__ */ new Map()}
6
- static bind(key, factory) {
7
- this.bindings.set(key, factory);
8
- }
9
- static singleton(key, factory) {
10
- this.singletons.set(key, factory);
11
- }
12
- static make(key) {
13
- if (this.instances.has(key)) {
14
- return this.instances.get(key);
15
- }
16
- if (this.singletons.has(key)) {
17
- const instance = this.singletons.get(key)();
18
- this.instances.set(key, instance);
19
- return instance;
20
- }
21
- if (this.bindings.has(key)) {
22
- return this.bindings.get(key)();
23
- }
24
- throw new Error(`Service "${key}" is not bound in the container`);
25
- }
26
- static has(key) {
27
- return this.bindings.has(key) || this.singletons.has(key) || this.instances.has(key);
28
- }
29
- static clear() {
30
- this.bindings.clear();
31
- this.singletons.clear();
32
- this.instances.clear();
33
- }
34
- }, _class.__initStatic(), _class.__initStatic2(), _class.__initStatic3(), _class);
35
-
36
-
37
-
38
- exports.Container = Container;
@@ -1,122 +0,0 @@
1
- import {
2
- sqlDateTime
3
- } from "./chunk-EJ5BW35V.js";
4
- import {
5
- Store
6
- } from "./chunk-FKMBNWX4.js";
7
-
8
- // src/stores/better_sqlite.ts
9
- import { randomUUID } from "crypto";
10
- import Database from "libsql";
11
- var TABLE_NAME = "lens_entries";
12
- var BetterSqliteStore = class extends Store {
13
- connection;
14
- async initialize() {
15
- this.connection = new Database("lens.db");
16
- this.setupSchema();
17
- console.log("Connected to Lens (SQLite) database.");
18
- }
19
- async truncate() {
20
- this.connection.prepare(`DELETE FROM ${TABLE_NAME};`).run();
21
- }
22
- async save(entry) {
23
- this.connection.prepare(
24
- `INSERT INTO ${TABLE_NAME} (id, data, type, created_at, lens_entry_id, minimal_data) values($id, $data, $type, $created_at, $lens_entry_id, $minimalData)`
25
- ).run({
26
- id: entry.id ?? randomUUID(),
27
- data: JSON.stringify(entry.data),
28
- type: entry.type,
29
- created_at: entry.timestamp ?? sqlDateTime(),
30
- lens_entry_id: entry.requestId || null,
31
- minimalData: JSON.stringify(entry.minimal_data ?? {})
32
- });
33
- }
34
- async getAllQueries(pagination) {
35
- return await this.paginate("query" /* QUERY */, pagination);
36
- }
37
- async getAllRequests(pagination) {
38
- return await this.paginate("request" /* REQUEST */, pagination, false);
39
- }
40
- async allByRequestId(requestId, type) {
41
- const rows = this.connection.prepare(
42
- `${this.getSelectedColumns()} FROM ${TABLE_NAME} WHERE type = $type AND lens_entry_id = $requestId ORDER BY created_at DESC`
43
- ).all({ type, requestId });
44
- return this.mapRows(rows);
45
- }
46
- async paginate(type, { page, perPage }, includeFullData = true) {
47
- const offset = (page - 1) * perPage;
48
- const query = `${this.getSelectedColumns(
49
- includeFullData
50
- )} FROM ${TABLE_NAME} WHERE type = ? ORDER BY created_at DESC LIMIT ? OFFSET ?`;
51
- const count = await this.count(type);
52
- const rows = this.connection.prepare(query).all(type, perPage, offset);
53
- const mappedRows = this.mapRows(rows, includeFullData);
54
- return {
55
- meta: {
56
- total: count,
57
- lastPage: Math.ceil(count / perPage),
58
- currentPage: page
59
- },
60
- data: mappedRows
61
- };
62
- }
63
- async count(type) {
64
- const result = this.connection.prepare(`SELECT count(*) as count FROM ${TABLE_NAME} WHERE type = ?`).get(type);
65
- return Number(result.count);
66
- }
67
- async find(type, id) {
68
- const row = this.connection.prepare(
69
- `${this.getSelectedColumns()} FROM ${TABLE_NAME} WHERE id = ? AND type = ? LIMIT 1`
70
- ).get(id, type);
71
- if (!row) {
72
- return null;
73
- }
74
- return this.mapRow(row, true);
75
- }
76
- setupSchema() {
77
- const createTable = `
78
- CREATE TABLE IF NOT EXISTS ${TABLE_NAME} (
79
- id TEXT PRIMARY KEY,
80
- minimal_data TEXT,
81
- data TEXT NOT NULL,
82
- type TEXT NOT NULL,
83
- created_at TEXT NOT NULL,
84
- updated_at TEXT,
85
- lens_entry_id TEXT NULL
86
- );
87
- `;
88
- const createIndex = `
89
- CREATE INDEX IF NOT EXISTS lens_entries_id_type_index
90
- ON ${TABLE_NAME} (id, type);
91
- `;
92
- this.connection.exec(createTable);
93
- this.connection.exec(createIndex);
94
- }
95
- mapRow(row, includeFullData = true) {
96
- let data = includeFullData ? JSON.parse(row.data) : {};
97
- if (!includeFullData) {
98
- data = JSON.parse(row.minimal_data);
99
- }
100
- return {
101
- id: row.id,
102
- type: row.type,
103
- created_at: row.created_at,
104
- lens_entry_id: row.lens_entry_id,
105
- data
106
- };
107
- }
108
- mapRows(rows, includeFullData = true) {
109
- let mappedRows = [];
110
- for (const row of rows) {
111
- mappedRows.push(this.mapRow(row, includeFullData));
112
- }
113
- return mappedRows;
114
- }
115
- getSelectedColumns(includeFullData = true) {
116
- return `SELECT id, minimal_data, type, created_at, lens_entry_id ${includeFullData ? ",data" : ""}`;
117
- }
118
- };
119
-
120
- export {
121
- BetterSqliteStore
122
- };
@@ -1,87 +0,0 @@
1
- "use strict";Object.defineProperty(exports, "__esModule", {value: true});
2
-
3
-
4
- var _chunkQRZUNYF6cjs = require('./chunk-QRZUNYF6.cjs');
5
-
6
- // src/core/api_controller.ts
7
- var ApiController = class {
8
- static async getRequests({ qs }) {
9
- return this.paginatedResponse(
10
- await _chunkQRZUNYF6cjs.getStore.call(void 0, ).getAllRequests(this.extractPaginationParams(qs))
11
- );
12
- }
13
- static async getRequest({
14
- params
15
- }) {
16
- const request = await _chunkQRZUNYF6cjs.getStore.call(void 0, ).find("request" /* REQUEST */, params.id);
17
- if (!request) {
18
- return this.notFoundResponse();
19
- }
20
- return this.resourceResponse(request);
21
- }
22
- static async getQueries({
23
- qs
24
- }) {
25
- const queries = await _chunkQRZUNYF6cjs.getStore.call(void 0, ).getAllQueries(
26
- this.extractPaginationParams(qs)
27
- );
28
- return this.paginatedResponse(queries);
29
- }
30
- static async getQuery({
31
- params
32
- }) {
33
- const query = await _chunkQRZUNYF6cjs.getStore.call(void 0, ).find("query" /* QUERY */, params.id);
34
- if (!query) {
35
- return this.notFoundResponse();
36
- }
37
- return this.resourceResponse(query);
38
- }
39
- static async truncate() {
40
- await _chunkQRZUNYF6cjs.getStore.call(void 0, ).truncate();
41
- return this.baseResponse({}, 200, "All entries cleared");
42
- }
43
- static fetchUiConfig() {
44
- return _chunkQRZUNYF6cjs.getUiConfig.call(void 0, );
45
- }
46
- static extractPaginationParams(qs) {
47
- if (!qs || Object.keys(qs).length === 0) {
48
- return { page: 1, perPage: 100 };
49
- }
50
- let page = Number(qs.page);
51
- let perPage = Number(qs.perPage);
52
- if (!Number.isInteger(perPage) || perPage > 100 || perPage < 5) {
53
- perPage = 100;
54
- }
55
- if (!Number.isInteger(page) || page < 1) {
56
- page = 1;
57
- }
58
- return { page, perPage };
59
- }
60
- static resourceResponse(data) {
61
- return this.baseResponse(data, 200, "Data fetched successfully");
62
- }
63
- static notFoundResponse(message = "Could not find the requested resource") {
64
- return this.baseResponse(null, 404, message);
65
- }
66
- static paginatedResponse(data) {
67
- return this.baseResponse(data, 200, "Data fetched successfully");
68
- }
69
- static baseResponse(data, status, message) {
70
- if (!data) {
71
- return { status, message, data: null };
72
- }
73
- if ("meta" in data) {
74
- return {
75
- status,
76
- message,
77
- data: data.data,
78
- meta: data.meta
79
- };
80
- }
81
- return { status, message, data };
82
- }
83
- };
84
-
85
-
86
-
87
- exports.ApiController = ApiController;
@@ -1,9 +0,0 @@
1
- var __defProp = Object.defineProperty;
2
- var __export = (target, all) => {
3
- for (var name in all)
4
- __defProp(target, name, { get: all[name], enumerable: true });
5
- };
6
-
7
- export {
8
- __export
9
- };
@@ -1,16 +0,0 @@
1
- "use strict";Object.defineProperty(exports, "__esModule", {value: true});
2
-
3
- var _chunkGI7SJDNQcjs = require('./chunk-GI7SJDNQ.cjs');
4
-
5
- // src/context/context.ts
6
- var getStore = () => {
7
- return _chunkGI7SJDNQcjs.Container.make("store");
8
- };
9
- var getUiConfig = () => {
10
- return _chunkGI7SJDNQcjs.Container.make("uiConfig");
11
- };
12
-
13
-
14
-
15
-
16
- exports.getStore = getStore; exports.getUiConfig = getUiConfig;
@@ -1,14 +0,0 @@
1
- // src/utils/event_emitter.ts
2
- import { AsyncResource } from "async_hooks";
3
- import Emittery from "emittery";
4
- var createEmittery = () => {
5
- return new Emittery();
6
- };
7
- var lensResource = new AsyncResource("lens-emitter");
8
- var lensEmitter = new Emittery();
9
-
10
- export {
11
- createEmittery,
12
- lensResource,
13
- lensEmitter
14
- };
@@ -1,22 +0,0 @@
1
- "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } var _class;
2
-
3
- var _chunkQRZUNYF6cjs = require('./chunk-QRZUNYF6.cjs');
4
-
5
-
6
- var _chunkEKG3FVLVcjs = require('./chunk-EKG3FVLV.cjs');
7
-
8
- // src/watchers/query_watcher.ts
9
- var QueryWatcher = (_class = class extends _chunkEKG3FVLVcjs.Watcher {constructor(...args) { super(...args); _class.prototype.__init.call(this); }
10
- __init() {this.name = "query"} /* QUERY */
11
- async log(entry) {
12
- await _chunkQRZUNYF6cjs.getStore.call(void 0, ).save({
13
- type: this.name,
14
- data: entry.data,
15
- requestId: _nullishCoalesce(entry.requestId, () => ( ""))
16
- });
17
- }
18
- }, _class);
19
-
20
-
21
-
22
- exports.QueryWatcher = QueryWatcher;
@@ -1,87 +0,0 @@
1
- import {
2
- getStore,
3
- getUiConfig
4
- } from "./chunk-XYXPHWEI.js";
5
-
6
- // src/core/api_controller.ts
7
- var ApiController = class {
8
- static async getRequests({ qs }) {
9
- return this.paginatedResponse(
10
- await getStore().getAllRequests(this.extractPaginationParams(qs))
11
- );
12
- }
13
- static async getRequest({
14
- params
15
- }) {
16
- const request = await getStore().find("request" /* REQUEST */, params.id);
17
- if (!request) {
18
- return this.notFoundResponse();
19
- }
20
- return this.resourceResponse(request);
21
- }
22
- static async getQueries({
23
- qs
24
- }) {
25
- const queries = await getStore().getAllQueries(
26
- this.extractPaginationParams(qs)
27
- );
28
- return this.paginatedResponse(queries);
29
- }
30
- static async getQuery({
31
- params
32
- }) {
33
- const query = await getStore().find("query" /* QUERY */, params.id);
34
- if (!query) {
35
- return this.notFoundResponse();
36
- }
37
- return this.resourceResponse(query);
38
- }
39
- static async truncate() {
40
- await getStore().truncate();
41
- return this.baseResponse({}, 200, "All entries cleared");
42
- }
43
- static fetchUiConfig() {
44
- return getUiConfig();
45
- }
46
- static extractPaginationParams(qs) {
47
- if (!qs || Object.keys(qs).length === 0) {
48
- return { page: 1, perPage: 100 };
49
- }
50
- let page = Number(qs.page);
51
- let perPage = Number(qs.perPage);
52
- if (!Number.isInteger(perPage) || perPage > 100 || perPage < 5) {
53
- perPage = 100;
54
- }
55
- if (!Number.isInteger(page) || page < 1) {
56
- page = 1;
57
- }
58
- return { page, perPage };
59
- }
60
- static resourceResponse(data) {
61
- return this.baseResponse(data, 200, "Data fetched successfully");
62
- }
63
- static notFoundResponse(message = "Could not find the requested resource") {
64
- return this.baseResponse(null, 404, message);
65
- }
66
- static paginatedResponse(data) {
67
- return this.baseResponse(data, 200, "Data fetched successfully");
68
- }
69
- static baseResponse(data, status, message) {
70
- if (!data) {
71
- return { status, message, data: null };
72
- }
73
- if ("meta" in data) {
74
- return {
75
- status,
76
- message,
77
- data: data.data,
78
- meta: data.meta
79
- };
80
- }
81
- return { status, message, data };
82
- }
83
- };
84
-
85
- export {
86
- ApiController
87
- };
@@ -1,32 +0,0 @@
1
- import {
2
- shouldIgnoreCurrentPath
3
- } from "./chunk-EJ5BW35V.js";
4
-
5
- // src/abstracts/adapter.ts
6
- var Adapter = class {
7
- watchers = [];
8
- ignoredPaths = [];
9
- onlyPaths = [];
10
- setWatchers(watchers) {
11
- this.watchers = watchers;
12
- return this;
13
- }
14
- setIgnoredPaths(paths) {
15
- this.ignoredPaths = paths;
16
- return this;
17
- }
18
- setOnlyPaths(paths) {
19
- this.onlyPaths = paths;
20
- return this;
21
- }
22
- getWatchers() {
23
- return this.watchers;
24
- }
25
- shouldIgnorePath(path) {
26
- return shouldIgnoreCurrentPath(path, this.ignoredPaths, this.onlyPaths);
27
- }
28
- };
29
-
30
- export {
31
- Adapter
32
- };
@@ -1,22 +0,0 @@
1
- import {
2
- getStore
3
- } from "./chunk-XYXPHWEI.js";
4
- import {
5
- Watcher
6
- } from "./chunk-CQ2Z4TCR.js";
7
-
8
- // src/watchers/query_watcher.ts
9
- var QueryWatcher = class extends Watcher {
10
- name = "query" /* QUERY */;
11
- async log(entry) {
12
- await getStore().save({
13
- type: this.name,
14
- data: entry.data,
15
- requestId: entry.requestId ?? ""
16
- });
17
- }
18
- };
19
-
20
- export {
21
- QueryWatcher
22
- };
File without changes