@blaze-cache/core 0.4.0-beta.2 → 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 +131 -44
- package/dist/cache.d.ts +67 -0
- package/dist/cache.d.ts.map +1 -1
- package/dist/cache.js +608 -28
- package/dist/cache.js.map +1 -1
- package/dist/events.d.ts.map +1 -1
- package/dist/events.js.map +1 -1
- package/dist/index.d.ts +8 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +5 -3
- package/dist/index.js.map +1 -1
- package/dist/multitab.d.ts +140 -0
- package/dist/multitab.d.ts.map +1 -0
- package/dist/multitab.js +306 -0
- package/dist/multitab.js.map +1 -0
- package/dist/persistence/indexeddb.d.ts.map +1 -1
- package/dist/persistence/indexeddb.js +8 -2
- package/dist/persistence/indexeddb.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/reactivity.d.ts.map +1 -1
- 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 +48 -3
- package/dist/types.d.ts.map +1 -1
- package/dist/utils.d.ts +16 -0
- package/dist/utils.d.ts.map +1 -1
- package/dist/utils.js +31 -0
- package/dist/utils.js.map +1 -1
- package/dist/wasm.d.ts +38 -0
- package/dist/wasm.d.ts.map +1 -1
- package/dist/wasm.js +189 -5
- package/dist/wasm.js.map +1 -1
- package/package.json +6 -2
- package/pkg/blaze_cache_wasm.d.ts +157 -0
- package/pkg/blaze_cache_wasm.js +460 -0
- package/pkg/blaze_cache_wasm_bg.wasm +0 -0
- package/pkg/blaze_cache_wasm_bg.wasm.d.ts +23 -0
- package/pkg/package.json +1 -1
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;;;;;;;;;;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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[];
|
|
@@ -106,7 +109,17 @@ export type CacheChange = {
|
|
|
106
109
|
* `evict` and `expire` are produced by the Rust/Wasm core itself — see *Events* on
|
|
107
110
|
* {@link BlazeCache}.
|
|
108
111
|
*/
|
|
109
|
-
export type CacheEventType = 'set' | 'delete' | 'clear' | 'invalidate' | 'prune' | 'touch' | 'evict' | 'expire' | 'hit' | 'miss'
|
|
112
|
+
export type CacheEventType = 'set' | 'delete' | 'clear' | 'invalidate' | 'prune' | 'touch' | 'evict' | 'expire' | 'hit' | 'miss'
|
|
113
|
+
/** A set applied from another tab (`multiTab`). */
|
|
114
|
+
| 'remote-set'
|
|
115
|
+
/** A delete/tombstone applied from another tab (`multiTab`). */
|
|
116
|
+
| 'remote-delete'
|
|
117
|
+
/** A clear applied from another tab (`multiTab`). */
|
|
118
|
+
| 'remote-clear'
|
|
119
|
+
/** A tag invalidation applied from another tab (`multiTab`). */
|
|
120
|
+
| 'remote-invalidate'
|
|
121
|
+
/** A persistence generation rotation applied from another tab (`multiTab`). */
|
|
122
|
+
| 'remote-rotate';
|
|
110
123
|
/**
|
|
111
124
|
* Per-event payload shapes, keyed by {@link CacheEventType}.
|
|
112
125
|
*
|
|
@@ -131,9 +144,14 @@ export interface CacheEventMap<V = any> {
|
|
|
131
144
|
clear: {
|
|
132
145
|
type: 'clear';
|
|
133
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
|
+
*/
|
|
134
151
|
invalidate: {
|
|
135
152
|
type: 'invalidate';
|
|
136
153
|
keys: string[];
|
|
154
|
+
tags: string[];
|
|
137
155
|
};
|
|
138
156
|
prune: {
|
|
139
157
|
type: 'prune';
|
|
@@ -166,6 +184,33 @@ export interface CacheEventMap<V = any> {
|
|
|
166
184
|
type: 'miss';
|
|
167
185
|
key: string;
|
|
168
186
|
};
|
|
187
|
+
/** A remote tab's set was applied. `value` is the structured-cloned payload. */
|
|
188
|
+
'remote-set': {
|
|
189
|
+
type: 'remote-set';
|
|
190
|
+
key: string;
|
|
191
|
+
value: V;
|
|
192
|
+
};
|
|
193
|
+
/** A remote tab's delete/tombstone was applied. */
|
|
194
|
+
'remote-delete': {
|
|
195
|
+
type: 'remote-delete';
|
|
196
|
+
key: string;
|
|
197
|
+
};
|
|
198
|
+
/** A remote tab cleared its cache. */
|
|
199
|
+
'remote-clear': {
|
|
200
|
+
type: 'remote-clear';
|
|
201
|
+
};
|
|
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
|
+
*/
|
|
207
|
+
'remote-invalidate': {
|
|
208
|
+
type: 'remote-invalidate';
|
|
209
|
+
};
|
|
210
|
+
/** A remote tab rotated the persistence generation. */
|
|
211
|
+
'remote-rotate': {
|
|
212
|
+
type: 'remote-rotate';
|
|
213
|
+
};
|
|
169
214
|
}
|
|
170
215
|
/** One event of any type — what a wildcard listener receives. */
|
|
171
216
|
export type CacheEvent<V = any> = CacheEventMap<V>[CacheEventType];
|
|
@@ -194,7 +239,7 @@ export type CacheListener = (change: CacheChange) => void;
|
|
|
194
239
|
* `evict`/`expire` carry the dropped entry's live reference (exactly what `get` would have
|
|
195
240
|
* returned a moment earlier); every other member is the very object the event system emits.
|
|
196
241
|
*/
|
|
197
|
-
export type CacheMutation<V = any> = CacheEventMap<V>[Exclude<CacheEventType, 'hit' | 'miss'>];
|
|
242
|
+
export type CacheMutation<V = any> = CacheEventMap<V>[Exclude<CacheEventType, 'hit' | 'miss' | 'remote-set' | 'remote-delete' | 'remote-clear' | 'remote-invalidate' | 'remote-rotate'>];
|
|
198
243
|
/**
|
|
199
244
|
* What a {@link BlazeCache.subscribeTag} listener receives: which tag woke it, which of its
|
|
200
245
|
* keys the mutation touched, and the mutation itself.
|
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,C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CHANGED
|
@@ -23,4 +23,20 @@ export declare function stableStringify(value: unknown): string;
|
|
|
23
23
|
* @returns the canonical string, or `undefined` when `value` cannot be serialised.
|
|
24
24
|
*/
|
|
25
25
|
export declare function safeStableStringify(value: unknown): string | undefined;
|
|
26
|
+
/**
|
|
27
|
+
* Collision-resistant 128-bit hash for cache keys.
|
|
28
|
+
*
|
|
29
|
+
* Use this — **not** the adapters' deprecated `fnv1a` — whenever a value that separates
|
|
30
|
+
* identities (a `vary` header, a request body, a session token) is folded into a cache key.
|
|
31
|
+
* The output is a fixed 32-character lowercase hex string, so keys are stable across page
|
|
32
|
+
* loads and can be persisted. BigInt keeps the whole computation in one accumulator; the
|
|
33
|
+
* cost is ~10 µs for a 200-character input, paid once per request rather than per lookup.
|
|
34
|
+
*
|
|
35
|
+
* FNV-1a is not a cryptographic MAC: it is unkeyed and its structure is public. That is
|
|
36
|
+
* fine here because collision resistance comes from the 128-bit output (birthday bound
|
|
37
|
+
* 2^64), and inverting a multiply step yields a 128-bit value that cannot be forced back
|
|
38
|
+
* into the 16-bit code units the input is built from. Do not use it for password storage,
|
|
39
|
+
* signatures, or anywhere an adversary needs preimage resistance against a *known* target.
|
|
40
|
+
*/
|
|
41
|
+
export declare function cacheKeyHash(input: string): string;
|
|
26
42
|
//# sourceMappingURL=utils.d.ts.map
|
package/dist/utils.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,eAAe,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,CA0BtD;AAED;;;;;;;GAOG;AACH,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,GAAG,SAAS,CAMtE"}
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,eAAe,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,CA0BtD;AAED;;;;;;;GAOG;AACH,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,GAAG,SAAS,CAMtE;AAWD;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,YAAY,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAOlD"}
|
package/dist/utils.js
CHANGED
|
@@ -56,4 +56,35 @@ export function safeStableStringify(value) {
|
|
|
56
56
|
return undefined;
|
|
57
57
|
}
|
|
58
58
|
}
|
|
59
|
+
// FNV-1a's 128-bit parameters. The 32-bit variant used to build HTTP cache keys had a
|
|
60
|
+
// ~2^16 birthday bound, which let two different `Authorization` values land on one key —
|
|
61
|
+
// i.e. one identity received another's cached response. 128 bits push the birthday bound
|
|
62
|
+
// to 2^64, which is not reachable, while keeping the function synchronous and dependency-
|
|
63
|
+
// free (Web Crypto's SHA-256 is Promise-based and would make every key call async).
|
|
64
|
+
const FNV128_OFFSET = 0x6c62272e07bb014262b821756295c58dn;
|
|
65
|
+
const FNV128_PRIME = 0x0000000001000000000000000000013bn;
|
|
66
|
+
const FNV128_MASK = (1n << 128n) - 1n;
|
|
67
|
+
/**
|
|
68
|
+
* Collision-resistant 128-bit hash for cache keys.
|
|
69
|
+
*
|
|
70
|
+
* Use this — **not** the adapters' deprecated `fnv1a` — whenever a value that separates
|
|
71
|
+
* identities (a `vary` header, a request body, a session token) is folded into a cache key.
|
|
72
|
+
* The output is a fixed 32-character lowercase hex string, so keys are stable across page
|
|
73
|
+
* loads and can be persisted. BigInt keeps the whole computation in one accumulator; the
|
|
74
|
+
* cost is ~10 µs for a 200-character input, paid once per request rather than per lookup.
|
|
75
|
+
*
|
|
76
|
+
* FNV-1a is not a cryptographic MAC: it is unkeyed and its structure is public. That is
|
|
77
|
+
* fine here because collision resistance comes from the 128-bit output (birthday bound
|
|
78
|
+
* 2^64), and inverting a multiply step yields a 128-bit value that cannot be forced back
|
|
79
|
+
* into the 16-bit code units the input is built from. Do not use it for password storage,
|
|
80
|
+
* signatures, or anywhere an adversary needs preimage resistance against a *known* target.
|
|
81
|
+
*/
|
|
82
|
+
export function cacheKeyHash(input) {
|
|
83
|
+
let hash = FNV128_OFFSET;
|
|
84
|
+
for (let i = 0; i < input.length; i += 1) {
|
|
85
|
+
hash ^= BigInt(input.charCodeAt(i));
|
|
86
|
+
hash = (hash * FNV128_PRIME) & FNV128_MASK;
|
|
87
|
+
}
|
|
88
|
+
return hash.toString(16).padStart(32, '0');
|
|
89
|
+
}
|
|
59
90
|
//# sourceMappingURL=utils.js.map
|
package/dist/utils.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AACH,MAAM,UAAU,eAAe,CAAC,KAAc;IAC5C,IAAI,KAAK,KAAK,SAAS;QAAE,OAAO,WAAW,CAAC;IAE5C,MAAM,IAAI,GAAG,IAAI,CAAC,SAAS,CAAC,KAAK,EAAE,CAAC,IAAI,EAAE,GAAY,EAAE,EAAE;QACxD,IAAI,GAAG,KAAK,IAAI,IAAI,OAAO,GAAG,KAAK,QAAQ,IAAI,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC;YAAE,OAAO,GAAG,CAAC;QAC9E,MAAM,MAAM,GAAG,GAA8B,CAAC;QAC9C,MAAM,MAAM,GAA4B,EAAE,CAAC;QAC3C,KAAK,MAAM,GAAG,IAAI,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC;YAC7C,uFAAuF;YACvF,sFAAsF;YACtF,oFAAoF;YACpF,qFAAqF;YACrF,oEAAoE;YACpE,MAAM,CAAC,cAAc,CAAC,MAAM,EAAE,GAAG,EAAE;gBACjC,KAAK,EAAE,MAAM,CAAC,GAAG,CAAC;gBAClB,UAAU,EAAE,IAAI;gBAChB,QA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C,CAAC;QACL,CAAC;QACD,OAAO,MAAM,CAAC;IAChB,CAAC,CAAC,CAAC;IAEH,sFAAsF;IACtF,2DAA2D;IAC3D,OAAO,IAAI,IAAI,MAAM,CAAC;AACxB,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,UAAU,mBAAmB,CAAC,KAAc;IAChD,IAAI,CAAC;QACH,OAAO,eAAe,CAAC,KAAK,CAAC,CAAC;IAChC,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,SAAS,CAAC;IACnB,CAAC;AACH,CAAC;AAED,sFAAsF;AACtF,yFAAyF;AACzF,yFAAyF;AACzF,0FAA0F;AAC1F,oFAAoF;AACpF,MAAM,aAAa,GAAG,mCAAmC,CAAC;AAC1D,MAAM,YAAY,GAAG,mCAAmC,CAAC;AACzD,MAAM,WAAW,GAAG,CAAC,EAAE,IAAI,IAAI,CAAC,GAAG,EAAE,CAAC;AAEtC;;;;;;;;;;;;;;GAcG;AACH,MAAM,UAAU,YAAY,CAAC,KAAa;IACxC,IAAI,IAAI,GAAG,aAAa,CAAC;IACzB,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,KAAK,CAAC,MAAM,EAAE,CAAC,IAAI,CAAC,EAAE,CAAC;QACzC,IAAI,IAAI,MAAM,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC;QACpC,IAAI,GAAG,CAAC,IAAI,GAAG,YAAY,CAAC,GAAG,WAAW,CAAC;IAC7C,CAAC;IACD,OAAO,IAAI,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,QAAQ,CAAC,EAAE,EAAE,GAAG,CAAC,CAAC;AAC7C,CAAC"}
|
package/dist/wasm.d.ts
CHANGED
|
@@ -110,9 +110,47 @@ declare class KeyScratch {
|
|
|
110
110
|
* the scratch *offset* never moves — so a refresh is a view rebuild, not a re-encode.
|
|
111
111
|
*/
|
|
112
112
|
encode(key: string): void;
|
|
113
|
+
/** Encodes a whole batch of keys into one contiguous region for `setManyRaw`. */
|
|
114
|
+
encodeMany(keys: readonly string[]): {
|
|
115
|
+
ptr: number;
|
|
116
|
+
offsets: Uint32Array;
|
|
117
|
+
lengths: Uint32Array;
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* Flat tag-name scratch for the tagged raw-write path. One encode per distinct tag list means
|
|
122
|
+
* the common `full-featured` workload crosses the boundary with two pointers and an offset
|
|
123
|
+
* table instead of a freshly allocated `Vec<String>` on every `set`.
|
|
124
|
+
*/
|
|
125
|
+
declare class TagScratch {
|
|
126
|
+
#private;
|
|
127
|
+
ptr: number;
|
|
128
|
+
len: number;
|
|
129
|
+
offsets: Uint32Array<ArrayBuffer>;
|
|
130
|
+
/** A zero-copy view of exactly the live offset range — avoids a subarray per write. */
|
|
131
|
+
offsetsView: Uint32Array<ArrayBuffer>;
|
|
132
|
+
enabled: boolean;
|
|
133
|
+
setup(exports: InitOutput): void;
|
|
134
|
+
/** Makes the flat tag buffer and its offset table describe `tags`. */
|
|
135
|
+
encode(tags: readonly string[]): this;
|
|
136
|
+
/** Encodes a single tag — the common case — with no cache-key allocation. */
|
|
137
|
+
encodeOne(tag: string): this;
|
|
138
|
+
/**
|
|
139
|
+
* Encodes per-entry tag groups into one flat buffer with one offset per entry (plus a final
|
|
140
|
+
* sentinel), matching the `tag_offsets` contract of `setManyRaw`.
|
|
141
|
+
*/
|
|
142
|
+
encodeRanges(groups: readonly (readonly string[])[]): this;
|
|
113
143
|
}
|
|
114
144
|
/** The one key scratch shared by every {@link WasmCache} instance (see {@link KeyScratch}). */
|
|
115
145
|
export declare const keyScratch: KeyScratch;
|
|
146
|
+
/** The one tag scratch shared by every {@link WasmCache} instance. */
|
|
147
|
+
export declare const tagScratch: TagScratch;
|
|
148
|
+
/**
|
|
149
|
+
* The current Wasm linear memory, for the opt-in bytes value mode. Read it fresh for every
|
|
150
|
+
* view: `memory.grow` swaps the `ArrayBuffer` and detaches views built from the old one.
|
|
151
|
+
* Offsets themselves are stable (see `bytesReserve` in the binding).
|
|
152
|
+
*/
|
|
153
|
+
export declare function wasmLinearMemory(): WebAssembly.Memory;
|
|
116
154
|
/**
|
|
117
155
|
* Loads and instantiates the Blaze Cache wasm module exactly once.
|
|
118
156
|
*
|
package/dist/wasm.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"wasm.d.ts","sourceRoot":"","sources":["../src/wasm.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,EAAE,
|
|
1
|
+
{"version":3,"file":"wasm.d.ts","sourceRoot":"","sources":["../src/wasm.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,EAAE,EAIX,UAAU,IAAI,SAAS,EACxB,MAAM,4BAA4B,CAAC;AACpC,OAAO,KAAK,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,4BAA4B,CAAC;AAExE,0EAA0E;AAC1E,MAAM,MAAM,aAAa,GAAG,WAAW,CAAC,UAAU,CAAC,OAAO,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AAEpE;;;GAGG;AACH,MAAM,MAAM,UAAU,GAAG,SAAS,CAAC;AAEnC;;;;;GAKG;AACH,eAAO,MAAM,OAAO,EAAE,GAAiE,CAAC;AAExF,wFAAwF;AACxF,MAAM,WAAW,eAAe;IAC9B;;;;;;;;;;;OAWG;IACH,OAAO,CAAC,EAAE,MAAM,GAAG,GAAG,CAAC;IACvB;;;;;;;;OAQG;IACH,MAAM,CAAC,EAAE,WAAW,CAAC,MAAM,CAAC;IAC5B;;;;;;;;;;;;;;;;;;;;OAoBG;IACH,WAAW,CAAC,EAAE,MAAM,UAAU,GAAG,OAAO,CAAC,UAAU,CAAC,CAAC;IACrD;;;;;OAKG;IACH,IAAI,CAAC,EAAE,aAAa,CAAC;CACtB;AAOD;;;;;;;;;;;;;;;;GAgBG;AACH,cAAM,UAAU;;IACd,yDAAyD;IACzD,GAAG,SAAK;IACR,gEAAgE;IAChE,GAAG,SAAK;IACR,qFAA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AAC"}
|
package/dist/wasm.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import init, { setPanicHook, ensureScratch, BlazeCache as WasmCache, } from '../pkg/blaze_cache_wasm.js';
|
|
1
|
+
import init, { setPanicHook, ensureScratch, ensureTagScratch, BlazeCache as WasmCache, } from '../pkg/blaze_cache_wasm.js';
|
|
2
2
|
/**
|
|
3
3
|
* URL of the `.wasm` binary, resolved relative to **this** module.
|
|
4
4
|
*
|
|
@@ -94,8 +94,7 @@ class KeyScratch {
|
|
|
94
94
|
break;
|
|
95
95
|
view[base + j] = code;
|
|
96
96
|
}
|
|
97
|
-
this.len =
|
|
98
|
-
j === n ? n : textEncoder.encodeInto(key, view.subarray(base, base + n * 3)).written;
|
|
97
|
+
this.len = j === n ? n : textEncoder.encodeInto(key, view.subarray(base, base + n * 3)).written;
|
|
99
98
|
this.ptr = base;
|
|
100
99
|
this.#last = key;
|
|
101
100
|
}
|
|
@@ -105,9 +104,193 @@ class KeyScratch {
|
|
|
105
104
|
this.#cap = want;
|
|
106
105
|
this.#view = null; // the old view addressed the pre-growth buffer
|
|
107
106
|
}
|
|
107
|
+
/** Encodes a whole batch of keys into one contiguous region for `setManyRaw`. */
|
|
108
|
+
encodeMany(keys) {
|
|
109
|
+
const need = Math.max(SCRATCH_MIN, keys.reduce((sum, key) => sum + key.length * 3, 0));
|
|
110
|
+
if (need > this.#cap)
|
|
111
|
+
this.#grow(need);
|
|
112
|
+
const view = this.#viewForWrite();
|
|
113
|
+
const offsets = new Uint32Array(keys.length);
|
|
114
|
+
const lengths = new Uint32Array(keys.length);
|
|
115
|
+
let position = 0;
|
|
116
|
+
for (let i = 0; i < keys.length; i += 1) {
|
|
117
|
+
const key = keys[i];
|
|
118
|
+
const written = encodeInto(view, this.#base + position, key);
|
|
119
|
+
offsets[i] = position;
|
|
120
|
+
lengths[i] = written;
|
|
121
|
+
position += written;
|
|
122
|
+
}
|
|
123
|
+
this.#last = null;
|
|
124
|
+
return { ptr: this.#base, offsets, lengths };
|
|
125
|
+
}
|
|
126
|
+
/** Returns a current view of wasm memory, rebuilding it after `memory.grow`. */
|
|
127
|
+
#viewForWrite() {
|
|
128
|
+
const memory = this.#memory;
|
|
129
|
+
let view = this.#view;
|
|
130
|
+
if (view === null || view.buffer !== memory.buffer) {
|
|
131
|
+
view = new Uint8Array(memory.buffer);
|
|
132
|
+
this.#view = view;
|
|
133
|
+
}
|
|
134
|
+
return view;
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
/** Writes one JS string into `view` at `offset` and returns the UTF-8 byte count. */
|
|
138
|
+
function encodeInto(view, offset, value) {
|
|
139
|
+
const n = value.length;
|
|
140
|
+
let j = 0;
|
|
141
|
+
for (; j < n; j += 1) {
|
|
142
|
+
const code = value.charCodeAt(j);
|
|
143
|
+
if (code > 0x7f)
|
|
144
|
+
break;
|
|
145
|
+
view[offset + j] = code;
|
|
146
|
+
}
|
|
147
|
+
return j === n ? n : textEncoder.encodeInto(value, view.subarray(offset, offset + n * 3)).written;
|
|
148
|
+
}
|
|
149
|
+
/**
|
|
150
|
+
* Flat tag-name scratch for the tagged raw-write path. One encode per distinct tag list means
|
|
151
|
+
* the common `full-featured` workload crosses the boundary with two pointers and an offset
|
|
152
|
+
* table instead of a freshly allocated `Vec<String>` on every `set`.
|
|
153
|
+
*/
|
|
154
|
+
class TagScratch {
|
|
155
|
+
ptr = 0;
|
|
156
|
+
len = 0;
|
|
157
|
+
offsets = new Uint32Array(1);
|
|
158
|
+
/** A zero-copy view of exactly the live offset range — avoids a subarray per write. */
|
|
159
|
+
offsetsView = new Uint32Array(1);
|
|
160
|
+
enabled = false;
|
|
161
|
+
#memory = null;
|
|
162
|
+
#view = null;
|
|
163
|
+
#base = 0;
|
|
164
|
+
#cap = 0;
|
|
165
|
+
#last = null;
|
|
166
|
+
setup(exports) {
|
|
167
|
+
const memory = exports.memory;
|
|
168
|
+
if (!(memory instanceof WebAssembly.Memory))
|
|
169
|
+
return;
|
|
170
|
+
if (typeof exports.blazecache_setRawWithTags !== 'function' ||
|
|
171
|
+
typeof exports.blazecache_setManyRaw !== 'function' ||
|
|
172
|
+
typeof exports.ensureTagScratch !== 'function') {
|
|
173
|
+
return;
|
|
174
|
+
}
|
|
175
|
+
try {
|
|
176
|
+
this.#base = ensureTagScratch(SCRATCH_MIN);
|
|
177
|
+
this.#cap = SCRATCH_MIN;
|
|
178
|
+
}
|
|
179
|
+
catch {
|
|
180
|
+
return;
|
|
181
|
+
}
|
|
182
|
+
this.#memory = memory;
|
|
183
|
+
this.enabled = true;
|
|
184
|
+
}
|
|
185
|
+
/** Makes the flat tag buffer and its offset table describe `tags`. */
|
|
186
|
+
encode(tags) {
|
|
187
|
+
// The hot path writes exactly one tag; use it directly as the cache key instead of
|
|
188
|
+
// allocating a JSON string on every set.
|
|
189
|
+
const cacheKey = tags.length === 1 ? `1:${tags[0]}` : JSON.stringify(tags);
|
|
190
|
+
if (cacheKey === this.#last)
|
|
191
|
+
return this;
|
|
192
|
+
const need = Math.max(SCRATCH_MIN, tags.reduce((sum, tag) => sum + tag.length * 3, 0));
|
|
193
|
+
if (need > this.#cap) {
|
|
194
|
+
this.#base = ensureTagScratch(need);
|
|
195
|
+
this.#cap = need;
|
|
196
|
+
this.#view = null;
|
|
197
|
+
}
|
|
198
|
+
const memory = this.#memory;
|
|
199
|
+
let view = this.#view;
|
|
200
|
+
if (view === null || view.buffer !== memory.buffer) {
|
|
201
|
+
view = new Uint8Array(memory.buffer);
|
|
202
|
+
this.#view = view;
|
|
203
|
+
}
|
|
204
|
+
if (this.offsets.length < tags.length + 1)
|
|
205
|
+
this.offsets = new Uint32Array(tags.length + 1);
|
|
206
|
+
let position = 0;
|
|
207
|
+
this.offsets[0] = 0;
|
|
208
|
+
for (let i = 0; i < tags.length; i += 1) {
|
|
209
|
+
position += encodeInto(view, this.#base + position, tags[i]);
|
|
210
|
+
this.offsets[i + 1] = position;
|
|
211
|
+
}
|
|
212
|
+
this.len = position;
|
|
213
|
+
this.ptr = this.#base;
|
|
214
|
+
this.offsetsView = this.offsets.subarray(0, tags.length + 1);
|
|
215
|
+
this.#last = cacheKey;
|
|
216
|
+
return this;
|
|
217
|
+
}
|
|
218
|
+
/** Encodes a single tag — the common case — with no cache-key allocation. */
|
|
219
|
+
encodeOne(tag) {
|
|
220
|
+
if (this.#last === tag && this.len > 0)
|
|
221
|
+
return this;
|
|
222
|
+
const need = Math.max(SCRATCH_MIN, tag.length * 3);
|
|
223
|
+
if (need > this.#cap) {
|
|
224
|
+
this.#base = ensureTagScratch(need);
|
|
225
|
+
this.#cap = need;
|
|
226
|
+
this.#view = null;
|
|
227
|
+
}
|
|
228
|
+
const memory = this.#memory;
|
|
229
|
+
let view = this.#view;
|
|
230
|
+
if (view === null || view.buffer !== memory.buffer) {
|
|
231
|
+
view = new Uint8Array(memory.buffer);
|
|
232
|
+
this.#view = view;
|
|
233
|
+
}
|
|
234
|
+
this.len = encodeInto(view, this.#base, tag);
|
|
235
|
+
this.ptr = this.#base;
|
|
236
|
+
if (this.offsets.length < 2)
|
|
237
|
+
this.offsets = new Uint32Array(2);
|
|
238
|
+
this.offsets[0] = 0;
|
|
239
|
+
this.offsets[1] = this.len;
|
|
240
|
+
this.offsetsView = this.offsets.subarray(0, 2);
|
|
241
|
+
this.#last = tag;
|
|
242
|
+
return this;
|
|
243
|
+
}
|
|
244
|
+
/**
|
|
245
|
+
* Encodes per-entry tag groups into one flat buffer with one offset per entry (plus a final
|
|
246
|
+
* sentinel), matching the `tag_offsets` contract of `setManyRaw`.
|
|
247
|
+
*/
|
|
248
|
+
encodeRanges(groups) {
|
|
249
|
+
const cacheKey = `ranges:${JSON.stringify(groups)}`;
|
|
250
|
+
if (cacheKey === this.#last)
|
|
251
|
+
return this;
|
|
252
|
+
const need = Math.max(SCRATCH_MIN, groups.reduce((sum, group) => sum + group.reduce((n, tag) => n + tag.length * 3, 0), 0));
|
|
253
|
+
if (need > this.#cap) {
|
|
254
|
+
this.#base = ensureTagScratch(need);
|
|
255
|
+
this.#cap = need;
|
|
256
|
+
this.#view = null;
|
|
257
|
+
}
|
|
258
|
+
const memory = this.#memory;
|
|
259
|
+
let view = this.#view;
|
|
260
|
+
if (view === null || view.buffer !== memory.buffer) {
|
|
261
|
+
view = new Uint8Array(memory.buffer);
|
|
262
|
+
this.#view = view;
|
|
263
|
+
}
|
|
264
|
+
if (this.offsets.length < groups.length + 1) {
|
|
265
|
+
this.offsets = new Uint32Array(groups.length + 1);
|
|
266
|
+
}
|
|
267
|
+
let position = 0;
|
|
268
|
+
this.offsets[0] = 0;
|
|
269
|
+
for (let i = 0; i < groups.length; i += 1) {
|
|
270
|
+
for (const tag of groups[i]) {
|
|
271
|
+
position += encodeInto(view, this.#base + position, tag);
|
|
272
|
+
}
|
|
273
|
+
this.offsets[i + 1] = position;
|
|
274
|
+
}
|
|
275
|
+
this.len = position;
|
|
276
|
+
this.ptr = this.#base;
|
|
277
|
+
this.offsetsView = this.offsets.subarray(0, groups.length + 1);
|
|
278
|
+
this.#last = cacheKey;
|
|
279
|
+
return this;
|
|
280
|
+
}
|
|
108
281
|
}
|
|
109
282
|
/** The one key scratch shared by every {@link WasmCache} instance (see {@link KeyScratch}). */
|
|
110
283
|
export const keyScratch = new KeyScratch();
|
|
284
|
+
/** The one tag scratch shared by every {@link WasmCache} instance. */
|
|
285
|
+
export const tagScratch = new TagScratch();
|
|
286
|
+
/**
|
|
287
|
+
* The current Wasm linear memory, for the opt-in bytes value mode. Read it fresh for every
|
|
288
|
+
* view: `memory.grow` swaps the `ArrayBuffer` and detaches views built from the old one.
|
|
289
|
+
* Offsets themselves are stable (see `bytesReserve` in the binding).
|
|
290
|
+
*/
|
|
291
|
+
export function wasmLinearMemory() {
|
|
292
|
+
return WasmCache.wasmMemory();
|
|
293
|
+
}
|
|
111
294
|
let pending = null;
|
|
112
295
|
/**
|
|
113
296
|
* Loads and instantiates the Blaze Cache wasm module exactly once.
|
|
@@ -126,6 +309,7 @@ export function initBlazeWasm(input) {
|
|
|
126
309
|
// resolved value is the module's exports — needed for the raw-key scratch.
|
|
127
310
|
const exports = await init({ module_or_path: input ?? wasmUrl });
|
|
128
311
|
keyScratch.setup(exports);
|
|
312
|
+
tagScratch.setup(exports);
|
|
129
313
|
// Forward Rust panics to `console.error` so devtools shows something useful.
|
|
130
314
|
setPanicHook();
|
|
131
315
|
})();
|
|
@@ -244,9 +428,9 @@ async function fetchWasmBinary(target) {
|
|
|
244
428
|
function adoptWasmSource(source) {
|
|
245
429
|
if (isWasmSource(source))
|
|
246
430
|
return source;
|
|
247
|
-
throw new Error(
|
|
431
|
+
throw new Error('@blaze-cache/core: `instantiate` must resolve to a *source* — a URL, a Request or ' +
|
|
248
432
|
'Response, raw bytes, or a precompiled WebAssembly.Module — not to a ' +
|
|
249
|
-
|
|
433
|
+
"WebAssembly.Instance or to an object's exports. wasm-bindgen's generated glue owns " +
|
|
250
434
|
'the import object and has to create the instance itself, so an instance built ' +
|
|
251
435
|
'elsewhere can never be wired up. Return the source instead, for example ' +
|
|
252
436
|
'`(await fetch(url)).arrayBuffer()`.');
|