@web-ts-toolkit/access-router 0.61.0 → 0.62.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/README.md +320 -56
- package/advanced.d.mts +1 -1
- package/advanced.d.ts +1 -1
- package/advanced.js +253 -129
- package/advanced.mjs +253 -129
- package/index.d.mts +25 -17
- package/index.d.ts +25 -17
- package/index.js +724 -412
- package/index.mjs +667 -355
- package/llms.txt +4 -2
- package/package.json +3 -3
- package/{parsers-DFZ_6fGl.d.mts → parsers-Bdq0jg69.d.mts} +197 -79
- package/{parsers-DFZ_6fGl.d.ts → parsers-Bdq0jg69.d.ts} +197 -79
package/index.mjs
CHANGED
|
@@ -9,10 +9,10 @@ var __export = (target, all) => {
|
|
|
9
9
|
};
|
|
10
10
|
|
|
11
11
|
// src/acl/unsafe-snapshot-options.ts
|
|
12
|
-
var unsafeSnapshotOptions;
|
|
12
|
+
var unsafeSnapshotCheckOptions, unsafeInitialOutputCopyOptions, unsafeSnapshotOptions;
|
|
13
13
|
var init_unsafe_snapshot_options = __esm({
|
|
14
14
|
"src/acl/unsafe-snapshot-options.ts"() {
|
|
15
|
-
|
|
15
|
+
unsafeSnapshotCheckOptions = [
|
|
16
16
|
"unsafeSkipListDocumentSnapshotChecks",
|
|
17
17
|
"unsafeSkipReadDocumentSnapshotChecks",
|
|
18
18
|
"unsafeSkipListOutputSnapshotChecks",
|
|
@@ -20,6 +20,11 @@ var init_unsafe_snapshot_options = __esm({
|
|
|
20
20
|
"unsafeSkipListNestedDocumentSnapshotChecks",
|
|
21
21
|
"unsafeSkipReadNestedDocumentSnapshotChecks"
|
|
22
22
|
];
|
|
23
|
+
unsafeInitialOutputCopyOptions = [
|
|
24
|
+
"unsafeSkipListInitialOutputSnapshotCopy",
|
|
25
|
+
"unsafeSkipReadInitialOutputSnapshotCopy"
|
|
26
|
+
];
|
|
27
|
+
unsafeSnapshotOptions = [...unsafeSnapshotCheckOptions, ...unsafeInitialOutputCopyOptions];
|
|
23
28
|
}
|
|
24
29
|
});
|
|
25
30
|
|
|
@@ -64,9 +69,9 @@ function assertPublicAdmission(input, kind = "envelope") {
|
|
|
64
69
|
for (const key of ["filter", "match", "data"]) add(record3[key], "data", key);
|
|
65
70
|
}
|
|
66
71
|
}
|
|
67
|
-
function assertHydrationDefaults(
|
|
68
|
-
if (
|
|
69
|
-
const record3 =
|
|
72
|
+
function assertHydrationDefaults(defaults2) {
|
|
73
|
+
if (defaults2 && typeof defaults2 === "object") {
|
|
74
|
+
const record3 = defaults2;
|
|
70
75
|
if ("hydration" in record3)
|
|
71
76
|
throw new TypeError("defaults.hydration is unsupported; use model hydration configuration");
|
|
72
77
|
for (const bucket of [
|
|
@@ -94,11 +99,11 @@ function assertHydrationDefaults(defaults) {
|
|
|
94
99
|
}
|
|
95
100
|
}
|
|
96
101
|
}
|
|
97
|
-
function assertPublicDefaults(
|
|
98
|
-
assertHydrationDefaults(
|
|
99
|
-
assertPublicAdmission(
|
|
100
|
-
if (
|
|
101
|
-
for (const value of Object.values(
|
|
102
|
+
function assertPublicDefaults(defaults2) {
|
|
103
|
+
assertHydrationDefaults(defaults2);
|
|
104
|
+
assertPublicAdmission(defaults2);
|
|
105
|
+
if (defaults2 && typeof defaults2 === "object") {
|
|
106
|
+
for (const value of Object.values(defaults2)) assertPublicAdmission(value);
|
|
102
107
|
}
|
|
103
108
|
}
|
|
104
109
|
function pickPublicKeys(input, keys2) {
|
|
@@ -199,6 +204,37 @@ var init_hydration = __esm({
|
|
|
199
204
|
}
|
|
200
205
|
});
|
|
201
206
|
|
|
207
|
+
// src/options/populate-policy.ts
|
|
208
|
+
function isPopulatePolicyKey(key) {
|
|
209
|
+
return populatePolicyKeys.includes(key);
|
|
210
|
+
}
|
|
211
|
+
function normalizePopulatePolicyValue(value) {
|
|
212
|
+
return value === void 0 ? void 0 : value !== false;
|
|
213
|
+
}
|
|
214
|
+
function normalizePopulatePolicyOptions(options) {
|
|
215
|
+
const next = { ...options };
|
|
216
|
+
for (const key of populatePolicyKeys) {
|
|
217
|
+
if (key in options)
|
|
218
|
+
next[key] = normalizePopulatePolicyValue(options[key]);
|
|
219
|
+
}
|
|
220
|
+
return next;
|
|
221
|
+
}
|
|
222
|
+
function assertNoGlobalPopulatePolicy(key) {
|
|
223
|
+
if (isPopulatePolicyKey(key))
|
|
224
|
+
throw new TypeError(
|
|
225
|
+
`${key} is target-model configuration; migrate to setModelOptions(targetModelName, { ${key}: value }) or setDefaultModelOptions({ ${key}: value }) for runtime model defaults`
|
|
226
|
+
);
|
|
227
|
+
}
|
|
228
|
+
var populatePolicyKeys;
|
|
229
|
+
var init_populate_policy = __esm({
|
|
230
|
+
"src/options/populate-policy.ts"() {
|
|
231
|
+
populatePolicyKeys = [
|
|
232
|
+
"requireOperationAccessForPopulateQueries",
|
|
233
|
+
"requireOperationAccessForPopulateDependencies"
|
|
234
|
+
];
|
|
235
|
+
}
|
|
236
|
+
});
|
|
237
|
+
|
|
202
238
|
// src/helpers/collection.ts
|
|
203
239
|
import sift from "sift";
|
|
204
240
|
import { filter, find } from "@web-ts-toolkit/utils";
|
|
@@ -1315,7 +1351,7 @@ var init_logger_default = __esm({
|
|
|
1315
1351
|
|
|
1316
1352
|
// src/options/manager.ts
|
|
1317
1353
|
import { assign, get as get3, isPlainObject as isPlainObject9, set as set2 } from "@web-ts-toolkit/utils";
|
|
1318
|
-
var toPath, cloneConfigValue, cloneForRead, freezeConfigValue, cloneAndFreezeForStore, getNestedOption, resolveNestedOption, OptionsManager;
|
|
1354
|
+
var toPath, cloneConfigValue, cloneForRead, freezeConfigValue, cloneAndFreezeForStore, cloneOptionsSnapshot, getNestedOption, resolveNestedOption, OptionsManager;
|
|
1319
1355
|
var init_manager = __esm({
|
|
1320
1356
|
"src/options/manager.ts"() {
|
|
1321
1357
|
toPath = (key) => {
|
|
@@ -1378,6 +1414,7 @@ var init_manager = __esm({
|
|
|
1378
1414
|
return value;
|
|
1379
1415
|
};
|
|
1380
1416
|
cloneAndFreezeForStore = (value) => freezeConfigValue(cloneForRead(value));
|
|
1417
|
+
cloneOptionsSnapshot = (value) => freezeConfigValue(cloneForRead(value));
|
|
1381
1418
|
getNestedOption = (manager, key, defaultValue) => resolveNestedOption((path, fallback) => manager.get(path, fallback), String(key), defaultValue);
|
|
1382
1419
|
resolveNestedOption = (read, key, defaultValue) => {
|
|
1383
1420
|
const keys2 = key.split(".");
|
|
@@ -1886,7 +1923,8 @@ var init_virtual_descriptor = __esm({
|
|
|
1886
1923
|
});
|
|
1887
1924
|
|
|
1888
1925
|
// src/acl/authorization-snapshot.ts
|
|
1889
|
-
import { isDeepStrictEqual } from "util";
|
|
1926
|
+
import { isDeepStrictEqual, types as types2 } from "util";
|
|
1927
|
+
import { Buffer as NodeBuffer } from "buffer";
|
|
1890
1928
|
import { mongo as mongo2 } from "mongoose";
|
|
1891
1929
|
import JsonRouter3 from "@web-ts-toolkit/express-json-router";
|
|
1892
1930
|
function authorizationError(detail) {
|
|
@@ -1989,6 +2027,71 @@ function outputIdentities(value) {
|
|
|
1989
2027
|
visit(value);
|
|
1990
2028
|
return Object.freeze(result2);
|
|
1991
2029
|
}
|
|
2030
|
+
function tryOutputIdentitiesWithoutSnapshot(value) {
|
|
2031
|
+
const identities = [];
|
|
2032
|
+
const seen = /* @__PURE__ */ new WeakSet();
|
|
2033
|
+
const active = /* @__PURE__ */ new WeakSet();
|
|
2034
|
+
const fallback = {};
|
|
2035
|
+
let nodes = 0;
|
|
2036
|
+
function visit(input, depth) {
|
|
2037
|
+
if (++nodes > 2e4 || depth > 100) authorizationError("snapshot exceeds structural limits");
|
|
2038
|
+
if (typeof input === "function") authorizationError("functions are not policy values");
|
|
2039
|
+
if (typeof input === "symbol") authorizationError("symbols are not policy values");
|
|
2040
|
+
if (input === null || typeof input !== "object") return;
|
|
2041
|
+
if (types2.isProxy(input)) throw fallback;
|
|
2042
|
+
if (active.has(input)) authorizationError("cyclic input");
|
|
2043
|
+
if (!seen.has(input)) {
|
|
2044
|
+
seen.add(input);
|
|
2045
|
+
identities.push(input);
|
|
2046
|
+
}
|
|
2047
|
+
const prototype = Object.getPrototypeOf(input);
|
|
2048
|
+
if (types2.isDate(input)) {
|
|
2049
|
+
if (prototype === Date.prototype) return;
|
|
2050
|
+
throw fallback;
|
|
2051
|
+
}
|
|
2052
|
+
if (types2.isRegExp(input)) {
|
|
2053
|
+
if (prototype === RegExp.prototype) return;
|
|
2054
|
+
throw fallback;
|
|
2055
|
+
}
|
|
2056
|
+
if (types2.isUint8Array(input)) {
|
|
2057
|
+
if (prototype === NodeBuffer.prototype) return;
|
|
2058
|
+
throw fallback;
|
|
2059
|
+
}
|
|
2060
|
+
if (types2.isMap(input) || types2.isSet(input)) throw fallback;
|
|
2061
|
+
const array = Array.isArray(input);
|
|
2062
|
+
if (!array) {
|
|
2063
|
+
if (prototype !== Object.prototype && prototype !== null) {
|
|
2064
|
+
let parent = prototype;
|
|
2065
|
+
for (let count = 0; parent && count < 100; count++) {
|
|
2066
|
+
if (types2.isProxy(parent)) throw fallback;
|
|
2067
|
+
if (parent === mongo2.BSON.BSONValue.prototype) return;
|
|
2068
|
+
parent = Object.getPrototypeOf(parent);
|
|
2069
|
+
}
|
|
2070
|
+
throw fallback;
|
|
2071
|
+
}
|
|
2072
|
+
} else if (input.length > 2e4) authorizationError("snapshot array exceeds structural limits");
|
|
2073
|
+
active.add(input);
|
|
2074
|
+
try {
|
|
2075
|
+
for (const key of Reflect.ownKeys(input)) {
|
|
2076
|
+
if (array && key === "length") continue;
|
|
2077
|
+
if (typeof key !== "string" || unsafeKeys.has(key)) authorizationError("unsafe snapshot key");
|
|
2078
|
+
if (array && !/^(0|[1-9]\d*)$/.test(key)) authorizationError("invalid array property");
|
|
2079
|
+
const descriptor = Object.getOwnPropertyDescriptor(input, key);
|
|
2080
|
+
if (!("value" in descriptor)) authorizationError("accessor/non-enumerable input");
|
|
2081
|
+
visit(descriptor.value, depth + 1);
|
|
2082
|
+
}
|
|
2083
|
+
} finally {
|
|
2084
|
+
active.delete(input);
|
|
2085
|
+
}
|
|
2086
|
+
}
|
|
2087
|
+
try {
|
|
2088
|
+
visit(value, 0);
|
|
2089
|
+
return Object.freeze(identities);
|
|
2090
|
+
} catch (error2) {
|
|
2091
|
+
if (error2 !== fallback) throw error2;
|
|
2092
|
+
return void 0;
|
|
2093
|
+
}
|
|
2094
|
+
}
|
|
1992
2095
|
var ServiceAuthorizationError, unsafeKeys;
|
|
1993
2096
|
var init_authorization_snapshot = __esm({
|
|
1994
2097
|
"src/acl/authorization-snapshot.ts"() {
|
|
@@ -2026,6 +2129,9 @@ function isInputVirtualPath(catalog, path) {
|
|
|
2026
2129
|
return false;
|
|
2027
2130
|
}
|
|
2028
2131
|
function matchesCatalogPattern(pattern, path, descendants = false) {
|
|
2132
|
+
if (typeof pattern === "string" && typeof path === "string" && !pattern.includes("$*")) {
|
|
2133
|
+
return pattern === path || !!descendants && path.startsWith(pattern) && path[pattern.length] === ".";
|
|
2134
|
+
}
|
|
2029
2135
|
const expected = pattern.split(".");
|
|
2030
2136
|
const actual = path.split(".");
|
|
2031
2137
|
return (descendants ? actual.length >= expected.length : actual.length === expected.length) && expected.every((part, index) => part === "$*" || part === actual[index]);
|
|
@@ -2158,9 +2264,46 @@ var init_field_catalog = __esm({
|
|
|
2158
2264
|
}
|
|
2159
2265
|
});
|
|
2160
2266
|
|
|
2267
|
+
// src/runtime-context.ts
|
|
2268
|
+
import { AsyncLocalStorage as AsyncLocalStorage2 } from "async_hooks";
|
|
2269
|
+
function runWithRuntime(runtime, callback) {
|
|
2270
|
+
return runtimeStorage.run(runtime, callback);
|
|
2271
|
+
}
|
|
2272
|
+
function getActiveRuntime() {
|
|
2273
|
+
return runtimeStorage.getStore() ?? null;
|
|
2274
|
+
}
|
|
2275
|
+
var runtimeStorage;
|
|
2276
|
+
var init_runtime_context = __esm({
|
|
2277
|
+
"src/runtime-context.ts"() {
|
|
2278
|
+
runtimeStorage = new AsyncLocalStorage2();
|
|
2279
|
+
}
|
|
2280
|
+
});
|
|
2281
|
+
|
|
2282
|
+
// src/meta.ts
|
|
2283
|
+
var getRuntime, getModelReference;
|
|
2284
|
+
var init_meta = __esm({
|
|
2285
|
+
"src/meta.ts"() {
|
|
2286
|
+
init_runtime();
|
|
2287
|
+
init_runtime_context();
|
|
2288
|
+
getRuntime = () => getActiveRuntime() ?? defaultRuntime;
|
|
2289
|
+
getModelReference = (modelName, refPath, runtime = getRuntime()) => {
|
|
2290
|
+
const instance = runtime.getModelInstance(modelName);
|
|
2291
|
+
let type = instance?.schema.path(refPath);
|
|
2292
|
+
const result2 = {};
|
|
2293
|
+
while (type) {
|
|
2294
|
+
result2.ref ??= type.options?.ref;
|
|
2295
|
+
result2.refPath ??= type.options?.refPath;
|
|
2296
|
+
if (type.instance !== "Array") break;
|
|
2297
|
+
type = type.$embeddedSchemaType ?? type.embeddedSchemaType ?? type.caster;
|
|
2298
|
+
}
|
|
2299
|
+
return result2;
|
|
2300
|
+
};
|
|
2301
|
+
}
|
|
2302
|
+
});
|
|
2303
|
+
|
|
2161
2304
|
// src/acl/populate-target-configuration.ts
|
|
2162
2305
|
import { isPlainObject as isPlainObject12 } from "@web-ts-toolkit/utils";
|
|
2163
|
-
function capturePopulateTargetConfiguration(runtime, modelName, source, proposedOptions) {
|
|
2306
|
+
function capturePopulateTargetConfiguration(runtime, modelName, source, proposedOptions, defaults2 = runtime.getDefaultModelOptions()) {
|
|
2164
2307
|
const label = `Populate target "${modelName}" for ${source}`;
|
|
2165
2308
|
if (!proposedOptions && !runtime.hasModel(modelName))
|
|
2166
2309
|
authorizationError(
|
|
@@ -2169,16 +2312,75 @@ function capturePopulateTargetConfiguration(runtime, modelName, source, proposed
|
|
|
2169
2312
|
const model = runtime.getModelInstance(modelName);
|
|
2170
2313
|
if (!model) authorizationError(`${label} requires an actual registered Mongoose model in this runtime`);
|
|
2171
2314
|
const options = proposedOptions ?? runtime.getModelOptions(modelName);
|
|
2172
|
-
const permissionSchema = options.permissionSchema === void 0 ?
|
|
2315
|
+
const permissionSchema = options.permissionSchema === void 0 ? defaults2.permissionSchema : options.permissionSchema;
|
|
2173
2316
|
if (!isPlainObject12(permissionSchema))
|
|
2174
2317
|
authorizationError(
|
|
2175
2318
|
`${label} requires an effective object permissionSchema; configure the model or runtime model defaults ({} explicitly closes business fields)`
|
|
2176
2319
|
);
|
|
2177
2320
|
return { model, options: { ...options, permissionSchema } };
|
|
2178
2321
|
}
|
|
2322
|
+
function capturePopulateTargetBinding(runtime, sourceModelName, path) {
|
|
2323
|
+
const { ref, refPath } = getModelReference(sourceModelName, path, runtime);
|
|
2324
|
+
if (refPath !== void 0 || typeof ref === "function" && !("modelName" in ref))
|
|
2325
|
+
authorizationError(
|
|
2326
|
+
`Populate target for ${sourceModelName}.${path} requires a static string or Mongoose Model-valued source ref; dynamic refs/refPath cannot be bound before I/O`
|
|
2327
|
+
);
|
|
2328
|
+
const modelName = typeof ref === "string" ? ref : ref?.modelName;
|
|
2329
|
+
if (!modelName) return void 0;
|
|
2330
|
+
const target = capturePopulateTargetConfiguration(runtime, modelName, `${sourceModelName}.${path}`);
|
|
2331
|
+
const source = runtime.getModelInstance(sourceModelName);
|
|
2332
|
+
const actual = typeof ref === "string" ? source?.db.models[ref] : ref;
|
|
2333
|
+
if (!actual)
|
|
2334
|
+
authorizationError(
|
|
2335
|
+
`Populate target "${modelName}" for ${sourceModelName}.${path} is missing on the source connection; configure the actual model bound to the source ref in this runtime`
|
|
2336
|
+
);
|
|
2337
|
+
if (actual !== target.model)
|
|
2338
|
+
authorizationError(
|
|
2339
|
+
`Populate target "${modelName}" for ${sourceModelName}.${path} resolves to a different actual Mongoose model than this runtime configured; register and configure the actual source ref instance`
|
|
2340
|
+
);
|
|
2341
|
+
return { ...target, modelName };
|
|
2342
|
+
}
|
|
2179
2343
|
var init_populate_target_configuration = __esm({
|
|
2180
2344
|
"src/acl/populate-target-configuration.ts"() {
|
|
2181
2345
|
init_authorization_snapshot();
|
|
2346
|
+
init_meta();
|
|
2347
|
+
}
|
|
2348
|
+
});
|
|
2349
|
+
|
|
2350
|
+
// src/acl/populate-policy.ts
|
|
2351
|
+
function capturePopulatePolicyDefaults(runtime) {
|
|
2352
|
+
const options = runtime.getDefaultModelOptions();
|
|
2353
|
+
const token = () => {
|
|
2354
|
+
};
|
|
2355
|
+
defaults.set(
|
|
2356
|
+
token,
|
|
2357
|
+
Object.freeze({
|
|
2358
|
+
requireOperationAccessForPopulateQueries: options.requireOperationAccessForPopulateQueries !== false,
|
|
2359
|
+
requireOperationAccessForPopulateDependencies: options.requireOperationAccessForPopulateDependencies !== false
|
|
2360
|
+
})
|
|
2361
|
+
);
|
|
2362
|
+
return token;
|
|
2363
|
+
}
|
|
2364
|
+
function resolvePopulatePolicy(options, token) {
|
|
2365
|
+
const captured = defaults.get(token);
|
|
2366
|
+
if (!captured) return authorizationError("invalid captured populate model defaults");
|
|
2367
|
+
const resolve = (key) => (options[key] === void 0 ? captured[key] : options[key]) !== false;
|
|
2368
|
+
return Object.freeze({
|
|
2369
|
+
requireOperationAccessForPopulateQueries: resolve(populatePolicyKeys[0]),
|
|
2370
|
+
requireOperationAccessForPopulateDependencies: resolve(populatePolicyKeys[1])
|
|
2371
|
+
});
|
|
2372
|
+
}
|
|
2373
|
+
function getCapturedPopulatePolicyDefaults(configuration) {
|
|
2374
|
+
const token = configuration.populatePolicyDefaults;
|
|
2375
|
+
if (!token || !defaults.has(token)) return authorizationError("missing captured populate model defaults");
|
|
2376
|
+
return token;
|
|
2377
|
+
}
|
|
2378
|
+
var defaults;
|
|
2379
|
+
var init_populate_policy2 = __esm({
|
|
2380
|
+
"src/acl/populate-policy.ts"() {
|
|
2381
|
+
init_populate_policy();
|
|
2382
|
+
init_authorization_snapshot();
|
|
2383
|
+
defaults = /* @__PURE__ */ new WeakMap();
|
|
2182
2384
|
}
|
|
2183
2385
|
});
|
|
2184
2386
|
|
|
@@ -2273,9 +2475,7 @@ function normalizeSelection(select, catalog, label) {
|
|
|
2273
2475
|
includeId: selection.includes("_id")
|
|
2274
2476
|
};
|
|
2275
2477
|
}
|
|
2276
|
-
function captureVirtualPopulateDependencies(runtime, modelName, options,
|
|
2277
|
-
const requireOperationAccessForPopulateDependencies = globalOptions.requireOperationAccessForPopulateDependencies !== false;
|
|
2278
|
-
const requireOperationAccessForPopulateQueries = globalOptions.requireOperationAccessForPopulateQueries !== false;
|
|
2478
|
+
function captureVirtualPopulateDependencies(runtime, modelName, options, populatePolicyDefaults = capturePopulatePolicyDefaults(runtime), proposed) {
|
|
2279
2479
|
const model = runtime.getModelInstance(modelName);
|
|
2280
2480
|
const targets = /* @__PURE__ */ new Map();
|
|
2281
2481
|
const scopes = [];
|
|
@@ -2319,18 +2519,19 @@ function captureVirtualPopulateDependencies(runtime, modelName, options, globalO
|
|
|
2319
2519
|
runtime,
|
|
2320
2520
|
ref,
|
|
2321
2521
|
`dependsOnPopulate virtual "${label}"`,
|
|
2322
|
-
ref === modelName ? options :
|
|
2522
|
+
ref === modelName ? options : proposed?.models.get(ref),
|
|
2523
|
+
proposed?.defaults
|
|
2323
2524
|
);
|
|
2324
|
-
const
|
|
2325
|
-
const readOption = (key) => resolveNestedOption((path2, fallback) => get4(targetOptions, path2, fallback), key, get4(
|
|
2326
|
-
const documentPermissionField = targetOptions.documentPermissionField ??
|
|
2525
|
+
const defaults2 = proposed?.defaults ?? runtime.getDefaultModelOptions();
|
|
2526
|
+
const readOption = (key) => resolveNestedOption((path2, fallback) => get4(targetOptions, path2, fallback), key, get4(defaults2, key));
|
|
2527
|
+
const documentPermissionField = targetOptions.documentPermissionField ?? defaults2.documentPermissionField;
|
|
2327
2528
|
const catalog = captureAuthorizationFieldCatalog(targetModel.schema, void 0, documentPermissionField);
|
|
2328
2529
|
const configuration = copyAuthorizationValue(
|
|
2329
2530
|
{
|
|
2330
2531
|
catalog,
|
|
2331
2532
|
documentPermissionField,
|
|
2332
|
-
|
|
2333
|
-
|
|
2533
|
+
populatePolicyDefaults,
|
|
2534
|
+
...resolvePopulatePolicy(targetOptions, populatePolicyDefaults),
|
|
2334
2535
|
permissionSchema: targetOptions.permissionSchema,
|
|
2335
2536
|
operationAccess: { read: readOption("operationAccess.read") },
|
|
2336
2537
|
baseFilter: { read: readOption("baseFilter.read") },
|
|
@@ -2411,8 +2612,8 @@ function captureVirtualPopulateDependencies(runtime, modelName, options, globalO
|
|
|
2411
2612
|
visit(options.virtuals ?? {}, model?.schema, "", [], !!model && varyingModel(model));
|
|
2412
2613
|
return Object.freeze({ scopes: Object.freeze(scopes) });
|
|
2413
2614
|
}
|
|
2414
|
-
function captureVirtualPopulateSnapshot(runtime, modelName, options,
|
|
2415
|
-
const snapshot = captureVirtualPopulateDependencies(runtime, modelName, options,
|
|
2615
|
+
function captureVirtualPopulateSnapshot(runtime, modelName, options, populatePolicyDefaults = capturePopulatePolicyDefaults(runtime)) {
|
|
2616
|
+
const snapshot = captureVirtualPopulateDependencies(runtime, modelName, options, populatePolicyDefaults);
|
|
2416
2617
|
const token = () => {
|
|
2417
2618
|
};
|
|
2418
2619
|
snapshots.set(token, snapshot);
|
|
@@ -2445,6 +2646,7 @@ var init_virtual_populate_dependencies = __esm({
|
|
|
2445
2646
|
init_field_catalog();
|
|
2446
2647
|
init_virtual_descriptor();
|
|
2447
2648
|
init_populate_target_configuration();
|
|
2649
|
+
init_populate_policy2();
|
|
2448
2650
|
elementType = (type) => type.$embeddedSchemaType ?? type.embeddedSchemaType ?? type.caster;
|
|
2449
2651
|
join = (prefix, path) => prefix ? `${prefix}.${path}` : path;
|
|
2450
2652
|
within = (path, parent) => path === parent || path.startsWith(`${parent}.`);
|
|
@@ -2475,11 +2677,12 @@ import {
|
|
|
2475
2677
|
normalizeUrlPath,
|
|
2476
2678
|
set as set4
|
|
2477
2679
|
} from "@web-ts-toolkit/utils";
|
|
2478
|
-
var mongooseJsonSchemaInitialized, ensureMongooseJsonSchemaInitialized, pluralize, FIELD_ACCESS_KEYS, defaultModelOptions, defaultDataOptions, normalizeBasePath, hasModelPermission, classifyPermissionSchema, refreshPermissionMetadata, VIRTUAL_SUPPORTED_ACCESSES, VIRTUAL_UNSUPPORTED_ACCESSES, VIRTUAL_RESERVED_NAMES, VIRTUAL_DANGEROUS_SEGMENTS, VIRTUAL_NAME_PATTERN, isVirtualContainerValue2, virtualFullPath, virtualPathsOverlap, collectStoredTopLevel, getChildSchemaForField, getNestedChildFields,
|
|
2680
|
+
var mongooseJsonSchemaInitialized, ensureMongooseJsonSchemaInitialized, pluralize, FIELD_ACCESS_KEYS, defaultModelOptions, modelOverrides, defaultDataOptions, normalizeBasePath, hasModelPermission, classifyPermissionSchema, refreshPermissionMetadata, VIRTUAL_SUPPORTED_ACCESSES, VIRTUAL_UNSUPPORTED_ACCESSES, VIRTUAL_RESERVED_NAMES, VIRTUAL_DANGEROUS_SEGMENTS, VIRTUAL_NAME_PATTERN, isVirtualContainerValue2, virtualFullPath, virtualPathsOverlap, collectStoredTopLevel, getChildSchemaForField, getNestedChildFields, cloneModelOptionForUpdate, validateVirtualDependsOn, validateVirtualLeafValue, validateVirtualsScope, validateVirtualsTree, AccessRuntime, defaultRuntime;
|
|
2479
2681
|
var init_runtime = __esm({
|
|
2480
2682
|
"src/runtime.ts"() {
|
|
2481
2683
|
init_public_admission();
|
|
2482
2684
|
init_hydration();
|
|
2685
|
+
init_populate_policy();
|
|
2483
2686
|
init_helpers();
|
|
2484
2687
|
init_registry();
|
|
2485
2688
|
init_logger_default();
|
|
@@ -2489,6 +2692,7 @@ var init_runtime = __esm({
|
|
|
2489
2692
|
init_request_complexity();
|
|
2490
2693
|
init_virtual_descriptor();
|
|
2491
2694
|
init_virtual_populate_dependencies();
|
|
2695
|
+
init_unsafe_snapshot_options();
|
|
2492
2696
|
mongooseJsonSchemaInitialized = false;
|
|
2493
2697
|
ensureMongooseJsonSchemaInitialized = () => {
|
|
2494
2698
|
if (mongooseJsonSchemaInitialized) return;
|
|
@@ -2501,6 +2705,15 @@ var init_runtime = __esm({
|
|
|
2501
2705
|
basePath: null,
|
|
2502
2706
|
alwaysSelectFields: []
|
|
2503
2707
|
};
|
|
2708
|
+
modelOverrides = (options) => {
|
|
2709
|
+
const result2 = Object.fromEntries(
|
|
2710
|
+
Object.entries(options).filter(
|
|
2711
|
+
([key, value]) => value !== void 0 || key === "operationAccess" || isPopulatePolicyKey(key)
|
|
2712
|
+
)
|
|
2713
|
+
);
|
|
2714
|
+
for (const key of unsafeSnapshotOptions) if (key in result2) result2[key] = result2[key] === true;
|
|
2715
|
+
return cloneOptionsSnapshot(result2);
|
|
2716
|
+
};
|
|
2504
2717
|
defaultDataOptions = {
|
|
2505
2718
|
basePath: null,
|
|
2506
2719
|
parentPath: "/",
|
|
@@ -2634,12 +2847,12 @@ var init_runtime = __esm({
|
|
|
2634
2847
|
}
|
|
2635
2848
|
return fields;
|
|
2636
2849
|
};
|
|
2637
|
-
|
|
2638
|
-
if (Array.isArray(value)) return value.map((item) =>
|
|
2850
|
+
cloneModelOptionForUpdate = (value) => {
|
|
2851
|
+
if (Array.isArray(value)) return value.map((item) => cloneModelOptionForUpdate(item));
|
|
2639
2852
|
if (!value || typeof value !== "object") return value;
|
|
2640
2853
|
if (Object.getPrototypeOf(value) !== Object.prototype) return value;
|
|
2641
2854
|
return Object.fromEntries(
|
|
2642
|
-
Object.entries(value).map(([k, v]) => [k,
|
|
2855
|
+
Object.entries(value).map(([k, v]) => [k, cloneModelOptionForUpdate(v)])
|
|
2643
2856
|
);
|
|
2644
2857
|
};
|
|
2645
2858
|
validateVirtualDependsOn = (dependsOn, entryLabel, storedFields, siblingVirtualNames) => {
|
|
@@ -2835,8 +3048,6 @@ var init_runtime = __esm({
|
|
|
2835
3048
|
{
|
|
2836
3049
|
requestPermissionField: "_permissions",
|
|
2837
3050
|
globalPermissions: () => ({}),
|
|
2838
|
-
requireOperationAccessForPopulateQueries: true,
|
|
2839
|
-
requireOperationAccessForPopulateDependencies: true,
|
|
2840
3051
|
logger: defaultLogger,
|
|
2841
3052
|
requestComplexity: defaultRequestComplexity
|
|
2842
3053
|
},
|
|
@@ -2851,15 +3062,20 @@ var init_runtime = __esm({
|
|
|
2851
3062
|
queryRouteSegment: "__query",
|
|
2852
3063
|
mutationRouteSegment: "__mutation",
|
|
2853
3064
|
operationAccess: false,
|
|
3065
|
+
requireOperationAccessForPopulateQueries: true,
|
|
3066
|
+
requireOperationAccessForPopulateDependencies: true,
|
|
2854
3067
|
modelPermissionPrefix: "",
|
|
2855
3068
|
unsafeSkipListDocumentSnapshotChecks: false,
|
|
2856
3069
|
unsafeSkipReadDocumentSnapshotChecks: false,
|
|
2857
3070
|
unsafeSkipListOutputSnapshotChecks: false,
|
|
2858
3071
|
unsafeSkipReadOutputSnapshotChecks: false,
|
|
2859
3072
|
unsafeSkipListNestedDocumentSnapshotChecks: false,
|
|
2860
|
-
unsafeSkipReadNestedDocumentSnapshotChecks: false
|
|
3073
|
+
unsafeSkipReadNestedDocumentSnapshotChecks: false,
|
|
3074
|
+
unsafeSkipListInitialOutputSnapshotCopy: false,
|
|
3075
|
+
unsafeSkipReadInitialOutputSnapshotCopy: false
|
|
2861
3076
|
}).build();
|
|
2862
3077
|
this.modelOptions = {};
|
|
3078
|
+
this.modelOptionOverrides = {};
|
|
2863
3079
|
this.modelJsonSchemas = {};
|
|
2864
3080
|
this.dataOptions = {};
|
|
2865
3081
|
this.modelRefs = {};
|
|
@@ -2947,6 +3163,7 @@ var init_runtime = __esm({
|
|
|
2947
3163
|
globalOptions: this.globalOptions.snapshot(),
|
|
2948
3164
|
defaultModelOptions: this.defaultModelOptions.snapshot(),
|
|
2949
3165
|
modelOptions: modelOptionsSnap,
|
|
3166
|
+
modelOptionOverrides: { ...this.modelOptionOverrides },
|
|
2950
3167
|
dataOptions: dataOptionsSnap,
|
|
2951
3168
|
modelInstances: { ...this.modelInstances },
|
|
2952
3169
|
modelJsonSchemas: { ...this.modelJsonSchemas },
|
|
@@ -2961,6 +3178,10 @@ var init_runtime = __esm({
|
|
|
2961
3178
|
restoreBootstrapSnapshot(snapshot) {
|
|
2962
3179
|
this.globalOptions.restore(snapshot.globalOptions);
|
|
2963
3180
|
this.defaultModelOptions.restore(snapshot.defaultModelOptions);
|
|
3181
|
+
for (const name of Object.keys(this.modelOptionOverrides)) delete this.modelOptionOverrides[name];
|
|
3182
|
+
for (const [name, options] of Object.entries(snapshot.modelOptionOverrides)) {
|
|
3183
|
+
this.modelOptionOverrides[name] = modelOverrides(options);
|
|
3184
|
+
}
|
|
2964
3185
|
for (const name of Object.keys(this.modelOptions)) {
|
|
2965
3186
|
if (!(name in snapshot.modelOptions)) {
|
|
2966
3187
|
delete this.modelOptions[name];
|
|
@@ -2971,8 +3192,7 @@ var init_runtime = __esm({
|
|
|
2971
3192
|
if (existing) {
|
|
2972
3193
|
existing.restore(opts);
|
|
2973
3194
|
} else {
|
|
2974
|
-
const mgr = this.createModelOptions(name);
|
|
2975
|
-
mgr.restore(opts);
|
|
3195
|
+
const mgr = this.createModelOptions(name, opts);
|
|
2976
3196
|
this.modelOptions[name] = mgr;
|
|
2977
3197
|
}
|
|
2978
3198
|
}
|
|
@@ -3015,18 +3235,11 @@ var init_runtime = __esm({
|
|
|
3015
3235
|
}
|
|
3016
3236
|
/** Shallowly replace supplied global values; nested objects such as requestComplexity are not deep-merged. */
|
|
3017
3237
|
setGlobalOptions(options) {
|
|
3018
|
-
const
|
|
3019
|
-
|
|
3020
|
-
next.requireOperationAccessForPopulateQueries = next.requireOperationAccessForPopulateQueries !== false;
|
|
3021
|
-
if ("requireOperationAccessForPopulateDependencies" in next)
|
|
3022
|
-
next.requireOperationAccessForPopulateDependencies = next.requireOperationAccessForPopulateDependencies !== false;
|
|
3023
|
-
this.globalOptions.assign(next);
|
|
3238
|
+
for (const key of populatePolicyKeys) if (key in options) assertNoGlobalPopulatePolicy(key);
|
|
3239
|
+
this.globalOptions.assign({ ...options });
|
|
3024
3240
|
}
|
|
3025
3241
|
setGlobalOption(key, value) {
|
|
3026
|
-
|
|
3027
|
-
this.globalOptions.set(key, value !== false);
|
|
3028
|
-
return;
|
|
3029
|
-
}
|
|
3242
|
+
assertNoGlobalPopulatePolicy(String(key));
|
|
3030
3243
|
this.globalOptions.set(key, value);
|
|
3031
3244
|
}
|
|
3032
3245
|
getGlobalOptions() {
|
|
@@ -3035,28 +3248,30 @@ var init_runtime = __esm({
|
|
|
3035
3248
|
getGlobalOption(key, defaultValue) {
|
|
3036
3249
|
return this.globalOptions.get(key, defaultValue);
|
|
3037
3250
|
}
|
|
3038
|
-
/** Update model
|
|
3251
|
+
/** Update inherited model defaults shallowly. Explicit model values and captured calls are unchanged. */
|
|
3039
3252
|
setDefaultModelOptions(options) {
|
|
3040
3253
|
assertPublicDefaults(options.defaults);
|
|
3041
3254
|
if ("hydration" in options) options = { ...options, hydration: normalizeHydration(options.hydration) };
|
|
3042
|
-
|
|
3255
|
+
const draft = new OptionsManager(
|
|
3256
|
+
this.getDefaultModelOptions()
|
|
3257
|
+
).build();
|
|
3258
|
+
draft.assign(normalizePopulatePolicyOptions(options));
|
|
3259
|
+
this.publishDefaultModelOptions(draft.fetch());
|
|
3043
3260
|
}
|
|
3044
3261
|
setDefaultModelOption(key, value) {
|
|
3045
3262
|
const keyStr = String(key);
|
|
3046
|
-
|
|
3047
|
-
this.
|
|
3048
|
-
|
|
3049
|
-
|
|
3050
|
-
);
|
|
3051
|
-
|
|
3052
|
-
|
|
3053
|
-
|
|
3054
|
-
|
|
3055
|
-
const proposed = {};
|
|
3056
|
-
set4(proposed, keyStr.slice("defaults.".length), value);
|
|
3057
|
-
assertPublicDefaults(proposed);
|
|
3263
|
+
const draft = new OptionsManager(
|
|
3264
|
+
this.getDefaultModelOptions()
|
|
3265
|
+
).build();
|
|
3266
|
+
if (isPopulatePolicyKey(keyStr)) {
|
|
3267
|
+
draft.set(keyStr, normalizePopulatePolicyValue(value));
|
|
3268
|
+
} else if (keyStr === "hydration" || keyStr.startsWith("hydration.")) {
|
|
3269
|
+
draft.set("hydration", normalizeHydrationUpdate(this.getDefaultModelOptions().hydration, keyStr, value));
|
|
3270
|
+
} else {
|
|
3271
|
+
draft.set(key, value);
|
|
3058
3272
|
}
|
|
3059
|
-
|
|
3273
|
+
assertPublicDefaults(draft.fetch().defaults);
|
|
3274
|
+
this.publishDefaultModelOptions(draft.fetch());
|
|
3060
3275
|
}
|
|
3061
3276
|
getDefaultModelOptions() {
|
|
3062
3277
|
return this.defaultModelOptions.fetch();
|
|
@@ -3064,30 +3279,103 @@ var init_runtime = __esm({
|
|
|
3064
3279
|
getDefaultModelOption(key, defaultValue) {
|
|
3065
3280
|
return this.defaultModelOptions.get(key, defaultValue);
|
|
3066
3281
|
}
|
|
3067
|
-
|
|
3282
|
+
resolveModelOptions(modelName, overrides = this.modelOptionOverrides[modelName] ?? {}, defaults2 = this.getDefaultModelOptions()) {
|
|
3283
|
+
const inherited = { ...defaults2 };
|
|
3284
|
+
for (const key of populatePolicyKeys) delete inherited[key];
|
|
3285
|
+
const effective = { ...defaultModelOptions, ...inherited, ...overrides, modelName };
|
|
3286
|
+
effective.basePath = normalizeBasePath(modelName, effective.basePath);
|
|
3287
|
+
for (const key of unsafeSnapshotOptions) effective[key] = effective[key] === true;
|
|
3288
|
+
refreshPermissionMetadata(effective);
|
|
3289
|
+
return cloneOptionsSnapshot(effective);
|
|
3290
|
+
}
|
|
3291
|
+
validateModelOptions(modelName, options, proposed) {
|
|
3292
|
+
validateVirtualsTree(
|
|
3293
|
+
this.getModelInstance(modelName),
|
|
3294
|
+
options.virtuals,
|
|
3295
|
+
options.documentPermissionField ?? "_permissions",
|
|
3296
|
+
modelName
|
|
3297
|
+
);
|
|
3298
|
+
captureVirtualPopulateDependencies(this, modelName, options, void 0, proposed);
|
|
3299
|
+
}
|
|
3300
|
+
publishDefaultModelOptions(options) {
|
|
3301
|
+
const next = { ...options };
|
|
3302
|
+
for (const key of unsafeSnapshotOptions) if (key in next) next[key] = next[key] === true;
|
|
3303
|
+
const defaults2 = cloneOptionsSnapshot(next);
|
|
3304
|
+
const models = new Map(
|
|
3305
|
+
Object.keys(this.modelOptions).map((name) => [name, this.resolveModelOptions(name, void 0, defaults2)])
|
|
3306
|
+
);
|
|
3307
|
+
for (const [name, options2] of models) this.validateModelOptions(name, options2, { defaults: defaults2, models });
|
|
3308
|
+
this.deferSnapshotWarnings(() => {
|
|
3309
|
+
this.defaultModelOptions.restore(defaults2);
|
|
3310
|
+
for (const [name, options2] of models) this.modelOptions[name].restore(options2);
|
|
3311
|
+
});
|
|
3312
|
+
}
|
|
3313
|
+
warnSnapshotFlag(modelName, key) {
|
|
3314
|
+
if (this.pendingSnapshotWarnings) {
|
|
3315
|
+
this.pendingSnapshotWarnings.push({ modelName, key });
|
|
3316
|
+
return;
|
|
3317
|
+
}
|
|
3318
|
+
const operation = key.startsWith("unsafeSkipRead") ? "read" : "list";
|
|
3319
|
+
const category = key.includes("NestedDocument") ? "nested-document" : key.includes("Output") ? "output" : "document";
|
|
3320
|
+
const risk = category === "output" ? "output mutation" : "source mutation";
|
|
3321
|
+
try {
|
|
3322
|
+
this.getGlobalOption("logger")?.warn?.(
|
|
3323
|
+
`UNSAFE: ${operation} ${category} snapshot checks disabled; ${risk} can leave stale authorization decisions. Restore ${key}=false after the temporary workaround.`,
|
|
3324
|
+
{ modelName }
|
|
3325
|
+
);
|
|
3326
|
+
} catch {
|
|
3327
|
+
}
|
|
3328
|
+
}
|
|
3329
|
+
deferSnapshotWarnings(publish) {
|
|
3330
|
+
if (this.pendingSnapshotWarnings) return publish();
|
|
3331
|
+
const copyModes = this.initialOutputCopyModes();
|
|
3332
|
+
const pending = [];
|
|
3333
|
+
this.pendingSnapshotWarnings = pending;
|
|
3334
|
+
let result2;
|
|
3335
|
+
try {
|
|
3336
|
+
result2 = publish();
|
|
3337
|
+
} finally {
|
|
3338
|
+
this.pendingSnapshotWarnings = void 0;
|
|
3339
|
+
}
|
|
3340
|
+
const nextCopyModes = this.initialOutputCopyModes();
|
|
3341
|
+
for (const { modelName, key } of pending) this.warnSnapshotFlag(modelName, key);
|
|
3342
|
+
for (const [modelName, modes] of nextCopyModes) {
|
|
3343
|
+
for (const operation of ["List", "Read"]) {
|
|
3344
|
+
const mode = modes[operation];
|
|
3345
|
+
if (mode === "off" || mode === copyModes.get(modelName)?.[operation]) continue;
|
|
3346
|
+
const key = `unsafeSkip${operation}InitialOutputSnapshotCopy`;
|
|
3347
|
+
const prerequisite = `unsafeSkip${operation}OutputSnapshotChecks`;
|
|
3348
|
+
try {
|
|
3349
|
+
this.getGlobalOption("logger")?.warn?.(
|
|
3350
|
+
mode === "active" ? `UNSAFE: ${operation.toLowerCase()} initial output snapshot copying disabled for eligible graphs; omitted native normalization/validation can change side effects and authorization outcomes. Restore ${key}=false after the temporary workaround.` : `UNSAFE: ${key} is dormant; requires ${prerequisite}=true. Initial copying and output comparisons remain enabled. Restore ${key}=false if not intended.`,
|
|
3351
|
+
{ modelName }
|
|
3352
|
+
);
|
|
3353
|
+
} catch {
|
|
3354
|
+
}
|
|
3355
|
+
}
|
|
3356
|
+
}
|
|
3357
|
+
return result2;
|
|
3358
|
+
}
|
|
3359
|
+
initialOutputCopyModes() {
|
|
3360
|
+
return new Map(
|
|
3361
|
+
Object.entries(this.modelOptions).map(([modelName, options]) => {
|
|
3362
|
+
const mode = (operation) => options.get(`unsafeSkip${operation}InitialOutputSnapshotCopy`) !== true ? "off" : options.get(`unsafeSkip${operation}OutputSnapshotChecks`) === true ? "active" : "dormant";
|
|
3363
|
+
return [modelName, { List: mode("List"), Read: mode("Read") }];
|
|
3364
|
+
})
|
|
3365
|
+
);
|
|
3366
|
+
}
|
|
3367
|
+
createModelOptions(modelName, options = this.resolveModelOptions(modelName)) {
|
|
3068
3368
|
const model = this.getModelInstance(modelName);
|
|
3069
3369
|
if (!model) {
|
|
3070
3370
|
throw new Error(
|
|
3071
3371
|
`Runtime model registry missing model "${modelName}". Pass a mongoose.Model instance to createRouter() or register it with registerModelInstance() before using this isolated runtime.`
|
|
3072
3372
|
);
|
|
3073
3373
|
}
|
|
3074
|
-
const manager = new OptionsManager(
|
|
3075
|
-
...defaultModelOptions,
|
|
3076
|
-
modelName
|
|
3077
|
-
});
|
|
3374
|
+
const manager = new OptionsManager(options);
|
|
3078
3375
|
const snapshotFlagChanged = (newValue, key, target, oldValue) => {
|
|
3079
3376
|
target[key] = newValue === true;
|
|
3080
3377
|
if (newValue !== true || oldValue === true) return;
|
|
3081
|
-
|
|
3082
|
-
const category = key.includes("NestedDocument") ? "nested-document" : key.includes("Output") ? "output" : "document";
|
|
3083
|
-
const risk = category === "output" ? "output mutation" : "source mutation";
|
|
3084
|
-
try {
|
|
3085
|
-
this.getGlobalOption("logger")?.warn?.(
|
|
3086
|
-
`UNSAFE: ${operation} ${category} snapshot checks disabled; ${risk} can leave stale authorization decisions. Restore ${key}=false after the temporary workaround.`,
|
|
3087
|
-
{ modelName }
|
|
3088
|
-
);
|
|
3089
|
-
} catch {
|
|
3090
|
-
}
|
|
3378
|
+
this.warnSnapshotFlag(modelName, key);
|
|
3091
3379
|
};
|
|
3092
3380
|
manager.onchange("permissionSchema", function(_newval, _key, target) {
|
|
3093
3381
|
refreshPermissionMetadata(target);
|
|
@@ -3105,13 +3393,17 @@ var init_runtime = __esm({
|
|
|
3105
3393
|
getOrCreateModelOptions(modelName) {
|
|
3106
3394
|
let manager = this.modelOptions[modelName];
|
|
3107
3395
|
if (!manager) {
|
|
3108
|
-
manager = this.
|
|
3109
|
-
|
|
3396
|
+
manager = this.deferSnapshotWarnings(() => {
|
|
3397
|
+
const created = this.createModelOptions(modelName);
|
|
3398
|
+
this.modelOptions[modelName] = created;
|
|
3399
|
+
return created;
|
|
3400
|
+
});
|
|
3110
3401
|
}
|
|
3111
3402
|
return manager;
|
|
3112
3403
|
}
|
|
3113
3404
|
/**
|
|
3114
|
-
*
|
|
3405
|
+
* Update explicit model overrides shallowly; undefined restores default inheritance
|
|
3406
|
+
* (operationAccess preserves its existing exact-key-only default fallback). A supplied
|
|
3115
3407
|
* operationAccess/defaults object replaces that whole value. Defaults accept only
|
|
3116
3408
|
* query/presentation settings; virtual configuration is validated before assignment.
|
|
3117
3409
|
* Existing router.options remains its construction-time snapshot. Fresh model-service
|
|
@@ -3119,22 +3411,23 @@ var init_runtime = __esm({
|
|
|
3119
3411
|
*/
|
|
3120
3412
|
setModelOptions(modelName, options) {
|
|
3121
3413
|
assertPublicDefaults(options.defaults);
|
|
3414
|
+
options = normalizePopulatePolicyOptions(options);
|
|
3122
3415
|
if ("hydration" in options) options = { ...options, hydration: normalizeHydration(options.hydration) };
|
|
3123
|
-
const
|
|
3124
|
-
const
|
|
3125
|
-
|
|
3126
|
-
|
|
3127
|
-
|
|
3128
|
-
|
|
3129
|
-
|
|
3130
|
-
|
|
3131
|
-
|
|
3416
|
+
const overrides = modelOverrides({ ...this.modelOptionOverrides[modelName], ...options });
|
|
3417
|
+
const effective = this.resolveModelOptions(modelName, overrides);
|
|
3418
|
+
this.validateModelOptions(modelName, effective);
|
|
3419
|
+
this.deferSnapshotWarnings(() => {
|
|
3420
|
+
const manager = this.modelOptions[modelName];
|
|
3421
|
+
if (manager) manager.restore(effective);
|
|
3422
|
+
else this.modelOptions[modelName] = this.createModelOptions(modelName, effective);
|
|
3423
|
+
this.modelOptionOverrides[modelName] = overrides;
|
|
3424
|
+
});
|
|
3132
3425
|
}
|
|
3133
3426
|
setModelOption(modelName, key, value) {
|
|
3134
3427
|
const keyStr = String(key);
|
|
3135
3428
|
if (keyStr === "hydration" || keyStr.startsWith("hydration.")) {
|
|
3136
|
-
const hydration = normalizeHydrationUpdate(this.
|
|
3137
|
-
this.
|
|
3429
|
+
const hydration = normalizeHydrationUpdate(this.resolveModelOptions(modelName).hydration, keyStr, value);
|
|
3430
|
+
this.setModelOptions(modelName, { hydration });
|
|
3138
3431
|
return;
|
|
3139
3432
|
}
|
|
3140
3433
|
if (keyStr === "defaults") assertPublicDefaults(value);
|
|
@@ -3143,47 +3436,20 @@ var init_runtime = __esm({
|
|
|
3143
3436
|
set4(proposed, keyStr.slice("defaults.".length), value);
|
|
3144
3437
|
assertPublicDefaults(proposed);
|
|
3145
3438
|
}
|
|
3146
|
-
const
|
|
3147
|
-
if (
|
|
3148
|
-
|
|
3149
|
-
|
|
3150
|
-
const currentPermissionField = manager?.get("documentPermissionField") ?? this.getDefaultModelOption("documentPermissionField") ?? "_permissions";
|
|
3151
|
-
let proposedVirtuals = currentVirtuals;
|
|
3152
|
-
let proposedPermissionField = currentPermissionField;
|
|
3153
|
-
if (keyStr === "documentPermissionField") {
|
|
3154
|
-
proposedPermissionField = value;
|
|
3155
|
-
} else if (keyStr === "virtuals") {
|
|
3156
|
-
proposedVirtuals = value;
|
|
3157
|
-
} else {
|
|
3158
|
-
const cloned = cloneVirtualsForValidation(currentVirtuals ?? {});
|
|
3159
|
-
const nestedPath = keyStr.slice("virtuals.".length);
|
|
3160
|
-
if (value === void 0) {
|
|
3161
|
-
const segments = nestedPath.split(".");
|
|
3162
|
-
let cursor = cloned;
|
|
3163
|
-
for (let i = 0; i < segments.length - 1; i++) {
|
|
3164
|
-
if (!isPlainObject14(cursor)) break;
|
|
3165
|
-
cursor = cursor[segments[i]];
|
|
3166
|
-
}
|
|
3167
|
-
if (isPlainObject14(cursor)) {
|
|
3168
|
-
delete cursor[segments[segments.length - 1]];
|
|
3169
|
-
}
|
|
3170
|
-
proposedVirtuals = cloned;
|
|
3171
|
-
} else {
|
|
3172
|
-
set4(cloned, nestedPath, value);
|
|
3173
|
-
proposedVirtuals = cloned;
|
|
3174
|
-
}
|
|
3175
|
-
}
|
|
3176
|
-
validateVirtualsTree(model, proposedVirtuals, proposedPermissionField, modelName);
|
|
3177
|
-
captureVirtualPopulateDependencies(this, modelName, {
|
|
3178
|
-
...this.getDefaultModelOptions(),
|
|
3179
|
-
...manager?.fetch(),
|
|
3180
|
-
virtuals: proposedVirtuals,
|
|
3181
|
-
documentPermissionField: proposedPermissionField
|
|
3182
|
-
});
|
|
3439
|
+
const [root, ...path] = keyStr.split(".");
|
|
3440
|
+
if (!path.length) {
|
|
3441
|
+
this.setModelOptions(modelName, { [root]: value });
|
|
3442
|
+
return;
|
|
3183
3443
|
}
|
|
3184
|
-
this.
|
|
3185
|
-
|
|
3186
|
-
|
|
3444
|
+
const current = this.resolveModelOptions(modelName);
|
|
3445
|
+
const nested = cloneModelOptionForUpdate(isPlainObject14(current[root]) ? current[root] : {});
|
|
3446
|
+
if (root === "virtuals" && value === void 0) {
|
|
3447
|
+
const parent = path.length === 1 ? nested : get5(nested, path.slice(0, -1));
|
|
3448
|
+
if (isPlainObject14(parent)) delete parent[path[path.length - 1]];
|
|
3449
|
+
} else set4(nested, path, value);
|
|
3450
|
+
this.setModelOptions(modelName, { [root]: nested });
|
|
3451
|
+
}
|
|
3452
|
+
/** Frozen model/default snapshot; populate flags remain raw overrides. Read again for current values. */
|
|
3187
3453
|
getModelOptions(modelName) {
|
|
3188
3454
|
const manager = this.getOrCreateModelOptions(modelName);
|
|
3189
3455
|
return manager.fetch();
|
|
@@ -3350,132 +3616,117 @@ var init_runtime = __esm({
|
|
|
3350
3616
|
}
|
|
3351
3617
|
});
|
|
3352
3618
|
|
|
3353
|
-
// src/runtime-context.ts
|
|
3354
|
-
import { AsyncLocalStorage as AsyncLocalStorage2 } from "async_hooks";
|
|
3355
|
-
function runWithRuntime(runtime, callback) {
|
|
3356
|
-
return runtimeStorage.run(runtime, callback);
|
|
3357
|
-
}
|
|
3358
|
-
function getActiveRuntime() {
|
|
3359
|
-
return runtimeStorage.getStore() ?? null;
|
|
3360
|
-
}
|
|
3361
|
-
var runtimeStorage;
|
|
3362
|
-
var init_runtime_context = __esm({
|
|
3363
|
-
"src/runtime-context.ts"() {
|
|
3364
|
-
runtimeStorage = new AsyncLocalStorage2();
|
|
3365
|
-
}
|
|
3366
|
-
});
|
|
3367
|
-
|
|
3368
3619
|
// src/options/global-options.ts
|
|
3369
|
-
var
|
|
3620
|
+
var getRuntime2, setGlobalOptions, setGlobalOption, getGlobalOptions, getGlobalOption;
|
|
3370
3621
|
var init_global_options = __esm({
|
|
3371
3622
|
"src/options/global-options.ts"() {
|
|
3372
3623
|
init_runtime();
|
|
3373
3624
|
init_runtime_context();
|
|
3374
|
-
|
|
3625
|
+
getRuntime2 = () => getActiveRuntime() ?? defaultRuntime;
|
|
3375
3626
|
setGlobalOptions = (options) => {
|
|
3376
|
-
|
|
3627
|
+
getRuntime2().setGlobalOptions(options);
|
|
3377
3628
|
};
|
|
3378
3629
|
setGlobalOption = (key, value) => {
|
|
3379
|
-
|
|
3630
|
+
getRuntime2().setGlobalOption(key, value);
|
|
3380
3631
|
};
|
|
3381
3632
|
getGlobalOptions = () => {
|
|
3382
|
-
return
|
|
3633
|
+
return getRuntime2().getGlobalOptions();
|
|
3383
3634
|
};
|
|
3384
3635
|
getGlobalOption = (key, defaultValue) => {
|
|
3385
|
-
return
|
|
3636
|
+
return getRuntime2().getGlobalOption(key, defaultValue);
|
|
3386
3637
|
};
|
|
3387
3638
|
}
|
|
3388
3639
|
});
|
|
3389
3640
|
|
|
3390
3641
|
// src/options/model-options.ts
|
|
3391
|
-
var
|
|
3642
|
+
var getRuntime3, setModelOptions, setModelOption, getModelOptions, getModelOption, getExactModelOption, getModelNames, getModelJsonSchema, registerModelInstance, hasModelInstance, getModelInstance;
|
|
3392
3643
|
var init_model_options = __esm({
|
|
3393
3644
|
"src/options/model-options.ts"() {
|
|
3394
3645
|
init_runtime();
|
|
3395
3646
|
init_runtime_context();
|
|
3396
|
-
|
|
3647
|
+
getRuntime3 = () => getActiveRuntime() ?? defaultRuntime;
|
|
3397
3648
|
setModelOptions = (modelName, options) => {
|
|
3398
|
-
|
|
3649
|
+
getRuntime3().setModelOptions(modelName, options);
|
|
3399
3650
|
};
|
|
3400
3651
|
setModelOption = (modelName, key, value) => {
|
|
3401
|
-
|
|
3652
|
+
getRuntime3().setModelOption(modelName, key, value);
|
|
3402
3653
|
};
|
|
3403
3654
|
getModelOptions = (modelName) => {
|
|
3404
|
-
return
|
|
3655
|
+
return getRuntime3().getModelOptions(modelName);
|
|
3405
3656
|
};
|
|
3406
3657
|
getModelOption = (modelName, key, defaultValue) => {
|
|
3407
|
-
return
|
|
3658
|
+
return getRuntime3().getModelOption(modelName, key, defaultValue);
|
|
3408
3659
|
};
|
|
3409
3660
|
getExactModelOption = (modelName, key) => {
|
|
3410
|
-
return
|
|
3661
|
+
return getRuntime3().getExactModelOption(modelName, key);
|
|
3411
3662
|
};
|
|
3412
3663
|
getModelNames = () => {
|
|
3413
3664
|
return (getActiveRuntime() ?? defaultRuntime).getModelNames();
|
|
3414
3665
|
};
|
|
3415
3666
|
getModelJsonSchema = (modelName) => {
|
|
3416
|
-
return
|
|
3667
|
+
return getRuntime3().getModelJsonSchema(modelName);
|
|
3417
3668
|
};
|
|
3418
3669
|
registerModelInstance = (modelName, model) => {
|
|
3419
|
-
|
|
3670
|
+
getRuntime3().registerModelInstance(modelName, model);
|
|
3420
3671
|
};
|
|
3421
3672
|
hasModelInstance = (modelName) => {
|
|
3422
|
-
return
|
|
3673
|
+
return getRuntime3().hasModelInstance(modelName);
|
|
3423
3674
|
};
|
|
3424
3675
|
getModelInstance = (modelName) => {
|
|
3425
|
-
return
|
|
3676
|
+
return getRuntime3().getModelInstance(modelName);
|
|
3426
3677
|
};
|
|
3427
3678
|
}
|
|
3428
3679
|
});
|
|
3429
3680
|
|
|
3430
3681
|
// src/options/default-model-options.ts
|
|
3431
|
-
var
|
|
3682
|
+
var getRuntime4, setDefaultModelOptions, setDefaultModelOption, getDefaultModelOptions, getDefaultModelOption;
|
|
3432
3683
|
var init_default_model_options = __esm({
|
|
3433
3684
|
"src/options/default-model-options.ts"() {
|
|
3434
3685
|
init_runtime();
|
|
3435
3686
|
init_runtime_context();
|
|
3436
|
-
|
|
3687
|
+
getRuntime4 = () => getActiveRuntime() ?? defaultRuntime;
|
|
3437
3688
|
setDefaultModelOptions = (options) => {
|
|
3438
|
-
|
|
3689
|
+
getRuntime4().setDefaultModelOptions(options);
|
|
3439
3690
|
};
|
|
3440
3691
|
setDefaultModelOption = (key, value) => {
|
|
3441
|
-
|
|
3692
|
+
getRuntime4().setDefaultModelOption(key, value);
|
|
3442
3693
|
};
|
|
3443
3694
|
getDefaultModelOptions = () => {
|
|
3444
|
-
return
|
|
3695
|
+
return getRuntime4().getDefaultModelOptions();
|
|
3445
3696
|
};
|
|
3446
3697
|
getDefaultModelOption = (key, defaultValue) => {
|
|
3447
|
-
return
|
|
3698
|
+
return getRuntime4().getDefaultModelOption(key, defaultValue);
|
|
3448
3699
|
};
|
|
3449
3700
|
}
|
|
3450
3701
|
});
|
|
3451
3702
|
|
|
3452
3703
|
// src/options/data-options.ts
|
|
3453
|
-
var
|
|
3704
|
+
var getRuntime5, setDataOptions, setDataOption, getDataOptions, getDataSnapshot, getDataOption, getExactDataOption, getDataNames;
|
|
3454
3705
|
var init_data_options = __esm({
|
|
3455
3706
|
"src/options/data-options.ts"() {
|
|
3456
3707
|
init_runtime();
|
|
3457
3708
|
init_runtime_context();
|
|
3458
|
-
|
|
3709
|
+
getRuntime5 = () => getActiveRuntime() ?? defaultRuntime;
|
|
3459
3710
|
setDataOptions = (dataName, options) => {
|
|
3460
|
-
|
|
3711
|
+
getRuntime5().setDataOptions(dataName, options);
|
|
3461
3712
|
};
|
|
3462
3713
|
setDataOption = (dataName, key, value) => {
|
|
3463
|
-
|
|
3714
|
+
getRuntime5().setDataOption(dataName, key, value);
|
|
3464
3715
|
};
|
|
3465
3716
|
getDataOptions = (dataName) => {
|
|
3466
|
-
return
|
|
3717
|
+
return getRuntime5().getDataOptions(dataName);
|
|
3467
3718
|
};
|
|
3468
3719
|
getDataSnapshot = (dataName) => {
|
|
3469
|
-
return
|
|
3720
|
+
return getRuntime5().getDataSnapshot(dataName);
|
|
3470
3721
|
};
|
|
3471
3722
|
getDataOption = (dataName, key, defaultValue) => {
|
|
3472
|
-
return
|
|
3723
|
+
return getRuntime5().getDataOption(dataName, key, defaultValue);
|
|
3473
3724
|
};
|
|
3474
3725
|
getExactDataOption = (dataName, key) => {
|
|
3475
|
-
return
|
|
3726
|
+
return getRuntime5().getExactDataOption(dataName, key);
|
|
3476
3727
|
};
|
|
3477
3728
|
getDataNames = () => {
|
|
3478
|
-
return
|
|
3729
|
+
return getRuntime5().getDataNames();
|
|
3479
3730
|
};
|
|
3480
3731
|
}
|
|
3481
3732
|
});
|
|
@@ -3796,10 +4047,12 @@ function resolveServiceAuthorization(input) {
|
|
|
3796
4047
|
const listResponse = input.listResponse === true && input.parent === void 0 && (input.applicability ?? "service") === "service" && scopePath.length === 0 && outputAccess.operation === "list" && outputAccess.rowAccess === "list" && queryOutputAccess(outputAccess);
|
|
3797
4048
|
const responseSnapshots = input.parent && (nestedResponse || readResponse) ? callRecord(input.parent).responseSnapshots : listResponse ? Object.freeze({
|
|
3798
4049
|
skipOutput: configuration.unsafeSkipListOutputSnapshotChecks === true,
|
|
3799
|
-
skipNested: configuration.unsafeSkipListNestedDocumentSnapshotChecks === true
|
|
4050
|
+
skipNested: configuration.unsafeSkipListNestedDocumentSnapshotChecks === true,
|
|
4051
|
+
skipInitialOutputCopy: configuration.unsafeSkipListOutputSnapshotChecks === true && configuration.unsafeSkipListInitialOutputSnapshotCopy === true
|
|
3800
4052
|
}) : readResponse ? Object.freeze({
|
|
3801
4053
|
skipOutput: configuration.unsafeSkipReadOutputSnapshotChecks === true,
|
|
3802
|
-
skipNested: configuration.unsafeSkipReadNestedDocumentSnapshotChecks === true
|
|
4054
|
+
skipNested: configuration.unsafeSkipReadNestedDocumentSnapshotChecks === true,
|
|
4055
|
+
skipInitialOutputCopy: configuration.unsafeSkipReadOutputSnapshotChecks === true && configuration.unsafeSkipReadInitialOutputSnapshotCopy === true
|
|
3803
4056
|
}) : void 0;
|
|
3804
4057
|
const call = Object.freeze(/* @__PURE__ */ Object.create(null));
|
|
3805
4058
|
calls.set(call, {
|
|
@@ -3816,6 +4069,7 @@ function resolveServiceAuthorization(input) {
|
|
|
3816
4069
|
nestedResponse,
|
|
3817
4070
|
responseSnapshots,
|
|
3818
4071
|
validateOutputSnapshots: responseSnapshots?.skipOutput !== true,
|
|
4072
|
+
skipInitialOutputSnapshotCopy: responseSnapshots?.skipInitialOutputCopy === true,
|
|
3819
4073
|
validateDocumentSnapshots: !(input.listResponse === true && input.parent === void 0 && (input.applicability ?? "service") === "service" && outputAccess.operation === "list" && outputAccess.rowAccess === "list" && outputAccess.outputAccess === "list" && scopePath.length === 0 && configuration.unsafeSkipListDocumentSnapshotChecks === true || readResponse && configuration.unsafeSkipReadDocumentSnapshotChecks === true || nestedResponse && responseSnapshots?.skipNested === true)
|
|
3820
4074
|
});
|
|
3821
4075
|
return call;
|
|
@@ -3845,6 +4099,10 @@ function requiresOutputSnapshotChecks(call, binding) {
|
|
|
3845
4099
|
assertAuthorizationBinding(call, binding);
|
|
3846
4100
|
return callRecord(call).validateOutputSnapshots;
|
|
3847
4101
|
}
|
|
4102
|
+
function skipsInitialOutputSnapshotCopy(call) {
|
|
4103
|
+
const record3 = callRecord(call);
|
|
4104
|
+
return !record3.validateOutputSnapshots && record3.skipInitialOutputSnapshotCopy;
|
|
4105
|
+
}
|
|
3848
4106
|
function readServiceAuthorizationHydration(call, binding) {
|
|
3849
4107
|
assertAuthorizationBinding(call, binding);
|
|
3850
4108
|
return copyAuthorizationValue({ hydration: callRecord(call).configuration.hydration }, true);
|
|
@@ -4297,9 +4555,9 @@ var init_virtual_projection = __esm({
|
|
|
4297
4555
|
});
|
|
4298
4556
|
|
|
4299
4557
|
// src/acl/output-projection.ts
|
|
4300
|
-
import { types as
|
|
4558
|
+
import { types as types3 } from "util";
|
|
4301
4559
|
function copyOutputDecisionFields(value) {
|
|
4302
|
-
if (!Array.isArray(value) ||
|
|
4560
|
+
if (!Array.isArray(value) || types3.isProxy(value) || Object.getPrototypeOf(value) !== Array.prototype) return;
|
|
4303
4561
|
const length = Object.getOwnPropertyDescriptor(value, "length").value;
|
|
4304
4562
|
if (length > 2e4) return;
|
|
4305
4563
|
const fields = [];
|
|
@@ -4312,14 +4570,14 @@ function copyOutputDecisionFields(value) {
|
|
|
4312
4570
|
}
|
|
4313
4571
|
function readStaticOutputPlanFields(plan, authorization) {
|
|
4314
4572
|
const record3 = staticPlanFields.get(plan);
|
|
4315
|
-
if (!record3 || record3.authorization !== authorization ||
|
|
4573
|
+
if (!record3 || record3.authorization !== authorization || types3.isProxy(plan)) return;
|
|
4316
4574
|
const ownValue2 = (key) => {
|
|
4317
4575
|
const slot = Object.getOwnPropertyDescriptor(plan, key);
|
|
4318
4576
|
return slot && "value" in slot ? slot.value : void 0;
|
|
4319
4577
|
};
|
|
4320
4578
|
if (ownValue2("authorization") !== authorization || ownValue2("authorizationBinding") !== record3.binding) return;
|
|
4321
4579
|
const children = ownValue2("childPlans");
|
|
4322
|
-
if (children !== record3.children ||
|
|
4580
|
+
if (children !== record3.children || types3.isProxy(children) || Reflect.ownKeys(children).length) return;
|
|
4323
4581
|
const persisted = copyOutputDecisionFields(ownValue2("outputPersistedFields"));
|
|
4324
4582
|
const virtuals = copyOutputDecisionFields(ownValue2("outputVirtualNames"));
|
|
4325
4583
|
const same = (a, b) => a?.length === b.length && a.every((field, index) => field === b[index]);
|
|
@@ -4574,7 +4832,7 @@ var init_output_projection = __esm({
|
|
|
4574
4832
|
});
|
|
4575
4833
|
|
|
4576
4834
|
// src/acl/output-field-policy.ts
|
|
4577
|
-
import { types as
|
|
4835
|
+
import { types as types4 } from "util";
|
|
4578
4836
|
import { isPlainObject as isPlainObject16 } from "@web-ts-toolkit/utils";
|
|
4579
4837
|
function callFieldPolicy(authorization, binding) {
|
|
4580
4838
|
assertAuthorizationBinding(authorization, binding);
|
|
@@ -4646,7 +4904,7 @@ function prepareOutputPath(policy, authorization, binding, path, access) {
|
|
|
4646
4904
|
return prepared;
|
|
4647
4905
|
}
|
|
4648
4906
|
function ordinaryContainer(value) {
|
|
4649
|
-
return value !== null && typeof value === "object" && !
|
|
4907
|
+
return value !== null && typeof value === "object" && !types4.isProxy(value) && Object.getPrototypeOf(value) === Object.prototype && Object.isFrozen(value);
|
|
4650
4908
|
}
|
|
4651
4909
|
function booleanRuleLookup(schema, path, access) {
|
|
4652
4910
|
if (schema == null) return true;
|
|
@@ -4705,7 +4963,7 @@ var init_output_field_policy = __esm({
|
|
|
4705
4963
|
});
|
|
4706
4964
|
|
|
4707
4965
|
// src/acl/document-authorization.ts
|
|
4708
|
-
import { types as
|
|
4966
|
+
import { types as types5 } from "util";
|
|
4709
4967
|
import { Document as Document3 } from "mongoose";
|
|
4710
4968
|
function bindOutputDocumentOwner(handle, knownOutput, owner, binding) {
|
|
4711
4969
|
lookupDocumentOwner(handle);
|
|
@@ -4887,7 +5145,7 @@ function memoizeDocumentFieldDecision(handle, binding, field, evaluate) {
|
|
|
4887
5145
|
return decision.promise;
|
|
4888
5146
|
}
|
|
4889
5147
|
function ordinaryDecisionBinding(binding) {
|
|
4890
|
-
if (
|
|
5148
|
+
if (types5.isProxy(binding) || Object.getPrototypeOf(binding) !== Object.prototype) return false;
|
|
4891
5149
|
for (const key of ["request", "runtime", "model", "modelName", "scopePath"]) {
|
|
4892
5150
|
const slot = Object.getOwnPropertyDescriptor(binding, key);
|
|
4893
5151
|
if (slot && !("value" in slot)) return false;
|
|
@@ -5038,8 +5296,18 @@ function associateDocumentAuthorization(handle, binding, output) {
|
|
|
5038
5296
|
authorizationError("output already associated");
|
|
5039
5297
|
return;
|
|
5040
5298
|
}
|
|
5299
|
+
if (skipsInitialOutputSnapshotCopy(stage.call) && ordinaryDecisionBinding(binding)) {
|
|
5300
|
+
if (requiresOutputSnapshotChecks(stage.call, binding))
|
|
5301
|
+
authorizationError("output snapshot copy requires skipped comparisons");
|
|
5302
|
+
const identities = tryOutputIdentitiesWithoutSnapshot(output);
|
|
5303
|
+
if (identities) {
|
|
5304
|
+
outputs.set(output, { handle, snapshotState: "omitted", identities, validateSnapshot: false });
|
|
5305
|
+
return;
|
|
5306
|
+
}
|
|
5307
|
+
}
|
|
5041
5308
|
outputs.set(output, {
|
|
5042
5309
|
handle,
|
|
5310
|
+
snapshotState: "copied",
|
|
5043
5311
|
snapshot: copyAuthorizationValue(output, "document"),
|
|
5044
5312
|
identities: outputIdentities(output),
|
|
5045
5313
|
validateSnapshot: requiresOutputSnapshotChecks(stage.call, binding)
|
|
@@ -5219,7 +5487,8 @@ function getCapturedAuthorizationOption(configuration, key) {
|
|
|
5219
5487
|
const defaultValue = key.startsWith("operationAccess.") ? get7(configuration.operationAccessDefaults, key.slice("operationAccess.".length)) : void 0;
|
|
5220
5488
|
return resolveNestedOption((path, fallback) => get7(configuration, path, fallback), key, defaultValue);
|
|
5221
5489
|
}
|
|
5222
|
-
function captureModelAuthorizationConfiguration(runtime, modelName, options
|
|
5490
|
+
function captureModelAuthorizationConfiguration(runtime, modelName, options, populatePolicyDefaults = capturePopulatePolicyDefaults(runtime)) {
|
|
5491
|
+
options ??= runtime.getModelOptions(modelName);
|
|
5223
5492
|
const model = runtime.getModelInstance(modelName);
|
|
5224
5493
|
if (!model) return authorizationError(`unknown receiving model: ${modelName}`);
|
|
5225
5494
|
const virtuals = options.virtuals;
|
|
@@ -5230,10 +5499,10 @@ function captureModelAuthorizationConfiguration(runtime, modelName, options = ru
|
|
|
5230
5499
|
runtime,
|
|
5231
5500
|
modelName,
|
|
5232
5501
|
options,
|
|
5233
|
-
|
|
5502
|
+
populatePolicyDefaults
|
|
5234
5503
|
),
|
|
5235
|
-
|
|
5236
|
-
|
|
5504
|
+
populatePolicyDefaults,
|
|
5505
|
+
...resolvePopulatePolicy(options, populatePolicyDefaults),
|
|
5237
5506
|
permissionSchema: options.permissionSchema === void 0 ? runtime.getDefaultModelOption("permissionSchema") : options.permissionSchema,
|
|
5238
5507
|
virtuals,
|
|
5239
5508
|
alwaysSelectFields: options.alwaysSelectFields,
|
|
@@ -5250,6 +5519,8 @@ function captureModelAuthorizationConfiguration(runtime, modelName, options = ru
|
|
|
5250
5519
|
unsafeSkipReadOutputSnapshotChecks: options.unsafeSkipReadOutputSnapshotChecks === true,
|
|
5251
5520
|
unsafeSkipListNestedDocumentSnapshotChecks: options.unsafeSkipListNestedDocumentSnapshotChecks === true,
|
|
5252
5521
|
unsafeSkipReadNestedDocumentSnapshotChecks: options.unsafeSkipReadNestedDocumentSnapshotChecks === true,
|
|
5522
|
+
unsafeSkipListInitialOutputSnapshotCopy: options.unsafeSkipListInitialOutputSnapshotCopy === true,
|
|
5523
|
+
unsafeSkipReadInitialOutputSnapshotCopy: options.unsafeSkipReadInitialOutputSnapshotCopy === true,
|
|
5253
5524
|
overrideFilter: options.overrideFilter,
|
|
5254
5525
|
baseFilter: options.baseFilter,
|
|
5255
5526
|
idField: options.idField,
|
|
@@ -5294,6 +5565,7 @@ var init_model_output_planning = __esm({
|
|
|
5294
5565
|
init_virtual_populate_dependencies();
|
|
5295
5566
|
init_document_authorization();
|
|
5296
5567
|
init_output_projection();
|
|
5568
|
+
init_populate_policy2();
|
|
5297
5569
|
}
|
|
5298
5570
|
});
|
|
5299
5571
|
|
|
@@ -5772,6 +6044,13 @@ var init_logger_helpers = __esm({
|
|
|
5772
6044
|
|
|
5773
6045
|
// src/acl/populate-target.ts
|
|
5774
6046
|
function setPopulateTargetMeta(entry, meta) {
|
|
6047
|
+
if (meta.fetchBinding)
|
|
6048
|
+
Object.defineProperty(entry, "model", {
|
|
6049
|
+
value: meta.fetchBinding.model,
|
|
6050
|
+
enumerable: true,
|
|
6051
|
+
writable: false,
|
|
6052
|
+
configurable: false
|
|
6053
|
+
});
|
|
5775
6054
|
Object.defineProperty(entry, POPULATE_TARGET_PLAN, {
|
|
5776
6055
|
value: meta,
|
|
5777
6056
|
enumerable: false,
|
|
@@ -6323,7 +6602,7 @@ var init_virtual_populate_execution = __esm({
|
|
|
6323
6602
|
});
|
|
6324
6603
|
|
|
6325
6604
|
// src/acl/output-field-filter.ts
|
|
6326
|
-
import { types as
|
|
6605
|
+
import { types as types6 } from "util";
|
|
6327
6606
|
import { isPlainObject as isPlainObject22 } from "@web-ts-toolkit/utils";
|
|
6328
6607
|
function assertOwningOutputDocuments(handle) {
|
|
6329
6608
|
const owner = readOutputDocumentOwner(handle);
|
|
@@ -6552,7 +6831,7 @@ function helperPlan(authorization, binding) {
|
|
|
6552
6831
|
return planAuthorizedModelProjection({ authorization, binding, effectiveSelect: [] });
|
|
6553
6832
|
}
|
|
6554
6833
|
function primitiveHelperFields(source, plan) {
|
|
6555
|
-
if (
|
|
6834
|
+
if (types6.isProxy(source)) return;
|
|
6556
6835
|
const canonical = readStaticOutputPlanFields(plan, plan.authorization);
|
|
6557
6836
|
if (!canonical) return;
|
|
6558
6837
|
const fields = [];
|
|
@@ -7373,7 +7652,7 @@ init_sort_policy();
|
|
|
7373
7652
|
init_concurrency();
|
|
7374
7653
|
import {
|
|
7375
7654
|
castArray as castArray2,
|
|
7376
|
-
cloneDeep as
|
|
7655
|
+
cloneDeep as cloneDeep3,
|
|
7377
7656
|
compact,
|
|
7378
7657
|
flatten,
|
|
7379
7658
|
forEach as forEach3,
|
|
@@ -7944,14 +8223,111 @@ function isCorrelatedInclude(value) {
|
|
|
7944
8223
|
// src/services/base.ts
|
|
7945
8224
|
init_request_complexity();
|
|
7946
8225
|
|
|
8226
|
+
// src/model.ts
|
|
8227
|
+
init_runtime_context();
|
|
8228
|
+
init_runtime();
|
|
8229
|
+
import { AsyncLocalStorage as AsyncLocalStorage3 } from "async_hooks";
|
|
8230
|
+
import { cloneDeep as cloneDeep2 } from "@web-ts-toolkit/utils";
|
|
8231
|
+
var capturedModelConstruction = new AsyncLocalStorage3();
|
|
8232
|
+
function withCapturedPopulateModel(runtime, modelName, model, construct) {
|
|
8233
|
+
return capturedModelConstruction.run({ runtime, modelName, model }, construct);
|
|
8234
|
+
}
|
|
8235
|
+
function admitModelPersistence(adapter, scheduler) {
|
|
8236
|
+
return {
|
|
8237
|
+
modelName: adapter.modelName,
|
|
8238
|
+
mongooseModel: adapter.mongooseModel,
|
|
8239
|
+
new: () => adapter.new(),
|
|
8240
|
+
// Mongoose create(array) otherwise starts all document saves at once. Keep
|
|
8241
|
+
// the adapter's array input/output contract, with one permit per item; all
|
|
8242
|
+
// items are submitted even if one rejects, as with unordered create(array).
|
|
8243
|
+
create: (data) => Array.isArray(data) ? Promise.all(data.map((item) => scheduler.work(async () => (await adapter.create([item]))[0]))) : scheduler.work(() => adapter.create(data)),
|
|
8244
|
+
find: (props) => scheduler.work(() => adapter.find(props)),
|
|
8245
|
+
findOne: (props) => scheduler.work(() => adapter.findOne(props)),
|
|
8246
|
+
exists: (filter2) => scheduler.work(() => adapter.exists(filter2)),
|
|
8247
|
+
countDocuments: (filter2) => scheduler.work(() => adapter.countDocuments(filter2)),
|
|
8248
|
+
distinct: (field, conditions) => scheduler.work(() => adapter.distinct(field, conditions)),
|
|
8249
|
+
aggregate: (pipeline) => scheduler.work(() => adapter.aggregate(pipeline)),
|
|
8250
|
+
// Casting builds no persistence work and must not acquire a recursive permit.
|
|
8251
|
+
...adapter.castFilter ? { castFilter: (filter2) => adapter.castFilter(filter2) } : {}
|
|
8252
|
+
};
|
|
8253
|
+
}
|
|
8254
|
+
var Model = class {
|
|
8255
|
+
constructor(modelName, runtime) {
|
|
8256
|
+
this.modelName = modelName;
|
|
8257
|
+
this.runtime = runtime ?? null;
|
|
8258
|
+
const resolvedRuntime = runtime ?? getActiveRuntime() ?? defaultRuntime;
|
|
8259
|
+
const captured = capturedModelConstruction.getStore();
|
|
8260
|
+
const registered = captured?.runtime === resolvedRuntime && captured.modelName === modelName ? captured.model : resolvedRuntime.getModelInstance(modelName);
|
|
8261
|
+
if (!registered) {
|
|
8262
|
+
throw new Error(
|
|
8263
|
+
`Runtime model registry missing model "${modelName}". Pass a mongoose.Model instance to createRouter() or register it with registerModelInstance() before using this runtime.`
|
|
8264
|
+
);
|
|
8265
|
+
}
|
|
8266
|
+
this.mongooseModel = registered;
|
|
8267
|
+
if (!this.mongooseModel) return;
|
|
8268
|
+
}
|
|
8269
|
+
new() {
|
|
8270
|
+
const doc = new this.mongooseModel();
|
|
8271
|
+
return doc;
|
|
8272
|
+
}
|
|
8273
|
+
create(data) {
|
|
8274
|
+
return this.mongooseModel.create(data);
|
|
8275
|
+
}
|
|
8276
|
+
find({ filter: filter2, select, sort, populate, limit, hardLimit, skip, lean }) {
|
|
8277
|
+
const builder = this.mongooseModel.find(filter2);
|
|
8278
|
+
if (select) builder.select(select);
|
|
8279
|
+
if (skip) builder.skip(Number(skip));
|
|
8280
|
+
const normalizedLimit = Number(limit);
|
|
8281
|
+
if (Number.isSafeInteger(normalizedLimit) && normalizedLimit > 0) {
|
|
8282
|
+
builder.limit(normalizedLimit);
|
|
8283
|
+
} else if (Number.isSafeInteger(hardLimit) && Number(hardLimit) > 0) {
|
|
8284
|
+
builder.limit(Number(hardLimit));
|
|
8285
|
+
}
|
|
8286
|
+
if (sort) builder.sort(sort);
|
|
8287
|
+
if (populate) builder.populate(populate);
|
|
8288
|
+
if (lean) builder.lean();
|
|
8289
|
+
return builder;
|
|
8290
|
+
}
|
|
8291
|
+
findOne({ filter: filter2, select, sort, populate, lean }) {
|
|
8292
|
+
const builder = this.mongooseModel.findOne(filter2);
|
|
8293
|
+
if (select) builder.select(select);
|
|
8294
|
+
if (sort) builder.sort(sort);
|
|
8295
|
+
if (populate) builder.populate(populate);
|
|
8296
|
+
if (lean) builder.lean();
|
|
8297
|
+
return builder;
|
|
8298
|
+
}
|
|
8299
|
+
exists(filter2) {
|
|
8300
|
+
if (!filter2) return null;
|
|
8301
|
+
return this.findOne({ filter: filter2 }).select("_id").lean();
|
|
8302
|
+
}
|
|
8303
|
+
// see https://mongoosejs.com/docs/api.html#query_Query-countDocuments
|
|
8304
|
+
countDocuments(filter2 = {}) {
|
|
8305
|
+
return this.mongooseModel.countDocuments(filter2);
|
|
8306
|
+
}
|
|
8307
|
+
/** Cast a copy using this model's query schema/setters, without executing query middleware or persistence. */
|
|
8308
|
+
castFilter(filter2) {
|
|
8309
|
+
const query = this.mongooseModel.countDocuments(cloneDeep2(filter2));
|
|
8310
|
+
return query.cast(this.mongooseModel);
|
|
8311
|
+
}
|
|
8312
|
+
// see https://mongoosejs.com/docs/api.html#model_Model.distinct
|
|
8313
|
+
distinct(field, conditions = {}) {
|
|
8314
|
+
return this.mongooseModel.distinct(field, conditions);
|
|
8315
|
+
}
|
|
8316
|
+
aggregate(pipeline) {
|
|
8317
|
+
return this.mongooseModel.aggregate(pipeline);
|
|
8318
|
+
}
|
|
8319
|
+
};
|
|
8320
|
+
var model_default = Model;
|
|
8321
|
+
|
|
7947
8322
|
// src/acl/model-service-owner.ts
|
|
7948
8323
|
init_runtime();
|
|
7949
8324
|
init_runtime_context();
|
|
7950
|
-
|
|
8325
|
+
init_populate_policy2();
|
|
8326
|
+
import { AsyncLocalStorage as AsyncLocalStorage4 } from "async_hooks";
|
|
7951
8327
|
var cores = /* @__PURE__ */ new WeakMap();
|
|
7952
|
-
var construction = new
|
|
7953
|
-
var dispatch = new
|
|
7954
|
-
var operationGuard = new
|
|
8328
|
+
var construction = new AsyncLocalStorage4();
|
|
8329
|
+
var dispatch = new AsyncLocalStorage4();
|
|
8330
|
+
var operationGuard = new AsyncLocalStorage4();
|
|
7955
8331
|
function withCapturedModelOperationGuard(core, modelName, access, guard2, permissions, run) {
|
|
7956
8332
|
return operationGuard.run({ captured: { core, modelName, access, guard: guard2, permissions } }, run);
|
|
7957
8333
|
}
|
|
@@ -8000,15 +8376,16 @@ function bindModelOwnerMethods(receiver, runtime) {
|
|
|
8000
8376
|
}
|
|
8001
8377
|
}
|
|
8002
8378
|
}
|
|
8003
|
-
function modelServiceOptions(receiver, read) {
|
|
8379
|
+
function modelServiceOptions(receiver, runtime, read) {
|
|
8380
|
+
modelServicePopulatePolicyDefaults(receiver, runtime);
|
|
8004
8381
|
const call = dispatch.getStore();
|
|
8005
8382
|
if (call?.receiver !== receiver) return read();
|
|
8006
8383
|
return call.options ??= read();
|
|
8007
8384
|
}
|
|
8008
|
-
function
|
|
8385
|
+
function modelServicePopulatePolicyDefaults(receiver, runtime) {
|
|
8009
8386
|
const call = dispatch.getStore();
|
|
8010
|
-
if (call?.receiver !== receiver) return runtime
|
|
8011
|
-
return call.
|
|
8387
|
+
if (call?.receiver !== receiver) return capturePopulatePolicyDefaults(runtime);
|
|
8388
|
+
return call.populatePolicyDefaults ??= capturePopulatePolicyDefaults(runtime);
|
|
8012
8389
|
}
|
|
8013
8390
|
|
|
8014
8391
|
// src/services/base.ts
|
|
@@ -8162,27 +8539,6 @@ function castCountGroups(input, values) {
|
|
|
8162
8539
|
// src/services/base.ts
|
|
8163
8540
|
init_service_authorization();
|
|
8164
8541
|
|
|
8165
|
-
// src/meta.ts
|
|
8166
|
-
init_runtime();
|
|
8167
|
-
init_runtime_context();
|
|
8168
|
-
var getRuntime5 = () => getActiveRuntime() ?? defaultRuntime;
|
|
8169
|
-
var getModelRef = (modelName, refPath, runtime = getRuntime5()) => {
|
|
8170
|
-
const direct = runtime.getModelRef(modelName, refPath);
|
|
8171
|
-
if (direct) return direct;
|
|
8172
|
-
if (!refPath.includes(".")) return null;
|
|
8173
|
-
try {
|
|
8174
|
-
const instance = runtime.getModelInstance?.(
|
|
8175
|
-
modelName
|
|
8176
|
-
);
|
|
8177
|
-
const schemaPath = instance?.schema?.path?.(refPath);
|
|
8178
|
-
const element = schemaPath?.$embeddedSchemaType ?? schemaPath?.embeddedSchemaType ?? schemaPath?.caster;
|
|
8179
|
-
const ref = schemaPath?.options?.ref ?? element?.options?.ref ?? null;
|
|
8180
|
-
return typeof ref === "string" && ref.length > 0 ? ref : null;
|
|
8181
|
-
} catch {
|
|
8182
|
-
return null;
|
|
8183
|
-
}
|
|
8184
|
-
};
|
|
8185
|
-
|
|
8186
8542
|
// src/acl/related-execution.ts
|
|
8187
8543
|
init_public_admission();
|
|
8188
8544
|
init_model_output_planning();
|
|
@@ -8430,9 +8786,9 @@ function resolveExistsOptions(service, options = {}) {
|
|
|
8430
8786
|
|
|
8431
8787
|
// src/services/model-service-intent.ts
|
|
8432
8788
|
function captureModelServiceIntent(owner, method, args = {}, options = {}) {
|
|
8433
|
-
const
|
|
8789
|
+
const defaults2 = owner.defaults;
|
|
8434
8790
|
const posture = owner.getPermissionsPosture();
|
|
8435
|
-
const service = { defaults, getPermissionsPosture: () => posture };
|
|
8791
|
+
const service = { defaults: defaults2, getPermissionsPosture: () => posture };
|
|
8436
8792
|
switch (method) {
|
|
8437
8793
|
case "find":
|
|
8438
8794
|
return deepIsolateValue({ args: resolveFindArgs(service, args), options: resolveFindOptions(service, options) });
|
|
@@ -8463,6 +8819,7 @@ function captureModelServiceIntent(owner, method, args = {}, options = {}) {
|
|
|
8463
8819
|
}
|
|
8464
8820
|
|
|
8465
8821
|
// src/acl/related-execution.ts
|
|
8822
|
+
init_populate_policy2();
|
|
8466
8823
|
init_service_authorization();
|
|
8467
8824
|
function staticObjectIdReference(runtime, source, path, target) {
|
|
8468
8825
|
const model = runtime.getModelInstance(source), related = runtime.getModelInstance(target);
|
|
@@ -8479,7 +8836,7 @@ function staticObjectIdReference(runtime, source, path, target) {
|
|
|
8479
8836
|
const scalar = type?.instance === "Array" ? type.$embeddedSchemaType ?? type.embeddedSchemaType ?? type.caster : type;
|
|
8480
8837
|
return scalar?.instance === "ObjectId" && (type?.options?.ref ?? scalar.options?.ref) === target && type?.options?.refPath === void 0 && scalar.options?.refPath === void 0;
|
|
8481
8838
|
}
|
|
8482
|
-
function captureRelatedTargets(runtime, modelName, args = {}, depth = 0,
|
|
8839
|
+
function captureRelatedTargets(runtime, modelName, args = {}, depth = 0, populatePolicyDefaults = capturePopulatePolicyDefaults(runtime)) {
|
|
8483
8840
|
if (depth > 32) authorizationError("related descriptor depth exceeded");
|
|
8484
8841
|
assertPublicAdmission(args.populate, "populate");
|
|
8485
8842
|
assertPublicAdmission(args.include, "include");
|
|
@@ -8488,20 +8845,32 @@ function captureRelatedTargets(runtime, modelName, args = {}, depth = 0, globalO
|
|
|
8488
8845
|
for (const entry of entries(args.populate)) {
|
|
8489
8846
|
const path = typeof entry === "string" ? entry : entry.path;
|
|
8490
8847
|
if (typeof entry !== "string") assertPopulateAccess(entry.access);
|
|
8491
|
-
const
|
|
8492
|
-
if (
|
|
8493
|
-
const target = capturePopulateTargetConfiguration(runtime, model, `${modelName}.${path}`);
|
|
8848
|
+
const target = capturePopulateTargetBinding(runtime, modelName, path);
|
|
8849
|
+
if (target) {
|
|
8494
8850
|
targets.push({
|
|
8495
8851
|
path,
|
|
8496
|
-
modelName:
|
|
8497
|
-
|
|
8498
|
-
|
|
8852
|
+
modelName: target.modelName,
|
|
8853
|
+
model: target.model,
|
|
8854
|
+
configuration: captureModelAuthorizationConfiguration(
|
|
8855
|
+
runtime,
|
|
8856
|
+
target.modelName,
|
|
8857
|
+
target.options,
|
|
8858
|
+
populatePolicyDefaults
|
|
8859
|
+
),
|
|
8860
|
+
staticObjectIdReference: staticObjectIdReference(runtime, modelName, path, target.modelName)
|
|
8499
8861
|
});
|
|
8500
8862
|
}
|
|
8501
8863
|
}
|
|
8502
8864
|
for (const entry of entries(args.include)) {
|
|
8503
8865
|
if (!runtime.hasModel(entry.model)) authorizationError(`Model ${entry.model} not found`);
|
|
8504
|
-
const
|
|
8866
|
+
const model = runtime.getModelInstance(entry.model);
|
|
8867
|
+
if (!model) authorizationError(`unknown receiving model: ${entry.model}`);
|
|
8868
|
+
const configuration = captureModelAuthorizationConfiguration(
|
|
8869
|
+
runtime,
|
|
8870
|
+
entry.model,
|
|
8871
|
+
void 0,
|
|
8872
|
+
populatePolicyDefaults
|
|
8873
|
+
);
|
|
8505
8874
|
const queryIntent = entry.op === "count" ? void 0 : captureModelServiceIntent(
|
|
8506
8875
|
{
|
|
8507
8876
|
defaults: configuration.defaults ?? {},
|
|
@@ -8523,6 +8892,7 @@ function captureRelatedTargets(runtime, modelName, args = {}, depth = 0, globalO
|
|
|
8523
8892
|
targets.push({
|
|
8524
8893
|
path: entry.path,
|
|
8525
8894
|
modelName: entry.model,
|
|
8895
|
+
model,
|
|
8526
8896
|
kind: entry.op === "count" ? "count" : "output",
|
|
8527
8897
|
configuration,
|
|
8528
8898
|
queryIntent,
|
|
@@ -8532,7 +8902,7 @@ function captureRelatedTargets(runtime, modelName, args = {}, depth = 0, globalO
|
|
|
8532
8902
|
entry.model,
|
|
8533
8903
|
queryIntent?.args ?? entry.args ?? {},
|
|
8534
8904
|
depth + 1,
|
|
8535
|
-
|
|
8905
|
+
populatePolicyDefaults
|
|
8536
8906
|
)
|
|
8537
8907
|
});
|
|
8538
8908
|
}
|
|
@@ -8549,7 +8919,8 @@ function createRelatedExecution(receiver, access, parent, binding, path) {
|
|
|
8549
8919
|
const captured = readServiceAuthorization(parent, binding);
|
|
8550
8920
|
const target = captured.relatedTargets.find((entry) => entry.path === path);
|
|
8551
8921
|
const policy = captured.authorization.related[path];
|
|
8552
|
-
|
|
8922
|
+
const receiving = getServiceExecutors(receiver).binding();
|
|
8923
|
+
if (policy && !target || target && (target.modelName !== receiving.modelName || target.model !== void 0 && target.model !== receiving.model))
|
|
8553
8924
|
authorizationError(`related model mismatch: ${path}`);
|
|
8554
8925
|
const execution = createServiceExecution(
|
|
8555
8926
|
receiver,
|
|
@@ -9047,34 +9418,37 @@ var Base = class {
|
|
|
9047
9418
|
});
|
|
9048
9419
|
}
|
|
9049
9420
|
async getAuthorizedTargetService(modelName, op, path, parentAuthorization) {
|
|
9050
|
-
|
|
9421
|
+
const binding = parentAuthorization ? this.relatedBinding() : void 0;
|
|
9422
|
+
const captured = parentAuthorization ? readServiceAuthorization(parentAuthorization, binding) : void 0;
|
|
9423
|
+
const target = captured?.relatedTargets.find((entry) => entry.path === path);
|
|
9424
|
+
const policy = path ? captured?.authorization.related[path] : void 0;
|
|
9425
|
+
if (target && target.modelName !== modelName)
|
|
9426
|
+
this.throwClientRequestError("bad_request" /* BadRequest */, `related model mismatch: ${path}`);
|
|
9427
|
+
if (hasModelCoreOwner(this.requestCore) && !target?.model && !this.requestRuntime.hasModel(modelName)) {
|
|
9051
9428
|
this.throwClientRequestError("bad_request" /* BadRequest */, `Model ${modelName} not found`);
|
|
9052
9429
|
}
|
|
9053
|
-
const policy = path ? relatedPolicy(parentAuthorization, this.relatedBinding(), path) : void 0;
|
|
9054
|
-
const captured = parentAuthorization ? readServiceAuthorization(parentAuthorization, this.relatedBinding()) : void 0;
|
|
9055
|
-
const target = captured?.relatedTargets.find((entry) => entry.path === path);
|
|
9056
9430
|
const allowed = policy?.operation.mode === "grant" || (target ? await getRequestWorkState(this.req, this.requestRuntime).hookGate.run(
|
|
9057
9431
|
() => withCapturedModelOperationGuard(
|
|
9058
9432
|
this.requestCore,
|
|
9059
9433
|
modelName,
|
|
9060
9434
|
op,
|
|
9061
9435
|
target.operationGuard,
|
|
9062
|
-
getAuthorizationPermissions(parentAuthorization,
|
|
9436
|
+
getAuthorizationPermissions(parentAuthorization, binding),
|
|
9063
9437
|
() => this.requestCore.isAllowed(modelName, op)
|
|
9064
9438
|
)
|
|
9065
9439
|
) : await this.requestCore.isAllowed(modelName, op));
|
|
9066
9440
|
if (!allowed) {
|
|
9067
9441
|
this.throwClientRequestError("unauthorized" /* Unauthorized */, "Unauthorized");
|
|
9068
9442
|
}
|
|
9069
|
-
return
|
|
9443
|
+
return target?.model ? withCapturedPopulateModel(
|
|
9444
|
+
this.requestRuntime,
|
|
9445
|
+
modelName,
|
|
9446
|
+
target.model,
|
|
9447
|
+
() => this.requestCore.getPublicService(modelName)
|
|
9448
|
+
) : this.requestCore.getPublicService(modelName);
|
|
9070
9449
|
}
|
|
9071
9450
|
relatedBinding() {
|
|
9072
|
-
return
|
|
9073
|
-
request: this.req,
|
|
9074
|
-
runtime: this.requestRuntime,
|
|
9075
|
-
model: this.requestRuntime.getModelInstance(this.modelName),
|
|
9076
|
-
modelName: this.modelName
|
|
9077
|
-
};
|
|
9451
|
+
return getServiceExecutors(this).binding();
|
|
9078
9452
|
}
|
|
9079
9453
|
relatedExecution(svc, include, parentAuthorization) {
|
|
9080
9454
|
const op = include.op;
|
|
@@ -9484,7 +9858,7 @@ var Base = class {
|
|
|
9484
9858
|
}
|
|
9485
9859
|
const state = this.getCorrelatedExecState();
|
|
9486
9860
|
docs = docs.map(prepareIncludeOutput);
|
|
9487
|
-
const resolvedSnapshots = snapshots2 ?? docs.map((doc) =>
|
|
9861
|
+
const resolvedSnapshots = snapshots2 ?? docs.map((doc) => cloneDeep3(toObject(getIncludeSource(doc))));
|
|
9488
9862
|
for (const include of correlatedIncludes) {
|
|
9489
9863
|
switch (include.op) {
|
|
9490
9864
|
case "read":
|
|
@@ -9863,96 +10237,6 @@ import {
|
|
|
9863
10237
|
} from "@web-ts-toolkit/utils";
|
|
9864
10238
|
import { diff } from "just-diff";
|
|
9865
10239
|
|
|
9866
|
-
// src/model.ts
|
|
9867
|
-
init_runtime_context();
|
|
9868
|
-
init_runtime();
|
|
9869
|
-
import { cloneDeep as cloneDeep3 } from "@web-ts-toolkit/utils";
|
|
9870
|
-
function admitModelPersistence(adapter, scheduler) {
|
|
9871
|
-
return {
|
|
9872
|
-
modelName: adapter.modelName,
|
|
9873
|
-
mongooseModel: adapter.mongooseModel,
|
|
9874
|
-
new: () => adapter.new(),
|
|
9875
|
-
// Mongoose create(array) otherwise starts all document saves at once. Keep
|
|
9876
|
-
// the adapter's array input/output contract, with one permit per item; all
|
|
9877
|
-
// items are submitted even if one rejects, as with unordered create(array).
|
|
9878
|
-
create: (data) => Array.isArray(data) ? Promise.all(data.map((item) => scheduler.work(async () => (await adapter.create([item]))[0]))) : scheduler.work(() => adapter.create(data)),
|
|
9879
|
-
find: (props) => scheduler.work(() => adapter.find(props)),
|
|
9880
|
-
findOne: (props) => scheduler.work(() => adapter.findOne(props)),
|
|
9881
|
-
exists: (filter2) => scheduler.work(() => adapter.exists(filter2)),
|
|
9882
|
-
countDocuments: (filter2) => scheduler.work(() => adapter.countDocuments(filter2)),
|
|
9883
|
-
distinct: (field, conditions) => scheduler.work(() => adapter.distinct(field, conditions)),
|
|
9884
|
-
aggregate: (pipeline) => scheduler.work(() => adapter.aggregate(pipeline)),
|
|
9885
|
-
// Casting builds no persistence work and must not acquire a recursive permit.
|
|
9886
|
-
...adapter.castFilter ? { castFilter: (filter2) => adapter.castFilter(filter2) } : {}
|
|
9887
|
-
};
|
|
9888
|
-
}
|
|
9889
|
-
var Model = class {
|
|
9890
|
-
constructor(modelName, runtime) {
|
|
9891
|
-
this.modelName = modelName;
|
|
9892
|
-
this.runtime = runtime ?? null;
|
|
9893
|
-
const resolvedRuntime = runtime ?? getActiveRuntime() ?? defaultRuntime;
|
|
9894
|
-
const registered = resolvedRuntime.getModelInstance(modelName);
|
|
9895
|
-
if (!registered) {
|
|
9896
|
-
throw new Error(
|
|
9897
|
-
`Runtime model registry missing model "${modelName}". Pass a mongoose.Model instance to createRouter() or register it with registerModelInstance() before using this runtime.`
|
|
9898
|
-
);
|
|
9899
|
-
}
|
|
9900
|
-
this.mongooseModel = registered;
|
|
9901
|
-
if (!this.mongooseModel) return;
|
|
9902
|
-
}
|
|
9903
|
-
new() {
|
|
9904
|
-
const doc = new this.mongooseModel();
|
|
9905
|
-
return doc;
|
|
9906
|
-
}
|
|
9907
|
-
create(data) {
|
|
9908
|
-
return this.mongooseModel.create(data);
|
|
9909
|
-
}
|
|
9910
|
-
find({ filter: filter2, select, sort, populate, limit, hardLimit, skip, lean }) {
|
|
9911
|
-
const builder = this.mongooseModel.find(filter2);
|
|
9912
|
-
if (select) builder.select(select);
|
|
9913
|
-
if (skip) builder.skip(Number(skip));
|
|
9914
|
-
const normalizedLimit = Number(limit);
|
|
9915
|
-
if (Number.isSafeInteger(normalizedLimit) && normalizedLimit > 0) {
|
|
9916
|
-
builder.limit(normalizedLimit);
|
|
9917
|
-
} else if (Number.isSafeInteger(hardLimit) && Number(hardLimit) > 0) {
|
|
9918
|
-
builder.limit(Number(hardLimit));
|
|
9919
|
-
}
|
|
9920
|
-
if (sort) builder.sort(sort);
|
|
9921
|
-
if (populate) builder.populate(populate);
|
|
9922
|
-
if (lean) builder.lean();
|
|
9923
|
-
return builder;
|
|
9924
|
-
}
|
|
9925
|
-
findOne({ filter: filter2, select, sort, populate, lean }) {
|
|
9926
|
-
const builder = this.mongooseModel.findOne(filter2);
|
|
9927
|
-
if (select) builder.select(select);
|
|
9928
|
-
if (sort) builder.sort(sort);
|
|
9929
|
-
if (populate) builder.populate(populate);
|
|
9930
|
-
if (lean) builder.lean();
|
|
9931
|
-
return builder;
|
|
9932
|
-
}
|
|
9933
|
-
exists(filter2) {
|
|
9934
|
-
if (!filter2) return null;
|
|
9935
|
-
return this.findOne({ filter: filter2 }).select("_id").lean();
|
|
9936
|
-
}
|
|
9937
|
-
// see https://mongoosejs.com/docs/api.html#query_Query-countDocuments
|
|
9938
|
-
countDocuments(filter2 = {}) {
|
|
9939
|
-
return this.mongooseModel.countDocuments(filter2);
|
|
9940
|
-
}
|
|
9941
|
-
/** Cast a copy using this model's query schema/setters, without executing query middleware or persistence. */
|
|
9942
|
-
castFilter(filter2) {
|
|
9943
|
-
const query = this.mongooseModel.countDocuments(cloneDeep3(filter2));
|
|
9944
|
-
return query.cast(this.mongooseModel);
|
|
9945
|
-
}
|
|
9946
|
-
// see https://mongoosejs.com/docs/api.html#model_Model.distinct
|
|
9947
|
-
distinct(field, conditions = {}) {
|
|
9948
|
-
return this.mongooseModel.distinct(field, conditions);
|
|
9949
|
-
}
|
|
9950
|
-
aggregate(pipeline) {
|
|
9951
|
-
return this.mongooseModel.aggregate(pipeline);
|
|
9952
|
-
}
|
|
9953
|
-
};
|
|
9954
|
-
var model_default = Model;
|
|
9955
|
-
|
|
9956
10240
|
// src/acl/distinct-field-authorization.ts
|
|
9957
10241
|
init_field_authorization();
|
|
9958
10242
|
init_field_catalog();
|
|
@@ -10090,6 +10374,7 @@ init_finalize_model_output();
|
|
|
10090
10374
|
init_populate_target();
|
|
10091
10375
|
init_virtual_populate_execution();
|
|
10092
10376
|
init_request_work();
|
|
10377
|
+
init_populate_policy2();
|
|
10093
10378
|
var populateExecutors = /* @__PURE__ */ new WeakMap();
|
|
10094
10379
|
function registerSubdocumentPopulateExecutor(service, execute2, core) {
|
|
10095
10380
|
populateExecutors.set(service, { execute: execute2, core });
|
|
@@ -10122,7 +10407,7 @@ function prepareSubdocumentOutput(service, sub, operation, virtualAccess, output
|
|
|
10122
10407
|
service.getServiceModelName(),
|
|
10123
10408
|
{ populate },
|
|
10124
10409
|
0,
|
|
10125
|
-
configuration
|
|
10410
|
+
getCapturedPopulatePolicyDefaults(configuration)
|
|
10126
10411
|
),
|
|
10127
10412
|
void 0,
|
|
10128
10413
|
configuration,
|
|
@@ -11161,12 +11446,15 @@ var Service = class extends Base {
|
|
|
11161
11446
|
model: this.model.mongooseModel,
|
|
11162
11447
|
modelName: this.modelName
|
|
11163
11448
|
}),
|
|
11164
|
-
configuration: () =>
|
|
11165
|
-
this.requestRuntime
|
|
11166
|
-
this.modelName
|
|
11167
|
-
|
|
11168
|
-
|
|
11169
|
-
|
|
11449
|
+
configuration: () => {
|
|
11450
|
+
const populatePolicyDefaults = modelServicePopulatePolicyDefaults(this, this.requestRuntime);
|
|
11451
|
+
return this.requestRuntime.getModelInstance(this.modelName) ? captureModelAuthorizationConfiguration(
|
|
11452
|
+
this.requestRuntime,
|
|
11453
|
+
this.modelName,
|
|
11454
|
+
{ ...this.options, defaults: this.defaults },
|
|
11455
|
+
populatePolicyDefaults
|
|
11456
|
+
) : { catalog: { paths: [] }, ...this.options, populatePolicyDefaults };
|
|
11457
|
+
},
|
|
11170
11458
|
permissions: () => this.requestCore.getPermissions?.() ?? new permission_default({}),
|
|
11171
11459
|
parse: (filter2) => this.parseClientData(filter2, this.getCorrelatedExecState().scheduler),
|
|
11172
11460
|
validate: (filter2, expanded) => {
|
|
@@ -11215,7 +11503,7 @@ var Service = class extends Base {
|
|
|
11215
11503
|
});
|
|
11216
11504
|
}
|
|
11217
11505
|
get options() {
|
|
11218
|
-
return modelServiceOptions(this, () => this.getModelRouterOptions(this.modelName));
|
|
11506
|
+
return modelServiceOptions(this, this.requestRuntime, () => this.getModelRouterOptions(this.modelName));
|
|
11219
11507
|
}
|
|
11220
11508
|
/**
|
|
11221
11509
|
* Presentation/query defaults for this service instance; an explicit assignment
|
|
@@ -11700,14 +11988,14 @@ var Service = class extends Base {
|
|
|
11700
11988
|
}
|
|
11701
11989
|
});
|
|
11702
11990
|
}
|
|
11703
|
-
captureRelated(args,
|
|
11704
|
-
const
|
|
11705
|
-
const effective = { populate: args?.populate ??
|
|
11991
|
+
captureRelated(args, defaults2) {
|
|
11992
|
+
const populatePolicyDefaults = modelServicePopulatePolicyDefaults(this, this.requestRuntime);
|
|
11993
|
+
const effective = { populate: args?.populate ?? defaults2?.populate, include: args?.include ?? defaults2?.include };
|
|
11706
11994
|
if (effective.include) {
|
|
11707
11995
|
const processed = this.processInclude(effective.include);
|
|
11708
11996
|
effective.include = [...processed.includes, ...processed.correlatedIncludes];
|
|
11709
11997
|
}
|
|
11710
|
-
return captureRelatedTargets(this.requestRuntime, this.modelName, effective, 0,
|
|
11998
|
+
return captureRelatedTargets(this.requestRuntime, this.modelName, effective, 0, populatePolicyDefaults);
|
|
11711
11999
|
}
|
|
11712
12000
|
/** Canonical population uses the target's retained policy for both fetch and output. */
|
|
11713
12001
|
async genExecutionPopulate(execution, access, populate) {
|
|
@@ -11733,7 +12021,12 @@ var Service = class extends Base {
|
|
|
11733
12021
|
const modelName = target?.modelName;
|
|
11734
12022
|
if (!modelName) continue;
|
|
11735
12023
|
const policy = relatedPolicy(state.authorization, state.binding, descriptor.path);
|
|
11736
|
-
const svc =
|
|
12024
|
+
const svc = withCapturedPopulateModel(
|
|
12025
|
+
this.requestRuntime,
|
|
12026
|
+
modelName,
|
|
12027
|
+
target.model,
|
|
12028
|
+
() => this.requestCore.getPublicService(modelName)
|
|
12029
|
+
);
|
|
11737
12030
|
const child = createRelatedExecution(
|
|
11738
12031
|
svc,
|
|
11739
12032
|
{
|
|
@@ -11778,8 +12071,8 @@ var Service = class extends Base {
|
|
|
11778
12071
|
snapshot: readServiceAuthorization(childState.authorization, childState.binding).configuration,
|
|
11779
12072
|
fetchBinding: {
|
|
11780
12073
|
runtime: this.requestRuntime,
|
|
11781
|
-
model:
|
|
11782
|
-
schema:
|
|
12074
|
+
model: target.model,
|
|
12075
|
+
schema: target.model.schema,
|
|
11783
12076
|
configuration: targetConfiguration,
|
|
11784
12077
|
requestRead: targetAccess === "read" && policy?.operation.mode !== "grant" && readServiceAuthorization(childState.authorization, childState.binding).authorization.rows.mode === "request",
|
|
11785
12078
|
staticObjectIdReference: captured.relatedTargets.find((target2) => target2.path === descriptor.path)?.staticObjectIdReference
|
|
@@ -14636,9 +14929,20 @@ var Core = class {
|
|
|
14636
14929
|
if (!isString6(p)) assertPopulateAccess(p.access);
|
|
14637
14930
|
}
|
|
14638
14931
|
const runtime = this.requestRuntime;
|
|
14639
|
-
const
|
|
14640
|
-
const relatedTargets = captureRelatedTargets(
|
|
14641
|
-
|
|
14932
|
+
const populatePolicyDefaults = modelServicePopulatePolicyDefaults(this, runtime);
|
|
14933
|
+
const relatedTargets = captureRelatedTargets(
|
|
14934
|
+
runtime,
|
|
14935
|
+
modelName,
|
|
14936
|
+
{ populate: descriptors },
|
|
14937
|
+
0,
|
|
14938
|
+
populatePolicyDefaults
|
|
14939
|
+
);
|
|
14940
|
+
const sourceConfiguration = captureModelAuthorizationConfiguration(
|
|
14941
|
+
runtime,
|
|
14942
|
+
modelName,
|
|
14943
|
+
void 0,
|
|
14944
|
+
populatePolicyDefaults
|
|
14945
|
+
);
|
|
14642
14946
|
const originalPermissions = this.getGlobalPermissions();
|
|
14643
14947
|
const permissions = new permission_default(
|
|
14644
14948
|
Object.fromEntries(originalPermissions.keys.map((key) => [key, originalPermissions.has(key)]))
|
|
@@ -14735,7 +15039,15 @@ var Core = class {
|
|
|
14735
15039
|
docPermissionsAccess: planAccess,
|
|
14736
15040
|
requestedSelect: originalSelect,
|
|
14737
15041
|
plan: targetPlan,
|
|
14738
|
-
snapshot: targetSnapshot
|
|
15042
|
+
snapshot: targetSnapshot,
|
|
15043
|
+
fetchBinding: {
|
|
15044
|
+
runtime,
|
|
15045
|
+
model: target.model,
|
|
15046
|
+
schema: target.model.schema,
|
|
15047
|
+
configuration: targetConfiguration,
|
|
15048
|
+
requestRead: populateAccess === "read",
|
|
15049
|
+
staticObjectIdReference: target.staticObjectIdReference
|
|
15050
|
+
}
|
|
14739
15051
|
});
|
|
14740
15052
|
return ret;
|
|
14741
15053
|
})
|