Skip to content

Commit db8f206

Browse files
committed
refactor!: implement brand new cache layer
1 parent a290904 commit db8f206

44 files changed

Lines changed: 2312 additions & 1645 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.changeset/forty-vans-live.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
"@nodesecure/server": major
3+
"@nodesecure/cache": major
4+
---
5+
6+
Major refactor to enhance cache integration

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,3 +72,4 @@ reports
7272
# macOS system files
7373
.DS_Store
7474

75+
.claude

.npmrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@ package-lock=false
22
provenance=true
33
save-exact=true
44
ignore-scripts=true
5+
allow-git=none

bin/index.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,6 @@ prog
126126
.command("cache")
127127
.option("-l, --list", i18n.getTokenSync("cli.commands.cache.option_list"), false)
128128
.option("-c, --clear", i18n.getTokenSync("cli.commands.cache.option_clear"), false)
129-
.option("-f, --full", i18n.getTokenSync("cli.commands.cache.option_full"), false)
130129
.describe(i18n.getTokenSync("cli.commands.cache.desc"))
131130
.action(commands.cache.main);
132131

docs/cli/cache.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,3 @@ $ nsecure cache [options]
1414
|---|---|---|---|
1515
| `--list` | `-l` | `false` | Display the cache contents in JSON format. Use with `--full` to include scanned payloads stored on disk. |
1616
| `--clear` | `-c` | `false` | Remove cached entries. Use with `--full` to also delete scanned payloads stored on disk. |
17-
| `--full` | `-f` | `false` | Extend the scope of `--list` or `--clear` to include scanned payloads stored on disk.|

esbuild.dev.config.ts

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@ import http from "node:http";
44
import path from "node:path";
55

66
// Import Third-party Dependencies
7-
import { getBuildConfiguration } from "@nodesecure/documentation-ui/node";
7+
import {
8+
getBuildConfiguration
9+
} from "@nodesecure/documentation-ui/node";
810
import * as i18n from "@nodesecure/i18n";
911
import chokidar from "chokidar";
1012
import esbuild from "esbuild";
@@ -14,12 +16,17 @@ import sirv from "sirv";
1416
// Import Internal Dependencies
1517
import english from "./i18n/english.js";
1618
import french from "./i18n/french.js";
17-
import { context as als, type AsyncStoreContext } from "./workspaces/server/src/ALS.ts";
18-
import { ViewBuilder } from "./workspaces/server/src/ViewBuilder.class.ts";
19-
import { cache } from "./workspaces/server/src/cache.ts";
20-
import { getApiRouter } from "./workspaces/server/src/endpoints/index.ts";
21-
import { logger } from "./workspaces/server/src/logger.ts";
22-
import { WebSocketServerInstanciator } from "./workspaces/server/src/websocket/index.ts";
19+
20+
import {
21+
PayloadCache
22+
} from "./workspaces/cache/src/index.ts";
23+
import {
24+
WebSocketServerInstanciator,
25+
logger,
26+
ViewBuilder,
27+
getApiRouter,
28+
context as als, type AsyncStoreContext
29+
} from "./workspaces/server/src/index.ts";
2330

2431
// CONSTANTS
2532
const kPublicDir = path.join(import.meta.dirname, "public");
@@ -73,10 +80,13 @@ const { hosts: esbuildHosts, port: esbuildPort } = await buildContext.serve({
7380
servedir: kOutDir
7481
});
7582

76-
const dataFilePath = await fsAsync.access(kDefaultPayloadPath).then(() => kDefaultPayloadPath, () => undefined);
83+
const dataFilePath = await fsAsync.access(
84+
kDefaultPayloadPath
85+
).then(() => kDefaultPayloadPath, () => undefined);
86+
const cache = await new PayloadCache().load();
7787

7888
if (dataFilePath === undefined) {
79-
cache.startFromZero = true;
89+
cache.setCurrentSpec(null);
8090
}
8191

8292
const store: AsyncStoreContext = {
@@ -85,7 +95,7 @@ const store: AsyncStoreContext = {
8595
projectRootDir: import.meta.dirname,
8696
componentsDir: kComponentsDir
8797
}),
88-
dataFilePath
98+
cache
8999
};
90100
const htmlWatcher = chokidar.watch(kComponentsDir, {
91101
persistent: false,
@@ -129,7 +139,7 @@ function defaultRoute(req: http.IncomingMessage, res: http.ServerResponse) {
129139

130140
const apiRouter = getApiRouter(defaultRoute);
131141

132-
const httpServer = http.createServer((req, res) => als.run(store, () => apiRouter.lookup(req, res)))
142+
http.createServer((req, res) => als.run(store, () => apiRouter.lookup(req, res)))
133143
.listen(kDevPort, () => {
134144
console.log(`Dev server: http://localhost:${kDevPort}`);
135145
open(`http://localhost:${kDevPort}`);

i18n/arabic.js

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,9 +80,7 @@ const cli = {
8080
missingAction: "لم يتم تحديد إجراء صالح. استخدم --help لرؤية الخيارات.",
8181
option_list: "عرض ملفات ذاكرة التخزين المؤقت",
8282
option_clear: "مسح ذاكرة التخزين المؤقت",
83-
option_full: "مسح أو عرض ذاكرة التخزين المؤقت الكاملة، بما في ذلك الحمولات",
8483
cacheTitle: "ذاكرة التخزين المؤقت لـ NodeSecure:",
85-
scannedPayloadsTitle: "الحمولات الممسوحة المتاحة على القرص:",
8684
cleared: "تم مسح ذاكرة التخزين المؤقت بنجاح!"
8785
},
8886
extractIntegrity: {
@@ -226,7 +224,6 @@ const ui = {
226224
"Available licenses": "التراخيص المتاحة",
227225
"Available flags": "الأعلام المتاحة",
228226
default: "خيارات البحث",
229-
recentPackages: "الحزم الأخيرة",
230227
packagesCache: "الحزم المتاحة في ذاكرة التخزين المؤقت",
231228
noPackageFound: "لم يتم العثور على حزمة",
232229
packageLengthErr: "يجب أن يكون اسم الحزمة بين 2 و 64 حرفاً.",

i18n/english.js

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,9 +82,7 @@ const cli = {
8282
missingAction: "No valid action specified. Use --help to see options.",
8383
option_list: "List cache files",
8484
option_clear: "Clear the cache",
85-
option_full: "Clear or list the full cache, including payloads",
8685
cacheTitle: "NodeSecure Cache:",
87-
scannedPayloadsTitle: "Scanned payloads available on disk:",
8886
cleared: "Cache cleared successfully!"
8987
},
9088
extractIntegrity: {
@@ -223,7 +221,6 @@ const ui = {
223221
locked: "locked"
224222
},
225223
search: {
226-
recentPackages: "Recent packages",
227224
packagesCache: "Packages available in the cache",
228225
noPackageFound: "No package found",
229226
packageLengthErr: "Package name must be between 2 and 64 characters.",

i18n/french.js

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,9 +82,7 @@ const cli = {
8282
missingAction: "Aucune action valide spécifiée. Utilisez --help pour voir les options.",
8383
option_list: "Lister les fichiers du cache",
8484
option_clear: "Nettoyer le cache",
85-
option_full: "Nettoyer ou lister le cache complet, y compris les payloads",
8685
cacheTitle: "Cache NodeSecure:",
87-
scannedPayloadsTitle: "Payloads scannés disponibles sur le disque:",
8886
cleared: "Cache nettoyé avec succès !"
8987
},
9088
extractIntegrity: {
@@ -223,7 +221,6 @@ const ui = {
223221
locked: "Verrouillé"
224222
},
225223
search: {
226-
recentPackages: "Packages récents",
227224
packagesCache: "Packages disponibles dans le cache",
228225
noPackageFound: "Aucun package trouvé",
229226
packageLengthErr: "Le nom du package doit être compris entre 2 et 64 caractères.",

i18n/turkish.js

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,9 +82,7 @@ const cli = {
8282
missingAction: "Geçerli bir işlem belirtilmedi. Seçenekleri görmek için --help kullanın.",
8383
option_list: "Önbellek dosyalarını listele",
8484
option_clear: "Önbelleği temizle",
85-
option_full: "Yükler dahil tam önbelleği temizle veya listele",
8685
cacheTitle: "NodeSecure Önbelleği:",
87-
scannedPayloadsTitle: "Diskte mevcut taranan yükler:",
8886
cleared: "Önbellek başarıyla temizlendi!"
8987
},
9088
extractIntegrity: {
@@ -228,7 +226,6 @@ const ui = {
228226
"Available licenses": "Mevcut lisanslar",
229227
"Available flags": "Mevcut bayraklar",
230228
default: "Arama seçenekleri",
231-
recentPackages: "Son paketler",
232229
packagesCache: "Önbellekte mevcut paketler",
233230
noPackageFound: "Paket bulunamadı",
234231
packageLengthErr: "Paket adı 2 ile 64 karakter arasında olmalıdır.",

0 commit comments

Comments
 (0)