@malloy-publisher/server 0.0.229 → 0.0.230
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/app/api-doc.yaml +18 -9
- package/dist/app/assets/{EnvironmentPage-QOoHiVeJ.js → EnvironmentPage-wa_EPkwK.js} +1 -1
- package/dist/app/assets/{HomePage-C71GOfVW.js → HomePage-jnCrupQp.js} +1 -1
- package/dist/app/assets/{LightMode-CrgCAwLe.js → LightMode-DYbwNULZ.js} +1 -1
- package/dist/app/assets/{MainPage-BG5__FN3.js → MainPage-CuJLrPNI.js} +1 -1
- package/dist/app/assets/{MaterializationsPage-DE6PnrDR.js → MaterializationsPage-D_67x2ee.js} +1 -1
- package/dist/app/assets/{ModelPage-CcBjcbLm.js → ModelPage-D5JtAWqR.js} +1 -1
- package/dist/app/assets/{PackagePage-JTy3ztkB.js → PackagePage-BRwtqUSG.js} +1 -1
- package/dist/app/assets/{RouteError-Cymbp47a.js → RouteError-CBNNrnSD.js} +1 -1
- package/dist/app/assets/{ThemeEditorPage-C_nMnHr8.js → ThemeEditorPage-CTCeBneA.js} +1 -1
- package/dist/app/assets/{WorkbookPage-CPQu-DQx.js → WorkbookPage-SN6f1RBm.js} +1 -1
- package/dist/app/assets/{core-Coi3caGs.es-CSOmajHS.js → core-Dp3q5Ieu.es-CD5FvM2s.js} +1 -1
- package/dist/app/assets/{index-DlWCXghy.js → index-B3Nn8Vm2.js} +459 -446
- package/dist/app/assets/index-BLCx1EdC.js +18 -0
- package/dist/app/assets/{index-DxArlgRD.js → index-C_tJstcx.js} +4 -4
- package/dist/app/assets/{index-CcuuST2X.js → index-CfmBVB6M.js} +1 -1
- package/dist/app/assets/{index-CkmABCAw.js → index-DU4r7GdU.js} +435 -422
- package/dist/app/index.html +1 -1
- package/dist/package_load_worker.mjs +108 -7
- package/dist/server.mjs +575 -49
- package/package.json +12 -12
- package/scripts/bake-duckdb-extensions.js +5 -2
- package/src/config.ts +40 -0
- package/src/ducklake_version.spec.ts +163 -0
- package/src/ducklake_version.ts +153 -0
- package/src/errors.ts +12 -0
- package/src/malloy_pin_prereqs.spec.ts +25 -0
- package/src/mcp/skills/skills_bundle.json +1 -1
- package/src/server.ts +7 -0
- package/src/service/authorize.spec.ts +22 -0
- package/src/service/authorize.ts +267 -10
- package/src/service/authorize_integration.spec.ts +1068 -26
- package/src/service/connection.spec.ts +71 -0
- package/src/service/connection.ts +312 -25
- package/src/service/connection_config.spec.ts +21 -0
- package/src/service/connection_config.ts +15 -1
- package/src/service/ducklake_lazy_attach.spec.ts +110 -0
- package/src/service/environment.ts +43 -9
- package/src/service/environment_store.spec.ts +197 -12
- package/src/service/environment_store.ts +88 -14
- package/src/service/extension_fetch_policy.spec.ts +256 -0
- package/src/service/materialization_scheduler.spec.ts +29 -0
- package/src/service/materialization_service.spec.ts +119 -1
- package/src/service/model.spec.ts +67 -0
- package/src/service/model.ts +656 -31
- package/src/service/package.spec.ts +38 -0
- package/src/service/package.ts +12 -1
- package/src/storage/duckdb/MaterializationRepository.spec.ts +39 -2
- package/src/storage/duckdb/MaterializationRepository.ts +12 -0
- package/tests/integration/materialization/scheduler_transitions.integration.spec.ts +256 -0
- package/dist/app/assets/index-CM2qhQCI.js +0 -18
package/src/server.ts
CHANGED
|
@@ -35,6 +35,7 @@ import {
|
|
|
35
35
|
import { logger, loggerMiddleware } from "./logger";
|
|
36
36
|
|
|
37
37
|
import {
|
|
38
|
+
getExtensionFetchPolicy,
|
|
38
39
|
getMaterializationSchedulerConfig,
|
|
39
40
|
getMemoryGovernorConfig,
|
|
40
41
|
} from "./config";
|
|
@@ -199,6 +200,12 @@ const modelController = new ModelController(environmentStore);
|
|
|
199
200
|
// that Environment.getPackage / addPackage consult before allocating
|
|
200
201
|
// any new package — the server responds with HTTP 503 instead of
|
|
201
202
|
// OOM-killing the pod.
|
|
203
|
+
// Validate the DuckDB extension-fetch policy at boot so an unrecognised value
|
|
204
|
+
// (e.g. a k8s-manifest typo) fails the boot loudly here, rather than surfacing
|
|
205
|
+
// on the first query that resolves a DuckDB connection — which matters most for
|
|
206
|
+
// an operator relying on `local-only` for a no-network guarantee. Logging the
|
|
207
|
+
// resolved policy also records the posture the server booted with.
|
|
208
|
+
logger.info(`DuckDB extension-fetch policy: ${getExtensionFetchPolicy()}`);
|
|
202
209
|
const memoryGovernorConfig = getMemoryGovernorConfig();
|
|
203
210
|
const memoryGovernor = memoryGovernorConfig
|
|
204
211
|
? new PackageMemoryGovernor(memoryGovernorConfig)
|
|
@@ -3,8 +3,30 @@ import {
|
|
|
3
3
|
collectAuthorizeExprs,
|
|
4
4
|
isProbeTrue,
|
|
5
5
|
parseAuthorizeAnnotation,
|
|
6
|
+
referencedGivenNames,
|
|
6
7
|
} from "./authorize";
|
|
7
8
|
|
|
9
|
+
describe("referencedGivenNames", () => {
|
|
10
|
+
it("returns the $NAME tokens deduped in first-seen order", () => {
|
|
11
|
+
expect(
|
|
12
|
+
referencedGivenNames("$ROLE = 'admin' and $ROLE != $PRIOR"),
|
|
13
|
+
).toEqual(["ROLE", "PRIOR"]);
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
it("ignores a $NAME inside a string literal (not a real reference)", () => {
|
|
17
|
+
// Otherwise a joined gate's referenced-given count is inflated and the
|
|
18
|
+
// full-coverage check wrongly denies a correctly-authorized request.
|
|
19
|
+
expect(referencedGivenNames("$ROLE = 'the $BOSS role'")).toEqual([
|
|
20
|
+
"ROLE",
|
|
21
|
+
]);
|
|
22
|
+
expect(referencedGivenNames("'$A $B $C'")).toEqual([]);
|
|
23
|
+
expect(referencedGivenNames("$X = 'it\\'s $Y' or $Z = 1")).toEqual([
|
|
24
|
+
"X",
|
|
25
|
+
"Z",
|
|
26
|
+
]);
|
|
27
|
+
});
|
|
28
|
+
});
|
|
29
|
+
|
|
8
30
|
describe("isProbeTrue", () => {
|
|
9
31
|
it("grants only on a genuine true / 1 / 'true'", () => {
|
|
10
32
|
expect(isProbeTrue(true)).toBe(true);
|
package/src/service/authorize.ts
CHANGED
|
@@ -27,6 +27,12 @@ const FILE_PREFIX = "##(authorize)";
|
|
|
27
27
|
/** source name → effective authorize expressions (file-level then source-level). */
|
|
28
28
|
export type AuthorizeMap = Map<string, string[]>;
|
|
29
29
|
|
|
30
|
+
/** A `given:` declaration to prepend to a probe so it compiles standalone. */
|
|
31
|
+
export interface ProbeGivenDecl {
|
|
32
|
+
name: string;
|
|
33
|
+
type: string;
|
|
34
|
+
}
|
|
35
|
+
|
|
30
36
|
/**
|
|
31
37
|
* Build the synthetic probe query that evaluates a source's authorize
|
|
32
38
|
* expressions. Each expression becomes a boolean `select` column over a
|
|
@@ -37,18 +43,119 @@ export type AuthorizeMap = Map<string, string[]>;
|
|
|
37
43
|
* compile errors); running it evaluates the gate. The reserved dummy column
|
|
38
44
|
* name is deliberately obscure so a real authorize expression is unlikely to
|
|
39
45
|
* collide with it — a bare field reference in an expression is meant to fail.
|
|
46
|
+
*
|
|
47
|
+
* `givenDecls`, when supplied, are prepended as the probe's OWN `given:`
|
|
48
|
+
* block, making the probe self-contained: it compiles against whatever
|
|
49
|
+
* givens it declares itself rather than depending on the ambient model's
|
|
50
|
+
* given namespace. This is what lets {@link evaluateAuthorize} gate a joined
|
|
51
|
+
* source whose givens live in a model that isn't the one the probe is
|
|
52
|
+
* compiled against (see the two-hop transitive-import case in
|
|
53
|
+
* `docs/authorize.md`). Compile-time validation (`validateAuthorizeProbes`)
|
|
54
|
+
* calls this with no decls, so it still validates against the ambient
|
|
55
|
+
* namespace of the model it's compiling in.
|
|
40
56
|
*/
|
|
41
|
-
export function buildAuthorizeProbe(
|
|
57
|
+
export function buildAuthorizeProbe(
|
|
58
|
+
exprs: string[],
|
|
59
|
+
givenDecls: ProbeGivenDecl[] = [],
|
|
60
|
+
): string {
|
|
42
61
|
const selects = exprs
|
|
43
62
|
.map((expr, i) => `__auth_${i} is (${expr})`)
|
|
44
63
|
.join("\n ");
|
|
45
|
-
|
|
64
|
+
const givenBlock =
|
|
65
|
+
givenDecls.length > 0
|
|
66
|
+
? `given:\n${givenDecls.map((g) => ` ${g.name} :: ${g.type}`).join("\n")}\n\n`
|
|
67
|
+
: "";
|
|
68
|
+
return `${givenBlock}run: duckdb.sql("SELECT 1 AS __authorize_probe_row") -> {
|
|
46
69
|
select:
|
|
47
70
|
${selects}
|
|
48
71
|
limit: 1
|
|
49
72
|
}`;
|
|
50
73
|
}
|
|
51
74
|
|
|
75
|
+
const GIVEN_REF_PATTERN = /\$([A-Za-z_][A-Za-z0-9_]*)/g;
|
|
76
|
+
// Malloy string literals are single-quoted; a `$NAME` inside one is literal
|
|
77
|
+
// text, not a given reference. Strip literals (honoring `\'` escapes) before
|
|
78
|
+
// scanning, so e.g. `$ROLE = 'the $BOSS role'` references only ROLE — otherwise
|
|
79
|
+
// a joined gate's referenced-count is inflated and the full-coverage check
|
|
80
|
+
// wrongly denies a correctly-authorized request.
|
|
81
|
+
const STRING_LITERAL_PATTERN = /'(?:\\.|[^'\\])*'/g;
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* Given names an authorize expression references (`$NAME` tokens), deduped,
|
|
85
|
+
* in first-seen order. Used to figure out which givens a self-contained
|
|
86
|
+
* probe needs to declare for a given expression.
|
|
87
|
+
*/
|
|
88
|
+
export function referencedGivenNames(expr: string): string[] {
|
|
89
|
+
const scanned = expr.replace(STRING_LITERAL_PATTERN, "''");
|
|
90
|
+
const names: string[] = [];
|
|
91
|
+
const seen = new Set<string>();
|
|
92
|
+
for (const match of scanned.matchAll(GIVEN_REF_PATTERN)) {
|
|
93
|
+
const name = match[1];
|
|
94
|
+
if (!seen.has(name)) {
|
|
95
|
+
seen.add(name);
|
|
96
|
+
names.push(name);
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
return names;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* Infer a Malloy given type from a caller-supplied JS value, so a
|
|
104
|
+
* self-contained probe can declare exactly the givens an expression
|
|
105
|
+
* references without depending on the ambient model's own given namespace —
|
|
106
|
+
* which a joined source pulled in from a different (possibly multi-hop
|
|
107
|
+
* transitively imported) file may not share. Returns `null` for a value with
|
|
108
|
+
* no sensible Malloy type (null, a plain object, an empty untyped array);
|
|
109
|
+
* callers skip declaring that given, which fails the probe closed —
|
|
110
|
+
* consistent with the existing "referenced given has no value" behavior.
|
|
111
|
+
*/
|
|
112
|
+
function inferGivenType(value: GivenValue): string | null {
|
|
113
|
+
if (typeof value === "string") return "string";
|
|
114
|
+
if (typeof value === "number" || typeof value === "bigint") return "number";
|
|
115
|
+
if (typeof value === "boolean") return "boolean";
|
|
116
|
+
if (value instanceof Date) return "timestamp";
|
|
117
|
+
if (Array.isArray(value)) {
|
|
118
|
+
if (value.length === 0) return null;
|
|
119
|
+
const elementType = inferGivenType(value[0]);
|
|
120
|
+
return elementType ? `${elementType}[]` : null;
|
|
121
|
+
}
|
|
122
|
+
return null;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
/**
|
|
126
|
+
* Build the self-contained `given:` declarations + bound values a probe
|
|
127
|
+
* needs for one expression, from whatever the caller supplied. A referenced
|
|
128
|
+
* name that's absent from `givens` (or whose value has no inferrable type) is
|
|
129
|
+
* simply left undeclared — the probe then fails to compile for that
|
|
130
|
+
* expression (an undeclared `$NAME`), which {@link evaluateAuthorize} already
|
|
131
|
+
* treats as "this disjunct can't be evaluated" and denies that branch.
|
|
132
|
+
*
|
|
133
|
+
* `declaredTypes`, when supplied, is preferred over inferring the type from
|
|
134
|
+
* the caller's JS value — the gate author's own `given:` declaration is the
|
|
135
|
+
* source of truth (e.g. `$LEVEL > 3` should compare numerically even if the
|
|
136
|
+
* caller sends `"5"` as a string). Only covers a name declared within one
|
|
137
|
+
* import hop of the entry model (the same reach as `this.givens` — see
|
|
138
|
+
* `docs/authorize.md`); a gate on a source reached through a deeper
|
|
139
|
+
* transitive import falls back to inferring from the value, same as before.
|
|
140
|
+
*/
|
|
141
|
+
function bindProbeGivens(
|
|
142
|
+
expr: string,
|
|
143
|
+
givens: Record<string, GivenValue>,
|
|
144
|
+
declaredTypes?: Map<string, string>,
|
|
145
|
+
): { decls: ProbeGivenDecl[]; bound: Record<string, GivenValue> } {
|
|
146
|
+
const decls: ProbeGivenDecl[] = [];
|
|
147
|
+
const bound: Record<string, GivenValue> = {};
|
|
148
|
+
for (const name of referencedGivenNames(expr)) {
|
|
149
|
+
if (!(name in givens)) continue;
|
|
150
|
+
const value = givens[name];
|
|
151
|
+
const type = declaredTypes?.get(name) ?? inferGivenType(value);
|
|
152
|
+
if (!type) continue;
|
|
153
|
+
decls.push({ name, type });
|
|
154
|
+
bound[name] = value;
|
|
155
|
+
}
|
|
156
|
+
return { decls, bound };
|
|
157
|
+
}
|
|
158
|
+
|
|
52
159
|
/**
|
|
53
160
|
* Strict, fail-closed truthiness for a probe result cell. DuckDB (the probe's
|
|
54
161
|
* connection) returns a native boolean, but normalize defensively: only a real
|
|
@@ -74,6 +181,25 @@ interface AuthorizeProbeExecutor {
|
|
|
74
181
|
};
|
|
75
182
|
}
|
|
76
183
|
|
|
184
|
+
/**
|
|
185
|
+
* Run one probe (already-built query text) and report whether it evaluated
|
|
186
|
+
* true. Any throw (compile error, runtime "no value" for a referenced given,
|
|
187
|
+
* a missing/malformed result) propagates to the caller, which decides how to
|
|
188
|
+
* react — {@link evaluateAuthorize} treats it as "can't evaluate this way,
|
|
189
|
+
* try something else" rather than granting.
|
|
190
|
+
*/
|
|
191
|
+
async function runProbe(
|
|
192
|
+
executor: AuthorizeProbeExecutor,
|
|
193
|
+
probeText: string,
|
|
194
|
+
givens: Record<string, GivenValue>,
|
|
195
|
+
): Promise<boolean> {
|
|
196
|
+
const result = await executor
|
|
197
|
+
.loadQuery(probeText)
|
|
198
|
+
.run({ rowLimit: 1, givens });
|
|
199
|
+
const row = result?.data?.value?.[0];
|
|
200
|
+
return !!(row && isProbeTrue(row.__auth_0));
|
|
201
|
+
}
|
|
202
|
+
|
|
77
203
|
/**
|
|
78
204
|
* Evaluate a source's authorize disjunction against the supplied givens.
|
|
79
205
|
* Returns true if ANY expression evaluates true (OR semantics).
|
|
@@ -88,31 +214,162 @@ interface AuthorizeProbeExecutor {
|
|
|
88
214
|
* Per-branch failures are swallowed to false (fail closed at the branch level);
|
|
89
215
|
* access is granted only if some branch genuinely returns true. Short-circuits
|
|
90
216
|
* on the first true. Returns false (→ caller denies) if none grant.
|
|
217
|
+
*
|
|
218
|
+
* Each expression is tried TWICE if needed, in one of two orders depending on
|
|
219
|
+
* `selfContainedFirst`:
|
|
220
|
+
*
|
|
221
|
+
* - AMBIENT FIRST (`selfContainedFirst` false — the default, used only for
|
|
222
|
+
* the run target's OWN source gate): compile against `executor`'s own
|
|
223
|
+
* given namespace, passing the full supplied `givens` — the original
|
|
224
|
+
* approach, unchanged for the common case where `executor` (always the
|
|
225
|
+
* ENTRY model's materializer) already has the referenced givens in scope
|
|
226
|
+
* (same file, or a directly imported one — Malloy merges one level of
|
|
227
|
+
* import into a model's given namespace). Falls back to the
|
|
228
|
+
* self-contained probe below only if the ambient probe THROWS.
|
|
229
|
+
*
|
|
230
|
+
* - SELF-CONTAINED FIRST (`selfContainedFirst` true — used for every gate
|
|
231
|
+
* reached via a join/derivation/composite-member walk): declare just the
|
|
232
|
+
* givens this expression references ({@link bindProbeGivens}), preferring
|
|
233
|
+
* `declaredTypes` (the gate author's own declaration) over inferring from
|
|
234
|
+
* the caller-supplied value, so the probe compiles independently of
|
|
235
|
+
* `executor`'s namespace. This is what isolates a JOINED source's gate
|
|
236
|
+
* from the entry model's own ambient given namespace: if the entry model
|
|
237
|
+
* happens to declare its OWN given of the SAME NAME the joined gate
|
|
238
|
+
* references, an ambient-first probe would compile successfully against
|
|
239
|
+
* the ENTRY model's default/value instead of failing closed — silently
|
|
240
|
+
* granting access based on an unrelated given. An expression referencing
|
|
241
|
+
* NO givens at all (a constant/public gate, e.g. `#(authorize) "true"`)
|
|
242
|
+
* has nothing ambient to isolate from, so it's evaluated with a no-decls
|
|
243
|
+
* self-contained probe and returned directly — no fallback needed.
|
|
244
|
+
* Otherwise, the probe is attempted ONLY when EVERY referenced given got
|
|
245
|
+
* a decl — a probe that declares just SOME of them is not actually
|
|
246
|
+
* isolated: `executor.loadQuery` still compiles it against the ENTRY
|
|
247
|
+
* model's own materializer, so an undeclared referenced name resolves via
|
|
248
|
+
* the entry model's own ambient value/default for that name INSTEAD OF
|
|
249
|
+
* THROWING — reopening the collision hole for a partially supplied
|
|
250
|
+
* multi-given gate without ever reaching a catch block. So "not every
|
|
251
|
+
* referenced name could be bound" denies immediately, with NO probe
|
|
252
|
+
* attempted and NO ambient fallback. Once every referenced name IS
|
|
253
|
+
* declared, ambient is tried as a last resort only if that fully-declared
|
|
254
|
+
* probe itself throws for some OTHER reason — safe at that point since no
|
|
255
|
+
* referenced name is left for an entry default to decide.
|
|
256
|
+
*
|
|
257
|
+
* Either order still lets a gate on a source reached through a multi-hop
|
|
258
|
+
* transitive import evaluate correctly — Malloy does not flatten a `given:`
|
|
259
|
+
* declaration through more than one level of import, so the entry model's own
|
|
260
|
+
* namespace can be missing a given that's declared two-or-more imports away
|
|
261
|
+
* from a JOINED source's home file (see `docs/authorize.md`).
|
|
91
262
|
*/
|
|
92
263
|
export async function evaluateAuthorize(
|
|
93
264
|
executor: AuthorizeProbeExecutor,
|
|
94
265
|
exprs: string[],
|
|
95
266
|
givens: Record<string, GivenValue>,
|
|
267
|
+
declaredTypes?: Map<string, string>,
|
|
268
|
+
options?: { selfContainedFirst?: boolean },
|
|
96
269
|
): Promise<boolean> {
|
|
270
|
+
const selfContainedFirst = options?.selfContainedFirst ?? false;
|
|
97
271
|
for (const expr of exprs) {
|
|
272
|
+
if (selfContainedFirst) {
|
|
273
|
+
if (
|
|
274
|
+
await evaluateSelfContainedFirst(
|
|
275
|
+
executor,
|
|
276
|
+
expr,
|
|
277
|
+
givens,
|
|
278
|
+
declaredTypes,
|
|
279
|
+
)
|
|
280
|
+
) {
|
|
281
|
+
return true;
|
|
282
|
+
}
|
|
283
|
+
continue;
|
|
284
|
+
}
|
|
98
285
|
try {
|
|
99
|
-
|
|
100
|
-
.loadQuery(buildAuthorizeProbe([expr]))
|
|
101
|
-
.run({ rowLimit: 1, givens });
|
|
102
|
-
const row = result?.data?.value?.[0];
|
|
103
|
-
if (row && isProbeTrue(row.__auth_0)) {
|
|
286
|
+
if (await runProbe(executor, buildAuthorizeProbe([expr]), givens)) {
|
|
104
287
|
return true;
|
|
105
288
|
}
|
|
289
|
+
continue;
|
|
106
290
|
} catch {
|
|
107
|
-
//
|
|
108
|
-
//
|
|
109
|
-
//
|
|
291
|
+
// Ambient compile/eval failed — fall through to the self-contained
|
|
292
|
+
// retry below rather than immediately treating this disjunct as
|
|
293
|
+
// not-granting.
|
|
294
|
+
}
|
|
295
|
+
try {
|
|
296
|
+
const { decls, bound } = bindProbeGivens(expr, givens, declaredTypes);
|
|
297
|
+
if (decls.length === 0) continue; // nothing left to try — deny
|
|
298
|
+
if (
|
|
299
|
+
await runProbe(executor, buildAuthorizeProbe([expr], decls), bound)
|
|
300
|
+
) {
|
|
301
|
+
return true;
|
|
302
|
+
}
|
|
303
|
+
} catch {
|
|
304
|
+
// Still can't be evaluated — deny this branch and try the next.
|
|
305
|
+
// Does not fail the whole request, which is what keeps OR
|
|
306
|
+
// semantics intact.
|
|
110
307
|
continue;
|
|
111
308
|
}
|
|
112
309
|
}
|
|
113
310
|
return false;
|
|
114
311
|
}
|
|
115
312
|
|
|
313
|
+
/**
|
|
314
|
+
* One expression's self-contained-first evaluation (see
|
|
315
|
+
* {@link evaluateAuthorize}'s `selfContainedFirst` mode). A probe is only
|
|
316
|
+
* ever attempted once every given the expression references has been
|
|
317
|
+
* declared — a partially-declared probe still compiles against the ENTRY
|
|
318
|
+
* model's own materializer, so an undeclared name silently resolves via the
|
|
319
|
+
* entry's own ambient value/default instead of throwing, which is not
|
|
320
|
+
* isolation at all. Ambient is tried as a last resort only when the
|
|
321
|
+
* fully-declared self-contained probe itself throws for some other reason.
|
|
322
|
+
*/
|
|
323
|
+
async function evaluateSelfContainedFirst(
|
|
324
|
+
executor: AuthorizeProbeExecutor,
|
|
325
|
+
expr: string,
|
|
326
|
+
givens: Record<string, GivenValue>,
|
|
327
|
+
declaredTypes?: Map<string, string>,
|
|
328
|
+
): Promise<boolean> {
|
|
329
|
+
const referenced = referencedGivenNames(expr);
|
|
330
|
+
if (referenced.length === 0) {
|
|
331
|
+
// The expression references NO givens at all — a constant/public gate
|
|
332
|
+
// (e.g. `#(authorize) "true"`). There's nothing ambient to isolate
|
|
333
|
+
// from, so run the no-decls probe (still fully self-contained: it
|
|
334
|
+
// declares no givens and is handed none) and use its result directly.
|
|
335
|
+
// This is NOT the "unsatisfiable" case below — that's specifically
|
|
336
|
+
// about a referenced given the caller can't supply.
|
|
337
|
+
try {
|
|
338
|
+
return await runProbe(executor, buildAuthorizeProbe([expr]), {});
|
|
339
|
+
} catch {
|
|
340
|
+
return false;
|
|
341
|
+
}
|
|
342
|
+
}
|
|
343
|
+
const { decls, bound } = bindProbeGivens(expr, givens, declaredTypes);
|
|
344
|
+
if (decls.length !== referenced.length) {
|
|
345
|
+
// Not every referenced given could be bound — deny. A probe that
|
|
346
|
+
// declares only SOME of the referenced names is not actually isolated:
|
|
347
|
+
// `executor.loadQuery` compiles it against the ENTRY model's own
|
|
348
|
+
// materializer, so an undeclared referenced given resolves via the
|
|
349
|
+
// ENTRY model's own ambient value/default for that name instead of
|
|
350
|
+
// throwing — reopening the name-collision hole for a partially
|
|
351
|
+
// supplied multi-given gate. Only attempt a probe once every
|
|
352
|
+
// referenced name can be declared (and thus shadowed) ourselves.
|
|
353
|
+
return false;
|
|
354
|
+
}
|
|
355
|
+
try {
|
|
356
|
+
return await runProbe(
|
|
357
|
+
executor,
|
|
358
|
+
buildAuthorizeProbe([expr], decls),
|
|
359
|
+
bound,
|
|
360
|
+
);
|
|
361
|
+
} catch {
|
|
362
|
+
// Every referenced given was supplied and declared, so a throw here
|
|
363
|
+
// isn't the collision case — there's no unsupplied name left for an
|
|
364
|
+
// entry default to decide. Ambient is a safe last resort.
|
|
365
|
+
try {
|
|
366
|
+
return await runProbe(executor, buildAuthorizeProbe([expr]), givens);
|
|
367
|
+
} catch {
|
|
368
|
+
return false;
|
|
369
|
+
}
|
|
370
|
+
}
|
|
371
|
+
}
|
|
372
|
+
|
|
116
373
|
/** A source plus its effective authorize expressions. */
|
|
117
374
|
interface SourceWithAuthorize {
|
|
118
375
|
name?: string;
|