layercache 1.2.0 → 1.2.2
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.
- package/README.md +110 -8
- package/dist/chunk-46UH7LNM.js +312 -0
- package/dist/{chunk-BWM4MU2X.js → chunk-IXCMHVHP.js} +62 -56
- package/dist/chunk-ZMDB5KOK.js +159 -0
- package/dist/cli.cjs +170 -39
- package/dist/cli.js +57 -2
- package/dist/edge-DLpdQN0W.d.cts +672 -0
- package/dist/edge-DLpdQN0W.d.ts +672 -0
- package/dist/edge.cjs +399 -0
- package/dist/edge.d.cts +2 -0
- package/dist/edge.d.ts +2 -0
- package/dist/edge.js +14 -0
- package/dist/index.cjs +1173 -221
- package/dist/index.d.cts +51 -568
- package/dist/index.d.ts +51 -568
- package/dist/index.js +1005 -505
- package/package.json +8 -3
- package/packages/nestjs/dist/index.cjs +980 -370
- package/packages/nestjs/dist/index.d.cts +80 -0
- package/packages/nestjs/dist/index.d.ts +80 -0
- package/packages/nestjs/dist/index.js +968 -368
package/dist/cli.js
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import {
|
|
3
3
|
RedisTagIndex
|
|
4
|
-
} from "./chunk-
|
|
4
|
+
} from "./chunk-IXCMHVHP.js";
|
|
5
|
+
import {
|
|
6
|
+
isStoredValueEnvelope,
|
|
7
|
+
resolveStoredValue
|
|
8
|
+
} from "./chunk-ZMDB5KOK.js";
|
|
5
9
|
|
|
6
10
|
// src/cli.ts
|
|
7
11
|
import Redis from "ioredis";
|
|
@@ -65,6 +69,31 @@ async function main(argv = process.argv.slice(2)) {
|
|
|
65
69
|
`);
|
|
66
70
|
return;
|
|
67
71
|
}
|
|
72
|
+
if (args.command === "inspect") {
|
|
73
|
+
if (!args.key) {
|
|
74
|
+
throw new Error("inspect requires --key <key>.");
|
|
75
|
+
}
|
|
76
|
+
const payload = await redis.getBuffer(args.key);
|
|
77
|
+
const ttl = await redis.ttl(args.key);
|
|
78
|
+
const decoded = decodeInspectablePayload(payload);
|
|
79
|
+
process.stdout.write(
|
|
80
|
+
`${JSON.stringify(
|
|
81
|
+
{
|
|
82
|
+
key: args.key,
|
|
83
|
+
exists: payload !== null,
|
|
84
|
+
ttlSeconds: ttl >= 0 ? ttl : null,
|
|
85
|
+
sizeBytes: payload?.byteLength ?? 0,
|
|
86
|
+
isEnvelope: isStoredValueEnvelope(decoded),
|
|
87
|
+
state: payload === null ? null : resolveStoredValue(decoded).state,
|
|
88
|
+
preview: summarizeInspectableValue(decoded)
|
|
89
|
+
},
|
|
90
|
+
null,
|
|
91
|
+
2
|
|
92
|
+
)}
|
|
93
|
+
`
|
|
94
|
+
);
|
|
95
|
+
return;
|
|
96
|
+
}
|
|
68
97
|
printUsage();
|
|
69
98
|
process.exitCode = 1;
|
|
70
99
|
} catch (error) {
|
|
@@ -105,6 +134,9 @@ function parseArgs(argv) {
|
|
|
105
134
|
} else if (token === "--tag") {
|
|
106
135
|
parsed.tag = value;
|
|
107
136
|
index += 1;
|
|
137
|
+
} else if (token === "--key") {
|
|
138
|
+
parsed.key = value;
|
|
139
|
+
index += 1;
|
|
108
140
|
} else if (token === "--tag-index-prefix") {
|
|
109
141
|
parsed.tagIndexPrefix = value;
|
|
110
142
|
index += 1;
|
|
@@ -131,9 +163,32 @@ async function scanKeys(redis, pattern) {
|
|
|
131
163
|
}
|
|
132
164
|
function printUsage() {
|
|
133
165
|
process.stdout.write(
|
|
134
|
-
"Usage:\n layercache stats --redis <url> [--pattern <glob>]\n layercache keys --redis <url> [--pattern <glob>]\n layercache invalidate --redis <url> [--pattern <glob> | --tag <tag>] [--tag-index-prefix <prefix>]\n\nOptions:\n --redis <url> Redis connection URL (e.g. redis://localhost:6379)\n --pattern <glob> Glob pattern to filter keys (default: *)\n --tag <tag> Invalidate by tag name\n --tag-index-prefix <prefix> Redis key prefix for tag index (default: layercache:tag-index)\n"
|
|
166
|
+
"Usage:\n layercache stats --redis <url> [--pattern <glob>]\n layercache keys --redis <url> [--pattern <glob>]\n layercache inspect --redis <url> --key <key>\n layercache invalidate --redis <url> [--pattern <glob> | --tag <tag>] [--tag-index-prefix <prefix>]\n\nOptions:\n --redis <url> Redis connection URL (e.g. redis://localhost:6379)\n --pattern <glob> Glob pattern to filter keys (default: *)\n --key <key> Exact cache key to inspect\n --tag <tag> Invalidate by tag name\n --tag-index-prefix <prefix> Redis key prefix for tag index (default: layercache:tag-index)\n"
|
|
135
167
|
);
|
|
136
168
|
}
|
|
169
|
+
function decodeInspectablePayload(payload) {
|
|
170
|
+
if (payload === null) {
|
|
171
|
+
return null;
|
|
172
|
+
}
|
|
173
|
+
const text = payload.toString("utf8");
|
|
174
|
+
try {
|
|
175
|
+
return JSON.parse(text);
|
|
176
|
+
} catch {
|
|
177
|
+
return text.length > 256 ? `${text.slice(0, 256)}...` : text;
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
function summarizeInspectableValue(value) {
|
|
181
|
+
if (isStoredValueEnvelope(value)) {
|
|
182
|
+
return {
|
|
183
|
+
kind: value.kind,
|
|
184
|
+
value: value.value,
|
|
185
|
+
freshUntil: value.freshUntil,
|
|
186
|
+
staleUntil: value.staleUntil,
|
|
187
|
+
errorUntil: value.errorUntil
|
|
188
|
+
};
|
|
189
|
+
}
|
|
190
|
+
return value;
|
|
191
|
+
}
|
|
137
192
|
if (process.argv[1]?.includes("cli.")) {
|
|
138
193
|
void main();
|
|
139
194
|
}
|