@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
package/package.json CHANGED
@@ -1,8 +1,7 @@
1
1
  {
2
2
  "name": "@lensjs/core",
3
- "version": "1.0.7",
3
+ "version": "1.0.10",
4
4
  "type": "module",
5
- "private": false,
6
5
  "main": "./dist/index.js",
7
6
  "types": "./dist/index.d.ts",
8
7
  "exports": {
@@ -17,27 +16,28 @@
17
16
  "publishConfig": {
18
17
  "access": "public"
19
18
  },
20
- "scripts": {
21
- "build": "tsup --clean && npm run build:ui",
22
- "build:ui": "npm --prefix src/ui run build",
23
- "clean": "rm -rf dist",
24
- "postbuild": "node copy-front-build.cjs",
25
- "format": "prettier --write .",
26
- "test": "vitest"
27
- },
28
19
  "devDependencies": {
29
- "@tailwindcss/vite": "^4.1.11",
20
+ "@tailwindcss/vite": "^4.1.12",
30
21
  "@types/luxon": "^3.7.1",
31
22
  "cross-env": "^10.0.0",
32
- "luxon": "^3.7.1",
33
- "prettier": "^3.0.0",
34
- "vitest": "^3.2.4"
23
+ "vitest": "^3.2.4",
24
+ "@lensjs/typescript-config": "1.0.10"
35
25
  },
36
26
  "dependencies": {
37
27
  "emittery": "^1.2.0",
38
- "libsql": "^0.5.17",
28
+ "libsql": "^0.5.20",
29
+ "luxon": "^3.7.1",
30
+ "rimraf": "^6.0.1",
39
31
  "sql-formatter": "^15.6.6",
40
- "tailwind-merge": "^3.3.1"
32
+ "tailwind-merge": "^3.3.1",
33
+ "@lensjs/date": "1.0.10"
41
34
  },
42
- "gitHead": "a229fde5700970ec290ff31f1e3b7d84cc56d325"
43
- }
35
+ "gitHead": "a229fde5700970ec290ff31f1e3b7d84cc56d325",
36
+ "scripts": {
37
+ "build": "npm run clean && tsup --clean && npm run build:ui",
38
+ "build:ui": "npm --prefix src/ui run prod",
39
+ "clean": "rimraf dist",
40
+ "postbuild": "node copy-front-build.cjs",
41
+ "test": "vitest"
42
+ }
43
+ }
package/README.md DELETED
@@ -1 +0,0 @@
1
- // README.md
@@ -1,10 +0,0 @@
1
- "use strict";Object.defineProperty(exports, "__esModule", {value: true});// src/types/index.ts
2
- var WatcherTypeEnum = /* @__PURE__ */ ((WatcherTypeEnum2) => {
3
- WatcherTypeEnum2["REQUEST"] = "request";
4
- WatcherTypeEnum2["QUERY"] = "query";
5
- return WatcherTypeEnum2;
6
- })(WatcherTypeEnum || {});
7
-
8
-
9
-
10
- exports.WatcherTypeEnum = WatcherTypeEnum;
@@ -1,14 +0,0 @@
1
- "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }// src/utils/event_emitter.ts
2
- var _async_hooks = require('async_hooks');
3
- var _emittery = require('emittery'); var _emittery2 = _interopRequireDefault(_emittery);
4
- var createEmittery = () => {
5
- return new (0, _emittery2.default)();
6
- };
7
- var lensResource = new (0, _async_hooks.AsyncResource)("lens-emitter");
8
- var lensEmitter = new (0, _emittery2.default)();
9
-
10
-
11
-
12
-
13
-
14
- exports.createEmittery = createEmittery; exports.lensResource = lensResource; exports.lensEmitter = lensEmitter;
@@ -1,34 +0,0 @@
1
- import {
2
- getStore
3
- } from "./chunk-XYXPHWEI.js";
4
- import {
5
- Watcher
6
- } from "./chunk-CQ2Z4TCR.js";
7
-
8
- // src/watchers/request_watcher.ts
9
- var RequestWatcher = class extends Watcher {
10
- name = "request" /* REQUEST */;
11
- async log(data) {
12
- await getStore().save({
13
- id: data.request.id,
14
- type: this.name,
15
- minimal_data: {
16
- id: data.request.id,
17
- method: data.request.method,
18
- path: data.request.path,
19
- duration: data.request.duration,
20
- createdAt: data.request.createdAt,
21
- status: data.request.status
22
- },
23
- data: {
24
- ...data.request,
25
- user: data.user,
26
- response: data.response
27
- }
28
- });
29
- }
30
- };
31
-
32
- export {
33
- RequestWatcher
34
- };
@@ -1,129 +0,0 @@
1
- import {
2
- BetterSqliteStore
3
- } from "./chunk-IPMTMCFP.js";
4
- import {
5
- getMeta
6
- } from "./chunk-EJ5BW35V.js";
7
- import {
8
- ApiController
9
- } from "./chunk-TJDE6AZM.js";
10
- import {
11
- getUiConfig
12
- } from "./chunk-XYXPHWEI.js";
13
- import {
14
- Container
15
- } from "./chunk-YC6T4XWI.js";
16
-
17
- // src/core/lens.ts
18
- import * as path from "path";
19
- var Lens = class {
20
- static watchers = /* @__PURE__ */ new Map();
21
- static store;
22
- static adapter;
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 } = getMeta(import.meta.url);
47
- const uiPath = path.resolve(this.normalizeDirName(__dirname), "ui");
48
- adapter.serveUI(uiPath, config.basePath, getUiConfig());
49
- }
50
- static setStore(store) {
51
- this.store = store;
52
- return this;
53
- }
54
- static async getStore() {
55
- return this.store ?? 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
- Container.singleton("store", () => dbStore);
70
- 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: () => ApiController.fetchUiConfig()
88
- },
89
- {
90
- method: "GET",
91
- path: `${basePath}/api/requests`,
92
- handler: async (data) => await ApiController.getRequests(data)
93
- },
94
- {
95
- method: "GET",
96
- path: `${basePath}/api/requests/:id`,
97
- handler: async (data) => await ApiController.getRequest(data)
98
- },
99
- {
100
- method: "GET",
101
- path: `${basePath}/api/queries`,
102
- handler: async (data) => await ApiController.getQueries(data)
103
- },
104
- {
105
- method: "GET",
106
- path: `${basePath}/api/queries/:id`,
107
- handler: async (data) => await ApiController.getQuery(data)
108
- },
109
- {
110
- method: "DELETE",
111
- path: `${basePath}/api/truncate`,
112
- handler: async () => await ApiController.truncate()
113
- }
114
- ];
115
- return { apiRoutes };
116
- }
117
- static async getDefaultStore() {
118
- const store = new BetterSqliteStore();
119
- await store.initialize();
120
- return store;
121
- }
122
- static normalizeDirName(path2) {
123
- return path2.replace(/(\/packages\/)[^/]+(?=\/dist)/, "$1core");
124
- }
125
- };
126
-
127
- export {
128
- Lens
129
- };
@@ -1,9 +0,0 @@
1
- "use strict";Object.defineProperty(exports, "__esModule", {value: true});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
-
8
-
9
- exports.__export = __export;
@@ -1 +0,0 @@
1
- "use strict";
@@ -1,122 +0,0 @@
1
- "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } }
2
-
3
- var _chunkWU6IZUEVcjs = require('./chunk-WU6IZUEV.cjs');
4
-
5
-
6
- var _chunkEHOWCXZVcjs = require('./chunk-EHOWCXZV.cjs');
7
-
8
- // src/stores/better_sqlite.ts
9
- var _crypto = require('crypto');
10
- var _libsql = require('libsql'); var _libsql2 = _interopRequireDefault(_libsql);
11
- var TABLE_NAME = "lens_entries";
12
- var BetterSqliteStore = class extends _chunkEHOWCXZVcjs.Store {
13
-
14
- async initialize() {
15
- this.connection = new (0, _libsql2.default)("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: _nullishCoalesce(entry.id, () => ( _crypto.randomUUID.call(void 0, ))),
27
- data: JSON.stringify(entry.data),
28
- type: entry.type,
29
- created_at: _nullishCoalesce(entry.timestamp, () => ( _chunkWU6IZUEVcjs.sqlDateTime.call(void 0, ))),
30
- lens_entry_id: entry.requestId || null,
31
- minimalData: JSON.stringify(_nullishCoalesce(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
-
121
-
122
- exports.BetterSqliteStore = BetterSqliteStore;
@@ -1,32 +0,0 @@
1
- "use strict";Object.defineProperty(exports, "__esModule", {value: true}); var _class;
2
-
3
- var _chunkWU6IZUEVcjs = require('./chunk-WU6IZUEV.cjs');
4
-
5
- // src/abstracts/adapter.ts
6
- var Adapter = (_class = class {constructor() { _class.prototype.__init.call(this);_class.prototype.__init2.call(this);_class.prototype.__init3.call(this); }
7
- __init() {this.watchers = []}
8
- __init2() {this.ignoredPaths = []}
9
- __init3() {this.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 _chunkWU6IZUEVcjs.shouldIgnoreCurrentPath.call(void 0, path, this.ignoredPaths, this.onlyPaths);
27
- }
28
- }, _class);
29
-
30
-
31
-
32
- exports.Adapter = Adapter;
@@ -1,34 +0,0 @@
1
- "use strict";Object.defineProperty(exports, "__esModule", {value: true}); var _class;
2
-
3
- var _chunkQRZUNYF6cjs = require('./chunk-QRZUNYF6.cjs');
4
-
5
-
6
- var _chunkEKG3FVLVcjs = require('./chunk-EKG3FVLV.cjs');
7
-
8
- // src/watchers/request_watcher.ts
9
- var RequestWatcher = (_class = class extends _chunkEKG3FVLVcjs.Watcher {constructor(...args) { super(...args); _class.prototype.__init.call(this); }
10
- __init() {this.name = "request"} /* REQUEST */
11
- async log(data) {
12
- await _chunkQRZUNYF6cjs.getStore.call(void 0, ).save({
13
- id: data.request.id,
14
- type: this.name,
15
- minimal_data: {
16
- id: data.request.id,
17
- method: data.request.method,
18
- path: data.request.path,
19
- duration: data.request.duration,
20
- createdAt: data.request.createdAt,
21
- status: data.request.status
22
- },
23
- data: {
24
- ...data.request,
25
- user: data.user,
26
- response: data.response
27
- }
28
- });
29
- }
30
- }, _class);
31
-
32
-
33
-
34
- exports.RequestWatcher = RequestWatcher;
@@ -1,7 +0,0 @@
1
- // src/core/watcher.ts
2
- var Watcher = class {
3
- };
4
-
5
- export {
6
- Watcher
7
- };
@@ -1,7 +0,0 @@
1
- "use strict";Object.defineProperty(exports, "__esModule", {value: true});// src/abstracts/store.ts
2
- var Store = class {
3
- };
4
-
5
-
6
-
7
- exports.Store = Store;
@@ -1,159 +0,0 @@
1
- import {
2
- __export
3
- } from "./chunk-MLKGABMK.js";
4
-
5
- // src/utils/index.ts
6
- var utils_exports = {};
7
- __export(utils_exports, {
8
- convertToUTC: () => convertToUTC,
9
- formatSqlQuery: () => formatSqlQuery,
10
- generateRandomUuid: () => generateRandomUuid,
11
- getMeta: () => getMeta,
12
- interpolateQuery: () => interpolateQuery,
13
- isStaticFile: () => isStaticFile,
14
- now: () => now,
15
- nowISO: () => nowISO,
16
- prepareIgnoredPaths: () => prepareIgnoredPaths,
17
- prettyHrTime: () => prettyHrTime,
18
- shouldIgnoreCurrentPath: () => shouldIgnoreCurrentPath,
19
- sqlDateTime: () => sqlDateTime,
20
- stripBeforeAssetsPath: () => stripBeforeAssetsPath
21
- });
22
- import { DateTime } from "luxon";
23
- import { format } from "sql-formatter";
24
- import { randomUUID } from "crypto";
25
- import { fileURLToPath } from "url";
26
- import path from "path/posix";
27
- var generateRandomUuid = () => {
28
- return randomUUID();
29
- };
30
- function interpolateQuery(query, bindings) {
31
- const formatValue = (value) => {
32
- if (value === null || value === void 0) return "NULL";
33
- if (typeof value === "string") return `'${value.replace(/'/g, "''")}'`;
34
- if (value instanceof DateTime) return `'${value.toISO()}'`;
35
- if (value instanceof Date) return `'${value.toISOString()}'`;
36
- if (Array.isArray(value))
37
- return value.map((v) => typeof v === "string" ? `'${v.replace(/'/g, "''")}'` : v).join(", ");
38
- if (typeof value === "object")
39
- return `'${JSON.stringify(value).replace(/'/g, "''")}'`;
40
- return value.toString();
41
- };
42
- if (Array.isArray(bindings)) {
43
- let i = 0;
44
- return query.replace(/\?/g, () => {
45
- if (i >= bindings.length)
46
- throw new Error("Not enough bindings for placeholders");
47
- return formatValue(bindings[i++]);
48
- });
49
- }
50
- return query.replace(/(\$|\:)(\w+)/g, (match, prefix, keyOrIndex) => {
51
- let value;
52
- if (prefix === "$" && /^\d+$/.test(keyOrIndex)) {
53
- const index = parseInt(keyOrIndex, 10) - 1;
54
- const keys = Object.keys(bindings);
55
- if (index < 0 || index >= keys.length)
56
- throw new Error(`Missing binding for ${match}`);
57
- value = bindings[keys[index]];
58
- } else {
59
- if (!(keyOrIndex in bindings))
60
- throw new Error(`Missing binding for ${match}`);
61
- value = bindings[keyOrIndex];
62
- }
63
- return formatValue(value);
64
- });
65
- }
66
- var formatSqlQuery = (query, language) => {
67
- return format(query, {
68
- language,
69
- dataTypeCase: "upper",
70
- keywordCase: "upper",
71
- functionCase: "upper"
72
- });
73
- };
74
- function now() {
75
- return DateTime.now().setZone("utc");
76
- }
77
- function nowISO() {
78
- return now().toISO({ includeOffset: false });
79
- }
80
- function sqlDateTime(dateTime) {
81
- const time = dateTime ?? now();
82
- return time.toSQL({ includeOffset: false });
83
- }
84
- function convertToUTC(dateTime) {
85
- return DateTime.fromISO(dateTime).setZone("utc").toISO({ includeOffset: false });
86
- }
87
- function getMeta(metaUrl) {
88
- const isESM = typeof __dirname === "undefined";
89
- if (isESM) {
90
- if (!metaUrl) {
91
- throw new Error("In ESM, you must pass import.meta.url to getMeta()");
92
- }
93
- const __filename2 = fileURLToPath(metaUrl);
94
- const __dirname2 = path.dirname(__filename2);
95
- return { __filename: __filename2, __dirname: __dirname2 };
96
- } else {
97
- return { __filename, __dirname };
98
- }
99
- }
100
- function isStaticFile(params) {
101
- return params.includes("assets");
102
- }
103
- function stripBeforeAssetsPath(url) {
104
- const match = url.match(/assets.*/);
105
- return match ? match[0] : url;
106
- }
107
- function prepareIgnoredPaths(path2, ignoredPaths) {
108
- const normalizedPath = path2.replace(/^\/+|\/+$/g, "");
109
- ignoredPaths = [
110
- ...ignoredPaths,
111
- new RegExp(`^/?${normalizedPath}(/|$)`),
112
- /^\/?lens-config$/,
113
- /^\/\.well-known\//
114
- ];
115
- return { ignoredPaths, normalizedPath };
116
- }
117
- function shouldIgnoreCurrentPath(path2, ignoredPaths, onlyPaths) {
118
- if (onlyPaths.length > 0) {
119
- return !onlyPaths.some((pattern) => pattern.test(path2));
120
- }
121
- return ignoredPaths.some((pattern) => pattern.test(path2));
122
- }
123
- function prettyHrTime(hrtime, verbose = false) {
124
- const seconds = hrtime[0];
125
- const nanoseconds = hrtime[1];
126
- const ms = seconds * 1e3 + nanoseconds / 1e6;
127
- if (verbose) {
128
- if (seconds > 60) {
129
- const minutes = Math.floor(seconds / 60);
130
- const remainingSeconds = seconds % 60;
131
- return `${minutes}m ${remainingSeconds}s`;
132
- }
133
- if (seconds >= 1) {
134
- return `${seconds}.${Math.floor(nanoseconds / 1e7)}s`;
135
- }
136
- return `${ms.toFixed(3)} ms`;
137
- }
138
- if (ms < 1e3) {
139
- return `${ms.toFixed(0)} ms`;
140
- }
141
- return `${(ms / 1e3).toFixed(1)} s`;
142
- }
143
-
144
- export {
145
- generateRandomUuid,
146
- interpolateQuery,
147
- formatSqlQuery,
148
- now,
149
- nowISO,
150
- sqlDateTime,
151
- convertToUTC,
152
- getMeta,
153
- isStaticFile,
154
- stripBeforeAssetsPath,
155
- prepareIgnoredPaths,
156
- shouldIgnoreCurrentPath,
157
- prettyHrTime,
158
- utils_exports
159
- };
@@ -1,7 +0,0 @@
1
- "use strict";Object.defineProperty(exports, "__esModule", {value: true});// src/core/watcher.ts
2
- var Watcher = class {
3
- };
4
-
5
-
6
-
7
- exports.Watcher = Watcher;