@c9up/warden 0.2.4 → 0.2.6
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 +70 -3
- package/dist/AccessToken.d.ts +257 -0
- package/dist/AccessToken.d.ts.map +1 -0
- package/dist/AccessToken.js +370 -0
- package/dist/AccessToken.js.map +1 -0
- package/dist/AttemptStore.d.ts +16 -2
- package/dist/AttemptStore.d.ts.map +1 -1
- package/dist/AttemptStore.js +26 -12
- package/dist/AttemptStore.js.map +1 -1
- package/dist/AuthManager.d.ts +33 -2
- package/dist/AuthManager.d.ts.map +1 -1
- package/dist/AuthManager.js +23 -2
- package/dist/AuthManager.js.map +1 -1
- package/dist/Authenticator.d.ts +19 -1
- package/dist/Authenticator.d.ts.map +1 -1
- package/dist/Authenticator.js +37 -3
- package/dist/Authenticator.js.map +1 -1
- package/dist/Guard.d.ts.map +1 -1
- package/dist/Guard.js +17 -5
- package/dist/Guard.js.map +1 -1
- package/dist/ResilientBlacklistDriver.d.ts +23 -6
- package/dist/ResilientBlacklistDriver.d.ts.map +1 -1
- package/dist/ResilientBlacklistDriver.js +24 -8
- package/dist/ResilientBlacklistDriver.js.map +1 -1
- package/dist/WardenProvider.d.ts +2 -0
- package/dist/WardenProvider.d.ts.map +1 -1
- package/dist/WardenProvider.js +4 -58
- package/dist/WardenProvider.js.map +1 -1
- package/dist/config.d.ts +8 -4
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +4 -1
- package/dist/config.js.map +1 -1
- package/dist/index.d.ts +4 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -1
- package/dist/index.js.map +1 -1
- package/dist/mfa/MfaManager.d.ts +16 -4
- package/dist/mfa/MfaManager.d.ts.map +1 -1
- package/dist/mfa/MfaManager.js +32 -6
- package/dist/mfa/MfaManager.js.map +1 -1
- package/dist/middleware.d.ts.map +1 -1
- package/dist/middleware.js +27 -5
- package/dist/middleware.js.map +1 -1
- package/dist/native.d.ts +6 -2
- package/dist/native.d.ts.map +1 -1
- package/dist/native.js +19 -2
- package/dist/native.js.map +1 -1
- package/dist/quasar.d.ts.map +1 -1
- package/dist/quasar.js +8 -1
- package/dist/quasar.js.map +1 -1
- package/dist/standalone.d.ts +24 -3
- package/dist/standalone.d.ts.map +1 -1
- package/dist/standalone.js +21 -29
- package/dist/standalone.js.map +1 -1
- package/dist/strategies/ApiKeyStrategy.d.ts +45 -12
- package/dist/strategies/ApiKeyStrategy.d.ts.map +1 -1
- package/dist/strategies/ApiKeyStrategy.js +71 -37
- package/dist/strategies/ApiKeyStrategy.js.map +1 -1
- package/dist/strategies/JwtStrategy.d.ts.map +1 -1
- package/dist/strategies/JwtStrategy.js +3 -3
- package/dist/strategies/JwtStrategy.js.map +1 -1
- package/dist/strategies/SessionStrategy.d.ts +48 -1
- package/dist/strategies/SessionStrategy.d.ts.map +1 -1
- package/dist/strategies/SessionStrategy.js +70 -4
- package/dist/strategies/SessionStrategy.js.map +1 -1
- package/dist/templateTags.d.ts +42 -0
- package/dist/templateTags.d.ts.map +1 -0
- package/dist/templateTags.js +82 -0
- package/dist/templateTags.js.map +1 -0
- package/dist/vendor/nativeBinary.d.ts +26 -2
- package/dist/vendor/nativeBinary.d.ts.map +1 -1
- package/dist/vendor/nativeBinary.js +63 -6
- package/dist/vendor/nativeBinary.js.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/index.darwin-arm64.node +0 -0
- package/index.darwin-x64.node +0 -0
- package/index.linux-arm64-gnu.node +0 -0
- package/index.linux-x64-gnu.node +0 -0
- package/index.win32-x64-msvc.node +0 -0
- package/package.json +8 -3
- package/src/AccessToken.ts +550 -0
- package/src/AttemptStore.ts +29 -13
- package/src/AuthManager.ts +40 -2
- package/src/Authenticator.ts +39 -3
- package/src/Guard.ts +18 -5
- package/src/ResilientBlacklistDriver.ts +28 -8
- package/src/WardenProvider.ts +6 -83
- package/src/config.ts +8 -4
- package/src/index.ts +18 -0
- package/src/mfa/MfaManager.ts +39 -6
- package/src/middleware.ts +36 -5
- package/src/native.ts +20 -4
- package/src/quasar.ts +13 -2
- package/src/standalone.ts +74 -33
- package/src/strategies/ApiKeyStrategy.ts +112 -42
- package/src/strategies/JwtStrategy.ts +3 -1
- package/src/strategies/SessionStrategy.ts +121 -4
- package/src/templateTags.ts +117 -0
- package/src/vendor/nativeBinary.ts +82 -6
- package/src/vendor/quasarConnection.ts +84 -22
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
import { WardenError } from "./errors.js";
|
|
2
|
+
|
|
3
|
+
/** The only surface warden needs of a template engine. */
|
|
4
|
+
export interface TemplateEngineLike {
|
|
5
|
+
registerTag(tag: {
|
|
6
|
+
tagName: string;
|
|
7
|
+
block: boolean;
|
|
8
|
+
seekable: boolean;
|
|
9
|
+
compile(
|
|
10
|
+
parser: unknown,
|
|
11
|
+
buffer: { writeRaw(text: string): void },
|
|
12
|
+
token: {
|
|
13
|
+
properties: { jsArg: string };
|
|
14
|
+
renderBody(): string | Promise<string>;
|
|
15
|
+
evaluate(expression: string): unknown;
|
|
16
|
+
},
|
|
17
|
+
): void | Promise<void>;
|
|
18
|
+
}): void;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Register `@can` / `@cannot`, as AdonisJS's bouncer publishes them. A
|
|
23
|
+
* migrated template keeps `@can('PostPolicy.edit', post) … @endcan` unchanged.
|
|
24
|
+
*
|
|
25
|
+
* Both are BLOCK tags and both AWAIT — the check returns a promise — so they
|
|
26
|
+
* render on the async path and raise on a synchronous one, matching upstream
|
|
27
|
+
* (which emits `await bouncer.can(...)`). The checks themselves come from
|
|
28
|
+
* `ctx.bouncer.templateHelpers`, shared into the view per request.
|
|
29
|
+
*/
|
|
30
|
+
export function registerBouncerTemplateTags(engine: TemplateEngineLike): void {
|
|
31
|
+
for (const tagName of ["can", "cannot"] as const) {
|
|
32
|
+
engine.registerTag({
|
|
33
|
+
tagName,
|
|
34
|
+
block: true,
|
|
35
|
+
seekable: true,
|
|
36
|
+
async compile(_parser, buffer, token) {
|
|
37
|
+
// The shared bag lives in the render scope under `bouncer`.
|
|
38
|
+
const bouncer = token.evaluate(
|
|
39
|
+
"typeof bouncer === 'undefined' ? undefined : bouncer",
|
|
40
|
+
);
|
|
41
|
+
const check = Reflect.get(Object(bouncer), tagName);
|
|
42
|
+
if (typeof check !== "function") {
|
|
43
|
+
// No bouncer on this request: deny rather than render an
|
|
44
|
+
// unguarded body.
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
const args = token.evaluate(`[${token.properties.jsArg}]`);
|
|
48
|
+
const allowed = await check.apply(
|
|
49
|
+
bouncer,
|
|
50
|
+
Array.isArray(args) ? args : [],
|
|
51
|
+
);
|
|
52
|
+
if (allowed === true) buffer.writeRaw(await token.renderBody());
|
|
53
|
+
},
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/** Loads the template engine package. Swappable so a test needs no engine. */
|
|
59
|
+
export type EnginePackageLoader = () => Promise<unknown>;
|
|
60
|
+
|
|
61
|
+
const loadInker: EnginePackageLoader = () => {
|
|
62
|
+
// Built rather than written inline: inker is an OPTIONAL peer, and a
|
|
63
|
+
// literal `import("@c9up/inker")` makes a bundler resolve it at build time
|
|
64
|
+
// for an application that never installed it. Computed, it only runs
|
|
65
|
+
// behind the `usingInker` flag.
|
|
66
|
+
const specifier = "@c9up/inker";
|
|
67
|
+
return import(/* @vite-ignore */ specifier);
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
function unusable(detail: string): WardenError {
|
|
71
|
+
return new WardenError(
|
|
72
|
+
"E_WARDEN_TEMPLATE_ENGINE_UNUSABLE",
|
|
73
|
+
`The template engine is installed but @can / @cannot cannot be registered: ${detail}`,
|
|
74
|
+
{
|
|
75
|
+
hint: "`@c9up/inker` must default-export its plugin registrar (`inker.use(plugin)`), whose plugins receive an engine with `registerTag()`.",
|
|
76
|
+
},
|
|
77
|
+
);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* Publish the bouncer tags the way AdonisJS's bouncer does with Edge: through
|
|
82
|
+
* the engine package's MODULE SINGLETON (`inker.use(plugin)`), guarded by the
|
|
83
|
+
* host's `usingInker` flag — never by resolving a container binding. `use()`
|
|
84
|
+
* queues the plugin and the engine runs it before its next render, whenever
|
|
85
|
+
* the engine was built.
|
|
86
|
+
*
|
|
87
|
+
* Returns whether the tags were handed over. A registrar or an engine of the
|
|
88
|
+
* wrong shape is an error, not a skip: an unregistered `@can` would render as
|
|
89
|
+
* plain text and show the guarded body's markup to everyone.
|
|
90
|
+
*/
|
|
91
|
+
export async function installBouncerTemplateTags(
|
|
92
|
+
usingInker: boolean,
|
|
93
|
+
load: EnginePackageLoader = loadInker,
|
|
94
|
+
): Promise<boolean> {
|
|
95
|
+
if (!usingInker) return false;
|
|
96
|
+
const module: unknown = await load();
|
|
97
|
+
const registrar =
|
|
98
|
+
typeof module === "object" && module !== null
|
|
99
|
+
? Reflect.get(module, "default")
|
|
100
|
+
: undefined;
|
|
101
|
+
const use = Reflect.get(Object(registrar), "use");
|
|
102
|
+
if (typeof use !== "function") {
|
|
103
|
+
throw unusable("its default export has no use()");
|
|
104
|
+
}
|
|
105
|
+
use.call(registrar, (engine: unknown) => {
|
|
106
|
+
const register = Reflect.get(Object(engine), "registerTag");
|
|
107
|
+
if (typeof register !== "function") {
|
|
108
|
+
throw unusable("the engine has no registerTag()");
|
|
109
|
+
}
|
|
110
|
+
registerBouncerTemplateTags({
|
|
111
|
+
registerTag: (tag) => {
|
|
112
|
+
register.call(engine, tag);
|
|
113
|
+
},
|
|
114
|
+
});
|
|
115
|
+
});
|
|
116
|
+
return true;
|
|
117
|
+
}
|
|
@@ -87,24 +87,100 @@ export type NativeBinaryResult<T> =
|
|
|
87
87
|
| { loaded: true; binary: T }
|
|
88
88
|
| { loaded: false; suffix: string | undefined; cause?: unknown };
|
|
89
89
|
|
|
90
|
+
/** Whether `value` carries a function under `name` (a napi class is one too). */
|
|
91
|
+
function hasFunction(value: object, name: string): boolean {
|
|
92
|
+
const member: unknown = Reflect.get(value, name);
|
|
93
|
+
return typeof member === "function";
|
|
94
|
+
}
|
|
95
|
+
|
|
90
96
|
/**
|
|
91
|
-
*
|
|
97
|
+
* The names among `names` that `value` does not carry as functions.
|
|
98
|
+
*
|
|
99
|
+
* Classes count, being functions, and so does a class's static member: `value`
|
|
100
|
+
* may itself be a function. What a guard rejects is only useful named, so the
|
|
101
|
+
* loader reports this list rather than a bare "no".
|
|
102
|
+
*/
|
|
103
|
+
export function missingFunctions(
|
|
104
|
+
value: unknown,
|
|
105
|
+
names: readonly string[],
|
|
106
|
+
): string[] {
|
|
107
|
+
if (
|
|
108
|
+
value === null ||
|
|
109
|
+
(typeof value !== "object" && typeof value !== "function")
|
|
110
|
+
) {
|
|
111
|
+
return [...names];
|
|
112
|
+
}
|
|
113
|
+
return names.filter((name) => !hasFunction(value, name));
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* Whether `value` carries every one of `names` as a function.
|
|
118
|
+
*
|
|
119
|
+
* The building block of the guard a package hands to `loadNativeBinary`, over
|
|
120
|
+
* the list of what it actually calls on its binary — the same list it passes
|
|
121
|
+
* as `expects`, so the message can name what is missing.
|
|
122
|
+
*/
|
|
123
|
+
export function hasFunctions(
|
|
124
|
+
value: unknown,
|
|
125
|
+
names: readonly string[],
|
|
126
|
+
): value is object {
|
|
127
|
+
if (
|
|
128
|
+
value === null ||
|
|
129
|
+
(typeof value !== "object" && typeof value !== "function")
|
|
130
|
+
) {
|
|
131
|
+
return false;
|
|
132
|
+
}
|
|
133
|
+
return missingFunctions(value, names).length === 0;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
/**
|
|
137
|
+
* Load `<package root>/index.<suffix>.node`, and check it is the binary the
|
|
138
|
+
* package calls.
|
|
92
139
|
*
|
|
93
140
|
* The path is fixed rather than passed: this file is generated into
|
|
94
141
|
* `<package>/src/vendor/`, so the package root is always two levels up, from
|
|
95
142
|
* `src` and from `dist` alike.
|
|
143
|
+
*
|
|
144
|
+
* `isBinary` is the package's own check of what it calls. A declaration only
|
|
145
|
+
* says what the Rust promises: a stale build, or one from another version,
|
|
146
|
+
* loads just as well and then fails on the first missing call, far from here.
|
|
147
|
+
* A rejected module is reported as a failed load, so the package's policy
|
|
148
|
+
* (degrade or refuse) applies to it unchanged. `expects`, the list the guard is
|
|
149
|
+
* built from, lets that report name the missing calls.
|
|
96
150
|
*/
|
|
97
|
-
export function loadNativeBinary<T>(
|
|
151
|
+
export function loadNativeBinary<T>(
|
|
152
|
+
isBinary: (value: unknown) => value is T,
|
|
153
|
+
expects?: readonly string[],
|
|
154
|
+
): NativeBinaryResult<T> {
|
|
98
155
|
const suffix = nativeBinarySuffix();
|
|
99
156
|
if (suffix === undefined) return { loaded: false, suffix };
|
|
100
157
|
const here = dirname(fileURLToPath(import.meta.url));
|
|
158
|
+
let loaded: unknown;
|
|
101
159
|
try {
|
|
102
160
|
const nodeRequire = createRequire(import.meta.url);
|
|
103
|
-
|
|
104
|
-
loaded: true,
|
|
105
|
-
binary: nodeRequire(join(here, `../../index.${suffix}.node`)) as T,
|
|
106
|
-
};
|
|
161
|
+
loaded = nodeRequire(join(here, `../../index.${suffix}.node`));
|
|
107
162
|
} catch (cause) {
|
|
108
163
|
return { loaded: false, suffix, cause };
|
|
109
164
|
}
|
|
165
|
+
if (isBinary(loaded)) return { loaded: true, binary: loaded };
|
|
166
|
+
return {
|
|
167
|
+
loaded: false,
|
|
168
|
+
suffix,
|
|
169
|
+
cause: new Error(
|
|
170
|
+
`index.${suffix}.node loaded, but ${rejection(loaded, expects)}. ` +
|
|
171
|
+
"The binary is stale or from another version: rebuild it.",
|
|
172
|
+
),
|
|
173
|
+
};
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
/** What a rejected binary lacks, or, without a list to check, what it has. */
|
|
177
|
+
function rejection(loaded: unknown, expects?: readonly string[]): string {
|
|
178
|
+
const missing =
|
|
179
|
+
expects === undefined ? [] : missingFunctions(loaded, expects);
|
|
180
|
+
if (missing.length > 0) return `it lacks ${missing.join(", ")}`;
|
|
181
|
+
const exported =
|
|
182
|
+
typeof loaded === "object" && loaded !== null
|
|
183
|
+
? Object.keys(loaded).filter((name) => hasFunction(loaded, name))
|
|
184
|
+
: [];
|
|
185
|
+
return `it is not the binary this package calls (it exports: ${exported.length > 0 ? exported.join(", ") : "none"})`;
|
|
110
186
|
}
|
|
@@ -31,23 +31,62 @@ interface ConnectionSource {
|
|
|
31
31
|
* `"connection" in manager` is FALSE while reading it returns the function —
|
|
32
32
|
* gating on `in` rejected the real manager. And a module namespace under a
|
|
33
33
|
* test double RAISES for an export it does not have, rather than answering
|
|
34
|
-
* undefined, so a bare read fails on the mock.
|
|
35
|
-
*
|
|
34
|
+
* undefined, so a bare read fails on the mock.
|
|
35
|
+
*
|
|
36
|
+
* So the read is caught, but what it raised is kept: on quasar's accessor a
|
|
37
|
+
* throw is not an absence, it is the accessor saying its provider has not
|
|
38
|
+
* booted, and dropping that turned it into a wrong diagnosis.
|
|
36
39
|
*/
|
|
37
|
-
|
|
38
|
-
|
|
40
|
+
type MemberRead = { value: unknown } | { threw: unknown };
|
|
41
|
+
|
|
42
|
+
function readMember(value: unknown, name: string): MemberRead {
|
|
43
|
+
if (typeof value !== "object" || value === null) return { value: undefined };
|
|
39
44
|
try {
|
|
40
|
-
return Reflect.get(value, name);
|
|
41
|
-
} catch {
|
|
42
|
-
return
|
|
45
|
+
return { value: Reflect.get(value, name) };
|
|
46
|
+
} catch (threw) {
|
|
47
|
+
return { threw };
|
|
43
48
|
}
|
|
44
49
|
}
|
|
45
50
|
|
|
51
|
+
function memberValue(read: MemberRead): unknown {
|
|
52
|
+
return "value" in read ? read.value : undefined;
|
|
53
|
+
}
|
|
54
|
+
|
|
46
55
|
function isConnectionSource(value: unknown): value is ConnectionSource {
|
|
47
|
-
return typeof readMember(value, "connection") === "function";
|
|
56
|
+
return typeof memberValue(readMember(value, "connection")) === "function";
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* The commands among `commands` that `value` does not carry as functions.
|
|
61
|
+
*
|
|
62
|
+
* Reads go through the same catch as above, so a command whose read throws
|
|
63
|
+
* counts as missing.
|
|
64
|
+
*/
|
|
65
|
+
export function missingCommands(
|
|
66
|
+
value: unknown,
|
|
67
|
+
commands: readonly string[],
|
|
68
|
+
): string[] {
|
|
69
|
+
return commands.filter(
|
|
70
|
+
(command) => typeof memberValue(readMember(value, command)) !== "function",
|
|
71
|
+
);
|
|
48
72
|
}
|
|
49
73
|
|
|
50
|
-
|
|
74
|
+
/**
|
|
75
|
+
* Whether `value` carries every one of `commands` as a function.
|
|
76
|
+
*
|
|
77
|
+
* The building block of the guard a caller passes as `isConnection`, over the
|
|
78
|
+
* same list it passes as `required` — which is what names the gap when the
|
|
79
|
+
* guard says no.
|
|
80
|
+
*/
|
|
81
|
+
export function hasCommands(
|
|
82
|
+
value: unknown,
|
|
83
|
+
commands: readonly string[],
|
|
84
|
+
): value is object {
|
|
85
|
+
if (typeof value !== "object" || value === null) return false;
|
|
86
|
+
return missingCommands(value, commands).length === 0;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
export interface QuasarConnectionRequest<T> {
|
|
51
90
|
/** The package asking. It prefixes every message this can raise. */
|
|
52
91
|
pkg: string;
|
|
53
92
|
/**
|
|
@@ -65,8 +104,16 @@ export interface QuasarConnectionRequest {
|
|
|
65
104
|
) => Error;
|
|
66
105
|
/** Connection name, or `undefined` for quasar's default. */
|
|
67
106
|
name?: string;
|
|
68
|
-
/** The commands the caller will actually issue. */
|
|
107
|
+
/** The commands the caller will actually issue, named in the message. */
|
|
69
108
|
required: readonly string[];
|
|
109
|
+
/**
|
|
110
|
+
* The caller's check that the connection is the client it needs.
|
|
111
|
+
*
|
|
112
|
+
* Written by the caller over the commands it issues (`hasCommands` with
|
|
113
|
+
* `required` does it), because only the caller knows its client type. The
|
|
114
|
+
* connection is handed over only once this has said yes.
|
|
115
|
+
*/
|
|
116
|
+
isConnection: (value: unknown) => value is T;
|
|
70
117
|
/** What the caller does with them, for the message that names a gap. */
|
|
71
118
|
what: string;
|
|
72
119
|
/**
|
|
@@ -86,9 +133,10 @@ export interface QuasarConnectionRequest {
|
|
|
86
133
|
* command, far from the line that asked for it.
|
|
87
134
|
*/
|
|
88
135
|
export async function quasarConnection<T>(
|
|
89
|
-
request: QuasarConnectionRequest
|
|
136
|
+
request: QuasarConnectionRequest<T>,
|
|
90
137
|
): Promise<T> {
|
|
91
|
-
const { pkg, name, required, what, raise, alternative } =
|
|
138
|
+
const { pkg, name, required, what, raise, alternative, isConnection } =
|
|
139
|
+
request;
|
|
92
140
|
const specifier = "@c9up/quasar/services/main";
|
|
93
141
|
let loaded: unknown;
|
|
94
142
|
try {
|
|
@@ -102,9 +150,22 @@ export async function quasarConnection<T>(
|
|
|
102
150
|
);
|
|
103
151
|
}
|
|
104
152
|
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
153
|
+
// The namespace itself may be the manager (a test double); a throw there is
|
|
154
|
+
// the mock refusing an export it lacks, not an answer.
|
|
155
|
+
const direct = memberValue(readMember(loaded, "connection"));
|
|
156
|
+
const manager =
|
|
157
|
+
typeof direct === "function"
|
|
158
|
+
? loaded
|
|
159
|
+
: memberValue(readMember(Object(loaded), "default"));
|
|
160
|
+
const read = readMember(manager, "connection");
|
|
161
|
+
if ("threw" in read) {
|
|
162
|
+
throw raise(
|
|
163
|
+
"quasar-missing",
|
|
164
|
+
`[${pkg}] ${what} asks for the quasar connection "${name ?? "default"}", but @c9up/quasar's manager is not available yet: ` +
|
|
165
|
+
"its provider has not booted, or is not registered in this application's providers.",
|
|
166
|
+
read.threw,
|
|
167
|
+
);
|
|
168
|
+
}
|
|
108
169
|
if (!isConnectionSource(manager)) {
|
|
109
170
|
throw raise(
|
|
110
171
|
"quasar-missing",
|
|
@@ -113,17 +174,18 @@ export async function quasarConnection<T>(
|
|
|
113
174
|
}
|
|
114
175
|
|
|
115
176
|
const connection = manager.connection(name);
|
|
116
|
-
const missing = required
|
|
117
|
-
(command) => typeof readMember(connection, command) !== "function",
|
|
118
|
-
);
|
|
177
|
+
const missing = missingCommands(connection, required);
|
|
119
178
|
if (missing.length > 0) {
|
|
120
179
|
throw raise(
|
|
121
180
|
"incomplete-connection",
|
|
122
181
|
`[${pkg}] the quasar connection${name ? ` '${name}'` : ""} is missing ${missing.join(", ")}, which ${what} issues`,
|
|
123
182
|
);
|
|
124
183
|
}
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
184
|
+
if (!isConnection(connection)) {
|
|
185
|
+
throw raise(
|
|
186
|
+
"incomplete-connection",
|
|
187
|
+
`[${pkg}] the quasar connection${name ? ` '${name}'` : ""} is not the client ${what} needs`,
|
|
188
|
+
);
|
|
189
|
+
}
|
|
190
|
+
return connection;
|
|
129
191
|
}
|