@web-ts-toolkit/access-router 0.51.0 → 0.52.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/advanced.js CHANGED
@@ -123,15 +123,91 @@ var FilterOperator = /* @__PURE__ */ ((FilterOperator2) => {
123
123
  })(FilterOperator || {});
124
124
 
125
125
  // src/validation/parsers.ts
126
- var import_express_json_router = __toESM(require("@web-ts-toolkit/express-json-router"));
126
+ var import_express_json_router2 = __toESM(require("@web-ts-toolkit/express-json-router"));
127
127
 
128
128
  // src/runtime.ts
129
129
  var import_mongoose2 = __toESM(require("mongoose"));
130
+
131
+ // src/validation/public-admission.ts
132
+ var import_express_json_router = __toESM(require("@web-ts-toolkit/express-json-router"));
133
+ var import_utils = require("@web-ts-toolkit/utils");
134
+ var privateControls = [
135
+ "authorization",
136
+ "overrides",
137
+ "documentAuthorization",
138
+ "documentAuthorizationStage",
139
+ "execution",
140
+ "executionContext",
141
+ "serviceExecutionContext",
142
+ "resolvedAuthorization",
143
+ "preparedQuery",
144
+ "preparedFilter",
145
+ "preparedModelQuery",
146
+ "resolvedIdentifier",
147
+ "skipParsing",
148
+ "skipAuthorization",
149
+ "alreadyAuthorized",
150
+ "operation"
151
+ ];
152
+ var PublicAdmissionError = class extends import_express_json_router.default.clientErrors.BadRequestError {
153
+ constructor(detail) {
154
+ const errors = [{ detail }];
155
+ super("Bad Request", { errors });
156
+ this.result = { success: false, kind: "error", code: "bad_request" /* BadRequest */, errors };
157
+ }
158
+ };
159
+ function assertPublicAdmission(input, kind = "envelope") {
160
+ const pending = [{ value: input, kind, path: "request" }];
161
+ const seen = /* @__PURE__ */ new WeakMap();
162
+ while (pending.length) {
163
+ const { value, kind: slot, path } = pending.pop();
164
+ if (!value || typeof value !== "object" && typeof value !== "function") continue;
165
+ const kinds = seen.get(value) ?? /* @__PURE__ */ new Set();
166
+ if (kinds.has(slot)) continue;
167
+ kinds.add(slot);
168
+ seen.set(value, kinds);
169
+ const add = (child, childKind, key) => {
170
+ pending.push({ value: child, kind: childKind, path: `${path}.${key}` });
171
+ };
172
+ const record = value;
173
+ if (slot !== "data") {
174
+ for (const key of privateControls) {
175
+ if (key in record) {
176
+ throw new PublicAdmissionError(
177
+ `Unsupported public control ${path}.${key}; use explicit per-call internal service options for backend authorization`
178
+ );
179
+ }
180
+ }
181
+ }
182
+ if (Array.isArray(value)) {
183
+ value.forEach((child, index) => add(child, slot, String(index)));
184
+ continue;
185
+ }
186
+ if (slot === "data") {
187
+ if (!(0, import_utils.isPlainObject)(value)) continue;
188
+ for (const [key, child] of Object.entries(value)) add(child, key === "$$sq" ? "envelope" : "data", key);
189
+ continue;
190
+ }
191
+ for (const key of ["args", "options", "sqOptions"]) add(record[key], "envelope", key);
192
+ add(record.include, "include", "include");
193
+ add(record.populate, "populate", "populate");
194
+ for (const key of ["filter", "match", "data"]) add(record[key], "data", key);
195
+ }
196
+ }
197
+ function assertPublicDefaults(defaults) {
198
+ assertPublicAdmission(defaults);
199
+ if (defaults && typeof defaults === "object") {
200
+ for (const value of Object.values(defaults)) assertPublicAdmission(value);
201
+ }
202
+ }
203
+ var requestAuthorization = Object.freeze({ outputFields: Object.freeze({ mode: "request" }) });
204
+
205
+ // src/runtime.ts
130
206
  var import_mongoose_schema_jsonschema = __toESM(require("mongoose-schema-jsonschema"));
131
- var import_utils8 = require("@web-ts-toolkit/utils");
207
+ var import_utils10 = require("@web-ts-toolkit/utils");
132
208
 
133
209
  // src/helpers/query.ts
134
- var import_utils = require("@web-ts-toolkit/utils");
210
+ var import_utils2 = require("@web-ts-toolkit/utils");
135
211
  var DEFAULT_LIST_HARD_LIMIT = 1e3;
136
212
 
137
213
  // src/helpers/sort-policy.ts
@@ -141,44 +217,44 @@ function isValidFieldPath(field) {
141
217
  }
142
218
 
143
219
  // src/helpers/index.ts
144
- var import_utils3 = require("@web-ts-toolkit/utils");
220
+ var import_utils4 = require("@web-ts-toolkit/utils");
145
221
 
146
222
  // src/lib.ts
147
223
  var import_mongoose = require("mongoose");
148
- var import_utils2 = require("@web-ts-toolkit/utils");
224
+ var import_utils3 = require("@web-ts-toolkit/utils");
149
225
  var isSchema = (val) => val instanceof import_mongoose.Schema;
150
226
  var isObjectIdType = (val) => val === "ObjectId" || val === import_mongoose.Schema.Types.ObjectId;
151
- var isReference = (val) => (0, import_utils2.isPlainObject)(val) && !!val.ref && isObjectIdType(val.type);
227
+ var isReference = (val) => (0, import_utils3.isPlainObject)(val) && !!val.ref && isObjectIdType(val.type);
152
228
 
153
229
  // src/helpers/index.ts
154
230
  function recurseObject(obj) {
155
231
  if (isSchema(obj)) {
156
232
  return buildRefs(obj.tree);
157
233
  }
158
- if (!(0, import_utils3.isObject)(obj)) return null;
234
+ if (!(0, import_utils4.isObject)(obj)) return null;
159
235
  if (isReference(obj)) {
160
236
  return obj.ref;
161
237
  }
162
238
  let ret = null;
163
- (0, import_utils3.forEach)(obj, (val) => {
239
+ (0, import_utils4.forEach)(obj, (val) => {
164
240
  ret = recurseObject(val);
165
- if (!(0, import_utils3.isEmpty)(ret)) {
241
+ if (!(0, import_utils4.isEmpty)(ret)) {
166
242
  return false;
167
243
  }
168
244
  });
169
245
  return ret;
170
246
  }
171
247
  function buildRefs(schema) {
172
- if (!(0, import_utils3.isObject)(schema)) return {};
248
+ if (!(0, import_utils4.isObject)(schema)) return {};
173
249
  const references = {};
174
- (0, import_utils3.forEach)(schema, (val, key) => {
250
+ (0, import_utils4.forEach)(schema, (val, key) => {
175
251
  const paths = recurseObject(val);
176
- if (!(0, import_utils3.isEmpty)(paths)) {
252
+ if (!(0, import_utils4.isEmpty)(paths)) {
177
253
  references[key] = paths;
178
254
  }
179
- const target = (0, import_utils3.isObject)(val) && "type" in val ? val.type ?? val : val;
180
- if ((0, import_utils3.isArray)(target) && target.length > 0) {
181
- if (isSchema(target[0]) || (0, import_utils3.isPlainObject)(target[0])) {
255
+ const target = (0, import_utils4.isObject)(val) && "type" in val ? val.type ?? val : val;
256
+ if ((0, import_utils4.isArray)(target) && target.length > 0) {
257
+ if (isSchema(target[0]) || (0, import_utils4.isPlainObject)(target[0])) {
182
258
  return;
183
259
  }
184
260
  }
@@ -186,12 +262,12 @@ function buildRefs(schema) {
186
262
  return references;
187
263
  }
188
264
  function buildSubPaths(schema) {
189
- if (!(0, import_utils3.isObject)(schema)) return [];
265
+ if (!(0, import_utils4.isObject)(schema)) return [];
190
266
  const subPaths = [];
191
- (0, import_utils3.forEach)(schema, (val, key) => {
192
- const target = (0, import_utils3.isObject)(val) && "type" in val ? val.type ?? val : val;
193
- if ((0, import_utils3.isArray)(target) && target.length > 0) {
194
- if (isSchema(target[0]) || (0, import_utils3.isPlainObject)(target[0]) && !isReference(target[0])) {
267
+ (0, import_utils4.forEach)(schema, (val, key) => {
268
+ const target = (0, import_utils4.isObject)(val) && "type" in val ? val.type ?? val : val;
269
+ if ((0, import_utils4.isArray)(target) && target.length > 0) {
270
+ if (isSchema(target[0]) || (0, import_utils4.isPlainObject)(target[0]) && !isReference(target[0])) {
195
271
  subPaths.push(key);
196
272
  }
197
273
  }
@@ -200,7 +276,7 @@ function buildSubPaths(schema) {
200
276
  }
201
277
 
202
278
  // src/openapi/build-spec.ts
203
- var import_utils5 = require("@web-ts-toolkit/utils");
279
+ var import_utils6 = require("@web-ts-toolkit/utils");
204
280
 
205
281
  // src/openapi/responses.ts
206
282
  var json = (schema) => ({
@@ -271,19 +347,19 @@ var openApiResponses = {
271
347
 
272
348
  // src/openapi/schemas.ts
273
349
  var import_zod = require("zod");
274
- var import_utils4 = require("@web-ts-toolkit/utils");
350
+ var import_utils5 = require("@web-ts-toolkit/utils");
275
351
  var fallbackObjectSchema = { type: "object", additionalProperties: true };
276
352
  function isOpenApiSchemaPatch(source) {
277
- return (0, import_utils4.isPlainObject)(source) && source.kind === "objectProperties";
353
+ return (0, import_utils5.isPlainObject)(source) && source.kind === "objectProperties";
278
354
  }
279
355
  function isOpenApiSchemaResolver(source) {
280
- return (0, import_utils4.isPlainObject)(source) && source.kind === "schemaResolver" && typeof source.resolve === "function";
356
+ return (0, import_utils5.isPlainObject)(source) && source.kind === "schemaResolver" && typeof source.resolve === "function";
281
357
  }
282
358
  function isJsonSchemaLike(source) {
283
- return (0, import_utils4.isPlainObject)(source) && ("type" in source || "properties" in source || "$ref" in source || "anyOf" in source);
359
+ return (0, import_utils5.isPlainObject)(source) && ("type" in source || "properties" in source || "$ref" in source || "anyOf" in source);
284
360
  }
285
361
  function hasOpenApiSchema(source) {
286
- return (0, import_utils4.isPlainObject)(source) && isJsonSchemaLike(source.openapi);
362
+ return (0, import_utils5.isPlainObject)(source) && isJsonSchemaLike(source.openapi);
287
363
  }
288
364
  function toOpenApiSchema(source) {
289
365
  if (!source) return void 0;
@@ -291,7 +367,7 @@ function toOpenApiSchema(source) {
291
367
  if (!resolvedSource) return void 0;
292
368
  if (isOpenApiSchemaPatch(resolvedSource)) {
293
369
  const schema = toOpenApiSchema(resolvedSource.source) ?? { ...fallbackObjectSchema };
294
- const properties = (0, import_utils4.isPlainObject)(schema.properties) ? { ...schema.properties } : {};
370
+ const properties = (0, import_utils5.isPlainObject)(schema.properties) ? { ...schema.properties } : {};
295
371
  for (const [key, value] of Object.entries(resolvedSource.properties)) {
296
372
  properties[key] = toOpenApiSchema(value) ?? fallbackObjectSchema;
297
373
  }
@@ -324,9 +400,9 @@ var toOpenApiPath = (path) => normalizePath(path).replace(/:([A-Za-z0-9_]+)/g, "
324
400
  var schemaToQueryParameters = (schema) => {
325
401
  const jsonSchema = toOpenApiSchema(schema);
326
402
  if (!jsonSchema || jsonSchema.type !== "object") return [];
327
- const properties = (0, import_utils5.isPlainObject)(jsonSchema.properties) ? jsonSchema.properties : {};
403
+ const properties = (0, import_utils6.isPlainObject)(jsonSchema.properties) ? jsonSchema.properties : {};
328
404
  const required = new Set(
329
- (0, import_utils5.isArray)(jsonSchema.required) ? jsonSchema.required.filter((item) => typeof item === "string") : []
405
+ (0, import_utils6.isArray)(jsonSchema.required) ? jsonSchema.required.filter((item) => typeof item === "string") : []
330
406
  );
331
407
  return Object.entries(properties).map(([name, value]) => ({
332
408
  name,
@@ -417,7 +493,7 @@ var OpenApiCollisionError = class extends Error {
417
493
  };
418
494
 
419
495
  // src/openapi/registry.ts
420
- var isPlainObject6 = (value) => value !== null && typeof value === "object" && !Array.isArray(value);
496
+ var isPlainObject7 = (value) => value !== null && typeof value === "object" && !Array.isArray(value);
421
497
  var stableKey = (value) => {
422
498
  if (value === null || typeof value === "undefined") return "null";
423
499
  if (typeof value === "function") return "[Function]";
@@ -452,7 +528,7 @@ var OpenApiRegistry = class {
452
528
  this.routes[existingIndex] = route;
453
529
  return;
454
530
  }
455
- if (descriptorsEqual(existing, route) && (route.idempotent || isPlainObject6(existing) && existing.idempotent)) {
531
+ if (descriptorsEqual(existing, route) && (route.idempotent || isPlainObject7(existing) && existing.idempotent)) {
456
532
  return;
457
533
  }
458
534
  if (this.options.rejectConflicts) {
@@ -541,7 +617,7 @@ var defaultLogger = (0, import_winston.createLogger)({
541
617
  });
542
618
 
543
619
  // src/options/manager.ts
544
- var import_utils6 = require("@web-ts-toolkit/utils");
620
+ var import_utils7 = require("@web-ts-toolkit/utils");
545
621
  var toPath = (key) => {
546
622
  if (Array.isArray(key)) return key;
547
623
  return typeof key === "string" ? key.split(".") : [key];
@@ -602,19 +678,20 @@ var freezeConfigValue = (value) => {
602
678
  return value;
603
679
  };
604
680
  var cloneAndFreezeForStore = (value) => freezeConfigValue(cloneForRead(value));
605
- var getNestedOption = (manager, key, defaultValue) => {
606
- const keys2 = String(key).split(".");
681
+ var getNestedOption = (manager, key, defaultValue) => resolveNestedOption((path, fallback) => manager.get(path, fallback), String(key), defaultValue);
682
+ var resolveNestedOption = (read, key, defaultValue) => {
683
+ const keys2 = key.split(".");
607
684
  if (keys2.length === 1) {
608
- return manager.get(key, defaultValue);
685
+ return read(key, defaultValue);
609
686
  }
610
- let option = manager.get(key, void 0);
687
+ let option = read(key);
611
688
  if (option !== void 0) {
612
689
  return option;
613
690
  }
614
691
  const parentKey = keys2.slice(0, -1).join(".");
615
- option = manager.get(`${parentKey}.default`, void 0);
692
+ option = read(`${parentKey}.default`);
616
693
  if (option === void 0) {
617
- option = manager.get(parentKey, defaultValue);
694
+ option = read(parentKey, defaultValue);
618
695
  }
619
696
  return option;
620
697
  };
@@ -647,20 +724,20 @@ var OptionsManager = class {
647
724
  return this;
648
725
  }
649
726
  get(key, defaultValue) {
650
- return (0, import_utils6.get)(this.currentOptions, key, defaultValue);
727
+ return (0, import_utils7.get)(this.currentOptions, key, defaultValue);
651
728
  }
652
729
  set(key, value) {
653
730
  const path = toPath(key);
654
731
  if (path.length <= 1) {
655
- (0, import_utils6.set)(this.currentOptions, path, this.preserveKeys.has(String(path[0])) ? value : cloneAndFreezeForStore(value));
732
+ (0, import_utils7.set)(this.currentOptions, path, this.preserveKeys.has(String(path[0])) ? value : cloneAndFreezeForStore(value));
656
733
  return;
657
734
  }
658
735
  const [rootKey, ...nestedPath] = path;
659
- const currentRoot = (0, import_utils6.get)(this.currentOptions, [rootKey], void 0);
660
- const baseRoot = (0, import_utils6.isPlainObject)(currentRoot) ? currentRoot : {};
736
+ const currentRoot = (0, import_utils7.get)(this.currentOptions, [rootKey], void 0);
737
+ const baseRoot = (0, import_utils7.isPlainObject)(currentRoot) ? currentRoot : {};
661
738
  const nextRoot = cloneConfigValue(baseRoot);
662
- (0, import_utils6.set)(nextRoot, nestedPath, cloneForRead(value));
663
- (0, import_utils6.set)(this.currentOptions, [rootKey], freezeConfigValue(nextRoot));
739
+ (0, import_utils7.set)(nextRoot, nestedPath, cloneForRead(value));
740
+ (0, import_utils7.set)(this.currentOptions, [rootKey], freezeConfigValue(nextRoot));
664
741
  }
665
742
  fetch() {
666
743
  const cloned = cloneForRead(this.currentOptions);
@@ -678,10 +755,10 @@ var OptionsManager = class {
678
755
  cloned[key] = options[key];
679
756
  }
680
757
  }
681
- (0, import_utils6.assign)(this.currentOptions, freezeConfigValue(cloned));
758
+ (0, import_utils7.assign)(this.currentOptions, freezeConfigValue(cloned));
682
759
  }
683
760
  onchange(key, func) {
684
- (0, import_utils6.set)(this.listeners, key, func);
761
+ (0, import_utils7.set)(this.listeners, key, func);
685
762
  return this;
686
763
  }
687
764
  snapshot() {
@@ -707,12 +784,230 @@ var OptionsManager = class {
707
784
  cloned[key] = snap[key];
708
785
  }
709
786
  }
710
- (0, import_utils6.assign)(current, freezeConfigValue(cloned));
787
+ (0, import_utils7.assign)(current, freezeConfigValue(cloned));
788
+ }
789
+ };
790
+
791
+ // src/options/data-manager.ts
792
+ var import_utils8 = require("@web-ts-toolkit/utils");
793
+
794
+ // src/options/data-values.ts
795
+ var import_node_util2 = require("util");
796
+ var typedArrays = [
797
+ Int8Array,
798
+ Uint8Array,
799
+ Uint8ClampedArray,
800
+ Int16Array,
801
+ Uint16Array,
802
+ Int32Array,
803
+ Uint32Array,
804
+ Float32Array,
805
+ Float64Array,
806
+ BigInt64Array,
807
+ BigUint64Array
808
+ ];
809
+ var unsupported = (path, reason) => {
810
+ throw new TypeError(`Unsupported data value at ${path}: ${reason}`);
811
+ };
812
+ var isPlainContainer = (value) => {
813
+ const prototype = Object.getPrototypeOf(value);
814
+ return prototype === Object.prototype || prototype === null || prototype === Array.prototype;
815
+ };
816
+ var defineValue = (target, key, value) => {
817
+ Object.defineProperty(target, key, { value, enumerable: true, configurable: true, writable: true });
818
+ };
819
+ var assertNativeProperties = (value, path, allowed = () => false) => {
820
+ for (const key of Reflect.ownKeys(value)) {
821
+ if (typeof key !== "string" || !allowed(key)) unsupported(path, "custom native properties are not supported");
822
+ }
823
+ };
824
+ var copyBytes = (buffer, path, start = 0, end) => {
825
+ if (!import_node_util2.types.isArrayBuffer(buffer) || Object.getPrototypeOf(buffer) !== ArrayBuffer.prototype) {
826
+ return unsupported(path, "binary storage must be a fixed, non-shared ArrayBuffer");
827
+ }
828
+ assertNativeProperties(buffer, path);
829
+ if (buffer.resizable) {
830
+ return unsupported(path, "resizable binary storage is not supported");
831
+ }
832
+ try {
833
+ return ArrayBuffer.prototype.slice.call(buffer, start, end);
834
+ } catch {
835
+ return unsupported(path, "detached binary storage is not supported");
836
+ }
837
+ };
838
+ function copyValue(input, freezePlain, rootPath) {
839
+ const copies = /* @__PURE__ */ new WeakMap();
840
+ const active = /* @__PURE__ */ new WeakSet();
841
+ const visit = (value, path) => {
842
+ if (typeof value === "function" || typeof value === "symbol") {
843
+ return unsupported(path, `${typeof value} values are not supported`);
844
+ }
845
+ if (value === null || typeof value !== "object") return value;
846
+ if (import_node_util2.types.isProxy(value)) return unsupported(path, "proxies are not supported");
847
+ if (active.has(value)) return unsupported(path, "cycles are not supported");
848
+ const previous = copies.get(value);
849
+ if (previous) return previous;
850
+ active.add(value);
851
+ try {
852
+ const prototype = Object.getPrototypeOf(value);
853
+ if (isPlainContainer(value)) {
854
+ const array = Array.isArray(value);
855
+ if (array && prototype !== Array.prototype) return unsupported(path, "unsupported array prototype");
856
+ if (prototype === Array.prototype && !array) return unsupported(path, "unsupported object prototype");
857
+ if (Object.getOwnPropertySymbols(value).length) return unsupported(path, "symbol keys are not supported");
858
+ const output2 = array ? new Array(value.length) : Object.create(prototype);
859
+ copies.set(value, output2);
860
+ for (const key of Object.keys(value)) {
861
+ const childPath = array ? `${path}[${key}]` : `${path}.${key}`;
862
+ defineValue(output2, key, visit(value[key], childPath));
863
+ }
864
+ return freezePlain ? Object.freeze(output2) : output2;
865
+ }
866
+ let output;
867
+ if (prototype === Date.prototype && import_node_util2.types.isDate(value)) {
868
+ assertNativeProperties(value, path);
869
+ output = new Date(Date.prototype.getTime.call(value));
870
+ } else if (prototype === Map.prototype && import_node_util2.types.isMap(value)) {
871
+ assertNativeProperties(value, path);
872
+ const map = /* @__PURE__ */ new Map();
873
+ copies.set(value, map);
874
+ let index = 0;
875
+ for (const [key, entry] of Map.prototype.entries.call(value)) {
876
+ map.set(visit(key, `${path}.<key:${index}>`), visit(entry, `${path}.<value:${index}>`));
877
+ index += 1;
878
+ }
879
+ output = map;
880
+ } else if (prototype === Set.prototype && import_node_util2.types.isSet(value)) {
881
+ assertNativeProperties(value, path);
882
+ const set4 = /* @__PURE__ */ new Set();
883
+ copies.set(value, set4);
884
+ let index = 0;
885
+ for (const entry of Set.prototype.values.call(value)) {
886
+ set4.add(visit(entry, `${path}.<entry:${index}>`));
887
+ index += 1;
888
+ }
889
+ output = set4;
890
+ } else if (prototype === RegExp.prototype && import_node_util2.types.isRegExp(value)) {
891
+ assertNativeProperties(value, path, (key) => key === "lastIndex");
892
+ const regexp = value;
893
+ if (typeof regexp.lastIndex !== "number") return unsupported(path, "RegExp.lastIndex must be a number");
894
+ const copy = new RegExp(regexp.source, regexp.flags);
895
+ copy.lastIndex = regexp.lastIndex;
896
+ output = copy;
897
+ } else if (prototype === ArrayBuffer.prototype) {
898
+ output = copyBytes(value, path);
899
+ } else if (ArrayBuffer.isView(value)) {
900
+ const Type = typedArrays.find((candidate) => candidate.prototype === prototype);
901
+ const buffer = prototype === Buffer.prototype && Buffer.isBuffer(value);
902
+ const dataView = prototype === DataView.prototype;
903
+ if (!Type && !buffer && !dataView) return unsupported(path, "unsupported binary view prototype");
904
+ assertNativeProperties(
905
+ value,
906
+ path,
907
+ (key) => !dataView && /^(0|[1-9]\d*)$/.test(key) && Number(key) < value.length
908
+ );
909
+ let bytes;
910
+ try {
911
+ bytes = copyBytes(value.buffer, path, value.byteOffset, value.byteOffset + value.byteLength);
912
+ } catch (error) {
913
+ if (error instanceof TypeError && error.message.startsWith("Unsupported data value at ")) throw error;
914
+ return unsupported(path, "detached binary storage is not supported");
915
+ }
916
+ output = buffer ? Buffer.from(bytes) : dataView ? new DataView(bytes) : new Type(bytes);
917
+ } else {
918
+ return unsupported(path, "unsupported object prototype");
919
+ }
920
+ copies.set(value, output);
921
+ return output;
922
+ } finally {
923
+ active.delete(value);
924
+ }
925
+ };
926
+ return visit(input, rootPath);
927
+ }
928
+ var copyDataValue = (value) => copyValue(value, false, "data");
929
+ function exposeSnapshot(root) {
930
+ const views = /* @__PURE__ */ new WeakMap();
931
+ const visit = (value) => {
932
+ const previous = views.get(value);
933
+ if (previous) return previous;
934
+ let exposed;
935
+ const keys2 = Object.keys(value);
936
+ const mutableView = () => {
937
+ if (!exposed) {
938
+ exposed = Array.isArray(value) ? new Array(value.length) : Object.create(Object.getPrototypeOf(value));
939
+ for (const key of keys2) defineValue(exposed, key, value[key]);
940
+ }
941
+ return exposed;
942
+ };
943
+ for (const key of keys2) {
944
+ const child = value[key];
945
+ if (child === null || typeof child !== "object") continue;
946
+ if (isPlainContainer(child)) {
947
+ const view2 = visit(child);
948
+ if (view2 !== child) defineValue(mutableView(), key, view2);
949
+ } else {
950
+ Object.defineProperty(mutableView(), key, {
951
+ enumerable: true,
952
+ configurable: true,
953
+ get: () => copyDataValue(child)
954
+ });
955
+ }
956
+ }
957
+ const view = exposed ? Object.freeze(exposed) : value;
958
+ views.set(value, view);
959
+ return view;
960
+ };
961
+ return visit(root);
962
+ }
963
+ var emptyDataSnapshot = Object.freeze([]);
964
+ var ownedSnapshots = new WeakMap([[emptyDataSnapshot, emptyDataSnapshot]]);
965
+ function createDataSnapshot(data) {
966
+ if (data === void 0) return void 0;
967
+ if (!Array.isArray(data) || import_node_util2.types.isProxy(data) || Object.getPrototypeOf(data) !== Array.prototype) {
968
+ return unsupported("data", "expected an ordinary array or undefined");
969
+ }
970
+ if (ownedSnapshots.has(data)) return data;
971
+ const owned = copyValue(data, true, "data");
972
+ const exposed = exposeSnapshot(owned);
973
+ ownedSnapshots.set(exposed, owned);
974
+ return exposed;
975
+ }
976
+ function getOwnedDataSnapshot(snapshot = emptyDataSnapshot) {
977
+ const owned = ownedSnapshots.get(snapshot);
978
+ if (!owned) throw new TypeError("DataService requires an admitted data snapshot");
979
+ return owned;
980
+ }
981
+
982
+ // src/options/data-manager.ts
983
+ var admitData = (options) => {
984
+ if (!Object.hasOwn(options, "data")) return options;
985
+ const { data, ...otherOptions } = options;
986
+ return { ...otherOptions, data: createDataSnapshot(data) };
987
+ };
988
+ var DataOptionsManager = class extends OptionsManager {
989
+ assign(options) {
990
+ super.assign(admitData(options));
991
+ }
992
+ set(key, value) {
993
+ const path = String(key);
994
+ if (path === "data") {
995
+ super.set("data", createDataSnapshot(value));
996
+ } else if (path.startsWith("data.")) {
997
+ const next = copyDataValue(getOwnedDataSnapshot(super.get("data")));
998
+ (0, import_utils8.set)(next, path.slice("data.".length), value);
999
+ super.set("data", createDataSnapshot(next));
1000
+ } else {
1001
+ super.set(key, value);
1002
+ }
1003
+ }
1004
+ restore(snapshot) {
1005
+ super.restore(admitData(snapshot));
711
1006
  }
712
1007
  };
713
1008
 
714
1009
  // src/request-complexity.ts
715
- var import_utils7 = require("@web-ts-toolkit/utils");
1010
+ var import_utils9 = require("@web-ts-toolkit/utils");
716
1011
  var defaultRequestComplexity = {
717
1012
  maxDepth: 8,
718
1013
  maxNodes: 500,
@@ -778,7 +1073,7 @@ function validateRequestComplexity(value, options, scope = "request") {
778
1073
  pushError(`Request exceeds maximum depth of ${limits.maxDepth}`, path);
779
1074
  return;
780
1075
  }
781
- if ((0, import_utils7.isArray)(current)) {
1076
+ if ((0, import_utils9.isArray)(current)) {
782
1077
  if (parentKey === "$and" || parentKey === "$or" || parentKey === "$nor") {
783
1078
  logicalClauses += current.length;
784
1079
  if (logicalClauses > limits.maxLogicalClauses) {
@@ -798,14 +1093,14 @@ function validateRequestComplexity(value, options, scope = "request") {
798
1093
  }
799
1094
  return;
800
1095
  }
801
- if (!(0, import_utils7.isPlainObject)(current)) return;
1096
+ if (!(0, import_utils9.isPlainObject)(current)) return;
802
1097
  for (const [key, child] of Object.entries(current)) {
803
1098
  if (key === "__proto__" || key === "prototype" || key === "constructor") {
804
1099
  pushError(`Unsupported key: ${key}`, path.concat(key));
805
1100
  return;
806
1101
  }
807
1102
  if (scope === "request" && key === "include") {
808
- includeCount += (0, import_utils7.isArray)(child) ? child.length : 1;
1103
+ includeCount += (0, import_utils9.isArray)(child) ? child.length : 1;
809
1104
  if (includeCount > limits.maxIncludeCount) {
810
1105
  pushError(`Request exceeds maximum include count of ${limits.maxIncludeCount}`, path.concat(key));
811
1106
  return;
@@ -849,44 +1144,44 @@ var defaultDataOptions = {
849
1144
  listHardLimit: DEFAULT_LIST_HARD_LIMIT
850
1145
  };
851
1146
  var normalizeBasePath = (name, value) => {
852
- if ((0, import_utils8.isNil)(value)) {
1147
+ if ((0, import_utils10.isNil)(value)) {
853
1148
  return `/${pluralize(name)}`;
854
1149
  }
855
- return (0, import_utils8.isString)(value) ? (0, import_utils8.addLeadingSlash)(value) : "";
1150
+ return (0, import_utils10.isString)(value) ? (0, import_utils10.addLeadingSlash)(value) : "";
856
1151
  };
857
1152
  var hasModelPermission = (value, modelPermissionPrefix) => {
858
1153
  if (!modelPermissionPrefix) {
859
1154
  return true;
860
1155
  }
861
- if ((0, import_utils8.isString)(value)) {
1156
+ if ((0, import_utils10.isString)(value)) {
862
1157
  return value.trim().split(" ").some((item) => item.startsWith(modelPermissionPrefix));
863
1158
  }
864
- if ((0, import_utils8.isArray)(value)) {
1159
+ if ((0, import_utils10.isArray)(value)) {
865
1160
  return value.some((item) => {
866
- if ((0, import_utils8.isString)(item) || (0, import_utils8.isArray)(item)) {
1161
+ if ((0, import_utils10.isString)(item) || (0, import_utils10.isArray)(item)) {
867
1162
  return hasModelPermission(item, modelPermissionPrefix);
868
1163
  }
869
1164
  return true;
870
1165
  });
871
1166
  }
872
- return (0, import_utils8.isFunction)(value);
1167
+ return (0, import_utils10.isFunction)(value);
873
1168
  };
874
1169
  var classifyPermissionSchema = (permissionSchema, modelPermissionPrefix) => {
875
1170
  const schemaKeys = Object.keys(permissionSchema);
876
1171
  const globalPermissionKeys = {};
877
1172
  const modelPermissionKeys = {};
878
- (0, import_utils8.forEach)(schemaKeys, (schemaKey) => {
1173
+ (0, import_utils10.forEach)(schemaKeys, (schemaKey) => {
879
1174
  const schemaRule = permissionSchema[schemaKey];
880
- const ruleEntries = (0, import_utils8.isPlainObject)(schemaRule) ? Object.entries(schemaRule) : FIELD_ACCESS_KEYS.map((accessKey) => [accessKey, schemaRule]);
1175
+ const ruleEntries = (0, import_utils10.isPlainObject)(schemaRule) ? Object.entries(schemaRule) : FIELD_ACCESS_KEYS.map((accessKey) => [accessKey, schemaRule]);
881
1176
  for (let x = 0; x < ruleEntries.length; x++) {
882
1177
  const [accessKey, value] = ruleEntries[x];
883
- if (!(0, import_utils8.isArray)(globalPermissionKeys[accessKey])) {
1178
+ if (!(0, import_utils10.isArray)(globalPermissionKeys[accessKey])) {
884
1179
  globalPermissionKeys[accessKey] = [];
885
1180
  }
886
- if (!(0, import_utils8.isArray)(modelPermissionKeys[accessKey])) {
1181
+ if (!(0, import_utils10.isArray)(modelPermissionKeys[accessKey])) {
887
1182
  modelPermissionKeys[accessKey] = [];
888
1183
  }
889
- if ((0, import_utils8.isBoolean)(value)) {
1184
+ if ((0, import_utils10.isBoolean)(value)) {
890
1185
  globalPermissionKeys[accessKey].push(schemaKey);
891
1186
  continue;
892
1187
  }
@@ -918,13 +1213,13 @@ var VIRTUAL_UNSUPPORTED_ACCESSES = ["delete", "distinct", "count"];
918
1213
  var VIRTUAL_RESERVED_NAMES = /* @__PURE__ */ new Set(["_id", "__v", "id"]);
919
1214
  var VIRTUAL_DANGEROUS_SEGMENTS = /* @__PURE__ */ new Set(["__proto__", "prototype", "constructor"]);
920
1215
  var VIRTUAL_NAME_PATTERN = /^[A-Za-z_][A-Za-z0-9_$]*$/;
921
- var isVirtualContainerValue = (value) => (0, import_utils8.isPlainObject)(value) && "sub" in value;
1216
+ var isVirtualContainerValue = (value) => (0, import_utils10.isPlainObject)(value) && "sub" in value;
922
1217
  var virtualFullPath = (prefix, name) => prefix ? `${prefix}.${name}` : name;
923
1218
  var virtualPathsOverlap = (virtualPath, permissionField) => {
924
1219
  if (!virtualPath || !permissionField) return false;
925
1220
  try {
926
- if ((0, import_utils8.get)((0, import_utils8.set)({}, virtualPath, true), permissionField) !== void 0) return true;
927
- if ((0, import_utils8.get)((0, import_utils8.set)({}, permissionField, true), virtualPath) !== void 0) return true;
1221
+ if ((0, import_utils10.get)((0, import_utils10.set)({}, virtualPath, true), permissionField) !== void 0) return true;
1222
+ if ((0, import_utils10.get)((0, import_utils10.set)({}, permissionField, true), virtualPath) !== void 0) return true;
928
1223
  } catch {
929
1224
  return false;
930
1225
  }
@@ -985,12 +1280,12 @@ var cloneVirtualsForValidation = (value) => {
985
1280
  };
986
1281
  var validateVirtualDependsOn = (dependsOn, entryLabel, storedFields, siblingVirtualNames) => {
987
1282
  if (dependsOn === void 0) return [];
988
- if (!(0, import_utils8.isArray)(dependsOn)) {
1283
+ if (!(0, import_utils10.isArray)(dependsOn)) {
989
1284
  throw new Error(`Virtual ${entryLabel}: dependsOn must be an array of top-level persisted field names`);
990
1285
  }
991
1286
  const list = dependsOn;
992
1287
  for (const dep of list) {
993
- if (!(0, import_utils8.isString)(dep) || dep.length === 0) {
1288
+ if (!(0, import_utils10.isString)(dep) || dep.length === 0) {
994
1289
  throw new Error(`Virtual ${entryLabel}: dependsOn entries must be non-empty strings`);
995
1290
  }
996
1291
  if (dep.includes(".")) {
@@ -1012,12 +1307,12 @@ var validateVirtualDependsOn = (dependsOn, entryLabel, storedFields, siblingVirt
1012
1307
  return list;
1013
1308
  };
1014
1309
  var validateVirtualLeafValue = (value, entryLabel, storedFields, siblingVirtualNames, sharedDependsOn) => {
1015
- if ((0, import_utils8.isFunction)(value)) return;
1016
- if (!(0, import_utils8.isPlainObject)(value)) {
1310
+ if ((0, import_utils10.isFunction)(value)) return;
1311
+ if (!(0, import_utils10.isPlainObject)(value)) {
1017
1312
  throw new Error(`Virtual ${entryLabel}: descriptor must be a getter function or { get, dependsOn }`);
1018
1313
  }
1019
1314
  const record = value;
1020
- if (!(0, import_utils8.isFunction)(record.get)) {
1315
+ if (!(0, import_utils10.isFunction)(record.get)) {
1021
1316
  throw new Error(`Virtual ${entryLabel}: descriptor.get must be a callable getter function`);
1022
1317
  }
1023
1318
  validateVirtualDependsOn(record.dependsOn ?? sharedDependsOn, entryLabel, storedFields, siblingVirtualNames);
@@ -1057,7 +1352,7 @@ var validateVirtualsScope = (scope, documentPermissionField) => {
1057
1352
  `Virtual ${scopeLabel}${name}: scope-container must only hold "sub" (embedded container "${name}" is not a virtual-leaf collision)`
1058
1353
  );
1059
1354
  }
1060
- if (!(0, import_utils8.isPlainObject)(record2.sub)) {
1355
+ if (!(0, import_utils10.isPlainObject)(record2.sub)) {
1061
1356
  throw new Error(`Virtual ${scopeLabel}${name}: scope-container "sub" must be a plain object`);
1062
1357
  }
1063
1358
  continue;
@@ -1067,8 +1362,8 @@ var validateVirtualsScope = (scope, documentPermissionField) => {
1067
1362
  `Virtual ${scopeLabel}${name}: collides with a stored path (inspected actual Mongoose schema/child scope; getModelAtt alone is insufficient)`
1068
1363
  );
1069
1364
  }
1070
- if ((0, import_utils8.isFunction)(raw)) continue;
1071
- if (!(0, import_utils8.isPlainObject)(raw)) {
1365
+ if ((0, import_utils10.isFunction)(raw)) continue;
1366
+ if (!(0, import_utils10.isPlainObject)(raw)) {
1072
1367
  throw new Error(
1073
1368
  `Virtual ${scopeLabel}${name}: malformed descriptor (expected getter, { get, dependsOn }, or per-access record)`
1074
1369
  );
@@ -1076,7 +1371,7 @@ var validateVirtualsScope = (scope, documentPermissionField) => {
1076
1371
  const record = raw;
1077
1372
  const hasGet = "get" in record;
1078
1373
  const accessKeys = Object.keys(record).filter((k) => VIRTUAL_SUPPORTED_ACCESSES.includes(k));
1079
- const unsupported = Object.keys(record).filter(
1374
+ const unsupported2 = Object.keys(record).filter(
1080
1375
  (k) => k !== "get" && k !== "dependsOn" && k !== "sub" && !VIRTUAL_SUPPORTED_ACCESSES.includes(k)
1081
1376
  );
1082
1377
  for (const key of Object.keys(record)) {
@@ -1086,9 +1381,9 @@ var validateVirtualsScope = (scope, documentPermissionField) => {
1086
1381
  );
1087
1382
  }
1088
1383
  }
1089
- if (unsupported.length > 0) {
1384
+ if (unsupported2.length > 0) {
1090
1385
  throw new Error(
1091
- `Virtual ${scopeLabel}${name}: unsupported access/key "${unsupported[0]}" (supported: default + list/create/read/update)`
1386
+ `Virtual ${scopeLabel}${name}: unsupported access/key "${unsupported2[0]}" (supported: default + list/create/read/update)`
1092
1387
  );
1093
1388
  }
1094
1389
  if (hasGet) {
@@ -1122,7 +1417,7 @@ var validateVirtualsScope = (scope, documentPermissionField) => {
1122
1417
  };
1123
1418
  var validateVirtualsTree = (model, virtuals, documentPermissionField, modelName) => {
1124
1419
  if (virtuals === void 0 || virtuals === null) return;
1125
- if (!(0, import_utils8.isPlainObject)(virtuals)) {
1420
+ if (!(0, import_utils10.isPlainObject)(virtuals)) {
1126
1421
  throw new Error(`Virtuals for model "${modelName}": virtuals must be a plain object mapping names to descriptors`);
1127
1422
  }
1128
1423
  const rootSchema = model?.schema ?? null;
@@ -1169,27 +1464,27 @@ var validateVirtualsTree = (model, virtuals, documentPermissionField, modelName)
1169
1464
  visitContainers(rootVirtuals, rootSchema, "");
1170
1465
  };
1171
1466
  var getScopeVirtualsObject = (rootVirtuals, scopePath) => {
1172
- if (!rootVirtuals || !(0, import_utils8.isPlainObject)(rootVirtuals)) return null;
1467
+ if (!rootVirtuals || !(0, import_utils10.isPlainObject)(rootVirtuals)) return null;
1173
1468
  if (!scopePath || scopePath.length === 0) return rootVirtuals;
1174
1469
  let current = rootVirtuals;
1175
1470
  for (let i = 0; i < scopePath.length; i += 2) {
1176
1471
  const field = scopePath[i];
1177
1472
  const subMarker = scopePath[i + 1];
1178
1473
  if (!field || subMarker !== "sub") return null;
1179
- if (!(0, import_utils8.isPlainObject)(current)) return null;
1474
+ if (!(0, import_utils10.isPlainObject)(current)) return null;
1180
1475
  const container = current[field];
1181
1476
  if (!isVirtualContainerValue(container)) return null;
1182
1477
  current = container.sub;
1183
- if (!(0, import_utils8.isPlainObject)(current)) return null;
1478
+ if (!(0, import_utils10.isPlainObject)(current)) return null;
1184
1479
  }
1185
1480
  return current;
1186
1481
  };
1187
1482
  var toVirtualDescriptor = (leaf, sharedDependsOn) => {
1188
- if ((0, import_utils8.isFunction)(leaf))
1483
+ if ((0, import_utils10.isFunction)(leaf))
1189
1484
  return { get: leaf, dependsOn: sharedDependsOn ?? [] };
1190
- if (!(0, import_utils8.isPlainObject)(leaf)) return null;
1485
+ if (!(0, import_utils10.isPlainObject)(leaf)) return null;
1191
1486
  const record = leaf;
1192
- if (!(0, import_utils8.isFunction)(record.get)) return null;
1487
+ if (!(0, import_utils10.isFunction)(record.get)) return null;
1193
1488
  const dependsOn = record.dependsOn ?? sharedDependsOn ?? [];
1194
1489
  return { get: record.get, dependsOn };
1195
1490
  };
@@ -1254,7 +1549,7 @@ var AccessRuntime = class {
1254
1549
  }
1255
1550
  registerOpenApiRoute(route) {
1256
1551
  this.openApiRegistry.register(
1257
- this.openApiPathPrefix ? { ...route, path: (0, import_utils8.normalizeUrlPath)(`${this.openApiPathPrefix}/${route.path}`) } : route
1552
+ this.openApiPathPrefix ? { ...route, path: (0, import_utils10.normalizeUrlPath)(`${this.openApiPathPrefix}/${route.path}`) } : route
1258
1553
  );
1259
1554
  }
1260
1555
  /**
@@ -1265,7 +1560,7 @@ var AccessRuntime = class {
1265
1560
  */
1266
1561
  withOpenApiPathPrefix(prefix, build) {
1267
1562
  const previous = this.openApiPathPrefix;
1268
- this.openApiPathPrefix = (0, import_utils8.normalizeUrlPath)(`${previous}/${prefix}`);
1563
+ this.openApiPathPrefix = (0, import_utils10.normalizeUrlPath)(`${previous}/${prefix}`);
1269
1564
  try {
1270
1565
  return build();
1271
1566
  } finally {
@@ -1370,6 +1665,7 @@ var AccessRuntime = class {
1370
1665
  Object.assign(this.modelAtts, snapshot.modelAtts);
1371
1666
  this.openApiRegistry.restore(snapshot.openApi);
1372
1667
  }
1668
+ /** Shallowly replace supplied global values; nested objects such as requestComplexity are not deep-merged. */
1373
1669
  setGlobalOptions(options) {
1374
1670
  this.globalOptions.assign(options);
1375
1671
  }
@@ -1382,6 +1678,7 @@ var AccessRuntime = class {
1382
1678
  getGlobalOption(key, defaultValue) {
1383
1679
  return this.globalOptions.get(key, defaultValue);
1384
1680
  }
1681
+ /** Update model starting defaults shallowly; already-stored model values are not broadcast-replaced. */
1385
1682
  setDefaultModelOptions(options) {
1386
1683
  this.defaultModelOptions.assign(options);
1387
1684
  }
@@ -1412,7 +1709,7 @@ var AccessRuntime = class {
1412
1709
  }).onchange("basePath", function(newval, key, target) {
1413
1710
  target[key] = normalizeBasePath(
1414
1711
  modelName,
1415
- (0, import_utils8.isString)(newval) || (0, import_utils8.isNil)(newval) ? newval : void 0
1712
+ (0, import_utils10.isString)(newval) || (0, import_utils10.isNil)(newval) ? newval : void 0
1416
1713
  );
1417
1714
  }).build();
1418
1715
  this.modelJsonSchemas[modelName] = model.jsonSchema();
@@ -1426,7 +1723,15 @@ var AccessRuntime = class {
1426
1723
  }
1427
1724
  return manager;
1428
1725
  }
1726
+ /**
1727
+ * Assign `{ ...modelDefaults, ...storedOptions, ...options }` shallowly. A supplied
1728
+ * operationAccess/defaults object replaces that whole value. Defaults accept only
1729
+ * query/presentation settings; virtual configuration is validated before assignment.
1730
+ * Existing router.options remains its construction-time snapshot. Fresh model-service
1731
+ * calls capture the owner's current options/defaults; in-flight calls retain their snapshot.
1732
+ */
1429
1733
  setModelOptions(modelName, options) {
1734
+ assertPublicDefaults(options.defaults);
1430
1735
  const manager = this.getOrCreateModelOptions(modelName);
1431
1736
  const defaultOptions = this.getDefaultModelOptions();
1432
1737
  const currentModelOptions = manager.fetch();
@@ -1439,6 +1744,12 @@ var AccessRuntime = class {
1439
1744
  setModelOption(modelName, key, value) {
1440
1745
  const manager = this.getOrCreateModelOptions(modelName);
1441
1746
  const keyStr = String(key);
1747
+ if (keyStr === "defaults") assertPublicDefaults(value);
1748
+ else if (keyStr.startsWith("defaults.")) {
1749
+ const proposed = {};
1750
+ (0, import_utils10.set)(proposed, keyStr.slice("defaults.".length), value);
1751
+ assertPublicDefaults(proposed);
1752
+ }
1442
1753
  if (keyStr === "virtuals" || keyStr.startsWith("virtuals.") || keyStr === "documentPermissionField") {
1443
1754
  const model = this.getModelInstance(modelName);
1444
1755
  const currentVirtuals = manager.get("virtuals");
@@ -1456,15 +1767,15 @@ var AccessRuntime = class {
1456
1767
  const segments = nestedPath.split(".");
1457
1768
  let cursor = cloned;
1458
1769
  for (let i = 0; i < segments.length - 1; i++) {
1459
- if (!(0, import_utils8.isPlainObject)(cursor)) break;
1770
+ if (!(0, import_utils10.isPlainObject)(cursor)) break;
1460
1771
  cursor = cursor[segments[i]];
1461
1772
  }
1462
- if ((0, import_utils8.isPlainObject)(cursor)) {
1773
+ if ((0, import_utils10.isPlainObject)(cursor)) {
1463
1774
  delete cursor[segments[segments.length - 1]];
1464
1775
  }
1465
1776
  proposedVirtuals = cloned;
1466
1777
  } else {
1467
- (0, import_utils8.set)(cloned, nestedPath, value);
1778
+ (0, import_utils10.set)(cloned, nestedPath, value);
1468
1779
  proposedVirtuals = cloned;
1469
1780
  }
1470
1781
  }
@@ -1472,10 +1783,17 @@ var AccessRuntime = class {
1472
1783
  }
1473
1784
  manager.set(key, value);
1474
1785
  }
1786
+ /** Frozen stored snapshot, not fully resolved per-path defaults. Read again for current configuration. */
1475
1787
  getModelOptions(modelName) {
1476
1788
  const manager = this.getOrCreateModelOptions(modelName);
1477
1789
  return manager.fetch();
1478
1790
  }
1791
+ /**
1792
+ * Generic stored exact → parent.default → parent lookup; only undefined falls through.
1793
+ * The exact runtime-model-default path is the final fallback if the stored parent is
1794
+ * absent. This is not the route-specific variant-to-base resolver; use
1795
+ * getExactModelOption to inspect a variant including its exact model-default fallback.
1796
+ */
1479
1797
  getModelOption(modelName, key, defaultValue) {
1480
1798
  const manager = this.getOrCreateModelOptions(modelName);
1481
1799
  const defaultModelValue = this.getDefaultModelOption(
@@ -1484,6 +1802,7 @@ var AccessRuntime = class {
1484
1802
  );
1485
1803
  return getNestedOption(manager, key, defaultModelValue);
1486
1804
  }
1805
+ /** Exact stored path, then the same runtime-model-default path; no parent/default or variant-to-base lookup. */
1487
1806
  getExactModelOption(modelName, key) {
1488
1807
  const manager = this.getOrCreateModelOptions(modelName);
1489
1808
  const defaultModelValue = this.getDefaultModelOption(key);
@@ -1534,8 +1853,8 @@ var AccessRuntime = class {
1534
1853
  if (!scopeVirtuals || !(virtualName in scopeVirtuals)) return void 0;
1535
1854
  const entry = scopeVirtuals[virtualName];
1536
1855
  if (entry === void 0 || isVirtualContainerValue(entry)) return void 0;
1537
- if ((0, import_utils8.isFunction)(entry)) return { get: entry, dependsOn: [] };
1538
- if (!(0, import_utils8.isPlainObject)(entry)) return void 0;
1856
+ if ((0, import_utils10.isFunction)(entry)) return { get: entry, dependsOn: [] };
1857
+ if (!(0, import_utils10.isPlainObject)(entry)) return void 0;
1539
1858
  const record = entry;
1540
1859
  if ("get" in record) {
1541
1860
  const descriptor = toVirtualDescriptor(entry, void 0);
@@ -1564,14 +1883,14 @@ var AccessRuntime = class {
1564
1883
  return this.modelJsonSchemas[modelName];
1565
1884
  }
1566
1885
  createDataOptions(dataName) {
1567
- const manager = new OptionsManager({
1886
+ const manager = new DataOptionsManager({
1568
1887
  ...defaultDataOptions,
1569
1888
  dataName
1570
1889
  });
1571
1890
  manager.onchange("basePath", function(newval, key, target) {
1572
1891
  target[key] = normalizeBasePath(
1573
1892
  dataName,
1574
- (0, import_utils8.isString)(newval) || (0, import_utils8.isNil)(newval) ? newval : void 0
1893
+ (0, import_utils10.isString)(newval) || (0, import_utils10.isNil)(newval) ? newval : void 0
1575
1894
  );
1576
1895
  }).build();
1577
1896
  return manager;
@@ -1596,10 +1915,15 @@ var AccessRuntime = class {
1596
1915
  const manager = this.getOrCreateDataOptions(dataName);
1597
1916
  return manager.fetch();
1598
1917
  }
1918
+ /**
1919
+ * Reusable configured data view: plain containers are frozen; native properties
1920
+ * return detached mutable copies on access. Native identity is not stable.
1921
+ * Replacement leaves previously captured views on their original data version.
1922
+ */
1599
1923
  getDataSnapshot(dataName) {
1600
1924
  const manager = this.getOrCreateDataOptions(dataName);
1601
1925
  const snapshot = manager.get("data");
1602
- return snapshot ?? [];
1926
+ return snapshot ?? emptyDataSnapshot;
1603
1927
  }
1604
1928
  getDataOption(dataName, key, defaultValue) {
1605
1929
  const manager = this.getOrCreateDataOptions(dataName);
@@ -1626,20 +1950,20 @@ var AccessRuntime = class {
1626
1950
  const schema = model.schema;
1627
1951
  this.modelRefs[modelName] = buildRefs(schema.tree);
1628
1952
  this.modelSubs[modelName] = buildSubPaths(schema.tree);
1629
- this.modelAtts[modelName] = (0, import_utils8.keys)(schema.obj);
1953
+ this.modelAtts[modelName] = (0, import_utils10.keys)(schema.obj);
1630
1954
  }
1631
1955
  getModelRef(modelName, refPath) {
1632
1956
  this.ensureModelMeta(modelName);
1633
- const value = (0, import_utils8.get)(this.modelRefs, `${modelName}.${refPath}`, null);
1634
- return (0, import_utils8.isString)(value) ? value : null;
1957
+ const value = (0, import_utils10.get)(this.modelRefs, `${modelName}.${refPath}`, null);
1958
+ return (0, import_utils10.isString)(value) ? value : null;
1635
1959
  }
1636
1960
  getModelSub(modelName) {
1637
1961
  this.ensureModelMeta(modelName);
1638
- return (0, import_utils8.get)(this.modelSubs, modelName, []);
1962
+ return (0, import_utils10.get)(this.modelSubs, modelName, []);
1639
1963
  }
1640
1964
  getModelAtt(modelName) {
1641
1965
  this.ensureModelMeta(modelName);
1642
- return (0, import_utils8.get)(this.modelAtts, modelName, []);
1966
+ return (0, import_utils10.get)(this.modelAtts, modelName, []);
1643
1967
  }
1644
1968
  };
1645
1969
  var defaultRuntime = new AccessRuntime({ allowGlobalModelLookup: true });
@@ -1659,10 +1983,29 @@ var getGlobalOption = (key, defaultValue) => {
1659
1983
 
1660
1984
  // src/validation/common.ts
1661
1985
  var import_zod2 = require("zod");
1662
- var import_utils10 = require("@web-ts-toolkit/utils");
1986
+ var import_utils12 = require("@web-ts-toolkit/utils");
1987
+
1988
+ // src/validation/public-admission-schema.ts
1989
+ var admissions = /* @__PURE__ */ new WeakMap();
1990
+ function publicBoundarySchema(schema, kind = "envelope") {
1991
+ const checked = schema.superRefine((value, ctx) => {
1992
+ try {
1993
+ assertPublicAdmission(value, kind);
1994
+ } catch (error) {
1995
+ if (!(error instanceof PublicAdmissionError)) throw error;
1996
+ ctx.addIssue({ code: "custom", message: error.result.errors[0].detail });
1997
+ }
1998
+ });
1999
+ admissions.set(checked, kind);
2000
+ return checked;
2001
+ }
2002
+ function assertTransformedPublicAdmission(schema, value) {
2003
+ const kind = admissions.get(schema);
2004
+ if (kind) assertPublicAdmission(value, kind);
2005
+ }
1663
2006
 
1664
2007
  // src/correlated-includes.ts
1665
- var import_utils9 = require("@web-ts-toolkit/utils");
2008
+ var import_utils11 = require("@web-ts-toolkit/utils");
1666
2009
  var PARENT_MARKER_KEY = "$parent";
1667
2010
  var ESCAPE_WRAPPER_KEY = "$escape";
1668
2011
  var SUBQUERY_PAYLOAD_KEYS = /* @__PURE__ */ new Set(["$$sq", "$$date"]);
@@ -1673,10 +2016,10 @@ var FIELD_SEGMENT_PATTERN = /^[A-Za-z_][A-Za-z0-9_$]*$/;
1673
2016
  var ARRAY_INDEX_SEGMENT_PATTERN = /^(0|[1-9]\d*)$/;
1674
2017
  var ownKeys = (value) => Object.keys(value);
1675
2018
  function isParentRefMarker(value) {
1676
- return (0, import_utils9.isPlainObject)(value) && ownKeys(value).length === 1 && ownKeys(value)[0] === PARENT_MARKER_KEY;
2019
+ return (0, import_utils11.isPlainObject)(value) && ownKeys(value).length === 1 && ownKeys(value)[0] === PARENT_MARKER_KEY;
1677
2020
  }
1678
2021
  function isEscapedParentRef(value) {
1679
- return (0, import_utils9.isPlainObject)(value) && ownKeys(value).length === 1 && ownKeys(value)[0] === ESCAPE_WRAPPER_KEY;
2022
+ return (0, import_utils11.isPlainObject)(value) && ownKeys(value).length === 1 && ownKeys(value)[0] === ESCAPE_WRAPPER_KEY;
1680
2023
  }
1681
2024
  function hasMarkerKey(value) {
1682
2025
  return ownKeys(value).includes(PARENT_MARKER_KEY) || ownKeys(value).includes(ESCAPE_WRAPPER_KEY);
@@ -1695,12 +2038,12 @@ function containsParentMarkerShape(value) {
1695
2038
  const seen = /* @__PURE__ */ new Set();
1696
2039
  const visit = (current) => {
1697
2040
  if (isParentRefMarker(current) || isEscapedParentRef(current)) return true;
1698
- if ((0, import_utils9.isArray)(current)) {
2041
+ if ((0, import_utils11.isArray)(current)) {
1699
2042
  if (seen.has(current)) return false;
1700
2043
  seen.add(current);
1701
2044
  return current.some(visit);
1702
2045
  }
1703
- if ((0, import_utils9.isPlainObject)(current)) {
2046
+ if ((0, import_utils11.isPlainObject)(current)) {
1704
2047
  if (seen.has(current)) return false;
1705
2048
  seen.add(current);
1706
2049
  if (hasMarkerKey(current)) return true;
@@ -1730,7 +2073,7 @@ function scanTemplateValueNode(value, path, issues) {
1730
2073
  }
1731
2074
  return;
1732
2075
  }
1733
- if ((0, import_utils9.isPlainObject)(value)) {
2076
+ if ((0, import_utils11.isPlainObject)(value)) {
1734
2077
  if (hasMarkerKey(value)) {
1735
2078
  issues.push({
1736
2079
  message: 'Malformed $parent reference: objects carrying $parent must be exactly { "$parent": "<field>" }',
@@ -1741,7 +2084,7 @@ function scanTemplateValueNode(value, path, issues) {
1741
2084
  scanTemplateObjectEntries(value, path, issues);
1742
2085
  return;
1743
2086
  }
1744
- if ((0, import_utils9.isArray)(value)) {
2087
+ if ((0, import_utils11.isArray)(value)) {
1745
2088
  value.forEach((item, index) => scanTemplateValueNode(item, [...path, index], issues));
1746
2089
  }
1747
2090
  }
@@ -1782,7 +2125,7 @@ function scanTemplateObjectEntries(obj, basePath, issues) {
1782
2125
  continue;
1783
2126
  }
1784
2127
  if (LOGICAL_CLAUSE_KEYS.has(key)) {
1785
- if (!(0, import_utils9.isArray)(child)) {
2128
+ if (!(0, import_utils11.isArray)(child)) {
1786
2129
  scanTemplateValueNode(child, childPath, issues);
1787
2130
  continue;
1788
2131
  }
@@ -1795,7 +2138,7 @@ function scanTemplateObjectEntries(obj, basePath, issues) {
1795
2138
  });
1796
2139
  return;
1797
2140
  }
1798
- if ((0, import_utils9.isPlainObject)(clause)) {
2141
+ if ((0, import_utils11.isPlainObject)(clause)) {
1799
2142
  scanTemplateObjectEntries(clause, clausePath, issues);
1800
2143
  }
1801
2144
  });
@@ -1806,7 +2149,7 @@ function scanTemplateObjectEntries(obj, basePath, issues) {
1806
2149
  }
1807
2150
  function validateCorrelatedFilterTemplate(filter) {
1808
2151
  const issues = [];
1809
- if (!(0, import_utils9.isPlainObject)(filter)) {
2152
+ if (!(0, import_utils11.isPlainObject)(filter)) {
1810
2153
  issues.push({ message: "Correlated include filter must be an object", path: [] });
1811
2154
  return issues;
1812
2155
  }
@@ -1853,42 +2196,48 @@ var sortSchema = import_zod2.z.union([
1853
2196
  import_zod2.z.null()
1854
2197
  ]);
1855
2198
  var populateAccessSchema = import_zod2.z.enum(["list", "read"]);
1856
- var populateSchema = import_zod2.z.union([
1857
- import_zod2.z.string(),
1858
- import_zod2.z.array(
1859
- import_zod2.z.union([
1860
- import_zod2.z.string(),
1861
- import_zod2.z.object({
1862
- path: import_zod2.z.string().min(1),
1863
- select: projectionSchema.optional(),
1864
- match: import_zod2.z.unknown().optional(),
1865
- access: populateAccessSchema.optional()
1866
- }).passthrough()
1867
- ])
1868
- ),
1869
- import_zod2.z.object({
1870
- path: import_zod2.z.string().min(1),
1871
- select: projectionSchema.optional(),
1872
- match: import_zod2.z.unknown().optional(),
1873
- access: populateAccessSchema.optional()
1874
- }).passthrough()
1875
- ]);
1876
- var subPopulateSchema = import_zod2.z.union([
1877
- import_zod2.z.string(),
1878
- import_zod2.z.array(
1879
- import_zod2.z.union([
1880
- import_zod2.z.string(),
1881
- import_zod2.z.object({
1882
- path: import_zod2.z.string().min(1),
1883
- select: projectionSchema.optional()
1884
- }).passthrough()
1885
- ])
1886
- ),
1887
- import_zod2.z.object({
1888
- path: import_zod2.z.string().min(1),
1889
- select: projectionSchema.optional()
1890
- }).passthrough()
1891
- ]);
2199
+ var populateSchema = publicBoundarySchema(
2200
+ import_zod2.z.union([
2201
+ import_zod2.z.string(),
2202
+ import_zod2.z.array(
2203
+ import_zod2.z.union([
2204
+ import_zod2.z.string(),
2205
+ import_zod2.z.object({
2206
+ path: import_zod2.z.string().min(1),
2207
+ select: projectionSchema.optional(),
2208
+ match: import_zod2.z.unknown().optional(),
2209
+ access: populateAccessSchema.optional()
2210
+ }).passthrough()
2211
+ ])
2212
+ ),
2213
+ import_zod2.z.object({
2214
+ path: import_zod2.z.string().min(1),
2215
+ select: projectionSchema.optional(),
2216
+ match: import_zod2.z.unknown().optional(),
2217
+ access: populateAccessSchema.optional()
2218
+ }).passthrough()
2219
+ ]),
2220
+ "populate"
2221
+ );
2222
+ var subPopulateSchema = publicBoundarySchema(
2223
+ import_zod2.z.union([
2224
+ import_zod2.z.string(),
2225
+ import_zod2.z.array(
2226
+ import_zod2.z.union([
2227
+ import_zod2.z.string(),
2228
+ import_zod2.z.object({
2229
+ path: import_zod2.z.string().min(1),
2230
+ select: projectionSchema.optional()
2231
+ }).passthrough()
2232
+ ])
2233
+ ),
2234
+ import_zod2.z.object({
2235
+ path: import_zod2.z.string().min(1),
2236
+ select: projectionSchema.optional()
2237
+ }).passthrough()
2238
+ ]),
2239
+ "populate"
2240
+ );
1892
2241
  var legacyIncludeItemSchema = import_zod2.z.object({
1893
2242
  mode: import_zod2.z.enum(["legacy"]).optional(),
1894
2243
  model: import_zod2.z.string().min(1),
@@ -1928,7 +2277,7 @@ var correlatedFilterSchema = import_zod2.z.record(import_zod2.z.string(), import
1928
2277
  }
1929
2278
  });
1930
2279
  var correlatedEmptyOptionsSchema = import_zod2.z.unknown().refine(
1931
- (value) => value === void 0 || (0, import_utils10.isPlainObject)(value) && Object.keys(value).length === 0,
2280
+ (value) => value === void 0 || (0, import_utils12.isPlainObject)(value) && Object.keys(value).length === 0,
1932
2281
  "Correlated include options must be absent or empty"
1933
2282
  ).optional();
1934
2283
  var correlatedPathSchema = import_zod2.z.string().min(1).superRefine((path, ctx) => {
@@ -1965,7 +2314,7 @@ var correlatedListArgsSchema = import_zod2.z.object({
1965
2314
  include: import_zod2.z.lazy(() => correlatedNestedIncludeSchema).optional()
1966
2315
  }).strict().superRefine((args, ctx) => checkArgsMarkers(args.select, args.sort, ctx));
1967
2316
  var correlatedCountArgsSchema = import_zod2.z.unknown().refine(
1968
- (value) => value === void 0 || (0, import_utils10.isPlainObject)(value) && Object.keys(value).length === 0,
2317
+ (value) => value === void 0 || (0, import_utils12.isPlainObject)(value) && Object.keys(value).length === 0,
1969
2318
  "Count includes accept no args"
1970
2319
  ).optional();
1971
2320
  var correlatedReadByIdSchema = import_zod2.z.object({
@@ -2004,18 +2353,21 @@ var correlatedCountSchema = import_zod2.z.object({
2004
2353
  args: correlatedCountArgsSchema,
2005
2354
  options: correlatedEmptyOptionsSchema
2006
2355
  }).strict();
2007
- var includeItemSchema = import_zod2.z.union([
2008
- legacyIncludeItemSchema,
2009
- correlatedReadByIdSchema,
2010
- correlatedReadByFilterSchema,
2011
- correlatedListSchema,
2012
- correlatedCountSchema
2013
- ]);
2356
+ var includeItemSchema = publicBoundarySchema(
2357
+ import_zod2.z.union([
2358
+ legacyIncludeItemSchema,
2359
+ correlatedReadByIdSchema,
2360
+ correlatedReadByFilterSchema,
2361
+ correlatedListSchema,
2362
+ correlatedCountSchema
2363
+ ]),
2364
+ "include"
2365
+ );
2014
2366
  var correlatedNestedIncludeSchema = import_zod2.z.union([includeItemSchema, import_zod2.z.array(includeItemSchema)]);
2015
2367
  var rejectDuplicateCorrelatedPaths = (items, ctx) => {
2016
2368
  const seen = /* @__PURE__ */ new Set();
2017
2369
  items.forEach((item, index) => {
2018
- if ((0, import_utils10.isPlainObject)(item) && item.mode === "correlated" && typeof item.path === "string") {
2370
+ if ((0, import_utils12.isPlainObject)(item) && item.mode === "correlated" && typeof item.path === "string") {
2019
2371
  if (seen.has(item.path)) {
2020
2372
  ctx.addIssue({
2021
2373
  code: import_zod2.z.ZodIssueCode.custom,
@@ -2053,7 +2405,7 @@ function rejectKeys(body, ctx, keys2) {
2053
2405
  }
2054
2406
 
2055
2407
  // src/validation/parsers.ts
2056
- var clientErrors = import_express_json_router.default.clientErrors;
2408
+ var clientErrors = import_express_json_router2.default.clientErrors;
2057
2409
  function parsePathParam(value, parameter) {
2058
2410
  const result = stringOrStringArray.safeParse(value);
2059
2411
  if (!result.success) {
@@ -2068,6 +2420,7 @@ function parsePathParam(value, parameter) {
2068
2420
  return param;
2069
2421
  }
2070
2422
  function parseQuery(schema, value) {
2423
+ assertTransformedPublicAdmission(schema, value);
2071
2424
  const complexityErrors = validateRequestComplexity(value, getGlobalOption("requestComplexity"), "request");
2072
2425
  if (complexityErrors.length > 0) {
2073
2426
  throw new clientErrors.BadRequestError("Bad Request", { errors: complexityErrors });
@@ -2079,6 +2432,7 @@ function parseQuery(schema, value) {
2079
2432
  return result.data;
2080
2433
  }
2081
2434
  function parseBody(schema, value) {
2435
+ assertTransformedPublicAdmission(schema, value);
2082
2436
  const complexityErrors = validateRequestComplexity(value ?? {}, getGlobalOption("requestComplexity"), "request");
2083
2437
  if (complexityErrors.length > 0) {
2084
2438
  throw new clientErrors.BadRequestError("Bad Request", { errors: complexityErrors });
@@ -2089,17 +2443,22 @@ function parseBody(schema, value) {
2089
2443
  }
2090
2444
  return result.data;
2091
2445
  }
2092
- function parseBodyWithSchema(schema, value, userSchema) {
2446
+ async function parseBodyWithSchema(schema, value, userSchema) {
2093
2447
  const body = parseBody(schema, value);
2094
- return isRequestSchema(userSchema) ? parseUserSchema(userSchema, body) : Promise.resolve(body);
2448
+ if (!isRequestSchema(userSchema)) return body;
2449
+ const transformed = await parseUserSchema(userSchema, body);
2450
+ assertTransformedPublicAdmission(schema, transformed);
2451
+ return transformed;
2095
2452
  }
2096
2453
  async function parseNestedBodyWithSchema(schema, value, nestedKey, userSchema) {
2097
2454
  const body = parseBody(schema, value);
2098
2455
  if (!isRequestSchema(userSchema)) return body;
2099
- return {
2456
+ const transformed = {
2100
2457
  ...body,
2101
2458
  [nestedKey]: await parseUserSchema(userSchema, body?.[nestedKey], [nestedKey])
2102
2459
  };
2460
+ assertTransformedPublicAdmission(schema, transformed);
2461
+ return transformed;
2103
2462
  }
2104
2463
  function throwValidationError(issues, key, location = "pointer") {
2105
2464
  const errors = issues.map((issue) => formatIssue(issue, key, location));
@@ -2527,147 +2886,177 @@ function buildPointer(path) {
2527
2886
 
2528
2887
  // src/validation/model-router.ts
2529
2888
  var import_zod3 = require("zod");
2530
- var listQuerySchema = import_zod3.z.object({
2531
- skip: nonNegativeIntegerString.optional(),
2532
- limit: positiveIntegerString.optional(),
2533
- page: nonNegativeIntegerString.optional(),
2534
- page_size: positiveIntegerString.optional(),
2535
- skim: queryBooleanString.optional(),
2536
- include_permissions: queryBooleanString.optional(),
2537
- include_field_permissions: queryBooleanString.optional(),
2538
- include_count: queryBooleanString.optional(),
2539
- include_extra_headers: queryBooleanString.optional(),
2540
- select: stringOrStringArray.optional(),
2541
- sort: import_zod3.z.string().optional().describe("Space-separated sort fields; prefix a field with - for descending order.")
2542
- }).passthrough();
2543
- var createQuerySchema = import_zod3.z.object({
2544
- include_permissions: queryBooleanString.optional(),
2545
- include_field_permissions: queryBooleanString.optional()
2546
- }).passthrough();
2547
- var readQuerySchema = import_zod3.z.object({
2548
- include_permissions: queryBooleanString.optional(),
2549
- include_field_permissions: queryBooleanString.optional(),
2550
- try_list: queryBooleanString.optional(),
2551
- select: stringOrStringArray.optional()
2552
- }).passthrough();
2553
- var updateQuerySchema = import_zod3.z.object({
2554
- returning_all: queryBooleanString.optional(),
2555
- include_permissions: queryBooleanString.optional(),
2556
- include_field_permissions: queryBooleanString.optional(),
2557
- select: stringOrStringArray.optional()
2558
- }).passthrough();
2559
- var upsertQuerySchema = import_zod3.z.object({
2560
- returning_all: queryBooleanString.optional(),
2561
- include_permissions: queryBooleanString.optional(),
2562
- include_field_permissions: queryBooleanString.optional()
2563
- }).passthrough();
2564
- var listBodySchema = import_zod3.z.object({
2565
- filter: objectOrArraySchema.optional(),
2566
- select: projectionSchema.optional(),
2567
- sort: sortSchema.optional(),
2568
- populate: populateSchema.optional(),
2569
- include: includeSchema.optional(),
2570
- tasks: tasksSchema.optional(),
2571
- skip: import_zod3.z.union([nonNegativeIntegerSchema, nonNegativeIntegerString]).optional(),
2572
- limit: import_zod3.z.union([positiveIntegerSchema, positiveIntegerString]).optional(),
2573
- page: import_zod3.z.union([nonNegativeIntegerSchema, nonNegativeIntegerString]).optional(),
2574
- pageSize: import_zod3.z.union([positiveIntegerSchema, positiveIntegerString]).optional(),
2575
- options: import_zod3.z.object({
2576
- skim: import_zod3.z.boolean().optional(),
2577
- includePermissions: import_zod3.z.boolean().optional(),
2578
- includeFieldPermissions: import_zod3.z.boolean().optional(),
2579
- includeCount: import_zod3.z.boolean().optional(),
2580
- includeExtraHeaders: import_zod3.z.boolean().optional(),
2581
- populateAccess: populateAccessSchema.optional()
2582
- }).passthrough().optional()
2583
- }).passthrough().superRefine((body, ctx) => rejectKeys(body, ctx, ["query"]));
2584
- var countBodySchema = import_zod3.z.object({
2585
- filter: objectOrArraySchema.optional()
2586
- }).passthrough().superRefine((body, ctx) => rejectKeys(body, ctx, ["query", "access", "options", "include"]));
2587
- var readFilterBodySchema = import_zod3.z.object({
2588
- filter: objectOrArraySchema.optional(),
2589
- select: projectionSchema.optional(),
2590
- sort: sortSchema.optional(),
2591
- populate: populateSchema.optional(),
2592
- include: includeSchema.optional(),
2593
- tasks: tasksSchema.optional(),
2594
- options: import_zod3.z.object({
2595
- skim: import_zod3.z.boolean().optional(),
2596
- includePermissions: import_zod3.z.boolean().optional(),
2597
- includeFieldPermissions: import_zod3.z.boolean().optional(),
2598
- tryList: import_zod3.z.boolean().optional(),
2599
- populateAccess: populateAccessSchema.optional()
2600
- }).passthrough().optional()
2601
- }).passthrough();
2602
- var readByIdBodySchema = import_zod3.z.object({
2603
- select: projectionSchema.optional(),
2604
- populate: populateSchema.optional(),
2605
- include: includeSchema.optional(),
2606
- tasks: tasksSchema.optional(),
2607
- options: import_zod3.z.object({
2608
- skim: import_zod3.z.boolean().optional(),
2609
- includePermissions: import_zod3.z.boolean().optional(),
2610
- includeFieldPermissions: import_zod3.z.boolean().optional(),
2611
- tryList: import_zod3.z.boolean().optional(),
2612
- populateAccess: populateAccessSchema.optional()
2613
- }).passthrough().optional()
2614
- }).passthrough();
2615
- var advancedCreateBodySchema = import_zod3.z.object({
2616
- data: import_zod3.z.unknown(),
2617
- select: projectionSchema.optional(),
2618
- populate: populateSchema.optional(),
2619
- tasks: tasksSchema.optional(),
2620
- options: import_zod3.z.object({
2621
- includePermissions: import_zod3.z.boolean().optional(),
2622
- includeFieldPermissions: import_zod3.z.boolean().optional(),
2623
- populateAccess: populateAccessSchema.optional()
2624
- }).passthrough().optional()
2625
- }).passthrough();
2626
- var createBodySchema = import_zod3.z.union([
2627
- import_zod3.z.record(import_zod3.z.string(), import_zod3.z.unknown()),
2628
- import_zod3.z.array(import_zod3.z.record(import_zod3.z.string(), import_zod3.z.unknown()))
2629
- ]);
2630
- var updateBodySchema = import_zod3.z.record(import_zod3.z.string(), import_zod3.z.unknown());
2631
- var advancedUpdateBodySchema = import_zod3.z.object({
2632
- data: import_zod3.z.unknown(),
2633
- select: projectionSchema.optional(),
2634
- populate: populateSchema.optional(),
2635
- tasks: tasksSchema.optional(),
2636
- options: import_zod3.z.object({
2637
- returningAll: import_zod3.z.boolean().optional(),
2638
- includePermissions: import_zod3.z.boolean().optional(),
2639
- includeFieldPermissions: import_zod3.z.boolean().optional(),
2640
- populateAccess: populateAccessSchema.optional()
2641
- }).passthrough().optional()
2642
- }).passthrough();
2643
- var upsertBodySchema = import_zod3.z.record(import_zod3.z.string(), import_zod3.z.unknown());
2644
- var advancedUpsertBodySchema = import_zod3.z.object({
2645
- data: import_zod3.z.record(import_zod3.z.string(), import_zod3.z.unknown()),
2646
- select: projectionSchema.optional(),
2647
- populate: populateSchema.optional(),
2648
- tasks: tasksSchema.optional(),
2649
- options: import_zod3.z.object({
2650
- returningAll: import_zod3.z.boolean().optional(),
2651
- includePermissions: import_zod3.z.boolean().optional(),
2652
- includeFieldPermissions: import_zod3.z.boolean().optional(),
2653
- populateAccess: populateAccessSchema.optional()
2654
- }).passthrough().optional()
2655
- }).passthrough();
2656
- var distinctBodySchema = import_zod3.z.object({
2657
- filter: objectOrArraySchema.optional()
2658
- }).passthrough().superRefine((body, ctx) => rejectKeys(body, ctx, ["query"]));
2659
- var subListBodySchema = import_zod3.z.object({
2660
- filter: import_zod3.z.record(import_zod3.z.string(), import_zod3.z.unknown()).optional(),
2661
- select: fieldsSchema.optional()
2662
- }).passthrough().superRefine((body, ctx) => rejectKeys(body, ctx, ["fields"]));
2663
- var subMutationBodySchema = import_zod3.z.union([
2664
- import_zod3.z.record(import_zod3.z.string(), import_zod3.z.unknown()),
2665
- import_zod3.z.array(import_zod3.z.record(import_zod3.z.string(), import_zod3.z.unknown()))
2666
- ]);
2667
- var subReadBodySchema = import_zod3.z.object({
2668
- select: fieldsSchema.optional(),
2669
- populate: subPopulateSchema.optional()
2670
- }).passthrough().superRefine((body, ctx) => rejectKeys(body, ctx, ["fields"]));
2889
+ var listQuerySchema = publicBoundarySchema(
2890
+ import_zod3.z.object({
2891
+ skip: nonNegativeIntegerString.optional(),
2892
+ limit: positiveIntegerString.optional(),
2893
+ page: nonNegativeIntegerString.optional(),
2894
+ page_size: positiveIntegerString.optional(),
2895
+ skim: queryBooleanString.optional(),
2896
+ include_permissions: queryBooleanString.optional(),
2897
+ include_field_permissions: queryBooleanString.optional(),
2898
+ include_count: queryBooleanString.optional(),
2899
+ include_extra_headers: queryBooleanString.optional(),
2900
+ select: stringOrStringArray.optional(),
2901
+ sort: import_zod3.z.string().optional().describe("Space-separated sort fields; prefix a field with - for descending order.")
2902
+ }).passthrough()
2903
+ );
2904
+ var createQuerySchema = publicBoundarySchema(
2905
+ import_zod3.z.object({
2906
+ include_permissions: queryBooleanString.optional(),
2907
+ include_field_permissions: queryBooleanString.optional()
2908
+ }).passthrough()
2909
+ );
2910
+ var readQuerySchema = publicBoundarySchema(
2911
+ import_zod3.z.object({
2912
+ include_permissions: queryBooleanString.optional(),
2913
+ include_field_permissions: queryBooleanString.optional(),
2914
+ try_list: queryBooleanString.optional(),
2915
+ select: stringOrStringArray.optional()
2916
+ }).passthrough()
2917
+ );
2918
+ var updateQuerySchema = publicBoundarySchema(
2919
+ import_zod3.z.object({
2920
+ returning_all: queryBooleanString.optional(),
2921
+ include_permissions: queryBooleanString.optional(),
2922
+ include_field_permissions: queryBooleanString.optional(),
2923
+ select: stringOrStringArray.optional()
2924
+ }).passthrough()
2925
+ );
2926
+ var upsertQuerySchema = publicBoundarySchema(
2927
+ import_zod3.z.object({
2928
+ returning_all: queryBooleanString.optional(),
2929
+ include_permissions: queryBooleanString.optional(),
2930
+ include_field_permissions: queryBooleanString.optional()
2931
+ }).passthrough()
2932
+ );
2933
+ var listBodySchema = publicBoundarySchema(
2934
+ import_zod3.z.object({
2935
+ filter: objectOrArraySchema.optional(),
2936
+ select: projectionSchema.optional(),
2937
+ sort: sortSchema.optional(),
2938
+ populate: populateSchema.optional(),
2939
+ include: includeSchema.optional(),
2940
+ tasks: tasksSchema.optional(),
2941
+ skip: import_zod3.z.union([nonNegativeIntegerSchema, nonNegativeIntegerString]).optional(),
2942
+ limit: import_zod3.z.union([positiveIntegerSchema, positiveIntegerString]).optional(),
2943
+ page: import_zod3.z.union([nonNegativeIntegerSchema, nonNegativeIntegerString]).optional(),
2944
+ pageSize: import_zod3.z.union([positiveIntegerSchema, positiveIntegerString]).optional(),
2945
+ options: import_zod3.z.object({
2946
+ skim: import_zod3.z.boolean().optional(),
2947
+ includePermissions: import_zod3.z.boolean().optional(),
2948
+ includeFieldPermissions: import_zod3.z.boolean().optional(),
2949
+ includeCount: import_zod3.z.boolean().optional(),
2950
+ includeExtraHeaders: import_zod3.z.boolean().optional(),
2951
+ populateAccess: populateAccessSchema.optional()
2952
+ }).passthrough().optional()
2953
+ }).passthrough().superRefine((body, ctx) => rejectKeys(body, ctx, ["query"]))
2954
+ );
2955
+ var countBodySchema = publicBoundarySchema(
2956
+ import_zod3.z.object({
2957
+ filter: objectOrArraySchema.optional()
2958
+ }).passthrough().superRefine((body, ctx) => rejectKeys(body, ctx, ["query", "access", "options", "include"]))
2959
+ );
2960
+ var readFilterBodySchema = publicBoundarySchema(
2961
+ import_zod3.z.object({
2962
+ filter: objectOrArraySchema.optional(),
2963
+ select: projectionSchema.optional(),
2964
+ sort: sortSchema.optional(),
2965
+ populate: populateSchema.optional(),
2966
+ include: includeSchema.optional(),
2967
+ tasks: tasksSchema.optional(),
2968
+ options: import_zod3.z.object({
2969
+ skim: import_zod3.z.boolean().optional(),
2970
+ includePermissions: import_zod3.z.boolean().optional(),
2971
+ includeFieldPermissions: import_zod3.z.boolean().optional(),
2972
+ tryList: import_zod3.z.boolean().optional(),
2973
+ populateAccess: populateAccessSchema.optional()
2974
+ }).passthrough().optional()
2975
+ }).passthrough()
2976
+ );
2977
+ var readByIdBodySchema = publicBoundarySchema(
2978
+ import_zod3.z.object({
2979
+ select: projectionSchema.optional(),
2980
+ populate: populateSchema.optional(),
2981
+ include: includeSchema.optional(),
2982
+ tasks: tasksSchema.optional(),
2983
+ options: import_zod3.z.object({
2984
+ skim: import_zod3.z.boolean().optional(),
2985
+ includePermissions: import_zod3.z.boolean().optional(),
2986
+ includeFieldPermissions: import_zod3.z.boolean().optional(),
2987
+ tryList: import_zod3.z.boolean().optional(),
2988
+ populateAccess: populateAccessSchema.optional()
2989
+ }).passthrough().optional()
2990
+ }).passthrough()
2991
+ );
2992
+ var advancedCreateBodySchema = publicBoundarySchema(
2993
+ import_zod3.z.object({
2994
+ data: import_zod3.z.unknown(),
2995
+ select: projectionSchema.optional(),
2996
+ populate: populateSchema.optional(),
2997
+ tasks: tasksSchema.optional(),
2998
+ options: import_zod3.z.object({
2999
+ includePermissions: import_zod3.z.boolean().optional(),
3000
+ includeFieldPermissions: import_zod3.z.boolean().optional(),
3001
+ populateAccess: populateAccessSchema.optional()
3002
+ }).passthrough().optional()
3003
+ }).passthrough()
3004
+ );
3005
+ var createBodySchema = publicBoundarySchema(
3006
+ import_zod3.z.union([import_zod3.z.record(import_zod3.z.string(), import_zod3.z.unknown()), import_zod3.z.array(import_zod3.z.record(import_zod3.z.string(), import_zod3.z.unknown()))]),
3007
+ "data"
3008
+ );
3009
+ var updateBodySchema = publicBoundarySchema(import_zod3.z.record(import_zod3.z.string(), import_zod3.z.unknown()), "data");
3010
+ var advancedUpdateBodySchema = publicBoundarySchema(
3011
+ import_zod3.z.object({
3012
+ data: import_zod3.z.unknown(),
3013
+ select: projectionSchema.optional(),
3014
+ populate: populateSchema.optional(),
3015
+ tasks: tasksSchema.optional(),
3016
+ options: import_zod3.z.object({
3017
+ returningAll: import_zod3.z.boolean().optional(),
3018
+ includePermissions: import_zod3.z.boolean().optional(),
3019
+ includeFieldPermissions: import_zod3.z.boolean().optional(),
3020
+ populateAccess: populateAccessSchema.optional()
3021
+ }).passthrough().optional()
3022
+ }).passthrough()
3023
+ );
3024
+ var upsertBodySchema = publicBoundarySchema(import_zod3.z.record(import_zod3.z.string(), import_zod3.z.unknown()), "data");
3025
+ var advancedUpsertBodySchema = publicBoundarySchema(
3026
+ import_zod3.z.object({
3027
+ data: import_zod3.z.record(import_zod3.z.string(), import_zod3.z.unknown()),
3028
+ select: projectionSchema.optional(),
3029
+ populate: populateSchema.optional(),
3030
+ tasks: tasksSchema.optional(),
3031
+ options: import_zod3.z.object({
3032
+ returningAll: import_zod3.z.boolean().optional(),
3033
+ includePermissions: import_zod3.z.boolean().optional(),
3034
+ includeFieldPermissions: import_zod3.z.boolean().optional(),
3035
+ populateAccess: populateAccessSchema.optional()
3036
+ }).passthrough().optional()
3037
+ }).passthrough()
3038
+ );
3039
+ var distinctBodySchema = publicBoundarySchema(
3040
+ import_zod3.z.object({
3041
+ filter: objectOrArraySchema.optional()
3042
+ }).passthrough().superRefine((body, ctx) => rejectKeys(body, ctx, ["query"]))
3043
+ );
3044
+ var subListBodySchema = publicBoundarySchema(
3045
+ import_zod3.z.object({
3046
+ filter: import_zod3.z.record(import_zod3.z.string(), import_zod3.z.unknown()).optional(),
3047
+ select: fieldsSchema.optional()
3048
+ }).passthrough().superRefine((body, ctx) => rejectKeys(body, ctx, ["fields"]))
3049
+ );
3050
+ var subMutationBodySchema = publicBoundarySchema(
3051
+ import_zod3.z.union([import_zod3.z.record(import_zod3.z.string(), import_zod3.z.unknown()), import_zod3.z.array(import_zod3.z.record(import_zod3.z.string(), import_zod3.z.unknown()))]),
3052
+ "data"
3053
+ );
3054
+ var subReadBodySchema = publicBoundarySchema(
3055
+ import_zod3.z.object({
3056
+ select: fieldsSchema.optional(),
3057
+ populate: subPopulateSchema.optional()
3058
+ }).passthrough().superRefine((body, ctx) => rejectKeys(body, ctx, ["fields"]))
3059
+ );
2671
3060
  var requestSchemas = {
2672
3061
  listQuery: listQuerySchema,
2673
3062
  createQuery: createQuerySchema,
@@ -2945,7 +3334,9 @@ var rootDataQueryEntrySchema = import_zod5.z.union([
2945
3334
  args: rootDataReadArgsSchema.optional()
2946
3335
  }).passthrough()
2947
3336
  ]);
2948
- var rootQuerySchema = import_zod5.z.array(import_zod5.z.union([rootModelQueryEntrySchema, rootDataQueryEntrySchema]));
3337
+ var rootQuerySchema = publicBoundarySchema(
3338
+ import_zod5.z.array(import_zod5.z.union([rootModelQueryEntrySchema, rootDataQueryEntrySchema]))
3339
+ );
2949
3340
  // Annotate the CommonJS export names for ESM import in node:
2950
3341
  0 && (module.exports = {
2951
3342
  Codes,