@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,10 +1,152 @@
1
- "use strict";Object.defineProperty(exports, "__esModule", {value: true});
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
2
29
 
3
- var _chunkAUDSBNLFcjs = require('../chunk-AUDSBNLF.cjs');
4
- require('../chunk-WU6IZUEV.cjs');
5
- require('../chunk-EHOWCXZV.cjs');
6
- require('../chunk-2HRVJRKV.cjs');
7
- require('../chunk-75ZPJI57.cjs');
30
+ // src/stores/better_sqlite.ts
31
+ var better_sqlite_exports = {};
32
+ __export(better_sqlite_exports, {
33
+ default: () => BetterSqliteStore
34
+ });
35
+ module.exports = __toCommonJS(better_sqlite_exports);
8
36
 
37
+ // src/abstracts/store.ts
38
+ var Store = class {
39
+ };
9
40
 
10
- exports.default = _chunkAUDSBNLFcjs.BetterSqliteStore;
41
+ // src/stores/better_sqlite.ts
42
+ var import_crypto = require("crypto");
43
+ var import_libsql = __toESM(require("libsql"), 1);
44
+ var import_date = require("@lensjs/date");
45
+ var TABLE_NAME = "lens_entries";
46
+ var BetterSqliteStore = class extends Store {
47
+ connection;
48
+ async initialize() {
49
+ this.connection = new import_libsql.default("lens.db");
50
+ this.setupSchema();
51
+ console.log("Connected to Lens (SQLite) database.");
52
+ }
53
+ async truncate() {
54
+ this.connection.prepare(`DELETE FROM ${TABLE_NAME};`).run();
55
+ }
56
+ async save(entry) {
57
+ this.connection.prepare(
58
+ `INSERT INTO ${TABLE_NAME} (id, data, type, created_at, lens_entry_id, minimal_data) values($id, $data, $type, $created_at, $lens_entry_id, $minimalData)`
59
+ ).run({
60
+ id: entry.id ?? (0, import_crypto.randomUUID)(),
61
+ data: JSON.stringify(entry.data),
62
+ type: entry.type,
63
+ created_at: entry.timestamp ?? (0, import_date.sqlDateTime)(),
64
+ lens_entry_id: entry.requestId || null,
65
+ minimalData: JSON.stringify(entry.minimal_data ?? {})
66
+ });
67
+ }
68
+ async getAllQueries(pagination) {
69
+ return await this.paginate("query" /* QUERY */, pagination);
70
+ }
71
+ async getAllRequests(pagination) {
72
+ return await this.paginate("request" /* REQUEST */, pagination, false);
73
+ }
74
+ async allByRequestId(requestId, type) {
75
+ const rows = this.connection.prepare(
76
+ `${this.getSelectedColumns()} FROM ${TABLE_NAME} WHERE type = $type AND lens_entry_id = $requestId ORDER BY created_at DESC`
77
+ ).all({ type, requestId });
78
+ return this.mapRows(rows);
79
+ }
80
+ async paginate(type, { page, perPage }, includeFullData = true) {
81
+ const offset = (page - 1) * perPage;
82
+ const query = `${this.getSelectedColumns(
83
+ includeFullData
84
+ )} FROM ${TABLE_NAME} WHERE type = ? ORDER BY created_at DESC LIMIT ? OFFSET ?`;
85
+ const count = await this.count(type);
86
+ const rows = this.connection.prepare(query).all(type, perPage, offset);
87
+ const mappedRows = this.mapRows(rows, includeFullData);
88
+ return {
89
+ meta: {
90
+ total: count,
91
+ lastPage: Math.ceil(count / perPage),
92
+ currentPage: page
93
+ },
94
+ data: mappedRows
95
+ };
96
+ }
97
+ async count(type) {
98
+ const result = this.connection.prepare(`SELECT count(*) as count FROM ${TABLE_NAME} WHERE type = ?`).get(type);
99
+ return Number(result.count);
100
+ }
101
+ async find(type, id) {
102
+ const row = this.connection.prepare(
103
+ `${this.getSelectedColumns()} FROM ${TABLE_NAME} WHERE id = ? AND type = ? LIMIT 1`
104
+ ).get(id, type);
105
+ if (!row) {
106
+ return null;
107
+ }
108
+ return this.mapRow(row, true);
109
+ }
110
+ setupSchema() {
111
+ const createTable = `
112
+ CREATE TABLE IF NOT EXISTS ${TABLE_NAME} (
113
+ id TEXT PRIMARY KEY,
114
+ minimal_data TEXT,
115
+ data TEXT NOT NULL,
116
+ type TEXT NOT NULL,
117
+ created_at TEXT NOT NULL,
118
+ updated_at TEXT,
119
+ lens_entry_id TEXT NULL
120
+ );
121
+ `;
122
+ const createIndex = `
123
+ CREATE INDEX IF NOT EXISTS lens_entries_id_type_index
124
+ ON ${TABLE_NAME} (id, type);
125
+ `;
126
+ this.connection.exec(createTable);
127
+ this.connection.exec(createIndex);
128
+ }
129
+ mapRow(row, includeFullData = true) {
130
+ let data = includeFullData ? JSON.parse(row.data) : {};
131
+ if (!includeFullData) {
132
+ data = JSON.parse(row.minimal_data);
133
+ }
134
+ return {
135
+ id: row.id,
136
+ type: row.type,
137
+ created_at: row.created_at,
138
+ lens_entry_id: row.lens_entry_id,
139
+ data
140
+ };
141
+ }
142
+ mapRows(rows, includeFullData = true) {
143
+ let mappedRows = [];
144
+ for (const row of rows) {
145
+ mappedRows.push(this.mapRow(row, includeFullData));
146
+ }
147
+ return mappedRows;
148
+ }
149
+ getSelectedColumns(includeFullData = true) {
150
+ return `SELECT id, minimal_data, type, created_at, lens_entry_id ${includeFullData ? ",data" : ""}`;
151
+ }
152
+ };
@@ -1,10 +1,119 @@
1
- import {
2
- BetterSqliteStore
3
- } from "../chunk-IPMTMCFP.js";
4
- import "../chunk-EJ5BW35V.js";
5
- import "../chunk-FKMBNWX4.js";
6
- import "../chunk-FLOVBBFU.js";
7
- import "../chunk-MLKGABMK.js";
1
+ // src/abstracts/store.ts
2
+ var Store = class {
3
+ };
4
+
5
+ // src/stores/better_sqlite.ts
6
+ import { randomUUID } from "crypto";
7
+ import Database from "libsql";
8
+ import { sqlDateTime } from "@lensjs/date";
9
+ var TABLE_NAME = "lens_entries";
10
+ var BetterSqliteStore = class extends Store {
11
+ connection;
12
+ async initialize() {
13
+ this.connection = new Database("lens.db");
14
+ this.setupSchema();
15
+ console.log("Connected to Lens (SQLite) database.");
16
+ }
17
+ async truncate() {
18
+ this.connection.prepare(`DELETE FROM ${TABLE_NAME};`).run();
19
+ }
20
+ async save(entry) {
21
+ this.connection.prepare(
22
+ `INSERT INTO ${TABLE_NAME} (id, data, type, created_at, lens_entry_id, minimal_data) values($id, $data, $type, $created_at, $lens_entry_id, $minimalData)`
23
+ ).run({
24
+ id: entry.id ?? randomUUID(),
25
+ data: JSON.stringify(entry.data),
26
+ type: entry.type,
27
+ created_at: entry.timestamp ?? sqlDateTime(),
28
+ lens_entry_id: entry.requestId || null,
29
+ minimalData: JSON.stringify(entry.minimal_data ?? {})
30
+ });
31
+ }
32
+ async getAllQueries(pagination) {
33
+ return await this.paginate("query" /* QUERY */, pagination);
34
+ }
35
+ async getAllRequests(pagination) {
36
+ return await this.paginate("request" /* REQUEST */, pagination, false);
37
+ }
38
+ async allByRequestId(requestId, type) {
39
+ const rows = this.connection.prepare(
40
+ `${this.getSelectedColumns()} FROM ${TABLE_NAME} WHERE type = $type AND lens_entry_id = $requestId ORDER BY created_at DESC`
41
+ ).all({ type, requestId });
42
+ return this.mapRows(rows);
43
+ }
44
+ async paginate(type, { page, perPage }, includeFullData = true) {
45
+ const offset = (page - 1) * perPage;
46
+ const query = `${this.getSelectedColumns(
47
+ includeFullData
48
+ )} FROM ${TABLE_NAME} WHERE type = ? ORDER BY created_at DESC LIMIT ? OFFSET ?`;
49
+ const count = await this.count(type);
50
+ const rows = this.connection.prepare(query).all(type, perPage, offset);
51
+ const mappedRows = this.mapRows(rows, includeFullData);
52
+ return {
53
+ meta: {
54
+ total: count,
55
+ lastPage: Math.ceil(count / perPage),
56
+ currentPage: page
57
+ },
58
+ data: mappedRows
59
+ };
60
+ }
61
+ async count(type) {
62
+ const result = this.connection.prepare(`SELECT count(*) as count FROM ${TABLE_NAME} WHERE type = ?`).get(type);
63
+ return Number(result.count);
64
+ }
65
+ async find(type, id) {
66
+ const row = this.connection.prepare(
67
+ `${this.getSelectedColumns()} FROM ${TABLE_NAME} WHERE id = ? AND type = ? LIMIT 1`
68
+ ).get(id, type);
69
+ if (!row) {
70
+ return null;
71
+ }
72
+ return this.mapRow(row, true);
73
+ }
74
+ setupSchema() {
75
+ const createTable = `
76
+ CREATE TABLE IF NOT EXISTS ${TABLE_NAME} (
77
+ id TEXT PRIMARY KEY,
78
+ minimal_data TEXT,
79
+ data TEXT NOT NULL,
80
+ type TEXT NOT NULL,
81
+ created_at TEXT NOT NULL,
82
+ updated_at TEXT,
83
+ lens_entry_id TEXT NULL
84
+ );
85
+ `;
86
+ const createIndex = `
87
+ CREATE INDEX IF NOT EXISTS lens_entries_id_type_index
88
+ ON ${TABLE_NAME} (id, type);
89
+ `;
90
+ this.connection.exec(createTable);
91
+ this.connection.exec(createIndex);
92
+ }
93
+ mapRow(row, includeFullData = true) {
94
+ let data = includeFullData ? JSON.parse(row.data) : {};
95
+ if (!includeFullData) {
96
+ data = JSON.parse(row.minimal_data);
97
+ }
98
+ return {
99
+ id: row.id,
100
+ type: row.type,
101
+ created_at: row.created_at,
102
+ lens_entry_id: row.lens_entry_id,
103
+ data
104
+ };
105
+ }
106
+ mapRows(rows, includeFullData = true) {
107
+ let mappedRows = [];
108
+ for (const row of rows) {
109
+ mappedRows.push(this.mapRow(row, includeFullData));
110
+ }
111
+ return mappedRows;
112
+ }
113
+ getSelectedColumns(includeFullData = true) {
114
+ return `SELECT id, minimal_data, type, created_at, lens_entry_id ${includeFullData ? ",data" : ""}`;
115
+ }
116
+ };
8
117
  export {
9
118
  BetterSqliteStore as default
10
119
  };
@@ -1,11 +1,156 @@
1
- "use strict";Object.defineProperty(exports, "__esModule", {value: true});require('../chunk-XZFXXD3A.cjs');
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
2
29
 
30
+ // src/stores/index.ts
31
+ var stores_exports = {};
32
+ __export(stores_exports, {
33
+ BetterSqliteStore: () => BetterSqliteStore
34
+ });
35
+ module.exports = __toCommonJS(stores_exports);
3
36
 
4
- var _chunkAUDSBNLFcjs = require('../chunk-AUDSBNLF.cjs');
5
- require('../chunk-WU6IZUEV.cjs');
6
- require('../chunk-EHOWCXZV.cjs');
7
- require('../chunk-2HRVJRKV.cjs');
8
- require('../chunk-75ZPJI57.cjs');
37
+ // src/abstracts/store.ts
38
+ var Store = class {
39
+ };
9
40
 
10
-
11
- exports.BetterSqliteStore = _chunkAUDSBNLFcjs.BetterSqliteStore;
41
+ // src/stores/better_sqlite.ts
42
+ var import_crypto = require("crypto");
43
+ var import_libsql = __toESM(require("libsql"), 1);
44
+ var import_date = require("@lensjs/date");
45
+ var TABLE_NAME = "lens_entries";
46
+ var BetterSqliteStore = class extends Store {
47
+ connection;
48
+ async initialize() {
49
+ this.connection = new import_libsql.default("lens.db");
50
+ this.setupSchema();
51
+ console.log("Connected to Lens (SQLite) database.");
52
+ }
53
+ async truncate() {
54
+ this.connection.prepare(`DELETE FROM ${TABLE_NAME};`).run();
55
+ }
56
+ async save(entry) {
57
+ this.connection.prepare(
58
+ `INSERT INTO ${TABLE_NAME} (id, data, type, created_at, lens_entry_id, minimal_data) values($id, $data, $type, $created_at, $lens_entry_id, $minimalData)`
59
+ ).run({
60
+ id: entry.id ?? (0, import_crypto.randomUUID)(),
61
+ data: JSON.stringify(entry.data),
62
+ type: entry.type,
63
+ created_at: entry.timestamp ?? (0, import_date.sqlDateTime)(),
64
+ lens_entry_id: entry.requestId || null,
65
+ minimalData: JSON.stringify(entry.minimal_data ?? {})
66
+ });
67
+ }
68
+ async getAllQueries(pagination) {
69
+ return await this.paginate("query" /* QUERY */, pagination);
70
+ }
71
+ async getAllRequests(pagination) {
72
+ return await this.paginate("request" /* REQUEST */, pagination, false);
73
+ }
74
+ async allByRequestId(requestId, type) {
75
+ const rows = this.connection.prepare(
76
+ `${this.getSelectedColumns()} FROM ${TABLE_NAME} WHERE type = $type AND lens_entry_id = $requestId ORDER BY created_at DESC`
77
+ ).all({ type, requestId });
78
+ return this.mapRows(rows);
79
+ }
80
+ async paginate(type, { page, perPage }, includeFullData = true) {
81
+ const offset = (page - 1) * perPage;
82
+ const query = `${this.getSelectedColumns(
83
+ includeFullData
84
+ )} FROM ${TABLE_NAME} WHERE type = ? ORDER BY created_at DESC LIMIT ? OFFSET ?`;
85
+ const count = await this.count(type);
86
+ const rows = this.connection.prepare(query).all(type, perPage, offset);
87
+ const mappedRows = this.mapRows(rows, includeFullData);
88
+ return {
89
+ meta: {
90
+ total: count,
91
+ lastPage: Math.ceil(count / perPage),
92
+ currentPage: page
93
+ },
94
+ data: mappedRows
95
+ };
96
+ }
97
+ async count(type) {
98
+ const result = this.connection.prepare(`SELECT count(*) as count FROM ${TABLE_NAME} WHERE type = ?`).get(type);
99
+ return Number(result.count);
100
+ }
101
+ async find(type, id) {
102
+ const row = this.connection.prepare(
103
+ `${this.getSelectedColumns()} FROM ${TABLE_NAME} WHERE id = ? AND type = ? LIMIT 1`
104
+ ).get(id, type);
105
+ if (!row) {
106
+ return null;
107
+ }
108
+ return this.mapRow(row, true);
109
+ }
110
+ setupSchema() {
111
+ const createTable = `
112
+ CREATE TABLE IF NOT EXISTS ${TABLE_NAME} (
113
+ id TEXT PRIMARY KEY,
114
+ minimal_data TEXT,
115
+ data TEXT NOT NULL,
116
+ type TEXT NOT NULL,
117
+ created_at TEXT NOT NULL,
118
+ updated_at TEXT,
119
+ lens_entry_id TEXT NULL
120
+ );
121
+ `;
122
+ const createIndex = `
123
+ CREATE INDEX IF NOT EXISTS lens_entries_id_type_index
124
+ ON ${TABLE_NAME} (id, type);
125
+ `;
126
+ this.connection.exec(createTable);
127
+ this.connection.exec(createIndex);
128
+ }
129
+ mapRow(row, includeFullData = true) {
130
+ let data = includeFullData ? JSON.parse(row.data) : {};
131
+ if (!includeFullData) {
132
+ data = JSON.parse(row.minimal_data);
133
+ }
134
+ return {
135
+ id: row.id,
136
+ type: row.type,
137
+ created_at: row.created_at,
138
+ lens_entry_id: row.lens_entry_id,
139
+ data
140
+ };
141
+ }
142
+ mapRows(rows, includeFullData = true) {
143
+ let mappedRows = [];
144
+ for (const row of rows) {
145
+ mappedRows.push(this.mapRow(row, includeFullData));
146
+ }
147
+ return mappedRows;
148
+ }
149
+ getSelectedColumns(includeFullData = true) {
150
+ return `SELECT id, minimal_data, type, created_at, lens_entry_id ${includeFullData ? ",data" : ""}`;
151
+ }
152
+ };
153
+ // Annotate the CommonJS export names for ESM import in node:
154
+ 0 && (module.exports = {
155
+ BetterSqliteStore
156
+ });
@@ -1,11 +1,119 @@
1
- import "../chunk-VD5IMUWL.js";
2
- import {
3
- BetterSqliteStore
4
- } from "../chunk-IPMTMCFP.js";
5
- import "../chunk-EJ5BW35V.js";
6
- import "../chunk-FKMBNWX4.js";
7
- import "../chunk-FLOVBBFU.js";
8
- import "../chunk-MLKGABMK.js";
1
+ // src/abstracts/store.ts
2
+ var Store = class {
3
+ };
4
+
5
+ // src/stores/better_sqlite.ts
6
+ import { randomUUID } from "crypto";
7
+ import Database from "libsql";
8
+ import { sqlDateTime } from "@lensjs/date";
9
+ var TABLE_NAME = "lens_entries";
10
+ var BetterSqliteStore = class extends Store {
11
+ connection;
12
+ async initialize() {
13
+ this.connection = new Database("lens.db");
14
+ this.setupSchema();
15
+ console.log("Connected to Lens (SQLite) database.");
16
+ }
17
+ async truncate() {
18
+ this.connection.prepare(`DELETE FROM ${TABLE_NAME};`).run();
19
+ }
20
+ async save(entry) {
21
+ this.connection.prepare(
22
+ `INSERT INTO ${TABLE_NAME} (id, data, type, created_at, lens_entry_id, minimal_data) values($id, $data, $type, $created_at, $lens_entry_id, $minimalData)`
23
+ ).run({
24
+ id: entry.id ?? randomUUID(),
25
+ data: JSON.stringify(entry.data),
26
+ type: entry.type,
27
+ created_at: entry.timestamp ?? sqlDateTime(),
28
+ lens_entry_id: entry.requestId || null,
29
+ minimalData: JSON.stringify(entry.minimal_data ?? {})
30
+ });
31
+ }
32
+ async getAllQueries(pagination) {
33
+ return await this.paginate("query" /* QUERY */, pagination);
34
+ }
35
+ async getAllRequests(pagination) {
36
+ return await this.paginate("request" /* REQUEST */, pagination, false);
37
+ }
38
+ async allByRequestId(requestId, type) {
39
+ const rows = this.connection.prepare(
40
+ `${this.getSelectedColumns()} FROM ${TABLE_NAME} WHERE type = $type AND lens_entry_id = $requestId ORDER BY created_at DESC`
41
+ ).all({ type, requestId });
42
+ return this.mapRows(rows);
43
+ }
44
+ async paginate(type, { page, perPage }, includeFullData = true) {
45
+ const offset = (page - 1) * perPage;
46
+ const query = `${this.getSelectedColumns(
47
+ includeFullData
48
+ )} FROM ${TABLE_NAME} WHERE type = ? ORDER BY created_at DESC LIMIT ? OFFSET ?`;
49
+ const count = await this.count(type);
50
+ const rows = this.connection.prepare(query).all(type, perPage, offset);
51
+ const mappedRows = this.mapRows(rows, includeFullData);
52
+ return {
53
+ meta: {
54
+ total: count,
55
+ lastPage: Math.ceil(count / perPage),
56
+ currentPage: page
57
+ },
58
+ data: mappedRows
59
+ };
60
+ }
61
+ async count(type) {
62
+ const result = this.connection.prepare(`SELECT count(*) as count FROM ${TABLE_NAME} WHERE type = ?`).get(type);
63
+ return Number(result.count);
64
+ }
65
+ async find(type, id) {
66
+ const row = this.connection.prepare(
67
+ `${this.getSelectedColumns()} FROM ${TABLE_NAME} WHERE id = ? AND type = ? LIMIT 1`
68
+ ).get(id, type);
69
+ if (!row) {
70
+ return null;
71
+ }
72
+ return this.mapRow(row, true);
73
+ }
74
+ setupSchema() {
75
+ const createTable = `
76
+ CREATE TABLE IF NOT EXISTS ${TABLE_NAME} (
77
+ id TEXT PRIMARY KEY,
78
+ minimal_data TEXT,
79
+ data TEXT NOT NULL,
80
+ type TEXT NOT NULL,
81
+ created_at TEXT NOT NULL,
82
+ updated_at TEXT,
83
+ lens_entry_id TEXT NULL
84
+ );
85
+ `;
86
+ const createIndex = `
87
+ CREATE INDEX IF NOT EXISTS lens_entries_id_type_index
88
+ ON ${TABLE_NAME} (id, type);
89
+ `;
90
+ this.connection.exec(createTable);
91
+ this.connection.exec(createIndex);
92
+ }
93
+ mapRow(row, includeFullData = true) {
94
+ let data = includeFullData ? JSON.parse(row.data) : {};
95
+ if (!includeFullData) {
96
+ data = JSON.parse(row.minimal_data);
97
+ }
98
+ return {
99
+ id: row.id,
100
+ type: row.type,
101
+ created_at: row.created_at,
102
+ lens_entry_id: row.lens_entry_id,
103
+ data
104
+ };
105
+ }
106
+ mapRows(rows, includeFullData = true) {
107
+ let mappedRows = [];
108
+ for (const row of rows) {
109
+ mappedRows.push(this.mapRow(row, includeFullData));
110
+ }
111
+ return mappedRows;
112
+ }
113
+ getSelectedColumns(includeFullData = true) {
114
+ return `SELECT id, minimal_data, type, created_at, lens_entry_id ${includeFullData ? ",data" : ""}`;
115
+ }
116
+ };
9
117
  export {
10
118
  BetterSqliteStore
11
119
  };
@@ -1,7 +1,34 @@
1
- "use strict";Object.defineProperty(exports, "__esModule", {value: true});
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
2
19
 
3
- var _chunk2HRVJRKVcjs = require('../chunk-2HRVJRKV.cjs');
4
- require('../chunk-75ZPJI57.cjs');
5
-
6
-
7
- exports.WatcherTypeEnum = _chunk2HRVJRKVcjs.WatcherTypeEnum;
20
+ // src/types/index.ts
21
+ var types_exports = {};
22
+ __export(types_exports, {
23
+ WatcherTypeEnum: () => WatcherTypeEnum
24
+ });
25
+ module.exports = __toCommonJS(types_exports);
26
+ var WatcherTypeEnum = /* @__PURE__ */ ((WatcherTypeEnum2) => {
27
+ WatcherTypeEnum2["REQUEST"] = "request";
28
+ WatcherTypeEnum2["QUERY"] = "query";
29
+ return WatcherTypeEnum2;
30
+ })(WatcherTypeEnum || {});
31
+ // Annotate the CommonJS export names for ESM import in node:
32
+ 0 && (module.exports = {
33
+ WatcherTypeEnum
34
+ });
@@ -1,7 +1,9 @@
1
- import {
2
- WatcherTypeEnum
3
- } from "../chunk-FLOVBBFU.js";
4
- import "../chunk-MLKGABMK.js";
1
+ // src/types/index.ts
2
+ var WatcherTypeEnum = /* @__PURE__ */ ((WatcherTypeEnum2) => {
3
+ WatcherTypeEnum2["REQUEST"] = "request";
4
+ WatcherTypeEnum2["QUERY"] = "query";
5
+ return WatcherTypeEnum2;
6
+ })(WatcherTypeEnum || {});
5
7
  export {
6
8
  WatcherTypeEnum
7
9
  };
@@ -0,0 +1,2 @@
1
+ const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["./QueryTable-BcrtUssT.js","./index-BS8XxorB.js","./index-DzNHqeKh.css","./Table-DYaXk80S.js","./index-CpP2Ap5X.js"])))=>i.map(i=>d[i]);
2
+ import{r as t,j as s,_ as a}from"./index-BS8XxorB.js";import{u as i}from"./useQueries-C8mDDDc6.js";import{u}from"./useLoadMore-CJltToLI.js";import"./useLensApi-DG6atd6d.js";const m=t.lazy(()=>a(()=>import("./QueryTable-BcrtUssT.js"),__vite__mapDeps([0,1,2,3,4]),import.meta.url)),l=()=>{const{loadMoreRequests:o,fetchQueries:r}=i(),e=u({paginatedPage:o});return t.useEffect(()=>{r()},[]),console.log("data",e.data),s.jsx(m,{hasMoreObject:e})};export{l as default};