@ultimat3/query 30.7.0 → 30.9.0
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/package.json +8 -8
- package/src/exercise-declarations.ts +6 -2
- package/src/exercise.ts +13 -7
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ultimat3/query",
|
|
3
|
-
"version": "30.
|
|
3
|
+
"version": "30.9.0",
|
|
4
4
|
"description": "The query primitive: a policy-checked read, optionally live, with cursor pagination and an incremental matcher",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"ultimate",
|
|
@@ -47,12 +47,12 @@
|
|
|
47
47
|
"test": "bun test"
|
|
48
48
|
},
|
|
49
49
|
"dependencies": {
|
|
50
|
-
"@ultimat3/cache": "30.
|
|
51
|
-
"@ultimat3/core": "30.
|
|
52
|
-
"@ultimat3/db": "30.
|
|
53
|
-
"@ultimat3/entity": "30.
|
|
54
|
-
"@ultimat3/http": "30.
|
|
55
|
-
"@ultimat3/policy": "30.
|
|
56
|
-
"@ultimat3/schema": "30.
|
|
50
|
+
"@ultimat3/cache": "30.9.0",
|
|
51
|
+
"@ultimat3/core": "30.9.0",
|
|
52
|
+
"@ultimat3/db": "30.9.0",
|
|
53
|
+
"@ultimat3/entity": "30.9.0",
|
|
54
|
+
"@ultimat3/http": "30.9.0",
|
|
55
|
+
"@ultimat3/policy": "30.9.0",
|
|
56
|
+
"@ultimat3/schema": "30.9.0"
|
|
57
57
|
}
|
|
58
58
|
}
|
|
@@ -24,11 +24,15 @@ export const isQueryExerciseDeclarations = (
|
|
|
24
24
|
value: QueryContractExercise,
|
|
25
25
|
): value is QueryExerciseDeclarations => 'kind' in value && value.kind === 'exercise-overrides';
|
|
26
26
|
|
|
27
|
-
/**
|
|
27
|
+
/**
|
|
28
|
+
* The entry `name` reads: the declarations' own, or the inline one. `undefined` when none. A
|
|
29
|
+
* `'query:<name>'` key wins over the bare name — the one `x exercise` reads for a query whose
|
|
30
|
+
* name another kind shares (`@ultimat3/testing`'s `overrideFor`; action's twin keeps the same rule).
|
|
31
|
+
*/
|
|
28
32
|
export function resolveQueryExercise(
|
|
29
33
|
name: string,
|
|
30
34
|
exercise: QueryContractExercise | undefined,
|
|
31
35
|
): QueryExerciseOptions | undefined {
|
|
32
36
|
if (exercise === undefined || !isQueryExerciseDeclarations(exercise)) return exercise;
|
|
33
|
-
return exercise.entries.get(name);
|
|
37
|
+
return exercise.entries.get(`query:${name}`) ?? exercise.entries.get(name);
|
|
34
38
|
}
|
package/src/exercise.ts
CHANGED
|
@@ -18,7 +18,8 @@ import {
|
|
|
18
18
|
tryUseContext,
|
|
19
19
|
UltimateError,
|
|
20
20
|
} from '@ultimat3/core';
|
|
21
|
-
import {
|
|
21
|
+
import type { ExerciseRequestOption } from '@ultimat3/http';
|
|
22
|
+
import { statusFor, withRequestAs, withScratchRateLimitStore } from '@ultimat3/http';
|
|
22
23
|
import { admitsAnonymous } from '@ultimat3/policy';
|
|
23
24
|
import type { StandardSchemaV1 } from '@ultimat3/schema';
|
|
24
25
|
import { validateAsync } from '@ultimat3/schema';
|
|
@@ -38,6 +39,8 @@ export interface QueryExerciseActorOptions {
|
|
|
38
39
|
readonly actor?: Actor | null | undefined;
|
|
39
40
|
readonly input?: (drawn: DrawnInput) => unknown;
|
|
40
41
|
readonly runs?: number;
|
|
42
|
+
/** What each run's request carries in; the read then runs inside it (action's `request`). */
|
|
43
|
+
readonly request?: ExerciseRequestOption;
|
|
41
44
|
}
|
|
42
45
|
|
|
43
46
|
export interface QueryExerciseOffOptions {
|
|
@@ -93,13 +96,16 @@ export async function exerciseQuery(
|
|
|
93
96
|
bind: bindDrawn(options.input),
|
|
94
97
|
accepts: (input) => accepts(target.input, input),
|
|
95
98
|
attempt: async (input) => {
|
|
99
|
+
const { request } = options;
|
|
96
100
|
try {
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
actor,
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
101
|
+
// On a declared request the reader is ON it, so `sourceFor` takes no actor.
|
|
102
|
+
if (request === undefined) {
|
|
103
|
+
await (await sourceFor(target, input, { ctx: base, actor, surface: 'http' })).execute();
|
|
104
|
+
} else {
|
|
105
|
+
await withRequestAs(name, actor, request, async () => {
|
|
106
|
+
await (await sourceFor(target, input, { surface: 'http' })).execute();
|
|
107
|
+
});
|
|
108
|
+
}
|
|
103
109
|
return { ok: true, reached: true };
|
|
104
110
|
} catch (error) {
|
|
105
111
|
return { ok: false, reached: !beforeSql(error), error };
|