@web-ts-toolkit/access-router 0.65.0 → 0.66.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/MIGRATION.md +777 -0
- package/README.md +229 -550
- package/advanced.d.mts +2 -1
- package/advanced.d.ts +2 -1
- package/advanced.js +1322 -497
- package/advanced.mjs +1210 -385
- package/index.d.mts +14 -5
- package/index.d.ts +14 -5
- package/index.js +11482 -11188
- package/index.mjs +11206 -10914
- package/llms.txt +6 -3
- package/package.json +3 -3
- package/{parsers-h_oU4bB0.d.mts → parsers-BiFHfrNd.d.mts} +2608 -2929
- package/{parsers-h_oU4bB0.d.ts → parsers-BiFHfrNd.d.ts} +2608 -2929
- package/processors.js +13 -1
- package/processors.mjs +13 -1
package/advanced.mjs
CHANGED
|
@@ -47,53 +47,988 @@ import JsonRouter3 from "@web-ts-toolkit/express-json-router";
|
|
|
47
47
|
import mongoose from "mongoose";
|
|
48
48
|
|
|
49
49
|
// src/validation/public-admission.ts
|
|
50
|
-
import
|
|
50
|
+
import JsonRouter2 from "@web-ts-toolkit/express-json-router";
|
|
51
|
+
import { types as types6 } from "util";
|
|
51
52
|
import { isPlainObject } from "@web-ts-toolkit/utils";
|
|
52
53
|
|
|
53
|
-
// src/acl/
|
|
54
|
-
|
|
54
|
+
// src/acl/output-work-ledger.ts
|
|
55
|
+
import { AsyncLocalStorage } from "async_hooks";
|
|
56
|
+
|
|
57
|
+
// src/acl/authorization-snapshot.ts
|
|
58
|
+
import { types as types4 } from "util";
|
|
59
|
+
import { mongo as mongo2 } from "mongoose";
|
|
60
|
+
import JsonRouter from "@web-ts-toolkit/express-json-router";
|
|
61
|
+
|
|
62
|
+
// src/acl/field-catalog.ts
|
|
63
|
+
import { types } from "util";
|
|
64
|
+
var ownedCatalogs = /* @__PURE__ */ new WeakMap();
|
|
65
|
+
function readOwnedAuthorizationCatalogWork(value) {
|
|
66
|
+
return ownedCatalogs.get(value);
|
|
67
|
+
}
|
|
68
|
+
var safeSegment = (part) => !!part && part !== "sub" && !["__proto__", "constructor", "prototype", "_doc", "__v"].includes(part) && !/^[+$-]|[\s*]/.test(part) && !part.includes("[") && !part.includes("]") && !/^\d+$/.test(part) && !hasControlCharacter(part);
|
|
69
|
+
function hasControlCharacter(part) {
|
|
70
|
+
for (let index = 0; index < part.length; index++) {
|
|
71
|
+
const code = part.charCodeAt(index);
|
|
72
|
+
if (code < 32 || code === 127) return true;
|
|
73
|
+
}
|
|
74
|
+
return false;
|
|
75
|
+
}
|
|
76
|
+
function prepareCatalogPathParts(path) {
|
|
77
|
+
const ledger = currentOutputWorkLedger();
|
|
78
|
+
if (ledger) {
|
|
79
|
+
let segments = 1;
|
|
80
|
+
for (let index = 0; index < path.length; index++) if (path.charCodeAt(index) === 46) segments++;
|
|
81
|
+
debitOutputWork(ledger, segments);
|
|
82
|
+
debitOutputPayload(ledger, path);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
function catalogPathParts(path) {
|
|
86
|
+
prepareCatalogPathParts(path);
|
|
87
|
+
return path.split(".");
|
|
88
|
+
}
|
|
89
|
+
var isSafeOutputPath = (path) => catalogPathParts(path).every(safeSegment);
|
|
90
|
+
var inputControlSegments = /* @__PURE__ */ new Set([
|
|
91
|
+
"_permissions",
|
|
92
|
+
"_view",
|
|
93
|
+
"_edit",
|
|
94
|
+
"documentAuthorization",
|
|
95
|
+
"documentAuthorizationStage",
|
|
96
|
+
"resolvedAuthorization",
|
|
97
|
+
"execution",
|
|
98
|
+
"executionContext",
|
|
99
|
+
"serviceExecutionContext",
|
|
100
|
+
"preparedQuery",
|
|
101
|
+
"preparedFilter",
|
|
102
|
+
"preparedModelQuery",
|
|
103
|
+
"resolvedIdentifier",
|
|
104
|
+
"skipParsing",
|
|
105
|
+
"skipAuthorization",
|
|
106
|
+
"alreadyAuthorized"
|
|
107
|
+
]);
|
|
108
|
+
function isSafeInputPath(path, requestIdentity = false) {
|
|
109
|
+
return isSafeOutputPath(path) && path.split(".").every((part) => !inputControlSegments.has(part) && (requestIdentity || part !== "_id"));
|
|
110
|
+
}
|
|
111
|
+
function matchesCatalogPattern(pattern, path, descendants = false) {
|
|
112
|
+
debitOutputWork();
|
|
113
|
+
if (typeof pattern === "string" && typeof path === "string" && !pattern.includes("$*")) {
|
|
114
|
+
return pattern === path || !!descendants && path.startsWith(pattern) && path[pattern.length] === ".";
|
|
115
|
+
}
|
|
116
|
+
prepareCatalogPathParts(pattern);
|
|
117
|
+
const expected = pattern.split(".");
|
|
118
|
+
prepareCatalogPathParts(path);
|
|
119
|
+
const actual = path.split(".");
|
|
120
|
+
return (descendants ? actual.length >= expected.length : actual.length === expected.length) && expected.every((part, index) => part === "$*" || part === actual[index]);
|
|
121
|
+
}
|
|
122
|
+
function captureAuthorizationFieldCatalog(schema, virtuals, documentPermissionField = "_permissions") {
|
|
123
|
+
debitOutputPayload(currentOutputWorkLedger(), documentPermissionField);
|
|
124
|
+
const paths = /* @__PURE__ */ new Set();
|
|
125
|
+
const containers = /* @__PURE__ */ new Set();
|
|
126
|
+
const opaque = /* @__PURE__ */ new Set();
|
|
127
|
+
const references = /* @__PURE__ */ new Set();
|
|
128
|
+
const virtualPaths = /* @__PURE__ */ new Set();
|
|
129
|
+
const virtualScopes = /* @__PURE__ */ new Set();
|
|
130
|
+
const schemaVirtualPaths = /* @__PURE__ */ new Set();
|
|
131
|
+
const arrays = /* @__PURE__ */ new Set();
|
|
132
|
+
const protectedPaths = /* @__PURE__ */ new Set([documentPermissionField, "_doc", "$__", "__v"]);
|
|
133
|
+
const add = (path) => {
|
|
134
|
+
debitOutputWork();
|
|
135
|
+
debitOutputPayload(currentOutputWorkLedger(), path);
|
|
136
|
+
if (catalogPathParts(path).every((part) => part === "$*" || safeSegment(part))) paths.add(path);
|
|
137
|
+
};
|
|
138
|
+
const ancestors = (path) => {
|
|
139
|
+
const parts = catalogPathParts(path);
|
|
140
|
+
for (let n = 1; n < parts.length; n++) {
|
|
141
|
+
debitOutputWork(void 0, n);
|
|
142
|
+
const parent = prepareOutputWorkString(parts.slice(0, n));
|
|
143
|
+
add(parent);
|
|
144
|
+
containers.add(parent);
|
|
145
|
+
}
|
|
146
|
+
};
|
|
147
|
+
const visitType = (type, path, active) => {
|
|
148
|
+
debitOutputWork();
|
|
149
|
+
add(path);
|
|
150
|
+
ancestors(path);
|
|
151
|
+
const element = type.$embeddedSchemaType ?? type.embeddedSchemaType ?? type.caster;
|
|
152
|
+
if (type.instance === "Array" || type.$isMongooseDocumentArray) arrays.add(path);
|
|
153
|
+
if (type.options?.ref || type.options?.refPath || element?.options?.ref || element?.options?.refPath) {
|
|
154
|
+
references.add(path);
|
|
155
|
+
return;
|
|
156
|
+
}
|
|
157
|
+
if (type.$isSchemaMap || type.instance === "Map") {
|
|
158
|
+
const value = type.$__schemaType;
|
|
159
|
+
if (value) visitType(value, prepareOutputWorkString([path, "$*"]), active);
|
|
160
|
+
else opaque.add(path);
|
|
161
|
+
containers.delete(path);
|
|
162
|
+
return;
|
|
163
|
+
}
|
|
164
|
+
const child = type.schema ?? element?.schema;
|
|
165
|
+
if (child) {
|
|
166
|
+
containers.add(path);
|
|
167
|
+
if (!active.has(child)) visitSchema(child, path, /* @__PURE__ */ new Set([...active, child]));
|
|
168
|
+
return;
|
|
169
|
+
}
|
|
170
|
+
if (type.instance === "Mixed" || element?.instance === "Mixed") opaque.add(path);
|
|
171
|
+
};
|
|
172
|
+
const visitSchema = (current, prefix, active) => {
|
|
173
|
+
debitOutputWork();
|
|
174
|
+
const version = current.options.versionKey;
|
|
175
|
+
if (typeof version === "string") protectedPaths.add(prefix ? `${prefix}.${version}` : version);
|
|
176
|
+
for (const name of Object.keys(current.virtuals)) {
|
|
177
|
+
debitOutputWork();
|
|
178
|
+
schemaVirtualPaths.add(prefix ? prepareOutputWorkString([prefix, name]) : name);
|
|
179
|
+
}
|
|
180
|
+
for (const [name, raw] of Object.entries(current.paths)) {
|
|
181
|
+
debitOutputWork();
|
|
182
|
+
if (name.includes("$*")) continue;
|
|
183
|
+
visitType(raw, prefix ? prepareOutputWorkString([prefix, name]) : name, active);
|
|
184
|
+
}
|
|
185
|
+
};
|
|
186
|
+
visitSchema(schema, "", /* @__PURE__ */ new Set([schema]));
|
|
187
|
+
const copyPaths = (values) => {
|
|
188
|
+
debitOutputWork(void 0, 1 + (Array.isArray(values) ? values.length : values.size));
|
|
189
|
+
return [...values];
|
|
190
|
+
};
|
|
191
|
+
const persistedPaths = copyPaths(paths);
|
|
192
|
+
const visitVirtuals = (record2, prefix) => {
|
|
193
|
+
for (const [name, value] of Object.entries(record2 ?? {})) {
|
|
194
|
+
debitOutputWork();
|
|
195
|
+
if (value === void 0) continue;
|
|
196
|
+
const path = prefix ? prepareOutputWorkString([prefix, name]) : name;
|
|
197
|
+
debitOutputPayload(currentOutputWorkLedger(), path);
|
|
198
|
+
if (!isSafeOutputPath(path)) continue;
|
|
199
|
+
if (value && typeof value === "object" && "sub" in value) {
|
|
200
|
+
if (references.has(path)) continue;
|
|
201
|
+
virtualScopes.add(path);
|
|
202
|
+
add(path);
|
|
203
|
+
containers.add(path);
|
|
204
|
+
visitVirtuals(value.sub, path);
|
|
205
|
+
} else {
|
|
206
|
+
add(path);
|
|
207
|
+
ancestors(path);
|
|
208
|
+
virtualPaths.add(path);
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
};
|
|
212
|
+
visitVirtuals(virtuals, "");
|
|
213
|
+
const protectedEntries = copyPaths(protectedPaths);
|
|
214
|
+
const filterPaths = (values, keep) => {
|
|
215
|
+
debitOutputWork(void 0, values.length + 1);
|
|
216
|
+
return values.filter(keep);
|
|
217
|
+
};
|
|
218
|
+
const eligible = filterPaths(
|
|
219
|
+
copyPaths(paths),
|
|
220
|
+
(p) => !protectedEntries.some((v) => matchesCatalogPattern(v, p, true))
|
|
221
|
+
);
|
|
222
|
+
debitOutputWork(void 0, 3);
|
|
223
|
+
const catalog = Object.freeze({
|
|
224
|
+
paths: Object.freeze(filterPaths(eligible, (p) => !p.includes("$*"))),
|
|
225
|
+
persistedPaths: Object.freeze(persistedPaths),
|
|
226
|
+
arrayPaths: Object.freeze(copyPaths(arrays)),
|
|
227
|
+
schemaVirtualPaths: Object.freeze(copyPaths(schemaVirtualPaths)),
|
|
228
|
+
metadataPaths: Object.freeze([documentPermissionField]),
|
|
229
|
+
dynamicPaths: Object.freeze(filterPaths(eligible, (p) => p.includes("$*"))),
|
|
230
|
+
containerPaths: Object.freeze(copyPaths(containers)),
|
|
231
|
+
opaquePaths: Object.freeze(copyPaths(opaque)),
|
|
232
|
+
referencePaths: Object.freeze(copyPaths(references)),
|
|
233
|
+
virtualPaths: Object.freeze(copyPaths(virtualPaths)),
|
|
234
|
+
virtualScopePaths: Object.freeze(copyPaths(virtualScopes)),
|
|
235
|
+
protectedPaths: Object.freeze(protectedEntries)
|
|
236
|
+
});
|
|
237
|
+
if (typeof documentPermissionField === "string") {
|
|
238
|
+
const arrays2 = Object.values(catalog);
|
|
239
|
+
ownedCatalogs.set(
|
|
240
|
+
catalog,
|
|
241
|
+
Object.freeze({ slots: 1 + arrays2.length + arrays2.reduce((sum, paths2) => sum + paths2.length, 0), depth: 2 })
|
|
242
|
+
);
|
|
243
|
+
}
|
|
244
|
+
return catalog;
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
// src/acl/trusted-output-materialization.ts
|
|
248
|
+
import { types as types3 } from "util";
|
|
249
|
+
import { mongo } from "mongoose";
|
|
250
|
+
|
|
251
|
+
// src/output/permissions-alias.ts
|
|
252
|
+
import { get } from "@web-ts-toolkit/utils";
|
|
253
|
+
import { types as types2 } from "util";
|
|
254
|
+
var aliases = /* @__PURE__ */ new WeakMap();
|
|
255
|
+
function isGeneratedPermissionsAliasSlot(output, key, slot) {
|
|
256
|
+
return key === "permissions" && aliases.has(output) && "value" in slot && !slot.enumerable;
|
|
257
|
+
}
|
|
258
|
+
function attachPermissionsAlias(output, field) {
|
|
259
|
+
if ("permissions" in output) return;
|
|
260
|
+
const metadata = get(output, field);
|
|
261
|
+
if (metadata === void 0) return;
|
|
262
|
+
Object.defineProperty(output, "permissions", {
|
|
263
|
+
value: metadata,
|
|
264
|
+
enumerable: false,
|
|
265
|
+
writable: true,
|
|
266
|
+
configurable: true
|
|
267
|
+
});
|
|
268
|
+
aliases.set(output, field);
|
|
269
|
+
}
|
|
270
|
+
function copyPermissionsAlias(source, target) {
|
|
271
|
+
if (source && typeof source === "object" && target && typeof target === "object") {
|
|
272
|
+
const field = aliases.get(source);
|
|
273
|
+
const readData = (value) => {
|
|
274
|
+
const parts = field?.split(".") ?? [];
|
|
275
|
+
if (parts.length > 100) return void 0;
|
|
276
|
+
for (const key of parts) {
|
|
277
|
+
if (!value || typeof value !== "object" || types2.isProxy(value)) return void 0;
|
|
278
|
+
const slot = Object.getOwnPropertyDescriptor(value, key);
|
|
279
|
+
if (!slot || !("value" in slot)) return void 0;
|
|
280
|
+
value = slot.value;
|
|
281
|
+
}
|
|
282
|
+
return value;
|
|
283
|
+
};
|
|
284
|
+
if (field && readData(target) !== void 0 && Object.getOwnPropertyDescriptor(source, "permissions")?.value === readData(source))
|
|
285
|
+
attachPermissionsAlias(target, field);
|
|
286
|
+
}
|
|
287
|
+
return target;
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
// src/acl/trusted-output-materialization.ts
|
|
291
|
+
var unsafeKeys = /* @__PURE__ */ new Set(["__proto__", "constructor", "prototype", "_doc", "$__"]);
|
|
292
|
+
var protectedValueKeys = /* @__PURE__ */ new Set([...unsafeKeys, "__v"]);
|
|
293
|
+
var budgets = /* @__PURE__ */ new WeakMap();
|
|
294
|
+
function createTrustedOutputBudget(onFailure, ownerCheck, ledger) {
|
|
295
|
+
const budget = Object.freeze(/* @__PURE__ */ Object.create(null));
|
|
296
|
+
const ownerLedger = arguments.length < 3 ? currentOutputWorkLedger() : ledger;
|
|
297
|
+
budgets.set(budget, {
|
|
298
|
+
slots: 0,
|
|
299
|
+
failure: void 0,
|
|
300
|
+
recipients: void 0,
|
|
301
|
+
onFailure,
|
|
302
|
+
ownerCheck,
|
|
303
|
+
ledger: ownerLedger
|
|
304
|
+
});
|
|
305
|
+
return budget;
|
|
306
|
+
}
|
|
307
|
+
function failTrustedOutputBudget(budget, error) {
|
|
308
|
+
const record2 = budgets.get(budget);
|
|
309
|
+
if (!record2) authorizationError("invalid selected output budget");
|
|
310
|
+
record2.failure ??= error instanceof ServiceAuthorizationError ? error : new ServiceAuthorizationError("unsupported selected value");
|
|
311
|
+
record2.onFailure?.(record2.failure);
|
|
312
|
+
for (const edge of record2.recipients ?? []) {
|
|
313
|
+
try {
|
|
314
|
+
failTrustedOutputBudget(edge.budget, record2.failure);
|
|
315
|
+
} catch {
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
throw record2.failure;
|
|
319
|
+
}
|
|
320
|
+
function assertTrustedOutputBudget(budget) {
|
|
321
|
+
const record2 = budgets.get(budget);
|
|
322
|
+
if (!record2) authorizationError("invalid selected output budget");
|
|
323
|
+
record2.ownerCheck?.();
|
|
324
|
+
record2.ledger?.check();
|
|
325
|
+
if (record2.failure) throw record2.failure;
|
|
326
|
+
for (const edge of record2.recipients ?? []) assertTrustedOutputBudget(edge.budget);
|
|
327
|
+
}
|
|
328
|
+
function visitTrustedOutput(budget, depth, slots = 1, charged) {
|
|
329
|
+
const record2 = budgets.get(budget);
|
|
330
|
+
if (!record2) authorizationError("invalid selected output budget");
|
|
331
|
+
assertTrustedOutputBudget(budget);
|
|
332
|
+
if (record2.recipients?.length) charged ??= /* @__PURE__ */ new Set();
|
|
333
|
+
if (record2.ledger && !charged?.has(record2.ledger)) {
|
|
334
|
+
debitOutputWork(record2.ledger, slots);
|
|
335
|
+
charged?.add(record2.ledger);
|
|
336
|
+
}
|
|
337
|
+
if (depth > 100 || (record2.slots += slots) > 2e4)
|
|
338
|
+
failTrustedOutputBudget(budget, new ServiceAuthorizationError("selected output exceeds structural limits"));
|
|
339
|
+
try {
|
|
340
|
+
for (const edge of record2.recipients ?? [])
|
|
341
|
+
visitTrustedOutput(edge.budget, depth + edge.depth, slots * edge.multiplicity, charged);
|
|
342
|
+
} catch (error) {
|
|
343
|
+
failTrustedOutputBudget(budget, error);
|
|
344
|
+
}
|
|
345
|
+
}
|
|
346
|
+
function preloadTrustedOutputBudget(budget, depth, slots) {
|
|
347
|
+
const record2 = budgets.get(budget);
|
|
348
|
+
if (!record2) authorizationError("invalid selected output budget");
|
|
349
|
+
visitTrustedOutput(budget, depth, slots, record2.ledger ? /* @__PURE__ */ new Set([record2.ledger]) : void 0);
|
|
350
|
+
}
|
|
351
|
+
function prepareTrustedOutputPayload(budget, value, charged) {
|
|
352
|
+
const record2 = budgets.get(budget);
|
|
353
|
+
if (!record2) authorizationError("invalid selected output budget");
|
|
354
|
+
if (!record2.ledger && !record2.recipients?.length) return;
|
|
355
|
+
assertTrustedOutputBudget(budget);
|
|
356
|
+
if (record2.recipients?.length) charged ??= /* @__PURE__ */ new Set();
|
|
357
|
+
if (record2.ledger && !charged?.has(record2.ledger)) {
|
|
358
|
+
debitOutputPayload(record2.ledger, value);
|
|
359
|
+
charged?.add(record2.ledger);
|
|
360
|
+
}
|
|
361
|
+
for (const edge of record2.recipients ?? []) prepareTrustedOutputPayload(edge.budget, value, charged);
|
|
362
|
+
}
|
|
363
|
+
function defineTrustedOutputValue(output, key, value) {
|
|
364
|
+
Object.defineProperty(output, key, { value, enumerable: true, configurable: true, writable: true });
|
|
365
|
+
}
|
|
366
|
+
function isBsonValue(input) {
|
|
367
|
+
let prototype = Object.getPrototypeOf(input);
|
|
368
|
+
for (let depth = 0; prototype && depth <= 100; depth++) {
|
|
369
|
+
debitOutputWork();
|
|
370
|
+
if (types3.isProxy(prototype)) return false;
|
|
371
|
+
if (prototype === mongo.BSON.BSONValue.prototype) return true;
|
|
372
|
+
prototype = Object.getPrototypeOf(prototype);
|
|
373
|
+
}
|
|
374
|
+
return false;
|
|
375
|
+
}
|
|
376
|
+
var bsonFamilies = new Map(
|
|
377
|
+
Object.entries({
|
|
378
|
+
ObjectId: mongo.BSON.ObjectId,
|
|
379
|
+
Code: mongo.BSON.Code,
|
|
380
|
+
DBRef: mongo.BSON.DBRef,
|
|
381
|
+
Timestamp: mongo.BSON.Timestamp,
|
|
382
|
+
Long: mongo.BSON.Long,
|
|
383
|
+
Decimal128: mongo.BSON.Decimal128,
|
|
384
|
+
Binary: mongo.BSON.Binary,
|
|
385
|
+
Double: mongo.BSON.Double,
|
|
386
|
+
Int32: mongo.BSON.Int32,
|
|
387
|
+
BSONRegExp: mongo.BSON.BSONRegExp,
|
|
388
|
+
BSONSymbol: mongo.BSON.BSONSymbol,
|
|
389
|
+
MinKey: mongo.BSON.MinKey,
|
|
390
|
+
MaxKey: mongo.BSON.MaxKey
|
|
391
|
+
}).map(([name, family]) => [family.prototype, name])
|
|
392
|
+
);
|
|
393
|
+
function selectedDataProperty(input, key, own = false) {
|
|
394
|
+
let object = input;
|
|
395
|
+
for (let depth = 0; object && depth <= 100; depth++) {
|
|
396
|
+
debitOutputWork();
|
|
397
|
+
if (types3.isProxy(object)) authorizationError("unsupported selected proxy");
|
|
398
|
+
const slot = Object.getOwnPropertyDescriptor(object, key);
|
|
399
|
+
if (slot) {
|
|
400
|
+
if (!("value" in slot)) authorizationError("accessor selected BSON state");
|
|
401
|
+
return slot.value;
|
|
402
|
+
}
|
|
403
|
+
object = own ? null : Object.getPrototypeOf(object);
|
|
404
|
+
}
|
|
405
|
+
if (object) authorizationError("unsupported selected prototype depth");
|
|
406
|
+
return void 0;
|
|
407
|
+
}
|
|
408
|
+
function selectedBsonBytes(input, budget) {
|
|
409
|
+
if (!input || typeof input !== "object" || types3.isProxy(input) || !types3.isUint8Array(input))
|
|
410
|
+
authorizationError("unsupported selected BSON bytes");
|
|
411
|
+
const prototype = Object.getPrototypeOf(Uint8Array.prototype);
|
|
412
|
+
const buffer = Object.getOwnPropertyDescriptor(prototype, "buffer").get.call(input);
|
|
413
|
+
const offset = Object.getOwnPropertyDescriptor(prototype, "byteOffset").get.call(input);
|
|
414
|
+
const length = Object.getOwnPropertyDescriptor(prototype, "byteLength").get.call(input);
|
|
415
|
+
prepareTrustedOutputPayload(budget, length);
|
|
416
|
+
return Buffer.from(new Uint8Array(buffer, offset, length));
|
|
417
|
+
}
|
|
418
|
+
var regexpFlagNames = [
|
|
419
|
+
"hasIndices",
|
|
420
|
+
"global",
|
|
421
|
+
"ignoreCase",
|
|
422
|
+
"multiline",
|
|
423
|
+
"dotAll",
|
|
424
|
+
"unicode",
|
|
425
|
+
"unicodeSets",
|
|
426
|
+
"sticky"
|
|
427
|
+
];
|
|
428
|
+
function prepareRegExpFlags(input, budget) {
|
|
429
|
+
const ledger = budgets.get(budget).ledger;
|
|
430
|
+
if (ledger) debitOutputWork(ledger, regexpFlagNames.length);
|
|
431
|
+
const flags = [];
|
|
432
|
+
for (let index = 0; index < regexpFlagNames.length; index++)
|
|
433
|
+
if (Object.getOwnPropertyDescriptor(RegExp.prototype, regexpFlagNames[index])?.get?.call(input)) {
|
|
434
|
+
prepareTrustedOutputPayload(budget, 1);
|
|
435
|
+
defineTrustedOutputValue(flags, String(flags.length), "dgimsuvy"[index]);
|
|
436
|
+
}
|
|
437
|
+
prepareTrustedOutputPayload(budget, flags.length);
|
|
438
|
+
return flags.join("");
|
|
439
|
+
}
|
|
440
|
+
function copyTrustedBsonValue(value, path, budget, policy, depth, active) {
|
|
441
|
+
const wireKeys = /* @__PURE__ */ new Set([
|
|
442
|
+
"value",
|
|
443
|
+
"code",
|
|
444
|
+
"scope",
|
|
445
|
+
"collection",
|
|
446
|
+
"oid",
|
|
447
|
+
"db",
|
|
448
|
+
"fields",
|
|
449
|
+
"low",
|
|
450
|
+
"high",
|
|
451
|
+
"unsigned",
|
|
452
|
+
"buffer",
|
|
453
|
+
"sub_type",
|
|
454
|
+
"position",
|
|
455
|
+
"pattern",
|
|
456
|
+
"options",
|
|
457
|
+
"bytes",
|
|
458
|
+
"i0",
|
|
459
|
+
"i1",
|
|
460
|
+
"i2",
|
|
461
|
+
"i3"
|
|
462
|
+
]);
|
|
463
|
+
const defineWireValue = (output, key, value2) => {
|
|
464
|
+
debitOutputWork();
|
|
465
|
+
prepareTrustedOutputPayload(budget, key);
|
|
466
|
+
wireKeys.add(key);
|
|
467
|
+
defineTrustedOutputValue(output, key, value2);
|
|
468
|
+
};
|
|
469
|
+
const prepareWire = (input, current, level, observeHook = true, entered = false, documentRoot = false, slots = 1) => {
|
|
470
|
+
if (!entered) visitTrustedOutput(budget, level, slots);
|
|
471
|
+
if (typeof input === "function" || typeof input === "symbol") authorizationError("unsupported selected BSON value");
|
|
472
|
+
if (input === null || typeof input !== "object") {
|
|
473
|
+
if (typeof input === "string") prepareTrustedOutputPayload(budget, input);
|
|
474
|
+
return input;
|
|
475
|
+
}
|
|
476
|
+
if (types3.isProxy(input)) authorizationError("unsupported selected proxy");
|
|
477
|
+
if (!entered && active.has(input)) authorizationError("cyclic selected output");
|
|
478
|
+
if (!entered) active.add(input);
|
|
479
|
+
try {
|
|
480
|
+
const hook = selectedDataProperty(input, "toBSON");
|
|
481
|
+
if (typeof hook === "function") {
|
|
482
|
+
if (!observeHook) authorizationError("chained selected BSON hooks");
|
|
483
|
+
const normalized = outsideOutputWorkLedger(() => Reflect.apply(hook, input, []));
|
|
484
|
+
if (normalized !== input) return prepareWire(normalized, current, level, false, false, documentRoot);
|
|
485
|
+
}
|
|
486
|
+
if (isBsonValue(input)) {
|
|
487
|
+
if (documentRoot) authorizationError("unsupported selected BSON document");
|
|
488
|
+
let prototype2 = input;
|
|
489
|
+
for (let hops = 0; prototype2 && !bsonFamilies.has(prototype2) && hops <= 100; hops++) {
|
|
490
|
+
if (types3.isProxy(prototype2)) authorizationError("unsupported selected proxy");
|
|
491
|
+
if (Object.hasOwn(prototype2, "_bsontype") || Object.hasOwn(prototype2, /* @__PURE__ */ Symbol.for("@@mdb.bson.type")))
|
|
492
|
+
authorizationError("overridden selected BSON brand");
|
|
493
|
+
prototype2 = Object.getPrototypeOf(prototype2);
|
|
494
|
+
}
|
|
495
|
+
if (!prototype2 || !bsonFamilies.has(prototype2)) authorizationError("unsupported selected BSON family");
|
|
496
|
+
const family = bsonFamilies.get(prototype2);
|
|
497
|
+
const output2 = Object.create(prototype2);
|
|
498
|
+
Object.defineProperty(output2, "toBSON", { value: void 0 });
|
|
499
|
+
const field = (key, type) => {
|
|
500
|
+
const value2 = selectedDataProperty(input, key, true);
|
|
501
|
+
if (typeof value2 !== type) authorizationError("unsupported selected BSON state");
|
|
502
|
+
if (typeof value2 === "string") prepareTrustedOutputPayload(budget, value2);
|
|
503
|
+
defineWireValue(output2, key, value2);
|
|
504
|
+
return value2;
|
|
505
|
+
};
|
|
506
|
+
const bytes = (key, length) => {
|
|
507
|
+
const value2 = selectedBsonBytes(selectedDataProperty(input, key, true), budget);
|
|
508
|
+
if (length !== void 0 && value2.length !== length) authorizationError("invalid selected BSON bytes");
|
|
509
|
+
defineWireValue(output2, key, value2);
|
|
510
|
+
};
|
|
511
|
+
const method = (key) => {
|
|
512
|
+
if (selectedDataProperty(input, key) !== selectedDataProperty(prototype2, key))
|
|
513
|
+
authorizationError("unsupported selected BSON serializer override");
|
|
514
|
+
};
|
|
515
|
+
const document = (key) => {
|
|
516
|
+
const raw = selectedDataProperty(input, key, true);
|
|
517
|
+
const value2 = prepareWire(raw, prepareOutputWorkString([current, key]), level + 1, true, false, true);
|
|
518
|
+
if (!value2 || typeof value2 !== "object" || !Array.isArray(value2) && Object.getPrototypeOf(value2) !== null)
|
|
519
|
+
authorizationError("unsupported selected BSON document");
|
|
520
|
+
defineWireValue(output2, key, value2);
|
|
521
|
+
};
|
|
522
|
+
switch (family) {
|
|
523
|
+
case "Code": {
|
|
524
|
+
field("code", "string");
|
|
525
|
+
const scope = selectedDataProperty(input, "scope", true);
|
|
526
|
+
if (scope != null) document("scope");
|
|
527
|
+
else defineWireValue(output2, "scope", scope);
|
|
528
|
+
break;
|
|
529
|
+
}
|
|
530
|
+
case "DBRef": {
|
|
531
|
+
field("collection", "string");
|
|
532
|
+
const db = selectedDataProperty(input, "db", true);
|
|
533
|
+
if (db != null) field("db", "string");
|
|
534
|
+
defineWireValue(
|
|
535
|
+
output2,
|
|
536
|
+
"oid",
|
|
537
|
+
prepareWire(
|
|
538
|
+
selectedDataProperty(input, "oid", true),
|
|
539
|
+
prepareOutputWorkString([current, "oid"]),
|
|
540
|
+
level + 1
|
|
541
|
+
)
|
|
542
|
+
);
|
|
543
|
+
document("fields");
|
|
544
|
+
const ordered = /* @__PURE__ */ Object.create(null);
|
|
545
|
+
defineWireValue(ordered, "$ref", output2.collection);
|
|
546
|
+
defineWireValue(ordered, "$id", output2.oid);
|
|
547
|
+
if (db != null) defineWireValue(ordered, "$db", output2.db);
|
|
548
|
+
for (const key of Object.keys(output2.fields))
|
|
549
|
+
defineWireValue(ordered, key, output2.fields[key]);
|
|
550
|
+
return ordered;
|
|
551
|
+
}
|
|
552
|
+
case "ObjectId":
|
|
553
|
+
method("serializeInto");
|
|
554
|
+
if (Object.hasOwn(input, "buffer"))
|
|
555
|
+
bytes("buffer", 12);
|
|
556
|
+
else for (const key of ["i0", "i1", "i2", "i3"]) field(key, "number");
|
|
557
|
+
break;
|
|
558
|
+
case "Timestamp":
|
|
559
|
+
case "Long":
|
|
560
|
+
method("getLowBits");
|
|
561
|
+
method("getHighBits");
|
|
562
|
+
field("low", "number");
|
|
563
|
+
field("high", "number");
|
|
564
|
+
field("unsigned", "boolean");
|
|
565
|
+
break;
|
|
566
|
+
case "Decimal128":
|
|
567
|
+
bytes("bytes", 16);
|
|
568
|
+
break;
|
|
569
|
+
case "Binary": {
|
|
570
|
+
bytes("buffer");
|
|
571
|
+
const position = field("position", "number");
|
|
572
|
+
const subtype = field("sub_type", "number");
|
|
573
|
+
if (!Number.isInteger(position) || position < 0 || position > output2.buffer.length || !Number.isInteger(subtype) || subtype < 0 || subtype > 255)
|
|
574
|
+
authorizationError("invalid selected BSON binary");
|
|
575
|
+
break;
|
|
576
|
+
}
|
|
577
|
+
case "Int32":
|
|
578
|
+
method("valueOf");
|
|
579
|
+
field("value", "number");
|
|
580
|
+
break;
|
|
581
|
+
case "Double":
|
|
582
|
+
field("value", "number");
|
|
583
|
+
break;
|
|
584
|
+
case "BSONSymbol":
|
|
585
|
+
field("value", "string");
|
|
586
|
+
break;
|
|
587
|
+
case "BSONRegExp":
|
|
588
|
+
field("pattern", "string");
|
|
589
|
+
field("options", "string");
|
|
590
|
+
break;
|
|
591
|
+
}
|
|
592
|
+
return output2;
|
|
593
|
+
}
|
|
594
|
+
if (selectedDataProperty(input, "_bsontype") != null) authorizationError("unsupported selected BSON tag");
|
|
595
|
+
const noHook = (value2) => {
|
|
596
|
+
Object.defineProperty(value2, "toBSON", { value: void 0 });
|
|
597
|
+
return value2;
|
|
598
|
+
};
|
|
599
|
+
if (types3.isDate(input)) {
|
|
600
|
+
const getTime = selectedDataProperty(input, "getTime");
|
|
601
|
+
if (typeof getTime !== "function") authorizationError("unsupported selected BSON date");
|
|
602
|
+
const time = outsideOutputWorkLedger(() => Reflect.apply(getTime, input, []));
|
|
603
|
+
if (typeof time !== "number") authorizationError("unsupported selected BSON date");
|
|
604
|
+
prepareTrustedOutputPayload(budget, 8);
|
|
605
|
+
return noHook(new Date(time));
|
|
606
|
+
}
|
|
607
|
+
if (types3.isUint8Array(input)) return noHook(selectedBsonBytes(input, budget));
|
|
608
|
+
if (types3.isRegExp(input)) {
|
|
609
|
+
const source = Object.getOwnPropertyDescriptor(RegExp.prototype, "source").get.call(input);
|
|
610
|
+
prepareTrustedOutputPayload(budget, source);
|
|
611
|
+
const flags = prepareRegExpFlags(input, budget);
|
|
612
|
+
prepareTrustedOutputPayload(budget, flags);
|
|
613
|
+
return noHook(new RegExp(source, flags));
|
|
614
|
+
}
|
|
615
|
+
const output = /* @__PURE__ */ Object.create(null);
|
|
616
|
+
if (types3.isMap(input)) {
|
|
617
|
+
for (const [key, entry] of Map.prototype.entries.call(input)) {
|
|
618
|
+
visitTrustedOutput(budget, level + 1);
|
|
619
|
+
if (typeof key !== "string") authorizationError("selected Map requires string keys");
|
|
620
|
+
if (protectedValueKeys.has(key)) {
|
|
621
|
+
if (policy.rejectProtectedKeys) authorizationError("protected native snapshot key");
|
|
622
|
+
continue;
|
|
623
|
+
}
|
|
624
|
+
const child = prepareOutputWorkString([current, key]);
|
|
625
|
+
if (!policy.keep(key, child)) continue;
|
|
626
|
+
prepareTrustedOutputPayload(budget, key);
|
|
627
|
+
defineWireValue(output, key, prepareWire(entry, child, level + 1));
|
|
628
|
+
}
|
|
629
|
+
return output;
|
|
630
|
+
}
|
|
631
|
+
const array = Array.isArray(input);
|
|
632
|
+
const prototype = Object.getPrototypeOf(input);
|
|
633
|
+
if (!array && prototype !== Object.prototype && prototype !== null)
|
|
634
|
+
authorizationError("unsupported selected object");
|
|
635
|
+
const container = array ? noHook([]) : output;
|
|
636
|
+
if (array) {
|
|
637
|
+
const length = Object.getOwnPropertyDescriptor(input, "length").value;
|
|
638
|
+
if (length) visitTrustedOutput(budget, level + 1, length);
|
|
639
|
+
container.length = length;
|
|
640
|
+
for (let index = 0; index < length; index++) defineWireValue(container, String(index), void 0);
|
|
641
|
+
}
|
|
642
|
+
for (const key of Reflect.ownKeys(input)) {
|
|
643
|
+
if (array && key === "length") continue;
|
|
644
|
+
visitTrustedOutput(budget, level + 1);
|
|
645
|
+
if (typeof key !== "string") authorizationError("symbol selected output key");
|
|
646
|
+
if (protectedValueKeys.has(key)) {
|
|
647
|
+
if (policy.rejectProtectedKeys) authorizationError("protected native snapshot key");
|
|
648
|
+
continue;
|
|
649
|
+
}
|
|
650
|
+
if (key === "toBSON" && (array || typeof hook === "function")) continue;
|
|
651
|
+
if (array && !/^(0|[1-9]\d*)$/.test(key)) authorizationError("invalid selected array property");
|
|
652
|
+
const child = array ? current : prepareOutputWorkString([current, key]);
|
|
653
|
+
if (!array && !policy.keep(key, child)) continue;
|
|
654
|
+
prepareTrustedOutputPayload(budget, key);
|
|
655
|
+
const slot = Object.getOwnPropertyDescriptor(input, key);
|
|
656
|
+
if (!("value" in slot) || !slot.enumerable) authorizationError("accessor/non-enumerable selected value");
|
|
657
|
+
defineWireValue(container, key, prepareWire(slot.value, child, level + 1, true, false, false, 0));
|
|
658
|
+
}
|
|
659
|
+
return container;
|
|
660
|
+
} finally {
|
|
661
|
+
if (!entered) active.delete(input);
|
|
662
|
+
}
|
|
663
|
+
};
|
|
664
|
+
const prepared = prepareWire(value, path, depth, true, true);
|
|
665
|
+
assertTrustedOutputBudget(budget);
|
|
666
|
+
for (const key of wireKeys) {
|
|
667
|
+
const slot = Object.getOwnPropertyDescriptor(Object.prototype, key);
|
|
668
|
+
if (slot && !("value" in slot)) authorizationError("inherited accessor selected BSON output");
|
|
669
|
+
}
|
|
670
|
+
const wrapper = /* @__PURE__ */ Object.create(null);
|
|
671
|
+
defineTrustedOutputValue(wrapper, "value", prepared);
|
|
672
|
+
const result = outsideOutputWorkLedger(
|
|
673
|
+
() => mongo.BSON.deserialize(mongo.BSON.serialize(wrapper), { promoteValues: false, bsonRegExp: true }).value
|
|
674
|
+
);
|
|
675
|
+
assertTrustedOutputBudget(budget);
|
|
676
|
+
return result;
|
|
677
|
+
}
|
|
678
|
+
function materializeTrustedOutputValue(value, path, budget, policy, depth = 0, prepaid = false) {
|
|
679
|
+
const ledger = budgets.get(budget)?.ledger;
|
|
680
|
+
if (ledger && currentOutputWorkLedger() !== ledger)
|
|
681
|
+
return withOutputWorkLedger(
|
|
682
|
+
ledger,
|
|
683
|
+
() => materializeTrustedOutputValue(value, path, budget, policy, depth, prepaid)
|
|
684
|
+
);
|
|
685
|
+
if (value === null || typeof value !== "object" && typeof value !== "function" && typeof value !== "symbol") {
|
|
686
|
+
try {
|
|
687
|
+
visitTrustedOutput(budget, depth, prepaid ? 0 : 1);
|
|
688
|
+
if (typeof value === "string") prepareTrustedOutputPayload(budget, value);
|
|
689
|
+
assertTrustedOutputBudget(budget);
|
|
690
|
+
return value;
|
|
691
|
+
} catch (error) {
|
|
692
|
+
failTrustedOutputBudget(budget, error);
|
|
693
|
+
}
|
|
694
|
+
}
|
|
695
|
+
const active = /* @__PURE__ */ new WeakSet();
|
|
696
|
+
const visit = (input, current, level, slots = 1) => {
|
|
697
|
+
visitTrustedOutput(budget, level, slots);
|
|
698
|
+
if (typeof input === "function" || typeof input === "symbol") authorizationError("unsupported selected value");
|
|
699
|
+
if (input === null || typeof input !== "object") {
|
|
700
|
+
if (typeof input === "string") prepareTrustedOutputPayload(budget, input);
|
|
701
|
+
return input;
|
|
702
|
+
}
|
|
703
|
+
if (types3.isProxy(input)) authorizationError("unsupported selected proxy");
|
|
704
|
+
if (active.has(input)) authorizationError("cyclic selected output");
|
|
705
|
+
active.add(input);
|
|
706
|
+
try {
|
|
707
|
+
if (types3.isDate(input)) {
|
|
708
|
+
const method = selectedDataProperty(input, "getTime");
|
|
709
|
+
if (typeof method !== "function") authorizationError("unsupported selected date");
|
|
710
|
+
const time = outsideOutputWorkLedger(() => Reflect.apply(method, input, []));
|
|
711
|
+
if (typeof time !== "number") authorizationError("unsupported selected date");
|
|
712
|
+
prepareTrustedOutputPayload(budget, 8);
|
|
713
|
+
return new Date(time);
|
|
714
|
+
}
|
|
715
|
+
if (Buffer.isBuffer(input)) return selectedBsonBytes(input, budget);
|
|
716
|
+
if (types3.isRegExp(input)) {
|
|
717
|
+
const source = Object.getOwnPropertyDescriptor(RegExp.prototype, "source").get.call(input);
|
|
718
|
+
prepareTrustedOutputPayload(budget, source);
|
|
719
|
+
const flags = prepareRegExpFlags(input, budget);
|
|
720
|
+
prepareTrustedOutputPayload(budget, flags);
|
|
721
|
+
const output2 = new RegExp(source, flags);
|
|
722
|
+
const lastIndex = selectedDataProperty(input, "lastIndex", true);
|
|
723
|
+
if (typeof lastIndex !== "number") authorizationError("unsupported selected regexp");
|
|
724
|
+
output2.lastIndex = lastIndex;
|
|
725
|
+
return output2;
|
|
726
|
+
}
|
|
727
|
+
if (isBsonValue(input)) {
|
|
728
|
+
try {
|
|
729
|
+
return copyTrustedBsonValue(input, current, budget, policy, level, active);
|
|
730
|
+
} catch (error) {
|
|
731
|
+
if (error instanceof ServiceAuthorizationError) throw error;
|
|
732
|
+
authorizationError("unsupported selected BSON value");
|
|
733
|
+
}
|
|
734
|
+
}
|
|
735
|
+
if (types3.isMap(input)) {
|
|
736
|
+
const output2 = {};
|
|
737
|
+
for (const [key, entry] of Map.prototype.entries.call(input)) {
|
|
738
|
+
visitTrustedOutput(budget, level + 1);
|
|
739
|
+
if (typeof key !== "string") authorizationError("selected Map requires string keys");
|
|
740
|
+
if (protectedValueKeys.has(key)) {
|
|
741
|
+
if (policy.rejectProtectedKeys) authorizationError("protected native snapshot key");
|
|
742
|
+
continue;
|
|
743
|
+
}
|
|
744
|
+
const child = prepareOutputWorkString([current, key]);
|
|
745
|
+
if (!policy.keep(key, child)) continue;
|
|
746
|
+
prepareTrustedOutputPayload(budget, key);
|
|
747
|
+
defineTrustedOutputValue(output2, key, visit(entry, child, level + 1));
|
|
748
|
+
}
|
|
749
|
+
return output2;
|
|
750
|
+
}
|
|
751
|
+
const array = Array.isArray(input);
|
|
752
|
+
const prototype = Object.getPrototypeOf(input);
|
|
753
|
+
if (!array && prototype !== Object.prototype && prototype !== null)
|
|
754
|
+
authorizationError("unsupported selected object");
|
|
755
|
+
const output = array ? [] : {};
|
|
756
|
+
if (array) {
|
|
757
|
+
const length = Object.getOwnPropertyDescriptor(input, "length").value;
|
|
758
|
+
if (length) visitTrustedOutput(budget, level + 1, length);
|
|
759
|
+
output.length = length;
|
|
760
|
+
}
|
|
761
|
+
for (const key of Reflect.ownKeys(input)) {
|
|
762
|
+
if (array && key === "length") continue;
|
|
763
|
+
visitTrustedOutput(budget, level + 1);
|
|
764
|
+
if (typeof key !== "string") authorizationError("symbol selected output key");
|
|
765
|
+
if (protectedValueKeys.has(key)) {
|
|
766
|
+
if (policy.rejectProtectedKeys) authorizationError("protected native snapshot key");
|
|
767
|
+
continue;
|
|
768
|
+
}
|
|
769
|
+
if (array && !/^(0|[1-9]\d*)$/.test(key)) authorizationError("invalid selected array property");
|
|
770
|
+
const child = array ? current : prepareOutputWorkString([current, key]);
|
|
771
|
+
if (!array && !policy.keep(key, child)) continue;
|
|
772
|
+
prepareTrustedOutputPayload(budget, key);
|
|
773
|
+
const slot = Object.getOwnPropertyDescriptor(input, key);
|
|
774
|
+
if (isGeneratedPermissionsAliasSlot(input, key, slot)) continue;
|
|
775
|
+
if (!("value" in slot) || !slot.enumerable) authorizationError("accessor/non-enumerable selected value");
|
|
776
|
+
defineTrustedOutputValue(output, key, visit(slot.value, child, level + 1, 0));
|
|
777
|
+
}
|
|
778
|
+
return copyPermissionsAlias(input, output);
|
|
779
|
+
} catch (error) {
|
|
780
|
+
failTrustedOutputBudget(budget, error);
|
|
781
|
+
} finally {
|
|
782
|
+
active.delete(input);
|
|
783
|
+
}
|
|
784
|
+
};
|
|
785
|
+
try {
|
|
786
|
+
const result = visit(value, path, depth, prepaid ? 0 : 1);
|
|
787
|
+
assertTrustedOutputBudget(budget);
|
|
788
|
+
return result;
|
|
789
|
+
} catch (error) {
|
|
790
|
+
failTrustedOutputBudget(budget, error);
|
|
791
|
+
}
|
|
792
|
+
}
|
|
793
|
+
|
|
794
|
+
// src/acl/authorization-snapshot.ts
|
|
795
|
+
var ServiceAuthorizationError = class extends JsonRouter.clientErrors.BadRequestError {
|
|
796
|
+
constructor(detail) {
|
|
797
|
+
const errors = [{ detail: `Service authorization: ${detail}` }];
|
|
798
|
+
super("Bad Request", { errors });
|
|
799
|
+
this.result = { success: false, kind: "error", code: "bad_request" /* BadRequest */, errors };
|
|
800
|
+
Object.freeze(errors[0]);
|
|
801
|
+
Object.freeze(errors);
|
|
802
|
+
Object.freeze(this.result);
|
|
803
|
+
Object.defineProperty(this, "result", {
|
|
804
|
+
value: this.result,
|
|
805
|
+
enumerable: true,
|
|
806
|
+
writable: false,
|
|
807
|
+
configurable: false
|
|
808
|
+
});
|
|
809
|
+
}
|
|
810
|
+
};
|
|
811
|
+
function authorizationError(detail) {
|
|
812
|
+
throw new ServiceAuthorizationError(detail);
|
|
813
|
+
}
|
|
814
|
+
var unsafeKeys2 = /* @__PURE__ */ new Set(["__proto__", "constructor", "prototype"]);
|
|
815
|
+
function authorizationRecord(value, label) {
|
|
816
|
+
if (!value || typeof value !== "object" || Object.getPrototypeOf(value) !== Object.prototype && Object.getPrototypeOf(value) !== null) {
|
|
817
|
+
authorizationError(`${label} must be a plain object`);
|
|
818
|
+
}
|
|
819
|
+
return value;
|
|
820
|
+
}
|
|
821
|
+
function copyAuthorizationValue(value, configuration = false) {
|
|
822
|
+
const active = /* @__PURE__ */ new WeakSet();
|
|
823
|
+
const budget = createTrustedOutputBudget();
|
|
824
|
+
function copy(input, depth) {
|
|
825
|
+
visitTrustedOutput(budget, depth);
|
|
826
|
+
if (typeof input === "function") {
|
|
827
|
+
if (configuration === true) return input;
|
|
828
|
+
authorizationError("functions are not policy values");
|
|
829
|
+
}
|
|
830
|
+
if (typeof input === "symbol") authorizationError("symbols are not policy values");
|
|
831
|
+
if (input === null || typeof input !== "object") {
|
|
832
|
+
if (typeof input === "string") prepareTrustedOutputPayload(budget, input);
|
|
833
|
+
return input;
|
|
834
|
+
}
|
|
835
|
+
if (types4.isProxy(input)) authorizationError("proxy snapshot input");
|
|
836
|
+
const ownedCatalog = configuration === true ? readOwnedAuthorizationCatalogWork(input) : void 0;
|
|
837
|
+
if (ownedCatalog) {
|
|
838
|
+
preloadTrustedOutputBudget(budget, depth + ownedCatalog.depth, ownedCatalog.slots - 1);
|
|
839
|
+
return input;
|
|
840
|
+
}
|
|
841
|
+
if (active.has(input)) authorizationError("cyclic input");
|
|
842
|
+
active.add(input);
|
|
843
|
+
try {
|
|
844
|
+
if (input instanceof Date) {
|
|
845
|
+
const time = outsideOutputWorkLedger(() => input.getTime());
|
|
846
|
+
prepareTrustedOutputPayload(budget, 8);
|
|
847
|
+
return outsideOutputWorkLedger(() => new Date(time));
|
|
848
|
+
}
|
|
849
|
+
if (Buffer.isBuffer(input)) {
|
|
850
|
+
if (!currentOutputWorkLedger()) return Buffer.from(input);
|
|
851
|
+
const normalized = outsideOutputWorkLedger(() => Buffer.from(input));
|
|
852
|
+
return materializeTrustedOutputValue(normalized, "", budget, { keep: () => true }, depth, true);
|
|
853
|
+
}
|
|
854
|
+
if (input instanceof RegExp) {
|
|
855
|
+
const result2 = outsideOutputWorkLedger(() => new RegExp(input.source, input.flags));
|
|
856
|
+
result2.lastIndex = input.lastIndex;
|
|
857
|
+
return currentOutputWorkLedger() ? materializeTrustedOutputValue(result2, "", budget, { keep: () => true }, depth, true) : result2;
|
|
858
|
+
}
|
|
859
|
+
if (input instanceof mongo2.BSON.BSONValue) {
|
|
860
|
+
try {
|
|
861
|
+
return materializeTrustedOutputValue(
|
|
862
|
+
input,
|
|
863
|
+
"",
|
|
864
|
+
budget,
|
|
865
|
+
{ keep: () => true, rejectProtectedKeys: true },
|
|
866
|
+
depth,
|
|
867
|
+
true
|
|
868
|
+
);
|
|
869
|
+
} catch (error) {
|
|
870
|
+
if (error instanceof ServiceAuthorizationError) throw error;
|
|
871
|
+
authorizationError("unsupported BSON snapshot");
|
|
872
|
+
}
|
|
873
|
+
}
|
|
874
|
+
if (configuration && input instanceof Map) {
|
|
875
|
+
const result2 = /* @__PURE__ */ new Map();
|
|
876
|
+
for (const [key, entry] of Map.prototype.entries.call(input))
|
|
877
|
+
result2.set(copy(key, depth + 1), copy(entry, depth + 1));
|
|
878
|
+
return result2;
|
|
879
|
+
}
|
|
880
|
+
if (configuration && input instanceof Set) {
|
|
881
|
+
const result2 = /* @__PURE__ */ new Set();
|
|
882
|
+
for (const entry of Set.prototype.values.call(input)) result2.add(copy(entry, depth + 1));
|
|
883
|
+
return result2;
|
|
884
|
+
}
|
|
885
|
+
const array = Array.isArray(input);
|
|
886
|
+
if (array && input.length > 2e4) authorizationError("snapshot array exceeds structural limits");
|
|
887
|
+
if (!array) authorizationRecord(input, "snapshot");
|
|
888
|
+
const result = array ? [] : {};
|
|
889
|
+
let definedProperty = false;
|
|
890
|
+
for (const key of Reflect.ownKeys(input)) {
|
|
891
|
+
if (array && key === "length") continue;
|
|
892
|
+
if (typeof key !== "string" || unsafeKeys2.has(key)) authorizationError("unsafe snapshot key");
|
|
893
|
+
prepareTrustedOutputPayload(budget, key);
|
|
894
|
+
if (array && !/^(0|[1-9]\d*)$/.test(key)) authorizationError("invalid array property");
|
|
895
|
+
const descriptor = Object.getOwnPropertyDescriptor(input, key);
|
|
896
|
+
if (!("value" in descriptor) || !descriptor.enumerable && configuration !== "document")
|
|
897
|
+
authorizationError("accessor/non-enumerable input");
|
|
898
|
+
const value2 = copy(descriptor.value, depth + 1);
|
|
899
|
+
if (array || definedProperty && Object.getPrototypeOf(result) !== Object.prototype || key in result) {
|
|
900
|
+
definedProperty = true;
|
|
901
|
+
Object.defineProperty(result, key, {
|
|
902
|
+
value: value2,
|
|
903
|
+
enumerable: true,
|
|
904
|
+
writable: true,
|
|
905
|
+
configurable: true
|
|
906
|
+
});
|
|
907
|
+
} else result[key] = value2;
|
|
908
|
+
}
|
|
909
|
+
if (array) result.length = input.length;
|
|
910
|
+
return Object.freeze(result);
|
|
911
|
+
} finally {
|
|
912
|
+
active.delete(input);
|
|
913
|
+
}
|
|
914
|
+
}
|
|
915
|
+
return copy(value, 0);
|
|
916
|
+
}
|
|
917
|
+
|
|
918
|
+
// src/acl/output-work-ledger.ts
|
|
919
|
+
var preparation = new AsyncLocalStorage();
|
|
920
|
+
function currentOutputWorkLedger() {
|
|
921
|
+
return preparation.getStore();
|
|
922
|
+
}
|
|
923
|
+
function withOutputWorkLedger(ledger, run) {
|
|
924
|
+
if (preparation.getStore() === ledger) return run();
|
|
925
|
+
return preparation.run(ledger, run);
|
|
926
|
+
}
|
|
927
|
+
function outsideOutputWorkLedger(run) {
|
|
928
|
+
if (!preparation.getStore()) return run();
|
|
929
|
+
return preparation.run(void 0, run);
|
|
930
|
+
}
|
|
931
|
+
function debitOutputWork(ledger = currentOutputWorkLedger(), units = 1) {
|
|
932
|
+
if (!ledger) return;
|
|
933
|
+
ledger.check();
|
|
934
|
+
if (ledger.failure) throw ledger.failure;
|
|
935
|
+
if (!Number.isSafeInteger(units) || units < 0 || ledger.work + units > 2e5) {
|
|
936
|
+
ledger.failure ??= new ServiceAuthorizationError("collection output exceeds aggregate work limit");
|
|
937
|
+
ledger.fail(ledger.failure);
|
|
938
|
+
throw ledger.failure;
|
|
939
|
+
}
|
|
940
|
+
ledger.work += units;
|
|
941
|
+
}
|
|
942
|
+
function debitOutputPayload(ledger, value) {
|
|
943
|
+
if (!ledger) return;
|
|
944
|
+
ledger.check();
|
|
945
|
+
if (ledger.failure) throw ledger.failure;
|
|
946
|
+
const bytes = typeof value === "string" ? Buffer.byteLength(value, "utf8") : value;
|
|
947
|
+
if (!Number.isSafeInteger(bytes) || bytes < 0 || ledger.payload + bytes > 16 * 1024 * 1024) {
|
|
948
|
+
ledger.failure ??= new ServiceAuthorizationError("collection output exceeds payload limit");
|
|
949
|
+
ledger.fail(ledger.failure);
|
|
950
|
+
throw ledger.failure;
|
|
951
|
+
}
|
|
952
|
+
ledger.payload += bytes;
|
|
953
|
+
}
|
|
954
|
+
function prepareOutputWorkString(parts, separator = ".", ledger = currentOutputWorkLedger()) {
|
|
955
|
+
if (ledger) {
|
|
956
|
+
const bytes = parts.reduce((sum, part) => sum + Buffer.byteLength(part, "utf8"), 0) + Math.max(0, parts.length - 1) * Buffer.byteLength(separator, "utf8");
|
|
957
|
+
debitOutputPayload(ledger, bytes);
|
|
958
|
+
}
|
|
959
|
+
return parts.join(separator);
|
|
960
|
+
}
|
|
961
|
+
|
|
962
|
+
// src/acl/authorization-modes.ts
|
|
963
|
+
import { types as types5 } from "util";
|
|
964
|
+
var retiredAuthorizationOptions = [
|
|
55
965
|
"unsafeSkipListDocumentSnapshotChecks",
|
|
56
966
|
"unsafeSkipReadDocumentSnapshotChecks",
|
|
57
967
|
"unsafeSkipListOutputSnapshotChecks",
|
|
58
968
|
"unsafeSkipReadOutputSnapshotChecks",
|
|
59
969
|
"unsafeSkipListNestedDocumentSnapshotChecks",
|
|
60
|
-
"unsafeSkipReadNestedDocumentSnapshotChecks"
|
|
61
|
-
];
|
|
62
|
-
var unsafeInitialOutputCopyOptions = [
|
|
970
|
+
"unsafeSkipReadNestedDocumentSnapshotChecks",
|
|
63
971
|
"unsafeSkipListInitialOutputSnapshotCopy",
|
|
64
|
-
"unsafeSkipReadInitialOutputSnapshotCopy"
|
|
65
|
-
];
|
|
66
|
-
var unsafeSnapshotOptions = [...unsafeSnapshotCheckOptions, ...unsafeInitialOutputCopyOptions];
|
|
67
|
-
var unsafeAuthorizationFastPathOptions = [
|
|
972
|
+
"unsafeSkipReadInitialOutputSnapshotCopy",
|
|
68
973
|
"unsafeUseListAuthorizationFastPath",
|
|
69
974
|
"unsafeUseReadAuthorizationFastPath"
|
|
70
975
|
];
|
|
71
|
-
var
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
return
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
function captureAuthorizationFastPath(options, origin) {
|
|
82
|
-
const literalTrue = (key2) => {
|
|
83
|
-
const descriptor = Object.getOwnPropertyDescriptor(options, key2);
|
|
84
|
-
return !!descriptor && "value" in descriptor && descriptor.value === true;
|
|
85
|
-
};
|
|
86
|
-
const key = origin === "read" ? unsafeAuthorizationFastPathOptions[1] : unsafeAuthorizationFastPathOptions[0];
|
|
87
|
-
const requested = literalTrue(key);
|
|
88
|
-
const prerequisites = authorizationFastPathPrerequisites(origin).reduce(
|
|
89
|
-
(mask, key2, index) => mask | (literalTrue(key2) ? 1 << index : 0),
|
|
90
|
-
0
|
|
976
|
+
var authorizationModeKeys = ["readAuthorizationMode", "listAuthorizationMode"];
|
|
977
|
+
var serverAuthorizationControls = [...retiredAuthorizationOptions, ...authorizationModeKeys];
|
|
978
|
+
function authorizationControlError(key) {
|
|
979
|
+
return retiredAuthorizationOptions.includes(key) ? `${key} was removed; migrate to readAuthorizationMode/listAuthorizationMode on server model/default-model options` : `${key} is server model/default-model configuration only`;
|
|
980
|
+
}
|
|
981
|
+
function normalizeAuthorizationMode(value) {
|
|
982
|
+
if (value === void 0) return void 0;
|
|
983
|
+
if (value === "isolated" || value === "trusted") return value;
|
|
984
|
+
throw new TypeError(
|
|
985
|
+
"Authorization mode must be the literal isolated or trusted, or undefined to restore inheritance"
|
|
91
986
|
);
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
987
|
+
}
|
|
988
|
+
function assertAuthorizationModeKey(key, model) {
|
|
989
|
+
if (typeof key !== "string") throw new TypeError("Configuration option key must be a string");
|
|
990
|
+
const root = key.split(".")[0];
|
|
991
|
+
if (retiredAuthorizationOptions.includes(root))
|
|
992
|
+
throw new TypeError(authorizationControlError(root));
|
|
993
|
+
if (authorizationModeKeys.includes(root) && (!model || key !== root))
|
|
994
|
+
throw new TypeError(
|
|
995
|
+
!model ? authorizationControlError(root) : `${root} is a scalar mode; dotted setters are unsupported`
|
|
996
|
+
);
|
|
997
|
+
}
|
|
998
|
+
function admitControlPrototypes(value, reject) {
|
|
999
|
+
const owners = [];
|
|
1000
|
+
for (let owner = value; owner; owner = Object.getPrototypeOf(owner)) {
|
|
1001
|
+
if (types5.isProxy(owner)) reject("Proxy control/configuration prototype is unsupported");
|
|
1002
|
+
if (owners.length > 100) reject("Control/configuration prototype depth exceeded");
|
|
1003
|
+
owners.push(owner);
|
|
1004
|
+
}
|
|
1005
|
+
return owners;
|
|
1006
|
+
}
|
|
1007
|
+
function controlPropertyKeys(owners, reject) {
|
|
1008
|
+
const keys2 = /* @__PURE__ */ new Set();
|
|
1009
|
+
for (const owner of owners) {
|
|
1010
|
+
for (const key of Reflect.ownKeys(owner)) {
|
|
1011
|
+
if (typeof key === "string") keys2.add(key);
|
|
1012
|
+
if (keys2.size > 2e4) reject("Control/configuration keys exceed structural limits");
|
|
1013
|
+
}
|
|
1014
|
+
}
|
|
1015
|
+
return [...keys2];
|
|
1016
|
+
}
|
|
1017
|
+
function assertAuthorizationModeOptions(value, model) {
|
|
1018
|
+
const reject = (detail) => {
|
|
1019
|
+
throw new TypeError(detail);
|
|
1020
|
+
};
|
|
1021
|
+
if (!value || typeof value !== "object" || Array.isArray(value))
|
|
1022
|
+
throw new TypeError("Authorization configuration must be an options object");
|
|
1023
|
+
const owners = admitControlPrototypes(value, reject);
|
|
1024
|
+
for (const key of controlPropertyKeys(owners, reject)) {
|
|
1025
|
+
assertAuthorizationModeKey(key, model);
|
|
1026
|
+
if (!authorizationModeKeys.includes(key)) continue;
|
|
1027
|
+
const slot = Object.getOwnPropertyDescriptor(value, key);
|
|
1028
|
+
if (!slot || !("value" in slot) || !slot.enumerable)
|
|
1029
|
+
throw new TypeError(`${key} must be an own enumerable data option`);
|
|
1030
|
+
normalizeAuthorizationMode(slot.value);
|
|
1031
|
+
}
|
|
97
1032
|
}
|
|
98
1033
|
|
|
99
1034
|
// src/validation/public-admission.ts
|
|
@@ -114,10 +1049,10 @@ var privateControls = [
|
|
|
114
1049
|
"skipParsing",
|
|
115
1050
|
"skipAuthorization",
|
|
116
1051
|
"alreadyAuthorized",
|
|
117
|
-
...
|
|
1052
|
+
...serverAuthorizationControls,
|
|
118
1053
|
"operation"
|
|
119
1054
|
];
|
|
120
|
-
var PublicAdmissionError = class extends
|
|
1055
|
+
var PublicAdmissionError = class extends JsonRouter2.clientErrors.BadRequestError {
|
|
121
1056
|
constructor(detail) {
|
|
122
1057
|
const errors = [{ detail }];
|
|
123
1058
|
super("Bad Request", { errors });
|
|
@@ -156,11 +1091,12 @@ function assertPublicControlAdmission(input, kind) {
|
|
|
156
1091
|
walkControlAdmission(
|
|
157
1092
|
input,
|
|
158
1093
|
kind,
|
|
159
|
-
(
|
|
160
|
-
for (const
|
|
161
|
-
|
|
1094
|
+
(_record, path, keys2) => {
|
|
1095
|
+
for (const property of keys2) {
|
|
1096
|
+
const key = property.split(".")[0];
|
|
1097
|
+
if (privateControls.includes(key)) {
|
|
162
1098
|
throw new PublicAdmissionError(
|
|
163
|
-
|
|
1099
|
+
serverAuthorizationControls.includes(key) ? `Unsupported public control ${path}.${authorizationControlError(key)}` : `Unsupported public control ${path}.${key}; use explicit per-call internal service options for backend authorization`
|
|
164
1100
|
);
|
|
165
1101
|
}
|
|
166
1102
|
}
|
|
@@ -170,13 +1106,33 @@ function assertPublicControlAdmission(input, kind) {
|
|
|
170
1106
|
}
|
|
171
1107
|
);
|
|
172
1108
|
}
|
|
1109
|
+
function assertNoServerModelControls(input, reject, kind = "envelope") {
|
|
1110
|
+
walkControlAdmission(
|
|
1111
|
+
input,
|
|
1112
|
+
kind,
|
|
1113
|
+
(_record, path, keys2) => {
|
|
1114
|
+
for (const property of keys2) {
|
|
1115
|
+
const key = property.split(".")[0];
|
|
1116
|
+
if (serverAuthorizationControls.includes(key))
|
|
1117
|
+
reject(`${path}.${authorizationControlError(key)}`);
|
|
1118
|
+
if (key === "documentAuthorization" || key === "documentAuthorizationStage")
|
|
1119
|
+
reject(`${path}.${key} was removed; output DTOs carry no authority`);
|
|
1120
|
+
}
|
|
1121
|
+
},
|
|
1122
|
+
reject
|
|
1123
|
+
);
|
|
1124
|
+
}
|
|
173
1125
|
function walkControlAdmission(input, kind, check, reject) {
|
|
174
1126
|
const pending = [{ value: input, kind, path: "request", depth: 0 }];
|
|
175
1127
|
const seen = /* @__PURE__ */ new WeakMap();
|
|
176
1128
|
let slots = 1;
|
|
177
1129
|
while (pending.length) {
|
|
1130
|
+
debitOutputWork();
|
|
178
1131
|
const { value, kind: slot, path, depth } = pending.pop();
|
|
179
1132
|
if (!value || typeof value !== "object" && typeof value !== "function") continue;
|
|
1133
|
+
if (typeof value === "function" && (slot === "policy" || slot === "data")) continue;
|
|
1134
|
+
if (types6.isProxy(value)) reject(`unsupported proxy in control admission: ${path}`);
|
|
1135
|
+
const owners = admitControlPrototypes(value, reject);
|
|
180
1136
|
const kinds = seen.get(value) ?? /* @__PURE__ */ new Set();
|
|
181
1137
|
if (kinds.has(slot)) continue;
|
|
182
1138
|
kinds.add(slot);
|
|
@@ -187,11 +1143,29 @@ function walkControlAdmission(input, kind, check, reject) {
|
|
|
187
1143
|
pending.push({ value: child, kind: childKind, path: `${path}.${key}`, depth: depth + 1 });
|
|
188
1144
|
};
|
|
189
1145
|
const record2 = value;
|
|
190
|
-
|
|
1146
|
+
const propertyKeys = slot === "data" || slot === "policies" ? [] : controlPropertyKeys(owners, reject);
|
|
1147
|
+
debitOutputWork(void 0, propertyKeys.length);
|
|
1148
|
+
if (slot !== "data" && slot !== "policies" && slot !== "model-options") check(record2, path, propertyKeys);
|
|
1149
|
+
for (const property of propertyKeys) {
|
|
1150
|
+
const parts = property.split(".");
|
|
1151
|
+
if (parts.length < 2 || !parts.some((part) => serverAuthorizationControls.includes(part)))
|
|
1152
|
+
continue;
|
|
1153
|
+
const roots = slot === "defaults" ? defaultControlBuckets : slot === "policy" ? ["rows", "outputFields", "inputFields", "operation", "related"] : ["args", "options", "sqOptions", "include", "populate", "authorization", "defaults"];
|
|
1154
|
+
if (!roots.includes(parts[0])) continue;
|
|
1155
|
+
if (parts.length > 100) reject("control admission dotted path exceeds structural limits");
|
|
1156
|
+
const wrapper = {};
|
|
1157
|
+
let target = wrapper;
|
|
1158
|
+
for (const part of parts.slice(0, -1)) {
|
|
1159
|
+
const child = {};
|
|
1160
|
+
Object.defineProperty(target, part, { value: child, enumerable: true });
|
|
1161
|
+
target = child;
|
|
1162
|
+
}
|
|
1163
|
+
const descriptor = owners.map((owner) => Object.getOwnPropertyDescriptor(owner, property)).find(Boolean);
|
|
1164
|
+
Object.defineProperty(target, parts.at(-1), descriptor);
|
|
1165
|
+
add(wrapper, slot, property);
|
|
1166
|
+
}
|
|
191
1167
|
const read = (key) => {
|
|
192
|
-
|
|
193
|
-
for (let depth2 = 0; owner; depth2++, owner = Object.getPrototypeOf(owner)) {
|
|
194
|
-
if (depth2 > 100) reject("control admission prototype depth exceeded");
|
|
1168
|
+
for (const owner of owners) {
|
|
195
1169
|
const descriptor = Object.getOwnPropertyDescriptor(owner, key);
|
|
196
1170
|
if (!descriptor) continue;
|
|
197
1171
|
if (!("value" in descriptor)) reject(`accessor control/data property: ${path}.${key}`);
|
|
@@ -218,12 +1192,14 @@ function walkControlAdmission(input, kind, check, reject) {
|
|
|
218
1192
|
for (const key of keys2) if (key in record2) add(read(key), "envelope", key);
|
|
219
1193
|
continue;
|
|
220
1194
|
}
|
|
1195
|
+
add(read("defaults"), "defaults", "defaults");
|
|
221
1196
|
if (slot === "policies") {
|
|
222
1197
|
for (const key of Object.keys(value)) add(read(key), "policy", key);
|
|
223
1198
|
continue;
|
|
224
1199
|
}
|
|
225
1200
|
if (slot === "policy") {
|
|
226
|
-
for (const key of ["rows", "outputFields", "inputFields", "operation"
|
|
1201
|
+
for (const key of ["rows", "outputFields", "inputFields", "operation", "parent", "child", "visibility"])
|
|
1202
|
+
add(read(key), "policy", key);
|
|
227
1203
|
add(read("related"), "policies", "related");
|
|
228
1204
|
add(read("filter"), "data", "filter");
|
|
229
1205
|
continue;
|
|
@@ -232,7 +1208,9 @@ function walkControlAdmission(input, kind, check, reject) {
|
|
|
232
1208
|
add(read("include"), "include", "include");
|
|
233
1209
|
add(read("populate"), "populate", "populate");
|
|
234
1210
|
add(read("authorization"), "policy", "authorization");
|
|
235
|
-
|
|
1211
|
+
add(read("operationAccess"), "policy", "operationAccess");
|
|
1212
|
+
for (const key of slot === "data-options" ? ["filter", "match"] : ["filter", "match", "data"])
|
|
1213
|
+
add(read(key), "data", key);
|
|
236
1214
|
}
|
|
237
1215
|
}
|
|
238
1216
|
function assertHydrationDefaults(defaults2) {
|
|
@@ -327,7 +1305,7 @@ import mschema2Jsonschema from "mongoose-schema-jsonschema";
|
|
|
327
1305
|
import {
|
|
328
1306
|
addLeadingSlash,
|
|
329
1307
|
forEach as forEach2,
|
|
330
|
-
get as
|
|
1308
|
+
get as get4,
|
|
331
1309
|
isArray as isArray4,
|
|
332
1310
|
isBoolean,
|
|
333
1311
|
isFunction as isFunction2,
|
|
@@ -767,7 +1745,7 @@ var defaultLogger = createLogger({
|
|
|
767
1745
|
});
|
|
768
1746
|
|
|
769
1747
|
// src/options/manager.ts
|
|
770
|
-
import { assign, get, isPlainObject as isPlainObject8, set } from "@web-ts-toolkit/utils";
|
|
1748
|
+
import { assign, get as get2, isPlainObject as isPlainObject8, set } from "@web-ts-toolkit/utils";
|
|
771
1749
|
var toPath = (key) => {
|
|
772
1750
|
if (Array.isArray(key)) return key;
|
|
773
1751
|
return typeof key === "string" ? key.split(".") : [key];
|
|
@@ -875,7 +1853,7 @@ var OptionsManager = class {
|
|
|
875
1853
|
return this;
|
|
876
1854
|
}
|
|
877
1855
|
get(key, defaultValue) {
|
|
878
|
-
return
|
|
1856
|
+
return get2(this.currentOptions, key, defaultValue);
|
|
879
1857
|
}
|
|
880
1858
|
set(key, value) {
|
|
881
1859
|
const path = toPath(key);
|
|
@@ -884,7 +1862,7 @@ var OptionsManager = class {
|
|
|
884
1862
|
return;
|
|
885
1863
|
}
|
|
886
1864
|
const [rootKey, ...nestedPath] = path;
|
|
887
|
-
const currentRoot =
|
|
1865
|
+
const currentRoot = get2(this.currentOptions, [rootKey], void 0);
|
|
888
1866
|
const baseRoot = isPlainObject8(currentRoot) ? currentRoot : {};
|
|
889
1867
|
const nextRoot = cloneConfigValue(baseRoot);
|
|
890
1868
|
set(nextRoot, nestedPath, cloneForRead(value));
|
|
@@ -943,7 +1921,7 @@ var OptionsManager = class {
|
|
|
943
1921
|
import { set as set2 } from "@web-ts-toolkit/utils";
|
|
944
1922
|
|
|
945
1923
|
// src/options/data-values.ts
|
|
946
|
-
import { types } from "util";
|
|
1924
|
+
import { types as types7 } from "util";
|
|
947
1925
|
var typedArrays = [
|
|
948
1926
|
Int8Array,
|
|
949
1927
|
Uint8Array,
|
|
@@ -973,7 +1951,7 @@ var assertNativeProperties = (value, path, allowed = () => false) => {
|
|
|
973
1951
|
}
|
|
974
1952
|
};
|
|
975
1953
|
var copyBytes = (buffer, path, start = 0, end) => {
|
|
976
|
-
if (!
|
|
1954
|
+
if (!types7.isArrayBuffer(buffer) || Object.getPrototypeOf(buffer) !== ArrayBuffer.prototype) {
|
|
977
1955
|
return unsupported(path, "binary storage must be a fixed, non-shared ArrayBuffer");
|
|
978
1956
|
}
|
|
979
1957
|
assertNativeProperties(buffer, path);
|
|
@@ -994,7 +1972,7 @@ function copyValue(input, freezePlain, rootPath) {
|
|
|
994
1972
|
return unsupported(path, `${typeof value} values are not supported`);
|
|
995
1973
|
}
|
|
996
1974
|
if (value === null || typeof value !== "object") return value;
|
|
997
|
-
if (
|
|
1975
|
+
if (types7.isProxy(value)) return unsupported(path, "proxies are not supported");
|
|
998
1976
|
if (active.has(value)) return unsupported(path, "cycles are not supported");
|
|
999
1977
|
const previous = copies.get(value);
|
|
1000
1978
|
if (previous) return previous;
|
|
@@ -1015,10 +1993,10 @@ function copyValue(input, freezePlain, rootPath) {
|
|
|
1015
1993
|
return freezePlain ? Object.freeze(output2) : output2;
|
|
1016
1994
|
}
|
|
1017
1995
|
let output;
|
|
1018
|
-
if (prototype === Date.prototype &&
|
|
1996
|
+
if (prototype === Date.prototype && types7.isDate(value)) {
|
|
1019
1997
|
assertNativeProperties(value, path);
|
|
1020
1998
|
output = new Date(Date.prototype.getTime.call(value));
|
|
1021
|
-
} else if (prototype === Map.prototype &&
|
|
1999
|
+
} else if (prototype === Map.prototype && types7.isMap(value)) {
|
|
1022
2000
|
assertNativeProperties(value, path);
|
|
1023
2001
|
const map = /* @__PURE__ */ new Map();
|
|
1024
2002
|
copies.set(value, map);
|
|
@@ -1028,7 +2006,7 @@ function copyValue(input, freezePlain, rootPath) {
|
|
|
1028
2006
|
index += 1;
|
|
1029
2007
|
}
|
|
1030
2008
|
output = map;
|
|
1031
|
-
} else if (prototype === Set.prototype &&
|
|
2009
|
+
} else if (prototype === Set.prototype && types7.isSet(value)) {
|
|
1032
2010
|
assertNativeProperties(value, path);
|
|
1033
2011
|
const set4 = /* @__PURE__ */ new Set();
|
|
1034
2012
|
copies.set(value, set4);
|
|
@@ -1038,7 +2016,7 @@ function copyValue(input, freezePlain, rootPath) {
|
|
|
1038
2016
|
index += 1;
|
|
1039
2017
|
}
|
|
1040
2018
|
output = set4;
|
|
1041
|
-
} else if (prototype === RegExp.prototype &&
|
|
2019
|
+
} else if (prototype === RegExp.prototype && types7.isRegExp(value)) {
|
|
1042
2020
|
assertNativeProperties(value, path, (key) => key === "lastIndex");
|
|
1043
2021
|
const regexp = value;
|
|
1044
2022
|
if (typeof regexp.lastIndex !== "number") return unsupported(path, "RegExp.lastIndex must be a number");
|
|
@@ -1115,7 +2093,7 @@ var emptyDataSnapshot = Object.freeze([]);
|
|
|
1115
2093
|
var ownedSnapshots = new WeakMap([[emptyDataSnapshot, emptyDataSnapshot]]);
|
|
1116
2094
|
function createDataSnapshot(data) {
|
|
1117
2095
|
if (data === void 0) return void 0;
|
|
1118
|
-
if (!Array.isArray(data) ||
|
|
2096
|
+
if (!Array.isArray(data) || types7.isProxy(data) || Object.getPrototypeOf(data) !== Array.prototype) {
|
|
1119
2097
|
return unsupported("data", "expected an ordinary array or undefined");
|
|
1120
2098
|
}
|
|
1121
2099
|
if (ownedSnapshots.has(data)) return data;
|
|
@@ -1315,230 +2293,14 @@ function resolveSnapshotDescriptor(scopeVirtuals, virtualName, access) {
|
|
|
1315
2293
|
}
|
|
1316
2294
|
|
|
1317
2295
|
// src/acl/virtual-populate-dependencies.ts
|
|
1318
|
-
import { get as
|
|
1319
|
-
|
|
1320
|
-
// src/acl/authorization-snapshot.ts
|
|
1321
|
-
import { isDeepStrictEqual, types as types2 } from "util";
|
|
1322
|
-
import { Buffer as NodeBuffer } from "buffer";
|
|
1323
|
-
import { mongo } from "mongoose";
|
|
1324
|
-
import JsonRouter2 from "@web-ts-toolkit/express-json-router";
|
|
1325
|
-
var ServiceAuthorizationError = class extends JsonRouter2.clientErrors.BadRequestError {
|
|
1326
|
-
constructor(detail) {
|
|
1327
|
-
const errors = [{ detail: `Service authorization: ${detail}` }];
|
|
1328
|
-
super("Bad Request", { errors });
|
|
1329
|
-
this.result = { success: false, kind: "error", code: "bad_request" /* BadRequest */, errors };
|
|
1330
|
-
}
|
|
1331
|
-
};
|
|
1332
|
-
function authorizationError(detail) {
|
|
1333
|
-
throw new ServiceAuthorizationError(detail);
|
|
1334
|
-
}
|
|
1335
|
-
var unsafeKeys = /* @__PURE__ */ new Set(["__proto__", "constructor", "prototype"]);
|
|
1336
|
-
function authorizationRecord(value, label) {
|
|
1337
|
-
if (!value || typeof value !== "object" || Object.getPrototypeOf(value) !== Object.prototype && Object.getPrototypeOf(value) !== null) {
|
|
1338
|
-
authorizationError(`${label} must be a plain object`);
|
|
1339
|
-
}
|
|
1340
|
-
return value;
|
|
1341
|
-
}
|
|
1342
|
-
function copyAuthorizationValue(value, configuration = false) {
|
|
1343
|
-
const active = /* @__PURE__ */ new WeakSet();
|
|
1344
|
-
let nodes = 0;
|
|
1345
|
-
function copy(input, depth) {
|
|
1346
|
-
if (++nodes > 2e4 || depth > 100) authorizationError("snapshot exceeds structural limits");
|
|
1347
|
-
if (typeof input === "function") {
|
|
1348
|
-
if (configuration === true) return input;
|
|
1349
|
-
authorizationError("functions are not policy values");
|
|
1350
|
-
}
|
|
1351
|
-
if (typeof input === "symbol") authorizationError("symbols are not policy values");
|
|
1352
|
-
if (input === null || typeof input !== "object") return input;
|
|
1353
|
-
if (active.has(input)) authorizationError("cyclic input");
|
|
1354
|
-
active.add(input);
|
|
1355
|
-
try {
|
|
1356
|
-
if (input instanceof Date) return new Date(input.getTime());
|
|
1357
|
-
if (Buffer.isBuffer(input)) return Buffer.from(input);
|
|
1358
|
-
if (input instanceof RegExp) {
|
|
1359
|
-
const result2 = new RegExp(input.source, input.flags);
|
|
1360
|
-
result2.lastIndex = input.lastIndex;
|
|
1361
|
-
return result2;
|
|
1362
|
-
}
|
|
1363
|
-
if (input instanceof mongo.BSON.BSONValue) {
|
|
1364
|
-
try {
|
|
1365
|
-
return mongo.BSON.deserialize(mongo.BSON.serialize({ value: input }), {
|
|
1366
|
-
promoteValues: false,
|
|
1367
|
-
bsonRegExp: true
|
|
1368
|
-
}).value;
|
|
1369
|
-
} catch {
|
|
1370
|
-
authorizationError("unsupported BSON snapshot");
|
|
1371
|
-
}
|
|
1372
|
-
}
|
|
1373
|
-
if (configuration && input instanceof Map) {
|
|
1374
|
-
return new Map([...input].map(([key, entry]) => [copy(key, depth + 1), copy(entry, depth + 1)]));
|
|
1375
|
-
}
|
|
1376
|
-
if (configuration && input instanceof Set) return new Set([...input].map((entry) => copy(entry, depth + 1)));
|
|
1377
|
-
const array = Array.isArray(input);
|
|
1378
|
-
if (array && input.length > 2e4) authorizationError("snapshot array exceeds structural limits");
|
|
1379
|
-
if (!array) authorizationRecord(input, "snapshot");
|
|
1380
|
-
const result = array ? [] : {};
|
|
1381
|
-
let definedProperty = false;
|
|
1382
|
-
for (const key of Reflect.ownKeys(input)) {
|
|
1383
|
-
if (array && key === "length") continue;
|
|
1384
|
-
if (typeof key !== "string" || unsafeKeys.has(key)) authorizationError("unsafe snapshot key");
|
|
1385
|
-
if (array && !/^(0|[1-9]\d*)$/.test(key)) authorizationError("invalid array property");
|
|
1386
|
-
const descriptor = Object.getOwnPropertyDescriptor(input, key);
|
|
1387
|
-
if (!("value" in descriptor) || !descriptor.enumerable && configuration !== "document")
|
|
1388
|
-
authorizationError("accessor/non-enumerable input");
|
|
1389
|
-
const value2 = copy(descriptor.value, depth + 1);
|
|
1390
|
-
if (array || definedProperty && Object.getPrototypeOf(result) !== Object.prototype || key in result) {
|
|
1391
|
-
definedProperty = true;
|
|
1392
|
-
Object.defineProperty(result, key, {
|
|
1393
|
-
value: value2,
|
|
1394
|
-
enumerable: true,
|
|
1395
|
-
writable: true,
|
|
1396
|
-
configurable: true
|
|
1397
|
-
});
|
|
1398
|
-
} else result[key] = value2;
|
|
1399
|
-
}
|
|
1400
|
-
if (array) result.length = input.length;
|
|
1401
|
-
return Object.freeze(result);
|
|
1402
|
-
} finally {
|
|
1403
|
-
active.delete(input);
|
|
1404
|
-
}
|
|
1405
|
-
}
|
|
1406
|
-
return copy(value, 0);
|
|
1407
|
-
}
|
|
1408
|
-
|
|
1409
|
-
// src/acl/field-catalog.ts
|
|
1410
|
-
import { types as types3 } from "util";
|
|
1411
|
-
var safeSegment = (part) => !!part && part !== "sub" && !["__proto__", "constructor", "prototype", "_doc", "__v"].includes(part) && !/^[+$-]|[\s*]/.test(part) && !part.includes("[") && !part.includes("]") && !/^\d+$/.test(part) && ![...part].some((character) => character.charCodeAt(0) < 32 || character.charCodeAt(0) === 127);
|
|
1412
|
-
var isSafeOutputPath = (path) => path.split(".").every(safeSegment);
|
|
1413
|
-
var inputControlSegments = /* @__PURE__ */ new Set([
|
|
1414
|
-
"_permissions",
|
|
1415
|
-
"_view",
|
|
1416
|
-
"_edit",
|
|
1417
|
-
"documentAuthorization",
|
|
1418
|
-
"documentAuthorizationStage",
|
|
1419
|
-
"resolvedAuthorization",
|
|
1420
|
-
"execution",
|
|
1421
|
-
"executionContext",
|
|
1422
|
-
"serviceExecutionContext",
|
|
1423
|
-
"preparedQuery",
|
|
1424
|
-
"preparedFilter",
|
|
1425
|
-
"preparedModelQuery",
|
|
1426
|
-
"resolvedIdentifier",
|
|
1427
|
-
"skipParsing",
|
|
1428
|
-
"skipAuthorization",
|
|
1429
|
-
"alreadyAuthorized"
|
|
1430
|
-
]);
|
|
1431
|
-
function isSafeInputPath(path, requestIdentity = false) {
|
|
1432
|
-
return isSafeOutputPath(path) && path.split(".").every((part) => !inputControlSegments.has(part) && (requestIdentity || part !== "_id"));
|
|
1433
|
-
}
|
|
1434
|
-
function matchesCatalogPattern(pattern, path, descendants = false) {
|
|
1435
|
-
if (typeof pattern === "string" && typeof path === "string" && !pattern.includes("$*")) {
|
|
1436
|
-
return pattern === path || !!descendants && path.startsWith(pattern) && path[pattern.length] === ".";
|
|
1437
|
-
}
|
|
1438
|
-
const expected = pattern.split(".");
|
|
1439
|
-
const actual = path.split(".");
|
|
1440
|
-
return (descendants ? actual.length >= expected.length : actual.length === expected.length) && expected.every((part, index) => part === "$*" || part === actual[index]);
|
|
1441
|
-
}
|
|
1442
|
-
function captureAuthorizationFieldCatalog(schema, virtuals, documentPermissionField = "_permissions") {
|
|
1443
|
-
const paths = /* @__PURE__ */ new Set();
|
|
1444
|
-
const containers = /* @__PURE__ */ new Set();
|
|
1445
|
-
const opaque = /* @__PURE__ */ new Set();
|
|
1446
|
-
const references = /* @__PURE__ */ new Set();
|
|
1447
|
-
const virtualPaths = /* @__PURE__ */ new Set();
|
|
1448
|
-
const virtualScopes = /* @__PURE__ */ new Set();
|
|
1449
|
-
const schemaVirtualPaths = /* @__PURE__ */ new Set();
|
|
1450
|
-
const arrays = /* @__PURE__ */ new Set();
|
|
1451
|
-
const protectedPaths = /* @__PURE__ */ new Set([documentPermissionField, "_doc", "$__", "__v"]);
|
|
1452
|
-
const add = (path) => {
|
|
1453
|
-
if (path.split(".").every((part) => part === "$*" || safeSegment(part))) paths.add(path);
|
|
1454
|
-
};
|
|
1455
|
-
const ancestors = (path) => {
|
|
1456
|
-
const parts = path.split(".");
|
|
1457
|
-
for (let n = 1; n < parts.length; n++) {
|
|
1458
|
-
const parent = parts.slice(0, n).join(".");
|
|
1459
|
-
add(parent);
|
|
1460
|
-
containers.add(parent);
|
|
1461
|
-
}
|
|
1462
|
-
};
|
|
1463
|
-
const visitType = (type, path, active) => {
|
|
1464
|
-
add(path);
|
|
1465
|
-
ancestors(path);
|
|
1466
|
-
const element = type.$embeddedSchemaType ?? type.embeddedSchemaType ?? type.caster;
|
|
1467
|
-
if (type.instance === "Array" || type.$isMongooseDocumentArray) arrays.add(path);
|
|
1468
|
-
if (type.options?.ref || type.options?.refPath || element?.options?.ref || element?.options?.refPath) {
|
|
1469
|
-
references.add(path);
|
|
1470
|
-
return;
|
|
1471
|
-
}
|
|
1472
|
-
if (type.$isSchemaMap || type.instance === "Map") {
|
|
1473
|
-
const value = type.$__schemaType;
|
|
1474
|
-
if (value) visitType(value, `${path}.$*`, active);
|
|
1475
|
-
else opaque.add(path);
|
|
1476
|
-
containers.delete(path);
|
|
1477
|
-
return;
|
|
1478
|
-
}
|
|
1479
|
-
const child = type.schema ?? element?.schema;
|
|
1480
|
-
if (child) {
|
|
1481
|
-
containers.add(path);
|
|
1482
|
-
if (!active.has(child)) visitSchema(child, path, /* @__PURE__ */ new Set([...active, child]));
|
|
1483
|
-
return;
|
|
1484
|
-
}
|
|
1485
|
-
if (type.instance === "Mixed" || element?.instance === "Mixed") opaque.add(path);
|
|
1486
|
-
};
|
|
1487
|
-
const visitSchema = (current, prefix, active) => {
|
|
1488
|
-
const version = current.options.versionKey;
|
|
1489
|
-
if (typeof version === "string") protectedPaths.add(prefix ? `${prefix}.${version}` : version);
|
|
1490
|
-
for (const name of Object.keys(current.virtuals)) {
|
|
1491
|
-
schemaVirtualPaths.add(prefix ? `${prefix}.${name}` : name);
|
|
1492
|
-
}
|
|
1493
|
-
for (const [name, raw] of Object.entries(current.paths)) {
|
|
1494
|
-
if (name.includes("$*")) continue;
|
|
1495
|
-
visitType(raw, prefix ? `${prefix}.${name}` : name, active);
|
|
1496
|
-
}
|
|
1497
|
-
};
|
|
1498
|
-
visitSchema(schema, "", /* @__PURE__ */ new Set([schema]));
|
|
1499
|
-
const persistedPaths = [...paths];
|
|
1500
|
-
const visitVirtuals = (record2, prefix) => {
|
|
1501
|
-
for (const [name, value] of Object.entries(record2 ?? {})) {
|
|
1502
|
-
if (value === void 0) continue;
|
|
1503
|
-
const path = prefix ? `${prefix}.${name}` : name;
|
|
1504
|
-
if (!isSafeOutputPath(path)) continue;
|
|
1505
|
-
if (value && typeof value === "object" && "sub" in value) {
|
|
1506
|
-
if (references.has(path)) continue;
|
|
1507
|
-
virtualScopes.add(path);
|
|
1508
|
-
add(path);
|
|
1509
|
-
containers.add(path);
|
|
1510
|
-
visitVirtuals(value.sub, path);
|
|
1511
|
-
} else {
|
|
1512
|
-
add(path);
|
|
1513
|
-
ancestors(path);
|
|
1514
|
-
virtualPaths.add(path);
|
|
1515
|
-
}
|
|
1516
|
-
}
|
|
1517
|
-
};
|
|
1518
|
-
visitVirtuals(virtuals, "");
|
|
1519
|
-
const eligible = [...paths].filter((p) => ![...protectedPaths].some((v) => matchesCatalogPattern(v, p, true)));
|
|
1520
|
-
return Object.freeze({
|
|
1521
|
-
paths: Object.freeze(eligible.filter((p) => !p.includes("$*"))),
|
|
1522
|
-
persistedPaths: Object.freeze(persistedPaths),
|
|
1523
|
-
arrayPaths: Object.freeze([...arrays]),
|
|
1524
|
-
schemaVirtualPaths: Object.freeze([...schemaVirtualPaths]),
|
|
1525
|
-
metadataPaths: Object.freeze([documentPermissionField]),
|
|
1526
|
-
dynamicPaths: Object.freeze(eligible.filter((p) => p.includes("$*"))),
|
|
1527
|
-
containerPaths: Object.freeze([...containers]),
|
|
1528
|
-
opaquePaths: Object.freeze([...opaque]),
|
|
1529
|
-
referencePaths: Object.freeze([...references]),
|
|
1530
|
-
virtualPaths: Object.freeze([...virtualPaths]),
|
|
1531
|
-
virtualScopePaths: Object.freeze([...virtualScopes]),
|
|
1532
|
-
protectedPaths: Object.freeze([...protectedPaths])
|
|
1533
|
-
});
|
|
1534
|
-
}
|
|
2296
|
+
import { get as get3, isPlainObject as isPlainObject12 } from "@web-ts-toolkit/utils";
|
|
1535
2297
|
|
|
1536
2298
|
// src/acl/populate-target-configuration.ts
|
|
1537
2299
|
import { isPlainObject as isPlainObject11 } from "@web-ts-toolkit/utils";
|
|
1538
2300
|
|
|
1539
2301
|
// src/runtime-context.ts
|
|
1540
|
-
import { AsyncLocalStorage } from "async_hooks";
|
|
1541
|
-
var runtimeStorage = new
|
|
2302
|
+
import { AsyncLocalStorage as AsyncLocalStorage2 } from "async_hooks";
|
|
2303
|
+
var runtimeStorage = new AsyncLocalStorage2();
|
|
1542
2304
|
function getActiveRuntime() {
|
|
1543
2305
|
return runtimeStorage.getStore() ?? null;
|
|
1544
2306
|
}
|
|
@@ -1733,7 +2495,7 @@ function captureVirtualPopulateDependencies(runtime, modelName, options, populat
|
|
|
1733
2495
|
proposed?.defaults
|
|
1734
2496
|
);
|
|
1735
2497
|
const defaults2 = proposed?.defaults ?? runtime.getDefaultModelOptions();
|
|
1736
|
-
const readOption = (key) => resolveNestedOption((path2, fallback) =>
|
|
2498
|
+
const readOption = (key) => resolveNestedOption((path2, fallback) => get3(targetOptions, path2, fallback), key, get3(defaults2, key));
|
|
1737
2499
|
const documentPermissionField = targetOptions.documentPermissionField ?? defaults2.documentPermissionField;
|
|
1738
2500
|
const catalog = captureAuthorizationFieldCatalog(targetModel.schema, void 0, documentPermissionField);
|
|
1739
2501
|
const configuration = copyAuthorizationValue(
|
|
@@ -1842,7 +2604,6 @@ var modelOverrides = (options) => {
|
|
|
1842
2604
|
([key, value]) => value !== void 0 || key === "operationAccess" || isPopulatePolicyKey(key)
|
|
1843
2605
|
)
|
|
1844
2606
|
);
|
|
1845
|
-
for (const key of unsafeServerOptions) if (key in result) result[key] = result[key] === true;
|
|
1846
2607
|
return cloneOptionsSnapshot(result);
|
|
1847
2608
|
};
|
|
1848
2609
|
var defaultDataOptions = {
|
|
@@ -1926,8 +2687,8 @@ var virtualFullPath = (prefix, name) => prefix ? `${prefix}.${name}` : name;
|
|
|
1926
2687
|
var virtualPathsOverlap = (virtualPath, permissionField) => {
|
|
1927
2688
|
if (!virtualPath || !permissionField) return false;
|
|
1928
2689
|
try {
|
|
1929
|
-
if (
|
|
1930
|
-
if (
|
|
2690
|
+
if (get4(set3({}, virtualPath, true), permissionField) !== void 0) return true;
|
|
2691
|
+
if (get4(set3({}, permissionField, true), virtualPath) !== void 0) return true;
|
|
1931
2692
|
} catch {
|
|
1932
2693
|
return false;
|
|
1933
2694
|
}
|
|
@@ -2196,19 +2957,12 @@ var AccessRuntime = class {
|
|
|
2196
2957
|
requireOperationAccessForPopulateQueries: true,
|
|
2197
2958
|
requireOperationAccessForPopulateDependencies: true,
|
|
2198
2959
|
modelPermissionPrefix: "",
|
|
2199
|
-
|
|
2200
|
-
|
|
2201
|
-
unsafeSkipListOutputSnapshotChecks: false,
|
|
2202
|
-
unsafeSkipReadOutputSnapshotChecks: false,
|
|
2203
|
-
unsafeSkipListNestedDocumentSnapshotChecks: false,
|
|
2204
|
-
unsafeSkipReadNestedDocumentSnapshotChecks: false,
|
|
2205
|
-
unsafeSkipListInitialOutputSnapshotCopy: false,
|
|
2206
|
-
unsafeSkipReadInitialOutputSnapshotCopy: false,
|
|
2207
|
-
unsafeUseListAuthorizationFastPath: false,
|
|
2208
|
-
unsafeUseReadAuthorizationFastPath: false
|
|
2960
|
+
readAuthorizationMode: "isolated",
|
|
2961
|
+
listAuthorizationMode: "isolated"
|
|
2209
2962
|
}).build();
|
|
2210
2963
|
this.modelOptions = {};
|
|
2211
2964
|
this.modelOptionOverrides = {};
|
|
2965
|
+
this.publishingAuthorizationModes = false;
|
|
2212
2966
|
this.modelJsonSchemas = {};
|
|
2213
2967
|
this.dataOptions = {};
|
|
2214
2968
|
this.modelRefs = {};
|
|
@@ -2217,6 +2971,10 @@ var AccessRuntime = class {
|
|
|
2217
2971
|
this.modelInstances = {};
|
|
2218
2972
|
this.openApiRegistry = new OpenApiRegistry();
|
|
2219
2973
|
this.openApiPathPrefix = "";
|
|
2974
|
+
assertAuthorizationModeOptions(options, false);
|
|
2975
|
+
assertNoServerModelControls(options, (detail) => {
|
|
2976
|
+
throw new TypeError(detail);
|
|
2977
|
+
});
|
|
2220
2978
|
this.allowGlobalModelLookup = options.allowGlobalModelLookup ?? false;
|
|
2221
2979
|
ensureMongooseJsonSchemaInitialized();
|
|
2222
2980
|
}
|
|
@@ -2309,6 +3067,49 @@ var AccessRuntime = class {
|
|
|
2309
3067
|
};
|
|
2310
3068
|
}
|
|
2311
3069
|
restoreBootstrapSnapshot(snapshot) {
|
|
3070
|
+
assertAuthorizationModeOptions(snapshot, false);
|
|
3071
|
+
const reject = (detail) => {
|
|
3072
|
+
throw new TypeError(detail);
|
|
3073
|
+
};
|
|
3074
|
+
for (const key of [
|
|
3075
|
+
"globalOptions",
|
|
3076
|
+
"defaultModelOptions",
|
|
3077
|
+
"modelOptions",
|
|
3078
|
+
"modelOptionOverrides",
|
|
3079
|
+
"dataOptions",
|
|
3080
|
+
"modelInstances",
|
|
3081
|
+
"modelJsonSchemas",
|
|
3082
|
+
"modelRefs",
|
|
3083
|
+
"modelSubs",
|
|
3084
|
+
"modelAtts",
|
|
3085
|
+
"openApi"
|
|
3086
|
+
]) {
|
|
3087
|
+
const slot = Object.getOwnPropertyDescriptor(snapshot, key);
|
|
3088
|
+
if (!slot || !("value" in slot) || !slot.enumerable) reject(`Invalid bootstrap snapshot slot: ${key}`);
|
|
3089
|
+
if (!slot.value || typeof slot.value !== "object" || Array.isArray(slot.value))
|
|
3090
|
+
reject(`Invalid bootstrap snapshot object: ${key}`);
|
|
3091
|
+
admitControlPrototypes(slot.value, reject);
|
|
3092
|
+
if (key === "globalOptions" || key === "defaultModelOptions" || key === "openApi") continue;
|
|
3093
|
+
for (const entry of Reflect.ownKeys(slot.value)) {
|
|
3094
|
+
const item = Object.getOwnPropertyDescriptor(slot.value, entry);
|
|
3095
|
+
if (typeof entry !== "string" || !("value" in item) || !item.enumerable)
|
|
3096
|
+
reject(`Invalid bootstrap snapshot entry: ${key}`);
|
|
3097
|
+
}
|
|
3098
|
+
}
|
|
3099
|
+
assertAuthorizationModeOptions(snapshot.globalOptions, false);
|
|
3100
|
+
assertNoServerModelControls(snapshot.globalOptions, reject);
|
|
3101
|
+
assertAuthorizationModeOptions(snapshot.defaultModelOptions, true);
|
|
3102
|
+
assertNoServerModelControls(snapshot.defaultModelOptions, reject, "model-options");
|
|
3103
|
+
assertPublicDefaults(snapshot.defaultModelOptions.defaults);
|
|
3104
|
+
for (const options of [...Object.values(snapshot.modelOptions), ...Object.values(snapshot.modelOptionOverrides)]) {
|
|
3105
|
+
assertAuthorizationModeOptions(options, true);
|
|
3106
|
+
assertNoServerModelControls(options, reject, "model-options");
|
|
3107
|
+
assertPublicDefaults(options.defaults);
|
|
3108
|
+
}
|
|
3109
|
+
for (const options of Object.values(snapshot.dataOptions)) {
|
|
3110
|
+
assertAuthorizationModeOptions(options, false);
|
|
3111
|
+
assertNoServerModelControls(options, reject, "data-options");
|
|
3112
|
+
}
|
|
2312
3113
|
this.globalOptions.restore(snapshot.globalOptions);
|
|
2313
3114
|
this.defaultModelOptions.restore(snapshot.defaultModelOptions);
|
|
2314
3115
|
for (const name of Object.keys(this.modelOptionOverrides)) delete this.modelOptionOverrides[name];
|
|
@@ -2368,11 +3169,21 @@ var AccessRuntime = class {
|
|
|
2368
3169
|
}
|
|
2369
3170
|
/** Shallowly replace supplied global values; nested objects such as requestComplexity are not deep-merged. */
|
|
2370
3171
|
setGlobalOptions(options) {
|
|
3172
|
+
assertAuthorizationModeOptions(options, false);
|
|
3173
|
+
assertNoServerModelControls(options, (detail) => {
|
|
3174
|
+
throw new TypeError(detail);
|
|
3175
|
+
});
|
|
2371
3176
|
for (const key of populatePolicyKeys) if (key in options) assertNoGlobalPopulatePolicy(key);
|
|
2372
3177
|
this.globalOptions.assign({ ...options });
|
|
2373
3178
|
}
|
|
2374
3179
|
setGlobalOption(key, value) {
|
|
3180
|
+
assertAuthorizationModeKey(key, false);
|
|
2375
3181
|
assertNoGlobalPopulatePolicy(String(key));
|
|
3182
|
+
const proposed = {};
|
|
3183
|
+
set3(proposed, key, value);
|
|
3184
|
+
assertNoServerModelControls(proposed, (detail) => {
|
|
3185
|
+
throw new TypeError(detail);
|
|
3186
|
+
});
|
|
2376
3187
|
this.globalOptions.set(key, value);
|
|
2377
3188
|
}
|
|
2378
3189
|
getGlobalOptions() {
|
|
@@ -2383,6 +3194,17 @@ var AccessRuntime = class {
|
|
|
2383
3194
|
}
|
|
2384
3195
|
/** Update inherited model defaults shallowly. Explicit model values and captured calls are unchanged. */
|
|
2385
3196
|
setDefaultModelOptions(options) {
|
|
3197
|
+
assertAuthorizationModeOptions(options, true);
|
|
3198
|
+
assertNoServerModelControls(
|
|
3199
|
+
options,
|
|
3200
|
+
(detail) => {
|
|
3201
|
+
throw new TypeError(detail);
|
|
3202
|
+
},
|
|
3203
|
+
"model-options"
|
|
3204
|
+
);
|
|
3205
|
+
options = { ...options };
|
|
3206
|
+
for (const key of authorizationModeKeys)
|
|
3207
|
+
if (key in options && options[key] === void 0) options[key] = "isolated";
|
|
2386
3208
|
assertPublicDefaults(options.defaults);
|
|
2387
3209
|
if ("hydration" in options) options = { ...options, hydration: normalizeHydration(options.hydration) };
|
|
2388
3210
|
const draft = new OptionsManager(
|
|
@@ -2392,11 +3214,31 @@ var AccessRuntime = class {
|
|
|
2392
3214
|
this.publishDefaultModelOptions(draft.fetch());
|
|
2393
3215
|
}
|
|
2394
3216
|
setDefaultModelOption(key, value) {
|
|
2395
|
-
|
|
2396
|
-
|
|
2397
|
-
|
|
3217
|
+
assertAuthorizationModeKey(key, true);
|
|
3218
|
+
const keyStr = key;
|
|
3219
|
+
if (authorizationModeKeys.includes(keyStr)) {
|
|
3220
|
+
this.setDefaultModelOptions({ [keyStr]: value });
|
|
3221
|
+
return;
|
|
3222
|
+
}
|
|
3223
|
+
if (keyStr === "defaults") {
|
|
3224
|
+
assertNoServerModelControls(
|
|
3225
|
+
value,
|
|
3226
|
+
(detail) => {
|
|
3227
|
+
throw new TypeError(detail);
|
|
3228
|
+
},
|
|
3229
|
+
"defaults"
|
|
3230
|
+
);
|
|
3231
|
+
assertPublicDefaults(value);
|
|
3232
|
+
} else if (keyStr.startsWith("defaults.")) {
|
|
2398
3233
|
const proposed = {};
|
|
2399
3234
|
set3(proposed, keyStr.slice("defaults.".length), value);
|
|
3235
|
+
assertNoServerModelControls(
|
|
3236
|
+
proposed,
|
|
3237
|
+
(detail) => {
|
|
3238
|
+
throw new TypeError(detail);
|
|
3239
|
+
},
|
|
3240
|
+
"defaults"
|
|
3241
|
+
);
|
|
2400
3242
|
assertPublicDefaults(proposed);
|
|
2401
3243
|
}
|
|
2402
3244
|
const draft = new OptionsManager(
|
|
@@ -2423,7 +3265,6 @@ var AccessRuntime = class {
|
|
|
2423
3265
|
for (const key of populatePolicyKeys) delete inherited[key];
|
|
2424
3266
|
const effective = { ...defaultModelOptions, ...inherited, ...overrides, modelName };
|
|
2425
3267
|
effective.basePath = normalizeBasePath(modelName, effective.basePath);
|
|
2426
|
-
for (const key of unsafeServerOptions) effective[key] = effective[key] === true;
|
|
2427
3268
|
refreshPermissionMetadata(effective);
|
|
2428
3269
|
return cloneOptionsSnapshot(effective);
|
|
2429
3270
|
}
|
|
@@ -2438,77 +3279,43 @@ var AccessRuntime = class {
|
|
|
2438
3279
|
}
|
|
2439
3280
|
publishDefaultModelOptions(options) {
|
|
2440
3281
|
const next = { ...options };
|
|
2441
|
-
for (const key of unsafeServerOptions) if (key in next) next[key] = next[key] === true;
|
|
2442
3282
|
const defaults2 = cloneOptionsSnapshot(next);
|
|
2443
3283
|
const models = new Map(
|
|
2444
3284
|
Object.keys(this.modelOptions).map((name) => [name, this.resolveModelOptions(name, void 0, defaults2)])
|
|
2445
3285
|
);
|
|
2446
3286
|
for (const [name, options2] of models) this.validateModelOptions(name, options2, { defaults: defaults2, models });
|
|
2447
|
-
this.
|
|
3287
|
+
this.publishAuthorizationModes(() => {
|
|
2448
3288
|
this.defaultModelOptions.restore(defaults2);
|
|
2449
3289
|
for (const [name, options2] of models) this.modelOptions[name].restore(options2);
|
|
2450
3290
|
});
|
|
2451
3291
|
}
|
|
2452
|
-
|
|
2453
|
-
|
|
2454
|
-
|
|
2455
|
-
|
|
2456
|
-
|
|
2457
|
-
|
|
2458
|
-
|
|
2459
|
-
const
|
|
2460
|
-
|
|
2461
|
-
this.getGlobalOption("logger")?.warn?.(
|
|
2462
|
-
`UNSAFE: ${operation} ${category} snapshot checks disabled; ${risk} can leave stale authorization decisions. Restore ${key}=false after the temporary workaround.`,
|
|
2463
|
-
{ modelName }
|
|
2464
|
-
);
|
|
2465
|
-
} catch {
|
|
2466
|
-
}
|
|
2467
|
-
}
|
|
2468
|
-
deferSnapshotWarnings(publish) {
|
|
2469
|
-
if (this.pendingSnapshotWarnings) return publish();
|
|
2470
|
-
const copyModes = this.initialOutputCopyModes();
|
|
2471
|
-
const fastModes = this.authorizationFastPathModes();
|
|
2472
|
-
const pending = [];
|
|
2473
|
-
this.pendingSnapshotWarnings = pending;
|
|
3292
|
+
/** Warn only on effective transitions into trusted, after the entire update commits. */
|
|
3293
|
+
publishAuthorizationModes(publish) {
|
|
3294
|
+
if (this.publishingAuthorizationModes) return publish();
|
|
3295
|
+
const capture = () => new Map([
|
|
3296
|
+
["default-model", this.getDefaultModelOptions()],
|
|
3297
|
+
...Object.entries(this.modelOptions).map(([name, manager]) => [name, manager.fetch()])
|
|
3298
|
+
]);
|
|
3299
|
+
const before = capture();
|
|
3300
|
+
this.publishingAuthorizationModes = true;
|
|
2474
3301
|
let result;
|
|
2475
3302
|
try {
|
|
2476
3303
|
result = publish();
|
|
2477
3304
|
} finally {
|
|
2478
|
-
this.
|
|
2479
|
-
}
|
|
2480
|
-
const nextCopyModes = this.initialOutputCopyModes();
|
|
2481
|
-
const nextFastModes = this.authorizationFastPathModes();
|
|
2482
|
-
for (const { modelName, key } of pending) this.warnSnapshotFlag(modelName, key);
|
|
2483
|
-
for (const [modelName, modes] of nextCopyModes) {
|
|
2484
|
-
for (const operation of ["List", "Read"]) {
|
|
2485
|
-
const mode = modes[operation];
|
|
2486
|
-
if (mode === "off" || mode === copyModes.get(modelName)?.[operation]) continue;
|
|
2487
|
-
const key = `unsafeSkip${operation}InitialOutputSnapshotCopy`;
|
|
2488
|
-
const prerequisite = `unsafeSkip${operation}OutputSnapshotChecks`;
|
|
2489
|
-
try {
|
|
2490
|
-
this.getGlobalOption("logger")?.warn?.(
|
|
2491
|
-
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.`,
|
|
2492
|
-
{ modelName }
|
|
2493
|
-
);
|
|
2494
|
-
} catch {
|
|
2495
|
-
}
|
|
2496
|
-
}
|
|
3305
|
+
this.publishingAuthorizationModes = false;
|
|
2497
3306
|
}
|
|
2498
|
-
|
|
2499
|
-
|
|
2500
|
-
|
|
2501
|
-
|
|
2502
|
-
if (captured.mode === "off" || captured.mode === previous?.mode && (captured.mode !== "dormant" || captured.prerequisites === previous.prerequisites))
|
|
2503
|
-
continue;
|
|
2504
|
-
const key = origin === "read" ? "unsafeUseReadAuthorizationFastPath" : "unsafeUseListAuthorizationFastPath";
|
|
2505
|
-
const missing = authorizationFastPathPrerequisites(origin).filter(
|
|
2506
|
-
(_, index) => !(captured.prerequisites & 1 << index)
|
|
2507
|
-
);
|
|
3307
|
+
const after = capture();
|
|
3308
|
+
for (const [modelName, options] of after) {
|
|
3309
|
+
for (const key of authorizationModeKeys) {
|
|
3310
|
+
if (options[key] !== "trusted" || before.get(modelName)?.[key] === "trusted") continue;
|
|
2508
3311
|
try {
|
|
2509
3312
|
this.getGlobalOption("logger")?.warn?.(
|
|
2510
|
-
|
|
2511
|
-
{
|
|
3313
|
+
"Trusted authorization source mode enabled; projected source/document-hook input may be borrowed. Actor, policy, facts, getter views and selected output bounds remain owned.",
|
|
3314
|
+
{
|
|
3315
|
+
modelName,
|
|
3316
|
+
access: key === "readAuthorizationMode" ? "read" : "list",
|
|
3317
|
+
category: "trustedAuthorizationSource"
|
|
3318
|
+
}
|
|
2512
3319
|
);
|
|
2513
3320
|
} catch {
|
|
2514
3321
|
}
|
|
@@ -2516,25 +3323,6 @@ var AccessRuntime = class {
|
|
|
2516
3323
|
}
|
|
2517
3324
|
return result;
|
|
2518
3325
|
}
|
|
2519
|
-
authorizationFastPathModes() {
|
|
2520
|
-
return new Map(
|
|
2521
|
-
Object.entries(this.modelOptions).map(([modelName, manager]) => {
|
|
2522
|
-
const options = manager.fetch();
|
|
2523
|
-
return [
|
|
2524
|
-
modelName,
|
|
2525
|
-
{ list: captureAuthorizationFastPath(options, "list"), read: captureAuthorizationFastPath(options, "read") }
|
|
2526
|
-
];
|
|
2527
|
-
})
|
|
2528
|
-
);
|
|
2529
|
-
}
|
|
2530
|
-
initialOutputCopyModes() {
|
|
2531
|
-
return new Map(
|
|
2532
|
-
Object.entries(this.modelOptions).map(([modelName, options]) => {
|
|
2533
|
-
const mode = (operation) => options.get(`unsafeSkip${operation}InitialOutputSnapshotCopy`) !== true ? "off" : options.get(`unsafeSkip${operation}OutputSnapshotChecks`) === true ? "active" : "dormant";
|
|
2534
|
-
return [modelName, { List: mode("List"), Read: mode("Read") }];
|
|
2535
|
-
})
|
|
2536
|
-
);
|
|
2537
|
-
}
|
|
2538
3326
|
createModelOptions(modelName, options = this.resolveModelOptions(modelName)) {
|
|
2539
3327
|
const model = this.getModelInstance(modelName);
|
|
2540
3328
|
if (!model) {
|
|
@@ -2543,16 +3331,11 @@ var AccessRuntime = class {
|
|
|
2543
3331
|
);
|
|
2544
3332
|
}
|
|
2545
3333
|
const manager = new OptionsManager(options);
|
|
2546
|
-
const snapshotFlagChanged = (newValue, key, target, oldValue) => {
|
|
2547
|
-
target[key] = newValue === true;
|
|
2548
|
-
if (newValue !== true || oldValue === true) return;
|
|
2549
|
-
this.warnSnapshotFlag(modelName, key);
|
|
2550
|
-
};
|
|
2551
3334
|
manager.onchange("permissionSchema", function(_newval, _key, target) {
|
|
2552
3335
|
refreshPermissionMetadata(target);
|
|
2553
3336
|
}).onchange("modelPermissionPrefix", function(_newval, _key, target) {
|
|
2554
3337
|
refreshPermissionMetadata(target);
|
|
2555
|
-
}).onchange("
|
|
3338
|
+
}).onchange("basePath", function(newval, key, target) {
|
|
2556
3339
|
target[key] = normalizeBasePath(
|
|
2557
3340
|
modelName,
|
|
2558
3341
|
isString3(newval) || isNil2(newval) ? newval : void 0
|
|
@@ -2564,7 +3347,7 @@ var AccessRuntime = class {
|
|
|
2564
3347
|
getOrCreateModelOptions(modelName) {
|
|
2565
3348
|
let manager = this.modelOptions[modelName];
|
|
2566
3349
|
if (!manager) {
|
|
2567
|
-
manager = this.
|
|
3350
|
+
manager = this.publishAuthorizationModes(() => {
|
|
2568
3351
|
const created = this.createModelOptions(modelName);
|
|
2569
3352
|
this.modelOptions[modelName] = created;
|
|
2570
3353
|
return created;
|
|
@@ -2581,13 +3364,21 @@ var AccessRuntime = class {
|
|
|
2581
3364
|
* calls capture the owner's current options/defaults; in-flight calls retain their snapshot.
|
|
2582
3365
|
*/
|
|
2583
3366
|
setModelOptions(modelName, options) {
|
|
3367
|
+
assertAuthorizationModeOptions(options, true);
|
|
3368
|
+
assertNoServerModelControls(
|
|
3369
|
+
options,
|
|
3370
|
+
(detail) => {
|
|
3371
|
+
throw new TypeError(detail);
|
|
3372
|
+
},
|
|
3373
|
+
"model-options"
|
|
3374
|
+
);
|
|
2584
3375
|
assertPublicDefaults(options.defaults);
|
|
2585
3376
|
options = normalizePopulatePolicyOptions(options);
|
|
2586
3377
|
if ("hydration" in options) options = { ...options, hydration: normalizeHydration(options.hydration) };
|
|
2587
3378
|
const overrides = modelOverrides({ ...this.modelOptionOverrides[modelName], ...options });
|
|
2588
3379
|
const effective = this.resolveModelOptions(modelName, overrides);
|
|
2589
3380
|
this.validateModelOptions(modelName, effective);
|
|
2590
|
-
this.
|
|
3381
|
+
this.publishAuthorizationModes(() => {
|
|
2591
3382
|
const manager = this.modelOptions[modelName];
|
|
2592
3383
|
if (manager) manager.restore(effective);
|
|
2593
3384
|
else this.modelOptions[modelName] = this.createModelOptions(modelName, effective);
|
|
@@ -2595,16 +3386,32 @@ var AccessRuntime = class {
|
|
|
2595
3386
|
});
|
|
2596
3387
|
}
|
|
2597
3388
|
setModelOption(modelName, key, value) {
|
|
2598
|
-
|
|
3389
|
+
assertAuthorizationModeKey(key, true);
|
|
3390
|
+
const keyStr = key;
|
|
2599
3391
|
if (keyStr === "hydration" || keyStr.startsWith("hydration.")) {
|
|
2600
3392
|
const hydration = normalizeHydrationUpdate(this.resolveModelOptions(modelName).hydration, keyStr, value);
|
|
2601
3393
|
this.setModelOptions(modelName, { hydration });
|
|
2602
3394
|
return;
|
|
2603
3395
|
}
|
|
2604
|
-
if (keyStr === "defaults")
|
|
2605
|
-
|
|
3396
|
+
if (keyStr === "defaults") {
|
|
3397
|
+
assertNoServerModelControls(
|
|
3398
|
+
value,
|
|
3399
|
+
(detail) => {
|
|
3400
|
+
throw new TypeError(detail);
|
|
3401
|
+
},
|
|
3402
|
+
"defaults"
|
|
3403
|
+
);
|
|
3404
|
+
assertPublicDefaults(value);
|
|
3405
|
+
} else if (keyStr.startsWith("defaults.")) {
|
|
2606
3406
|
const proposed = {};
|
|
2607
3407
|
set3(proposed, keyStr.slice("defaults.".length), value);
|
|
3408
|
+
assertNoServerModelControls(
|
|
3409
|
+
proposed,
|
|
3410
|
+
(detail) => {
|
|
3411
|
+
throw new TypeError(detail);
|
|
3412
|
+
},
|
|
3413
|
+
"defaults"
|
|
3414
|
+
);
|
|
2608
3415
|
assertPublicDefaults(proposed);
|
|
2609
3416
|
}
|
|
2610
3417
|
const [root, ...path] = keyStr.split(".");
|
|
@@ -2615,7 +3422,7 @@ var AccessRuntime = class {
|
|
|
2615
3422
|
const current = this.resolveModelOptions(modelName);
|
|
2616
3423
|
const nested = cloneModelOptionForUpdate(isPlainObject13(current[root]) ? current[root] : {});
|
|
2617
3424
|
if (root === "virtuals" && value === void 0) {
|
|
2618
|
-
const parent = path.length === 1 ? nested :
|
|
3425
|
+
const parent = path.length === 1 ? nested : get4(nested, path.slice(0, -1));
|
|
2619
3426
|
if (isPlainObject13(parent)) delete parent[path[path.length - 1]];
|
|
2620
3427
|
} else set3(nested, path, value);
|
|
2621
3428
|
this.setModelOptions(modelName, { [root]: nested });
|
|
@@ -2721,10 +3528,28 @@ var AccessRuntime = class {
|
|
|
2721
3528
|
return manager;
|
|
2722
3529
|
}
|
|
2723
3530
|
setDataOptions(dataName, options) {
|
|
3531
|
+
assertAuthorizationModeOptions(options, false);
|
|
3532
|
+
assertNoServerModelControls(
|
|
3533
|
+
options,
|
|
3534
|
+
(detail) => {
|
|
3535
|
+
throw new TypeError(detail);
|
|
3536
|
+
},
|
|
3537
|
+
"data-options"
|
|
3538
|
+
);
|
|
2724
3539
|
const manager = this.getOrCreateDataOptions(dataName);
|
|
2725
3540
|
manager.assign(options);
|
|
2726
3541
|
}
|
|
2727
3542
|
setDataOption(dataName, key, value) {
|
|
3543
|
+
assertAuthorizationModeKey(key, false);
|
|
3544
|
+
const proposed = {};
|
|
3545
|
+
set3(proposed, key, value);
|
|
3546
|
+
assertNoServerModelControls(
|
|
3547
|
+
proposed,
|
|
3548
|
+
(detail) => {
|
|
3549
|
+
throw new TypeError(detail);
|
|
3550
|
+
},
|
|
3551
|
+
"data-options"
|
|
3552
|
+
);
|
|
2728
3553
|
const manager = this.getOrCreateDataOptions(dataName);
|
|
2729
3554
|
manager.set(key, value);
|
|
2730
3555
|
}
|
|
@@ -2771,16 +3596,16 @@ var AccessRuntime = class {
|
|
|
2771
3596
|
}
|
|
2772
3597
|
getModelRef(modelName, refPath) {
|
|
2773
3598
|
this.ensureModelMeta(modelName);
|
|
2774
|
-
const value =
|
|
3599
|
+
const value = get4(this.modelRefs, `${modelName}.${refPath}`, null);
|
|
2775
3600
|
return isString3(value) ? value : null;
|
|
2776
3601
|
}
|
|
2777
3602
|
getModelSub(modelName) {
|
|
2778
3603
|
this.ensureModelMeta(modelName);
|
|
2779
|
-
return
|
|
3604
|
+
return get4(this.modelSubs, modelName, []);
|
|
2780
3605
|
}
|
|
2781
3606
|
getModelAtt(modelName) {
|
|
2782
3607
|
this.ensureModelMeta(modelName);
|
|
2783
|
-
return
|
|
3608
|
+
return get4(this.modelAtts, modelName, []);
|
|
2784
3609
|
}
|
|
2785
3610
|
};
|
|
2786
3611
|
var defaultRuntime = new AccessRuntime({ allowGlobalModelLookup: true });
|