@blaze-cache/core 0.4.0 → 0.5.0-beta.1
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 +31 -0
- package/dist/cache.d.ts +20 -0
- package/dist/cache.d.ts.map +1 -1
- package/dist/cache.js +149 -6
- package/dist/cache.js.map +1 -1
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/query.d.ts +102 -0
- package/dist/query.d.ts.map +1 -0
- package/dist/query.js +116 -0
- package/dist/query.js.map +1 -0
- package/dist/shared.d.ts +52 -0
- package/dist/shared.d.ts.map +1 -0
- package/dist/shared.js +100 -0
- package/dist/shared.js.map +1 -0
- package/dist/types.d.ts +14 -2
- package/dist/types.d.ts.map +1 -1
- package/package.json +5 -1
- package/pkg/blaze_cache_wasm.d.ts +33 -0
- package/pkg/blaze_cache_wasm.js +149 -0
- package/pkg/blaze_cache_wasm_bg.wasm +0 -0
- package/pkg/blaze_cache_wasm_bg.wasm.d.ts +5 -0
- package/pkg/package.json +1 -1
package/dist/query.d.ts
ADDED
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Types and small pure helpers for the opt-in indexed query API (0.5.0-beta.1).
|
|
3
|
+
*
|
|
4
|
+
* Query results are **metadata by default**. `includeValues: true` deliberately hands back
|
|
5
|
+
* the cache's live, by-reference values — the same contract as `get()` — and is only legal
|
|
6
|
+
* when both `maxEntries` and `maxValueBytes` caps are supplied. Devtools never exposes that
|
|
7
|
+
* mode to a UI; it summarizes the metadata instead.
|
|
8
|
+
*/
|
|
9
|
+
/** Metadata for one matching entry. Values are never included unless explicitly requested. */
|
|
10
|
+
export interface EntrySummary {
|
|
11
|
+
key: string;
|
|
12
|
+
/** Remaining TTL in ms, or `null` for a permanent entry. */
|
|
13
|
+
ttlMs: number | null;
|
|
14
|
+
tags: string[];
|
|
15
|
+
/** Approximate byte size when known; `0` for opaque externrefs without a size hint. */
|
|
16
|
+
size?: number;
|
|
17
|
+
}
|
|
18
|
+
/** A result row with a live, by-reference value. */
|
|
19
|
+
export interface QueryValueRow<V> extends EntrySummary {
|
|
20
|
+
value: V;
|
|
21
|
+
}
|
|
22
|
+
/** Tag constraints; all three lists are ANDed with the other filters. */
|
|
23
|
+
export interface QueryTagFilter {
|
|
24
|
+
/** Keep keys carrying at least one of these tags. */
|
|
25
|
+
any?: readonly string[];
|
|
26
|
+
/** Keep keys carrying every one of these tags. */
|
|
27
|
+
all?: readonly string[];
|
|
28
|
+
/** Drop keys carrying any of these tags. */
|
|
29
|
+
none?: readonly string[];
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Remaining-TTL window in milliseconds. Note this is the *expiry* filter — not the `ttlMs`
|
|
33
|
+
* write stamp and not `cache.ttl(key)`. A lower bound alone includes permanent entries
|
|
34
|
+
* (infinite TTL); an upper bound excludes them.
|
|
35
|
+
*/
|
|
36
|
+
export interface QueryTtlRange {
|
|
37
|
+
min?: number;
|
|
38
|
+
max?: number;
|
|
39
|
+
}
|
|
40
|
+
/** A bounded query. `limit` is required so no call can accidentally scan the whole cache. */
|
|
41
|
+
export interface QueryOptions {
|
|
42
|
+
prefix?: string;
|
|
43
|
+
tags?: QueryTagFilter;
|
|
44
|
+
ttlRange?: QueryTtlRange;
|
|
45
|
+
/** Optional allow-list: only these keys are considered. */
|
|
46
|
+
keys?: readonly string[];
|
|
47
|
+
/** Required page size (positive integer). */
|
|
48
|
+
limit: number;
|
|
49
|
+
/** Opaque last-key anchor from a previous page; survives deletion of the anchor key. */
|
|
50
|
+
cursor?: string;
|
|
51
|
+
/** Return live values. Requires `maxEntries` **and** `maxValueBytes`. Default `false`. */
|
|
52
|
+
includeValues?: boolean;
|
|
53
|
+
/** Hard cap on returned rows even when `limit` is larger. */
|
|
54
|
+
maxEntries?: number;
|
|
55
|
+
/** Hard cap on the estimated bytes of returned values. */
|
|
56
|
+
maxValueBytes?: number;
|
|
57
|
+
/** Post-filter over already-narrowed summaries; requires `fullScan` and no other constraint. */
|
|
58
|
+
where?: (summary: EntrySummary) => boolean;
|
|
59
|
+
/** Explicit, opt-in O(n) scan. Never implied: without `indexes: true`, `query()` throws. */
|
|
60
|
+
fullScan?: boolean;
|
|
61
|
+
/** Count all matches (a separate full pass). */
|
|
62
|
+
withTotal?: boolean;
|
|
63
|
+
}
|
|
64
|
+
/** One page of query results. */
|
|
65
|
+
export interface QueryResult<V = unknown> {
|
|
66
|
+
items: Array<EntrySummary | QueryValueRow<V>>;
|
|
67
|
+
/** Last key of this page when more matches follow; pass it back as `cursor`. */
|
|
68
|
+
nextCursor: string | null;
|
|
69
|
+
/** Present only when `withTotal` was requested. */
|
|
70
|
+
total?: number;
|
|
71
|
+
/**
|
|
72
|
+
* `true` when `maxEntries`/`maxValueBytes` cut this page short — matches exist beyond
|
|
73
|
+
* `items` that these caps prevented from being returned. Absent when the page is whole.
|
|
74
|
+
* A consumer that needs every row must raise the caps; it can never be inferred from
|
|
75
|
+
* `nextCursor` alone (a page can be both cap-truncated and last).
|
|
76
|
+
*/
|
|
77
|
+
truncated?: boolean;
|
|
78
|
+
}
|
|
79
|
+
/** The key-only counterpart of {@link QueryResult}. */
|
|
80
|
+
export interface QueryKeysResult {
|
|
81
|
+
keys: string[];
|
|
82
|
+
nextCursor: string | null;
|
|
83
|
+
total?: number;
|
|
84
|
+
}
|
|
85
|
+
/** The narrow shape devtools and other bounded consumers need from a cache. */
|
|
86
|
+
export interface QueryableCache<V = unknown> {
|
|
87
|
+
query(filter: QueryOptions): QueryResult<V>;
|
|
88
|
+
queryKeys(filter: QueryOptions): QueryKeysResult;
|
|
89
|
+
count(filter?: Omit<QueryOptions, 'limit' | 'cursor'>): number;
|
|
90
|
+
}
|
|
91
|
+
/** Validates the shared query contract. Throws synchronously so callers can catch setup errors. */
|
|
92
|
+
export declare function assertQueryOptions(filter: QueryOptions): void;
|
|
93
|
+
/** `true` when at least one index-backed constraint was supplied. */
|
|
94
|
+
export declare function hasIndexedConstraint(filter: QueryOptions): boolean;
|
|
95
|
+
/**
|
|
96
|
+
* Cheap, best-effort byte estimate used only for the `maxValueBytes` cap. JS object sizes
|
|
97
|
+
* are not observable; opaque externrefs report `0` here (tiered mode will require an
|
|
98
|
+
* explicit `sizeHint` for them). Never guesses at a cloned representation, and never
|
|
99
|
+
* throws: every object walk is fenced so a hostile stored value cannot break `query()`.
|
|
100
|
+
*/
|
|
101
|
+
export declare function estimateValueBytes(value: unknown, depth?: number): number;
|
|
102
|
+
//# sourceMappingURL=query.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"query.d.ts","sourceRoot":"","sources":["../src/query.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,8FAA8F;AAC9F,MAAM,WAAW,YAAY;IAC3B,GAAG,EAAE,MAAM,CAAC;IACZ,4DAA4D;IAC5D,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;IACrB,IAAI,EAAE,MAAM,EAAE,CAAC;IACf,uFAAuF;IACvF,IAAI,CAAC,EAAE,MAAM,CAAC;CACf;AAED,oDAAoD;AACpD,MAAM,WAAW,aAAa,CAAC,CAAC,CAAE,SAAQ,YAAY;IACpD,KAAK,EAAE,CAAC,CAAC;CACV;AAED,yEAAyE;AACzE,MAAM,WAAW,cAAc;IAC7B,qDAAqD;IACrD,GAAG,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;IACxB,kDAAkD;IAClD,GAAG,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;IACxB,4CAA4C;IAC5C,IAAI,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;CAC1B;AAED;;;;GAIG;AACH,MAAM,WAAW,aAAa;IAC5B,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,GAAG,CAAC,EAAE,MAAM,CAAC;CACd;AAED,6FAA6F;AAC7F,MAAM,WAAW,YAAY;IAC3B,MAAM,CAAC,EAAE,MAAM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e,CAAC;IACjD,KAAK,CAAC,MAAM,CAAC,EAAE,IAAI,CAAC,YAAY,EAAE,OAAO,GAAG,QAAQ,CAAC,GAAG,MAAM,CAAC;CAChE;AAED,mGAAmG;AACnG,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,YAAY,GAAG,IAAI,CA2C7D;AAED,qEAAqE;AACrE,wBAAgB,oBAAoB,CAAC,MAAM,EAAE,YAAY,GAAG,OAAO,CAUlE;AAKD;;;;;GAKG;AACH,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,OAAO,EAAE,KAAK,SAAI,GAAG,MAAM,CA+CpE"}
|
package/dist/query.js
ADDED
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Types and small pure helpers for the opt-in indexed query API (0.5.0-beta.1).
|
|
3
|
+
*
|
|
4
|
+
* Query results are **metadata by default**. `includeValues: true` deliberately hands back
|
|
5
|
+
* the cache's live, by-reference values — the same contract as `get()` — and is only legal
|
|
6
|
+
* when both `maxEntries` and `maxValueBytes` caps are supplied. Devtools never exposes that
|
|
7
|
+
* mode to a UI; it summarizes the metadata instead.
|
|
8
|
+
*/
|
|
9
|
+
/** Validates the shared query contract. Throws synchronously so callers can catch setup errors. */
|
|
10
|
+
export function assertQueryOptions(filter) {
|
|
11
|
+
if (!Number.isInteger(filter.limit) || filter.limit < 1) {
|
|
12
|
+
throw new RangeError('[blaze-cache] query() requires a positive integer `limit`.');
|
|
13
|
+
}
|
|
14
|
+
if (filter.maxEntries !== undefined &&
|
|
15
|
+
(!Number.isInteger(filter.maxEntries) || filter.maxEntries < 1)) {
|
|
16
|
+
throw new RangeError('[blaze-cache] `maxEntries` must be a positive integer when supplied (it bounds a page, so 0 would never make progress).');
|
|
17
|
+
}
|
|
18
|
+
if (filter.maxValueBytes !== undefined &&
|
|
19
|
+
(!Number.isFinite(filter.maxValueBytes) || filter.maxValueBytes < 0)) {
|
|
20
|
+
throw new RangeError('[blaze-cache] `maxValueBytes` must be a finite, non-negative number.');
|
|
21
|
+
}
|
|
22
|
+
if (filter.includeValues) {
|
|
23
|
+
if (!Number.isFinite(filter.maxEntries) ||
|
|
24
|
+
filter.maxEntries < 1 ||
|
|
25
|
+
!Number.isFinite(filter.maxValueBytes) ||
|
|
26
|
+
filter.maxValueBytes < 0) {
|
|
27
|
+
throw new TypeError('[blaze-cache] includeValues: true requires finite `maxEntries` and `maxValueBytes` caps.');
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
if (filter.where && !filter.fullScan) {
|
|
31
|
+
throw new TypeError('[blaze-cache] `where` requires `fullScan: true` with no indexed constraint.');
|
|
32
|
+
}
|
|
33
|
+
// `cursor` is deliberately absent: a full scan *can* resume from an anchor (it just
|
|
34
|
+
// costs O(n) per page, which `fullScan: true` already declared). The constraints below
|
|
35
|
+
// are the ones a full scan would silently *ignore* — those are what makes it a guard.
|
|
36
|
+
if (filter.fullScan && hasIndexedConstraint({ ...filter, cursor: undefined })) {
|
|
37
|
+
throw new TypeError('[blaze-cache] `fullScan: true` cannot be combined with prefix/tags/ttlRange/keys.');
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
/** `true` when at least one index-backed constraint was supplied. */
|
|
41
|
+
export function hasIndexedConstraint(filter) {
|
|
42
|
+
return (filter.prefix !== undefined ||
|
|
43
|
+
filter.tags?.any !== undefined ||
|
|
44
|
+
filter.tags?.all !== undefined ||
|
|
45
|
+
filter.tags?.none !== undefined ||
|
|
46
|
+
filter.ttlRange !== undefined ||
|
|
47
|
+
filter.keys !== undefined ||
|
|
48
|
+
filter.cursor !== undefined);
|
|
49
|
+
}
|
|
50
|
+
/** Walk ceiling for an object/array estimate — the value is a cheap hint, not an audit. */
|
|
51
|
+
const HARD_BYTE_CAP = 64 * 1024;
|
|
52
|
+
/**
|
|
53
|
+
* Cheap, best-effort byte estimate used only for the `maxValueBytes` cap. JS object sizes
|
|
54
|
+
* are not observable; opaque externrefs report `0` here (tiered mode will require an
|
|
55
|
+
* explicit `sizeHint` for them). Never guesses at a cloned representation, and never
|
|
56
|
+
* throws: every object walk is fenced so a hostile stored value cannot break `query()`.
|
|
57
|
+
*/
|
|
58
|
+
export function estimateValueBytes(value, depth = 0) {
|
|
59
|
+
if (depth > 4)
|
|
60
|
+
return 0;
|
|
61
|
+
if (typeof value === 'string')
|
|
62
|
+
return value.length * 2;
|
|
63
|
+
if (typeof value === 'number')
|
|
64
|
+
return 8;
|
|
65
|
+
if (typeof value === 'boolean')
|
|
66
|
+
return 4;
|
|
67
|
+
if (typeof value === 'bigint')
|
|
68
|
+
return 8;
|
|
69
|
+
if (value === null || value === undefined)
|
|
70
|
+
return 0;
|
|
71
|
+
if (value instanceof ArrayBuffer || ArrayBuffer.isView(value)) {
|
|
72
|
+
return value.byteLength;
|
|
73
|
+
}
|
|
74
|
+
// Every object walk below is fenced: a stored Proxy with a throwing `ownKeys`/`get`
|
|
75
|
+
// trap must not be able to throw out of `query()`. The estimate is best-effort by
|
|
76
|
+
// contract, so an unmeasurable value simply counts as 0.
|
|
77
|
+
if (Array.isArray(value)) {
|
|
78
|
+
let bytes = 0;
|
|
79
|
+
for (let i = 0; i < value.length && bytes < HARD_BYTE_CAP; i += 1) {
|
|
80
|
+
let item;
|
|
81
|
+
try {
|
|
82
|
+
item = value[i];
|
|
83
|
+
}
|
|
84
|
+
catch {
|
|
85
|
+
continue;
|
|
86
|
+
}
|
|
87
|
+
bytes += estimateValueBytes(item, depth + 1);
|
|
88
|
+
}
|
|
89
|
+
return bytes;
|
|
90
|
+
}
|
|
91
|
+
if (typeof value === 'object') {
|
|
92
|
+
let keys;
|
|
93
|
+
try {
|
|
94
|
+
keys = Object.keys(value);
|
|
95
|
+
}
|
|
96
|
+
catch {
|
|
97
|
+
return 0;
|
|
98
|
+
}
|
|
99
|
+
let bytes = 0;
|
|
100
|
+
for (const key of keys) {
|
|
101
|
+
if (bytes > HARD_BYTE_CAP)
|
|
102
|
+
break;
|
|
103
|
+
let property;
|
|
104
|
+
try {
|
|
105
|
+
property = value[key];
|
|
106
|
+
}
|
|
107
|
+
catch {
|
|
108
|
+
continue;
|
|
109
|
+
}
|
|
110
|
+
bytes += key.length * 2 + estimateValueBytes(property, depth + 1);
|
|
111
|
+
}
|
|
112
|
+
return bytes;
|
|
113
|
+
}
|
|
114
|
+
return 0;
|
|
115
|
+
}
|
|
116
|
+
//# sourceMappingURL=query.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"query.js","sourceRoot":"","sources":["../src/query.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AA4FH,mGAAmG;AACnG,MAAM,UAAU,kBAAkB,CAAC,MAAoB;IACrD,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,MAAM,CAAC,KAAK,GAAG,CAAC,EAAE,CAAC;QACxD,MAAM,IAAI,UAAU,CAAC,4DAA4D,CAAC,CAAC;IACrF,CAAC;IACD,IACE,MAAM,CAAC,UAAU,KAAK,SAAS;QAC/B,CAAC,CAAC,MAAM,CAAC,SAAS,CAAC,MAAM,CAAC,UAAU,CAAC,IAAI,MAAM,CAAC,UAAU,GAAG,CAAC,CAAC,EAC/D,CAAC;QACD,MAAM,IAAI,UAAU,CAClB,yHAAyH,CAC1H,CAAC;IACJ,CAAC;IACD,IACE,MAAM,CAAC,aAAa,KAAK,SAAS;QAClC,CAAC,CAAC,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC,aAAa,CAAC,IAAI,MAAM,CAAC,aAAa,GAAG,CAAC,CAAC,EACpE,CAAC;QACD,MAAM,IAAI,UAAU,CAAC,sEAAsE,CAAC,CAAC;IAC/F,CAAC;IACD,IAAI,MAAM,CAAC,aAAa,EAAE,CAAC;QACzB,IACE,CAAC,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC,UAAU,CAAC;YAClC,MAAM,CAAC,UAAqB,GAAG,CAAC;YACjC,CAAC,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC,aAAa,CAA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AAI,CAAC;gBACH,QAAQ,GAAI,KAAiC,CAAC,GAAG,CAAC,CAAC;YACrD,CAAC;YAAC,MAAM,CAAC;gBACP,SAAS;YACX,CAAC;YACD,KAAK,IAAI,GAAG,CAAC,MAAM,GAAG,CAAC,GAAG,kBAAkB,CAAC,QAAQ,EAAE,KAAK,GAAG,CAAC,CAAC,CAAC;QACpE,CAAC;QACD,OAAO,KAAK,CAAC;IACf,CAAC;IACD,OAAO,CAAC,CAAC;AACX,CAAC"}
|
package/dist/shared.d.ts
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The wasm-free, server-safe contract shared by Blaze Cache bindings, devtools and
|
|
3
|
+
* snapshot bridges.
|
|
4
|
+
*
|
|
5
|
+
* This module deliberately imports nothing from `./cache.js`, `./wasm.js` or any other
|
|
6
|
+
* module that touches WebAssembly, IndexedDB or the DOM. It is safe to import from a
|
|
7
|
+
* Node server, a server-rendering bundle, or a snapshot serialiser. Its shapes are
|
|
8
|
+
* **frozen here in 0.5.0-beta.1**: later releases import them rather than redefining
|
|
9
|
+
* them, so a devtools summary and a binding write can never drift apart.
|
|
10
|
+
*
|
|
11
|
+
* @packageDocumentation
|
|
12
|
+
*/
|
|
13
|
+
/**
|
|
14
|
+
* Default key patterns that mark a cache entry as sensitive. Keys are matched
|
|
15
|
+
* case-insensitively against the whole key; a match means "never display this value".
|
|
16
|
+
*
|
|
17
|
+
* These live here — not in devtools — so server snapshots and framework bindings can
|
|
18
|
+
* apply the same deny-by-default policy without importing the browser runtime.
|
|
19
|
+
*/
|
|
20
|
+
export declare const REDACT_KEY_PATTERNS: readonly RegExp[];
|
|
21
|
+
/** `true` when `key` matches any of `patterns` (defaults to {@link REDACT_KEY_PATTERNS}). */
|
|
22
|
+
export declare function isRedactedKey(key: string, patterns?: readonly RegExp[]): boolean;
|
|
23
|
+
/** Replaces a sensitive key with an opaque marker. */
|
|
24
|
+
export declare function redactKey(key: string, patterns?: readonly RegExp[], replacement?: string): string;
|
|
25
|
+
/**
|
|
26
|
+
* The record envelope written by framework bindings. `kind` follows the
|
|
27
|
+
* `<binding>:<feature>` convention (e.g. `next:route`); `v` is the envelope version,
|
|
28
|
+
* guard-tested as *any finite number* so older and newer records stay recognisable.
|
|
29
|
+
*/
|
|
30
|
+
export interface BlazeRecord<V = unknown> {
|
|
31
|
+
kind: string;
|
|
32
|
+
v: number;
|
|
33
|
+
data: V;
|
|
34
|
+
/** `Date.now()` at write time, used by restore logic to break ties. */
|
|
35
|
+
storedAt: number;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Duck-typed, version-tolerant guard for {@link BlazeRecord}. It deliberately does not
|
|
39
|
+
* inspect `data` (which may be any value) and does not require a specific `v`, so a
|
|
40
|
+
* record written by a future binding is still recognised and summarised as a record
|
|
41
|
+
* instead of being expanded into the devtools UI.
|
|
42
|
+
*/
|
|
43
|
+
export declare function isBlazeRecord(value: unknown): value is BlazeRecord<unknown>;
|
|
44
|
+
/** The separator in the `<binding>:<feature>` kind convention. */
|
|
45
|
+
export declare const KIND_SEPARATOR = ":";
|
|
46
|
+
/** Builds a namespaced kind (e.g. `makeBlazeKind('next', 'route')` → `next:route`). */
|
|
47
|
+
export declare function makeBlazeKind(binding: string, feature: string): string;
|
|
48
|
+
/** The framework prefix of a kind, or `undefined` when it does not follow the convention. */
|
|
49
|
+
export declare function bindingFromKind(kind: string): string | undefined;
|
|
50
|
+
/** The feature suffix of a kind, or `undefined` when it does not follow the convention. */
|
|
51
|
+
export declare function featureFromKind(kind: string): string | undefined;
|
|
52
|
+
//# sourceMappingURL=shared.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"shared.d.ts","sourceRoot":"","sources":["../src/shared.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH;;;;;;GAMG;AACH,eAAO,MAAM,mBAAmB,EAAE,SAAS,MAAM,EAU/C,CAAC;AAEH,6FAA6F;AAC7F,wBAAgB,aAAa,CAC3B,GAAG,EAAE,MAAM,EACX,QAAQ,GAAE,SAAS,MAAM,EAAwB,GAChD,OAAO,CAsBT;AAED,sDAAsD;AACtD,wBAAgB,SAAS,CACvB,GAAG,EAAE,MAAM,EACX,QAAQ,GAAE,SAAS,MAAM,EAAwB,EACjD,WAAW,SAAe,GACzB,MAAM,CAER;AAED;;;;GAIG;AACH,MAAM,WAAW,WAAW,CAAC,CAAC,GAAG,OAAO;IACtC,IAAI,EAAE,MAAM,CAAC;IACb,CAAC,EAAE,MAAM,CAAC;IACV,IAAI,EAAE,CAAC,CAAC;IACR,uEAAuE;IACvE,QAAQ,EAAE,MAAM,CAAC;CAClB;AAED;;;;;GAKG;AACH,wBAAgB,aAAa,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,WAAW,CAAC,OAAO,CAAC,CAY3E;AAED,kEAAkE;AAClE,eAAO,MAAM,cAAc,MAAM,CAAC;AAElC,uFAAuF;AACvF,wBAAgB,aAAa,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,MAAM,CAEtE;AAED,6FAA6F;AAC7F,wBAAgB,eAAe,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAIhE;AAED,2FAA2F;AAC3F,wBAAgB,eAAe,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAIhE"}
|
package/dist/shared.js
ADDED
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The wasm-free, server-safe contract shared by Blaze Cache bindings, devtools and
|
|
3
|
+
* snapshot bridges.
|
|
4
|
+
*
|
|
5
|
+
* This module deliberately imports nothing from `./cache.js`, `./wasm.js` or any other
|
|
6
|
+
* module that touches WebAssembly, IndexedDB or the DOM. It is safe to import from a
|
|
7
|
+
* Node server, a server-rendering bundle, or a snapshot serialiser. Its shapes are
|
|
8
|
+
* **frozen here in 0.5.0-beta.1**: later releases import them rather than redefining
|
|
9
|
+
* them, so a devtools summary and a binding write can never drift apart.
|
|
10
|
+
*
|
|
11
|
+
* @packageDocumentation
|
|
12
|
+
*/
|
|
13
|
+
/**
|
|
14
|
+
* Default key patterns that mark a cache entry as sensitive. Keys are matched
|
|
15
|
+
* case-insensitively against the whole key; a match means "never display this value".
|
|
16
|
+
*
|
|
17
|
+
* These live here — not in devtools — so server snapshots and framework bindings can
|
|
18
|
+
* apply the same deny-by-default policy without importing the browser runtime.
|
|
19
|
+
*/
|
|
20
|
+
export const REDACT_KEY_PATTERNS = Object.freeze([
|
|
21
|
+
/authorization/i,
|
|
22
|
+
/token/i,
|
|
23
|
+
/cookie/i,
|
|
24
|
+
/credential/i,
|
|
25
|
+
/password/i,
|
|
26
|
+
/passwd/i,
|
|
27
|
+
/secret/i,
|
|
28
|
+
/api[-_]?key/i,
|
|
29
|
+
/session/i,
|
|
30
|
+
]);
|
|
31
|
+
/** `true` when `key` matches any of `patterns` (defaults to {@link REDACT_KEY_PATTERNS}). */
|
|
32
|
+
export function isRedactedKey(key, patterns = REDACT_KEY_PATTERNS) {
|
|
33
|
+
for (let i = 0; i < patterns.length; i += 1) {
|
|
34
|
+
const pattern = patterns[i];
|
|
35
|
+
try {
|
|
36
|
+
// A pattern with the global/sticky flag is stateful; reset before testing so a
|
|
37
|
+
// caller-supplied pattern cannot make redaction alternate between calls. A frozen
|
|
38
|
+
// pattern rejects the write — harmless for a non-stateful one, whose `test` never
|
|
39
|
+
// reads `lastIndex`, so it must keep working rather than over-redact everything.
|
|
40
|
+
try {
|
|
41
|
+
pattern.lastIndex = 0;
|
|
42
|
+
}
|
|
43
|
+
catch {
|
|
44
|
+
// Frozen: fall through and let `test` decide.
|
|
45
|
+
}
|
|
46
|
+
if (pattern.test(key))
|
|
47
|
+
return true;
|
|
48
|
+
}
|
|
49
|
+
catch {
|
|
50
|
+
// Deny by default: a pattern that cannot be evaluated — a frozen *global* one (its
|
|
51
|
+
// `test` rewrites the frozen `lastIndex`), a hostile `test`, a non-regexp entry —
|
|
52
|
+
// must neither throw into the host nor silently disable redaction.
|
|
53
|
+
return true;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
return false;
|
|
57
|
+
}
|
|
58
|
+
/** Replaces a sensitive key with an opaque marker. */
|
|
59
|
+
export function redactKey(key, patterns = REDACT_KEY_PATTERNS, replacement = '[redacted]') {
|
|
60
|
+
return isRedactedKey(key, patterns) ? replacement : key;
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Duck-typed, version-tolerant guard for {@link BlazeRecord}. It deliberately does not
|
|
64
|
+
* inspect `data` (which may be any value) and does not require a specific `v`, so a
|
|
65
|
+
* record written by a future binding is still recognised and summarised as a record
|
|
66
|
+
* instead of being expanded into the devtools UI.
|
|
67
|
+
*/
|
|
68
|
+
export function isBlazeRecord(value) {
|
|
69
|
+
if (value === null || typeof value !== 'object')
|
|
70
|
+
return false;
|
|
71
|
+
const record = value;
|
|
72
|
+
return (typeof record.kind === 'string' &&
|
|
73
|
+
record.kind.length > 0 &&
|
|
74
|
+
typeof record.v === 'number' &&
|
|
75
|
+
Number.isFinite(record.v) &&
|
|
76
|
+
typeof record.storedAt === 'number' &&
|
|
77
|
+
Number.isFinite(record.storedAt) &&
|
|
78
|
+
Object.prototype.hasOwnProperty.call(record, 'data'));
|
|
79
|
+
}
|
|
80
|
+
/** The separator in the `<binding>:<feature>` kind convention. */
|
|
81
|
+
export const KIND_SEPARATOR = ':';
|
|
82
|
+
/** Builds a namespaced kind (e.g. `makeBlazeKind('next', 'route')` → `next:route`). */
|
|
83
|
+
export function makeBlazeKind(binding, feature) {
|
|
84
|
+
return `${binding}${KIND_SEPARATOR}${feature}`;
|
|
85
|
+
}
|
|
86
|
+
/** The framework prefix of a kind, or `undefined` when it does not follow the convention. */
|
|
87
|
+
export function bindingFromKind(kind) {
|
|
88
|
+
const index = kind.indexOf(KIND_SEPARATOR);
|
|
89
|
+
if (index <= 0 || index === kind.length - 1)
|
|
90
|
+
return undefined;
|
|
91
|
+
return kind.slice(0, index);
|
|
92
|
+
}
|
|
93
|
+
/** The feature suffix of a kind, or `undefined` when it does not follow the convention. */
|
|
94
|
+
export function featureFromKind(kind) {
|
|
95
|
+
const index = kind.indexOf(KIND_SEPARATOR);
|
|
96
|
+
if (index <= 0 || index === kind.length - 1)
|
|
97
|
+
return undefined;
|
|
98
|
+
return kind.slice(index + 1);
|
|
99
|
+
}
|
|
100
|
+
//# sourceMappingURL=shared.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"shared.js","sourceRoot":"","sources":["../src/shared.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,mBAAmB,GAAsB,MAAM,CAAC,MAAM,CAAC;IAClE,gBAAgB;IAChB,QAAQ;IACR,SAAS;IACT,aAAa;IACb,WAAW;IACX,SAAS;IACT,SAAS;IACT,cAAc;IACd,UAAU;CACX,CAAC,CAAC;AAEH,6FAA6F;AAC7F,MAAM,UAAU,aAAa,CAC3B,GAAW,EACX,QAAQ,GAAsB,mBAAmB;IAEjD,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,QAAQ,CAAC,MAAM,EAAE,CAAC,IAAI,CAAC,EAAE,CAAC;QAC5C,MAAM,OAAO,GAAG,QAAQ,CAAC,CAAC,CAAE,CAAC;QAC7B,IAAI,CAAC;YACH,+EAA+E;YAC/E,kFAAkF;YAClF,kFAAkF;YAClF,iFAAiF;YACjF,IAAI,CAAC;gBACH,OAAO,CAAC,SAAS,GAAG,CAAC,CAAC;YACxB,CAAC;YAAC,MAAM,CAAC;gBACP,8CAA8C;YAChD,CAAC;YACD,IAAI,OAAO,CAAC,IAAI,CAAC,GAAG,CAAC;gBAAE,OAAO,IAAI,CAAC;QACrC,CAAC;QAAC,MAAM,CAAC;YACP,mFAAmF;YACnF,kFAAkF;YAClF,mEAAmE;YACnE,OAAO,IAAI,CAAC;QACd,CAAC;IACH,CAA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;QAAE,OAAO,SAAS,CAAC;IAC9D,OAAO,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC;AAC9B,CAAC;AAED,2FAA2F;AAC3F,MAAM,UAAU,eAAe,CAAC,IAAY;IAC1C,MAAM,KAAK,GAAG,IAAI,CAAC,OAAO,CAAC,cAAc,CAAC,CAAC;IAC3C,IAAI,KAAK,IAAI,CAAC,IAAI,KAAK,KAAK,IAAI,CAAC,MAAM,GAAG,CAAC;QAAE,OAAO,SAAS,CAAC;IAC9D,OAAO,IAAI,CAAC,KAAK,CAAC,KAAK,GAAG,CAAC,CAAC,CAAC;AAC/B,CAAC"}
|
package/dist/types.d.ts
CHANGED
|
@@ -80,9 +80,12 @@ export type CacheChange = {
|
|
|
80
80
|
key: string;
|
|
81
81
|
} | {
|
|
82
82
|
type: 'clear';
|
|
83
|
-
}
|
|
83
|
+
}
|
|
84
|
+
/** `tags` is additive (0.5.0): the entries are gone, so `tagsOf(key)` cannot recover them. */
|
|
85
|
+
| {
|
|
84
86
|
type: 'invalidate';
|
|
85
87
|
keys: string[];
|
|
88
|
+
tags: string[];
|
|
86
89
|
} | {
|
|
87
90
|
type: 'prune';
|
|
88
91
|
keys: string[];
|
|
@@ -141,9 +144,14 @@ export interface CacheEventMap<V = any> {
|
|
|
141
144
|
clear: {
|
|
142
145
|
type: 'clear';
|
|
143
146
|
};
|
|
147
|
+
/**
|
|
148
|
+
* Tags are included since 0.5.0: listeners run after the entries were removed, so the
|
|
149
|
+
* original tag list cannot be recovered from `tagsOf(key)` any more.
|
|
150
|
+
*/
|
|
144
151
|
invalidate: {
|
|
145
152
|
type: 'invalidate';
|
|
146
153
|
keys: string[];
|
|
154
|
+
tags: string[];
|
|
147
155
|
};
|
|
148
156
|
prune: {
|
|
149
157
|
type: 'prune';
|
|
@@ -191,7 +199,11 @@ export interface CacheEventMap<V = any> {
|
|
|
191
199
|
'remote-clear': {
|
|
192
200
|
type: 'remote-clear';
|
|
193
201
|
};
|
|
194
|
-
/**
|
|
202
|
+
/**
|
|
203
|
+
* A remote tab invalidated one or more tags. **Keyless by design:** an unknown or
|
|
204
|
+
* keyless `remote-invalidate` means "broad revalidate — anything may have changed",
|
|
205
|
+
* so subscribers must re-read rather than assume a specific set of keys disappeared.
|
|
206
|
+
*/
|
|
195
207
|
'remote-invalidate': {
|
|
196
208
|
type: 'remote-invalidate';
|
|
197
209
|
};
|
package/dist/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,WAAW,UAAU;IACzB;;;;;;OAMG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,iEAAiE;IACjE,IAAI,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;CAC1B;AAED;;GAEG;AACH,MAAM,WAAW,YAAY,CAAC,CAAC,GAAG,GAAG;IACnC,GAAG,EAAE,MAAM,CAAC;IACZ,KAAK,EAAE,CAAC,CAAC;IACT,OAAO,CAAC,EAAE,UAAU,CAAC;CACtB;AAED;;GAEG;AACH,MAAM,WAAW,YAAY;IAC3B;;;;;;OAMG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED;;;;;GAKG;AACH,MAAM,WAAW,UAAU;IACzB,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,MAAM,CAAC;IACf,SAAS,EAAE,MAAM,CAAC;IAClB,WAAW,EAAE,MAAM,CAAC;IACpB,aAAa,EAAE,MAAM,CAAC;IACtB,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,MAAM,CAAC;IACjB,uEAAuE;IACvE,OAAO,EAAE,MAAM,CAAC;CACjB;AAED;;GAEG;AACH,MAAM,WAAW,UAAU,CAAC,CAAC,GAAG,OAAO;IACrC,GAAG,EAAE,MAAM,CAAC;IACZ,KAAK,EAAE,CAAC,CAAC;IACT,wEAAwE;IACxE,KAAK,EA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0.5.0-beta.1",
|
|
4
4
|
"description": "WebAssembly client-side cache for the browser: SIEVE eviction, per-entry TTLs, tag invalidation and optional IndexedDB persistence",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"cache",
|
|
@@ -37,6 +37,10 @@
|
|
|
37
37
|
"types": "./dist/wasm.d.ts",
|
|
38
38
|
"import": "./dist/wasm.js"
|
|
39
39
|
},
|
|
40
|
+
"./shared": {
|
|
41
|
+
"types": "./dist/shared.d.ts",
|
|
42
|
+
"import": "./dist/shared.js"
|
|
43
|
+
},
|
|
40
44
|
"./pkg/*": "./pkg/*"
|
|
41
45
|
},
|
|
42
46
|
"files": [
|
|
@@ -59,6 +59,11 @@ export class BlazeCache {
|
|
|
59
59
|
* release it entails — is completely absent from the default hot path.
|
|
60
60
|
*/
|
|
61
61
|
enableIds(): void;
|
|
62
|
+
/**
|
|
63
|
+
* Turns on the ordered key, expiry and tag query indexes, backfilling any existing
|
|
64
|
+
* entries. A no-op when already enabled; the default cache never allocates them.
|
|
65
|
+
*/
|
|
66
|
+
enableIndexes(): void;
|
|
62
67
|
/**
|
|
63
68
|
* Metadata for every live entry with its stable id, for `entries()` in JS mode.
|
|
64
69
|
*/
|
|
@@ -144,6 +149,10 @@ export class BlazeCache {
|
|
|
144
149
|
* `true` when `key` is present and not expired. Does not affect eviction state.
|
|
145
150
|
*/
|
|
146
151
|
has(key: string): boolean;
|
|
152
|
+
/**
|
|
153
|
+
* `true` once the query indexes are live.
|
|
154
|
+
*/
|
|
155
|
+
indexesEnabled(): boolean;
|
|
147
156
|
/**
|
|
148
157
|
* Removes every entry carrying any of `tags`, returning the removed keys so the host can
|
|
149
158
|
* drop them from its persistence layer.
|
|
@@ -188,6 +197,20 @@ export class BlazeCache {
|
|
|
188
197
|
* Removes every expired entry, returning the removed keys.
|
|
189
198
|
*/
|
|
190
199
|
prune(): string[];
|
|
200
|
+
/**
|
|
201
|
+
* Number of matching entries, ignoring paging. Also guarded by the indexes setup check.
|
|
202
|
+
*/
|
|
203
|
+
queryCount(prefix: string | null | undefined, tags_any: string[], tags_all: string[], tags_none: string[], ttl_min_ms?: number | null, ttl_max_ms?: number | null, keys?: string[] | null): number;
|
|
204
|
+
/**
|
|
205
|
+
* Runs a bounded, metadata-only query. Returns
|
|
206
|
+
* `{ rows: [{ key, ttlMs, tags }], nextCursor, total }` or throws a setup error when
|
|
207
|
+
* indexes were never enabled. Values are deliberately absent: the host fetches them
|
|
208
|
+
* separately (and caps them) only when `includeValues` was requested.
|
|
209
|
+
*
|
|
210
|
+
* Every offset is passed through safe helpers — there are no raw pointers here and both
|
|
211
|
+
* crates remain `forbid(unsafe_code)`.
|
|
212
|
+
*/
|
|
213
|
+
queryKeys(prefix: string | null | undefined, tags_any: string[], tags_all: string[], tags_none: string[], ttl_min_ms: number | null | undefined, ttl_max_ms: number | null | undefined, keys: string[] | null | undefined, limit: number, cursor: string | null | undefined, with_total: boolean): any;
|
|
191
214
|
/**
|
|
192
215
|
* Counts a miss for an absent key that was resolved locally, with no wasm lookup.
|
|
193
216
|
*/
|
|
@@ -284,6 +307,11 @@ export class BlazeCache {
|
|
|
284
307
|
* Counters: `{ hits, misses, evictions, expirations, invalidations, size, capacity }`.
|
|
285
308
|
*/
|
|
286
309
|
stats(): any;
|
|
310
|
+
/**
|
|
311
|
+
* Resolves tag names to interned numeric ids, for hosts that want to pass ids to
|
|
312
|
+
* `queryKeys`. Unknown names map to `u32::MAX`.
|
|
313
|
+
*/
|
|
314
|
+
tagIds(tags: string[]): Uint32Array;
|
|
287
315
|
/**
|
|
288
316
|
* Tags currently attached to `key` (empty array when the key is unknown).
|
|
289
317
|
*/
|
|
@@ -350,6 +378,7 @@ export interface InitOutput {
|
|
|
350
378
|
readonly blazecache_drainDrops: (a: number) => any;
|
|
351
379
|
readonly blazecache_dropTracking: (a: number) => number;
|
|
352
380
|
readonly blazecache_enableIds: (a: number) => void;
|
|
381
|
+
readonly blazecache_enableIndexes: (a: number) => void;
|
|
353
382
|
readonly blazecache_entries: (a: number) => any;
|
|
354
383
|
readonly blazecache_entriesMeta: (a: number) => any;
|
|
355
384
|
readonly blazecache_entry: (a: number, b: number, c: number) => any;
|
|
@@ -364,6 +393,7 @@ export interface InitOutput {
|
|
|
364
393
|
readonly blazecache_hasById: (a: number, b: number) => number;
|
|
365
394
|
readonly blazecache_hasMany: (a: number, b: number, c: number, d: number) => void;
|
|
366
395
|
readonly blazecache_hasTag: (a: number, b: number, c: number, d: number, e: number) => number;
|
|
396
|
+
readonly blazecache_indexesEnabled: (a: number) => number;
|
|
367
397
|
readonly blazecache_invalidateTags: (a: number, b: number, c: number, d: number) => void;
|
|
368
398
|
readonly blazecache_keys: (a: number, b: number) => void;
|
|
369
399
|
readonly blazecache_keysWithTag: (a: number, b: number, c: number, d: number) => void;
|
|
@@ -371,6 +401,8 @@ export interface InitOutput {
|
|
|
371
401
|
readonly blazecache_peek: (a: number, b: number, c: number) => any;
|
|
372
402
|
readonly blazecache_peekById: (a: number, b: number) => number;
|
|
373
403
|
readonly blazecache_prune: (a: number, b: number) => void;
|
|
404
|
+
readonly blazecache_queryCount: (a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number, i: number, j: number, k: number, l: number, m: number, n: number, o: number, p: number) => void;
|
|
405
|
+
readonly blazecache_queryKeys: (a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number, i: number, j: number, k: number, l: number, m: number, n: number, o: number, p: number, q: number, r: number, s: number, t: number) => void;
|
|
374
406
|
readonly blazecache_recordMiss: (a: number) => void;
|
|
375
407
|
readonly blazecache_resetStats: (a: number) => void;
|
|
376
408
|
readonly blazecache_set: (a: number, b: number, c: number, d: any, e: number, f: number, g: number, h: number) => void;
|
|
@@ -385,6 +417,7 @@ export interface InitOutput {
|
|
|
385
417
|
readonly blazecache_setRawWithTags: (a: number, b: number, c: number, d: any, e: number, f: number, g: number, h: number, i: number, j: number) => number;
|
|
386
418
|
readonly blazecache_size: (a: number) => number;
|
|
387
419
|
readonly blazecache_stats: (a: number, b: number) => void;
|
|
420
|
+
readonly blazecache_tagIds: (a: number, b: number, c: number, d: number) => void;
|
|
388
421
|
readonly blazecache_tagsOf: (a: number, b: number, c: number, d: number) => void;
|
|
389
422
|
readonly blazecache_touch: (a: number, b: number, c: number, d: number, e: number) => number;
|
|
390
423
|
readonly blazecache_ttl: (a: number, b: number, c: number, d: number) => void;
|