@c9up/echo 0.2.2 → 0.2.4
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/dist/CacheManager.d.ts +2 -0
- package/dist/CacheManager.d.ts.map +1 -1
- package/dist/CacheManager.js +92 -32
- package/dist/CacheManager.js.map +1 -1
- package/dist/EchoProvider.d.ts.map +1 -1
- package/dist/EchoProvider.js +32 -3
- package/dist/EchoProvider.js.map +1 -1
- package/dist/StoreManager.d.ts +28 -9
- package/dist/StoreManager.d.ts.map +1 -1
- package/dist/StoreManager.js +42 -18
- package/dist/StoreManager.js.map +1 -1
- package/dist/bytes.d.ts +13 -0
- package/dist/bytes.d.ts.map +1 -0
- package/dist/bytes.js +35 -0
- package/dist/bytes.js.map +1 -0
- package/dist/claim.d.ts +15 -0
- package/dist/claim.d.ts.map +1 -0
- package/dist/claim.js +10 -0
- package/dist/claim.js.map +1 -0
- package/dist/configure.d.ts +7 -0
- package/dist/configure.d.ts.map +1 -1
- package/dist/configure.js +5 -18
- package/dist/configure.js.map +1 -1
- package/dist/console/cacheClear.d.ts +13 -0
- package/dist/console/cacheClear.d.ts.map +1 -0
- package/dist/console/cacheClear.js +69 -0
- package/dist/console/cacheClear.js.map +1 -0
- package/dist/console/cacheDelete.d.ts +11 -0
- package/dist/console/cacheDelete.d.ts.map +1 -0
- package/dist/console/cacheDelete.js +42 -0
- package/dist/console/cacheDelete.js.map +1 -0
- package/dist/console/cachePrune.d.ts +9 -0
- package/dist/console/cachePrune.d.ts.map +1 -0
- package/dist/console/cachePrune.js +35 -0
- package/dist/console/cachePrune.js.map +1 -0
- package/dist/console/contract.d.ts +64 -0
- package/dist/console/contract.d.ts.map +1 -0
- package/dist/console/contract.js +32 -0
- package/dist/console/contract.js.map +1 -0
- package/dist/console/index.d.ts +25 -0
- package/dist/console/index.d.ts.map +1 -0
- package/dist/console/index.js +38 -0
- package/dist/console/index.js.map +1 -0
- package/dist/console/store.d.ts +14 -0
- package/dist/console/store.d.ts.map +1 -0
- package/dist/console/store.js +35 -0
- package/dist/console/store.js.map +1 -0
- package/dist/drivers/MemoryDriver.d.ts +36 -1
- package/dist/drivers/MemoryDriver.d.ts.map +1 -1
- package/dist/drivers/MemoryDriver.js +157 -62
- package/dist/drivers/MemoryDriver.js.map +1 -1
- package/dist/drivers/RedisDriver.d.ts +13 -8
- package/dist/drivers/RedisDriver.d.ts.map +1 -1
- package/dist/drivers/RedisDriver.js +171 -94
- package/dist/drivers/RedisDriver.js.map +1 -1
- package/dist/drivers/TieredDriver.d.ts +42 -0
- package/dist/drivers/TieredDriver.d.ts.map +1 -1
- package/dist/drivers/TieredDriver.js +114 -9
- package/dist/drivers/TieredDriver.js.map +1 -1
- package/dist/duration.d.ts +13 -3
- package/dist/duration.d.ts.map +1 -1
- package/dist/duration.js +22 -7
- package/dist/duration.js.map +1 -1
- package/dist/errors.d.ts +60 -2
- package/dist/errors.d.ts.map +1 -1
- package/dist/errors.js +81 -6
- package/dist/errors.js.map +1 -1
- package/dist/index.d.ts +4 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -3
- package/dist/index.js.map +1 -1
- package/dist/quasar.d.ts +1 -1
- package/dist/quasar.d.ts.map +1 -1
- package/dist/quasar.js +27 -6
- package/dist/quasar.js.map +1 -1
- package/dist/services/main.d.ts +1 -1
- package/dist/services/main.d.ts.map +1 -1
- package/dist/services/main.js +22 -5
- package/dist/services/main.js.map +1 -1
- package/dist/stubs.d.ts +14 -0
- package/dist/stubs.d.ts.map +1 -0
- package/dist/stubs.js +15 -0
- package/dist/stubs.js.map +1 -0
- package/dist/types.d.ts +12 -1
- package/dist/types.d.ts.map +1 -1
- package/dist/vendor/quasarConnection.d.ts +26 -3
- package/dist/vendor/quasarConnection.d.ts.map +1 -1
- package/dist/vendor/quasarConnection.js +44 -23
- package/dist/vendor/quasarConnection.js.map +1 -1
- package/package.json +8 -3
- package/src/CacheManager.ts +117 -41
- package/src/EchoProvider.ts +45 -4
- package/src/StoreManager.ts +86 -31
- package/src/bytes.ts +38 -0
- package/src/claim.ts +22 -0
- package/src/configure.ts +13 -21
- package/src/console/cacheClear.ts +96 -0
- package/src/console/cacheDelete.ts +65 -0
- package/src/console/cachePrune.ts +57 -0
- package/src/console/contract.ts +93 -0
- package/src/console/index.ts +61 -0
- package/src/console/store.ts +47 -0
- package/src/drivers/MemoryDriver.ts +205 -60
- package/src/drivers/RedisDriver.ts +205 -101
- package/src/drivers/TieredDriver.ts +169 -9
- package/src/duration.ts +28 -7
- package/src/errors.ts +103 -6
- package/src/index.ts +17 -3
- package/src/quasar.ts +44 -8
- package/src/services/main.ts +26 -8
- package/src/stubs.ts +16 -0
- package/src/types.ts +13 -2
- package/src/vendor/quasarConnection.ts +84 -22
- package/stubs/config/cache.stub +21 -0
package/dist/quasar.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"quasar.d.ts","sourceRoot":"","sources":["../src/quasar.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AAC5D,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"quasar.d.ts","sourceRoot":"","sources":["../src/quasar.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AAC5D,OAAO,EAEN,KAAK,QAAQ,EAEb,MAAM,2BAA2B,CAAC;AA0CnC;;;GAGG;AACH,wBAAgB,gBAAgB,CAAC,IAAI,CAAC,EAAE,MAAM,GAAG,MAAM,OAAO,CAAC,WAAW,CAAC,CAiB1E;AAyED;;;;;;;;;;;GAWG;AACH,wBAAgB,SAAS,CAAC,OAAO,CAAC,EAAE;IACnC,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,OAAO,CAAC,EAAE,MAAM,CAAC;CACjB,GAAG,QAAQ,CA+FX"}
|
package/dist/quasar.js
CHANGED
|
@@ -10,7 +10,9 @@
|
|
|
10
10
|
* again: `src/vendor/quasarConnection.ts`, generated from one source. The bus
|
|
11
11
|
* below is echo's alone and stays here.
|
|
12
12
|
*/
|
|
13
|
-
import {
|
|
13
|
+
import { isBusMessage, } from "./drivers/TieredDriver.js";
|
|
14
|
+
import { EchoError } from "./errors.js";
|
|
15
|
+
import { hasCommands, quasarConnection as loadQuasarConnection, } from "./vendor/quasarConnection.js";
|
|
14
16
|
/**
|
|
15
17
|
* The commands this driver actually issues.
|
|
16
18
|
*
|
|
@@ -31,6 +33,17 @@ const REQUIRED = [
|
|
|
31
33
|
"expire",
|
|
32
34
|
"ttl",
|
|
33
35
|
];
|
|
36
|
+
/**
|
|
37
|
+
* The connection is handed over only once it carries every command above.
|
|
38
|
+
* `keys` and `exists` are declared but never called, so not required either;
|
|
39
|
+
* `scan` stays optional, but when there it has to be a function too.
|
|
40
|
+
*/
|
|
41
|
+
function isRedisClient(value) {
|
|
42
|
+
return (hasCommands(value, REQUIRED) &&
|
|
43
|
+
(!("scan" in value) ||
|
|
44
|
+
value.scan === undefined ||
|
|
45
|
+
typeof value.scan === "function"));
|
|
46
|
+
}
|
|
34
47
|
/**
|
|
35
48
|
* A resolver for `drivers.redis({ connection })` — quasar is loaded on the
|
|
36
49
|
* first cache command, not at config time.
|
|
@@ -40,8 +53,11 @@ export function quasarConnection(name) {
|
|
|
40
53
|
pkg: "echo",
|
|
41
54
|
name,
|
|
42
55
|
required: REQUIRED,
|
|
56
|
+
isConnection: isRedisClient,
|
|
43
57
|
what: "the cache store",
|
|
44
|
-
raise: (
|
|
58
|
+
raise: (reason, message, cause) => new EchoError(reason === "quasar-missing"
|
|
59
|
+
? "E_ECHO_QUASAR_MISSING"
|
|
60
|
+
: "E_ECHO_INCOMPLETE_CONNECTION", message, { cause }),
|
|
45
61
|
});
|
|
46
62
|
}
|
|
47
63
|
function isConnectionSource(value) {
|
|
@@ -72,7 +88,7 @@ async function loadQuasar(context) {
|
|
|
72
88
|
: Reflect.get(Object(loaded), "default");
|
|
73
89
|
}
|
|
74
90
|
catch (cause) {
|
|
75
|
-
throw new
|
|
91
|
+
throw new EchoError("E_ECHO_QUASAR_MISSING", `Echo: ${context}, but @c9up/quasar is not installed.\n pnpm add @c9up/quasar`, { cause });
|
|
76
92
|
}
|
|
77
93
|
}
|
|
78
94
|
/**
|
|
@@ -98,7 +114,7 @@ export function quasarBus(options) {
|
|
|
98
114
|
? loaded.connection(options?.connection)
|
|
99
115
|
: loaded;
|
|
100
116
|
if (!isPubSubSource(source)) {
|
|
101
|
-
throw new
|
|
117
|
+
throw new EchoError("E_ECHO_INCOMPLETE_CONNECTION", "Echo: the quasar connection does not expose publish()/subscribe()");
|
|
102
118
|
}
|
|
103
119
|
return source;
|
|
104
120
|
});
|
|
@@ -111,12 +127,17 @@ export function quasarBus(options) {
|
|
|
111
127
|
},
|
|
112
128
|
async subscribe(handler) {
|
|
113
129
|
const wrapper = (raw) => {
|
|
130
|
+
let frame;
|
|
114
131
|
try {
|
|
115
|
-
|
|
132
|
+
frame = JSON.parse(raw);
|
|
116
133
|
}
|
|
117
134
|
catch {
|
|
118
|
-
|
|
135
|
+
// A malformed frame is not a reason to stop listening.
|
|
136
|
+
return;
|
|
119
137
|
}
|
|
138
|
+
// Anything on the channel reaches here, not only what echo sent.
|
|
139
|
+
if (isBusMessage(frame))
|
|
140
|
+
handler(frame);
|
|
120
141
|
};
|
|
121
142
|
// AWAITED, and a reported failure becomes a rejection.
|
|
122
143
|
//
|
package/dist/quasar.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"quasar.js","sourceRoot":"","sources":["../src/quasar.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;
|
|
1
|
+
{"version":3,"file":"quasar.js","sourceRoot":"","sources":["../src/quasar.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAGH,OAAO,EAGN,YAAY,GACZ,MAAM,2BAA2B,CAAC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10
10
|
* await cache.set('user:42', user, 60)
|
|
11
11
|
* const cached = await cache.get<User>('user:42')
|
|
12
12
|
*/
|
|
13
|
-
import
|
|
13
|
+
import { CacheManager } from "../CacheManager.js";
|
|
14
14
|
/** @internal Bind the singleton (called by EchoProvider or by the app). */
|
|
15
15
|
export declare function setCache(value: CacheManager): void;
|
|
16
16
|
/** @internal Read the singleton (or `undefined` pre-boot). */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"main.d.ts","sourceRoot":"","sources":["../../src/services/main.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,
|
|
1
|
+
{"version":3,"file":"main.d.ts","sourceRoot":"","sources":["../../src/services/main.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAKlD,2EAA2E;AAC3E,wBAAgB,QAAQ,CAAC,KAAK,EAAE,YAAY,GAAG,IAAI,CAElD;AAED,8DAA8D;AAC9D,wBAAgB,QAAQ,IAAI,YAAY,GAAG,SAAS,CAEnD;AAED;;;GAGG;AACH,wBAAgB,UAAU,IAAI,IAAI,CAEjC;AAwBD,QAAA,MAAM,KAAK,EAAE,YAeX,CAAC;AAEH,eAAe,KAAK,CAAC"}
|
package/dist/services/main.js
CHANGED
|
@@ -10,6 +10,8 @@
|
|
|
10
10
|
* await cache.set('user:42', user, 60)
|
|
11
11
|
* const cached = await cache.get<User>('user:42')
|
|
12
12
|
*/
|
|
13
|
+
import { CacheManager } from "../CacheManager.js";
|
|
14
|
+
import { EchoError } from "../errors.js";
|
|
13
15
|
let instance;
|
|
14
16
|
/** @internal Bind the singleton (called by EchoProvider or by the app). */
|
|
15
17
|
export function setCache(value) {
|
|
@@ -26,7 +28,24 @@ export function getCache() {
|
|
|
26
28
|
export function clearCache() {
|
|
27
29
|
instance = undefined;
|
|
28
30
|
}
|
|
29
|
-
|
|
31
|
+
/**
|
|
32
|
+
* What the proxy stands on. Never reached: every read goes through the trap
|
|
33
|
+
* below, to the bound manager or to the not-booted error. A real instance
|
|
34
|
+
* rather than an asserted `{}`, so the proxy is a `CacheManager` by type.
|
|
35
|
+
*/
|
|
36
|
+
const unbooted = () => Promise.reject(notBooted());
|
|
37
|
+
const placeholder = new CacheManager({
|
|
38
|
+
get: unbooted,
|
|
39
|
+
set: unbooted,
|
|
40
|
+
delete: unbooted,
|
|
41
|
+
flush: unbooted,
|
|
42
|
+
has: unbooted,
|
|
43
|
+
});
|
|
44
|
+
function notBooted() {
|
|
45
|
+
return new EchoError("E_ECHO_NOT_BOOTED", "[echo] CacheManager singleton accessed before EchoProvider.boot() ran " +
|
|
46
|
+
"or `setCache(myCache)` was called. Wire one of them first.");
|
|
47
|
+
}
|
|
48
|
+
const cache = new Proxy(placeholder, {
|
|
30
49
|
get(_target, prop) {
|
|
31
50
|
// A module loader inspects what it imports before anyone uses it: it reads
|
|
32
51
|
// `then` to decide whether the namespace is thenable, and various symbols
|
|
@@ -37,10 +56,8 @@ const cache = new Proxy({}, {
|
|
|
37
56
|
if (typeof prop === "symbol" || prop === "then") {
|
|
38
57
|
return undefined;
|
|
39
58
|
}
|
|
40
|
-
if (!instance)
|
|
41
|
-
throw
|
|
42
|
-
"or `setCache(myCache)` was called. Wire one of them first.");
|
|
43
|
-
}
|
|
59
|
+
if (!instance)
|
|
60
|
+
throw notBooted();
|
|
44
61
|
const value = Reflect.get(instance, prop, instance);
|
|
45
62
|
return typeof value === "function" ? value.bind(instance) : value;
|
|
46
63
|
},
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"main.js","sourceRoot":"","sources":["../../src/services/main.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;
|
|
1
|
+
{"version":3,"file":"main.js","sourceRoot":"","sources":["../../src/services/main.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAClD,OAA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AC,QAAQ,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC;IACnE,CAAC;CACD,CAAC,CAAC;AAEH,eAAe,KAAK,CAAC"}
|
package/dist/stubs.d.ts
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Where this package's stubs live.
|
|
3
|
+
*
|
|
4
|
+
* Its own module, as upstream keeps it: a stub root is a path a package
|
|
5
|
+
* publishes, and a caller importing it should not have to import the
|
|
6
|
+
* configure hook to get it.
|
|
7
|
+
*
|
|
8
|
+
* `import.meta.dirname` rather than a URL — upstream reads it straight off
|
|
9
|
+
* `import.meta`, and deriving it from `import.meta.url` breaks wherever that
|
|
10
|
+
* is not a `file://` URL, which is what a test runner serving modules over
|
|
11
|
+
* HTTP hands you.
|
|
12
|
+
*/
|
|
13
|
+
export declare const stubsRoot: string;
|
|
14
|
+
//# sourceMappingURL=stubs.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"stubs.d.ts","sourceRoot":"","sources":["../src/stubs.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAIH,eAAO,MAAM,SAAS,QAA2C,CAAC"}
|
package/dist/stubs.js
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Where this package's stubs live.
|
|
3
|
+
*
|
|
4
|
+
* Its own module, as upstream keeps it: a stub root is a path a package
|
|
5
|
+
* publishes, and a caller importing it should not have to import the
|
|
6
|
+
* configure hook to get it.
|
|
7
|
+
*
|
|
8
|
+
* `import.meta.dirname` rather than a URL — upstream reads it straight off
|
|
9
|
+
* `import.meta`, and deriving it from `import.meta.url` breaks wherever that
|
|
10
|
+
* is not a `file://` URL, which is what a test runner serving modules over
|
|
11
|
+
* HTTP hands you.
|
|
12
|
+
*/
|
|
13
|
+
import { join } from "node:path";
|
|
14
|
+
export const stubsRoot = join(import.meta.dirname, "..", "stubs");
|
|
15
|
+
//# sourceMappingURL=stubs.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"stubs.js","sourceRoot":"","sources":["../src/stubs.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAEjC,MAAM,CAAC,MAAM,SAAS,GAAG,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,EAAE,IAAI,EAAE,OAAO,CAAC,CAAC"}
|
package/dist/types.d.ts
CHANGED
|
@@ -18,6 +18,13 @@ export interface CacheEntry<T = unknown> {
|
|
|
18
18
|
* promotes an entry between tiers instead of resetting it to immortal.
|
|
19
19
|
*/
|
|
20
20
|
expiresAt?: number;
|
|
21
|
+
/**
|
|
22
|
+
* The tags the entry was written with, when the driver keeps them. A
|
|
23
|
+
* composing driver needs them to promote an entry between tiers: a
|
|
24
|
+
* promoted copy written without its tags was invisible to `deleteByTag`
|
|
25
|
+
* on the very instance that promoted it.
|
|
26
|
+
*/
|
|
27
|
+
tags?: string[];
|
|
21
28
|
}
|
|
22
29
|
/** Options for the grace-aware {@link CacheDriver.setEntry}. */
|
|
23
30
|
export interface DriverSetOptions {
|
|
@@ -125,7 +132,11 @@ export interface GetOrSetOptions<T> {
|
|
|
125
132
|
timeout?: Duration;
|
|
126
133
|
/** Hard timeout: reject with {@link TimeoutError} if the factory exceeds it (even without a stale fallback). */
|
|
127
134
|
hardTimeout?: Duration;
|
|
128
|
-
/**
|
|
135
|
+
/**
|
|
136
|
+
* Max time to wait on another caller's in-flight factory for the same key
|
|
137
|
+
* (single-flight lock). Past it the stale value is returned when there is
|
|
138
|
+
* one, and a {@link LockTimeoutError} is thrown when there is not.
|
|
139
|
+
*/
|
|
129
140
|
lockTimeout?: Duration;
|
|
130
141
|
tags?: string[];
|
|
131
142
|
/** Observe factory failures (foreground and background). */
|
package/dist/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":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AAG,EAAE,MAAM,CAAC;CACZ;AAED,uEAAuE;AACvE,MAAM,WAAW,aAAa;IAC7B,WAAW,EAAE;QACZ,GAAG,EAAE,MAAM,CAAC;QACZ,KAAK,EAAE,OAAO,CAAC;QACf,KAAK,EAAE,MAAM,CAAC;QACd,MAAM,EAAE,OAAO,CAAC;KAChB,CAAC;IACF,YAAY,EAAE;QAAE,GAAG,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAA;KAAE,CAAC;IAC7C,eAAe,EAAE;QAAE,GAAG,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,OAAO,CAAC;QAAC,KAAK,EAAE,MAAM,CAAA;KAAE,CAAC;IAChE,eAAe,EAAE;QAAE,GAAG,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAA;KAAE,CAAC;IAChD,eAAe,EAAE;QAAE,KAAK,EAAE,MAAM,CAAA;KAAE,CAAC;CACnC;AAED;;;GAGG;AACH,MAAM,WAAW,YAAY;IAC5B;;;;;;;;;;OAUG;IACH,IAAI,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,GAAG,OAAO,CAAC;CAC/C"}
|
|
@@ -1,4 +1,19 @@
|
|
|
1
|
-
|
|
1
|
+
/**
|
|
2
|
+
* The commands among `commands` that `value` does not carry as functions.
|
|
3
|
+
*
|
|
4
|
+
* Reads go through the same catch as above, so a command whose read throws
|
|
5
|
+
* counts as missing.
|
|
6
|
+
*/
|
|
7
|
+
export declare function missingCommands(value: unknown, commands: readonly string[]): string[];
|
|
8
|
+
/**
|
|
9
|
+
* Whether `value` carries every one of `commands` as a function.
|
|
10
|
+
*
|
|
11
|
+
* The building block of the guard a caller passes as `isConnection`, over the
|
|
12
|
+
* same list it passes as `required` — which is what names the gap when the
|
|
13
|
+
* guard says no.
|
|
14
|
+
*/
|
|
15
|
+
export declare function hasCommands(value: unknown, commands: readonly string[]): value is object;
|
|
16
|
+
export interface QuasarConnectionRequest<T> {
|
|
2
17
|
/** The package asking. It prefixes every message this can raise. */
|
|
3
18
|
pkg: string;
|
|
4
19
|
/**
|
|
@@ -12,8 +27,16 @@ export interface QuasarConnectionRequest {
|
|
|
12
27
|
raise: (reason: "quasar-missing" | "incomplete-connection", message: string, cause?: unknown) => Error;
|
|
13
28
|
/** Connection name, or `undefined` for quasar's default. */
|
|
14
29
|
name?: string;
|
|
15
|
-
/** The commands the caller will actually issue. */
|
|
30
|
+
/** The commands the caller will actually issue, named in the message. */
|
|
16
31
|
required: readonly string[];
|
|
32
|
+
/**
|
|
33
|
+
* The caller's check that the connection is the client it needs.
|
|
34
|
+
*
|
|
35
|
+
* Written by the caller over the commands it issues (`hasCommands` with
|
|
36
|
+
* `required` does it), because only the caller knows its client type. The
|
|
37
|
+
* connection is handed over only once this has said yes.
|
|
38
|
+
*/
|
|
39
|
+
isConnection: (value: unknown) => value is T;
|
|
17
40
|
/** What the caller does with them, for the message that names a gap. */
|
|
18
41
|
what: string;
|
|
19
42
|
/**
|
|
@@ -31,5 +54,5 @@ export interface QuasarConnectionRequest {
|
|
|
31
54
|
* handed over — a connection missing one would otherwise fail on the first
|
|
32
55
|
* command, far from the line that asked for it.
|
|
33
56
|
*/
|
|
34
|
-
export declare function quasarConnection<T>(request: QuasarConnectionRequest): Promise<T>;
|
|
57
|
+
export declare function quasarConnection<T>(request: QuasarConnectionRequest<T>): Promise<T>;
|
|
35
58
|
//# sourceMappingURL=quasarConnection.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"quasarConnection.d.ts","sourceRoot":"","sources":["../../src/vendor/quasarConnection.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"quasarConnection.d.ts","sourceRoot":"","sources":["../../src/vendor/quasarConnection.ts"],"names":[],"mappings":"AA0DA;;;;;GAKG;AACH,wBAAgB,eAAe,CAC9B,KAAK,EAAE,OAAO,EACd,QAAQ,EAAE,SAAS,MAAM,EAAE,GACzB,MAAM,EAAE,CAIV;AAED;;;;;;GAMG;AACH,wBAAgB,WAAW,CAC1B,KAAK,EAAE,OAAO,EACd,QAAQ,EAAE,SAAS,MAAM,EAAE,GACzB,KAAK,IAAI,MAAM,CAGjB;AAED,MAAM,WAAW,uBAAuB,CAAC,CAAC;IACzC,oEAAoE;IACpE,GAAG,EAAE,MAAM,CAAC;IACZ;;;;;;;OAOG;IACH,KAAK,EAAE,CACN,MAAM,EAAE,gBAAgB,GAAG,uBAAuB,EAClD,OAAO,EAAE,MAAM,EACf,KAAK,CAAC,EAAE,OAAO,KACX,KAAK,CAAC;IACX,4DAA4D;IAC5D,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,yEAAyE;IACzE,QAAQ,EAAE,SAAS,MAAM,EAAE,CAAC;IAC5B;;;;;;OAMG;IACH,YAAY,EAAE,CAAC,KAAK,EAAE,OAAO,KAAK,KAAK,IAAI,CAAC,CAAC;IAC7C,wEAAwE;IACxE,IAAI,EAAE,MAAM,CAAC;IACb;;;;;;;OAOG;IACH,WAAW,CAAC,EAAE,MAAM,CAAC;CACrB;AAED;;;;GAIG;AACH,wBAAsB,gBAAgB,CAAC,CAAC,EACvC,OAAO,EAAE,uBAAuB,CAAC,CAAC,CAAC,GACjC,OAAO,CAAC,CAAC,CAAC,CAsDZ"}
|
|
@@ -3,29 +3,42 @@
|
|
|
3
3
|
// This package is published and built from its own repository, so the file
|
|
4
4
|
// has to exist here rather than be imported. `pnpm vendor:sync` rewrites it,
|
|
5
5
|
// and `pnpm vendor:check` fails if this copy has drifted from the original.
|
|
6
|
-
/**
|
|
7
|
-
* Read a member without assuming how the object answers.
|
|
8
|
-
*
|
|
9
|
-
* Two shapes have to work, and they disagree about `in`. Quasar's accessor is
|
|
10
|
-
* a Proxy over an empty null-prototype object with only a `get` trap, so
|
|
11
|
-
* `"connection" in manager` is FALSE while reading it returns the function —
|
|
12
|
-
* gating on `in` rejected the real manager. And a module namespace under a
|
|
13
|
-
* test double RAISES for an export it does not have, rather than answering
|
|
14
|
-
* undefined, so a bare read fails on the mock. Reading through a catch is what
|
|
15
|
-
* satisfies both.
|
|
16
|
-
*/
|
|
17
6
|
function readMember(value, name) {
|
|
18
7
|
if (typeof value !== "object" || value === null)
|
|
19
|
-
return undefined;
|
|
8
|
+
return { value: undefined };
|
|
20
9
|
try {
|
|
21
|
-
return Reflect.get(value, name);
|
|
10
|
+
return { value: Reflect.get(value, name) };
|
|
22
11
|
}
|
|
23
|
-
catch {
|
|
24
|
-
return
|
|
12
|
+
catch (threw) {
|
|
13
|
+
return { threw };
|
|
25
14
|
}
|
|
26
15
|
}
|
|
16
|
+
function memberValue(read) {
|
|
17
|
+
return "value" in read ? read.value : undefined;
|
|
18
|
+
}
|
|
27
19
|
function isConnectionSource(value) {
|
|
28
|
-
return typeof readMember(value, "connection") === "function";
|
|
20
|
+
return typeof memberValue(readMember(value, "connection")) === "function";
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* The commands among `commands` that `value` does not carry as functions.
|
|
24
|
+
*
|
|
25
|
+
* Reads go through the same catch as above, so a command whose read throws
|
|
26
|
+
* counts as missing.
|
|
27
|
+
*/
|
|
28
|
+
export function missingCommands(value, commands) {
|
|
29
|
+
return commands.filter((command) => typeof memberValue(readMember(value, command)) !== "function");
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Whether `value` carries every one of `commands` as a function.
|
|
33
|
+
*
|
|
34
|
+
* The building block of the guard a caller passes as `isConnection`, over the
|
|
35
|
+
* same list it passes as `required` — which is what names the gap when the
|
|
36
|
+
* guard says no.
|
|
37
|
+
*/
|
|
38
|
+
export function hasCommands(value, commands) {
|
|
39
|
+
if (typeof value !== "object" || value === null)
|
|
40
|
+
return false;
|
|
41
|
+
return missingCommands(value, commands).length === 0;
|
|
29
42
|
}
|
|
30
43
|
/**
|
|
31
44
|
* The named connection, checked for the commands the caller needs BEFORE it is
|
|
@@ -33,7 +46,7 @@ function isConnectionSource(value) {
|
|
|
33
46
|
* command, far from the line that asked for it.
|
|
34
47
|
*/
|
|
35
48
|
export async function quasarConnection(request) {
|
|
36
|
-
const { pkg, name, required, what, raise, alternative } = request;
|
|
49
|
+
const { pkg, name, required, what, raise, alternative, isConnection } = request;
|
|
37
50
|
const specifier = "@c9up/quasar/services/main";
|
|
38
51
|
let loaded;
|
|
39
52
|
try {
|
|
@@ -43,20 +56,28 @@ export async function quasarConnection(request) {
|
|
|
43
56
|
throw raise("quasar-missing", `[${pkg}] ${what} asks for the quasar connection "${name ?? "default"}", but @c9up/quasar is not installed.\n` +
|
|
44
57
|
` pnpm add @c9up/quasar${alternative ? `, ${alternative}` : ""}`, cause);
|
|
45
58
|
}
|
|
46
|
-
|
|
59
|
+
// The namespace itself may be the manager (a test double); a throw there is
|
|
60
|
+
// the mock refusing an export it lacks, not an answer.
|
|
61
|
+
const direct = memberValue(readMember(loaded, "connection"));
|
|
62
|
+
const manager = typeof direct === "function"
|
|
47
63
|
? loaded
|
|
48
|
-
:
|
|
64
|
+
: memberValue(readMember(Object(loaded), "default"));
|
|
65
|
+
const read = readMember(manager, "connection");
|
|
66
|
+
if ("threw" in read) {
|
|
67
|
+
throw raise("quasar-missing", `[${pkg}] ${what} asks for the quasar connection "${name ?? "default"}", but @c9up/quasar's manager is not available yet: ` +
|
|
68
|
+
"its provider has not booted, or is not registered in this application's providers.", read.threw);
|
|
69
|
+
}
|
|
49
70
|
if (!isConnectionSource(manager)) {
|
|
50
71
|
throw raise("quasar-missing", `[${pkg}] @c9up/quasar/services/main did not expose a connection() manager`);
|
|
51
72
|
}
|
|
52
73
|
const connection = manager.connection(name);
|
|
53
|
-
const missing =
|
|
74
|
+
const missing = missingCommands(connection, required);
|
|
54
75
|
if (missing.length > 0) {
|
|
55
76
|
throw raise("incomplete-connection", `[${pkg}] the quasar connection${name ? ` '${name}'` : ""} is missing ${missing.join(", ")}, which ${what} issues`);
|
|
56
77
|
}
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
78
|
+
if (!isConnection(connection)) {
|
|
79
|
+
throw raise("incomplete-connection", `[${pkg}] the quasar connection${name ? ` '${name}'` : ""} is not the client ${what} needs`);
|
|
80
|
+
}
|
|
60
81
|
return connection;
|
|
61
82
|
}
|
|
62
83
|
//# sourceMappingURL=quasarConnection.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"quasarConnection.js","sourceRoot":"","sources":["../../src/vendor/quasarConnection.ts"],"names":[],"mappings":"AAAA,mEAAmE;AACnE,EAAE;AACF,2EAA2E;AAC3E,6EAA6E;AAC7E,4EAA4E;
|
|
1
|
+
{"version":3,"file":"quasarConnection.js","sourceRoot":"","sources":["../../src/vendor/quasarConnection.ts"],"names":[],"mappings":"AAAA,mEAAmE;AACnE,EAAE;AACF,2EAA2E;AAC3E,6EAA6E;AAC7E,4EAA4E;AAqC5E,SAAS,UAAU,CAAC,KAAc,EAAE,IAAY;IAC/C,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI;QAAE,OAAO,EAAE,KAAK,EAAE,SAAS,EAAE,CAAC;IAC7E,IAAI,CAAC;QACJ,OAAO,EAAE,KAAK,EAAE,OAAO,CAAC,GAAG,CAAC,KAAK,EAAE,IAAI,CAAC,EAAE,CAAC;IAC5C,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QAChB,OAAO,EAAE,KAAK,EAAE,CAAC;IAClB,CAAC;AACF,CAAC;AAED,SAAS,WAAW,CAAC,IAAgB;IACpC,OAAO,OAAO,IAAI,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,SAAS,CAAC;AACjD,CAAC;AAED,SAAS,kBAAkB,CAAC,KAAc;IACzC,OAAO,OAAO,WAAW,CAAC,UAAU,CAAC,KAAK,EAAE,YAAY,CAAC,CAAC,KAAK,UAAU,CAAC;AAC3E,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,eAAe,CAC9B,KAAc,EACd,QAA2B;IAE3B,OAAO,QAAQ,CAAC,MAAM,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": "Cache — pluggable cache contract with memory + Redis drivers for the Ream framework",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -26,16 +26,20 @@
|
|
|
26
26
|
"./testing": {
|
|
27
27
|
"types": "./dist/testing/main.d.ts",
|
|
28
28
|
"import": "./dist/testing/main.js"
|
|
29
|
+
},
|
|
30
|
+
"./commands": {
|
|
31
|
+
"types": "./dist/console/index.d.ts",
|
|
32
|
+
"import": "./dist/console/index.js"
|
|
29
33
|
}
|
|
30
34
|
},
|
|
31
35
|
"peerDependencies": {
|
|
32
36
|
"@c9up/quasar": "^0.1.0 || ^0.2.0",
|
|
33
|
-
"@c9up/ream": "^0.2.
|
|
37
|
+
"@c9up/ream": "^0.2.26"
|
|
34
38
|
},
|
|
35
39
|
"devDependencies": {
|
|
36
40
|
"@biomejs/biome": "^2.5.12",
|
|
37
41
|
"@c9up/quasar": "^0.1.0 || ^0.2.0",
|
|
38
|
-
"@c9up/ream": "^0.2.
|
|
42
|
+
"@c9up/ream": "^0.2.25",
|
|
39
43
|
"@types/node": "^22.20.1",
|
|
40
44
|
"@vitest/coverage-v8": "4.1.11",
|
|
41
45
|
"typescript": "^6.0.3",
|
|
@@ -48,6 +52,7 @@
|
|
|
48
52
|
"files": [
|
|
49
53
|
"src",
|
|
50
54
|
"dist",
|
|
55
|
+
"stubs",
|
|
51
56
|
"README.md",
|
|
52
57
|
"LICENSE"
|
|
53
58
|
],
|